Salome HOME
refs #636: flags for geometry 2d/3d change
[modules/hydro.git] / src / HYDROData / HYDROData_Object.h
index a44ffdb5affa77eee20a992de5b729a8ca50b1f8..a9c1ad82a2ecb3b4c9f38d83184f8c34a5d1d8e2 100644 (file)
@@ -1,49 +1,38 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #ifndef HYDROData_Object_HeaderFile
 #define HYDROData_Object_HeaderFile
 
-#include <HYDROData.h>
-
-#include <NCollection_Sequence.hxx>
-#include <TDF_Label.hxx>
-#include <QMap>
-
-class QColor;
-class QString;
-class QVariant;
-class QStringList;
-class Handle(TDataStd_ReferenceList);
-class Handle_HYDROData_Object;
-
-///! Kind of an object in a document
-typedef int ObjectKind;
-///! Unrecognized object
-const ObjectKind KIND_UNKNOWN        = 0;
-const ObjectKind KIND_IMAGE          = 1;
-const ObjectKind KIND_POLYLINE       = 2;
-const ObjectKind KIND_VISUAL_STATE   = 3;
-const ObjectKind KIND_BATHYMETRY     = 4;
-const ObjectKind KIND_CALCULATION    = 5;
-const ObjectKind KIND_PROFILE        = 6;
-const ObjectKind KIND_PROFILES_GROUP = 7;
-const ObjectKind KIND_GUIDE_LINE     = 8;
-const ObjectKind KIND_ZONE           = 9;
-const ObjectKind KIND_LAST           = KIND_ZONE;
+#include <HYDROData_Entity.h>
 
-DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
-
-typedef QMap<QString,Handle(Standard_Transient)> MapOfTreatedObjects;
-
-typedef NCollection_Sequence<Handle_HYDROData_Object> HYDROData_SequenceOfObjects;
+DEFINE_STANDARD_HANDLE(HYDROData_Object, HYDROData_Entity)
 
+class TopoDS_Shape;
+class Handle(HYDROData_IAltitudeObject);
+class Handle(HYDROData_DummyObject3D);
+class Handle(HYDROData_ShapesGroup);
 
 /**\class HYDROData_Object
- * \brief Generic class of any object in the data model.
+ * \brief The base class for all geometrical objects in the HYDRO module.
  *
- * Interface for getting access to the object that belong to the data model.
- * Managed by Document. Provides access to the common properties: 
- * kind of an object, name.
  */
-class HYDROData_Object : public MMgt_TShared
+class HYDROData_Object : public HYDROData_Entity
 {
 protected:
   /**
@@ -51,195 +40,220 @@ protected:
    */
   enum DataTag
   {
-    DataTag_First = 0     ///< first tag, to reserve
-    // ...
+    DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
+    DataTag_TopShape,
+    DataTag_Shape3D,
+    DataTag_AltitudeObject,      ///< reference altitude object
+    DataTag_FillingColor,        ///< filling color of geometrical object
+    DataTag_BorderColor,         ///< border color of geometrical object
+    DataTag_Object3D,            ///< child 3D object
+    DataTag_EdgesGroup,          ///< child group objects
+    DataTag_ChildAltitudeObject, ///< child altitude object
+    DataTag_IsSubmersible,       ///< the attribute "is submersible"
   };
 
 public:
   DEFINE_STANDARD_RTTI(HYDROData_Object);
 
   /**
-   * Returns the kind of this object. Must be redefined in all objects of known type.
+   * Updates the name of this object.
+   * Reimplemented to update the names child groups.
+   */
+  HYDRODATA_EXPORT virtual void SetName( const QString& theName );
+
+  /**
+   * Update the geometry object.
+   * Call this method whenever you made changes for object data.
    */
-  HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_UNKNOWN;}
+  HYDRODATA_EXPORT virtual void Update();
 
   /**
-   * Returns the name of this object.
+   * Returns the list of all reference objects of this object.
    */
-  HYDRODATA_EXPORT QString GetName() const;
+  HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
 
   /**
-   * Updates the name of this object.
+   * Sets the "MustBeUpdated" flag: if object is depended on updated features.
+   * Reimplemented to update the state of child 3D object.
+   */
+  HYDRODATA_EXPORT virtual void Changed( Geometry );
+
+
+  /**
+   * Sets the top(2d projection) shape of the object.
+   */
+  HYDRODATA_EXPORT virtual void SetTopShape( const TopoDS_Shape& theShape );
+
+  /**
+   * Returns the top shape of the object.
+   */
+  HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const = 0;
+
+  /**
+   * Sets the 3d shape of the object.
    */
