Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SensitivePoint.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_SensitivePoint.cpp
4 // Created:     24 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7
8 #include "SketcherPrs_SensitivePoint.h"
9
10 #include <Select3D_Projector.hxx>
11 #include <Bnd_Box2d.hxx>
12 #include <CSLib_Class2d.hxx>
13 #include <ElCLib.hxx>
14 #include <TopLoc_Location.hxx>
15 #include <SelectBasics_ListOfBox2d.hxx>
16
17 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
18 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
19
20 SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
21                                                         const Handle(Graphic3d_ArrayOfPoints)& thePntArray, 
22                                                         int theId)
23 :Select3D_SensitiveEntity(anOwner), myId(theId), myPntArray(thePntArray)
24 {
25   SetSensitivityFactor(4.);
26 }
27
28 void SketcherPrs_SensitivePoint::Project (const Handle(Select3D_Projector)& aProj)
29 {
30   gp_Pnt2d aPoint2d;
31   gp_Pnt aPnt = Point();
32   if(!HasLocation())
33     aProj->Project(aPnt, aPoint2d);
34   else
35   {
36     gp_Pnt aP(aPnt.X(), aPnt.Y(), aPnt.Z());
37     aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
38   }
39   myprojpt = aPoint2d;
40 }
41
42 void SketcherPrs_SensitivePoint::Areas(SelectBasics_ListOfBox2d& boxes)
43 {
44   Bnd_Box2d abox;
45   abox.Set(myprojpt);
46   boxes.Append(abox);
47 }
48
49 Standard_Boolean SketcherPrs_SensitivePoint::Matches(const SelectBasics_PickArgs& thePickArgs,
50                                                       Standard_Real& theMatchDMin,
51                                                       Standard_Real& theMatchDepth)
52 {
53   // check coordinate matching
54   Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
55   if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
56   {
57     return Standard_False;
58   }
59
60   Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
61   if (thePickArgs.IsClipped (aDepth))
62   {
63     return Standard_False;
64   }
65
66   theMatchDMin = aDist;
67   theMatchDepth = aDepth;
68   return Standard_True;
69 }
70
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)
76 {
77   Bnd_Box2d B;
78   B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
79   B.Enlarge(aTol);
80   return !B.IsOut(myprojpt);
81 }
82
83 Standard_Boolean SketcherPrs_SensitivePoint::Matches(const TColgp_Array1OfPnt2d& aPoly,
84                                                      const Bnd_Box2d& aBox,
85                                                      const Standard_Real aTol)
86 {
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);
90
91   Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
92   if(RES==1) return Standard_True;
93
94   return Standard_False;
95 }
96
97 gp_Pnt SketcherPrs_SensitivePoint::Point() const
98 {
99   return myPntArray->Vertice(myId);
100 }
101
102 Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
103 {
104   Handle(SketcherPrs_SensitivePoint) NiouEnt = new SketcherPrs_SensitivePoint(myOwnerId,myPntArray,myId);
105   if(HasLocation()) NiouEnt->SetLocation(Location());
106   NiouEnt->UpdateLocation(aLoc);
107   return NiouEnt;
108 }
109
110 void SketcherPrs_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
111 {
112   gp_Pnt aPnt = Point();
113   S<<"\tSensitivePoint 3D :";
114   if(HasLocation())
115     S<<"\t\tExisting Location"<<endl;
116
117   S<<"\t\t P3d [ "<<aPnt.X()<<" , "<<aPnt.Y()<<" , "<<aPnt.Z()<<" ]"<<endl;
118   S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
119 }
120
121 Standard_Real SketcherPrs_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
122 {
123   return ElCLib::Parameter(EyeLine, Point());
124 }