Salome HOME
Introduce ModelAPI_Expression.
[modules/shaper.git] / src / GeomData / GeomData_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomData_Point.cxx
4 // Created:     24 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "GeomData_Point.h"
8
9 #include <GeomAPI_Pnt.h>
10
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_Events.h>
13 #include <ModelAPI_Expression.h>
14 #include <ModelAPI_Feature.h>
15
16 #include <cassert>
17
18 GeomData_Point::GeomData_Point(TDF_Label& theLabel)
19 {
20   myIsInitialized = true;
21 }
22
23 void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
24 {
25   if (!myIsInitialized || x() != theX || y() != theY || z() != theZ) {
26     myExpression[0]->setValue(theX);
27     myExpression[1]->setValue(theY);
28     myExpression[2]->setValue(theZ);
29     owner()->data()->sendAttributeUpdated(this);
30   }
31 }
32
33 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
34 {
35   setCalculatedValue(textX().empty() ? theX : x(),
36                      textY().empty() ? theY : y(),
37                      textZ().empty() ? theZ : z());
38 }
39
40 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
41 {
42   setValue(thePoint->x(), thePoint->y(), thePoint->z());
43 }
44
45 double GeomData_Point::x() const
46 {
47   return myExpression[0]->value();
48 }
49
50 double GeomData_Point::y() const
51 {
52   return myExpression[1]->value();
53 }
54
55 double GeomData_Point::z() const
56 {
57   return myExpression[2]->value();
58 }
59
60 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
61 {
62   std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
63   return aResult;
64 }
65
66 void GeomData_Point::setText(const std::string& theX,
67                              const std::string& theY,
68                              const std::string& theZ)
69 {
70   if (!myIsInitialized || textX() != theX || textY() != theY || textZ() != theZ) {
71     myExpression[0]->setText(theX);
72     myExpression[1]->setText(theY);
73     myExpression[2]->setText(theZ);
74     // Send it to evaluator to convert into the double and store in the attribute
75     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
76     owner()->data()->sendAttributeUpdated(this);
77   }
78 }
79
80 std::string GeomData_Point::textX()
81 {
82   return myExpression[0]->text();
83 }
84 std::string GeomData_Point::textY()
85 {
86   return myExpression[1]->text();
87 }
88 std::string GeomData_Point::textZ()
89 {
90   return myExpression[2]->text();
91 }
92
93 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
94 {
95   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
96   if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
97     myExpression[theComponent]->setInvalid(theFlag);
98 }
99
100 bool GeomData_Point::expressionInvalid(int theComponent)
101 {
102   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
103   return myExpression[theComponent]->isInvalid();
104 }
105
106 void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
107 {
108   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
109   if (expressionError(theComponent) != theError)
110     myExpression[theComponent]->setError(theError);
111 }
112
113 std::string GeomData_Point::expressionError(int theComponent)
114 {
115   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
116   return myExpression[theComponent]->error();
117 }
118
119 void GeomData_Point::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
120 {
121   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
122   myExpression[theComponent]->setUsedParameters(theUsedParameters);
123 }
124
125 std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
126 {
127   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
128   return myExpression[theComponent]->usedParameters();
129 }