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