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