1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "GeomData_Point.h"
22 #include <GeomAPI_Pnt.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Events.h>
26 #include <ModelAPI_Expression.h>
27 #include <ModelAPI_Feature.h>
31 GeomData_Point::GeomData_Point()
33 myIsInitialized = false;
36 void GeomData_Point::reinit()
38 myIsInitialized = true;
39 for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
40 myExpression[aComponent]->reinit();
41 myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
45 void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
47 if (!myIsInitialized || x() != theX || y() != theY || z() != theZ) {
48 myExpression[0]->setValue(theX);
49 myExpression[1]->setValue(theY);
50 myExpression[2]->setValue(theZ);
51 owner()->data()->sendAttributeUpdated(this);
55 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
57 setCalculatedValue(textX().empty() ? theX : x(),
58 textY().empty() ? theY : y(),
59 textZ().empty() ? theZ : z());
62 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
64 setValue(thePoint->x(), thePoint->y(), thePoint->z());
67 double GeomData_Point::x() const
69 return myExpression[0]->value();
72 double GeomData_Point::y() const
74 return myExpression[1]->value();
77 double GeomData_Point::z() const
79 return myExpression[2]->value();
82 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
84 std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
88 void GeomData_Point::setText(const std::string& theX,
89 const std::string& theY,
90 const std::string& theZ)
92 if (!myIsInitialized || textX() != theX || textY() != theY || textZ() != theZ) {
93 myExpression[0]->setText(theX);
94 myExpression[1]->setText(theY);
95 myExpression[2]->setText(theZ);
96 // Send it to evaluator to convert into the double and store in the attribute
97 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
98 owner()->data()->sendAttributeUpdated(this);
102 std::string GeomData_Point::textX()
104 return myExpression[0]->text();
106 std::string GeomData_Point::textY()
108 return myExpression[1]->text();
110 std::string GeomData_Point::textZ()
112 return myExpression[2]->text();
115 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
117 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
118 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
119 myExpression[theComponent]->setInvalid(theFlag);
122 bool GeomData_Point::expressionInvalid(int theComponent)
124 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
125 return myExpression[theComponent]->isInvalid();
128 void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
130 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
131 if (expressionError(theComponent) != theError)
132 myExpression[theComponent]->setError(theError);
135 std::string GeomData_Point::expressionError(int theComponent)
137 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
138 return myExpression[theComponent]->error();
141 void GeomData_Point::setUsedParameters(int theComponent,
142 const std::set<std::string>& theUsedParameters)
144 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
145 myExpression[theComponent]->setUsedParameters(theUsedParameters);
148 std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
150 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
151 return myExpression[theComponent]->usedParameters();