]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Factorization of the Models and Views used for the traces into the classes PlotModel...
authorjh777916 <juba.hamma@cea.fr>
Mon, 9 Oct 2023 14:16:22 +0000 (16:16 +0200)
committerjh777916 <juba.hamma@cea.fr>
Mon, 9 Oct 2023 14:16:59 +0000 (16:16 +0200)
29 files changed:
tools/CurvePlot/src/python/model/BarModel.py
tools/CurvePlot/src/python/model/CMakeLists.txt
tools/CurvePlot/src/python/model/CurveModel.py
tools/CurvePlot/src/python/model/Model.py
tools/CurvePlot/src/python/model/PlotModel.py [new file with mode: 0644]
tools/CurvePlot/src/python/model/StemModel.py
tools/CurvePlot/src/python/test/PlotTestBase.py
tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png
tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png
tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png
tools/CurvePlot/src/python/test/baselines/testExtendCurve.png
tools/CurvePlot/src/python/test/baselines/testLockRepaint.png
tools/CurvePlot/src/python/test/baselines/testResetCurve.png
tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png
tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png
tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png
tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png
tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png
tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png
tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png
tools/CurvePlot/src/python/test/baselines/testShowAll.png
tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png
tools/CurvePlot/src/python/test/plot_test.py
tools/CurvePlot/src/python/views/BarView.py
tools/CurvePlot/src/python/views/CMakeLists.txt
tools/CurvePlot/src/python/views/CurveView.py
tools/CurvePlot/src/python/views/PlotView.py [new file with mode: 0644]
tools/CurvePlot/src/python/views/StemView.py
tools/CurvePlot/src/python/views/XYView.py

