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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomData_Point.h"
23 #include <GeomAPI_Pnt.h>
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_Expression.h>
28 #include <ModelAPI_Feature.h>
32 GeomData_Point::GeomData_Point()
34 myIsInitialized = false;
37 void GeomData_Point::reinit()
39 myIsInitialized = true;
40 for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
41 myExpression[aComponent]->reinit();
42 myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
46 void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
48 if (!myIsInitialized || x() != theX || y() != theY || z() != theZ) {
49 myExpression[0]->setValue(theX);
50 myExpression[1]->setValue(theY);
51 myExpression[2]->setValue(theZ);
52 owner()->data()->sendAttributeUpdated(this);
56 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
58 setCalculatedValue(textX().empty() ? theX : x(),
59 textY().empty() ? theY : y(),
60 textZ().empty() ? theZ : z());
63 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
65 setValue(thePoint->x(), thePoint->y(), thePoint->z());
68 double GeomData_Point::x() const
70 return myExpression[0]->value();
73 double GeomData_Point::y() const
75 return myExpression[1]->value();
78 double GeomData_Point::z() const
80 return myExpression[2]->value();
83 void GeomData_Point::setX(const double theX)
85 if (!myIsInitialized) {
86 setCalculatedValue(theX, 0, 0);
87 } else if (x() != theX) {
88 myExpression[0]->setValue(theX);
89 owner()->data()->sendAttributeUpdated(this);
93 void GeomData_Point::setY(const double theY)
95 if (!myIsInitialized) {
96 setCalculatedValue(0, theY, 0);
97 } else if (y() != theY) {
98 myExpression[1]->setValue(theY);
99 owner()->data()->sendAttributeUpdated(this);
103 void GeomData_Point::setZ(const double theZ)
105 if (!myIsInitialized) {
106 setCalculatedValue(0, 0, theZ);
108 else if (z() != theZ) {
109 myExpression[2]->setValue(theZ);
110 owner()->data()->sendAttributeUpdated(this);
115 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
117 std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
121 void GeomData_Point::setText(const std::string& theX,
122 const std::string& theY,
123 const std::string& theZ)
125 if (!myIsInitialized || textX() != theX || textY() != theY || textZ() != theZ) {
126 myExpression[0]->setText(theX);
127 myExpression[1]->setText(theY);
128 myExpression[2]->setText(theZ);
129 // Send it to evaluator to convert into the double and store in the attribute
130 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
131 owner()->data()->sendAttributeUpdated(this);
135 void GeomData_Point::setTextX(const std::string& theX)
137 if (!myIsInitialized) {
138 static const std::string aDefaultText = "0";
139 setText(theX, aDefaultText, aDefaultText);
141 else if (textX() != theX) {
142 myExpression[0]->setText(theX);
143 // Send it to evaluator to convert into the double and store in the attribute
144 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
145 owner()->data()->sendAttributeUpdated(this);
149 void GeomData_Point::setTextY(const std::string& theY)
151 if (!myIsInitialized) {
152 static const std::string aDefaultText = "0";
153 setText(aDefaultText, theY, aDefaultText);
155 else if (textY() != theY) {
156 myExpression[1]->setText(theY);
157 // Send it to evaluator to convert into the double and store in the attribute
158 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
159 owner()->data()->sendAttributeUpdated(this);
163 void GeomData_Point::setTextZ(const std::string& theZ)
165 if (!myIsInitialized) {
166 static const std::string aDefaultText = "0";
167 setText(aDefaultText, aDefaultText, theZ);
169 else if (textZ() != theZ) {
170 myExpression[2]->setText(theZ);
171 // Send it to evaluator to convert into the double and store in the attribute
172 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
173 owner()->data()->sendAttributeUpdated(this);
177 std::string GeomData_Point::textX()
179 return myExpression[0]->text();
181 std::string GeomData_Point::textY()
183 return myExpression[1]->text();
185 std::string GeomData_Point::textZ()
187 return myExpression[2]->text();
190 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
192 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
193 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
194 myExpression[theComponent]->setInvalid(theFlag);
197 bool GeomData_Point::expressionInvalid(int theComponent)
199 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
200 return myExpression[theComponent]->isInvalid();
203 void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
205 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
206 if (expressionError(theComponent) != theError)
207 myExpression[theComponent]->setError(theError);
210 std::string GeomData_Point::expressionError(int theComponent)
212 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
213 return myExpression[theComponent]->error();
216 void GeomData_Point::setUsedParameters(int theComponent,
217 const std::set<std::string>& theUsedParameters)
219 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
220 myExpression[theComponent]->setUsedParameters(theUsedParameters);
223 std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
225 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
226 return myExpression[theComponent]->usedParameters();