Salome HOME
Meet the coding style (line length <= 100)
[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::reinit()
24 {
25   myIsInitialized = true;
26   for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
27     myExpression[aComponent]->reinit();
28     myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
29   }
30 }
31
32 void GeomData_Point2D::reset()
33 {
34   myIsInitialized = false;
35   for(int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
36     myExpression[aComponent]->reset();
37   }
38 }
39
40 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
41 {
42   if (!myIsInitialized || x() != theX || y() != theY) {
43     myExpression[0]->setValue(theX);
44     myExpression[1]->setValue(theY);
45     owner()->data()->sendAttributeUpdated(this);
46   }
47 }
48
49 void GeomData_Point2D::setValue(const double theX, const double theY)
50 {
51   setCalculatedValue(textX().empty() ? theX : x(),
52                      textY().empty() ? theY : y());
53 }
54
55 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
56 {
57   setValue(thePoint->x(), thePoint->y());
58 }
59
60 double GeomData_Point2D::x() const
61 {
62   return myExpression[0]->value();
63 }
64
65 double GeomData_Point2D::y() const
66 {
67   return myExpression[1]->value();
68 }
69
70 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
71 {
72   std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
73   return aResult;
74 }
75
76 void GeomData_Point2D::setText(const std::string& theX,
77                                const std::string& theY)
78 {
79   if (!myIsInitialized && theX.empty() && theY.empty())
80     return; // empty strings are not good initializers
81   if (!myIsInitialized || textX() != theX || textY() != theY) {
82     myExpression[0]->setText(theX);
83     myExpression[1]->setText(theY);
84     // Send it to evaluator to convert into the double and store in the attribute
85     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
86     owner()->data()->sendAttributeUpdated(this);
87   }
88 }
89
90 std::string GeomData_Point2D::textX()
91 {
92   return myExpression[0]->text();
93 }
94 std::string GeomData_Point2D::textY()
95 {
96   return myExpression[1]->text();
97 }
98
99 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
100 {
101   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
102   if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
103     myExpression[theComponent]->setInvalid(theFlag);
104 }
105
106 bool GeomData_Point2D::expressionInvalid(int theComponent)
107 {
108   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
109   return myExpression[theComponent]->isInvalid();
110 }
111
112 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
113 {
114   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
115   if (expressionError(theComponent) != theError)
116     myExpression[theComponent]->setError(theError);
117 }
118
119 std::string GeomData_Point2D::expressionError(int theComponent)
120 {
121   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
122   return myExpression[theComponent]->error();
123 }
124
125 void GeomData_Point2D::setUsedParameters(int theComponent,
126                                          const std::set<std::string>& theUsedParameters)
127 {
128   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
129   myExpression[theComponent]->setUsedParameters(theUsedParameters);
130 }
131
132 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
133 {
134   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
135   return myExpression[theComponent]->usedParameters();
136 }