1 // Created on: 2002-11-18
2 // Created by: Vladimir ANIKIN
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _TDocStd_MultiTransactionManager_HeaderFile
17 #define _TDocStd_MultiTransactionManager_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
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;
32 class TDocStd_MultiTransactionManager;
33 DEFINE_STANDARD_HANDLE(TDocStd_MultiTransactionManager, Standard_Transient)
35 //! Class for synchronization of transactions within multiple documents.
36 //! Each transaction of this class involvess one transaction in each modified document.
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.
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.
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
57 Standard_EXPORT TDocStd_MultiTransactionManager();
59 //! Sets undo limit for the manager and all documents.
60 Standard_EXPORT void SetUndoLimit (const Standard_Integer theLimit);
62 //! Returns undo limit for the manager.
63 Standard_Integer GetUndoLimit() const;
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();
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();
78 //! Returns available manager undos.
79 const TDocStd_SequenceOfApplicationDelta& GetAvailableUndos() const;
81 //! Returns available manager redos.
82 const TDocStd_SequenceOfApplicationDelta& GetAvailableRedos() const;
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();
89 //! Unsets the flag of started manager transaction and aborts
90 //! transaction in each document.
91 Standard_EXPORT void AbortCommand();
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();
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);
103 //! Returns true if a transaction is opened.
104 Standard_Boolean HasOpenCommand() const;
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();
110 //! Dumps transactions in undos and redos
111 Standard_EXPORT void DumpTransaction (Standard_OStream& theOS) const;
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);
117 //! Removes the document from the transaction manager.
118 Standard_EXPORT void RemoveDocument (const Handle(TDocStd_Document)& theDoc);
120 //! Returns the added documents to the transaction manager.
121 const TDocStd_SequenceOfDocument& Documents() const;
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);
129 //! Returns Standard_True if NestedTransaction mode is set.
130 //! Methods for protection of changes outside transactions
131 Standard_Boolean IsNestedTransactionMode() const;
133 //! If theTransactionOnly is True, denies all changes outside transactions.
134 Standard_EXPORT void SetModificationMode (const Standard_Boolean theTransactionOnly);
136 //! Returns True if changes are allowed only inside transactions.
137 Standard_Boolean ModificationMode() const;
139 //! Clears undos in the manager and in documents.
140 Standard_EXPORT void ClearUndos();
142 //! Clears redos in the manager and in documents.
143 Standard_EXPORT void ClearRedos();
148 DEFINE_STANDARD_RTTIEXT(TDocStd_MultiTransactionManager,Standard_Transient)
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;
170 #include <TDocStd_MultiTransactionManager.lxx>
176 #endif // _TDocStd_MultiTransactionManager_HeaderFile