#include <BRepAdaptor_HSurface.hxx>
#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
+
+//=======================================================================
+//function : ChFi3d_IsFirstInside
+//purpose :
+//=======================================================================
+Standard_Boolean ChFi3d_IsFirstInside(const Standard_Real theVal1,
+ const Standard_Real theVal2,
+ const Standard_Real theMin,
+ const Standard_Real theMax)
+{
+ Standard_Real IsFirstInside = (theMin < theVal1 && theVal1 < theMax);
+ Standard_Real IsSecondInside = (theMin < theVal2 && theVal2 < theMax);
+ if (IsFirstInside && !IsSecondInside)
+ return Standard_True;
+ if (!IsFirstInside && IsSecondInside)
+ return Standard_False;
+
+ if (IsFirstInside && IsSecondInside)
+ {
+ Standard_Real MinDistForFirst = Min(theVal1 - theMin, theMax - theVal1);
+ Standard_Real MinDistForSecond = Min(theVal2 - theMin, theMax - theVal2);
+ return (MinDistForFirst > MinDistForSecond);
+ }
+ else
+ {
+ cout<<endl<<"Both points outside!"<<endl;
+ return Standard_True;
+ }
+}
+
+//=======================================================================
+//function : ChFi3d_AdjustPCurve
+//purpose :
+//=======================================================================
+void ChFi3d_AdjustPCurve(Geom2dAdaptor_Curve& thePCurve,
+ const Standard_Real theCoordOnPCurve,
+ const Standard_Real theRefCoord,
+ const Standard_Real thePeriod,
+ const Standard_Boolean theInUdirection)
+{
+ Standard_Real aCoord = theCoordOnPCurve;
+ Standard_Real Sign = (aCoord < theRefCoord)? 1 : -1;
+
+ while (Abs(aCoord - theRefCoord) > thePeriod/2)
+ aCoord += Sign * thePeriod;
+
+ Standard_Real Offset = aCoord - theCoordOnPCurve;
+ gp_Vec2d OffsetVector;
+ if (theInUdirection)
+ OffsetVector.SetCoord(Offset, 0.);
+ else
+ OffsetVector.SetCoord(0., Offset);
+
+ Handle(Geom2d_Curve) aPCurve = thePCurve.Curve();
+ aPCurve->Translate(OffsetVector);
+ thePCurve.Load(aPCurve);
+}
+
//=======================================================================
//function : ChFi3d_InPeriod
//purpose :
gp_Pnt2d P2d;
if (Check2dDistance)
P2d = BRep_Tool::Parameters( Vtx, face );
- if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) {
+ if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,
+ fd2,pref2,p2,jf2,sens2,
+ face,P2d,Check2dDistance,enlarge)) {
u1 = p1; u2 = p2; ss = sameside; j1 = jf1; j2 = jf2; ff = face;
ok = 1;
}
gp_Pnt2d P2d;
if (Check2dDistance)
P2d = BRep_Tool::Parameters( Vtx, face );
- if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) {
+ if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,
+ fd2,pref2,p2,jf2,sens2,
+ face,P2d,Check2dDistance,enlarge)) {
Standard_Boolean restore =
ok && ((j1 == jf1 && sens1*(p1 - u1) > 0.) ||
(j2 == jf2 && sens2*(p2 - u2) > 0.));
gp_Pnt2d P2d;
if (Check2dDistance)
P2d = BRep_Tool::Parameters( Vtx, face );
- if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) {
+ if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,
+ fd2,pref2,p2,jf2,sens2,
+ face,P2d,Check2dDistance,enlarge)) {
Standard_Boolean restore =
ok && ((j1 == jf1 && sens1*(p1 - u1) > 0.) ||
(j2 == jf2 && sens2*(p2 - u2) > 0.));
gp_Pnt2d P2d;
if (Check2dDistance)
P2d = BRep_Tool::Parameters( Vtx, face );
- if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) {
+ if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,
+ fd2,pref2,p2,jf2,sens2,
+ face,P2d,Check2dDistance,enlarge)) {
Standard_Boolean restore =
ok && ((j1 == jf1 && sens1*(p1 - u1) > 0.) ||
(j2 == jf2 && sens2*(p2 - u2) > 0.));
//purpose :
//=======================================================================
Standard_Boolean ChFi3d_IntTraces(const Handle(ChFiDS_SurfData)& fd1,
- const Standard_Real pref1,
- Standard_Real& p1,
- const Standard_Integer jf1,
- const Standard_Integer sens1,
- const Handle(ChFiDS_SurfData)& fd2,
- const Standard_Real pref2,
- Standard_Real& p2,
- const Standard_Integer jf2,
- const Standard_Integer sens2,
- const gp_Pnt2d& RefP2d,
- const Standard_Boolean Check2dDistance,
- const Standard_Boolean enlarge)
+ const Standard_Real pref1,
+ Standard_Real& p1,
+ const Standard_Integer jf1,
+ const Standard_Integer sens1,
+ const Handle(ChFiDS_SurfData)& fd2,
+ const Standard_Real pref2,
+ Standard_Real& p2,
+ const Standard_Integer jf2,
+ const Standard_Integer sens2,
+ const TopoDS_Face& theFace,
+ const gp_Pnt2d& RefP2d,
+ const Standard_Boolean Check2dDistance,
+ const Standard_Boolean enlarge)
{
Geom2dAdaptor_Curve C1;
Geom2dAdaptor_Curve C2;
Intersection.Perform(C1,C2,
Precision::PIntersection(),
Precision::PIntersection());
+
+ if (!Intersection.IsDone() || Intersection.IsEmpty())
+ {
+ BRepAdaptor_Surface BAsurf(theFace, Standard_False);
+ if (BAsurf.IsUPeriodic())
+ {
+ //put the pcurves in the same parametric context
+ Standard_Real Uperiod = BAsurf.UPeriod();
+ Standard_Real Umin = BAsurf.FirstUParameter();
+ Standard_Real Umax = BAsurf.LastUParameter();
+ gp_Pnt2d Origin1 = C1.Value(0.);
+ gp_Pnt2d Origin2 = C2.Value(0.);
+ Standard_Boolean IsFirstPointInside =
+ ChFi3d_IsFirstInside(Origin1.X(), Origin2.X(), Umin, Umax);
+ if (IsFirstPointInside)
+ ChFi3d_AdjustPCurve(C2, Origin2.X(), Origin1.X(), Uperiod, Standard_True);
+ else
+ ChFi3d_AdjustPCurve(C1, Origin1.X(), Origin2.X(), Uperiod, Standard_True);
+ }
+ }
}
if (Intersection.IsDone()) {
if (!Intersection.IsEmpty()) {
// Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 Begin
// if(ChFi3d_IntTraces(prevsd,prevpar1,nprevpar1,1,1,
// nextsd,nextpar1,nnextpar1,1,-1,p2d)){
+ TopoDS_Face FaceOfPCurves = TopoDS::Face(DStr.Shape(prevsd->Index(1)));
if(ChFi3d_IntTraces(prevsd,prevpar1,nprevpar1,1,1,
- nextsd,nextpar1,nnextpar1,1,-1,p2d,
- Standard_False, Standard_True)){
+ nextsd,nextpar1,nnextpar1,1,-1,
+ FaceOfPCurves,p2d,Standard_False, Standard_True)){
// Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 End
previntf1.SetLastParameter(nprevpar1);
nextintf1.SetFirstParameter(nnextpar1);
// Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 Begin
// if(ChFi3d_IntTraces(prevsd,prevpar2,nprevpar2,2,1,
// nextsd,nextpar2,nnextpar2,2,-1,p2d)){
+ TopoDS_Face FaceOfPCurves = TopoDS::Face(DStr.Shape(prevsd->Index(2)));
if(ChFi3d_IntTraces(prevsd,prevpar2,nprevpar2,2,1,
- nextsd,nextpar2,nnextpar2,2,-1,p2d,
- Standard_False, Standard_True)){
+ nextsd,nextpar2,nnextpar2,2,-1,
+ FaceOfPCurves,p2d,Standard_False, Standard_True)){
// Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 End
previntf2.SetLastParameter(nprevpar2);
nextintf2.SetFirstParameter(nnextpar2);