0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Select3D / Select3D_SensitiveFace.cxx
index 2aa0b52..d45cde8 100755 (executable)
 
 #include <CSLib_Class2d.hxx>
 
-
-#define AutoInterMask  0x01
-#define AutoComputeMask  0x02
-// Standard_True if the flag is one
-#define AutoInterFlag(aflag)  ( aflag & AutoInterMask )
-#define AutoComputeFlag(aflag)  ( aflag & AutoComputeMask )
-// set the flag to one
-#define SetAutoInterFlag(aflag)  ( aflag = aflag & AutoInterMask)
-#define SetAutoComputeFlag(aflag)  ( aflag = aflag & AutoComputeMask)
-// Initialize flags
-#define AutoInitFlags(aflag) (aflag = 0)
-
 //==================================================
 // Function: Hide this constructor to the next version...
 // Purpose : simply avoid interfering with the version update
@@ -54,10 +42,8 @@ Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
                        const TColgp_Array1OfPnt& ThePoints,
                        const Select3D_TypeOfSensitivity aType):
 Select3D_SensitivePoly(OwnerId, ThePoints),
-mytype (aType),
-myDetectedIndex(-1)
+mytype (aType)
 {
-  AutoInitFlags(myautointer);
 }
 
 //==================================================
@@ -70,10 +56,8 @@ Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
                        const Handle(TColgp_HArray1OfPnt)& ThePoints,
                        const Select3D_TypeOfSensitivity aType):
 Select3D_SensitivePoly(OwnerId, ThePoints),
-mytype (aType),
-myDetectedIndex(-1)
+mytype (aType)
 {
-  AutoInitFlags(myautointer);
 }
 
 //==================================================
@@ -81,18 +65,12 @@ myDetectedIndex(-1)
 // Purpose :
 //==================================================
 
