0026937: Eliminate NO_CXX_EXCEPTION macro support
[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 // Version:     0.0
18 //Version       Date            Purpose
19 //              0.0     Sep  8 1997     Creation
20
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>
31
32 IMPLEMENT_STANDARD_RTTIEXT(TDF_Delta,MMgt_TShared)
33
34 #ifdef OCCT_DEBUG
35 #include <Standard_ConstructionError.hxx>
36 #endif
37
38 #undef DEB_DELTA
39
40 //=======================================================================
41 //function : TDF_Delta
42 //purpose  : 
43 //=======================================================================
44
45 TDF_Delta::TDF_Delta() 
46 : myBeginTime(0),
47   myEndTime(0)
48 {}
49
50
51 //=======================================================================
52 //function : Validity
53 //purpose  : 
54 //=======================================================================
55
56 void TDF_Delta::Validity
57 (const Standard_Integer aBeginTime,
58  const Standard_Integer anEndTime)
59 {
60   myBeginTime   = aBeginTime;
61   myEndTime     = anEndTime;
62 }
63
64
65 //=======================================================================
66 //function : AddAttributeDelta
67 //purpose  : 
68 //=======================================================================
69
70 void TDF_Delta::AddAttributeDelta
71 (const Handle(TDF_AttributeDelta)& anAttributeDelta)
72 { if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
73
74
75 //=======================================================================
76 //function : BeforeOrAfterApply
77 //purpose  : 
78 //=======================================================================
79
80 void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
81 {
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());
86
87   Handle(TDF_AttributeDelta) attDelta;
88   Handle(TDF_Attribute) att;
89
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);
95     while (itr.More()) {
96       next = Standard_True;
97       attDelta = itr.Value();
98       att = attDelta->Attribute();
99       if (before)
100         next = !att->BeforeUndo(attDelta);
101       else
102         next = !att->AfterUndo(attDelta);
103
104       if (next)
105         itr.Next();
106       else
107         ADlist.Remove(itr);
108     }
109     noDeadLock = (nbAD > ADlist.Extent());
110     nbAD = ADlist.Extent();
111   }
112
113   if (!noDeadLock) {
114 #ifdef OCCT_DEBUG
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;;
120     if (before)
121       cout<<"BeforeUndo(): dead lock."<<endl;
122     else
123       cout<<"AfterUndo(): dead lock."<<endl;
124     }
125 #endif
126     for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
127       attDelta = itr.Value();
128       att = attDelta->Attribute();
129       if (before)
130         att->BeforeUndo(attDelta,Standard_True);
131       else
132         att->AfterUndo(attDelta,Standard_True);
133     }
134   }
135 }
136
137
138 //=======================================================================
139 //function : Apply
140 //purpose  : 
141 //=======================================================================
142
143 void TDF_Delta::Apply()
144 {
145   TDF_ListIteratorOfAttributeDeltaList itr;
146   for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
147     const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
148     attDelta->Apply();
149   }
150 }
151
152
153 //=======================================================================
154 //function : Labels
155 //purpose  : 
156 //=======================================================================
157
158 void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
159 {
160   TDF_LabelMap labMap;
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) ";
165 #endif
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);
171     if (!inList) {
172       lab1.EntryDump(cout);cout<<" | ";
173     }
174 #endif
175   }
176 #ifdef OCCT_DEBUG_DELTA
177   cout<<endl;
178 #endif
179
180   // New labels to add.
181 #ifdef OCCT_DEBUG_DELTA
182   if (myAttDeltaList.Extent() > 0) cout<<"New added as modified label(s) ";
183 #endif
184   for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
185        it2.More();
186        it2.Next()) {
187 #ifdef OCCT_DEBUG_DELTA
188     const TDF_Label& lab1 = it2.Value()->Label();
189     inList = labMap.Add(lab1);
190     if (!inList) {
191       lab1.EntryDump(cout);cout<<" | ";
192     }
193 #endif
194   }
195 #ifdef OCCT_DEBUG_DELTA
196   cout<<endl;
197 #endif
198
199   // Now put labels into <aLabelList>.
200   aLabelList.Clear();
201   for (TDF_MapIteratorOfLabelMap it3(labMap);
202        it3.More(); it3.Next()) {
203     aLabelList.Append(it3.Key());
204   }
205 }
206
207 //=======================================================================
208 //function : Dump
209 //purpose  : 
210 //=======================================================================
211
212 void TDF_Delta::Dump(Standard_OStream& OS) const
213 {
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;
223   }
224 }