Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:21

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