1 // Created on: 2000-02-14
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <TNaming_CopyShape.ixx>
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>
24 //=======================================================================
26 //purpose : Tool to copy a set of shape(s), using the aMap
27 //=======================================================================
29 void TNaming_CopyShape::CopyTool( const TopoDS_Shape& aShape,
30 TColStd_IndexedDataMapOfTransientTransient& aMap,
31 TopoDS_Shape& aResult)
34 Handle(TNaming_TranslateTool) TrTool = new TNaming_TranslateTool();
35 TNaming_CopyShape::Translate (aShape, aMap, aResult, TrTool) ;
38 //=======================================================================
39 //function : Translate
41 //=======================================================================
43 void TNaming_CopyShape::Translate( const TopoDS_Shape& aShape,
44 TColStd_IndexedDataMapOfTransientTransient& aMap,
45 TopoDS_Shape& aResult,
46 const Handle(TNaming_TranslateTool)& TrTool)
50 if (aShape.IsNull()) return;
52 if (aMap.Contains(aShape.TShape())) {
53 // get the translated TShape
54 Handle(TopoDS_TShape) TS =
55 *((Handle(TopoDS_TShape)*) &aMap.FindFromKey(aShape.TShape()));
60 // create if not translated and update
62 switch (aShape.ShapeType()) {
65 TrTool->MakeVertex(aResult);
66 TrTool->UpdateVertex(aShape,aResult,aMap);
70 TrTool->MakeEdge(aResult);
71 TrTool->UpdateEdge(aShape,aResult,aMap);
75 TrTool->MakeWire(aResult);
76 TrTool->UpdateShape(aShape,aResult);
80 TrTool->MakeFace(aResult);
81 TrTool->UpdateFace(aShape,aResult,aMap);
85 TrTool->MakeShell(aResult);
86 TrTool->UpdateShape(aShape,aResult);
90 TrTool->MakeSolid(aResult);
91 TrTool->UpdateShape(aShape,aResult);
94 case TopAbs_COMPSOLID :
95 TrTool->MakeCompSolid(aResult);
96 TrTool->UpdateShape(aShape,aResult);
99 case TopAbs_COMPOUND :
100 TrTool->MakeCompound(aResult);
101 TrTool->UpdateShape(aShape,aResult);
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
124 aResult.Free(wasFree);
127 aResult.Orientation(aShape.Orientation());
128 aResult.Location(TNaming_CopyShape::Translate(aShape.Location(), aMap));
129 TrTool->UpdateShape(aShape,aResult);
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;
144 //=======================================================================
145 // static TranslateDatum3D
146 //=======================================================================
147 static Handle(TopLoc_Datum3D) TranslateDatum3D(const Handle(TopLoc_Datum3D)& D,
148 TColStd_IndexedDataMapOfTransientTransient& aMap)
150 Handle(TopLoc_Datum3D) TD;
152 TD = Handle(TopLoc_Datum3D)::DownCast(aMap.FindFromKey(D));
154 TD = new TopLoc_Datum3D(D->Transformation());
159 //=======================================================================
160 //function : Translates
161 //purpose : Topological Location
162 //=======================================================================
164 TopLoc_Location TNaming_CopyShape::Translate(const TopLoc_Location& L,
165 TColStd_IndexedDataMapOfTransientTransient& aMap)
167 TopLoc_Location result;
169 if (!L.IsIdentity()) {
170 result = Translate(L.NextLocation(),aMap) *
171 TopLoc_Location(TranslateDatum3D(L.FirstDatum(),aMap)).Powered(L.FirstPower());