From: jh777916 Date: Mon, 9 Oct 2023 14:16:22 +0000 (+0200) Subject: Factorization of the Models and Views used for the traces into the classes PlotModel... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a7954d9a3c4ed4b5fce69dea44c9170e68d3954a;p=modules%2Fgui.git Factorization of the Models and Views used for the traces into the classes PlotModel and PlotView; PlotModel class has an idPlot variable to get the ID of each trace; updated the plot_test.py and PlotTestBase.py; added new tests; update of the test baselines" --- diff --git a/tools/CurvePlot/src/python/model/BarModel.py b/tools/CurvePlot/src/python/model/BarModel.py index 26b5c739b..5513f9b04 100644 --- a/tools/CurvePlot/src/python/model/BarModel.py +++ b/tools/CurvePlot/src/python/model/BarModel.py @@ -17,23 +17,19 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from .Model import Model -from .utils import toUnicodeWithWarning +from .PlotModel import PlotModel -class BarModel(Model): +class BarModel(PlotModel): def __init__(self, controller, table=None, heightIndex=-1, widthIndex=-1): - Model.__init__(self, controller) + PlotModel.__init__(self, controller) - # self.ID_PLOT += 1 self._name = "BarModel" self._title = "Barplot %d" % self.getID() self._table = table - self._xaxisIndex = 0 # By default the first column of the table is used for the X-s self._heightIndex = heightIndex # column index in the table, corresponding to the bar height self._widthIndex = widthIndex # column index in the table, corresponding to the bar width - def clone(self): ret = BarModel(self._controller) @@ -43,32 +39,6 @@ class BarModel(Model): ret._heightIndex = self._heightIndex ret._widthIndex = self._widthIndex return ret - - def setTable(self, t, silent=False): - self._table = t - if not silent: - self.notifyChange("DataChange") - - def getTable(self): - return self._table - - def extendData(self, t, silent=False): - self._table.extend(t) - if not silent: - self.notifyChange("DataChange") - - def resetData(self): - self._table.clear() - self.notifyChange("DataChange") - - def setTitle(self, ti, silent=False): - ti = toUnicodeWithWarning(ti, "BarModel::setTitle()") - self._title = ti - if not silent: - self.notifyChange("CurveTitleChange") - - def getTitle(self): - return self._title def getHeightIndex(self): return self._heightIndex @@ -85,18 +55,3 @@ class BarModel(Model): self._widthIndex = idx if not silent: self.notifyChange("WidthIndexChange") - - def getXAxisIndex(self): - return self._xaxisIndex - - def setXAxisIndex(self, idx, silent=False): - sh = self._table.getShape() - if idx >= sh[1]: - raise ValueError("Index out of bound (is %d, but max is %d)" % (idx, sh[1])) - self._xaxisIndex = idx - if not silent: - self.notifyChange("XAxisIndexChange") - - # Overloading to access the plotID instead of the Model ID - def getID(self): - return self._idPlot diff --git a/tools/CurvePlot/src/python/model/CMakeLists.txt b/tools/CurvePlot/src/python/model/CMakeLists.txt index 2cc819175..b756d9156 100644 --- a/tools/CurvePlot/src/python/model/CMakeLists.txt +++ b/tools/CurvePlot/src/python/model/CMakeLists.txt @@ -19,6 +19,7 @@ SET(_all_lib_SCRIPTS Model.py + PlotModel.py CurveModel.py BarModel.py StemModel.py diff --git a/tools/CurvePlot/src/python/model/CurveModel.py b/tools/CurvePlot/src/python/model/CurveModel.py index 56e4cb40a..c8d7c6426 100644 --- a/tools/CurvePlot/src/python/model/CurveModel.py +++ b/tools/CurvePlot/src/python/model/CurveModel.py @@ -17,13 +17,12 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from .Model import Model -from .utils import toUnicodeWithWarning +from .PlotModel import PlotModel -class CurveModel(Model): +class CurveModel(PlotModel): def __init__(self, controller, table=None, index=-1): - Model.__init__(self, controller) + PlotModel.__init__(self, controller) self._name = "CurveModel" self._title = "Curve %d" % self.getID() @@ -39,32 +38,6 @@ class CurveModel(Model): ret._xaxisIndex = self._xaxisIndex return ret - def setTable(self, t, silent=False): - self._table = t - if not silent: - self.notifyChange("DataChange") - - def getTable(self): - return self._table - - def extendData(self, t, silent=False): - self._table.extend(t) - if not silent: - self.notifyChange("DataChange") - - def resetData(self): - self._table.clear() - self.notifyChange("DataChange") - - def setTitle(self, ti, silent=False): - ti = toUnicodeWithWarning(ti, "CurveModel::setTitle()") - self._title = ti - if not silent: - self.notifyChange("CurveTitleChange") - - def getTitle(self): - return self._title - def getYAxisIndex(self): return self._yaxisIndex @@ -72,19 +45,3 @@ class CurveModel(Model): self._yaxisIndex = idx if not silent: self.notifyChange("YAxisIndexChange") - - def getXAxisIndex(self): - return self._xaxisIndex - - def setXAxisIndex(self, idx, silent=False): - sh = self._table.getShape() - if idx >= sh[1]: - raise ValueError("Index out of bound (is %d, but max is %d)" % (idx, sh[1])) - self._xaxisIndex = idx - if not silent: - self.notifyChange("XAxisIndexChange") - - # Overloading to access the plotID instead of the Model ID - def getID(self): - return self._idPlot - \ No newline at end of file diff --git a/tools/CurvePlot/src/python/model/Model.py b/tools/CurvePlot/src/python/model/Model.py index 201390444..e77132f10 100644 --- a/tools/CurvePlot/src/python/model/Model.py +++ b/tools/CurvePlot/src/python/model/Model.py @@ -21,7 +21,6 @@ from collections import defaultdict class Model(object): START_ID = -1 - COUNT_MODELS = defaultdict(int) @classmethod def __GenerateID(cls): @@ -35,23 +34,9 @@ class Model(object): self._controller = controller self._id = self.__GenerateID() # A unique ID for this class of object - # This part is added to "hack" the initial ID and manage different kind of plot models - # An intermediary "PlotModel" class with its own kind of ID - # (between Model and Model classes) would be useful to use as an interface - # instead of using this kind of hack - - # Counting instances of classes (Model) and subclasses - for cls in self.__class__.__mro__: - self.COUNT_MODELS[cls.__name__] += 1 - - # A unique ID for the traces (Curves, Bars and Stems), starting from 0 - self._idPlot = self.COUNT_MODELS["CurveModel"] \ - + self.COUNT_MODELS["BarModel"] \ - + self.COUNT_MODELS["StemModel"]- 1 - def getID(self): return self._id - + def getController(self): """ :returns: Controller -- This model's controller. diff --git a/tools/CurvePlot/src/python/model/PlotModel.py b/tools/CurvePlot/src/python/model/PlotModel.py new file mode 100644 index 000000000..5845a0c59 --- /dev/null +++ b/tools/CurvePlot/src/python/model/PlotModel.py @@ -0,0 +1,81 @@ +# Copyright (C) 2016-2022 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : J. Hamma +# + +from .Model import Model +from .utils import toUnicodeWithWarning + +class PlotModel(Model): + """ + Class used to regroup all the plot models and keep a unique id for each trace. + Classes CurveModel, BarModel and StemModel derives from this class. + Useful for the tests (especially the unique ID that can be easily reset when + screenshots are taken). + """ + START_IDPLOT = -1 + + def __init__( self, controller ): + Model.__init__(self, controller) + self._idPlot = PlotModel.START_IDPLOT + 1 + PlotModel.START_IDPLOT += 1 + + def getID(self): + """ + Overriding the Model.getID() method to get the plot ID instead of the Model ID. + Useful to easily superpose traces. + """ + return self._idPlot + + def setTable(self, t, silent=False): + self._table = t + if not silent: + self.notifyChange("DataChange") + + def getTable(self): + return self._table + + def extendData(self, t, silent=False): + self._table.extend(t) + if not silent: + self.notifyChange("DataChange") + + def resetData(self): + self._table.clear() + self.notifyChange("DataChange") + + def setTitle(self, ti, silent=False): + ti = toUnicodeWithWarning(ti, f"{type(self).__name__}::setTitle()") + self._title = ti + if not silent: + self.notifyChange("CurveTitleChange") + + def getTitle(self): + return self._title + + def getXAxisIndex(self): + return self._xaxisIndex + + def setXAxisIndex(self, idx, silent=False): + sh = self._table.getShape() + if idx >= sh[1]: + raise ValueError("Index out of bound (is %d, but max is %d)" % (idx, sh[1])) + self._xaxisIndex = idx + if not silent: + self.notifyChange("XAxisIndexChange") \ No newline at end of file diff --git a/tools/CurvePlot/src/python/model/StemModel.py b/tools/CurvePlot/src/python/model/StemModel.py index 6cc19c6b0..500f50890 100644 --- a/tools/CurvePlot/src/python/model/StemModel.py +++ b/tools/CurvePlot/src/python/model/StemModel.py @@ -17,13 +17,12 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from .Model import Model -from .utils import toUnicodeWithWarning +from .PlotModel import PlotModel + +class StemModel(PlotModel): -class StemModel(Model): - def __init__(self, controller, table=None, index=-1): - Model.__init__(self, controller) + PlotModel.__init__(self, controller) self._name = "StemModel" self._title = "Stem %d" % self.getID() @@ -39,32 +38,6 @@ class StemModel(Model): ret._xaxisIndex = self._xaxisIndex return ret - def setTable(self, t, silent=False): - self._table = t - if not silent: - self.notifyChange("DataChange") - - def getTable(self): - return self._table - - def extendData(self, t, silent=False): - self._table.extend(t) - if not silent: - self.notifyChange("DataChange") - - def resetData(self): - self._table.clear() - self.notifyChange("DataChange") - - def setTitle(self, ti, silent=False): - ti = toUnicodeWithWarning(ti, "StemModel::setTitle()") - self._title = ti - if not silent: - self.notifyChange("CurveTitleChange") - - def getTitle(self): - return self._title - def getYAxisIndex(self): return self._yaxisIndex @@ -72,19 +45,3 @@ class StemModel(Model): self._yaxisIndex = idx if not silent: self.notifyChange("YAxisIndexChange") - - def getXAxisIndex(self): - return self._xaxisIndex - - def setXAxisIndex(self, idx, silent=False): - sh = self._table.getShape() - if idx >= sh[1]: - raise ValueError("Index out of bound (is %d, but max is %d)" % (idx, sh[1])) - self._xaxisIndex = idx - if not silent: - self.notifyChange("XAxisIndexChange") - - # Overloading to access the plotID instead of the Model ID - def getID(self): - return self._idPlot - \ No newline at end of file diff --git a/tools/CurvePlot/src/python/test/PlotTestBase.py b/tools/CurvePlot/src/python/test/PlotTestBase.py index a2c5377c4..1e254e3a0 100644 --- a/tools/CurvePlot/src/python/test/PlotTestBase.py +++ b/tools/CurvePlot/src/python/test/PlotTestBase.py @@ -83,7 +83,7 @@ class PlotTestBase(unittest.TestCase): import sys from curveplot.SalomePyQt_MockUp import SalomePyQt from curveplot.TableModel import TableModel - from curveplot.CurveModel import CurveModel + from curveplot.PlotModel import PlotModel from curveplot.XYPlotSetModel import XYPlotSetModel from curveplot.TestDesktop import TestDesktop @@ -109,9 +109,7 @@ class PlotTestBase(unittest.TestCase): self._execQtWasCalled = False # Used to automatically finish Qt execution loop on tests not doing a screenshot # Reset some class var to make sure IDs appearing in screenshots do not depend on test seq order: - CurveModel.START_ID = -1 - BarModel.START_ID = -1 - StemModel.START_ID = -1 + PlotModel.START_IDPLOT = -1 TableModel.START_ID = -1 XYPlotSetModel.START_ID = -1 diff --git a/tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png b/tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png index 7829eefd2..4375a3718 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png and b/tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png b/tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png index b184a7a92..fb23c9754 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png and b/tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png b/tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png index 05e08a8f2..fb23c9754 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png and b/tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testExtendCurve.png b/tools/CurvePlot/src/python/test/baselines/testExtendCurve.png index d28e7940f..d198be0e5 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testExtendCurve.png and b/tools/CurvePlot/src/python/test/baselines/testExtendCurve.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testLockRepaint.png b/tools/CurvePlot/src/python/test/baselines/testLockRepaint.png index a4e767d1e..14b9b0c86 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testLockRepaint.png and b/tools/CurvePlot/src/python/test/baselines/testLockRepaint.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testResetCurve.png b/tools/CurvePlot/src/python/test/baselines/testResetCurve.png index 779bfa595..b9dc0b408 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testResetCurve.png and b/tools/CurvePlot/src/python/test/baselines/testResetCurve.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png b/tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png index f3996514e..d954fbc8a 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png and b/tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png index 333754c0b..6481cd391 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png index 9cb0e2944..6481cd391 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png index 9c2c29028..b80ea7bd3 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png b/tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png index 816c70662..08730f9dc 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png b/tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png index f0db9425d..9ceb9505f 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png and b/tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png b/tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png index fe56d5656..9be328881 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png and b/tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testShowAll.png b/tools/CurvePlot/src/python/test/baselines/testShowAll.png index 54b91a5fe..c6009d133 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testShowAll.png and b/tools/CurvePlot/src/python/test/baselines/testShowAll.png differ diff --git a/tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png b/tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png index 792d52d6b..d0673904b 100644 Binary files a/tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png and b/tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png differ diff --git a/tools/CurvePlot/src/python/test/plot_test.py b/tools/CurvePlot/src/python/test/plot_test.py index 9288321a8..8240dd9d0 100644 --- a/tools/CurvePlot/src/python/test/plot_test.py +++ b/tools/CurvePlot/src/python/test/plot_test.py @@ -338,7 +338,6 @@ class PlotTest(PlotTestBase): cont.plotCurveFromTable(t, y_col_index=2, append=True) self.assertTrue(self.areScreenshotEqual(tw)) - @runOnly def testSettingsCurveColor(self): tw = self.showTabWidget() x, y = self.generateSine() diff --git a/tools/CurvePlot/src/python/views/BarView.py b/tools/CurvePlot/src/python/views/BarView.py index 2384f716e..6bc796db6 100644 --- a/tools/CurvePlot/src/python/views/BarView.py +++ b/tools/CurvePlot/src/python/views/BarView.py @@ -17,30 +17,15 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from .View import View +from .PlotView import PlotView from .utils import Logger -class BarView(View): +class BarView(PlotView): _PICKER_PRECISION_BAR = 5 #pts def __init__(self, controller, parentXYView): - View.__init__(self, controller) - self._mplAxes = None - self._mplArtist = None - - self._isHighlighted = False - self._initialLineWidth = None + PlotView.__init__(self, controller, parentXYView) self._initialEdgeColorBar = None - self._initialOpacity = None - self._initialZOrder = None - self._parentXYView = parentXYView - - def setMPLAxes(self, axes): - self._mplAxes = axes - - def erase(self): - self._mplArtist.remove() - self._mplArtist = None def draw(self): m = self._model @@ -53,20 +38,13 @@ class BarView(View): align=x_align, label=m._title, alpha= 0.7, picker=self._PICKER_PRECISION_BAR) - self._initialLineWidth = 0. #self._mplArtist[0].get_linewidth() + self._initialLineWidth = 0. self._initialEdgeColorBar = self._mplArtist[0].get_edgecolor() self._initialOpacity = self._mplArtist[0].get_alpha() self._initialZOrder = self._mplArtist[0].get_zorder() - - def onCurveTitleChange(self): - if self._mplArtist is None: - return - self._mplArtist.set_label(self._model._title) - def update(self): Logger.Debug("BarView::udpate") - if self._mplArtist is None: return color = self.getColor() @@ -78,7 +56,7 @@ class BarView(View): self.toggleHighlight(self._isHighlighted, force=True) def toggleHighlight(self, highlight, force=False): - bar = self._mplArtist.patches # TAG CHECK + bar = self._mplArtist.patches if highlight and (force or not self._isHighlighted): for rect in bar : rect.set_linewidth(1.) @@ -96,10 +74,10 @@ class BarView(View): else: # Nothing to do, already the correct state return - - def isHighlighted(self): - return self._isHighlighted - + + def setLineStyle(self, lin_style): + pass + def setColor(self, rgb_color): for rect in self._mplArtist : rect.set_facecolor(rgb_color) @@ -117,14 +95,3 @@ class BarView(View): if self._mplArtist is None: return None return self._mplArtist[0].get_alpha() - - def setInitialAlpha(self, opacity): - self._initialOpacity = opacity - - def getInitialAlpha(self): - if self._mplArtist is None: - return None - return self._initialOpacity - - def setLineStyle(self, linestyle=""): - return \ No newline at end of file diff --git a/tools/CurvePlot/src/python/views/CMakeLists.txt b/tools/CurvePlot/src/python/views/CMakeLists.txt index 67f359c31..316a1d517 100644 --- a/tools/CurvePlot/src/python/views/CMakeLists.txt +++ b/tools/CurvePlot/src/python/views/CMakeLists.txt @@ -21,6 +21,7 @@ SET(_all_lib_SCRIPTS View.py CurveBrowserView.py CurveTabsView.py + PlotView.py CurveView.py BarView.py StemView.py diff --git a/tools/CurvePlot/src/python/views/CurveView.py b/tools/CurvePlot/src/python/views/CurveView.py index 990b6ac81..dafc9eb87 100644 --- a/tools/CurvePlot/src/python/views/CurveView.py +++ b/tools/CurvePlot/src/python/views/CurveView.py @@ -17,36 +17,21 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from .View import View +from .PlotView import PlotView from .utils import Logger -class CurveView(View): +class CurveView(PlotView): _PICKER_PRECISION = 10 #pts def __init__(self, controller, parentXYView): - View.__init__(self, controller) - self._mplAxes = None - self._mplArtist = None - - self._isHighlighted = False - self._initialLineWidth = None - self._initialOpacity = None - self._initialZOrder = None - self._parentXYView = parentXYView + PlotView.__init__(self, controller, parentXYView) - # Some of these seems to be unused ... + # These seems to be unused, kept to avoid any problems of dependencies ... self._marker = None self._color = None self._lineStyle = None self._opacity = None - def setMPLAxes(self, axes): - self._mplAxes = axes - - def erase(self): - self._mplAxes.lines.remove(self._mplArtist) - self._mplArtist = None - def draw(self): Logger.Debug("CurveView::draw") m = self._model @@ -58,14 +43,6 @@ class CurveView(View): self._initialLineWidth = self._mplArtist.get_linewidth() self._initialOpacity = self._mplArtist.get_alpha() self._initialZOrder = self._mplArtist.get_zorder() - - # print(f"TYPE ARTISTS LINES: {type(self._mplArtist)}") - # print(f"SIZE ARTISTS LINES: {len(self._mplArtist)}") - - def onCurveTitleChange(self): - if self._mplArtist is None: - return - self._mplArtist.set_label(self._model._title) def update(self): Logger.Debug("CurveView::udpate") @@ -114,9 +91,6 @@ class CurveView(View): # Nothing to do, already the correct state return - def isHighlighted(self): - return self._isHighlighted - def setColor(self, rgb_color): lin = self._mplArtist lin.set_color(rgb_color) @@ -134,11 +108,3 @@ class CurveView(View): if self._mplArtist is None: return None return self._mplArtist.get_alpha() - - def setInitialAlpha(self, opacity): - self._initialOpacity = opacity - - def getInitialAlpha(self): - if self._mplArtist is None: - return None - return self._initialOpacity diff --git a/tools/CurvePlot/src/python/views/PlotView.py b/tools/CurvePlot/src/python/views/PlotView.py new file mode 100644 index 000000000..801a9ec7e --- /dev/null +++ b/tools/CurvePlot/src/python/views/PlotView.py @@ -0,0 +1,85 @@ +# Copyright (C) 2016-2022 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : J. Hamma +# + +from .View import View +from .utils import Logger + +class PlotView(View): + """ + Class factorizing the different plot visualizations class of the data that model contains. + Classes StemView, CurveView, BarView derives from it. + """ + def __init__(self, controller, parentXYView): + View.__init__(self, controller) + self._mplAxes = None + self._mplArtist = None + + self._isHighlighted = False + self._initialLineWidth = None + self._initialOpacity = None + self._initialZOrder = None + self._parentXYView = parentXYView + + def setMPLAxes(self, axes): + self._mplAxes = axes + + def erase(self): + self._mplArtist.remove() + self._mplArtist = None + + def isHighlighted(self): + return self._isHighlighted + + def onCurveTitleChange(self): + if self._mplArtist is None: + return + self._mplArtist.set_label(self._model._title) + + def setInitialAlpha(self, opacity): + self._initialOpacity = opacity + + def getInitialAlpha(self): + if self._mplArtist is None: + return None + return self._initialOpacity + + # Methods that should be implemented in subclasses of PlotView (lineStyle needed for XYView::changeModeCurve) + def update(self) : + raise NotImplementedError + + def toggleHighlight(self, highlight, force=False): + raise NotImplementedError + + def setLineStyle(self, lin_style): + raise NotImplementedError + + def setColor(self, rgb_color): + raise NotImplementedError + + def getColor(self): + raise NotImplementedError + + def setAlpha(self, opacity): + raise NotImplementedError + + def getAlpha(self): + raise NotImplementedError + diff --git a/tools/CurvePlot/src/python/views/StemView.py b/tools/CurvePlot/src/python/views/StemView.py index 5333c7205..dd721b515 100644 --- a/tools/CurvePlot/src/python/views/StemView.py +++ b/tools/CurvePlot/src/python/views/StemView.py @@ -17,29 +17,14 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from .View import View +from .PlotView import PlotView from .utils import Logger -class StemView(View): +class StemView(PlotView): _PICKER_PRECISION = 10 #pts def __init__(self, controller, parentXYView): - View.__init__(self, controller) - self._mplAxes = None - self._mplArtist = None - - self._isHighlighted = False - self._initialLineWidth = None - self._initialOpacity = None - self._initialZOrder = None - self._parentXYView = parentXYView - - def setMPLAxes(self, axes): - self._mplAxes = axes - - def erase(self): - self._mplArtist.remove() - self._mplArtist = None + PlotView.__init__(self, controller, parentXYView) def draw(self): m = self._model @@ -62,11 +47,6 @@ class StemView(View): # picker for the stemlines for lin in self._mplArtist[1]: lin.set_picker(self._PICKER_PRECISION) - - def onCurveTitleChange(self): - if self._mplArtist is None: - return - self._mplArtist.set_label(self._model._title) def update(self): Logger.Debug("StemView::udpate") @@ -124,17 +104,17 @@ class StemView(View): else: # Nothing to do, already the correct state return - - def isHighlighted(self): - return self._isHighlighted def setZOrder(self, zorder): + """ + Had to define it to set the zorder of each element composing the stem. + """ markerline, stemlines, _ = self._mplArtist markerline.set_zorder(zorder) for lin in stemlines: lin.set_zorder(zorder) - def setLineWidth(self, lw): + def setLineWidth(self, lw): markerline, stemlines, _ = self._mplArtist markerline.set_linewidth(lw) for lin in stemlines: @@ -152,6 +132,9 @@ class StemView(View): return self._mplArtist[0].get_color() def setAlpha(self, opacity): + """ + Had to define it to set the opacity of each element composing the stem. + """ markerline, stemlines, _ = self._mplArtist markerline.set_alpha(opacity) for lin in stemlines: @@ -162,10 +145,3 @@ class StemView(View): return None return self._mplArtist[0].get_alpha() - def setInitialAlpha(self, opacity): - self._initialOpacity = opacity - - def getInitialAlpha(self): - if self._mplArtist is None: - return None - return self._initialOpacity diff --git a/tools/CurvePlot/src/python/views/XYView.py b/tools/CurvePlot/src/python/views/XYView.py index b90dda21a..6b0bdedf2 100644 --- a/tools/CurvePlot/src/python/views/XYView.py +++ b/tools/CurvePlot/src/python/views/XYView.py @@ -78,7 +78,7 @@ class XYView(View): View.__init__(self, controller) self._eventHandler = EventHandler() - self._curveViews = {} # key: trace ID (BarModel + CurveModel), value: CurveView / BarView + self._curveViews = {} # key: PlotModel IDPLOT associated to StemModel, BarModel or CurveModel), value: PlotView subclass associated to the model self._salomeViewID = None self._mplFigure = None self._mplAxes = None