0033040: Coding - get rid of unused headers [Storage to TopOpeBRepTool]
[occt.git] / src / TDocStd / TDocStd_MultiTransactionManager.hxx
1 // Created on: 2002-11-18
2 // Created by: Vladimir ANIKIN
3 // Copyright (c) 2002-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 #ifndef _TDocStd_MultiTransactionManager_HeaderFile
17 #define _TDocStd_MultiTransactionManager_HeaderFile
18
19 #include <Standard.hxx>
20
21 #include <TDocStd_SequenceOfApplicationDelta.hxx>
22 #include <Standard_Integer.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <Standard_Transient.hxx>
25 #include <Standard_OStream.hxx>
26 class TCollection_ExtendedString;
27 class TDocStd_Document;
28
29
30 class TDocStd_MultiTransactionManager;
31 DEFINE_STANDARD_HANDLE(TDocStd_MultiTransactionManager, Standard_Transient)
32
33 //! Class for synchronization of transactions within multiple documents.
34 //! Each transaction of this class involvess one transaction in each modified document.
35 //!
36 //! The documents to be synchronized should be added explicitly to
37 //! the manager; then its interface is used to ensure that all transactions
38 //! (Open/Commit, Undo/Redo) are performed synchronously in all managed documents.
39 //!
40 //! The current implementation does not support nested transactions
41 //! on multitransaction manager level. It only sets the flag enabling
42 //! or disabling nested transactions in all its documents, so that
43 //! a nested transaction can be opened for each particular document
44 //! with TDocStd_Document class interface.
45 //!
46 //! NOTE: When you invoke CommitTransaction of multi transaction
47 //! manager, all nested transaction of its documents will be closed (committed).
48 class TDocStd_MultiTransactionManager : public Standard_Transient
49 {
50
51 public:
52
53   
54   //! Constructor
55   Standard_EXPORT TDocStd_MultiTransactionManager();
56   
57   //! Sets undo limit for the manager and all documents.
58   Standard_EXPORT void SetUndoLimit (const Standard_Integer theLimit);
59   
60   //! Returns undo limit for the manager.
61     Standard_Integer GetUndoLimit() const;
62   
63   //! Undoes the current transaction of the manager.
64   //! It calls the Undo () method of the document being
65   //! on top of the manager list of undos (list.First())
66   //! and moves the list item to the top of the list of manager
67   //! redos (list.Prepend(item)).
68   Standard_EXPORT void Undo();
69   
70   //! Redoes the current transaction of the application. It calls
71   //! the Redo () method of the document being on top of the
72   //! manager list of redos (list.First()) and moves the list
73   //! item to the top of the list of manager undos (list.Prepend(item)).
74   Standard_EXPORT void Redo();
75   
76   //! Returns available manager undos.
77     const TDocStd_SequenceOfApplicationDelta& GetAvailableUndos() const;
78   
79   //! Returns available manager redos.
80     const TDocStd_SequenceOfApplicationDelta& GetAvailableRedos() const;
81   
82   //! Opens transaction in each document and sets the flag that
83   //! transaction is opened. If there are already opened transactions in the documents,
84   //! these transactions will be aborted before opening new ones.
85   Standard_EXPORT void OpenCommand();
86   
87   //! Unsets the flag of started manager transaction and aborts
88   //! transaction in each document.
89   Standard_EXPORT void AbortCommand();
90   
91   //! Commits transaction in all documents and fills the transaction manager
92   //! with the documents that have been changed during the transaction.
93   //! Returns True if new data has been added to myUndos.
94   //! NOTE: All nested transactions in the documents will be committed.
95   Standard_EXPORT Standard_Boolean CommitCommand();
96   
97   //! Makes the same steps as the previous function but defines the name for transaction.
98   //! Returns True if new data has been added to myUndos.
99   Standard_EXPORT Standard_Boolean CommitCommand (const TCollection_ExtendedString& theName);
100   
101   //! Returns true if a transaction is opened.
102     Standard_Boolean HasOpenCommand() const;
103   
104   //! Removes undo information from the list of undos of the manager and
105   //! all documents which have been modified during the transaction.
106   Standard_EXPORT void RemoveLastUndo();
107   
108   //! Dumps transactions in undos and redos
109   Standard_EXPORT void DumpTransaction (Standard_OStream& theOS) const;
110   
111   //! Adds the document to the transaction manager and
112   //! checks if it has been already added
113   Standard_EXPORT void AddDocument (const Handle(TDocStd_Document)& theDoc);
114   
115   //! Removes the document from the transaction manager.
116   Standard_EXPORT void RemoveDocument (const Handle(TDocStd_Document)& theDoc);
117   
118   //! Returns the added documents to the transaction manager.
119     const TDocStd_SequenceOfDocument& Documents() const;
120   
121   //! Sets nested transaction mode if isAllowed == Standard_True
122   //! NOTE: field myIsNestedTransactionMode exists only for synchronization
123   //! between several documents and has no effect on transactions
124   //! of multitransaction manager.
125   Standard_EXPORT void SetNestedTransactionMode (const Standard_Boolean isAllowed = Standard_True);
126   
127   //! Returns Standard_True if NestedTransaction mode is set.
128   //! Methods for protection of changes outside transactions
129     Standard_Boolean IsNestedTransactionMode() const;
130   
131   //! If theTransactionOnly is True, denies all changes outside transactions.
132   Standard_EXPORT void SetModificationMode (const Standard_Boolean theTransactionOnly);
133   
134   //! Returns True if changes are allowed only inside transactions.
135     Standard_Boolean ModificationMode() const;
136   
137   //! Clears undos in the manager and in documents.
138   Standard_EXPORT void ClearUndos();
139   
140   //! Clears redos in the manager and in documents.
141   Standard_EXPORT void ClearRedos();
142
143
144
145
146   DEFINE_STANDARD_RTTIEXT(TDocStd_MultiTransactionManager,Standard_Transient)
147
148 protected:
149
150
151
152
153 private:
154
155
156   TDocStd_SequenceOfDocument myDocuments;
157   TDocStd_SequenceOfApplicationDelta myUndos;
158   TDocStd_SequenceOfApplicationDelta myRedos;
159   Standard_Integer myUndoLimit;
160   Standard_Boolean myOpenTransaction;
161   Standard_Boolean myIsNestedTransactionMode;
162   Standard_Boolean myOnlyTransactionModification;
163
164
165 };
166
167
168 #include <TDocStd_MultiTransactionManager.lxx>
169
170
171
172
173
174 #endif // _TDocStd_MultiTransactionManager_HeaderFile