Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / Model / Model_Application.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef Model_Application_H_
21 #define Model_Application_H_
22
23 #include <Model_Document.h>
24 #include <TDocStd_Application.hxx>
25 #include <map>
26
27 // Define handle class
28 DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application)
29
30 /**\class Model_Application
31  * \ingroup DataModel
32  * \brief Realization of Open CASCADE application abstraction. Class for internal use only.
33  *
34  * Application supports the formats and document management. It is uses OCAF-lke
35  * architecture and just implements specific features of the module.
36  */
37 class Model_Application : public TDocStd_Application
38 {
39 public:
40   // useful methods inside of the module
41
42   // CASCADE RTTI
43   /// Definition of "Handles" usage
44   /// \param Model_Application is the class name that is covered by the OCCT Handle
45   DEFINE_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
46
47   //! Retuns the application: one per process
48   MODEL_EXPORT static Handle_Model_Application getApplication();
49   //! Returns the document by the identifier
50   //! \returns false of document is not yet created/not loaded
51   MODEL_EXPORT std::shared_ptr<Model_Document> document(const int theDocID);
52   //! Returns true if document has been created
53   MODEL_EXPORT bool hasDocument(const int theDocID);
54   //! Returns true if root document has been created
55   MODEL_EXPORT bool hasRoot();
56   //! Returns root document, if created (or null otherwise)
57   MODEL_EXPORT std::shared_ptr<Model_Document> rootDocument();
58   //! Deletes the document from the application
59   MODEL_EXPORT void deleteDocument(const int theDocID);
60   //! Deletes all documents existing in the application
61   MODEL_EXPORT void deleteAllDocuments();
62   //! Creates a new document an returns an id of this document
63   //! \param theDocID if it is zero, the root document is created
64   MODEL_EXPORT void createDocument(const int theDocID);
65   //! Loads document by the file name (if it is registered as load by demand)
66   //! \param theDocName name of the document file
67   //! \param theDocID the identifier of the loaded document (to be created)
68   //! \returns true if load is ok
69   MODEL_EXPORT bool loadDocument(const std::string theDocName, const int theDocID);
70
71   //! Set path for the loaded by demand documents
72   void setLoadPath(std::string thePath);
73   //! Returns the path for the loaded by demand documents
74   const std::string& loadPath() const;
75   //! Defines that specified document must be loaded by demand
76   void setLoadByDemand(std::string theID, const int theDocID);
77   //! Returns true if specified document must be loaded by demand
78   bool isLoadByDemand(std::string theID);
79   //! Closes and removes the documents that are not loaded by demand and
80   //! not in the given list
81   void removeUselessDocuments(std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs);
82
83   //! produces new unique identifier of the document
84   int generateDocumentId();
85
86  public:
87   // Redefined OCAF methods
88   //! Return name of resource (i.e. "Standard")
89   Standard_CString ResourcesName();
90   //! Return format (i.e "MDTV-Standard")
91   //! \param theFormats sequence of allowed formats for input/output
92   virtual void Formats(TColStd_SequenceOfExtendedString& theFormats);
93   //! Constructor
94   //! Use method GetInstance() method to obtain
95   //! the static instance of the object (or derive your own application)
96   Model_Application();
97
98  private:
99   /// Map from identifiers to created documents of an application
100   std::map<int, std::shared_ptr<Model_Document> > myDocs;
101   /// Path for the loaded by demand documents
102   std::string myPath;
103   /// Path for the loaded by demand documents (and the persistent ID as the value)
104   std::map<std::string, int> myLoadedByDemand;
105 };
106
107 #endif