Salome HOME
Merge branch 'rnv/autoconf_macros' of salome:modules/med into rnv/autoconf_macros
[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(activated(int)),
32                    this,                       SLOT(onComboCompoIndexChanged(int)) );
33   QObject::connect(_ui.comboBoxMesh,          SIGNAL(activated(int)),
34                      this,                       SLOT(onComboMeshIndexChanged(int)) );
35   QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)),
36                    this,                       SLOT(onComboScalarBarRangeIndexChanged(int)) );
37   QObject::connect(_ui.comboBoxColorMap,       SIGNAL(activated(int)),
38                    this,                       SLOT(onComboColorMapIndexChanged(int)) );
39   QObject::connect(_ui.comboBoxSliceOrient,       SIGNAL(activated(int)),
40                    this,                       SLOT(onComboOrientIndexChanged(int)) );
41   QObject::connect(_ui.spinBox,                SIGNAL(valueChanged(int)),
42                      this,                     SLOT(onSpinBoxValueChanged(int)) );
43 }
44
45 void
46 WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
47 {
48   if (!_blockSig) emit comboCompoIndexChanged(idx);
49 }
50
51 void
52 WidgetPresentationParameters::onComboOrientIndexChanged(int idx)
53 {
54   if (!_blockSig) emit comboOrientIndexChanged(idx);
55 }
56
57
58 void
59 WidgetPresentationParameters::onComboMeshIndexChanged(int idx)
60 {
61   if (!_blockSig) emit comboMeshIndexChanged(idx);
62 }
63
64 void
65 WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
66 {
67   if (!_blockSig) emit comboColorMapIndexChanged(idx);
68 }
69
70 void
71 WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
72 {
73   if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
74 }
75
76 void
77 WidgetPresentationParameters::onSpinBoxValueChanged(int val)
78 {
79   if (!_blockSig) emit spinBoxValueChanged(val);
80 }
81
82 void
83 WidgetPresentationParameters::toggleCommonFieldWidget(bool show)
84 {
85   _blockSig = true;
86   _ui.commonWidget->setEnabled(show);
87   _blockSig = false;
88 }
89
90 void
91 WidgetPresentationParameters::toggleWidget(bool show)
92 {
93   toggleCommonFieldWidget(true);
94   if (!show)
95     {
96       _blockSig = true;
97       _ui.widgetDynamic->hide();
98       setPresName(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
99       // reset colorMap and scalarBarRange:
100       setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
101       setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
102     }
103   else
104     {
105       _ui.widgetDynamic->show();
106       // It is the WidgetHelper responsability to re-show the widgets it needs
107       _ui.labelCompo->hide();
108       _ui.comboBoxCompo->hide();
109       _ui.labelMeshMode->hide();
110       _ui.comboBoxMesh->hide();
111       _ui.labelSpinBox->hide();
112       _ui.spinBox->hide();
113       _ui.labelSliceOrient->hide();
114       _ui.comboBoxSliceOrient->hide();
115       _blockSig = false;
116     }
117 }
118
119 bool
120 WidgetPresentationParameters::isShown() const
121 {
122   return _ui.widgetDynamic->isVisible();
123 }
124
125 string
126 WidgetPresentationParameters::getComponent() const
127 {
128   if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
129       return "";
130
131   return _ui.comboBoxCompo->currentText().toStdString();
132 }
133
134 void
135 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
136 {
137   _blockSig = true;
138
139   // Show the widget:
140   _ui.labelCompo->show();
141   _ui.comboBoxCompo->show();
142
143   _ui.comboBoxCompo->clear();
144   _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
145   for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
146     _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
147   _ui.comboBoxCompo->setCurrentIndex(selecIndex);
148
149   _blockSig = false;
150 }
151
152 void
153 WidgetPresentationParameters::setNbContour(int nbContour)
154 {
155   _blockSig = true;
156
157   if (nbContour <= 0)
158     {
159       //TODO throw?
160       STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
161     }
162
163   // Show the widget:
164   _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS"));
165   _ui.labelSpinBox->show();
166   _ui.spinBox->show();
167   _ui.spinBox->setValue(nbContour);
168
169   _blockSig = false;
170 }
171
172 void
173 WidgetPresentationParameters::setNbSlices(int nbSlices)
174 {
175   _blockSig = true;
176
177   if (nbSlices <= 0)
178     {
179       //TODO throw?
180       STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
181     }
182
183   // Show the widget:
184   _ui.labelSpinBox->setText(tr("LAB_NB_SLICES"));
185   _ui.labelSpinBox->show();
186   _ui.spinBox->show();
187   _ui.spinBox->setValue(nbSlices);
188
189   _blockSig = false;
190 }
191
192 int WidgetPresentationParameters::getNbContour() const
193 {
194   return _ui.spinBox->value();
195 }
196
197 int WidgetPresentationParameters::getNbSlices() const
198 {
199   return _ui.spinBox->value();
200 }
201
202
203 void
204 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
205 {
206   _blockSig = true;
207
208   int idx;
209   if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
210     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
211   else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
212     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
213
214   if (idx >= 0)
215       _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
216   else
217     STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
218
219   _blockSig = false;
220 }
221
222 void
223 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
224 {
225   _blockSig = true;
226
227   int idx = -1;
228   if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
229     idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
230   else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
231     idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
232
233   if (idx >= 0)
234       _ui.comboBoxColorMap->setCurrentIndex(idx);
235   else
236     STDLOG("Strange!! No matching found - unable to set color map in GUI.");
237
238   _blockSig = false;
239 }
240
241 void
242 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
243 {
244   _blockSig = true;
245
246   // Show the widget:
247   _ui.labelMeshMode->show();
248   _ui.comboBoxMesh->show();
249
250   int idx;
251   switch(mode)
252   {
253     case MEDCALC::MESH_MODE_WIREFRAME:
254       idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
255       break;
256     case MEDCALC::MESH_MODE_SURFACE:
257       idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
258       break;
259     case MEDCALC::MESH_MODE_SURFACE_EDGES:
260       idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
261       break;
262     default:
263       idx = -1;
264   }
265   if (idx >= 0)
266       _ui.comboBoxMesh->setCurrentIndex(idx);
267   else
268     STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
269
270   _blockSig = false;
271 }
272
273 void
274 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
275 {
276   _blockSig = true;
277
278   // Show the widget:
279   _ui.labelSliceOrient->show();
280   _ui.comboBoxSliceOrient->show();
281
282   int idx;
283   switch(orient)
284   {
285     case MEDCALC::SLICE_NORMAL_TO_X:
286       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
287       break;
288     case MEDCALC::SLICE_NORMAL_TO_Y:
289       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
290       break;
291     case MEDCALC::SLICE_NORMAL_TO_Z:
292       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
293       break;
294     case MEDCALC::SLICE_NORMAL_TO_XY:
295       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
296       break;
297     case MEDCALC::SLICE_NORMAL_TO_XZ:
298       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
299       break;
300     case MEDCALC::SLICE_NORMAL_TO_YZ:
301       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
302       break;
303     case MEDCALC::SLICE_NORMAL_TO_XYZ:
304       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
305       break;
306     default:
307       idx = -1;
308   }
309   if (idx >= 0)
310     _ui.comboBoxSliceOrient->setCurrentIndex(idx);
311   else
312     STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
313
314   _blockSig = false;
315 }
316
317
318 MEDCALC::SliceOrientationType
319 WidgetPresentationParameters::getSliceOrientation() const
320 {
321   QString sbrange = _ui.comboBoxSliceOrient->currentText();
322   if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
323       return MEDCALC::SLICE_NORMAL_TO_X;
324   }
325   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
326       return MEDCALC::SLICE_NORMAL_TO_Y;
327   }
328   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
329       return MEDCALC::SLICE_NORMAL_TO_Z;
330   }
331   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
332       return MEDCALC::SLICE_NORMAL_TO_XY;
333   }
334   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
335       return MEDCALC::SLICE_NORMAL_TO_XZ;
336   }
337   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
338       return MEDCALC::SLICE_NORMAL_TO_YZ;
339   }
340   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
341       return MEDCALC::SLICE_NORMAL_TO_XYZ;
342   }
343   // Should not happen
344   STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
345   return MEDCALC::SLICE_NORMAL_TO_X;
346 }
347
348 MEDCALC::MeshModeType
349 WidgetPresentationParameters::getMeshMode() const
350 {
351   QString mesm = _ui.comboBoxMesh->currentText();
352   if (mesm == tr("LAB_MESH_WIREFRAME")) {
353       return MEDCALC::MESH_MODE_WIREFRAME;
354   }
355   else if (mesm == tr("LAB_MESH_SURFACE")) {
356       return MEDCALC::MESH_MODE_SURFACE;
357   }
358   else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
359       return MEDCALC::MESH_MODE_SURFACE_EDGES;
360   }
361   // Should not happen
362   STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
363   return MEDCALC::MESH_MODE_WIREFRAME;
364 }
365
366
367 MEDCALC::ScalarBarRangeType
368 WidgetPresentationParameters::getScalarBarRange() const
369 {
370   QString sbrange = _ui.comboBoxScalarBarRange->currentText();
371   if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
372     return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
373   }
374   else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
375     return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
376   }
377   // Should not happen
378   STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
379   return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
380 }
381
382 //double
383 //WidgetPresentationParameters::getScalarBarTimestep() const
384 //{
385 //  return _ui.doubleSpinBoxTimeStep->value();
386 //}
387 //
388 //double
389 //WidgetPresentationParameters::getScalarBarMinVal() const
390 //{
391 //  return _ui.doubleSpinBoxMinVal->value();
392 //}
393 //
394 //double
395 //WidgetPresentationParameters::getScalarBarMaxVal() const
396 //{
397 //  return _ui.doubleSpinBoxMaxVal->value();
398 //}
399
400 MEDCALC::ColorMapType
401 WidgetPresentationParameters::getColorMap() const
402 {
403   QString colorMap = _ui.comboBoxColorMap->currentText();
404   if (colorMap == tr("LAB_BLUE_TO_RED")) {
405     return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
406   }
407   else if (colorMap == tr("LAB_COOL_TO_WARM")) {
408     return MEDCALC::COLOR_MAP_COOL_TO_WARM;
409   }
410   // Should not happen
411   STDLOG("Strange!! No matching color map found - returning blue to red.");
412   return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
413 }
414
415 void
416 WidgetPresentationParameters::setPresName(const std::string& name)
417 {
418   _ui.labelPresName->setText(QString::fromStdString(name));
419   QFont f(_ui.labelPresName->font());
420   f.setItalic(true);
421   _ui.labelPresName->setFont(f);
422 }