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