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.
18 //Version Date Purpose
19 // 0.0 Sep 8 1997 Creation
21 #include <Standard_OutOfRange.hxx>
22 #include <Standard_Type.hxx>
23 #include <TCollection_ExtendedString.hxx>
24 #include <TDF_AttributeDelta.hxx>
25 #include <TDF_Data.hxx>
26 #include <TDF_Delta.hxx>
27 #include <TDF_LabelMap.hxx>
28 #include <TDF_ListIteratorOfAttributeDeltaList.hxx>
29 #include <TDF_ListIteratorOfLabelList.hxx>
30 #include <TDF_MapIteratorOfLabelMap.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(TDF_Delta,MMgt_TShared)
35 #include <Standard_ConstructionError.hxx>
40 //=======================================================================
41 //function : TDF_Delta
43 //=======================================================================
45 TDF_Delta::TDF_Delta()
51 //=======================================================================
54 //=======================================================================
56 void TDF_Delta::Validity
57 (const Standard_Integer aBeginTime,
58 const Standard_Integer anEndTime)
60 myBeginTime = aBeginTime;
61 myEndTime = anEndTime;
65 //=======================================================================
66 //function : AddAttributeDelta
68 //=======================================================================
70 void TDF_Delta::AddAttributeDelta
71 (const Handle(TDF_AttributeDelta)& anAttributeDelta)
72 { if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
75 //=======================================================================
76 //function : BeforeOrAfterApply
78 //=======================================================================
80 void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
82 TDF_AttributeDeltaList ADlist;
83 // for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
84 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
85 for ( ; itr.More(); itr.Next()) ADlist.Append(itr.Value());
87 Handle(TDF_AttributeDelta) attDelta;
88 Handle(TDF_Attribute) att;
90 Standard_Boolean noDeadLock = Standard_True;
91 Standard_Integer nbAD = ADlist.Extent();
92 Standard_Boolean next;
93 while (noDeadLock && (nbAD != 0)) {
94 itr.Initialize(ADlist);
97 attDelta = itr.Value();
98 att = attDelta->Attribute();
100 next = !att->BeforeUndo(attDelta);
102 next = !att->AfterUndo(attDelta);
109 noDeadLock = (nbAD > ADlist.Extent());
110 nbAD = ADlist.Extent();
115 if (before) cout<<"Before"; else cout<<"After";
116 cout<<"Undo(): dead lock between these attributes:"<<endl;
117 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
118 cout<<"AttributeDelta type = "<<itr.Value()->DynamicType()->Name();
119 cout<<" Attribute type = "<<itr.Value()->Attribute()->DynamicType()->Name()<<endl;;
121 cout<<"BeforeUndo(): dead lock."<<endl;
123 cout<<"AfterUndo(): dead lock."<<endl;
126 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
127 attDelta = itr.Value();
128 att = attDelta->Attribute();
130 att->BeforeUndo(attDelta,Standard_True);
132 att->AfterUndo(attDelta,Standard_True);
138 //=======================================================================
141 //=======================================================================
143 void TDF_Delta::Apply()
145 TDF_ListIteratorOfAttributeDeltaList itr;
146 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
147 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
153 //=======================================================================
156 //=======================================================================
158 void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
161 // If <aLabelList> is not empty...
162 #ifdef OCCT_DEBUG_DELTA
163 Standard_Boolean inList;
164 if (aLabelList.Extent() > 0) cout<<"Previously added as modified label(s) ";
166 for (TDF_ListIteratorOfLabelList it1(aLabelList);
167 it1.More(); it1.Next()) {
168 #ifdef OCCT_DEBUG_DELTA
169 const TDF_Label& lab1 = it1.Value();
170 inList = labMap.Add(lab1);
172 lab1.EntryDump(cout);cout<<" | ";
176 #ifdef OCCT_DEBUG_DELTA
180 // New labels to add.
181 #ifdef OCCT_DEBUG_DELTA
182 if (myAttDeltaList.Extent() > 0) cout<<"New added as modified label(s) ";
184 for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
187 #ifdef OCCT_DEBUG_DELTA
188 const TDF_Label& lab1 = it2.Value()->Label();
189 inList = labMap.Add(lab1);
191 lab1.EntryDump(cout);cout<<" | ";
195 #ifdef OCCT_DEBUG_DELTA
199 // Now put labels into <aLabelList>.
201 for (TDF_MapIteratorOfLabelMap it3(labMap);
202 it3.More(); it3.Next()) {
203 aLabelList.Append(it3.Key());
207 //=======================================================================
210 //=======================================================================
212 void TDF_Delta::Dump(Standard_OStream& OS) const
214 OS<<"DELTA available from time \t#"<<myBeginTime<<" to time \t#"<<myEndTime<<endl;
215 Standard_Integer n = 0;
216 // for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
217 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
218 for ( ; itr.More(); itr.Next()) ++n;
219 OS<<"Nb Attribute Delta(s): "<<n<<endl;
220 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
221 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
222 OS<<"| "; attDelta->Dump(OS); OS<<endl;