Salome HOME
8b6116b63e51cf7fd7e019d5088cd291119c562b
[modules/shaper.git] / src / GeomData / GeomData_Point2D.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomData_Point2D.cxx
4 // Created:     24 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "GeomData_Point2D.h"
8
9 #include <GeomAPI_Pnt2d.h>
10
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_Events.h>
13 #include <ModelAPI_Expression.h>
14 #include <ModelAPI_Feature.h>
15
16 #include <cassert>
17
18 GeomData_Point2D::GeomData_Point2D()
19 {
20   myIsInitialized = false;
21 }
22
23 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
24 {
25   if (!myIsInitialized || x() != theX || y() != theY) {
26     myExpression[0]->setValue(theX);
27     myExpression[1]->setValue(theY);
28     owner()->data()->sendAttributeUpdated(this);
29   }
30 }
31
32 void GeomData_Point2D::setValue(const double theX, const double theY)
33 {
34   setCalculatedValue(textX().empty() ? theX : x(),
35                      textY().empty() ? theY : y());
36 }
37
38 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
39 {
40   setValue(thePoint->x(), thePoint->y());
41 }
42
43 double GeomData_Point2D::x() const
44 {
45   return myExpression[0]->value();
46 }
47
48 double GeomData_Point2D::y() const
49 {
50   return myExpression[1]->value();
51 }
52
53 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
54 {
55   std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
56   return aResult;
57 }
58
59 void GeomData_Point2D::setText(const std::string& theX,
60                                const std::string& theY)
61 {
62   if (!myIsInitialized && theX.empty() && theY.empty())
63     return; // empty strings are not good initializers
64   if (!myIsInitialized || textX() != theX || textY() != theY) {
65     myExpression[0]->setText(theX);
66     myExpression[1]->setText(theY);
67     // Send it to evaluator to convert into the double and store in the attribute
68     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
69     owner()->data()->sendAttributeUpdated(this);
70   }
71 }
72
73 std::string GeomData_Point2D::textX()
74 {
75   return myExpression[0]->text();
76 }
77 std::string GeomData_Point2D::textY()
78 {
79   return myExpression[1]->text();
80 }
81
82 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
83 {
84   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
85   if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
86     myExpression[theComponent]->setInvalid(theFlag);
87 }
88
89 bool GeomData_Point2D::expressionInvalid(int theComponent)
90 {
91   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
92   return myExpression[theComponent]->isInvalid();
93 }
94
95 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
96 {
97   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
98   if (expressionError(theComponent) != theError)
99     myExpression[theComponent]->setError(theError);
100 }
101
102 std::string GeomData_Point2D::expressionError(int theComponent)
103 {
104   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
105   return myExpression[theComponent]->error();
106 }
107
108 void GeomData_Point2D::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
109 {
110   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
111   myExpression[theComponent]->setUsedParameters(theUsedParameters);
112 }
113
114 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
115 {
116   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
117   return myExpression[theComponent]->usedParameters();
118 }