0f04ee5f9280a88fdce3879daaa66bc5d13eab1e
[occt.git] / src / TFunction / TFunction_Logbook.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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_Tool.hxx>
25 #include <TFunction_Logbook.hxx>
26
27 //=======================================================================
28 //function : TFunction_Logbook
29 //purpose  : A Logbook creation
30 //=======================================================================
31 TFunction_Logbook::TFunction_Logbook():isDone(Standard_False)
32 {}
33
34 //=======================================================================
35 //function : Clear
36 //purpose  : Clears the valid and modified labels
37 //=======================================================================
38
39 void TFunction_Logbook::Clear()
40 {
41   myTouched.Clear();
42   myImpacted.Clear();
43   myValid.Clear();
44 }
45
46 //=======================================================================
47 //function : IsEmpty
48 //purpose  : Returns Standard_True if the nothing is reccorded in the logbook
49 //=======================================================================
50
51 Standard_Boolean TFunction_Logbook::IsEmpty () const
52 {
53   return (myTouched.IsEmpty() && myImpacted.IsEmpty() && myValid.IsEmpty());
54 }
55
56 //=======================================================================
57 //function : IsModified
58 //purpose  : Returns Standard_True if the label is modified
59 //=======================================================================
60
61 Standard_Boolean TFunction_Logbook::IsModified(const TDF_Label& L,
62                                                const Standard_Boolean WithChildren) const
63 {
64   if (myTouched.Contains(L)) return Standard_True;
65   if (myImpacted.Contains(L)) return Standard_True;
66   if (WithChildren) {
67     TDF_ChildIterator itr(L);
68     for (; itr.More(); itr.Next())
69       if (IsModified(itr.Value(), Standard_True))
70         return Standard_True;
71   }
72   return Standard_False;
73 }
74
75 //=======================================================================
76 //function : SetValid
77 //purpose  : 
78 //=======================================================================
79
80 void TFunction_Logbook::SetValid(const TDF_Label& L,
81                                  const Standard_Boolean WithChildren)
82 {
83   myValid.Add(L);
84   if (WithChildren) {
85     TDF_ChildIterator itr(L, Standard_True);
86     for (; itr.More(); itr.Next()) {
87       myValid.Add(itr.Value());
88     }
89   }
90 }
91
92 //=======================================================================
93 //function : SetImpacted
94 //purpose  : 
95 //=======================================================================
96
97 void TFunction_Logbook::SetImpacted(const TDF_Label& L,
98                                     const Standard_Boolean WithChildren)
99 {
100   myImpacted.Add(L);
101   if (WithChildren) {
102     TDF_ChildIterator itr(L, Standard_True);
103     for (; itr.More(); itr.Next()) {
104       myImpacted.Add(itr.Value());
105     }
106   }  
107 }
108
109 //=======================================================================
110 //function : Dump
111 //purpose  : Dump of modifications
112 //=======================================================================
113
114 Standard_OStream& TFunction_Logbook::Dump(Standard_OStream& stream) const
115 {
116   TDF_MapIteratorOfLabelMap itr;
117   TCollection_AsciiString as;
118   
119   stream<<"Done = "<<isDone<<endl;
120   stream<<"Touched labels: "<<endl;
121   for (itr.Initialize(myTouched); itr.More(); itr.Next()) {
122     TDF_Tool::Entry(itr.Key(), as);
123     stream<<as<<endl;
124   }
125   stream<<"Impacted labels: "<<endl;
126   for (itr.Initialize(myImpacted); itr.More(); itr.Next()) {
127     TDF_Tool::Entry(itr.Key(), as);
128     stream<<as<<endl;
129   }  
130   stream<<"Valid labels: "<<endl;
131   for (itr.Initialize(myValid); itr.More(); itr.Next()) {
132     TDF_Tool::Entry(itr.Key(), as);
133     stream<<as<<endl;
134   }  
135
136   return stream;
137 }