Salome HOME
Merge branch 'V9_9_BR'
[modules/gui.git] / tools / CurvePlot / src / python / model / CurveModel.py
1 # Copyright (C) 2016-2022  CEA/DEN, EDF R&D
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 CurveModel(Model):  
24   def __init__(self, controller, table=None, index=-1):
25     Model.__init__(self, controller)
26     self._title = "Curve %d" % self.getID()
27     self._table = table
28     self._yaxisIndex = index   # column index in the table
29     self._xaxisIndex = 0  # By default the first column of the table is used for the X-s
30     
31   def clone(self):
32     ret = CurveModel(self._controller)
33     ret._title = self._title
34     ret._table = self._table  # TO CHECK: deep copy here? (I think not needed in Python ...)
35     ret._yaxisIndex = self._yaxisIndex
36     ret._xaxisIndex = self._xaxisIndex
37     return ret
38     
39   def setTable(self, t, silent=False):
40     self._table = t
41     if not silent:
42       self.notifyChange("DataChange") 
43     
44   def getTable(self):
45     return self._table
46     
47   def extendData(self, t, silent=False):
48     self._table.extend(t)
49     if not silent:
50       self.notifyChange("DataChange")
51     
52   def resetData(self):
53     self._table.clear()
54     self.notifyChange("DataChange")
55     
56   def setTitle(self, ti, silent=False):
57     ti = toUnicodeWithWarning(ti, "CurveModel::setTitle()")
58     self._title = ti
59     if not silent:
60       self.notifyChange("CurveTitleChange") 
61     
62   def getTitle(self):
63     return self._title
64     
65   def getYAxisIndex(self):
66     return self._yaxisIndex
67   
68   def setYAxisIndex(self, idx, silent=False):
69     self._yaxisIndex = idx
70     if not silent:
71       self.notifyChange("YAxisIndexChange")
72   
73   def getXAxisIndex(self):
74     return self._xaxisIndex
75   
76   def setXAxisIndex(self, idx, silent=False):
77     sh = self._table.getShape()
78     if idx >= sh[1]:
79       raise ValueError("Index out of bound (is %d, but max is %d)" % (idx, sh[1]))
80     self._xaxisIndex = idx
81     if not silent:
82       self.notifyChange("XAxisIndexChange")
83     
84   def getID(self):
85     return self._id
86   
87