Salome HOME
updated copyright message
[modules/med.git] / src / MEDCalc / gui / MEDWidgetHelperCutSegment.cxx
1 // Copyright (C) 2016-2023  CEA, EDF
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 "MEDWidgetHelperCutSegment.hxx"
21 #include "MEDPresentationCutSegment.hxx"  // from component side.
22 #include "PresentationController.hxx"
23
24 #include <Basics_Utils.hxx>
25
26 #include <sstream>
27
28 MEDWidgetHelperCutSegment::MEDWidgetHelperCutSegment(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 MEDWidgetHelperCutSegment::~MEDWidgetHelperCutSegment() 
35 {}
36
37 void MEDWidgetHelperCutSegment::loadParametersFromEngine()
38 {
39   MEDWidgetHelper::loadParametersFromEngine();
40   _point1[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT1_X.c_str());
41   _point1[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT1_Y.c_str());
42   _point1[2] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT1_Z.c_str());
43   _point2[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT2_X.c_str());
44   _point2[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT2_Y.c_str());
45   _point2[2] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT2_Z.c_str());
46 }
47
48 void MEDWidgetHelperCutSegment::updateWidget(bool connect)
49 {
50   MEDWidgetHelper::updateWidget(connect);
51
52   _paramWidget->setCutPoint1(_point1[0], _point1[1], _point1[2]);
53   _paramWidget->setCutPoint2(_point2[0], _point2[1], _point2[2]);
54
55   // Connect spin boxes changes
56   if (connect)
57   {
58     QObject::connect( _paramWidget, SIGNAL(spinCutPoint1ValuesChanged(double, double, double)), this, SLOT(onCutPoint1Changed(double, double, double)) );
59     QObject::connect( _paramWidget, SIGNAL(spinCutPoint2ValuesChanged(double, double, double)), this, SLOT(onCutPoint2Changed(double, double, double)) );
60   }
61 }
62
63 void MEDWidgetHelperCutSegment::releaseWidget()
64 {
65   MEDWidgetHelper::releaseWidget();
66
67   QObject::disconnect( _paramWidget, SIGNAL(spinCutPoint1ValuesChanged(double, double, double)), this, SLOT(onCutPoint1Changed(double, double, double)) );
68   QObject::disconnect( _paramWidget, SIGNAL(spinCutPoint2ValuesChanged(double, double, double)), this, SLOT(onCutPoint2Changed(double, double, double)) );
69 }
70
71 void MEDWidgetHelperCutSegment::onCutPoint1Changed(double x, double y, double z)
72 {
73     STDLOG("MEDWidgetHelperCutSegment::onCutPoint1Changed");
74     PresentationEvent* event = new PresentationEvent();
75     event->eventtype = PresentationEvent::EVENT_CHANGE_CUT_POINT1;
76     event->presentationId = _presId;
77     event->aDoubleP1[0] = x;
78     event->aDoubleP1[1] = y;
79     event->aDoubleP1[2] = z;
80
81     emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
82 }
83
84 void MEDWidgetHelperCutSegment::onCutPoint2Changed(double x, double y, double z)
85 {
86     STDLOG("MEDWidgetHelperCutSegment::onCutPoint2Changed");
87     PresentationEvent* event = new PresentationEvent();
88     event->eventtype = PresentationEvent::EVENT_CHANGE_CUT_POINT2;
89     event->presentationId = _presId;
90     event->aDoubleP2[0] = x;
91     event->aDoubleP2[1] = y;
92     event->aDoubleP2[2] = z;
93
94     emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
95 }