From 85ced8bdd4bdd80f962d99da73fc8681ba94d9f1 Mon Sep 17 00:00:00 2001 From: koldo Date: Mon, 21 Oct 2019 19:16:26 +0000 Subject: [PATCH] ScatterCtrl: GetSeries changed to GetDataSource git-svn-id: svn://ultimatepp.org/upp/trunk@13650 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ScatterCtrl/Data.cpp | 8 +-- uppsrc/ScatterCtrl/Processing.cpp | 28 +++++----- uppsrc/ScatterCtrl/Properties.cpp | 19 +++++++ uppsrc/ScatterCtrl/Properties.h | 1 + uppsrc/ScatterCtrl/ScatterCtrl.cpp | 89 ++++++++++++++++++++---------- uppsrc/ScatterCtrl/ScatterCtrl.h | 42 +++++++++----- uppsrc/ScatterCtrl/ScatterCtrl.lay | 1 + 7 files changed, 127 insertions(+), 61 deletions(-) diff --git a/uppsrc/ScatterCtrl/Data.cpp b/uppsrc/ScatterCtrl/Data.cpp index 046e8cf7c..5f42fa172 100644 --- a/uppsrc/ScatterCtrl/Data.cpp +++ b/uppsrc/ScatterCtrl/Data.cpp @@ -29,10 +29,10 @@ void DataDlg::Init(ScatterCtrl& scatter) OnTab(); bool addedAll = false; - DataSource &serie0 = scatter.GetSeries(0); + DataSource &serie0 = scatter.GetDataSource(0); for(int c = 1; c < scatter.GetCount(); c++) { if (!IsNull(scatter.GetCount(c))) { - DataSource &serie = scatter.GetSeries(c); + DataSource &serie = scatter.GetDataSource(c); if (serie0.SameX(serie)) { if (!addedAll) { addedAll = true; @@ -51,7 +51,7 @@ void DataDlg::Init(ScatterCtrl& scatter) Value DataDlg::DataSourceX::Format(const Value& q) const { - if (int(q) >= pscatter->GetSeries(index).GetCount()) + if (int(q) >= pscatter->GetDataSource(index).GetCount()) return Null; Value ret = pscatter->GetStringX(index, q); if (ret.Is()) { @@ -64,7 +64,7 @@ Value DataDlg::DataSourceX::Format(const Value& q) const Value DataDlg::DataSourceY::Format(const Value& q) const { - if (int(q) >= pscatter->GetSeries(index).GetCount()) + if (int(q) >= pscatter->GetDataSource(index).GetCount()) return Null; Value ret = pscatter->GetStringY(index, q); if (ret.Is()) { diff --git a/uppsrc/ScatterCtrl/Processing.cpp b/uppsrc/ScatterCtrl/Processing.cpp index 6da6413f4..4399ceec2 100644 --- a/uppsrc/ScatterCtrl/Processing.cpp +++ b/uppsrc/ScatterCtrl/Processing.cpp @@ -198,7 +198,7 @@ void ProcessingTab::OnArrayBar(Bar &menu) { void ProcessingTab::OnFit() { WaitCursor waitcursor; - DataSource &ds = pscatter->GetSeries(id); + DataSource &ds = pscatter->GetDataSource(id); userEquation->Init("User", ~tabBestFitRight.userFormula, "x"); @@ -230,7 +230,7 @@ void ProcessingTab::OnFit() { void ProcessingTab::OnOp() { - DataSource &data = tabFitLeft.scatter.GetSeries(0); + DataSource &data = tabFitLeft.scatter.GetDataSource(0); if (data.IsParam() || data.IsExplicit()) return; @@ -326,7 +326,7 @@ void ProcessingTab::OnOp() void ProcessingTab::OnAutoSensSector() { - DataSource &data = tabFitLeft.scatter.GetSeries(0); + DataSource &data = tabFitLeft.scatter.GetDataSource(0); Vector secAvg; double baseWidth; @@ -363,7 +363,7 @@ void ProcessingTab::OnOperation() } } exclamationOpened = false; - dataXRange.Init(pscatter->GetSeries(id), tabOpRight.xLow, tabOpRight.xHigh); + dataXRange.Init(pscatter->GetDataSource(id), tabOpRight.xLow, tabOpRight.xHigh); tabOpLeft.scatter.Refresh(); } @@ -373,7 +373,7 @@ void ProcessingTab::UpdateField(const String _name, int _id) name.SetText(_name); tabFitLeft.scatter.RemoveAllSeries(); - tabFitLeft.scatter.AddSeries(pscatter->GetSeries(id)).SetSequentialX(pscatter->GetSequentialX()) + tabFitLeft.scatter.AddSeries(pscatter->GetDataSource(id)).SetSequentialX(pscatter->GetSequentialX()) .Legend(pscatter->GetLegend(id)); tabFitLeft.scatter.SetFastViewX(pscatter->GetFastViewX()); @@ -400,7 +400,7 @@ void ProcessingTab::UpdateField(const String _name, int _id) tabFitLeft.scatter.ShowInfo().ShowContextMenu().ShowProcessDlg().ShowPropertiesDlg().SetMouseHandlingLinked(true, true); - DataSource &data = tabFitLeft.scatter.GetSeries(0); + DataSource &data = tabFitLeft.scatter.GetDataSource(0); if (!data.IsParam()/* && !data.IsExplicit()*/) { double avg = data.AvgY(); @@ -461,7 +461,7 @@ void ProcessingTab::UpdateField(const String _name, int _id) void ProcessingTab::OnUpdateSensitivity() { - DataSource &data = tabFitLeft.scatter.GetSeries(0); + DataSource &data = tabFitLeft.scatter.GetDataSource(0); bool refresh = false; if (tabFitRight.opMax && newWidthMax != tabFitRight.width) { @@ -505,7 +505,7 @@ void ProcessingTab::OnUpdateSensitivity() void ProcessingTab::OnSet() { - DataSource &data = tabFitLeft.scatter.GetSeries(0); + DataSource &data = tabFitLeft.scatter.GetDataSource(0); if (tabFreqFirst && tab.Get() == 1) { tabFreqFirst = false; @@ -538,19 +538,19 @@ void ProcessingTab::OnSet() tabOpLeft.scatter.RemoveAllSeries(); String legend = pscatter->GetLegend(id); - double xLow = pscatter->GetSeries(id).MinX(); + double xLow = pscatter->GetDataSource(id).MinX(); if (IsNull(xLow)) xLow = pscatter->GetXMin(); tabOpRight.xLow <<= xLow; - double xHigh = pscatter->GetSeries(id).MaxX(); + double xHigh = pscatter->GetDataSource(id).MaxX(); if (IsNull(xHigh)) xHigh = pscatter->GetXMin() + pscatter->GetXRange(); tabOpRight.xHigh <<= xHigh; - dataXRange.Init(pscatter->GetSeries(id), xLow, xHigh); + dataXRange.Init(pscatter->GetDataSource(id), xLow, xHigh); tabOpLeft.scatter.AddSeries(dataXRange).SetSequentialX(pscatter->GetSequentialX()) .Legend(legend + String("-") + t_("Processed")).NoMark() .Stroke(8, Upp::Color(115, 214, 74)); - tabOpLeft.scatter.AddSeries(pscatter->GetSeries(id)).SetSequentialX(pscatter->GetSequentialX()) + tabOpLeft.scatter.AddSeries(pscatter->GetDataSource(id)).SetSequentialX(pscatter->GetSequentialX()) .Legend(legend).NoMark().Stroke(2, Blue()); tabOpLeft.scatter.SetFastViewX(pscatter->GetFastViewX()); @@ -571,7 +571,7 @@ void ProcessingTab::OnSet() tabBestFitLeft.scatter.RemoveAllSeries(); String legend = pscatter->GetLegend(id); - tabBestFitLeft.scatter.AddSeries(pscatter->GetSeries(id)).SetSequentialX(pscatter->GetSequentialX()) + tabBestFitLeft.scatter.AddSeries(pscatter->GetDataSource(id)).SetSequentialX(pscatter->GetSequentialX()) .Legend(legend).NoMark().Stroke(2); tabBestFitLeft.scatter.SetFastViewX(pscatter->GetFastViewX()); @@ -636,7 +636,7 @@ void ProcessingTab::OnFFT() { WaitCursor waitcursor; - DataSource &data = tabFitLeft.scatter.GetSeries(0); + DataSource &data = tabFitLeft.scatter.GetDataSource(0); Vector orderedSeries; for (int64 i = 0; i < data.GetCount(); ++i) { // Clean Nulls diff --git a/uppsrc/ScatterCtrl/Properties.cpp b/uppsrc/ScatterCtrl/Properties.cpp index 2f2354b72..3fe6207ff 100644 --- a/uppsrc/ScatterCtrl/Properties.cpp +++ b/uppsrc/ScatterCtrl/Properties.cpp @@ -324,6 +324,8 @@ void GeneralTab::Init(ScatterCtrl& scatter) editSensitivity <<= THISBACK(Change); editJpgQ <<= THISBACK(Change); + butApplyToAll <<= THISBACK(ChangeAll); + Change(); } @@ -342,6 +344,23 @@ void GeneralTab::Change() scatter.Refresh(); } +void GeneralTab::ChangeAll() +{ + for (int i = 0; i < ScatterCtrl::GetInstancesCount(); ++i) { + ScatterCtrl &scatter = ScatterCtrl::GetInstance(i); + + scatter.SetMode(~dropResolution); + scatter.Rotate((ScatterCtrl::Angle)(int)dropRotate.GetData()); + Size size(~editWidth, ~editHeight); + scatter.SetSaveSize(size); + scatter.ScatterDraw::Responsive(~opResponsive, ~editSensitivity); + scatter.SetJPGQuality(~editJpgQ); + + scatter.SetModify(); + scatter.Refresh(); + } +} + void SeriesTab::Init(ScatterCtrl& scatter) { CtrlLayout(left); diff --git a/uppsrc/ScatterCtrl/Properties.h b/uppsrc/ScatterCtrl/Properties.h index 92a8e2172..5a16d0055 100644 --- a/uppsrc/ScatterCtrl/Properties.h +++ b/uppsrc/ScatterCtrl/Properties.h @@ -164,6 +164,7 @@ private: ScatterCtrl *pscatter; void Change(); + void ChangeAll(); }; class DataDlg : public WithData { diff --git a/uppsrc/ScatterCtrl/ScatterCtrl.cpp b/uppsrc/ScatterCtrl/ScatterCtrl.cpp index 26c23003a..5740be984 100644 --- a/uppsrc/ScatterCtrl/ScatterCtrl.cpp +++ b/uppsrc/ScatterCtrl/ScatterCtrl.cpp @@ -7,6 +7,8 @@ #define TFILE #include +Vector ScatterCtrl::instances; + #ifdef PLATFORM_WIN32 void ScatterCtrl::SaveAsMetafile(const char* file) @@ -193,7 +195,6 @@ void ScatterCtrl::SaveControl() { } void ScatterCtrl::Paint0(Draw& w, const Size &sz) { - GuiLock __; if (IsNull(highlight_0) && highlighting) { highlighting = false; KillTimeCallback(); @@ -233,6 +234,8 @@ void ScatterCtrl::Paint0(Draw& w, const Size &sz) { void ScatterCtrl::Paint(Draw& w) { + GuiLock __; + if (rotate == Angle_0) Paint0(w, GetSize()); else if (rotate == Angle_90) { @@ -257,8 +260,46 @@ void ScatterCtrl::TimerCallback() { Refresh(); } -void ScatterCtrl::ProcessPopUp(const Point &pt) -{ +void ScatterCtrl::Closest(double &x, double &y, double &y2) { + double minD = DBL_MAX; + double retx, rety, rety2; + + for (int i = 0; i < series.GetCount(); ++i) { + ScatterSeries &serie = series[i]; + if (serie.IsDeleted() || serie.opacity == 0 || serie.Data().IsExplicit()) + continue; + DataSource &data = serie.Data(); + double d; + int64 id; + if (serie.primaryY) { + id = data.Closest(x, y); + d = GetScatterDistance(x - data.x(id), y - data.y(id)); + } else { + id = data.Closest(x, y); + d = GetScatterDistance2(x - data.x(id), y - data.y(id)); + } + if (minD > d) { + minD = d; + retx = data.x(id); + if (serie.primaryY) { + rety = data.y(id); + rety2 = GetRealPosY2(GetScatterPosY(data.y(id))); + } else { + rety2 = data.y(id); + rety = GetRealPosY(GetScatterPosY2(data.y(id))); + } + } + } + if (minD == DBL_MAX) + x = y = y2 = Null; + else { + x = retx; + y = rety; + y2 = rety2; + } +} + +void ScatterCtrl::ProcessPopUp(Point &pt) { double _x = GetRealPosX(popLT.x); double _y = GetRealPosY(popLT.y); double _y2 = GetRealPosY2(popLT.y); @@ -266,6 +307,10 @@ void ScatterCtrl::ProcessPopUp(const Point &pt) double y = GetRealPosY(pt.y); double y2 = GetRealPosY2(pt.y); + if (IsNull(popLT)) + popLT = pt; + popRB = pt; + double dx = fabs(x - _x); double dy = fabs(y - _y); double dy2 = fabs(y2 - _y2); @@ -379,14 +424,6 @@ void ScatterCtrl::ProcessPopUp(const Point &pt) } else popTextEnd.Hide(); } - -/*void ScatterCtrl::ProcessClickSeries(const Point &pt) -{ - double posx = GetRealPosX(pt.x); - double posy = GetRealPosY(pt.y); - double dx = 2*GetPixelThickX(); - double dy = 2*GetPixelThickY(); -}*/ void ScatterCtrl::DoMouseAction(bool down, Point pt, ScatterAction action, int wheel) { @@ -520,8 +557,9 @@ bool ScatterCtrl::ProcessKey(int key) return processed; } -void ScatterCtrl::LabelPopUp(bool down, Point &pt) -{ +void ScatterCtrl::LabelPopUp(bool down, Point &pt) { + GuiLock __; + if (down) { if(showInfo && PointInPlot(pt)) { popTextBegin.AppearOnly(this); @@ -530,16 +568,6 @@ void ScatterCtrl::LabelPopUp(bool down, Point &pt) popTextEnd.AppearOnly(this); isLabelPopUp = true; - if (IsNull(popLT)) - popLT = pt; - popRB = pt; - /*Rect wa = GetWorkArea(); - Rect rc = GetScreenRect(); - if (wa.right - (rc.left + pt.x) < 200) - pt.x -= 200; - if (wa.bottom - (rc.top + pt.y) < 200) - pt.y -= 200;*/ - //ProcessClickSeries(pt); TBD ProcessPopUp(pt); } } else { @@ -555,8 +583,7 @@ void ScatterCtrl::LabelPopUp(bool down, Point &pt) } } -void ScatterCtrl::ZoomWindow(bool down, Point &pt) -{ +void ScatterCtrl::ZoomWindow(bool down, Point &pt) { if (down) { if (PointInPlot(pt)) { isZoomWindow = true; @@ -565,7 +592,7 @@ void ScatterCtrl::ZoomWindow(bool down, Point &pt) popRB = pt; } } else { - if(isZoomWindow) { + if (isZoomWindow) { isLabelPopUp = isZoomWindow = false; if (popLT.x > popRB.x) @@ -625,7 +652,7 @@ bool ScatterCtrl::Key(dword key, int ) else if (key == K_CTRL_D) DoShowData(); else if (key == K_CTRL_C) - SaveToClipboard(true); + SaveToClipboard(false); else if (key == K_CTRL_S) SaveToFile(Null); else @@ -722,6 +749,8 @@ void ScatterCtrl::MouseWheel(Point pt, int zdelta, dword keyFlags) void ScatterCtrl::MouseMove(Point pt, dword keyFlags) { + GuiLock __; + MousePointRot(pt); if (isScrolling) { double factorX = 0, factorY = 0; @@ -738,9 +767,6 @@ void ScatterCtrl::MouseMove(Point pt, dword keyFlags) } if(isLabelPopUp) { if (showInfo && PointInPlot(pt)) { - if (IsNull(popLT)) - popLT = pt; - popRB = pt; ProcessPopUp(pt); popTextBegin.AppearOnlyOpen(this); popTextHoriz.AppearOnlyOpen(this); @@ -886,6 +912,7 @@ void ScatterCtrl::OnTypeImage(FileSel *_fs) void ScatterCtrl::SaveToFile(String fileName) { GuiLock __; + if (IsNull(fileName)) { FileSel fs; fs.Type(Format(t_("%s bitmap file"), "jpeg"), "*.jpg"); @@ -1067,5 +1094,7 @@ ScatterCtrl::ScatterCtrl() : popOffset(10, 12), mouseAction(NONE) AddKeyBehavior(true, false, false, K_UP, true, ScatterCtrl::SCROLL_UP); AddKeyBehavior(true, false, false, K_DOWN, true, ScatterCtrl::SCROLL_DOWN); AddKeyBehavior(true, false, false, K_F, true, ScatterCtrl::ZOOM_FIT); + + AddInstance(this); } diff --git a/uppsrc/ScatterCtrl/ScatterCtrl.h b/uppsrc/ScatterCtrl/ScatterCtrl.h index 55c807193..20acaac81 100644 --- a/uppsrc/ScatterCtrl/ScatterCtrl.h +++ b/uppsrc/ScatterCtrl/ScatterCtrl.h @@ -60,15 +60,15 @@ public: ids << idY << idX; Init(_data, ids, _useCols, _beginData, _numData); } - virtual inline double y(int64 id) {return useCols ? data->Get(beginData + int(id), ids[0]) : data->Get(ids[0], beginData + int(id));}; - virtual inline double x(int64 id) { + virtual inline double y(int64 id) {return useCols ? data->Get(beginData + int(id), ids[0]) : data->Get(ids[0], beginData + int(id));}; + virtual inline double x(int64 id) { if (IsNull(ids[1])) return double(id); else return useCols ? data->Get(beginData + int(id), ids[1]) : data->Get(ids[1], beginData + int(id)); } virtual inline double xn(int n, int64 id) {return useCols ? data->Get(beginData + int(id), ids[n]) : data->Get(ids[n], beginData + int(id));} - virtual inline int64 GetCount() {return numData;}; + virtual inline int64 GetCount() const {return numData;}; }; class GridCtrlSource : public DataSource { @@ -112,7 +112,7 @@ public: _ids << idY << idX; Init(_data, _ids, _useCols, _beginData, _numData); } - double GetVal(int64 id, int idx) { + double GetVal(int64 id, int idx) const { if (IsNull(ids[idx])) return double(id); else { @@ -131,10 +131,10 @@ public: return ScanDouble(val.ToString()); } } - virtual inline double y(int64 id) {return GetVal(id, 0);} - virtual inline double x(int64 id) {return GetVal(id, 1);} + virtual inline double y(int64 id) {return GetVal(id, 0);} + virtual inline double x(int64 id) {return GetVal(id, 1);} virtual inline double xn(int n, int64 id) {return useCols ? data->Get(beginData + int(id), ids[n]) : data->Get(ids[n], beginData + int(id));} - virtual inline int64 GetCount() {return numData;}; + virtual inline int64 GetCount() const {return numData;}; }; class ScatterCtrl : public Ctrl, public ScatterDraw { @@ -142,10 +142,11 @@ public: typedef ScatterCtrl CLASSNAME; ScatterCtrl(); - virtual ~ScatterCtrl() {}; + virtual ~ScatterCtrl() {RemoveInstance(this);}; - enum ScatterAction {NO_ACTION = 0, SCROLL, ZOOM_H_ENL, ZOOM_H_RED, ZOOM_V_ENL, ZOOM_V_RED, SHOW_COORDINATES, CONTEXT_MENU, ZOOM_WINDOW, - SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, SCROLL_DOWN, ZOOM_FIT}; + enum ScatterAction {NO_ACTION = 0, SCROLL, ZOOM_H_ENL, ZOOM_H_RED, ZOOM_V_ENL, ZOOM_V_RED, + SHOW_COORDINATES, CONTEXT_MENU, ZOOM_WINDOW, + SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, SCROLL_DOWN, ZOOM_FIT}; #define SHOW_INFO SHOW_COORDINATES struct MouseBehavior { @@ -277,6 +278,11 @@ public: void InsertSeries(int id, ArrayCtrl &data, bool useCols = true, int idX = 0, int idY = 1, int idZ = 2, int beginData = 0, int numData = Null); void InsertSeries(int id, GridCtrl &data, bool useCols = true, int idX = 0, int idY = 1, int idZ = 2, int beginData = 0, int numData = Null); + void RemoveAllSeries() { + GuiLock __; + ScatterDraw::RemoveAllSeries(); + } + ScatterCtrl& SetMaxRefreshTime(int _maxRefresh_ms) {maxRefresh_ms = _maxRefresh_ms; return *this;} int GetMaxRefreshTime() {return maxRefresh_ms;} @@ -336,6 +342,9 @@ public: virtual bool Key(dword key, int count); virtual void GotFocus(); virtual void LostFocus(); + + static int GetInstancesCount() {return instances.GetCount();} + static ScatterCtrl &GetInstance(int i) {return *(instances[i]);} private: bool showInfo; @@ -366,8 +375,7 @@ private: void Paint0(Draw& w, const Size &sz); - void ProcessPopUp(const Point &pt); - //void ProcessClickSeries(const Point &pt); + void ProcessPopUp(Point &pt); void DoMouseAction(bool down, Point pt, ScatterAction action, int wheel); void DoKeyAction(ScatterAction action); @@ -383,6 +391,8 @@ private: void DoShowData(); void DoProcessing(); + void Closest(double &x, double &y, double &y2); + virtual Image CursorImage(Point p, dword keyflags); template @@ -404,7 +414,13 @@ private: int rotate; Point &MousePointRot(Point &pt); - Point &MousePointUnrot(Point &pt); + Point &MousePointUnrot(Point &pt); + + static Vector instances; + static void AddInstance(ScatterCtrl *instance) {instances << instance;} + static void RemoveInstance(ScatterCtrl *instance) { + instances.RemoveIf([&](int i) {return instance == instances[i];}); + } }; template diff --git a/uppsrc/ScatterCtrl/ScatterCtrl.lay b/uppsrc/ScatterCtrl/ScatterCtrl.lay index bc935d6fb..859fb5f71 100644 --- a/uppsrc/ScatterCtrl/ScatterCtrl.lay +++ b/uppsrc/ScatterCtrl/ScatterCtrl.lay @@ -105,6 +105,7 @@ LAYOUT(General, 340, 188) ITEM(OptionBox, opResponsive, AutoBox(true).SetLabel(t_("Responsive")).LeftPosZ(136, 112).TopPosZ(32, 44)) ITEM(Label, dv___12, SetLabel(t_("JPG quality:")).LeftPosZ(136, 64).TopPosZ(80, 19)) ITEM(EditDouble, editSensitivity, Min(0).LeftPosZ(216, 24).TopPosZ(48, 19)) + ITEM(Button, butApplyToAll, SetLabel(t_("Apply to all plots")).RightPosZ(8, 96).BottomPosZ(8, 20)) END_LAYOUT LAYOUT(SeriesLeft, 128, 228)