1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef Model_Application_H_
22 #define Model_Application_H_
24 #include <Model_Document.h>
25 #include <TDocStd_Application.hxx>
28 // Define handle class
29 DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application)
31 /**\class Model_Application
33 * \brief Realization of Open CASCADE application abstraction. Class for internal use only.
35 * Application supports the formats and document management. It is uses OCAF-lke
36 * architecture and just implements specific features of the module.
38 class Model_Application : public TDocStd_Application
41 // useful methods inside of the module
44 /// Definition of "Handles" usage
45 /// \param Model_Application is the class name that is covered by the OCCT Handle
46 DEFINE_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
48 //! Retuns the application: one per process
49 MODEL_EXPORT static Handle(Model_Application) getApplication();
50 //! Returns the document by the identifier
51 //! \returns false of document is not yet created/not loaded
52 MODEL_EXPORT std::shared_ptr<Model_Document> document(const int theDocID);
53 //! Returns true if document has been created
54 MODEL_EXPORT bool hasDocument(const int theDocID);
55 //! Returns true if root document has been created
56 MODEL_EXPORT bool hasRoot();
57 //! Returns root document, if created (or null otherwise)
58 MODEL_EXPORT std::shared_ptr<Model_Document> rootDocument();
59 //! Deletes the document from the application
60 MODEL_EXPORT void deleteDocument(const int theDocID);
61 //! Deletes all documents existing in the application
62 MODEL_EXPORT void deleteAllDocuments();
63 //! Creates a new document an returns an id of this document
64 //! \param theDocID if it is zero, the root document is created
65 MODEL_EXPORT void createDocument(const int theDocID);
66 //! Loads document by the file name (if it is registered as load by demand)
67 //! \param theDocName name of the document file
68 //! \param theDocID the identifier of the loaded document (to be created)
69 //! \returns true if load is ok
70 MODEL_EXPORT bool loadDocument(const std::string theDocName, const int theDocID);
72 //! Set path for the loaded by demand documents
73 void setLoadPath(std::string thePath);
74 //! Returns the path for the loaded by demand documents
75 const std::string& loadPath() const;
76 //! Defines that specified document must be loaded by demand
77 void setLoadByDemand(std::string theID, const int theDocID);
78 //! Returns true if specified document must be loaded by demand
79 bool isLoadByDemand(std::string theID, const int theDocIndex);
80 //! Closes and removes the documents that are not loaded by demand and
81 //! not in the given list
82 void removeUselessDocuments(std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs);
84 //! produces new unique identifier of the document
85 int generateDocumentId();
88 // Redefined OCAF methods
89 //! Return name of resource (i.e. "Standard")
90 Standard_CString ResourcesName();
91 //! Return format (i.e "MDTV-Standard")
92 //! \param theFormats sequence of allowed formats for input/output
93 virtual void Formats(TColStd_SequenceOfExtendedString& theFormats);
95 //! Use method GetInstance() method to obtain
96 //! the static instance of the object (or derive your own application)
100 /// Map from identifiers to created documents of an application
101 std::map<int, std::shared_ptr<Model_Document> > myDocs;
102 /// Path for the loaded by demand documents
104 /// Path for the loaded by demand documents (and the persistent ID as the value)
105 std::map<std::string, int> myLoadedByDemand;