]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomData/GeomData_Point2D.cpp
Salome HOME
Create text representation of components X, Y, Z for Point & Point2D
[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 #include <GeomAPI_Pnt2d.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Data.h>
11
12 using namespace std;
13
14 void GeomData_Point2D::setValue(const double theX, const double theY)
15 {
16   if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY) {
17     myCoords->SetValue(0, theX);
18     myCoords->SetValue(1, theY);
19     owner()->data()->sendAttributeUpdated(this);
20   }
21 }
22
23 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
24 {
25   setValue(thePoint->x(), thePoint->y());
26 }
27
28 double GeomData_Point2D::x() const
29 {
30   return myCoords->Value(0);
31 }
32
33 double GeomData_Point2D::y() const
34 {
35   return myCoords->Value(1);
36 }
37
38 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
39 {
40   std::shared_ptr<GeomAPI_Pnt2d> aResult(
41       new GeomAPI_Pnt2d(myCoords->Value(0), myCoords->Value(1)));
42   return aResult;
43 }
44
45 void GeomData_Point2D::setText(const std::string& theX,
46                                const std::string& theY)
47 {
48   TCollection_ExtendedString aX(theX.c_str());
49   TCollection_ExtendedString aY(theY.c_str());
50
51   if (!myIsInitialized ||
52       myTextArray->Value(0) != aX ||
53       myTextArray->Value(1) != aY) {
54     myTextArray->SetValue(0, aX);
55     myTextArray->SetValue(1, aY);
56     owner()->data()->sendAttributeUpdated(this);
57   }
58 }
59
60 std::string GeomData_Point2D::textX()
61 {
62   return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
63 }
64 std::string GeomData_Point2D::textY()
65 {
66   return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
67 }
68
69 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
70 {
71   if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
72     myExpressionInvalidArray->SetValue(theComponent, theFlag);
73   }
74 }
75
76 bool GeomData_Point2D::expressionInvalid(int theComponent)
77 {
78   return myExpressionInvalidArray->Value(theComponent);
79 }
80
81 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
82 {
83   myIsInitialized = true;
84
85   if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
86     // create attribute: not initialized by value yet, just zero
87     myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
88     myIsInitialized = false;
89   }
90   if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
91     // create attribute: not initialized by value yet, just zero
92     myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 1);
93     myIsInitialized = false;
94   }
95   if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
96     // create attribute: not initialized by value yet, just zero
97     myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 1);
98     myIsInitialized = false;
99   }
100 }