1 // Created on: 1997-08-07
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _CDF_Application_HeaderFile
18 #define _CDF_Application_HeaderFile
20 #include <TCollection_ExtendedString.hxx>
21 #include <PCDM_ReaderStatus.hxx>
22 #include <CDF_TypeOfActivation.hxx>
23 #include <CDF_MetaDataDriver.hxx>
24 #include <CDM_Application.hxx>
25 #include <CDM_CanCloseStatus.hxx>
26 #include <TColStd_SequenceOfExtendedString.hxx>
27 #include <Standard_IStream.hxx>
28 #include <NCollection_IndexedDataMap.hxx>
30 class Standard_NoSuchObject;
33 class TCollection_ExtendedString;
36 class PCDM_RetrievalDriver;
37 class PCDM_StorageDriver;
39 class CDF_Application;
40 DEFINE_STANDARD_HANDLE(CDF_Application, CDM_Application)
43 class CDF_Application : public CDM_Application
49 //! plugs an application.
52 //! - for opening a Document that has been created in an application
53 //! - for opening a Document from the database
54 //! - for opening a Document from a file.
55 //! The Open methods always add the document in the session directory and
56 //! calls the virtual Activate method. The document is considered to be
57 //! opened until Close is used. To be storable, a document must be
58 //! opened by an application since the application resources are
59 //! needed to store it.
60 Standard_EXPORT static Handle(CDF_Application) Load (const Standard_GUID& aGUID);
62 //! Constructs an new empty document.
63 //! This document will have the specified format.
64 //! If InitDocument() is redefined for a specific
65 //! application, the new document is handled by the
66 //! applicative session.
67 Standard_EXPORT virtual void NewDocument(const TCollection_ExtendedString& theFormat, Handle(CDM_Document)& theDoc);
69 //! Initialize a document for the applicative session.
70 //! This virtual function is called by NewDocument
71 //! and should be redefined for each specific application.
72 Standard_EXPORT virtual void InitDocument(const Handle(CDM_Document)& theDoc) const;
74 //! puts the document in the current session directory
75 //! and calls the virtual method Activate on it.
76 Standard_EXPORT void Open (const Handle(CDM_Document)& aDocument);
78 Standard_EXPORT CDM_CanCloseStatus CanClose (const Handle(CDM_Document)& aDocument);
80 //! removes the document of the current session directory
81 //! and closes the document;
82 Standard_EXPORT void Close (const Handle(CDM_Document)& aDocument);
84 //! This method retrieves a document from the database.
85 //! If the Document references other documents which have
86 //! been updated, the latest version of these documents will
87 //! be used if {UseStorageConfiguration} is Standard_True.
88 //! The content of {aFolder}, {aName} and {aVersion} depends on
89 //! the Database Manager system. If the DBMS is only based on
90 //! the OS, {aFolder} is a directory and {aName} is the name of a
91 //! file. In this case the use of the syntax with {aVersion}
92 //! has no sense. For example:
94 //! Handle(CDM_Document) theDocument=myApplication->Retrieve("/home/cascade","box.dsg");
95 //! If the DBMS is EUCLID/Design Manager, {aFolder}, {aName}
96 //! have the form they have in EUCLID/Design Manager. For example:
98 //! Handle(CDM_Document) theDocument=myApplication->Retrieve("|user|cascade","box");
100 //! Since the version is not specified in this syntax, the latest will be used.
101 //! A link is kept with the database through an instance of CDM_MetaData
102 Standard_EXPORT Handle(CDM_Document) Retrieve
103 (const TCollection_ExtendedString& aFolder,
104 const TCollection_ExtendedString& aName,
105 const Standard_Boolean UseStorageConfiguration = Standard_True,
106 const Message_ProgressRange& theRange = Message_ProgressRange());
108 //! This method retrieves a document from the database.
109 //! If the Document references other documents which have
110 //! been updated, the latest version of these documents
111 //! will be used if {UseStorageConfiguration} is
112 //! Standard_True. -- If the DBMS is only based on the
113 //! OS, this syntax should not be used.
115 //! If the DBMS is EUCLID/Design Manager, {aFolder}, {aName}
116 //! and {aVersion} have the form they have in
117 //! EUCLID/Design Manager. For example:
119 //! Handle(CDM_Document) theDocument=myApplication->Retrieve("|user|cascade","box","2");
120 //! A link is kept with the database through an instance
122 Standard_EXPORT Handle(CDM_Document) Retrieve
123 (const TCollection_ExtendedString& aFolder,
124 const TCollection_ExtendedString& aName,
125 const TCollection_ExtendedString& aVersion,
126 const Standard_Boolean UseStorageConfiguration = Standard_True,
127 const Message_ProgressRange& theRange = Message_ProgressRange());
129 Standard_EXPORT PCDM_ReaderStatus CanRetrieve (const TCollection_ExtendedString& aFolder,
130 const TCollection_ExtendedString& aName);
132 Standard_EXPORT PCDM_ReaderStatus CanRetrieve (const TCollection_ExtendedString& aFolder,
133 const TCollection_ExtendedString& aName,
134 const TCollection_ExtendedString& aVersion);
136 //! Checks status after Retrieve
137 PCDM_ReaderStatus GetRetrieveStatus() const { return myRetrievableStatus; }
139 //! Reads aDoc from standard SEEKABLE stream theIStream,
140 //! the stream should support SEEK fuctionality
141 Standard_EXPORT Handle(CDM_Document) Read
142 (Standard_IStream& theIStream,
143 const Message_ProgressRange& theRange = Message_ProgressRange());
145 //! Returns instance of read driver for specified format.
147 //! Default implementation uses plugin mechanism to load reader dynamically.
148 //! For this to work, application resources should define GUID of
149 //! the plugin as value of [Format].RetrievalPlugin, and "Plugin"
150 //! resource should define name of plugin library to be loaded as
151 //! value of [GUID].Location. Plugin library should provide
152 //! method PLUGINFACTORY returning instance of the reader for the
153 //! same GUID (see Plugin_Macro.hxx).
155 //! In case if reader is not available, will raise Standard_NoSuchObject
156 //! or other exception if raised by plugin loader.
157 Standard_EXPORT virtual Handle(PCDM_Reader) ReaderFromFormat (const TCollection_ExtendedString& aFormat);
159 //! Returns instance of storage driver for specified format.
161 //! Default implementation uses plugin mechanism to load driver dynamically.
162 //! For this to work, application resources should define GUID of
163 //! the plugin as value of [Format].StoragePlugin, and "Plugin"
164 //! resource should define name of plugin library to be loaded as
165 //! value of [GUID].Location. Plugin library should provide
166 //! method PLUGINFACTORY returning instance of the reader for the
167 //! same GUID (see Plugin_Macro.hxx).
169 //! In case if driver is not available, will raise Standard_NoSuchObject
170 //! or other exception if raised by plugin loader.
171 Standard_EXPORT virtual Handle(PCDM_StorageDriver) WriterFromFormat (const TCollection_ExtendedString& aFormat);
173 //! try to retrieve a Format directly in the file or in
174 //! application resource by using extension. returns
176 Standard_EXPORT Standard_Boolean Format (const TCollection_ExtendedString& aFileName,
177 TCollection_ExtendedString& theFormat);
179 Standard_EXPORT Standard_ExtString DefaultFolder();
181 Standard_EXPORT Standard_Boolean SetDefaultFolder (const Standard_ExtString aFolder);
183 //! returns MetaDatdDriver of this application
184 Standard_EXPORT Handle(CDF_MetaDataDriver) MetaDataDriver() const;
186 DEFINE_STANDARD_RTTIEXT(CDF_Application,CDM_Application)
188 Handle(CDF_MetaDataDriver) myMetaDataDriver;
189 Handle(CDF_Directory) myDirectory;
193 //! Informs the application that aDocument has been
194 //! activated. A document is activated when it is created or
196 //! aTypeOfActivation will be:
197 //! - CDF_TOA_New if the document is a new one
198 //! (even empty or retrieved from the database for
200 //! - CDF_TOA_Unchanged if the document was already
201 //! retrieved but had no changes since the previous retrieval.
202 //! - CDF_TOA_Modified if the document was already
203 //! retrieved and modified since the previous retrieval.
204 //! You do not need to call <Activate>, but you should redefine
205 //! this method to implement application specific behavior.
206 Standard_EXPORT virtual void Activate (const Handle(CDM_Document)& aDocument,
207 const CDF_TypeOfActivation aTypeOfActivation);
209 Standard_EXPORT Handle(CDM_Document) Retrieve
210 (const Handle(CDM_MetaData)& aMetaData,
211 const Standard_Boolean UseStorageConfiguration,
212 const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE;
214 Standard_EXPORT Handle(CDM_Document) Retrieve
215 (const Handle(CDM_MetaData)& aMetaData,
216 const Standard_Boolean UseStorageConfiguration,
217 const Standard_Boolean IsComponent,
218 const Message_ProgressRange& theRange = Message_ProgressRange());
220 Standard_EXPORT Standard_Integer DocumentVersion (const Handle(CDM_MetaData)& theMetaData) Standard_OVERRIDE;
222 Standard_EXPORT CDF_TypeOfActivation TypeOfActivation (const Handle(CDM_MetaData)& aMetaData);
224 Standard_EXPORT PCDM_ReaderStatus CanRetrieve (const Handle(CDM_MetaData)& aMetaData);
228 Standard_EXPORT CDF_Application();
230 PCDM_ReaderStatus myRetrievableStatus;
231 NCollection_IndexedDataMap<TCollection_ExtendedString, Handle(PCDM_RetrievalDriver)> myReaders;
232 NCollection_IndexedDataMap<TCollection_ExtendedString, Handle(PCDM_StorageDriver)> myWriters;
235 TCollection_ExtendedString myDefaultFolder;
238 #endif // _CDF_Application_HeaderFile