0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Select3D / Select3D_SensitiveSegment.cxx
index 3879f59..1476afc 100755 (executable)
@@ -1,8 +1,23 @@
-// Copyright:  Matra-Datavision 1995
-// File:       Select3D_SensitiveSegment.cxx
-// Created:    Wed Jan 25 11:27:54 1995
-// Author:     Mister rmi
-//             <rmi>
+// Created on: 1995-01-25
+// Created by: Mister rmi
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
 
 
 #include <Select3D_SensitiveSegment.ixx>
@@ -28,7 +43,7 @@
 //=====================================================
 
 Select3D_SensitiveSegment::
-Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId, 
+Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId,
                           const gp_Pnt& FirstP,
                           const gp_Pnt& LastP,
                           const Standard_Integer MaxRect):
@@ -47,18 +62,17 @@ mymaxrect(MaxRect)
 void Select3D_SensitiveSegment
 ::Project(const Handle(Select3D_Projector)& aProj)
 {
-  Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
   gp_Pnt2d aPoint2dStart;
   gp_Pnt2d aPoint2dEnd;
-  
-  if(HasLocation()) 
+
+  if(HasLocation())
   {
     gp_Pnt aStart(mystart.x, mystart.y, mystart.z);
     gp_Pnt aEnd(myend.x, myend.y, myend.z);
     aProj->Project(aStart.Transformed(Location().Transformation()),aPoint2dStart);
     aProj->Project(aEnd.Transformed(Location().Transformation()),aPoint2dEnd);
   }
-  else 
+  else
   {
     aProj->Project(mystart,aPoint2dStart);
     aProj->Project(myend,aPoint2dEnd);
@@ -68,7 +82,7 @@ void Select3D_SensitiveSegment
 }
 
 //=====================================================
-// Function : Areas 
+// Function : Areas
 // Purpose  :
 //=====================================================
 
@@ -77,30 +91,30 @@ void Select3D_SensitiveSegment
 {
 //  gp_Dir2d dy (0.,1.);
   gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
-  if(aPStart.Distance(myprojend)<=Precision::Confusion()) 
+  if(aPStart.Distance(myprojend)<=Precision::Confusion())
   {
       Bnd_Box2d curbox;
       curbox.Set(myprojstart);
       theareas.Append(curbox);
   }
-  else 
+  else
   {
     gp_Vec2d MyVec(myprojstart,myprojend);//,VAxx(gp_Dir2d(0.,1.));
     Standard_Real theangle = Abs(gp_Dir2d(0.,1.).Angle(gp_Vec2d(myprojstart,myprojend)));
     if(theangle>=M_PI/2.) theangle-=M_PI/2;
     if(theangle>=M_PI/12. && theangle <=5*M_PI/12.)
-      { 
-        TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1); 
+      {
+        TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1);
         BoxPoint (1) = myprojstart;
-        BoxPoint(mymaxrect+1)=myprojend; 
+        BoxPoint(mymaxrect+1)=myprojend;
         gp_Vec2d Vtr = MyVec/mymaxrect;
-        Standard_Integer i; 
-        for ( i=2;i<=mymaxrect;i++) 
-        { 
-          BoxPoint (i) = BoxPoint (i-1).Translated(Vtr); 
-        } 
-        for (i=2;i<=mymaxrect+1;i++) 
-        { 
+        Standard_Integer i;
+        for ( i=2;i<=mymaxrect;i++)
+        {
+          BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);
+        }
+        for (i=2;i<=mymaxrect+1;i++)
+        {
           Bnd_Box2d curbox;
           curbox.Set(BoxPoint(i-1));
           curbox.Add(BoxPoint(i));
@@ -108,10 +122,10 @@ void Select3D_SensitiveSegment
         }
       }
     else
-      { 
-        Bnd_Box2d curbox; 
-        curbox.Set(myprojstart); 
-        curbox.Add(myprojend); 
+      {
+        Bnd_Box2d curbox;
+        curbox.Set(myprojstart);
+        curbox.Add(myprojend);
         theareas.Append(curbox);
       }
   }
@@ -122,17 +136,24 @@ void Select3D_SensitiveSegment
 // Purpose  :
 //=====================================================
 
-Standard_Boolean Select3D_SensitiveSegment
-::Matches(const Standard_Real X,
-          const Standard_Real Y,
-          const Standard_Real aTol,
-          Standard_Real&  DMin)
+Standard_Boolean Select3D_SensitiveSegment::Matches (const SelectBasics_PickArgs& thePickArgs,
+                                                     Standard_Real& theMatchDMin,
+                                                     Standard_Real& theMatchDepth)
 {
-  gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
-  gp_Pnt2d aPEnd(myprojend.x,myprojend.y);
-  if ( ! SelectBasics_BasicTool::MatchSegment (aPStart, aPEnd, X, Y, aTol, DMin) )
+  gp_Pnt2d aPStart (myprojstart.x,myprojstart.y);
+  gp_Pnt2d aPEnd (myprojend.x,myprojend.y);
+  if (!SelectBasics_BasicTool::MatchSegment (aPStart, aPEnd,
+                                             thePickArgs.X(),
+                                             thePickArgs.Y(),
+                                             thePickArgs.Tolerance(),
+                                             theMatchDMin))
+  {
     return Standard_False;
-  return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); // compute and validate depth
+  }
+
+  theMatchDepth = ComputeDepth (thePickArgs.PickLine());
+
+  return !thePickArgs.IsClipped (theMatchDepth);
 }
 
 //=====================================================
@@ -156,19 +177,16 @@ Matches (const Standard_Real XMin,
 
 //=======================================================================
 //function : Matches
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 Standard_Boolean Select3D_SensitiveSegment::
 Matches (const TColgp_Array1OfPnt2d& aPoly,
          const Bnd_Box2d& aBox,
          const Standard_Real aTol)
-{ 
+{
   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);
 
   Standard_Integer RES = aClassifier2d.SiDans(myprojstart);
@@ -183,13 +201,13 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
 
 //=======================================================================
 //function : GetConnected
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 Handle(Select3D_SensitiveEntity) Select3D_SensitiveSegment::
-GetConnected(const TopLoc_Location& aLoc)  
+GetConnected(const TopLoc_Location& aLoc)
 {
-  Handle(Select3D_SensitiveSegment) NiouEnt = 
+  Handle(Select3D_SensitiveSegment) NiouEnt =
     new Select3D_SensitiveSegment(myOwnerId,mystart,myend,mymaxrect);
 
   if(HasLocation()) NiouEnt->SetLocation(Location());
@@ -199,10 +217,10 @@ GetConnected(const TopLoc_Location& aLoc)
 
 //=======================================================================
 //function : Dump
-//purpose  : 
+//purpose  :
 //=======================================================================
 
-void Select3D_SensitiveSegment::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
+void Select3D_SensitiveSegment::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
 {
   S<<"\tSensitivePoint 3D :"<<endl;
   if(HasLocation())
@@ -210,11 +228,11 @@ void Select3D_SensitiveSegment::Dump(Standard_OStream& S,const Standard_Boolean
   S<<"\t\t P1 [ "<<mystart.x<<" , "<<mystart.y <<" , "<<mystart.z <<" ]"<<endl;
   S<<"\t\t P2 [ "<<myend.x<<" , "<<myend.y <<" , "<<myend.z <<" ]"<<endl;
   S<<"\t\t maxrect ="<<mymaxrect<<endl;
-  
+
 }
 //=======================================================================
 //function : ComputeDepth
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 Standard_Real Select3D_SensitiveSegment::ComputeDepth(const gp_Lin& EyeLine) const