1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-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 _TDF_Data_HeaderFile
17 #define _TDF_Data_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
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>
27 #include <Standard_Transient.hxx>
28 #include <TDF_Label.hxx>
29 #include <Standard_OStream.hxx>
30 class Standard_NoMoreObject;
31 class TDF_Transaction;
38 DEFINE_STANDARD_HANDLE(TDF_Data, Standard_Transient)
40 //! This class is used to manipulate a complete
41 //! independant, self sufficient data structure and
44 //! Access to the root label;
46 //! Opens, aborts, commits a transaction;
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.
53 class TDF_Data : public Standard_Transient
59 //! A new and empty Data structure.
60 Standard_EXPORT TDF_Data();
62 //! Returns the root label of the Data structure.
63 const TDF_Label Root() const;
65 //! Returns the current transaction number.
66 Standard_Integer Transaction() const;
68 //! Returns the current tick. It is incremented each Commit.
69 Standard_Integer Time() const;
71 //! Returns true if <aDelta> is applicable HERE and NOW.
72 Standard_EXPORT Standard_Boolean IsApplicable (const Handle(TDF_Delta)& aDelta) const;
74 //! Apply <aDelta> to undo a set of attribute
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);
81 Standard_EXPORT void Destroy();
87 //! Returns the undo mode status.
88 Standard_Boolean NotUndoMode() const;
90 //! Dumps the Data on <aStream>.
91 Standard_EXPORT Standard_OStream& Dump (Standard_OStream& anOS) const;
92 Standard_OStream& operator<< (Standard_OStream& anOS) const
97 //! Sets modification mode.
98 void AllowModification (const Standard_Boolean isAllowed);
100 //! returns modification mode.
101 Standard_Boolean IsModificationAllowed() const;
103 //! Returns TDF_HAllocator, which is an
104 //! incremental allocator used by
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
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
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
135 const TDF_HAllocator& LabelNodeAllocator() const;
137 friend class TDF_Transaction;
138 friend class TDF_LabelNode;
141 DEFINE_STANDARD_RTTIEXT(TDF_Data,Standard_Transient)
150 //! Fixes order of Attributes' Deltas to perform undo/redo without exceptions:
151 //! puts OnRemoval deltas to the end of the list.
152 void FixOrder(const Handle(TDF_Delta)& theDelta);
154 //! Increments the transaction number and returns it.
155 Standard_EXPORT Standard_Integer OpenTransaction();
157 //! Decrements the transaction number and commits the
160 //! Raises if there is no current transaction.
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);
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);
171 //! Decrements the transaction number and forgets the
174 //! Raises if there is no current transaction.
175 Standard_EXPORT void AbortTransaction();
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);
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
188 Standard_EXPORT Standard_Integer CommitTransaction (const TDF_Label& aLabel, const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta);
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;
203 #include <TDF_Data.lxx>
209 #endif // _TDF_Data_HeaderFile