b311480e |
1 | // Created on: 1999-06-24 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <TDF_CopyLabel.ixx> |
18 | #include <TDF_Label.hxx> |
19 | #include <TDF_AttributeMap.hxx> |
20 | #include <TDF_ChildIterator.hxx> |
21 | #include <TDF_IDFilter.hxx> |
22 | #include <TDF_DataSet.hxx> |
23 | #include <TDF_AttributeIterator.hxx> |
24 | #include <TDF_AttributeMap.hxx> |
25 | #include <TDF_MapIteratorOfAttributeMap.hxx> |
26 | #include <TDF_LabelMap.hxx> |
27 | #include <TDF_MapIteratorOfLabelMap.hxx> |
28 | #include <TDF_CopyTool.hxx> |
29 | #include <TDF_ClosureMode.hxx> |
30 | #include <TDF_ClosureTool.hxx> |
31 | #include <TDF_Tool.hxx> |
32 | #include <TDF_Data.hxx> |
33 | |
34 | // The bug concerns the COPY operation of some attributes of a non-self-contained label. |
35 | // The attributes making the label non-self-contained are not involved by the operation. |
36 | // Therefore, these attributes shouldn't be considered by the COPY mechanism and |
37 | // the label should be considered as a self-contained. |
38 | // Correction of the bug consists of ignoring the attributes not involved by the COPY operation. |
39 | #define BUC60813 |
40 | |
41 | //======================================================================= |
42 | //function : TDF_CopyLabel |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | TDF_CopyLabel::TDF_CopyLabel() |
47 | :myFilter(Standard_False), myIsDone(Standard_False) |
48 | { |
49 | mySL.Nullify(); |
50 | myTL.Nullify(); |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : TDF_CopyLabel |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | TDF_CopyLabel::TDF_CopyLabel(const TDF_Label& aSource,const TDF_Label& aTarget ) |
59 | :myFilter(Standard_False), myIsDone(Standard_False) |
60 | { |
61 | mySL = aSource; myTL = aTarget; |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : Load |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | void TDF_CopyLabel::Load(const TDF_Label& aSource, const TDF_Label& aTarget) |
70 | { |
71 | mySL = aSource; myTL = aTarget; |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : ExternalReferences |
76 | //purpose : internal |
77 | //======================================================================= |
78 | void TDF_CopyLabel::ExternalReferences(const TDF_Label& aRefLabel, const TDF_Label& aLabel, |
79 | TDF_AttributeMap& aExternals, const TDF_IDFilter& aFilter, |
80 | Handle(TDF_DataSet)& ds) |
81 | { |
82 | // TCollection_AsciiString entr1,entr2; //d |
7fd59977 |
83 | for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) { |
84 | itr.Value()->References(ds); |
85 | const TDF_AttributeMap& attMap = ds->Attributes(); //attMap |
86 | // TDF_Tool::Entry(itr.Value()->Label(), entr1); //d |
87 | // cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<" Label = "<<entr1 <<endl; |
88 | for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) { |
89 | Handle(TDF_Attribute) att = attMItr.Key(); |
90 | |
91 | // TDF_Tool::Entry(att->Label(), entr1); |
92 | // cout<<"\t\tReferences attribute dynamic type = "<<att->DynamicType()<<" Label = "<<entr1 <<endl; |
643cc6aa |
93 | if (!att.IsNull() && !att->Label().IsNull()) |
94 | { |
95 | if (aFilter.IsKept(att) && att->Label().IsDifferent(aRefLabel) && |
96 | !att->Label().IsDescendant(aRefLabel)) { |
97 | aExternals.Add(att); |
643cc6aa |
98 | } |
7fd59977 |
99 | } |
100 | } |
643cc6aa |
101 | |
7fd59977 |
102 | // const TDF_LabelMap& labMap = ds->Labels(); |
103 | // for (TDF_MapIteratorOfLabelMap labMItr(labMap);labMItr.More(); labMItr.Next()) { |
104 | // TDF_Tool::Entry(labMItr.Key(), entr1); |
105 | // cout<<"\t\tLABELS from DS of Attr:: Lab = "<<entr1<<endl; |
106 | // if (!labMItr.Key().IsDescendant(aRefLabel) && labMItr.Key().IsDifferent(aRefLabel)) { |
107 | // // aExternals.Add(itr.Value()); // ??? LabelMap of Attribute has label which don't |
108 | // // belongs to source hierarchy. So, what we should do ? |
109 | // // Add this Attribute to the aExternals or add all attributes |
110 | // // from this label ? |
111 | // TCollection_AsciiString entr1, entr2; |
112 | // TDF_Tool::Entry(labMItr.Key(), entr1); |
113 | // TDF_Tool::Entry(aRefLabel, entr2); |
114 | // cout<<"\t\t\tNot descendant label:: Lab1 = "<<entr1<<" and RefLab = "<<entr2<<endl; |
115 | // } |
116 | // } |
117 | |
7fd59977 |
118 | ds->Clear(); |
119 | } |
120 | } |
121 | //======================================================================= |
122 | //function : ExternalReferences |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | Standard_Boolean TDF_CopyLabel::ExternalReferences(const TDF_Label& L, |
127 | TDF_AttributeMap& aExternals, |
128 | const TDF_IDFilter& aFilter) |
129 | { |
130 | Handle(TDF_DataSet) ds = new TDF_DataSet(); |
131 | ExternalReferences(L, L, aExternals, aFilter, ds); |
132 | for (TDF_ChildIterator itr(L, Standard_True);itr.More(); itr.Next()) { |
133 | ExternalReferences(L,itr.Value(),aExternals , aFilter, ds); |
134 | } |
135 | if(!aExternals.Extent()) |
136 | return Standard_False; |
137 | else |
138 | return Standard_True; |
139 | } |
140 | |
141 | //======================================================================= |
63c629aa |
142 | #ifdef TDF_DEB |
7fd59977 |
143 | static void PrintEntry(const TDF_Label& label, const Standard_Boolean allLevels) |
144 | { |
145 | TCollection_AsciiString entry; |
146 | TDF_Tool::Entry(label, entry); |
147 | cout << "\tShareable attribute on the label = "<< entry << endl; |
148 | TDF_ChildIterator it (label, allLevels); |
149 | for (; it.More(); it.Next()) |
150 | { |
151 | TDF_Tool::Entry(it.Value(), entry); |
152 | cout << "\tChildLabelEntry = "<< entry << endl; |
153 | } |
154 | } |
155 | #endif |
156 | //======================================================================= |
157 | //function : Perform |
158 | //purpose : |
159 | //======================================================================= |
160 | |
161 | void TDF_CopyLabel::Perform() |
162 | { |
163 | myIsDone = Standard_False; |
164 | if(mySL.Data()->Root().IsDifferent(myTL.Data()->Root()) && //TDF_Data is not the same |
165 | #ifdef BUC60813 |
166 | !TDF_Tool::IsSelfContained(mySL, myFilter)) return; //source label isn't self-contained |
167 | #else |
168 | !TDF_Tool::IsSelfContained(mySL)) return; |
169 | #endif |
170 | else { |
63c629aa |
171 | #ifdef TDF_DEB |
7fd59977 |
172 | cout << "THE SAME Data" <<endl; |
173 | #endif |
174 | } |
175 | |
176 | //TDF_Data of the source and target labels are the same |
177 | Standard_Boolean extReferers = |
178 | ExternalReferences(mySL, myMapOfExt, myFilter); |
179 | |
180 | myRT = new TDF_RelocationTable(Standard_True); |
181 | Handle(TDF_DataSet) ds = new TDF_DataSet(); |
182 | TDF_ClosureMode mode(Standard_True); // descendant plus reference |
183 | ds->AddLabel(mySL); |
184 | myRT->SetRelocation(mySL, myTL); |
185 | TDF_ClosureTool::Closure(ds, myFilter, mode); |
186 | if(extReferers) { |
187 | for (TDF_MapIteratorOfAttributeMap attMItr(myMapOfExt);attMItr.More(); attMItr.Next()) { |
188 | Handle(TDF_Attribute) att = attMItr.Key(); |
189 | myRT->SetRelocation(att, att); |
63c629aa |
190 | #ifdef TDF_DEB |
7fd59977 |
191 | PrintEntry(att->Label(), Standard_True); |
192 | #endif |
193 | } |
194 | } |
195 | |
196 | TDF_CopyTool::Copy(ds,myRT); |
197 | myIsDone = Standard_True; |
198 | } |
199 | |
200 | |
201 | //======================================================================= |
202 | //function : RelocationTable |
203 | //purpose : |
204 | //======================================================================= |
205 | |
206 | const Handle(TDF_RelocationTable)& TDF_CopyLabel::RelocationTable() const |
207 | { |
208 | return myRT; |
209 | } |
210 | |
211 | //======================================================================= |
212 | //function : UseFilter |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | void TDF_CopyLabel::UseFilter(const TDF_IDFilter& aFilter) |
217 | { |
218 | myFilter = aFilter; |
219 | } |