]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomData/GeomData_Point.cpp
Salome HOME
ef48bfc28f0a1d85263cfb98adf73f3f700bc246
[modules/shaper.git] / src / GeomData / GeomData_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomData_Point.cxx
4 // Created:     24 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "GeomData_Point.h"
8 #include <GeomAPI_Pnt.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Events.h>
12
13 using namespace std;
14
15 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
16 {
17   if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY
18       || myCoords->Value(2) != theZ) {
19     myCoords->SetValue(0, theX);
20     myCoords->SetValue(1, theY);
21     myCoords->SetValue(2, theZ);
22     owner()->data()->sendAttributeUpdated(this);
23   }
24 }
25
26 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
27 {
28   setValue(thePoint->x(), thePoint->y(), thePoint->z());
29 }
30
31 double GeomData_Point::x() const
32 {
33   return myCoords->Value(0);
34 }
35
36 double GeomData_Point::y() const
37 {
38   return myCoords->Value(1);
39 }
40
41 double GeomData_Point::z() const
42 {
43   return myCoords->Value(2);
44 }
45
46 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
47 {
48   std::shared_ptr<GeomAPI_Pnt> aResult(
49       new GeomAPI_Pnt(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
50   return aResult;
51 }
52
53 void GeomData_Point::setText(const std::string& theX,
54                              const std::string& theY,
55                              const std::string& theZ)
56 {
57   TCollection_ExtendedString aX(theX.c_str());
58   TCollection_ExtendedString aY(theY.c_str());
59   TCollection_ExtendedString aZ(theZ.c_str());
60
61   if (!myIsInitialized ||
62       myTextArray->Value(0) != aX ||
63       myTextArray->Value(1) != aY ||
64       myTextArray->Value(2) != aZ) {
65     myTextArray->SetValue(0, aX);
66     myTextArray->SetValue(1, aY);
67     myTextArray->SetValue(2, aZ);
68     owner()->data()->sendAttributeUpdated(this);
69     // Send it to evaluator to convert into the double and store in the attribute
70     static Events_ID anId = ModelAPI_AttributeEvalMessage::eventId();
71     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
72       std::shared_ptr<ModelAPI_AttributeEvalMessage>(new ModelAPI_AttributeEvalMessage(anId, this));
73     aMessage->setAttribute(owner()->data()->attribute(id())); // to get shared pointer to this
74     Events_Loop::loop()->send(aMessage);
75   }
76 }
77
78 std::string GeomData_Point::textX()
79 {
80   return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
81 }
82 std::string GeomData_Point::textY()
83 {
84   return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
85 }
86 std::string GeomData_Point::textZ()
87 {
88   return TCollection_AsciiString(myTextArray->Value(2)).ToCString();;
89 }
90
91 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
92 {
93   if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
94     myExpressionInvalidArray->SetValue(theComponent, theFlag);
95   }
96 }
97
98 bool GeomData_Point::expressionInvalid(int theComponent)
99 {
100   return myExpressionInvalidArray->Value(theComponent);
101 }
102
103 GeomData_Point::GeomData_Point(TDF_Label& theLabel)
104 {
105   myIsInitialized = true;
106
107   if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
108     // create attribute: not initialized by value yet, just zero
109     myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
110     myIsInitialized = false;
111   }
112   if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
113     // create attribute: not initialized by value yet, just zero
114     myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 2);
115     myIsInitialized = false;
116   }
117   if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
118     // create attribute: not initialized by value yet, just zero
119     myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 2);
120     myIsInitialized = false;
121   }
122 }