]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp
Salome HOME
Issue #1865 : initial implementation of fields results and high level API
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_ComponentValue.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : ModelHighAPI_ComponentValue.cpp
3 // Purpose:
4 //
5 // History:
6 // 29/03/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_ComponentValue.h"
10
11 #include <ModelAPI_AttributeInteger.h>
12
13 #include <sstream>
14
15 //--------------------------------------------------------------------------------------
16 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const bool theValue)
17   : myType(ModelAPI_AttributeTables::BOOLEAN)
18 {
19   // initialize everything since in python there may be problem with correct typification
20   myValue.myBool = theValue;
21   myValue.myInt = theValue ? 1 : 0;
22   myValue.myDouble = theValue ? 1. : 0.;
23   myValue.myStr = theValue ? "True" : "False";
24 }
25 //--------------------------------------------------------------------------------------
26 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const int theValue)
27   : myType(ModelAPI_AttributeTables::INTEGER)
28 {
29   // initialize everything since in python there may be problem with correct typification
30   myValue.myBool = theValue == 0 ? false : true;
31   myValue.myInt = theValue;
32   myValue.myDouble = theValue;
33   std::ostringstream s;
34   s << theValue;
35   myValue.myStr = s.str();
36 }
37 //--------------------------------------------------------------------------------------
38 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const double theValue)
39   : myType(ModelAPI_AttributeTables::DOUBLE)
40 {
41   // initialize everything since in python there may be problem with correct typification
42   myValue.myBool = theValue == 0. ? false : true;
43   myValue.myInt = int(theValue);
44   myValue.myDouble = theValue;
45   std::ostringstream s;
46   s << theValue;
47   myValue.myStr = s.str();
48 }
49 //--------------------------------------------------------------------------------------
50 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const std::string& theValue)
51   : myType(ModelAPI_AttributeTables::STRING)
52 {
53   myValue.myBool = (theValue.empty() || theValue == "False" || theValue == "0") ? false : true;
54
55   std::stringstream stream1(theValue);
56   myValue.myInt = 0;
57   stream1 >> myValue.myInt;
58   std::stringstream stream2(theValue);
59   myValue.myDouble = 0.;
60   stream2 >> myValue.myDouble;
61
62   myValue.myStr = theValue;
63 }
64
65 //--------------------------------------------------------------------------------------
66 ModelHighAPI_ComponentValue::~ModelHighAPI_ComponentValue()
67 {
68 }
69
70 //--------------------------------------------------------------------------------------
71 void ModelHighAPI_ComponentValue::fill(const std::shared_ptr<ModelAPI_AttributeTables>& theAttr,
72     const int theTable, const int theColumn, const int theRow) const
73 {
74   theAttr->setValue(myValue, theRow, theColumn, theTable);
75 }