Salome HOME
workaround for bug #16280 / #1514: tolerance for nodes on the border fixed to 0.01...
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.h
index d7ad12cb87b89ff03442f9c73996c515efb2ddfb..2396654f6623f463f049d5b2069229627b742ec5 100644 (file)
 #include <NCollection_Sequence.hxx>
 #include <TDF_Label.hxx>
 #include <QMap>
+#include <QString>
+#include <Standard_Type.hxx>
+
+
+#ifdef NONLS
+#undef NONLS
+#endif
+
+#ifdef NOMINMAX
+#undef NOMINMAX
+#endif
 
 class QColor;
-class QString;
 class QVariant;
 class QStringList;
-class Handle(TDataStd_ReferenceList);
-class Handle_HYDROData_Entity;
+class TDataStd_ReferenceList;
+class HYDROData_Entity;
 class TopoDS_Shape;
 
 ///! Kind of an object in a document
 typedef int ObjectKind;
 
-const ObjectKind KIND_UNKNOWN           = 0; ///! Unrecognized object
-const ObjectKind KIND_IMAGE             = 1;
-const ObjectKind KIND_POLYLINE          = 2;
-const ObjectKind KIND_BATHYMETRY        = 3;
-const ObjectKind KIND_ALTITUDE          = 4;
-const ObjectKind KIND_IMMERSIBLE_ZONE   = 5;
-const ObjectKind KIND_RIVER             = 6;
-const ObjectKind KIND_STREAM            = 7;
-const ObjectKind KIND_CONFLUENCE        = 8;
-const ObjectKind KIND_CHANNEL           = 9;
-const ObjectKind KIND_OBSTACLE          = 10;
-const ObjectKind KIND_DIGUE             = 11;
-const ObjectKind KIND_PROFILE           = 12;
-const ObjectKind KIND_PROFILEUZ         = 13;
-const ObjectKind KIND_POLYLINEXY        = 14;
-const ObjectKind KIND_CALCULATION       = 15;
-const ObjectKind KIND_ZONE              = 16;
-const ObjectKind KIND_REGION            = 17;
-const ObjectKind KIND_VISUAL_STATE      = 18;
-const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
-const ObjectKind KIND_NATURAL_OBJECT    = 20;
-const ObjectKind KIND_DUMMY_3D          = 21;
-const ObjectKind KIND_SHAPES_GROUP      = 22;
-const ObjectKind KIND_SPLITTED_GROUP    = 23;
-const ObjectKind KIND_STREAM_ALTITUDE   = 24;
-const ObjectKind KIND_OBSTACLE_ALTITUDE = 25;
-const ObjectKind KIND_STRICKLER_TABLE   = 26;
-const ObjectKind KIND_LAND_COVER        = 27;
-const ObjectKind KIND_LAND_COVER_MAP    = 28;
-const ObjectKind KIND_LAST              = KIND_LAND_COVER;
-
-DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
+const ObjectKind KIND_UNKNOWN             = 0; ///! Unrecognized object
+const ObjectKind KIND_IMAGE               = 1;
+const ObjectKind KIND_POLYLINE            = 2;
+const ObjectKind KIND_BATHYMETRY          = 3;
+const ObjectKind KIND_ALTITUDE            = 4;
+const ObjectKind KIND_IMMERSIBLE_ZONE     = 5;
+const ObjectKind KIND_RIVER               = 6;
+const ObjectKind KIND_STREAM              = 7;
+const ObjectKind KIND_CONFLUENCE          = 8;
+const ObjectKind KIND_CHANNEL             = 9;
+const ObjectKind KIND_OBSTACLE            = 10;
+const ObjectKind KIND_DIGUE               = 11;
+const ObjectKind KIND_PROFILE             = 12;
+const ObjectKind KIND_PROFILEUZ           = 13;
+const ObjectKind KIND_POLYLINEXY          = 14;
+const ObjectKind KIND_CALCULATION         = 15;
+const ObjectKind KIND_ZONE                = 16;
+const ObjectKind KIND_REGION              = 17;
+const ObjectKind KIND_VISUAL_STATE        = 18;
+const ObjectKind KIND_ARTIFICIAL_OBJECT   = 19;
+const ObjectKind KIND_NATURAL_OBJECT      = 20;
+const ObjectKind KIND_DUMMY_3D            = 21;
+const ObjectKind KIND_SHAPES_GROUP        = 22;
+const ObjectKind KIND_SPLIT_GROUP         = 23;
+const ObjectKind KIND_STREAM_ALTITUDE     = 24;
+const ObjectKind KIND_OBSTACLE_ALTITUDE   = 25;
+const ObjectKind KIND_STRICKLER_TABLE     = 26;
+const ObjectKind KIND_LAND_COVER_OBSOLETE = 27;
+const ObjectKind KIND_CHANNEL_ALTITUDE    = 28;
+const ObjectKind KIND_LAND_COVER_MAP      = 29;
+const ObjectKind KIND_DTM                 = 30;
+const ObjectKind KIND_LAST                = KIND_DTM+1;
 
 class MapOfTreatedObjects : public QMap<QString,Handle(Standard_Transient)>
 {
 };
 
