# 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)
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
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
SET(_all_lib_SCRIPTS
Model.py
+ PlotModel.py
CurveModel.py
BarModel.py
StemModel.py
# 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()
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
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
class Model(object):
START_ID = -1
- COUNT_MODELS = defaultdict(int)
@classmethod
def __GenerateID(cls):
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 <Bar/Curve/Stem>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.
--- /dev/null
+# 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
# 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()
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
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
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
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
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()
# 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
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()
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.)
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)
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
View.py
CurveBrowserView.py
CurveTabsView.py
+ PlotView.py
CurveView.py
BarView.py
StemView.py
# 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
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")
# 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)
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
--- /dev/null
+# 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
+
# 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
# 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")
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:
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:
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
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