Salome HOME
bos #28928: Merge branch 'rnv/28928'
[modules/med.git] / src / MEDCalc / gui / dialogs / WidgetPresentationParameters.cxx
1 // Copyright (C) 2016-2021  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 #ifdef WIN32
21 #define NOMINMAX
22 #endif
23
24 #include "WidgetPresentationParameters.hxx"
25 #include <Basics_Utils.hxx>
26
27 #include <limits>
28
29 using namespace std;
30
31 WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
32   : QWidget(parent), _blockSig(false)
33 {
34   _ui.setupUi(this); // To be done first
35
36   toggleWidget(false);
37   QObject::connect(_ui.comboBoxCompo,          SIGNAL(activated(int)),
38                    this,                       SLOT(onComboCompoIndexChanged(int)) );
39   QObject::connect(_ui.comboBoxMesh,           SIGNAL(activated(int)),
40                      this,                     SLOT(onComboMeshIndexChanged(int)) );
41   QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)),
42                    this,                       SLOT(onComboScalarBarRangeIndexChanged(int)) );
43   QObject::connect(_ui.comboBoxColorMap,       SIGNAL(activated(int)),
44                    this,                       SLOT(onComboColorMapIndexChanged(int)) );
45   QObject::connect(_ui.comboBoxSliceOrient,    SIGNAL(activated(int)),
46                    this,                       SLOT(onComboOrientIndexChanged(int)) );
47   QObject::connect(_ui.comboBoxIntegrDir,      SIGNAL(activated(int)),
48                    this,                       SLOT(onComboIntegrDirIndexChanged(int)) );
49   QObject::connect(_ui.comboBoxContComp,       SIGNAL(activated(int)),
50                    this,                       SLOT(onComboContCompIndexChanged(int)) );
51   QObject::connect(_ui.spinBox,                SIGNAL(editingFinished()),
52                      this,                     SLOT(onSpinBoxEditingFinished()) );
53   QObject::connect(_ui.checkBoxShowScalarBar,  SIGNAL(stateChanged(int)),
54                      this,                     SLOT(onCheckboxScalarBarVisibilityChanged(int)));
55   QObject::connect(_ui.checkBoxCustomRange,    SIGNAL(stateChanged(int)),
56                      this,                     SLOT(onCheckboxCustomRangeChanged(int)));
57   QObject::connect(_ui.checkBoxScaleFactor,    SIGNAL(stateChanged(int)),
58                      this,                     SLOT(onCheckboxScaleFactorChanged(int)));
59   QObject::connect(_ui.checkBoxScaleFactor,    SIGNAL(stateChanged(int)),
60                      this,                     SLOT(onCheckboxCustomScaleFactorChanged(int)));
61   QObject::connect(_ui.spinCustomRangeMin,     SIGNAL(editingFinished()),
62                      this,                     SLOT(onSpinboxCustomRangeChanged()));
63   QObject::connect(_ui.spinCustomRangeMax,     SIGNAL(editingFinished()),
64                      this,                     SLOT(onSpinboxCustomRangeChanged()));
65   QObject::connect(_ui.spinScaleFactor,        SIGNAL(editingFinished()),
66                      this,                     SLOT(onSpinboxScaleFactorChanged()));
67   QObject::connect(_ui.checkBoxHideDataOutsideCR, SIGNAL(stateChanged(int)),
68                      this,                        SLOT(onCheckboxHideDataOutsideCustomRangeChanged(int)));
69   // sphinx doc: begin of normal and plane connections
70   QObject::connect(_ui.spinNormalX,            SIGNAL(editingFinished()),
71                      this,                     SLOT(onSpinNormalEditingFinished()) );
72   QObject::connect(_ui.spinNormalY,            SIGNAL(editingFinished()),
73                      this,                     SLOT(onSpinNormalEditingFinished()) );
74   QObject::connect(_ui.spinNormalZ,            SIGNAL(editingFinished()),
75                      this,                     SLOT(onSpinNormalEditingFinished()) );
76   QObject::connect(_ui.spinPlanePos,           SIGNAL(editingFinished()),
77                      this,                     SLOT(onSpinPlanePosEditingFinished()) );
78   // sphinx doc: end of normal and plane connections
79   QObject::connect(_ui.spinPoint1_X,           SIGNAL(editingFinished()),
80                      this,                     SLOT(onSpinCutPoint1EditingFinished()) );
81   QObject::connect(_ui.spinPoint1_Y,           SIGNAL(editingFinished()),
82                      this,                     SLOT(onSpinCutPoint1EditingFinished()) );
83   QObject::connect(_ui.spinPoint1_Z,           SIGNAL(editingFinished()),
84                      this,                     SLOT(onSpinCutPoint1EditingFinished()) );
85   QObject::connect(_ui.spinPoint2_X,           SIGNAL(editingFinished()),
86                      this,                     SLOT(onSpinCutPoint2EditingFinished()) );
87   QObject::connect(_ui.spinPoint2_Y,           SIGNAL(editingFinished()),
88                      this,                     SLOT(onSpinCutPoint2EditingFinished()) );
89   QObject::connect(_ui.spinPoint2_Z,           SIGNAL(editingFinished()),
90                      this,                     SLOT(onSpinCutPoint2EditingFinished()) );
91
92    // Disable Custom Range Spin boxes
93   _ui.spinCustomRangeMax->setEnabled(false);
94   _ui.spinCustomRangeMin->setEnabled(false);
95   _ui.spinScaleFactor->setEnabled(false);
96   _ui.checkBoxHideDataOutsideCR->setEnabled(false);
97
98   // Min and max values
99   _ui.spinCustomRangeMin->setRange(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max());
100   _ui.spinCustomRangeMax->setRange(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max());
101   
102   _ui.spinCustomRangeMin->setDecimals(6);
103   _ui.spinCustomRangeMax->setDecimals(6);
104   
105   _ui.spinNormalX->setRange(0.0, 1.0);
106   _ui.spinNormalY->setRange(0.0, 1.0);
107   _ui.spinNormalZ->setRange(0.0, 1.0);
108   _ui.spinPlanePos->setRange(0.0, 1.0);
109 }
110
111 // for sphinx doc: start of onComboCompoIndexChanged
112 void
113 WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
114 {
115   if (!_blockSig) emit comboCompoIndexChanged(idx);
116 }
117 // for sphinx doc: end of onComboCompoIndexChanged
118
119 void
120 WidgetPresentationParameters::onComboOrientIndexChanged(int idx)
121 {
122   if (!_blockSig) emit comboOrientIndexChanged(idx);
123 }
124
125
126 void
127 WidgetPresentationParameters::onComboMeshIndexChanged(int idx)
128 {
129   if (!_blockSig) emit comboMeshIndexChanged(idx);
130 }
131
132 void
133 WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
134 {
135   if (!_blockSig) emit comboColorMapIndexChanged(idx);
136 }
137
138 void
139 WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
140 {
141   if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
142 }
143
144 void
145 WidgetPresentationParameters::onComboIntegrDirIndexChanged(int idx)
146 {
147   if (!_blockSig) emit comboIntegrDirIndexChanged(idx);
148 }
149
150 void
151 WidgetPresentationParameters::onComboContCompIndexChanged(int idx)
152 {
153   if (!_blockSig) emit comboContCompIndexChanged(idx);
154 }
155
156 void
157 WidgetPresentationParameters::onCheckboxScalarBarVisibilityChanged(int flag)
158 {
159   if (!_blockSig) emit checkboxScalarBarVisibilityChanged(flag);
160 }
161
162 void
163 WidgetPresentationParameters::onCheckboxCustomRangeChanged(int flag)
164 {
165   _ui.spinCustomRangeMin->setEnabled(flag);
166   _ui.spinCustomRangeMax->setEnabled(flag);
167   _ui.checkBoxHideDataOutsideCR->setEnabled(flag);
168   _ui.comboBoxScalarBarRange->setEnabled(!flag);
169   if (!_blockSig) emit checkboxCustomRangeChanged(flag);
170 }
171
172 void
173 WidgetPresentationParameters::onCheckboxScaleFactorChanged(int flag)
174 {
175   _ui.spinScaleFactor->setEnabled(flag);
176   if (!_blockSig) emit checkboxScaleFactorChanged(flag);
177 }
178
179 void
180 WidgetPresentationParameters::onSpinboxCustomRangeChanged()
181 {
182   if (!_blockSig) emit spinboxCustomRangeChanged(_ui.spinCustomRangeMin->value(),
183                                                  _ui.spinCustomRangeMax->value());
184 }
185
186 void
187 WidgetPresentationParameters::onSpinboxScaleFactorChanged()
188 {
189   if (!_blockSig) emit spinboxScaleFactorChaged(_ui.spinScaleFactor->value());
190 }
191
192 void
193 WidgetPresentationParameters::
194 onCheckboxHideDataOutsideCustomRangeChanged(int flag)
195 {
196   if (!_blockSig) emit checkboxHideDataOutsideCustomRangeChanged(flag);
197 }
198
199 void
200 WidgetPresentationParameters::
201 onCheckboxCustomScaleFactorChanged(int flag) {
202   if (!_blockSig) emit checkboxCustomScaleFactorChanged(flag);
203 }
204
205 void
206 WidgetPresentationParameters::onSpinBoxEditingFinished()
207 {
208   if (!_blockSig) emit spinBoxValueChanged(_ui.spinBox->value());
209 }
210
211 void
212 WidgetPresentationParameters::onSpinNormalEditingFinished()
213 {
214   if (!_blockSig) emit spinNormalValuesChanged(_ui.spinNormalX->value(),
215                                                _ui.spinNormalY->value(),
216                                                _ui.spinNormalZ->value());
217 }
218
219 void
220 WidgetPresentationParameters::onSpinCutPoint1EditingFinished()
221 {
222   if (!_blockSig) emit spinCutPoint1ValuesChanged(_ui.spinPoint1_X->value(),
223                                                   _ui.spinPoint1_Y->value(),
224                                                   _ui.spinPoint1_Z->value());
225 }
226
227 void
228 WidgetPresentationParameters::onSpinCutPoint2EditingFinished()
229 {
230   if (!_blockSig) emit spinCutPoint2ValuesChanged(_ui.spinPoint2_X->value(),
231                                                   _ui.spinPoint2_Y->value(),
232                                                   _ui.spinPoint2_Z->value());
233 }
234
235 void
236 WidgetPresentationParameters::onSpinPlanePosEditingFinished()
237 {
238   if (!_blockSig) emit spinPlanePosValueChanged(_ui.spinPlanePos->value());
239 }
240
241 void
242 WidgetPresentationParameters::hidePlot3D()
243 {
244   _ui.labelCutPlanePosition->hide();
245   _ui.spinPlanePos->hide();
246 }
247
248 void
249 WidgetPresentationParameters::hideContourComponent()
250 {
251   _ui.labelContourComp->hide();
252   _ui.comboBoxContComp->hide();
253 }
254
255 void
256 WidgetPresentationParameters::toggleCommonFieldWidget(bool show)
257 {
258   _blockSig = true;
259   _ui.commonWidget->setEnabled(show);
260   _blockSig = false;
261 }
262
263 void
264 WidgetPresentationParameters::toggleWidget(bool show)
265 {
266   toggleCommonFieldWidget(true);
267   if (!show)
268     {
269       _blockSig = true;
270       _ui.widgetDynamic->hide();
271       setPresName(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
272       // reset colorMap and scalarBarRange:
273       setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
274       setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
275     }
276   else
277     {
278       _ui.widgetDynamic->show();
279       // It is the WidgetHelper responsibility to re-show the widgets it needs
280       _ui.labelCompo->hide();
281       _ui.comboBoxCompo->hide();
282       _ui.labelMeshMode->hide();
283       _ui.comboBoxMesh->hide();
284       _ui.labelSpinBox->hide();
285       _ui.spinBox->hide();
286       _ui.labelSliceOrient->hide();
287       _ui.comboBoxSliceOrient->hide();
288       _ui.labelCutPlaneNormal->hide();
289       _ui.labelCutPlanePosition->hide();
290       _ui.spinNormalX->hide();
291       _ui.spinNormalY->hide();
292       _ui.spinNormalZ->hide();
293       _ui.spinPlanePos->hide();
294       _ui.labelIntegrDir->hide();
295       _ui.comboBoxIntegrDir->hide();
296       _ui.labelPoint1->hide();
297       _ui.spinPoint1_X->hide();
298       _ui.spinPoint1_Y->hide();
299       _ui.spinPoint1_Z->hide();
300       _ui.labelPoint2->hide();
301       _ui.spinPoint2_X->hide();
302       _ui.spinPoint2_Y->hide();
303       _ui.spinPoint2_Z->hide();
304       _ui.labelContourComp->hide();
305       _ui.comboBoxContComp->hide();
306       _ui.checkBoxScaleFactor->hide();
307       _ui.spinScaleFactor->hide();
308       _blockSig = false;
309     }
310 }
311
312 bool
313 WidgetPresentationParameters::isShown() const
314 {
315   return _ui.widgetDynamic->isVisible();
316 }
317
318 string
319 WidgetPresentationParameters::getComponent() const
320 {
321   if (_ui.comboBoxCompo->count() > 1 && _ui.comboBoxCompo->count() <= 4)
322     if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
323       return "";
324
325   return _ui.comboBoxCompo->currentText().toStdString();
326 }
327
328 void
329 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
330 {
331   _blockSig = true;
332
333   // Show the widget:
334   _ui.labelCompo->show();
335   _ui.comboBoxCompo->show();
336
337   _ui.comboBoxCompo->clear();
338   bool vectorField = (compos.size() > 1 && compos.size() <= 3);
339   if (vectorField)
340     _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
341   for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
342     _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
343   if (!vectorField)
344     _ui.comboBoxCompo->setCurrentIndex(std::max(0, selecIndex-1));
345   else
346     _ui.comboBoxCompo->setCurrentIndex(selecIndex);
347
348   _blockSig = false;
349 }
350
351 void
352 WidgetPresentationParameters::setNbContour(int nbContour)
353 {
354   _blockSig = true;
355
356   if (nbContour <= 0)
357     {
358       //TODO throw?
359       STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
360     }
361
362   // Show the widget:
363   _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS").arg(MEDCALC::NB_CONTOURS_MAX));
364
365   _ui.labelSpinBox->show();
366   _ui.spinBox->show();
367   _ui.spinBox->setRange(1, MEDCALC::NB_CONTOURS_MAX);
368   _ui.spinBox->setValue(nbContour);
369
370   _blockSig = false;
371 }
372
373 void
374 WidgetPresentationParameters::setNbSlices(int nbSlices)
375 {
376   _blockSig = true;
377
378   if (nbSlices <= 0)
379     {
380       //TODO throw?
381       STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
382     }
383
384   // Show the widget:
385   _ui.labelSpinBox->setText(tr("LAB_NB_SLICES").arg(MEDCALC::NB_SLICES_MAX));
386   _ui.labelSpinBox->show();
387   _ui.spinBox->show();
388   _ui.spinBox->setRange(1, MEDCALC::NB_SLICES_MAX);
389   _ui.spinBox->setValue(nbSlices);
390
391   _blockSig = false;
392 }
393
394 int WidgetPresentationParameters::getNbContour() const
395 {
396   return _ui.spinBox->value();
397 }
398
399 int WidgetPresentationParameters::getNbSlices() const
400 {
401   return _ui.spinBox->value();
402 }
403
404
405 void
406 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
407 {
408   _blockSig = true;
409
410   int idx = -1;
411   if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
412     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
413   else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
414     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
415
416   if (idx >= 0) {
417       _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
418       _ui.checkBoxCustomRange->setChecked(false);
419   }
420   else {
421     if (sbrange == MEDCALC::SCALAR_BAR_CUSTOM_RANGE) {
422       _ui.checkBoxCustomRange->setChecked(true);
423     } else {
424       STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
425     }
426   }
427   _blockSig = false;
428 }
429
430 void
431 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
432 {
433   _blockSig = true;
434
435   int idx = -1;
436   if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
437     idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
438   else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
439     idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
440
441   if (idx >= 0)
442   {
443     _ui.comboBoxColorMap->setCurrentIndex(idx);
444   }
445   else
446   {
447     STDLOG("Strange!! No matching found - unable to set color map in GUI.");
448   }
449
450   _blockSig = false;
451 }
452
453 void
454 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
455 {
456   _blockSig = true;
457
458   // Show the widget:
459   _ui.labelMeshMode->show();
460   _ui.comboBoxMesh->show();
461
462   int idx;
463   switch(mode)
464   {
465     case MEDCALC::MESH_MODE_WIREFRAME:
466       idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
467       break;
468     case MEDCALC::MESH_MODE_SURFACE:
469       idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
470       break;
471     case MEDCALC::MESH_MODE_SURFACE_EDGES:
472       idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
473       break;
474     default:
475       idx = -1;
476   }
477   if (idx >= 0)
478   {
479     _ui.comboBoxMesh->setCurrentIndex(idx);
480   }
481   else
482   {
483     STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
484   }
485
486   _blockSig = false;
487 }
488
489 void
490 WidgetPresentationParameters::setIntegrationDir(MEDCALC::IntegrationDirType iDir)
491 {
492   _blockSig = true;
493
494   // Show the widget;
495   _ui.labelIntegrDir->show();
496   _ui.comboBoxIntegrDir->show();
497
498   int idx;
499   switch(iDir)
500   {
501     case MEDCALC::INTEGRATION_DIR_BOTH:
502       idx = _ui.comboBoxIntegrDir->findText(tr("LAB_INTEGR_DIR_BOTH"));
503       break;
504     case MEDCALC::INTEGRATION_DIR_FORWARD:
505       idx = _ui.comboBoxIntegrDir->findText(tr("LAB_INTEGR_DIR_FORWARD"));
506       break;
507     case MEDCALC::INTEGRATION_DIR_BACKWARD:
508       idx = _ui.comboBoxIntegrDir->findText(tr("LAB_INTEGR_DIR_BACKWARD"));
509       break;
510     default:
511       idx = -1;
512   }
513   if (idx >= 0)
514   {
515     _ui.comboBoxIntegrDir->setCurrentIndex(idx);
516   }
517   else
518   {
519     STDLOG("Strange!! No matching found - unable to set integration direction in GUI.");
520   }
521
522   _blockSig = false;
523 }
524
525 void
526 WidgetPresentationParameters::setContourComponents(std::vector<std::string> compos, int selecIndex)
527 {
528   _blockSig = true;
529
530   // Show the widget;
531   _ui.labelContourComp->show();
532   _ui.comboBoxContComp->show();
533
534   _ui.comboBoxContComp->clear();
535   bool vectorField = (compos.size() > 1 && compos.size() <= 3);
536   if (vectorField)
537     _ui.comboBoxContComp->addItem(tr("LAB_EUCLIDEAN_NORM"));
538   for (vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
539     _ui.comboBoxContComp->addItem(QString::fromStdString(*it));
540   if (!vectorField)
541     _ui.comboBoxContComp->setCurrentIndex(std::max(0, selecIndex - 1));
542   else
543     _ui.comboBoxContComp->setCurrentIndex(selecIndex);
544
545   _blockSig = false;
546 }
547
548 void
549 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
550 {
551   _blockSig = true;
552
553   // Show the widget:
554   _ui.labelSliceOrient->show();
555   _ui.comboBoxSliceOrient->show();
556
557   int idx;
558   switch(orient)
559   {
560     case MEDCALC::SLICE_NORMAL_TO_X:
561       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
562       break;
563     case MEDCALC::SLICE_NORMAL_TO_Y:
564       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
565       break;
566     case MEDCALC::SLICE_NORMAL_TO_Z:
567       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
568       break;
569     case MEDCALC::SLICE_NORMAL_TO_XY:
570       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
571       break;
572     case MEDCALC::SLICE_NORMAL_TO_XZ:
573       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
574       break;
575     case MEDCALC::SLICE_NORMAL_TO_YZ:
576       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
577       break;
578     case MEDCALC::SLICE_NORMAL_TO_XYZ:
579       idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
580       break;
581     default:
582       idx = -1;
583   }
584   if (idx >= 0)
585   {
586     _ui.comboBoxSliceOrient->setCurrentIndex(idx);
587   }
588   else
589   {
590     STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
591   }
592
593   _blockSig = false;
594 }
595
596
597 MEDCALC::SliceOrientationType
598 WidgetPresentationParameters::getSliceOrientation() const
599 {
600   QString sbrange = _ui.comboBoxSliceOrient->currentText();
601   if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
602       return MEDCALC::SLICE_NORMAL_TO_X;
603   }
604   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
605       return MEDCALC::SLICE_NORMAL_TO_Y;
606   }
607   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
608       return MEDCALC::SLICE_NORMAL_TO_Z;
609   }
610   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
611       return MEDCALC::SLICE_NORMAL_TO_XY;
612   }
613   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
614       return MEDCALC::SLICE_NORMAL_TO_XZ;
615   }
616   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
617       return MEDCALC::SLICE_NORMAL_TO_YZ;
618   }
619   else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
620       return MEDCALC::SLICE_NORMAL_TO_XYZ;
621   }
622   // Should not happen
623   STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
624   return MEDCALC::SLICE_NORMAL_TO_X;
625 }
626
627 MEDCALC::MeshModeType
628 WidgetPresentationParameters::getMeshMode() const
629 {
630   QString mesm = _ui.comboBoxMesh->currentText();
631   if (mesm == tr("LAB_MESH_WIREFRAME")) {
632       return MEDCALC::MESH_MODE_WIREFRAME;
633   }
634   else if (mesm == tr("LAB_MESH_SURFACE")) {
635       return MEDCALC::MESH_MODE_SURFACE;
636   }
637   else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
638       return MEDCALC::MESH_MODE_SURFACE_EDGES;
639   }
640   // Should not happen
641   STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
642   return MEDCALC::MESH_MODE_WIREFRAME;
643 }
644
645 MEDCALC::IntegrationDirType 
646 WidgetPresentationParameters::getIntegrationDir() const
647 {
648   QString iDir = _ui.comboBoxIntegrDir->currentText();
649   if (iDir == tr("LAB_INTEGR_DIR_BOTH")) {
650       return MEDCALC::INTEGRATION_DIR_BOTH;
651   }
652   else if (iDir == tr("LAB_INTEGR_DIR_FORWARD")) {
653       return MEDCALC::INTEGRATION_DIR_FORWARD;
654   }
655   else if (iDir == tr("LAB_INTEGR_DIR_BACKWARD")) {
656       return MEDCALC::INTEGRATION_DIR_BACKWARD;
657   }
658   // Should not happen
659   STDLOG("Strange!! No matching found - returning LAB_INTEGR_DIR_BOTH.");
660   return MEDCALC::INTEGRATION_DIR_BOTH;
661 }
662
663 std::string 
664 WidgetPresentationParameters::getContourComponent() const
665 {
666   if (_ui.comboBoxContComp->count() > 1 && _ui.comboBoxContComp->count() <= 4)
667     if (_ui.comboBoxContComp->currentIndex() == 0) // Euclidean norm
668       return "";
669   return _ui.comboBoxContComp->currentText().toStdString();
670 }
671
672 MEDCALC::ScalarBarRangeType
673 WidgetPresentationParameters::getScalarBarRange() const
674 {
675   if (_ui.checkBoxCustomRange->isChecked()) {
676     return  MEDCALC::SCALAR_BAR_CUSTOM_RANGE;
677   }
678   QString sbrange = _ui.comboBoxScalarBarRange->currentText();
679   if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
680     return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
681   }
682   else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
683     return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
684   }
685   // Should not happen
686   STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
687   return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
688 }
689
690 //double
691 //WidgetPresentationParameters::getScalarBarTimestep() const
692 //{
693 //  return _ui.doubleSpinBoxTimeStep->value();
694 //}
695 //
696 //double
697 //WidgetPresentationParameters::getScalarBarMinVal() const
698 //{
699 //  return _ui.doubleSpinBoxMinVal->value();
700 //}
701 //
702 //double
703 //WidgetPresentationParameters::getScalarBarMaxVal() const
704 //{
705 //  return _ui.doubleSpinBoxMaxVal->value();
706 //}
707
708 MEDCALC::ColorMapType
709 WidgetPresentationParameters::getColorMap() const
710 {
711   QString colorMap = _ui.comboBoxColorMap->currentText();
712   if (colorMap == tr("LAB_BLUE_TO_RED")) {
713     return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
714   }
715   else if (colorMap == tr("LAB_COOL_TO_WARM")) {
716     return MEDCALC::COLOR_MAP_COOL_TO_WARM;
717   }
718   // Should not happen
719   STDLOG("Strange!! No matching color map found - returning blue to red.");
720   return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
721 }
722
723 void
724 WidgetPresentationParameters::setPresName(const std::string& name)
725 {
726   _ui.labelPresName->setText(QString::fromStdString(name));
727   QFont f(_ui.labelPresName->font());
728   f.setItalic(true);
729   _ui.labelPresName->setFont(f);
730 }
731
732
733 void 
734 WidgetPresentationParameters::getScalarBarRangeValue(double* arr) const 
735 {
736   arr[0] = _ui.spinCustomRangeMin->value();
737   arr[1] = _ui.spinCustomRangeMax->value();
738 }
739
740 void WidgetPresentationParameters::setScalarBarRangeValue(double aMin, double aMax) {
741   _blockSig = true;
742   _ui.spinCustomRangeMin->setValue(aMin);
743   _ui.spinCustomRangeMax->setValue(aMax);
744   _blockSig = false;
745 }
746
747 void WidgetPresentationParameters::setScaleFactor(double scale) {
748   _blockSig = true;
749
750   // Show widget:
751   _ui.checkBoxScaleFactor->show();
752   _ui.spinScaleFactor->show();
753
754   _ui.spinScaleFactor->setValue(scale);
755   _blockSig = false;
756 }
757
758 // sphinx doc: begin of getNormal
759 void WidgetPresentationParameters::getNormal(double* arr) const
760 {
761   arr[0] = _ui.spinNormalX->value();
762   arr[1] = _ui.spinNormalY->value();
763   arr[2] = _ui.spinNormalZ->value();
764 }
765 // sphinx doc: end of getNormal
766
767 // sphinx doc: begin of setNormal
768 void
769 WidgetPresentationParameters::setNormal(const double normX, const double normY, const double normZ)
770 {
771   _blockSig = true;
772   _ui.labelCutPlaneNormal->show();
773   _ui.spinNormalX->show();
774   _ui.spinNormalY->show();
775   _ui.spinNormalZ->show();
776   _ui.spinNormalX->setValue(normX);
777   _ui.spinNormalY->setValue(normY);
778   _ui.spinNormalZ->setValue(normZ);
779   _blockSig = false;
780 }
781 // sphinx doc: end of setNormal
782
783 void WidgetPresentationParameters::getCutPoint1(double* arr) const
784 {
785   arr[0] = _ui.spinPoint1_X->value();
786   arr[1] = _ui.spinPoint1_Y->value();
787   arr[2] = _ui.spinPoint1_Z->value();
788 }
789
790 void
791 WidgetPresentationParameters::setCutPoint1(const double x, const double y, const double z)
792 {
793   _blockSig = true;
794   _ui.labelPoint1->show();
795   _ui.spinPoint1_X->show();
796   _ui.spinPoint1_Y->show();
797   _ui.spinPoint1_Z->show();
798   _ui.spinPoint1_X->setValue(x);
799   _ui.spinPoint1_Y->setValue(y);
800   _ui.spinPoint1_Z->setValue(z);
801   _blockSig = false;
802 }
803
804 void WidgetPresentationParameters::getCutPoint2(double* arr) const
805 {
806   arr[0] = _ui.spinPoint2_X->value();
807   arr[1] = _ui.spinPoint2_Y->value();
808   arr[2] = _ui.spinPoint2_Z->value();
809 }
810
811 void
812 WidgetPresentationParameters::setCutPoint2(const double x, const double y, const double z)
813 {
814   _blockSig = true;
815   _ui.labelPoint2->show();
816   _ui.spinPoint2_X->show();
817   _ui.spinPoint2_Y->show();
818   _ui.spinPoint2_Z->show();
819   _ui.spinPoint2_X->setValue(x);
820   _ui.spinPoint2_Y->setValue(y);
821   _ui.spinPoint2_Z->setValue(z);
822   _blockSig = false;
823 }
824
825 // sphinx doc: begin of getPlanePosition
826 double WidgetPresentationParameters::getPlanePosition() const
827 {
828   return _ui.spinPlanePos->value();
829 }
830 // sphinx doc: begin of getPlanePosition
831
832 // sphinx doc: begin of setPlanePosition
833 void WidgetPresentationParameters::setPlanePosition(double pos)
834 {
835   _blockSig = true;
836   _ui.labelCutPlanePosition->show();
837   _ui.spinPlanePos->show();
838   _ui.spinPlanePos->setValue(pos);
839   _blockSig = false;
840 }
841 // sphinx doc: begin of setPlanePosition
842
843 bool WidgetPresentationParameters::getScalarBarVisibility() const {
844   return _ui.checkBoxShowScalarBar->isChecked();
845 }
846
847 void WidgetPresentationParameters::setScalarBarVisibility(const bool visibility) {
848   _blockSig = true;
849   _ui.checkBoxShowScalarBar->setChecked(visibility);
850   _blockSig = false;
851 }
852
853 bool WidgetPresentationParameters::getHideDataOutsideCustomRange() const {
854   return _ui.checkBoxHideDataOutsideCR->isChecked();
855 }
856
857 void WidgetPresentationParameters::setHideDataOutsideCustomRange(const bool flag) {
858   _blockSig = true;
859   _ui.checkBoxHideDataOutsideCR->setChecked(flag);
860   _blockSig = false;
861 }
862
863 void WidgetPresentationParameters::setScaleFactorFlag(const bool flag) {
864   _blockSig = true;
865   _ui.checkBoxScaleFactor->setChecked(flag);
866   _blockSig = false;
867 }