Salome HOME
Task "Make the size of the selection area even bigger, especially for points"
[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 || textX() != theX || textY() != theY) {
63     myExpression[0]->setText(theX);
64     myExpression[1]->setText(theY);
65     // Send it to evaluator to convert into the double and store in the attribute
66     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
67     owner()->data()->sendAttributeUpdated(this);
68   }
69 }
70
71 std::string GeomData_Point2D::textX()
72 {
73   return myExpression[0]->text();
74 }
75 std::string GeomData_Point2D::textY()
76 {
77   return myExpression[1]->text();
78 }
79
80 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
81 {
82   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
83   if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
84     myExpression[theComponent]->setInvalid(theFlag);
85 }
86
87 bool GeomData_Point2D::expressionInvalid(int theComponent)
88 {
89   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
90   return myExpression[theComponent]->isInvalid();
91 }
92
93 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
94 {
95   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
96   if (expressionError(theComponent) != theError)
97     myExpression[theComponent]->setError(theError);
98 }
99
100 std::string GeomData_Point2D::expressionError(int theComponent)
101 {
102   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
103   return myExpression[theComponent]->error();
104 }
105
106 void GeomData_Point2D::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
107 {
108   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
109   myExpression[theComponent]->setUsedParameters(theUsedParameters);
110 }
111
112 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
113 {
114   assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
115   return myExpression[theComponent]->usedParameters();
116 }