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