-  HYDRODATA_EXPORT void SetName(const QString& theName);
+  HYDRODATA_EXPORT virtual void SetShape3D( const TopoDS_Shape& theShape );
 
   /**
-   * Dump object to Python script representation.
-   * Base implementation returns empty list,
-   * You should reimplement this function in your derived class if it
-   * has Python API and can be imported/exported from/to Python script.
+   * Returns the 3d shape of the object.
    */
-  HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
+  HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const = 0;
 
+  
   /**
-   * Updates object state.
-   * Base implementation dose nothing.
-   * \param theIsForce force reupdating of data object
+   * Returns reference object which represent the 3D shape of object.
    */
-  HYDRODATA_EXPORT virtual void Update( const bool theIsForce = true );
+  HYDRODATA_EXPORT virtual Handle(HYDROData_DummyObject3D) GetObject3D() const;
+
 
   /**
-   * Returns data of object wrapped to QVariant.
-   * Base implementation returns null value.
+   * Returns sequence of object groups.
    */
-  HYDRODATA_EXPORT virtual QVariant GetDataVariant();
+  HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGroups() const;
 
   /**
-   * Checks is object exists in the data structure.
-   * \returns true is object is not exists in the data model
+   * Returns group data model object by it id.
    */
-  HYDRODATA_EXPORT bool IsRemoved() const;
+  HYDRODATA_EXPORT virtual Handle(HYDROData_ShapesGroup) GetGroup( const int theGroupId ) const;
 
   /**
-   * Removes object from the data structure.
+   * Returns group id by data model object.
    */
-  HYDRODATA_EXPORT void Remove();
+  HYDRODATA_EXPORT virtual int GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const;
+
 
   /**
-   * Returns unique integer identifier of the object (may be used for ordering of objects)
+   * Set reference altitude object for geometry object.
    */
-  HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();}
+  HYDRODATA_EXPORT virtual bool SetAltitudeObject( const Handle(HYDROData_IAltitudeObject)& theAltitude );
 
   /**
-   * Copies all properties of this to the destinated object.
-   * Objects must be the same type.
-   * \param theDestination initialized object (from any document) - target of copying
+   * Returns reference altitude object of geometry object.
    */
-  HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const;
+  HYDRODATA_EXPORT virtual Handle(HYDROData_IAltitudeObject) GetAltitudeObject() const;
 
   /**
-   * Returns the label of this object.
+   * Clear the reference altitude object for geometry object.
    */
-  HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
+  HYDRODATA_EXPORT virtual void RemoveAltitudeObject();
+
+
+   /**
+   * Sets filling color for object.
+   */
+  HYDRODATA_EXPORT virtual void SetFillingColor( const QColor& theColor );
+
+  /**
+   * Returns filling color of object.
+   */
+  HYDRODATA_EXPORT virtual QColor GetFillingColor() const;
+
+   /**
+   * Sets border color for object.
+   */
+  HYDRODATA_EXPORT virtual void SetBorderColor( const QColor& theColor );
+
+  /**
+   * Returns border color of object.
+   */
+  HYDRODATA_EXPORT virtual QColor GetBorderColor() const;
+
+  HYDRODATA_EXPORT bool IsSubmersible() const;
+  HYDRODATA_EXPORT void SetIsSubmersible( bool ) const;
 
 protected:
 
-  friend class HYDROData_Iterator;
+  /**
+   * Returns default filling color for new object.
+   */
+  HYDRODATA_EXPORT virtual QColor getDefaultFillingColor() const;
+
+  /**
+   * Returns default border color for new object.
+   */
+  HYDRODATA_EXPORT virtual QColor getDefaultBorderColor() const;
+
+protected:
 
   /**
    * Creates new object in the internal data structure. Use higher level objects 
    * to create objects with real content.
    */
-  HYDRODATA_EXPORT HYDROData_Object();
+  HYDRODATA_EXPORT HYDROData_Object( Geometry );
 
   /**
    * Destructs properties of the object and object itself, removes it from the document.
    */
   virtual HYDRODATA_EXPORT ~HYDROData_Object();
 
+protected:
+
   /**
-   * Put the object to the label of the document.
-   * \param theLabel new label of the object
+   * Dump the initial object creation to a Python script.
+   * Reimplemented to dump the object colors.
    */
