0024624: Lost word in license statement in source files
[occt.git] / src / TNaming / TNaming_CopyShape.cxx
CommitLineData
b311480e 1// Created on: 2000-02-14
2// Created by: Denis PASCAL
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <TNaming_CopyShape.ixx>
17#include <TopAbs.hxx>
18#include <TopoDS_Vertex.hxx>
19#include <TopoDS_Edge.hxx>
20#include <TopoDS_Face.hxx>
21#include <TopoDS_Iterator.hxx>
22#include <TopLoc_Datum3D.hxx>
23
24//=======================================================================
25//function : CopyTool
26//purpose : Tool to copy a set of shape(s), using the aMap
27//=======================================================================
28
29void TNaming_CopyShape::CopyTool( const TopoDS_Shape& aShape,
30 TColStd_IndexedDataMapOfTransientTransient& aMap,
31 TopoDS_Shape& aResult)
32{
33
34 Handle(TNaming_TranslateTool) TrTool = new TNaming_TranslateTool();
35 TNaming_CopyShape::Translate (aShape, aMap, aResult, TrTool) ;
36}
37
38//=======================================================================
39//function : Translate
40//purpose : TNaming
41//=======================================================================
42
43void TNaming_CopyShape::Translate( const TopoDS_Shape& aShape,
44 TColStd_IndexedDataMapOfTransientTransient& aMap,
45 TopoDS_Shape& aResult,
46 const Handle(TNaming_TranslateTool)& TrTool)
47{
659b232a 48 aResult.Nullify();
7fd59977 49
50 if (aShape.IsNull()) return;
51
52 if (aMap.Contains(aShape.TShape())) {
53 // get the translated TShape
54 Handle(TopoDS_TShape) TS =
55 *((Handle(TopoDS_TShape)*) &aMap.FindFromKey(aShape.TShape()));
56 aResult.TShape(TS);
57 }
58 else {
59
60 // create if not translated and update
61
62 switch (aShape.ShapeType()) {
63
64 case TopAbs_VERTEX :
65 TrTool->MakeVertex(aResult);
66 TrTool->UpdateVertex(aShape,aResult,aMap);
67 break;
68
69 case TopAbs_EDGE :
70 TrTool->MakeEdge(aResult);
71 TrTool->UpdateEdge(aShape,aResult,aMap);
72 break;
73
74 case TopAbs_WIRE :
75 TrTool->MakeWire(aResult);
76 TrTool->UpdateShape(aShape,aResult);
77 break;
78
79 case TopAbs_FACE :
80 TrTool->MakeFace(aResult);
81 TrTool->UpdateFace(aShape,aResult,aMap);
82 break;
83
84 case TopAbs_SHELL :
85 TrTool->MakeShell(aResult);
86 TrTool->UpdateShape(aShape,aResult);
87 break;
88
89 case TopAbs_SOLID :
90 TrTool->MakeSolid(aResult);
91 TrTool->UpdateShape(aShape,aResult);
92 break;
93
94 case TopAbs_COMPSOLID :
95 TrTool->MakeCompSolid(aResult);
96 TrTool->UpdateShape(aShape,aResult);
97 break;
98
99 case TopAbs_COMPOUND :
100 TrTool->MakeCompound(aResult);
101 TrTool->UpdateShape(aShape,aResult);
102 break;
103
104 default:
105 break;
106 }
107
108 // bind and copy the sub-elements
109 aMap.Add(aShape.TShape(),aResult.TShape()); //TShapes
110 TopoDS_Shape S = aShape;
111 S.Orientation(TopAbs_FORWARD);
112 S.Location(TopLoc_Location()); //Identity
113 // copy current Shape
114 TopoDS_Iterator itr(S, Standard_False);
115 Standard_Boolean wasFree = aResult.Free();
116 aResult.Free(Standard_True);
117 // translate <sub-shapes>
118 for (;itr.More();itr.Next()) {
119 TopoDS_Shape subShape;
120 TNaming_CopyShape::Translate(itr.Value(), aMap, subShape, TrTool);
121 TrTool->Add(aResult, subShape);// add subshapes
122 }
123
124 aResult.Free(wasFree);
125 }
126
127 aResult.Orientation(aShape.Orientation());
128 aResult.Location(TNaming_CopyShape::Translate(aShape.Location(), aMap));
129 TrTool->UpdateShape(aShape,aResult);
130// #ifdef DEB
131// if(fShar) {
132// cout << "=== Shareable shape ===" << endl;
133// cout << "aShape Type = " <<(aShape.TShape())->DynamicType() << endl;
134// if(aShape.Orientation() == aResult.Orientation())
135// cout<<"\tSource and result shapes have the same Orientation"<< endl;
136// if((aShape.Location().IsEqual(aResult.Location())))
137// cout <<"\tSource and result shapes have the same Locations" << endl;
138// if((aShape.IsSame(aResult)))
139// cout <<"\tShapes arew the same (i.e. the same TShape and the same Locations)" << endl;
140// }
141// #endif
142}
143
144//=======================================================================
145// static TranslateDatum3D
146//=======================================================================
147static Handle(TopLoc_Datum3D) TranslateDatum3D(const Handle(TopLoc_Datum3D)& D,
148 TColStd_IndexedDataMapOfTransientTransient& aMap)
149{
150 Handle(TopLoc_Datum3D) TD;
151 if(aMap.Contains(D))
152 TD = Handle(TopLoc_Datum3D)::DownCast(aMap.FindFromKey(D));
153 else {
154 TD = new TopLoc_Datum3D(D->Transformation());
155 aMap.Add(D, TD);
156 }
157 return TD;
158}
159//=======================================================================
160//function : Translates
161//purpose : Topological Location
162//=======================================================================
163
164TopLoc_Location TNaming_CopyShape::Translate(const TopLoc_Location& L,
165 TColStd_IndexedDataMapOfTransientTransient& aMap)
166{
167 TopLoc_Location result;
168
169 if (!L.IsIdentity()) {
170 result = Translate(L.NextLocation(),aMap) *
171 TopLoc_Location(TranslateDatum3D(L.FirstDatum(),aMap)).Powered(L.FirstPower());
172
173 }
174 return result;
175}
176
177