-class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle_HYDROData_Entity>
+class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle(HYDROData_Entity)>
 {
 public:
   HYDROData_SequenceOfObjects();
   HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& );
-  HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle_HYDROData_Entity>& );
+  HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle(HYDROData_Entity)>& );
 };
 
 ///! Is Equal for HYDROData_Entity mapping
-HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
+HYDRODATA_EXPORT bool IsEqual(const Handle(HYDROData_Entity)& theObj1, const Handle(HYDROData_Entity)& theObj2);
 
 /**\class HYDROData_Entity
  * \brief Generic class of any object in the data model.
@@ -92,9 +102,7 @@ HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Hand
  */
 class HYDROData_Entity : public MMgt_TShared
 {
-
 protected:
-
   /**
    * Enumeration of tags corresponding to the persistent object parameters.
    */
@@ -102,10 +110,28 @@ protected:
   {
     DataTag_First  = 0,     ///< first tag, to reserve
     DataTag_ZLevel,         ///< z-level of object presentation
+    DataTag_GeomChange,
+    DataTag_DefaultName,    ///< to keep the automatic name, useful in Python dump
+  };
+
+public:
+  enum Geometry
+  {
+    Geom_No = 1,
+    Geom_2d = 2,
+    Geom_Z  = 4,
+    Geom_Groups = 8,
+
+    Geom_3d = Geom_2d | Geom_Z,
+    Geom_2d_and_groups = Geom_2d | Geom_Groups,
+    Geom_All = Geom_3d | Geom_Groups | Geom_No,
   };
 
 public:
-  DEFINE_STANDARD_RTTI(HYDROData_Entity);
+  DEFINE_STANDARD_RTTIEXT(HYDROData_Entity, MMgt_TShared);
+
+  HYDRODATA_EXPORT static QString Type( ObjectKind );
+  HYDRODATA_EXPORT virtual QString GetType() const;
 
   /**
    * Returns the kind of this object. Must be redefined in all objects of known type.
@@ -117,10 +143,15 @@ public:
    */
   HYDRODATA_EXPORT virtual QString GetName() const;
 
+  /**
+   * Returns the default name of this object.
+   */
+  HYDRODATA_EXPORT virtual QString GetDefaultName() const;
+
   /**
    * Updates the name of this object.
    */
-  HYDRODATA_EXPORT virtual void SetName( const QString& theName );
+  HYDRODATA_EXPORT void SetName( const QString& theName, bool isDefault = false );
 
   /**
    * Returns the name of this object valid for Python script.
@@ -133,7 +164,8 @@ public:
    * You should reimplement this function in your derived class if it
    * has Python API and can be imported/exported from/to Python script.
    */
-  HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
+  HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
+                                                     MapOfTreatedObjects& theTreatedObjects ) const;
 
   /**
    * Updates object state. Base implementation dose nothing.
@@ -160,17 +192,11 @@ public:
   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
 
 
-  /**
-   * Sets the "MustBeUpdated" flag: if object is depended on updated features.
-   * \param theFlag is true for objects that must be updated, false for up-to-date
-   */
-  HYDRODATA_EXPORT virtual void SetToUpdate( bool theFlag );
 
-  /**
-   * Returns the "MustBeUpdated" flag: is object data must be updated or not
-   * \returns false if object is up to date
-   */
-  HYDRODATA_EXPORT virtual bool IsMustBeUpdated() const;
+  HYDRODATA_EXPORT virtual void ClearChanged();
+  HYDRODATA_EXPORT virtual void Changed( Geometry );
+
+  HYDRODATA_EXPORT bool IsMustBeUpdated( Geometry ) const;
 
   /**
    * Returns flag indicating that object is updateble or not.
@@ -228,7 +254,7 @@ public:
   /**
    * Returns the z-level for object presentation, -1 if no z-level.
    */
