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_ResultPart;
23 class ModelAPI_ResultGroup;
24 class ModelAPI_ResultParameter;
27 /**\class ModelAPI_Document
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.
33 class ModelAPI_Document
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;
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;
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 //! \param theMakeCurrent to make current this new feature in this document
48 virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID,
49 const bool theMakeCurrent = true) = 0;
51 //! Return a list of features, which refers to the feature
52 //! \param theFeature a feature
53 //! \param theRefs a list of features
54 //! \param isSendError a flag whether the error message should be send
55 virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
56 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
57 const bool isSendError = true) = 0;
59 //! Removes the feature from the document
60 //! \param theFeature a feature to be removed
61 virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
63 ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
64 virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
66 ///! Returns the id of the document
67 virtual const std::string& id() const = 0;
69 //! Returns the object in the group by the index (started from zero)
70 //! \param theGroupID group that contains an object
71 //! \param theIndex zero-based index of feature in the group
72 virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
73 const int theIndex) = 0;
75 //! Returns the first found object in the group by the object name
76 //! \param theGroupID group that contains an object
77 //! \param theName name of the object to search
78 //! \returns null if such object is not found
79 virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
80 const std::string& theName) = 0;
82 //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
83 //! \param theObject object of this document
84 //! \returns index started from zero, or -1 if object is invisible or belongs to another document
85 virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
87 //! Returns the number of objects in the group of objects
88 virtual int size(const std::string& theGroupID) = 0;
90 //! Returns the feature that is currently edited in this document, normally
91 //! this is the latest created feature
92 //! \param theVisible use visible features only: flag is true for Object Browser functionality
93 //! \returns null if next created feature must be the first
94 virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
96 //! Sets the current feature: all features below will be disabled, new features
97 //! will be appended after this one.
98 //! \param theCurrent the selected feature as current: blow it everythin become disabled
99 //! \param theVisible use visible features only: flag is true for Object Browser functionality
100 virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
101 const bool theVisible) = 0;
102 //! Makes the current feature one feature upper
103 virtual void setCurrentFeatureUp() = 0;
105 //! To virtually destroy the fields of successors
106 MODELAPI_EXPORT virtual ~ModelAPI_Document();
108 //! Creates a construction cresults
109 virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
110 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
111 //! Creates a body results
112 virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
113 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
114 //! Creates a part results
115 virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
116 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
117 //! Creates a group results
118 virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
119 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
121 virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
122 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
124 //! Returns a feature by result (owner of result)
125 virtual std::shared_ptr<ModelAPI_Feature> feature(
126 const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
128 //! Returns all features of the document including the hidden features which are not in
129 //! history. Not very fast method, for calling once, not in big cycles.
130 virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
132 //! Informs the document that it becomes active and some actions must be performed
133 virtual void setActive(const bool theFlag) = 0;
134 //! Returns true if this document is currently active
135 virtual bool isActive() const = 0;
138 //! Only for SWIG wrapping it is here
139 MODELAPI_EXPORT ModelAPI_Document();
141 //! Internally makes document know that feature was removed or added in history after creation
142 MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
143 //! Internally makes document know that feature was removed or added in history after creation
144 MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
146 friend class ModelAPI_Object; // to add or remove from the history
147 friend class ModelAPI_Result; // to add or remove from the history
150 //! Pointer on document object
151 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;