Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Double.cpp
1 // Copyright (C) 2014-2022  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 "ModelHighAPI_Double.h"
21
22 #include <ModelAPI_AttributeDouble.h>
23 #include <GeomDataAPI_Point.h>
24
25 #include <sstream>
26 //--------------------------------------------------------------------------------------
27
28 //--------------------------------------------------------------------------------------
29 ModelHighAPI_Double::ModelHighAPI_Double(double theValue)
30 : myVariantType(VT_DOUBLE)
31 , myDouble(theValue)
32 {
33 }
34
35 ModelHighAPI_Double::ModelHighAPI_Double(const std::wstring & theValue)
36 : myVariantType(VT_STRING)
37 , myString(theValue)
38 {
39 }
40
41 ModelHighAPI_Double::ModelHighAPI_Double(const wchar_t * theValue)
42 : myVariantType(VT_STRING)
43 , myString(theValue)
44 {
45 }
46
47 ModelHighAPI_Double::~ModelHighAPI_Double()
48 {
49 }
50
51 double ModelHighAPI_Double::value() const
52 {
53   // needed for array of double, which supports no text
54   return myDouble;
55 }
56
57 std::wstring ModelHighAPI_Double::string() const
58 {
59   if (myVariantType == VT_STRING)
60     return myString;
61
62   std::wostringstream anOut;
63   anOut << myDouble;
64   return anOut.str();
65 }
66
67 //--------------------------------------------------------------------------------------
68 void ModelHighAPI_Double::fillAttribute(
69     const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute) const
70 {
71   switch(myVariantType) {
72     case VT_DOUBLE: theAttribute->setValue(myDouble); return;
73     case VT_STRING: theAttribute->setText(myString); return;
74   }
75 }
76
77 void ModelHighAPI_Double::fillAttribute(
78   const std::shared_ptr<GeomDataAPI_Point> & thePoint,
79   const ModelHighAPI_Double & theX,
80   const ModelHighAPI_Double & theY,
81   const ModelHighAPI_Double & theZ) const
82 {
83   switch (theX.myVariantType) {
84   case VT_DOUBLE: thePoint->setX(theX.myDouble); break;
85   case VT_STRING: thePoint->setTextX(theX.myString);
86   }
87   switch (theY.myVariantType) {
88   case VT_DOUBLE: thePoint->setY(theY.myDouble); break;
89   case VT_STRING: thePoint->setTextY(theY.myString);
90   }
91   switch (theZ.myVariantType) {
92   case VT_DOUBLE: thePoint->setZ(theZ.myDouble); break;
93   case VT_STRING: thePoint->setTextZ(theZ.myString);
94   }
95 }