1 // Created on: 1999-06-24
2 // Created by: Sergey ZARITCHNY
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.
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>
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.
41 //=======================================================================
42 //function : TDF_CopyLabel
44 //=======================================================================
46 TDF_CopyLabel::TDF_CopyLabel()
47 :myFilter(Standard_False), myIsDone(Standard_False)
53 //=======================================================================
54 //function : TDF_CopyLabel
56 //=======================================================================
58 TDF_CopyLabel::TDF_CopyLabel(const TDF_Label& aSource,const TDF_Label& aTarget )
59 :myFilter(Standard_False), myIsDone(Standard_False)
61 mySL = aSource; myTL = aTarget;
64 //=======================================================================
67 //=======================================================================
69 void TDF_CopyLabel::Load(const TDF_Label& aSource, const TDF_Label& aTarget)
71 mySL = aSource; myTL = aTarget;
74 //=======================================================================
75 //function : ExternalReferences
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)
82 // TCollection_AsciiString entr1,entr2; //d
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();
91 // TDF_Tool::Entry(att->Label(), entr1);
92 // cout<<"\t\tReferences attribute dynamic type = "<<att->DynamicType()<<" Label = "<<entr1 <<endl;
93 if (!att.IsNull() && !att->Label().IsNull())
95 if (aFilter.IsKept(att) && att->Label().IsDifferent(aRefLabel) &&
96 !att->Label().IsDescendant(aRefLabel)) {
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;
121 //=======================================================================
122 //function : ExternalReferences
124 //=======================================================================
126 Standard_Boolean TDF_CopyLabel::ExternalReferences(const TDF_Label& L,
127 TDF_AttributeMap& aExternals,
128 const TDF_IDFilter& aFilter)
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);
135 if(!aExternals.Extent())
136 return Standard_False;
138 return Standard_True;
141 //=======================================================================
143 static void PrintEntry(const TDF_Label& label, const Standard_Boolean allLevels)
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())
151 TDF_Tool::Entry(it.Value(), entry);
152 cout << "\tChildLabelEntry = "<< entry << endl;
156 //=======================================================================
159 //=======================================================================
161 void TDF_CopyLabel::Perform()
163 myIsDone = Standard_False;
164 if(mySL.Data()->Root().IsDifferent(myTL.Data()->Root()) && //TDF_Data is not the same
166 !TDF_Tool::IsSelfContained(mySL, myFilter)) return; //source label isn't self-contained
168 !TDF_Tool::IsSelfContained(mySL)) return;
172 cout << "THE SAME Data" <<endl;
176 //TDF_Data of the source and target labels are the same
177 Standard_Boolean extReferers =
178 ExternalReferences(mySL, myMapOfExt, myFilter);
180 myRT = new TDF_RelocationTable(Standard_True);
181 Handle(TDF_DataSet) ds = new TDF_DataSet();
182 TDF_ClosureMode mode(Standard_True); // descendant plus reference
184 myRT->SetRelocation(mySL, myTL);
185 TDF_ClosureTool::Closure(ds, myFilter, mode);
187 for (TDF_MapIteratorOfAttributeMap attMItr(myMapOfExt);attMItr.More(); attMItr.Next()) {
188 Handle(TDF_Attribute) att = attMItr.Key();
189 myRT->SetRelocation(att, att);
191 PrintEntry(att->Label(), Standard_True);
196 TDF_CopyTool::Copy(ds,myRT);
197 myIsDone = Standard_True;
201 //=======================================================================
202 //function : RelocationTable
204 //=======================================================================
206 const Handle(TDF_RelocationTable)& TDF_CopyLabel::RelocationTable() const
211 //=======================================================================
212 //function : UseFilter
214 //=======================================================================
216 void TDF_CopyLabel::UseFilter(const TDF_IDFilter& aFilter)