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.
40 //=======================================================================
41 //function : TDF_CopyLabel
43 //=======================================================================
45 TDF_CopyLabel::TDF_CopyLabel()
46 :myFilter(Standard_False), myIsDone(Standard_False)
52 //=======================================================================
53 //function : TDF_CopyLabel
55 //=======================================================================
57 TDF_CopyLabel::TDF_CopyLabel(const TDF_Label& aSource,const TDF_Label& aTarget )
58 :myFilter(Standard_False), myIsDone(Standard_False)
60 mySL = aSource; myTL = aTarget;
63 //=======================================================================
66 //=======================================================================
68 void TDF_CopyLabel::Load(const TDF_Label& aSource, const TDF_Label& aTarget)
70 mySL = aSource; myTL = aTarget;
73 //=======================================================================
74 //function : ExternalReferences
76 //=======================================================================
77 void TDF_CopyLabel::ExternalReferences(const TDF_Label& aRefLabel, const TDF_Label& aLabel,
78 TDF_AttributeMap& aExternals, const TDF_IDFilter& aFilter,
79 Handle(TDF_DataSet)& ds)
81 // TCollection_AsciiString entr1,entr2; //d
82 for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) {
83 itr.Value()->References(ds);
84 const TDF_AttributeMap& attMap = ds->Attributes(); //attMap
85 // TDF_Tool::Entry(itr.Value()->Label(), entr1); //d
86 // cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<" Label = "<<entr1 <<endl;
87 for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
88 Handle(TDF_Attribute) att = attMItr.Key();
90 // TDF_Tool::Entry(att->Label(), entr1);
91 // cout<<"\t\tReferences attribute dynamic type = "<<att->DynamicType()<<" Label = "<<entr1 <<endl;
92 if (!att.IsNull() && !att->Label().IsNull())
94 if (aFilter.IsKept(att) && att->Label().IsDifferent(aRefLabel) &&
95 !att->Label().IsDescendant(aRefLabel)) {
101 // const TDF_LabelMap& labMap = ds->Labels();
102 // for (TDF_MapIteratorOfLabelMap labMItr(labMap);labMItr.More(); labMItr.Next()) {
103 // TDF_Tool::Entry(labMItr.Key(), entr1);
104 // cout<<"\t\tLABELS from DS of Attr:: Lab = "<<entr1<<endl;
105 // if (!labMItr.Key().IsDescendant(aRefLabel) && labMItr.Key().IsDifferent(aRefLabel)) {
106 // // aExternals.Add(itr.Value()); // ??? LabelMap of Attribute has label which don't
107 // // belongs to source hierarchy. So, what we should do ?
108 // // Add this Attribute to the aExternals or add all attributes
109 // // from this label ?
110 // TCollection_AsciiString entr1, entr2;
111 // TDF_Tool::Entry(labMItr.Key(), entr1);
112 // TDF_Tool::Entry(aRefLabel, entr2);
113 // cout<<"\t\t\tNot descendant label:: Lab1 = "<<entr1<<" and RefLab = "<<entr2<<endl;
120 //=======================================================================
121 //function : ExternalReferences
123 //=======================================================================
125 Standard_Boolean TDF_CopyLabel::ExternalReferences(const TDF_Label& L,
126 TDF_AttributeMap& aExternals,
127 const TDF_IDFilter& aFilter)
129 Handle(TDF_DataSet) ds = new TDF_DataSet();
130 ExternalReferences(L, L, aExternals, aFilter, ds);
131 for (TDF_ChildIterator itr(L, Standard_True);itr.More(); itr.Next()) {
132 ExternalReferences(L,itr.Value(),aExternals , aFilter, ds);
134 if(!aExternals.Extent())
135 return Standard_False;
137 return Standard_True;
140 //=======================================================================
142 static void PrintEntry(const TDF_Label& label, const Standard_Boolean allLevels)
144 TCollection_AsciiString entry;
145 TDF_Tool::Entry(label, entry);
146 cout << "\tShareable attribute on the label = "<< entry << endl;
147 TDF_ChildIterator it (label, allLevels);
148 for (; it.More(); it.Next())
150 TDF_Tool::Entry(it.Value(), entry);
151 cout << "\tChildLabelEntry = "<< entry << endl;
155 //=======================================================================
158 //=======================================================================
160 void TDF_CopyLabel::Perform()
162 myIsDone = Standard_False;
163 if(mySL.Data()->Root().IsDifferent(myTL.Data()->Root()) && //TDF_Data is not the same
164 !TDF_Tool::IsSelfContained(mySL, myFilter)) return; //source label isn't self-contained
167 cout << "THE SAME Data" <<endl;
171 //TDF_Data of the source and target labels are the same
172 Standard_Boolean extReferers =
173 ExternalReferences(mySL, myMapOfExt, myFilter);
175 myRT = new TDF_RelocationTable(Standard_True);
176 Handle(TDF_DataSet) ds = new TDF_DataSet();
177 TDF_ClosureMode mode(Standard_True); // descendant plus reference
179 myRT->SetRelocation(mySL, myTL);
180 TDF_ClosureTool::Closure(ds, myFilter, mode);
182 for (TDF_MapIteratorOfAttributeMap attMItr(myMapOfExt);attMItr.More(); attMItr.Next()) {
183 Handle(TDF_Attribute) att = attMItr.Key();
184 myRT->SetRelocation(att, att);
186 PrintEntry(att->Label(), Standard_True);
191 TDF_CopyTool::Copy(ds,myRT);
192 myIsDone = Standard_True;
196 //=======================================================================
197 //function : RelocationTable
199 //=======================================================================
201 const Handle(TDF_RelocationTable)& TDF_CopyLabel::RelocationTable() const
206 //=======================================================================
207 //function : UseFilter
209 //=======================================================================
211 void TDF_CopyLabel::UseFilter(const TDF_IDFilter& aFilter)