Salome HOME
Copyright update 2020
[modules/med.git] / src / MEDCalc / gui / MEDWidgetHelper.cxx
1 // Copyright (C) 2016-2020  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 "MEDWidgetHelper.hxx"
21 #include "PresentationController.hxx"
22 #include "MEDPresentation.hxx"
23 #include <Basics_Utils.hxx>
24
25 MEDWidgetHelper::MEDWidgetHelper(const PresentationController * presController,
26                                  MEDCALC::MEDPresentationManager_ptr presManager, int presId,
27                                  const std::string & presName,  WidgetPresentationParameters * paramWidget):
28   _presController(presController),
29   _presManager(presManager),
30   _presId(presId),
31   _presName(presName),
32   _paramWidget(paramWidget)
33 {}
34
35 MEDWidgetHelper::~MEDWidgetHelper()
36 {}
37
38 void MEDWidgetHelper::loadParametersFromEngine()
39 {
40   _selectedCompo = _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SELECTED_COMPONENT.c_str());
41   _nbCompos = _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_NB_COMPONENTS.c_str());
42   _allCompos.clear();
43   _allCompos.reserve(_nbCompos);
44   for (int i = 0; i < _nbCompos; i++)
45     {
46       std::ostringstream oss;
47       oss << MEDPresentation::PROP_COMPONENT << i;
48       _allCompos.push_back(_presManager->getPresentationStringProperty(_presId, oss.str().c_str()));
49     }
50   _colorMap = static_cast<MEDCALC::ColorMapType>(
51       _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_COLOR_MAP.c_str()));
52   _scalarBarRange = static_cast<MEDCALC::ScalarBarRangeType>(
53       _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_RANGE.c_str()));
54 }
55
56 void MEDWidgetHelper::updateWidget(bool connect)
57 {
58   // Set presentation name
59   _paramWidget->setPresName(_presName);
60
61   // Show dynamic part of the widget (i.e. everything else than color map and scalar bar range)
62   _paramWidget->toggleWidget(true);
63
64   loadParametersFromEngine();
65
66   // Set properly color map and scalar bar range
67   STDLOG("MEDWidgetHelper::udpateWidget() colorMap is " << _colorMap);
68   _paramWidget->setColorMap(_colorMap);
69   STDLOG("MEDWidgetHelper::udpateWidget() scalarBarRange is " << _scalarBarRange);
70   _paramWidget->setScalarBarRange(_scalarBarRange);
71
72   if (connect)
73     {
74       QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
75                               _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
76       QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) );
77       QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) );
78     }
79 }
80
81 void MEDWidgetHelper::releaseWidget()
82 {
83   QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
84                           _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
85   QObject::disconnect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) );
86   QObject::disconnect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) );
87
88   // Reset default for color map and scalar bar range
89   _paramWidget->setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
90   _paramWidget->setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
91 }
92
93 void MEDWidgetHelper::onComponentChanged(int idx)
94 {
95   STDLOG("MEDWidgetHelper::onComponentChanged");
96   PresentationEvent* event = new PresentationEvent();
97   event->eventtype = PresentationEvent::EVENT_CHANGE_COMPONENT;
98   event->presentationId = _presId;
99   event->anInteger = idx;
100   event->aString = _paramWidget->getComponent();
101
102   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
103 }
104
105 void MEDWidgetHelper::onColorMapChanged(int idx)
106 {
107   STDLOG("MEDWidgetHelper::onColorMapChanged");
108   PresentationEvent* event = new PresentationEvent();
109   event->eventtype = PresentationEvent::EVENT_CHANGE_COLORMAP;
110   event->presentationId = _presId;
111   // The actual selected item in the combo list is retrieved by the workspace controller _getColorMap()
112 //  event->anInteger = idx;
113
114   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
115 }
116
117 void MEDWidgetHelper::onScalarBarRangeChanged(int idx)
118 {
119   STDLOG("MEDWidgetHelper::onScalarBarRangeChanged");
120   PresentationEvent* event = new PresentationEvent();
121   event->eventtype = PresentationEvent::EVENT_CHANGE_TIME_RANGE;
122   event->presentationId = _presId;
123   event->anInteger = idx;
124   // The actual selected item in the combo list is retrieved by the workspace controller _getScalarBarRange()
125   //event->aString = _paramWidget->getScalarBarRange();
126
127   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
128 }