Salome HOME
Issue #2171: Avoid error message appears for tangency constraint
[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()
19 {
20   myIsInitialized = false;
21 }
22
23 void GeomData_Point::reinit()
24 {
25   myIsInitialized = true;
26   for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
27     myExpression[aComponent]->reinit();
28     myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
29   }
30 }
31
32 void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
33 {
34   if (!myIsInitialized || x() != theX || y() != theY || z() != theZ) {
35     myExpression[0]->setValue(theX);
36     myExpression[1]->setValue(theY);
37     myExpression[2]->setValue(theZ);
38     owner()->data()->sendAttributeUpdated(this);
39   }
40 }
41
42 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
43 {
44   setCalculatedValue(textX().empty() ? theX : x(),
45                      textY().empty() ? theY : y(),
46                      textZ().empty() ? theZ : z());
47 }
48
49 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
50 {
51   setValue(thePoint->x(), thePoint->y(), thePoint->z());
52 }
53
54 double GeomData_Point::x() const
55 {
56   return myExpression[0]->value();
57 }
58
59 double GeomData_Point::y() const
60 {
61   return myExpression[1]->value();
62 }
63
64 double GeomData_Point::z() const
65 {
66   return myExpression[2]->value();
67 }
68
69 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
70 {
71   std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
72   return aResult;
73 }
74
75 void GeomData_Point::setText(const std::string& theX,
76                              const std::string& theY,
77                              const std::string& theZ)
78 {
79   if (!myIsInitialized || textX() != theX || textY() != theY || textZ() != theZ) {
80     myExpression[0]->setText(theX);
81     myExpression[1]->setText(theY);
82     myExpression[2]->setText(theZ);
83     // Send it to evaluator to convert into the double and store in the attribute
84     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
85     owner()->data()->sendAttributeUpdated(this);
86   }
87 }
88
89 std::string GeomData_Point::textX()
90 {
91   return myExpression[0]->text();
92 }
93 std::string GeomData_Point::textY()
94 {
95   return myExpression[1]->text();
96 }
97 std::string GeomData_Point::textZ()
98 {
99   return myExpression[2]->text();
100 }
101
102 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
103 {
104   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
105   if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
106     myExpression[theComponent]->setInvalid(theFlag);
107 }
108
109 bool GeomData_Point::expressionInvalid(int theComponent)
110 {
111   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
112   return myExpression[theComponent]->isInvalid();
113 }
114
115 void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
116 {
117   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
118   if (expressionError(theComponent) != theError)
119     myExpression[theComponent]->setError(theError);
120 }
121
122 std::string GeomData_Point::expressionError(int theComponent)
123 {
124   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
125   return myExpression[theComponent]->error();
126 }
127
128 void GeomData_Point::setUsedParameters(int theComponent,
129                                        const std::set<std::string>& theUsedParameters)
130 {
131   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
132   myExpression[theComponent]->setUsedParameters(theUsedParameters);
133 }
134
135 std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
136 {
137   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
138   return myExpression[theComponent]->usedParameters();
139 }