Salome HOME
Added isSub method for selection of external objects task in the Sketch
[modules/shaper.git] / src / ModelAPI / ModelAPI_Object.h
index 64240ce38b63a274007d598aea7fc91a8b24cca6..7ac6696f5ad5b0433b2d662bd2c5917f6858372f 100644 (file)
@@ -2,32 +2,84 @@
 // Created:     19 May 2014
 // Author:      Mikhail PONIKAROV
 
-#ifndef ModelAPI_Object_HeaderFile
-#define ModelAPI_Object_HeaderFile
+#ifndef ModelAPI_Object_H_
+#define ModelAPI_Object_H_
 
-#include "ModelAPI_Feature.h"
+#include "ModelAPI.h"
+#include "ModelAPI_Data.h"
+
+#include <boost/shared_ptr.hpp>
+
+class ModelAPI_Data;
+class ModelAPI_Document;
 
 /**\class ModelAPI_Object
  * \ingroup DataModel
- * \brief Represents the result of some feature in the object browser
- * under the specific folder. Just a reference to specific feature-operation
- * with possibility to rename it.
+ * \brief Represents any object in the data model and in the object browser.
+ *
+ * It may be feature or result of the feature. User just may set name for it
+ * or change this name later. Generic class for Feature, Body, Parameter and other
+ * objects related to the features and their results. Contains attributes of this 
+ * object in the "Data".
  */
-class ModelAPI_Object : public ModelAPI_Feature
+class ModelAPI_Object
 {
-public:
+  boost::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
+  boost::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
+ public:
+  /// By default object is displayed in the object browser.
+  virtual bool isInHistory()
+  {
+    return true;
+  }
+
+  /// Returns the data manager of this object: attributes
+  virtual boost::shared_ptr<ModelAPI_Data> data() const
+  {
+    return myData;
+  }
+
+  /// Returns true if object refers to the same data model instance
+  virtual bool isSame(const boost::shared_ptr<ModelAPI_Object>& theObject)
+  {
+    return theObject.get() == this;
+  }
+
+  /// Returns document this feature belongs to
+  virtual boost::shared_ptr<ModelAPI_Document> document() const
+  {
+    return myDoc;
+  }
 
-  /// It is never located in history
-  MODELAPI_EXPORT virtual bool isInHistory() {return false;}
+  /// Returns the group identifier of this object
+  virtual std::string groupName() = 0;
 
-  /// Reference to the feature-operation that produces this object
-  MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> featureRef() = 0;
+  /// To use virtuality for destructors
+  virtual ~ModelAPI_Object() {}
 
-  /// Returns the name of this object (by default equal to the name of feature)
-  MODELAPI_EXPORT virtual std::string getName() = 0;
+ protected:
+  /// Sets the data manager of an object (document does)
+  virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
+  {
+    myData = theData;
+  }
+
+  /// Sets the data manager of an object (document does)
+  virtual void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc)
+  {
+    myDoc = theDoc;
+  }
+
+  /// removes all fields from this feature
+  MODELAPI_EXPORT virtual void erase() {
+    if (myData) myData->erase();
+    setData(DataPtr());
+  }
+
+  friend class Model_Document;
 
-  /// Defines the name of the object
-  MODELAPI_EXPORT virtual void setName(std::string theName) = 0;
 };
 
+typedef boost::shared_ptr<ModelAPI_Object> ObjectPtr;
+
 #endif