+
+//modified by NIZNHY-PKV Fri Feb 03 11:16:35 2012f
+//=======================================================================
+//function : BuildPCurveForEdgeOnFace
+//purpose :
+//=======================================================================
+Standard_Integer
+ GEOMAlgo_Tools::BuildPCurveForEdgeOnFace(const TopoDS_Edge& aEold,
+ const TopoDS_Edge& aEnew,
+ const TopoDS_Face& aF,
+ const Handle(IntTools_Context)& aCtx)
+{
+ Standard_Boolean bIsClosed, bUClosed, bHasOld;
+ Standard_Integer iRet, aNbPoints;
+ Standard_Real aTS, aTS1, aTS2, aT, aT1, aT2, aScPr, aTol;
+ Standard_Real aU, aV, aUS1, aVS1, aUS2, aVS2;
+ gp_Pnt aP;
+ gp_Pnt2d aP2DS1, aP2DS2, aP2D;
+ gp_Vec2d aV2DS1, aV2DS2;
+ Handle(Geom2d_Curve) aC2D, aC2DS1, aC2DS2;
+ Handle(Geom_Surface) aS;
+ TopoDS_Edge aES;
+ //
+ iRet=0;
+ //
+ bHasOld=BOPTools_Tools2D::HasCurveOnSurface(aEnew, aF, aC2D, aT1, aT2, aTol);
+ if (bHasOld) {
+ return iRet;
+ }
+ //
+ BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aEnew, aF);
+ aC2D=BRep_Tool::CurveOnSurface(aEnew, aF, aT1, aT2);
+ if (aC2D.IsNull()){
+ iRet=1;
+ return iRet;
+ }
+ //
+ bIsClosed=BRep_Tool::IsClosed(aEold, aF);
+ if (!bIsClosed) {
+ return iRet;
+ }
+ //
+ aTol=1.e-7;
+ //
+ // 1. bUClosed - direction of closeness
+ //
+ aES=aEold;
+ aES.Orientation(TopAbs_FORWARD);
+ aC2DS1=BRep_Tool::CurveOnSurface(aES, aF, aTS1, aTS2);
+ //
+ aES.Orientation(TopAbs_REVERSED);
+ aC2DS2=BRep_Tool::CurveOnSurface(aES, aF, aTS1, aTS2);
+ //
+ aTS=BOPTools_Tools2D::IntermediatePoint(aTS1, aTS2);
+ //
+ aC2DS1->D1(aTS, aP2DS1, aV2DS1);
+ aC2DS2->D1(aTS, aP2DS2, aV2DS2);
+ //
+ gp_Vec2d aV2DS12(aP2DS1, aP2DS2);
+ gp_Dir2d aD2DS12(aV2DS12);
+ const gp_Dir2d& aD2DX=gp::DX2d();
+ //
+ aScPr=aD2DS12*aD2DX;
+ bUClosed=Standard_True;
+ if (fabs(aScPr) < aTol) {
+ bUClosed=!bUClosed;
+ }
+ //
+ // 2. aP2D - point on curve aC2D, that corresponds to aP2DS1
+ aP2DS1.Coord(aUS1, aVS1);
+ aP2DS2.Coord(aUS2, aVS2);
+ //
+ aS=BRep_Tool::Surface(aF);
+ aS->D0(aUS1, aVS1, aP);
+ //
+ GeomAPI_ProjectPointOnCurve& aProjPC=aCtx->ProjPC(aEnew);
+ //
+ aProjPC.Perform(aP);
+ aNbPoints=aProjPC.NbPoints();
+ if (!aNbPoints) {
+ iRet=2;
+ return iRet;
+ }
+ //
+ aT=aProjPC.LowerDistanceParameter();
+
+ //
+ // 3. Build the second 2D curve
+ Standard_Boolean bRevOrder;
+ gp_Vec2d aV2DT, aV2D;
+ Handle(Geom2d_Curve) aC2Dnew;
+ Handle(Geom2d_TrimmedCurve) aC2DTnew;
+ BRep_Builder aBB;
+ //
+ aC2D->D1(aT, aP2D, aV2D);
+ aP2D.Coord(aU, aV);
+ //
+ aC2Dnew=Handle(Geom2d_Curve)::DownCast(aC2D->Copy());
+ aC2DTnew = new Geom2d_TrimmedCurve(aC2Dnew, aT1, aT2);
+ //
+ aV2DT=aV2DS12;
+ if (!bUClosed) { // V Closed
+ if (fabs(aV-aVS2)<aTol) {
+ aV2DT.Reverse();
+ }
+ }
+ else { // U Closed
+ if (fabs(aU-aUS2)<aTol) {
+ aV2DT.Reverse();
+ }
+ }
+ //
+ aC2DTnew->Translate(aV2DT);
+ //
+ // 4 Order the 2D curves
+ bRevOrder=Standard_False;
+ aScPr=aV2D*aV2DS1;
+ if(aScPr<0.) {
+ bRevOrder=!bRevOrder;
+ }
+ //
+ // 5. Update the edge
+ aTol=BRep_Tool::Tolerance(aEnew);
+ if (!bRevOrder) {
+ aBB.UpdateEdge(aEnew, aC2D, aC2DTnew, aF, aTol);
+ }
+ else {
+ aBB.UpdateEdge(aEnew, aC2DTnew, aC2D , aF, aTol);
+ }
+ //
+ return iRet;
+}