0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / TDF / TDF_Delta.cxx
1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //              -------------
17
18 // Version:     0.0
19 //Version       Date            Purpose
20 //              0.0     Sep  8 1997     Creation
21
22
23
24 #include <TDF_Delta.ixx>
25
26 #include <TDF_LabelMap.hxx>
27 #include <TDF_ListIteratorOfAttributeDeltaList.hxx>
28 #include <TDF_ListIteratorOfLabelList.hxx>
29 #include <TDF_MapIteratorOfLabelMap.hxx>
30
31 #ifdef DEB
32 #include <Standard_ConstructionError.hxx>
33 #endif
34
35 #undef DEB_DELTA
36
37 //=======================================================================
38 //function : TDF_Delta
39 //purpose  : 
40 //=======================================================================
41
42 TDF_Delta::TDF_Delta() 
43 : myBeginTime(0),
44   myEndTime(0)
45 {}
46
47
48 //=======================================================================
49 //function : Validity
50 //purpose  : 
51 //=======================================================================
52
53 void TDF_Delta::Validity
54 (const Standard_Integer aBeginTime,
55  const Standard_Integer anEndTime)
56 {
57   myBeginTime   = aBeginTime;
58   myEndTime     = anEndTime;
59 }
60
61
62 //=======================================================================
63 //function : AddAttributeDelta
64 //purpose  : 
65 //=======================================================================
66
67 void TDF_Delta::AddAttributeDelta
68 (const Handle(TDF_AttributeDelta)& anAttributeDelta)
69 { if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
70
71
72 //=======================================================================
73 //function : BeforeOrAfterApply
74 //purpose  : 
75 //=======================================================================
76
77 void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
78 {
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());
83
84   Handle(TDF_AttributeDelta) attDelta;
85   Handle(TDF_Attribute) att;
86
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);
92     while (itr.More()) {
93       next = Standard_True;
94       attDelta = itr.Value();
95       att = attDelta->Attribute();
96       if (before)
97         next = !att->BeforeUndo(attDelta);
98       else
99         next = !att->AfterUndo(attDelta);
100
101       if (next)
102         itr.Next();
103       else
104         ADlist.Remove(itr);
105     }
106     noDeadLock = (nbAD > ADlist.Extent());
107     nbAD = ADlist.Extent();
108   }
109
110   if (!noDeadLock) {
111 #ifdef DEB
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;;
117     if (before)
118       Standard_ConstructionError::Raise("BeforeUndo(): dead lock.");
119     else
120       Standard_ConstructionError::Raise("AfterUndo(): dead lock.");
121     }
122 #endif
123     for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
124       attDelta = itr.Value();
125       att = attDelta->Attribute();
126       if (before)
127         att->BeforeUndo(attDelta,Standard_True);
128       else
129         att->AfterUndo(attDelta,Standard_True);
130     }
131   }
132 }
133
134
135 //=======================================================================
136 //function : Apply
137 //purpose  : 
138 //=======================================================================
139
140 void TDF_Delta::Apply()
141 {
142   TDF_ListIteratorOfAttributeDeltaList itr;
143   for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
144     const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
145     attDelta->Apply();
146   }
147 }
148
149
150 //=======================================================================
151 //function : Labels
152 //purpose  : 
153 //=======================================================================
154
155 void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
156 {
157   TDF_LabelMap labMap;
158   // If <aLabelList> is not empty...
159 #ifdef DEB_DELTA
160   Standard_Boolean inList;
161   if (aLabelList.Extent() > 0) cout<<"Previously added as modified label(s) ";
162 #endif
163   for (TDF_ListIteratorOfLabelList it1(aLabelList);
164        it1.More(); it1.Next()) {
165 #ifdef DEB_DELTA
166     const TDF_Label& lab1 = it1.Value();
167     inList = labMap.Add(lab1);
168     if (!inList) {
169       lab1.EntryDump(cout);cout<<" | ";
170     }
171 #endif
172   }
173 #ifdef DEB_DELTA
174   cout<<endl;
175 #endif
176
177   // New labels to add.
178 #ifdef DEB_DELTA
179   if (myAttDeltaList.Extent() > 0) cout<<"New added as modified label(s) ";
180 #endif
181   for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
182        it2.More();
183        it2.Next()) {
184 #ifdef DEB_DELTA
185     const TDF_Label& lab1 = it2.Value()->Label();
186     inList = labMap.Add(lab1);
187     if (!inList) {
188       lab1.EntryDump(cout);cout<<" | ";
189     }
190 #endif
191   }
192 #ifdef DEB_DELTA
193   cout<<endl;
194 #endif
195
196   // Now put labels into <aLabelList>.
197   aLabelList.Clear();
198   for (TDF_MapIteratorOfLabelMap it3(labMap);
199        it3.More(); it3.Next()) {
200     aLabelList.Append(it3.Key());
201   }
202 }
203
204 //=======================================================================
205 //function : Dump
206 //purpose  : 
207 //=======================================================================
208
209 void TDF_Delta::Dump(Standard_OStream& OS) const
210 {
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;
220   }
221 }