b311480e |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // ------------------ |
7fd59977 |
17 | // Version: 0.0 |
b311480e |
18 | //Version Date Purpose |
7fd59977 |
19 | // 0.0 Feb 7 1997 Creation |
20 | |
42cf5bc1 |
21 | #include <Standard_DomainError.hxx> |
22 | #include <Standard_GUID.hxx> |
23 | #include <Standard_ImmutableObject.hxx> |
24 | #include <Standard_Type.hxx> |
7fd59977 |
25 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
26 | #include <TDF_Attribute.hxx> |
27 | #include <TDF_AttributeDelta.hxx> |
28 | #include <TDF_AttributeIterator.hxx> |
29 | #include <TDF_Data.hxx> |
30 | #include <TDF_DataSet.hxx> |
7fd59977 |
31 | #include <TDF_DefaultDeltaOnModification.hxx> |
32 | #include <TDF_DefaultDeltaOnRemoval.hxx> |
42cf5bc1 |
33 | #include <TDF_DeltaOnAddition.hxx> |
7fd59977 |
34 | #include <TDF_DeltaOnForget.hxx> |
42cf5bc1 |
35 | #include <TDF_DeltaOnModification.hxx> |
36 | #include <TDF_DeltaOnRemoval.hxx> |
7fd59977 |
37 | #include <TDF_DeltaOnResume.hxx> |
42cf5bc1 |
38 | #include <TDF_IDFilter.hxx> |
7fd59977 |
39 | #include <TDF_Label.hxx> |
40 | #include <TDF_LabelNode.hxx> |
42cf5bc1 |
41 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
42 | #include <TDF_Tool.hxx> |
43 | |
92efcf78 |
44 | IMPLEMENT_STANDARD_RTTIEXT(TDF_Attribute,MMgt_TShared) |
45 | |
7fd59977 |
46 | #undef TDF_DATA_COMMIT_OPTIMIZED |
47 | |
7fd59977 |
48 | //======================================================================= |
49 | //function : TDF_Attribute |
50 | //purpose : Initializes fields. |
51 | //======================================================================= |
52 | |
53 | TDF_Attribute::TDF_Attribute() : |
54 | myLabelNode(NULL), |
55 | myTransaction(0), |
56 | mySavedTransaction(0), |
57 | myFlags(1) |
58 | |
59 | {} |
60 | |
61 | |
62 | //======================================================================= |
63 | //function : Label |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | const TDF_Label TDF_Attribute::Label() const |
68 | { return TDF_Label(myLabelNode); } |
69 | |
70 | |
71 | //======================================================================= |
72 | //function : Find |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | Standard_Boolean TDF_Attribute::FindAttribute (const Standard_GUID& anID, |
77 | Handle(TDF_Attribute)& anAttribute) const |
78 | { |
79 | return Label().FindAttribute(anID,anAttribute); |
80 | } |
81 | |
82 | //======================================================================= |
83 | //function : IsAttribute |
84 | //purpose : |
85 | //======================================================================= |
86 | |
87 | Standard_Boolean TDF_Attribute::IsAttribute (const Standard_GUID& anID) const |
88 | { |
89 | return Label().IsAttribute(anID); |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : AddAttribute |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | void TDF_Attribute::AddAttribute (const Handle(TDF_Attribute)& otherAttribute) const |
98 | { Label().AddAttribute (otherAttribute); } |
99 | |
100 | |
101 | |
102 | //======================================================================= |
103 | //function : ForgetAttribute |
104 | //purpose : |
105 | //======================================================================= |
106 | |
107 | Standard_Boolean TDF_Attribute::ForgetAttribute (const Standard_GUID& anID) const |
108 | { return Label().ForgetAttribute (anID); } |
109 | |
110 | |
111 | |
112 | //======================================================================= |
113 | //function : ForgetAllAttributes |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | void TDF_Attribute::ForgetAllAttributes (const Standard_Boolean clearChildren) const |
118 | { Label().ForgetAllAttributes (clearChildren); } |
119 | |
120 | |
121 | |
122 | |
123 | //======================================================================= |
124 | //function : Forget |
125 | //purpose : |
126 | //======================================================================= |
127 | |
128 | void TDF_Attribute::Forget (const Standard_Integer aTransaction) |
129 | { |
130 | mySavedTransaction = myTransaction; |
131 | myTransaction = aTransaction; |
132 | myFlags = (myFlags | TDF_AttributeForgottenMsk); |
133 | Validate(Standard_False); |
134 | } |
135 | |
136 | |
137 | //======================================================================= |
138 | //function : Resume |
139 | //purpose : |
140 | //======================================================================= |
141 | |
142 | void TDF_Attribute::Resume() |
143 | { |
144 | myTransaction = mySavedTransaction; |
145 | mySavedTransaction = -1; // To say "just resumed"! |
146 | myFlags = (myFlags & ~TDF_AttributeForgottenMsk); |
147 | Validate(Standard_True); |
148 | } |
149 | |
150 | |
151 | //======================================================================= |
152 | //function : UntilTransaction |
153 | //purpose : |
154 | //======================================================================= |
155 | |
156 | Standard_Integer TDF_Attribute::UntilTransaction() const |
157 | { |
158 | if (IsForgotten()) return myTransaction; |
159 | else if (IsBackuped()) return myNext->myTransaction - 1; |
160 | else if (IsValid()) return myLabelNode->Data()->Transaction(); |
9775fa61 |
161 | throw Standard_DomainError("The attribute structure is wrong."); |
7fd59977 |
162 | } |
163 | |
164 | |
165 | //======================================================================= |
166 | //function : AfterAddition |
167 | //purpose : |
168 | //======================================================================= |
169 | |
170 | void TDF_Attribute::AfterAddition() |
171 | {} |
172 | |
173 | |
174 | //======================================================================= |
175 | //function : BeforeRemoval |
176 | //purpose : |
177 | //======================================================================= |
178 | |
179 | void TDF_Attribute::BeforeRemoval() |
180 | {} |
181 | |
182 | //======================================================================= |
183 | //function : BeforeForget |
184 | //purpose : |
185 | //======================================================================= |
186 | |
187 | void TDF_Attribute::BeforeForget() |
188 | {} |
189 | |
190 | |
191 | //======================================================================= |
192 | //function : AfterResume |
193 | //purpose : |
194 | //======================================================================= |
195 | |
196 | void TDF_Attribute::AfterResume() |
197 | {} |
198 | |
199 | |
200 | //======================================================================= |
201 | //function : BeforeUndo |
202 | //purpose : Before application of a TDF_Delta. |
203 | //======================================================================= |
204 | |
205 | Standard_Boolean TDF_Attribute::BeforeUndo |
35e08fe8 |
206 | (const Handle(TDF_AttributeDelta)& /*anAttDelta*/, |
207 | const Standard_Boolean /*forceIt*/) |
7fd59977 |
208 | { return Standard_True; } |
209 | |
210 | |
211 | //======================================================================= |
212 | //function : AfterUndo |
213 | //purpose : After application of a TDF_Delta. |
214 | //======================================================================= |
215 | |
216 | Standard_Boolean TDF_Attribute::AfterUndo |
35e08fe8 |
217 | (const Handle(TDF_AttributeDelta)& /*anAttDelta*/, |
218 | const Standard_Boolean /*forceIt*/) |
7fd59977 |
219 | { return Standard_True; } |
220 | |
221 | |
222 | //======================================================================= |
223 | //function : AfterRetrieval |
224 | //purpose : |
225 | //======================================================================= |
226 | |
227 | Standard_Boolean TDF_Attribute::AfterRetrieval |
35e08fe8 |
228 | (const Standard_Boolean /*forceIt*/) |
7fd59977 |
229 | { return Standard_True; } |
230 | |
7fd59977 |
231 | //======================================================================= |
232 | //function : BeforeCommitTransaction |
233 | //purpose : |
234 | //======================================================================= |
235 | |
236 | void TDF_Attribute::BeforeCommitTransaction() {} |
7fd59977 |
237 | |
238 | //======================================================================= |
239 | //function : Backup |
240 | //purpose : Backups the attribute. |
241 | //======================================================================= |
242 | |
243 | void TDF_Attribute::Backup() |
244 | { |
245 | // The attribute must be valid and attached to a label. |
246 | if (IsValid() && (myLabelNode != NULL)) { |
247 | Handle(TDF_Data) aData = myLabelNode->Data(); |
248 | |
249 | // check that modification is allowed |
250 | if ( !aData->IsModificationAllowed() ) { |
251 | TCollection_AsciiString aMess; |
252 | aMess = "Attribute \""; |
253 | aMess += DynamicType()->Name(); |
254 | aMess += "\" is changed outside transaction"; |
9775fa61 |
255 | throw Standard_ImmutableObject(aMess.ToCString()); |
7fd59977 |
256 | } |
257 | |
258 | const Standard_Integer currentTransaction = |
259 | aData->Transaction(); |
260 | if (myTransaction < currentTransaction) {//"!=" is less secure. |
261 | Handle(TDF_Attribute) backup = BackupCopy(); |
262 | #ifdef TDF_DATA_COMMIT_OPTIMIZED |
263 | myLabelNode->AttributesModified(Standard_True); |
264 | #endif |
265 | backup->myLabelNode = myLabelNode; |
266 | backup->myNext = this; // Back reference; |
267 | backup->myBackup = myBackup; |
268 | backup->myTransaction = myTransaction; |
269 | backup->Backup(Standard_True); |
270 | |
271 | myBackup = backup; |
272 | myTransaction = currentTransaction; |
273 | } |
274 | } |
275 | } |
276 | |
277 | |
278 | //======================================================================= |
279 | //function : BackupCopy |
280 | //purpose : Standard implementation of BackupCopy. |
281 | //======================================================================= |
282 | |
283 | Handle(TDF_Attribute) TDF_Attribute::BackupCopy() const |
284 | { |
285 | Handle(TDF_Attribute) copy = NewEmpty(); copy->Restore(this); |
286 | return copy; |
287 | } |
288 | |
289 | |
290 | //======================================================================= |
291 | //function : RemoveBackup |
292 | //purpose : |
293 | //======================================================================= |
294 | |
295 | void TDF_Attribute::RemoveBackup() |
296 | { |
0797d9d3 |
297 | #ifdef OCCT_DEBUG |
7fd59977 |
298 | if (myBackup.IsNull()) |
9775fa61 |
299 | throw Standard_DomainError("Impossible to remove a nonexistent backup."); |
7fd59977 |
300 | #endif |
301 | myBackup->BeforeRemoval(); |
302 | myBackup->myLabelNode = NULL; // Absolutly necessary! |
303 | myBackup->myNext.Nullify(); // Absolutly necessary! |
304 | myBackup = myBackup->myBackup; |
305 | if (!myBackup.IsNull()) myBackup->myNext = this; // New back reference. |
306 | } |
307 | |
308 | //======================================================================= |
309 | //function : References |
310 | //purpose : Adds the referenced attributes or labels. |
311 | //======================================================================= |
312 | |
302f96fb |
313 | void TDF_Attribute::References(const Handle(TDF_DataSet)& /*aDataSet*/) const |
7fd59977 |
314 | {} |
315 | |
316 | |
317 | //======================================================================= |
318 | //function : DeltaOnAddition |
319 | //purpose : Creates such a delta. |
320 | //======================================================================= |
321 | |
322 | Handle(TDF_DeltaOnAddition) TDF_Attribute::DeltaOnAddition() const |
323 | { return new TDF_DeltaOnAddition(this); } |
324 | |
325 | |
326 | //======================================================================= |
327 | //function : DeltaOnForget |
328 | //purpose : Creates such a delta. |
329 | //======================================================================= |
330 | |
331 | Handle(TDF_DeltaOnForget) TDF_Attribute::DeltaOnForget() const |
332 | { return new TDF_DeltaOnForget(this); } |
333 | |
334 | |
335 | //======================================================================= |
336 | //function : DeltaOnResume |
337 | //purpose : Creates such a delta. |
338 | //======================================================================= |
339 | |
340 | Handle(TDF_DeltaOnResume) TDF_Attribute::DeltaOnResume() const |
341 | { return new TDF_DeltaOnResume(this); } |
342 | |
343 | |
344 | //======================================================================= |
345 | //function : DeltaOnModification |
346 | //purpose : Creates such a delta. |
347 | //======================================================================= |
348 | |
349 | Handle(TDF_DeltaOnModification) TDF_Attribute::DeltaOnModification |
350 | (const Handle(TDF_Attribute)& anOldAttribute) const |
351 | { return new TDF_DefaultDeltaOnModification(anOldAttribute); } |
352 | |
353 | |
354 | //======================================================================= |
355 | //function : DeltaOnModification |
356 | //purpose : Applies such a delta. |
357 | //======================================================================= |
358 | |
359 | void TDF_Attribute::DeltaOnModification |
360 | (const Handle(TDF_DeltaOnModification)& aDelta) |
361 | { |
362 | Backup(); |
363 | Restore(aDelta->Attribute()); |
364 | } |
365 | |
366 | |
367 | //======================================================================= |
368 | //function : DeltaOnRemoval |
369 | //purpose : Creates such a delta. |
370 | //======================================================================= |
371 | |
372 | Handle(TDF_DeltaOnRemoval) TDF_Attribute::DeltaOnRemoval() const |
373 | { return new TDF_DefaultDeltaOnRemoval(this); } // myBackup |
374 | |
375 | |
376 | //======================================================================= |
377 | //function : Dump |
378 | //purpose : This method is equivalent to operator << |
379 | //======================================================================= |
380 | |
381 | Standard_OStream& TDF_Attribute::Dump(Standard_OStream& anOS) const |
382 | { |
383 | anOS<<"\t"<<DynamicType()->Name()<<"\tTrans. "<<myTransaction<<";"; |
384 | if (IsValid()) anOS<<" Valid"; |
385 | if (IsBackuped()) anOS<<" Backuped"; |
386 | if (IsForgotten()) anOS<<" Forgotten"; |
387 | char toto[45]; |
388 | Standard_PCharacter pStr; |
389 | // |
390 | pStr=toto; |
2cb44241 |
391 | ID().ToCString(pStr); |
392 | anOS<<";\tID = "<<toto<<endl; |
7fd59977 |
393 | return anOS; |
394 | } |
395 | |
396 | |
397 | //======================================================================= |
398 | //function :ExtendedDump |
399 | //purpose : |
400 | //======================================================================= |
401 | |
402 | void TDF_Attribute::ExtendedDump |
403 | (Standard_OStream& anOS, |
35e08fe8 |
404 | const TDF_IDFilter& /*aFilter*/, |
405 | TDF_AttributeIndexedMap& /*aMap*/) const |
7fd59977 |
406 | { Dump(anOS); } |
407 | |