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