Salome HOME
[MEDCalc] Fully functional scalar map (other pres deactivated)
[modules/med.git] / src / MEDCalc / gui / dialogs / WidgetPresentationParameters.cxx
1 // Copyright (C) 2016  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 #include "WidgetPresentationParameters.hxx"
21 #include <Basics_Utils.hxx>
22
23 using namespace std;
24
25 WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
26   : QWidget(parent), _blockSig(false)
27 {
28   _ui.setupUi(this); // To be done first
29
30   toggleWidget(false);
31   QObject::connect(_ui.comboBoxCompo,          SIGNAL(currentIndexChanged(int)),
32                    this,                       SLOT(onComboCompoIndexChanged(int)) );
33   QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(currentIndexChanged(int)),
34                    this,                       SLOT(onComboScalarBarRangeIndexChanged(int)) );
35   QObject::connect(_ui.comboBoxColorMap,       SIGNAL(currentIndexChanged(int)),
36                    this,                       SLOT(onComboColorMapIndexChanged(int)) );
37 }
38
39 void
40 WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
41 {
42   if (!_blockSig) emit comboCompoIndexChanged(idx);
43 }
44
45 void
46 WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
47 {
48   if (!_blockSig) emit comboColorMapIndexChanged(idx);
49 }
50
51 void
52 WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
53 {
54   if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
55 }
56
57
58 void
59 WidgetPresentationParameters::toggleWidget(bool show)
60 {
61   if (!show)
62     {
63       _blockSig = true;
64       _ui.widgetDynamic->hide();
65       setPresName("Choose a presentation");
66       // reset colorMap and scalarBarRange:
67       setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
68       setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
69     }
70   else
71     {
72       _ui.widgetDynamic->show();
73       // It is the WidgetHelper responsability to re-show the widgets it needs
74       _ui.labelCompo->hide();
75       _ui.comboBoxCompo->hide();
76       _ui.labelSpinBox->hide();
77       _ui.spinBox->hide();
78       _ui.labelSliceOrient->hide();
79       _ui.comboBoxSliceOrient->hide();
80       _blockSig = false;
81     }
82 }
83
84 bool
85 WidgetPresentationParameters::isShown() const
86 {
87   return _ui.widgetDynamic->isVisible();
88 }
89
90 string
91 WidgetPresentationParameters::getComponent() const
92 {
93   if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
94       return "";
95
96   return _ui.comboBoxCompo->currentText().toStdString();
97 }
98
99 void
100 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
101 {
102   // Show the widget:
103   _ui.labelCompo->show();
104   _ui.comboBoxCompo->show();
105
106   _blockSig = true;
107   _ui.comboBoxCompo->clear();
108   _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
109   for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
110     _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
111   _ui.comboBoxCompo->setCurrentIndex(selecIndex);
112   _blockSig = false;
113 }
114
115 void
116 WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange)
117 {
118   int idx;
119   if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
120     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
121   else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
122     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
123
124   if (idx >= 0)
125     {
126       _blockSig = true;
127       _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
128       _blockSig = false;
129     }
130   else
131     STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
132 }
133
134 void
135 WidgetPresentationParameters::setColorMap(MEDCALC::MEDPresentationColorMap colorMap)
136 {
137   int idx;
138   if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
139     idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
140   else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
141     idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
142
143   if (idx >= 0)
144     {
145       _blockSig = true;
146       _ui.comboBoxColorMap->setCurrentIndex(idx);
147       _blockSig = false;
148     }
149
150   else
151     STDLOG("Strange!! No matching found - unable to set color map in GUI.");
152 }
153
154
155 MEDCALC::MEDPresentationScalarBarRange
156 WidgetPresentationParameters::getScalarBarRange() const
157 {
158   QString sbrange = _ui.comboBoxScalarBarRange->currentText();
159   if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
160     return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
161   }
162   else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
163     return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
164   }
165   // Should not happen
166   STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
167   return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
168 }
169
170 //double
171 //WidgetPresentationParameters::getScalarBarTimestep() const
172 //{
173 //  return _ui.doubleSpinBoxTimeStep->value();
174 //}
175 //
176 //double
177 //WidgetPresentationParameters::getScalarBarMinVal() const
178 //{
179 //  return _ui.doubleSpinBoxMinVal->value();
180 //}
181 //
182 //double
183 //WidgetPresentationParameters::getScalarBarMaxVal() const
184 //{
185 //  return _ui.doubleSpinBoxMaxVal->value();
186 //}
187
188 MEDCALC::MEDPresentationColorMap
189 WidgetPresentationParameters::getColorMap() const
190 {
191   QString colorMap = _ui.comboBoxColorMap->currentText();
192   if (colorMap == tr("LAB_BLUE_TO_RED")) {
193     return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
194   }
195   else if (colorMap == tr("LAB_COOL_TO_WARM")) {
196     return MEDCALC::COLOR_MAP_COOL_TO_WARM;
197   }
198   // Should not happen
199   STDLOG("Strange!! No matching color map found - returning blue to red.");
200   return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
201 }
202
203 QComboBox *
204 WidgetPresentationParameters::getComboBoxCompo()
205 {
206   return _ui.comboBoxCompo;
207 }
208
209 void
210 WidgetPresentationParameters::setPresName(const std::string& name)
211 {
212   _ui.labelPresName->setText(QString::fromStdString(name));
213   QFont f(_ui.labelPresName->font());
214   f.setItalic(true);
215   _ui.labelPresName->setFont(f);
216 }