Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SensitivePoint.cpp
index ac89d78a6b0f842d32bc1955300da516b5443785..61c33fab80d3b361e4d5835095537ea1487cf1a2 100644 (file)
 
 #include "SketcherPrs_SensitivePoint.h"
 
-#include <Select3D_Projector.hxx>
-#include <Bnd_Box2d.hxx>
-#include <CSLib_Class2d.hxx>
-#include <ElCLib.hxx>
-#include <TopLoc_Location.hxx>
-#include <SelectBasics_ListOfBox2d.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include "SketcherPrs_SymbolPrs.h"
+
+#define DEBUG_SENSITIVE_TO_BE_CORRECTED
 
 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
 
-SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
-                                                        const Handle(Graphic3d_ArrayOfPoints)& thePntArray, 
-                                                        int theId)
-:Select3D_SensitiveEntity(anOwner), myId(theId), myPntArray(thePntArray)
+SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(
+  const Handle(SelectBasics_EntityOwner)& anOwner, int theId)
+:Select3D_SensitiveEntity(anOwner), myId(theId)
 {
-  SetSensitivityFactor(4.);
+  SetSensitivityFactor(12);
 }
 
-void SketcherPrs_SensitivePoint::Project (const Handle(Select3D_Projector)& aProj)
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(SelectBasics_SelectingVolumeManager& theMgr,
+                                                   SelectBasics_PickResult& thePickResult)
 {
-  gp_Pnt2d aPoint2d;
+  Standard_Real aDepth      = RealLast();
+  Standard_Real aDistToCOG  = RealLast();
   gp_Pnt aPnt = Point();
-  if(!HasLocation())
-    aProj->Project(aPnt, aPoint2d);
-  else
-  {
-    gp_Pnt aP(aPnt.X(), aPnt.Y(), aPnt.Z());
-    aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
-  }
-  myprojpt = aPoint2d;
-}
-
-void SketcherPrs_SensitivePoint::Areas(SelectBasics_ListOfBox2d& boxes)
-{
-  Bnd_Box2d abox;
-  abox.Set(myprojpt);
-  boxes.Append(abox);
-}
-
-Standard_Boolean SketcherPrs_SensitivePoint::Matches(const SelectBasics_PickArgs& thePickArgs,
-                                                      Standard_Real& theMatchDMin,
-                                                      Standard_Real& theMatchDepth)
-{
-  // check coordinate matching
-  Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
-  if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
-  {
-    return Standard_False;
-  }
-
-  Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
-  if (thePickArgs.IsClipped (aDepth))
+  if (!theMgr.Overlaps (aPnt, aDepth))
   {
+    thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
     return Standard_False;
   }
 
-  theMatchDMin = aDist;
-  theMatchDepth = aDepth;
+  aDistToCOG = aDepth;
+  thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
   return Standard_True;
 }
 
-Standard_Boolean SketcherPrs_SensitivePoint::Matches(const Standard_Real XMin,
-                                                     const Standard_Real YMin,
-                                                     const Standard_Real XMax,
-                                                     const Standard_Real YMax,
-                                                     const Standard_Real aTol)
+gp_Pnt SketcherPrs_SensitivePoint::Point() const
 {
-  Bnd_Box2d B;
-  B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
-  B.Enlarge(aTol);
-  return !B.IsOut(myprojpt);
+  const Handle(SelectMgr_EntityOwner)& anOwner =
+    Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
+  const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
+    Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
+  return aSymbPrs->pointsArray()->Vertice(myId);
 }
 
-Standard_Boolean SketcherPrs_SensitivePoint::Matches(const TColgp_Array1OfPnt2d& aPoly,
-                                                     const Bnd_Box2d& aBox,
-                                                     const Standard_Real aTol)
+Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected()
 {
-  Standard_Real Umin,Vmin,Umax,Vmax;
-  aBox.Get(Umin,Vmin,Umax,Vmax);
-  CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
-
-  Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
-  if(RES==1) return Standard_True;
-
-  return Standard_False;
+  Handle(SketcherPrs_SensitivePoint) aNewEntity = new SketcherPrs_SensitivePoint (myOwnerId, myId);
+  return aNewEntity;
 }
 
-gp_Pnt SketcherPrs_SensitivePoint::Point() const
+gp_Pnt SketcherPrs_SensitivePoint::CenterOfGeometry() const
 {
-  return myPntArray->Vertice(myId);
+#ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
+  const Handle(SelectMgr_EntityOwner)& anOwner =
+    Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
+  const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
+    Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
+  if (aSymbPrs->pointsArray()->VertexNumber() < myId)
+    return gp_Pnt();
+#endif
+  return Point();
 }
 
-Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
+Select3D_BndBox3d SketcherPrs_SensitivePoint::BoundingBox()
 {
-  Handle(SketcherPrs_SensitivePoint) NiouEnt = new SketcherPrs_SensitivePoint(myOwnerId,myPntArray,myId);
-  if(HasLocation()) NiouEnt->SetLocation(Location());
-  NiouEnt->UpdateLocation(aLoc);
-  return NiouEnt;
+#ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
+  const Handle(SelectMgr_EntityOwner)& anOwner =
+    Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
+  const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
+    Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
+  if (aSymbPrs->pointsArray()->VertexNumber() < myId)
+    return Select3D_BndBox3d();
+#endif
+  gp_Pnt aPnt = Point();
+  return Select3D_BndBox3d (SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()),
+                            SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()));
 }
 
-void SketcherPrs_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
+Standard_Integer SketcherPrs_SensitivePoint::NbSubElements()
 {
-  gp_Pnt aPnt = Point();
-  S<<"\tSensitivePoint 3D :";
-  if(HasLocation())
-    S<<"\t\tExisting Location"<<endl;
-
-  S<<"\t\t P3d [ "<<aPnt.X()<<" , "<<aPnt.Y()<<" , "<<aPnt.Z()<<" ]"<<endl;
-  S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
+  return 1;
 }
 
-Standard_Real SketcherPrs_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
+void SketcherPrs_SensitivePoint::Clear()
 {
-  return ElCLib::Parameter(EyeLine, Point());
+  return;
 }