1 // Copyright (C) 2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "WidgetPresentationParameters.hxx"
21 #include <Basics_Utils.hxx>
25 WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
26 : QWidget(parent), _blockSig(false)
28 _ui.setupUi(this); // To be done first
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 QObject::connect(_ui.spinBox, SIGNAL(valueChanged(int)),
38 this, SLOT(onSpinBoxValueChanged(int)) );
42 WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
44 if (!_blockSig) emit comboCompoIndexChanged(idx);
48 WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
50 if (!_blockSig) emit comboColorMapIndexChanged(idx);
54 WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
56 if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
60 WidgetPresentationParameters::onSpinBoxValueChanged(int val)
62 if (!_blockSig) emit spinBoxValueChanged(val);
66 WidgetPresentationParameters::toggleWidget(bool show)
71 _ui.widgetDynamic->hide();
72 setPresName("Choose a presentation");
73 // reset colorMap and scalarBarRange:
74 setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
75 setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
79 _ui.widgetDynamic->show();
80 // It is the WidgetHelper responsability to re-show the widgets it needs
81 _ui.labelCompo->hide();
82 _ui.comboBoxCompo->hide();
83 _ui.labelSpinBox->hide();
85 _ui.labelSliceOrient->hide();
86 _ui.comboBoxSliceOrient->hide();
92 WidgetPresentationParameters::isShown() const
94 return _ui.widgetDynamic->isVisible();
98 WidgetPresentationParameters::getComponent() const
100 if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
103 return _ui.comboBoxCompo->currentText().toStdString();
107 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
110 _ui.labelCompo->show();
111 _ui.comboBoxCompo->show();
114 _ui.comboBoxCompo->clear();
115 _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
116 for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
117 _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
118 _ui.comboBoxCompo->setCurrentIndex(selecIndex);
123 WidgetPresentationParameters::setNbContour(int nbContour)
128 STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
132 _ui.labelSpinBox->setText(tr("LAB_NB_CONTOUR"));
133 _ui.labelSpinBox->show();
137 _ui.spinBox->setValue(nbContour);
141 int WidgetPresentationParameters::getNbContour() const
143 return _ui.spinBox->value();
147 WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange)
150 if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
151 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
152 else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
153 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
158 _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
162 STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
166 WidgetPresentationParameters::setColorMap(MEDCALC::MEDPresentationColorMap colorMap)
169 if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
170 idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
171 else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
172 idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
177 _ui.comboBoxColorMap->setCurrentIndex(idx);
182 STDLOG("Strange!! No matching found - unable to set color map in GUI.");
186 MEDCALC::MEDPresentationScalarBarRange
187 WidgetPresentationParameters::getScalarBarRange() const
189 QString sbrange = _ui.comboBoxScalarBarRange->currentText();
190 if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
191 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
193 else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
194 return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
197 STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
198 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
202 //WidgetPresentationParameters::getScalarBarTimestep() const
204 // return _ui.doubleSpinBoxTimeStep->value();
208 //WidgetPresentationParameters::getScalarBarMinVal() const
210 // return _ui.doubleSpinBoxMinVal->value();
214 //WidgetPresentationParameters::getScalarBarMaxVal() const
216 // return _ui.doubleSpinBoxMaxVal->value();
219 MEDCALC::MEDPresentationColorMap
220 WidgetPresentationParameters::getColorMap() const
222 QString colorMap = _ui.comboBoxColorMap->currentText();
223 if (colorMap == tr("LAB_BLUE_TO_RED")) {
224 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
226 else if (colorMap == tr("LAB_COOL_TO_WARM")) {
227 return MEDCALC::COLOR_MAP_COOL_TO_WARM;
230 STDLOG("Strange!! No matching color map found - returning blue to red.");
231 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
235 WidgetPresentationParameters::getComboBoxCompo()
237 return _ui.comboBoxCompo;
241 WidgetPresentationParameters::setPresName(const std::string& name)
243 _ui.labelPresName->setText(QString::fromStdString(name));
244 QFont f(_ui.labelPresName->font());
246 _ui.labelPresName->setFont(f);