1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Application.hxx
4 // Created: 28 Dec 2011
5 // Author: Mikhail PONIKAROV
8 #ifndef Model_Application_H_
9 #define Model_Application_H_
11 #include <Model_Document.h>
12 #include <TDocStd_Application.hxx>
15 // Define handle class
16 DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application)
18 /**\class Model_Application
20 * \brief Realization of Open CASCADE application abstraction. Class for internal use only.
22 * Application supports the formats and document management. It is uses OCAF-lke
23 * architecture and just implements specific features of the module.
25 class Model_Application : public TDocStd_Application
28 // useful methods inside of the module
31 /// Definition of "Handles" usage
32 /// \param Model_Application is the class name that is covered by the OCCT Handle
33 DEFINE_STANDARD_RTTI(Model_Application);
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);
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);
71 //! produces new unique identifier of the document
72 int generateDocumentId();
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);
82 //! Use method GetInstance() method to obtain
83 //! the static instance of the object (or derive your own application)
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
91 /// Path for the loaded by demand documents
92 std::set<std::string> myLoadedByDemand;