1 // Created on: 1999-07-20
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_OStream.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TDF_ChildIterator.hxx>
21 #include <TDF_Label.hxx>
22 #include <TDF_LabelMap.hxx>
23 #include <TDF_MapIteratorOfLabelMap.hxx>
24 #include <TDF_RelocationTable.hxx>
25 #include <TDF_Tool.hxx>
26 #include <TFunction_Logbook.hxx>
27 #include <Standard_GUID.hxx>
29 //=======================================================================
31 //purpose : Static method to get an ID
32 //=======================================================================
33 const Standard_GUID& TFunction_Logbook::GetID()
35 static Standard_GUID TFunction_LogbookID("CF519724-5CA4-4B90-835F-8919BE1DDE4B");
36 return TFunction_LogbookID;
39 //=======================================================================
41 //purpose : Finds or creates a Scope attribute
42 //=======================================================================
44 Handle(TFunction_Logbook) TFunction_Logbook::Set(const TDF_Label& Access)
46 Handle(TFunction_Logbook) S;
47 if (!Access.Root().FindAttribute(TFunction_Logbook::GetID(), S))
49 S = new TFunction_Logbook();
50 Access.Root().AddAttribute(S);
55 //=======================================================================
57 //purpose : Returns GUID of the function
58 //=======================================================================
60 const Standard_GUID& TFunction_Logbook::ID() const
65 //=======================================================================
66 //function : TFunction_Logbook
67 //purpose : A Logbook creation
68 //=======================================================================
69 TFunction_Logbook::TFunction_Logbook():isDone(Standard_False)
72 //=======================================================================
74 //purpose : Clears the valid and modified labels
75 //=======================================================================
77 void TFunction_Logbook::Clear()
88 //=======================================================================
90 //purpose : Returns Standard_True if the nothing is reccorded in the logbook
91 //=======================================================================
93 Standard_Boolean TFunction_Logbook::IsEmpty () const
95 return (myTouched.IsEmpty() && myImpacted.IsEmpty() && myValid.IsEmpty());
98 //=======================================================================
99 //function : IsModified
100 //purpose : Returns Standard_True if the label is modified
101 //=======================================================================
103 Standard_Boolean TFunction_Logbook::IsModified(const TDF_Label& L,
104 const Standard_Boolean WithChildren) const
106 if (myTouched.Contains(L))
107 return Standard_True;
108 if (myImpacted.Contains(L))
109 return Standard_True;
112 TDF_ChildIterator itr(L);
113 for (; itr.More(); itr.Next())
115 if (IsModified(itr.Value(), Standard_True))
117 return Standard_True;
121 return Standard_False;
124 //=======================================================================
125 //function : SetValid
127 //=======================================================================
129 void TFunction_Logbook::SetValid(const TDF_Label& L,
130 const Standard_Boolean WithChildren)
136 TDF_ChildIterator itr(L, Standard_True);
137 for (; itr.More(); itr.Next())
139 myValid.Add(itr.Value());
144 void TFunction_Logbook::SetValid(const TDF_LabelMap& Ls)
147 TDF_MapIteratorOfLabelMap itrm(Ls);
148 for (; itrm.More(); itrm.Next())
150 const TDF_Label& L = itrm.Key();
155 //=======================================================================
156 //function : SetImpacted
158 //=======================================================================
160 void TFunction_Logbook::SetImpacted(const TDF_Label& L,
161 const Standard_Boolean WithChildren)
167 TDF_ChildIterator itr(L, Standard_True);
168 for (; itr.More(); itr.Next())
170 myImpacted.Add(itr.Value());
175 //=======================================================================
176 //function : GetValid
177 //purpose : Returns valid labels.
178 //=======================================================================
180 void TFunction_Logbook::GetValid(TDF_LabelMap& Ls) const
182 // Copy valid labels.
183 TDF_MapIteratorOfLabelMap itrm(myValid);
184 for (; itrm.More(); itrm.Next())
186 const TDF_Label& L = itrm.Key();
191 //=======================================================================
193 //purpose : Undos (and redos) the attribute.
194 //=======================================================================
196 void TFunction_Logbook::Restore(const Handle(TDF_Attribute)& other)
198 Handle(TFunction_Logbook) logbook = Handle(TFunction_Logbook)::DownCast(other);
201 isDone = logbook->isDone;
204 TDF_MapIteratorOfLabelMap itrm;
205 for (itrm.Initialize(logbook->myValid); itrm.More(); itrm.Next())
207 myValid.Add(itrm.Key());
210 for (itrm.Initialize(logbook->myTouched); itrm.More(); itrm.Next())
212 myTouched.Add(itrm.Key());
215 for (itrm.Initialize(logbook->myImpacted); itrm.More(); itrm.Next())
217 myImpacted.Add(itrm.Key());
221 //=======================================================================
223 //purpose : Method for Copy mechanism
224 //=======================================================================
226 void TFunction_Logbook::Paste(const Handle(TDF_Attribute)& into,
227 const Handle(TDF_RelocationTable)& RT) const
229 Handle(TFunction_Logbook) logbook = Handle(TFunction_Logbook)::DownCast(into);
232 logbook->isDone = isDone;
235 logbook->myTouched.Clear();
236 TDF_MapIteratorOfLabelMap itr(myTouched);
237 for (; itr.More(); itr.Next())
239 const TDF_Label& L = itr.Value();
243 if (RT->HasRelocation(L, relocL))
244 logbook->myTouched.Add(relocL);
246 logbook->myTouched.Add(L);
251 logbook->myImpacted.Clear();
252 itr.Initialize(myImpacted);
253 for (; itr.More(); itr.Next())
255 const TDF_Label& L = itr.Value();
259 if (RT->HasRelocation(L, relocL))
260 logbook->myImpacted.Add(relocL);
262 logbook->myImpacted.Add(L);
267 logbook->myValid.Clear();
268 itr.Initialize(myValid);
269 for (; itr.More(); itr.Next())
271 const TDF_Label& L = itr.Value();
275 if (RT->HasRelocation(L, relocL))
276 logbook->myValid.Add(relocL);
278 logbook->myValid.Add(L);
283 //=======================================================================
284 //function : NewEmpty
285 //purpose : Returns new empty graph node attribute
286 //=======================================================================
288 Handle(TDF_Attribute) TFunction_Logbook::NewEmpty() const
290 return new TFunction_Logbook();
293 //=======================================================================
295 //purpose : Dump of modifications
296 //=======================================================================
298 Standard_OStream& TFunction_Logbook::Dump(Standard_OStream& stream) const
300 TDF_MapIteratorOfLabelMap itr;
301 TCollection_AsciiString as;
303 stream<<"Done = "<<isDone<<endl;
304 stream<<"Touched labels: "<<endl;
305 for (itr.Initialize(myTouched); itr.More(); itr.Next())
307 TDF_Tool::Entry(itr.Key(), as);
310 stream<<"Impacted labels: "<<endl;
311 for (itr.Initialize(myImpacted); itr.More(); itr.Next())
313 TDF_Tool::Entry(itr.Key(), as);
316 stream<<"Valid labels: "<<endl;
317 for (itr.Initialize(myValid); itr.More(); itr.Next())
319 TDF_Tool::Entry(itr.Key(), as);