Salome HOME
Correctly close the document on opening the new one
[modules/shaper.git] / src / ModelAPI / ModelAPI_Document.h
1 // File:        ModelAPI_Document.cxx
2 // Created:     28 Feb 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Document_H_
6 #define ModelAPI_Document_H_
7
8 #include <ModelAPI.h>
9 #include <string>
10 #include <boost/shared_ptr.hpp>
11 #include <vector>
12 #include <list>
13
14 class ModelAPI_Feature;
15 class ModelAPI_Object;
16 class ModelAPI_Result;
17 class ModelAPI_ResultConstruction;
18 class ModelAPI_ResultBody;
19 class ModelAPI_ResultPart;
20 class ModelAPI_ResultGroup;
21 class ModelAPI_Data;
22
23 /**\class Model_Document
24  * \ingroup DataModel
25  * \brief Document for internal data structure of any object storage.
26  * Document contains all data that must be stored/retrived in the file.
27  * Also it provides acces to this data: open/save, transactions management etc.
28  */
29 class ModelAPI_Document
30 {
31 public:
32   //! Returns the kind of the document: "PartSet", "Part", or something else.
33   //! This kind is used for feature buttons enable/disable depending on active document
34   //! (it uses workbench "document" identifier in XML configuration file for this)
35   virtual const std::string& kind() const = 0;
36
37   //! Removes document data
38   //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
39   virtual void close(const bool theForever = false) = 0;
40
41   //! Adds to the document the new feature of the given feature id
42   //! \param creates feature and puts it in the document (if it is not action)
43   virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
44
45   //! Removes the feature from the document
46   virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
47                              const bool theCheck = true) = 0;
48
49   ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
50   virtual boost::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
51
52   ///! Returns the id of the document
53   virtual const std::string& id() const = 0;
54
55   //! Returns the object in the group by the index (started from zero)
56   //! \param theGroupID group that contains an object
57   //! \param theIndex zero-based index of feature in the group
58   //! \param theHidden if it is true, it counts also the features that are not in tree
59   virtual boost::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
60                                                     const int theIndex,
61                                                     const bool theHidden = false) = 0;
62
63   //! Returns the number of objects in the group of objects
64   //! If theHidden is true, it counts also the features that are not in tree
65   virtual int size(const std::string& theGroupID, const bool theHidden = false) = 0;
66
67   /// To virtually destroy the fields of successors
68   virtual ~ModelAPI_Document()
69   {
70   }
71
72   /// Creates a construction cresults
73   virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
74       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
75   /// Creates a body results
76   virtual boost::shared_ptr<ModelAPI_ResultBody> createBody(
77       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
78   /// Creates a part results
79   virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
80       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
81   /// Creates a group results
82   virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
83       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
84
85   //! Returns a feature by result (owner of result)
86   virtual boost::shared_ptr<ModelAPI_Feature> feature(
87       const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
88
89 protected:
90   /// Only for SWIG wrapping it is here
91   MODELAPI_EXPORT ModelAPI_Document()
92   {
93   }
94 };
95
96 //! Pointer on document object
97 typedef boost::shared_ptr<ModelAPI_Document> DocumentPtr;
98
99 #endif