From: Sergey POKHODENKO Date: Tue, 26 May 2015 07:18:07 +0000 (+0300) Subject: Create text representation of components X, Y, Z for Point & Point2D X-Git-Tag: V_1.2.0~87 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b719c47b37c8dde30c075260dd1457d8f8a00f72;p=modules%2Fshaper.git Create text representation of components X, Y, Z for Point & Point2D --- diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index 2a2f52d80..e76498c00 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -49,11 +49,67 @@ std::shared_ptr GeomData_Point::pnt() return aResult; } +void GeomData_Point::setText(const std::string& theX, + const std::string& theY, + const std::string& theZ) +{ + TCollection_ExtendedString aX(theX.c_str()); + TCollection_ExtendedString aY(theY.c_str()); + TCollection_ExtendedString aZ(theZ.c_str()); + + if (!myIsInitialized || + myTextArray->Value(0) != aX || + myTextArray->Value(1) != aY || + myTextArray->Value(2) != aZ) { + myTextArray->SetValue(0, aX); + myTextArray->SetValue(1, aY); + myTextArray->SetValue(2, aZ); + owner()->data()->sendAttributeUpdated(this); + } +} + +std::string GeomData_Point::textX() +{ + return TCollection_AsciiString(myTextArray->Value(0)).ToCString();; +} +std::string GeomData_Point::textY() +{ + return TCollection_AsciiString(myTextArray->Value(1)).ToCString();; +} +std::string GeomData_Point::textZ() +{ + return TCollection_AsciiString(myTextArray->Value(2)).ToCString();; +} + +void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag) +{ + if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) { + myExpressionInvalidArray->SetValue(theComponent, theFlag); + } +} + +bool GeomData_Point::expressionInvalid(int theComponent) +{ + return myExpressionInvalidArray->Value(theComponent); +} + GeomData_Point::GeomData_Point(TDF_Label& theLabel) { - myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True; - if (!myIsInitialized) { + myIsInitialized = true; + + if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) { // create attribute: not initialized by value yet, just zero myCoords = TDataStd_RealArray::Set(theLabel, 0, 2); + myIsInitialized = false; + } + if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) { + // create attribute: not initialized by value yet, just zero + myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 2); + myIsInitialized = false; + } + if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) { + // create attribute: not initialized by value yet, just zero + myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 2); + myIsInitialized = false; } } diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index d4b715ac4..8a0fb83aa 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -10,6 +10,8 @@ #include "GeomData.h" #include "GeomDataAPI_Point.h" #include +#include +#include #include /**\class GeomData_Point @@ -20,6 +22,8 @@ class GeomData_Point : public GeomDataAPI_Point { Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2] + Handle_TDataStd_ExtStringArray myTextArray; ///< Text representation of the X, Y and Z attributes [0; 2] + Handle_TDataStd_BooleanArray myExpressionInvalidArray; ///< Flag of invalid expression of the X, Y and Z attributes [0; 2] public: /// Defines the double value GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ); @@ -35,6 +39,24 @@ class GeomData_Point : public GeomDataAPI_Point /// Returns the 3D point GEOMDATA_EXPORT virtual std::shared_ptr pnt(); + /// Defines the text values + GEOMDATA_EXPORT virtual void setText(const std::string& theX, + const std::string& theY, + const std::string& theZ); + + /// Returns the X text value + GEOMDATA_EXPORT virtual std::string textX(); + /// Returns the Y text value + GEOMDATA_EXPORT virtual std::string textY(); + /// Returns the Z text value + GEOMDATA_EXPORT virtual std::string textZ(); + + /// Allows to set expression (text) as invalid (by the parameters listener) + GEOMDATA_EXPORT virtual void setExpressionInvalid(int, bool theFlag); + + /// Returns true if text is invalid + GEOMDATA_EXPORT virtual bool expressionInvalid(int); + protected: /// Initializes attributes GEOMDATA_EXPORT GeomData_Point(TDF_Label& theLabel); diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 314a0ab79..bb1e6c519 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -42,11 +42,59 @@ std::shared_ptr GeomData_Point2D::pnt() return aResult; } +void GeomData_Point2D::setText(const std::string& theX, + const std::string& theY) +{ + TCollection_ExtendedString aX(theX.c_str()); + TCollection_ExtendedString aY(theY.c_str()); + + if (!myIsInitialized || + myTextArray->Value(0) != aX || + myTextArray->Value(1) != aY) { + myTextArray->SetValue(0, aX); + myTextArray->SetValue(1, aY); + owner()->data()->sendAttributeUpdated(this); + } +} + +std::string GeomData_Point2D::textX() +{ + return TCollection_AsciiString(myTextArray->Value(0)).ToCString();; +} +std::string GeomData_Point2D::textY() +{ + return TCollection_AsciiString(myTextArray->Value(1)).ToCString();; +} + +void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag) +{ + if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) { + myExpressionInvalidArray->SetValue(theComponent, theFlag); + } +} + +bool GeomData_Point2D::expressionInvalid(int theComponent) +{ + return myExpressionInvalidArray->Value(theComponent); +} + GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel) { - myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True; - if (!myIsInitialized) { + myIsInitialized = true; + + if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) { // create attribute: not initialized by value yet, just zero myCoords = TDataStd_RealArray::Set(theLabel, 0, 1); + myIsInitialized = false; + } + if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) { + // create attribute: not initialized by value yet, just zero + myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 1); + myIsInitialized = false; + } + if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) { + // create attribute: not initialized by value yet, just zero + myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 1); + myIsInitialized = false; } } diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h index 8363f9967..8a41a4c0c 100644 --- a/src/GeomData/GeomData_Point2D.h +++ b/src/GeomData/GeomData_Point2D.h @@ -10,6 +10,8 @@ #include "GeomData.h" #include "GeomDataAPI_Point2D.h" #include +#include +#include #include /**\class GeomData_Point2D @@ -20,6 +22,8 @@ class GeomData_Point2D : public GeomDataAPI_Point2D { Handle_TDataStd_RealArray myCoords; ///< X and Y doubles as real array attribute [0; 1] + Handle_TDataStd_ExtStringArray myTextArray; ///< Text representation of the X, Y and Z attributes [0; 2] + Handle_TDataStd_BooleanArray myExpressionInvalidArray; ///< Flag of invalid expression of the X, Y and Z attributes [0; 2] public: /// Defines the double value GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY); @@ -33,6 +37,20 @@ class GeomData_Point2D : public GeomDataAPI_Point2D /// Returns the 2D point GEOMDATA_EXPORT virtual std::shared_ptr pnt(); + /// Defines the double values + GEOMDATA_EXPORT virtual void setText(const std::string& theX, + const std::string& theY); + + /// Returns the double values + GEOMDATA_EXPORT virtual std::string textX(); + GEOMDATA_EXPORT virtual std::string textY(); + + /// Allows to set expression (text) as invalid (by the parameters listener) + GEOMDATA_EXPORT virtual void setExpressionInvalid(int, const bool theFlag); + + /// Returns true if text is invalid + GEOMDATA_EXPORT virtual bool expressionInvalid(int); + protected: /// Initializes attributes GEOMDATA_EXPORT GeomData_Point2D(TDF_Label& theLabel); diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index 245f9b0f8..9aedfd1df 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -34,6 +34,27 @@ class GeomDataAPI_Point : public ModelAPI_Attribute /// Returns the 3D point virtual std::shared_ptr pnt() = 0; + /// Defines the double values + virtual void setText(const std::string& theX, + const std::string& theY, + const std::string& theZ) = 0; + + /// Returns the double values + virtual std::string textX() = 0; + virtual std::string textY() = 0; + virtual std::string textZ() = 0; + + enum PointComponent { C_X = 0, + C_Y = 1, + C_Z = 2, + }; + + /// Allows to set expression (text) as invalid (by the parameters listener) + virtual void setExpressionInvalid(int theComponent, const bool theFlag) = 0; + + /// Returns true if text is invalid + virtual bool expressionInvalid(int theComponent) = 0; + /// Returns the type of this class of attributes static std::string typeId() { diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h index 3c67bec90..459185ce7 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point2D.h +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.h @@ -32,6 +32,24 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute /// Returns the 2D point virtual std::shared_ptr pnt() = 0; + /// Defines the double values + virtual void setText(const std::string& theX, + const std::string& theY) = 0; + + /// Returns the double values + virtual std::string textX() = 0; + virtual std::string textY() = 0; + + enum PointComponent { C_X = 0, + C_Y = 1, + }; + + /// Allows to set expression (text) as invalid (by the parameters listener) + virtual void setExpressionInvalid(int theComponent, const bool theFlag) = 0; + + /// Returns true if text is invalid + virtual bool expressionInvalid(int theComponent) = 0; + /// Appends the delta values to point GEOMDATAAPI_EXPORT void move(const double theDeltaX, const double theDeltaY);