1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomData_Point.cxx
4 // Created: 24 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include "GeomData_Point.h"
9 #include <GeomAPI_Pnt.h>
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_Events.h>
13 #include <ModelAPI_Expression.h>
14 #include <ModelAPI_Feature.h>
18 GeomData_Point::GeomData_Point()
20 myIsInitialized = false;
23 void GeomData_Point::reinit()
25 myIsInitialized = true;
26 for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
27 myExpression[aComponent]->reinit();
28 myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
32 void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
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);
42 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
44 setCalculatedValue(textX().empty() ? theX : x(),
45 textY().empty() ? theY : y(),
46 textZ().empty() ? theZ : z());
49 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
51 setValue(thePoint->x(), thePoint->y(), thePoint->z());
54 double GeomData_Point::x() const
56 return myExpression[0]->value();
59 double GeomData_Point::y() const
61 return myExpression[1]->value();
64 double GeomData_Point::z() const
66 return myExpression[2]->value();
69 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
71 std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
75 void GeomData_Point::setText(const std::string& theX,
76 const std::string& theY,
77 const std::string& theZ)
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);
89 std::string GeomData_Point::textX()
91 return myExpression[0]->text();
93 std::string GeomData_Point::textY()
95 return myExpression[1]->text();
97 std::string GeomData_Point::textZ()
99 return myExpression[2]->text();
102 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
104 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
105 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
106 myExpression[theComponent]->setInvalid(theFlag);
109 bool GeomData_Point::expressionInvalid(int theComponent)
111 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
112 return myExpression[theComponent]->isInvalid();
115 void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
117 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
118 if (expressionError(theComponent) != theError)
119 myExpression[theComponent]->setError(theError);
122 std::string GeomData_Point::expressionError(int theComponent)
124 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
125 return myExpression[theComponent]->error();
128 void GeomData_Point::setUsedParameters(int theComponent,
129 const std::set<std::string>& theUsedParameters)
131 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
132 myExpression[theComponent]->setUsedParameters(theUsedParameters);
135 std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
137 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
138 return myExpression[theComponent]->usedParameters();