0024263: TNaming_CopyShape::CopyTool failure
[occt.git] / src / TNaming / TNaming_CopyShape.cxx
CommitLineData
b311480e 1// Created on: 2000-02-14
2// Created by: Denis PASCAL
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <TNaming_CopyShape.ixx>
23#include <TopAbs.hxx>
24#include <TopoDS_Vertex.hxx>
25#include <TopoDS_Edge.hxx>
26#include <TopoDS_Face.hxx>
27#include <TopoDS_Iterator.hxx>
28#include <TopLoc_Datum3D.hxx>
29
30//=======================================================================
31//function : CopyTool
32//purpose : Tool to copy a set of shape(s), using the aMap
33//=======================================================================
34
35void TNaming_CopyShape::CopyTool( const TopoDS_Shape& aShape,
36 TColStd_IndexedDataMapOfTransientTransient& aMap,
37 TopoDS_Shape& aResult)
38{
39
40 Handle(TNaming_TranslateTool) TrTool = new TNaming_TranslateTool();
41 TNaming_CopyShape::Translate (aShape, aMap, aResult, TrTool) ;
42}
43
44//=======================================================================
45//function : Translate
46//purpose : TNaming
47//=======================================================================
48
49void TNaming_CopyShape::Translate( const TopoDS_Shape& aShape,
50 TColStd_IndexedDataMapOfTransientTransient& aMap,
51 TopoDS_Shape& aResult,
52 const Handle(TNaming_TranslateTool)& TrTool)
53{
659b232a 54 aResult.Nullify();
7fd59977 55
56 if (aShape.IsNull()) return;
57
58 if (aMap.Contains(aShape.TShape())) {
59 // get the translated TShape
60 Handle(TopoDS_TShape) TS =
61 *((Handle(TopoDS_TShape)*) &aMap.FindFromKey(aShape.TShape()));
62 aResult.TShape(TS);
63 }
64 else {
65
66 // create if not translated and update
67
68 switch (aShape.ShapeType()) {
69
70 case TopAbs_VERTEX :
71 TrTool->MakeVertex(aResult);
72 TrTool->UpdateVertex(aShape,aResult,aMap);
73 break;
74
75 case TopAbs_EDGE :
76 TrTool->MakeEdge(aResult);
77 TrTool->UpdateEdge(aShape,aResult,aMap);
78 break;
79
80 case TopAbs_WIRE :
81 TrTool->MakeWire(aResult);
82 TrTool->UpdateShape(aShape,aResult);
83 break;
84
85 case TopAbs_FACE :
86 TrTool->MakeFace(aResult);
87 TrTool->UpdateFace(aShape,aResult,aMap);
88 break;
89
90 case TopAbs_SHELL :
91 TrTool->MakeShell(aResult);
92 TrTool->UpdateShape(aShape,aResult);
93 break;
94
95 case TopAbs_SOLID :
96 TrTool->MakeSolid(aResult);
97 TrTool->UpdateShape(aShape,aResult);
98 break;
99
100 case TopAbs_COMPSOLID :
101 TrTool->MakeCompSolid(aResult);
102 TrTool->UpdateShape(aShape,aResult);
103 break;
104
105 case TopAbs_COMPOUND :
106 TrTool->MakeCompound(aResult);
107 TrTool->UpdateShape(aShape,aResult);
108 break;
109
110 default:
111 break;
112 }
113
114 // bind and copy the sub-elements
115 aMap.Add(aShape.TShape(),aResult.TShape()); //TShapes
116 TopoDS_Shape S = aShape;
117 S.Orientation(TopAbs_FORWARD);
118 S.Location(TopLoc_Location()); //Identity
119 // copy current Shape
120 TopoDS_Iterator itr(S, Standard_False);
121 Standard_Boolean wasFree = aResult.Free();
122 aResult.Free(Standard_True);
123 // translate <sub-shapes>
124 for (;itr.More();itr.Next()) {
125 TopoDS_Shape subShape;
126 TNaming_CopyShape::Translate(itr.Value(), aMap, subShape, TrTool);
127 TrTool->Add(aResult, subShape);// add subshapes
128 }
129
130 aResult.Free(wasFree);
131 }
132
133 aResult.Orientation(aShape.Orientation());
134 aResult.Location(TNaming_CopyShape::Translate(aShape.Location(), aMap));
135 TrTool->UpdateShape(aShape,aResult);
136// #ifdef DEB
137// if(fShar) {
138// cout << "=== Shareable shape ===" << endl;
139// cout << "aShape Type = " <<(aShape.TShape())->DynamicType() << endl;
140// if(aShape.Orientation() == aResult.Orientation())
141// cout<<"\tSource and result shapes have the same Orientation"<< endl;
142// if((aShape.Location().IsEqual(aResult.Location())))
143// cout <<"\tSource and result shapes have the same Locations" << endl;
144// if((aShape.IsSame(aResult)))
145// cout <<"\tShapes arew the same (i.e. the same TShape and the same Locations)" << endl;
146// }
147// #endif
148}
149
150//=======================================================================
151// static TranslateDatum3D
152//=======================================================================
153static Handle(TopLoc_Datum3D) TranslateDatum3D(const Handle(TopLoc_Datum3D)& D,
154 TColStd_IndexedDataMapOfTransientTransient& aMap)
155{
156 Handle(TopLoc_Datum3D) TD;
157 if(aMap.Contains(D))
158 TD = Handle(TopLoc_Datum3D)::DownCast(aMap.FindFromKey(D));
159 else {
160 TD = new TopLoc_Datum3D(D->Transformation());
161 aMap.Add(D, TD);
162 }
163 return TD;
164}
165//=======================================================================
166//function : Translates
167//purpose : Topological Location
168//=======================================================================
169
170TopLoc_Location TNaming_CopyShape::Translate(const TopLoc_Location& L,
171 TColStd_IndexedDataMapOfTransientTransient& aMap)
172{
173 TopLoc_Location result;
174
175 if (!L.IsIdentity()) {
176 result = Translate(L.NextLocation(),aMap) *
177 TopLoc_Location(TranslateDatum3D(L.FirstDatum(),aMap)).Powered(L.FirstPower());
178
179 }
180 return result;
181}
182
183