1 // Created on: 1999-06-30
2 // Created by: Denis PASCAL
3 // Copyright (c) 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 _TDocStd_Application_HeaderFile
18 #define _TDocStd_Application_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <CDF_Application.hxx>
25 #include <Message_Messenger.hxx>
26 #include <Standard_CString.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_IStream.hxx>
29 #include <TColStd_SequenceOfAsciiString.hxx>
30 #include <PCDM_ReaderStatus.hxx>
31 #include <PCDM_StoreStatus.hxx>
33 class Resource_Manager;
34 class Standard_NoSuchObject;
35 class TDocStd_Document;
36 class TCollection_ExtendedString;
38 class TDocStd_Application;
39 DEFINE_STANDARD_HANDLE(TDocStd_Application, CDF_Application)
42 //! The abstract root class for all application classes.
43 //! They are in charge of:
44 //! - Creating documents
45 //! - Storing documents and retrieving them
46 //! - Initializing document views.
47 //! To create a useful OCAF-based application, you
48 //! derive a class from Application and implement
49 //! the methods below. You will have to redefine the
50 //! deferred (virtual) methods Formats,
51 //! InitDocument, and Resources, and override others.
52 //! The application is a container for a document,
53 //! which in its turn is the container of the data
54 //! framework made up of labels and attributes.
55 //! Besides furnishing a container for documents,
56 //! TDocStd_Application provides the following
57 //! services for them:
58 //! - Creation of new documents
59 //! - Activation of documents in sessions of an application
60 //! - Storage and retrieval of documents
61 //! - Initialization of document views.
63 //! If a client needs detailed information concerning
64 //! the events during the Open/Store operation, a MessageDriver
65 //! based on Message_PrinterOStream may be used. In case of need client
66 //! can implement his own version inheriting from Message_Printer class
67 //! and add it to the Messanger.
68 //! Also the trace level of messages can be tuned by setting trace level (SetTraceLevel (Gravity )) for the used Printer.
69 //! By default, trace level is Message_Info, so that all messages are output.
71 class TDocStd_Application : public CDF_Application
76 //! Constructs the new instance and registers it in CDM_Session
77 Standard_EXPORT TDocStd_Application();
79 //! Check if meta data driver was successfully loaded
80 //! by the application constructor
81 Standard_EXPORT Standard_Boolean IsDriverLoaded() const;
83 //! Returns resource manager defining supported persistent formats.
85 //! Default implementation loads resource file with name ResourcesName(),
86 //! unless field myResources is already initialized (either by
87 //! previous call or in any other way).
89 //! The resource manager should define:
91 //! * Format name for each file extension supported:
92 //! - [Extension].FileFormat: [Format]
94 //! * For each format supported (as returned by Formats()),
95 //! its extension, description string, and (when applicable)
96 //! GUIDs of storage and retrieval plugins:
97 //! - [Format].Description: [Description]
98 //! - [Format].FileExtension: [Extension]
99 //! - [Format].RetrievalPlugin: [GUID] (optional)
100 //! - [Format].StoragePlugin: [GUID] (optional)
101 Standard_EXPORT virtual Handle(Resource_Manager) Resources() Standard_OVERRIDE;
103 //! Returns the name of the file containing the
104 //! resources of this application, for support of legacy
105 //! method of loading formats data from resource files.
107 //! Method DefineFormat() can be used to define all necessary
108 //! parameters explicitly without actually using resource files.
110 //! In a resource file, the application associates the
111 //! schema name of the document with the storage and
112 //! retrieval plug-ins that are to be loaded for each
113 //! document. On retrieval, the application reads the
114 //! schema name in the heading of the CSF file and
115 //! loads the plug-in indicated in the resource file.
116 //! This plug-in instantiates the actual driver for
117 //! transient-persistent conversion.
118 //! Your application can bring this process into play
119 //! by defining a class which inherits
120 //! CDF_Application and redefines the function
121 //! which returns the appropriate resources file. At
122 //! this point, the function Retrieve and the class
123 //! CDF_Store can be called. This allows you to
124 //! deal with storage and retrieval of - as well as
125 //! copying and pasting - documents.
126 //! To implement a class like this, several virtual
127 //! functions should be redefined. In particular, you
128 //! must redefine the abstract function Resources
129 //! inherited from the superclass CDM_Application.
131 //! Default implementation returns empty string.
132 Standard_EXPORT virtual Standard_CString ResourcesName();
134 //! Sets up resources and registers read and storage drivers for
135 //! the specified format.
137 //! @param theFormat - unique name for the format, used to identify it.
138 //! @param theDescription - textual description of the format.
139 //! @param theExtension - extension of the files in that format.
140 //! The same extension can be used by several formats.
141 //! @param theReader - instance of the read driver for the format.
142 //! Null value is allowed (no possibility to read).
143 //! @param theWriter - instance of the write driver for the format.
144 //! Null value is allowed (no possibility to write).
145 Standard_EXPORT void DefineFormat (const TCollection_AsciiString& theFormat,
146 const TCollection_AsciiString& theDescription,
147 const TCollection_AsciiString& theExtension,
148 const Handle(PCDM_RetrievalDriver)& theReader,
149 const Handle(PCDM_StorageDriver)& theWriter);
151 //! Returns the sequence of reading formats supported by the application.
153 //! @param theFormats - sequence of reading formats. Output parameter.
154 Standard_EXPORT void ReadingFormats(TColStd_SequenceOfAsciiString &theFormats);
156 //! Returns the sequence of writing formats supported by the application.
158 //! @param theFormats - sequence of writing formats. Output parameter.
159 Standard_EXPORT void WritingFormats(TColStd_SequenceOfAsciiString &theFormats);
161 //! returns the number of documents handled by the current applicative session.
162 Standard_EXPORT Standard_Integer NbDocuments() const;
164 //! Constructs the new document aDoc.
165 //! aDoc is identified by the index index which is
166 //! any integer between 1 and n where n is the
167 //! number of documents returned by NbDocument.
169 //! Handle(TDocStd_Application)
171 //! if (!CafTest::Find(A)) return 1;
172 //! Handle(TDocStd) aDoc;
173 //! Standard_Integer nbdoc = anApp->NbDocuments();
174 //! for (Standard_Integer i = 1; i <= nbdoc; i++) {
175 //! aApp->GetDocument(i,aDoc);
176 Standard_EXPORT void GetDocument (const Standard_Integer index, Handle(TDocStd_Document)& aDoc) const;
178 //! Constructs the empty new document aDoc.
179 //! This document will have the format format.
180 //! If InitDocument is redefined for a specific
181 //! application, the new document is handled by the
182 //! applicative session.
183 Standard_EXPORT virtual void NewDocument (const TCollection_ExtendedString& format, Handle(TDocStd_Document)& aDoc);
185 //! Initialize the document aDoc for the applicative session.
186 //! This virtual function is called by NewDocument
187 //! and is to be redefined for each specific application.
188 //! Modified flag (different of disk version)
190 //! to open/save a document
191 //! =======================
192 Standard_EXPORT virtual void InitDocument (const Handle(TDocStd_Document)& aDoc) const;
194 //! Close the given document. the document is not any more
195 //! handled by the applicative session.
196 Standard_EXPORT void Close (const Handle(TDocStd_Document)& aDoc);
198 //! Returns an index for the document found in the
199 //! path path in this applicative session.
200 //! If the returned value is 0, the document is not
201 //! present in the applicative session.
202 //! This method can be used for the interactive part
203 //! of an application. For instance, on a call to
204 //! Open, the document to be opened may already
205 //! be in memory. IsInSession checks to see if this
206 //! is the case. Open can be made to depend on
207 //! the value of the index returned: if IsInSession
208 //! returns 0, the document is opened; if it returns
209 //! another value, a message is displayed asking the
210 //! user if he wants to override the version of the
211 //! document in memory.
213 //! Standard_Integer insession = A->IsInSession(aDoc);
214 //! if (insession > 0) {
215 //! std::cout << "document " << insession << " is already in session" << std::endl;
218 Standard_EXPORT Standard_Integer IsInSession (const TCollection_ExtendedString& path) const;
220 //! Retrieves the document aDoc stored under the
221 //! name aName in the directory directory.
222 //! In order not to override a version of aDoc which
223 //! is already in memory, this method can be made
224 //! to depend on the value returned by IsInSession.
225 Standard_EXPORT PCDM_ReaderStatus Open (const TCollection_ExtendedString& path,
226 Handle(TDocStd_Document)& aDoc,
227 const Handle(Message_ProgressIndicator)& theProgress = NULL);
229 //! Retrieves aDoc from standard SEEKABLE stream theIStream.
230 //! the stream should support SEEK fuctionality
231 Standard_EXPORT PCDM_ReaderStatus Open (Standard_IStream& theIStream, Handle(TDocStd_Document)& theDoc,
232 const Handle(Message_ProgressIndicator)& theProgress = NULL);
235 //! Save the active document in the file <name> in the
236 //! path <path> ; o verwrites the file if it already exists.
237 Standard_EXPORT PCDM_StoreStatus SaveAs (const Handle(TDocStd_Document)& aDoc,
238 const TCollection_ExtendedString& path,
239 const Handle(Message_ProgressIndicator)& theProgress = NULL);
241 //! Save theDoc to standard SEEKABLE stream theOStream.
242 //! the stream should support SEEK fuctionality
243 Standard_EXPORT PCDM_StoreStatus SaveAs (const Handle(TDocStd_Document)& theDoc,
244 Standard_OStream& theOStream,
245 const Handle(Message_ProgressIndicator)& theProgress = NULL);
247 //! Save aDoc active document.
249 //! Standard_NotImplemented if the document
250 //! was not retrieved in the applicative session by using Open.
251 Standard_EXPORT PCDM_StoreStatus Save (const Handle(TDocStd_Document)& aDoc,
252 const Handle(Message_ProgressIndicator)& theProgress = NULL);
254 //! Save the active document in the file <name> in the
255 //! path <path> . overwrite the file if it
257 Standard_EXPORT PCDM_StoreStatus SaveAs (const Handle(TDocStd_Document)& aDoc,
258 const TCollection_ExtendedString& path,
259 TCollection_ExtendedString& theStatusMessage,
260 const Handle(Message_ProgressIndicator)& theProgress = NULL);
262 //! Save theDoc TO standard SEEKABLE stream theOStream.
263 //! the stream should support SEEK fuctionality
264 Standard_EXPORT PCDM_StoreStatus SaveAs (const Handle(TDocStd_Document)& theDoc,
265 Standard_OStream& theOStream,
266 TCollection_ExtendedString& theStatusMessage,
267 const Handle(Message_ProgressIndicator)& theProgress = NULL);
269 //! Save the document overwriting the previous file
270 Standard_EXPORT PCDM_StoreStatus Save (const Handle(TDocStd_Document)& aDoc,
271 TCollection_ExtendedString& theStatusMessage,
272 const Handle(Message_ProgressIndicator)& theProgress = NULL);
274 //! Notification that is fired at each OpenTransaction event.
275 Standard_EXPORT virtual void OnOpenTransaction (const Handle(TDocStd_Document)& theDoc);
277 //! Notification that is fired at each CommitTransaction event.
278 Standard_EXPORT virtual void OnCommitTransaction (const Handle(TDocStd_Document)& theDoc);
280 //! Notification that is fired at each AbortTransaction event.
281 Standard_EXPORT virtual void OnAbortTransaction (const Handle(TDocStd_Document)& theDoc);
283 //! Dumps the content of me into the stream
284 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
286 //! Remove this application from the current session
287 Standard_EXPORT Standard_Boolean RemoveFromSession();
289 DEFINE_STANDARD_RTTIEXT(TDocStd_Application, CDF_Application)
293 Handle(Resource_Manager) myResources;
294 Standard_Boolean myIsDriverLoaded;
298 //! Add this application to the current session (register in internal container)
302 #endif // _TDocStd_Application_HeaderFile