0029901: Support save to and restore from Stream interface in TObj package
[occt.git] / src / TObj / TObj_Application.hxx
1 // Created on: 2004-11-23
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // The original implementation Copyright: (C) RINA S.p.A
17
18 #ifndef TObj_Application_HeaderFile
19 #define TObj_Application_HeaderFile
20
21 #include <TDocStd_Application.hxx>
22 #include <TObj_Common.hxx>
23 #include <Message_Gravity.hxx>
24 #include <Message_Messenger.hxx>
25 #include <TColStd_SequenceOfExtendedString.hxx>
26
27 //!
28 //! This is a base class for OCAF based TObj models
29 //!  with declared virtual methods
30 //!
31 class TObj_Application : public TDocStd_Application
32 {
33 public:
34   //! Returns static instance of the application
35   Standard_EXPORT static Handle(TObj_Application) GetInstance();
36  
37   //! Returns reference to associated messenger handle
38   Handle(Message_Messenger) &Messenger() { return myMessenger; }
39     
40  public:
41   /**
42   *    Load/Save support
43   */
44
45   //! Saving the OCAF document to a file
46   Standard_EXPORT virtual Standard_Boolean SaveDocument
47                         (const Handle(TDocStd_Document)&   theSourceDoc,
48                          const TCollection_ExtendedString& theTargetFile);
49
50   //! Saving the OCAF document to a stream
51   Standard_EXPORT virtual Standard_Boolean SaveDocument
52                         (const Handle(TDocStd_Document)&   theSourceDoc,
53                          Standard_OStream&                 theOStream);
54
55   //! Loading the OCAF document from a file
56   Standard_EXPORT virtual Standard_Boolean LoadDocument
57                          (const TCollection_ExtendedString& theSourceFile,
58                           Handle(TDocStd_Document)&         theTargetDoc);
59
60   //! Loading the OCAF document from a stream
61   Standard_EXPORT virtual Standard_Boolean LoadDocument
62                         (Standard_IStream&                 theIStream,
63                          Handle(TDocStd_Document)&         theTargetDoc);
64
65   //! Create the OCAF document from scratch
66   virtual Standard_EXPORT Standard_Boolean CreateNewDocument
67                          (Handle(TDocStd_Document)&         theDoc,
68                           const TCollection_ExtendedString& theFormat);
69
70   //! Signal error during Load or Save
71   //! Default imiplementation is empty
72   virtual Standard_EXPORT void ErrorMessage
73                         (const TCollection_ExtendedString &theMsg,
74                          const Message_Gravity theLevel);
75
76   //! Signal error during Load or Save
77   //! Default imiplementation invoke previous declaration with 0
78   virtual void ErrorMessage
79                         (const TCollection_ExtendedString &theMsg)
80   { ErrorMessage( theMsg, Message_Alarm ); }
81
82
83   //! Sets the verbose flag, meaning that load/save models should show
84   //! CPU and elapsed times
85   void SetVerbose (const Standard_Boolean isVerbose)
86   { myIsVerbose = isVerbose; }
87
88   //! Returns the verbose flag
89   Standard_Boolean IsVerbose () const
90   { return myIsVerbose; }
91
92   //! Dumps the content of me into the stream
93   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
94
95  public:
96   /** 
97   * Redefined OCAF methods
98   */
99
100   //! Return name of resource (i.e. "TObj")
101   virtual Standard_EXPORT Standard_CString ResourcesName() Standard_OVERRIDE;
102
103  protected:
104   /**
105   * Constructor
106   */
107
108   //! Constructor is protected. Use method GetInstance() method to obtain 
109   //! the static instance of the object (or derive your own application)
110   Standard_EXPORT TObj_Application();
111
112   //! Sets an error occured on storage of a document.
113   void SetError (const PCDM_StoreStatus theStatus, const TCollection_ExtendedString& theInfo);
114
115   //! Sets an error occured on reading of a document.
116   void SetError (const PCDM_ReaderStatus theStatus, const TCollection_ExtendedString& theInfo);
117
118  private:
119   /**
120   * Fields
121   */
122
123   Standard_Boolean          myIsError;       //!< error flag
124   Standard_Boolean          myIsVerbose;     //!< verbose flag
125   Handle(Message_Messenger) myMessenger;     //!< messenger
126
127  public:
128   //! CASCADE RTTI
129   DEFINE_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)
130 };
131
132
133 //! Define handle class 
134 DEFINE_STANDARD_HANDLE(TObj_Application,TDocStd_Application)
135
136 #endif