1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BOPCol_IndexedMapOfShape.hxx>
17 #include <BOPTools.hxx>
18 #include <BOPTools_AlgoTools2D.hxx>
19 #include <BRep_Builder.hxx>
20 #include <BRep_CurveRepresentation.hxx>
21 #include <BRep_GCurve.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23 #include <BRep_TEdge.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRepAdaptor_Curve.hxx>
26 #include <BRepAdaptor_HSurface.hxx>
27 #include <BRepAdaptor_Surface.hxx>
28 #include <BRepClass_FaceClassifier.hxx>
29 #include <BRepTools.hxx>
30 #include <Geom2d_BSplineCurve.hxx>
31 #include <Geom2d_Circle.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom2d_Ellipse.hxx>
34 #include <Geom2d_Hyperbola.hxx>
35 #include <Geom2d_Line.hxx>
36 #include <Geom2d_Parabola.hxx>
37 #include <Geom2d_TrimmedCurve.hxx>
38 #include <Geom2dAdaptor.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_RectangularTrimmedSurface.hxx>
42 #include <Geom_Surface.hxx>
43 #include <Geom_TrimmedCurve.hxx>
44 #include <GeomAdaptor_Curve.hxx>
45 #include <GeomAdaptor_HCurve.hxx>
46 #include <GeomAdaptor_HSurface.hxx>
47 #include <GeomAdaptor_Surface.hxx>
48 #include <GeomInt.hxx>
49 #include <GeomProjLib.hxx>
51 #include <gp_Cylinder.hxx>
53 #include <gp_Pnt2d.hxx>
55 #include <gp_Vec2d.hxx>
56 #include <IntTools_Context.hxx>
57 #include <IntTools_Tools.hxx>
58 #include <Precision.hxx>
59 #include <ProjLib_ProjectedCurve.hxx>
60 #include <Standard_ConstructionError.hxx>
61 #include <Standard_NotImplemented.hxx>
63 #include <TopExp_Explorer.hxx>
64 #include <TopLoc_Location.hxx>
65 #include <TopoDS_Edge.hxx>
66 #include <TopoDS_Face.hxx>
69 Standard_Boolean CheckEdgeLength (const TopoDS_Edge& );
72 Handle(Geom2d_Curve) BRep_Tool_CurveOnSurface(const TopoDS_Edge& ,
78 Handle(Geom2d_Curve) BRep_Tool_CurveOnSurface(const TopoDS_Edge& ,
79 const Handle(Geom_Surface)& ,
80 const TopLoc_Location& ,
85 Standard_Real MaxToleranceEdge (const TopoDS_Face& );
87 //=======================================================================
88 //function : BuildPCurveForEdgeOnFace
90 //=======================================================================
91 void BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace (const TopoDS_Edge& aE,
92 const TopoDS_Face& aF)
95 Handle(Geom2d_Curve) aC2D;
96 Standard_Real aTolPC, aTolFact, aTolEdge, aFirst, aLast;
98 Standard_Boolean aHasOld;
99 aHasOld=BOPTools_AlgoTools2D::HasCurveOnSurface (aE, aF, aC2D,
107 BOPTools_AlgoTools2D::CurveOnSurface(aE, aF, aC2D, aTolPC);
109 aTolEdge=BRep_Tool::Tolerance(aE);
111 aTolFact=Max(aTolEdge, aTolPC);
113 aBB.UpdateEdge(aE, aC2D, aF, aTolFact);
117 //=======================================================================
118 //function : EdgeTangent
120 //=======================================================================
121 Standard_Boolean BOPTools_AlgoTools2D::EdgeTangent
122 (const TopoDS_Edge& anEdge,
123 const Standard_Real aT,
126 Standard_Boolean isdgE;
127 Standard_Real first, last;
129 isdgE = BRep_Tool::Degenerated(anEdge);
131 return Standard_False;
133 if (!CheckEdgeLength(anEdge)) {
134 return Standard_False;
137 Handle(Geom_Curve) aC=BRep_Tool::Curve(anEdge, first, last);
139 aC->D1(aT, aP, aTau);
140 Standard_Real mod = aTau.Magnitude();
141 if(mod > gp::Resolution()) {
145 return Standard_False;
148 if (anEdge.Orientation() == TopAbs_REVERSED){
151 return Standard_True;
154 //=======================================================================
155 //function : PointOnOnSurface
157 //=======================================================================
158 void BOPTools_AlgoTools2D::PointOnSurface (const TopoDS_Edge& aE,
159 const TopoDS_Face& aF,
160 const Standard_Real aParameter,
165 Handle(Geom2d_Curve) aC2D;
166 Standard_Real aToler, aFirst, aLast;
168 BOPTools_AlgoTools2D::CurveOnSurface (aE, aF, aC2D,
169 aFirst, aLast, aToler);
170 aC2D->D0(aParameter, aP2D);
176 //=======================================================================
177 //function : CurveOnSurface
179 //=======================================================================
180 void BOPTools_AlgoTools2D::CurveOnSurface (const TopoDS_Edge& aE,
181 const TopoDS_Face& aF,
182 Handle(Geom2d_Curve)& aC2D,
183 Standard_Real& aToler)
185 Standard_Real aFirst, aLast;
187 BOPTools_AlgoTools2D::CurveOnSurface (aE, aF, aC2D,
188 aFirst, aLast, aToler);
192 //=======================================================================
193 //function : CurveOnSurface
195 //=======================================================================
196 void BOPTools_AlgoTools2D::CurveOnSurface (const TopoDS_Edge& aE,
197 const TopoDS_Face& aF,
198 Handle(Geom2d_Curve)& aC2D,
199 Standard_Real& aFirst,
200 Standard_Real& aLast,
201 Standard_Real& aToler)
203 Standard_Boolean aHasOld;
204 Handle(Geom2d_Curve) C2D;
206 aHasOld=BOPTools_AlgoTools2D::HasCurveOnSurface (aE, aF, C2D,
214 BOPTools_AlgoTools2D::Make2D(aE, aF, C2D, aFirst, aLast, aToler);
218 //=======================================================================
219 //function : HasCurveOnSurface
221 //=======================================================================
222 Standard_Boolean BOPTools_AlgoTools2D::HasCurveOnSurface
223 (const TopoDS_Edge& aE,
224 const TopoDS_Face& aF,
225 Handle(Geom2d_Curve)& aC2D,
226 Standard_Real& aFirst,
227 Standard_Real& aLast,
228 Standard_Real& aToler)
230 Standard_Boolean aHasOld;
232 aToler=BRep_Tool::Tolerance(aE);
233 BRep_Tool::Range(aE, aFirst, aLast);
235 if((aLast - aFirst) < Precision::PConfusion()) {
236 return Standard_False;
239 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aFirst, aLast);
240 aHasOld=!aC2D.IsNull();
243 //=======================================================================
244 //function : HasCurveOnSurface
246 //=======================================================================
247 Standard_Boolean BOPTools_AlgoTools2D::HasCurveOnSurface
248 (const TopoDS_Edge& aE,
249 const TopoDS_Face& aF)
252 Standard_Boolean bHasOld;
253 Handle(Geom2d_Curve) aC2D;
254 Standard_Real aFirst, aLast;
256 BRep_Tool::Range(aE, aFirst, aLast);
258 if((aLast - aFirst) < Precision::PConfusion()) {
259 return Standard_False;
262 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aFirst, aLast);
263 bHasOld=!aC2D.IsNull();
267 //=======================================================================
268 //function : AdjustPCurveOnFace
270 //=======================================================================
271 void BOPTools_AlgoTools2D::AdjustPCurveOnFace
272 (const TopoDS_Face& aF,
273 const Handle(Geom_Curve)& aC3D,
274 const Handle(Geom2d_Curve)& aC2D,
275 Handle(Geom2d_Curve)& aC2DA)
277 Standard_Real aT1, aT2;
279 aT1=aC3D->FirstParameter();
280 aT2=aC3D->LastParameter();
282 BOPTools_AlgoTools2D::AdjustPCurveOnFace (aF, aT1, aT2, aC2D, aC2DA);
284 //=======================================================================
285 //function : AdjustPCurveOnFace
287 //=======================================================================
288 void BOPTools_AlgoTools2D::AdjustPCurveOnFace
289 (const TopoDS_Face& aF,
290 const Standard_Real aT1,
291 const Standard_Real aT2,
292 const Handle(Geom2d_Curve)& aC2D,
293 Handle(Geom2d_Curve)& aC2DA)
295 BRepAdaptor_Surface aBAS(aF, Standard_True);
297 BOPTools_AlgoTools2D::AdjustPCurveOnFace(aBAS, aT1, aT2,
301 //=======================================================================
302 //function : AdjustPCurveOnFace
304 //=======================================================================
305 void BOPTools_AlgoTools2D::AdjustPCurveOnFace
306 (const BRepAdaptor_Surface& aBAS,
307 const Standard_Real aFirst,
308 const Standard_Real aLast,
309 const Handle(Geom2d_Curve)& aC2D,
310 Handle(Geom2d_Curve)& aC2DA)
312 Standard_Boolean mincond, maxcond;
313 Standard_Real UMin, UMax, VMin, VMax, aT, u2, v2, du, dv, aDelta;
314 Standard_Real aUPeriod;
316 const TopoDS_Face& aF=aBAS.Face();
317 UMin=aBAS.FirstUParameter();
318 UMax=aBAS.LastUParameter();
319 VMin=aBAS.FirstVParameter();
320 VMax=aBAS.LastVParameter();
322 //BRepAdaptor_Surface aBAS(aF, Standard_False);
323 //BRepTools::UVBounds(aF, UMin, UMax, VMin, VMax);
325 aDelta=Precision::PConfusion();
327 aT =.5*(aFirst+aLast);
337 if (aBAS.IsUPeriodic()) {
338 aUPeriod = aBAS.UPeriod();
341 // a. try to clarify u2 using the precision (aDelta)
342 if (fabs(u2-UMin) < aDelta) {
345 else if (fabs(u2-UMin-aUPeriod) < aDelta) {
348 // b. compute du again using clarified value of u2
349 GeomInt::AdjustPeriodic(u2, UMin, UMax, aUPeriod, u2, du, 0.);
352 if (aBAS.GetType()==GeomAbs_Cylinder) {
353 Standard_Real aR, dFi, aTol;
355 gp_Cylinder aCylinder=aBAS.Cylinder();
356 aR=aCylinder.Radius();
357 aTol=MaxToleranceEdge(aF);
363 mincond = (UMin - u2 > dFi);
364 maxcond = (u2 - UMax > dFi);
365 if (mincond || maxcond) {
366 du = ( mincond ) ? aUPeriod : -aUPeriod;
374 if (aBAS.IsVPeriodic()) {
375 Standard_Real aVPeriod, aVm, aVr, aVmid, dVm, dVr;
377 aVPeriod = aBAS.VPeriod();
378 mincond = (VMin - v2 > aDelta);
379 maxcond = (v2 - VMax > aDelta);
381 if (mincond || maxcond) {
382 dv = ( mincond ) ? aVPeriod : -aVPeriod;
385 if ((VMax-VMin<aVPeriod) && dv) {
388 aVmid=0.5*(VMin+VMax);
398 //check the point with classifier
402 if (aBAS.IsUPeriodic()) {
403 aUPeriod = aBAS.UPeriod();
404 if ((UMax - UMin - 2*aDelta) > aUPeriod) {
405 if ((u > (UMin + aDelta + aUPeriod)) ||
406 (u < (UMax - aDelta - aUPeriod))) {
407 BRepClass_FaceClassifier aClassifier;
408 aClassifier.Perform(aF, gp_Pnt2d(u, v), aDelta);
409 TopAbs_State Status = aClassifier.State();
410 if (Status == TopAbs_OUT) {
411 du += (u > (UMin + aDelta + aUPeriod)) ? -aUPeriod : aUPeriod;
418 if (aBAS.IsVPeriodic()) {
419 Standard_Real aVPeriod = aBAS.VPeriod();
420 if ((VMax - VMin - 2*aDelta) > aVPeriod) {
421 if ((v > (VMin + aDelta + aVPeriod)) ||
422 (v < (VMax - aDelta - aVPeriod))) {
423 BRepClass_FaceClassifier aClassifier;
424 aClassifier.Perform(aF, gp_Pnt2d(u, v), aDelta);
425 TopAbs_State Status = aClassifier.State();
426 if (Status == TopAbs_OUT) {
427 dv += (v > (VMin + aDelta + aVPeriod)) ? -aVPeriod : aVPeriod;
433 // Translation if necessary
434 Handle(Geom2d_Curve) aC2Dx=aC2D;
436 if ( du != 0. || dv != 0.) {
437 Handle(Geom2d_Curve) PCT = Handle(Geom2d_Curve)::DownCast(aC2Dx->Copy());
438 gp_Vec2d aV2D(du,dv);
439 PCT->Translate(aV2D);
446 //=======================================================================
447 //function : IntermediatePoint
449 //=======================================================================
450 Standard_Real BOPTools_AlgoTools2D::IntermediatePoint
451 (const Standard_Real aFirst,
452 const Standard_Real aLast)
454 //define parameter division number as 10*e^(-PI) = 0.43213918
455 const Standard_Real PAR_T = 0.43213918;
457 aParm=(1.-PAR_T)*aFirst + PAR_T*aLast;
460 //=======================================================================
461 //function : IntermediatePoint
463 //=======================================================================
464 Standard_Real BOPTools_AlgoTools2D::IntermediatePoint
465 (const TopoDS_Edge& aE)
468 Standard_Real aT, aT1, aT2;
470 Handle(Geom_Curve)aC1=BRep_Tool::Curve(aE, aT1, aT2);
472 BRep_Tool::Range(aE, aT1, aT2);
474 aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2);
478 //=======================================================================
479 //function : BuildPCurveForEdgeOnPlane
481 //=======================================================================
482 void BOPTools_AlgoTools2D::BuildPCurveForEdgeOnPlane
483 (const TopoDS_Edge& aE,
484 const TopoDS_Face& aF)
486 Standard_Boolean bToUpdate;
487 Standard_Real aTolE, aT1, aT2;
488 Handle(Geom2d_Curve) aC2D;
491 aC2D=BRep_Tool_CurveOnSurface(aE, aF, aT1, aT2, bToUpdate);
493 aTolE=BRep_Tool::Tolerance(aE);
494 aBB.UpdateEdge(aE, aC2D, aF, aTolE);
498 //=======================================================================
499 //function : BuildPCurveForEdgeOnPlane
501 //=======================================================================
502 void BOPTools_AlgoTools2D::BuildPCurveForEdgeOnPlane
503 (const TopoDS_Edge& aE,
504 const TopoDS_Face& aF,
505 Handle(Geom2d_Curve)& aC2D,
506 Standard_Boolean& bToUpdate)
508 Standard_Real aT1, aT2;
509 aC2D=BRep_Tool_CurveOnSurface(aE, aF, aT1, aT2, bToUpdate);
512 //=======================================================================
513 // function: BuildPCurveForEdgesOnPlane
515 //=======================================================================
516 void BOPTools_AlgoTools2D::BuildPCurveForEdgesOnPlane
517 (const BOPCol_ListOfShape& aLE,
518 const TopoDS_Face& aF)
520 BOPCol_ListIteratorOfListOfShape aIt;
523 for(; aIt.More(); aIt.Next()) {
524 const TopoDS_Edge& aE=(*(TopoDS_Edge *)&aIt.Value());
525 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnPlane (aE, aF);
528 //=======================================================================
531 //=======================================================================
532 void BOPTools_AlgoTools2D::Make2D (const TopoDS_Edge& aE,
533 const TopoDS_Face& aF,
534 Handle(Geom2d_Curve)& aC2D,
535 Standard_Real& aFirst,
536 Standard_Real& aLast,
537 Standard_Real& aToler)
539 Standard_Boolean aLocIdentity;
540 Standard_Real f3d, l3d;
541 TopLoc_Location aLoc;
543 Handle(Geom2d_Curve) C2D;
546 C2D=BRep_Tool::CurveOnSurface(aE, aF, aFirst, aLast);
553 Handle(Geom_Curve) C3D2, C3D;
554 C3D = BRep_Tool::Curve(aE, aLoc, f3d, l3d);
557 // aE has no 3D curve, so nothing is done
560 aLocIdentity=aLoc.IsIdentity();
566 C3D2 = Handle(Geom_Curve)::
567 DownCast(C3D->Transformed(aLoc.Transformation()));
571 aToler = BRep_Tool::Tolerance(aE);
572 BOPTools_AlgoTools2D::MakePCurveOnFace(aF, C3D2, f3d, l3d, aC2D, aToler);
578 //=======================================================================
579 //function : MakePCurveOnFace
581 //=======================================================================
582 void BOPTools_AlgoTools2D::MakePCurveOnFace (const TopoDS_Face& aF,
583 const Handle(Geom_Curve)& aC3D,
584 Handle(Geom2d_Curve)& aC2D, //->
585 Standard_Real& TolReached2d)
587 Standard_Real aFirst, aLast;
589 aFirst = aC3D -> FirstParameter();
590 aLast = aC3D -> LastParameter();
594 BOPTools_AlgoTools2D::MakePCurveOnFace (aF, aC3D, aFirst,
595 aLast, aC2D, TolReached2d);
598 //=======================================================================
599 //function : MakePCurveOnFace
601 //=======================================================================
602 void BOPTools_AlgoTools2D::MakePCurveOnFace
603 (const TopoDS_Face& aF,
604 const Handle(Geom_Curve)& aC3D,
605 const Standard_Real aT1,
606 const Standard_Real aT2,
607 Handle(Geom2d_Curve)& aC2D,
608 Standard_Real& TolReached2d)
610 Standard_Real aTolR, aT;
611 Standard_Real aUMin, aUMax, aVMin, aVMax;
612 Handle(Geom2d_Curve) aC2DA;
613 Handle(GeomAdaptor_HSurface) aBAHS;
614 Handle(GeomAdaptor_HCurve) aBAHC;
615 Handle(Geom_Surface) aS;
617 BRepAdaptor_Surface aBAS(aF, Standard_True);
618 aUMin=aBAS.FirstUParameter();
619 aUMax=aBAS.LastUParameter();
620 aVMin=aBAS.FirstVParameter();
621 aVMax=aBAS.LastVParameter();
622 aS=aBAS.Surface().Surface();
623 aS=Handle(Geom_Surface)::DownCast(aS->Transformed(aBAS.Trsf()));
624 GeomAdaptor_Surface aGAS(aS, aUMin, aUMax, aVMin, aVMax);
626 aBAHS=new GeomAdaptor_HSurface(aGAS);
627 aBAHC=new GeomAdaptor_HCurve(aC3D, aT1, aT2);
629 //when the type of surface is GeomAbs_SurfaceOfRevolution
630 if (aGAS.GetType() == GeomAbs_SurfaceOfRevolution) {
633 aTR=Precision::Confusion();//1.e-7;
634 if (TolReached2d > aTR) {
638 ProjLib_ProjectedCurve aProj1(aBAHS, aBAHC, aTR);
639 BOPTools_AlgoTools2D::MakePCurveOfType(aProj1, aC2D);
640 aTolR = aProj1.GetTolerance();
643 ProjLib_ProjectedCurve aProjCurv(aBAHS, aBAHC);// 1
644 BOPTools_AlgoTools2D::MakePCurveOfType(aProjCurv, aC2D);
645 aTolR=aProjCurv.GetTolerance();
649 ProjLib_ProjectedCurve aProjCurvAgain(aBAHS, aBAHC, TolReached2d);// 2
650 BOPTools_AlgoTools2D::MakePCurveOfType(aProjCurvAgain, aC2D);
651 aTolR = aProjCurvAgain.GetTolerance();
654 Standard_Real aTR=0.0001;
655 ProjLib_ProjectedCurve aProj3(aBAHS, aBAHC, aTR);// 3
656 BOPTools_AlgoTools2D::MakePCurveOfType(aProj3, aC2D);
657 aTolR = aProj3.GetTolerance();
663 Standard_ConstructionError::Raise("BOPTools_AlgoTools2D::MakePCurveOnFace : PCurve is Null");
667 BOPTools_AlgoTools2D::AdjustPCurveOnFace (aBAS, aT1, aT2,
672 // compute the appropriate tolerance for the edge
673 if (IntTools_Tools::ComputeTolerance
674 (aC3D, aC2D, aS, aT1, aT2, aTolR, aT)) {
675 if (aTolR > TolReached2d) {
676 TolReached2d = aTolR;
681 //=======================================================================
682 //function : MakePCurveOfType
684 //=======================================================================
685 void BOPTools_AlgoTools2D::MakePCurveOfType
686 (const ProjLib_ProjectedCurve& PC,
687 Handle(Geom2d_Curve)& C2D)
690 switch (PC.GetType()) {
693 C2D = new Geom2d_Line(PC.Line());
695 case GeomAbs_Circle :
696 C2D = new Geom2d_Circle(PC.Circle());
698 case GeomAbs_Ellipse :
699 C2D = new Geom2d_Ellipse(PC.Ellipse());
701 case GeomAbs_Parabola :
702 C2D = new Geom2d_Parabola(PC.Parabola());
704 case GeomAbs_Hyperbola :
705 C2D = new Geom2d_Hyperbola(PC.Hyperbola());
707 case GeomAbs_BSplineCurve :
710 case GeomAbs_BezierCurve :
711 case GeomAbs_OtherCurve :
713 Standard_NotImplemented::Raise
714 ("BOPTools_AlgoTools2D::MakePCurveOfType");
718 //=======================================================================
719 //function : CheckEdgeLength
721 //=======================================================================
722 Standard_Boolean CheckEdgeLength (const TopoDS_Edge& E)
724 BRepAdaptor_Curve BC(E);
726 BOPCol_IndexedMapOfShape aM;
727 BOPTools::MapShapes(E, TopAbs_VERTEX, aM);
728 Standard_Integer i, anExtent, aN=10;
729 Standard_Real ln=0., d, t, f, l, dt;
730 anExtent=aM.Extent();
733 return Standard_True;
736 f = BC.FirstParameter();
737 l = BC.LastParameter();
741 for (i=1; i<=aN; i++) {
754 return (ln > Precision::Confusion());
756 //=======================================================================
757 //function : BRep_Tool_CurveOnSurface
759 //=======================================================================
760 Handle(Geom2d_Curve) BRep_Tool_CurveOnSurface(const TopoDS_Edge& E,
761 const TopoDS_Face& F,
762 Standard_Real& First,
764 Standard_Boolean& bToUpdate)
767 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
768 TopoDS_Edge aLocalEdge = E;
769 if (F.Orientation() == TopAbs_REVERSED) {
770 aLocalEdge.Reverse();
773 return BRep_Tool_CurveOnSurface(aLocalEdge,S,l,First,Last,bToUpdate);
775 //=======================================================================
776 //function : BRep_Tool_CurveOnSurface
778 //=======================================================================
779 Handle(Geom2d_Curve) BRep_Tool_CurveOnSurface
780 (const TopoDS_Edge& E,
781 const Handle(Geom_Surface)& S,
782 const TopLoc_Location& L,
783 Standard_Real& First,
785 Standard_Boolean& bToUpdate)
787 static const Handle(Geom2d_Curve) nullPCurve;
788 bToUpdate=Standard_False;
789 TopLoc_Location loc = L.Predivided(E.Location());
790 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
792 // find the representation
793 BRep_ListIteratorOfListOfCurveRepresentation itcr
794 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
796 while (itcr.More()) {
797 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
798 if (cr->IsCurveOnSurface(S,loc)) {
799 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr));
800 GC->Range(First,Last);
801 if (GC->IsCurveOnClosedSurface() && Eisreversed)
802 return GC->PCurve2();
809 // for planar surface and 3d curve try a projection
810 // modif 21-05-97 : for RectangularTrimmedSurface, try a projection
811 Handle(Geom_Plane) GP;
812 Handle(Geom_RectangularTrimmedSurface) GRTS;
813 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
815 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
817 GP = Handle(Geom_Plane)::DownCast(S);
818 //fin modif du 21-05-97
822 Handle(GeomAdaptor_HCurve) HC;
823 Handle(GeomAdaptor_HSurface) HS;
825 HC = new GeomAdaptor_HCurve();
826 HS = new GeomAdaptor_HSurface();
830 Standard_Real f, l;// for those who call with (u,u).
831 Handle(Geom_Curve) C3d =
832 BRep_Tool::Curve(E,/*LC,*/f,l); // transforming plane instead of curve
833 // we can loose scale factor of Curve transformation (eap 13 May 2002)
835 LC = L/*.Predivided(LC)*/;
837 if (C3d.IsNull()) return nullPCurve;
839 Handle(Geom_Plane) Plane = GP;
840 if (!LC.IsIdentity()) {
841 const gp_Trsf& T = LC.Transformation();
842 Handle(Geom_Geometry) GPT = GP->Transformed(T);
843 Plane = Handle(Geom_Plane)::DownCast (GPT);
845 GeomAdaptor_Surface& GAS = HS->ChangeSurface();
848 Handle(Geom_Curve) ProjOnPlane =
849 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l),
851 Plane->Position().Direction(),
854 GeomAdaptor_Curve& GAC = HC->ChangeCurve();
855 GAC.Load(ProjOnPlane);
857 ProjLib_ProjectedCurve Proj(HS,HC);
858 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
860 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
861 Handle(Geom2d_TrimmedCurve) TC =
862 Handle(Geom2d_TrimmedCurve)::DownCast (pc);
863 pc = TC->BasisCurve();
867 bToUpdate=Standard_True;
874 //=======================================================================
875 //function : MaxToleranceEdge
877 //=======================================================================
878 Standard_Real MaxToleranceEdge (const TopoDS_Face& aF)
880 Standard_Real aTol, aTolMax;
881 TopExp_Explorer aExp;
884 aExp.Init(aF, TopAbs_EDGE);
885 for (; aExp.More(); aExp.Next()) {
886 const TopoDS_Edge& aE=*((TopoDS_Edge *)&aExp.Current());
887 aTol=BRep_Tool::Tolerance(aE);