0022627: Change OCCT memory management defaults
[occt.git] / src / TDF / TDF_Delta.cxx
CommitLineData
7fd59977 1// File: TDF_Delta.cxx
2// -------------
3// Author: DAUTRY Philippe
4// <fid@fox.paris1.matra-dtv.fr>
5// Copyright: Matra Datavision 1997
6
7// Version: 0.0
8// History: Version Date Purpose
9// 0.0 Sep 8 1997 Creation
10
11
12
13#include <TDF_Delta.ixx>
14
15#include <TDF_LabelMap.hxx>
16#include <TDF_ListIteratorOfAttributeDeltaList.hxx>
17#include <TDF_ListIteratorOfLabelList.hxx>
18#include <TDF_MapIteratorOfLabelMap.hxx>
19
20#ifdef DEB
21#include <Standard_ConstructionError.hxx>
22#endif
23
24#undef DEB_DELTA
25
26//=======================================================================
27//function : TDF_Delta
28//purpose :
29//=======================================================================
30
31TDF_Delta::TDF_Delta()
32: myBeginTime(0),
33 myEndTime(0)
34{}
35
36
37//=======================================================================
38//function : Validity
39//purpose :
40//=======================================================================
41
42void TDF_Delta::Validity
43(const Standard_Integer aBeginTime,
44 const Standard_Integer anEndTime)
45{
46 myBeginTime = aBeginTime;
47 myEndTime = anEndTime;
48}
49
50
51//=======================================================================
52//function : AddAttributeDelta
53//purpose :
54//=======================================================================
55
56void TDF_Delta::AddAttributeDelta
57(const Handle(TDF_AttributeDelta)& anAttributeDelta)
58{ if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
59
60
61//=======================================================================
62//function : BeforeOrAfterApply
63//purpose :
64//=======================================================================
65
66void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
67{
68 TDF_AttributeDeltaList ADlist;
69// for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
70 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
71 for ( ; itr.More(); itr.Next()) ADlist.Append(itr.Value());
72
73 Handle(TDF_AttributeDelta) attDelta;
74 Handle(TDF_Attribute) att;
75
76 Standard_Boolean noDeadLock = Standard_True;
77 Standard_Integer nbAD = ADlist.Extent();
78 Standard_Boolean next;
79 while (noDeadLock && (nbAD != 0)) {
80 itr.Initialize(ADlist);
81 while (itr.More()) {
82 next = Standard_True;
83 attDelta = itr.Value();
84 att = attDelta->Attribute();
85 if (before)
86 next = !att->BeforeUndo(attDelta);
87 else
88 next = !att->AfterUndo(attDelta);
89
90 if (next)
91 itr.Next();
92 else
93 ADlist.Remove(itr);
94 }
95 noDeadLock = (nbAD > ADlist.Extent());
96 nbAD = ADlist.Extent();
97 }
98
99 if (!noDeadLock) {
100#ifdef DEB
101 if (before) cout<<"Before"; else cout<<"After";
102 cout<<"Undo(): dead lock between these attributes:"<<endl;
103 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
104 cout<<"AttributeDelta type = "<<itr.Value()->DynamicType()->Name();
105 cout<<" Attribute type = "<<itr.Value()->Attribute()->DynamicType()->Name()<<endl;;
106 if (before)
107 Standard_ConstructionError::Raise("BeforeUndo(): dead lock.");
108 else
109 Standard_ConstructionError::Raise("AfterUndo(): dead lock.");
110 }
111#endif
112 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
113 attDelta = itr.Value();
114 att = attDelta->Attribute();
115 if (before)
116 att->BeforeUndo(attDelta,Standard_True);
117 else
118 att->AfterUndo(attDelta,Standard_True);
119 }
120 }
121}
122
123
124//=======================================================================
125//function : Apply
126//purpose :
127//=======================================================================
128
129void TDF_Delta::Apply()
130{
131 TDF_ListIteratorOfAttributeDeltaList itr;
132 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
133 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
134 attDelta->Apply();
135 }
136}
137
138
139//=======================================================================
140//function : Labels
141//purpose :
142//=======================================================================
143
144void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
145{
146 Standard_Boolean inList;
147 TDF_LabelMap labMap;
148 // If <aLabelList> is not empty...
149#ifdef DEB_DELTA
150 if (aLabelList.Extent() > 0) cout<<"Previously added as modified label(s) ";
151#endif
152 for (TDF_ListIteratorOfLabelList it1(aLabelList);
153 it1.More(); it1.Next()) {
154 const TDF_Label& lab1 = it1.Value();
155 inList = labMap.Add(lab1);
156#ifdef DEB_DELTA
157 if (!inList) {
158 lab1.EntryDump(cout);cout<<" | ";
159 }
160#endif
161 }
162#ifdef DEB_DELTA
163 cout<<endl;
164#endif
165
166 // New labels to add.
167#ifdef DEB_DELTA
168 if (myAttDeltaList.Extent() > 0) cout<<"New added as modified label(s) ";
169#endif
170 for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
171 it2.More();
172 it2.Next()) {
173 const TDF_Label& lab1 = it2.Value()->Label();
174 inList = labMap.Add(lab1);
175#ifdef DEB_DELTA
176 if (!inList) {
177 lab1.EntryDump(cout);cout<<" | ";
178 }
179#endif
180 }
181#ifdef DEB_DELTA
182 cout<<endl;
183#endif
184
185 // Now put labels into <aLabelList>.
186 aLabelList.Clear();
187 for (TDF_MapIteratorOfLabelMap it3(labMap);
188 it3.More(); it3.Next()) {
189 aLabelList.Append(it3.Key());
190 }
191}
192
193//=======================================================================
194//function : Dump
195//purpose :
196//=======================================================================
197
198void TDF_Delta::Dump(Standard_OStream& OS) const
199{
200 OS<<"DELTA available from time \t#"<<myBeginTime<<" to time \t#"<<myEndTime<<endl;
201 Standard_Integer n = 0;
202// for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
203 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
204 for ( ; itr.More(); itr.Next()) ++n;
205 OS<<"Nb Attribute Delta(s): "<<n<<endl;
206 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
207 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
208 OS<<"| "; attDelta->Dump(OS); OS<<endl;
209 }
210}