1 # Copyright (C) 2016-2019 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 .View import View
21 from .utils import Logger
23 class CurveView(View):
24 _PICKER_PRECISION = 20 #pts
26 def __init__(self, controller, parentXYView):
27 View.__init__(self, controller)
30 self._isHighlighted = False
31 self._initialLineWidth = None
32 self._parentXYView = parentXYView
36 self._lineStyle = None
38 def setMPLAxes(self, axes):
42 self._mplAxes.lines.remove(self._mplLines[0])
47 x_idx, y_idx = m.getXAxisIndex(), m.getYAxisIndex()
48 d = self._model.getTable().getData()
49 self._mplLines = self._mplAxes.plot(d[:, x_idx], d[:, y_idx], label=m._title,
50 picker=self._PICKER_PRECISION)
51 self._initialLineWidth = self._mplLines[0].get_linewidth()
53 def onCurveTitleChange(self):
54 if self._mplLines is None:
56 self._mplLines[0].set_label(self._model._title)
59 Logger.Debug("CurveView::udpate")
60 if self._mplLines is None:
62 lineStyle, marker, color = self.getLineStyle(), self.getMarker(), self.getColor()
65 # Reset correctly color, marker and highlight state
66 self.setLineStyle(lineStyle)
67 self.setMarker(marker)
69 self.toggleHighlight(self._isHighlighted, force=True)
71 def setLineStyle(self, lin_style):
72 lin = self._mplLines[0]
73 lin.set_linestyle(lin_style)
75 def getLineStyle(self):
76 if self._mplLines is None:
78 return self._mplLines[0].get_linestyle()
80 def setMarker(self, marker):
81 lin = self._mplLines[0]
82 lin.set_marker(marker)
85 if self._mplLines is None:
87 return self._mplLines[0].get_marker()
89 def toggleHighlight(self, highlight, force=False):
90 lin = self._mplLines[0]
91 if highlight and (force or not self._isHighlighted):
92 lin.set_linewidth(2*self._initialLineWidth)
93 self._isHighlighted = True
94 elif not highlight and (force or self._isHighlighted):
95 lin.set_linewidth(self._initialLineWidth)
96 self._isHighlighted = False
98 # Nothing to do, already the correct state
101 def isHighlighted(self):
102 return self._isHighlighted
104 def setColor(self, rgb_color):
105 lin = self._mplLines[0]
106 lin.set_color(rgb_color)
109 if self._mplLines is None:
111 return self._mplLines[0].get_color()