Salome HOME
aa4921214c730287c9d9feaa9540c2cbba232ed9
[modules/med.git] / src / MEDCalc / gui / MEDWidgetHelperVectorField.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 "MEDWidgetHelperVectorField.hxx"
21 #include "MEDPresentationVectorField.hxx"  // from component side.
22 #include "PresentationController.hxx"
23
24 #include <Basics_Utils.hxx>
25
26 #include <sstream>
27
28
29 MEDWidgetHelperVectorField::MEDWidgetHelperVectorField(const PresentationController* presController,
30                            MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
31                            WidgetPresentationParameters * paramW):
32      MEDWidgetHelper(presController, presManager, presId, presName, paramW)
33   {}
34 MEDWidgetHelperVectorField::~MEDWidgetHelperVectorField() {}
35
36 void MEDWidgetHelperVectorField::loadParametersFromEngine()
37 {
38     MEDWidgetHelper::loadParametersFromEngine();
39     _scaleFactor = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationVectorField::PROP_SCALE_FACTOR.c_str());
40     _customScaleFactor = _presManager->getPresentationIntProperty(_presId, MEDPresentationVectorField::PROP_CUSTOM_SCALE_FACTOR.c_str());
41 }
42
43 void MEDWidgetHelperVectorField::updateWidget(bool connect)
44 {
45   MEDWidgetHelper::updateWidget(connect);
46   _paramWidget->setScaleFactor(_scaleFactor);
47   _paramWidget->setScaleFactorFlag(_customScaleFactor);
48
49   // Connect spin boxes changes
50   if (connect)
51   {
52     QObject::connect( _paramWidget, SIGNAL(spinboxScaleFactorChaged(double)), this, SLOT(onScaleFactorChanged(double)) );
53     QObject::connect( _paramWidget, SIGNAL(checkboxCustomScaleFactorChanged(int)), this, SLOT(onCustomScaleFactorChanged(int)));
54
55   }
56 }
57
58 void MEDWidgetHelperVectorField::releaseWidget()
59 {
60   MEDWidgetHelper::releaseWidget();
61
62   QObject::disconnect( _paramWidget, SIGNAL(spinboxScaleFactorChaged(double)), this, SLOT(onScaleFactorChanged(double)) );
63 }
64
65 void MEDWidgetHelperVectorField::onScaleFactorChanged(double scale)
66 {
67     STDLOG("MEDWidgetHelperVectorField::onScaleFactorChanged");
68     PresentationEvent* event = new PresentationEvent();
69     event->eventtype = PresentationEvent::EVENT_CHANGE_SCALE_FACTOR;
70     event->presentationId = _presId;
71     event->aDouble3 = scale;
72
73     emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
74 }
75
76 void MEDWidgetHelperVectorField::onCustomScaleFactorChanged(int flag)
77 {
78   STDLOG("MEDWidgetHelperVectorField::onScaleFactorChanged");
79   PresentationEvent* event = new PresentationEvent();
80   event->eventtype = PresentationEvent::EVENT_CHANGE_CUSTOM_SCALE_FACTOR;
81   event->presentationId = _presId;
82   event->anInteger = flag;
83   event->aDouble3 = _paramWidget->getScaleFactor();
84
85   emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
86 }