Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0
[modules/shaper.git] / src / ModelAPI / ModelAPI_Document.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Document.cxx
4 // Created:     28 Feb 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Document_H_
8 #define ModelAPI_Document_H_
9
10 #include <ModelAPI.h>
11 #include <string>
12 #include <memory>
13 #include <vector>
14 #include <list>
15 #include <set>
16
17 class ModelAPI_Feature;
18 class ModelAPI_Object;
19 class ModelAPI_Result;
20 class ModelAPI_ResultConstruction;
21 class ModelAPI_ResultBody;
22 class ModelAPI_ResultPart;
23 class ModelAPI_ResultGroup;
24 class ModelAPI_ResultParameter;
25 class ModelAPI_Data;
26
27 /**\class ModelAPI_Document
28  * \ingroup DataModel
29  * \brief Document for internal data structure of any object storage.
30  * Document contains all data that must be stored/retrived in the file.
31  * Also it provides acces to this data: open/save, transactions management etc.
32  */
33 class ModelAPI_Document
34 {
35 public:
36   //! Returns the kind of the document: "PartSet", "Part", or something else.
37   //! This kind is used for feature buttons enable/disable depending on active document
38   //! (it uses workbench "document" identifier in XML configuration file for this)
39   virtual const std::string& kind() const = 0;
40
41   //! Removes document data
42   //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
43   virtual void close(const bool theForever = false) = 0;
44
45   //! Adds to the document the new feature of the given feature id
46   //! \param theID creates feature and puts it in the document (if it is not action)
47   virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
48
49   //! Return a list of features, which refers to the feature
50   //! \param theFeature a feature
51   //! \param theRefs a list of features
52   //! \param isSendError a flag whether the error message should be send
53   virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
54                              std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
55                              const bool isSendError = true) = 0;
56
57   //! Removes the feature from the document
58   //! \param theFeature a feature to be removed
59   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
60
61   ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
62   virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
63
64   ///! Returns the id of the document
65   virtual const std::string& id() const = 0;
66
67   //! Returns the object in the group by the index (started from zero)
68   //! \param theGroupID group that contains an object
69   //! \param theIndex zero-based index of feature in the group
70   virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
71                                                     const int theIndex) = 0;
72
73   //! Returns the first found object in the group by the object name
74   //! \param theGroupID group that contains an object
75   //! \param theName name of the object to search
76   //! \returns null if such object is not found
77   virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
78                                                     const std::string& theName) = 0;
79
80   //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
81   //! \param theObject object of this document
82   //! \returns index started from zero, or -1 if object is invisible or belongs to another document
83   virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
84
85   //! Returns the number of objects in the group of objects
86   virtual int size(const std::string& theGroupID) = 0;
87
88   //! Returns the feature that is currently edited in this document, normally
89   //! this is the latest created feature
90   //! \param theVisible use visible features only: flag is true for Object Browser functionality
91   //! \returns null if next created feature must be the first
92   virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
93
94   //! Sets the current feature: all features below will be disabled, new features
95   //! will be appended after this one.
96   //! \param theCurrent the selected feature as current: blow it everythin become disabled
97   //! \param theVisible use visible features only: flag is true for Object Browser functionality
98   virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
99     const bool theVisible) = 0;
100
101   /// To virtually destroy the fields of successors
102   MODELAPI_EXPORT virtual ~ModelAPI_Document();
103
104   /// Creates a construction cresults
105   virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
106       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
107   /// Creates a body results
108   virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
109       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
110   /// Creates a part results
111   virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
112       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
113   /// Creates a group results
114   virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
115       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
116
117   virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
118       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
119
120   //! Returns a feature by result (owner of result)
121   virtual std::shared_ptr<ModelAPI_Feature> feature(
122       const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
123
124 protected:
125   /// Only for SWIG wrapping it is here
126   MODELAPI_EXPORT ModelAPI_Document();
127
128   /// Internally makes document know that feature was removed or added in history after creation
129   MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
130   /// Internally makes document know that feature was removed or added in history after creation
131   MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
132
133   friend class ModelAPI_Object; // to add or remove from the history
134   friend class ModelAPI_Result; // to add or remove from the history
135 };
136
137 //! Pointer on document object
138 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
139
140 #endif