Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_ScalarWrapper.cpp
1 // Copyright (C) 2014-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 <PlaneGCSSolver_ScalarWrapper.h>
21 #include <PlaneGCSSolver_Tools.h>
22
23 #include <ModelAPI_AttributeDouble.h>
24 #include <ModelAPI_AttributeInteger.h>
25
26 PlaneGCSSolver_ScalarWrapper::PlaneGCSSolver_ScalarWrapper(double *const theParam)
27   : myValue(theParam)
28 {
29 }
30
31 void PlaneGCSSolver_ScalarWrapper::setValue(double theValue)
32 {
33   *myValue = theValue;
34 }
35
36 double PlaneGCSSolver_ScalarWrapper::value() const
37 {
38   return *myValue;
39 }
40
41 bool PlaneGCSSolver_ScalarWrapper::update(AttributePtr theAttribute)
42 {
43   double anAttrValue = 0.0;
44   AttributeDoublePtr aDouble =
45       std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
46   if (aDouble)
47     anAttrValue = aDouble->value();
48   else {
49     AttributeIntegerPtr anInt =
50         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
51     if (anInt)
52       anAttrValue = anInt->value();
53     else
54       return false;
55   }
56
57   // There is possible an angular value, which is converted between degrees and radians.
58   // So, we use its value instead of using direct pointer to variable.
59   double aCurrentValue = value();
60
61   bool isUpdated = PlaneGCSSolver_Tools::updateValue(anAttrValue, aCurrentValue);
62   if (isUpdated)
63     setValue(aCurrentValue);
64   return isUpdated;
65 }