0029531: Exception on Redo
[occt.git] / src / TDF / TDF_Data.hxx
CommitLineData
42cf5bc1 1// Created by: DAUTRY Philippe
2// Copyright (c) 1997-1999 Matra Datavision
3// Copyright (c) 1999-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 _TDF_Data_HeaderFile
17#define _TDF_Data_HeaderFile
18
19#include <Standard.hxx>
20#include <Standard_Type.hxx>
21
22#include <TDF_LabelNodePtr.hxx>
23#include <Standard_Integer.hxx>
24#include <Standard_Boolean.hxx>
25#include <TColStd_ListOfInteger.hxx>
26#include <TDF_HAllocator.hxx>
25e59720 27#include <Standard_Transient.hxx>
42cf5bc1 28#include <TDF_Label.hxx>
29#include <Standard_OStream.hxx>
30class Standard_NoMoreObject;
31class TDF_Transaction;
32class TDF_LabelNode;
33class TDF_Delta;
34class TDF_Label;
35
36
37class TDF_Data;
25e59720 38DEFINE_STANDARD_HANDLE(TDF_Data, Standard_Transient)
42cf5bc1 39
40//! This class is used to manipulate a complete
41//! independant, self sufficient data structure and
42//! its services:
43//!
44//! Access to the root label;
45//!
46//! Opens, aborts, commits a transaction;
47//!
48//! Generation and use of Delta, depending on the time.
49//! This class uses a special allocator
50//! (see LabelNodeAllocator() method)
51//! for more efficient allocation of
52//! objects in memory.
25e59720 53class TDF_Data : public Standard_Transient
42cf5bc1 54{
55
56public:
57
58
59 //! A new and empty Data structure.
60 Standard_EXPORT TDF_Data();
61
62 //! Returns the root label of the Data structure.
63 const TDF_Label Root() const;
64
65 //! Returns the current transaction number.
be5c3602 66 Standard_Integer Transaction() const;
42cf5bc1 67
68 //! Returns the current tick. It is incremented each Commit.
69 Standard_Integer Time() const;
70
71 //! Returns true if <aDelta> is applicable HERE and NOW.
72 Standard_EXPORT Standard_Boolean IsApplicable (const Handle(TDF_Delta)& aDelta) const;
73
74 //! Apply <aDelta> to undo a set of attribute
75 //! modifications.
76 //!
77 //! Optionnal <withDelta> set to True indiquates a
78 //! Delta Set must be generated. (See above)
79 Standard_EXPORT Handle(TDF_Delta) Undo (const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta = Standard_False);
80
81 Standard_EXPORT void Destroy();
82~TDF_Data()
83{
84 Destroy();
85}
86
87 //! Returns the undo mode status.
88 Standard_Boolean NotUndoMode() const;
89
90 //! Dumps the Data on <aStream>.
a7378539 91 Standard_EXPORT Standard_OStream& Dump (Standard_OStream& anOS) const;
42cf5bc1 92Standard_OStream& operator<< (Standard_OStream& anOS) const
93{
94 return Dump(anOS);
95}
96
97 //! Sets modification mode.
98 void AllowModification (const Standard_Boolean isAllowed);
99
100 //! returns modification mode.
101 Standard_Boolean IsModificationAllowed() const;
102
103 //! Returns TDF_HAllocator, which is an
104 //! incremental allocator used by
105 //! TDF_LabelNode.
106 //! This allocator is used to
107 //! manage TDF_LabelNode objects,
108 //! but it can also be used for
109 //! allocating memory to
110 //! application-specific data (be
111 //! careful because this
112 //! allocator does not release
113 //! the memory).
114 //! The benefits of this
115 //! allocation scheme are
116 //! noticeable when dealing with
117 //! large OCAF documents, due to:
118 //! 1. Very quick allocation of
119 //! objects (memory heap is not
120 //! used, the algorithm that
121 //! replaces it is very simple).
122 //! 2. Very quick destruction of
123 //! objects (memory is released not
124 //! by destructors of TDF_LabelNode,
125 //! but rather by the destructor of
126 //! TDF_Data).
127 //! 3. TDF_LabelNode objects do not
128 //! fragmentize the memory; they are
129 //! kept compactly in a number of
130 //! arrays of 16K each.
131 //! 4. Swapping is reduced on large
132 //! data, because each document now
133 //! occupies a smaller number of
134 //! memory pages.
135 const TDF_HAllocator& LabelNodeAllocator() const;
136
137friend class TDF_Transaction;
138friend class TDF_LabelNode;
139
140
25e59720 141 DEFINE_STANDARD_RTTIEXT(TDF_Data,Standard_Transient)
42cf5bc1 142
143protected:
144
145
146
147
148private:
149
f46c2b39 150 //! Fixes order of Attributes' Deltas to perform undo/redo without exceptions:
151 //! puts OnRemoval deltas to the end of the list.
a7378539 152 void FixOrder(const Handle(TDF_Delta)& theDelta);
42cf5bc1 153
154 //! Increments the transaction number and returns it.
155 Standard_EXPORT Standard_Integer OpenTransaction();
156
157 //! Decrements the transaction number and commits the
158 //! modifications.
159 //!
160 //! Raises if there is no current transaction.
161 //!
162 //! Optionnal <withDelta> set to True indiquates a
163 //! Delta must be generated.
164 Standard_EXPORT Handle(TDF_Delta) CommitTransaction (const Standard_Boolean withDelta = Standard_False);
165
166 //! Decrements the transaction number and commits the
167 //! modifications until AND including the transaction
168 //! <untilTransaction>.
169 Standard_EXPORT Handle(TDF_Delta) CommitUntilTransaction (const Standard_Integer untilTransaction, const Standard_Boolean withDelta = Standard_False);
170
171 //! Decrements the transaction number and forgets the
172 //! modifications.
173 //!
174 //! Raises if there is no current transaction.
175 Standard_EXPORT void AbortTransaction();
176
177 //! Decrements the transaction number and forgets the
178 //! modifications until AND including the transaction
179 //! <untilTransaction>.
180 Standard_EXPORT void AbortUntilTransaction (const Standard_Integer untilTransaction);
181
182 //! Decrements the transaction number and commits the
183 //! modifications. Used to implement the recursif
184 //! commit process. The returned boolean says how many
185 //! attributes (new, modified or deleted) has been
186 //! committed from the previous transaction into the
187 //! current one.
188 Standard_EXPORT Standard_Integer CommitTransaction (const TDF_Label& aLabel, const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta);
189
190 TDF_LabelNodePtr myRoot;
191 Standard_Integer myTransaction;
192 Standard_Integer myNbTouchedAtt;
193 Standard_Boolean myNotUndoMode;
194 Standard_Integer myTime;
195 TColStd_ListOfInteger myTimes;
196 TDF_HAllocator myLabelNodeAllocator;
197 Standard_Boolean myAllowModification;
198
199
200};
201
202
203#include <TDF_Data.lxx>
204
205
206
207
208
209#endif // _TDF_Data_HeaderFile