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