Salome HOME
Create text representation of components X, Y, Z for Point & Point2D
authorSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 26 May 2015 07:18:07 +0000 (10:18 +0300)
committerSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 26 May 2015 07:35:37 +0000 (10:35 +0300)
src/GeomData/GeomData_Point.cpp
src/GeomData/GeomData_Point.h
src/GeomData/GeomData_Point2D.cpp
src/GeomData/GeomData_Point2D.h
src/GeomDataAPI/GeomDataAPI_Point.h
src/GeomDataAPI/GeomDataAPI_Point2D.h

index 2a2f52d80ea3e2b93de5f66eb0dd9cb6b9e19be6..e76498c00db8fbfcd830d8bfa98fbc7f918685f6 100644 (file)
@@ -49,11 +49,67 @@ std::shared_ptr<GeomAPI_Pnt> 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;
   }
 }
index d4b715ac43a86418b9f94b746b1a1efe52ff8d61..8a0fb83aa438b26b071eb92f77d749b04722bf6e 100644 (file)
@@ -10,6 +10,8 @@
 #include "GeomData.h"
 #include "GeomDataAPI_Point.h"
 #include <TDataStd_RealArray.hxx>
+#include <TDataStd_ExtStringArray.hxx>
+#include <TDataStd_BooleanArray.hxx>
 #include <TDF_Label.hxx>
 
 /**\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<GeomAPI_Pnt> 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);
index 314a0ab79468c6d545e651dcdfa2a70b963b3ac2..bb1e6c51981a269bce373b477e6cbced83efc7fa 100644 (file)
@@ -42,11 +42,59 @@ std::shared_ptr<GeomAPI_Pnt2d> 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;
   }
 }
index 8363f99670fdb47bdd70b829dfd690b277785f7c..8a41a4c0c5056613619939b2bd0aabcebd914204 100644 (file)
@@ -10,6 +10,8 @@
 #include "GeomData.h"
 #include "GeomDataAPI_Point2D.h"
 #include <TDataStd_RealArray.hxx>
+#include <TDataStd_ExtStringArray.hxx>
+#include <TDataStd_BooleanArray.hxx>
 #include <TDF_Label.hxx>
 
 /**\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<GeomAPI_Pnt2d> 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);
index 245f9b0f80c65732e8647226c8297493a8f54d71..9aedfd1df1a27a992c4a07328cea9aae979bc3d1 100644 (file)
@@ -34,6 +34,27 @@ class GeomDataAPI_Point : public ModelAPI_Attribute
   /// Returns the 3D point
   virtual std::shared_ptr<GeomAPI_Pnt> 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()
   {
index 3c67bec90d85c9e7a39cd68156b76c2db745c349..459185ce7a452269d561b39bb9f64865a44916ff 100644 (file)
@@ -32,6 +32,24 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute
   /// Returns the 2D point
   virtual std::shared_ptr<GeomAPI_Pnt2d> 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);