7fd59977 |
1 | // File: TNaming_TranslateTool.cxx |
2 | // Created: Thu Jun 24 16:49:08 1999 |
3 | // Author: Sergey ZARITCHNY |
4 | // <szy@philipox.nnov.matra-dtv.fr> |
5 | |
6 | |
7 | #include <TNaming_TranslateTool.ixx> |
8 | #include <BRep_Builder.hxx> |
9 | #include <TopoDS.hxx> |
10 | #include <BRep_TVertex.hxx> |
11 | #include <BRep_ListIteratorOfListOfPointRepresentation.hxx> |
12 | #include <BRep_ListOfPointRepresentation.hxx> |
13 | #include <BRep_PointRepresentation.hxx> |
14 | #include <BRep_PointOnCurve.hxx> |
15 | #include <BRep_PointOnCurveOnSurface.hxx> |
16 | #include <TNaming_CopyShape.hxx> |
17 | #include <BRep_TFace.hxx> |
18 | #include <BRep_TEdge.hxx> |
19 | #include <BRep_PointOnSurface.hxx> |
20 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
21 | #include <BRep_ListOfCurveRepresentation.hxx> |
22 | #include <BRep_CurveRepresentation.hxx> |
23 | #include <BRep_GCurve.hxx> |
24 | #include <BRep_Curve3D.hxx> |
25 | #include <BRep_CurveOnSurface.hxx> |
26 | #include <BRep_CurveOnClosedSurface.hxx> |
27 | #include <BRep_CurveOn2Surfaces.hxx> |
28 | #include <BRep_Polygon3D.hxx> |
29 | #include <BRep_PolygonOnClosedSurface.hxx> |
30 | #include <BRep_PolygonOnSurface.hxx> |
31 | #include <BRep_PolygonOnClosedTriangulation.hxx> |
32 | #include <BRep_PolygonOnTriangulation.hxx> |
33 | #include <Standard_NullObject.hxx> |
34 | |
35 | |
36 | //======================================================================= |
37 | //function : TNaming_TranslateTool |
38 | |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | //TNaming_TranslateTool::TNaming_TranslateTool |
43 | //(const MgtBRep_TriangleMode aTriMode) : |
44 | //myTriangleMode(aTriMode) |
45 | //{ |
46 | //} |
47 | |
48 | //======================================================================= |
49 | //function : Add |
50 | //purpose : Adds S2 in S1 |
51 | //======================================================================= |
52 | |
53 | void TNaming_TranslateTool::Add(TopoDS_Shape& S1, |
54 | const TopoDS_Shape& S2) const |
55 | { |
56 | BRep_Builder B; |
57 | B.Add(S1,S2); |
58 | } |
59 | |
60 | //======================================================================= |
61 | //function : MakeVertex |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | void TNaming_TranslateTool::MakeVertex(TopoDS_Shape& S) const |
66 | { |
67 | BRep_Builder B; |
68 | B.MakeVertex(TopoDS::Vertex(S)); |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : MakeEdge |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | void TNaming_TranslateTool::MakeEdge(TopoDS_Shape& S) const |
77 | { |
78 | BRep_Builder B; |
79 | B.MakeEdge(TopoDS::Edge(S)); |
80 | } |
81 | |
82 | //======================================================================= |
83 | //function : MakeWire |
84 | //purpose : |
85 | //======================================================================= |
86 | |
87 | void TNaming_TranslateTool::MakeWire(TopoDS_Shape& S) const |
88 | { |
89 | BRep_Builder B; |
90 | B.MakeWire(TopoDS::Wire(S)); |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : MakeFace |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | void TNaming_TranslateTool::MakeFace(TopoDS_Shape& S) const |
99 | { |
100 | BRep_Builder B; |
101 | B.MakeFace(TopoDS::Face(S)); |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : MakeShell |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | void TNaming_TranslateTool::MakeShell(TopoDS_Shape& S) const |
110 | { |
111 | BRep_Builder B; |
112 | B.MakeShell(TopoDS::Shell(S)); |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : MakeSolid |
117 | //purpose : |
118 | //======================================================================= |
119 | |
120 | void TNaming_TranslateTool::MakeSolid(TopoDS_Shape& S) const |
121 | { |
122 | BRep_Builder B; |
123 | B.MakeSolid(TopoDS::Solid(S)); |
124 | } |
125 | |
126 | //======================================================================= |
127 | //function : MakeCompSolid |
128 | //purpose : |
129 | //======================================================================= |
130 | |
131 | void TNaming_TranslateTool::MakeCompSolid(TopoDS_Shape& S) const |
132 | { |
133 | BRep_Builder B; |
134 | B.MakeCompSolid(TopoDS::CompSolid(S)); |
135 | } |
136 | |
137 | //======================================================================= |
138 | //function : MakeCompound |
139 | //purpose : |
140 | //======================================================================= |
141 | |
142 | void TNaming_TranslateTool::MakeCompound(TopoDS_Shape& S) const |
143 | { |
144 | BRep_Builder B; |
145 | B.MakeCompound(TopoDS::Compound(S)); |
146 | } |
147 | |
148 | //======================================================================= |
149 | // Update methods |
150 | //======================================================================= |
151 | //function : UpdateVertex |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | void TNaming_TranslateTool::UpdateVertex |
156 | (const TopoDS_Shape& S1, |
157 | TopoDS_Shape& S2, |
158 | TColStd_IndexedDataMapOfTransientTransient& aMap) const |
159 | { |
160 | const Handle(BRep_TVertex)& TTV1 = *((Handle(BRep_TVertex)*) &(S1.TShape())); |
161 | const Handle(BRep_TVertex)& TTV2 = *((Handle(BRep_TVertex)*) &(S2.TShape())); |
162 | |
163 | // Point |
164 | TTV2->Pnt(TTV1->Pnt()); |
165 | |
166 | // Tolerance |
167 | TTV2->Tolerance(TTV1->Tolerance()); |
168 | |
169 | // Representations |
170 | BRep_ListIteratorOfListOfPointRepresentation itpr(TTV1->Points()); |
171 | // cout << "Vertex List Extent = "<< TTV1->Points().Extent()<< endl;// == 0 ??? |
172 | BRep_ListOfPointRepresentation& lpr = TTV2->ChangePoints(); |
173 | lpr.Clear(); |
174 | |
175 | while (itpr.More()) { |
176 | |
177 | const Handle(BRep_PointRepresentation)& PR1 = itpr.Value(); |
178 | Handle(BRep_PointRepresentation) PR2; |
179 | |
180 | if (PR1->IsPointOnCurve()) { // pointOnCurve (1) |
181 | Handle(BRep_PointOnCurve) OC = |
182 | new BRep_PointOnCurve(PR1->Parameter(), // the same geometry |
183 | PR1->Curve(), // the same geometry |
184 | TNaming_CopyShape::Translate(PR1->Location(), aMap)); |
185 | PR2 = OC; |
186 | } |
187 | |
188 | else if (PR1->IsPointOnCurveOnSurface()) { // PointOnCurveOnSurface (2) |
189 | |
190 | Handle(BRep_PointOnCurveOnSurface) OCS = |
191 | new BRep_PointOnCurveOnSurface(PR1->Parameter(), |
192 | PR1->PCurve(), |
193 | PR1->Surface(), |
194 | TNaming_CopyShape::Translate(PR1->Location(), aMap)); |
195 | PR2 = OCS; |
196 | } |
197 | |
198 | else if (PR1->IsPointOnSurface()) { // PointOnSurface (3) |
199 | |
200 | Handle(BRep_PointOnSurface) OS = |
201 | new BRep_PointOnSurface(PR1->Parameter(), |
202 | PR1->Parameter2(), |
203 | PR1->Surface(), |
204 | TNaming_CopyShape::Translate(PR1->Location(), aMap)); |
205 | PR2 = OS; |
206 | } |
207 | |
208 | // lpr.Prepend(PR2); |
209 | lpr.Append(PR2); |
210 | itpr.Next(); |
211 | } |
212 | |
213 | UpdateShape(S1,S2); |
214 | |
215 | } |
216 | |
217 | //======================================================================= |
218 | //function : UpdateEdge |
219 | //purpose : Transient->Transient |
220 | //======================================================================= |
221 | |
222 | void TNaming_TranslateTool::UpdateEdge |
223 | (const TopoDS_Shape& S1, |
224 | TopoDS_Shape& S2, |
225 | TColStd_IndexedDataMapOfTransientTransient& aMap) const |
226 | { |
227 | const Handle(BRep_TEdge)& TTE1 = *((Handle(BRep_TEdge)*) &(S1.TShape())); |
228 | const Handle(BRep_TEdge)& TTE2 = *((Handle(BRep_TEdge)*) &(S2.TShape())); |
229 | // tolerance TopLoc_Location |
230 | TTE2->Tolerance(TTE1->Tolerance()); |
231 | |
232 | // same parameter |
233 | TTE2->SameParameter(TTE1->SameParameter()); |
234 | |
235 | // same range |
236 | TTE2->SameRange(TTE1->SameRange()); |
237 | |
238 | // Degenerated |
239 | TTE2->Degenerated(TTE1->Degenerated()); |
240 | |
241 | // Representations |
242 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE1->Curves()); |
243 | BRep_ListOfCurveRepresentation& lcr = TTE2->ChangeCurves(); |
244 | lcr.Clear(); |
245 | Handle(BRep_CurveRepresentation) CR; |
246 | |
247 | Handle(BRep_GCurve) GC; |
248 | Standard_Real f, l; |
249 | while (itcr.More()) { |
250 | |
251 | const Handle(BRep_CurveRepresentation)& CR = itcr.Value(); |
252 | Handle(BRep_CurveRepresentation) CR2; |
253 | |
254 | GC = Handle(BRep_GCurve)::DownCast(CR); |
255 | if (!GC.IsNull()) { // (1) |
256 | GC->Range(f, l); |
257 | // CurveRepresentation is Curve3D - (1a) |
258 | if (CR->IsCurve3D()) { |
259 | |
260 | CR2 = (Handle(BRep_Curve3D)::DownCast(GC))->Copy(); |
261 | |
262 | } |
263 | |
264 | // CurveRepresentation is CurveOnSurface - (1b) |
265 | else if (CR->IsCurveOnSurface()) { |
266 | |
267 | if (!CR->IsCurveOnClosedSurface()) { // -(1b1) -if not closed surface |
268 | |
269 | // CurveRepresentation is a PBRep_CurveOnSurface |
270 | CR2 = (Handle(BRep_CurveOnSurface)::DownCast(GC))->Copy(); |
271 | } |
272 | |
273 | else { |
274 | // CurveRepresentation is CurveOnClosedSurface -(1b2) |
275 | CR2 = (Handle(BRep_CurveOnClosedSurface)::DownCast(GC))->Copy(); |
276 | } |
277 | } |
278 | |
279 | (Handle(BRep_GCurve)::DownCast(CR2))->SetRange(f, l); |
280 | } |
281 | |
282 | // CurveRepresentation is CurveOn2Surfaces (2:) |
283 | else if (CR->IsRegularity()) { |
284 | |
285 | CR2 = (Handle(BRep_CurveOn2Surfaces)::DownCast(CR))->Copy(); |
286 | TopLoc_Location L2 = TNaming_CopyShape::Translate(CR->Location2(), aMap); |
287 | CR2->Location(L2); |
288 | } |
289 | |
290 | // CurveRepresentation is Polygon or Triangulation (3:) |
291 | // else if (myTriangleMode == MgtBRep_WithTriangle) { |
292 | |
293 | // CurveRepresentation is Polygon3D (3a) |
294 | else if (CR->IsPolygon3D()) { |
295 | |
296 | CR2 = (Handle(BRep_Polygon3D)::DownCast(CR))->Copy(); |
297 | } |
298 | |
299 | // CurveRepresentation is PolygonOnSurface - (3b) |
300 | else if (CR->IsPolygonOnSurface()) { |
301 | |
302 | // CurveRepresentation is PolygonOnClosedSurface - (3b1) |
303 | if (CR->IsPolygonOnClosedSurface()) { |
304 | |
305 | CR2 = (Handle(BRep_PolygonOnClosedSurface)::DownCast(CR))->Copy(); |
306 | } |
307 | |
308 | // CurveRepresentation is PolygonOnSurface - (3b2) |
309 | else { |
310 | |
311 | CR2 = (Handle(BRep_PolygonOnSurface)::DownCast(CR))->Copy(); |
312 | |
313 | } |
314 | } |
315 | |
316 | // CurveRepresentation is PolygonOnTriangulation - (3c) |
317 | else if (CR->IsPolygonOnTriangulation()) { |
318 | |
319 | // CurveRepresentation is PolygonOnClosedTriangulation |
320 | if (CR->IsPolygonOnClosedTriangulation()) { // (3c1) |
321 | |
322 | CR2 = (Handle(BRep_PolygonOnClosedTriangulation)::DownCast(CR))->Copy(); |
323 | } |
324 | |
325 | // CurveRepresentation is PolygonOnTriangulation - (3c2) |
326 | else { |
327 | |
328 | CR2 = (Handle(BRep_PolygonOnTriangulation)::DownCast(CR))->Copy(); |
329 | } |
330 | } |
331 | // } |
332 | else { |
333 | // jumps the curve representation |
334 | itcr.Next(); |
335 | continue; |
336 | } |
337 | |
338 | TopLoc_Location L = TNaming_CopyShape::Translate(CR->Location(), aMap); |
339 | CR2->Location(L); |
340 | |
341 | Standard_NullObject_Raise_if (CR2.IsNull(), "Null CurveRepresentation"); |
342 | |
343 | // lcr.Prepend(CR2); // add |
344 | lcr.Append(CR2); |
345 | itcr.Next(); |
346 | } |
347 | |
348 | UpdateShape(S1,S2); |
349 | } |
350 | |
351 | |
352 | //======================================================================= |
353 | //function : UpdateFace |
354 | //purpose : Transient->Transient |
355 | //======================================================================= |
356 | |
357 | void TNaming_TranslateTool::UpdateFace |
358 | (const TopoDS_Shape& S1, |
359 | TopoDS_Shape& S2, |
360 | TColStd_IndexedDataMapOfTransientTransient& aMap) const |
361 | { |
362 | const Handle(BRep_TFace)& TTF1 = *((Handle(BRep_TFace)*) &(S1.TShape())); |
363 | const Handle(BRep_TFace)& TTF2 = *((Handle(BRep_TFace)*) &(S2.TShape())); |
364 | |
365 | // natural restriction |
366 | TTF2->NaturalRestriction(TTF1->NaturalRestriction()); |
367 | |
368 | // tolerance |
369 | TTF2->Tolerance(TTF1->Tolerance()); |
370 | |
371 | // location |
372 | TTF2->Location(TNaming_CopyShape::Translate(TTF1->Location(), aMap)); |
373 | |
374 | // surface |
375 | TTF2->Surface(TTF1->Surface()); |
376 | |
377 | // Triangulation |
378 | // if (myTriangleMode == MgtBRep_WithTriangle) { |
379 | TTF2->Triangulation(TTF1->Triangulation()); |
380 | // } |
381 | |
382 | UpdateShape(S1,S2); |
383 | |
384 | } |
385 | |
386 | //======================================================================= |
387 | //function : UpdateShape |
388 | //purpose : |
389 | //======================================================================= |
390 | |
391 | void TNaming_TranslateTool::UpdateShape |
392 | (const TopoDS_Shape& S1, TopoDS_Shape& S2) const |
393 | { |
394 | // Transfer the flags |
395 | S2.TShape()->Free(S1.TShape()->Free()); |
396 | S2.TShape()->Modified(S1.TShape()->Modified()); |
397 | S2.TShape()->Checked(S1.TShape()->Checked()); |
398 | S2.TShape()->Orientable(S1.TShape()->Orientable()); |
399 | S2.TShape()->Closed(S1.TShape()->Closed()); |
400 | S2.TShape()->Infinite(S1.TShape()->Infinite()); |
401 | S2.TShape()->Convex(S1.TShape()->Convex()); |
402 | } |