Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / Model / Model_Application.h
1 // Copyright (C) 2014-2020  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
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::wstring 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::wstring theID, const int theDocID);
77   //! Returns true if specified document must be loaded by demand
78   bool isLoadByDemand(std::wstring theID, const int theDocIndex);
79
80   //! produces new unique identifier of the document
81   int generateDocumentId();
82
83  public:
84   // Redefined OCAF methods
85   //! Return name of resource (i.e. "Standard")
86   Standard_CString ResourcesName();
87   //! Return format (i.e "MDTV-Standard")
88   //! \param theFormats sequence of allowed formats for input/output
89   virtual void Formats(TColStd_SequenceOfExtendedString& theFormats);
90   //! Constructor
91   //! Use method GetInstance() method to obtain
92   //! the static instance of the object (or derive your own application)
93   Model_Application();
94
95  private:
96   /// Map from identifiers to created documents of an application
97   std::map<int, std::shared_ptr<Model_Document> > myDocs;
98   /// Path for the loaded by demand documents
99   std::string myPath;
100   /// Path for the loaded by demand documents (and the persistent ID as the value)
101   std::map<std::wstring, int> myLoadedByDemand;
102 };
103
104 #endif