Salome HOME
updated copyright message
[modules/med.git] / src / MEDCalc / gui / MEDWidgetHelperPlot3D.cxx
1 // Copyright (C) 2016-2023  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 "MEDWidgetHelperPlot3D.hxx"
21 #include "MEDPresentationPlot3D.hxx"  // from component side.
22 #include "PresentationController.hxx"
23
24 #include <Basics_Utils.hxx>
25
26 #include <sstream>
27
28 MEDWidgetHelperPlot3D::MEDWidgetHelperPlot3D(const PresentationController* presController,
29                            MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
30                            WidgetPresentationParameters * paramW):
31   MEDWidgetHelper(presController, presManager, presId, presName, paramW)
32   {}
33
34 MEDWidgetHelperPlot3D::~MEDWidgetHelperPlot3D() 
35 {}
36
37 void MEDWidgetHelperPlot3D::loadParametersFromEngine()
38 {
39   MEDWidgetHelper::loadParametersFromEngine();
40   _planeNormal[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_NORMAL_X.c_str());
41   _planeNormal[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_NORMAL_Y.c_str());
42   _planeNormal[2] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_NORMAL_Z.c_str());
43   _planePos = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_POS.c_str());
44   _isPlanar = _presManager->getPresentationIntProperty(_presId, MEDPresentationPlot3D::PROP_IS_PLANAR.c_str());
45 }
46
47 void MEDWidgetHelperPlot3D::updateWidget(bool connect)
48 {
49   MEDWidgetHelper::updateWidget(connect);
50
51   _paramWidget->setNormal(_planeNormal[0], _planeNormal[1], _planeNormal[2]);
52   _paramWidget->setPlanePosition(_planePos);
53
54   // Connect spin boxes changes
55   if (connect)
56   {
57     QObject::connect( _paramWidget, SIGNAL(spinNormalValuesChanged(double, double, double)), this, SLOT(onPlaneNormalChanged(double, double, double)) );
58     QObject::connect( _paramWidget, SIGNAL(spinPlanePosValueChanged(double)), this, SLOT(onPlanePositionChanged(double)) );
59   }
60   if(_isPlanar)
61     _paramWidget->hidePlot3D();
62 }
63
64 void MEDWidgetHelperPlot3D::releaseWidget()
65 {
66   MEDWidgetHelper::releaseWidget();
67
68   QObject::disconnect( _paramWidget, SIGNAL(spinNormalValuesChanged(double, double, double)), this, SLOT(onPlaneNormalChanged(double, double, double)) );
69   QObject::disconnect( _paramWidget, SIGNAL(spinPlanePosValueChanged(double)), this, SLOT(onPlanePositionChanged(double)) );
70 }
71
72 void MEDWidgetHelperPlot3D::onPlaneNormalChanged(double normX, double normY, double normZ)
73 {
74     STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged");
75     PresentationEvent* event = new PresentationEvent();
76     event->eventtype = PresentationEvent::EVENT_CHANGE_NORMAL;
77     event->presentationId = _presId;
78     event->aDoubleN[0] = normX;
79     event->aDoubleN[1] = normY;
80     event->aDoubleN[2] = normZ;
81
82     emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
83 }
84   
85 void MEDWidgetHelperPlot3D::onPlanePositionChanged(double planePos)
86 {
87     STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged");
88     PresentationEvent* event = new PresentationEvent();
89     event->eventtype = PresentationEvent::EVENT_CHANGE_PLANE_POS;
90     event->presentationId = _presId;
91     event->aDouble3 = planePos;
92
93     emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
94 }