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(TDF_Label& theLabel)
20 myIsInitialized = true;
23 void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
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);
33 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
35 setCalculatedValue(textX().empty() ? theX : x(),
36 textY().empty() ? theY : y(),
37 textZ().empty() ? theZ : z());
40 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
42 setValue(thePoint->x(), thePoint->y(), thePoint->z());
45 double GeomData_Point::x() const
47 return myExpression[0]->value();
50 double GeomData_Point::y() const
52 return myExpression[1]->value();
55 double GeomData_Point::z() const
57 return myExpression[2]->value();
60 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
62 std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
66 void GeomData_Point::setText(const std::string& theX,
67 const std::string& theY,
68 const std::string& theZ)
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);
80 std::string GeomData_Point::textX()
82 return myExpression[0]->text();
84 std::string GeomData_Point::textY()
86 return myExpression[1]->text();
88 std::string GeomData_Point::textZ()
90 return myExpression[2]->text();
93 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
95 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
96 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
97 myExpression[theComponent]->setInvalid(theFlag);
100 bool GeomData_Point::expressionInvalid(int theComponent)
102 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
103 return myExpression[theComponent]->isInvalid();
106 void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
108 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
109 if (expressionError(theComponent) != theError)
110 myExpression[theComponent]->setError(theError);
113 std::string GeomData_Point::expressionError(int theComponent)
115 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
116 return myExpression[theComponent]->error();
119 void GeomData_Point::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
121 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
122 myExpression[theComponent]->setUsedParameters(theUsedParameters);
125 std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
127 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
128 return myExpression[theComponent]->usedParameters();