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.
18 #include <TDF_AttributeIterator.hxx>
19 #include <TDF_AttributeMap.hxx>
20 #include <TDF_ChildIterator.hxx>
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>
26 #include <TDF_DataSet.hxx>
27 #include <TDF_IDFilter.hxx>
28 #include <TDF_Label.hxx>
29 #include <TDF_LabelMap.hxx>
30 #include <TDF_MapIteratorOfAttributeMap.hxx>
31 #include <TDF_MapIteratorOfLabelMap.hxx>
32 #include <TDF_RelocationTable.hxx>
33 #include <TDF_Tool.hxx>
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.
40 //=======================================================================
41 //function : TDF_CopyLabel
43 //=======================================================================
44 TDF_CopyLabel::TDF_CopyLabel()
45 :myFilter(Standard_False), myIsDone(Standard_False)
51 //=======================================================================
52 //function : TDF_CopyLabel
54 //=======================================================================
56 TDF_CopyLabel::TDF_CopyLabel(const TDF_Label& aSource,const TDF_Label& aTarget )
57 :myFilter(Standard_False), myIsDone(Standard_False)
59 mySL = aSource; myTL = aTarget;
62 //=======================================================================
65 //=======================================================================
67 void TDF_CopyLabel::Load(const TDF_Label& aSource, const TDF_Label& aTarget)
69 mySL = aSource; myTL = aTarget;
72 //=======================================================================
73 //function : ExternalReferences
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)
80 // TCollection_AsciiString entr1,entr2; //d
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
85 // std::cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<" Label = "<<entr1 <<std::endl;
86 for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
87 Handle(TDF_Attribute) att = attMItr.Key();
89 // TDF_Tool::Entry(att->Label(), entr1);
90 // std::cout<<"\t\tReferences attribute dynamic type = "<<att->DynamicType()<<" Label = "<<entr1 <<std::endl;
91 if (!att.IsNull() && !att->Label().IsNull())
93 if (aFilter.IsKept(att) && att->Label().IsDifferent(aRefLabel) &&
94 !att->Label().IsDescendant(aRefLabel)) {
100 // const TDF_LabelMap& labMap = ds->Labels();
101 // for (TDF_MapIteratorOfLabelMap labMItr(labMap);labMItr.More(); labMItr.Next()) {
102 // TDF_Tool::Entry(labMItr.Key(), entr1);
103 // std::cout<<"\t\tLABELS from DS of Attr:: Lab = "<<entr1<<std::endl;
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);
112 // std::cout<<"\t\t\tNot descendant label:: Lab1 = "<<entr1<<" and RefLab = "<<entr2<<std::endl;
119 //=======================================================================
120 //function : ExternalReferences
122 //=======================================================================
124 Standard_Boolean TDF_CopyLabel::ExternalReferences(const TDF_Label& L,
125 TDF_AttributeMap& aExternals,
126 const TDF_IDFilter& aFilter)
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);
133 if(!aExternals.Extent())
134 return Standard_False;
136 return Standard_True;
139 //=======================================================================
141 static void PrintEntry(const TDF_Label& label, const Standard_Boolean allLevels)
143 TCollection_AsciiString entry;
144 TDF_Tool::Entry(label, entry);
145 std::cout << "\tShareable attribute on the label = "<< entry << std::endl;
146 TDF_ChildIterator it (label, allLevels);
147 for (; it.More(); it.Next())
149 TDF_Tool::Entry(it.Value(), entry);
150 std::cout << "\tChildLabelEntry = "<< entry << std::endl;
154 //=======================================================================
157 //=======================================================================
159 void TDF_CopyLabel::Perform()
161 myIsDone = Standard_False;
162 if(mySL.Data()->Root().IsDifferent(myTL.Data()->Root()) && //TDF_Data is not the same
163 !TDF_Tool::IsSelfContained(mySL, myFilter)) return; //source label isn't self-contained
165 Standard_Boolean extReferers =
166 ExternalReferences(mySL, myMapOfExt, myFilter);
168 myRT = new TDF_RelocationTable(Standard_True);
169 Handle(TDF_DataSet) ds = new TDF_DataSet();
170 TDF_ClosureMode mode(Standard_True); // descendant plus reference
172 myRT->SetRelocation(mySL, myTL);
173 TDF_ClosureTool::Closure(ds, myFilter, mode);
175 for (TDF_MapIteratorOfAttributeMap attMItr(myMapOfExt);attMItr.More(); attMItr.Next()) {
176 Handle(TDF_Attribute) att = attMItr.Key();
177 myRT->SetRelocation(att, att);
179 PrintEntry(att->Label(), Standard_True);
184 TDF_CopyTool::Copy(ds,myRT);
185 myIsDone = Standard_True;
189 //=======================================================================
190 //function : RelocationTable
192 //=======================================================================
194 const Handle(TDF_RelocationTable)& TDF_CopyLabel::RelocationTable() const
199 //=======================================================================
200 //function : UseFilter
202 //=======================================================================
204 void TDF_CopyLabel::UseFilter(const TDF_IDFilter& aFilter)
206 myFilter.Assign (aFilter);