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