0029142: 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
a7378539 150 //! Fixes order of Attributes' Deltas
151 void FixOrder(const Handle(TDF_Delta)& theDelta);
42cf5bc1 152
153 //! Increments the transaction number and returns it.
154 Standard_EXPORT Standard_Integer OpenTransaction();
155
156 //! Decrements the transaction number and commits the
157 //! modifications.
158 //!
159 //! Raises if there is no current transaction.
160 //!
161 //! Optionnal <withDelta> set to True indiquates a
162 //! Delta must be generated.
163 Standard_EXPORT Handle(TDF_Delta) CommitTransaction (const Standard_Boolean withDelta = Standard_False);
164
165 //! Decrements the transaction number and commits the
166 //! modifications until AND including the transaction
167 //! <untilTransaction>.
168 Standard_EXPORT Handle(TDF_Delta) CommitUntilTransaction (const Standard_Integer untilTransaction, const Standard_Boolean withDelta = Standard_False);
169
170 //! Decrements the transaction number and forgets the
171 //! modifications.
172 //!
173 //! Raises if there is no current transaction.
174 Standard_EXPORT void AbortTransaction();
175
176 //! Decrements the transaction number and forgets the
177 //! modifications until AND including the transaction
178 //! <untilTransaction>.
179 Standard_EXPORT void AbortUntilTransaction (const Standard_Integer untilTransaction);
180
181 //! Decrements the transaction number and commits the
182 //! modifications. Used to implement the recursif
183 //! commit process. The returned boolean says how many
184 //! attributes (new, modified or deleted) has been
185 //! committed from the previous transaction into the
186 //! current one.
187 Standard_EXPORT Standard_Integer CommitTransaction (const TDF_Label& aLabel, const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta);
188
189 TDF_LabelNodePtr myRoot;
190 Standard_Integer myTransaction;
191 Standard_Integer myNbTouchedAtt;
192 Standard_Boolean myNotUndoMode;
193 Standard_Integer myTime;
194 TColStd_ListOfInteger myTimes;
195 TDF_HAllocator myLabelNodeAllocator;
196 Standard_Boolean myAllowModification;
197
198
199};
200
201
202#include <TDF_Data.lxx>
203
204
205
206
207
208#endif // _TDF_Data_HeaderFile