0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / TDocStd / TDocStd_Document.hxx
1 // Created on: 1999-04-07
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_Document_HeaderFile
18 #define _TDocStd_Document_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TCollection_ExtendedString.hxx>
24 #include <Standard_Integer.hxx>
25 #include <TDF_Transaction.hxx>
26 #include <TDF_DeltaList.hxx>
27 #include <Standard_Boolean.hxx>
28 #include <CDM_Document.hxx>
29 #include <TDF_LabelMap.hxx>
30 #include <Standard_Address.hxx>
31 class TDF_Data;
32 class TDF_Delta;
33 class TDF_Label;
34 class TCollection_ExtendedString;
35 class TCollection_AsciiString;
36 class CDM_Document;
37 class TDocStd_CompoundDelta;
38
39
40 class TDocStd_Document;
41 DEFINE_STANDARD_HANDLE(TDocStd_Document, CDM_Document)
42
43 //! The contents of a TDocStd_Application, a
44 //! document is a container for a data framework
45 //! composed of labels and attributes. As such,
46 //! TDocStd_Document is the entry point into the data framework.
47 //! To gain access to the data, you create a document as follows:
48 //! Handle(TDocStd_Document) MyDF = new TDocStd_Document
49 //! The document also allows you to manage:
50 //! -   modifications, providing Undo and Redo functions.
51 //! -   command transactions.
52 //! Warning: The only data saved is the framework (TDF_Data)
53 class TDocStd_Document : public CDM_Document
54 {
55
56 public:
57
58   
59   //! Will Abort any execution, clear fields
60   //! returns the    document which contains <L>.  raises  an
61   //! exception if the document is not found.
62   Standard_EXPORT static Handle(TDocStd_Document) Get (const TDF_Label& L);
63   
64   //! Constructs a document object defined by the
65   //! string astorageformat.
66   Standard_EXPORT TDocStd_Document(const TCollection_ExtendedString& astorageformat);
67   
68   //! the document is saved in a file.
69   Standard_EXPORT Standard_Boolean IsSaved() const;
70   
71   //! returns True if document differs from the state of last saving.
72   //! this method have to be called only wroking in the transaction mode
73     Standard_Boolean IsChanged() const;
74   
75   //! This method have to be called to show document that it has been saved
76     void SetSaved();
77   
78   //! Say to document what it is not saved.
79   //! Use value, returned earlier by GetSavedTime().
80     void SetSavedTime (const Standard_Integer theTime);
81   
82   //! Returns value of <mySavedTime> to be used later in SetSavedTime()
83     Standard_Integer GetSavedTime() const;
84   
85   //! raise if <me> is not saved.
86   Standard_EXPORT TCollection_ExtendedString GetName() const;
87   
88   //! returns the OS  path of the  file, in wich one <me> is
89   //! saved. Raise an exception if <me> is not saved.
90   Standard_EXPORT TCollection_ExtendedString GetPath() const;
91   
92   Standard_EXPORT void SetData (const Handle(TDF_Data)& data);
93   
94   Standard_EXPORT Handle(TDF_Data) GetData() const;
95   
96   //! Returns the main label in this data framework.
97   //! By definition, this is the label with the entry 0:1.
98   Standard_EXPORT TDF_Label Main() const;
99   
100   //! Returns True if the main label has no attributes
101   Standard_EXPORT Standard_Boolean IsEmpty() const;
102   
103   //! Returns False if the  document has been modified
104   //! but not recomputed.
105   Standard_EXPORT Standard_Boolean IsValid() const;
106   
107   //! Notify the label as modified, the Document becomes UnValid.
108   //! returns True if <L> has been notified as modified.
109   Standard_EXPORT void SetModified (const TDF_Label& L);
110   
111   //! Remove all modifications. After this call The document
112   //! becomesagain Valid.
113   Standard_EXPORT void PurgeModified();
114   
115   //! Returns the labels which have been modified in
116   //! this document.
117   Standard_EXPORT const TDF_LabelMap& GetModified() const;
118   
119   //! Launches a new command. This command may be undone.
120   Standard_EXPORT void NewCommand();
121   
122   //! returns True if a Command transaction is open in the curret .
123   Standard_EXPORT Standard_Boolean HasOpenCommand() const;
124   
125   //! Opens a new command transaction in this document.
126   //! You can use HasOpenCommand to see whether a command is already open.
127   //! Exceptions
128   //! Standard_DomainError if a command is already open in this document.
129   Standard_EXPORT void OpenCommand();
130   
131   //! Commits documents transactions and fills the
132   //! transaction manager with documents that have
133   //! been changed during the transaction.
134   //! If no command transaction is open, nothing is done.
135   //! Returns True if a new delta has been added to myUndos.
136   Standard_EXPORT Standard_Boolean CommitCommand();
137   
138   //! Abort the  Command  transaction. Does nothing If there is
139   //! no Command transaction open.
140   Standard_EXPORT void AbortCommand();
141   
142   //! The current limit on the number of undos
143   Standard_EXPORT Standard_Integer GetUndoLimit() const;
144   
145   //! Set the  limit on  the number of  Undo Delta  stored 0
146   //! will disable  Undo  on the  document A negative  value
147   //! means no limit. Note that by default Undo is disabled.
148   //! Enabling  it will  take effect with  the next  call to
149   //! NewCommand. Of course this limit is the same for Redo
150   Standard_EXPORT void SetUndoLimit (const Standard_Integer L);
151   
152   //! Remove all stored Undos and Redos
153   Standard_EXPORT void ClearUndos();
154   
155   //! Remove all stored Redos
156   Standard_EXPORT void ClearRedos();
157   
158   //! Returns the number of undos stored in this
159   //! document. If this figure is greater than 0, the method Undo
160   //! can be used.
161   Standard_EXPORT Standard_Integer GetAvailableUndos() const;
162   
163   //! Will UNDO  one step, returns  False if no undo was
164   //! done (Undos == 0).
165   //! Otherwise, true is returned and one step in the
166   //! list of undoes is undone.
167   Standard_EXPORT Standard_Boolean Undo();
168   
169   //! Returns the number of redos stored in this
170   //! document. If this figure is greater than 0, the method Redo
171   //! can be used.
172   Standard_EXPORT Standard_Integer GetAvailableRedos() const;
173   
174   //! Will REDO  one step, returns  False if no redo was
175   //! done (Redos == 0).
176   //! Otherwise, true is returned, and one step in the list of redoes is done again.
177   Standard_EXPORT Standard_Boolean Redo();
178   
179   Standard_EXPORT const TDF_DeltaList& GetUndos() const;
180   
181   Standard_EXPORT const TDF_DeltaList& GetRedos() const;
182   
183   //! Removes the first undo in the list of document undos.
184   //! It is used in the application when the undo limit is exceed.
185   Standard_EXPORT void RemoveFirstUndo();
186   
187   //! Initializes the procedure of delta compaction
188   //! Returns false if there is no delta to compact
189   //! Marks the last delta as a "from" delta
190   Standard_EXPORT Standard_Boolean InitDeltaCompaction();
191   
192   //! Performs the procedure of delta compaction
193   //! Makes all deltas starting from "from" delta
194   //! till the last one to be one delta.
195   Standard_EXPORT Standard_Boolean PerformDeltaCompaction();
196   
197   //! Set   modifications on  labels  impacted  by  external
198   //! references to the entry.  The document becomes invalid
199   //! and must be recomputed.
200   Standard_EXPORT void UpdateReferences (const TCollection_AsciiString& aDocEntry);
201   
202   //! Recompute if the document was  not valid and propagate
203   //! the reccorded modification.
204   Standard_EXPORT void Recompute();
205   
206   //! This method Update   will be called
207   //! to signal the end   of the modified references list.
208   //! The    document     should    be  recomputed     and
209   //! UpdateFromDocuments  should be called.  Update should
210   //! returns True in case  of success, false otherwise.  In
211   //! case of Failure, additional information can be given in
212   //! ErrorString.
213   //! Update the document by propagation
214   //! ==================================
215   //! Update   the    document    from   internal   stored
216   //! modifications.   If   you   want  to   undoing  this
217   //! operation, please call NewCommand before.
218   //! to change format (advanced programming)
219   //! ================
220   Standard_EXPORT virtual void Update (const Handle(CDM_Document)& aToDocument, const Standard_Integer aReferenceIdentifier, const Standard_Address aModifContext) Standard_OVERRIDE;
221   
222   Standard_EXPORT virtual TCollection_ExtendedString StorageFormat() const Standard_OVERRIDE;
223   
224   //! methods for the nested transaction mode
225   Standard_EXPORT virtual void ChangeStorageFormat (const TCollection_ExtendedString& newStorageFormat);
226   
227   //! Sets nested transaction mode if isAllowed == Standard_True
228   Standard_EXPORT void SetNestedTransactionMode (const Standard_Boolean isAllowed = Standard_True);
229   
230   //! Returns Standard_True if mode is set
231     Standard_Boolean IsNestedTransactionMode() const;
232   
233   //! if theTransactionOnly is True changes is denied outside transactions
234     void SetModificationMode (const Standard_Boolean theTransactionOnly);
235   
236   //! returns True if changes allowed only inside transactions
237     Standard_Boolean ModificationMode() const;
238   
239   //! Prepares document for closing
240   Standard_EXPORT virtual void BeforeClose();
241
242
243
244
245   DEFINE_STANDARD_RTTIEXT(TDocStd_Document,CDM_Document)
246
247 protected:
248
249   
250   //! Returns Standard_True done
251   Standard_EXPORT virtual Standard_Boolean CommitTransaction();
252   
253   Standard_EXPORT virtual void AbortTransaction();
254   
255   //! methods for protection of changes outside transactions
256   Standard_EXPORT virtual void OpenTransaction();
257
258   TCollection_ExtendedString myStorageFormat;
259   TDF_DeltaList myUndos;
260   TDF_DeltaList myRedos;
261
262
263 private:
264
265   
266   //! Appends delta to the first delta in the myUndoFILO
267   //! private methods
268   //! ===============
269   Standard_EXPORT static void AppendDeltaToTheFirst (const Handle(TDocStd_CompoundDelta)& theDelta1, const Handle(TDF_Delta)& theDelta2);
270
271   Handle(TDF_Data) myData;
272   Standard_Integer myUndoLimit;
273   TDF_Transaction myUndoTransaction;
274   Handle(TDF_Delta) myFromUndo;
275   Handle(TDF_Delta) myFromRedo;
276   Standard_Integer mySaveTime;
277   Standard_Boolean myIsNestedTransactionMode;
278   TDF_DeltaList myUndoFILO;
279   Standard_Boolean myOnlyTransactionModification;
280
281
282 };
283
284
285 #include <TDocStd_Document.lxx>
286
287
288
289
290
291 #endif // _TDocStd_Document_HeaderFile