|
|
|||
File indexing completed on 2026-09-08 09:17:48
0001 // Created on: 1999-06-30 0002 // Created by: Denis PASCAL 0003 // Copyright (c) 1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _TDocStd_Application_HeaderFile 0018 #define _TDocStd_Application_HeaderFile 0019 0020 #include <Standard.hxx> 0021 0022 #include <CDF_Application.hxx> 0023 #include <Message_Messenger.hxx> 0024 #include <Standard_Integer.hxx> 0025 #include <Standard_IStream.hxx> 0026 #include <TColStd_SequenceOfAsciiString.hxx> 0027 #include <PCDM_ReaderStatus.hxx> 0028 #include <PCDM_StoreStatus.hxx> 0029 #include <TDocStd_Document.hxx> 0030 0031 class Resource_Manager; 0032 class CDM_Document; 0033 class TCollection_ExtendedString; 0034 0035 class TDocStd_Application; 0036 DEFINE_STANDARD_HANDLE(TDocStd_Application, CDF_Application) 0037 0038 //! The abstract root class for all application classes. 0039 //! They are in charge of: 0040 //! - Creating documents 0041 //! - Storing documents and retrieving them 0042 //! - Initializing document views. 0043 //! To create a useful OCAF-based application, you 0044 //! derive a class from Application and implement 0045 //! the methods below. You will have to redefine the 0046 //! deferred (virtual) methods Formats, 0047 //! InitDocument, and Resources, and override others. 0048 //! The application is a container for a document, 0049 //! which in its turn is the container of the data 0050 //! framework made up of labels and attributes. 0051 //! Besides furnishing a container for documents, 0052 //! TDocStd_Application provides the following 0053 //! services for them: 0054 //! - Creation of new documents 0055 //! - Activation of documents in sessions of an application 0056 //! - Storage and retrieval of documents 0057 //! - Initialization of document views. 0058 //! Note: 0059 //! If a client needs detailed information concerning 0060 //! the events during the Open/Store operation, a MessageDriver 0061 //! based on Message_PrinterOStream may be used. In case of need client 0062 //! can implement his own version inheriting from Message_Printer class 0063 //! and add it to the Messenger. 0064 //! Also the trace level of messages can be tuned by setting trace level (SetTraceLevel (Gravity )) 0065 //! for the used Printer. By default, trace level is Message_Info, so that all messages are output. 0066 0067 class TDocStd_Application : public CDF_Application 0068 { 0069 0070 public: 0071 //! Constructs the new instance and registers it in CDM_Session 0072 Standard_EXPORT TDocStd_Application(); 0073 0074 //! Check if meta data driver was successfully loaded 0075 //! by the application constructor 0076 Standard_EXPORT Standard_Boolean IsDriverLoaded() const; 0077 0078 //! Returns resource manager defining supported persistent formats. 0079 //! 0080 //! Default implementation loads resource file with name ResourcesName(), 0081 //! unless field myResources is already initialized (either by 0082 //! previous call or in any other way). 0083 //! 0084 //! The resource manager should define: 0085 //! 0086 //! * Format name for each file extension supported: 0087 //! - [Extension].FileFormat: [Format] 0088 //! 0089 //! * For each format supported (as returned by Formats()), 0090 //! its extension, description string, and (when applicable) 0091 //! GUIDs of storage and retrieval plugins: 0092 //! - [Format].Description: [Description] 0093 //! - [Format].FileExtension: [Extension] 0094 //! - [Format].RetrievalPlugin: [GUID] (optional) 0095 //! - [Format].StoragePlugin: [GUID] (optional) 0096 Standard_EXPORT virtual Handle(Resource_Manager) Resources() Standard_OVERRIDE; 0097 0098 //! Returns the name of the file containing the 0099 //! resources of this application, for support of legacy 0100 //! method of loading formats data from resource files. 0101 //! 0102 //! Method DefineFormat() can be used to define all necessary 0103 //! parameters explicitly without actually using resource files. 0104 //! 0105 //! In a resource file, the application associates the 0106 //! schema name of the document with the storage and 0107 //! retrieval plug-ins that are to be loaded for each 0108 //! document. On retrieval, the application reads the 0109 //! schema name in the heading of the CSF file and 0110 //! loads the plug-in indicated in the resource file. 0111 //! This plug-in instantiates the actual driver for 0112 //! transient-persistent conversion. 0113 //! Your application can bring this process into play 0114 //! by defining a class which inherits 0115 //! CDF_Application and redefines the function 0116 //! which returns the appropriate resources file. At 0117 //! this point, the function Retrieve and the class 0118 //! CDF_Store can be called. This allows you to 0119 //! deal with storage and retrieval of - as well as 0120 //! copying and pasting - documents. 0121 //! To implement a class like this, several virtual 0122 //! functions should be redefined. In particular, you 0123 //! must redefine the abstract function Resources 0124 //! inherited from the superclass CDM_Application. 0125 //! 0126 //! Default implementation returns empty string. 0127 Standard_EXPORT virtual Standard_CString ResourcesName(); 0128 0129 //! Sets up resources and registers read and storage drivers for 0130 //! the specified format. 0131 //! 0132 //! @param theFormat - unique name for the format, used to identify it. 0133 //! @param theDescription - textual description of the format. 0134 //! @param theExtension - extension of the files in that format. 0135 //! The same extension can be used by several formats. 0136 //! @param theReader - instance of the read driver for the format. 0137 //! Null value is allowed (no possibility to read). 0138 //! @param theWriter - instance of the write driver for the format. 0139 //! Null value is allowed (no possibility to write). 0140 Standard_EXPORT void DefineFormat(const TCollection_AsciiString& theFormat, 0141 const TCollection_AsciiString& theDescription, 0142 const TCollection_AsciiString& theExtension, 0143 const Handle(PCDM_RetrievalDriver)& theReader, 0144 const Handle(PCDM_StorageDriver)& theWriter); 0145 0146 //! Returns the sequence of reading formats supported by the application. 0147 //! 0148 //! @param theFormats - sequence of reading formats. Output parameter. 0149 Standard_EXPORT void ReadingFormats(TColStd_SequenceOfAsciiString& theFormats); 0150 0151 //! Returns the sequence of writing formats supported by the application. 0152 //! 0153 //! @param theFormats - sequence of writing formats. Output parameter. 0154 Standard_EXPORT void WritingFormats(TColStd_SequenceOfAsciiString& theFormats); 0155 0156 //! returns the number of documents handled by the current applicative session. 0157 Standard_EXPORT Standard_Integer NbDocuments() const; 0158 0159 //! Constructs the new document aDoc. 0160 //! aDoc is identified by the index index which is 0161 //! any integer between 1 and n where n is the 0162 //! number of documents returned by NbDocument. 0163 //! Example 0164 //! Handle(TDocStd_Application) 0165 //! anApp; 0166 //! if (!CafTest::Find(A)) return 1; 0167 //! Handle(TDocStd) aDoc; 0168 //! Standard_Integer nbdoc = anApp->NbDocuments(); 0169 //! for (Standard_Integer i = 1; i <= nbdoc; i++) { 0170 //! aApp->GetDocument(i,aDoc); 0171 Standard_EXPORT void GetDocument(const Standard_Integer index, 0172 Handle(TDocStd_Document)& aDoc) const; 0173 0174 //! Constructs the empty new document aDoc. 0175 //! This document will have the format format. 0176 //! If InitDocument is redefined for a specific 0177 //! application, the new document is handled by the 0178 //! applicative session. 0179 Standard_EXPORT virtual void NewDocument(const TCollection_ExtendedString& format, 0180 Handle(CDM_Document)& aDoc) Standard_OVERRIDE; 0181 0182 //! A non-virtual method taking a TDocStd_Documment object as an input. 0183 //! Internally it calls a virtual method NewDocument() with CDM_Document object. 0184 Standard_EXPORT void NewDocument(const TCollection_ExtendedString& format, 0185 Handle(TDocStd_Document)& aDoc); 0186 0187 //! Initialize the document aDoc for the applicative session. 0188 //! This virtual function is called by NewDocument 0189 //! and is to be redefined for each specific application. 0190 //! Modified flag (different of disk version) 0191 //! ============= 0192 //! to open/save a document 0193 //! ======================= 0194 Standard_EXPORT virtual void InitDocument(const Handle(CDM_Document)& aDoc) const 0195 Standard_OVERRIDE; 0196 0197 //! Close the given document. the document is not any more 0198 //! handled by the applicative session. 0199 Standard_EXPORT void Close(const Handle(TDocStd_Document)& aDoc); 0200 0201 //! Returns an index for the document found in the 0202 //! path path in this applicative session. 0203 //! If the returned value is 0, the document is not 0204 //! present in the applicative session. 0205 //! This method can be used for the interactive part 0206 //! of an application. For instance, on a call to 0207 //! Open, the document to be opened may already 0208 //! be in memory. IsInSession checks to see if this 0209 //! is the case. Open can be made to depend on 0210 //! the value of the index returned: if IsInSession 0211 //! returns 0, the document is opened; if it returns 0212 //! another value, a message is displayed asking the 0213 //! user if he wants to override the version of the 0214 //! document in memory. 0215 //! Example: 0216 //! Standard_Integer insession = A->IsInSession(aDoc); 0217 //! if (insession > 0) { 0218 //! std::cout << "document " << insession << " is already in session" << std::endl; 0219 //! return 0; 0220 //! } 0221 Standard_EXPORT Standard_Integer IsInSession(const TCollection_ExtendedString& path) const; 0222 0223 //! Retrieves the document from specified file. 0224 //! In order not to override a version of the document which is already in memory, 0225 //! this method can be made to depend on the value returned by IsInSession. 0226 //! @param[in] thePath file path to open 0227 //! @param[out] theDoc result document 0228 //! @param[in] theFilter optional filter to skip attributes or parts of the retrieved tree 0229 //! @param[in] theRange optional progress indicator 0230 //! @return reading status 0231 Standard_EXPORT PCDM_ReaderStatus 0232 Open(const TCollection_ExtendedString& thePath, 0233 Handle(TDocStd_Document)& theDoc, 0234 const Handle(PCDM_ReaderFilter)& theFilter, 0235 const Message_ProgressRange& theRange = Message_ProgressRange()); 0236 0237 //! Retrieves the document from specified file. 0238 //! In order not to override a version of the document which is already in memory, 0239 //! this method can be made to depend on the value returned by IsInSession. 0240 //! @param[in] thePath file path to open 0241 //! @param[out] theDoc result document 0242 //! @param[in] theRange optional progress indicator 0243 //! @return reading status 0244 PCDM_ReaderStatus Open(const TCollection_ExtendedString& thePath, 0245 Handle(TDocStd_Document)& theDoc, 0246 const Message_ProgressRange& theRange = Message_ProgressRange()) 0247 { 0248 return Open(thePath, theDoc, Handle(PCDM_ReaderFilter)(), theRange); 0249 } 0250 0251 //! Retrieves document from standard stream. 0252 //! @param[in,out] theIStream input seekable stream 0253 //! @param[out] theDoc result document 0254 //! @param[in] theFilter optional filter to skip attributes or parts of the retrieved tree 0255 //! @param[in] theRange optional progress indicator 0256 //! @return reading status 0257 Standard_EXPORT PCDM_ReaderStatus 0258 Open(Standard_IStream& theIStream, 0259 Handle(TDocStd_Document)& theDoc, 0260 const Handle(PCDM_ReaderFilter)& theFilter, 0261 const Message_ProgressRange& theRange = Message_ProgressRange()); 0262 0263 //! Retrieves document from standard stream. 0264 //! @param[in,out] theIStream input seekable stream 0265 //! @param[out] theDoc result document 0266 //! @param[in] theRange optional progress indicator 0267 //! @return reading status 0268 PCDM_ReaderStatus Open(Standard_IStream& theIStream, 0269 Handle(TDocStd_Document)& theDoc, 0270 const Message_ProgressRange& theRange = Message_ProgressRange()) 0271 { 0272 return Open(theIStream, theDoc, Handle(PCDM_ReaderFilter)(), theRange); 0273 } 0274 0275 //! Save the active document in the file <name> in the 0276 //! path <path> ; o verwrites the file if it already exists. 0277 Standard_EXPORT PCDM_StoreStatus 0278 SaveAs(const Handle(TDocStd_Document)& theDoc, 0279 const TCollection_ExtendedString& path, 0280 const Message_ProgressRange& theRange = Message_ProgressRange()); 0281 0282 //! Save theDoc to standard SEEKABLE stream theOStream. 0283 //! the stream should support SEEK functionality 0284 Standard_EXPORT PCDM_StoreStatus 0285 SaveAs(const Handle(TDocStd_Document)& theDoc, 0286 Standard_OStream& theOStream, 0287 const Message_ProgressRange& theRange = Message_ProgressRange()); 0288 0289 //! Save aDoc active document. 0290 //! Exceptions: 0291 //! Standard_NotImplemented if the document 0292 //! was not retrieved in the applicative session by using Open. 0293 Standard_EXPORT PCDM_StoreStatus 0294 Save(const Handle(TDocStd_Document)& theDoc, 0295 const Message_ProgressRange& theRange = Message_ProgressRange()); 0296 0297 //! Save the active document in the file <name> in the 0298 //! path <path> . overwrite the file if it 0299 //! already exist. 0300 Standard_EXPORT PCDM_StoreStatus 0301 SaveAs(const Handle(TDocStd_Document)& theDoc, 0302 const TCollection_ExtendedString& path, 0303 TCollection_ExtendedString& theStatusMessage, 0304 const Message_ProgressRange& theRange = Message_ProgressRange()); 0305 0306 //! Save theDoc TO standard SEEKABLE stream theOStream. 0307 //! the stream should support SEEK functionality 0308 Standard_EXPORT PCDM_StoreStatus 0309 SaveAs(const Handle(TDocStd_Document)& theDoc, 0310 Standard_OStream& theOStream, 0311 TCollection_ExtendedString& theStatusMessage, 0312 const Message_ProgressRange& theRange = Message_ProgressRange()); 0313 0314 //! Save the document overwriting the previous file 0315 Standard_EXPORT PCDM_StoreStatus 0316 Save(const Handle(TDocStd_Document)& theDoc, 0317 TCollection_ExtendedString& theStatusMessage, 0318 const Message_ProgressRange& theRange = Message_ProgressRange()); 0319 0320 //! Notification that is fired at each OpenTransaction event. 0321 Standard_EXPORT virtual void OnOpenTransaction(const Handle(TDocStd_Document)& theDoc); 0322 0323 //! Notification that is fired at each CommitTransaction event. 0324 Standard_EXPORT virtual void OnCommitTransaction(const Handle(TDocStd_Document)& theDoc); 0325 0326 //! Notification that is fired at each AbortTransaction event. 0327 Standard_EXPORT virtual void OnAbortTransaction(const Handle(TDocStd_Document)& theDoc); 0328 0329 //! Dumps the content of me into the stream 0330 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; 0331 0332 DEFINE_STANDARD_RTTIEXT(TDocStd_Application, CDF_Application) 0333 0334 protected: 0335 Handle(Resource_Manager) myResources; 0336 Standard_Boolean myIsDriverLoaded; 0337 }; 0338 0339 #endif // _TDocStd_Application_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|