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.
19 //Version Date Purpose
20 // 0.0 Sep 8 1997 Creation
24 #include <TDF_Delta.ixx>
26 #include <TDF_LabelMap.hxx>
27 #include <TDF_ListIteratorOfAttributeDeltaList.hxx>
28 #include <TDF_ListIteratorOfLabelList.hxx>
29 #include <TDF_MapIteratorOfLabelMap.hxx>
32 #include <Standard_ConstructionError.hxx>
37 //=======================================================================
38 //function : TDF_Delta
40 //=======================================================================
42 TDF_Delta::TDF_Delta()
48 //=======================================================================
51 //=======================================================================
53 void TDF_Delta::Validity
54 (const Standard_Integer aBeginTime,
55 const Standard_Integer anEndTime)
57 myBeginTime = aBeginTime;
58 myEndTime = anEndTime;
62 //=======================================================================
63 //function : AddAttributeDelta
65 //=======================================================================
67 void TDF_Delta::AddAttributeDelta
68 (const Handle(TDF_AttributeDelta)& anAttributeDelta)
69 { if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
72 //=======================================================================
73 //function : BeforeOrAfterApply
75 //=======================================================================
77 void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
79 TDF_AttributeDeltaList ADlist;
80 // for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
81 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
82 for ( ; itr.More(); itr.Next()) ADlist.Append(itr.Value());
84 Handle(TDF_AttributeDelta) attDelta;
85 Handle(TDF_Attribute) att;
87 Standard_Boolean noDeadLock = Standard_True;
88 Standard_Integer nbAD = ADlist.Extent();
89 Standard_Boolean next;
90 while (noDeadLock && (nbAD != 0)) {
91 itr.Initialize(ADlist);
94 attDelta = itr.Value();
95 att = attDelta->Attribute();
97 next = !att->BeforeUndo(attDelta);
99 next = !att->AfterUndo(attDelta);
106 noDeadLock = (nbAD > ADlist.Extent());
107 nbAD = ADlist.Extent();
112 if (before) cout<<"Before"; else cout<<"After";
113 cout<<"Undo(): dead lock between these attributes:"<<endl;
114 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
115 cout<<"AttributeDelta type = "<<itr.Value()->DynamicType()->Name();
116 cout<<" Attribute type = "<<itr.Value()->Attribute()->DynamicType()->Name()<<endl;;
118 Standard_ConstructionError::Raise("BeforeUndo(): dead lock.");
120 Standard_ConstructionError::Raise("AfterUndo(): dead lock.");
123 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
124 attDelta = itr.Value();
125 att = attDelta->Attribute();
127 att->BeforeUndo(attDelta,Standard_True);
129 att->AfterUndo(attDelta,Standard_True);
135 //=======================================================================
138 //=======================================================================
140 void TDF_Delta::Apply()
142 TDF_ListIteratorOfAttributeDeltaList itr;
143 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
144 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
150 //=======================================================================
153 //=======================================================================
155 void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
158 // If <aLabelList> is not empty...
160 Standard_Boolean inList;
161 if (aLabelList.Extent() > 0) cout<<"Previously added as modified label(s) ";
163 for (TDF_ListIteratorOfLabelList it1(aLabelList);
164 it1.More(); it1.Next()) {
166 const TDF_Label& lab1 = it1.Value();
167 inList = labMap.Add(lab1);
169 lab1.EntryDump(cout);cout<<" | ";
177 // New labels to add.
179 if (myAttDeltaList.Extent() > 0) cout<<"New added as modified label(s) ";
181 for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
185 const TDF_Label& lab1 = it2.Value()->Label();
186 inList = labMap.Add(lab1);
188 lab1.EntryDump(cout);cout<<" | ";
196 // Now put labels into <aLabelList>.
198 for (TDF_MapIteratorOfLabelMap it3(labMap);
199 it3.More(); it3.Next()) {
200 aLabelList.Append(it3.Key());
204 //=======================================================================
207 //=======================================================================
209 void TDF_Delta::Dump(Standard_OStream& OS) const
211 OS<<"DELTA available from time \t#"<<myBeginTime<<" to time \t#"<<myEndTime<<endl;
212 Standard_Integer n = 0;
213 // for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
214 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
215 for ( ; itr.More(); itr.Next()) ++n;
216 OS<<"Nb Attribute Delta(s): "<<n<<endl;
217 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
218 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
219 OS<<"| "; attDelta->Dump(OS); OS<<endl;