dae631394a4848506567c2495540746f64ca49e4
[occt.git] / src / TDocStd / TDocStd_Application.hxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _TDocStd_Application_HeaderFile
18 #define _TDocStd_Application_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Boolean.hxx>
24 #include <CDF_Application.hxx>
25 #include <Standard_CString.hxx>
26 #include <Standard_Integer.hxx>
27 #include <TColStd_SequenceOfExtendedString.hxx>
28 #include <PCDM_ReaderStatus.hxx>
29 #include <PCDM_StoreStatus.hxx>
30 class Resource_Manager;
31 class Standard_NoSuchObject;
32 class TDocStd_Document;
33 class TCollection_ExtendedString;
34
35
36 class TDocStd_Application;
37 DEFINE_STANDARD_HANDLE(TDocStd_Application, CDF_Application)
38
39
40 //! The abstract root class for all application classes.
41 //! They are in charge of:
42 //! -   Creating documents
43 //! -   Storing documents and retrieving them
44 //! -   Initializing document views.
45 //! To create a useful OCAF-based application, you
46 //! derive a class from Application and implement
47 //! the methods below. You will have to redefine the
48 //! deferred (virtual) methods Formats,
49 //! InitDocument, and Resources, and override others.
50 //! The application is a container for a document,
51 //! which in its turn is the container of the data
52 //! framework made up of labels and attributes.
53 //! Besides furnishing a container for documents,
54 //! TDocStd_Application provides the following
55 //! services for them:
56 //! -   Creation of new documents
57 //! -   Activation of documents in sessions of an application
58 //! -   Storage and retrieval of documents
59 //! -   Initialization of document views.
60 //! Note:
61 //! If a client needs detailed information concerning
62 //! the events during the Open/Store operation, MessageDriver
63 //! inherited from CDM_MessageDriver of the
64 //! corresponding application has to be implemented.
65 //! If the MessageDriver is not defined all messages
66 //! will be (by default) directed to
67 //! CDM_NullMessageDriver and will be lost.
68 class TDocStd_Application : public CDF_Application
69 {
70
71 public:
72
73   
74   //! Check if meta data driver was successfully loaded
75   //! by the application constructor
76   Standard_EXPORT Standard_Boolean IsDriverLoaded() const;
77   
78   //! create  (if  not done)  a Manager  using ResourcesName
79   //! method.
80   Standard_EXPORT virtual Handle(Resource_Manager) Resources() Standard_OVERRIDE;
81   
82   //! Returns the name of the file containing the
83   //! resources of this application.
84   //! In a resource file, the application associates the schema name
85   //! of the document with the storage and
86   //! retrieval plug-ins that are to be loaded for each
87   //! document. On retrieval, the application reads the
88   //! schema name in the heading of the CSF file and
89   //! loads the plug-in indicated in the resource file.
90   //! This plug-in instantiates the actual driver for
91   //! transient-persistent conversion.
92   //! Your application can bring this process into play
93   //! by defining a class which inherits
94   //! CDF_Application and redefines the function
95   //! which returns the appropriate resources file. At
96   //! this point, the function Retrieve and the class
97   //! CDF_Store can be called. This allows you to
98   //! deal with storage and retrieval of - as well as
99   //! copying and pasting - documents.
100   //! To implement a class like this, several virtual
101   //! functions should be redefined. In particular, you
102   //! must redefine the abstract function Resources
103   //! inherited from the superclass CDM_Application.
104   Standard_EXPORT virtual Standard_CString ResourcesName() = 0;
105   
106   //! returns the number of documents handled by the current applicative session.
107   Standard_EXPORT Standard_Integer NbDocuments() const;
108   
109   //! Constructs the new document aDoc.
110   //! aDoc is identified by the index index which is
111   //! any integer between 1 and n where n is the
112   //! number of documents returned by NbDocument.
113   //! Example
114   //! Handle(TDocStd_Application)
115   //! anApp;
116   //! if (!CafTest::Find(A)) return 1;
117   //! Handle(TDocStd) aDoc;
118   //! Standard_Integer nbdoc = anApp->NbDocuments();
119   //! for (Standard_Integer i = 1; i <= nbdoc; i++) {
120   //! aApp->GetDocument(i,aDoc);
121   Standard_EXPORT void GetDocument (const Standard_Integer index, Handle(TDocStd_Document)& aDoc) const;
122   
123
124   //! Returns the format name Formats
125   //! representing the format supported for
126   //! application documents.
127   //! This virtual function is to be redefined for each
128   //! specific application.
129   Standard_EXPORT virtual void Formats (TColStd_SequenceOfExtendedString& Formats) Standard_OVERRIDE = 0;
130   
131   //! Constructs the empty new document aDoc.
132   //! This document will have the format format.
133   //! If InitDocument is redefined for a specific
134   //! application, the new document is handled by the
135   //! applicative session.
136   Standard_EXPORT virtual void NewDocument (const TCollection_ExtendedString& format, Handle(TDocStd_Document)& aDoc);
137   
138   //! Initialize the document aDoc for the applicative session.
139   //! This virtual function is called by NewDocument
140   //! and is to be redefined for each specific application.
141   //! Modified flag (different of disk version)
142   //! =============
143   //! to open/save a document
144   //! =======================
145   Standard_EXPORT virtual void InitDocument (const Handle(TDocStd_Document)& aDoc) const;
146   
147   //! Close the given document. the document is not any more
148   //! handled by the applicative session.
149   Standard_EXPORT void Close (const Handle(TDocStd_Document)& aDoc);
150   
151   //! Returns an index for the document found in the
152   //! path path in this applicative session.
153   //! If the returned value is 0, the document is not
154   //! present in the applicative session.
155   //! This method can be used for the interactive part
156   //! of an application. For instance, on a call to
157   //! Open, the document to be opened may already
158   //! be in memory. IsInSession checks to see if this
159   //! is the case. Open can be made to depend on
160   //! the value of the index returned: if IsInSession
161   //! returns 0, the document is opened; if it returns
162   //! another value, a message is displayed asking the
163   //! user if he wants to override the version of the
164   //! document in memory.
165   //! Example:
166   //! Standard_Integer insession = A->IsInSession(aDoc);
167   //! if (insession > 0) {
168   //! cout << "document " << insession << " is already in session" << endl;
169   //! return 0;
170   //! }
171   Standard_EXPORT Standard_Integer IsInSession (const TCollection_ExtendedString& path) const;
172   
173   //! Retrieves the document aDoc stored under the
174   //! name aName in the directory directory.
175   //! In order not to override a version of aDoc which
176   //! is already in memory, this method can be made
177   //! to depend on the value returned by IsInSession.
178   Standard_EXPORT PCDM_ReaderStatus Open (const TCollection_ExtendedString& path, Handle(TDocStd_Document)& aDoc);
179   
180   //! Save the  active document  in the file  <name> in the
181   //! path <path> ; o verwrites  the file  if  it already exists.
182   Standard_EXPORT PCDM_StoreStatus SaveAs (const Handle(TDocStd_Document)& aDoc, const TCollection_ExtendedString& path);
183   
184   //! Save aDoc active document.
185   //! Exceptions:
186   //! Standard_NotImplemented if the document
187   //! was not retrieved in the applicative session by using Open.
188   Standard_EXPORT PCDM_StoreStatus Save (const Handle(TDocStd_Document)& aDoc);
189   
190   //! Save the  active document  in the file  <name> in the
191   //! path <path>  .  overwrite  the file  if  it
192   //! already exist.
193   Standard_EXPORT PCDM_StoreStatus SaveAs (const Handle(TDocStd_Document)& aDoc, const TCollection_ExtendedString& path, TCollection_ExtendedString& theStatusMessage);
194   
195   //! Save the document overwriting the previous file
196   Standard_EXPORT PCDM_StoreStatus Save (const Handle(TDocStd_Document)& aDoc, TCollection_ExtendedString& theStatusMessage);
197
198
199 friend class TDocStd_Document;
200
201
202   DEFINE_STANDARD_RTTIEXT(TDocStd_Application,CDF_Application)
203
204 protected:
205
206   
207   Standard_EXPORT TDocStd_Application();
208   
209   //! Notification that is fired at each OpenTransaction event.
210   Standard_EXPORT virtual void OnOpenTransaction (const Handle(TDocStd_Document)& theDoc);
211   
212   //! Notification that is fired at each CommitTransaction event.
213   Standard_EXPORT virtual void OnCommitTransaction (const Handle(TDocStd_Document)& theDoc);
214   
215   //! Notification that is fired at each AbortTransaction event.
216   Standard_EXPORT virtual void OnAbortTransaction (const Handle(TDocStd_Document)& theDoc);
217
218   Handle(Resource_Manager) myResources;
219   Standard_Boolean myIsDriverLoaded;
220
221
222 private:
223
224
225
226
227 };
228
229
230
231
232
233
234
235 #endif // _TDocStd_Application_HeaderFile