1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Document.cxx
4 // Created: 28 Feb 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef ModelAPI_Document_H_
8 #define ModelAPI_Document_H_
17 class ModelAPI_Feature;
18 class ModelAPI_Object;
19 class ModelAPI_Result;
20 class ModelAPI_ResultConstruction;
21 class ModelAPI_ResultBody;
22 class ModelAPI_ResultCompSolid;
23 class ModelAPI_ResultPart;
24 class ModelAPI_ResultGroup;
25 class ModelAPI_ResultParameter;
28 /**\class ModelAPI_Document
30 * \brief Document for internal data structure of any object storage.
31 * Document contains all data that must be stored/retrived in the file.
32 * Also it provides acces to this data: open/save, transactions management etc.
34 class ModelAPI_Document
37 //! Returns the kind of the document: "PartSet", "Part", or something else.
38 //! This kind is used for feature buttons enable/disable depending on active document
39 //! (it uses workbench "document" identifier in XML configuration file for this)
40 virtual const std::string& kind() const = 0;
42 //! Removes document data
43 //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
44 virtual void close(const bool theForever = false) = 0;
46 //! Adds to the document the new feature of the given feature id
47 //! \param theID creates feature and puts it in the document (if it is not action)
48 //! \param theMakeCurrent to make current this new feature in this document
49 virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID,
50 const bool theMakeCurrent = true) = 0;
52 //! Return a list of features, which refers to the feature
53 //! \param theFeature a feature
54 //! \param theRefs a list of features
55 //! \param isSendError a flag whether the error message should be send
56 virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
57 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
58 const bool isSendError = true) = 0;
60 //! Removes the feature from the document
61 //! \param theFeature a feature to be removed
62 virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
64 //! Moves the feature to make it after the given one in the history.
65 virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved,
66 std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
68 ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
69 virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
71 ///! Returns the id of the document
72 virtual const std::string& id() const = 0;
74 //! Returns the object in the group by the index (started from zero)
75 //! \param theGroupID group that contains an object
76 //! \param theIndex zero-based index of feature in the group
77 virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
78 const int theIndex) = 0;
80 //! Returns the first found object in the group by the object name
81 //! \param theGroupID group that contains an object
82 //! \param theName name of the object to search
83 //! \returns null if such object is not found
84 virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
85 const std::string& theName) = 0;
87 //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
88 //! \param theObject object of this document
89 //! \returns index started from zero, or -1 if object is invisible or belongs to another document
90 virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
92 //! Returns the number of objects in the group of objects
93 virtual int size(const std::string& theGroupID) = 0;
95 //! Returns the feature that is currently edited in this document, normally
96 //! this is the latest created feature
97 //! \param theVisible use visible features only: flag is true for Object Browser functionality
98 //! \returns null if next created feature must be the first
99 virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
101 //! Sets the current feature: all features below will be disabled, new features
102 //! will be appended after this one.
103 //! \param theCurrent the selected feature as current: blow it everythin become disabled
104 //! \param theVisible use visible features only: flag is true for Object Browser functionality
105 virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
106 const bool theVisible) = 0;
107 //! Makes the current feature one feature upper
108 virtual void setCurrentFeatureUp() = 0;
110 //! Returns the number of all features: in the history or not
111 virtual int numInternalFeatures() = 0;
112 //! Returns the feature by zero-based index: features in the history or not
113 virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
116 //! To virtually destroy the fields of successors
117 MODELAPI_EXPORT virtual ~ModelAPI_Document();
119 //! Creates a construction cresults
120 virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
121 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
122 //! Creates a body results
123 virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
124 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
125 /// Creates a compsolid results
126 virtual std::shared_ptr<ModelAPI_ResultCompSolid> createCompSolid(
127 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
128 //! Creates a part results
129 virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
130 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
131 //! Copies a part result, keeping the same data
132 virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
133 const std::shared_ptr<ModelAPI_Result>& theOldPart,
134 const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
135 const int theIndex = 0) = 0;
136 //! Creates a group results
137 virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
138 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
140 virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
141 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
143 //! Returns a feature by result (owner of result)
144 virtual std::shared_ptr<ModelAPI_Feature> feature(
145 const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
147 //! Returns all features of the document including the hidden features which are not in
148 //! history. Not very fast method, for calling once, not in big cycles.
149 virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
151 //! Informs the document that it becomes active and some actions must be performed
152 virtual void setActive(const bool theFlag) = 0;
153 //! Returns true if this document is currently active
154 virtual bool isActive() const = 0;
156 /// Returns true if document is opened and valid
157 virtual bool isOpened() = 0;
161 //! Only for SWIG wrapping it is here
162 MODELAPI_EXPORT ModelAPI_Document();
164 //! Internally makes document know that feature was removed or added in history after creation
165 MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
166 //! Internally makes document know that feature was removed or added in history after creation
167 MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
169 friend class ModelAPI_Object; // to add or remove from the history
170 friend class ModelAPI_Result; // to add or remove from the history
173 //! Pointer on document object
174 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;