Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-01-07 |
2 | // Created by: Philippe MANGIN | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | #include <stdio.h> | |
23 | ||
24 | #include <BRepFill_Sweep.ixx> | |
25 | ||
26 | #include <BRepFill_SectionLaw.hxx> | |
27 | //#include <BRepFill_TrimCorner.hxx> | |
28 | #include <BRepFill_CurveConstraint.hxx> | |
29 | ||
30 | #include <GeomFill_SectionLaw.hxx> | |
31 | #include <GeomFill_LocationLaw.hxx> | |
32 | #include <GeomFill_Sweep.hxx> | |
33 | ||
34 | // modified by NIZHNY-MKK Wed Oct 22 12:25:45 2003 | |
35 | #include <BRepFill_TrimShellCorner.hxx> | |
36 | ||
37 | //#include <GeomPlate_BuildPlateSurface.hxx> | |
38 | //#include <GeomPlate_Surface.hxx> | |
39 | //#include <GeomPlate_PointConstraint.hxx> | |
40 | ||
41 | #include <gp_Pnt2d.hxx> | |
42 | #include <gp_Vec2d.hxx> | |
43 | #include <Bnd_Box.hxx> | |
44 | ||
45 | #include <Geom_Surface.hxx> | |
46 | #include <Geom_SurfaceOfRevolution.hxx> | |
47 | #include <Geom_RectangularTrimmedSurface.hxx> | |
48 | #include <Geom_Plane.hxx> | |
49 | #include <Geom_Curve.hxx> | |
50 | #include <Geom_BezierCurve.hxx> | |
51 | #include <Geom_BSplineCurve.hxx> | |
52 | #include <Geom2d_Line.hxx> | |
53 | #include <Geom2d_Curve.hxx> | |
54 | #include <Geom2d_TrimmedCurve.hxx> | |
55 | #include <GeomLib.hxx> | |
56 | #include <GeomLib_IsPlanarSurface.hxx> | |
57 | #include <BRepLib_FindSurface.hxx> | |
58 | #include <GeomConvert_ApproxSurface.hxx> | |
59 | ||
60 | #include <BRepAdaptor_HCurve.hxx> | |
61 | #include <BRepAdaptor_HCurve2d.hxx> | |
62 | #include <BRepAdaptor_HSurface.hxx> | |
63 | #include <Adaptor3d_HCurveOnSurface.hxx> | |
64 | #include <GeomAdaptor_HSurface.hxx> | |
65 | #include <GeomAdaptor_HCurve.hxx> | |
66 | #include <Geom2dAdaptor_HCurve.hxx> | |
67 | #include <Approx_CurveOnSurface.hxx> | |
68 | #include <Approx_SameParameter.hxx> | |
69 | #include <GCPnts_AbscissaPoint.hxx> | |
70 | ||
71 | #include <BRep_Builder.hxx> | |
72 | #include <BRep_Tool.hxx> | |
73 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> | |
74 | #include <BRep_TEdge.hxx> | |
75 | #include <BRep_TVertex.hxx> | |
76 | #include <BRep_CurveRepresentation.hxx> | |
77 | #include <BRep_GCurve.hxx> | |
78 | ||
79 | #include <BRepLib.hxx> | |
80 | #include <BRepLib_MakeEdge.hxx> | |
81 | #include <BRepLib_MakeFace.hxx> | |
82 | #include <BRepLib_FaceError.hxx> | |
83 | ||
84 | #include <TopoDS.hxx> | |
85 | #include <TopoDS_Edge.hxx> | |
86 | #include <TopoDS_Face.hxx> | |
87 | #include <TopoDS_Compound.hxx> | |
88 | #include <TopoDS_Shell.hxx> | |
89 | #include <TopExp.hxx> | |
90 | #include <TopExp_Explorer.hxx> | |
91 | #include <TopAbs_Orientation.hxx> | |
92 | ||
93 | #include <TColStd_HArray1OfInteger.hxx> | |
94 | #include <TColStd_Array2OfInteger.hxx> | |
95 | #include <TColStd_Array1OfReal.hxx> | |
96 | #include <TColStd_Array2OfReal.hxx> | |
97 | #include <TColGeom_Array2OfSurface.hxx> | |
98 | #include <TColgp_Array1OfPnt.hxx> | |
99 | ||
100 | #include <TopTools_Array1OfShape.hxx> | |
101 | #include <TopTools_Array2OfShape.hxx> | |
102 | #include <TopTools_HArray2OfShape.hxx> | |
103 | #include <TopTools_HArray1OfShape.hxx> | |
104 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
105 | #include <TopTools_ListOfShape.hxx> | |
106 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> | |
107 | #include <BRepTools_WireExplorer.hxx> | |
108 | ||
109 | #include <Standard_ConstructionError.hxx> | |
110 | #include <Precision.hxx> | |
111 | #include <BRepBuilderAPI_MakeWire.hxx> | |
112 | ||
113 | #include <BRepTools_Substitution.hxx> | |
114 | #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx> | |
115 | #include <TopoDS_Iterator.hxx> | |
116 | ||
117 | //OCC500(apo) | |
118 | #include <BRepCheck_Edge.hxx> | |
119 | ||
120 | #ifdef DRAW | |
121 | #include <Draw.hxx> | |
122 | #include <DrawTrSurf.hxx> | |
123 | #include <DBRep.hxx> | |
124 | static Standard_Boolean Affich = 0; | |
125 | #endif | |
126 | ||
127 | //======================================================================= | |
128 | //function : NumberOfPoles | |
129 | //purpose : | |
130 | //======================================================================= | |
131 | static Standard_Integer NumberOfPoles(const TopoDS_Wire& W) | |
132 | { | |
133 | Standard_Integer NbPoints = 0; | |
134 | ||
135 | TopoDS_Iterator iter(W); | |
136 | for (; iter.More(); iter.Next()) | |
137 | { | |
138 | BRepAdaptor_Curve c(TopoDS::Edge(iter.Value())); | |
139 | ||
140 | Standard_Real dfUf = c.FirstParameter(); | |
141 | Standard_Real dfUl = c.LastParameter(); | |
142 | if (IsEqual(dfUf,dfUl)) | |
143 | // Degenerate | |
144 | continue; | |
145 | ||
146 | switch (c.GetType()) | |
147 | { | |
148 | case GeomAbs_BezierCurve: | |
149 | { | |
150 | // Put all poles for bezier | |
151 | Handle(Geom_BezierCurve) GC = c.Bezier(); | |
152 | Standard_Integer iNbPol = GC->NbPoles(); | |
153 | if ( iNbPol >= 2) | |
154 | NbPoints += iNbPol; | |
155 | break; | |
156 | } | |
157 | case GeomAbs_BSplineCurve: | |
158 | { | |
159 | // Put all poles for bspline | |
160 | Handle(Geom_BSplineCurve) GC = c.BSpline(); | |
161 | Standard_Integer iNbPol = GC->NbPoles(); | |
162 | if ( iNbPol >= 2) | |
163 | NbPoints += iNbPol; | |
164 | break; | |
165 | } | |
166 | case GeomAbs_Line: | |
167 | { | |
168 | NbPoints += 2; | |
169 | break; | |
170 | } | |
171 | case GeomAbs_Circle: | |
172 | case GeomAbs_Ellipse: | |
173 | case GeomAbs_Hyperbola: | |
174 | case GeomAbs_Parabola: | |
175 | { | |
176 | NbPoints += 4; | |
177 | break; | |
178 | } | |
179 | default: | |
180 | NbPoints += 15 + c.NbIntervals(GeomAbs_C3); | |
181 | } // switch (c.GetType()) ... | |
182 | } // for (; iter.More(); iter.Next()) | |
183 | ||
184 | return NbPoints; | |
185 | } | |
186 | ||
187 | //======================================================================= | |
188 | //function : HasPCurves | |
189 | //purpose : | |
190 | //======================================================================= | |
191 | static Standard_Boolean HasPCurves(const TopoDS_Edge& E) | |
192 | { | |
193 | Standard_Boolean haspcurves = Standard_False; | |
194 | ||
195 | BRep_ListIteratorOfListOfCurveRepresentation itcr | |
196 | ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves()); | |
197 | for (; itcr.More(); itcr.Next()) | |
198 | { | |
199 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
200 | if (cr->IsCurveOnSurface()) | |
201 | { | |
202 | haspcurves = Standard_True; | |
203 | break; | |
204 | } | |
205 | } | |
206 | return haspcurves; | |
207 | } | |
208 | ||
209 | //======================================================================= | |
210 | //function : Translate | |
0d969553 | 211 | //purpose : Copy a column from one table to another. |
7fd59977 | 212 | //======================================================================= |
213 | static void Translate(const Handle(TopTools_HArray2OfShape)& ArrayIn, | |
214 | const Standard_Integer In, | |
215 | Handle(TopTools_HArray2OfShape)& ArrayOut, | |
216 | const Standard_Integer Out) | |
217 | { | |
218 | Standard_Integer ii, Nb; | |
219 | Nb = ArrayOut->ColLength(); | |
220 | for (ii=1; ii<=Nb; ii++) { | |
221 | ArrayOut->SetValue(ii, Out, ArrayIn->Value(ii, In)); | |
222 | } | |
223 | } | |
224 | ||
225 | ||
226 | //======================================================================= | |
227 | //function : Box | |
0d969553 | 228 | //purpose : Bounding box of a section. |
7fd59977 | 229 | //======================================================================= |
230 | static void Box(Handle(GeomFill_SectionLaw)& Sec, | |
231 | const Standard_Real U, | |
232 | Bnd_Box& Box) | |
233 | ||
234 | { | |
235 | Standard_Integer NbPoles, bid; | |
236 | Box.SetVoid(); | |
237 | Sec->SectionShape(NbPoles, bid, bid); | |
238 | TColgp_Array1OfPnt Poles(1, NbPoles); | |
239 | TColStd_Array1OfReal W(1, NbPoles); | |
240 | Sec->D0(U, Poles, W); | |
241 | for (Standard_Integer ii=1; ii<=NbPoles; ii++) { | |
242 | Box.Add(Poles(ii)); | |
243 | } | |
244 | } | |
245 | ||
246 | //======================================================================= | |
247 | //function : Couture | |
0d969553 Y |
248 | //purpose : Check if E is an edge of sewing on S |
249 | // and make the representation HadHoc | |
7fd59977 | 250 | //======================================================================= |
251 | static Handle(Geom2d_Curve) Couture(const TopoDS_Edge& E, | |
252 | const Handle(Geom_Surface)& S, | |
253 | const TopLoc_Location& L) | |
254 | { | |
255 | TopLoc_Location l = L.Predivided(E.Location()); | |
256 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
257 | ||
258 | // find the representation | |
259 | BRep_ListIteratorOfListOfCurveRepresentation itcr | |
260 | ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves()); | |
261 | ||
262 | while (itcr.More()) { | |
263 | Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
264 | if (cr->IsCurveOnSurface(S,l)) { | |
265 | Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr); | |
266 | if (GC->IsCurveOnClosedSurface() && Eisreversed) | |
267 | return GC->PCurve2(); | |
268 | else | |
269 | return GC->PCurve(); | |
270 | } | |
271 | itcr.Next(); | |
272 | } | |
273 | Handle(Geom2d_Curve) pc; | |
274 | pc.Nullify(); | |
275 | return pc; | |
276 | } | |
277 | ||
278 | //======================================================================= | |
279 | //function : CheckSameParameter | |
0d969553 | 280 | //purpose : Check a posteriori that sameparameter has worked correctly |
7fd59977 | 281 | //======================================================================= |
282 | ||
283 | static Standard_Boolean CheckSameParameter | |
284 | (const Handle(Adaptor3d_HCurve)& C3d, | |
471ce736 | 285 | const Handle(Geom2d_Curve)& Pcurv, |
7fd59977 | 286 | const Handle(Adaptor3d_HSurface)& S, |
287 | const Standard_Real tol3d, | |
288 | Standard_Real& tolreached) | |
289 | { | |
290 | tolreached = 0.; | |
291 | Standard_Real f = C3d->FirstParameter(); | |
292 | Standard_Real l = C3d->LastParameter(); | |
293 | Standard_Integer nbp = 45; | |
294 | Standard_Real step = 1./(nbp -1); | |
295 | for(Standard_Integer i = 0; i < nbp; i++){ | |
296 | Standard_Real t,u,v; | |
297 | t = step * i; | |
298 | t = (1-t) * f + t * l; | |
299 | Pcurv->Value(t).Coord(u,v); | |
300 | gp_Pnt pS = S->Value(u,v); | |
301 | gp_Pnt pC = C3d->Value(t); | |
302 | Standard_Real d2 = pS.SquareDistance(pC); | |
303 | tolreached = Max(tolreached,d2); | |
304 | } | |
305 | tolreached = sqrt(tolreached); | |
306 | if(tolreached > tol3d){ | |
307 | tolreached *= 2.; | |
308 | return Standard_False; | |
309 | } | |
310 | tolreached *= 2.; | |
311 | tolreached = Max(tolreached,Precision::Confusion()); | |
312 | return Standard_True; | |
313 | } | |
314 | ||
315 | //======================================================================= | |
316 | //function : SameParameter | |
0d969553 Y |
317 | //purpose : Encapsulation of Sameparameter |
318 | // Boolean informs if the pcurve was computed or not... | |
319 | // The tolerance is always OK. | |
7fd59977 | 320 | //======================================================================= |
321 | ||
322 | static Standard_Boolean SameParameter(TopoDS_Edge& E, | |
323 | Handle(Geom2d_Curve)& Pcurv, | |
324 | const Handle(Geom_Surface)& Surf, | |
325 | const Standard_Real tol3d, | |
326 | Standard_Real& tolreached) | |
327 | { | |
328 | //Handle(BRepAdaptor_HCurve) C3d = new (BRepAdaptor_HCurve)(E); | |
329 | Standard_Real f, l; | |
330 | Handle(Geom_Curve) C3d = BRep_Tool::Curve( E, f, l ); | |
331 | GeomAdaptor_Curve GAC3d( C3d, f, l ); | |
332 | Handle(GeomAdaptor_HCurve) HC3d = new GeomAdaptor_HCurve( GAC3d ); | |
333 | ||
334 | Handle(GeomAdaptor_HSurface) S = new (GeomAdaptor_HSurface)(Surf); | |
335 | Standard_Real ResTol; | |
336 | ||
337 | if(CheckSameParameter( HC3d, Pcurv, S, tol3d, tolreached )) | |
338 | return Standard_True; | |
339 | ||
340 | if (!HasPCurves(E)) | |
341 | { | |
342 | Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( Pcurv ); | |
343 | Approx_CurveOnSurface AppCurve(HC2d, S, HC2d->FirstParameter(), HC2d->LastParameter(), | |
344 | Precision::Confusion(), GeomAbs_C1, 10, 10, Standard_True); | |
345 | if (AppCurve.IsDone() && AppCurve.HasResult()) | |
346 | { | |
347 | C3d = AppCurve.Curve3d(); | |
348 | tolreached = AppCurve.MaxError3d(); | |
349 | BRep_Builder B; | |
350 | B.UpdateEdge( E, C3d, tolreached ); | |
351 | return Standard_True; | |
352 | } | |
353 | } | |
354 | ||
355 | Approx_SameParameter sp( HC3d, Pcurv, S, tol3d ); | |
356 | if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d(); | |
357 | else if(!sp.IsDone() && !sp.IsSameParameter()){ | |
358 | #ifdef DEB | |
359 | cout<<"echec SameParameter"<<endl; | |
360 | #endif | |
361 | return Standard_False; | |
362 | } | |
363 | ||
364 | ResTol = sp.TolReached(); | |
365 | if(ResTol > tolreached ){ | |
366 | #ifdef DEB | |
0d969553 Y |
367 | cout<<"SameParameter : Tolerance not reached!"<<endl; |
368 | cout<<"tol visee : "<<tol3d<<" tol obtained : "<<ResTol<<endl; | |
7fd59977 | 369 | #endif |
370 | return Standard_False; | |
371 | } | |
372 | else { | |
373 | tolreached = 1.1*ResTol; | |
374 | if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d(); | |
375 | } | |
376 | return Standard_True; | |
377 | } | |
378 | ||
379 | //======================================================================= | |
0d969553 Y |
380 | //Objet : Orientate an edge of natural restriction |
381 | // : General | |
7fd59977 | 382 | //======================================================================= |
383 | static void Oriente(const Handle(Geom_Surface)& S, | |
384 | TopoDS_Edge& E) | |
385 | { | |
386 | gp_Pnt2d P; | |
387 | gp_Vec2d D, URef(1, 0), VRef(0, 1); | |
388 | Standard_Boolean isuiso, isfirst, isopposite; | |
389 | Standard_Real UFirst, ULast, VFirst, VLast, f, l; | |
390 | S->Bounds(UFirst, ULast, VFirst, VLast); | |
391 | Handle(Geom2d_Curve) C; | |
392 | TopLoc_Location bid; | |
393 | ||
394 | C = BRep_Tool::CurveOnSurface(E, S, bid, f, l); | |
395 | C->D1((f+l)/2, P, D); | |
396 | ||
397 | isuiso = D.IsParallel(VRef, 0.1); | |
398 | ||
399 | if ( isuiso ) { | |
400 | isfirst = (Abs (P.X()-UFirst) < Precision::Confusion()); | |
401 | isopposite = D.IsOpposite(VRef, 0.1); | |
402 | E.Orientation(TopAbs_REVERSED); | |
403 | } | |
404 | else { | |
405 | isfirst = (Abs (P.Y()-VFirst) < Precision::Confusion()); | |
406 | isopposite = D.IsOpposite(URef, 0.1); | |
407 | E.Orientation(TopAbs_FORWARD); | |
408 | } | |
409 | ||
410 | if (!isfirst) E.Reverse(); | |
411 | if (isopposite) E.Reverse(); | |
412 | } | |
413 | //OCC500(apo)-> | |
414 | static void UpdateEdgeOnPlane(const TopoDS_Face& F, const TopoDS_Edge& E, | |
415 | const BRep_Builder& BB) | |
416 | { | |
417 | Standard_Real f, l; | |
418 | Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l); | |
419 | Handle(Geom_Surface) S = BRep_Tool::Surface(F); | |
420 | TopLoc_Location Loc; | |
421 | Standard_Real Tol = BRep_Tool::Tolerance(E); | |
422 | BB.UpdateEdge(E, C2d, S, Loc, Tol); | |
423 | BRepCheck_Edge Check(E); | |
424 | Tol = Max(Tol,Check.Tolerance()); | |
425 | BB.UpdateEdge(E, Tol); | |
426 | TopoDS_Vertex V; | |
427 | Tol *= 1.01; | |
428 | V = TopExp::FirstVertex(E); | |
429 | if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol); | |
430 | V = TopExp::LastVertex(E); | |
431 | if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol); | |
432 | } | |
433 | //<-OCC500(apo) | |
434 | //======================================================================= | |
435 | //Function : BuildFace | |
0d969553 Y |
436 | //Objet : Construct a Face via a surface and 4 Edges (natural borders) |
437 | // : Only one Hypothesis : isos u and v are switched : | |
438 | // Edge1/3 are iso u (recp v) | |
439 | // Edge2/4 are iso v (recp u) | |
7fd59977 | 440 | //======================================================================= |
441 | static void BuildFace(const Handle(Geom_Surface)& S, | |
442 | const TopoDS_Edge& E1, | |
443 | const TopoDS_Edge& E2, | |
444 | const TopoDS_Edge& E3, | |
445 | const TopoDS_Edge& E4, | |
446 | TopTools_DataMapOfShapeShape& EEmap, | |
447 | const Standard_Boolean ExchUV, | |
448 | const Standard_Boolean UReverse, | |
449 | TopoDS_Face& F) | |
450 | { | |
451 | Standard_Real Tol; | |
452 | // Class BRep_Tool without fields and without Constructor : | |
453 | // BRep_Tool BT; | |
454 | TopoDS_Edge e1, e2, E; | |
455 | TopoDS_Wire WW; | |
456 | BRep_Builder BB; | |
457 | BRepBuilderAPI_MakeWire B; | |
458 | TopoDS_Iterator Iter; | |
459 | //gp_Pnt2d P; | |
460 | ||
0d969553 | 461 | //Is the surface planar ? |
7fd59977 | 462 | Standard_Real Tol1, Tol2, Tol3, Tol4; |
463 | Tol1 = BRep_Tool::Tolerance( E1 ); | |
464 | Tol2 = BRep_Tool::Tolerance( E2 ); | |
465 | Tol3 = BRep_Tool::Tolerance( E3 ); | |
466 | Tol4 = BRep_Tool::Tolerance( E4 ); | |
467 | // Tol = Min( BT.Tolerance(E1), BT.Tolerance(E2)); | |
468 | Tol = Min( Tol1, Tol2 ); | |
469 | // Tol = Min(Tol, Min(BT.Tolerance(E3),BT.Tolerance(E4))); | |
470 | Tol = Min( Tol, Min( Tol3, Tol4 ) ); | |
471 | Standard_Boolean IsPlan = Standard_False; | |
472 | Handle(Geom_Plane) thePlane; | |
473 | ||
474 | if (!E1.IsSame(E3) && !E2.IsSame(E4)) //exclude cases with seam edges: they are not planar | |
475 | { | |
476 | GeomLib_IsPlanarSurface IsP(S, Tol); | |
477 | if (IsP.IsPlanar()) | |
478 | { | |
479 | IsPlan = Standard_True; | |
480 | thePlane = new Geom_Plane( IsP.Plan() ); | |
481 | } | |
482 | else | |
483 | { | |
484 | Handle(BRep_TEdge)& TE1 = *((Handle(BRep_TEdge)*)&E1.TShape()); | |
485 | Handle(BRep_TEdge)& TE2 = *((Handle(BRep_TEdge)*)&E2.TShape()); | |
486 | Handle(BRep_TEdge)& TE3 = *((Handle(BRep_TEdge)*)&E3.TShape()); | |
487 | Handle(BRep_TEdge)& TE4 = *((Handle(BRep_TEdge)*)&E4.TShape()); | |
488 | TE1->Tolerance( Precision::Confusion() ); | |
489 | TE2->Tolerance( Precision::Confusion() ); | |
490 | TE3->Tolerance( Precision::Confusion() ); | |
491 | TE4->Tolerance( Precision::Confusion() ); | |
492 | ||
493 | TopoDS_Wire theWire = BRepLib_MakeWire( E1, E2, E3, E4 ); | |
494 | Standard_Integer NbPoints = NumberOfPoles( theWire ); | |
495 | if (NbPoints <= 100) //limitation for CPU | |
496 | { | |
497 | BRepLib_FindSurface FS( theWire, -1, Standard_True ); | |
498 | if (FS.Found()) | |
499 | { | |
500 | IsPlan = Standard_True; | |
501 | thePlane = Handle(Geom_Plane)::DownCast(FS.Surface()); | |
502 | } | |
503 | } | |
504 | BB.UpdateEdge( E1, Tol1 ); | |
505 | BB.UpdateEdge( E2, Tol2 ); | |
506 | BB.UpdateEdge( E3, Tol3 ); | |
507 | BB.UpdateEdge( E4, Tol4 ); | |
508 | } | |
509 | } | |
510 | ||
0d969553 | 511 | // Construction of the wire |
7fd59977 | 512 | // B.MakeWire(WW); |
513 | e1 = E1; | |
514 | Oriente(S, e1); | |
515 | // if (!IsPlan || !BT.Degenerated(e1)) | |
516 | if (!IsPlan || !BRep_Tool::Degenerated(e1)) | |
517 | B.Add(e1); | |
518 | ||
519 | e2 = E2; | |
520 | Oriente(S, e2); | |
521 | // if (!IsPlan || !BT.Degenerated(e2)) | |
522 | if (!IsPlan || !BRep_Tool::Degenerated(e2)) | |
523 | { | |
524 | B.Add(e2); | |
525 | if (!BRep_Tool::Degenerated(e2)) | |
526 | { | |
527 | WW = B.Wire(); | |
528 | TopoDS_Shape NewEdge; | |
529 | //take the last edge added to WW | |
530 | for (Iter.Initialize( WW ); Iter.More(); Iter.Next()) | |
531 | NewEdge = Iter.Value(); | |
532 | if (! e2.IsSame(NewEdge)) | |
533 | EEmap.Bind( e2, NewEdge ); | |
534 | } | |
535 | } | |
536 | ||
537 | if (E3.IsSame(E1)) { | |
538 | E = e1; | |
539 | E.Reverse(); | |
540 | } | |
541 | else { | |
542 | E = E3; | |
543 | Oriente(S, E); | |
544 | } | |
545 | // if (!IsPlan || !BT.Degenerated(E)) | |
546 | if (!IsPlan || !BRep_Tool::Degenerated(E)) | |
547 | { | |
548 | B.Add(E); | |
549 | if (!BRep_Tool::Degenerated(E)) | |
550 | { | |
551 | WW = B.Wire(); | |
552 | TopoDS_Shape NewEdge; | |
553 | //take the last edge added to WW | |
554 | for (Iter.Initialize( WW ); Iter.More(); Iter.Next()) | |
555 | NewEdge = Iter.Value(); | |
556 | if (! E.IsSame(NewEdge)) | |
557 | EEmap.Bind( E, NewEdge ); | |
558 | } | |
559 | } | |
560 | ||
561 | if (E4.IsSame(E2)) { | |
562 | E = e2; | |
563 | E.Reverse(); | |
564 | } | |
565 | else { | |
566 | E = E4; | |
567 | Oriente(S, E); | |
568 | } | |
569 | // if (!IsPlan || !BT.Degenerated(E)) | |
570 | if (!IsPlan || !BRep_Tool::Degenerated(E)) | |
571 | { | |
572 | B.Add(E); | |
573 | if (!BRep_Tool::Degenerated(E)) | |
574 | { | |
575 | WW = B.Wire(); | |
576 | TopoDS_Shape NewEdge; | |
577 | //take the last edge added to WW | |
578 | for (Iter.Initialize( WW ); Iter.More(); Iter.Next()) | |
579 | NewEdge = Iter.Value(); | |
580 | if (! E.IsSame(NewEdge)) | |
581 | EEmap.Bind( E, NewEdge ); | |
582 | } | |
583 | } | |
584 | ||
585 | WW = B.Wire(); | |
586 | #if DRAW | |
c0695321 A |
587 | if (Affich) |
588 | DBRep::Set("wire-on-face", WW); | |
7fd59977 | 589 | #endif |
590 | ||
0d969553 Y |
591 | // Construction of the face. |
592 | if (IsPlan) { // Suspend representation 2d | |
593 | // and construct face Plane | |
7fd59977 | 594 | |
595 | //BRepLib_MakeFace MkF(IsP.Plan(), WW); | |
596 | gp_Pnt aPnt; | |
597 | gp_Vec DU, DV, NS, NP; | |
598 | Standard_Real Ufirst, Ulast, Vfirst, Vlast; | |
599 | S->Bounds( Ufirst, Ulast, Vfirst, Vlast ); | |
600 | S->D1( (Ufirst+Ulast)/2., (Vfirst+Vlast)/2., aPnt, DU, DV ); | |
601 | NS = DU ^ DV; | |
602 | NP = thePlane->Pln().Axis().Direction(); | |
603 | if (NS.Dot(NP) < 0.) | |
604 | thePlane->UReverse(); | |
605 | BRepLib_MakeFace MkF( thePlane, WW ); | |
606 | if (MkF.Error() != BRepLib_FaceDone) { | |
607 | #if DEB | |
608 | BRepLib_FaceError Err = MkF.Error(); | |
609 | cout << "Planar Face Error :" << Err << endl; | |
610 | #endif | |
611 | } | |
612 | else { | |
613 | Handle(Geom2d_Curve) NullC2d; | |
614 | TopLoc_Location Loc; | |
615 | BB.UpdateEdge( E1, NullC2d, S, Loc, Tol1 ); | |
616 | BB.UpdateEdge( E2, NullC2d, S, Loc, Tol2 ); | |
617 | BB.UpdateEdge( E3, NullC2d, S, Loc, Tol3 ); | |
618 | BB.UpdateEdge( E4, NullC2d, S, Loc, Tol4 ); | |
619 | ||
620 | F = MkF.Face(); | |
621 | UpdateEdgeOnPlane(F,E1,BB); | |
622 | UpdateEdgeOnPlane(F,E2,BB); | |
623 | UpdateEdgeOnPlane(F,E3,BB); | |
624 | UpdateEdgeOnPlane(F,E4,BB); | |
625 | /*OCC500(apo)-> | |
626 | TopLoc_Location Loc; | |
627 | Handle(Geom2d_Curve) NC; | |
628 | NC.Nullify(); | |
629 | // B.UpdateEdge(E1, NC, S, Loc, BT.Tolerance(E1)); | |
630 | BB.UpdateEdge(E1, NC, S, Loc, BRep_Tool::Tolerance(E1)); | |
631 | // B.UpdateEdge(E2, NC, S, Loc, BT.Tolerance(E2)); | |
632 | BB.UpdateEdge(E2, NC, S, Loc, BRep_Tool::Tolerance(E2)); | |
633 | // B.UpdateEdge(E3, NC, S, Loc, BT.Tolerance(E3)); | |
634 | BB.UpdateEdge(E3, NC, S, Loc, BRep_Tool::Tolerance(E3)); | |
635 | // B.UpdateEdge(E4, NC, S, Loc, BT.Tolerance(E4)); | |
636 | BB.UpdateEdge(E4, NC, S, Loc, BRep_Tool::Tolerance(E4)); | |
637 | <-OCC500(apo)*/ | |
638 | } | |
639 | } | |
640 | ||
641 | if (!IsPlan) {// Cas Standard : Ajout | |
642 | BB.MakeFace(F, S, Precision::Confusion()); | |
643 | BB.Add(F, WW); | |
644 | } | |
645 | ||
646 | // Reorientation | |
647 | if (ExchUV) F.Reverse(); | |
648 | if (UReverse) F.Reverse(); | |
649 | } | |
650 | ||
651 | ||
652 | //======================================================================= | |
653 | //Fonction : BuildEdge | |
0d969553 | 654 | //Objet : Construct non-closed Edge |
7fd59977 | 655 | //======================================================================= |
656 | static TopoDS_Edge BuildEdge(Handle(Geom_Curve)& C3d, | |
657 | Handle(Geom2d_Curve)& C2d, | |
658 | Handle(Geom_Surface)& S, | |
659 | const TopoDS_Vertex& VF, | |
660 | const TopoDS_Vertex& VL, | |
661 | const Standard_Real f, | |
662 | const Standard_Real l, | |
663 | const Standard_Real Tol3d) | |
664 | { | |
665 | gp_Pnt P1, P2, P; | |
666 | Standard_Real Tol1, Tol2, Tol, d; | |
667 | // Class BRep_Tool without fields and without Constructor : | |
668 | // BRep_Tool BT; | |
669 | BRep_Builder B; | |
670 | TopoDS_Edge E; | |
671 | ||
672 | // P1 = BT.Pnt(VF); | |
673 | P1 = BRep_Tool::Pnt(VF); | |
674 | // Tol1 = BT.Tolerance(VF); | |
675 | Tol1 = BRep_Tool::Tolerance(VF); | |
676 | // P2 = BT.Pnt(VL); | |
677 | P2 = BRep_Tool::Pnt(VL); | |
678 | // Tol2 = BT.Tolerance(VF); | |
679 | Tol2 = BRep_Tool::Tolerance(VF); | |
680 | Tol = Max(Tol1, Tol2); | |
681 | ||
682 | if (VF.IsSame(VL) || | |
683 | (P1.Distance(P2) < Tol ) ) { | |
0d969553 | 684 | // Degenerated case |
7fd59977 | 685 | gp_Pnt2d P2d; |
686 | C2d->D0(f, P2d); | |
687 | S->D0(P2d.X(), P2d.Y(), P); | |
688 | d = P1.Distance(P); | |
689 | if (d > Tol) Tol = d; | |
690 | C2d->D0(l, P2d); | |
691 | S->D0(P2d.X(), P2d.Y(), P); | |
692 | d = P2.Distance(P); | |
693 | if (d > Tol) Tol = d; | |
694 | ||
695 | B.UpdateVertex(VF, Tol); | |
696 | B.UpdateVertex(VL, Tol); | |
697 | ||
698 | B.MakeEdge(E); | |
699 | B.UpdateEdge(E,C2d,S,TopLoc_Location(), Tol); | |
700 | B.Add(E,VF); | |
701 | B.Add(E,VL); | |
702 | B.Range(E,f,l); | |
703 | B.Degenerated(E, Standard_True); | |
704 | ||
705 | return E; | |
706 | } | |
707 | ||
708 | C3d->D0(f, P); | |
709 | d = P1.Distance(P); | |
710 | if (d > Tol1) | |
711 | B.UpdateVertex(VF, d); | |
712 | ||
713 | // P1 = BT.Pnt(VL); | |
714 | P1 = BRep_Tool::Pnt(VL); | |
715 | C3d->D0(l, P); | |
716 | d = P2.Distance(P); | |
717 | if (d > Tol2) | |
718 | B.UpdateVertex(VL, d); | |
719 | ||
720 | BRepLib_MakeEdge MkE (C3d, VF, VL, f, l); | |
0d969553 | 721 | if (!MkE.IsDone()) { // Error of construction !! |
7fd59977 | 722 | #ifdef DRAW |
723 | char name[100]; | |
724 | sprintf(name,"firstvertex_error"); | |
725 | DBRep::Set(name, VF); | |
726 | sprintf(name,"lastvertex_error"); | |
727 | DBRep::Set(name, VL); | |
728 | sprintf(name,"curve3d_error"); | |
729 | char* Temp = name ; | |
730 | DrawTrSurf::Set(Temp, C3d); | |
731 | // DrawTrSurf::Set(name, C3d); | |
732 | Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge"); | |
733 | #endif | |
734 | } | |
735 | ||
736 | E = MkE.Edge(); | |
737 | TopLoc_Location Loc; | |
738 | B.UpdateEdge(E, C2d, S, Loc, Tol3d); | |
739 | ||
740 | return E; | |
741 | } | |
742 | ||
743 | ||
744 | //======================================================================= | |
745 | //Fonction : Filling | |
0d969553 | 746 | //Objet : Construct the faces of filling |
7fd59977 | 747 | //======================================================================= |
748 | static Standard_Boolean Filling(const TopoDS_Shape& EF, | |
749 | const TopoDS_Shape& F1, | |
750 | const TopoDS_Shape& EL, | |
751 | const TopoDS_Shape& F2, | |
752 | TopTools_DataMapOfShapeShape& EEmap, | |
753 | const Standard_Real Tol, | |
754 | const gp_Ax2& Axe, | |
755 | const gp_Vec& TangentOnPart1, | |
756 | TopoDS_Edge& Aux1, | |
757 | TopoDS_Edge& Aux2, | |
758 | TopoDS_Face& Result) | |
759 | { | |
760 | BRep_Builder B; | |
761 | // Class BRep_Tool without fields and without Constructor : | |
762 | // BRep_Tool BT; | |
763 | // Standard_Integer NbInt =0; | |
764 | // Standard_Real Tol3d = Tol; | |
765 | Standard_Boolean WithE3, WithE4; | |
766 | ||
0d969553 | 767 | // Return constraints |
7fd59977 | 768 | TopoDS_Vertex V1, V2, Vf, Vl; |
769 | TopoDS_Edge E1, E2, E3, E4; | |
770 | E1 = TopoDS::Edge(EF); | |
771 | E2 = TopoDS::Edge(EL); | |
772 | ||
773 | TopExp::Vertices(E1, Vf, Vl); | |
774 | Vf.Orientation(TopAbs_FORWARD); | |
775 | Vl.Orientation(TopAbs_FORWARD); | |
776 | ||
777 | TopExp::Vertices(E2, V1, V2); | |
778 | V1.Orientation(TopAbs_REVERSED); | |
779 | V2.Orientation(TopAbs_REVERSED); | |
780 | ||
781 | B.MakeEdge(E3); | |
782 | B.MakeEdge(E4); | |
783 | ||
784 | WithE3 = WithE4 = Standard_False; | |
785 | ||
786 | if ((!Aux1.IsNull()) && (!Vf.IsSame(V1))) { | |
787 | E3 = Aux1; | |
788 | // E3 = TopoDS::Edge(Aux1); | |
789 | WithE3 = Standard_True; | |
790 | } | |
791 | ||
792 | if (Vf.IsSame(Vl)) { | |
793 | E4 = E3; | |
794 | E4.Reverse(); | |
795 | WithE4 = WithE3; | |
796 | } | |
797 | else if (!Aux2.IsNull() && (!Vl.IsSame(V2))) { | |
798 | E4 = Aux2; | |
799 | // E4 = TopoDS::Edge(Aux2); | |
800 | WithE4 = Standard_True; | |
801 | } | |
802 | ||
803 | #if DRAW | |
804 | if (Affich) { | |
805 | DBRep::Set("Fill_Edge1", E1); | |
806 | DBRep::Set("Fill_Edge2", E2); | |
807 | if (!E3.IsNull()) | |
808 | DBRep::Set("Fill_Edge3", E3); | |
809 | if (!E4.IsNull()) | |
810 | DBRep::Set("Fill_Edge4", E4); | |
811 | } | |
812 | #endif | |
813 | ||
0d969553 | 814 | // Construction of a surface of revolution |
7fd59977 | 815 | Handle(Geom_Curve) Prof1, Prof2; |
816 | //Standard_Integer ii, jj;//, Nb; | |
817 | Standard_Real f1, f2, l1, l2,/*d1, d2,*/ Angle;//, Eps = 1.e-9; | |
818 | // Prof1 = BT.Curve(E1, f1, l1); | |
819 | Prof1 = BRep_Tool::Curve(E1, f1, l1); | |
820 | // Prof2 = BT.Curve(E2, f2, l2); | |
821 | Prof2 = BRep_Tool::Curve(E2, f2, l2); | |
822 | gp_Pnt P1, P2, P; | |
823 | gp_Pnt2d p1, p2; | |
824 | gp_Trsf Tf; | |
825 | Tf.SetTransformation(Axe); | |
826 | ||
0d969553 | 827 | // Choose the angle of opening |
7fd59977 | 828 | P1 = Prof1->Value((f1+l1)/2); |
829 | P2 = Prof2->Value((f2+l2)/2); | |
830 | P1.Transform(Tf); | |
831 | P2.Transform(Tf); | |
832 | p1.SetCoord(P1.Z(), P1.X()); | |
833 | p2.SetCoord(P2.Z(), P2.X()); | |
834 | gp_Vec2d v1(gp::Origin2d(), p1); | |
835 | gp_Vec2d v2(gp::Origin2d(), p2); | |
836 | if (v1.Magnitude() <= gp::Resolution() || | |
837 | v2.Magnitude() <= gp::Resolution()) | |
838 | return Standard_False; | |
839 | Angle = v1.Angle(v2); | |
840 | ||
841 | gp_Ax1 axe(Axe.Location(), Axe.YDirection()); | |
842 | ||
843 | if (Angle < 0) { | |
844 | Angle = -Angle; | |
845 | axe.Reverse(); | |
846 | } | |
847 | ||
848 | Handle(Geom_SurfaceOfRevolution) Rev = | |
849 | new (Geom_SurfaceOfRevolution) (Prof1, axe); | |
850 | ||
851 | Handle(Geom_Surface) Surf = | |
852 | new (Geom_RectangularTrimmedSurface) (Rev, 0, Angle, f1, l1); | |
853 | ||
0d969553 | 854 | // Control the direction of the rotation |
7fd59977 | 855 | Standard_Boolean ToReverseResult = Standard_False; |
856 | gp_Vec d1u; | |
857 | d1u = Surf->DN(0, (f1+l1)/2, 1, 0); | |
c6541a0c | 858 | if (d1u.Angle(TangentOnPart1) > M_PI/2) { //Invert everything |
7fd59977 | 859 | ToReverseResult = Standard_True; |
860 | /* | |
861 | axe.Reverse(); | |
c6541a0c | 862 | Angle = 2*M_PI - Angle; |
7fd59977 | 863 | Rev = new (Geom_SurfaceOfRevolution) (Prof1, axe); |
864 | Surf = new (Geom_RectangularTrimmedSurface) | |
865 | (Rev, 0, Angle, f1, l1); | |
866 | */ | |
867 | } | |
868 | ||
869 | #if DRAW | |
870 | if (Affich) { | |
871 | char* Temp = "Surf_Init" ; | |
872 | DrawTrSurf::Set(Temp, Surf); | |
873 | } | |
874 | #endif | |
875 | ||
876 | Handle(Geom2d_Curve) C1, C2, C3, C4; | |
877 | /* | |
0d969553 | 878 | // Deform the surface of revolution. |
7fd59977 | 879 | GeomPlate_BuildPlateSurface BPS; |
880 | ||
881 | Handle(BRepAdaptor_HSurface) AS; | |
882 | Handle(BRepAdaptor_HCurve2d) AC2d; | |
883 | Handle(Adaptor3d_HCurveOnSurface) HConS; | |
884 | */ | |
885 | Handle(Geom2d_Line) L; | |
886 | gp_Pnt2d P2d(0.,0.); | |
887 | ||
888 | L = new (Geom2d_Line) (P2d, gp::DY2d()); | |
889 | C1 = new (Geom2d_TrimmedCurve) (L, f1, l1); | |
890 | ||
891 | P2d.SetCoord(Angle,0.); | |
892 | L = new (Geom2d_Line) (P2d, gp::DY2d()); | |
893 | C2 = new (Geom2d_TrimmedCurve) (L, f1, l1); | |
894 | ||
0d969553 | 895 | // It is required to control the direction and the range. |
7fd59977 | 896 | C2->D0(f1, P2d); |
897 | Surf->D0(P2d.X(), P2d.Y(), P1); | |
898 | C2->D0(l1, P2d); | |
899 | Surf->D0(P2d.X(), P2d.Y(), P2); | |
900 | // P = BT.Pnt(V1); | |
901 | P = BRep_Tool::Pnt(V1); | |
902 | if (P.Distance(P2)+Tol < P.Distance(P1)) { | |
0d969553 | 903 | // E2 is parsed in the direction opposite to E1 |
7fd59977 | 904 | C2->Reverse(); |
905 | TopoDS_Vertex aux; | |
906 | aux = V2; | |
907 | V2 = V1; | |
908 | V1 = aux; | |
909 | } | |
910 | GeomLib::SameRange(Precision::PConfusion(), C2, | |
911 | C2->FirstParameter(), | |
912 | C2->LastParameter(), | |
913 | f2, l2, C3); | |
914 | C2 = C3; | |
915 | ||
916 | Standard_Boolean pointu_f, pointu_l; | |
917 | // P1 = BT.Pnt(Vf); | |
918 | P1 = BRep_Tool::Pnt(Vf); | |
919 | // P2 = BT.Pnt(V1); | |
920 | P2 = BRep_Tool::Pnt(V1); | |
921 | // pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BT.Tolerance(Vf)); | |
922 | pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BRep_Tool::Tolerance(Vf)); | |
923 | // P1 = BT.Pnt(Vl); | |
924 | P1 = BRep_Tool::Pnt(Vl); | |
925 | // P2 = BT.Pnt(V2); | |
926 | P2 = BRep_Tool::Pnt(V2); | |
927 | // pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BT.Tolerance(Vl)); | |
928 | pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BRep_Tool::Tolerance(Vl)); | |
929 | ||
930 | ||
931 | P2d.SetCoord(0.,f1); | |
932 | L = new (Geom2d_Line) (P2d, gp::DX2d()); | |
933 | C3 = new (Geom2d_TrimmedCurve) (L, 0, Angle); | |
934 | ||
935 | ||
936 | P2d.SetCoord(0.,l1); | |
937 | L = new (Geom2d_Line) (P2d, gp::DX2d()); | |
938 | C4 = new (Geom2d_TrimmedCurve) (L, 0, Angle); | |
939 | /* | |
0d969553 Y |
940 | // Determine the constraints and |
941 | // their parametric localisation. | |
7fd59977 | 942 | if (!E1.IsNull()) { |
943 | AS = new BRepAdaptor_HSurface(TopoDS::Face(F1)); | |
944 | AC2d = new BRepAdaptor_HCurve2d(); | |
945 | AC2d->ChangeCurve2d().Initialize(E1,TopoDS::Face(F1)); | |
946 | HConS = new (Adaptor3d_HCurveOnSurface)(); | |
947 | HConS->ChangeCurve().Load(AC2d); | |
948 | HConS->ChangeCurve().Load(AS); | |
949 | ||
950 | Handle(BRepFill_CurveConstraint) Cont | |
951 | = new BRepFill_CurveConstraint(HConS, 1, 15); | |
952 | Cont->SetCurve2dOnSurf(C1); | |
953 | ||
954 | BPS.Add(Cont); | |
955 | NbInt = HConS->NbIntervals(GeomAbs_CN); | |
956 | } | |
957 | ||
958 | if (!E2.IsNull()) { | |
959 | AS = new BRepAdaptor_HSurface(TopoDS::Face(F2)); | |
960 | AC2d = new BRepAdaptor_HCurve2d(); | |
961 | AC2d->ChangeCurve2d().Initialize(E2,TopoDS::Face(F2)); | |
962 | HConS = new (Adaptor3d_HCurveOnSurface); | |
963 | ||
964 | HConS->ChangeCurve().Load(AC2d); | |
965 | HConS->ChangeCurve().Load(AS); | |
966 | ||
967 | Handle(BRepFill_CurveConstraint) Cont | |
968 | = new BRepFill_CurveConstraint(HConS, 1, 15); | |
969 | Cont->SetCurve2dOnSurf(C2); | |
970 | BPS.Add(Cont); | |
971 | } | |
972 | ||
973 | if (WithE3) { | |
974 | Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E3); | |
975 | Handle(BRepFill_CurveConstraint) Cont | |
976 | = new BRepFill_CurveConstraint(AC, 0); | |
977 | Cont->SetCurve2dOnSurf(C3); | |
978 | BPS.Add(Cont); | |
979 | } | |
980 | else if (pointu_f) { | |
981 | Standard_Real delta = Angle / 11; | |
982 | // P = BT.Pnt(Vf); | |
983 | P = BRep_Tool::Pnt(Vf); | |
984 | Handle(GeomPlate_PointConstraint) PC; | |
985 | for (ii=1; ii<=10; ii++) { | |
986 | C3->D0(ii*delta, P2d); | |
987 | PC = new (GeomPlate_PointConstraint) (P, 0); | |
988 | PC->SetPnt2dOnSurf(P2d); | |
989 | BPS.Add(PC); | |
990 | } | |
991 | } | |
992 | ||
993 | ||
994 | if (WithE4) { | |
995 | Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E4); | |
996 | Handle(BRepFill_CurveConstraint) Cont | |
997 | = new BRepFill_CurveConstraint(AC, 0); | |
998 | Cont->SetCurve2dOnSurf(C4); | |
999 | BPS.Add(Cont); | |
1000 | } | |
1001 | else if (pointu_l) { | |
1002 | Standard_Real delta = Angle / 11; | |
1003 | // P = BT.Pnt(Vl); | |
1004 | P = BRep_Tool::Pnt(Vl); | |
1005 | Handle(GeomPlate_PointConstraint) PC; | |
1006 | for (ii=1; ii<=10; ii++) { | |
1007 | C4->D0(ii*delta, P2d); | |
1008 | PC = new (GeomPlate_PointConstraint) (P, 0); | |
1009 | PC->SetPnt2dOnSurf(P2d); | |
1010 | BPS.Add(PC); | |
1011 | } | |
1012 | } | |
1013 | ||
1014 | BPS.LoadInitSurface(Surf); | |
1015 | BPS.Perform(); | |
1016 | ||
1017 | // Controle s'il y a une deformation effective | |
1018 | Handle(GeomPlate_Surface) plate; | |
1019 | plate = BPS.Surface(); | |
1020 | plate->SetBounds(0, Angle, f1, l1); | |
1021 | Standard_Boolean Ok=Standard_True; | |
1022 | Standard_Real u, v; | |
1023 | d1 = (l1-f1)/5; | |
1024 | d2 = Angle/5; | |
1025 | for (ii=0; ii<=5 && Ok; ii++) { | |
1026 | u = f1 + ii*d1; | |
1027 | for (jj=0; jj<=5 && Ok; jj++) { | |
1028 | v = jj*d2; | |
1029 | plate->D0(u, v, P1); | |
1030 | Surf->D0(u, v, P2); | |
1031 | Ok = (P2.IsEqual(P1, Tol)); | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | ||
1036 | if (!Ok) { | |
1037 | // Approx de la plate surface | |
1038 | // Bords naturelles => pas besoin de criteres. | |
1039 | GeomConvert_ApproxSurface App(BPS.Surface(), | |
1040 | Tol3d, | |
1041 | GeomAbs_C1, GeomAbs_C1, | |
1042 | 8, 8, 2*NbInt, 0); | |
1043 | if (!App.HasResult()) { | |
1044 | #if DEB | |
1045 | cout << "Filling_Approx : Pas de resultat" << endl; | |
1046 | #endif | |
1047 | return Standard_False; | |
1048 | } | |
1049 | #if DEB | |
1050 | cout << "Filling_Approx Error 3d = " << | |
1051 | App.MaxError() << endl; | |
1052 | #endif | |
1053 | Surf = App.Surface(); | |
1054 | Tol3d = App.MaxError(); | |
1055 | } | |
1056 | */ | |
1057 | ||
1058 | // Update des Edges | |
1059 | TopLoc_Location Loc; | |
1060 | Handle(Geom_Curve) C3d; | |
1061 | B.UpdateEdge(E1, C1, Surf, Loc, /*Tol3d*/Precision::Confusion()); | |
1062 | B.UpdateEdge(E2, C2, Surf, Loc, /*Tol3d*/Precision::Confusion()); | |
1063 | ||
1064 | if (E3.IsSame(E4)) { | |
1065 | if (!WithE3) | |
1066 | { | |
1067 | C3d = Surf->VIso(f1); | |
1068 | E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion()); | |
1069 | } | |
1070 | else | |
1071 | { | |
1072 | BRepAdaptor_Curve aCurve(E3); | |
1073 | Standard_Real AngleOld = aCurve.LastParameter(); | |
1074 | if (Angle > AngleOld) | |
1075 | { | |
1076 | B.Range( E3, 0, Angle ); | |
1077 | TopoDS_Vertex V (TopExp::LastVertex(E3)); | |
1078 | Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape()); | |
1079 | TVlast->Tolerance( Precision::Confusion() ); | |
1080 | } | |
1081 | } | |
1082 | ||
1083 | B.UpdateEdge(E3, C3, C4, Surf, Loc, /*Tol3d*/Precision::Confusion()); | |
1084 | E4 = E3; | |
1085 | E4.Reverse(); | |
1086 | } | |
1087 | else { | |
1088 | if (!WithE3) | |
1089 | { | |
1090 | C3d = Surf->VIso(f1); | |
1091 | E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion()); | |
1092 | } | |
1093 | else | |
1094 | { | |
1095 | BRepAdaptor_Curve aCurve(E3); | |
1096 | Standard_Real AngleOld = aCurve.LastParameter(); | |
1097 | if (Angle > AngleOld) | |
1098 | { | |
1099 | B.Range( E3, 0, Angle ); | |
1100 | TopoDS_Vertex V(TopExp::LastVertex(E3)); | |
1101 | Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape()); | |
1102 | TVlast->Tolerance( Precision::Confusion() ); | |
1103 | } | |
1104 | ||
1105 | B.UpdateEdge(E3, C3, Surf, Loc, /*Tol3d*/Precision::Confusion()); | |
1106 | } | |
1107 | ||
1108 | if (!WithE4) | |
1109 | { | |
1110 | C3d = Surf->VIso(l1); | |
1111 | E4 = BuildEdge(C3d, C4, Surf, Vl, V2, 0, Angle, /*Tol3d*/Precision::Confusion()); | |
1112 | } | |
1113 | else | |
1114 | { | |
1115 | BRepAdaptor_Curve aCurve(E4); | |
1116 | Standard_Real AngleOld = aCurve.LastParameter(); | |
1117 | if (Angle > AngleOld) | |
1118 | { | |
1119 | B.Range( E4, 0, Angle ); | |
1120 | TopoDS_Vertex V (TopExp::LastVertex(E4)); | |
1121 | Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*)&V.TShape()); | |
1122 | TVlast->Tolerance( Precision::Confusion() ); | |
1123 | } | |
1124 | ||
1125 | B.UpdateEdge(E4, C4, Surf, Loc, /*Tol3d*/Precision::Confusion()); | |
1126 | } | |
1127 | } | |
1128 | ||
0d969553 | 1129 | //Construct face |
7fd59977 | 1130 | BuildFace(Surf,E1, E3, E2, E4, EEmap, |
1131 | Standard_False, Standard_False, | |
1132 | Result); | |
1133 | ||
0d969553 | 1134 | // Set the continuities. |
7fd59977 | 1135 | B.Continuity(E1, TopoDS::Face(F1), Result, GeomAbs_G1); |
1136 | B.Continuity(E2, TopoDS::Face(F2), Result, GeomAbs_G1); | |
1137 | ||
0d969553 | 1138 | // Render the calculated borders. |
7fd59977 | 1139 | // if (!BT.Degenerated(E3)) |
1140 | if (!BRep_Tool::Degenerated(E3)) | |
1141 | Aux1 = E3; | |
1142 | else | |
1143 | B.MakeEdge(Aux1); //Nullify | |
1144 | ||
1145 | // if (!BT.Degenerated(E4)) | |
1146 | if (!BRep_Tool::Degenerated(E4)) | |
1147 | Aux2 = E4; | |
1148 | else | |
1149 | B.MakeEdge(Aux2); | |
1150 | ||
0d969553 | 1151 | // Set the orientation |
7fd59977 | 1152 | gp_Vec D1U, D1V, N1, N2; |
1153 | C1->D0( (f1+l1)/2, P2d); | |
1154 | Surf->D1(P2d.X(), P2d.Y(), P, D1U, D1V); | |
1155 | N1 = D1U^D1V; | |
1156 | ||
1157 | // C1 = BT.CurveOnSurface(E1, TopoDS::Face(F1), f2, l2); | |
1158 | C1 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(F1), f2, l2); | |
1159 | C1->D0( (f1+l1)/2, P2d); | |
1160 | Handle(BRepAdaptor_HSurface) AS = new BRepAdaptor_HSurface(TopoDS::Face(F1)); | |
1161 | AS->D1(P2d.X(), P2d.Y(), P, D1U, D1V); | |
1162 | N2 = D1U^D1V; | |
1163 | ||
c6541a0c | 1164 | if ( (F1.Orientation() == TopAbs_REVERSED) ^ (N1.Angle(N2)>M_PI/2) ) |
7fd59977 | 1165 | Result.Orientation(TopAbs_REVERSED); |
1166 | else Result.Orientation(TopAbs_FORWARD); | |
1167 | ||
1168 | if (ToReverseResult) | |
1169 | Result.Reverse(); | |
1170 | ||
1171 | #if DRAW | |
1172 | if (Affich) DBRep::Set("BoucheTrou", Result); | |
1173 | #endif | |
1174 | ||
1175 | return Standard_True; | |
1176 | } | |
1177 | ||
1178 | //======================================================================= | |
1179 | //function : Substitute | |
1180 | //purpose : | |
1181 | //======================================================================= | |
1182 | static void Substitute(BRepTools_Substitution& aSubstitute, | |
1183 | const TopoDS_Edge& Old, | |
1184 | const TopoDS_Edge& New) | |
1185 | { | |
1186 | TopTools_ListOfShape listShape; | |
1187 | ||
1188 | TopoDS_Vertex OldV1, OldV2, NewV1, NewV2; | |
1189 | TopExp::Vertices( Old, OldV1, OldV2 ); | |
1190 | TopExp::Vertices( New, NewV1, NewV2 ); | |
1191 | ||
1192 | if (!aSubstitute.IsCopied( OldV1 )) | |
1193 | { | |
1194 | listShape.Append( NewV1.Oriented(TopAbs_FORWARD) ); | |
1195 | aSubstitute.Substitute( OldV1, listShape ); | |
1196 | listShape.Clear(); | |
1197 | } | |
1198 | if (!aSubstitute.IsCopied( OldV2 )) | |
1199 | { | |
1200 | listShape.Append( NewV2.Oriented(TopAbs_FORWARD) ); | |
1201 | aSubstitute.Substitute( OldV2, listShape ); | |
1202 | listShape.Clear(); | |
1203 | } | |
1204 | if (!aSubstitute.IsCopied( Old )) | |
1205 | { | |
1206 | listShape.Append( New.Oriented(TopAbs_FORWARD) ); | |
1207 | aSubstitute.Substitute( Old, listShape ); | |
1208 | } | |
1209 | } | |
1210 | ||
1211 | //======================================================================= | |
1212 | //Function : SetCommonEdgeInFace | |
0d969553 | 1213 | //Purpose : Replace an edge of the face by the corresponding edge from |
7fd59977 | 1214 | // myUEdges |
1215 | //======================================================================= | |
1216 | /* | |
1217 | static void SetCommonEdgeInFace(BRepTools_Substitution& aSubstitute, | |
1218 | const TopoDS_Shape& Face, | |
1219 | const TopoDS_Shape& Edge) | |
1220 | { | |
1221 | if (Edge.IsNull()) | |
1222 | return; | |
1223 | ||
1224 | Standard_Boolean done = Standard_False; | |
1225 | // Class BRep_Tool without fields and without Constructor : | |
1226 | // BRep_Tool BT; | |
1227 | Standard_Real f, l; | |
1228 | TopExp_Explorer Exp(Face, TopAbs_EDGE); | |
1229 | Handle(Geom_Curve) Cref, C; | |
1230 | TopLoc_Location Lref, L; | |
1231 | // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l); | |
1232 | const TopoDS_Edge& NewEdge = TopoDS::Edge(Edge); | |
1233 | Cref = BRep_Tool::Curve( NewEdge, Lref, f, l ); | |
1234 | ||
1235 | for ( ; Exp.More() && !done; Exp.Next()) { | |
1236 | // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l); | |
1237 | const TopoDS_Edge& OldEdge = TopoDS::Edge(Exp.Current()); | |
1238 | C = BRep_Tool::Curve(OldEdge, L, f, l); | |
1239 | if ((Cref==C) && (Lref == L)) { | |
1240 | done = Standard_True; | |
1241 | Substitute( aSubstitute, OldEdge, NewEdge ); | |
1242 | } | |
1243 | } | |
1244 | #if DEB | |
1245 | if (!done) cout << "Substitution of Edge failed" << endl; | |
1246 | #endif | |
1247 | } | |
1248 | */ | |
1249 | ||
1250 | //======================================================================= | |
1251 | //Fonction : KeepEdge | |
0d969553 | 1252 | //Objet : Find edges of the face supported by the same Curve. |
7fd59977 | 1253 | //======================================================================= |
1254 | static void KeepEdge(const TopoDS_Shape& Face, | |
1255 | const TopoDS_Shape& Edge, | |
1256 | TopTools_ListOfShape& List) | |
1257 | { | |
1258 | List.Clear(); | |
1259 | // Class BRep_Tool without fields and without Constructor : | |
1260 | // BRep_Tool BT; | |
1261 | Standard_Real f, l; | |
1262 | TopExp_Explorer Exp(Face, TopAbs_EDGE); | |
1263 | Handle(Geom_Curve) Cref, C; | |
1264 | TopLoc_Location Lref, L; | |
1265 | // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l); | |
1266 | Cref = BRep_Tool::Curve(TopoDS::Edge(Edge), Lref, f, l); | |
1267 | ||
1268 | for ( ; Exp.More(); Exp.Next()) { | |
1269 | // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l); | |
1270 | C = BRep_Tool::Curve(TopoDS::Edge(Exp.Current()), L, f, l); | |
1271 | if ((Cref==C) && (Lref == L)) { | |
1272 | List.Append(Exp.Current()); | |
1273 | } | |
1274 | } | |
1275 | } | |
1276 | ||
1277 | //======================================================================= | |
1278 | //Function : | |
0d969553 | 1279 | //Objet : Construct a vertex via an iso |
7fd59977 | 1280 | //======================================================================= |
1281 | static void BuildVertex(const Handle(Geom_Curve)& Iso, | |
1282 | const Standard_Boolean isfirst, | |
1283 | const Standard_Real First, | |
1284 | const Standard_Real Last, | |
1285 | TopoDS_Shape& Vertex) | |
1286 | { | |
1287 | BRep_Builder B; | |
1288 | Standard_Real val; | |
1289 | ||
1290 | if (isfirst) val = First; | |
1291 | else val = Last; | |
1292 | B.MakeVertex(TopoDS::Vertex(Vertex), | |
1293 | Iso->Value(val), | |
1294 | Precision::Confusion()); | |
1295 | } | |
1296 | ||
1297 | //======================================================================= | |
1298 | //Function : | |
0d969553 | 1299 | //Objet : Construct an empty edge |
7fd59977 | 1300 | //======================================================================= |
1301 | static TopoDS_Edge NullEdge(TopoDS_Shape& Vertex) | |
1302 | { | |
1303 | TopoDS_Edge E; | |
1304 | BRep_Builder B; | |
1305 | B.MakeEdge(E); | |
1306 | Vertex.Orientation(TopAbs_FORWARD); | |
1307 | B.Add(E, Vertex); | |
1308 | B.Add(E, Vertex.Reversed()); | |
1309 | B.Degenerated(E, Standard_True); | |
1310 | return E; | |
1311 | ||
1312 | } | |
1313 | ||
1314 | //======================================================================= | |
1315 | //Function : | |
0d969553 | 1316 | //Objet : Construct an edge via an iso |
7fd59977 | 1317 | //======================================================================= |
1318 | static TopoDS_Edge BuildEdge(const Handle(Geom_Surface)& S, | |
1319 | const Standard_Boolean isUiso, | |
1320 | const Standard_Real ValIso, | |
1321 | const TopoDS_Shape& VFirst, | |
1322 | const TopoDS_Shape& VLast, | |
1323 | const Standard_Real Tol) | |
1324 | { | |
1325 | TopoDS_Edge E; | |
1326 | BRep_Builder B; | |
1327 | Handle(Geom_Curve) Iso; | |
1328 | Standard_Boolean sing = Standard_False; | |
1329 | if (isUiso) { | |
1330 | Iso = S->UIso(ValIso); | |
1331 | } | |
1332 | else { | |
1333 | Iso = S->VIso(ValIso); | |
1334 | } | |
1335 | ||
0d969553 | 1336 | if (VFirst.IsSame(VLast)) { // Singular case ? |
7fd59977 | 1337 | gp_Pnt P; |
1338 | // Class BRep_Tool without fields and without Constructor : | |
1339 | // BRep_Tool BT; | |
1340 | const TopoDS_Vertex& V = TopoDS::Vertex(VFirst); | |
1341 | // Standard_Real tol = BT.Tolerance(V); | |
1342 | Standard_Real tol = BRep_Tool::Tolerance(V); | |
1343 | if (Tol > tol) tol = Tol; | |
1344 | Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, P); | |
1345 | // if (P.Distance(BT.Pnt(V)) < tol) { | |
1346 | if (P.Distance(BRep_Tool::Pnt(V)) < tol) { | |
1347 | GeomAdaptor_Curve AC(Iso); | |
1348 | sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol; | |
1349 | } | |
1350 | } | |
1351 | ||
1352 | ||
0d969553 | 1353 | if (sing) { // Singular case |
7fd59977 | 1354 | TopoDS_Shape V; |
1355 | V = VFirst; | |
1356 | E = NullEdge(V); | |
1357 | // Iso.Nullify(); | |
1358 | // B.UpdateEdge(E, Iso, Precision::Confusion()); | |
1359 | B.Degenerated(E, Standard_True); | |
1360 | } | |
1361 | ||
1362 | else { | |
0d969553 | 1363 | // Construction Via 3d |
7fd59977 | 1364 | // if (isUiso) { |
1365 | // Iso = S->UIso(ValIso); | |
1366 | gp_Pnt P1,P2; | |
1367 | Standard_Real p1, p2, p11, p12, p21, p22; | |
1368 | Standard_Boolean fwd = Standard_False; | |
1369 | p1 = Iso->FirstParameter(); | |
1370 | p2 = Iso->LastParameter(); | |
1371 | P1 = Iso->Value(p1); | |
1372 | P2 = Iso->Value(p2); | |
1373 | ||
1374 | Standard_Real t1 = BRep_Tool::Tolerance(TopoDS::Vertex(VFirst)); | |
1375 | Standard_Real t2 = BRep_Tool::Tolerance(TopoDS::Vertex(VLast)); | |
1376 | ||
1377 | BRep_Builder BB; | |
1378 | ||
1379 | p11 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst))); | |
1380 | p22 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast))); | |
1381 | p12 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast))); | |
1382 | p21 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst))); | |
1383 | ||
1384 | if(p11 < p12 && p22 < p21) fwd = Standard_True; | |
1385 | ||
1386 | if(fwd) { //OCC500(apo) | |
1387 | if (p11 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p11); | |
1388 | if (p22 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p22); | |
1389 | } | |
1390 | else { | |
1391 | // Iso = S->VIso(ValIso); | |
1392 | if (p12 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p12); | |
1393 | if (p21 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p21); | |
1394 | } | |
1395 | ||
1396 | BRepLib_MakeEdge MkE; | |
1397 | ||
1398 | // MkE.Init(Iso, | |
1399 | // TopoDS::Vertex(VFirst), | |
1400 | // TopoDS::Vertex(VLast), | |
1401 | // Iso->FirstParameter(), | |
1402 | // Iso->LastParameter()); | |
1403 | if(fwd) | |
1404 | MkE.Init(Iso, | |
1405 | TopoDS::Vertex(VFirst), | |
1406 | TopoDS::Vertex(VLast), | |
1407 | Iso->FirstParameter(), | |
1408 | Iso->LastParameter()); | |
1409 | else | |
1410 | MkE.Init(Iso, | |
1411 | TopoDS::Vertex(VLast), | |
1412 | TopoDS::Vertex(VFirst), | |
1413 | Iso->FirstParameter(), | |
1414 | Iso->LastParameter()); | |
1415 | ||
1416 | // if (!MkE.IsDone()) { // Il faut peut etre permuter les Vertex | |
1417 | // MkE.Init(Iso, | |
1418 | // TopoDS::Vertex(VLast), | |
1419 | // TopoDS::Vertex(VFirst), | |
1420 | // Iso->FirstParameter(), | |
1421 | // Iso->LastParameter()); | |
1422 | // } | |
1423 | ||
1424 | if (!MkE.IsDone()) { // Erreur de construction !! | |
1425 | #ifdef DRAW | |
1426 | char name[100]; | |
1427 | sprintf(name,"firstvertex_error"); | |
1428 | DBRep::Set(name, VFirst); | |
1429 | sprintf(name,"lastvertex_error"); | |
1430 | DBRep::Set(name, VLast); | |
1431 | sprintf(name,"curve3d_error"); | |
1432 | char* Temp = name ; | |
1433 | DrawTrSurf::Set(Temp,Iso); | |
1434 | // DrawTrSurf::Set(name,Iso); | |
1435 | #endif | |
1436 | Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge"); | |
1437 | } | |
1438 | ||
1439 | E = MkE.Edge(); | |
1440 | } | |
1441 | ||
0d969553 | 1442 | // Associate 2d |
7fd59977 | 1443 | Handle(Geom2d_Line) L; |
1444 | TopLoc_Location Loc; | |
1445 | if (isUiso) { | |
1446 | gp_Pnt2d P(ValIso, 0); | |
1447 | gp_Vec2d V(0., 1.); | |
1448 | L = new (Geom2d_Line) (P, V); | |
1449 | } | |
1450 | else { | |
1451 | gp_Pnt2d P(0., ValIso); | |
1452 | gp_Vec2d V(1., 0.); | |
1453 | L = new (Geom2d_Line) (P, V); | |
1454 | } | |
1455 | ||
1456 | B.UpdateEdge(E, L, S, Loc, Precision::Confusion()); | |
1457 | if (sing) B.Range(E, S, Loc, | |
1458 | Iso->FirstParameter(), | |
1459 | Iso->LastParameter()); | |
1460 | ||
471ce736 | 1461 | Standard_Real MaxTol = 1.e-4; |
1462 | Standard_Real theTol; | |
1463 | GeomAdaptor_Curve GAiso(Iso); | |
1464 | Handle(GeomAdaptor_HCurve) GAHiso = new GeomAdaptor_HCurve(GAiso); | |
1465 | GeomAdaptor_Surface GAsurf(S); | |
1466 | Handle(GeomAdaptor_HSurface) GAHsurf = new GeomAdaptor_HSurface(GAsurf); | |
1467 | CheckSameParameter( GAHiso, L, GAHsurf, MaxTol, theTol); | |
1468 | B.UpdateEdge(E, theTol); | |
1469 | ||
7fd59977 | 1470 | return E; |
1471 | } | |
1472 | ||
1473 | //======================================================================= | |
1474 | //Function : | |
0d969553 | 1475 | //Objet : Complete an edge via an iso |
7fd59977 | 1476 | //======================================================================= |
1477 | static void UpdateEdge(TopoDS_Edge& E, | |
1478 | const Handle(Geom_Surface)& S, | |
1479 | const Standard_Boolean isUiso, | |
1480 | const Standard_Real ValIso) | |
1481 | { | |
1482 | BRep_Builder B; | |
1483 | Handle(Geom2d_Line) L; | |
1484 | Handle(Geom2d_Curve) PCurve, CL; | |
1485 | TopLoc_Location Loc; | |
1486 | Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d; | |
1487 | S->Bounds( UFirst, ULast, VFirst, VLast); | |
1488 | ||
1489 | Standard_Boolean sing = Standard_False; | |
1490 | Handle(Geom_Curve) Iso; | |
1491 | if (isUiso) { | |
1492 | Iso = S->UIso(ValIso); | |
1493 | } | |
1494 | else { | |
1495 | Iso = S->VIso(ValIso); | |
1496 | } | |
1497 | ||
1498 | TopoDS_Vertex Vf, Vl; | |
1499 | TopExp::Vertices(E, Vf, Vl); | |
0d969553 | 1500 | if (Vf.IsSame(Vl)) { // Singular case ? |
7fd59977 | 1501 | gp_Pnt Pmid; |
1502 | Standard_Real tol = BRep_Tool::Tolerance(Vf); | |
1503 | Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid); | |
1504 | if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) { | |
1505 | GeomAdaptor_Curve AC(Iso); | |
1506 | sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol; | |
1507 | } | |
1508 | } | |
1509 | ||
1510 | if (isUiso) { | |
1511 | gp_Pnt2d P(ValIso, 0); | |
1512 | gp_Vec2d V(0., 1.); | |
1513 | L = new (Geom2d_Line) (P, V); | |
1514 | F2d = VFirst; | |
1515 | L2d = VLast; | |
1516 | } | |
1517 | else { | |
1518 | gp_Pnt2d P(0., ValIso); | |
1519 | gp_Vec2d V(1., 0.); | |
1520 | L = new (Geom2d_Line) (P, V); | |
1521 | F2d = UFirst; | |
1522 | L2d = ULast; | |
1523 | } | |
1524 | CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d); | |
1525 | ||
0d969553 | 1526 | // Control direction & Range |
7fd59977 | 1527 | Standard_Real R, First, Last, Tol=1.e-4; |
1528 | Standard_Boolean reverse = Standard_False;; | |
1529 | ||
1530 | ||
1531 | // Class BRep_Tool without fields and without Constructor : | |
1532 | // BRep_Tool BT; | |
1533 | gp_Pnt POnS; | |
1534 | gp_Pnt2d P2d; | |
1535 | // BT.Range(E, First, Last); | |
1536 | BRep_Tool::Range(E, First, Last); | |
1537 | ||
1538 | if (!Vf.IsSame(Vl)) { | |
0d969553 | 1539 | // Test distances between "FirstPoint" and "Vertex" |
7fd59977 | 1540 | P2d = CL->Value(F2d); |
1541 | POnS = S->Value(P2d.X(), P2d.Y()); | |
1542 | // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf)); | |
1543 | reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf)); | |
1544 | } | |
1545 | else if (!sing) { | |
0d969553 | 1546 | // Test angle between "First Tangente" |
7fd59977 | 1547 | gp_Vec2d V2d; |
1548 | gp_Vec V3d, du, dv, dC3d; | |
1549 | BRepAdaptor_Curve C3d(E); | |
1550 | ||
1551 | C3d.D1(First, POnS, dC3d); | |
1552 | CL->D1(F2d, P2d, V2d); | |
1553 | S->D1(P2d.X(), P2d.Y(), POnS, du, dv); | |
1554 | V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv); | |
1555 | reverse = ( dC3d.Angle(V3d) > Tol); | |
1556 | } | |
0d969553 | 1557 | if (reverse ) { // Return curve 2d |
7fd59977 | 1558 | CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d); |
1559 | CL->Reverse(); | |
1560 | F2d = CL->FirstParameter(); | |
1561 | L2d = CL->LastParameter(); | |
1562 | } | |
1563 | ||
1564 | if (sing) | |
1565 | { | |
1566 | Handle(Geom_Curve) NullCurve; | |
1567 | B.UpdateEdge(E, NullCurve, 0.); | |
1568 | B.Degenerated(E, Standard_True); | |
1569 | B.Range(E, F2d, L2d); | |
1570 | First = F2d; | |
1571 | Last = L2d; | |
1572 | } | |
1573 | ||
1574 | if (First != F2d || Last != L2d) { | |
1575 | Handle(Geom2d_Curve) C2d; | |
1576 | GeomLib::SameRange(Precision::PConfusion(), CL, | |
1577 | F2d, L2d, First, Last, | |
1578 | C2d); | |
1579 | CL = new (Geom2d_TrimmedCurve)(C2d, First, Last); | |
1580 | } | |
1581 | ||
1582 | // Update des Vertex | |
1583 | ||
1584 | TopoDS_Vertex V; | |
1585 | ||
1586 | P2d = CL->Value(First); | |
1587 | POnS = S->Value(P2d.X(), P2d.Y()); | |
1588 | V = TopExp::FirstVertex(E); | |
1589 | // R = POnS.Distance(BT.Pnt(V)); | |
1590 | R = POnS.Distance(BRep_Tool::Pnt(V)); | |
1591 | B.UpdateVertex(V, R); | |
1592 | ||
1593 | P2d = CL->Value(Last); | |
1594 | POnS = S->Value(P2d.X(), P2d.Y()); | |
1595 | V = TopExp::LastVertex(E); | |
1596 | // R = POnS.Distance(BT.Pnt(V)); | |
1597 | R = POnS.Distance(BRep_Tool::Pnt(V)); | |
1598 | B.UpdateVertex(V, R); | |
1599 | ||
0d969553 | 1600 | // Update Edge |
7fd59977 | 1601 | if (!sing && SameParameter(E, CL, S, Tol, R)) { |
1602 | B.UpdateEdge(E, R); | |
1603 | } | |
1604 | ||
1605 | PCurve = Couture(E, S, Loc); | |
1606 | if (PCurve.IsNull()) | |
1607 | B.UpdateEdge(E, CL, S, Loc, Precision::Confusion()); | |
0d969553 | 1608 | else { // Sewing edge |
7fd59977 | 1609 | TopoDS_Edge e = E; |
1610 | Oriente(S, e); | |
1611 | if (e.Orientation() == TopAbs_REVERSED) | |
1612 | B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion()); | |
1613 | else | |
1614 | B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion()); | |
1615 | } | |
1616 | ||
0d969553 | 1617 | // Attention to case not SameRange on its shapes (PRO13551) |
7fd59977 | 1618 | // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last); |
1619 | if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last); | |
1620 | } | |
1621 | ||
1622 | //======================================================================= | |
0d969553 | 1623 | // Object : Check if a surface is degenerated |
7fd59977 | 1624 | //======================================================================= |
1625 | static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S, | |
1626 | const Standard_Real Tol) | |
1627 | { | |
1628 | Standard_Integer Nb = 5; | |
1629 | Standard_Boolean B = Standard_True; | |
1630 | Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l; | |
1631 | Standard_Integer ii; | |
1632 | Handle(Geom_Curve) Iso; | |
1633 | gp_Pnt P1,P2,P3; | |
1634 | GCPnts_AbscissaPoint GC; | |
1635 | ||
1636 | S->Bounds(Umin, Umax, Vmin, Vmax); | |
1637 | ||
0d969553 | 1638 | // Check the length of Iso-U |
7fd59977 | 1639 | t = (Umin + Umax)/2; |
1640 | S->D0(t, Vmin, P1); | |
1641 | S->D0(t, (Vmin+Vmax)/2, P2); | |
1642 | S->D0(t, Vmax, P3); | |
1643 | B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol); | |
1644 | ||
1645 | for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) { | |
1646 | t = Umin + ii*dt; | |
1647 | Iso = S->UIso(t); | |
1648 | GeomAdaptor_Curve AC(Iso); | |
1649 | l = GC.Length(AC, Tol/4); | |
1650 | B = (l <= Tol); | |
1651 | } | |
1652 | ||
1653 | if (B) return Standard_True; | |
1654 | ||
0d969553 | 1655 | // Check the length of Iso-V |
7fd59977 | 1656 | t = (Vmin + Vmax)/2; |
1657 | S->D0(Umin, t, P1); | |
1658 | S->D0((Umin+Umax)/2, t, P2); | |
1659 | S->D0(Umax, t, P3); | |
1660 | B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol); | |
1661 | ||
1662 | ||
1663 | for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) { | |
1664 | t = Vmin + ii*dt; | |
1665 | Iso = S->VIso(t); | |
1666 | GeomAdaptor_Curve AC(Iso); | |
1667 | l = GC.Length(AC, Tol/4); | |
1668 | B = (l <= Tol); | |
1669 | } | |
1670 | ||
1671 | return B; | |
1672 | } | |
1673 | ||
1674 | //======================================================================= | |
1675 | //function : Constructeur | |
1676 | //purpose : | |
1677 | //====================================================================== | |
1678 | BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section, | |
1679 | const Handle(BRepFill_LocationLaw)& Location, | |
1680 | const Standard_Boolean WithKPart) : | |
1681 | isDone(Standard_False), | |
1682 | KPart(WithKPart) | |
1683 | ||
1684 | ||
1685 | { | |
1686 | mySec = Section; | |
1687 | myLoc = Location; | |
1688 | ||
1689 | SetTolerance(1.e-4); | |
1690 | SetAngularControl(); | |
1691 | myAuxShape.Clear(); | |
1692 | ||
1693 | myApproxStyle = GeomFill_Location; | |
1694 | myContinuity = GeomAbs_C2; | |
1695 | myDegmax = 11; | |
1696 | mySegmax = 30; | |
a31abc03 | 1697 | myForceApproxC1 = Standard_False; |
7fd59977 | 1698 | } |
1699 | ||
1700 | //======================================================================= | |
1701 | //function : SetBounds | |
0d969553 | 1702 | //purpose : Define start and end shapes |
7fd59977 | 1703 | //====================================================================== |
1704 | void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First, | |
1705 | const TopoDS_Wire& Last) | |
1706 | { | |
1707 | FirstShape = First; | |
1708 | LastShape = Last; | |
1709 | ||
0d969553 | 1710 | // It is necessary to check the SameRange on its (PRO13551) |
7fd59977 | 1711 | Standard_Boolean issame = Standard_True; |
1712 | BRep_Builder B; | |
1713 | BRepTools_WireExplorer wexp; | |
1714 | if (!FirstShape.IsNull()) { | |
1715 | for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) { | |
1716 | if (!BRepLib::CheckSameRange(wexp.Current())) { | |
1717 | B.SameRange(wexp.Current(), Standard_False); | |
1718 | B.SameParameter(wexp.Current(), Standard_False); | |
1719 | issame = Standard_False; | |
1720 | } | |
1721 | } | |
1722 | } | |
1723 | ||
1724 | if (!LastShape.IsNull()) { | |
1725 | for (wexp.Init(LastShape); wexp.More(); wexp.Next()) { | |
1726 | if (!BRepLib::CheckSameRange(wexp.Current())) { | |
1727 | B.SameRange(wexp.Current(), Standard_False); | |
1728 | B.SameParameter(wexp.Current(), Standard_False); | |
1729 | issame = Standard_False; | |
1730 | } | |
1731 | } | |
1732 | } | |
1733 | ||
1734 | #if DEB | |
1735 | if (!issame) | |
0d969553 | 1736 | cout<<"Sweep Warning : Edge not SameRange in the limits"<<endl; |
7fd59977 | 1737 | #endif |
1738 | } | |
1739 | ||
1740 | //======================================================================= | |
1741 | //function : SetTolerance | |
1742 | //purpose : | |
1743 | //====================================================================== | |
1744 | void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d, | |
1745 | const Standard_Real BoundTol, | |
1746 | const Standard_Real Tol2d, | |
1747 | const Standard_Real TolAngular) | |
1748 | { | |
1749 | myTol3d = Tol3d; | |
1750 | myBoundTol = BoundTol; | |
1751 | myTol2d =Tol2d; | |
1752 | myTolAngular = TolAngular; | |
1753 | } | |
1754 | //======================================================================= | |
1755 | //function : SetAngularControl | |
1756 | //purpose : | |
1757 | //====================================================================== | |
1758 | void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle, | |
1759 | const Standard_Real MaxAngle) | |
1760 | { | |
1761 | myAngMin = Max (MinAngle, Precision::Angular()); | |
1762 | myAngMax = Min (MaxAngle, 6.28); | |
1763 | } | |
1764 | ||
a31abc03 | 1765 | //======================================================================= |
1766 | //function : SetForceApproxC1 | |
1767 | //purpose : Set the flag that indicates attempt to approximate | |
1768 | // a C1-continuous surface if a swept surface proved | |
1769 | // to be C0. | |
1770 | //======================================================================= | |
1771 | void BRepFill_Sweep::SetForceApproxC1(const Standard_Boolean ForceApproxC1) | |
1772 | { | |
1773 | myForceApproxC1 = ForceApproxC1; | |
1774 | } | |
1775 | ||
7fd59977 | 1776 | ///======================================================================= |
1777 | //function : CorrectApproxParameters | |
1778 | //purpose : | |
1779 | //======================================================================= | |
1780 | Standard_Boolean BRepFill_Sweep::CorrectApproxParameters() | |
1781 | { | |
1782 | TopoDS_Wire thePath = myLoc->Wire(); | |
1783 | GeomAbs_Shape NewCont = myContinuity; | |
1784 | Standard_Integer NewSegmax = mySegmax; | |
1785 | ||
1786 | TopoDS_Iterator iter(thePath); | |
1787 | for (; iter.More(); iter.Next()) | |
1788 | { | |
1789 | TopoDS_Edge anEdge = TopoDS::Edge(iter.Value()); | |
1790 | BRepAdaptor_Curve aBAcurve(anEdge); | |
1791 | GeomAbs_Shape aContinuity = aBAcurve.Continuity(); | |
1792 | Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN); | |
1793 | if (aContinuity < NewCont) | |
1794 | NewCont = aContinuity; | |
1795 | if (aNbInterv > NewSegmax) | |
1796 | NewSegmax = aNbInterv; | |
1797 | } | |
1798 | ||
1799 | Standard_Boolean Corrected = Standard_False; | |
1800 | if (NewCont != myContinuity || NewSegmax != mySegmax) | |
1801 | Corrected = Standard_True; | |
1802 | myContinuity = NewCont; | |
1803 | mySegmax = NewSegmax; | |
1804 | return Corrected; | |
1805 | } | |
1806 | ||
1807 | //======================================================================= | |
1808 | //function : BuildWire | |
0d969553 | 1809 | //purpose : Construit a wire by sweeping |
7fd59977 | 1810 | //====================================================================== |
1811 | Standard_Boolean BRepFill_Sweep:: | |
1812 | BuildWire(const BRepFill_TransitionStyle /*Transition*/) | |
1813 | { | |
1814 | Standard_Integer ipath, isec = 1; | |
1815 | gp_Pnt P1;//, P2; | |
1816 | ||
1817 | BRep_Builder B; | |
1818 | // Class BRep_Tool without fields and without Constructor : | |
1819 | // BRep_Tool BT; | |
1820 | Standard_Integer NbPath = myLoc->NbLaw(); | |
1821 | Standard_Boolean vclose; | |
1822 | vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0)); | |
1823 | Error = 0.; | |
1824 | Handle(Geom_Surface) S; | |
1825 | Handle(Geom_Curve) Iso; | |
1826 | Standard_Real val, bid, First, Last, Tol; | |
1827 | ||
1828 | TopoDS_Wire wire; | |
1829 | TopoDS_Edge E; | |
1830 | B.MakeWire(wire); | |
1831 | ||
0d969553 | 1832 | // (1) Construction of all curves |
7fd59977 | 1833 | |
0d969553 | 1834 | // (1.1) Construction of Tables |
7fd59977 | 1835 | myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath); |
1836 | myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath); | |
1837 | myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1); | |
1838 | ||
0d969553 | 1839 | // (1.2) Calculate curves / vertex / edge |
7fd59977 | 1840 | for (ipath=1; ipath <=NbPath; ipath++) { |
0d969553 | 1841 | // Curve by iso value |
7fd59977 | 1842 | GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart); |
1843 | Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular); | |
a31abc03 | 1844 | Sweep.SetForceApproxC1(myForceApproxC1); |
7fd59977 | 1845 | Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax); |
1846 | if (!Sweep.IsDone()) | |
1847 | return Standard_False; | |
1848 | S = Sweep.Surface(); | |
1849 | if (Sweep.ExchangeUV()) { | |
1850 | if (Sweep.UReversed()) S->Bounds(First, Last, bid, val); | |
1851 | else S->Bounds(First, Last, val, bid); | |
1852 | Iso = S->VIso(val); | |
1853 | } | |
1854 | else { | |
1855 | if (Sweep.UReversed()) S->Bounds(bid, val, First, Last); | |
1856 | else S->Bounds(val, bid, First, Last); | |
1857 | Iso = S->UIso(val); | |
1858 | } | |
0d969553 | 1859 | // Vertex by position |
7fd59977 | 1860 | if (ipath < NbPath) |
1861 | BuildVertex(Iso, Standard_False, First, Last, | |
1862 | myVEdges->ChangeValue(1, ipath+1)); | |
1863 | else { | |
1864 | if (vclose) { | |
1865 | TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1)); | |
1866 | myVEdges->SetValue(1, ipath+1, V); | |
1867 | Iso->D0(Last, P1); | |
1868 | // Tol = P1.Distance(BT.Pnt(V)); | |
1869 | Tol = P1.Distance(BRep_Tool::Pnt(V)); | |
1870 | B.UpdateVertex(V, Tol); | |
1871 | } | |
1872 | else { | |
1873 | if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape); | |
1874 | else BuildVertex(Iso, Standard_False, First, Last, | |
1875 | myVEdges->ChangeValue(1, NbPath+1)); | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | if (ipath > 1) { | |
1880 | Iso->D0(First, P1); | |
1881 | TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath)); | |
1882 | // Tol = P1.Distance(BT.Pnt(V)); | |
1883 | Tol = P1.Distance(BRep_Tool::Pnt(V)); | |
1884 | B.UpdateVertex(V, Tol); | |
1885 | } | |
1886 | if (ipath == 1) { | |
1887 | if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape); | |
1888 | else BuildVertex(Iso, Standard_True, First, Last, | |
1889 | myVEdges->ChangeValue(1, 1)); | |
1890 | } | |
1891 | ||
0d969553 | 1892 | // Construction of the edge |
7fd59977 | 1893 | BRepLib_MakeEdge MkE; |
1894 | MkE.Init(Iso, | |
1895 | TopoDS::Vertex(myVEdges->Value(1, ipath)), | |
1896 | TopoDS::Vertex(myVEdges->Value(1, ipath+1)), | |
1897 | Iso->FirstParameter(), | |
1898 | Iso->LastParameter()); | |
0d969553 | 1899 | if (!MkE.IsDone()) { // Error of construction !! |
7fd59977 | 1900 | #ifdef DRAW |
1901 | char name[100]; | |
1902 | sprintf(name,"firstvertex_error"); | |
1903 | DBRep::Set(name, myVEdges->Value(1, ipath)); | |
1904 | sprintf(name,"lastvertex_error"); | |
1905 | DBRep::Set(name, myVEdges->Value(1, ipath+1)); | |
1906 | sprintf(name,"curve3d_error"); | |
1907 | char* Temp = name ; | |
1908 | DrawTrSurf::Set(Temp,Iso); | |
1909 | // DrawTrSurf::Set(name,Iso); | |
1910 | Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge"); | |
1911 | #endif | |
1912 | return Standard_False; | |
1913 | } | |
1914 | E = MkE.Edge(); | |
1915 | #if DRAW | |
1916 | if (Affich) { | |
1917 | sprintf(name,"Surf_%d", ipath); | |
1918 | char* Temp = name; | |
1919 | DrawTrSurf::Set(Temp, S); | |
1920 | // DrawTrSurf::Set(name, S); | |
1921 | sprintf(name,"Edge_%d", ipath); | |
1922 | DBRep::Set(name, E); | |
1923 | } | |
1924 | #endif | |
1925 | B.UpdateEdge(E, Sweep.ErrorOnSurface()); | |
1926 | B.Add(wire, E); | |
1927 | myFaces->SetValue(1, ipath, E); | |
1928 | } | |
1929 | myShape = wire; | |
1930 | return Standard_True; | |
1931 | } | |
1932 | ||
1933 | //======================================================================= | |
1934 | //function : BuildShell | |
0d969553 | 1935 | //purpose : Construct a Shell by sweeping |
7fd59977 | 1936 | //====================================================================== |
1937 | Standard_Boolean BRepFill_Sweep:: | |
1938 | BuildShell(const BRepFill_TransitionStyle /*Transition*/, | |
1939 | const Standard_Integer IFirst, | |
1940 | const Standard_Integer ILast, | |
1941 | const Standard_Real ExtendFirst, | |
1942 | const Standard_Real ExtendLast) | |
1943 | { | |
1944 | Standard_Integer ipath, isec, IPath; | |
1945 | #ifdef DRAW | |
1946 | char name[100]; | |
1947 | #endif | |
1948 | BRep_Builder B; | |
1949 | Standard_Integer NbPath = ILast - IFirst; | |
1950 | Standard_Integer NbLaw = mySec->NbLaw(); | |
1951 | Standard_Boolean uclose, vclose, constSection, hasdegen = Standard_False; | |
1952 | constSection = mySec->IsConstant(); | |
1953 | uclose = mySec->IsUClosed(); | |
1954 | vclose = (mySec->IsVClosed() && myLoc->IsClosed()) && | |
1955 | (NbPath == myLoc->NbLaw()) && (myLoc->IsG1(0, myTol3d)>= 0); | |
1956 | Error = 0.; | |
1957 | ||
0d969553 | 1958 | // (1) Construction of all surfaces |
7fd59977 | 1959 | |
0d969553 | 1960 | // (1.1) Construction of Tables |
7fd59977 | 1961 | |
1962 | TColStd_Array2OfInteger ExchUV(1, NbLaw, 1, NbPath); | |
1963 | TColStd_Array2OfInteger UReverse(1, NbLaw, 1, NbPath); | |
1964 | TColStd_Array2OfInteger Degenerated(1, NbLaw, 1, NbPath); | |
1965 | Degenerated.Init(0); | |
0d969553 | 1966 | // No VReverse for the moment... |
7fd59977 | 1967 | TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath); |
1968 | TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath); | |
1969 | ||
1970 | TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath); | |
1971 | TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1); | |
1972 | TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1); | |
1973 | ||
1974 | TopoDS_Vertex VNULL; | |
1975 | VNULL.Nullify(); | |
1976 | Vertex.Init(VNULL); | |
1977 | ||
1978 | TopTools_Array1OfShape SecVertex(1, NbLaw+1); | |
1979 | TColStd_Array1OfReal VError(1, NbLaw+1); | |
1980 | TColStd_Array1OfReal Vi(1, NbPath+1); | |
1981 | ||
0d969553 Y |
1982 | //Initialization of management of parametric intervals |
1983 | //(Case of evolutionary sections) | |
7fd59977 | 1984 | Standard_Real Length, SecDom, SecDeb; |
1985 | myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length); | |
1986 | mySec->Law(1)->GetDomain(SecDeb, SecDom); | |
1987 | SecDom -= SecDeb; | |
1988 | if (IFirst > 1) { | |
1989 | Standard_Real Lf, Ll; | |
1990 | myLoc->CurvilinearBounds(IFirst-1, Lf, Ll); | |
1991 | Vi(1) = SecDeb + (Ll/Length)*SecDom; | |
1992 | } | |
1993 | else | |
1994 | Vi(1) = SecDeb; | |
1995 | ||
0d969553 | 1996 | // Error a priori on vertices |
7fd59977 | 1997 | if (constSection) { |
1998 | for (isec=1; isec<=NbLaw+1; isec++) { | |
1999 | VError(isec) = mySec->VertexTol(isec-1, 0.); | |
2000 | SecVertex(isec) = mySec->Vertex(isec, 0.); | |
2001 | } | |
2002 | } | |
2003 | ||
2004 | ||
0d969553 | 2005 | // (1.2) Calculate surfaces |
7fd59977 | 2006 | for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) { |
2007 | ||
2008 | GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart); | |
2009 | Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular); | |
a31abc03 | 2010 | Sweep.SetForceApproxC1(myForceApproxC1); |
7fd59977 | 2011 | |
0d969553 | 2012 | // Case of evolutionary section, definition of parametric correspondence |
7fd59977 | 2013 | if (!constSection) { |
2014 | Standard_Real lf, ll, Lf, Ll; | |
2015 | myLoc->Law(IPath)->GetDomain(lf, ll); | |
2016 | myLoc->CurvilinearBounds(IPath, Lf, Ll); | |
2017 | Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom; | |
2018 | Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1)); | |
2019 | } | |
2020 | else //section is constant | |
2021 | { | |
2022 | Standard_Real lf, ll, Lf, Ll; | |
2023 | myLoc->Law(IPath)->GetDomain(lf, ll); | |
2024 | myLoc->CurvilinearBounds(IPath, Lf, Ll); | |
2025 | Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom; | |
2026 | } | |
2027 | ||
2028 | for(isec=1; isec<=NbLaw; isec++) { | |
2029 | Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax); | |
2030 | if (!Sweep.IsDone()) | |
2031 | return Standard_False; | |
2032 | TabS(isec,ipath) = Sweep.Surface(); | |
2033 | TabErr(isec,ipath) = Sweep.ErrorOnSurface(); | |
2034 | ExchUV(isec, ipath) = Sweep.ExchangeUV(); | |
2035 | UReverse(isec, ipath) = Sweep.UReversed(); | |
2036 | if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface(); | |
2037 | ||
2038 | if ((ipath==1)&&(ExtendFirst>0)) { | |
2039 | Handle(Geom_BoundedSurface) BndS; | |
2040 | BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath)); | |
2041 | GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1, | |
2042 | Sweep.ExchangeUV(), Standard_False); | |
2043 | TabS(isec,ipath) = BndS; | |
2044 | } | |
2045 | if ((ipath==NbPath)&&(ExtendLast>0)){ | |
2046 | Handle(Geom_BoundedSurface) BndS; | |
2047 | BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath)); | |
2048 | GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1, | |
2049 | Sweep.ExchangeUV(), Standard_True); | |
2050 | TabS(isec,ipath) = BndS; | |
2051 | } | |
2052 | ||
2053 | #ifdef DRAW | |
2054 | if (Affich) { | |
2055 | sprintf(name,"Surf_%d_%d", isec, IPath); | |
2056 | char* Temp = name ; | |
2057 | DrawTrSurf::Set(Temp, TabS(isec,ipath)); | |
2058 | } | |
2059 | #endif | |
2060 | } | |
2061 | } | |
2062 | ||
0d969553 | 2063 | // (2) Construction of Edges |
7fd59977 | 2064 | Standard_Real UFirst, ULast, VFirst, VLast; |
2065 | Standard_Boolean exuv, singu, singv; | |
2066 | Handle(Geom_Surface) S; | |
2067 | ||
2068 | if (! vclose) { | |
0d969553 | 2069 | // (2.0) return preexisting Edges and vertices |
7fd59977 | 2070 | TopoDS_Edge E; |
2071 | if (! FirstShape.IsNull() && (IFirst==1)) { | |
2072 | mySec->Init(FirstShape); | |
2073 | for (isec=1; isec<=NbLaw; isec++) { | |
2074 | E = mySec->CurrentEdge(); | |
2075 | VEdge(isec, 1) = E; | |
2076 | if (E.Orientation() == TopAbs_REVERSED) | |
2077 | Vertex(isec+1, 1) = TopExp::FirstVertex(E); | |
2078 | else | |
2079 | Vertex(isec+1, 1) = TopExp::LastVertex(E); | |
2080 | UpdateVertex(IFirst-1, isec+1, | |
2081 | TabErr(isec, 1), Vi(1), Vertex(isec+1, 1)); | |
2082 | } | |
2083 | if (VEdge(1, 1).Orientation() == TopAbs_REVERSED) | |
2084 | Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1))); | |
2085 | else | |
2086 | Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1))); | |
2087 | UpdateVertex(IFirst-1, 1, | |
2088 | TabErr(1, 1), Vi(1), Vertex(1, 1)); | |
2089 | } | |
0d969553 | 2090 | else { // Otherwise construct vertices |
7fd59977 | 2091 | Standard_Real u, v, aux; |
2092 | Standard_Boolean ureverse; | |
2093 | for (isec=1; isec<=NbLaw+1; isec++) { | |
0d969553 | 2094 | // Return data |
7fd59977 | 2095 | if (isec >NbLaw) { |
2096 | S = TabS(NbLaw, 1); | |
2097 | ureverse = UReverse(NbLaw, 1); | |
2098 | exuv = ExchUV(NbLaw, 1); | |
2099 | } | |
2100 | else { | |
2101 | S = TabS(isec, 1); | |
2102 | ureverse = UReverse(isec, 1); | |
2103 | exuv = ExchUV(isec, 1); | |
2104 | } | |
2105 | S->Bounds(UFirst, ULast, VFirst, VLast); | |
2106 | ||
0d969553 | 2107 | // Choice of parameters |
7fd59977 | 2108 | if (ureverse) { |
2109 | if (exuv) { | |
2110 | aux = VFirst; VFirst = VLast; VLast = aux; | |
2111 | } | |
2112 | else { | |
2113 | aux = UFirst; UFirst = ULast; ULast = aux; | |
2114 | } | |
2115 | } | |
2116 | if (isec!= NbLaw+1) { | |
2117 | u = UFirst; | |
2118 | v = VFirst; | |
2119 | } | |
2120 | else { | |
2121 | if (exuv) { | |
2122 | u = UFirst; | |
2123 | v = VLast; | |
2124 | } | |
2125 | else { | |
2126 | u = ULast; | |
2127 | v = VFirst; | |
2128 | } | |
2129 | } | |
2130 | ||
0d969553 | 2131 | // construction of vertices |
7fd59977 | 2132 | B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)), |
2133 | S->Value(u,v), | |
2134 | mySec->VertexTol(isec-1,Vi(1))); | |
2135 | } | |
2136 | } | |
2137 | ||
2138 | if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) { | |
2139 | mySec->Init(LastShape); | |
2140 | for (isec=1; isec<=NbLaw; isec++) { | |
2141 | E = mySec->CurrentEdge(); | |
2142 | VEdge(isec, NbPath+1) = E; | |
2143 | if (E.Orientation() == TopAbs_REVERSED) | |
2144 | Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(E); | |
2145 | else | |
2146 | Vertex(isec+1, NbPath+1) = TopExp::LastVertex(E); | |
2147 | UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath), | |
2148 | Vi(NbPath+1), Vertex(isec+1, NbPath+1)); | |
2149 | } | |
2150 | if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED) | |
2151 | Vertex(1, NbPath+1) = | |
2152 | TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1))); | |
2153 | else | |
2154 | Vertex(1, NbPath+1) = | |
2155 | TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1))); | |
2156 | UpdateVertex(ILast-1, 1, | |
2157 | TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 )); | |
2158 | } | |
2159 | else { | |
2160 | Standard_Real u, v, aux; | |
2161 | Standard_Boolean ureverse; | |
2162 | for (isec=1; isec<=NbLaw+1; isec++) { | |
0d969553 | 2163 | // Return data |
7fd59977 | 2164 | if (isec >NbLaw) { |
2165 | S = TabS(NbLaw, NbPath); | |
2166 | ureverse = UReverse(NbLaw, NbPath); | |
2167 | exuv = ExchUV(NbLaw, NbPath); | |
2168 | } | |
2169 | else { | |
2170 | S = TabS(isec, NbPath); | |
2171 | ureverse = UReverse(isec, NbPath); | |
2172 | exuv = ExchUV(isec, NbPath); | |
2173 | } | |
2174 | S->Bounds(UFirst, ULast, VFirst, VLast); | |
2175 | ||
0d969553 | 2176 | // Choice of parametres |
7fd59977 | 2177 | if (ureverse) { |
2178 | if (exuv) { | |
2179 | aux = VFirst; VFirst = VLast; VLast = aux; | |
2180 | } | |
2181 | else { | |
2182 | aux = UFirst; UFirst = ULast; ULast = aux; | |
2183 | } | |
2184 | } | |
2185 | if (isec == NbLaw+1) { | |
2186 | u = ULast; | |
2187 | v = VLast; | |
2188 | } | |
2189 | else { | |
2190 | if (exuv) { | |
2191 | u = ULast; | |
2192 | v = VFirst; | |
2193 | } | |
2194 | else { | |
2195 | u = UFirst; | |
2196 | v = VLast; | |
2197 | } | |
2198 | } | |
2199 | ||
0d969553 | 2200 | // construction of vertex |
7fd59977 | 2201 | B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)), |
2202 | S->Value(u,v), | |
2203 | mySec->VertexTol(isec-1, Vi(NbPath+1))); | |
2204 | } | |
2205 | } | |
2206 | } | |
2207 | ||
2208 | ||
0d969553 | 2209 | // ---------- Creation of Vertex and edge ------------ |
7fd59977 | 2210 | for (ipath=1, IPath=IFirst; ipath<=NbPath; |
2211 | ipath++, IPath++) { | |
2212 | for (isec=1; isec <=NbLaw; isec++) { | |
2213 | S = TabS(isec, ipath); | |
2214 | exuv = ExchUV(isec, ipath); | |
2215 | S->Bounds(UFirst, ULast, VFirst, VLast); | |
2216 | if (UReverse(isec, ipath)) { | |
2217 | Standard_Real aux; | |
2218 | if (exuv) { | |
2219 | aux = VFirst; VFirst = VLast; VLast = aux; | |
2220 | } | |
2221 | else { | |
2222 | aux = UFirst; UFirst = ULast; ULast = aux; | |
2223 | } | |
2224 | } | |
2225 | ||
0d969553 | 2226 | // (2.1) Construction of new vertices |
7fd59977 | 2227 | if (isec == 1) { |
2228 | if (ipath == 1 && Vertex(1, 1).IsNull()) { | |
0d969553 | 2229 | // All first |
7fd59977 | 2230 | if (constSection) |
2231 | myLoc->PerformVertex(IPath-1, | |
2232 | TopoDS::Vertex(SecVertex(1)), | |
2233 | VError(1), | |
2234 | TopoDS::Vertex(Vertex(1, 1))); | |
2235 | else | |
2236 | myLoc->PerformVertex(IPath-1, | |
2237 | mySec->Vertex(1,Vi(1)), | |
2238 | mySec->VertexTol(0,Vi(1)), | |
2239 | TopoDS::Vertex(Vertex(1, 1))); | |
2240 | } | |
0d969553 | 2241 | // the first and the next column |
7fd59977 | 2242 | if (vclose &&(ipath == NbPath) ) { |
2243 | Vertex(1, ipath+1) = Vertex(1, 1); | |
2244 | } | |
2245 | else if (Vertex(1, ipath+1).IsNull()) { | |
2246 | if (constSection) | |
2247 | myLoc->PerformVertex(IPath, | |
2248 | TopoDS::Vertex(SecVertex(1)), | |
2249 | TabErr(1,ipath)+VError(1), | |
2250 | TopoDS::Vertex(Vertex(1, ipath+1)) ); | |
2251 | else | |
2252 | myLoc->PerformVertex(IPath, | |
2253 | mySec->Vertex(1,Vi(ipath+1)), | |
2254 | TabErr(1,ipath) + | |
2255 | mySec->VertexTol(0,Vi(ipath+1)), | |
2256 | TopoDS::Vertex(Vertex(1, ipath+1))); | |
2257 | ||
2258 | if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) { | |
2259 | UEdge(1, ipath) = NullEdge(Vertex(1,ipath)); | |
2260 | } | |
2261 | } | |
2262 | } | |
2263 | ||
2264 | if (ipath == 1) | |
2265 | if (uclose && (isec == NbLaw)) { | |
2266 | Vertex(isec+1, 1) = Vertex(1, 1); | |
2267 | } | |
2268 | else if (Vertex(isec+1, 1).IsNull()) { | |
2269 | if (constSection) | |
2270 | myLoc->PerformVertex(IPath-1, | |
2271 | TopoDS::Vertex(SecVertex(isec+1)), | |
2272 | TabErr(isec,1)+VError(isec+1), | |
2273 | TopoDS::Vertex(Vertex(isec+1, 1)) ); | |
2274 | else | |
2275 | myLoc->PerformVertex(IPath-1, | |
2276 | mySec->Vertex(isec+1,Vi(1)), | |
2277 | TabErr(isec,1) + | |
2278 | mySec->VertexTol(isec,Vi(1)), | |
2279 | TopoDS::Vertex(Vertex(isec+1, 1)) ); | |
2280 | if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) { | |
2281 | VEdge(isec, 1) = NullEdge(Vertex(isec, 1)); | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | if (uclose && (isec == NbLaw)) { | |
2286 | Vertex(isec+1, ipath+1) = Vertex(1, ipath+1); | |
2287 | } | |
2288 | else if (vclose && (ipath == NbPath)) { | |
2289 | Vertex(isec+1, ipath+1) = Vertex(isec+1, 1); | |
2290 | } | |
2291 | else if (Vertex(isec+1, ipath+1).IsNull()) { | |
2292 | if (constSection) | |
2293 | myLoc->PerformVertex(IPath, | |
2294 | TopoDS::Vertex(SecVertex(isec+1)), | |
2295 | TabErr(isec, ipath)+ VError(isec+1), | |
2296 | TopoDS::Vertex(Vertex(isec+1, ipath+1)) ); | |
2297 | else | |
2298 | myLoc->PerformVertex(IPath, | |
2299 | mySec->Vertex(isec+1,Vi(ipath+1)), | |
2300 | TabErr(isec, ipath) + | |
2301 | mySec->VertexTol(isec, Vi(ipath+1)), | |
2302 | TopoDS::Vertex(Vertex(isec+1, ipath+1)) ); | |
2303 | } | |
2304 | ||
0d969553 | 2305 | // Singular cases |
7fd59977 | 2306 | singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1)); |
2307 | singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1)); | |
2308 | ||
2309 | ||
2310 | ||
2311 | if (singu || singv) { | |
2312 | Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath), | |
2313 | Max(myTol3d, TabErr(isec,ipath))); | |
2314 | } | |
2315 | if (Degenerated(isec, ipath)) { | |
2316 | #if DEB | |
0d969553 | 2317 | cout << "Sweep : Degenerated case" << endl; |
7fd59977 | 2318 | #endif |
2319 | hasdegen = Standard_True; | |
0d969553 | 2320 | // Particular construction of edges |
7fd59977 | 2321 | if (UEdge(isec+1, ipath).IsNull()) { |
2322 | if (singu) { | |
0d969553 | 2323 | // Degenerated edge |
7fd59977 | 2324 | UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath)); |
2325 | } | |
0d969553 | 2326 | else { // Copy the previous edge |
7fd59977 | 2327 | UEdge(isec+1, ipath) = UEdge(isec, ipath); |
2328 | } | |
2329 | } | |
2330 | if (VEdge(isec, ipath+1).IsNull()) { | |
2331 | if (singv) { | |
0d969553 | 2332 | // Degenerated Edge |
7fd59977 | 2333 | VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1)); |
2334 | } | |
0d969553 | 2335 | else { // Copy the previous edge |
7fd59977 | 2336 | VEdge(isec, ipath+1) = VEdge(isec, ipath); |
2337 | } | |
2338 | } | |
2339 | } | |
0d969553 | 2340 | else { // Construction of edges by isos |
7fd59977 | 2341 | if (exuv) { |
2342 | Standard_Real UV; | |
2343 | UV = UFirst; UFirst = VFirst; VFirst = UV; | |
2344 | UV = ULast ; ULast = VLast ; VLast = UV; | |
2345 | } | |
2346 | ||
2347 | // (2.2) Iso-u | |
2348 | if (isec == 1) { | |
2349 | if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) { | |
2350 | gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath))); | |
2351 | gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1))); | |
2352 | if (P1.Distance(P2) <= myTol3d) | |
2353 | Vertex(1,ipath+1) = Vertex(1,ipath); | |
2354 | } | |
2355 | UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst, | |
2356 | Vertex(1,ipath), | |
2357 | Vertex(1,ipath+1), | |
2358 | myTol3d); | |
2359 | } | |
2360 | else UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)), | |
2361 | S, !exuv, UFirst); | |
2362 | ||
2363 | if (uclose && (isec==NbLaw)) { | |
2364 | UpdateEdge(TopoDS::Edge(UEdge(1, ipath)), | |
2365 | S, !exuv, ULast); | |
2366 | UEdge(isec+1, ipath) = UEdge(1, ipath); | |
2367 | } | |
2368 | else { | |
2369 | UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast, | |
2370 | Vertex(isec+1, ipath), | |
2371 | Vertex(isec+1, ipath+1), | |
2372 | myTol3d); | |
2373 | } | |
2374 | ||
2375 | // (2.3) Iso-v | |
2376 | if (ipath == 1 && VEdge(isec, ipath).IsNull()) | |
2377 | VEdge(isec, ipath) = BuildEdge(S, exuv, VFirst, | |
2378 | Vertex(isec , 1), | |
2379 | Vertex(isec+1, 1), | |
2380 | myTol3d); | |
2381 | ||
2382 | else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)), | |
2383 | S, exuv, VFirst); | |
2384 | ||
2385 | if (vclose && (ipath == NbPath)) { | |
2386 | UpdateEdge(TopoDS::Edge(VEdge(isec, 1)), | |
2387 | S, exuv, VLast); | |
2388 | VEdge(isec, ipath+1) = VEdge(isec, 1); | |
2389 | } | |
2390 | else if (VEdge(isec, ipath+1).IsNull()) | |
2391 | VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast, | |
2392 | Vertex(isec , ipath+1), | |
2393 | Vertex(isec+1, ipath+1), | |
2394 | myTol3d); | |
2395 | else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)), | |
2396 | S, exuv, VLast); | |
2397 | ||
2398 | } | |
0d969553 | 2399 | }// End of construction of edges |
7fd59977 | 2400 | } |
2401 | ||
0d969553 | 2402 | // (3) Construction of Faces |
7fd59977 | 2403 | TopoDS_Face face; |
2404 | ||
2405 | #ifdef DRAW | |
2406 | if (Affich) { | |
2407 | for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) { | |
2408 | for (isec=1; isec <=NbLaw+1; isec++){ | |
2409 | sprintf(name,"uedge_%d_%d", isec, IPath); | |
2410 | DBRep::Set(name,UEdge(isec, ipath)); | |
2411 | } | |
2412 | } | |
2413 | ||
2414 | for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) { | |
2415 | for (isec=1; isec <=NbLaw; isec++){ | |
2416 | sprintf(name,"vedge_%d_%d", isec, IPath); | |
2417 | DBRep::Set(name,VEdge(isec, ipath)); | |
2418 | } | |
2419 | ||
2420 | for (isec=1; isec <=NbLaw+1; isec++){ | |
2421 | sprintf(name,"vertex_%d_%d", isec, IPath); | |
2422 | DBRep::Set(name,Vertex(isec, ipath)); | |
2423 | } | |
2424 | } | |
2425 | } | |
2426 | #endif | |
2427 | ||
2428 | for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) { | |
2429 | for (isec=1; isec <=NbLaw; isec++) { | |
2430 | if (Degenerated(isec, ipath)) { | |
2431 | if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath))) | |
2432 | myFaces->SetValue(isec, IPath, UEdge(isec, ipath)); | |
2433 | else | |
2434 | myFaces->SetValue(isec, IPath, VEdge(isec, ipath)); | |
2435 | } | |
2436 | else { | |
2437 | BuildFace(TabS(isec,ipath), | |
2438 | TopoDS::Edge(UEdge(isec, ipath)), | |
2439 | TopoDS::Edge(VEdge(isec, ipath)), | |
2440 | TopoDS::Edge(UEdge(isec+1, ipath)), | |
2441 | TopoDS::Edge(VEdge(isec, ipath+1)), | |
2442 | myVEdgesModified, | |
2443 | ExchUV(isec, ipath), | |
2444 | UReverse(isec, ipath), | |
2445 | face); | |
2446 | myFaces->SetValue(isec, IPath, face); | |
2447 | } | |
2448 | } | |
2449 | } | |
2450 | ||
2451 | ||
0d969553 | 2452 | // (4) History and Continuity |
7fd59977 | 2453 | |
2454 | if (hasdegen) { | |
0d969553 | 2455 | //(4.1) // Degenerated case => Sledgehammer |
7fd59977 | 2456 | TopoDS_Compound Comp; |
2457 | B.MakeCompound(Comp); | |
2458 | for (isec=1; isec <= NbLaw+1; isec++) | |
2459 | for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) { | |
2460 | if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath)); | |
2461 | if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath)); | |
2462 | if ((ipath <= NbPath) && (isec <= NbLaw) && | |
2463 | (myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE)) | |
2464 | B.Add(Comp, myFaces->Value(isec, IPath)); | |
2465 | } | |
2466 | BRepLib::EncodeRegularity(Comp, myTolAngular); | |
2467 | } | |
2468 | else { | |
0d969553 | 2469 | //(4.2) // General case => Tweezers |
7fd59977 | 2470 | Standard_Boolean isG1; |
2471 | TopoDS_Face FF; | |
2472 | TopoDS_Edge E; | |
2473 | ||
2474 | for (isec=1; isec <= NbLaw+1; isec++) { | |
2475 | if (isec>1) isG1 = | |
2476 | (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1); | |
2477 | else isG1 = Standard_False; | |
2478 | for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) { | |
2479 | myUEdges->SetValue(isec, IPath, UEdge(isec, ipath)); | |
2480 | if (isG1) { | |
2481 | if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath)); | |
2482 | else FF = TopoDS::Face(myFaces->Value(isec, IPath)); | |
2483 | B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)), | |
2484 | TopoDS::Face(myFaces->Value(isec-1, IPath)), | |
2485 | FF, GeomAbs_G1); | |
2486 | } | |
2487 | } | |
2488 | } | |
2489 | ||
2490 | Standard_Integer nbpath = NbPath; | |
0d969553 | 2491 | if (vclose) nbpath++; //Another test G1 |
7fd59977 | 2492 | for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) { |
2493 | if ((ipath > 1) && (ipath <=nbpath)) | |
2494 | isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0); | |
2495 | else isG1 = Standard_False; | |
2496 | for (isec=1; isec <= NbLaw; isec++) { | |
2497 | myVEdges->SetValue(isec, IPath, VEdge(isec, ipath)); | |
2498 | if (isG1) { | |
2499 | if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1)); | |
2500 | else FF = TopoDS::Face(myFaces->Value(isec, IPath)); | |
2501 | E = TopoDS::Edge(myVEdges->Value(isec, IPath)); | |
2502 | BRepLib::EncodeRegularity(E, FF, | |
2503 | TopoDS::Face(myFaces->Value(isec, IPath-1)), | |
2504 | myTolAngular); | |
2505 | } | |
2506 | } | |
2507 | } | |
2508 | } | |
2509 | return Standard_True; | |
2510 | } | |
2511 | ||
2512 | //======================================================================= | |
2513 | //function : Build | |
0d969553 | 2514 | //purpose : Construt the result of sweeping |
7fd59977 | 2515 | //====================================================================== |
2516 | void BRepFill_Sweep::Build(const BRepFill_TransitionStyle Transition, | |
7fd59977 | 2517 | const GeomAbs_Shape Continuity, |
a31abc03 | 2518 | const GeomFill_ApproxStyle Approx, |
7fd59977 | 2519 | const Standard_Integer Degmax, |
2520 | const Standard_Integer Segmax) | |
2521 | { | |
7fd59977 | 2522 | myContinuity = Continuity; |
a31abc03 | 2523 | myApproxStyle = Approx; |
7fd59977 | 2524 | myDegmax = Degmax; |
2525 | mySegmax = Segmax; | |
2526 | ||
2527 | CorrectApproxParameters(); | |
2528 | ||
2529 | // Wire | |
2530 | if (mySec->IsVertex()) isDone = BuildWire(Transition); | |
2531 | ||
2532 | else { // Shell | |
2533 | Standard_Integer NbTrous = myLoc->NbHoles(myTol3d), | |
2534 | NbPath = myLoc->NbLaw(), | |
2535 | NbLaw = mySec->NbLaw(), ii, jj, NbPart=1; | |
2536 | Standard_Integer ipath, isec; | |
2537 | BRep_Builder B; | |
2538 | myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath); | |
2539 | myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1); | |
2540 | myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath); | |
2541 | Handle (TopTools_HArray2OfShape) Bounds = | |
2542 | new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2); | |
2543 | ||
2544 | Handle(TColStd_HArray1OfInteger) Trous; | |
2545 | ||
0d969553 | 2546 | if (NbTrous>0) { // How many sub-parts ? |
7fd59977 | 2547 | Trous = new (TColStd_HArray1OfInteger) (1, NbTrous); |
2548 | myLoc->Holes(Trous->ChangeArray1()); | |
2549 | NbPart += NbTrous; | |
2550 | if (Trous->Value(NbTrous) == NbPath+1) NbPart--; | |
2551 | } | |
0d969553 | 2552 | if (NbPart == 1) { // This is done at once |
7fd59977 | 2553 | Standard_Real Extend = 0.0; |
2554 | if (NbTrous==1) Extend = EvalExtrapol(1, Transition); | |
2555 | isDone = BuildShell(Transition, | |
2556 | 1, NbPath+1, | |
2557 | Extend, Extend); | |
2558 | } | |
0d969553 | 2559 | else { // This is done piece by piece |
7fd59977 | 2560 | Standard_Integer IFirst = 1, ILast; |
2561 | for (ii=1, isDone=Standard_True; | |
2562 | ii<=NbPart && isDone; ii++) { | |
2563 | if (ii > NbTrous) ILast = NbPath+1; | |
2564 | else ILast = Trous->Value(ii); | |
2565 | isDone = BuildShell(Transition, | |
2566 | IFirst, ILast, | |
2567 | EvalExtrapol(IFirst, Transition), | |
2568 | EvalExtrapol(ILast, Transition)); | |
2569 | if (IFirst>1) { | |
2570 | Translate(myVEdges, IFirst, Bounds, 2); | |
2571 | PerformCorner(IFirst, | |
2572 | Transition, Bounds); | |
2573 | } | |
2574 | IFirst = ILast; | |
2575 | Translate(myVEdges, IFirst, Bounds, 1); | |
2576 | } | |
2577 | } | |
0d969553 | 2578 | // Management of looping ends |
7fd59977 | 2579 | if ( (NbTrous>0) && (myLoc->IsClosed()) && |
2580 | (Trous->Value(NbTrous) == NbPath+1) ) { | |
2581 | Translate(myVEdges, NbPath+1, Bounds, 1); | |
2582 | Translate(myVEdges, 1, Bounds, 2); | |
2583 | PerformCorner(1, Transition, Bounds); | |
2584 | } | |
2585 | ||
0d969553 | 2586 | // Construction of the shell |
7fd59977 | 2587 | TopoDS_Shell shell; |
2588 | B.MakeShell(shell); | |
2589 | for (ipath=1; ipath<=NbPath; ipath++) | |
2590 | for (isec=1; isec <=NbLaw; isec++) { | |
2591 | const TopoDS_Shape& face = myFaces->Value(isec, ipath); | |
2592 | if (!face.IsNull() && | |
2593 | (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face); | |
2594 | } | |
2595 | ||
2596 | TopTools_ListIteratorOfListOfShape It(myAuxShape); | |
2597 | for (; It.More(); It.Next()) { | |
2598 | const TopoDS_Shape& face = It.Value(); | |
2599 | if (!face.IsNull() && | |
2600 | (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face); | |
2601 | } | |
2602 | //Set common Uedges to faces | |
2603 | BRepTools_Substitution aSubstitute; | |
2604 | /* | |
2605 | for (ii = 1; ii <= NbLaw; ii++) | |
2606 | for (jj = 1; jj <= NbPath; jj++) | |
2607 | { | |
2608 | SetCommonEdgeInFace(aSubstitute, | |
2609 | myFaces->Value(ii, jj), | |
2610 | myUEdges->Value(ii, jj)); | |
2611 | SetCommonEdgeInFace(aSubstitute, | |
2612 | myFaces->Value(ii, jj), | |
2613 | myUEdges->Value(ii+1, jj)); | |
2614 | } | |
2615 | if (mySec->IsUClosed()) | |
2616 | for (jj = 1; jj <= NbPath; jj++) | |
2617 | SetCommonEdgeInFace(aSubstitute, | |
2618 | myFaces->Value( 1, jj ), | |
2619 | myUEdges->Value( NbLaw+1, jj)); | |
2620 | */ | |
2621 | TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified ); | |
2622 | for (; mapit.More(); mapit.Next()) | |
2623 | { | |
2624 | const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key()); | |
2625 | const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value()); | |
2626 | Substitute( aSubstitute, OldEdge, NewEdge ); | |
2627 | } | |
2628 | aSubstitute.Build( shell ); | |
2629 | if (aSubstitute.IsCopied( shell )) { | |
2630 | const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell ); | |
2631 | shell = TopoDS::Shell( listSh.First() ); | |
2632 | } | |
2633 | ||
2634 | for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) { | |
2635 | for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) { | |
2636 | const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj); | |
2637 | ||
2638 | if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) { | |
2639 | const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape); | |
2640 | ||
2641 | if(!aList.IsEmpty()) | |
2642 | myFaces->ChangeValue(ii, jj) = aList.First(); | |
2643 | } | |
2644 | } | |
2645 | } | |
2646 | ||
2647 | for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) { | |
2648 | for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) { | |
2649 | const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj); | |
2650 | ||
2651 | if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) { | |
2652 | const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape); | |
2653 | ||
2654 | if(!aList.IsEmpty()) | |
2655 | myVEdges->ChangeValue(ii, jj) = aList.First(); | |
2656 | } | |
2657 | } | |
2658 | } | |
2659 | ||
2660 | for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) { | |
2661 | for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) { | |
2662 | const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj); | |
2663 | ||
2664 | if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) { | |
2665 | const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape); | |
2666 | ||
2667 | if(!aList.IsEmpty()) | |
2668 | myUEdges->ChangeValue(ii, jj) = aList.First(); | |
2669 | } | |
2670 | } | |
2671 | } | |
2672 | ||
0d969553 | 2673 | // Is it Closed ? |
7fd59977 | 2674 | if (myLoc->IsClosed() && mySec->IsUClosed()) { |
0d969553 | 2675 | //Check |
7fd59977 | 2676 | Standard_Boolean closed = Standard_True; |
2677 | Standard_Integer iedge; | |
2678 | TopTools_IndexedDataMapOfShapeListOfShape EFmap; | |
2679 | TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE, | |
2680 | TopAbs_FACE, EFmap); | |
2681 | ||
2682 | for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) { | |
2683 | const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge)); | |
2684 | if (BRep_Tool::Degenerated(theEdge)) continue; | |
2685 | closed = ( EFmap(iedge).Extent() > 1); | |
2686 | } | |
2687 | shell.Closed(closed); | |
2688 | } | |
2689 | myShape = shell; | |
2690 | } | |
2691 | } | |
2692 | ||
2693 | ||
2694 | //======================================================================= | |
2695 | //function : IsDone | |
2696 | //purpose : | |
2697 | //======================================================================= | |
2698 | Standard_Boolean BRepFill_Sweep::IsDone() const | |
2699 | { | |
2700 | return isDone; | |
2701 | } | |
2702 | ||
2703 | //======================================================================= | |
2704 | //function : Shape | |
2705 | //purpose : | |
2706 | //======================================================================= | |
2707 | TopoDS_Shape BRepFill_Sweep::Shape() const | |
2708 | { | |
2709 | return myShape; | |
2710 | } | |
2711 | ||
2712 | //======================================================================= | |
2713 | //function : ErrorOnSurface | |
2714 | //purpose : | |
2715 | //======================================================================= | |
2716 | Standard_Real BRepFill_Sweep::ErrorOnSurface() const | |
2717 | { | |
2718 | return Error; | |
2719 | } | |
2720 | ||
2721 | //======================================================================= | |
2722 | //function : SubShape | |
0d969553 | 2723 | //purpose : Faces obtained by sweeping |
7fd59977 | 2724 | //======================================================================= |
2725 | Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const | |
2726 | { | |
2727 | return myFaces; | |
2728 | } | |
2729 | ||
2730 | //======================================================================= | |
2731 | //function : InterFaces | |
0d969553 | 2732 | //purpose : Edges obtained by sweeping |
7fd59977 | 2733 | //======================================================================= |
2734 | Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const | |
2735 | { | |
2736 | return myUEdges; | |
2737 | } | |
2738 | ||
2739 | //======================================================================= | |
2740 | //function : Sections | |
0d969553 | 2741 | //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings |
7fd59977 | 2742 | //======================================================================= |
2743 | Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const | |
2744 | { | |
2745 | return myVEdges; | |
2746 | } | |
2747 | ||
2748 | //======================================================================= | |
2749 | //function : PerformCorner | |
0d969553 | 2750 | //purpose : Trim and/or loop a corner |
7fd59977 | 2751 | //====================================================================== |
2752 | void BRepFill_Sweep::PerformCorner(const Standard_Integer Index, | |
2753 | const BRepFill_TransitionStyle Transition, | |
2754 | const Handle(TopTools_HArray2OfShape)& Bounds) | |
2755 | { | |
2756 | ||
0d969553 | 2757 | if (Transition == BRepFill_Modified) return; // Do nothing. |
7fd59977 | 2758 | |
2759 | BRepFill_TransitionStyle TheTransition = Transition; | |
2760 | Standard_Boolean isTangent=Standard_False; | |
2761 | Standard_Real F, L; | |
2762 | Standard_Integer I1, I2, ii; //, jj; | |
2763 | gp_Pnt P1,P2; | |
2764 | gp_Vec T1, T2, Tang, Sortant; | |
2765 | // gp_Mat M; | |
2766 | //Handle(TopTools_HArray1OfShape) TheShape = | |
2767 | //new TopTools_HArray1OfShape( 1, mySec->NbLaw() ); | |
2768 | // TopTools_ListIteratorOfListOfShape Iterator; | |
2769 | ||
2770 | if (Index > 1) { | |
2771 | I1 = Index-1; | |
2772 | I2 = Index; | |
2773 | } | |
2774 | else { | |
2775 | I1 = myLoc->NbLaw(); | |
2776 | I2 = 1; | |
2777 | } | |
2778 | ||
0d969553 | 2779 | // Construct an axis supported by the bissectrice |
7fd59977 | 2780 | myLoc->Law(I1)->GetDomain(F, L); |
2781 | myLoc->Law(I1)->GetCurve()->D1(L, P1, T1); | |
2782 | T1.Normalize(); | |
2783 | ||
2784 | myLoc->Law(I2)->GetDomain(F, L); | |
2785 | myLoc->Law(I2)->GetCurve()->D1(F, P2, T2); | |
2786 | T2.Normalize(); | |
2787 | ||
2788 | if (T1.Angle(T2) < myAngMin) { | |
2789 | isTangent = Standard_True; | |
2790 | gp_Vec t1, t2, V; | |
2791 | gp_Mat M; | |
2792 | myLoc->Law(I1)->GetDomain(F, L); | |
2793 | myLoc->Law(I1)->D0(L, M, V); | |
2794 | t1 = M.Column(3); | |
2795 | myLoc->Law(I2)->GetDomain(F, L); | |
2796 | myLoc->Law(I2)->D0(L, M, V); | |
2797 | t2 = M.Column(3); | |
2798 | ||
2799 | if (t1.Angle(t2) < myAngMin) { | |
2800 | #if DEB | |
0d969553 | 2801 | cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << endl; |
7fd59977 | 2802 | #endif |
2803 | return; | |
2804 | } | |
2805 | Sortant = t2 - t1; | |
2806 | } | |
2807 | ||
2808 | if ((TheTransition == BRepFill_Right) | |
2809 | && (T1.Angle(T2) > myAngMax) ) { | |
2810 | TheTransition = BRepFill_Round; | |
2811 | } | |
2812 | ||
0d969553 | 2813 | Tang = T1 + T2; //Average direction |
7fd59977 | 2814 | gp_Dir NormalOfBisPlane = Tang; |
2815 | ||
2816 | if (isTangent) { | |
2817 | Sortant -= Tang.Dot(Tang)*Tang; | |
2818 | } | |
2819 | else { | |
0d969553 Y |
2820 | Sortant = T2-T1; //Direction input |
2821 | Sortant *= -1; // " " output | |
7fd59977 | 2822 | Tang -= (Tang.Dot(T2))*T2; |
2823 | } | |
2824 | ||
2825 | P1.BaryCenter(0.5, P2, 0.5); | |
2826 | gp_Dir N(Sortant); | |
2827 | gp_Dir Dx(Tang); | |
2828 | ||
2829 | gp_Ax2 Axe (P1, N, Dx); | |
2830 | gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane ); | |
2831 | ||
0d969553 | 2832 | // Construct 2 intersecting Shells |
7fd59977 | 2833 | Handle (TopTools_HArray2OfShape) UEdges = |
2834 | new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() ); | |
2835 | UEdges->ChangeArray2() = myUEdges->Array2(); | |
2836 | ||
2837 | // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN | |
2838 | Handle (TopTools_HArray2OfShape) aFaces = | |
2839 | new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2); | |
2840 | Translate(myFaces, I1, aFaces, 1); | |
2841 | Translate(myFaces, I2, aFaces, 2); | |
2842 | ||
2843 | Handle (TopTools_HArray2OfShape) aUEdges = | |
2844 | new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2); | |
2845 | Translate(myUEdges, I1, aUEdges, 1); | |
2846 | Translate(myUEdges, I2, aUEdges, 2); | |
2847 | ||
2848 | gp_Vec aNormal = T2 + T1; | |
2849 | TopoDS_Face aPlaneF; | |
2850 | ||
2851 | if(aNormal.Magnitude() > gp::Resolution()) { | |
2852 | gp_Pln pl(P1, gp_Dir(aNormal)); | |
2853 | BRepLib_MakeFace aFMaker(pl); | |
2854 | ||
2855 | if(aFMaker.Error() == BRepLib_FaceDone) { | |
2856 | aPlaneF = aFMaker.Face(); | |
2857 | BRep_Builder aBB; | |
2858 | aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.); | |
2859 | } | |
2860 | } | |
2861 | ||
2862 | BRepFill_TrimShellCorner aTrim(aFaces, AxeOfBisPlane, aPlaneF); | |
2863 | aTrim.AddBounds(Bounds); | |
2864 | aTrim.AddUEdges(aUEdges); | |
2865 | aTrim.Perform(); | |
2866 | ||
2867 | if (aTrim.IsDone()) { | |
2868 | TopTools_ListOfShape listmodif; | |
2869 | Standard_Integer iit = 0; | |
2870 | ||
2871 | for(iit = 0; iit < 2; iit++) { | |
2872 | Standard_Integer II = (iit == 0) ? I1 : I2; | |
2873 | ||
2874 | for (ii = 1; ii <= mySec->NbLaw(); ii++) { | |
2875 | aTrim.Modified(myFaces->Value(ii, II), listmodif); | |
2876 | ||
2877 | if(!listmodif.IsEmpty()) { | |
2878 | myFaces->SetValue(ii, II, listmodif.First()); | |
2879 | } | |
2880 | } | |
2881 | ||
2882 | for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) { | |
2883 | aTrim.Modified(myUEdges->Value(ii, II), listmodif); | |
2884 | ||
2885 | if(!listmodif.IsEmpty()) { | |
2886 | myUEdges->SetValue(ii, II, listmodif.First()); | |
2887 | } | |
2888 | } | |
2889 | } | |
2890 | } | |
2891 | else if ((TheTransition == BRepFill_Right) || | |
2892 | aTrim.HasSection() ) { | |
2893 | #if DEB | |
0d969553 | 2894 | cout << "Fail of TrimCorner" << endl; |
7fd59977 | 2895 | #endif |
0d969553 | 2896 | return; // Nothing is touched |
7fd59977 | 2897 | } |
2898 | ||
2899 | if (mySec->IsUClosed()) | |
2900 | { | |
2901 | myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) ); | |
2902 | myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) ); | |
2903 | } | |
2904 | ||
2905 | if (TheTransition == BRepFill_Round) { | |
0d969553 | 2906 | // Filling |
7fd59977 | 2907 | TopTools_ListOfShape list1, list2; |
2908 | TopoDS_Edge Bord1, Bord2, BordFirst; | |
2909 | BordFirst.Nullify(); | |
2910 | Bord1.Nullify(); | |
2911 | Bord2.Nullify(); | |
2912 | Standard_Boolean HasFilling = Standard_False; | |
2913 | TopoDS_Face FF; | |
2914 | for (ii=1; ii<=mySec->NbLaw(); ii++) { | |
2915 | KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1); | |
2916 | KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2); | |
2917 | if (list1.Extent() == list2.Extent()) { | |
2918 | TopTools_ListIteratorOfListOfShape It1(list1); | |
2919 | TopTools_ListIteratorOfListOfShape It2(list2); | |
2920 | Standard_Boolean B; | |
2921 | for (; It1.More(); It1.Next(), It2.Next()) { | |
0d969553 | 2922 | if (HasFilling) { // Transversal choice of constraints |
7fd59977 | 2923 | TopoDS_Vertex VF, VL, VC; |
2924 | TopoDS_Edge E = TopoDS::Edge(It1.Value()); | |
2925 | TopoDS_Edge E1, E2; | |
2926 | E1.Nullify(); | |
2927 | E2.Nullify(); | |
2928 | TopExp::Vertices(E, VF, VL); | |
2929 | if (!Bord1.IsNull() && | |
2930 | TopExp::CommonVertex(E, Bord1, VC)) { | |
2931 | if (VC.IsSame(VF)) E1 = Bord1; | |
2932 | else E2 = Bord1; | |
2933 | } | |
2934 | if (!Bord2.IsNull() && | |
2935 | TopExp::CommonVertex(E, Bord2, VC)) { | |
2936 | if (VC.IsSame(VF)) E1 = Bord2; | |
2937 | else E2 = Bord2; | |
2938 | } | |
2939 | if (!BordFirst.IsNull() && | |
2940 | TopExp::CommonVertex(E, BordFirst, VC)) { | |
2941 | if (VC.IsSame(VF)) E1 = BordFirst; | |
2942 | else E2 = BordFirst; | |
2943 | } | |
2944 | Bord1 = E1; | |
2945 | Bord2 = E2; | |
2946 | } | |
2947 | ||
0d969553 | 2948 | // Filling |
7fd59977 | 2949 | B = Filling(It1.Value(), myFaces->Value(ii, I1), |
2950 | It2.Value(), myFaces->Value(ii, I2), | |
2951 | myVEdgesModified, myTol3d, Axe, T1, Bord1, Bord2, FF); | |
2952 | ||
2953 | if (B) { | |
2954 | myAuxShape.Append(FF); | |
2955 | myVEdges->ChangeValue(ii, I2) = FF; | |
2956 | HasFilling = Standard_True; | |
2957 | } | |
2958 | if (ii==1) BordFirst = Bord1; | |
2959 | } | |
2960 | } | |
2961 | #if DEB | |
0d969553 | 2962 | else cout << "PerformCorner : Unsymmetry of free border" << endl; |
7fd59977 | 2963 | #endif |
2964 | } | |
2965 | } | |
2966 | ||
2967 | /* | |
2968 | #if DRAW | |
2969 | if (Affich) { | |
2970 | Standard_Integer jj; | |
2971 | char name[100]; | |
2972 | DBRep::Set("TrimmedShell", TheShape); | |
2973 | for (jj=1; jj <=myFaces->ColLength(); jj++){ | |
2974 | sprintf(name,"Tfaces_%d_%d", jj, I1); | |
2975 | DBRep::Set(name, myFaces->Value(jj, I1)); | |
2976 | sprintf(name,"Tfaces_%d_%d", jj, I2); | |
2977 | DBRep::Set(name, myFaces->Value(jj, I2)); | |
2978 | } | |
2979 | } | |
2980 | #endif | |
2981 | */ | |
2982 | } | |
2983 | ||
2984 | //======================================================================= | |
2985 | //function : EvalExtrapol | |
2986 | //purpose : | |
2987 | //====================================================================== | |
2988 | Standard_Real BRepFill_Sweep:: | |
2989 | EvalExtrapol(const Standard_Integer Index, | |
2990 | const BRepFill_TransitionStyle Transition) const | |
2991 | { | |
2992 | Standard_Real Extrap = 0.0; | |
2993 | if (Transition == BRepFill_Right) { | |
2994 | Standard_Integer I1, I2; | |
2995 | if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) { | |
2996 | if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap; | |
2997 | I1 = myLoc->NbLaw(); | |
2998 | I2 = 1; | |
2999 | } | |
3000 | else { | |
3001 | I1 = Index-1; | |
3002 | I2 = Index; | |
3003 | } | |
3004 | ||
3005 | gp_Vec V1, V2, T1, T2; | |
3006 | gp_Mat M1, M2; | |
3007 | Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l; | |
3008 | ||
3009 | myLoc->Law(I1)->GetDomain(f, l); | |
3010 | myLoc->Law(I1)->D0(l, M1, V1); | |
3011 | T1.SetXYZ(M1.Column(3)); | |
3012 | myLoc->Law(I2)->GetDomain(f, l); | |
3013 | myLoc->Law(I2)->D0(f, M2, V2); | |
3014 | T2.SetXYZ(M2.Column(3)); | |
3015 | ||
3016 | Standard_Real alpha = T1.Angle(T2); | |
3017 | if ((alpha > myAngMax) || (alpha < myAngMin)) { | |
0d969553 Y |
3018 | //Angle too great => No "straight" connection |
3019 | //Angle too small => No connection | |
7fd59977 | 3020 | return Extrap; // = 0.0 |
3021 | } | |
3022 | ||
3023 | Handle(GeomFill_SectionLaw) Sec; | |
3024 | Sec = mySec->ConcatenedLaw(); | |
3025 | ||
3026 | //Calculating parameter U | |
3027 | Standard_Real U, Length, SecFirst, SecLen, Lf, Ll; | |
3028 | myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length ); | |
3029 | mySec->Law(1)->GetDomain( SecFirst, SecLen ); | |
3030 | SecLen -= SecFirst; | |
3031 | myLoc->CurvilinearBounds( I1, Lf, Ll ); | |
3032 | U = SecFirst + (Ll/Length)*SecLen; | |
3033 | ||
3034 | Bnd_Box box; | |
3035 | //Box(Sec, 0., box); | |
3036 | Box(Sec, U, box); | |
3037 | box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); | |
3038 | ||
3039 | R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax))); | |
3040 | //R *= 1.1; | |
3041 | // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003 | |
3042 | // Standard_Real coef = 1.2; | |
3043 | Standard_Real coef = 2.; | |
3044 | R *= coef; | |
3045 | Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d; | |
3046 | Extrap += R*Tan(alpha/2); | |
3047 | } | |
3048 | return Extrap; | |
3049 | } | |
3050 | ||
3051 | //======================================================================= | |
3052 | //function : MergeVertex | |
0d969553 | 3053 | //purpose : Make V2 = V1 if V2 is too close to V1 |
7fd59977 | 3054 | //====================================================================== |
3055 | Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1, | |
3056 | TopoDS_Shape& V2) const | |
3057 | { | |
3058 | // Class BRep_Tool without fields and without Constructor : | |
3059 | // BRep_Tool BT; | |
3060 | const TopoDS_Vertex& v1 = TopoDS::Vertex(V1); | |
3061 | const TopoDS_Vertex& v2 = TopoDS::Vertex(V2); | |
3062 | Standard_Real tol; | |
3063 | // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2)); | |
3064 | tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2)); | |
3065 | if (tol < myTol3d) tol = myTol3d; | |
3066 | // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){ | |
3067 | if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){ | |
3068 | V2 = V1; | |
3069 | return Standard_True; | |
3070 | } | |
3071 | return Standard_False; | |
3072 | } | |
3073 | ||
3074 | ||
3075 | //======================================================================= | |
3076 | //function : UpdateVertex | |
0d969553 | 3077 | //purpose : Update the Tolerance of Vertices depending on Laws. |
7fd59977 | 3078 | //====================================================================== |
3079 | void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath, | |
3080 | const Standard_Integer isec, | |
3081 | const Standard_Real ErrApp, | |
3082 | const Standard_Real Param, | |
3083 | TopoDS_Shape& V) const | |
3084 | { | |
3085 | TopoDS_Vertex vv, TheV; | |
3086 | TheV = TopoDS::Vertex(V); | |
3087 | myLoc->PerformVertex(ipath, | |
3088 | mySec->Vertex(isec, Param), | |
3089 | ErrApp+mySec->VertexTol(isec-1, Param), | |
3090 | vv); | |
3091 | // Class BRep_Tool without fields and without Constructor : | |
3092 | // BRep_Tool BT; | |
3093 | gp_Pnt P1, P2; | |
3094 | // P1 = BT.Pnt(vv); | |
3095 | P1 = BRep_Tool::Pnt(vv); | |
3096 | // P2 = BT.Pnt(TheV); | |
3097 | P2 = BRep_Tool::Pnt(TheV); | |
3098 | ||
3099 | // Standard_Real Tol = BT.Tolerance(vv); | |
3100 | Standard_Real Tol = BRep_Tool::Tolerance(vv); | |
3101 | Tol += P1.Distance(P2); | |
3102 | ||
3103 | // if (Tol > BT.Tolerance(TheV)) { | |
3104 | if (Tol > BRep_Tool::Tolerance(TheV)) { | |
3105 | BRep_Builder B; | |
3106 | B.UpdateVertex(TheV, Tol); | |
3107 | } | |
3108 | } |