Salome HOME
[MEDCalc] Mesh view and slice presentation.
[modules/med.git] / src / MEDCalc / gui / MEDWidgetHelperSlices.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 "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   MEDWidgetHelper(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::MEDPresentationSliceOrientation>(
44       _presManager->getPresentationIntProperty(_presId, MEDPresentationSlices::PROP_SLICE_ORIENTATION.c_str()));
45 }
46
47 void MEDWidgetHelperSlices::udpateWidget()
48 {
49   MEDWidgetHelper::udpateWidget();
50   STDLOG("MEDWidgetHelperSlices::udpateWidget() nbSlices is " << _nbSlices);
51
52 //  _paramWidget->setNbSlices(_nbSlices);        // TODO: uncomment when ready to deal with slice number
53   _paramWidget->setSliceOrientation(_sliceOrientation);
54
55   // Connect combo box changes
56   QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
57                     _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
58   QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
59   QObject::connect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
60 }
61
62 void MEDWidgetHelperSlices::releaseWidget()
63 {
64   MEDWidgetHelper::releaseWidget();
65
66   QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
67                        _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
68   QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
69   QObject::disconnect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
70 }
71
72 void MEDWidgetHelperSlices::onNbSlicesChanged(int nbSlices)
73 {
74   STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged");
75   PresentationEvent* event = new PresentationEvent();
76   event->eventtype = PresentationEvent::EVENT_CHANGE_NB_SLICES;
77   event->presentationId = _presId;
78   event->anInteger = nbSlices;
79
80   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
81 }
82
83
84 void MEDWidgetHelperSlices::onSliceOrientationChanged(int sliceOrient)
85 {
86   STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged");
87   PresentationEvent* event = new PresentationEvent();
88   event->eventtype = PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION;
89   event->presentationId = _presId;
90   event->anInteger = static_cast<int>(_paramWidget->getSliceOrientation());
91
92   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
93 }