Salome HOME
Issue #273: Add copyright string
[modules/shaper.git] / src / ModelAPI / ModelAPI_Object.h
index cf81f99bfee1dda02e24ba738a498ef8c6aeaf65..6d8aeaec8f82869cf259908aacb9bbb8cdcdf779 100644 (file)
@@ -1,52 +1,92 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModelAPI_Object.hxx
-// Created:     21 Mar 2014
+// 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.h"
-#include <string>
+#include "ModelAPI_Data.h"
+
 #include <memory>
 
-class ModelAPI_AttributeDocRef;
-class ModelAPI_AttributeDouble;
+class ModelAPI_Data;
 class ModelAPI_Document;
 
 /**\class ModelAPI_Object
  * \ingroup DataModel
- * \brief General object of the application that allows
- * to get/set attributes from the document and compute result of an operation.
+ * \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_EXPORT ModelAPI_Object
+class ModelAPI_Object
 {
-public:
+  std::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
+  std::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 name of the feature visible by the user in the object browser
-  virtual std::string getName() = 0;
+  /// Returns the data manager of this object: attributes
+  virtual std::shared_ptr<ModelAPI_Data> data() const
+  {
+    return myData;
+  }
 
-  /// Defines the name of the feature visible by the user in the object browser
-  virtual void setName(std::string theName) = 0;
+  /// Returns true if object refers to the same data model instance
+  virtual bool isSame(const std::shared_ptr<ModelAPI_Object>& theObject)
+  {
+    return theObject.get() == this;
+  }
 
-  /// Returns the attribute that references to another document
-  virtual std::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID) = 0;
-  /// Returns the attribute that contains real value with double precision
-  virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID) = 0;
+  /// Returns document this feature belongs to
+  virtual std::shared_ptr<ModelAPI_Document> document() const
+  {
+    return myDoc;
+  }
 
-  /// Initializes object by the attributes: must be called just after the object is created
-  /// for each attribute of the object
-  /// \param theID identifier of the attribute that can be referenced by this ID later
-  /// \param theAttrType type of the created attribute (received from the type method)
-  virtual void addAttribute(std::string theID, std::string theAttrType) = 0;
+  /// Returns the group identifier of this object
+  virtual std::string groupName() = 0;
 
-  /// Returns the document of this data
-  virtual std::shared_ptr<ModelAPI_Document> document() = 0;
-
-protected:
-  /// Objects are created for features automatically
-  ModelAPI_Object()
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID) 
   {}
+
+  /// To use virtuality for destructors
+  virtual ~ModelAPI_Object() {}
+
+ protected:
+  /// Sets the data manager of an object (document does)
+  virtual void setData(std::shared_ptr<ModelAPI_Data> theData)
+  {
+    myData = theData;
+  }
+
+  /// Sets the data manager of an object (document does)
+  virtual void setDoc(std::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;
+
 };
 
+typedef std::shared_ptr<ModelAPI_Object> ObjectPtr;
+
 #endif