Salome HOME
updated copyright message
[modules/gui.git] / tools / CurvePlot / src / python / ui / PlotSettings.py
1 # Copyright (C) 2016-2023  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 pyqtside.QtWidgets import QDialog, QColorDialog, QMessageBox
21 from pyqtside.QtGui import QIcon, QPixmap, QColor
22 from pyqtside.QtCore import pyqtSlot
23 from pyqtside.uic import loadUiGen
24 from .utils import completeResPath, Logger
25
26 class PlotSettings(QDialog):
27   def __init__(self):
28     QDialog.__init__(self)
29     loadUiGen(completeResPath("PlotSettings.ui"), self)
30     self.initialize()
31
32   def initialize(self):
33     self.legendPositionComboBox.addItem("Bottom")
34     self.legendPositionComboBox.addItem("Right")
35     self._r = 0
36     self._g = 0
37     self._b = 1
38
39   @pyqtSlot(int)
40   def onShowLegend(self, index):
41     if index > 0 :
42       self.legendPositionComboBox.setEnabled(True)
43     else :
44       self.legendPositionComboBox.setEnabled(False)
45
46   @pyqtSlot()
47   def onChangeColor(self):
48     col = QColorDialog.getColor()
49
50     if col.isValid():
51       r, g, b = [c/255.0 for c in col.getRgb()[:3]]
52       self.setRGB(r, g, b)
53
54   def setSelectedCurveName(self, name):
55     self.nameCurve.setText(name)
56     if name :
57       Logger.Debug("show curve panel")
58       self.selectedCurvePanel.setTitle("Selected curve : " + name)
59       self.selectedCurvePanel.show()
60     else :
61       Logger.Debug("hide curve panel")
62       self.selectedCurvePanel.hide()
63
64   def setRGB(self, r, g, b):
65     self._r = r
66     self._g = g
67     self._b = b
68     self.colorCurve.setIcon(QIcon(self.drawColorPixmap(int(r*255), int(g*255), int(b*255))))
69
70   def getRGB(self):
71     return self._r, self._g, self._b
72
73   def drawColorPixmap(self, r, g, b):
74     pix = QPixmap( 16, 16 )
75     color = QColor(r, g, b)
76     pix.fill(color)
77     return pix
78
79   def accept(self):
80     xminText = str(self.axisXMinEdit.text())
81     xmaxText = str(self.axisXMaxEdit.text())
82     yminText = str(self.axisYMinEdit.text())
83     ymaxText = str(self.axisYMaxEdit.text())
84     if (yminText == "" or ymaxText == "") :
85       QMessageBox.critical(self, "Plot settings", "A field \"YMin\" or \"YMax\" is empty")
86     else :
87       try:
88         xmin = float(xminText)
89       except ValueError:
90         QMessageBox.critical(self, "Plot settings", "It is not possible to convert XMin")
91       try:
92         xmax = float(xmaxText)
93       except ValueError:
94         QMessageBox.critical(self, "Plot settings", "It is not possible to convert XMax")
95       try:
96         ymin = float(yminText)
97       except ValueError:
98         QMessageBox.critical(self, "Plot settings", "It is not possible to convert YMin")
99       try:
100         ymax = float(ymaxText)
101       except ValueError:
102         QMessageBox.critical(self, "Plot settings", "It is not possible to convert YMax")
103       if ((xmax-xmin) == 0) :
104         QMessageBox.critical(self, "Plot settings", "XMax is is equal to XMin.")
105         return
106       if ((ymax-ymin) == 0) :
107         QMessageBox.critical(self, "Plot settings", "YMax is is equal to YMin.")
108         return
109       if ((xmax-xmin) < 0) :
110         QMessageBox.warning(self, "Plot settings", "XMax is less than XMin.")
111       if ((ymax-ymin) < 0) :
112         QMessageBox.warning(self, "Plot settings", "YMax is less than YMin.")
113       super(PlotSettings, self).accept()