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