Salome HOME
Merge branch 'SALOME-8.2.0_porting'
[modules/shaper.git] / src / Model / Model_Application.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Application.hxx
4 // Created:     28 Dec 2011
5 // Author:      Mikhail PONIKAROV
6 // Copyright:   CEA 2011
7
8 #ifndef Model_Application_H_
9 #define Model_Application_H_
10
11 #include <Model_Document.h>
12 #include <TDocStd_Application.hxx>
13 #include <map>
14
15 // Define handle class
16 DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application)
17
18 /**\class Model_Application
19  * \ingroup DataModel
20  * \brief Realization of Open CASCADE application abstraction. Class for internal use only.
21  *
22  * Application supports the formats and document management. It is uses OCAF-lke
23  * architecture and just implements specific features of the module.
24  */
25 class Model_Application : public TDocStd_Application
26 {
27 public:
28   // useful methods inside of the module
29
30   // CASCADE RTTI
31   /// Definition of "Handles" usage
32   /// \param Model_Application is the class name that is covered by the OCCT Handle
33   DEFINE_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
34
35   //! Retuns the application: one per process
36   MODEL_EXPORT static Handle_Model_Application getApplication();
37   //! Returns the document by the identifier
38   //! \returns false of document is not yet created/not loaded
39   MODEL_EXPORT std::shared_ptr<Model_Document> document(const int theDocID);
40   //! Returns true if document has been created
41   MODEL_EXPORT bool hasDocument(const int theDocID);
42   //! Returns true if root document has been created
43   MODEL_EXPORT bool hasRoot();
44   //! Returns root document, if created (or null otherwise)
45   MODEL_EXPORT std::shared_ptr<Model_Document> rootDocument();
46   //! Deletes the document from the application
47   MODEL_EXPORT void deleteDocument(const int theDocID);
48   //! Deletes all documents existing in the application
49   MODEL_EXPORT void deleteAllDocuments();
50   //! Creates a new document an returns an id of this document
51   //! \param theDocID if it is zero, the root document is created
52   MODEL_EXPORT void createDocument(const int theDocID);
53   //! Loads document by the file name (if it is registered as load by demand)
54   //! \param theDocName name of the document file
55   //! \param theDocID the identifier of the loaded document (to be created)
56   //! \returns true if load is ok
57   MODEL_EXPORT bool loadDocument(const std::string theDocName, const int theDocID);
58
59   //! Set path for the loaded by demand documents
60   void setLoadPath(std::string thePath);
61   //! Returns the path for the loaded by demand documents
62   const std::string& loadPath() const;
63   //! Defines that specified document must be loaded by demand
64   void setLoadByDemand(std::string theID);
65   //! Returns true if specified document must be loaded by demand
66   bool isLoadByDemand(std::string theID);
67   //! Closes and removes the documents that are not loaded by demand and
68   //! not in the given list
69   void removeUselessDocuments(std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs);
70
71   //! produces new unique identifier of the document
72   int generateDocumentId();
73
74  public:
75   // Redefined OCAF methods
76   //! Return name of resource (i.e. "Standard")
77   Standard_CString ResourcesName();
78   //! Return format (i.e "MDTV-Standard")
79   //! \param theFormats sequence of allowed formats for input/output
80   virtual void Formats(TColStd_SequenceOfExtendedString& theFormats);
81   //! Constructor
82   //! Use method GetInstance() method to obtain
83   //! the static instance of the object (or derive your own application)
84   Model_Application();
85
86  private:
87   /// Map from identifiers to created documents of an application
88   std::map<int, std::shared_ptr<Model_Document> > myDocs;
89   /// Path for the loaded by demand documents
90   std::string myPath;
91   /// Path for the loaded by demand documents
92   std::set<std::string> myLoadedByDemand;
93 };
94
95 #endif