0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / TDF / TDF_Delta.cxx
CommitLineData
b311480e 1// Created by: DAUTRY Philippe
2// Copyright (c) 1997-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// -------------
7fd59977 17// Version: 0.0
b311480e 18//Version Date Purpose
7fd59977 19// 0.0 Sep 8 1997 Creation
20
42cf5bc1 21#include <Standard_OutOfRange.hxx>
bc73b006 22#include <Standard_Dump.hxx>
42cf5bc1 23#include <Standard_Type.hxx>
24#include <TCollection_ExtendedString.hxx>
25#include <TDF_AttributeDelta.hxx>
26#include <TDF_Data.hxx>
27#include <TDF_Delta.hxx>
7fd59977 28#include <TDF_LabelMap.hxx>
29#include <TDF_ListIteratorOfAttributeDeltaList.hxx>
30#include <TDF_ListIteratorOfLabelList.hxx>
31#include <TDF_MapIteratorOfLabelMap.hxx>
32
25e59720 33IMPLEMENT_STANDARD_RTTIEXT(TDF_Delta,Standard_Transient)
92efcf78 34
0797d9d3 35#ifdef OCCT_DEBUG
7fd59977 36#include <Standard_ConstructionError.hxx>
37#endif
38
39#undef DEB_DELTA
40
41//=======================================================================
42//function : TDF_Delta
43//purpose :
44//=======================================================================
45
46TDF_Delta::TDF_Delta()
47: myBeginTime(0),
48 myEndTime(0)
49{}
50
51
52//=======================================================================
53//function : Validity
54//purpose :
55//=======================================================================
56
57void TDF_Delta::Validity
58(const Standard_Integer aBeginTime,
59 const Standard_Integer anEndTime)
60{
61 myBeginTime = aBeginTime;
62 myEndTime = anEndTime;
63}
64
65
66//=======================================================================
67//function : AddAttributeDelta
68//purpose :
69//=======================================================================
70
71void TDF_Delta::AddAttributeDelta
72(const Handle(TDF_AttributeDelta)& anAttributeDelta)
73{ if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
74
75
76//=======================================================================
77//function : BeforeOrAfterApply
78//purpose :
79//=======================================================================
80
81void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
82{
83 TDF_AttributeDeltaList ADlist;
84// for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
85 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
86 for ( ; itr.More(); itr.Next()) ADlist.Append(itr.Value());
87
88 Handle(TDF_AttributeDelta) attDelta;
89 Handle(TDF_Attribute) att;
90
91 Standard_Boolean noDeadLock = Standard_True;
92 Standard_Integer nbAD = ADlist.Extent();
93 Standard_Boolean next;
94 while (noDeadLock && (nbAD != 0)) {
95 itr.Initialize(ADlist);
96 while (itr.More()) {
97 next = Standard_True;
98 attDelta = itr.Value();
99 att = attDelta->Attribute();
100 if (before)
101 next = !att->BeforeUndo(attDelta);
102 else
103 next = !att->AfterUndo(attDelta);
104
105 if (next)
106 itr.Next();
107 else
108 ADlist.Remove(itr);
109 }
110 noDeadLock = (nbAD > ADlist.Extent());
111 nbAD = ADlist.Extent();
112 }
113
114 if (!noDeadLock) {
0797d9d3 115#ifdef OCCT_DEBUG
04232180 116 if (before) std::cout<<"Before"; else std::cout<<"After";
117 std::cout<<"Undo(): dead lock between these attributes:"<<std::endl;
7fd59977 118 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
04232180 119 std::cout<<"AttributeDelta type = "<<itr.Value()->DynamicType()->Name();
8c2d3314 120 std::cout<<" Attribute type = "<<itr.Value()->Attribute()->DynamicType()->Name()<<std::endl;
7fd59977 121 if (before)
04232180 122 std::cout<<"BeforeUndo(): dead lock."<<std::endl;
7fd59977 123 else
04232180 124 std::cout<<"AfterUndo(): dead lock."<<std::endl;
7fd59977 125 }
126#endif
127 for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
128 attDelta = itr.Value();
129 att = attDelta->Attribute();
130 if (before)
131 att->BeforeUndo(attDelta,Standard_True);
132 else
133 att->AfterUndo(attDelta,Standard_True);
134 }
135 }
136}
137
138
139//=======================================================================
140//function : Apply
141//purpose :
142//=======================================================================
143
144void TDF_Delta::Apply()
145{
146 TDF_ListIteratorOfAttributeDeltaList itr;
147 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
148 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
149 attDelta->Apply();
150 }
151}
152
153
154//=======================================================================
155//function : Labels
156//purpose :
157//=======================================================================
158
159void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
160{
7fd59977 161 TDF_LabelMap labMap;
162 // If <aLabelList> is not empty...
0797d9d3 163#ifdef OCCT_DEBUG_DELTA
96a95605 164 Standard_Boolean inList;
04232180 165 if (aLabelList.Extent() > 0) std::cout<<"Previously added as modified label(s) ";
7fd59977 166#endif
167 for (TDF_ListIteratorOfLabelList it1(aLabelList);
168 it1.More(); it1.Next()) {
0797d9d3 169#ifdef OCCT_DEBUG_DELTA
7fd59977 170 const TDF_Label& lab1 = it1.Value();
171 inList = labMap.Add(lab1);
7fd59977 172 if (!inList) {
04232180 173 lab1.EntryDump(std::cout);std::cout<<" | ";
7fd59977 174 }
175#endif
176 }
0797d9d3 177#ifdef OCCT_DEBUG_DELTA
04232180 178 std::cout<<std::endl;
7fd59977 179#endif
180
181 // New labels to add.
0797d9d3 182#ifdef OCCT_DEBUG_DELTA
04232180 183 if (myAttDeltaList.Extent() > 0) std::cout<<"New added as modified label(s) ";
7fd59977 184#endif
185 for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
186 it2.More();
187 it2.Next()) {
0797d9d3 188#ifdef OCCT_DEBUG_DELTA
7fd59977 189 const TDF_Label& lab1 = it2.Value()->Label();
190 inList = labMap.Add(lab1);
7fd59977 191 if (!inList) {
04232180 192 lab1.EntryDump(std::cout);std::cout<<" | ";
7fd59977 193 }
194#endif
195 }
0797d9d3 196#ifdef OCCT_DEBUG_DELTA
04232180 197 std::cout<<std::endl;
7fd59977 198#endif
199
200 // Now put labels into <aLabelList>.
201 aLabelList.Clear();
202 for (TDF_MapIteratorOfLabelMap it3(labMap);
203 it3.More(); it3.Next()) {
204 aLabelList.Append(it3.Key());
205 }
206}
207
208//=======================================================================
209//function : Dump
210//purpose :
211//=======================================================================
212
213void TDF_Delta::Dump(Standard_OStream& OS) const
214{
04232180 215 OS<<"DELTA available from time \t#"<<myBeginTime<<" to time \t#"<<myEndTime<<std::endl;
7fd59977 216 Standard_Integer n = 0;
217// for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
218 TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
219 for ( ; itr.More(); itr.Next()) ++n;
04232180 220 OS<<"Nb Attribute Delta(s): "<<n<<std::endl;
7fd59977 221 for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
222 const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
04232180 223 OS<<"| "; attDelta->Dump(OS); OS<<std::endl;
7fd59977 224 }
225}
bc73b006 226
227//=======================================================================
228//function : DumpJson
229//purpose :
230//=======================================================================
231void TDF_Delta::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
232{
233 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
234
235 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBeginTime)
236 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myEndTime)
237
238 for (TDF_AttributeDeltaList::Iterator anAttDeltaListIt (myAttDeltaList); anAttDeltaListIt.More(); anAttDeltaListIt.Next())
239 {
240 const Handle(TDF_AttributeDelta)& anAttDeltaList = anAttDeltaListIt.Value();
241 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anAttDeltaList.get())
242 }
243
244 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName)
245}