1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_SensitivePoint.cpp
4 // Created: 24 March 2015
5 // Author: Vitaly SMETANNIKOV
8 #include "SketcherPrs_SensitivePoint.h"
10 #include <Select3D_Projector.hxx>
11 #include <Bnd_Box2d.hxx>
12 #include <CSLib_Class2d.hxx>
14 #include <TopLoc_Location.hxx>
15 #include <SelectBasics_ListOfBox2d.hxx>
17 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
18 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
20 SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
21 const Handle(Graphic3d_ArrayOfPoints)& thePntArray,
23 :Select3D_SensitiveEntity(anOwner), myId(theId), myPntArray(thePntArray)
25 SetSensitivityFactor(4.);
28 void SketcherPrs_SensitivePoint::Project (const Handle(Select3D_Projector)& aProj)
31 gp_Pnt aPnt = Point();
33 aProj->Project(aPnt, aPoint2d);
36 gp_Pnt aP(aPnt.X(), aPnt.Y(), aPnt.Z());
37 aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
42 void SketcherPrs_SensitivePoint::Areas(SelectBasics_ListOfBox2d& boxes)
49 Standard_Boolean SketcherPrs_SensitivePoint::Matches(const SelectBasics_PickArgs& thePickArgs,
50 Standard_Real& theMatchDMin,
51 Standard_Real& theMatchDepth)
53 // check coordinate matching
54 Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
55 if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
57 return Standard_False;
60 Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
61 if (thePickArgs.IsClipped (aDepth))
63 return Standard_False;
67 theMatchDepth = aDepth;
71 Standard_Boolean SketcherPrs_SensitivePoint::Matches(const Standard_Real XMin,
72 const Standard_Real YMin,
73 const Standard_Real XMax,
74 const Standard_Real YMax,
75 const Standard_Real aTol)
78 B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
80 return !B.IsOut(myprojpt);
83 Standard_Boolean SketcherPrs_SensitivePoint::Matches(const TColgp_Array1OfPnt2d& aPoly,
84 const Bnd_Box2d& aBox,
85 const Standard_Real aTol)
87 Standard_Real Umin,Vmin,Umax,Vmax;
88 aBox.Get(Umin,Vmin,Umax,Vmax);
89 CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
91 Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
92 if(RES==1) return Standard_True;
94 return Standard_False;
97 gp_Pnt SketcherPrs_SensitivePoint::Point() const
99 return myPntArray->Vertice(myId);
102 Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
104 Handle(SketcherPrs_SensitivePoint) NiouEnt = new SketcherPrs_SensitivePoint(myOwnerId,myPntArray,myId);
105 if(HasLocation()) NiouEnt->SetLocation(Location());
106 NiouEnt->UpdateLocation(aLoc);
110 void SketcherPrs_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
112 gp_Pnt aPnt = Point();
113 S<<"\tSensitivePoint 3D :";
115 S<<"\t\tExisting Location"<<endl;
117 S<<"\t\t P3d [ "<<aPnt.X()<<" , "<<aPnt.Y()<<" , "<<aPnt.Z()<<" ]"<<endl;
118 S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
121 Standard_Real SketcherPrs_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
123 return ElCLib::Parameter(EyeLine, Point());