Salome HOME
068cc4ecf30cce90695f6cc1c05c88c47485641c
[modules/gui.git] / tools / CurvePlot / src / python / model / XYPlotSetModel.py
1 # Copyright (C) 2016-2023  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from .Model import Model
21 from .utils import toUnicodeWithWarning
22
23 class XYPlotSetModel(Model):
24   
25   def __init__(self, controller):
26     Model.__init__(self, controller)
27     self._title = "Plot set %d" % self.getID()
28     self._curves = {}  # Key: model ID, value: CurveModel
29     self._currentCurve = None
30     self._xlabel = ""
31     self._ylabel = ""
32     
33   def eraseAll(self):
34     self._curves = {}
35     self._currentCurve = None
36     self.notifyChange("ClearAll")
37     
38   def setTitle(self, title, silent=False):
39     title = toUnicodeWithWarning(title, "XYPlotSetModel::setTitle()")
40     self._title = title
41     if not silent:
42       self.notifyChange("TitleChange")
43       
44   def getTitle(self):
45     return self._title
46       
47   def setCurrentCurve(self, curveID, silent=False):
48     if curveID not in self._curves and curveID != -1:
49       raise ValueError("Invalid curve ID (%d)!" % curveID)
50     self._currentCurve = self._curves.get(curveID, None)
51     if not silent:
52       self.notifyChange("CurrentCurveChange") 
53
54   def getCurrentCurve(self):
55     return self._currentCurve
56       
57   def addCurve(self, curve, silent=False):
58     self._curves[curve.getID()] = curve
59     if not silent:
60       self.notifyChange("AddCurve")
61   
62   def removeCurve(self, curveID, silent=False):
63     if curveID not in self._curves:
64       raise ValueError("Curve ID (%d) not found for deletion!" % curveID)
65     c = self._curves.pop(curveID)
66     if self._currentCurve is c:
67       self._currentCurve = None
68     if not silent:
69       self.notifyChange("RemoveCurve")
70     
71   def setXLabel(self, x_label, silent=False):
72     x_label = toUnicodeWithWarning(x_label, "XYPlotSetModel::setXLabel()")
73     self._xlabel = x_label
74     if not silent:
75       self.notifyChange("XLabelChange")
76   
77   def setYLabel(self, y_label, silent=False):
78     y_label = toUnicodeWithWarning(y_label, "XYPlotSetModel::setYLabel()")
79     self._ylabel = y_label
80     if not silent:
81       self.notifyChange("YLabelChange")
82