1 # Copyright (C) 2016-2021 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from .Model import Model
21 from .XYPlotSetModel import XYPlotSetModel
22 from .utils import Logger
24 class PlotManager(Model):
25 def __init__(self, controller):
26 from collections import OrderedDict
27 Model.__init__(self, controller)
28 self._currentPlotSet = None
29 self._plotSets = OrderedDict() # key: plotSet ID, value: instance of XYPlotSetModel. We use an OrderedDict so that
30 # when removing elemetns, we can easily re-select the last-but-one.
31 self._lockRepaint = False # if True, repaint routines are blocked.
32 self._plotSetsRepaint = set() # plot waiting for repaint/update while repaint is locked
35 return len(self._plotSets) == 0
37 def setCurrentPlotSet(self, plotSetID, silent=False):
38 if plotSetID not in self._plotSets and plotSetID != -1:
39 raise ValueError("Invalid plot set ID (%d)!" % plotSetID)
40 self._currentPlotSet = self._plotSets.get(plotSetID, None)
42 self.notifyChange("CurrentPlotSetChange")
44 def getCurrentPlotSet(self):
45 return self._currentPlotSet
47 def getPlotSetContainingCurve(self, curveID):
48 for ps in list(self._plotSets.values()):
49 if curveID in ps._curves:
53 def setCurrentCurve(self, curveId):
54 ps = self.getPlotSetContainingCurve(curveId)
55 if ps is None and curveId != -1:
56 raise ValueError("Invalid curve ID (%d)!" % curveId)
57 self.clearAllCurrentCurve()
61 currPs = self.getCurrentPlotSet()
62 if currPs is None or currPs.getID() != ps_id:
63 self.setCurrentPlotSet(ps_id)
64 ps.setCurrentCurve(curveId)
67 def getCurrentCurve(self):
68 ps = self.getCurrentPlotSet()
71 return ps.getCurrentCurve()
73 def clearAllCurrentCurve(self, silent=False):
74 for psID in self._plotSets:
75 self._plotSets[psID].setCurrentCurve(-1)
77 self.notifyChange("CurrentCurveChange")
79 def createXYPlotSet(self, silent=False):
80 cv = XYPlotSetModel(self._controller)
81 self._plotSets[cv.getID()] = cv
82 self._currentPlotSet = cv
84 self.notifyChange("NewPlotSet")
87 def removeXYPlotSet(self, plotSetID):
88 Logger.Debug("====> PlotManager::removeXYPlotSet() %d" % plotSetID)
89 if plotSetID not in self._plotSets:
91 raise ValueError("Plot set ID (%d) not found for deletion!" % plotSetID)
92 ps = self._plotSets.pop(plotSetID)
93 if self._currentPlotSet is ps:
94 self._currentPlotSet = None
95 self.notifyChange("RemovePlotSet")
100 self._currentPlotSet = None
101 self.notifyChange("ClearAll")
103 def lockRepaint(self):
104 self._lockRepaint = True
105 self._plotSetsRepaint = set()
107 def isRepaintLocked(self):
108 return self._lockRepaint
110 def registerRepaint(self, ps_id):
111 self._plotSetsRepaint.add(ps_id)
113 def unlockRepaint(self):
114 self._lockRepaint = False
115 for obj in self._plotSetsRepaint:
117 self._plotSetsRepaint = set()