7fd59977 |
1 | // File: BRepOffset_Tool.cxx |
2 | // Created: Mon Oct 23 14:25:07 1995 |
3 | // Author: Yves FRICAUD |
4 | // <yfr@stylox> |
5 | |
6 | #include <stdio.h> |
7 | |
8 | #include <BRepOffset_Tool.ixx> |
9 | |
10 | #include <BRepAlgo_Tool.hxx> |
11 | |
12 | #include <BRepAdaptor_Curve.hxx> |
13 | #include <BRepAdaptor_Surface.hxx> |
14 | #include <BRepAdaptor_HCurve.hxx> |
15 | #include <BRepAdaptor_HSurface.hxx> |
16 | |
17 | #include <BRepBndLib.hxx> |
18 | |
19 | #include <Bnd_Box2d.hxx> |
20 | #include <BndLib_Add3dCurve.hxx> |
21 | #include <BRep_Tool.hxx> |
22 | #include <BRepLib.hxx> |
23 | #include <BRepLib_MakeEdge.hxx> |
24 | #include <BRepLib_MakeVertex.hxx> |
25 | #include <BRepLib_MakePolygon.hxx> |
26 | #include <BRepLib_MakeFace.hxx> |
27 | #include <BRepLib_MakeWire.hxx> |
28 | #include <BRepTools.hxx> |
29 | #include <BRepTools_WireExplorer.hxx> |
30 | |
31 | #include <BRepTools_Modifier.hxx> |
32 | #include <BRepTools_TrsfModification.hxx> |
33 | #include <BRepTopAdaptor_FClass2d.hxx> |
34 | #include <BRepAdaptor_Curve.hxx> |
35 | #include <BRepAdaptor_Curve2d.hxx> |
36 | |
37 | #include <IntRes2d_IntersectionPoint.hxx> |
38 | #include <IntRes2d_IntersectionSegment.hxx> |
39 | #include <Extrema_ExtPC.hxx> |
40 | |
41 | #include <TopExp.hxx> |
42 | #include <TopExp_Explorer.hxx> |
43 | #include <TopAbs.hxx> |
44 | #include <Standard_ConstructionError.hxx> |
45 | |
46 | #include <TopOpeBRepBuild_Builder.hxx> |
47 | #include <TopOpeBRepDS_HDataStructure.hxx> |
48 | #include <TopOpeBRepDS_CurveExplorer.hxx> |
49 | #include <TopOpeBRep_DSFiller.hxx> |
50 | #include <TopOpeBRepTool_GeomTool.hxx> |
51 | #include <TopOpeBRep_ShapeIntersector.hxx> |
52 | #include <TopOpeBRep_FacesFiller.hxx> |
53 | #include <TopOpeBRep_GeomTool.hxx> |
54 | #include <TopoDS.hxx> |
55 | #include <TopoDS_Iterator.hxx> |
56 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
57 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
58 | |
59 | #include <Geom_Surface.hxx> |
60 | #include <Geom_RectangularTrimmedSurface.hxx> |
61 | #include <Geom_OffsetSurface.hxx> |
62 | #include <Geom_BezierSurface.hxx> |
63 | #include <Geom_BSplineSurface.hxx> |
64 | #include <Geom_ConicalSurface.hxx> |
65 | #include <Geom_Curve.hxx> |
66 | #include <Geom_Line.hxx> |
67 | #include <Geom_Conic.hxx> |
68 | #include <Geom_TrimmedCurve.hxx> |
69 | #include <GCPnts_QuasiUniformDeflection.hxx> |
70 | |
71 | #include <GeomLib.hxx> |
72 | #include <GeomAPI.hxx> |
73 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
74 | #include <Geom2d_TrimmedCurve.hxx> |
75 | #include <Geom2d_Line.hxx> |
76 | #include <Geom2d_Curve.hxx> |
77 | #include <Geom2d_Circle.hxx> |
78 | #include <Geom2d_Ellipse.hxx> |
79 | #include <Geom2d_Parabola.hxx> |
80 | #include <Geom2d_Hyperbola.hxx> |
81 | #include <Geom2d_BezierCurve.hxx> |
82 | #include <Geom2d_BSplineCurve.hxx> |
83 | |
84 | #include <Geom2dAdaptor_Curve.hxx> |
85 | #include <Geom2dInt_GInter.hxx> |
86 | |
87 | #include <GeomAdaptor_Surface.hxx> |
88 | #include <GeomProjLib.hxx> |
89 | #include <GeomInt_IntSS.hxx> |
90 | #include <ProjLib_ProjectedCurve.hxx> |
91 | #include <ProjLib_HProjectedCurve.hxx> |
92 | |
93 | #include <ElSLib.hxx> |
94 | #include <ElCLib.hxx> |
95 | |
96 | #include <gp.hxx> |
97 | #include <gp_Pnt.hxx> |
98 | #include <gp_Vec.hxx> |
99 | |
100 | |
101 | #include <Precision.hxx> |
102 | #include <Standard_ConstructionError.hxx> |
103 | |
104 | #include <BRep_TEdge.hxx> |
105 | #include <Extrema_ExtPC2d.hxx> |
106 | |
107 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
108 | #include <Geom_SurfaceOfRevolution.hxx> |
109 | #include <GCPnts_AbscissaPoint.hxx> |
110 | |
111 | //tma: for new boolean operation |
112 | #include <TopTools_SequenceOfShape.hxx> |
113 | #include <BOPTools_DSFiller.hxx> |
114 | #include <Geom_BSplineCurve.hxx> |
115 | #include <GeomConvert_CompCurveToBSplineCurve.hxx> |
116 | #include <Geom2dConvert_CompCurveToBSplineCurve.hxx> |
117 | #include <GeomConvert_ApproxCurve.hxx> |
118 | #include <Geom2dConvert_ApproxCurve.hxx> |
119 | //#include <BRepAlgoAPI_Section.hxx> |
120 | #include <BooleanOperations_ShapesDataStructure.hxx> |
121 | #include <BOPTools_InterferencePool.hxx> |
122 | #include <BOPTools_SSInterference.hxx> |
123 | #include <BOPTools_SequenceOfCurves.hxx> |
124 | #include <BOPTools_Curve.hxx> |
125 | #include <BOPTools_ListOfPaveBlock.hxx> |
126 | #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx> |
127 | #include <BOPTools_PaveBlock.hxx> |
128 | #include <BRepAlgoAPI_Section.hxx> |
129 | #include <BOPTools_SSIntersectionAttribute.hxx> |
130 | #include <BOPTools_PaveFiller.hxx> |
131 | #include <BOPTools_Tools2D.hxx> |
132 | #include <BOPTools_ListIteratorOfListOfPave.hxx> |
133 | #include <TopoDS_Compound.hxx> |
134 | #include <GCPnts_UniformAbscissa.hxx> |
135 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
136 | #include <BRep_CurveRepresentation.hxx> |
137 | |
138 | #include <BRepOffset_ListOfInterval.hxx> |
139 | #include <BRepOffset_Interval.hxx> |
140 | #include <TColgp_Array1OfPnt2d.hxx> |
141 | #include <ShapeCustom_Curve2d.hxx> |
142 | #include <GeomAPI_ExtremaCurveCurve.hxx> |
143 | |
144 | |
145 | #ifdef DRAW |
146 | #include <DBRep.hxx> |
147 | #endif |
148 | |
149 | #ifdef DEB |
150 | Standard_Boolean AffichInter = Standard_False; |
151 | static Standard_Boolean AffichExtent = Standard_False; |
152 | static Standard_Integer NbNewEdges = 1; |
153 | static Standard_Integer NbFaces = 1; |
154 | static Standard_Integer NbFOB = 1; |
155 | static Standard_Integer NbFTE = 1; |
156 | static Standard_Integer NbExtE = 1; |
157 | //POP pour NT |
158 | //char* name = new char[100]; |
159 | #endif |
160 | |
161 | |
162 | //======================================================================= |
163 | //function : EdgeVertices |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | void BRepOffset_Tool::EdgeVertices (const TopoDS_Edge& E, |
168 | TopoDS_Vertex& V1, |
169 | TopoDS_Vertex& V2) |
170 | { |
171 | if (E.Orientation() == TopAbs_REVERSED) { |
172 | TopExp::Vertices(E,V2,V1); |
173 | } |
174 | else { |
175 | TopExp::Vertices(E,V1,V2); |
176 | } |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : OriEdgeInFace |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | TopAbs_Orientation BRepOffset_Tool::OriEdgeInFace (const TopoDS_Edge& E, |
185 | const TopoDS_Face& F ) |
186 | |
187 | { |
188 | #ifdef DEB |
189 | TopAbs_Orientation O = |
190 | #endif |
191 | F.Orientation(); |
192 | TopExp_Explorer Exp; |
193 | Exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
194 | |
195 | for (; Exp.More() ;Exp.Next()) { |
196 | if (Exp.Current().IsSame(E)) { |
197 | return Exp.Current().Orientation(); |
198 | } |
199 | } |
200 | Standard_ConstructionError::Raise("BRepOffset_Tool::OriEdgeInFace"); |
201 | return E.Orientation(); |
202 | } |
203 | |
204 | |
205 | //======================================================================= |
206 | //function : FindPeriod |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | static void FindPeriod (const TopoDS_Face& F, |
211 | Standard_Real& umin, |
212 | Standard_Real& umax, |
213 | Standard_Real& vmin, |
214 | Standard_Real& vmax) |
215 | { |
216 | |
217 | Bnd_Box2d B; |
218 | TopExp_Explorer exp; |
219 | for (exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next()) { |
220 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); |
221 | |
222 | Standard_Real pf,pl; |
223 | const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl); |
224 | if (C.IsNull()) return; |
225 | Geom2dAdaptor_Curve PC(C,pf,pl); |
226 | Standard_Real i, nbp = 20; |
227 | if (PC.GetType() == GeomAbs_Line) nbp = 2; |
228 | Standard_Real step = (pl - pf) / nbp; |
229 | gp_Pnt2d P; |
230 | PC.D0(pf,P); |
231 | B.Add(P); |
232 | for (i = 2; i < nbp; i++) { |
233 | pf += step; |
234 | PC.D0(pf,P); |
235 | B.Add(P); |
236 | } |
237 | PC.D0(pl,P); |
238 | B.Add(P); |
239 | B.Get(umin,vmin,umax,vmax); |
240 | } |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : PutInBounds |
245 | //purpose : Recadre la courbe 2d dans les bounds de la face |
246 | //======================================================================= |
247 | |
248 | static void PutInBounds (const TopoDS_Face& F, |
249 | const TopoDS_Edge& E, |
250 | Handle(Geom2d_Curve)& C2d) |
251 | { |
252 | Standard_Real umin,umax,vmin,vmax; |
253 | Standard_Real f,l; |
254 | BRep_Tool::Range(E,f,l); |
255 | |
256 | TopLoc_Location L; // Recup S avec la location pour eviter la copie. |
257 | Handle (Geom_Surface) S = BRep_Tool::Surface(F,L); |
258 | |
259 | if (S->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { |
260 | S = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface(); |
261 | } |
262 | //--------------- |
263 | // Recadre en U. |
264 | //--------------- |
265 | if (!S->IsUPeriodic() && !S->IsVPeriodic()) return; |
266 | |
267 | FindPeriod (F,umin,umax,vmin,vmax); |
268 | |
269 | if (S->IsUPeriodic()) { |
270 | Standard_Real period = S->UPeriod(); |
271 | Standard_Real eps = period*1.e-6; |
272 | gp_Pnt2d Pf = C2d->Value(f); |
273 | gp_Pnt2d Pl = C2d->Value(l); |
274 | gp_Pnt2d Pm = C2d->Value(0.34*f + 0.66*l); |
275 | Standard_Real minC = Min(Pf.X(),Pl.X()); minC = Min(minC,Pm.X()); |
276 | Standard_Real maxC = Max(Pf.X(),Pl.X()); maxC = Max(maxC,Pm.X()); |
277 | Standard_Real du = 0.; |
278 | if (minC< umin - eps) { |
279 | du = (int((umin - minC)/period) + 1)*period; |
280 | } |
281 | if (minC > umax + eps) { |
282 | du = -(int((minC - umax)/period) + 1)*period; |
283 | } |
284 | if (du != 0) { |
285 | gp_Vec2d T1(du,0.); |
286 | C2d->Translate(T1); |
287 | minC += du; maxC += du; |
288 | } |
289 | // Ajuste au mieux la courbe dans le domaine. |
290 | if (maxC > umax +100*eps) { |
291 | Standard_Real d1 = maxC - umax; |
292 | Standard_Real d2 = umin - minC + period; |
293 | if (d2 < d1) du =-period; |
294 | if ( du != 0.) { |
295 | gp_Vec2d T2(du,0.); |
296 | C2d->Translate(T2); |
297 | } |
298 | } |
299 | } |
300 | //------------------ |
301 | // Recadre en V. |
302 | //------------------ |
303 | if (S->IsVPeriodic()) { |
304 | Standard_Real period = S->VPeriod(); |
305 | Standard_Real eps = period*1.e-6; |
306 | gp_Pnt2d Pf = C2d->Value(f); |
307 | gp_Pnt2d Pl = C2d->Value(l); |
308 | gp_Pnt2d Pm = C2d->Value(0.34*f + 0.66*l); |
309 | Standard_Real minC = Min(Pf.Y(),Pl.Y()); minC = Min(minC,Pm.Y()); |
310 | Standard_Real maxC = Max(Pf.Y(),Pl.Y()); maxC = Max(maxC,Pm.Y()); |
311 | Standard_Real dv = 0.; |
312 | if (minC< vmin - eps) { |
313 | dv = (int((vmin - minC)/period) + 1)*period; |
314 | } |
315 | if (minC > vmax + eps) { |
316 | dv = -(int((minC - vmax)/period) + 1)*period; |
317 | } |
318 | if (dv != 0) { |
319 | gp_Vec2d T1(0.,dv); |
320 | C2d->Translate(T1); |
321 | minC += dv; maxC += dv; |
322 | } |
323 | // Ajuste au mieux la courbe dans le domaine. |
324 | if (maxC > vmax +100*eps) { |
325 | Standard_Real d1 = maxC - vmax; |
326 | Standard_Real d2 = vmin - minC + period; |
327 | if (d2 < d1) dv =-period; |
328 | if ( dv != 0.) { |
329 | gp_Vec2d T2(0.,dv); |
330 | C2d->Translate(T2); |
331 | } |
332 | } |
333 | } |
334 | } |
335 | |
336 | //======================================================================= |
337 | //function : Gabarit |
338 | //purpose : |
339 | //======================================================================= |
340 | |
341 | Standard_Real BRepOffset_Tool::Gabarit(const Handle(Geom_Curve)& aCurve) |
342 | { |
343 | GeomAdaptor_Curve GC( aCurve ); |
344 | Bnd_Box aBox; |
345 | BndLib_Add3dCurve::Add( GC, Precision::Confusion(), aBox ); |
346 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dist; |
347 | aBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax ); |
348 | dist = Max( (aXmax-aXmin), (aYmax-aYmin) ); |
349 | dist = Max( dist, (aZmax-aZmin) ); |
350 | return dist; |
351 | } |
352 | |
353 | //======================================================================= |
354 | //function : BuildPCurves |
355 | //purpose : |
356 | //======================================================================= |
357 | |
358 | static void BuildPCurves (const TopoDS_Edge& E, |
359 | const TopoDS_Face& F) |
360 | { |
361 | Standard_Real ff,ll; |
362 | Handle (Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface (E,F,ff,ll); |
363 | if (!C2d.IsNull()) return; |
364 | |
365 | //Standard_Real Tolerance = Max(Precision::Confusion(),BRep_Tool::Tolerance(E)); |
366 | Standard_Real Tolerance = Precision::Confusion(); |
367 | |
368 | BRepAdaptor_Surface AS(F,0); |
369 | BRepAdaptor_Curve AC(E); |
370 | |
371 | //Try to find pcurve on a bound of BSpline or Bezier surface |
372 | Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( F ); |
373 | Handle( Standard_Type ) typS = theSurf->DynamicType(); |
374 | if (typS == STANDARD_TYPE(Geom_OffsetSurface)) |
375 | typS = (*((Handle(Geom_OffsetSurface)*)&theSurf))->BasisSurface()->DynamicType(); |
376 | if (typS == STANDARD_TYPE(Geom_BezierSurface) || typS == STANDARD_TYPE(Geom_BSplineSurface)) |
377 | { |
378 | gp_Pnt fpoint = AC.Value( AC.FirstParameter() ); |
379 | gp_Pnt lpoint = AC.Value( AC.LastParameter() ); |
1c72dff6 |
380 | TopoDS_Face theFace = BRepLib_MakeFace( theSurf, Precision::Confusion() ); |
7fd59977 |
381 | Standard_Real U1 = 0., U2 = 0., TolProj = 1.e-4; //1.e-5; |
382 | TopoDS_Edge theEdge; |
383 | TopExp_Explorer Explo; |
384 | Explo.Init( theFace, TopAbs_EDGE ); |
385 | for (; Explo.More(); Explo.Next()) |
386 | { |
387 | TopoDS_Edge anEdge = TopoDS::Edge( Explo.Current() ); |
388 | BRepAdaptor_Curve aCurve( anEdge ); |
389 | Extrema_ExtPC fextr( fpoint, aCurve ); |
390 | if (!fextr.IsDone() || fextr.NbExt() < 1) |
391 | continue; |
392 | Standard_Real dist2, dist2min = RealLast(); |
393 | Standard_Integer i; |
394 | for (i = 1; i <= fextr.NbExt(); i++) |
395 | { |
396 | dist2 = fextr.SquareDistance(i); |
397 | if (dist2 < dist2min) |
398 | { |
399 | dist2min = dist2; |
400 | U1 = fextr.Point(i).Parameter(); |
401 | } |
402 | } |
403 | if (dist2min > TolProj * TolProj) |
404 | continue; |
405 | Extrema_ExtPC lextr( lpoint, aCurve ); |
406 | if (!lextr.IsDone() || lextr.NbExt() <1) |
407 | continue; |
408 | dist2min = RealLast(); |
409 | for (i = 1; i <= lextr.NbExt(); i++) |
410 | { |
411 | dist2 = lextr.SquareDistance(i); |
412 | if (dist2 < dist2min) |
413 | { |
414 | dist2min = dist2; |
415 | U2 = lextr.Point(i).Parameter(); |
416 | } |
417 | } |
418 | if (dist2min <= TolProj * TolProj) |
419 | { |
420 | theEdge = anEdge; |
421 | break; |
422 | } |
423 | } // for (; Explo.More(); Explo.Current()) |
424 | |
425 | if (! theEdge.IsNull()) |
426 | { |
427 | //Construction of pcurve |
428 | if (U2 < U1) |
429 | { |
430 | Standard_Real temp = U1; |
431 | U1 = U2; |
432 | U2 = temp; |
433 | } |
434 | Standard_Real f, l; |
435 | C2d = BRep_Tool::CurveOnSurface( theEdge, theFace, f, l ); |
436 | C2d = new Geom2d_TrimmedCurve( C2d, U1, U2 ); |
437 | |
438 | if (theSurf->IsUPeriodic() || theSurf->IsVPeriodic()) |
439 | PutInBounds( F, E, C2d ); |
440 | |
441 | BRep_Builder B; |
442 | B.UpdateEdge( E, C2d, F, BRep_Tool::Tolerance(E) ); |
443 | BRepLib::SameRange( E ); |
444 | |
445 | return; |
446 | } |
447 | } // if (typS == ... |
448 | |
449 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(AS); |
450 | Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(AC); |
451 | |
452 | ProjLib_ProjectedCurve Proj(HS,HC,Tolerance); |
453 | |
454 | switch ( Proj.GetType()) { |
455 | |
456 | case GeomAbs_Line: |
457 | C2d = new Geom2d_Line(Proj.Line()); |
458 | break; |
459 | |
460 | case GeomAbs_Circle: |
461 | C2d = new Geom2d_Circle(Proj.Circle()); |
462 | break; |
463 | |
464 | case GeomAbs_Ellipse: |
465 | C2d = new Geom2d_Ellipse(Proj.Ellipse()); |
466 | break; |
467 | |
468 | case GeomAbs_Parabola: |
469 | C2d = new Geom2d_Parabola(Proj.Parabola()); |
470 | break; |
471 | |
472 | case GeomAbs_Hyperbola: |
473 | C2d = new Geom2d_Hyperbola(Proj.Hyperbola()); |
474 | break; |
475 | |
476 | case GeomAbs_BezierCurve: |
477 | C2d = Proj.Bezier(); |
478 | break; |
479 | |
480 | case GeomAbs_BSplineCurve: |
481 | C2d = Proj.BSpline(); |
482 | break; |
483 | #ifndef DEB |
484 | default: |
485 | break; |
486 | #endif |
487 | } |
488 | |
489 | if (AS.IsUPeriodic() || AS.IsVPeriodic()) { |
490 | PutInBounds(F,E,C2d); |
491 | } |
492 | if (!C2d.IsNull()) { |
493 | BRep_Builder B; |
494 | B.UpdateEdge (E,C2d,F,BRep_Tool::Tolerance(E)); |
495 | } |
496 | else { |
497 | Standard_ConstructionError::Raise("BRepOffset_Tool::BuildPCurves"); |
498 | cout <<"Echec ProjLib"<<endl; |
499 | } |
500 | } |
501 | |
502 | //======================================================================= |
503 | //function : OriSect |
504 | //purpose : |
505 | //======================================================================= |
506 | |
507 | void BRepOffset_Tool::OrientSection (const TopoDS_Edge& E, |
508 | const TopoDS_Face& F1, |
509 | const TopoDS_Face& F2, |
510 | TopAbs_Orientation& O1, |
511 | TopAbs_Orientation& O2) |
512 | { |
513 | TopLoc_Location L; |
514 | Standard_Real f,l; |
515 | |
516 | Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1); |
517 | Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2); |
518 | Handle (Geom2d_Curve) C1 = BRep_Tool::CurveOnSurface(E,F1,f,l); |
519 | Handle (Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(E,F2,f,l); |
520 | Handle (Geom_Curve) C = BRep_Tool::Curve(E,L,f,l); |
521 | |
522 | BRepAdaptor_Curve BAcurve( E ); |
523 | GCPnts_UniformAbscissa Distribution( BAcurve, 3 ); |
524 | Standard_Real ParOnC = Distribution.Parameter(2); //0.5*(f+l); |
525 | |
526 | gp_Vec T1 = C->DN(ParOnC,1).Transformed(L.Transformation()); |
527 | if (T1.SquareMagnitude() > gp::Resolution()) { |
528 | T1.Normalize(); |
529 | } |
530 | |
531 | gp_Pnt2d P = C1->Value(ParOnC); |
532 | gp_Pnt P3; |
533 | gp_Vec D1U,D1V; |
534 | |
535 | S1->D1(P.X(),P.Y(),P3,D1U,D1V); |
536 | gp_Vec DN1(D1U^D1V); |
537 | if (F1.Orientation() == TopAbs_REVERSED) DN1.Reverse(); |
538 | |
539 | P = C2->Value(ParOnC); |
540 | S2->D1(P.X(),P.Y(),P3,D1U,D1V); |
541 | gp_Vec DN2(D1U^D1V); |
542 | if (F2.Orientation() == TopAbs_REVERSED) DN2.Reverse(); |
543 | |
544 | gp_Vec ProVec = DN2^T1; |
545 | Standard_Real Prod = DN1.Dot(ProVec); |
546 | if (Prod < 0.0) { |
547 | O1 = TopAbs_FORWARD; |
548 | } |
549 | else { |
550 | O1 = TopAbs_REVERSED; |
551 | } |
552 | ProVec = DN1^T1; |
553 | Prod = DN2.Dot(ProVec); |
554 | if (Prod < 0.0) { |
555 | O2 = TopAbs_FORWARD; |
556 | } |
557 | else { |
558 | O2 = TopAbs_REVERSED; |
559 | } |
560 | if (F1.Orientation() == TopAbs_REVERSED) O1 = TopAbs::Reverse(O1); |
561 | if (F2.Orientation() == TopAbs_REVERSED) O2 = TopAbs::Reverse(O2); |
562 | } |
563 | |
564 | //======================================================================= |
565 | //function : HasCommonShape |
566 | //purpose : |
567 | //======================================================================= |
568 | |
569 | Standard_Boolean BRepOffset_Tool::HasCommonShapes (const TopoDS_Face& F1, |
570 | const TopoDS_Face& F2, |
571 | TopTools_ListOfShape& LE, |
572 | TopTools_ListOfShape& LV) |
573 | { |
574 | Standard_Boolean Common = Standard_False; |
575 | LE.Clear(); LV.Clear(); |
576 | |
577 | TopExp_Explorer exp1; |
578 | exp1.Init(F1,TopAbs_EDGE); |
579 | |
580 | for (; exp1.More(); exp1.Next()) { |
581 | TopExp_Explorer exp2; |
582 | exp2.Init(F2,TopAbs_EDGE); |
583 | for (; exp2.More(); exp2.Next()) { |
584 | if (exp1.Current().IsSame(exp2.Current())) { |
585 | Common = Standard_True; |
586 | LE.Append(exp1.Current()); |
587 | } |
588 | } |
589 | } |
590 | for (exp1.Init(F1,TopAbs_VERTEX); exp1.More(); exp1.Next()) { |
591 | TopExp_Explorer exp2; |
592 | exp2.Init(F2,TopAbs_EDGE); |
593 | for (exp2.Init(F2,TopAbs_VERTEX); exp2.More(); exp2.Next()) { |
594 | if (exp1.Current().IsSame(exp2.Current())) { |
595 | Common = Standard_True; |
596 | LV.Append(exp1.Current()); |
597 | } |
598 | } |
599 | } |
600 | return Common; |
601 | } |
602 | |
603 | //======================================================================= |
604 | //function : ToSmall |
605 | //purpose : |
606 | //======================================================================= |
607 | |
608 | static Standard_Boolean ToSmall (const Handle(Geom_Curve)& C) |
609 | { |
610 | Standard_Real Tol = 10*Precision::Confusion(); |
611 | Standard_Real m = (C->FirstParameter()*0.668 + C->LastParameter()*0.332); |
612 | gp_Pnt P1 = C->Value(C->FirstParameter()); |
613 | gp_Pnt P2 = C->Value(C->LastParameter()); |
614 | gp_Pnt P3 = C->Value(m); |
615 | if (P1.Distance(P2) > Tol) return Standard_False; |
616 | if (P2.Distance(P3) > Tol) return Standard_False; |
617 | return Standard_True; |
618 | } |
619 | |
620 | |
621 | //======================================================================= |
622 | //function : IsOnSurface |
623 | //purpose : |
624 | //======================================================================= |
625 | |
626 | static Standard_Boolean IsOnSurface(const Handle(Geom_Curve)& C, |
627 | const Handle(Geom_Surface)& S, |
628 | Standard_Real TolConf, |
629 | Standard_Real& TolReached) |
630 | { |
631 | Standard_Real f = C->FirstParameter(); |
632 | Standard_Real l = C->LastParameter(); |
633 | Standard_Integer n = 5; |
634 | Standard_Real du = (f-l)/(n-1); |
635 | TolReached = 0.; |
636 | |
637 | gp_Pnt P; |
638 | Standard_Real U,V; |
639 | |
640 | GeomAdaptor_Surface AS(S); |
641 | |
642 | switch ( AS.GetType()) { |
643 | case GeomAbs_Plane: |
644 | { |
645 | gp_Ax3 Ax = AS.Plane().Position(); |
646 | for ( Standard_Integer i = 0; i < n; i++) { |
647 | P = C->Value(f+i*du); |
648 | ElSLib::PlaneParameters(Ax,P,U,V); |
649 | TolReached = P.Distance(ElSLib::PlaneValue(U,V,Ax)); |
650 | if ( TolReached > TolConf) |
651 | return Standard_False; |
652 | } |
653 | break; |
654 | } |
655 | case GeomAbs_Cylinder: |
656 | { |
657 | gp_Ax3 Ax = AS.Cylinder().Position(); |
658 | Standard_Real Rad = AS.Cylinder().Radius(); |
659 | for ( Standard_Integer i = 0; i < n; i++) { |
660 | P = C->Value(f+i*du); |
661 | ElSLib::CylinderParameters(Ax,Rad,P,U,V); |
662 | TolReached = P.Distance(ElSLib::CylinderValue(U,V,Ax,Rad)); |
663 | if ( TolReached > TolConf) |
664 | return Standard_False; |
665 | } |
666 | break; |
667 | } |
668 | case GeomAbs_Cone: |
669 | { |
670 | gp_Ax3 Ax = AS.Cone().Position(); |
671 | Standard_Real Rad = AS.Cone().RefRadius(); |
672 | Standard_Real Alp = AS.Cone().SemiAngle(); |
673 | for ( Standard_Integer i = 0; i < n; i++) { |
674 | P = C->Value(f+i*du); |
675 | ElSLib::ConeParameters(Ax,Rad,Alp,P,U,V); |
676 | TolReached = P.Distance(ElSLib::ConeValue(U,V,Ax,Rad,Alp)); |
677 | if ( TolReached > TolConf) |
678 | return Standard_False; |
679 | } |
680 | break; |
681 | } |
682 | case GeomAbs_Sphere: |
683 | { |
684 | gp_Ax3 Ax = AS.Sphere().Position(); |
685 | Standard_Real Rad = AS.Sphere().Radius(); |
686 | for ( Standard_Integer i = 0; i < n; i++) { |
687 | P = C->Value(f+i*du); |
688 | ElSLib::SphereParameters(Ax,Rad,P,U,V); |
689 | TolReached = P.Distance(ElSLib::SphereValue(U,V,Ax,Rad)); |
690 | if ( TolReached > TolConf) |
691 | return Standard_False; |
692 | } |
693 | break; |
694 | } |
695 | case GeomAbs_Torus: |
696 | { |
697 | gp_Ax3 Ax = AS.Torus().Position(); |
698 | Standard_Real R1 = AS.Torus().MajorRadius(); |
699 | Standard_Real R2 = AS.Torus().MinorRadius(); |
700 | for ( Standard_Integer i = 0; i < n; i++) { |
701 | P = C->Value(f+i*du); |
702 | ElSLib::TorusParameters(Ax,R1,R2,P,U,V); |
703 | TolReached = P.Distance(ElSLib::TorusValue(U,V,Ax,R1,R2)); |
704 | if ( TolReached > TolConf) |
705 | return Standard_False; |
706 | } |
707 | break; |
708 | } |
709 | |
710 | default: |
711 | { |
712 | return Standard_False; |
713 | } |
714 | } |
715 | |
716 | return Standard_True; |
717 | } |
718 | |
719 | |
720 | //======================================================================= |
721 | //function : PipeInter |
722 | //purpose : |
723 | //======================================================================= |
724 | |
725 | void BRepOffset_Tool::PipeInter(const TopoDS_Face& F1, |
726 | const TopoDS_Face& F2, |
727 | TopTools_ListOfShape& L1, |
728 | TopTools_ListOfShape& L2, |
729 | const TopAbs_State Side) |
730 | { |
731 | #ifdef DRAW |
732 | if (AffichInter) { |
733 | // POP pour NT |
734 | char* name = new char[100]; |
735 | sprintf(name,"FF_%d",NbFaces++); |
736 | DBRep::Set(name,F1); |
737 | sprintf(name,"FF_%d",NbFaces++); |
738 | DBRep::Set(name,F2); |
739 | } |
740 | #endif |
741 | |
742 | Handle (Geom_Curve) CI; |
743 | TopoDS_Edge E; |
744 | TopAbs_Orientation O1,O2; |
745 | L1.Clear(); L2.Clear(); |
746 | BRep_Builder B; |
747 | Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1); |
748 | Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2); |
749 | |
750 | GeomInt_IntSS Inter (S1,S2, Precision::Confusion(),1,1,1); |
751 | |
752 | if (Inter.IsDone()) { |
753 | for (Standard_Integer i = 1; i <= Inter.NbLines(); i++) { |
754 | CI = Inter.Line(i); |
755 | if (ToSmall(CI)) continue; |
756 | TopoDS_Edge E = BRepLib_MakeEdge(CI); |
757 | if (Inter.HasLineOnS1(i)) { |
758 | Handle(Geom2d_Curve) C2 = Inter.LineOnS1(i); |
759 | PutInBounds (F1,E,C2); |
760 | B.UpdateEdge (E,C2,F1,BRep_Tool::Tolerance(E)); |
761 | } |
762 | else { |
763 | BuildPCurves (E,F1); |
764 | } |
765 | if (Inter.HasLineOnS2(i)) { |
766 | Handle(Geom2d_Curve) C2 = Inter.LineOnS2(i); |
767 | PutInBounds (F2,E,C2); |
768 | B.UpdateEdge (E,C2,F2,BRep_Tool::Tolerance(E)); |
769 | } |
770 | else { |
771 | BuildPCurves (E,F2); |
772 | } |
773 | OrientSection (E,F1,F2,O1,O2); |
774 | if (Side == TopAbs_OUT) { |
775 | O1 = TopAbs::Reverse(O1); |
776 | O2 = TopAbs::Reverse(O2); |
777 | } |
778 | L1.Append (E.Oriented(O1)); |
779 | L2.Append (E.Oriented(O2)); |
780 | #ifdef DRAW |
781 | if (AffichInter) { |
782 | // POP pour NT |
783 | char* name = new char[100]; |
784 | sprintf(name,"EI_%d",NbNewEdges++); |
785 | DBRep::Set(name,E.Oriented(O1)); |
786 | } |
787 | #endif |
788 | } |
789 | } |
790 | } |
791 | |
792 | |
793 | //======================================================================= |
794 | //function : IsAutonomVertex |
795 | //purpose : Checks wether a vertex is "autonom" or not |
796 | //======================================================================= |
797 | |
798 | static Standard_Boolean IsAutonomVertex(const TopoDS_Shape& aVertex, |
799 | const TopoDS_Shape& F1, |
800 | const TopoDS_Shape& F2, |
801 | const BooleanOperations_ShapesDataStructure& theDS, |
802 | const BOPTools_PaveFiller& thePaveFiller) |
803 | { |
804 | Standard_Integer i, index = theDS.ShapeIndex( aVertex, 1 ); |
805 | if (index == 0) |
806 | { |
807 | index = theDS.ShapeIndex( aVertex, 2 ); |
808 | if (index == 0) |
809 | { |
810 | for (i = theDS.NumberOfSourceShapes()+1; i <= theDS.NumberOfInsertedShapes(); i++) |
811 | { |
812 | const TopoDS_Shape& aShape = theDS.GetShape(i); |
813 | if (aVertex.IsSame(aShape)) |
814 | { |
815 | index = i; |
816 | break; |
817 | } |
818 | } |
819 | } |
820 | } |
821 | |
822 | Standard_Integer indF1 = theDS.ShapeIndex( F1, 1 ); |
823 | Standard_Integer indF2 = theDS.ShapeIndex( F2, 2 ); |
824 | |
825 | BooleanOperations_KindOfInterference theTypeInterf; |
826 | const BOPTools_PavePool& thePavePool = thePaveFiller.PavePool(); |
827 | BOPTools_ListIteratorOfListOfPave itpave; |
828 | for (i = 1; i <= thePavePool.Length(); i++) |
829 | { |
830 | const BOPTools_ListOfPave& aPaveList = thePavePool(i).Set(); |
831 | for (itpave.Initialize( aPaveList ); itpave.More(); itpave.Next()) |
832 | { |
833 | BOPTools_Pave aPave = itpave.Value(); |
834 | if (aPave.Index() == index) |
835 | { |
836 | theTypeInterf = aPave.Type(); |
837 | if (theTypeInterf != BooleanOperations_SurfaceSurface && |
838 | theTypeInterf != BooleanOperations_UnknownInterference) |
839 | return Standard_False; |
840 | } |
841 | } |
842 | } |
843 | |
844 | BOPTools_PaveFiller * pPF = (BOPTools_PaveFiller*) &thePaveFiller; |
845 | BOPTools_PaveFiller& thePF = *pPF; |
846 | BOPTools_CArray1OfSSInterference& aFFs = thePF.InterfPool()->SSInterferences(); |
847 | Standard_Integer aNbFFs=aFFs.Extent(); |
848 | for (i = 1; i <= aNbFFs; i++) |
849 | { |
850 | BOPTools_SSInterference& aFFi = aFFs(i); |
851 | |
852 | if (aFFi.Index1() == indF1 && aFFi.Index2() == indF2) |
853 | { |
854 | const BOPTools_ListOfPave& aPaveList = aFFi.NewPaveSet().Set(); |
855 | for (itpave.Initialize( aPaveList ); itpave.More(); itpave.Next()) |
856 | { |
857 | BOPTools_Pave aPave = itpave.Value(); |
858 | if (aPave.Index() == index) |
859 | { |
860 | theTypeInterf = aPave.Type(); |
861 | if (theTypeInterf != BooleanOperations_SurfaceSurface && |
862 | theTypeInterf != BooleanOperations_UnknownInterference) |
863 | return Standard_False; |
864 | } |
865 | } |
866 | } |
867 | } |
868 | |
869 | return Standard_True; |
870 | } |
871 | |
872 | |
873 | //======================================================================= |
874 | //function : AreConnex |
875 | //purpose : define if two shapes are connex by a vertex (vertices) |
876 | //======================================================================= |
877 | |
878 | static Standard_Boolean AreConnex(const TopoDS_Wire& W1, |
879 | const TopoDS_Wire& W2, |
880 | const TopoDS_Shape& F1, |
881 | const TopoDS_Shape& F2, |
882 | const BOPTools_DSFiller* pDF) |
883 | { |
884 | TopoDS_Vertex V11, V12, V21, V22; |
885 | TopExp::Vertices( W1, V11, V12 ); |
886 | TopExp::Vertices( W2, V21, V22 ); |
887 | |
888 | if (V11.IsSame(V21) || V11.IsSame(V22) || |
889 | V12.IsSame(V21) || V12.IsSame(V22)) |
890 | { |
891 | Standard_Boolean isCV1 = V11.IsSame(V21) || V11.IsSame(V22); |
892 | Standard_Boolean isCV2 = V12.IsSame(V21) || V12.IsSame(V22); |
893 | if (isCV1 && !IsAutonomVertex(V11, F1, F2, pDF->DS(), pDF->PaveFiller())) |
894 | { |
895 | if (!isCV2) |
896 | return Standard_False; |
897 | if (!IsAutonomVertex(V12, F1, F2, pDF->DS(), pDF->PaveFiller())) |
898 | return Standard_False; |
899 | } |
900 | if (!isCV1 && !IsAutonomVertex(V12, F1, F2, pDF->DS(), pDF->PaveFiller())) |
901 | return Standard_False; |
902 | |
903 | TopoDS_Vertex CV = (V11.IsSame(V21) || V11.IsSame(V22))? V11 : V12; |
904 | TopoDS_Edge E1, E2; |
905 | TopoDS_Iterator itw( W1 ); |
906 | for (; itw.More(); itw.Next()) |
907 | { |
908 | E1 = TopoDS::Edge(itw.Value()); |
909 | TopoDS_Vertex V1, V2; |
910 | TopExp::Vertices( E1, V1, V2 ); |
911 | if (V1.IsSame(CV) || V2.IsSame(CV)) |
912 | break; |
913 | } |
914 | itw.Initialize( W2 ); |
915 | E2 = TopoDS::Edge(itw.Value()); |
916 | |
917 | Standard_Real f, l; |
918 | Handle(Geom_Curve) C1 = BRep_Tool::Curve( E1, f, l ); |
919 | if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve))) |
920 | C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve(); |
921 | |
922 | Handle(Geom_Curve) C2 = BRep_Tool::Curve( E2, f, l ); |
923 | if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve))) |
924 | C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve(); |
925 | |
926 | if (C1->IsInstance(STANDARD_TYPE(Geom_Line)) && |
927 | C2->IsInstance(STANDARD_TYPE(Geom_Line))) |
928 | { |
929 | Handle(Geom_Line) L1 = *((Handle(Geom_Line)*) &C1); |
930 | gp_Ax1 Axis1 = L1->Position(); |
931 | Handle(Geom_Line) L2 = *((Handle(Geom_Line)*) &C2); |
932 | gp_Ax1 Axis2 = L2->Position(); |
933 | if (! Axis1.IsParallel( Axis2, Precision::Angular() )) |
934 | return Standard_False; |
935 | } |
936 | |
937 | return Standard_True; |
938 | } |
939 | |
940 | return Standard_False; |
941 | } |
942 | |
943 | //======================================================================= |
944 | //function : AreClosed |
945 | //purpose : define if two edges are connex by two vertices |
946 | //======================================================================= |
947 | |
948 | static Standard_Boolean AreClosed(const TopoDS_Edge& E1, |
949 | const TopoDS_Edge& E2) |
950 | { |
951 | TopoDS_Vertex V11, V12, V21, V22; |
952 | TopExp::Vertices( E1, V11, V12 ); |
953 | TopExp::Vertices( E2, V21, V22 ); |
954 | |
955 | if (V11.IsSame(V21) && V12.IsSame(V22) || |
956 | V11.IsSame(V22) && V12.IsSame(V21)) |
957 | return Standard_True; |
958 | |
959 | return Standard_False; |
960 | } |
961 | |
962 | //======================================================================= |
963 | //function : BSplineEdges |
964 | //purpose : |
965 | //======================================================================= |
966 | |
967 | static Standard_Boolean BSplineEdges(const TopoDS_Edge& E1, |
968 | const TopoDS_Edge& E2, |
969 | const Standard_Integer par1, |
970 | const Standard_Integer par2, |
971 | Standard_Real& angle) |
972 | { |
973 | Standard_Real first1, last1, first2, last2, Param1, Param2; |
974 | |
975 | Handle(Geom_Curve) C1 = BRep_Tool::Curve( E1, first1, last1 ); |
976 | if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve))) |
977 | C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve(); |
978 | |
979 | Handle(Geom_Curve) C2 = BRep_Tool::Curve( E2, first2, last2 ); |
980 | if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve))) |
981 | C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve(); |
982 | |
983 | if (!C1->IsInstance(STANDARD_TYPE(Geom_BSplineCurve)) || |
984 | !C2->IsInstance(STANDARD_TYPE(Geom_BSplineCurve))) |
985 | return Standard_False; |
986 | |
987 | Param1 = (par1 == 0)? first1 : last1; |
988 | Param2 = (par2 == 0)? first2 : last2; |
989 | |
990 | gp_Pnt Pnt1, Pnt2; |
991 | gp_Vec Der1, Der2; |
992 | C1->D1( Param1, Pnt1, Der1 ); |
993 | C2->D1( Param2, Pnt2, Der2 ); |
994 | |
995 | if (Der1.Magnitude() <= gp::Resolution() || |
996 | Der2.Magnitude() <= gp::Resolution()) |
c6541a0c |
997 | angle = M_PI/2.; |
7fd59977 |
998 | else |
999 | angle = Der1.Angle(Der2); |
1000 | |
1001 | return Standard_True; |
1002 | } |
1003 | |
1004 | //======================================================================= |
1005 | //function : AngleWireEdge |
1006 | //purpose : |
1007 | //======================================================================= |
1008 | |
1009 | static Standard_Real AngleWireEdge(const TopoDS_Wire& aWire, |
1010 | const TopoDS_Edge& anEdge) |
1011 | { |
1012 | TopoDS_Vertex V11, V12, V21, V22, CV; |
1013 | TopExp::Vertices( aWire, V11, V12 ); |
1014 | TopExp::Vertices( anEdge, V21, V22 ); |
1015 | CV = (V11.IsSame(V21) || V11.IsSame(V22))? V11 : V12; |
1016 | TopoDS_Edge FirstEdge; |
1017 | TopoDS_Iterator itw(aWire); |
1018 | for (; itw.More(); itw.Next()) |
1019 | { |
1020 | FirstEdge = TopoDS::Edge(itw.Value()); |
1021 | TopoDS_Vertex v1, v2; |
1022 | TopExp::Vertices( FirstEdge, v1, v2 ); |
1023 | if (v1.IsSame(CV) || v2.IsSame(CV)) |
1024 | { |
1025 | V11 = v1; |
1026 | V12 = v2; |
1027 | break; |
1028 | } |
1029 | } |
1030 | Standard_Real Angle; |
1031 | if (V11.IsSame(CV) && V21.IsSame(CV)) |
1032 | { |
1033 | BSplineEdges( FirstEdge, anEdge, 0, 0, Angle ); |
c6541a0c |
1034 | Angle = M_PI - Angle; |
7fd59977 |
1035 | } |
1036 | else if (V11.IsSame(CV) && V22.IsSame(CV)) |
1037 | BSplineEdges( FirstEdge, anEdge, 0, 1, Angle ); |
1038 | else if (V12.IsSame(CV) && V21.IsSame(CV)) |
1039 | BSplineEdges( FirstEdge, anEdge, 1, 0, Angle ); |
1040 | else |
1041 | { |
1042 | BSplineEdges( FirstEdge, anEdge, 1, 1, Angle ); |
c6541a0c |
1043 | Angle = M_PI - Angle; |
7fd59977 |
1044 | } |
1045 | return Angle; |
1046 | } |
1047 | |
1048 | |
1049 | //======================================================================= |
1050 | //function : ReconstructPCurves |
1051 | //purpose : |
1052 | //======================================================================= |
1053 | |
1054 | static void ReconstructPCurves(const TopoDS_Edge& anEdge) |
1055 | { |
1056 | Standard_Real f, l; |
1057 | Handle(Geom_Curve) C3d = BRep_Tool::Curve(anEdge, f, l); |
1058 | |
1059 | BRep_ListIteratorOfListOfCurveRepresentation |
1060 | itcr( (Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->ChangeCurves() ); |
1061 | for (; itcr.More(); itcr.Next()) |
1062 | { |
1063 | Handle( BRep_CurveRepresentation ) CurveRep = itcr.Value(); |
1064 | if (CurveRep->IsCurveOnSurface()) |
1065 | { |
1066 | Handle(Geom_Surface) theSurf = CurveRep->Surface(); |
1067 | TopLoc_Location theLoc = CurveRep->Location(); |
1068 | theLoc = anEdge.Location() * theLoc; |
1069 | theSurf = Handle(Geom_Surface)::DownCast |
1070 | (theSurf->Transformed(theLoc.Transformation())); |
1071 | Handle(Geom2d_Curve) ProjPCurve = |
1072 | GeomProjLib::Curve2d( C3d, f, l, theSurf ); |
1073 | CurveRep->PCurve( ProjPCurve ); |
1074 | } |
1075 | } |
1076 | } |
1077 | |
1078 | //======================================================================= |
1079 | //function : ConcatPCurves |
1080 | //purpose : |
1081 | //======================================================================= |
1082 | |
1083 | static Handle(Geom2d_Curve) ConcatPCurves(const TopoDS_Edge& E1, |
1084 | const TopoDS_Edge& E2, |
1085 | const TopoDS_Face& F, |
1086 | const Standard_Boolean After, |
1087 | Standard_Real& newFirst, |
1088 | Standard_Real& newLast) |
1089 | { |
1090 | Standard_Real Tol = 1.e-7; |
1091 | GeomAbs_Shape Continuity = GeomAbs_C1; |
1092 | Standard_Integer MaxDeg = 14; |
1093 | Standard_Integer MaxSeg = 16; |
1094 | |
1095 | Standard_Real first1, last1, first2, last2; |
1096 | Handle(Geom2d_Curve) PCurve1, PCurve2, newPCurve; |
1097 | |
1098 | PCurve1 = BRep_Tool::CurveOnSurface( E1, F, first1, last1 ); |
1099 | if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve))) |
1100 | PCurve1 = (*((Handle(Geom2d_TrimmedCurve)*)&PCurve1))->BasisCurve(); |
1101 | |
1102 | PCurve2 = BRep_Tool::CurveOnSurface( E2, F, first2, last2 ); |
1103 | if (PCurve2->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve))) |
1104 | PCurve2 = (*((Handle(Geom2d_TrimmedCurve)*)&PCurve2))->BasisCurve(); |
1105 | |
1106 | if (PCurve1 == PCurve2) |
1107 | { |
1108 | newPCurve = PCurve1; |
1109 | newFirst = Min( first1, first2 ); |
1110 | newLast = Max( last1, last2 ); |
1111 | } |
1112 | else if (PCurve1->DynamicType() == PCurve2->DynamicType() && |
1113 | (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Line)) || |
1114 | PCurve1->IsKind(STANDARD_TYPE(Geom2d_Conic)))) |
1115 | { |
1116 | newPCurve = PCurve1; |
1117 | gp_Pnt2d P1, P2; |
1118 | P1 = PCurve2->Value( first2 ); |
1119 | P2 = PCurve2->Value( last2 ); |
1120 | if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Line))) |
1121 | { |
1122 | Handle(Geom2d_Line) Lin1 = *((Handle(Geom2d_Line)*) &PCurve1); |
1123 | gp_Lin2d theLin = Lin1->Lin2d(); |
1124 | first2 = ElCLib::Parameter( theLin, P1 ); |
1125 | last2 = ElCLib::Parameter( theLin, P2 ); |
1126 | } |
1127 | else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Circle))) |
1128 | { |
1129 | Handle(Geom2d_Circle) Circ1 = *((Handle(Geom2d_Circle)*) &PCurve1); |
1130 | gp_Circ2d theCirc = Circ1->Circ2d(); |
1131 | first2 = ElCLib::Parameter( theCirc, P1 ); |
1132 | last2 = ElCLib::Parameter( theCirc, P2 ); |
1133 | } |
1134 | else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Ellipse))) |
1135 | { |
1136 | Handle(Geom2d_Ellipse) Ell1 = *((Handle(Geom2d_Ellipse)*) &PCurve1); |
1137 | gp_Elips2d theElips = Ell1->Elips2d(); |
1138 | first2 = ElCLib::Parameter( theElips, P1 ); |
1139 | last2 = ElCLib::Parameter( theElips, P2 ); |
1140 | } |
1141 | else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Parabola))) |
1142 | { |
1143 | Handle(Geom2d_Parabola) Parab1 = *((Handle(Geom2d_Parabola)*) &PCurve1); |
1144 | gp_Parab2d theParab = Parab1->Parab2d(); |
1145 | first2 = ElCLib::Parameter( theParab, P1 ); |
1146 | last2 = ElCLib::Parameter( theParab, P2 ); |
1147 | } |
1148 | else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Hyperbola))) |
1149 | { |
1150 | Handle(Geom2d_Hyperbola) Hypr1 = *((Handle(Geom2d_Hyperbola)*) &PCurve1); |
1151 | gp_Hypr2d theHypr = Hypr1->Hypr2d(); |
1152 | first2 = ElCLib::Parameter( theHypr, P1 ); |
1153 | last2 = ElCLib::Parameter( theHypr, P2 ); |
1154 | } |
1155 | newFirst = Min( first1, first2 ); |
1156 | newLast = Max( last1, last2 ); |
1157 | } |
1158 | else |
1159 | { |
1160 | Handle(Geom2d_TrimmedCurve) TC1 = new Geom2d_TrimmedCurve( PCurve1, first1, last1 ); |
1161 | Handle(Geom2d_TrimmedCurve) TC2 = new Geom2d_TrimmedCurve( PCurve2, first2, last2 ); |
1162 | Geom2dConvert_CompCurveToBSplineCurve Concat2d( TC1 ); |
1163 | Concat2d.Add( TC2, Precision::Confusion(), After ); |
1164 | newPCurve = Concat2d.BSplineCurve(); |
1165 | if (newPCurve->Continuity() < GeomAbs_C1) |
1166 | { |
1167 | Geom2dConvert_ApproxCurve Approx2d( newPCurve, Tol, Continuity, MaxSeg, MaxDeg ); |
1168 | if (Approx2d.HasResult()) |
1169 | newPCurve = Approx2d.Curve(); |
1170 | } |
1171 | newFirst = newPCurve->FirstParameter(); |
1172 | newLast = newPCurve->LastParameter(); |
1173 | } |
1174 | |
1175 | return newPCurve; |
1176 | } |
1177 | |
1178 | //======================================================================= |
1179 | //function : Glue |
1180 | //purpose : glue two edges. |
1181 | //======================================================================= |
1182 | |
1183 | static TopoDS_Edge Glue(const TopoDS_Edge& E1, |
1184 | const TopoDS_Edge& E2, |
1185 | const TopoDS_Vertex& Vfirst, |
1186 | const TopoDS_Vertex& Vlast, |
1187 | const Standard_Boolean After, |
1188 | const TopoDS_Face& F1, |
1189 | const Standard_Boolean addPCurve1, |
1190 | const TopoDS_Face& F2, |
1191 | const Standard_Boolean addPCurve2) |
1192 | { |
1193 | Standard_Real Tol = 1.e-7; |
1194 | GeomAbs_Shape Continuity = GeomAbs_C1; |
1195 | Standard_Integer MaxDeg = 14; |
1196 | Standard_Integer MaxSeg = 16; |
1197 | |
1198 | Handle(Geom_Curve) C1, C2, newCurve; |
1199 | Handle(Geom2d_Curve) PCurve1, PCurve2, newPCurve; |
1200 | Standard_Real first1, last1, first2, last2, fparam=0., lparam=0.; |
1201 | Standard_Boolean IsCanonic = Standard_False; |
1202 | |
1203 | C1 = BRep_Tool::Curve( E1, first1, last1 ); |
1204 | if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve))) |
1205 | C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve(); |
1206 | |
1207 | C2 = BRep_Tool::Curve( E2, first2, last2 ); |
1208 | if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve))) |
1209 | C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve(); |
1210 | |
1211 | if (C1 == C2) |
1212 | { |
1213 | newCurve = C1; |
1214 | fparam = Min( first1, first2 ); |
1215 | lparam = Max( last1, last2 ); |
1216 | } |
1217 | else if (C1->DynamicType() == C2->DynamicType() && |
1218 | (C1->IsInstance(STANDARD_TYPE(Geom_Line)) || |
1219 | C1->IsKind(STANDARD_TYPE(Geom_Conic)))) |
1220 | { |
1221 | IsCanonic = Standard_True; |
1222 | newCurve = C1; |
1223 | } |
1224 | else |
1225 | { |
1226 | Handle(Geom_TrimmedCurve) TC1 = new Geom_TrimmedCurve( C1, first1, last1 ); |
1227 | Handle(Geom_TrimmedCurve) TC2 = new Geom_TrimmedCurve( C2, first2, last2 ); |
1228 | GeomConvert_CompCurveToBSplineCurve Concat( TC1 ); |
1229 | Concat.Add( TC2, Precision::Confusion(), After ); |
1230 | newCurve = Concat.BSplineCurve(); |
1231 | if (newCurve->Continuity() < GeomAbs_C1) |
1232 | { |
1233 | GeomConvert_ApproxCurve Approx3d( newCurve, Tol, Continuity, MaxSeg, MaxDeg ); |
1234 | if (Approx3d.HasResult()) |
1235 | newCurve = Approx3d.Curve(); |
1236 | } |
1237 | fparam = newCurve->FirstParameter(); |
1238 | lparam = newCurve->LastParameter(); |
1239 | } |
1240 | |
1241 | TopoDS_Edge newEdge; |
1242 | BRep_Builder BB; |
1243 | |
1244 | if (IsCanonic) |
1245 | newEdge = BRepLib_MakeEdge( newCurve, Vfirst, Vlast ); |
1246 | else |
1247 | newEdge = BRepLib_MakeEdge( newCurve, Vfirst, Vlast, fparam, lparam ); |
1248 | |
1249 | Standard_Real newFirst, newLast; |
1250 | if (addPCurve1) |
1251 | { |
1252 | newPCurve = ConcatPCurves( E1, E2, F1, After, newFirst, newLast ); |
1253 | BB.UpdateEdge( newEdge, newPCurve, F1, 0. ); |
1254 | BB.Range( newEdge, F1, newFirst, newLast ); |
1255 | } |
1256 | if (addPCurve2) |
1257 | { |
1258 | newPCurve = ConcatPCurves( E1, E2, F2, After, newFirst, newLast ); |
1259 | BB.UpdateEdge( newEdge, newPCurve, F2, 0. ); |
1260 | BB.Range( newEdge, F2, newFirst, newLast ); |
1261 | } |
1262 | |
1263 | return newEdge; |
1264 | } |
1265 | |
1266 | |
1267 | //======================================================================= |
1268 | //function : FindNewVerticesOnBoundsOfFace |
1269 | //purpose : |
1270 | //======================================================================= |
1271 | |
1272 | static void FindNewVerticesOnBoundsOfFace(const BOPTools_DSFiller& pDF, |
1273 | const TopoDS_Face& aFace, |
1274 | const Standard_Integer iFace, |
1275 | TopTools_DataMapOfShapeShape& VEmap) |
1276 | { |
1277 | TopTools_IndexedMapOfShape OldVertices; |
1278 | TopExp::MapShapes( aFace, TopAbs_VERTEX, OldVertices ); |
1279 | |
1280 | const BOPTools_SplitShapesPool& aPool = pDF.SplitShapesPool(); |
1281 | |
1282 | TopExp_Explorer Explo( aFace, TopAbs_EDGE ); |
1283 | for (; Explo.More(); Explo.Next()) |
1284 | { |
1285 | TopoDS_Shape anEdge = Explo.Current(); |
1286 | Standard_Integer eind = pDF.DS().ShapeIndex(anEdge,iFace); |
1287 | const BOPTools_ListOfPaveBlock& aSplitEdges = aPool( pDF.DS().RefEdge(eind) ); |
1288 | BOPTools_ListIteratorOfListOfPaveBlock itpb( aSplitEdges ); |
1289 | for (; itpb.More(); itpb.Next()) |
1290 | { |
1291 | BOPTools_PaveBlock& aPaveBlock = itpb.Value(); |
1292 | TopoDS_Shape aSplit = pDF.DS().GetShape( aPaveBlock.Edge() ); |
1293 | TopoDS_Edge aNewEdge = TopoDS::Edge(aSplit); |
1294 | TopoDS_Vertex V1, V2; |
1295 | TopExp::Vertices( aNewEdge, V1, V2 ); |
1296 | if (!OldVertices.Contains( V1 )) |
1297 | VEmap.Bind( V1, anEdge ); |
1298 | if (!OldVertices.Contains( V2 )) |
1299 | VEmap.Bind( V2, anEdge ); |
1300 | } |
1301 | } |
1302 | } |
1303 | |
1304 | //======================================================================= |
1305 | //function : CheckIntersFF |
1306 | //purpose : |
1307 | //======================================================================= |
1308 | |
1309 | static Standard_Boolean CheckIntersFF(const BOPTools_DSFiller& pDF, |
1310 | const TopoDS_Edge& RefEdge, |
1311 | const TopoDS_Face& F1, |
1312 | const TopoDS_Face& F2, |
1313 | TopTools_IndexedMapOfShape& TrueEdges) |
1314 | { |
1315 | Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False; |
1316 | Standard_Boolean isPlane1 = Standard_False, isPlane2 = Standard_False; |
1317 | |
1318 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F1); |
1319 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) |
1320 | aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface(); |
1321 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane))) |
1322 | isPlane1 = Standard_True; |
1323 | else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) |
1324 | isEl1 = Standard_True; |
1325 | |
1326 | aSurf = BRep_Tool::Surface(F2); |
1327 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) |
1328 | aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface(); |
1329 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane))) |
1330 | isPlane2 = Standard_True; |
1331 | else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) |
1332 | isEl2 = Standard_True; |
1333 | |
1334 | if (isPlane1 || isPlane2) |
1335 | return Standard_True; |
1336 | |
1337 | if (isEl1 && isEl2) |
1338 | return Standard_True; |
1339 | |
1340 | const BooleanOperations_ShapesDataStructure& aDS = pDF.DS(); |
1341 | BOPTools_InterferencePool* anIntrPool = (BOPTools_InterferencePool*)&pDF.InterfPool(); |
1342 | BOPTools_CArray1OfSSInterference& aFFs = anIntrPool->SSInterferences(); |
1343 | Standard_Integer aNb = aFFs.Extent(); |
1344 | Standard_Integer i, j, nbe = 0; |
1345 | |
1346 | TopTools_SequenceOfShape Edges; |
1347 | |
1348 | for (i = 1; i <= aNb; i++) |
1349 | { |
1350 | BOPTools_SSInterference& aFFi = aFFs(i); |
1351 | BOPTools_SequenceOfCurves& aBCurves = aFFi.Curves(); |
1352 | Standard_Integer aNbCurves = aBCurves.Length(); |
1353 | |
1354 | for (j = 1; j <= aNbCurves; j++) |
1355 | { |
1356 | BOPTools_Curve& aBC = aBCurves(j); |
1357 | const BOPTools_ListOfPaveBlock& aSectEdges = aBC.NewPaveBlocks(); |
1358 | |
1359 | BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges); |
1360 | |
1361 | for (; aPBIt.More(); aPBIt.Next()) |
1362 | { |
1363 | BOPTools_PaveBlock& aPB=aPBIt.Value(); |
1364 | Standard_Integer nSect = aPB.Edge(); |
1365 | TopoDS_Edge anEdge = TopoDS::Edge(aDS.Shape(nSect)); |
1366 | Edges.Append( anEdge ); |
1367 | nbe++; |
1368 | } |
1369 | } |
1370 | } |
1371 | |
1372 | if (nbe <= 1) |
1373 | return Standard_True; |
1374 | |
1375 | //define tangents of RefEdge on start and on end |
1376 | BRepAdaptor_Curve cref(RefEdge); |
1377 | gp_Vec RefTangFirst = cref.DN(cref.FirstParameter(), 1); |
1378 | gp_Vec RefTangLast = cref.DN(cref.LastParameter(), 1); |
1379 | |
1380 | //find the start edge and take it from Edges |
1381 | TopoDS_Edge StartEdge; //, StartEonF1, StartEonF2, EndEonF1, EndEonF2; |
1382 | |
1383 | TopTools_DataMapOfShapeShape VEmapF1, VEmapF2; |
1384 | FindNewVerticesOnBoundsOfFace( pDF, F1, 1, VEmapF1 ); |
1385 | FindNewVerticesOnBoundsOfFace( pDF, F2, 2, VEmapF2 ); |
1386 | |
1387 | Standard_Real AngTol = 0.1; |
1388 | Standard_Boolean V1onBound = Standard_False; |
1389 | Standard_Boolean V2onBound = Standard_False; |
1390 | TopoDS_Vertex V1, V2, Vcur; |
1391 | gp_Vec TangFirst, TangLast, TangCur; |
1392 | for (i = 1; i <= Edges.Length(); i++) |
1393 | { |
1394 | StartEdge = TopoDS::Edge(Edges(i)); |
1395 | TopExp::Vertices( StartEdge, V1, V2 ); |
1396 | V1onBound = VEmapF1.IsBound(V1) || VEmapF2.IsBound(V1); // && ? |
1397 | V2onBound = VEmapF1.IsBound(V2) || VEmapF2.IsBound(V2); // && ? |
1398 | if (V1onBound || V2onBound) |
1399 | { |
1400 | BRepAdaptor_Curve CE(StartEdge); |
1401 | TangFirst = CE.DN( CE.FirstParameter(), 1 ); |
1402 | TangLast = CE.DN( CE.LastParameter(), 1 ); |
1403 | if (V1onBound) |
1404 | { |
1405 | if (TangFirst.IsParallel( RefTangFirst, AngTol ) || |
1406 | TangFirst.IsParallel( RefTangLast, AngTol )) |
1407 | break; //start edged found |
1408 | } |
1409 | else if (V2onBound) |
1410 | { |
1411 | if (TangLast.IsParallel( RefTangLast, AngTol ) || |
1412 | TangLast.IsParallel( RefTangFirst, AngTol )) |
1413 | break; //start edged found |
1414 | } |
1415 | } |
1416 | } |
1417 | |
1418 | if (i > Edges.Length()) //start edged not found |
1419 | return Standard_False; |
1420 | |
1421 | if (V1onBound && V2onBound) |
1422 | { |
1423 | if (TangFirst.IsParallel(RefTangFirst,AngTol) && TangLast.IsParallel(RefTangLast,AngTol) || |
1424 | TangFirst.IsParallel(RefTangLast,AngTol) && TangLast.IsParallel(RefTangFirst,AngTol)) |
1425 | { |
1426 | TrueEdges.Add( Edges(i) ); |
1427 | return Standard_True; |
1428 | } |
1429 | else |
1430 | return Standard_False; |
1431 | } |
1432 | |
1433 | //StartEonF1 = (V1onBound)? VEmapF1( V1 ) : VEmapF1( V2 ); |
1434 | //StartEonF2 = (V1onBound)? VEmapF2( V1 ) : VEmapF2( V2 ); |
1435 | |
1436 | TrueEdges.Add( Edges(i) ); |
1437 | Edges.Remove(i); |
1438 | Vcur = (V1onBound)? V2 : V1; |
1439 | TangCur = (V1onBound)? TangLast : TangFirst; |
1440 | if (V2onBound) |
1441 | TangCur.Reverse(); |
1442 | |
1443 | //build the chain from StartEdge till the opposite bound of face |
1444 | for (;;) |
1445 | { |
1446 | TColStd_SequenceOfInteger Candidates; |
1447 | for (i = 1; i <= Edges.Length(); i++) |
1448 | { |
1449 | TopoDS_Edge anEdge = TopoDS::Edge(Edges(i)); |
1450 | TopExp::Vertices( anEdge, V1, V2 ); |
1451 | if (V1.IsSame(Vcur) || V2.IsSame(Vcur)) |
1452 | Candidates.Append(i); |
1453 | } |
1454 | if (Candidates.IsEmpty()) |
1455 | { |
1456 | TrueEdges.Clear(); |
1457 | return Standard_False; |
1458 | } |
1459 | |
1460 | Standard_Integer minind = 1; |
1461 | if (Candidates.Length() > 1) |
1462 | { |
1463 | Standard_Real MinAngle = RealLast(); |
1464 | for (i = 1; i <= Candidates.Length(); i++) |
1465 | { |
1466 | TopoDS_Edge anEdge = TopoDS::Edge(Edges(Candidates(i))); |
1467 | TopExp::Vertices( anEdge, V1, V2 ); |
1468 | Standard_Boolean ConnectByFirst = (Vcur.IsSame(V1))? Standard_True : Standard_False; |
1469 | BRepAdaptor_Curve CE(anEdge); |
1470 | gp_Vec aTang = (ConnectByFirst)? |
1471 | CE.DN( CE.FirstParameter(), 1 ) : CE.DN( CE.LastParameter(), 1 ); |
1472 | if (!ConnectByFirst) |
1473 | aTang.Reverse(); |
1474 | Standard_Real anAngle = TangCur.Angle(aTang); |
1475 | if (anAngle < MinAngle) |
1476 | { |
1477 | MinAngle = anAngle; |
1478 | minind = i; |
1479 | } |
1480 | } |
1481 | } |
1482 | TopoDS_Edge CurEdge = TopoDS::Edge(Edges(Candidates(minind))); |
1483 | TrueEdges.Add( CurEdge ); |
1484 | Edges.Remove(Candidates(minind)); |
1485 | TopExp::Vertices( CurEdge, V1, V2 ); |
1486 | Standard_Boolean ConnectByFirst = (Vcur.IsSame(V1))? Standard_True : Standard_False; |
1487 | Vcur = (ConnectByFirst)? V2 : V1; |
1488 | BRepAdaptor_Curve CE(CurEdge); |
1489 | TangCur = (ConnectByFirst)? CE.DN( CE.LastParameter(), 1 ) : CE.DN( CE.FirstParameter(), 1 ); |
1490 | if (!ConnectByFirst) |
1491 | TangCur.Reverse(); |
1492 | //check if Vcur is on bounds of faces |
1493 | if (VEmapF1.IsBound(Vcur) || VEmapF2.IsBound(Vcur)) |
1494 | break; |
1495 | } //end of for (;;) |
1496 | |
1497 | if (TangCur.IsParallel( RefTangFirst, AngTol ) || |
1498 | TangCur.IsParallel( RefTangLast, AngTol )) |
1499 | return Standard_True; |
1500 | |
1501 | TrueEdges.Clear(); |
1502 | return Standard_False; |
1503 | } |
1504 | |
1505 | //======================================================================= |
1506 | //function : AssembleEdge |
1507 | //purpose : |
1508 | //======================================================================= |
1509 | |
1510 | static TopoDS_Edge AssembleEdge(const BOPTools_DSFiller* pDF, |
1511 | const TopoDS_Face& F1, |
1512 | const TopoDS_Face& F2, |
1513 | const Standard_Boolean addPCurve1, |
1514 | const Standard_Boolean addPCurve2, |
1515 | const TopTools_SequenceOfShape& EdgesForConcat) |
1516 | { |
1517 | TopoDS_Edge CurEdge = TopoDS::Edge( EdgesForConcat(1) ); |
1518 | for (Standard_Integer j = 2; j <= EdgesForConcat.Length(); j++) |
1519 | { |
1520 | TopoDS_Edge anEdge = TopoDS::Edge( EdgesForConcat(j) ); |
1521 | Standard_Boolean After = Standard_False; |
1522 | TopoDS_Vertex Vfirst, Vlast; |
1523 | if (AreClosed( CurEdge, anEdge )) |
1524 | { |
1525 | TopoDS_Vertex V1, V2; |
1526 | TopExp::Vertices( CurEdge, V1, V2 ); |
1527 | if (IsAutonomVertex( V1, F1, F2, pDF->DS(), pDF->PaveFiller() )) |
1528 | { |
1529 | After = Standard_False; |
1530 | Vfirst = Vlast = V2; |
1531 | } |
1532 | else |
1533 | { |
1534 | After = Standard_True; |
1535 | Vfirst = Vlast = V1; |
1536 | } |
1537 | } |
1538 | else |
1539 | { |
1540 | TopoDS_Vertex CV, V11, V12, V21, V22; |
1541 | TopExp::CommonVertex( CurEdge, anEdge, CV ); |
1542 | TopExp::Vertices( CurEdge, V11, V12 ); |
1543 | TopExp::Vertices( anEdge, V21, V22 ); |
1544 | if (V11.IsSame(CV) && V21.IsSame(CV)) |
1545 | { |
1546 | Vfirst = V22; |
1547 | Vlast = V12; |
1548 | } |
1549 | else if (V11.IsSame(CV) && V22.IsSame(CV)) |
1550 | { |
1551 | Vfirst = V21; |
1552 | Vlast = V12; |
1553 | } |
1554 | else if (V12.IsSame(CV) && V21.IsSame(CV)) |
1555 | { |
1556 | Vfirst = V11; |
1557 | Vlast = V22; |
1558 | } |
1559 | else |
1560 | { |
1561 | Vfirst = V11; |
1562 | Vlast = V21; |
1563 | } |
1564 | } //end of else (open wire) |
1565 | |
1566 | TopoDS_Edge NewEdge = Glue(CurEdge, anEdge, |
1567 | Vfirst, Vlast, After, |
1568 | F1, addPCurve1, F2, addPCurve2); |
1569 | CurEdge = NewEdge; |
1570 | } //end of for (Standard_Integer j = 2; j <= EdgesForConcat.Length(); j++) |
1571 | |
1572 | return CurEdge; |
1573 | } |
1574 | |
1575 | //======================================================================= |
1576 | //function : Inter3D |
1577 | //purpose : |
1578 | //======================================================================= |
1579 | |
1580 | void BRepOffset_Tool::Inter3D(const TopoDS_Face& F1, |
1581 | const TopoDS_Face& F2, |
1582 | TopTools_ListOfShape& L1, |
1583 | TopTools_ListOfShape& L2, |
1584 | const TopAbs_State Side, |
1585 | const TopoDS_Edge& RefEdge, |
1586 | const Standard_Boolean IsRefEdgeDefined) |
1587 | { |
1588 | #ifdef DRAW |
1589 | if (AffichInter) { |
1590 | // POP pour NT |
1591 | char* name = new char[100]; |
1592 | sprintf(name,"FF_%d",NbFaces++); |
1593 | DBRep::Set(name,F1); |
1594 | sprintf(name,"FF_%d",NbFaces++); |
1595 | DBRep::Set(name,F2); |
1596 | } |
1597 | #endif |
1598 | |
1599 | TopoDS_Face cpF1=F1; |
1600 | TopoDS_Face cpF2=F2; |
1601 | // create 3D curves on faces |
1602 | BRepLib::BuildCurves3d(cpF1); |
1603 | BRepLib::BuildCurves3d(cpF2); |
1604 | |
1605 | BOPTools_DSFiller pDF1, pDF2; |
1606 | pDF1.SetShapes(cpF1, cpF2); |
1607 | |
1608 | pDF1.Perform(); |
1609 | |
1610 | BOPTools_DSFiller * pDF = &pDF1; |
1611 | TopTools_IndexedMapOfShape TrueEdges; |
1612 | if (IsRefEdgeDefined && !CheckIntersFF( pDF1, RefEdge, cpF1, cpF2, TrueEdges )) |
1613 | { |
1614 | cpF1 = F2; |
1615 | cpF2 = F1; |
1616 | pDF2.SetShapes(cpF1, cpF2); |
1617 | pDF2.Perform(); |
1618 | CheckIntersFF( pDF2, RefEdge, cpF1, cpF2, TrueEdges ); |
1619 | pDF = &pDF2; |
1620 | } |
1621 | |
1622 | Standard_Boolean addPCurve1 = pDF->PaveFiller().SectionAttribute().PCurveOnS1(); |
1623 | Standard_Boolean addPCurve2 = pDF->PaveFiller().SectionAttribute().PCurveOnS2(); |
1624 | |
1625 | const BooleanOperations_ShapesDataStructure& aDS = pDF->DS(); |
1626 | BOPTools_InterferencePool* anIntrPool = (BOPTools_InterferencePool*)& pDF->InterfPool(); |
1627 | BOPTools_CArray1OfSSInterference& aFFs = anIntrPool->SSInterferences(); |
1628 | Standard_Integer aNb = aFFs.Extent(); |
1629 | Standard_Integer i = 0, j = 0, k; |
1630 | // Store Result |
1631 | L1.Clear(); L2.Clear(); |
1632 | TopAbs_Orientation O1,O2; |
1633 | |
1634 | for (i = 1; i <= aNb; i++) { |
1635 | BOPTools_SSInterference& aFFi = aFFs(i); |
1636 | BOPTools_SequenceOfCurves& aBCurves = aFFi.Curves(); |
1637 | Standard_Integer aNbCurves = aBCurves.Length(); |
1638 | |
1639 | for (j = 1; j <= aNbCurves; j++) { |
1640 | BOPTools_Curve& aBC = aBCurves(j); |
1641 | const BOPTools_ListOfPaveBlock& aSectEdges = aBC.NewPaveBlocks(); |
1642 | |
1643 | BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges); |
1644 | |
1645 | for (; aPBIt.More(); aPBIt.Next()) { |
1646 | BOPTools_PaveBlock& aPB=aPBIt.Value(); |
1647 | Standard_Integer nSect = aPB.Edge(); |
1648 | TopoDS_Edge anEdge = TopoDS::Edge(aDS.Shape(nSect)); |
1649 | if (!TrueEdges.IsEmpty() && !TrueEdges.Contains(anEdge)) |
1650 | continue; |
1651 | |
1652 | Standard_Real f, l; |
1653 | const Handle(Geom_Curve)& aC3DE = BRep_Tool::Curve(anEdge, f, l); |
1654 | Handle(Geom_TrimmedCurve) aC3DETrim; |
1655 | |
1656 | if(!aC3DE.IsNull()) |
1657 | aC3DETrim = new Geom_TrimmedCurve(aC3DE, f, l); |
1658 | |
1659 | BRep_Builder aBB; |
1660 | Standard_Real aTolEdge = BRep_Tool::Tolerance(anEdge); |
1661 | |
1662 | if (!BOPTools_Tools2D::HasCurveOnSurface(anEdge, cpF1)) { |
1663 | Handle(Geom2d_Curve) aC2d = aBC.Curve().FirstCurve2d(); |
1664 | if(!aC3DETrim.IsNull()) { |
1665 | Handle(Geom2d_Curve) aC2dNew; |
1666 | |
1667 | if(aC3DE->IsPeriodic()) { |
1668 | BOPTools_Tools2D::AdjustPCurveOnFace(cpF1, f, l, aC2d, aC2dNew); |
1669 | } |
1670 | else { |
1671 | BOPTools_Tools2D::AdjustPCurveOnFace(cpF1, aC3DETrim, aC2d, aC2dNew); |
1672 | } |
1673 | aC2d = aC2dNew; |
1674 | } |
1675 | aBB.UpdateEdge(anEdge, aC2d, cpF1, aTolEdge); |
1676 | } |
1677 | |
1678 | if (!BOPTools_Tools2D::HasCurveOnSurface(anEdge, cpF2)) { |
1679 | Handle(Geom2d_Curve) aC2d = aBC.Curve().SecondCurve2d(); |
1680 | if(!aC3DETrim.IsNull()) { |
1681 | Handle(Geom2d_Curve) aC2dNew; |
1682 | |
1683 | if(aC3DE->IsPeriodic()) { |
1684 | BOPTools_Tools2D::AdjustPCurveOnFace(cpF2, f, l, aC2d, aC2dNew); |
1685 | } |
1686 | else { |
1687 | BOPTools_Tools2D::AdjustPCurveOnFace(cpF2, aC3DETrim, aC2d, aC2dNew); |
1688 | } |
1689 | aC2d = aC2dNew; |
1690 | } |
1691 | aBB.UpdateEdge(anEdge, aC2d, cpF2, aTolEdge); |
1692 | } |
1693 | |
1694 | OrientSection (anEdge, F1, F2, O1, O2); |
1695 | if (Side == TopAbs_OUT) { |
1696 | O1 = TopAbs::Reverse(O1); |
1697 | O2 = TopAbs::Reverse(O2); |
1698 | } |
1699 | |
1700 | L1.Append (anEdge.Oriented(O1)); |
1701 | L2.Append (anEdge.Oriented(O2)); |
1702 | |
1703 | #ifdef DRAW |
1704 | if (AffichInter) { |
1705 | char* name = new char[100]; |
1706 | sprintf(name,"EI_%d",NbNewEdges++); |
1707 | DBRep::Set(name,anEdge.Oriented(O1)); |
1708 | |
1709 | } |
1710 | #endif |
1711 | } |
1712 | } |
1713 | } |
1714 | |
1715 | Standard_Real aSameParTol = Precision::Confusion(); |
1716 | Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False; |
1717 | |
1718 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(cpF1); |
1719 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) |
1720 | aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface(); |
1721 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane))) |
1722 | addPCurve1 = Standard_False; |
1723 | else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) |
1724 | isEl1 = Standard_True; |
1725 | |
1726 | aSurf = BRep_Tool::Surface(cpF2); |
1727 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) |
1728 | aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface(); |
1729 | if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane))) |
1730 | addPCurve2 = Standard_False; |
1731 | else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) |
1732 | isEl2 = Standard_True; |
1733 | |
1734 | if (L1.Extent() > 1 && (!isEl1 || !isEl2)) { |
1735 | TopTools_SequenceOfShape eseq; |
1736 | TopTools_SequenceOfShape EdgesForConcat; |
1737 | |
1738 | if (!TrueEdges.IsEmpty()) |
1739 | { |
1740 | for (i = TrueEdges.Extent(); i >= 1; i--) |
1741 | EdgesForConcat.Append( TrueEdges(i) ); |
1742 | TopoDS_Edge theEdge = |
1743 | AssembleEdge( pDF, cpF1, cpF2, addPCurve1, addPCurve2, EdgesForConcat ); |
1744 | eseq.Append(theEdge); |
1745 | } |
1746 | else |
1747 | { |
1748 | const BOPTools_PaveFiller& thePaveFiller = pDF->PaveFiller(); |
1749 | |
1750 | TopTools_SequenceOfShape wseq; |
1751 | TopTools_SequenceOfShape edges; |
1752 | TopTools_ListIteratorOfListOfShape itl(L1); |
1753 | for (; itl.More(); itl.Next()) |
1754 | edges.Append( itl.Value() ); |
1755 | while (!edges.IsEmpty()) |
1756 | { |
1757 | TopoDS_Edge anEdge = TopoDS::Edge( edges.First() ); |
1758 | TopoDS_Wire aWire = BRepLib_MakeWire( anEdge ), resWire; |
1759 | TColStd_SequenceOfInteger Candidates; |
1760 | for (k = 1; k <= wseq.Length(); k++) |
1761 | { |
1762 | resWire = TopoDS::Wire(wseq(k)); |
1763 | if (AreConnex( resWire, aWire, cpF1, cpF2, pDF )) |
1764 | { |
1765 | Candidates.Append( 1 ); |
1766 | break; |
1767 | } |
1768 | } |
1769 | if (Candidates.IsEmpty()) |
1770 | { |
1771 | wseq.Append( aWire ); |
1772 | edges.Remove(1); |
1773 | } |
1774 | else |
1775 | { |
1776 | for (j = 2; j <= edges.Length(); j++) |
1777 | { |
1778 | anEdge = TopoDS::Edge( edges(j) ); |
1779 | //if (anEdge.IsSame(edges(Candidates.First()))) |
1780 | //continue; |
1781 | aWire = BRepLib_MakeWire( anEdge ); |
1782 | if (AreConnex( resWire, aWire, cpF1, cpF2, pDF )) |
1783 | Candidates.Append( j ); |
1784 | } |
1785 | Standard_Integer minind = 1; |
1786 | if (Candidates.Length() > 1) |
1787 | { |
1788 | Standard_Real MinAngle = RealLast(); |
1789 | for (j = 1; j <= Candidates.Length(); j++) |
1790 | { |
1791 | anEdge = TopoDS::Edge( edges(Candidates(j)) ); |
1792 | Standard_Real anAngle = AngleWireEdge( resWire, anEdge ); |
1793 | if (anAngle < MinAngle) |
1794 | { |
1795 | MinAngle = anAngle; |
1796 | minind = j; |
1797 | } |
1798 | } |
1799 | } |
1800 | TopoDS_Wire NewWire = BRepLib_MakeWire( resWire, TopoDS::Edge(edges(Candidates(minind))) ); |
1801 | wseq(k) = NewWire; |
1802 | edges.Remove(Candidates(minind)); |
1803 | } |
1804 | } //end of while (!edges.IsEmpty()) |
1805 | |
1806 | for (i = 1; i <= wseq.Length(); i++) |
1807 | { |
1808 | TopoDS_Wire aWire = TopoDS::Wire(wseq(i)); |
1809 | TopTools_SequenceOfShape EdgesForConcat; |
1810 | if (aWire.Closed()) |
1811 | { |
1812 | TopoDS_Vertex StartVertex; |
1813 | TopoDS_Edge StartEdge; |
1814 | Standard_Boolean StartFound = Standard_False; |
1815 | TopTools_ListOfShape Elist; |
1816 | |
1817 | TopoDS_Iterator itw(aWire); |
1818 | for (; itw.More(); itw.Next()) |
1819 | { |
1820 | TopoDS_Edge anEdge = TopoDS::Edge(itw.Value()); |
1821 | if (StartFound) |
1822 | Elist.Append(anEdge); |
1823 | else |
1824 | { |
1825 | TopoDS_Vertex V1, V2; |
1826 | TopExp::Vertices( anEdge, V1, V2 ); |
1827 | if (!IsAutonomVertex( V1, cpF1, cpF2, aDS, thePaveFiller )) |
1828 | { |
1829 | StartVertex = V2; |
1830 | StartEdge = anEdge; |
1831 | StartFound = Standard_True; |
1832 | } |
1833 | else if (!IsAutonomVertex( V2, cpF1, cpF2, aDS, thePaveFiller )) |
1834 | { |
1835 | StartVertex = V1; |
1836 | StartEdge = anEdge; |
1837 | StartFound = Standard_True; |
1838 | } |
1839 | else |
1840 | Elist.Append(anEdge); |
1841 | } |
1842 | } //end of for (; itw.More(); itw.Next()) |
1843 | if (!StartFound) |
1844 | { |
1845 | itl.Initialize(Elist); |
1846 | StartEdge = TopoDS::Edge(itl.Value()); |
1847 | Elist.Remove(itl); |
1848 | TopoDS_Vertex V1, V2; |
1849 | TopExp::Vertices( StartEdge, V1, V2 ); |
1850 | StartVertex = V1; |
1851 | } |
1852 | EdgesForConcat.Append( StartEdge ); |
1853 | while (!Elist.IsEmpty()) |
1854 | { |
1855 | for (itl.Initialize(Elist); itl.More(); itl.Next()) |
1856 | { |
1857 | TopoDS_Edge anEdge = TopoDS::Edge(itl.Value()); |
1858 | TopoDS_Vertex V1, V2; |
1859 | TopExp::Vertices( anEdge, V1, V2 ); |
1860 | if (V1.IsSame(StartVertex)) |
1861 | { |
1862 | StartVertex = V2; |
1863 | EdgesForConcat.Append( anEdge ); |
1864 | Elist.Remove(itl); |
1865 | break; |
1866 | } |
1867 | else if (V2.IsSame(StartVertex)) |
1868 | { |
1869 | StartVertex = V1; |
1870 | EdgesForConcat.Append( anEdge ); |
1871 | Elist.Remove(itl); |
1872 | break; |
1873 | } |
1874 | } |
1875 | } //end of while (!Elist.IsEmpty()) |
1876 | } //end of if (aWire.Closed()) |
1877 | else |
1878 | { |
1879 | BRepTools_WireExplorer Wexp( aWire ); |
1880 | for (; Wexp.More(); Wexp.Next()) |
1881 | EdgesForConcat.Append( Wexp.Current() ); |
1882 | } |
1883 | |
1884 | TopoDS_Edge theEdge = |
1885 | AssembleEdge( pDF, cpF1, cpF2, addPCurve1, addPCurve2, EdgesForConcat ); |
1886 | eseq.Append( theEdge ); |
1887 | } |
1888 | } //end of else (when TrueEdges is empty) |
1889 | |
1890 | if (eseq.Length() < L1.Extent()) |
1891 | { |
1892 | L1.Clear(); |
1893 | L2.Clear(); |
1894 | for (i = 1; i <= eseq.Length(); i++) |
1895 | { |
1896 | TopoDS_Edge anEdge = TopoDS::Edge(eseq(i)); |
1897 | BRepLib::SameParameter(anEdge, aSameParTol, Standard_True); |
1898 | Standard_Real EdgeTol = BRep_Tool::Tolerance(anEdge); |
1899 | #ifdef DEB |
1900 | cout<<"Tolerance of glued E = "<<EdgeTol<<endl; |
1901 | #endif |
1902 | if (EdgeTol > 1.e-2) |
1903 | continue; |
1904 | |
1905 | if (EdgeTol >= 1.e-4) |
1906 | { |
1907 | ReconstructPCurves(anEdge); |
1908 | BRepLib::SameParameter(anEdge, aSameParTol, Standard_True); |
1909 | #ifdef DEB |
1910 | cout<<"After projection tol of E = "<<BRep_Tool::Tolerance(anEdge)<<endl; |
1911 | #endif |
1912 | } |
1913 | |
1914 | OrientSection( anEdge, F1, F2, O1, O2 ); |
1915 | if (Side == TopAbs_OUT) |
1916 | { |
1917 | O1 = TopAbs::Reverse(O1); |
1918 | O2 = TopAbs::Reverse(O2); |
1919 | } |
1920 | |
1921 | L1.Append( anEdge.Oriented(O1) ); |
1922 | L2.Append( anEdge.Oriented(O2) ); |
1923 | } |
1924 | } |
1925 | } //end of if (L1.Extent() > 1) |
1926 | |
1927 | else |
1928 | { |
1929 | TopTools_ListIteratorOfListOfShape itl(L1); |
1930 | for (; itl.More(); itl.Next()) |
1931 | { |
1932 | const TopoDS_Edge& anEdge = TopoDS::Edge( itl.Value() ); |
1933 | BRepLib::SameParameter(anEdge, aSameParTol, Standard_True); |
1934 | } |
1935 | } |
1936 | } |
1937 | |
1938 | //======================================================================= |
1939 | //function : TryProject |
1940 | //purpose : |
1941 | //======================================================================= |
1942 | |
1943 | Standard_Boolean BRepOffset_Tool::TryProject |
1944 | (const TopoDS_Face& F1, |
1945 | const TopoDS_Face& F2, |
1946 | const TopTools_ListOfShape& Edges, |
1947 | TopTools_ListOfShape& LInt1, |
1948 | TopTools_ListOfShape& LInt2, |
1949 | const TopAbs_State Side, |
1950 | const Standard_Real TolConf) |
1951 | { |
1952 | #ifdef DRAW |
1953 | if (AffichInter) { |
1954 | // POP pour NT |
1955 | char* name = new char[100]; |
1956 | sprintf(name,"FF_%d",NbFaces++); |
1957 | DBRep::Set(name,F1); |
1958 | sprintf(name,"FF_%d",NbFaces++); |
1959 | DBRep::Set(name,F2); |
1960 | } |
1961 | #endif |
1962 | |
1963 | // try to find if the edges <Edges> are laying on the face F1. |
1964 | LInt1.Clear(); LInt2.Clear(); |
1965 | TopTools_ListIteratorOfListOfShape it(Edges); |
1966 | Standard_Boolean isOk = Standard_True; |
1967 | Standard_Boolean Ok = Standard_True; |
1968 | TopAbs_Orientation O1,O2; |
1969 | Handle(Geom_Surface) Bouchon = BRep_Tool::Surface(F1); |
1970 | BRep_Builder B; |
1971 | |
1972 | for ( ; it.More(); it.Next()) { |
1973 | TopLoc_Location L; |
1974 | Standard_Real f,l; |
1975 | TopoDS_Edge CurE = TopoDS::Edge(it.Value()); |
1976 | Handle(Geom_Curve) C = BRep_Tool::Curve(CurE,L,f,l); |
1977 | if (C.IsNull()) { |
1978 | BRepLib::BuildCurve3d(CurE,BRep_Tool::Tolerance(CurE)); |
1979 | C = BRep_Tool::Curve(CurE,L,f,l); |
1980 | } |
1981 | C = new Geom_TrimmedCurve(C,f,l); |
1982 | if ( !L.IsIdentity()) C->Transform(L); |
1983 | Standard_Real TolReached; |
1984 | isOk = IsOnSurface(C,Bouchon,TolConf,TolReached); |
1985 | |
1986 | if ( isOk) { |
1987 | B.UpdateEdge(CurE,TolReached); |
1988 | BuildPCurves(CurE,F1); |
1989 | OrientSection (CurE,F1,F2,O1,O2); |
1990 | if (Side == TopAbs_OUT) { |
1991 | O1 = TopAbs::Reverse(O1); |
1992 | O2 = TopAbs::Reverse(O2); |
1993 | } |
1994 | LInt1.Append (CurE.Oriented(O1)); |
1995 | LInt2.Append (CurE.Oriented(O2)); |
1996 | #ifdef DRAW |
1997 | if (AffichInter) { |
1998 | // POP pour NT |
1999 | char* name = new char[100]; |
2000 | sprintf(name,"EI_%d",NbNewEdges++); |
2001 | DBRep::Set(name,CurE.Oriented(O1)); |
2002 | } |
2003 | #endif |
2004 | } |
2005 | else |
2006 | Ok = Standard_False; |
2007 | } |
2008 | return Ok; |
2009 | } |
2010 | |
2011 | |
2012 | //======================================================================= |
2013 | //function : InterOrExtent |
2014 | //purpose : |
2015 | //======================================================================= |
2016 | |
2017 | void BRepOffset_Tool::InterOrExtent(const TopoDS_Face& F1, |
2018 | const TopoDS_Face& F2, |
2019 | TopTools_ListOfShape& L1, |
2020 | TopTools_ListOfShape& L2, |
2021 | const TopAbs_State Side) |
2022 | { |
2023 | #ifdef DRAW |
2024 | if (AffichInter) { |
2025 | // POP pour NT |
2026 | char* name = new char[100]; |
2027 | sprintf(name,"FF_%d",NbFaces++); |
2028 | DBRep::Set(name,F1); |
2029 | sprintf(name,"FF_%d",NbFaces++); |
2030 | DBRep::Set(name,F2); |
2031 | } |
2032 | #endif |
2033 | |
2034 | Handle (Geom_Curve) CI; |
2035 | TopoDS_Edge E; |
2036 | TopAbs_Orientation O1,O2; |
2037 | L1.Clear(); L2.Clear(); |
2038 | Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1); |
2039 | Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2); |
2040 | |
2041 | if (S1->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
2042 | Handle(Geom_RectangularTrimmedSurface) RTS ; |
2043 | RTS = *((Handle(Geom_RectangularTrimmedSurface)*) &S1); |
2044 | if (RTS->BasisSurface()->DynamicType() == STANDARD_TYPE(Geom_Plane)) { |
2045 | S1 = RTS->BasisSurface(); |
2046 | } |
2047 | } |
2048 | if (S2->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
2049 | Handle(Geom_RectangularTrimmedSurface) RTS ; |
2050 | RTS = *((Handle(Geom_RectangularTrimmedSurface)*) &S2); |
2051 | if (RTS->BasisSurface()->DynamicType() == STANDARD_TYPE(Geom_Plane)) { |
2052 | S2 = RTS->BasisSurface(); |
2053 | } |
2054 | } |
2055 | |
2056 | GeomInt_IntSS Inter (S1,S2, Precision::Confusion()); |
2057 | |
2058 | if (Inter.IsDone()) { |
2059 | for (Standard_Integer i = 1; i <= Inter.NbLines(); i++) { |
2060 | CI = Inter.Line(i); |
2061 | |
2062 | if (ToSmall(CI)) continue; |
2063 | TopoDS_Edge E = BRepLib_MakeEdge(CI); |
2064 | BuildPCurves (E,F1); |
2065 | BuildPCurves (E,F2); |
2066 | OrientSection (E,F1,F2,O1,O2); |
2067 | if (Side == TopAbs_OUT) { |
2068 | O1 = TopAbs::Reverse(O1); |
2069 | O2 = TopAbs::Reverse(O2); |
2070 | } |
2071 | L1.Append (E.Oriented(O1)); |
2072 | L2.Append (E.Oriented(O2)); |
2073 | #ifdef DRAW |
2074 | if (AffichInter) { |
2075 | // POP pour NT |
2076 | char* name = new char[100]; |
2077 | sprintf(name,"EI_%d",NbNewEdges++); |
2078 | DBRep::Set(name,E.Oriented(O1)); |
2079 | } |
2080 | #endif |
2081 | } |
2082 | } |
2083 | } |
2084 | |
2085 | //======================================================================= |
2086 | //function : ExtentEdge |
2087 | //purpose : |
2088 | //======================================================================= |
2089 | |
2090 | static void ExtentEdge(const TopoDS_Face& F, |
2091 | const TopoDS_Face& EF, |
2092 | const TopoDS_Edge& E, |
2093 | TopoDS_Edge& NE) |
2094 | { |
2095 | BRepAdaptor_Curve CE(E); |
2096 | GeomAbs_CurveType Type = CE.GetType(); |
2097 | TopoDS_Shape aLocalEdge = E.EmptyCopied(); |
2098 | NE = TopoDS::Edge(aLocalEdge); |
2099 | // NE = TopoDS::Edge(E.EmptyCopied()); |
2100 | |
2101 | if (Type == GeomAbs_Line || Type == GeomAbs_Circle || Type == GeomAbs_Ellipse || |
2102 | Type == GeomAbs_Hyperbola || Type == GeomAbs_Parabola) { |
2103 | return; |
2104 | } |
2105 | // Extension en tangence jusqu'au bord de la surface. |
2106 | Standard_Real PMax = 1.e2; |
2107 | TopLoc_Location L; |
2108 | Handle(Geom_Surface) S = BRep_Tool::Surface(F,L); |
2109 | Standard_Real umin,umax,vmin,vmax; |
2110 | |
2111 | S->Bounds(umin,umax,vmin,vmax); |
2112 | umin = Max(umin,-PMax);vmin = Max(vmin,-PMax); |
2113 | umax = Min(umax, PMax);vmax = Min(vmax, PMax); |
2114 | |
2115 | |
2116 | Standard_Real f,l; |
2117 | Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l); |
2118 | |
2119 | //calcul point cible . ie point d'intersection du prolongement tangent et des bords. |
2120 | gp_Pnt2d P; |
2121 | gp_Vec2d Tang; |
2122 | C2d->D1(CE.FirstParameter(),P,Tang); |
2123 | Standard_Real tx,ty,tmin; |
2124 | tx = ty = Precision::Infinite(); |
2125 | if (Abs(Tang.X()) > Precision::Confusion()) |
2126 | tx = Min (Abs((umax - P.X())/Tang.X()), Abs((umin - P.X())/Tang.X())); |
2127 | if (Abs(Tang.Y()) > Precision::Confusion()) |
2128 | ty = Min (Abs((vmax - P.Y())/Tang.Y()), Abs((vmin - P.Y())/Tang.Y())); |
2129 | tmin = Min (tx,ty); |
2130 | Tang = tmin*Tang; |
2131 | gp_Pnt2d PF2d (P.X() - Tang.X(),P.Y() - Tang.Y()); |
2132 | |
2133 | C2d->D1(CE.LastParameter(),P,Tang); |
2134 | tx = ty = Precision::Infinite(); |
2135 | if (Abs(Tang.X()) > Precision::Confusion()) |
2136 | tx = Min (Abs((umax - P.X())/Tang.X()), Abs((umin - P.X())/Tang.X())); |
2137 | if (Abs(Tang.Y()) > Precision::Confusion()) |
2138 | ty = Min (Abs((vmax - P.Y())/Tang.Y()), Abs((vmin - P.Y())/Tang.Y())); |
2139 | tmin = Min (tx,ty); |
2140 | Tang = tmin*Tang; |
2141 | gp_Pnt2d PL2d (P.X() + Tang.X(),P.Y() + Tang.Y()); |
2142 | |
2143 | Handle(Geom_Curve) CC = GeomAPI::To3d(C2d,gp_Pln(gp::XOY())); |
2144 | gp_Pnt PF(PF2d.X(),PF2d.Y(),0.); |
2145 | gp_Pnt PL(PL2d.X(),PL2d.Y(),0.); |
2146 | |
2147 | Handle(Geom_BoundedCurve) ExtC = Handle(Geom_BoundedCurve)::DownCast(CC); |
2148 | if (ExtC.IsNull()) return; |
2149 | |
2150 | GeomLib::ExtendCurveToPoint(ExtC,PF,1,0); |
2151 | GeomLib::ExtendCurveToPoint(ExtC,PL,1,1); |
2152 | |
2153 | Handle(Geom2d_Curve) CNE2d = GeomAPI::To2d(ExtC,gp_Pln(gp::XOY())); |
2154 | |
2155 | //Construction de la nouvelle arrete; |
2156 | BRep_Builder B; |
2157 | B.MakeEdge(NE); |
2158 | // B.UpdateEdge (NE,CNE2d,F,BRep_Tool::Tolerance(E)); |
2159 | B.UpdateEdge (NE,CNE2d,EF,BRep_Tool::Tolerance(E)); |
2160 | B.Range (NE,CNE2d->FirstParameter(), CNE2d->LastParameter()); |
2161 | NE.Orientation(E.Orientation()); |
2162 | #ifdef DRAW |
2163 | if (AffichExtent) { |
2164 | char* name = new char[100]; |
2165 | sprintf (name,"F_%d",NbExtE); |
2166 | DBRep::Set(name,EF); |
2167 | sprintf (name,"OE_%d",NbExtE); |
2168 | DBRep::Set (name,E); |
2169 | sprintf (name,"ExtE_%d",NbExtE++); |
2170 | DBRep::Set(name,NE); |
2171 | } |
2172 | #endif |
2173 | } |
2174 | |
2175 | //======================================================================= |
2176 | //function : ProjectVertexOnEdge |
2177 | //purpose : |
2178 | //======================================================================= |
2179 | |
2180 | static Standard_Boolean ProjectVertexOnEdge(TopoDS_Vertex& V, |
2181 | const TopoDS_Edge& E, |
2182 | Standard_Real TolConf) |
2183 | { |
2184 | #ifdef DRAW |
2185 | if (AffichExtent) { |
2186 | DBRep::Set("V",V); |
2187 | DBRep::Set("E",E); |
2188 | } |
2189 | #endif |
2190 | BRep_Builder B; |
2191 | Standard_Real f,l; |
2192 | #ifndef DEB |
2193 | Standard_Real U = 0.; |
2194 | #else |
2195 | Standard_Real U; |
2196 | #endif |
2197 | TopLoc_Location L; |
2198 | Standard_Boolean found = Standard_False; |
2199 | |
2200 | gp_Pnt P = BRep_Tool::Pnt (V); |
2201 | BRepAdaptor_Curve C = BRepAdaptor_Curve(E); |
2202 | f = C.FirstParameter(); l = C.LastParameter(); |
2203 | |
2204 | if (V.Orientation() == TopAbs_FORWARD) { |
2205 | if (Abs(f) < Precision::Infinite()) { |
2206 | gp_Pnt PF = C.Value (f); |
2207 | if (PF.IsEqual(P,TolConf)) { |
2208 | U = f; |
2209 | found = Standard_True; |
2210 | } |
2211 | } |
2212 | } |
2213 | if (V.Orientation() == TopAbs_REVERSED) { |
2214 | if (!found && Abs(l) < Precision::Infinite()) { |
2215 | gp_Pnt PL = C.Value (l); |
2216 | if (PL.IsEqual(P,TolConf)) { |
2217 | U = l; |
2218 | found = Standard_True; |
2219 | } |
2220 | } |
2221 | } |
2222 | if (!found) { |
2223 | Extrema_ExtPC Proj(P,C); |
2224 | if (Proj.IsDone() && Proj.NbExt() > 0) { |
2225 | Standard_Real Dist2,Dist2Min = Proj.SquareDistance(1); |
2226 | U = Proj.Point(1).Parameter(); |
2227 | for (Standard_Integer i = 2; i <= Proj.NbExt(); i++) { |
2228 | Dist2 = Proj.SquareDistance(i); |
2229 | if (Dist2 < Dist2Min) { |
2230 | Dist2Min = Dist2; |
2231 | U = Proj.Point(i).Parameter(); |
2232 | } |
2233 | } |
2234 | found = Standard_True; |
2235 | } |
2236 | } |
2237 | |
2238 | #ifdef DEB |
2239 | if (AffichExtent) { |
2240 | Standard_Real Dist = P.Distance(C.Value(U)); |
2241 | if (Dist > TolConf) { |
2242 | cout << " ProjectVertexOnEdge :distance vertex edge :"<<Dist<<endl; |
2243 | } |
2244 | if (U < f - Precision::Confusion() || |
2245 | U > l + Precision::Confusion()) { |
2246 | cout << " ProjectVertexOnEdge : hors borne :"<<endl; |
2247 | cout << " f = "<<f<<" l ="<<l<< " U ="<<U<<endl; |
2248 | } |
2249 | } |
2250 | if (!found) { |
2251 | cout <<"BRepOffset_Tool::ProjectVertexOnEdge Parameter no found"<<endl; |
2252 | if (Abs(f) < Precision::Infinite() && |
2253 | Abs(l) < Precision::Infinite()) { |
2254 | #ifdef DRAW |
2255 | DBRep::Set("E",E); |
2256 | #endif |
2257 | } |
2258 | } |
2259 | #endif |
2260 | if (found) { |
2261 | TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD); |
2262 | TopoDS_Edge EE = TopoDS::Edge(aLocalShape); |
2263 | aLocalShape = V.Oriented(TopAbs_INTERNAL); |
2264 | // TopoDS_Edge EE = TopoDS::Edge(E.Oriented(TopAbs_FORWARD)); |
2265 | B.UpdateVertex(TopoDS::Vertex(aLocalShape), |
2266 | U,EE,BRep_Tool::Tolerance(E)); |
2267 | |
2268 | } |
2269 | return found; |
2270 | } |
2271 | |
2272 | //======================================================================= |
2273 | //function : Inter2d |
2274 | //purpose : |
2275 | //======================================================================= |
2276 | |
2277 | void BRepOffset_Tool::Inter2d (const TopoDS_Face& F, |
2278 | const TopoDS_Edge& E1, |
2279 | const TopoDS_Edge& E2, |
2280 | TopTools_ListOfShape& LV, |
2281 | const Standard_Real TolConf) |
2282 | { |
2283 | #ifdef DRAW |
2284 | if (AffichExtent) { |
2285 | DBRep::Set("E1",E1); |
2286 | DBRep::Set("E2",E2); |
2287 | DBRep::Set("F",F); |
2288 | } |
2289 | #endif |
2290 | BRep_Builder B; |
2291 | Standard_Real fl1[2],fl2[2]; |
2292 | LV.Clear(); |
2293 | |
2294 | // Si l edge a ete etendu les pcurves ne sont pas forcement |
2295 | // a jour. |
2296 | BuildPCurves(E1,F); |
2297 | BuildPCurves(E2,F); |
2298 | |
2299 | |
2300 | // Construction des curves 3d si elles n existent pas |
2301 | // utile pour coder correctement les parametres des vertex |
2302 | // d intersection sur les edges. |
2303 | //TopLoc_Location L; |
2304 | //Standard_Real f,l; |
2305 | //Handle(Geom_Curve) C3d1 = BRep_Tool::Curve(E1,L,f,l); |
2306 | //if (C3d1.IsNull()) { |
2307 | // BRepLib::BuildCurve3d(E1,BRep_Tool::Tolerance(E1)); |
2308 | //} |
2309 | //Handle(Geom_Curve) C3d2 = BRep_Tool::Curve(E2,L,f,l); |
2310 | //if (C3d2.IsNull()) { |
2311 | // BRepLib::BuildCurve3d(E2,BRep_Tool::Tolerance(E2)); |
2312 | //} |
2313 | |
2314 | Standard_Integer NbPC1 = 1, NbPC2 = 1; |
2315 | if (BRep_Tool::IsClosed(E1,F)) NbPC1++; |
2316 | if (BRep_Tool::IsClosed(E2,F)) NbPC2++; |
2317 | |
2318 | Handle(Geom_Surface) S = BRep_Tool::Surface(F); |
2319 | Handle(Geom2d_Curve) C1, C2; |
2320 | Standard_Boolean YaSol = Standard_False; |
2321 | Standard_Integer itry = 0; |
2322 | |
2323 | while (!YaSol && itry < 2) { |
2324 | for ( Standard_Integer i = 1; i <= NbPC1 ; i++) { |
2325 | TopoDS_Shape aLocalEdge = E1.Reversed(); |
2326 | if (i == 1) C1 = BRep_Tool::CurveOnSurface(E1,F,fl1[0],fl1[1]); |
2327 | else C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalEdge), |
2328 | F,fl1[0],fl1[1]); |
2329 | // if (i == 1) C1 = BRep_Tool::CurveOnSurface(E1,F,fl1[0],fl1[1]); |
2330 | // else C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(E1.Reversed()), |
2331 | // F,fl1[0],fl1[1]); |
2332 | for ( Standard_Integer j = 1; j <= NbPC2; j++ ) { |
2333 | TopoDS_Shape aLocalEdge = E2.Reversed(); |
2334 | if (j == 1) C2 = BRep_Tool::CurveOnSurface(E2,F,fl2[0],fl2[1]); |
2335 | else C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalEdge), |
2336 | F,fl2[0],fl2[1]); |
2337 | // if (j == 1) C2 = BRep_Tool::CurveOnSurface(E2,F,fl2[0],fl2[1]); |
2338 | // else C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(E2.Reversed()), |
2339 | // F,fl2[0],fl2[1]); |
2340 | #ifdef DEB |
2341 | if (C1.IsNull() || C2.IsNull()) { |
2342 | cout <<"Inter2d : Pas de pcurve"<<endl; |
2343 | #ifdef DRAW |
2344 | DBRep::Set("E1",E1); |
2345 | DBRep::Set("E2",E2); |
2346 | DBRep::Set("F",F); |
2347 | #endif |
2348 | return; |
2349 | } |
2350 | #endif |
2351 | #ifndef DEB |
2352 | Standard_Real U1 = 0.,U2 = 0.; |
2353 | #else |
2354 | Standard_Real U1,U2; |
2355 | #endif |
2356 | gp_Pnt2d P2d; |
2357 | if (itry == 1) { |
2358 | fl1[0] = C1->FirstParameter(); fl1[1] = C1->LastParameter(); |
2359 | fl2[0] = C2->FirstParameter(); fl2[1] = C2->LastParameter(); |
2360 | } |
2361 | Geom2dAdaptor_Curve AC1(C1,fl1[0],fl1[1]); |
2362 | Geom2dAdaptor_Curve AC2(C2,fl2[0],fl2[1]); |
2363 | |
2364 | if (itry == 0) { |
2365 | gp_Pnt2d P1[2],P2[2]; |
2366 | P1[0] = C1->Value(fl1[0]); P1[1] = C1->Value(fl1[1]); |
2367 | P2[0] = C2->Value(fl2[0]); P2[1] = C2->Value(fl2[1]); |
2368 | |
2369 | Standard_Integer i1 ; |
2370 | for ( i1 = 0; i1 < 2; i1++) { |
2371 | for (Standard_Integer i2 = 0; i2 < 2; i2++) { |
2372 | if (Abs(fl1[i1]) < Precision::Infinite() && |
2373 | Abs(fl2[i2]) < Precision::Infinite() ) { |
2374 | if (P1[i1].IsEqual(P2[i2],TolConf)) { |
2375 | YaSol = Standard_True; |
2376 | U1 = fl1[i1]; U2 = fl2[i2]; |
2377 | P2d = C1->Value(U1); |
2378 | } |
2379 | } |
2380 | } |
2381 | } |
2382 | if (!YaSol) |
2383 | for (i1 = 0; i1 < 2; i1++) |
2384 | { |
2385 | Extrema_ExtPC2d extr( P1[i1], AC2 ); |
2386 | if (extr.IsDone() && extr.NbExt() > 0) |
2387 | { |
2388 | Standard_Real Dist2, Dist2Min = extr.SquareDistance(1); |
2389 | Standard_Integer IndexMin = 1; |
2390 | for (Standard_Integer ind = 2; ind <= extr.NbExt(); ind++) |
2391 | { |
2392 | Dist2 = extr.SquareDistance(ind); |
2393 | if (Dist2 < Dist2Min) |
2394 | { |
2395 | Dist2Min = Dist2; |
2396 | IndexMin = ind; |
2397 | } |
2398 | } |
2399 | if (Dist2Min <= Precision::Confusion() * Precision::Confusion()) |
2400 | { |
2401 | YaSol = Standard_True; |
2402 | P2d = P1[i1]; |
2403 | U1 = fl1[i1]; |
2404 | U2 = (extr.Point(IndexMin)).Parameter(); |
2405 | break; |
2406 | } |
2407 | } |
2408 | } |
2409 | if (!YaSol) |
2410 | for (Standard_Integer i2 = 0; i2 < 2; i2++) |
2411 | { |
2412 | Extrema_ExtPC2d extr( P2[i2], AC1 ); |
2413 | if (extr.IsDone() && extr.NbExt() > 0) |
2414 | { |
2415 | Standard_Real Dist2, Dist2Min = extr.SquareDistance(1); |
2416 | Standard_Integer IndexMin = 1; |
2417 | for (Standard_Integer ind = 2; ind <= extr.NbExt(); ind++) |
2418 | { |
2419 | Dist2 = extr.SquareDistance(ind); |
2420 | if (Dist2 < Dist2Min) |
2421 | { |
2422 | Dist2Min = Dist2; |
2423 | IndexMin = ind; |
2424 | } |
2425 | } |
2426 | if (Dist2Min <= Precision::Confusion() * Precision::Confusion()) |
2427 | { |
2428 | YaSol = Standard_True; |
2429 | P2d = P2[i2]; |
2430 | U2 = fl2[i2]; |
2431 | U1 = (extr.Point(IndexMin)).Parameter(); |
2432 | break; |
2433 | } |
2434 | } |
2435 | } |
2436 | } |
2437 | |
2438 | if (!YaSol) { |
2439 | Geom2dInt_GInter Inter (AC1,AC2,TolConf,TolConf); |
2440 | |
2441 | if (!Inter.IsEmpty() && Inter.NbPoints() > 0) { |
2442 | YaSol = Standard_True; |
2443 | U1 = Inter.Point(1).ParamOnFirst(); |
2444 | U2 = Inter.Point(1).ParamOnSecond(); |
2445 | P2d = Inter.Point(1).Value(); |
2446 | } |
2447 | else if (!Inter.IsEmpty() && Inter.NbSegments() > 0) { |
2448 | YaSol = Standard_True; |
2449 | IntRes2d_IntersectionSegment Seg = Inter.Segment(1); |
2450 | IntRes2d_IntersectionPoint IntP1 = Seg.FirstPoint(); |
2451 | IntRes2d_IntersectionPoint IntP2 = Seg.LastPoint(); |
2452 | Standard_Real U1on1 = IntP1.ParamOnFirst(); |
2453 | Standard_Real U1on2 = IntP2.ParamOnFirst(); |
2454 | Standard_Real U2on1 = IntP1.ParamOnSecond(); |
2455 | Standard_Real U2on2 = IntP2.ParamOnSecond(); |
2456 | #ifdef DEB |
2457 | cout << " BRepOffset_Tool::Inter2d SEGMENT d intersection" << endl; |
2458 | cout << " ===> Parametres sur Curve1 : "; |
2459 | cout << U1on1 << " " << U1on2 << endl; |
2460 | cout << " ===> Parametres sur Curve2 : "; |
2461 | cout << U2on1 << " " << U2on2 << endl; |
2462 | #endif |
2463 | U1 = (U1on1 + U1on2)/2.; |
2464 | U2 = (U2on1 + U2on2)/2.; |
2465 | gp_Pnt2d P2d1 = C1->Value(U1); |
2466 | gp_Pnt2d P2d2 = C2->Value(U2); |
2467 | P2d.SetX( (P2d1.X() + P2d2.X()) / 2.); |
2468 | P2d.SetY( (P2d1.Y() + P2d2.Y()) / 2.); |
2469 | } |
2470 | } |
2471 | if (YaSol) { |
2472 | gp_Pnt P = S->Value(P2d.X(),P2d.Y()); |
2473 | TopoDS_Vertex V = BRepLib_MakeVertex(P); |
2474 | V.Orientation(TopAbs_INTERNAL); |
2475 | TopoDS_Shape aLocalEdge = E1.Oriented(TopAbs_FORWARD); |
2476 | B.UpdateVertex(V,U1,TopoDS::Edge(aLocalEdge),TolConf); |
2477 | aLocalEdge = E2.Oriented(TopAbs_FORWARD); |
2478 | B.UpdateVertex(V,U2,TopoDS::Edge(aLocalEdge),TolConf); |
2479 | // B.UpdateVertex(V,U1,TopoDS::Edge(E1.Oriented(TopAbs_FORWARD)),TolConf); |
2480 | // B.UpdateVertex(V,U2,TopoDS::Edge(E2.Oriented(TopAbs_FORWARD)),TolConf); |
2481 | LV.Append(V); |
2482 | } |
2483 | } |
2484 | } |
2485 | itry++; |
2486 | } |
2487 | |
2488 | if (LV.Extent() > 1) { |
2489 | //------------------------------------------------ |
2490 | // garde seulement les vertex les plus proches du |
2491 | //debut et de la fin. |
2492 | //------------------------------------------------ |
2493 | TopTools_ListIteratorOfListOfShape it(LV); |
2494 | TopoDS_Vertex VF,VL; |
2495 | Standard_Real UMin = Precision::Infinite(); |
2496 | Standard_Real UMax = -Precision::Infinite(); |
2497 | Standard_Real U; |
2498 | |
2499 | for ( ; it.More(); it.Next()) { |
2500 | TopoDS_Vertex CV = TopoDS::Vertex(it.Value()); |
2501 | TopoDS_Shape aLocalEdge = E1.Oriented(TopAbs_FORWARD); |
2502 | U = BRep_Tool::Parameter(CV,TopoDS::Edge(aLocalEdge)); |
2503 | // U = BRep_Tool::Parameter(CV,TopoDS::Edge(E1.Oriented(TopAbs_FORWARD))); |
2504 | if ( U < UMin) { |
2505 | VF = CV; UMin = U; |
2506 | } |
2507 | if ( U > UMax) { |
2508 | VL = CV; UMax = U; |
2509 | } |
2510 | } |
2511 | LV.Clear();LV.Append(VF); LV.Append(VL); |
2512 | } |
2513 | |
2514 | #ifdef DEB |
2515 | if (!YaSol) { |
2516 | cout <<"Inter2d : Pas de solution"<<endl; |
2517 | #ifdef DRAW |
2518 | DBRep::Set("E1",E1); |
2519 | DBRep::Set("E2",E2); |
2520 | DBRep::Set("F",F); |
2521 | #endif |
2522 | } |
2523 | #endif |
2524 | } |
2525 | |
2526 | //======================================================================= |
2527 | //function : SelectEdge |
2528 | //purpose : |
2529 | //======================================================================= |
2530 | |
2531 | static void SelectEdge (const TopoDS_Face& F, |
2532 | const TopoDS_Face& EF, |
2533 | const TopoDS_Edge& E, |
2534 | TopTools_ListOfShape& LInt) |
2535 | { |
2536 | //------------------------------------------------------------ |
2537 | // detrompeur sur les intersections sur les faces periodiques |
2538 | //------------------------------------------------------------ |
2539 | TopTools_ListIteratorOfListOfShape it(LInt); |
2540 | Standard_Real dU = 1.0e100; |
2541 | TopoDS_Edge GE; |
2542 | |
2543 | Standard_Real Fst, Lst, tmp; |
2544 | BRep_Tool::Range(E, Fst, Lst); |
2545 | BRepAdaptor_Curve Ad1(E); |
2546 | |
2547 | gp_Pnt PFirst = Ad1.Value( Fst ); |
2548 | gp_Pnt PLast = Ad1.Value( Lst ); |
2549 | |
2550 | //---------------------------------------------------------------------- |
2551 | // Selection de l edge qui couvre le plus le domaine de l edge initiale. |
2552 | //---------------------------------------------------------------------- |
2553 | for (; it.More(); it.Next()) { |
2554 | const TopoDS_Edge& EI = TopoDS::Edge(it.Value()); |
2555 | |
2556 | BRep_Tool::Range(EI, Fst, Lst); |
2557 | BRepAdaptor_Curve Ad2(EI); |
2558 | gp_Pnt P1 = Ad2.Value(Fst); |
2559 | gp_Pnt P2 = Ad2.Value(Lst); |
2560 | |
2561 | tmp = P1.Distance(PFirst) + P2.Distance(PLast); |
2562 | if( tmp <= dU ) { |
2563 | dU = tmp; |
2564 | GE = EI; |
2565 | } |
2566 | |
2567 | } |
2568 | LInt.Clear(); |
2569 | LInt.Append(GE); |
2570 | } |
2571 | |
2572 | |
2573 | //======================================================================= |
2574 | //function : Init |
2575 | //purpose : |
2576 | //======================================================================= |
2577 | |
2578 | static void MakeFace(const Handle(Geom_Surface)& S, |
2579 | const Standard_Real Um, |
2580 | const Standard_Real UM, |
2581 | const Standard_Real Vm, |
2582 | const Standard_Real VM, |
2583 | const Standard_Boolean isVminDegen, |
2584 | const Standard_Boolean isVmaxDegen, |
2585 | TopoDS_Face& F) |
2586 | { |
2587 | Standard_Real UMin = Um; |
2588 | Standard_Real UMax = UM; |
2589 | Standard_Real VMin = Vm; |
2590 | Standard_Real VMax = VM; |
2591 | Standard_Real epsilon = Precision::Confusion(); |
2592 | |
2593 | Standard_Real umin,umax,vmin,vmax; |
2594 | S->Bounds(umin,umax,vmin,vmax); |
2595 | |
2596 | |
2597 | // compute infinite flags |
2598 | Standard_Boolean umininf = Precision::IsNegativeInfinite(UMin); |
2599 | Standard_Boolean umaxinf = Precision::IsPositiveInfinite(UMax); |
2600 | Standard_Boolean vmininf = Precision::IsNegativeInfinite(VMin); |
2601 | Standard_Boolean vmaxinf = Precision::IsPositiveInfinite(VMax); |
2602 | |
2603 | // closed flag |
2604 | Standard_Boolean IsSuclosed = S->IsUClosed(), IsSvclosed = S->IsVClosed(); |
2605 | if (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)) |
2606 | { |
2607 | Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&S))->BasisSurface(); |
2608 | IsSuclosed = BasisSurf->IsUClosed(); |
2609 | IsSvclosed = BasisSurf->IsVClosed(); |
2610 | } |
2611 | |
2612 | Standard_Boolean uclosed = |
2613 | IsSuclosed && |
2614 | Abs(UMin - umin) < epsilon && |
2615 | Abs(UMax - umax) < epsilon; |
2616 | |
2617 | Standard_Boolean vclosed = |
2618 | IsSvclosed && |
2619 | Abs(VMin - vmin) < epsilon && |
2620 | Abs(VMax - vmax) < epsilon; |
2621 | |
2622 | // degenerated flags (for cones) |
2623 | Standard_Boolean vmindegen = isVminDegen, vmaxdegen = isVmaxDegen; |
2624 | Handle(Geom_Surface) theSurf = S; |
2625 | if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) |
2626 | theSurf = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface(); |
2627 | if (theSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface)) |
2628 | { |
2629 | Handle(Geom_ConicalSurface) ConicalS = *((Handle(Geom_ConicalSurface)*) &theSurf); |
2630 | gp_Cone theCone = ConicalS->Cone(); |
2631 | gp_Pnt theApex = theCone.Apex(); |
2632 | Standard_Real Uapex, Vapex; |
2633 | ElSLib::Parameters( theCone, theApex, Uapex, Vapex ); |
2634 | if (Abs(VMin - Vapex) <= Precision::Confusion()) |
2635 | vmindegen = Standard_True; |
2636 | if (Abs(VMax - Vapex) <= Precision::Confusion()) |
2637 | vmaxdegen = Standard_True; |
2638 | } |
2639 | |
2640 | // compute vertices |
2641 | BRep_Builder B; |
2642 | Standard_Real tol = Precision::Confusion(); |
2643 | |
2644 | TopoDS_Vertex V00,V10,V11,V01; |
2645 | |
2646 | if (!umininf) { |
2647 | if (!vmininf) B.MakeVertex(V00,S->Value(UMin,VMin),tol); |
2648 | if (!vmaxinf) B.MakeVertex(V01,S->Value(UMin,VMax),tol); |
2649 | } |
2650 | if (!umaxinf) { |
2651 | if (!vmininf) B.MakeVertex(V10,S->Value(UMax,VMin),tol); |
2652 | if (!vmaxinf) B.MakeVertex(V11,S->Value(UMax,VMax),tol); |
2653 | } |
2654 | |
2655 | if (uclosed) { |
2656 | V10 = V00; |
2657 | V11 = V01; |
2658 | } |
2659 | |
2660 | if (vclosed) { |
2661 | V01 = V00; |
2662 | V11 = V10; |
2663 | } |
2664 | |
2665 | if (vmindegen) |
2666 | V10 = V00; |
2667 | if (vmaxdegen) |
2668 | V11 = V01; |
2669 | |
2670 | // make the lines |
2671 | Handle(Geom2d_Line) Lumin,Lumax,Lvmin,Lvmax; |
2672 | if (!umininf) |
2673 | Lumin = new Geom2d_Line(gp_Pnt2d(UMin,0),gp_Dir2d(0,1)); |
2674 | if (!umaxinf) |
2675 | Lumax = new Geom2d_Line(gp_Pnt2d(UMax,0),gp_Dir2d(0,1)); |
2676 | if (!vmininf) |
2677 | Lvmin = new Geom2d_Line(gp_Pnt2d(0,VMin),gp_Dir2d(1,0)); |
2678 | if (!vmaxinf) |
2679 | Lvmax = new Geom2d_Line(gp_Pnt2d(0,VMax),gp_Dir2d(1,0)); |
2680 | |
2681 | Handle(Geom_Curve) Cumin,Cumax,Cvmin,Cvmax; |
2682 | Standard_Real TolApex = 1.e-5; |
2683 | //Standard_Boolean hasiso = ! S->IsKind(STANDARD_TYPE(Geom_OffsetSurface)); |
2684 | Standard_Boolean hasiso = S->IsKind(STANDARD_TYPE(Geom_ElementarySurface)); |
2685 | if (hasiso) { |
2686 | if (!umininf) |
2687 | Cumin = S->UIso(UMin); |
2688 | if (!umaxinf) |
2689 | Cumax = S->UIso(UMax); |
2690 | if (!vmininf) |
2691 | { |
2692 | Cvmin = S->VIso(VMin); |
2693 | if (BRepOffset_Tool::Gabarit( Cvmin ) <= TolApex) |
2694 | vmindegen = Standard_True; |
2695 | } |
2696 | if (!vmaxinf) |
2697 | { |
2698 | Cvmax = S->VIso(VMax); |
2699 | if (BRepOffset_Tool::Gabarit( Cvmax ) <= TolApex) |
2700 | vmaxdegen = Standard_True; |
2701 | } |
2702 | } |
2703 | |
2704 | // make the face |
2705 | B.MakeFace(F,S,tol); |
2706 | |
2707 | // make the edges |
2708 | TopoDS_Edge eumin,eumax,evmin,evmax; |
2709 | |
2710 | if (!umininf) { |
2711 | if (hasiso) |
2712 | B.MakeEdge(eumin,Cumin,tol); |
2713 | else |
2714 | B.MakeEdge(eumin); |
2715 | if (uclosed) |
2716 | B.UpdateEdge(eumin,Lumax,Lumin,F,tol); |
2717 | else |
2718 | B.UpdateEdge(eumin,Lumin,F,tol); |
2719 | if (!vmininf) { |
2720 | V00.Orientation(TopAbs_FORWARD); |
2721 | B.Add(eumin,V00); |
2722 | } |
2723 | if (!vmaxinf) { |
2724 | V01.Orientation(TopAbs_REVERSED); |
2725 | B.Add(eumin,V01); |
2726 | } |
2727 | B.Range(eumin,VMin,VMax); |
2728 | } |
2729 | |
2730 | if (!umaxinf) { |
2731 | if (uclosed) |
2732 | eumax = eumin; |
2733 | else { |
2734 | if (hasiso) |
2735 | B.MakeEdge(eumax,Cumax,tol); |
2736 | else |
2737 | B.MakeEdge(eumax); |
2738 | B.UpdateEdge(eumax,Lumax,F,tol); |
2739 | if (!vmininf) { |
2740 | V10.Orientation(TopAbs_FORWARD); |
2741 | B.Add(eumax,V10); |
2742 | } |
2743 | if (!vmaxinf) { |
2744 | V11.Orientation(TopAbs_REVERSED); |
2745 | B.Add(eumax,V11); |
2746 | } |
2747 | B.Range(eumax,VMin,VMax); |
2748 | } |
2749 | } |
2750 | |
2751 | if (!vmininf) { |
2752 | if (hasiso && !vmindegen) |
2753 | B.MakeEdge(evmin,Cvmin,tol); |
2754 | else |
2755 | B.MakeEdge(evmin); |
2756 | if (vclosed) |
2757 | B.UpdateEdge(evmin,Lvmin,Lvmax,F,tol); |
2758 | else |
2759 | B.UpdateEdge(evmin,Lvmin,F,tol); |
2760 | if (!umininf) { |
2761 | V00.Orientation(TopAbs_FORWARD); |
2762 | B.Add(evmin,V00); |
2763 | } |
2764 | if (!umaxinf) { |
2765 | V10.Orientation(TopAbs_REVERSED); |
2766 | B.Add(evmin,V10); |
2767 | } |
2768 | B.Range(evmin,UMin,UMax); |
2769 | if (vmindegen) |
2770 | B.Degenerated(evmin, Standard_True); |
2771 | } |
2772 | |
2773 | if (!vmaxinf) { |
2774 | if (vclosed) |
2775 | evmax = evmin; |
2776 | else { |
2777 | if (hasiso && !vmaxdegen) |
2778 | B.MakeEdge(evmax,Cvmax,tol); |
2779 | else |
2780 | B.MakeEdge(evmax); |
2781 | B.UpdateEdge(evmax,Lvmax,F,tol); |
2782 | if (!umininf) { |
2783 | V01.Orientation(TopAbs_FORWARD); |
2784 | B.Add(evmax,V01); |
2785 | } |
2786 | if (!umaxinf) { |
2787 | V11.Orientation(TopAbs_REVERSED); |
2788 | B.Add(evmax,V11); |
2789 | } |
2790 | B.Range(evmax,UMin,UMax); |
2791 | if (vmaxdegen) |
2792 | B.Degenerated(evmax, Standard_True); |
2793 | } |
2794 | } |
2795 | |
2796 | // make the wires and add them to the face |
2797 | eumin.Orientation(TopAbs_REVERSED); |
2798 | evmax.Orientation(TopAbs_REVERSED); |
2799 | |
2800 | TopoDS_Wire W; |
2801 | |
2802 | if (!umininf && !umaxinf && vmininf && vmaxinf) { |
2803 | // two wires in u |
2804 | B.MakeWire(W); |
2805 | B.Add(W,eumin); |
2806 | B.Add(F,W); |
2807 | B.MakeWire(W); |
2808 | B.Add(W,eumax); |
2809 | B.Add(F,W); |
2810 | F.Closed(uclosed); |
2811 | } |
2812 | |
2813 | else if (umininf && umaxinf && !vmininf && !vmaxinf) { |
2814 | // two wires in v |
2815 | B.MakeWire(W); |
2816 | B.Add(W,evmin); |
2817 | B.Add(F,W); |
2818 | B.MakeWire(W); |
2819 | B.Add(W,evmax); |
2820 | B.Add(F,W); |
2821 | F.Closed(vclosed); |
2822 | } |
2823 | |
2824 | else if (!umininf || !umaxinf || !vmininf || !vmaxinf) { |
2825 | // one wire |
2826 | B.MakeWire(W); |
2827 | if (!umininf) B.Add(W,eumin); |
2828 | if (!vmininf) B.Add(W,evmin); |
2829 | if (!umaxinf) B.Add(W,eumax); |
2830 | if (!vmaxinf) B.Add(W,evmax); |
2831 | B.Add(F,W); |
2832 | W.Closed(!umininf && !umaxinf && !vmininf && !vmaxinf); |
2833 | F.Closed(uclosed && vclosed); |
2834 | } |
2835 | } |
2836 | |
2837 | //======================================================================= |
2838 | //function : EnLargeGeometry |
2839 | //purpose : |
2840 | //======================================================================= |
2841 | |
2842 | static Standard_Boolean EnlargeGeometry(Handle(Geom_Surface)& S, |
2843 | Standard_Real& U1, |
2844 | Standard_Real& U2, |
2845 | Standard_Real& V1, |
2846 | Standard_Real& V2, |
2847 | Standard_Boolean& IsV1degen, |
2848 | Standard_Boolean& IsV2degen, |
2849 | const Standard_Real uf1, |
2850 | const Standard_Real uf2, |
2851 | const Standard_Real vf1, |
2852 | const Standard_Real vf2, |
2853 | const Standard_Boolean GlobalEnlargeU, |
2854 | const Standard_Boolean GlobalEnlargeVfirst, |
2855 | const Standard_Boolean GlobalEnlargeVlast) |
2856 | { |
2857 | const Standard_Real coeff = 4.; |
2858 | const Standard_Real TolApex = 1.e-5; |
2859 | |
2860 | Standard_Boolean SurfaceChange = Standard_False; |
2861 | if ( S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
2862 | Handle(Geom_Surface) BS = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); |
2863 | EnlargeGeometry(BS,U1,U2,V1,V2,IsV1degen,IsV2degen, |
2864 | uf1,uf2,vf1,vf2,GlobalEnlargeU,GlobalEnlargeVfirst,GlobalEnlargeVlast); |
2865 | if (!GlobalEnlargeVfirst) |
2866 | V1 = vf1; |
2867 | if (!GlobalEnlargeVlast) |
2868 | V2 = vf2; |
2869 | if (!GlobalEnlargeVfirst || !GlobalEnlargeVlast) |
2870 | //(*((Handle(Geom_RectangularTrimmedSurface)*)&S))->SetTrim( U1, U2, V1, V2 ); |
2871 | S = new Geom_RectangularTrimmedSurface( BS, U1, U2, V1, V2 ); |
2872 | else |
2873 | S = BS; |
2874 | SurfaceChange = Standard_True; |
2875 | } |
2876 | else if (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)) { |
2877 | Handle(Geom_Surface) Surf = (*((Handle(Geom_OffsetSurface)*)&S))->BasisSurface(); |
2878 | SurfaceChange = EnlargeGeometry(Surf,U1,U2,V1,V2,IsV1degen,IsV2degen, |
2879 | uf1,uf2,vf1,vf2,GlobalEnlargeU,GlobalEnlargeVfirst,GlobalEnlargeVlast); |
2880 | Handle(Geom_OffsetSurface)::DownCast(S)->SetBasisSurface(Surf); |
2881 | } |
2882 | else if (S->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) || |
2883 | S->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution)) |
2884 | { |
2885 | Standard_Real du=0., dv=0.; |
2886 | Handle( Geom_Curve ) uiso, viso, uiso1, uiso2, viso1, viso2; |
2887 | Standard_Real u1, u2, v1, v2; |
2888 | Standard_Boolean enlargeU = GlobalEnlargeU, enlargeV = Standard_True; |
2889 | Standard_Boolean enlargeUfirst = enlargeU, enlargeUlast = enlargeU; |
2890 | Standard_Boolean enlargeVfirst = GlobalEnlargeVfirst, enlargeVlast = GlobalEnlargeVlast; |
2891 | S->Bounds( u1, u2, v1, v2 ); |
2892 | if (Precision::IsInfinite(u1) || Precision::IsInfinite(u2)) |
2893 | { |
2894 | du = uf2-uf1; |
2895 | u1 = uf1-du; |
2896 | u2 = uf2+du; |
2897 | enlargeU = Standard_False; |
2898 | } |
2899 | else if (S->IsUClosed()) |
2900 | enlargeU = Standard_False; |
2901 | else |
2902 | { |
2903 | viso = S->VIso( vf1 ); |
2904 | GeomAdaptor_Curve gac( viso ); |
2905 | du = GCPnts_AbscissaPoint::Length( gac ) / coeff; |
2906 | uiso1 = S->UIso( uf1 ); |
2907 | uiso2 = S->UIso( uf2 ); |
2908 | if (BRepOffset_Tool::Gabarit( uiso1 ) <= TolApex) |
2909 | enlargeUfirst = Standard_False; |
2910 | if (BRepOffset_Tool::Gabarit( uiso2 ) <= TolApex) |
2911 | enlargeUlast = Standard_False; |
2912 | } |
2913 | if (Precision::IsInfinite(v1) || Precision::IsInfinite(v2)) |
2914 | { |
2915 | dv = vf2-vf1; |
2916 | v1 = vf1-dv; |
2917 | v2 = vf2+dv; |
2918 | enlargeV = Standard_False; |
2919 | } |
2920 | else if (S->IsVClosed()) |
2921 | enlargeV = Standard_False; |
2922 | else |
2923 | { |
2924 | uiso = S->UIso( uf1 ); |
2925 | GeomAdaptor_Curve gac( uiso ); |
2926 | dv = GCPnts_AbscissaPoint::Length( gac ) / coeff; |
2927 | viso1 = S->VIso( vf1 ); |
2928 | viso2 = S->VIso( vf2 ); |
2929 | if (BRepOffset_Tool::Gabarit( viso1 ) <= TolApex) |
2930 | { |
2931 | enlargeVfirst = Standard_False; |
2932 | IsV1degen = Standard_True; |
2933 | } |
2934 | if (BRepOffset_Tool::Gabarit( viso2 ) <= TolApex) |
2935 | { |
2936 | enlargeVlast = Standard_False; |
2937 | IsV2degen = Standard_True; |
2938 | } |
2939 | } |
2940 | S = new Geom_RectangularTrimmedSurface( S, u1, u2, v1, v2 ); |
2941 | if (enlargeU) |
2942 | { |
2943 | if (enlargeUfirst) |
2944 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_False ); |
2945 | if (enlargeUlast) |
2946 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_True ); |
2947 | } |
2948 | if (enlargeV) |
2949 | { |
2950 | if (enlargeVfirst) |
2951 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_False ); |
2952 | if (enlargeVlast) |
2953 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_True ); |
2954 | } |
2955 | S->Bounds( U1, U2, V1, V2 ); |
2956 | SurfaceChange = Standard_True; |
2957 | } |
2958 | else if (S->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) || |
2959 | S->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) |
2960 | { |
2961 | Standard_Boolean enlargeU = GlobalEnlargeU, enlargeV = Standard_True; |
2962 | Standard_Boolean enlargeUfirst = enlargeU, enlargeUlast = enlargeU; |
2963 | Standard_Boolean enlargeVfirst = GlobalEnlargeVfirst, enlargeVlast = GlobalEnlargeVlast; |
2964 | if (S->IsUClosed()) |
2965 | enlargeU = Standard_False; |
2966 | if (S->IsVClosed()) |
2967 | enlargeV = Standard_False; |
2968 | |
2969 | Standard_Real duf = uf2-uf1, dvf = vf2-vf1; |
2970 | Standard_Real u1, u2, v1, v2; |
2971 | S->Bounds( u1, u2, v1, v2 ); |
2972 | |
2973 | Standard_Real du=0., dv=0.; |
2974 | Handle( Geom_Curve ) uiso, viso, uiso1, uiso2, viso1, viso2; |
2975 | GeomAdaptor_Curve gac; |
2976 | if (enlargeU) |
2977 | { |
2978 | viso = S->VIso( v1 ); |
2979 | gac.Load( viso ); |
2980 | du = GCPnts_AbscissaPoint::Length( gac ) / coeff; |
2981 | uiso1 = S->UIso( u1 ); |
2982 | uiso2 = S->UIso( u2 ); |
2983 | if (BRepOffset_Tool::Gabarit( uiso1 ) <= TolApex) |
2984 | enlargeUfirst = Standard_False; |
2985 | if (BRepOffset_Tool::Gabarit( uiso2 ) <= TolApex) |
2986 | enlargeUlast = Standard_False; |
2987 | } |
2988 | if (enlargeV) |
2989 | { |
2990 | uiso = S->UIso( u1 ); |
2991 | gac.Load( uiso ); |
2992 | dv = GCPnts_AbscissaPoint::Length( gac ) / coeff; |
2993 | viso1 = S->VIso( v1 ); |
2994 | viso2 = S->VIso( v2 ); |
2995 | if (BRepOffset_Tool::Gabarit( viso1 ) <= TolApex) |
2996 | { |
2997 | enlargeVfirst = Standard_False; |
2998 | IsV1degen = Standard_True; |
2999 | } |
3000 | if (BRepOffset_Tool::Gabarit( viso2 ) <= TolApex) |
3001 | { |
3002 | enlargeVlast = Standard_False; |
3003 | IsV2degen = Standard_True; |
3004 | } |
3005 | } |
3006 | |
3007 | if (enlargeU) |
3008 | { |
3009 | if (enlargeUfirst && uf1-u1 < duf) |
3010 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_False ); |
3011 | if (enlargeUlast && u2-uf2 < duf) |
3012 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_True ); |
3013 | } |
3014 | if (enlargeV) |
3015 | { |
3016 | if (enlargeVfirst && vf1-v1 < dvf) |
3017 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_False ); |
3018 | if (enlargeVlast && v2-vf2 < dvf) |
3019 | GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_True ); |
3020 | } |
3021 | |
3022 | S->Bounds( U1, U2, V1, V2 ); |
3023 | SurfaceChange = Standard_True; |
3024 | } |
3025 | // else if (S->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) || |
3026 | // S->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) { |
3027 | // S->Bounds(U1,U2,V1,V2); |
3028 | // } |
3029 | else { |
3030 | Standard_Real UU1,UU2,VV1,VV2; |
3031 | S->Bounds(UU1,UU2,VV1,VV2); |
3032 | // Pas d extension au dela des bornes de la surface. |
3033 | U1 = Max(UU1,U1); |
3034 | V1 = Max(VV1,V1); |
3035 | U2 = Min(UU2,U2); |
3036 | V2 = Min(VV2,V2); |
3037 | } |
3038 | return SurfaceChange; |
3039 | } |
3040 | |
3041 | //======================================================================= |
3042 | //function : UpDatePCurve |
3043 | //purpose : Mise a jour des pcurves de F sur la surface de de BF. |
3044 | // F and BF has to be FORWARD, |
3045 | //======================================================================= |
3046 | |
3047 | static void UpdatePCurves (const TopoDS_Face& F, |
3048 | TopoDS_Face& BF) |
3049 | { |
3050 | Standard_Real f,l; |
3051 | Standard_Integer i; |
3052 | BRep_Builder B; |
3053 | TopTools_IndexedMapOfShape Emap; |
3054 | Handle(Geom2d_Curve) NullPCurve; |
3055 | |
3056 | TopExp::MapShapes( F, TopAbs_EDGE, Emap ); |
3057 | |
3058 | for (i = 1; i <= Emap.Extent(); i++) |
3059 | { |
3060 | TopoDS_Edge CE = TopoDS::Edge( Emap(i) ); |
3061 | CE.Orientation( TopAbs_FORWARD ); |
3062 | Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface( CE, F, f, l ); |
3063 | if (!C2.IsNull()) |
3064 | { |
3065 | if (BRep_Tool::IsClosed( CE, F )) |
3066 | { |
3067 | CE.Reverse(); |
3068 | Handle(Geom2d_Curve) C2R = BRep_Tool::CurveOnSurface( CE, F, f, l ); |
3069 | B.UpdateEdge( CE, NullPCurve, NullPCurve, F, BRep_Tool::Tolerance(CE) ); |
3070 | B.UpdateEdge( CE, C2, C2R, BF, BRep_Tool::Tolerance(CE) ); |
3071 | } |
3072 | else |
3073 | { |
3074 | B.UpdateEdge( CE, NullPCurve, F, BRep_Tool::Tolerance(CE) ); |
3075 | B.UpdateEdge( CE, C2, BF, BRep_Tool::Tolerance(CE) ); |
3076 | } |
3077 | |
3078 | B.Range(CE,f,l); |
3079 | } |
3080 | } |
3081 | } |
3082 | |
3083 | //======================================================================= |
3084 | //function :CompactUVBounds |
3085 | //purpose : |
3086 | //======================================================================= |
3087 | |
3088 | static void CompactUVBounds (const TopoDS_Face& F, |
3089 | Standard_Real& UMin, |
3090 | Standard_Real& UMax, |
3091 | Standard_Real& VMin, |
3092 | Standard_Real& VMax) |
3093 | { |
3094 | // Calcul serre pour que les bornes ne couvrent pas plus d une periode |
3095 | Standard_Real U1,U2; |
3096 | Standard_Real N = 33; |
3097 | Bnd_Box2d B; |
3098 | |
3099 | TopExp_Explorer exp; |
3100 | for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) { |
3101 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); |
3102 | BRepAdaptor_Curve2d C(E,F); |
3103 | BRep_Tool::Range(E,U1,U2); |
3104 | gp_Pnt2d P; |
3105 | Standard_Real U = U1; |
3106 | Standard_Real DU = (U2-U1)/(N-1); |
3107 | for (Standard_Integer j=1;j<N;j++) { |
3108 | C.D0(U,P); |
3109 | U+=DU; |
3110 | B.Add(P); |
3111 | } |
3112 | C.D0(U2,P); |
3113 | B.Add(P); |
3114 | } |
3115 | B.Get(UMin,VMin,UMax,VMax); |
3116 | } |
3117 | |
3118 | //======================================================================= |
3119 | //function : CheckBounds |
3120 | //purpose : |
3121 | //======================================================================= |
3122 | |
3123 | void BRepOffset_Tool::CheckBounds(const TopoDS_Face& F, |
3124 | const BRepOffset_Analyse& Analyse, |
3125 | Standard_Boolean& enlargeU, |
3126 | Standard_Boolean& enlargeVfirst, |
3127 | Standard_Boolean& enlargeVlast) |
3128 | { |
3129 | enlargeU = Standard_True; |
3130 | enlargeVfirst = Standard_True; enlargeVlast = Standard_True; |
3131 | |
3132 | Standard_Integer Ubound = 0, Vbound = 0; |
3133 | Standard_Real Ufirst = RealLast(), Ulast = RealFirst(); |
3134 | Standard_Real Vfirst = RealLast(), Vlast = RealFirst(); |
3135 | |
3136 | Standard_Real UF1,UF2,VF1,VF2; |
3137 | CompactUVBounds(F,UF1,UF2,VF1,VF2); |
3138 | |
3139 | Handle(Geom_Surface) theSurf = BRep_Tool::Surface(F); |
3140 | if (theSurf->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) |
3141 | theSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&theSurf))->BasisSurface(); |
3142 | |
3143 | if (theSurf->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) || |
3144 | theSurf->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution) || |
3145 | theSurf->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) || |
3146 | theSurf->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) |
3147 | { |
3148 | TopExp_Explorer Explo(F, TopAbs_EDGE); |
3149 | for (; Explo.More(); Explo.Next()) |
3150 | { |
3151 | const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current()); |
3152 | const BRepOffset_ListOfInterval& L = Analyse.Type(anEdge); |
3153 | if (!L.IsEmpty() || BRep_Tool::Degenerated(anEdge)) |
3154 | { |
3155 | BRepOffset_Type OT = L.First().Type(); |
3156 | if (OT == BRepOffset_Tangent || BRep_Tool::Degenerated(anEdge)) |
3157 | { |
3158 | Standard_Real fpar, lpar; |
3159 | Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, F, fpar, lpar); |
3160 | if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) |
3161 | aCurve = (*((Handle(Geom2d_TrimmedCurve)*)&aCurve))->BasisCurve(); |
3162 | |
3163 | Handle(Geom2d_Line) theLine; |
3164 | if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_Line)) |
3165 | theLine = *((Handle(Geom2d_Line)*)&aCurve); |
3166 | else if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_BezierCurve) || |
3167 | aCurve->DynamicType() == STANDARD_TYPE(Geom2d_BSplineCurve)) |
3168 | { |
3169 | Standard_Real newFpar, newLpar, deviation; |
3170 | theLine = ShapeCustom_Curve2d::ConvertToLine2d(aCurve, fpar, lpar, Precision::Confusion(), |
3171 | newFpar, newLpar, deviation); |
3172 | } |
3173 | |
3174 | if (!theLine.IsNull()) |
3175 | { |
3176 | gp_Dir2d theDir = theLine->Direction(); |
3177 | if (theDir.IsParallel( gp::DX2d(), Precision::Angular() )) |
3178 | { |
3179 | Vbound++; |
3180 | if (BRep_Tool::Degenerated(anEdge)) |
3181 | { |
3182 | if (Abs(theLine->Location().Y() - VF1) <= Precision::Confusion()) |
3183 | enlargeVfirst = Standard_False; |
3184 | else //theLine->Location().Y() is near VF2 |
3185 | enlargeVlast = Standard_False; |
3186 | } |
3187 | else |
3188 | { |
3189 | if (theLine->Location().Y() < Vfirst) |
3190 | Vfirst = theLine->Location().Y(); |
3191 | if (theLine->Location().Y() > Vlast) |
3192 | Vlast = theLine->Location().Y(); |
3193 | } |
3194 | } |
3195 | else if (theDir.IsParallel( gp::DY2d(), Precision::Angular() )) |
3196 | { |
3197 | Ubound++; |
3198 | if (theLine->Location().X() < Ufirst) |
3199 | Ufirst = theLine->Location().X(); |
3200 | if (theLine->Location().X() > Ulast) |
3201 | Ulast = theLine->Location().X(); |
3202 | } |
3203 | } |
3204 | } |
3205 | } |
3206 | } |
3207 | } |
3208 | |
3209 | if (Ubound >= 2 || Vbound >= 2) |
3210 | { |
3211 | if (Ubound >= 2 && |
3212 | Abs(UF1-Ufirst) <= Precision::Confusion() && |
3213 | Abs(UF2-Ulast) <= Precision::Confusion()) |
3214 | enlargeU = Standard_False; |
3215 | if (Vbound >= 2 && |
3216 | Abs(VF1-Vfirst) <= Precision::Confusion() && |
3217 | Abs(VF2-Vlast) <= Precision::Confusion()) |
3218 | { |
3219 | enlargeVfirst = Standard_False; |
3220 | enlargeVlast = Standard_False; |
3221 | } |
3222 | } |
3223 | } |
3224 | |
3225 | //======================================================================= |
3226 | //function : EnLargeFace |
3227 | //purpose : |
3228 | //======================================================================= |
3229 | |
3230 | Standard_Boolean BRepOffset_Tool::EnLargeFace |
3231 | (const TopoDS_Face& F, |
3232 | TopoDS_Face& BF, |
3233 | const Standard_Boolean CanExtentSurface, |
3234 | const Standard_Boolean UpdatePCurve, |
3235 | const Standard_Boolean enlargeU, |
3236 | const Standard_Boolean enlargeVfirst, |
3237 | const Standard_Boolean enlargeVlast) |
3238 | { |
3239 | //--------------------------- |
3240 | // extension de la geometrie. |
3241 | //--------------------------- |
3242 | TopLoc_Location L; |
3243 | Handle (Geom_Surface) S = BRep_Tool::Surface(F,L); |
3244 | Standard_Real UU1,VV1,UU2,VV2; |
3245 | Standard_Boolean isVV1degen = Standard_False, isVV2degen = Standard_False; |
3246 | Standard_Real US1,VS1,US2,VS2; |
3247 | Standard_Real UF1,VF1,UF2,VF2; |
3248 | Standard_Real infini = 1.e8; |
3249 | Standard_Boolean SurfaceChange = Standard_False; |
3250 | |
3251 | if (S->IsUPeriodic() || S->IsVPeriodic()) { |
3252 | // Calcul serre pour que les bornes ne couvre pas plus d une periode |
3253 | CompactUVBounds(F,UF1,UF2,VF1,VF2); |
3254 | } |
3255 | else { |
3256 | BRepTools::UVBounds(F,UF1,UF2,VF1,VF2); |
3257 | } |
3258 | |
3259 | S->Bounds (US1,US2,VS1,VS2); |
3260 | UU1 = VV1 = - infini; |
3261 | UU2 = VV2 = infini; |
3262 | |
3263 | if (CanExtentSurface) { |
3264 | SurfaceChange = EnlargeGeometry( S, UU1, UU2, VV1, VV2, isVV1degen, isVV2degen, UF1, UF2, VF1, VF2, |
3265 | enlargeU, enlargeVfirst, enlargeVlast ); |
3266 | } |
3267 | else { |
3268 | UU1 = Max(US1,UU1); UU2 = Min(UU2,US2); |
3269 | VV1 = Max(VS1,VV1); VV2 = Min(VS2,VV2); |
3270 | } |
3271 | |
3272 | if (S->IsUPeriodic()) { |
3273 | Standard_Real Period = S->UPeriod(); |
3274 | Standard_Real Delta = Period - (UF2 - UF1); |
3275 | Standard_Real alpha = 0.1; |
3276 | UU1 = UF1 - alpha*Delta; UU2 = UF2 + alpha*Delta; |
3277 | if ((UU2 - UU1) > Period) { |
3278 | UU2 = UU1 + Period; |
3279 | } |
3280 | } |
3281 | if (S->IsVPeriodic()) { |
3282 | Standard_Real Period = S->VPeriod(); |
3283 | Standard_Real Delta = Period - (VF2 - VF1); |
3284 | Standard_Real alpha = 0.1; |
3285 | VV1 = VF1 - alpha*Delta; VV2 = VF2 + alpha*Delta; |
3286 | if ((VV2 - VV1) > Period) { |
3287 | VV2 = VV1 + Period; |
3288 | } |
3289 | } |
3290 | |
3291 | //Special treatment for conical surfaces |
3292 | Handle(Geom_Surface) theSurf = S; |
3293 | if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) |
3294 | theSurf = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface(); |
3295 | if (theSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface)) |
3296 | { |
3297 | Handle(Geom_ConicalSurface) ConicalS = *((Handle(Geom_ConicalSurface)*) &theSurf); |
3298 | gp_Cone theCone = ConicalS->Cone(); |
3299 | gp_Pnt theApex = theCone.Apex(); |
3300 | Standard_Real Uapex, Vapex; |
3301 | ElSLib::Parameters( theCone, theApex, Uapex, Vapex ); |
3302 | if (VV1 < Vapex && Vapex < VV2) |
3303 | { |
3304 | //consider that VF1 and VF2 are on the same side from apex |
3305 | Standard_Real TolApex = 1.e-5; |
3306 | if (Vapex - VF1 >= TolApex || |
3307 | Vapex - VF2 >= TolApex) //if (VF1 < Vapex || VF2 < Vapex) |
3308 | VV2 = Vapex; |
3309 | else |
3310 | VV1 = Vapex; |
3311 | } |
3312 | } |
3313 | |
3314 | if (!enlargeU) |
3315 | { |
3316 | UU1 = UF1; UU2 = UF2; |
3317 | } |
3318 | if (!enlargeVfirst) |
3319 | VV1 = VF1; |
3320 | if (!enlargeVlast) |
3321 | VV2 = VF2; |
3322 | |
3323 | MakeFace(S,UU1,UU2,VV1,VV2,isVV1degen,isVV2degen,BF); |
3324 | BF.Location(L); |
3325 | /* |
3326 | if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
3327 | BRep_Builder B; |
3328 | //---------------------------------------------------------------- |
3329 | // utile pour les bouchons on ne doit pas changer leur geometrie. |
3330 | // (Ce que fait BRepLib_MakeFace si S est restreinte). |
3331 | // On remet S et on update les pcurves. |
3332 | //---------------------------------------------------------------- |
3333 | TopExp_Explorer exp; |
3334 | exp.Init(BF,TopAbs_EDGE); |
3335 | Standard_Real f=0.,l=0.; |
3336 | for (; exp.More(); exp.Next()) { |
3337 | TopoDS_Edge CE = TopoDS::Edge(exp.Current()); |
3338 | Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(CE,BF,f,l); |
3339 | B.UpdateEdge (CE,C2,S,L,BRep_Tool::Tolerance(CE)); |
3340 | } |
3341 | B.UpdateFace(BF,S,L,BRep_Tool::Tolerance(F)); |
3342 | } |
3343 | */ |
3344 | if (SurfaceChange && UpdatePCurve) { |
3345 | TopoDS_Shape aLocalFace = F.Oriented(TopAbs_FORWARD); |
3346 | UpdatePCurves(TopoDS::Face(aLocalFace),BF); |
3347 | //UpdatePCurves(TopoDS::Face(F.Oriented(TopAbs_FORWARD)),BF); |
3348 | BRep_Builder BB; |
3349 | BB.UpdateFace( F, S, L, BRep_Tool::Tolerance(F) ); |
3350 | } |
3351 | |
3352 | BF.Orientation(F.Orientation()); |
3353 | return SurfaceChange; |
3354 | } |
3355 | |
3356 | //======================================================================= |
3357 | //function : TryParameter |
3358 | //purpose : |
3359 | //======================================================================= |
3360 | |
3361 | static Standard_Boolean TryParameter (const TopoDS_Edge& OE, |
3362 | TopoDS_Vertex& V, |
3363 | const TopoDS_Edge& NE, |
3364 | Standard_Real TolConf) |
3365 | { |
3366 | BRepAdaptor_Curve OC(OE); |
3367 | BRepAdaptor_Curve NC(NE); |
3368 | Standard_Real Of = OC.FirstParameter(); Standard_Real Ol = OC.LastParameter(); |
3369 | Standard_Real Nf = NC.FirstParameter(); Standard_Real Nl = NC.LastParameter(); |
3370 | #ifndef DEB |
3371 | Standard_Real U = 0.; |
3372 | #else |
3373 | Standard_Real U; |
3374 | #endif |
3375 | gp_Pnt P = BRep_Tool::Pnt(V); |
3376 | Standard_Boolean OK = Standard_False; |
3377 | |
3378 | if (P.Distance(OC.Value(Of)) < TolConf) { |
3379 | if (Of > Nf && Of < Nl && P.Distance(NC.Value(Of)) < TolConf) { |
3380 | OK = Standard_True; |
3381 | U = Of; |
3382 | } |
3383 | } |
3384 | if (P.Distance(OC.Value(Ol)) < TolConf) { |
3385 | if (Ol > Nf && Ol < Nl && P.Distance(NC.Value(Ol)) < TolConf) { |
3386 | OK = Standard_True; |
3387 | U = Ol; |
3388 | } |
3389 | } |
3390 | if (OK) { |
3391 | BRep_Builder B; |
3392 | TopoDS_Shape aLocalShape = NE.Oriented(TopAbs_FORWARD); |
3393 | TopoDS_Edge EE = TopoDS::Edge(aLocalShape); |
3394 | // TopoDS_Edge EE = TopoDS::Edge(NE.Oriented(TopAbs_FORWARD)); |
3395 | aLocalShape = V.Oriented(TopAbs_INTERNAL); |
3396 | B.UpdateVertex(TopoDS::Vertex(aLocalShape), |
3397 | U,NE,BRep_Tool::Tolerance(NE)); |
3398 | // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)), |
3399 | // U,NE,BRep_Tool::Tolerance(NE)); |
3400 | } |
3401 | return OK; |
3402 | } |
3403 | |
3404 | //======================================================================= |
3405 | //function : |
3406 | //purpose : |
3407 | //======================================================================= |
3408 | |
3409 | void BRepOffset_Tool::MapVertexEdges (const TopoDS_Shape& S, |
3410 | TopTools_DataMapOfShapeListOfShape& MEV) |
3411 | { |
3412 | TopExp_Explorer exp; |
3413 | exp.Init(S.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
3414 | TopTools_MapOfShape DejaVu; |
3415 | for ( ; exp.More(); exp.Next()) { |
3416 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); |
3417 | if (DejaVu.Add(E)) { |
3418 | TopoDS_Vertex V1,V2; |
3419 | TopExp::Vertices (E,V1,V2); |
3420 | if (!MEV.IsBound(V1)) { |
3421 | TopTools_ListOfShape empty; |
3422 | MEV.Bind(V1,empty); |
3423 | } |
3424 | MEV(V1).Append(E); |
3425 | if (!V1.IsSame(V2)) { |
3426 | if (!MEV.IsBound(V2)) { |
3427 | TopTools_ListOfShape empty; |
3428 | MEV.Bind(V2,empty); |
3429 | } |
3430 | MEV(V2).Append(E); |
3431 | } |
3432 | } |
3433 | } |
3434 | } |
3435 | |
3436 | //======================================================================= |
3437 | //function : |
3438 | //purpose : |
3439 | //======================================================================= |
3440 | |
3441 | void BRepOffset_Tool::BuildNeighbour (const TopoDS_Wire& W, |
3442 | const TopoDS_Face& F, |
3443 | TopTools_DataMapOfShapeShape& NOnV1, |
3444 | TopTools_DataMapOfShapeShape& NOnV2) |
3445 | { |
3446 | TopoDS_Vertex V1,V2,VP1,VP2,FV1,FV2; |
3447 | TopoDS_Edge CurE,FirstE,PrecE; |
3448 | BRepTools_WireExplorer wexp; |
3449 | |
3450 | TopoDS_Shape aLocalFace = F.Oriented(TopAbs_FORWARD); |
3451 | TopoDS_Shape aLocalWire = W.Oriented(TopAbs_FORWARD); |
3452 | wexp.Init(TopoDS::Wire(aLocalWire),TopoDS::Face(aLocalFace)); |
3453 | // wexp.Init(TopoDS::Wire(W.Oriented(TopAbs_FORWARD)), |
3454 | // TopoDS::Face(F.Oriented(TopAbs_FORWARD))); |
3455 | CurE = FirstE = PrecE = wexp.Current(); |
3456 | TopExp::Vertices(CurE,V1,V2); |
3457 | FV1 = VP1 = V1; FV2 = VP2 = V2; |
3458 | wexp.Next(); |
3459 | while (wexp.More()) { |
3460 | CurE = wexp.Current(); |
3461 | TopExp::Vertices(CurE,V1,V2); |
3462 | if (V1.IsSame(VP1)) { NOnV1.Bind(PrecE,CurE); NOnV1.Bind(CurE,PrecE);} |
3463 | if (V1.IsSame(VP2)) { NOnV2.Bind(PrecE,CurE); NOnV1.Bind(CurE,PrecE);} |
3464 | if (V2.IsSame(VP1)) { NOnV1.Bind(PrecE,CurE); NOnV2.Bind(CurE,PrecE);} |
3465 | if (V2.IsSame(VP2)) { NOnV2.Bind(PrecE,CurE); NOnV2.Bind(CurE,PrecE);} |
3466 | PrecE = CurE; |
3467 | VP1 = V1; VP2 = V2; |
3468 | wexp.Next(); |
3469 | } |
3470 | if (V1.IsSame(FV1)) { NOnV1.Bind(FirstE,CurE); NOnV1.Bind(CurE,FirstE);} |
3471 | if (V1.IsSame(FV2)) { NOnV2.Bind(FirstE,CurE); NOnV1.Bind(CurE,FirstE);} |
3472 | if (V2.IsSame(FV1)) { NOnV1.Bind(FirstE,CurE); NOnV2.Bind(CurE,FirstE);} |
3473 | if (V2.IsSame(FV2)) { NOnV2.Bind(FirstE,CurE); NOnV2.Bind(CurE,FirstE);} |
3474 | } |
3475 | |
3476 | //======================================================================= |
3477 | //function : ExtentFace |
3478 | //purpose : |
3479 | //======================================================================= |
3480 | |
3481 | void BRepOffset_Tool::ExtentFace (const TopoDS_Face& F, |
3482 | TopTools_DataMapOfShapeShape& ConstShapes, |
3483 | TopTools_DataMapOfShapeShape& ToBuild, |
3484 | const TopAbs_State Side, |
3485 | const Standard_Real TolConf, |
3486 | TopoDS_Face& NF) |
3487 | { |
3488 | #ifdef DRAW |
3489 | if (AffichInter) { |
3490 | // POP pour NT |
3491 | char* name = new char[100]; |
3492 | sprintf(name,"FTE_%d",NbFTE++); |
3493 | DBRep::Set(name,F); |
3494 | } |
3495 | #endif |
3496 | |
3497 | TopExp_Explorer exp,exp2; |
3498 | TopTools_DataMapOfShapeShape Build; |
3499 | TopTools_DataMapOfShapeShape Extent; |
3500 | TopoDS_Edge FirstE,PrecE,CurE,NE; |
3501 | BRep_Builder B; |
3502 | TopoDS_Face EF; |
3503 | |
3504 | // Construction de la boite englobante de la face a etendre et des bouchons pour |
3505 | // limiter les extensions. |
3506 | //Bnd_Box ContextBox; |
3507 | //BRepBndLib::Add(F,B); |
3508 | //TopTools_DataMapIteratorOfDataMapOfShape itTB(ToBuild); |
3509 | //for (; itTB.More(); itTB.Next()) { |
3510 | //BRepBndLib::Add(TopBuild.Value(), ContextBox); |
3511 | //} |
3512 | |
3513 | |
3514 | Standard_Boolean SurfaceChange; |
3515 | SurfaceChange = EnLargeFace (F,EF,Standard_True); |
3516 | |
3517 | TopoDS_Shape aLocalShape = EF.EmptyCopied(); |
3518 | NF = TopoDS::Face(aLocalShape); |
3519 | // NF = TopoDS::Face(EF.EmptyCopied()); |
3520 | NF.Orientation(TopAbs_FORWARD); |
3521 | |
3522 | if (SurfaceChange) { |
3523 | //------------------------------------------------ |
3524 | // Mise a jour des pcurves sur la surface de base. |
3525 | //------------------------------------------------ |
3526 | TopoDS_Face Fforward = F; |
3527 | Fforward.Orientation(TopAbs_FORWARD); |
3528 | TopTools_IndexedMapOfShape Emap; |
3529 | TopExp::MapShapes( Fforward, TopAbs_EDGE, Emap ); |
3530 | Standard_Real f,l; |
3531 | for (Standard_Integer i = 1; i <= Emap.Extent(); i++) { |
3532 | TopoDS_Edge CE = TopoDS::Edge( Emap(i) ); |
3533 | CE.Orientation(TopAbs_FORWARD); |
3534 | TopoDS_Edge Ecs; //patch |
3535 | Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(CE,Fforward,f,l); |
3536 | if (!C2.IsNull()) { |
3537 | if (ConstShapes.IsBound(CE)) { |
3538 | Ecs = TopoDS::Edge(ConstShapes(CE)); |
3539 | BRep_Tool::Range(Ecs,f,l); |
3540 | } |
3541 | if (BRep_Tool::IsClosed(CE,Fforward)) { |
3542 | TopoDS_Shape aLocalShape = CE.Reversed(); |
3543 | Handle(Geom2d_Curve) C2R = |
3544 | BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),Fforward,f,l); |
3545 | // Handle(Geom2d_Curve) C2R = |
3546 | // BRep_Tool::CurveOnSurface(TopoDS::Edge(CE.Reversed()),F,f,l); |
3547 | B.UpdateEdge (CE,C2,C2R,EF,BRep_Tool::Tolerance(CE)); |
3548 | if (! Ecs.IsNull()) |
3549 | B.UpdateEdge (Ecs,C2,C2R,EF,BRep_Tool::Tolerance(CE)); |
3550 | } |
3551 | else { |
3552 | B.UpdateEdge (CE,C2,EF,BRep_Tool::Tolerance(CE)); |
3553 | if (! Ecs.IsNull()) |
3554 | B.UpdateEdge (Ecs,C2,EF,BRep_Tool::Tolerance(CE)); |
3555 | } |
3556 | B.Range(CE,f,l); |
3557 | if (! Ecs.IsNull()) |
3558 | B.Range(Ecs,f,l); |
3559 | } |
3560 | } |
3561 | } |
3562 | |
3563 | for (exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_WIRE); |
3564 | exp.More(); |
3565 | exp.Next()) { |
3566 | const TopoDS_Wire& W = TopoDS::Wire(exp.Current()); |
3567 | TopTools_DataMapOfShapeListOfShape MVE; // Vertex -> Edges incidentes. |
3568 | TopTools_DataMapOfShapeShape NOnV1; |
3569 | TopTools_DataMapOfShapeShape NOnV2; |
3570 | |
3571 | MapVertexEdges (W,MVE); |
3572 | BuildNeighbour (W,F,NOnV1,NOnV2); |
3573 | |
3574 | TopTools_ListOfShape LInt1,LInt2; |
3575 | TopoDS_Face StopFace; |
3576 | //------------------------------------------------ |
3577 | // Construction edges |
3578 | //------------------------------------------------ |
3579 | for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
3580 | exp2.More(); exp2.Next()) { |
3581 | const TopoDS_Edge& E = TopoDS::Edge(exp2.Current()); |
3582 | if (ConstShapes.IsBound(E)) ToBuild.UnBind(E); |
3583 | if (ToBuild.IsBound(E)) { |
3584 | TopTools_ListOfShape LOE; |
3585 | LOE.Append(E); |
3586 | BRepOffset_Tool::TryProject (TopoDS::Face(ToBuild(E)), |
3587 | EF,LOE,LInt2,LInt1,Side,TolConf); |
3588 | if (!LInt1.IsEmpty()) |
3589 | ToBuild.UnBind(E); |
3590 | } |
3591 | } |
3592 | |
3593 | for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
3594 | exp2.More(); exp2.Next()) { |
3595 | const TopoDS_Edge& E = TopoDS::Edge(exp2.Current()); |
3596 | if (ConstShapes.IsBound(E)) ToBuild.UnBind(E); |
3597 | if (ToBuild.IsBound(E)) { |
3598 | EnLargeFace(TopoDS::Face(ToBuild(E)),StopFace,Standard_False); |
3599 | BRepOffset_Tool::Inter3D (EF,StopFace,LInt1,LInt2,Side,E,Standard_True); |
3600 | if (LInt1.Extent() > 1) { |
3601 | // l intersection est en plusieurs edges (franchissement de couture) |
3602 | SelectEdge (F,EF,E,LInt1); |
3603 | } |
3604 | NE = TopoDS::Edge(LInt1.First()); |
3605 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &NE.TShape()); |
3606 | TE->Tolerance( TE->Tolerance()*10. ); //???? |
3607 | if (NE.Orientation() == E.Orientation()) { |
3608 | Build.Bind(E,NE.Oriented(TopAbs_FORWARD)); |
3609 | } |
3610 | else { |
3611 | Build.Bind(E,NE.Oriented(TopAbs_REVERSED)); |
3612 | } |
3613 | const TopoDS_Edge& EOnV1 = TopoDS::Edge(NOnV1(E)); |
3614 | if (!ToBuild .IsBound(EOnV1) && |
3615 | !ConstShapes.IsBound(EOnV1) && |
3616 | !Build .IsBound(EOnV1)) { |
3617 | ExtentEdge (F,EF,EOnV1,NE); |
3618 | Build.Bind (EOnV1,NE.Oriented(TopAbs_FORWARD)); |
3619 | } |
3620 | const TopoDS_Edge& EOnV2 = TopoDS::Edge(NOnV2(E)); |
3621 | if (!ToBuild .IsBound(EOnV2) && |
3622 | !ConstShapes.IsBound(EOnV2) && |
3623 | !Build .IsBound(EOnV2)) { |
3624 | ExtentEdge (F,EF,EOnV2,NE); |
3625 | Build.Bind (EOnV2,NE.Oriented (TopAbs_FORWARD)); |
3626 | } |
3627 | } |
3628 | } |
3629 | |
3630 | //------------------------------------------------ |
3631 | // Construction Vertex. |
3632 | //------------------------------------------------ |
3633 | TopTools_ListOfShape LV; |
3634 | Standard_Real f,l; |
3635 | TopoDS_Edge ERef; |
3636 | TopoDS_Vertex V1,V2; |
3637 | |
3638 | for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
3639 | exp2.More(); exp2.Next()) { |
3640 | const TopoDS_Edge& E = TopoDS::Edge(exp2.Current()); |
3641 | TopExp::Vertices (E,V1,V2); |
3642 | BRep_Tool::Range (E,f,l); |
3643 | TopoDS_Vertex V; |
3644 | if (Build.IsBound(E)) { |
3645 | const TopoDS_Edge& NEOnV1 = TopoDS::Edge(NOnV1(E)); |
3646 | if (Build.IsBound(NEOnV1) && |
3647 | (ToBuild.IsBound(E) || ToBuild.IsBound(NEOnV1))) { |
3648 | if (E.IsSame(NEOnV1)) |
3649 | V = TopExp::FirstVertex(TopoDS::Edge(Build(E))); |
3650 | else { |
3651 | //--------------- |
3652 | // intersection. |
3653 | //--------------- |
3654 | if (!Build.IsBound(V1)) { |
3655 | Inter2d (EF,TopoDS::Edge(Build(E)), |
3656 | TopoDS::Edge(Build(NEOnV1)),LV,/*TolConf*/Precision::Confusion()); |
3657 | if (Build(E).Orientation() == TopAbs_FORWARD) { |
3658 | V = TopoDS::Vertex(LV.First()); |
3659 | } |
3660 | else { |
3661 | V = TopoDS::Vertex(LV.Last()); |
3662 | } |
3663 | } |
3664 | else { |
3665 | V = TopoDS::Vertex(Build(V1)); |
3666 | if (MVE (V1).Extent() > 2) { |
3667 | V.Orientation(TopAbs_FORWARD); |
3668 | if (Build(E).Orientation() == TopAbs_REVERSED) |
3669 | V.Orientation(TopAbs_REVERSED); |
3670 | ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf); |
3671 | } |
3672 | } |
3673 | } |
3674 | } |
3675 | else { |
3676 | //------------ |
3677 | //projection |
3678 | //------------ |
3679 | V = V1; |
3680 | if (ConstShapes.IsBound(V1)) V = TopoDS::Vertex(ConstShapes(V1)); |
3681 | V.Orientation(TopAbs_FORWARD); |
3682 | if (Build(E).Orientation() == TopAbs_REVERSED) |
3683 | V.Orientation(TopAbs_REVERSED); |
3684 | if (!TryParameter (E,V,TopoDS::Edge(Build(E)),TolConf)) |
3685 | ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf); |
3686 | } |
3687 | ConstShapes.Bind(V1,V); |
3688 | Build.Bind (V1,V); |
3689 | const TopoDS_Edge& NEOnV2 = TopoDS::Edge(NOnV2(E)); |
3690 | if (Build.IsBound(NEOnV2) && |
3691 | (ToBuild.IsBound(E) || ToBuild.IsBound(NEOnV2))) { |
3692 | if (E.IsSame(NEOnV2)) |
3693 | V = TopExp::LastVertex(TopoDS::Edge(Build(E))); |
3694 | else { |
3695 | //-------------- |
3696 | // intersection. |
3697 | //--------------- |
3698 | if (!Build.IsBound(V2)) { |
3699 | Inter2d (EF,TopoDS::Edge(Build(E)), |
3700 | TopoDS::Edge(Build(NEOnV2)),LV,/*TolConf*/Precision::Confusion()); |
3701 | if (Build(E).Orientation() == TopAbs_FORWARD) { |
3702 | V = TopoDS::Vertex(LV.Last()); |
3703 | } |
3704 | else { |
3705 | V = TopoDS::Vertex(LV.First()); |
3706 | } |
3707 | } |
3708 | else { |
3709 | V = TopoDS::Vertex(Build(V2)); |
3710 | if (MVE (V2).Extent() > 2) { |
3711 | V.Orientation(TopAbs_REVERSED); |
3712 | if (Build(E).Orientation() == TopAbs_REVERSED) |
3713 | V.Orientation(TopAbs_FORWARD); |
3714 | ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf); |
3715 | } |
3716 | } |
3717 | } |
3718 | } |
3719 | else { |
3720 | //------------ |
3721 | //projection |
3722 | //------------ |
3723 | V = V2; |
3724 | if (ConstShapes.IsBound(V2)) V = TopoDS::Vertex(ConstShapes(V2)); |
3725 | V.Orientation(TopAbs_REVERSED); |
3726 | if (Build(E).Orientation() == TopAbs_REVERSED) |
3727 | V.Orientation(TopAbs_FORWARD); |
3728 | if (!TryParameter (E,V,TopoDS::Edge(Build(E)),TolConf)) |
3729 | ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf); |
3730 | } |
3731 | ConstShapes.Bind(V2,V); |
3732 | Build.Bind(V2,V); |
3733 | } |
3734 | } |
3735 | |
3736 | TopoDS_Wire NW; |
3737 | TopoDS_Vertex NV1,NV2; |
3738 | TopAbs_Orientation Or; |
3739 | Standard_Real U1,U2; |
3740 | Standard_Real eps = Precision::Confusion(); |
3741 | |
3742 | #ifdef DEB |
3743 | TopLoc_Location L; |
3744 | #endif |
3745 | B.MakeWire(NW); |
3746 | |
3747 | //----------------- |
3748 | // Reconstruction. |
3749 | //----------------- |
3750 | for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
3751 | exp2.More(); exp2.Next()) { |
3752 | const TopoDS_Edge& E = TopoDS::Edge(exp2.Current()); |
3753 | TopExp::Vertices (E,V1,V2); |
3754 | if (Build.IsBound(E)) { |
3755 | NE = TopoDS::Edge(Build(E)); |
3756 | BRep_Tool::Range(NE,f,l); |
3757 | Or = NE.Orientation(); |
3758 | //----------------------------------------------------- |
3759 | // Copy pour virer les vertex deja sur la nouvelle edge. |
3760 | //----------------------------------------------------- |
3761 | NV1 = TopoDS::Vertex(ConstShapes(V1)); |
3762 | NV2 = TopoDS::Vertex(ConstShapes(V2)); |
3763 | |
3764 | TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_INTERNAL); |
3765 | TopoDS_Shape aLocalEdge = NE.Oriented(TopAbs_INTERNAL); |
3766 | |
3767 | U1 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalVertex), |
3768 | TopoDS::Edge (aLocalEdge)); |
3769 | aLocalVertex = NV2.Oriented(TopAbs_INTERNAL); |
3770 | aLocalEdge = NE.Oriented(TopAbs_FORWARD); |
3771 | U2 = BRep_Tool::Parameter |
3772 | (TopoDS::Vertex(aLocalVertex),TopoDS::Edge (aLocalEdge)); |
3773 | // U1 = BRep_Tool::Parameter |
3774 | // (TopoDS::Vertex(NV1.Oriented(TopAbs_INTERNAL)), |
3775 | // TopoDS::Edge (NE .Oriented(TopAbs_FORWARD))); |
3776 | // U2 = BRep_Tool::Parameter |
3777 | // (TopoDS::Vertex(NV2.Oriented(TopAbs_INTERNAL)), |
3778 | // TopoDS::Edge (NE.Oriented(TopAbs_FORWARD))); |
3779 | aLocalEdge = NE.EmptyCopied(); |
3780 | NE = TopoDS::Edge(aLocalEdge); |
3781 | NE.Orientation(TopAbs_FORWARD); |
3782 | if (NV1.IsSame(NV2)) |
3783 | { |
3784 | //-------------- |
3785 | // edge ferme. |
3786 | //-------------- |
3787 | if (Or == TopAbs_FORWARD) {U1 = f; U2 = l;} |
3788 | else {U1 = l; U2 = f;} |
3789 | if (Or == TopAbs_FORWARD) |
3790 | { |
3791 | if (U1 > U2) |
3792 | { |
3793 | if (Abs(U1-l) < eps) U1 = f; |
3794 | if (Abs(U2-f) < eps) U2 = l; |
3795 | } |
3796 | TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD ); |
3797 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3798 | aLocalVertex = NV2.Oriented(TopAbs_REVERSED); |
3799 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3800 | // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD ))); |
3801 | // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED))); |
3802 | B.Range(NE,U1,U2); |
3803 | ConstShapes.Bind(E,NE); |
3804 | NE.Orientation(E.Orientation()); |
3805 | } |
3806 | else |
3807 | { |
3808 | if (U2 > U1) |
3809 | { |
3810 | if (Abs(U2-l) < eps) U2 = f; |
3811 | if (Abs(U1-f) < eps) U1 = l; |
3812 | } |
3813 | TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD ); |
3814 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3815 | aLocalVertex = NV1.Oriented(TopAbs_REVERSED); |
3816 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3817 | // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD ))); |
3818 | // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED))); |
3819 | B.Range(NE,U2,U1); |
3820 | ConstShapes.Bind(E,NE.Oriented(TopAbs_REVERSED)); |
3821 | NE.Orientation(TopAbs::Reverse(E.Orientation())); |
3822 | } |
3823 | } |
3824 | else |
3825 | { |
3826 | //------------------- |
3827 | // edge is not ferme. |
3828 | //------------------- |
3829 | if (Or == TopAbs_FORWARD) { |
3830 | if (U1 > U2) { |
3831 | TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD ); |
3832 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3833 | aLocalVertex = NV1.Oriented(TopAbs_REVERSED); |
3834 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3835 | // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD ))); |
3836 | // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED))); |
3837 | B.Range(NE,U2,U1); |
3838 | } |
3839 | else |
3840 | { |
3841 | TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD ); |
3842 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3843 | aLocalVertex = NV2.Oriented(TopAbs_REVERSED); |
3844 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3845 | // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD ))); |
3846 | // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED))); |
3847 | B.Range(NE,U1,U2); |
3848 | } |
3849 | ConstShapes.Bind(E,NE); |
3850 | NE.Orientation(E.Orientation()); |
3851 | } |
3852 | else { |
3853 | if (U2 > U1) { |
3854 | TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD ); |
3855 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3856 | aLocalVertex = NV2.Oriented(TopAbs_REVERSED); |
3857 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3858 | // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD ))); |
3859 | // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED))); |
3860 | B.Range(NE,U1,U2); |
3861 | ConstShapes.Bind(E,NE); |
3862 | NE.Orientation(E.Orientation()); |
3863 | } |
3864 | else |
3865 | { |
3866 | TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD ); |
3867 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3868 | aLocalVertex = NV1.Oriented(TopAbs_REVERSED); |
3869 | B.Add (NE,TopoDS::Vertex(aLocalVertex)); |
3870 | // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD ))); |
3871 | // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED))); |
3872 | B.Range(NE,U2,U1); |
3873 | ConstShapes.Bind(E,NE.Oriented(TopAbs_REVERSED)); |
3874 | NE.Orientation(TopAbs::Reverse(E.Orientation())); |
3875 | } |
3876 | } |
3877 | } |
3878 | Build.UnBind(E); |
3879 | } // Build.IsBound(E) |
3880 | else if (ConstShapes.IsBound(E)) { // !Build.IsBound(E) |
3881 | NE = TopoDS::Edge(ConstShapes(E)); |
3882 | BuildPCurves(NE,NF); |
3883 | Or = NE.Orientation(); |
3884 | if (Or == TopAbs_REVERSED) { |
3885 | NE.Orientation(TopAbs::Reverse(E.Orientation())); |
3886 | } |
3887 | else { |
3888 | NE.Orientation(E.Orientation()); |
3889 | } |
3890 | } |
3891 | else { |
3892 | NE = E; |
3893 | ConstShapes.Bind(E,NE.Oriented(TopAbs_FORWARD)); |
3894 | } |
3895 | B.Add(NW,NE); |
3896 | } |
3897 | B.Add(NF,NW.Oriented(W.Orientation())); |
3898 | } |
3899 | NF.Orientation(F.Orientation()); |
3900 | BRepTools::Update(NF); // Maj des UVPoints |
3901 | |
3902 | #ifdef DRAW |
3903 | if (AffichInter) { |
3904 | // POP pour NT |
3905 | char* name = new char[100]; |
3906 | sprintf(name,"FOB_%d",NbFOB++); |
3907 | DBRep::Set(name,NF); |
3908 | } |
3909 | #endif |
3910 | } |
3911 | |
3912 | |
3913 | //======================================================================= |
3914 | //function : Deboucle3D |
3915 | //purpose : |
3916 | //======================================================================= |
3917 | |
3918 | TopoDS_Shape BRepOffset_Tool::Deboucle3D(const TopoDS_Shape& S, |
3919 | const TopTools_MapOfShape& Boundary) |
3920 | { |
3921 | return BRepAlgo_Tool::Deboucle3D(S,Boundary); |
3922 | } |
3923 | |
3924 | //======================================================================= |
3925 | //function : IsInOut |
3926 | //purpose : |
3927 | //======================================================================= |
3928 | |
3929 | static Standard_Boolean IsInOut (BRepTopAdaptor_FClass2d& FC, |
3930 | Geom2dAdaptor_Curve AC, |
3931 | const TopAbs_State& S ) |
3932 | { |
3933 | Standard_Real Def = 100*Precision::Confusion(); |
3934 | GCPnts_QuasiUniformDeflection QU(AC,Def); |
3935 | |
3936 | for (Standard_Integer i = 1; i <= QU.NbPoints(); i++) { |
3937 | gp_Pnt2d P = AC.Value(QU.Parameter(i)); |
3938 | if (FC.Perform(P) != S) { |
3939 | return Standard_False; |
3940 | break; |
3941 | } |
3942 | } |
3943 | return Standard_True; |
3944 | } |
3945 | |
3946 | //======================================================================= |
3947 | //function : CorrectOrientation |
3948 | //purpose : |
3949 | //======================================================================= |
3950 | |
3951 | void BRepOffset_Tool::CorrectOrientation(const TopoDS_Shape& SI, |
3952 | const TopTools_MapOfShape& NewEdges, |
3953 | Handle(BRepAlgo_AsDes)& AsDes, |
3954 | BRepAlgo_Image& InitOffset, |
3955 | const Standard_Real Offset) |
3956 | { |
3957 | |
3958 | TopExp_Explorer exp; |
3959 | exp.Init(SI,TopAbs_FACE); |
3960 | Standard_Real f=0.,l=0.; |
3961 | |
3962 | for (; exp.More(); exp.Next()) { |
3963 | |
3964 | const TopoDS_Face& FI = TopoDS::Face(exp.Current()); |
3965 | const TopTools_ListOfShape& LOF = InitOffset.Image(FI); |
3966 | TopTools_ListIteratorOfListOfShape it(LOF); |
3967 | for (; it.More(); it.Next()) { |
3968 | const TopoDS_Face& OF = TopoDS::Face(it.Value()); |
3969 | TopTools_ListOfShape& LOE = AsDes->ChangeDescendant(OF); |
3970 | TopTools_ListIteratorOfListOfShape itE(LOE); |
3971 | |
3972 | Standard_Boolean YaInt = Standard_False; |
3973 | for (; itE.More(); itE.Next()) { |
3974 | const TopoDS_Edge& OE = TopoDS::Edge(itE.Value()); |
3975 | if (NewEdges.Contains(OE)) {YaInt = Standard_True; break;} |
3976 | } |
3977 | if (YaInt) { |
3978 | TopoDS_Shape aLocalFace = FI.Oriented(TopAbs_FORWARD); |
3979 | BRepTopAdaptor_FClass2d FC (TopoDS::Face(aLocalFace), |
3980 | Precision::Confusion()); |
3981 | // BRepTopAdaptor_FClass2d FC (TopoDS::Face(FI.Oriented(TopAbs_FORWARD)), |
3982 | // Precision::Confusion()); |
3983 | for (itE.Initialize(LOE); itE.More(); itE.Next()) { |
3984 | TopoDS_Shape& OE = itE.Value(); |
3985 | if (NewEdges.Contains(OE)) { |
3986 | Handle(Geom2d_Curve) CO2d = |
3987 | BRep_Tool::CurveOnSurface(TopoDS::Edge(OE),OF,f,l); |
3988 | Geom2dAdaptor_Curve AC(CO2d,f,l); |
3989 | |
3990 | if (Offset > 0) { |
3991 | if (IsInOut(FC,AC,TopAbs_OUT)) OE.Reverse(); |
3992 | } |
3993 | // else { |
3994 | // if (IsInOut(FC,AC,TopAbs_IN)) OE.Reverse(); |
3995 | // } |
3996 | } |
3997 | } |
3998 | } |
3999 | } |
4000 | } |
4001 | |
4002 | } |
4003 | |
4004 | |
4005 | |