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.
17 #include <TNaming_CopyShape.hxx>
18 #include <TNaming_TranslateTool.hxx>
20 #include <TopLoc_Datum3D.hxx>
21 #include <TopLoc_Location.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Face.hxx>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
28 //=======================================================================
30 //purpose : Tool to copy a set of shape(s), using the aMap
31 //=======================================================================
32 void TNaming_CopyShape::CopyTool( const TopoDS_Shape& aShape,
33 TColStd_IndexedDataMapOfTransientTransient& aMap,
34 TopoDS_Shape& aResult)
37 Handle(TNaming_TranslateTool) TrTool = new TNaming_TranslateTool();
38 TNaming_CopyShape::Translate (aShape, aMap, aResult, TrTool) ;
41 //=======================================================================
42 //function : Translate
44 //=======================================================================
46 void TNaming_CopyShape::Translate( const TopoDS_Shape& aShape,
47 TColStd_IndexedDataMapOfTransientTransient& aMap,
48 TopoDS_Shape& aResult,
49 const Handle(TNaming_TranslateTool)& TrTool)
53 if (aShape.IsNull()) return;
55 if (aMap.Contains(aShape.TShape())) {
56 // get the translated TShape
57 Handle(TopoDS_TShape) TS =
58 *((Handle(TopoDS_TShape)*) &aMap.FindFromKey(aShape.TShape()));
63 // create if not translated and update
65 switch (aShape.ShapeType()) {
68 TrTool->MakeVertex(aResult);
69 TrTool->UpdateVertex(aShape,aResult,aMap);
73 TrTool->MakeEdge(aResult);
74 TrTool->UpdateEdge(aShape,aResult,aMap);
78 TrTool->MakeWire(aResult);
79 TrTool->UpdateShape(aShape,aResult);
83 TrTool->MakeFace(aResult);
84 TrTool->UpdateFace(aShape,aResult,aMap);
88 TrTool->MakeShell(aResult);
89 TrTool->UpdateShape(aShape,aResult);
93 TrTool->MakeSolid(aResult);
94 TrTool->UpdateShape(aShape,aResult);
97 case TopAbs_COMPSOLID :
98 TrTool->MakeCompSolid(aResult);
99 TrTool->UpdateShape(aShape,aResult);
102 case TopAbs_COMPOUND :
103 TrTool->MakeCompound(aResult);
104 TrTool->UpdateShape(aShape,aResult);
111 // bind and copy the sub-elements
112 aMap.Add(aShape.TShape(),aResult.TShape()); //TShapes
113 TopoDS_Shape S = aShape;
114 S.Orientation(TopAbs_FORWARD);
115 S.Location(TopLoc_Location()); //Identity
116 // copy current Shape
117 TopoDS_Iterator itr(S, Standard_False);
118 Standard_Boolean wasFree = aResult.Free();
119 aResult.Free(Standard_True);
120 // translate <sub-shapes>
121 for (;itr.More();itr.Next()) {
122 TopoDS_Shape subShape;
123 TNaming_CopyShape::Translate(itr.Value(), aMap, subShape, TrTool);
124 TrTool->Add(aResult, subShape);// add subshapes
127 aResult.Free(wasFree);
130 aResult.Orientation(aShape.Orientation());
131 aResult.Location(TNaming_CopyShape::Translate(aShape.Location(), aMap));
132 TrTool->UpdateShape(aShape,aResult);
135 // std::cout << "=== Shareable shape ===" << std::endl;
136 // std::cout << "aShape Type = " <<(aShape.TShape())->DynamicType() << std::endl;
137 // if(aShape.Orientation() == aResult.Orientation())
138 // std::cout<<"\tSource and result shapes have the same Orientation"<< std::endl;
139 // if((aShape.Location().IsEqual(aResult.Location())))
140 // std::cout <<"\tSource and result shapes have the same Locations" << std::endl;
141 // if((aShape.IsSame(aResult)))
142 // std::cout <<"\tShapes arew the same (i.e. the same TShape and the same Locations)" << std::endl;
147 //=======================================================================
148 // static TranslateDatum3D
149 //=======================================================================
150 static Handle(TopLoc_Datum3D) TranslateDatum3D(const Handle(TopLoc_Datum3D)& D,
151 TColStd_IndexedDataMapOfTransientTransient& aMap)
153 Handle(TopLoc_Datum3D) TD;
155 TD = Handle(TopLoc_Datum3D)::DownCast(aMap.FindFromKey(D));
157 TD = new TopLoc_Datum3D(D->Transformation());
162 //=======================================================================
163 //function : Translates
164 //purpose : Topological Location
165 //=======================================================================
167 TopLoc_Location TNaming_CopyShape::Translate(const TopLoc_Location& L,
168 TColStd_IndexedDataMapOfTransientTransient& aMap)
170 TopLoc_Location result;
172 if (!L.IsIdentity()) {
173 result = Translate(L.NextLocation(),aMap) *
174 TopLoc_Location(TranslateDatum3D(L.FirstDatum(),aMap)).Powered(L.FirstPower());