-  HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
+  HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
+
 
   /**
-   * Internal method that used to store the byte array attribute
-   * \param theTag tag of a label to store attribute (for 0 this is myLab)
-   * \param theData pointer to bytes array
-   * \param theLen number of bytes in byte array that must be stored
+   * Checks and if necessary create child 3D object.
+   * Reimplement this function in your subclass if you 
+   * do not want to create child 3D object.
    */
-  void SaveByteArray(const int theTag, const char* theData, const int theLen);
+  HYDRODATA_EXPORT virtual void checkAndSetObject3D();
+
 
   /**
-   * Internal method that used to retreive the content of byte array attribute
-   * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
-   * \param theLen number of bytes in byte array
-   * \returns pointer to the internal data structure wit harray content, 
-   *          or NULL if array size is zero
+   * Returns the type of child altitude object.
+   * Base implementation returns KIND_UNKNOWN, it means that child altitude 
+   * object will not be created inside of checkAndSetAltitudeObject() function.
+   * Reimplement this function in your subclass an return correct altitude
+   * object type if you want to create child altitude object.
    */
-  const char* ByteArray(const int theTag, int& theLen) const;
+  HYDRODATA_EXPORT virtual ObjectKind getAltitudeObjectType() const;
 
   /**
-   * Internal method that used to store the reference object label attribute
-   * \param theObj pointer to reference object
-   * \param theTag tag of a label to store attribute (for 0 this is myLab)
+   * Checks and if necessary create child altitude object.
    */
-  int NbReferenceObjects( const int theTag = 0 ) const;
+  HYDRODATA_EXPORT virtual void checkAndSetAltitudeObject();
 
   /**
-   * Internal method that used to store the reference object label attribute
-   * \param theObj pointer to reference object
-   * \param theTag tag of a label to store attribute (for 0 this is myLab)
+   * Return the child altitude object.
    */
-  void AddReferenceObject( const Handle_HYDROData_Object& theObj,
-                           const int                      theTag = 0 );
+  HYDRODATA_EXPORT virtual Handle(HYDROData_IAltitudeObject) getChildAltitudeObject() const;
+
 
   /**
-   * Internal method that used to store the reference object label attribute
-   * \param theObj pointer to reference object
-   * \param theTag tag of a label to store attribute (for 0 this is myLab)
-   * \param theIndex index in the list of references 
-             - if more that len then just append it to the end of list
-             - if less than zero then prepend to the list
-             - indexing starts from 0
+   * Create new one child group object.
    */
-  void SetReferenceObject( const Handle_HYDROData_Object& theObj,
-                           const int                      theTag = 0,
-                           const int                      theIndex = 0 );
+  HYDRODATA_EXPORT virtual Handle(HYDROData_ShapesGroup) createGroupObject();
 
   /**
-   * Internal method that used to retreive the reference object(s) attribute
-   * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
-   * \param theIndex index in the list of references 
-   *        - indexing starts from 0
-   * \returns pointer to reference object or NULL if label is not set
+   * Remove all child group objects.
    */
-  Handle_HYDROData_Object GetReferenceObject( const int theTag   = 0,
-                                              const int theIndex = 0 ) const;
+  HYDRODATA_EXPORT virtual void removeGroupObjects();
 
-  HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
 
   /**
-   * Internal method that used to remove the reference object attribute
-   * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
-   * \param theIndex index in the list of references 
-   *        - indexing starts from 0
+   * Retrieve the top shape of the object from data label.
    */
-  void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
+  HYDRODATA_EXPORT TopoDS_Shape getTopShape() const;
 
   /**
-   * Internal method that used to clear list of the reference objects attribute
-   * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
+   * Removes the top shape from data label of the object.
    */
-  void ClearReferenceObjects( const int theTag = 0 );
+  HYDRODATA_EXPORT void removeTopShape();
+
 
   /**
-   * 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
+   * Retrieve the 3d shape of the object from data label.
    */
-  void SetColor( const QColor& theColor, const int theTag = 0 );
+  HYDRODATA_EXPORT TopoDS_Shape getShape3D() const;
 
   /**
-   * Internal method that used to retreive the color attribute
-   * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
-   * \param theDefColor default color to return if attribute has not been set before
+   * Removes the 3d shape from data label of the object.
    */
-  QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
-
-protected:
-
-  Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
-                                                   const bool theIsCreate ) 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
+  HYDRODATA_EXPORT void removeShape3D();
 };
 
-///! Is Equal for HYDROData_Object mapping
-HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2);
-
 #endif