Salome HOME
e63ca03887313b153a72ee86749d0b22da9f09aa
[modules/med.git] / src / MEDCalc / gui / MEDWidgetHelperSlices.cxx
1 // Copyright (C) 2016-2022  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 "MEDWidgetHelperSlices.hxx"
21 #include "MEDPresentationSlices.hxx"  // from component side.
22 #include "PresentationController.hxx"
23
24 #include <Basics_Utils.hxx>
25
26 #include <sstream>
27
28 MEDWidgetHelperSlices::MEDWidgetHelperSlices(const PresentationController * presController,
29                                                MEDCALC::MEDPresentationManager_ptr presManager, int presId,
30                                                const std::string & presName, WidgetPresentationParameters * paramW):
31   MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW),
32   _nbSlices(-1),
33   _sliceOrientation(MEDCALC::SLICE_ORIENTATION_DEFAULT)
34 {}
35
36 MEDWidgetHelperSlices::~MEDWidgetHelperSlices()
37 {}
38
39 void MEDWidgetHelperSlices::loadParametersFromEngine()
40 {
41   MEDWidgetHelper::loadParametersFromEngine();
42   _nbSlices = _presManager->getPresentationIntProperty(_presId, MEDPresentationSlices::PROP_NB_SLICES.c_str());
43   _sliceOrientation = static_cast<MEDCALC::SliceOrientationType>(
44       _presManager->getPresentationIntProperty(_presId, MEDPresentationSlices::PROP_SLICE_ORIENTATION.c_str()));
45 }
46
47 void MEDWidgetHelperSlices::updateWidget(bool connect)
48 {
49   MEDWidgetHelperComponent::updateWidget(connect);
50
51   _paramWidget->setNbSlices(_nbSlices);
52   _paramWidget->setSliceOrientation(_sliceOrientation);
53
54   // Connect combo box changes
55   if (connect)
56     {
57       QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
58       QObject::connect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
59     }
60 }
61
62 void MEDWidgetHelperSlices::releaseWidget()
63 {
64   MEDWidgetHelper::releaseWidget();
65
66   QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
67   QObject::disconnect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
68 }
69
70 void MEDWidgetHelperSlices::onNbSlicesChanged(int nbSlices)
71 {
72   STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged");
73   PresentationEvent* event = new PresentationEvent();
74   event->eventtype = PresentationEvent::EVENT_CHANGE_NB_SLICES;
75   event->presentationId = _presId;
76   event->anInteger = nbSlices;
77
78   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
79 }
80
81
82 void MEDWidgetHelperSlices::onSliceOrientationChanged(int /*sliceOrient*/)
83 {
84   STDLOG("MEDWidgetHelperSlices::onSliceOrientationChanged");
85   PresentationEvent* event = new PresentationEvent();
86   event->eventtype = PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION;
87   event->presentationId = _presId;
88   event->anInteger = static_cast<int>(_paramWidget->getSliceOrientation());
89
90   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
91 }