index 26b5c739b0cce0ca3342e2fd31afbf8dc17ce736..5513f9b04611a41f39d467af014eb256155faa8a 100644 (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 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
index 2cc819175724f7b85e71248c6ff2210c8b6fd2b7..b756d9156ae3cfc71f5f637fd14329b0b5add937 100644 (file)
@@ -19,6 +19,7 @@
 
 SET(_all_lib_SCRIPTS
     Model.py
+    PlotModel.py
     CurveModel.py
     BarModel.py
     StemModel.py
index 56e4cb40a8abc45fed6caa4a7af2b033f2e41579..c8d7c64261ba6ec4ec7024bd0e384f1f1a2e8e8c 100644 (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 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
index 201390444170f789e795380548744f07b3ef90bb..e77132f1067c146e817247fff94bc1af24867470 100644 (file)
@@ -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 <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.
diff --git a/tools/CurvePlot/src/python/model/PlotModel.py b/tools/CurvePlot/src/python/model/PlotModel.py
new file mode 100644 (file)
index 0000000..5845a0c
--- /dev/null
@@ -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
index 6cc19c6b0bbeb7125514a02ac94f4781007d02d6..500f50890ba2e9cd15ea259890732bc6eb461254 100644 (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()
@@ -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
index a2c5377c4d8e9e5cc6cc747393929ac108ff3bcf..1e254e3a053ffeb035459310be4718f9ad37d217 100644 (file)
@@ -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
 
index 7829eefd224c540ab16af0e4d5bdde3e60c0ab05..4375a3718be6db4005c3675e6d6df4259465d321 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png and b/tools/CurvePlot/src/python/test/baselines/testDeleteCurrentItem_curve.png differ
index b184a7a928691e56da4dfa6ac3dd8d2f3f6b0f79..fb23c9754e2146f4dddc24c501292a205f84b476 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png and b/tools/CurvePlot/src/python/test/baselines/testDeleteCurve1.png differ
index 05e08a8f29deae10dfbcfe845b772254d96c87bb..fb23c9754e2146f4dddc24c501292a205f84b476 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png and b/tools/CurvePlot/src/python/test/baselines/testDeleteCurve2.png differ
index d28e7940f09f3c88f74b079e8066c3a753e2281e..d198be0e52a9348df209a06e489da014e6acf987 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testExtendCurve.png and b/tools/CurvePlot/src/python/test/baselines/testExtendCurve.png differ
index a4e767d1ed1e5262c913fe1aced00690e0b3eeb6..14b9b0c86ce87eadcf91f146240cf37920688e94 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testLockRepaint.png and b/tools/CurvePlot/src/python/test/baselines/testLockRepaint.png differ
index 779bfa5955704ec6c4053d7edbcca7ceb481d49e..b9dc0b4088696be671b2fc1daffe8435fbdc81c2 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testResetCurve.png and b/tools/CurvePlot/src/python/test/baselines/testResetCurve.png differ
index f3996514eca9b5c064ab79a438f708c8e18c0471..d954fbc8a0895ae122ae1a3db1f0a0e4fbc4e322 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png and b/tools/CurvePlot/src/python/test/baselines/testSelectedBarplot.png differ
index 333754c0b0b13ce7484e55fa56cc26b8b8874cc2..6481cd391aca39de69202dba3aa54b387720295d 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve.png differ
index 9cb0e294486d9aec792749c54a945ecf125d6af2..6481cd391aca39de69202dba3aa54b387720295d 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve2.png differ
index 9c2c290287f5f1a20e3a392f098db37595bf9290..b80ea7bd3f4301a53f9e5d3daa54304fd3c74e59 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurrentCurve3.png differ
index 816c706624d44a1d01bf374fb54d714b13a0027c..08730f9dc9b4ff0007dab8ec2e4d9b218e63f0fe 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png and b/tools/CurvePlot/src/python/test/baselines/testSetCurveMarker.png differ
index f0db9425d0573c3b36b899021717ab3ffacb8c9c..9ceb9505f2ee8f9269a57c1f42bf16f586578c7f 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png and b/tools/CurvePlot/src/python/test/baselines/testSettingsCurveColor.png differ
index fe56d56563f2639a0507595d7c9aafc00569a63c..9be32888169ea6e186023062120a03df247649f9 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png and b/tools/CurvePlot/src/python/test/baselines/testSettingsCurveMarker.png differ
index 54b91a5fe60c799a1c47f4d4b12f7163ab552fba..c6009d13386b25ce4f0a128052877ffd0052674f 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testShowAll.png and b/tools/CurvePlot/src/python/test/baselines/testShowAll.png differ
index 792d52d6b6916a1f26c79b048c1115dbacb586d5..d0673904baebd58d9c5c355c3e781da9dd39cee3 100644 (file)
Binary files a/tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png and b/tools/CurvePlot/src/python/test/baselines/testShowOnlySelected.png differ
index 9288321a8e855a2e541a1db83eb5f8bf6c512da9..8240dd9d023c84ca5fc73f21c51fd959f9e37fad 100644 (file)
@@ -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()
index 2384f716ef72c3272e077843466e4fac23212927..6bc796db6105bdaf495a2ce41b72b41d5fe909fa 100644 (file)
 # 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
index 67f359c3168ca23ada4f22bb6fabc7f41c5cfcd8..316a1d517e258dc7eed8bf48411dd24c779f4eb9 100644 (file)
@@ -21,6 +21,7 @@ SET(_all_lib_SCRIPTS
     View.py
     CurveBrowserView.py
     CurveTabsView.py
+    PlotView.py
     CurveView.py
     BarView.py
     StemView.py
index 990b6ac81999684e531972f8f6ec0cc506dd84b3..dafc9eb87f41ecdd1f3cea6e426fd537adc0def5 100644 (file)
 # 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 (file)
index 0000000..801a9ec
--- /dev/null
@@ -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
+
index 5333c7205ee77a25cdf0dc42b23306669d76d23b..dd721b5153a5479150322cd300f9b168380a0ba4 100644 (file)
 # 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
index b90dda21a237bfde7254c74b7491f0cb255e49ae..6b0bdedf29061589dce8f39dc8247d33e1616379 100644 (file)
@@ -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