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_Point2D.h"
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_Expression.h>
28 #include <ModelAPI_Feature.h>
32 GeomData_Point2D::GeomData_Point2D()
34 myIsInitialized = false;
37 void GeomData_Point2D::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_Point2D::reset()
48 myIsInitialized = false;
49 for(int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
50 myExpression[aComponent]->reset();
54 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
56 if (!myIsInitialized || x() != theX || y() != theY) {
57 myExpression[0]->setValue(theX);
58 myExpression[1]->setValue(theY);
59 owner()->data()->sendAttributeUpdated(this);
63 void GeomData_Point2D::setValue(const double theX, const double theY)
65 setCalculatedValue(textX().empty() ? theX : x(),
66 textY().empty() ? theY : y());
69 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
71 setValue(thePoint->x(), thePoint->y());
74 double GeomData_Point2D::x() const
76 return myExpression[0]->value();
79 double GeomData_Point2D::y() const
81 return myExpression[1]->value();
84 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
86 std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
90 void GeomData_Point2D::setText(const std::string& theX,
91 const std::string& theY)
93 if (!myIsInitialized && theX.empty() && theY.empty())
94 return; // empty strings are not good initializers
95 if (!myIsInitialized || textX() != theX || textY() != theY) {
96 myExpression[0]->setText(theX);
97 myExpression[1]->setText(theY);
98 // Send it to evaluator to convert into the double and store in the attribute
99 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
100 owner()->data()->sendAttributeUpdated(this);
104 std::string GeomData_Point2D::textX()
106 return myExpression[0]->text();
108 std::string GeomData_Point2D::textY()
110 return myExpression[1]->text();
113 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
115 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
116 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
117 myExpression[theComponent]->setInvalid(theFlag);
120 bool GeomData_Point2D::expressionInvalid(int theComponent)
122 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
123 return myExpression[theComponent]->isInvalid();
126 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
128 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
129 if (expressionError(theComponent) != theError)
130 myExpression[theComponent]->setError(theError);
133 std::string GeomData_Point2D::expressionError(int theComponent)
135 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
136 return myExpression[theComponent]->error();
139 void GeomData_Point2D::setUsedParameters(int theComponent,
140 const std::set<std::string>& theUsedParameters)
142 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
143 myExpression[theComponent]->setUsedParameters(theUsedParameters);
146 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
148 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
149 return myExpression[theComponent]->usedParameters();