// File: Select3D_SensitiveCircle.cxx // Created: Tue Feb 6 14:15:06 1996 // Author: Robert COUBLANC // // Modified Tue Apr 14 1998 by rob : fix Bug : Case of Null Radius Circle... #include #include #include #include #include #include #include #include //======================================================================= //function : Select3D_SensitiveCircle (constructeur) //purpose : Definition of a sensitive circle //======================================================================= static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C, const Standard_Integer anInputNumber) { if(C->Radius()>Precision::Confusion()) return 2*anInputNumber+1; return 1; } static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C, const Standard_Integer anInputNumber) { if(C->Radius()>Precision::Confusion()) return 2*anInputNumber-1; return 1; } Select3D_SensitiveCircle:: Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, const Handle(Geom_Circle)& TheCircle, const Standard_Boolean FilledCircle, const Standard_Integer NbPoints): Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)), myFillStatus(FilledCircle), myDetectedIndex(-1) { if(mynbpoints!=1){ gp_Pnt p1,p2;//,pmid; gp_Vec v1;//,v2; Standard_Real ustart = TheCircle->FirstParameter(),uend = TheCircle->LastParameter(); Standard_Real du = (uend-ustart)/NbPoints; Standard_Real R = TheCircle->Radius(); Standard_Integer rank = 1; Standard_Real curu =ustart; for(Standard_Integer i=1;i<=NbPoints;i++) { TheCircle->D1(curu,p1,v1); v1.Normalize(); ((Select3D_Pnt*)mypolyg3d)[rank-1] = p1; rank++; p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R, p1.Y()+v1.Y()*tan(du/2.)*R, p1.Z()+v1.Z()*tan(du/2.)*R); ((Select3D_Pnt*)mypolyg3d)[rank-1] = p2; rank++; curu+=du; } ((Select3D_Pnt*)mypolyg3d)[NbPoints*2] = ((Select3D_Pnt*)mypolyg3d)[0]; } // Radius = 0.0 else ((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location(); } //======================================================================= //function : Select3D_SensitiveCircle (constructeur) //purpose : Definition of a sensitive arc //======================================================================= Select3D_SensitiveCircle:: Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, const Handle(Geom_Circle)& TheCircle, const Standard_Real u1, const Standard_Real u2, const Standard_Boolean FilledCircle, const Standard_Integer NbPoints): Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)), myFillStatus(FilledCircle), myDetectedIndex(-1) { if(mynbpoints > 1){ gp_Pnt p1,p2;//,pmid; gp_Vec v1;//,v2; Standard_Real ustart = u1; Standard_Real uend = u2; if (u1 > u2) {ustart=u1;uend=u2;} Standard_Real du = (uend-ustart)/(NbPoints-1); Standard_Real R = TheCircle->Radius(); Standard_Integer rank = 1; Standard_Real curu =ustart; for(Standard_Integer i=1;i<=NbPoints-1;i++) { TheCircle->D1(curu,p1,v1); v1.Normalize(); ((Select3D_Pnt*)mypolyg3d)[rank-1] = p1; rank++; p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R, p1.Y()+v1.Y()*tan(du/2.)*R, p1.Z()+v1.Z()*tan(du/2.)*R); ((Select3D_Pnt*)mypolyg3d)[rank-1] = p2; rank++; curu+=du; } TheCircle->D0(uend,p1); ((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1; } else ((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location(); } //======================================================================= //function : Select3D_SensitiveCircle //purpose : //======================================================================= Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, const Handle(TColgp_HArray1OfPnt)& Thepolyg3d, const Standard_Boolean FilledCircle): Select3D_SensitivePoly(OwnerId, Thepolyg3d), myFillStatus(FilledCircle), myDetectedIndex(-1) { } Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, const TColgp_Array1OfPnt& Thepolyg3d, const Standard_Boolean FilledCircle): Select3D_SensitivePoly(OwnerId, Thepolyg3d), myFillStatus(FilledCircle), myDetectedIndex(-1) { } Standard_Boolean Select3D_SensitiveCircle:: Matches(const Standard_Real X, const Standard_Real Y, const Standard_Real aTol, Standard_Real& DMin) { // in case of Edge (for the face it is only checked if // the mouse point X,Y is found inside the triangle // pi,pi+1,pi+2 with close tolerance... if yes, finish... if(mynbpoints>1){ Standard_Boolean Found =Standard_False; Standard_Integer i = 0; //gp_Pnt2d p1,p2,p3,pg; if(!myFillStatus){ while(i < mynbpoints-2 && !Found) { Standard_Integer TheStat = Select3D_SensitiveTriangle::Status(((Select3D_Pnt2d*)mypolyg2d)[i], ((Select3D_Pnt2d*)mypolyg2d)[i+1], ((Select3D_Pnt2d*)mypolyg2d)[i+2], gp_XY(X,Y),aTol,DMin); Found = (TheStat!=2); if(Found) myDetectedIndex=i; i+=2; } } else { myDetectedIndex =-1; #ifndef DEB Standard_Real DMin2 = 0.; #else Standard_Real DMin2; #endif Standard_Real Xmin,Ymin,Xmax,Ymax; Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax); if(!Bnd_Box2d(mybox2d).IsVoid()) DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus(); TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints); Points2D(aArrayOf2dPnt); CSLib_Class2d TheInOutTool(aArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax); Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y)); Standard_Real aTol2 = aTol*aTol; if(TheStat!=1) { for(Standard_Integer I=0;i=0&& Rank