Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-10-19 |
2 | // Created by: Bruno DUMORTIER | |
3 | // Copyright (c) 1995-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 | |
17 | #include <BRepOffset_Offset.ixx> | |
18 | ||
19 | #include <Adaptor3d_HCurveOnSurface.hxx> | |
20 | #include <Adaptor3d_CurveOnSurface.hxx> | |
21 | #include <BRepOffset.hxx> | |
22 | #include <BRepLib.hxx> | |
23 | #include <BRepLib_MakeFace.hxx> | |
24 | #include <BRepTools.hxx> | |
25 | #include <BRep_Tool.hxx> | |
26 | #include <BRep_Builder.hxx> | |
27 | #include <ElSLib.hxx> | |
28 | #include <GeomAPI.hxx> | |
29 | #include <Geom2d_Curve.hxx> | |
30 | #include <Geom2d_Line.hxx> | |
31 | #include <Geom2d_TrimmedCurve.hxx> | |
32 | #include <Geom_Line.hxx> | |
33 | #include <Geom_Circle.hxx> | |
34 | #include <Geom_Curve.hxx> | |
35 | #include <Geom_TrimmedCurve.hxx> | |
36 | #include <Geom_RectangularTrimmedSurface.hxx> | |
37 | #include <Geom_Surface.hxx> | |
38 | #include <Geom_OffsetSurface.hxx> | |
39 | #include <Geom_SphericalSurface.hxx> | |
40 | #include <Geom_ConicalSurface.hxx> | |
41 | #include <GeomAdaptor_HSurface.hxx> | |
42 | #include <GeomAdaptor_Surface.hxx> | |
43 | #include <GeomAdaptor_HCurve.hxx> | |
44 | #include <GeomAdaptor_Curve.hxx> | |
45 | #include <Geom2dAdaptor_HCurve.hxx> | |
46 | #include <Geom2dAdaptor_Curve.hxx> | |
47 | #include <GeomFill_Pipe.hxx> | |
48 | #include <GeomProjLib.hxx> | |
49 | #include <GeomConvert_ApproxSurface.hxx> | |
50 | #include <Precision.hxx> | |
51 | #include <Standard_ConstructionError.hxx> | |
52 | #include <TopoDS.hxx> | |
53 | #include <TopoDS_Wire.hxx> | |
54 | #include <TopExp.hxx> | |
55 | #include <TopExp_Explorer.hxx> | |
56 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
57 | #include <gp.hxx> | |
58 | #include <gp_Ax3.hxx> | |
59 | #include <gp_Cylinder.hxx> | |
60 | #include <gp_Torus.hxx> | |
61 | #include <gp_Lin.hxx> | |
62 | #include <gp_Pnt2d.hxx> | |
63 | ||
64 | #include <BRep_GCurve.hxx> | |
65 | #include <BRep_TEdge.hxx> | |
66 | #include <BRep_ListOfCurveRepresentation.hxx> | |
67 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> | |
68 | ||
69 | #include <TopTools_SequenceOfShape.hxx> | |
70 | #include <TopTools_MapOfShape.hxx> | |
71 | #include <BRepOffset_Tool.hxx> | |
72 | #include <GeomAPI_ExtremaCurveCurve.hxx> | |
73 | #include <GeomAPI_ProjectPointOnCurve.hxx> | |
74 | #include <GeomLib.hxx> | |
75 | ||
d804b26d | 76 | #include <TopTools_IndexedMapOfShape.hxx> |
77 | #include <BRepLib_MakeWire.hxx> | |
78 | #include <gce_MakePln.hxx> | |
79 | #include <ShapeFix_Shape.hxx> | |
80 | #include <GProp_GProps.hxx> | |
81 | #include <BRepGProp.hxx> | |
82 | ||
7fd59977 | 83 | #ifdef DEB |
84 | static Standard_Boolean Affich = Standard_False; | |
85 | static Standard_Integer NbOFFSET = 0; | |
86 | #endif | |
87 | #ifdef DRAW | |
88 | #include <DrawTrSurf.hxx> | |
89 | #include <DBRep.hxx> | |
90 | #endif | |
91 | #include <stdio.h> | |
92 | ||
d804b26d | 93 | |
94 | static gp_Pnt GetFarestCorner(const TopoDS_Wire& aWire) | |
95 | { | |
96 | TopTools_IndexedMapOfShape Vertices; | |
97 | TopExp::MapShapes(aWire, TopAbs_VERTEX, Vertices); | |
98 | ||
99 | Standard_Real MaxDist = 0.; | |
100 | gp_Pnt thePoint; | |
101 | for (Standard_Integer i = 1; i <= Vertices.Extent(); i++) | |
102 | for (Standard_Integer j = 1; j <= Vertices.Extent(); j++) | |
103 | { | |
104 | const TopoDS_Vertex& V1 = TopoDS::Vertex(Vertices(i)); | |
105 | const TopoDS_Vertex& V2 = TopoDS::Vertex(Vertices(j)); | |
106 | gp_Pnt P1 = BRep_Tool::Pnt(V1); | |
107 | gp_Pnt P2 = BRep_Tool::Pnt(V2); | |
108 | Standard_Real aDist = P1.SquareDistance(P2); | |
109 | if (aDist > MaxDist) | |
110 | { | |
111 | MaxDist = aDist; | |
112 | thePoint = P1; | |
113 | } | |
114 | } | |
115 | ||
116 | return thePoint; | |
117 | } | |
118 | ||
7fd59977 | 119 | //======================================================================= |
120 | //function : UpdateEdge | |
121 | //purpose : | |
122 | //======================================================================= | |
123 | ||
124 | static void UpdateEdge(const TopoDS_Edge& E, | |
125 | const Handle(Geom_Curve)& C, | |
126 | const TopLoc_Location& L, | |
127 | const Standard_Real Tol) | |
128 | { | |
0d969553 | 129 | // Cut curves to avoid copies in the extensions. |
7fd59977 | 130 | BRep_Builder B; |
131 | Handle(Geom_TrimmedCurve) BC = Handle(Geom_TrimmedCurve)::DownCast(C); | |
132 | if (!BC.IsNull()) { | |
133 | B.UpdateEdge(E,BC->BasisCurve(),L,Tol); | |
134 | } | |
135 | else { | |
136 | B.UpdateEdge(E,C,L,Tol); | |
137 | } | |
138 | } | |
139 | ||
140 | //======================================================================= | |
141 | //function : UpdateEdge | |
142 | //purpose : | |
143 | //======================================================================= | |
144 | ||
145 | static void UpdateEdge(const TopoDS_Edge& E, | |
146 | const Handle(Geom2d_Curve)& C, | |
147 | const TopoDS_Face& F, | |
148 | const Standard_Real Tol) | |
149 | { | |
0d969553 | 150 | // Cut curves to avoid copies in the extensions. |
7fd59977 | 151 | BRep_Builder B; |
152 | Handle(Geom2d_TrimmedCurve) BC = Handle(Geom2d_TrimmedCurve)::DownCast(C); | |
153 | if (!BC.IsNull()) { | |
154 | B.UpdateEdge(E,BC->BasisCurve(),F,Tol); | |
155 | } | |
156 | else { | |
157 | B.UpdateEdge(E,C,F,Tol); | |
158 | } | |
159 | } | |
160 | ||
161 | //======================================================================= | |
162 | //function : UpdateEdge | |
163 | //purpose : | |
164 | //======================================================================= | |
165 | ||
166 | static void UpdateEdge (const TopoDS_Edge& E, | |
167 | const Handle(Geom2d_Curve)& C1, | |
168 | const Handle(Geom2d_Curve)& C2, | |
169 | const TopoDS_Face& F, | |
170 | const Standard_Real Tol) | |
171 | { | |
0d969553 | 172 | // Cut curves to avoid copies in the extensions. |
7fd59977 | 173 | BRep_Builder B; |
174 | Handle(Geom2d_Curve) NC1,NC2; | |
175 | Handle(Geom2d_TrimmedCurve) BC1 = Handle(Geom2d_TrimmedCurve)::DownCast(C1); | |
176 | Handle(Geom2d_TrimmedCurve) BC2 = Handle(Geom2d_TrimmedCurve)::DownCast(C2); | |
177 | if (!BC1.IsNull()) NC1 = BC1->BasisCurve(); else NC1 = C1; | |
178 | if (!BC2.IsNull()) NC2 = BC2->BasisCurve(); else NC2 = C2; | |
179 | B.UpdateEdge(E,NC1,NC2,F,Tol); | |
180 | } | |
181 | ||
182 | //======================================================================= | |
183 | //function : Range3d | |
184 | //purpose : Set the range only on the 3d curve | |
0d969553 | 185 | // waitint that BRep_Builder does it !! |
7fd59977 | 186 | //======================================================================= |
187 | ||
188 | static void Range3d (const TopoDS_Edge& E, | |
189 | const Standard_Real First, | |
190 | const Standard_Real Last) | |
191 | { | |
192 | // set the range to all the representations | |
193 | const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape()); | |
194 | ||
195 | BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves(); | |
196 | BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr); | |
197 | Handle(BRep_GCurve) GC; | |
198 | ||
199 | while (itcr.More()) { | |
200 | GC = Handle(BRep_GCurve)::DownCast(itcr.Value()); | |
201 | if (!GC.IsNull()) { | |
202 | if (GC->IsCurve3D()) { | |
203 | GC->SetRange(First,Last); | |
204 | // Set the closedness flag to the correct value. | |
205 | Handle(Geom_Curve) C = GC->Curve3D(); | |
206 | if ( !C.IsNull() ) { | |
207 | Standard_Boolean closed = | |
208 | C->Value(First).IsEqual(C->Value(Last),BRep_Tool::Tolerance(E)); | |
209 | TE->Closed(closed); | |
210 | } | |
211 | } | |
212 | } | |
213 | itcr.Next(); | |
214 | } | |
215 | ||
216 | TE->Modified(Standard_True); | |
217 | } | |
218 | ||
219 | ||
220 | //======================================================================= | |
221 | //function : ComputeCurve3d | |
222 | //purpose : Particular case of Curve On Surface. | |
223 | //======================================================================= | |
224 | ||
225 | static void ComputeCurve3d(TopoDS_Edge Edge, | |
226 | Handle(Geom2d_Curve) Curve, | |
227 | Handle(Geom_Surface) Surf, | |
228 | const TopLoc_Location Loc, | |
229 | Standard_Real Tol) | |
230 | { | |
231 | // try to find the particular case | |
232 | // if not found call BRepLib::BuildCurve3d | |
233 | ||
234 | Standard_Boolean IsComputed = Standard_False; | |
235 | ||
0d969553 | 236 | // Search only isos on analytic surfaces. |
7fd59977 | 237 | Geom2dAdaptor_Curve C(Curve); |
238 | GeomAdaptor_Surface S(Surf); | |
239 | GeomAbs_CurveType CTy = C.GetType(); | |
240 | GeomAbs_SurfaceType STy = S.GetType(); | |
241 | BRep_Builder TheBuilder; | |
242 | ||
0d969553 | 243 | if ( STy != GeomAbs_Plane) { // if plane buildcurve3d manage KPart |
7fd59977 | 244 | if ( CTy == GeomAbs_Line) { |
245 | gp_Dir2d D = C.Line().Direction(); | |
246 | if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V. | |
247 | if ( STy == GeomAbs_Sphere) { | |
248 | gp_Pnt2d P = C.Line().Location(); | |
c6541a0c | 249 | if ( Abs( Abs(P.Y()) -M_PI/2. ) < Precision::PConfusion()) { |
7fd59977 | 250 | TheBuilder.Degenerated(Edge, Standard_True); |
251 | } | |
252 | else { | |
253 | gp_Sphere Sph = S.Sphere(); | |
254 | gp_Ax3 Axis = Sph.Position(); | |
255 | gp_Circ Ci = ElSLib::SphereVIso(Axis, | |
256 | Sph.Radius(), | |
257 | P.Y()); | |
258 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
259 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
260 | Ci.Rotate(AxeRev, P.X()); | |
261 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
262 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
263 | Circle->Reverse(); | |
264 | UpdateEdge(Edge, Circle, Loc, Tol); | |
265 | } | |
266 | IsComputed = Standard_True; | |
267 | } | |
268 | else if ( STy == GeomAbs_Cylinder) { | |
269 | gp_Cylinder Cyl = S.Cylinder(); | |
270 | gp_Pnt2d P = C.Line().Location(); | |
271 | gp_Ax3 Axis = Cyl.Position(); | |
272 | gp_Circ Ci = ElSLib::CylinderVIso(Axis, | |
273 | Cyl.Radius(), | |
274 | P.Y()); | |
275 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
276 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
277 | Ci.Rotate(AxeRev, P.X()); | |
278 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
279 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
280 | Circle->Reverse(); | |
281 | UpdateEdge(Edge, Circle, Loc, Tol); | |
282 | IsComputed = Standard_True; | |
283 | } | |
284 | else if ( STy == GeomAbs_Cone) { | |
285 | gp_Cone Cone = S.Cone(); | |
286 | gp_Pnt2d P = C.Line().Location(); | |
287 | gp_Ax3 Axis = Cone.Position(); | |
288 | gp_Circ Ci = ElSLib::ConeVIso(Axis, | |
289 | Cone.RefRadius(), | |
290 | Cone.SemiAngle(), | |
291 | P.Y()); | |
292 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
293 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
294 | Ci.Rotate(AxeRev, P.X()); | |
295 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
296 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
297 | Circle->Reverse(); | |
298 | UpdateEdge(Edge, Circle, Loc, Tol); | |
299 | IsComputed = Standard_True; | |
300 | } | |
301 | else if ( STy == GeomAbs_Torus) { | |
302 | gp_Torus Tore = S.Torus(); | |
303 | gp_Pnt2d P = C.Line().Location(); | |
304 | gp_Ax3 Axis = Tore.Position(); | |
305 | gp_Circ Ci = ElSLib::TorusVIso(Axis, | |
306 | Tore.MajorRadius(), | |
307 | Tore.MinorRadius(), | |
308 | P.Y()); | |
309 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
310 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
311 | Ci.Rotate(AxeRev, P.X()); | |
312 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
313 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
314 | Circle->Reverse(); | |
315 | UpdateEdge(Edge, Circle, Loc, Tol); | |
316 | IsComputed = Standard_True; | |
317 | } | |
318 | } | |
319 | else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U. | |
320 | if ( STy == GeomAbs_Sphere) { | |
321 | gp_Sphere Sph = S.Sphere(); | |
322 | gp_Pnt2d P = C.Line().Location(); | |
323 | gp_Ax3 Axis = Sph.Position(); | |
0d969553 | 324 | // calculate iso 0. |
7fd59977 | 325 | gp_Circ Ci = ElSLib::SphereUIso(Axis, Sph.Radius(),0.); |
326 | ||
0d969553 | 327 | // set to sameparameter (rotation of circle - offset of Y) |
7fd59977 | 328 | gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction()); |
329 | gp_Ax1 AxeRev(Axis.Location(),DRev); | |
330 | Ci.Rotate(AxeRev, P.Y()); | |
331 | ||
332 | // transformation en iso U ( = P.X()) | |
333 | DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
334 | AxeRev = gp_Ax1(Axis.Location(), DRev); | |
335 | Ci.Rotate(AxeRev, P.X()); | |
336 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
337 | ||
338 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
339 | Circle->Reverse(); | |
340 | UpdateEdge(Edge, Circle, Loc, Tol); | |
341 | IsComputed = Standard_True; | |
342 | } | |
343 | else if ( STy == GeomAbs_Cylinder) { | |
344 | gp_Cylinder Cyl = S.Cylinder(); | |
345 | gp_Pnt2d P = C.Line().Location(); | |
346 | gp_Lin L = ElSLib::CylinderUIso(Cyl.Position(), | |
347 | Cyl.Radius(), | |
348 | P.X()); | |
349 | gp_Vec Tr(L.Direction()); | |
350 | Tr.Multiply(P.Y()); | |
351 | L.Translate(Tr); | |
352 | Handle(Geom_Line) Line = new Geom_Line(L); | |
353 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
354 | Line->Reverse(); | |
355 | UpdateEdge(Edge, Line, Loc, Tol); | |
356 | IsComputed = Standard_True; | |
357 | } | |
358 | else if ( STy == GeomAbs_Cone) { | |
359 | gp_Cone Cone = S.Cone(); | |
360 | gp_Pnt2d P = C.Line().Location(); | |
361 | gp_Lin L = ElSLib::ConeUIso(Cone.Position(), | |
362 | Cone.RefRadius(), | |
363 | Cone.SemiAngle(), | |
364 | P.X()); | |
365 | gp_Vec Tr(L.Direction()); | |
366 | Tr.Multiply(P.Y()); | |
367 | L.Translate(Tr); Handle(Geom_Line) Line = new Geom_Line(L); | |
368 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
369 | Line->Reverse(); | |
370 | UpdateEdge(Edge, Line, Loc, Tol); | |
371 | IsComputed = Standard_True; | |
372 | } | |
373 | else if ( STy == GeomAbs_Torus) { | |
374 | gp_Torus Tore = S.Torus(); | |
375 | gp_Pnt2d P = C.Line().Location(); | |
376 | gp_Ax3 Axis = Tore.Position(); | |
377 | gp_Circ Ci = ElSLib::TorusUIso(Axis, | |
378 | Tore.MajorRadius(), | |
379 | Tore.MinorRadius(), | |
380 | P.X()); | |
381 | Ci.Rotate(Ci.Axis(),P.Y()); | |
382 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
383 | ||
384 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
385 | Circle->Reverse(); | |
386 | UpdateEdge(Edge, Circle, Loc, Tol); | |
387 | IsComputed = Standard_True; | |
388 | } | |
389 | } | |
390 | } | |
391 | } | |
392 | else { // Cas Plan | |
393 | Handle(Geom_Curve) C3d = GeomAPI::To3d(Curve,S.Plane()); | |
394 | UpdateEdge(Edge, C3d, Loc, Tol); | |
395 | IsComputed = Standard_True; | |
396 | } | |
397 | if ( !IsComputed) { | |
398 | //BRepLib::BuildCurves3d(Edge,Tol); | |
399 | //Les Courbes 3d des edges dans le cas general ne sont calcules que si | |
400 | // necessaire | |
401 | //ie dans les tuyaux et les bouchons .. | |
402 | // dans la derniere etapes de MakeShells on reconstruira les courbes3d | |
403 | // des edges du resultat qui n en ont pas. | |
404 | } | |
405 | } | |
406 | ||
407 | ||
408 | //======================================================================= | |
409 | //function : BRepOffset_Offset | |
410 | //purpose : | |
411 | //======================================================================= | |
412 | ||
413 | BRepOffset_Offset::BRepOffset_Offset() | |
414 | { | |
415 | } | |
416 | ||
417 | ||
418 | //======================================================================= | |
419 | //function : BRepOffset_Offset | |
420 | //purpose : | |
421 | //======================================================================= | |
422 | ||
423 | BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Face& Face, | |
424 | const Standard_Real Offset, | |
425 | const Standard_Boolean OffsetOutside, | |
426 | const GeomAbs_JoinType JoinType) | |
427 | { | |
428 | Init(Face, Offset, OffsetOutside, JoinType); | |
429 | } | |
430 | ||
431 | ||
432 | //======================================================================= | |
433 | //function : BRepOffset_Offset | |
434 | //purpose : | |
435 | //======================================================================= | |
436 | ||
437 | BRepOffset_Offset::BRepOffset_Offset | |
438 | (const TopoDS_Face& Face, | |
439 | const Standard_Real Offset, | |
440 | const TopTools_DataMapOfShapeShape& Created, | |
441 | const Standard_Boolean OffsetOutside, | |
442 | const GeomAbs_JoinType JoinType) | |
443 | { | |
444 | Init(Face,Offset,Created,OffsetOutside,JoinType); | |
445 | } | |
446 | ||
447 | ||
448 | //======================================================================= | |
449 | //function : BRepOffset_Offset | |
450 | //purpose : | |
451 | //======================================================================= | |
452 | ||
453 | BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Edge& Path, | |
454 | const TopoDS_Edge& Edge1, | |
455 | const TopoDS_Edge& Edge2, | |
456 | const Standard_Real Offset, | |
457 | const Standard_Boolean Polynomial, | |
458 | const Standard_Real Tol, | |
459 | const GeomAbs_Shape Conti) | |
460 | { | |
461 | Init(Path,Edge1,Edge2,Offset,Polynomial,Tol,Conti); | |
462 | } | |
463 | ||
464 | ||
465 | //======================================================================= | |
466 | //function : BRepOffset_Offset | |
467 | //purpose : | |
468 | //======================================================================= | |
469 | ||
470 | BRepOffset_Offset::BRepOffset_Offset | |
471 | (const TopoDS_Edge& Path, | |
472 | const TopoDS_Edge& Edge1, | |
473 | const TopoDS_Edge& Edge2, | |
474 | const Standard_Real Offset, | |
475 | const TopoDS_Edge& FirstEdge, | |
476 | const TopoDS_Edge& LastEdge, | |
477 | const Standard_Boolean Polynomial, | |
478 | const Standard_Real Tol, | |
479 | const GeomAbs_Shape Conti) | |
480 | { | |
481 | Init(Path,Edge1,Edge2,Offset,FirstEdge,LastEdge,Polynomial,Tol,Conti); | |
482 | } | |
483 | ||
484 | ||
485 | //======================================================================= | |
486 | //function : BRepOffset_Offset | |
487 | //purpose : | |
488 | //======================================================================= | |
489 | ||
490 | BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Vertex& Vertex, | |
491 | const TopTools_ListOfShape& LEdge, | |
492 | const Standard_Real Offset, | |
493 | const Standard_Boolean Polynomial, | |
494 | const Standard_Real Tol, | |
495 | const GeomAbs_Shape Conti) | |
496 | { | |
497 | Init(Vertex,LEdge,Offset,Polynomial,Tol,Conti); | |
498 | } | |
499 | ||
500 | ||
501 | //======================================================================= | |
502 | //function : Init | |
503 | //purpose : | |
504 | //======================================================================= | |
505 | ||
506 | void BRepOffset_Offset::Init(const TopoDS_Face& Face, | |
507 | const Standard_Real Offset, | |
508 | const Standard_Boolean OffsetOutside, | |
509 | const GeomAbs_JoinType JoinType) | |
510 | { | |
511 | TopTools_DataMapOfShapeShape Empty; | |
512 | Init(Face,Offset,Empty,OffsetOutside,JoinType); | |
513 | } | |
514 | ||
515 | ||
516 | //======================================================================= | |
517 | //function : Init | |
518 | //purpose : | |
519 | //======================================================================= | |
520 | ||
521 | void BRepOffset_Offset::Init(const TopoDS_Face& Face, | |
522 | const Standard_Real Offset, | |
523 | const TopTools_DataMapOfShapeShape& Created, | |
524 | const Standard_Boolean OffsetOutside, | |
525 | const GeomAbs_JoinType JoinType) | |
526 | { | |
527 | myShape = Face; | |
528 | Standard_Real myOffset = Offset; | |
529 | if ( Face.Orientation() == TopAbs_REVERSED) | |
530 | myOffset *= -1.; | |
531 | ||
532 | TopLoc_Location L; | |
533 | Handle(Geom_Surface) S = BRep_Tool::Surface(Face,L); | |
534 | ||
535 | // On detrime les surfaces, evite des recopies dans les extensions. | |
536 | Handle(Geom_RectangularTrimmedSurface) RT = | |
537 | Handle(Geom_RectangularTrimmedSurface)::DownCast(S); | |
538 | if (!RT.IsNull()) S = RT->BasisSurface(); | |
539 | ||
540 | // particular case of cone | |
541 | Handle(Geom_ConicalSurface) Co; | |
542 | Co = Handle(Geom_ConicalSurface)::DownCast(S); | |
543 | if ( !Co.IsNull()) { | |
544 | Standard_Real Uc,Vc; | |
545 | gp_Pnt Apex = Co->Apex(); | |
546 | ElSLib::Parameters( Co->Cone(),Apex,Uc,Vc); | |
547 | Standard_Real UU1,UU2,VV1,VV2; | |
548 | BRepTools::UVBounds(Face,UU1,UU2,VV1,VV2); | |
549 | if ( VV2 < Vc && Co->SemiAngle() > 0 ) | |
550 | myOffset *= -1; | |
551 | else if ( VV1 > Vc && Co->SemiAngle() < 0 ) | |
552 | myOffset *= -1; | |
553 | if ( !Co->Position().Direct()) myOffset *= -1; | |
554 | } | |
555 | ||
556 | Handle(Geom_Surface) TheSurf = | |
557 | BRepOffset::Surface( S, myOffset, myStatus); | |
558 | ||
559 | //processing offsets of faces with possible degenerated edges | |
903f7584 | 560 | Standard_Boolean UminDegen = Standard_False; |
561 | Standard_Boolean UmaxDegen = Standard_False; | |
7fd59977 | 562 | Standard_Boolean VminDegen = Standard_False; |
563 | Standard_Boolean VmaxDegen = Standard_False; | |
903f7584 | 564 | Standard_Boolean UisoDegen = Standard_False; |
565 | Standard_Boolean VisoDegen = Standard_False; | |
7fd59977 | 566 | gp_Pnt MinApex, MaxApex; |
567 | Standard_Boolean HasSingularity = Standard_False; | |
568 | Standard_Real uf1, uf2, vf1, vf2, fpar, lpar; | |
569 | BRepTools::UVBounds(Face, uf1, uf2, vf1, vf2); | |
570 | if (!(OffsetOutside && JoinType == GeomAbs_Arc) && | |
571 | (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface) || | |
572 | TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))) | |
573 | { | |
574 | TopTools_SequenceOfShape DegEdges; | |
575 | TopExp_Explorer Explo(Face, TopAbs_EDGE); | |
576 | for (; Explo.More(); Explo.Next()) | |
577 | { | |
578 | const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current()); | |
579 | if (BRep_Tool::Degenerated(anEdge)) | |
580 | DegEdges.Append(anEdge); | |
581 | } | |
582 | if (!DegEdges.IsEmpty()) | |
583 | { | |
584 | const Standard_Real TolApex = 1.e-5; | |
903f7584 | 585 | //define the iso of singularity (u or v) |
586 | const TopoDS_Edge& theDegEdge = TopoDS::Edge(DegEdges(1)); | |
587 | Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar); | |
588 | gp_Pnt2d fp2d = aCurve->Value(fpar); | |
589 | gp_Pnt2d lp2d = aCurve->Value(lpar); | |
590 | if (Abs(fp2d.X() - lp2d.X()) <= Precision::PConfusion()) | |
591 | UisoDegen = Standard_True; | |
592 | else | |
593 | VisoDegen = Standard_True; | |
594 | ||
7fd59977 | 595 | if (DegEdges.Length() == 2) |
596 | { | |
903f7584 | 597 | if (UisoDegen) |
598 | { UminDegen = Standard_True; UmaxDegen = Standard_True; } | |
599 | else | |
600 | { VminDegen = Standard_True; VmaxDegen = Standard_True; } | |
7fd59977 | 601 | } |
602 | else //DegEdges.Length() == 1 | |
603 | { | |
604 | const TopoDS_Edge& theDegEdge = TopoDS::Edge(DegEdges(1)); | |
605 | Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar); | |
903f7584 | 606 | if (UisoDegen) |
607 | { | |
608 | if (Abs(fp2d.X() - uf1) <= Precision::Confusion()) | |
609 | UminDegen = Standard_True; | |
610 | else | |
611 | UmaxDegen = Standard_True; | |
612 | } | |
613 | else | |
614 | { | |
615 | if (Abs(fp2d.Y() - vf1) <= Precision::Confusion()) | |
616 | VminDegen = Standard_True; | |
617 | else | |
618 | VmaxDegen = Standard_True; | |
619 | } | |
7fd59977 | 620 | } |
621 | if (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface)) | |
622 | { | |
623 | gp_Cone theCone = (*((Handle(Geom_ConicalSurface)*)&TheSurf))->Cone(); | |
624 | gp_Pnt apex = theCone.Apex(); | |
625 | Standard_Real Uapex, Vapex; | |
626 | ElSLib::Parameters( theCone, apex, Uapex, Vapex ); | |
627 | if (VminDegen) | |
628 | { | |
629 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, Vapex, vf2); | |
630 | MinApex = apex; | |
631 | HasSingularity = Standard_True; | |
632 | } | |
633 | else if (VmaxDegen) | |
634 | { | |
635 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, Vapex); | |
636 | MaxApex = apex; | |
637 | HasSingularity = Standard_True; | |
638 | } | |
639 | } | |
640 | else //TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface) | |
641 | { | |
903f7584 | 642 | if (UminDegen) |
643 | { | |
644 | Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 ); | |
645 | if (BRepOffset_Tool::Gabarit( uiso ) > TolApex) | |
646 | { | |
647 | Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface(); | |
648 | gp_Pnt Papex, Pfirst, Pquart, Pmid; | |
649 | Papex = BasisSurf->Value( uf1, vf1 ); | |
650 | Pfirst = TheSurf->Value( uf1, vf1 ); | |
651 | Pquart = TheSurf->Value( uf1, 0.75*vf1+0.25*vf2 ); | |
652 | Pmid = TheSurf->Value( uf1, 0.5*(vf1+vf2) ); | |
653 | gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid); | |
654 | Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex ); | |
655 | gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 1, 0 ); | |
656 | Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix ); | |
657 | GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex ); | |
658 | gp_Pnt Pint1, Pint2; | |
659 | theExtrema.NearestPoints(Pint1, Pint2); | |
660 | Standard_Real length = Pfirst.Distance(Pint1); | |
661 | if (OffsetOutside) | |
662 | { | |
663 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2); | |
664 | GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1, | |
665 | Standard_True, Standard_False); | |
666 | Standard_Real u1, u2, v1, v2; | |
667 | TheSurf->Bounds( u1, u2, v1, v2 ); | |
668 | MinApex = TheSurf->Value( u1, vf1 ); | |
669 | } | |
670 | else | |
671 | { | |
672 | Handle(Geom_Curve) viso = TheSurf->VIso( vf1 ); | |
673 | GeomAPI_ProjectPointOnCurve Projector( Pint1, viso ); | |
674 | Standard_Real NewFirstU = Projector.LowerDistanceParameter(); | |
675 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, NewFirstU, uf2, vf1, vf2); | |
676 | MinApex = TheSurf->Value( NewFirstU, vf1 ); | |
677 | } | |
678 | HasSingularity = Standard_True; | |
679 | } | |
680 | } //end of if (UminDegen) | |
681 | if (UmaxDegen) | |
682 | { | |
683 | Handle(Geom_Curve) uiso = TheSurf->UIso( uf2 ); | |
684 | if (BRepOffset_Tool::Gabarit( uiso ) > TolApex) | |
685 | { | |
686 | Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface(); | |
687 | gp_Pnt Papex, Pfirst, Pquart, Pmid; | |
688 | Papex = BasisSurf->Value( uf2, vf1 ); | |
689 | Pfirst = TheSurf->Value( uf2, vf1 ); | |
690 | Pquart = TheSurf->Value( uf2, 0.75*vf1+0.25*vf2 ); | |
691 | Pmid = TheSurf->Value( uf2, 0.5*(vf1+vf2) ); | |
692 | gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid); | |
693 | Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex ); | |
694 | gp_Vec DirGeneratrix = BasisSurf->DN( uf2, vf1, 1, 0 ); | |
695 | Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix ); | |
696 | GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex ); | |
697 | gp_Pnt Pint1, Pint2; | |
698 | theExtrema.NearestPoints(Pint1, Pint2); | |
699 | Standard_Real length = Pfirst.Distance(Pint1); | |
700 | if (OffsetOutside) | |
701 | { | |
702 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2); | |
703 | GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1, | |
704 | Standard_True, Standard_True); | |
705 | Standard_Real u1, u2, v1, v2; | |
706 | TheSurf->Bounds( u1, u2, v1, v2 ); | |
707 | MaxApex = TheSurf->Value( u2, vf1 ); | |
708 | } | |
709 | else | |
710 | { | |
711 | Handle(Geom_Curve) viso = TheSurf->VIso( vf1 ); | |
712 | GeomAPI_ProjectPointOnCurve Projector( Pint1, viso ); | |
713 | Standard_Real NewLastU = Projector.LowerDistanceParameter(); | |
714 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, NewLastU, vf1, vf2); | |
715 | MaxApex = TheSurf->Value( NewLastU, vf1 ); | |
716 | } | |
717 | HasSingularity = Standard_True; | |
718 | } | |
719 | } //end of if (UmaxDegen) | |
7fd59977 | 720 | if (VminDegen) |
903f7584 | 721 | { |
722 | Handle(Geom_Curve) viso = TheSurf->VIso( vf1 ); | |
723 | if (BRepOffset_Tool::Gabarit( viso ) > TolApex) | |
724 | { | |
725 | Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface(); | |
726 | gp_Pnt Papex, Pfirst, Pquart, Pmid; | |
727 | Papex = BasisSurf->Value( uf1, vf1 ); | |
728 | Pfirst = TheSurf->Value( uf1, vf1 ); | |
729 | Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf1 ); | |
730 | Pmid = TheSurf->Value( 0.5*(uf1+uf2), vf1 ); | |
731 | gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid); | |
732 | Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex ); | |
733 | gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 0, 1 ); | |
734 | Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix ); | |
735 | GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex ); | |
736 | gp_Pnt Pint1, Pint2; | |
737 | theExtrema.NearestPoints(Pint1, Pint2); | |
738 | Standard_Real length = Pfirst.Distance(Pint1); | |
739 | if (OffsetOutside) | |
740 | { | |
741 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2); | |
742 | GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1, | |
743 | Standard_False, Standard_False); | |
744 | Standard_Real u1, u2, v1, v2; | |
745 | TheSurf->Bounds( u1, u2, v1, v2 ); | |
746 | MinApex = TheSurf->Value( uf1, v1 ); | |
747 | } | |
748 | else | |
749 | { | |
750 | Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 ); | |
751 | GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso ); | |
752 | Standard_Real NewFirstV = Projector.LowerDistanceParameter(); | |
753 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, NewFirstV, vf2); | |
754 | MinApex = TheSurf->Value( uf1, NewFirstV ); | |
755 | //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1+length, vf2); | |
756 | //MinApex = TheSurf->Value( uf1, vf1+length ); | |
757 | } | |
758 | HasSingularity = Standard_True; | |
759 | } | |
760 | } //end of if (VminDegen) | |
7fd59977 | 761 | if (VmaxDegen) |
903f7584 | 762 | { |
763 | Handle(Geom_Curve) viso = TheSurf->VIso( vf2 ); | |
764 | if (BRepOffset_Tool::Gabarit( viso ) > TolApex) | |
765 | { | |
766 | Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface(); | |
767 | gp_Pnt Papex, Pfirst, Pquart, Pmid; | |
768 | Papex = BasisSurf->Value( uf1, vf2 ); | |
769 | Pfirst = TheSurf->Value( uf1, vf2 ); | |
770 | Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf2 ); | |
771 | Pmid = TheSurf->Value( 0.5*(uf1+uf2), vf2 ); | |
772 | gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid); | |
773 | Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex ); | |
774 | gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf2, 0, 1 ); | |
775 | Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix ); | |
776 | GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex ); | |
777 | gp_Pnt Pint1, Pint2; | |
778 | theExtrema.NearestPoints(Pint1, Pint2); | |
779 | Standard_Real length = Pfirst.Distance(Pint1); | |
780 | if (OffsetOutside) | |
781 | { | |
782 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2); | |
783 | GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1, | |
784 | Standard_False, Standard_True); | |
785 | Standard_Real u1, u2, v1, v2; | |
786 | TheSurf->Bounds( u1, u2, v1, v2 ); | |
787 | MaxApex = TheSurf->Value( uf1, v2 ); | |
788 | } | |
789 | else | |
790 | { | |
791 | Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 ); | |
792 | GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso ); | |
793 | Standard_Real NewLastV = Projector.LowerDistanceParameter(); | |
794 | TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, NewLastV); | |
795 | MaxApex = TheSurf->Value( uf1, NewLastV ); | |
796 | //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2-length); | |
797 | //MaxApex = TheSurf->Value( uf1, vf2-length ); | |
798 | } | |
799 | HasSingularity = Standard_True; | |
800 | } | |
801 | } //end of if (VmaxDegen) | |
7fd59977 | 802 | } //end of else (case of Geom_OffsetSurface) |
803 | } //end of if (!DegEdges.IsEmpty()) | |
804 | } //end of processing offsets of faces with possible degenerated edges | |
805 | ||
806 | // find the PCurves of the edges of <Faces> | |
807 | ||
808 | BRep_Builder myBuilder; | |
809 | myBuilder.MakeFace(myFace); | |
810 | myBuilder.UpdateFace(myFace,TheSurf,L,BRep_Tool::Tolerance(Face)); | |
811 | ||
812 | TopTools_DataMapOfShapeShape MapSS; | |
813 | ||
814 | // mise a jour de la map sur les vertex deja crees | |
815 | TopoDS_Shape aLocalShape = Face.Oriented(TopAbs_FORWARD); | |
816 | TopoDS_Face CurFace = TopoDS::Face(aLocalShape); | |
817 | // TopoDS_Face CurFace = TopoDS::Face(Face.Oriented(TopAbs_FORWARD)); | |
818 | ||
819 | TopTools_MapOfShape VonDegen; | |
820 | Standard_Real u1, u2, v1, v2; | |
821 | TheSurf->Bounds( u1, u2, v1, v2 ); | |
822 | ||
823 | TopExp_Explorer exp(CurFace, TopAbs_EDGE); | |
824 | for ( ; exp.More(); exp.Next()) { | |
825 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); | |
826 | TopoDS_Vertex V1,V2,OV1,OV2; | |
827 | TopExp::Vertices(E ,V1 ,V2 ); | |
828 | if (HasSingularity && BRep_Tool::Degenerated(E)) | |
829 | VonDegen.Add( V1 ); | |
830 | if (Created.IsBound(E)) { | |
831 | const TopoDS_Edge& OE = TopoDS::Edge(Created(E)); | |
832 | TopExp::Vertices(OE,OV1,OV2); | |
833 | if (!MapSS.IsBound(V1)) MapSS.Bind(V1,OV1); | |
834 | if (!MapSS.IsBound(V2)) MapSS.Bind(V2,OV2); | |
835 | } | |
836 | if (Created.IsBound(V1)) { | |
837 | if (!MapSS.IsBound(V1)) MapSS.Bind(V1,Created(V1)); | |
838 | } | |
839 | if (Created.IsBound(V2)) { | |
840 | if (!MapSS.IsBound(V2)) MapSS.Bind(V2,Created(V2)); | |
841 | } | |
842 | } | |
843 | ||
844 | TopExp_Explorer expw(CurFace, TopAbs_WIRE); | |
845 | for ( ; expw.More(); expw.Next()) { | |
846 | const TopoDS_Wire& W = TopoDS::Wire(expw.Current()); | |
847 | TopExp_Explorer expe(W.Oriented(TopAbs_FORWARD), | |
848 | TopAbs_EDGE); | |
849 | TopoDS_Wire OW; | |
850 | myBuilder.MakeWire(OW); | |
851 | for ( ; expe.More(); expe.Next()) { | |
852 | const TopoDS_Edge& E = TopoDS::Edge(expe.Current()); | |
853 | TopoDS_Vertex V1,V2; | |
854 | TopExp::Vertices(E,V1,V2); | |
855 | gp_Pnt2d P2d1, P2d2; | |
856 | gp_Pnt P1, P2; | |
857 | Standard_Real vstart, vend; | |
858 | Standard_Real f,l; | |
859 | Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,CurFace,f,l); | |
860 | TopoDS_Edge OE; | |
861 | if (MapSS.IsBound(E) && | |
862 | !VonDegen.Contains(V1) && !VonDegen.Contains(V2)) { // c`est un edge de couture | |
863 | OE = TopoDS::Edge(MapSS(E)); | |
864 | TopoDS_Shape aLocalShape = E.Reversed(); | |
865 | Handle(Geom2d_Curve) C2d_1 = | |
866 | BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),CurFace,f,l); | |
867 | // Handle(Geom2d_Curve) C2d_1 = | |
868 | // BRep_Tool::CurveOnSurface(TopoDS::Edge(E.Reversed()),CurFace,f,l); | |
869 | if ( E.Orientation() == TopAbs_FORWARD) | |
870 | UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E)); | |
871 | else | |
872 | UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E)); | |
873 | myBuilder.Range(OE,f,l); | |
874 | } | |
875 | else { | |
876 | TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD); | |
877 | TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape); | |
878 | P2d1 = C2d->Value(BRep_Tool::Parameter(V1,Eforward,CurFace)); | |
879 | P2d2 = C2d->Value(BRep_Tool::Parameter(V2,Eforward,CurFace)); | |
880 | if (VonDegen.Contains(V1)) | |
881 | { | |
882 | if (Abs(P2d1.Y() - vf1) <= Precision::Confusion()) | |
883 | { | |
884 | P1 = MinApex; vstart = v1; | |
885 | } | |
886 | else | |
887 | { | |
888 | P1 = MaxApex; vstart = v2; | |
889 | } | |
890 | } | |
891 | else | |
892 | { | |
893 | TheSurf->D0(P2d1.X(),P2d1.Y(),P1); | |
894 | P1.Transform(L.Transformation()); | |
895 | vstart = P2d1.Y(); | |
896 | } | |
897 | if (VonDegen.Contains(V2)) | |
898 | { | |
899 | if (Abs(P2d2.Y() - vf1) <= Precision::Confusion()) | |
900 | { | |
901 | P2 = MinApex; vend = v1; | |
902 | } | |
903 | else | |
904 | { | |
905 | P2 = MaxApex; vend = v2; | |
906 | } | |
907 | } | |
908 | else | |
909 | { | |
910 | TheSurf->D0(P2d2.X(),P2d2.Y(),P2); | |
911 | P2.Transform(L.Transformation()); | |
912 | vend = P2d2.Y(); | |
913 | } | |
914 | // E a-t-il ume image dans la Map des Created ? | |
915 | if ( Created.IsBound(E)) { | |
916 | OE = TopoDS::Edge(Created(E)); | |
917 | } | |
918 | else if (MapSS.IsBound(E)) //seam edge | |
919 | OE = TopoDS::Edge(MapSS(E)); | |
920 | else { | |
921 | myBuilder.MakeEdge(OE); | |
922 | TopoDS_Vertex OV1,OV2; | |
923 | if ( MapSS.IsBound(V1)) { | |
924 | OV1 = TopoDS::Vertex(MapSS(V1)); | |
925 | } | |
926 | else { | |
927 | myBuilder.MakeVertex(OV1); | |
928 | myBuilder.UpdateVertex(OV1,P1,BRep_Tool::Tolerance(V1)); | |
929 | MapSS.Bind(V1,OV1); | |
930 | } | |
931 | if ( MapSS.IsBound(V2)) { | |
932 | OV2 = TopoDS::Vertex(MapSS(V2)); | |
933 | } | |
934 | else { | |
935 | myBuilder.MakeVertex(OV2); | |
936 | myBuilder.UpdateVertex(OV2,P2,BRep_Tool::Tolerance(V2)); | |
937 | MapSS.Bind(V2,OV2); | |
938 | } | |
939 | myBuilder.Add(OE,OV1.Oriented(V1.Orientation())); | |
940 | myBuilder.Add(OE,OV2.Oriented(V2.Orientation())); | |
941 | if (BRep_Tool::Degenerated(E)) { | |
942 | myBuilder.Degenerated(OE, Standard_True); | |
943 | /* | |
944 | #ifdef DEB | |
945 | gp_Pnt P1,P2; | |
946 | gp_Pnt2d P2d; | |
947 | P2d = C2d->Value(f); TheSurf->D0(P2d.X(),P2d.Y(),P1); | |
948 | P2d = C2d->Value(l); TheSurf->D0(P2d.X(),P2d.Y(),P2); | |
949 | Standard_Real Tol = BRep_Tool::Tolerance(V1); | |
950 | if (!P1.IsEqual(P2,Tol)) { | |
951 | cout <<"BRepOffset_Offset : E degenerated -> OE not degenerated"<<endl; | |
952 | } | |
953 | #endif | |
954 | */ | |
955 | } | |
956 | } | |
957 | if (VonDegen.Contains(V1) || VonDegen.Contains(V2)) | |
958 | { | |
959 | if (VonDegen.Contains(V1)) | |
960 | P2d1.SetY( vstart ); | |
961 | if (VonDegen.Contains(V2)) | |
962 | P2d2.SetY( vend ); | |
963 | C2d = new Geom2d_Line( P2d1, gp_Vec2d(P2d1, P2d2) ); | |
964 | f = 0.; l = P2d1.Distance( P2d2 ); | |
965 | if (MapSS.IsBound(E)) //seam edge | |
966 | { | |
967 | Handle(Geom2d_Curve) C2d_1 = BRep_Tool::CurveOnSurface(OE, myFace, f, l); | |
968 | if (E.Orientation() == TopAbs_FORWARD) | |
969 | UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E)); | |
970 | else | |
971 | UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E)); | |
972 | } | |
973 | else | |
974 | UpdateEdge(OE,C2d,myFace,BRep_Tool::Tolerance(E)); | |
975 | //myBuilder.Range(OE,f,l); | |
976 | myBuilder.Range(OE, myFace, f, l); | |
977 | if (!BRep_Tool::Degenerated(E) && TheSurf->IsUClosed()) | |
978 | { | |
979 | TopoDS_Shape aLocalShape = E.Reversed(); | |
980 | Handle(Geom2d_Curve) C2d_1 = | |
981 | BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),CurFace,f,l); | |
982 | P2d1 = C2d_1->Value(BRep_Tool::Parameter(V1,E,CurFace)); | |
983 | P2d2 = C2d_1->Value(BRep_Tool::Parameter(V2,E,CurFace)); | |
984 | if (VonDegen.Contains(V1)) | |
985 | P2d1.SetY( vstart ); | |
986 | if (VonDegen.Contains(V2)) | |
987 | P2d2.SetY( vend ); | |
988 | C2d_1 = new Geom2d_Line( P2d1, gp_Vec2d(P2d1, P2d2) ); | |
989 | if ( E.Orientation() == TopAbs_FORWARD) | |
990 | UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E)); | |
991 | else | |
992 | UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E)); | |
993 | } | |
994 | /* | |
995 | if (!BRep_Tool::Degenerated(E)) | |
996 | { | |
997 | Handle(Geom_Line) theLine = new Geom_Line( P1, gp_Vec(P1, P2) ); | |
998 | myBuilder.UpdateEdge( OE, theLine, BRep_Tool::Tolerance(E) ); | |
999 | } | |
1000 | */ | |
1001 | } | |
1002 | else | |
1003 | { | |
1004 | UpdateEdge(OE,C2d,myFace,BRep_Tool::Tolerance(E)); | |
1005 | myBuilder.Range(OE,f,l); | |
1006 | //ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E)); | |
1007 | } | |
1008 | if (!BRep_Tool::Degenerated(OE)) | |
1009 | ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E)); | |
1010 | MapSS.Bind(E,OE); | |
1011 | } | |
1012 | myBuilder.Add(OW, OE.Oriented(E.Orientation())); | |
1013 | } | |
1014 | myBuilder.Add(myFace, OW.Oriented(W.Orientation())); | |
1015 | } | |
1016 | ||
1017 | myFace.Orientation(Face.Orientation()); | |
1018 | ||
1019 | BRepTools::Update(myFace); | |
1020 | } | |
1021 | ||
1022 | ||
1023 | //======================================================================= | |
1024 | //function : Init | |
1025 | //purpose : | |
1026 | //======================================================================= | |
1027 | ||
1028 | void BRepOffset_Offset::Init(const TopoDS_Edge& Path, | |
1029 | const TopoDS_Edge& Edge1, | |
1030 | const TopoDS_Edge& Edge2, | |
1031 | const Standard_Real Offset, | |
1032 | const Standard_Boolean Polynomial, | |
1033 | const Standard_Real Tol, | |
1034 | const GeomAbs_Shape Conti) | |
1035 | { | |
1036 | TopoDS_Edge FirstEdge,LastEdge; | |
1037 | Init(Path,Edge1,Edge2,Offset,FirstEdge,LastEdge,Polynomial,Tol,Conti); | |
1038 | } | |
1039 | ||
1040 | ||
1041 | //======================================================================= | |
1042 | //function : Init | |
1043 | //purpose : | |
1044 | //======================================================================= | |
1045 | ||
1046 | void BRepOffset_Offset::Init(const TopoDS_Edge& Path, | |
1047 | const TopoDS_Edge& Edge1, | |
1048 | const TopoDS_Edge& Edge2, | |
1049 | const Standard_Real Offset, | |
1050 | const TopoDS_Edge& FirstEdge, | |
1051 | const TopoDS_Edge& LastEdge, | |
1052 | const Standard_Boolean Polynomial, | |
1053 | const Standard_Real Tol, | |
1054 | const GeomAbs_Shape Conti) | |
1055 | { | |
1056 | Standard_Boolean C1Denerated = Standard_False; | |
1057 | Standard_Boolean C2Denerated = Standard_False; | |
1058 | myStatus = BRepOffset_Good; | |
1059 | myShape = Path; | |
1060 | ||
1061 | TopLoc_Location Loc; | |
1062 | Standard_Real f[3],l[3]; | |
1063 | ||
1064 | Handle(Geom_Curve) CP = BRep_Tool::Curve(Path,Loc,f[0],l[0]); | |
1065 | CP = new Geom_TrimmedCurve(CP,f[0], l[0]); | |
1066 | CP->Transform(Loc.Transformation()); | |
1067 | Handle(GeomAdaptor_HCurve) HCP = new GeomAdaptor_HCurve(CP); | |
1068 | ||
1069 | Handle(Geom_Curve) C1 = BRep_Tool::Curve(Edge1,Loc,f[1],l[1]); | |
1070 | ||
1071 | Handle(Adaptor3d_HCurve) HEdge1; | |
1072 | Standard_Boolean C1is3D = Standard_True; | |
1073 | if (C1.IsNull()) { | |
1074 | C1is3D = Standard_False; | |
1075 | Handle(Geom2d_Curve) C12d; | |
1076 | Handle(Geom_Surface) S1; | |
1077 | BRep_Tool::CurveOnSurface(Edge1,C12d,S1,Loc,f[1],l[1]); | |
1078 | S1 = Handle(Geom_Surface)::DownCast(S1->Transformed(Loc.Transformation())); | |
1079 | C12d = new Geom2d_TrimmedCurve(C12d,f[1],l[1]); | |
1080 | Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(S1); | |
1081 | Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C12d); | |
1082 | Adaptor3d_CurveOnSurface Cons(HC1,HS1); | |
1083 | HEdge1 = new Adaptor3d_HCurveOnSurface(Cons); | |
1084 | } | |
1085 | else { | |
1086 | C1 = new Geom_TrimmedCurve(C1, f[1], l[1]); | |
1087 | C1->Transform(Loc.Transformation()); | |
1088 | HEdge1 = new GeomAdaptor_HCurve(C1); | |
1089 | GeomAdaptor_Curve AC1(C1); | |
1090 | if ( AC1.GetType() == GeomAbs_Circle) { | |
1091 | C1Denerated = (AC1.Circle().Radius() < Precision::Confusion()); | |
1092 | } | |
1093 | } | |
1094 | ||
1095 | Handle(Geom_Curve) C2 = BRep_Tool::Curve(Edge2,Loc,f[2],l[2]); | |
1096 | ||
1097 | Handle(Adaptor3d_HCurve) HEdge2; | |
1098 | Standard_Boolean C2is3D = Standard_True; | |
1099 | if (C2.IsNull()) { | |
1100 | C2is3D = Standard_False; | |
1101 | Handle(Geom2d_Curve) C12d; | |
1102 | Handle(Geom_Surface) S1; | |
1103 | BRep_Tool::CurveOnSurface(Edge2,C12d,S1,Loc,f[2],l[2]); | |
1104 | S1 = Handle(Geom_Surface)::DownCast(S1->Transformed(Loc.Transformation())); | |
1105 | C12d = new Geom2d_TrimmedCurve(C12d,f[2],l[2]); | |
1106 | Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(S1); | |
1107 | Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C12d); | |
1108 | Adaptor3d_CurveOnSurface Cons(HC1,HS1); | |
1109 | HEdge2 = new Adaptor3d_HCurveOnSurface(Cons); | |
1110 | } | |
1111 | else { | |
1112 | C2 = new Geom_TrimmedCurve(C2, f[2], l[2]); | |
1113 | C2->Transform(Loc.Transformation()); | |
1114 | HEdge2 = new GeomAdaptor_HCurve(C2); | |
1115 | GeomAdaptor_Curve AC2(C2); | |
1116 | if ( AC2.GetType() == GeomAbs_Circle) { | |
1117 | C2Denerated = (AC2.Circle().Radius() < Precision::Confusion()); | |
1118 | } | |
1119 | } | |
1120 | ||
1121 | // Calcul du tuyau | |
1122 | GeomFill_Pipe Pipe(HCP, HEdge1, HEdge2, Abs(Offset)); | |
1123 | Pipe.Perform(Tol, Polynomial, Conti); | |
1124 | Standard_Real ErrorPipe = Pipe.ErrorOnSurf(); | |
1125 | ||
1126 | Handle(Geom_Surface) S = Pipe.Surface(); | |
1127 | Standard_Boolean ExchUV = Pipe.ExchangeUV(); | |
1128 | Standard_Real f1,l1,f2,l2; | |
1129 | S->Bounds(f1,l1,f2,l2); | |
1130 | ||
1131 | // Perform the face | |
1132 | Standard_Real PathTol = BRep_Tool::Tolerance(Path); | |
1133 | Standard_Real TheTol; | |
1134 | BRep_Builder myBuilder; | |
1135 | myBuilder.MakeFace(myFace); | |
1136 | TopLoc_Location Id; | |
1137 | myBuilder.UpdateFace(myFace,S,Id,PathTol); | |
1138 | ||
1139 | // update de Edge1. (Rem : has already a 3d curve) | |
1140 | Standard_Real U,U1,U2; | |
1141 | Handle(Geom2d_Curve) PC; | |
1142 | if ( ExchUV) { | |
1143 | PC = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)); | |
1144 | U1 = f1; | |
1145 | U2 = l1; | |
1146 | if (!C1is3D) C1 = S->VIso(f2); | |
1147 | } | |
1148 | else { | |
1149 | PC = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)); | |
1150 | U1 = f2; | |
1151 | U2 = l2; | |
1152 | if (!C1is3D) C1 = S->UIso(f1); | |
1153 | } | |
1154 | ||
1155 | Handle(Geom_Curve) Dummy; | |
1156 | if (!C1is3D) | |
1157 | UpdateEdge(Edge1,C1,Id,BRep_Tool::Tolerance(Edge1)); | |
1158 | else if ( C1Denerated) { | |
1159 | UpdateEdge(Edge1,Dummy,Id,BRep_Tool::Tolerance(Edge1)); | |
1160 | myBuilder.Degenerated(Edge1,Standard_True); | |
1161 | } | |
1162 | ||
1163 | TheTol = Max(PathTol, BRep_Tool::Tolerance(Edge1) + ErrorPipe); | |
1164 | UpdateEdge(Edge1, PC, myFace, TheTol); | |
1165 | ||
1166 | // mise a same range de la nouvelle pcurve. | |
1167 | if ( !C1is3D && !C1Denerated) | |
1168 | myBuilder.SameRange (Edge1,Standard_False); | |
1169 | if ( !C1is3D && !C1Denerated) | |
1170 | Range3d(Edge1,U1,U2); | |
1171 | myBuilder.Range (Edge1,myFace,U1,U2); | |
1172 | Range3d(Edge1,U1,U2); | |
1173 | myBuilder.Range (Edge1,myFace,U1,U2); | |
1174 | BRepLib::SameRange(Edge1); | |
1175 | ||
1176 | // mise a sameparameter pour les KPart | |
1177 | if (ErrorPipe == 0) { | |
1178 | TheTol = Max(TheTol, Tol); | |
1179 | myBuilder.SameParameter(Edge1,Standard_False); | |
1180 | BRepLib::SameParameter(Edge1, TheTol); | |
1181 | } | |
1182 | ||
1183 | // Update de edge2. (Rem : has already a 3d curve) | |
1184 | if (ExchUV) { | |
1185 | PC = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)); | |
1186 | U1 = f1; | |
1187 | U2 = l1; | |
1188 | if (!C2is3D) C2 = S->VIso(l2); | |
1189 | } | |
1190 | else { | |
1191 | PC = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)); | |
1192 | U1 = f2; | |
1193 | U2 = l2; | |
1194 | if (!C2is3D) C2 = S->UIso(l1); | |
1195 | } | |
1196 | ||
1197 | if (!C2is3D) | |
1198 | UpdateEdge(Edge2,C2,Id,BRep_Tool::Tolerance(Edge2)); | |
1199 | else if ( C2Denerated) { | |
1200 | UpdateEdge(Edge2,Dummy,Id,BRep_Tool::Tolerance(Edge2)); | |
1201 | myBuilder.Degenerated(Edge2,Standard_True); | |
1202 | } | |
1203 | ||
1204 | TheTol = Max(PathTol, BRep_Tool::Tolerance(Edge2) + ErrorPipe); | |
1205 | UpdateEdge(Edge2, PC, myFace, TheTol); | |
1206 | ||
1207 | // mise a same range de la nouvelle pcurve. | |
1208 | myBuilder.SameRange (Edge2,Standard_False); | |
1209 | if ( !C2is3D && !C2Denerated) Range3d(Edge2,U1,U2); | |
1210 | myBuilder.Range(Edge2,myFace,U1,U2); | |
1211 | BRepLib::SameRange(Edge2); | |
1212 | ||
1213 | // mise a sameparameter pour les KPart | |
1214 | if (ErrorPipe == 0) { | |
1215 | TheTol = Max(TheTol, Tol); | |
1216 | myBuilder.SameParameter(Edge2,Standard_False); | |
1217 | BRepLib::SameParameter(Edge2, TheTol); | |
1218 | } | |
1219 | ||
1220 | TopoDS_Edge Edge3, Edge4; | |
1221 | // eval edge3 | |
1222 | TopoDS_Vertex V1f,V1l,V2f,V2l; | |
1223 | TopExp::Vertices(Path,V1f,V1l); | |
1224 | Standard_Boolean IsClosed = ( V1f.IsSame(V1l)); | |
1225 | ||
1226 | TopExp::Vertices(Edge1,V1f,V1l); | |
1227 | TopExp::Vertices(Edge2,V2f,V2l); | |
1228 | ||
1229 | Standard_Boolean StartDegenerated = (V1f.IsSame(V2f)); | |
1230 | Standard_Boolean EndDegenerated = (V1l.IsSame(V2l)); | |
1231 | ||
1232 | Standard_Boolean E3rev = Standard_False; | |
1233 | Standard_Boolean E4rev = Standard_False; | |
1234 | ||
1235 | TopoDS_Vertex VVf,VVl; | |
1236 | if ( FirstEdge.IsNull()) { | |
1237 | myBuilder.MakeEdge(Edge3); | |
1238 | myBuilder.Add(Edge3,V1f.Oriented(TopAbs_FORWARD)); | |
1239 | myBuilder.Add(Edge3,V2f.Oriented(TopAbs_REVERSED)); | |
1240 | } | |
1241 | else { | |
1242 | TopoDS_Shape aLocalEdge = FirstEdge.Oriented(TopAbs_FORWARD); | |
1243 | Edge3 = TopoDS::Edge(aLocalEdge); | |
1244 | // Edge3 = TopoDS::Edge(FirstEdge.Oriented(TopAbs_FORWARD)); | |
1245 | TopExp::Vertices(Edge3,VVf,VVl); | |
63c629aa | 1246 | #ifdef BREPOFFSET_DEB |
7fd59977 | 1247 | // si firstedge n est pas nul, il faut que les vertex soient partages |
1248 | if ( !VVf.IsSame(V1f) && !VVf.IsSame(V2f) ) { | |
1249 | cout << "Attention Vertex non partages !!!!!!" << endl; | |
1250 | } | |
1251 | #endif | |
1252 | if ( !VVf.IsSame(V1f) && !VVf.IsSame(V2f) ) { | |
1253 | // On fait vraisemblablement des conneries !! | |
1254 | // On cree un autre edge, on appelle le Sewing apres. | |
1255 | myBuilder.MakeEdge(Edge3); | |
1256 | myBuilder.Add(Edge3,V1f.Oriented(TopAbs_FORWARD)); | |
1257 | myBuilder.Add(Edge3,V2f.Oriented(TopAbs_REVERSED)); | |
1258 | } | |
1259 | else if ( !VVf.IsSame(V1f)) { | |
1260 | Edge3.Reverse(); | |
1261 | E3rev = Standard_True; | |
1262 | } | |
1263 | } | |
1264 | ||
1265 | if ( IsClosed) | |
1266 | Edge4 = Edge3; | |
1267 | ||
1268 | Standard_Real TolApp = Precision::Approximation(); | |
1269 | ||
1270 | Handle(Geom2d_Line) L1,L2; | |
1271 | if ( IsClosed) { | |
1272 | if ( ExchUV) { | |
1273 | // rem : si ExchUv, il faut reverser le Wire. | |
1274 | // donc l'edge Forward dans la face sera E4 : d'ou L1 et L2 | |
1275 | L2 = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)); | |
1276 | L1 = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)); | |
1277 | U1 = f2; | |
1278 | U2 = l2; | |
1279 | } | |
1280 | else { | |
1281 | L1 = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)); | |
1282 | L2 = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)); | |
1283 | U1 = f1; | |
1284 | U2 = l1; | |
1285 | } | |
1286 | if ( E3rev) { | |
1287 | L1->Reverse(); L2->Reverse(); | |
1288 | U = -U1; | |
1289 | U1 = -U2; | |
1290 | U2 = U; | |
1291 | } | |
1292 | UpdateEdge(Edge3, L1, L2, myFace,PathTol); | |
1293 | myBuilder.Range(Edge3,myFace,U1,U2); | |
1294 | if (StartDegenerated) | |
1295 | myBuilder.Degenerated(Edge3,Standard_True); | |
1296 | else if (FirstEdge.IsNull()) // then the 3d curve has not been yet computed | |
1297 | ComputeCurve3d(Edge3,L1,S,Id,TolApp); | |
1298 | } | |
1299 | else { | |
1300 | if ( LastEdge.IsNull()) { | |
1301 | myBuilder.MakeEdge(Edge4); | |
1302 | myBuilder.Add(Edge4,V1l.Oriented(TopAbs_FORWARD)); | |
1303 | myBuilder.Add(Edge4,V2l.Oriented(TopAbs_REVERSED)); | |
1304 | } | |
1305 | else { | |
1306 | TopoDS_Shape aLocalEdge = LastEdge.Oriented(TopAbs_FORWARD); | |
1307 | Edge4 = TopoDS::Edge(aLocalEdge); | |
1308 | // Edge4 = TopoDS::Edge(LastEdge.Oriented(TopAbs_FORWARD)); | |
1309 | TopExp::Vertices(Edge4,VVf,VVl); | |
63c629aa | 1310 | #ifdef BREPOFFSET_DEB |
7fd59977 | 1311 | // si lastedge n est pas nul, il faut que les vertex soient partages |
1312 | if ( !VVf.IsSame(V1l) && !VVf.IsSame(V2l) ) { | |
1313 | cout << "Attention Vertex non partages !!!!!!" << endl; | |
1314 | } | |
1315 | #endif | |
1316 | if ( !VVf.IsSame(V1l) && !VVf.IsSame(V2l) ) { | |
1317 | // On fait vraisemblablement des conneries !! | |
1318 | // On cree un autre edge, on appelle le Sewing apres. | |
1319 | myBuilder.MakeEdge(Edge4); | |
1320 | myBuilder.Add(Edge4,V1l.Oriented(TopAbs_FORWARD)); | |
1321 | myBuilder.Add(Edge4,V2l.Oriented(TopAbs_REVERSED)); | |
1322 | } | |
1323 | else if ( !VVf.IsSame(V1l)) { | |
1324 | Edge4.Reverse(); | |
1325 | E4rev = Standard_True; | |
1326 | } | |
1327 | } | |
1328 | ||
1329 | if (ExchUV) { | |
1330 | L1 = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)); | |
1331 | U1 = f2; | |
1332 | U2 = l2; | |
1333 | } | |
1334 | else { | |
1335 | L1 = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)); | |
1336 | U1 = f1; | |
1337 | U2 = l1; | |
1338 | } | |
1339 | if ( E3rev) { | |
1340 | L1->Reverse(); | |
1341 | U = -U1; | |
1342 | U1 = -U2; | |
1343 | U2 = U; | |
1344 | } | |
1345 | UpdateEdge(Edge3,L1,myFace,PathTol); | |
1346 | myBuilder.Range(Edge3,myFace,U1,U2); | |
1347 | if (StartDegenerated) | |
1348 | myBuilder.Degenerated(Edge3,Standard_True); | |
1349 | else if (FirstEdge.IsNull()) // then the 3d curve has not been yet computed | |
1350 | ComputeCurve3d(Edge3,L1,S,Id,TolApp); | |
1351 | ||
1352 | if (ExchUV) { | |
1353 | L2 = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)); | |
1354 | U1 = f2; | |
1355 | U2 = l2; | |
1356 | } | |
1357 | else { | |
1358 | L2 = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)); | |
1359 | U1 = f1; | |
1360 | U2 = l1; | |
1361 | } | |
1362 | if ( E4rev) { | |
1363 | L2->Reverse(); | |
1364 | U = -U1; | |
1365 | U1 = -U2; | |
1366 | U2 = U; | |
1367 | } | |
1368 | UpdateEdge(Edge4,L2 ,myFace,PathTol); | |
1369 | myBuilder.Range(Edge4,myFace,U1,U2); | |
1370 | if (EndDegenerated) | |
1371 | myBuilder.Degenerated(Edge4,Standard_True); | |
1372 | else if (LastEdge.IsNull()) // then the 3d curve has not been yet computed | |
1373 | ComputeCurve3d(Edge4,L2,S,Id,TolApp); | |
1374 | } | |
1375 | ||
1376 | // SameParameter ?? | |
1377 | if ( !FirstEdge.IsNull() && !StartDegenerated) { | |
1378 | BRepLib::BuildCurve3d (Edge3,PathTol); | |
1379 | myBuilder.SameRange (Edge3,Standard_False); | |
1380 | myBuilder.SameParameter(Edge3,Standard_False); | |
1381 | BRepLib::SameParameter (Edge3, Tol); | |
1382 | } | |
1383 | if ( !LastEdge.IsNull() && !EndDegenerated) { | |
1384 | BRepLib::BuildCurve3d (Edge4,PathTol); | |
1385 | myBuilder.SameRange (Edge4,Standard_False); | |
1386 | myBuilder.SameParameter(Edge4,Standard_False); | |
1387 | BRepLib::SameParameter (Edge4, Tol); | |
1388 | } | |
1389 | ||
1390 | TopoDS_Wire W; | |
1391 | myBuilder.MakeWire(W); | |
1392 | ||
1393 | myBuilder.Add(W, Edge1.Oriented(TopAbs_REVERSED)); | |
1394 | myBuilder.Add(W, Edge2.Oriented(TopAbs_FORWARD)); | |
1395 | myBuilder.Add(W, Edge4.Reversed()); | |
1396 | myBuilder.Add(W, Edge3); | |
1397 | ||
1398 | if (ExchUV) { | |
1399 | W.Reverse(); | |
1400 | } | |
1401 | ||
1402 | myBuilder.Add(myFace, W); | |
1403 | if (ExchUV) myFace.Reverse(); | |
1404 | ||
1405 | BRepTools::Update(myFace); | |
1406 | ||
1407 | if ( Edge1.Orientation() == TopAbs_REVERSED) | |
1408 | myFace.Reverse(); | |
1409 | ||
1410 | } | |
1411 | ||
1412 | ||
1413 | //======================================================================= | |
1414 | //function : Init | |
1415 | //purpose : | |
1416 | //======================================================================= | |
1417 | ||
1418 | void BRepOffset_Offset::Init(const TopoDS_Vertex& Vertex, | |
1419 | const TopTools_ListOfShape& LEdge, | |
1420 | const Standard_Real Offset, | |
1421 | const Standard_Boolean Polynomial, | |
1422 | const Standard_Real TolApp, | |
1423 | const GeomAbs_Shape Conti) | |
1424 | { | |
1425 | myStatus = BRepOffset_Good; | |
1426 | myShape = Vertex; | |
1427 | ||
1428 | // evaluate the Ax3 of the Sphere | |
1429 | // find 3 different vertices in LEdge | |
1430 | TopTools_ListIteratorOfListOfShape it; | |
1431 | gp_Pnt P, P1, P2, P3; | |
1432 | TopoDS_Vertex V1, V2, V3, V4; | |
1433 | ||
1434 | ||
1435 | #ifdef DEB | |
1436 | char* name = new char[100]; | |
1437 | if (Affich) { | |
1438 | NbOFFSET++; | |
1439 | ||
1440 | sprintf(name,"VOnSph_%d",NbOFFSET); | |
1441 | #ifdef DRAW | |
1442 | DBRep::Set(name, Vertex); | |
1443 | #endif | |
1444 | Standard_Integer NbEdges = 1; | |
1445 | for (it.Initialize(LEdge); it.More(); it.Next()) { | |
7fd59977 | 1446 | sprintf(name,"EOnSph_%d_%d",NbOFFSET,NbEdges++); |
1447 | #ifdef DRAW | |
1448 | DBRep::Set(name, CurE); | |
1449 | #endif | |
1450 | } | |
1451 | ||
1452 | } | |
1453 | #endif | |
1454 | ||
d804b26d | 1455 | gp_Pnt Origin = BRep_Tool::Pnt(Vertex); |
7fd59977 | 1456 | |
d804b26d | 1457 | //// Find the axis of the sphere to exclude |
1458 | //// degenerated and seam edges from the face under construction | |
1459 | BRepLib_MakeWire MW; | |
1460 | MW.Add(LEdge); | |
1461 | TopoDS_Wire theWire = MW.Wire(); | |
7fd59977 | 1462 | |
d804b26d | 1463 | ShapeFix_Shape Fixer(theWire); |
1464 | Fixer.Perform(); | |
1465 | theWire = TopoDS::Wire(Fixer.Shape()); | |
7fd59977 | 1466 | |
d804b26d | 1467 | GProp_GProps GlobalProps; |
1468 | BRepGProp::LinearProperties(theWire, GlobalProps); | |
1469 | gp_Pnt BaryCenter = GlobalProps.CentreOfMass(); | |
1470 | gp_Vec Xdir(BaryCenter, Origin); | |
1471 | ||
1472 | gp_Pnt FarestCorner = GetFarestCorner(theWire); | |
1473 | gp_Pln thePlane = gce_MakePln(Origin, BaryCenter, FarestCorner); | |
1474 | gp_Dir Vdir = thePlane.Axis().Direction(); | |
7fd59977 | 1475 | |
d804b26d | 1476 | gp_Ax3 Axis(Origin, Vdir, Xdir); |
1477 | ||
7fd59977 | 1478 | Handle(Geom_Surface) S |
1479 | = new Geom_SphericalSurface( Axis, Abs(Offset)); | |
1480 | ||
1481 | Standard_Real f, l, Tol = BRep_Tool::Tolerance(Vertex); | |
1482 | ||
1483 | TopLoc_Location Loc; | |
1484 | BRep_Builder myBuilder; | |
1485 | myBuilder.MakeFace(myFace); | |
1486 | Handle(Geom_Surface) SS = S; | |
1487 | ||
1488 | // En polynomial, calcul de la surface par F(u,v). | |
1489 | // Pas de changement de parametre, donc ProjLib sur la Sphere | |
1490 | // reste OK. | |
1491 | if (Polynomial) { | |
1492 | GeomConvert_ApproxSurface Approx(S,TolApp,Conti,Conti,10,10,10,1); | |
1493 | if (Approx.IsDone()) { | |
1494 | SS = Approx.Surface(); | |
1495 | } | |
1496 | } | |
1497 | ||
1498 | myBuilder.UpdateFace(myFace, SS, Loc, Tol); | |
1499 | ||
1500 | TopoDS_Wire W; | |
1501 | myBuilder.MakeWire(W); | |
1502 | ||
1503 | #ifdef DRAW | |
1504 | // POP pour NT | |
1505 | // char name[100]; | |
1506 | if (Affich) { | |
1507 | sprintf(name,"SPHERE_%d",NbOFFSET); | |
1508 | DrawTrSurf::Set(name, S); | |
1509 | } | |
1510 | Standard_Integer CO = 1; | |
1511 | #endif | |
1512 | ||
1513 | for ( it.Initialize(LEdge); it.More(); it.Next()) { | |
1514 | TopoDS_Edge E = TopoDS::Edge(it.Value()); | |
1515 | ||
1516 | Handle(Geom_Curve) C = BRep_Tool::Curve(E,Loc,f,l); | |
1517 | if ( C.IsNull()) { | |
1518 | BRepLib::BuildCurve3d(E,BRep_Tool::Tolerance(E)); | |
1519 | C = BRep_Tool::Curve(E,Loc,f,l); | |
1520 | } | |
1521 | C = new Geom_TrimmedCurve(C, f, l); | |
1522 | C->Transform(Loc.Transformation()); | |
1523 | ||
1524 | #ifdef DRAW | |
1525 | if ( Affich) { | |
1526 | sprintf(name,"CURVE_%d_%d",NbOFFSET,CO); | |
1527 | DrawTrSurf::Set(name, C); | |
1528 | CO++; | |
1529 | } | |
1530 | #endif | |
1531 | ||
1532 | Handle(Geom2d_Curve) PCurve = GeomProjLib::Curve2d(C, S); | |
1533 | // check if the first point of PCurve in is the canonical boundaries | |
1534 | // of the sphere. Else move it. | |
1535 | // the transformation is : U` = U + PI + 2 k PI | |
1536 | // V` = +/- PI + 2 k` PI | |
1537 | gp_Pnt2d P2d = PCurve->Value(f); | |
1538 | Standard_Boolean IsToAdjust = Standard_False; | |
c6541a0c | 1539 | if ( P2d.Y() < -M_PI/2.) { |
7fd59977 | 1540 | IsToAdjust = Standard_True; |
c6541a0c | 1541 | PCurve->Mirror(gp_Ax2d(gp_Pnt2d(0.,-M_PI/2.),gp::DX2d())); |
7fd59977 | 1542 | } |
c6541a0c | 1543 | else if ( P2d.Y() > M_PI/2.) { |
7fd59977 | 1544 | IsToAdjust = Standard_True; |
c6541a0c | 1545 | PCurve->Mirror(gp_Ax2d(gp_Pnt2d(0., M_PI/2.),gp::DX2d())); |
7fd59977 | 1546 | } |
1547 | if ( IsToAdjust) { | |
1548 | // set the u firstpoint in [0,2*pi] | |
c6541a0c D |
1549 | gp_Vec2d Tr( M_PI, 0.); |
1550 | if ( P2d.X() > M_PI) Tr.Reverse(); | |
7fd59977 | 1551 | PCurve->Translate(Tr); |
1552 | } | |
1553 | ||
1554 | UpdateEdge(E, PCurve, myFace, Tol); | |
1555 | myBuilder.Range(E, myFace, f, l); | |
1556 | myBuilder.Add(W, E); | |
1557 | } | |
1558 | if ( Offset < 0.) { | |
1559 | myBuilder.Add(myFace, W.Oriented(TopAbs_REVERSED)); | |
1560 | myFace.Reverse(); | |
1561 | } | |
1562 | else { | |
1563 | myBuilder.Add(myFace, W); | |
1564 | } | |
1565 | ||
1566 | BRepTools::Update(myFace); | |
1567 | } | |
1568 | ||
1569 | ||
1570 | //======================================================================= | |
1571 | //function : Init | |
1572 | //purpose : | |
1573 | //======================================================================= | |
1574 | ||
1575 | void BRepOffset_Offset::Init(const TopoDS_Edge& Edge, | |
1576 | const Standard_Real Offset) | |
1577 | { | |
1578 | myShape = Edge; | |
1579 | Standard_Real myOffset = Abs(Offset); | |
1580 | ||
1581 | Standard_Real f,l; | |
1582 | TopLoc_Location Loc; | |
1583 | ||
1584 | Handle(Geom_Curve) CP = BRep_Tool::Curve(Edge,Loc,f,l); | |
1585 | CP = new Geom_TrimmedCurve(CP,f,l); | |
1586 | CP->Transform(Loc.Transformation()); | |
1587 | ||
1588 | GeomFill_Pipe Pipe(CP,myOffset); | |
1589 | Pipe.Perform(); | |
1590 | ||
1c72dff6 | 1591 | BRepLib_MakeFace MF(Pipe.Surface(), Precision::Confusion()); |
7fd59977 | 1592 | myFace = MF.Face(); |
1593 | ||
1594 | if ( Offset < 0.) myFace.Reverse(); | |
1595 | } | |
1596 | ||
1597 | ||
1598 | //======================================================================= | |
1599 | //function : Face | |
1600 | //purpose : | |
1601 | //======================================================================= | |
1602 | ||
1603 | const TopoDS_Face& BRepOffset_Offset::Face() const | |
1604 | { | |
1605 | return myFace; | |
1606 | } | |
1607 | ||
1608 | ||
1609 | //======================================================================= | |
1610 | //function : Generated | |
1611 | //purpose : | |
1612 | //======================================================================= | |
1613 | ||
1614 | TopoDS_Shape BRepOffset_Offset::Generated(const TopoDS_Shape& Shape) const | |
1615 | { | |
1616 | TopoDS_Shape aShape; | |
1617 | ||
1618 | switch ( myShape.ShapeType()) { | |
1619 | ||
1620 | case TopAbs_FACE: | |
1621 | { | |
1622 | TopExp_Explorer exp (myShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE); | |
1623 | TopExp_Explorer expo(myFace .Oriented(TopAbs_FORWARD), TopAbs_EDGE); | |
1624 | for ( ; exp.More() && expo.More(); exp.Next(), expo.Next()) { | |
1625 | if ( Shape.IsSame(exp.Current())) { | |
1626 | if ( myShape.Orientation() == TopAbs_REVERSED) | |
1627 | aShape = expo.Current().Reversed(); | |
1628 | else | |
1629 | aShape = expo.Current(); | |
1630 | } | |
1631 | } | |
1632 | } | |
1633 | break; | |
1634 | ||
1635 | case TopAbs_EDGE: | |
1636 | // have generate a pipe. | |
1637 | { | |
1638 | TopoDS_Vertex V1, V2; | |
1639 | TopExp::Vertices(TopoDS::Edge(myShape), V1, V2); | |
1640 | ||
1641 | TopExp_Explorer expf(myFace .Oriented(TopAbs_FORWARD), TopAbs_WIRE); | |
1642 | TopExp_Explorer expo(expf.Current().Oriented(TopAbs_FORWARD), | |
1643 | TopAbs_EDGE); | |
1644 | expo.Next(); | |
1645 | expo.Next(); | |
1646 | ||
1647 | if ( V2.IsSame(Shape)) { | |
1648 | if ( expf.Current().Orientation() == TopAbs_REVERSED) | |
1649 | aShape = expo.Current().Reversed(); | |
1650 | else | |
1651 | aShape = expo.Current(); | |
1652 | } | |
1653 | else { | |
1654 | expo.Next(); | |
1655 | if ( expf.Current().Orientation() == TopAbs_REVERSED) | |
1656 | aShape = expo.Current().Reversed(); | |
1657 | else | |
1658 | aShape = expo.Current(); | |
1659 | } | |
1660 | if ( myFace.Orientation() == TopAbs_REVERSED) | |
1661 | aShape.Reverse(); | |
1662 | } | |
1663 | break; | |
7fd59977 | 1664 | default: |
1665 | break; | |
7fd59977 | 1666 | } |
1667 | ||
1668 | return aShape; | |
1669 | } | |
1670 | ||
1671 | ||
1672 | //======================================================================= | |
1673 | //function : Status | |
1674 | //purpose : | |
1675 | //======================================================================= | |
1676 | ||
1677 | BRepOffset_Status BRepOffset_Offset::Status() const | |
1678 | { | |
1679 | return myStatus; | |
1680 | } | |
1681 | ||
1682 | ||
1683 |