-Standard_Boolean Select3D_SensitiveFace::
-Matches(const Standard_Real X,
-        const Standard_Real Y,
-        const Standard_Real aTol,
-        Standard_Real& DMin)
+Standard_Boolean Select3D_SensitiveFace::Matches (const SelectBasics_PickArgs& thePickArgs,
+                                                  Standard_Real& theMatchDMin,
+                                                  Standard_Real& theMatchDepth)
 {
-#ifndef DEB
   Standard_Real DMin2 = 0.;
-#else
-  Standard_Real DMin2;
-#endif
-  Standard_Real Xmin,Ymin,Xmax,Ymax;
+  Standard_Real Xmin = 0.,Ymin = 0.,Xmax = 0.,Ymax = 0.;
   if(!Bnd_Box2d(mybox2d).IsVoid())
   {
     Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
@@ -102,7 +80,7 @@ Matches(const Standard_Real X,
   // from start Dmin = size of the bounding box 2D,
   // then min. distance of the polyhedron or cdg...
 
-  Standard_Real aTol2 = aTol*aTol;
+  Standard_Real aTol2 = thePickArgs.Tolerance() * thePickArgs.Tolerance();
   Standard_Integer aSize = mypolyg.Size(), anIndex;
   gp_XY CDG;
   for(anIndex=0;anIndex<aSize;++anIndex)
@@ -114,38 +92,45 @@ Matches(const Standard_Real X,
   {
     CDG/=(aSize-1);
   }
-  DMin2=Min(DMin2,gp_XY(CDG.X()-X,CDG.Y()-Y).SquareModulus());
-  DMin = Sqrt(DMin2);
+  DMin2 = Min (DMin2, gp_XY (CDG.X() - thePickArgs.X(), CDG.Y() - thePickArgs.Y()).SquareModulus());
+  theMatchDMin = Sqrt(DMin2);
 
   Standard_Boolean isplane2d(Standard_True);
 
   for(anIndex=1;anIndex<aSize;++anIndex)
   {
-    gp_XY V1(mypolyg.Pnt2d(anIndex)),V(X,Y);
+    gp_XY V1(mypolyg.Pnt2d(anIndex)),V(thePickArgs.X(), thePickArgs.Y());
     V1-=mypolyg.Pnt2d(anIndex-1);
     V-=mypolyg.Pnt2d(anIndex-1);
     Standard_Real Vector = V1^V;
     Standard_Real V1V1 = V1.SquareModulus();
-    DMin2 = 
-      (V1V1 <=aTol2) ? 
+    DMin2 =
+      (V1V1 <=aTol2) ?
     Min(DMin2,V.SquareModulus()): // if the segment is too small...
       Min(DMin2,Vector*Vector/V1V1);
     //cdg ...
     gp_XY PlaneTest(CDG);
     PlaneTest-=mypolyg.Pnt2d(anIndex-1);
     Standard_Real valtst = PlaneTest^V1;
-    if(isplane2d && Abs(valtst)>aTol) isplane2d=Standard_False;
+    if(isplane2d && Abs(valtst) > thePickArgs.Tolerance()) isplane2d=Standard_False;
   }
   if (isplane2d)
   {
-    return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
+    theMatchDepth = ComputeDepth (thePickArgs.PickLine(),
+                                  thePickArgs.DepthMin(),
+                                  thePickArgs.DepthMax());
+
+    return !thePickArgs.IsClipped (theMatchDepth);
   }
 
   //otherwise it is checked if the point is in the face...
   TColgp_Array1OfPnt2d aArrayOf2dPnt(1, aSize);
   Points2D(aArrayOf2dPnt);
-  CSLib_Class2d TheInOutTool(aArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax);
-  Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y));
+  CSLib_Class2d TheInOutTool (aArrayOf2dPnt,
+                              thePickArgs.Tolerance(),
+                              thePickArgs.Tolerance(),
+                              Xmin, Ymin, Xmax, Ymax);
+  Standard_Integer TheStat = TheInOutTool.SiDans (gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()));
 
   Standard_Boolean res(Standard_False);
   switch(TheStat)
@@ -160,14 +145,18 @@ Matches(const Standard_Real X,
   }
   if (res)
   {
-    return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
+    theMatchDepth = ComputeDepth (thePickArgs.PickLine(),
+                                  thePickArgs.DepthMin(),
+                                  thePickArgs.DepthMax());
+
+    return !thePickArgs.IsClipped (theMatchDepth);
   }
   return Standard_False;
 }
 
 //=======================================================================
 //function : Matches
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 Standard_Boolean Select3D_SensitiveFace::
@@ -190,7 +179,7 @@ Matches (const Standard_Real XMin,
 
 //=======================================================================
 //function : Matches
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 Standard_Boolean Select3D_SensitiveFace::
@@ -200,9 +189,6 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
 {
   Standard_Real Umin,Vmin,Umax,Vmax;
   aBox.Get(Umin,Vmin,Umax,Vmax);
-  Standard_Real Tolu,Tolv;
-  Tolu = 1e-7;
-  Tolv = 1e-7;
   CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
 
   gp_Pnt2d aPnt2d;
@@ -217,7 +203,7 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
 
 //=======================================================================
 //function : Dump
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
@@ -225,10 +211,10 @@ void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean Ful
   S<<"\tSensitiveFace 3D :"<<endl;;
   if(HasLocation())
     S<<"\t\tExisting Location"<<endl;
-  
-  if(mytype==Select3D_TOS_BOUNDARY) 
+
+  if(mytype==Select3D_TOS_BOUNDARY)
     S<<"\t\tSelection Of Bounding Polyline Only"<<endl;
-  
+
   if(FullDump)
   {
     S<<"\t\tNumber Of Points :"<<mypolyg.Size()<<endl;
@@ -238,34 +224,43 @@ void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean Ful
 
 //=======================================================================
 //function : ComputeDepth
-//purpose  : 
+//purpose  :
 //=======================================================================
 
-Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
+Standard_Real Select3D_SensitiveFace::ComputeDepth (const gp_Lin& thePickLine,
+                                                    const Standard_Real theDepthMin,
+                                                    const Standard_Real theDepthMax) const
 {
   Standard_Real aDepth = Precision::Infinite();
-
-  Standard_Real aDepthMin = !mylastprj.IsNull() ? mylastprj->DepthMin() : -Precision::Infinite();
-  Standard_Real aDepthMax = !mylastprj.IsNull() ? mylastprj->DepthMax() :  Precision::Infinite();
-  Standard_Real aDepthTest;
+  Standard_Real aPointDepth;
 
   for (Standard_Integer anIndex = 0; anIndex < mypolyg.Size()-1; ++anIndex)
   {
-    aDepthTest = ElCLib::Parameter (EyeLine, mypolyg.Pnt(anIndex));
-    if (aDepthTest < aDepth && (aDepthTest > aDepthMin) && (aDepthTest < aDepthMax))
+    aPointDepth = ElCLib::Parameter (thePickLine, mypolyg.Pnt(anIndex));
+    if (aPointDepth < aDepth && (aPointDepth > theDepthMin) && (aPointDepth < theDepthMax))
     {
-      aDepth = aDepthTest;
+      aDepth = aPointDepth;
     }
   }
   return aDepth;
 }
 
+//=======================================================================
+//function : ComputeDepth
+//purpose  :
+//=======================================================================
+
+void Select3D_SensitiveFace::ComputeDepth(const gp_Lin& /*theEyeLine*/) const
+{
+  // this method is obsolete.
+}
+
 //=======================================================================
 //function : GetConnected
-//purpose  : 
+//purpose  :
 //=======================================================================
 
-Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected(const TopLoc_Location &theLocation) 
+Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected(const TopLoc_Location &theLocation)
 {
   // Create a copy of this
   Standard_Integer aSize = mypolyg.Size();
@@ -284,4 +279,4 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected(const TopL
   aNewEntity->UpdateLocation(theLocation);
 
   return aNewEntity;
-}
\ No newline at end of file
+}