-  HYDRODATA_EXPORT virtual Standard_Boolean GetZLevel( Standard_Integer& theLevel ) const;
+  HYDRODATA_EXPORT virtual bool GetZLevel( Standard_Integer& theLevel ) const;
 
   /**
    * Set the z-level for object presentation.
@@ -241,14 +267,22 @@ public:
   HYDRODATA_EXPORT virtual void RemoveZLevel();
 
   /**
-    Find the Python object in the document by the object name.
-    @param theTreatedObjects the map of treated objects
+    Add in Python script the find instruction, to retrieve the Python object in the document by the object name.
     @param theScript the script
+    @param defName the name to use, if not default name.
   */
-  void findPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
-                                  QStringList&                    theScript ) const;
+  void findPythonReferenceObject( QStringList&                    theScript,
+                                  QString                         defName = QString()) const;
 
   /**
+    Add in Python script the set name instruction.
+    @param theScript the script
+    @param defName the name to use, if not default name.
+  */
+ void SetNameInDumpPython(QStringList&                           theScript,
+                          QString                                theName = QString()) const;
+
+    /**
    * Internal method that used to store the color attribute
    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
    * \param theColor color to save
@@ -270,7 +304,7 @@ protected:
    * Creates new object in the internal data structure. Use higher level objects 
    * to create objects with real content.
    */
-  HYDRODATA_EXPORT HYDROData_Entity();
+  HYDRODATA_EXPORT HYDROData_Entity( Geometry );
 
   /**
    * Destructs properties of the object and object itself, removes it from the document.
@@ -312,7 +346,7 @@ protected:
    * \param theObj pointer to reference object
    * \param theTag tag of a label to store attribute (for 0 this is myLab)
    */
-  bool HasReference( const Handle_HYDROData_Entity& theObj,
+  bool HasReference( const Handle(HYDROData_Entity)& theObj,
                      const int                      theTag = 0 ) const;
 
   /**
@@ -320,7 +354,7 @@ protected:
    * \param theObj pointer to reference object
    * \param theTag tag of a label to store attribute (for 0 this is myLab)
    */
-  void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
+  void AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
                            const int                      theTag = 0 );
 
   /**
@@ -332,7 +366,7 @@ protected:
              - if less than zero then prepend to the list
              - indexing starts from 0
    */
-  void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
+  void SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
                            const int                      theTag = 0,
                            const int                      theIndex = 0 );
 
@@ -345,7 +379,7 @@ protected:
              - if less than zero then prepend to the list
              - indexing starts from 0
    */
-  void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
+  void InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
                               const int                      theTag = 0,
                               const int                      theBeforeIndex = 0 );
 
@@ -364,7 +398,7 @@ protected:
    *        - indexing starts from 0
    * \returns pointer to reference object or NULL if label is not set
    */
-  Handle_HYDROData_Entity GetReferenceObject( const int theTag   = 0,
+  Handle(HYDROData_Entity) GetReferenceObject( const int theTag   = 0,
                                               const int theIndex = 0 ) const;
 
   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
@@ -389,6 +423,10 @@ protected:
    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
    */
   void ClearReferenceObjects( const int theTag = 0 );
+
+public:
+
+   HYDRODATA_EXPORT virtual bool CompareLabels(const Handle(HYDROData_Entity)& theOtherObj);
   
 protected:
 
@@ -404,12 +442,14 @@ protected:
    */
   QString getPyTypeID() const;
 
-  void setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
+  void setPythonReferenceObject( const QString&                  thePyScriptPath,
+                                 MapOfTreatedObjects&            theTreatedObjects,
                                  QStringList&                    theScript,
                                  const Handle(HYDROData_Entity)& theRefObject,
                                  const QString&                  theMethod ) const;
 
-  bool checkObjectPythonDefinition( MapOfTreatedObjects&            theTreatedObjects,
+  bool checkObjectPythonDefinition( const QString&                  thePyScriptPath,
+                                    MapOfTreatedObjects&            theTreatedObjects,
                                     QStringList&                    theScript,
                                     const Handle(HYDROData_Entity)& theRefObject ) const;
 
@@ -417,7 +457,6 @@ protected:
                              const QColor&        theColor,
                              const QColor&        theDefaultColor,
                              const QString&       theMethod ) const;
-
 protected:
 
   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
@@ -426,9 +465,19 @@ protected:
   void SetShape( int theTag, const TopoDS_Shape& theShape );
   TopoDS_Shape GetShape( int theTag ) const;
 
+  void SetDouble( int theTag, double theValue );
+  double GetDouble( int theTag, double theDefValue = 0.0 ) const;
+
+  void SetInteger( int theTag, int theValue );
+  int GetInteger( int theTag, int theDefValue = 0 ) const;
+
+
+  int GetGeomChangeFlag() const;
+
 protected:
   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
   TDF_Label myLab; ///< label of this object
+  Geometry  myGeom;
 };
 
 #endif