Salome HOME
Copyright update 2020
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SensitivePoint.cpp
index ac89d78a6b0f842d32bc1955300da516b5443785..2d8f18c9c2bed1ca7bbfd533c8038a7e2ba3290d 100644 (file)
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        SketcherPrs_SensitivePoint.cpp
-// Created:     24 March 2015
-// Author:      Vitaly SMETANNIKOV
-
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "SketcherPrs_SensitivePoint.h"
+#include "SketcherPrs_SymbolPrs.h"
+
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Standard_Version.hxx>
 
-#include <Select3D_Projector.hxx>
-#include <Bnd_Box2d.hxx>
-#include <CSLib_Class2d.hxx>
-#include <ElCLib.hxx>
-#include <TopLoc_Location.hxx>
-#include <SelectBasics_ListOfBox2d.hxx>
+#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;
+#if OCC_VERSION_HEX < 0x070400
+       Standard_Real aDepth = RealLast();
+       Standard_Real aDistToCOG = RealLast();
+       gp_Pnt aPnt = Point();
+       if (!theMgr.Overlaps(aPnt, aDepth))
+       {
+               thePickResult = SelectBasics_PickResult(aDepth, aDistToCOG);
+               return Standard_False;
+       }
+
+       aDistToCOG = aDepth;
+       thePickResult = SelectBasics_PickResult(aDepth, aDistToCOG);
+       return Standard_True;
+#else
   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))
-  {
-    return Standard_False;
-  }
-
-  theMatchDMin = aDist;
-  theMatchDepth = aDepth;
-  return Standard_True;
+  if (theMgr.Overlaps (aPnt, thePickResult))
+         return Standard_True;
+  return Standard_False;
+#endif
 }
 
-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;
 }