7fd59977 |
1 | // File: TNaming_CopyShape.cxx |
2 | // Created: Mon Feb 14 16:50:36 2000 |
3 | // Author: Denis PASCAL |
4 | // <dp@dingox.paris1.matra-dtv.fr> |
5 | |
6 | |
7 | #include <TNaming_CopyShape.ixx> |
8 | #include <TopAbs.hxx> |
9 | #include <TopoDS_Vertex.hxx> |
10 | #include <TopoDS_Edge.hxx> |
11 | #include <TopoDS_Face.hxx> |
12 | #include <TopoDS_Iterator.hxx> |
13 | #include <TopLoc_Datum3D.hxx> |
14 | |
15 | //======================================================================= |
16 | //function : CopyTool |
17 | //purpose : Tool to copy a set of shape(s), using the aMap |
18 | //======================================================================= |
19 | |
20 | void TNaming_CopyShape::CopyTool( const TopoDS_Shape& aShape, |
21 | TColStd_IndexedDataMapOfTransientTransient& aMap, |
22 | TopoDS_Shape& aResult) |
23 | { |
24 | |
25 | Handle(TNaming_TranslateTool) TrTool = new TNaming_TranslateTool(); |
26 | TNaming_CopyShape::Translate (aShape, aMap, aResult, TrTool) ; |
27 | } |
28 | |
29 | //======================================================================= |
30 | //function : Translate |
31 | //purpose : TNaming |
32 | //======================================================================= |
33 | |
34 | void TNaming_CopyShape::Translate( const TopoDS_Shape& aShape, |
35 | TColStd_IndexedDataMapOfTransientTransient& aMap, |
36 | TopoDS_Shape& aResult, |
37 | const Handle(TNaming_TranslateTool)& TrTool) |
38 | { |
39 | |
40 | if (aShape.IsNull()) return; |
41 | |
42 | if (aMap.Contains(aShape.TShape())) { |
43 | // get the translated TShape |
44 | Handle(TopoDS_TShape) TS = |
45 | *((Handle(TopoDS_TShape)*) &aMap.FindFromKey(aShape.TShape())); |
46 | aResult.TShape(TS); |
47 | } |
48 | else { |
49 | |
50 | // create if not translated and update |
51 | |
52 | switch (aShape.ShapeType()) { |
53 | |
54 | case TopAbs_VERTEX : |
55 | TrTool->MakeVertex(aResult); |
56 | TrTool->UpdateVertex(aShape,aResult,aMap); |
57 | break; |
58 | |
59 | case TopAbs_EDGE : |
60 | TrTool->MakeEdge(aResult); |
61 | TrTool->UpdateEdge(aShape,aResult,aMap); |
62 | break; |
63 | |
64 | case TopAbs_WIRE : |
65 | TrTool->MakeWire(aResult); |
66 | TrTool->UpdateShape(aShape,aResult); |
67 | break; |
68 | |
69 | case TopAbs_FACE : |
70 | TrTool->MakeFace(aResult); |
71 | TrTool->UpdateFace(aShape,aResult,aMap); |
72 | break; |
73 | |
74 | case TopAbs_SHELL : |
75 | TrTool->MakeShell(aResult); |
76 | TrTool->UpdateShape(aShape,aResult); |
77 | break; |
78 | |
79 | case TopAbs_SOLID : |
80 | TrTool->MakeSolid(aResult); |
81 | TrTool->UpdateShape(aShape,aResult); |
82 | break; |
83 | |
84 | case TopAbs_COMPSOLID : |
85 | TrTool->MakeCompSolid(aResult); |
86 | TrTool->UpdateShape(aShape,aResult); |
87 | break; |
88 | |
89 | case TopAbs_COMPOUND : |
90 | TrTool->MakeCompound(aResult); |
91 | TrTool->UpdateShape(aShape,aResult); |
92 | break; |
93 | |
94 | default: |
95 | break; |
96 | } |
97 | |
98 | // bind and copy the sub-elements |
99 | aMap.Add(aShape.TShape(),aResult.TShape()); //TShapes |
100 | TopoDS_Shape S = aShape; |
101 | S.Orientation(TopAbs_FORWARD); |
102 | S.Location(TopLoc_Location()); //Identity |
103 | // copy current Shape |
104 | TopoDS_Iterator itr(S, Standard_False); |
105 | Standard_Boolean wasFree = aResult.Free(); |
106 | aResult.Free(Standard_True); |
107 | // translate <sub-shapes> |
108 | for (;itr.More();itr.Next()) { |
109 | TopoDS_Shape subShape; |
110 | TNaming_CopyShape::Translate(itr.Value(), aMap, subShape, TrTool); |
111 | TrTool->Add(aResult, subShape);// add subshapes |
112 | } |
113 | |
114 | aResult.Free(wasFree); |
115 | } |
116 | |
117 | aResult.Orientation(aShape.Orientation()); |
118 | aResult.Location(TNaming_CopyShape::Translate(aShape.Location(), aMap)); |
119 | TrTool->UpdateShape(aShape,aResult); |
120 | // #ifdef DEB |
121 | // if(fShar) { |
122 | // cout << "=== Shareable shape ===" << endl; |
123 | // cout << "aShape Type = " <<(aShape.TShape())->DynamicType() << endl; |
124 | // if(aShape.Orientation() == aResult.Orientation()) |
125 | // cout<<"\tSource and result shapes have the same Orientation"<< endl; |
126 | // if((aShape.Location().IsEqual(aResult.Location()))) |
127 | // cout <<"\tSource and result shapes have the same Locations" << endl; |
128 | // if((aShape.IsSame(aResult))) |
129 | // cout <<"\tShapes arew the same (i.e. the same TShape and the same Locations)" << endl; |
130 | // } |
131 | // #endif |
132 | } |
133 | |
134 | //======================================================================= |
135 | // static TranslateDatum3D |
136 | //======================================================================= |
137 | static Handle(TopLoc_Datum3D) TranslateDatum3D(const Handle(TopLoc_Datum3D)& D, |
138 | TColStd_IndexedDataMapOfTransientTransient& aMap) |
139 | { |
140 | Handle(TopLoc_Datum3D) TD; |
141 | if(aMap.Contains(D)) |
142 | TD = Handle(TopLoc_Datum3D)::DownCast(aMap.FindFromKey(D)); |
143 | else { |
144 | TD = new TopLoc_Datum3D(D->Transformation()); |
145 | aMap.Add(D, TD); |
146 | } |
147 | return TD; |
148 | } |
149 | //======================================================================= |
150 | //function : Translates |
151 | //purpose : Topological Location |
152 | //======================================================================= |
153 | |
154 | TopLoc_Location TNaming_CopyShape::Translate(const TopLoc_Location& L, |
155 | TColStd_IndexedDataMapOfTransientTransient& aMap) |
156 | { |
157 | TopLoc_Location result; |
158 | |
159 | if (!L.IsIdentity()) { |
160 | result = Translate(L.NextLocation(),aMap) * |
161 | TopLoc_Location(TranslateDatum3D(L.FirstDatum(),aMap)).Powered(L.FirstPower()); |
162 | |
163 | } |
164 | return result; |
165 | } |
166 | |
167 | |