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;
26 /**\class ModelAPI_Document
28 * \brief Document for internal data structure of any object storage.
29 * Document contains all data that must be stored/retrived in the file.
30 * Also it provides acces to this data: open/save, transactions management etc.
32 class ModelAPI_Document
35 //! Returns the kind of the document: "PartSet", "Part", or something else.
36 //! This kind is used for feature buttons enable/disable depending on active document
37 //! (it uses workbench "document" identifier in XML configuration file for this)
38 virtual const std::string& kind() const = 0;
40 //! Removes document data
41 //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
42 virtual void close(const bool theForever = false) = 0;
44 //! Adds to the document the new feature of the given feature id
45 //! \param theID creates feature and puts it in the document (if it is not action)
46 virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
48 //! Return a list of features, which refers to the feature
49 //! \param theFeature a feature
50 //! \param theRefs a list of features
51 //! \param isSendError a flag whether the error message should be send
52 virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
53 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
54 const bool isSendError = true) = 0;
56 //! Removes the feature from the document
57 //! \param theFeature a feature to be removed
58 virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
60 ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
61 virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
63 ///! Returns the id of the document
64 virtual const std::string& id() const = 0;
66 //! Returns the object in the group by the index (started from zero)
67 //! \param theGroupID group that contains an object
68 //! \param theIndex zero-based index of feature in the group
69 //! \param theHidden if it is true, it counts also the features that are not in tree
70 virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
72 const bool theHidden = false) = 0;
74 //! Returns the number of objects in the group of objects
75 //! If theHidden is true, it counts also the features that are not in tree
76 virtual int size(const std::string& theGroupID, const bool theHidden = false) = 0;
78 /// To virtually destroy the fields of successors
79 MODELAPI_EXPORT virtual ~ModelAPI_Document();
81 /// Creates a construction cresults
82 virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
83 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
84 /// Creates a body results
85 virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
86 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
87 /// Creates a part results
88 virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
89 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
90 /// Creates a group results
91 virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
92 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
94 //! Returns a feature by result (owner of result)
95 virtual std::shared_ptr<ModelAPI_Feature> feature(
96 const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
99 /// Only for SWIG wrapping it is here
100 MODELAPI_EXPORT ModelAPI_Document();
102 /// Internally makes document know that feature was removed or added in history after creation
103 MODELAPI_EXPORT virtual void addToHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
105 friend class ModelAPI_Object; // to add or remove from the history
108 //! Pointer on document object
109 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;