Salome HOME
Porting on OCCT 7.4.0
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SensitivePoint.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SketcherPrs_SensitivePoint.h"
21 #include "SketcherPrs_SymbolPrs.h"
22
23 #include <Graphic3d_ArrayOfPoints.hxx>
24 #include <Standard_Version.hxx>
25
26 #define DEBUG_SENSITIVE_TO_BE_CORRECTED
27
28 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
29
30 SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(
31   const Handle(SelectBasics_EntityOwner)& anOwner, int theId)
32 :Select3D_SensitiveEntity(anOwner), myId(theId)
33 {
34   SetSensitivityFactor(12);
35 }
36
37 Standard_Boolean SketcherPrs_SensitivePoint::Matches(SelectBasics_SelectingVolumeManager& theMgr,
38                                                    SelectBasics_PickResult& thePickResult)
39 {
40 #if OCC_VERSION_HEX < 0x070400
41         Standard_Real aDepth = RealLast();
42         Standard_Real aDistToCOG = RealLast();
43         gp_Pnt aPnt = Point();
44         if (!theMgr.Overlaps(aPnt, aDepth))
45         {
46                 thePickResult = SelectBasics_PickResult(aDepth, aDistToCOG);
47                 return Standard_False;
48         }
49
50         aDistToCOG = aDepth;
51         thePickResult = SelectBasics_PickResult(aDepth, aDistToCOG);
52         return Standard_True;
53 #else
54   gp_Pnt aPnt = Point();
55   if (theMgr.Overlaps (aPnt, thePickResult))
56         return Standard_True;
57   return Standard_False;
58 #endif
59 }
60
61 gp_Pnt SketcherPrs_SensitivePoint::Point() const
62 {
63   const Handle(SelectMgr_EntityOwner)& anOwner =
64     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
65   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
66     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
67   return aSymbPrs->pointsArray()->Vertice(myId);
68 }
69
70 Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected()
71 {
72   Handle(SketcherPrs_SensitivePoint) aNewEntity = new SketcherPrs_SensitivePoint (myOwnerId, myId);
73   return aNewEntity;
74 }
75
76 gp_Pnt SketcherPrs_SensitivePoint::CenterOfGeometry() const
77 {
78 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
79   const Handle(SelectMgr_EntityOwner)& anOwner =
80     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
81   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
82     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
83   if (aSymbPrs->pointsArray()->VertexNumber() < myId)
84     return gp_Pnt();
85 #endif
86   return Point();
87 }
88
89 Select3D_BndBox3d SketcherPrs_SensitivePoint::BoundingBox()
90 {
91 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
92   const Handle(SelectMgr_EntityOwner)& anOwner =
93     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
94   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
95     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
96   if (aSymbPrs->pointsArray()->VertexNumber() < myId)
97     return Select3D_BndBox3d();
98 #endif
99   gp_Pnt aPnt = Point();
100   return Select3D_BndBox3d (SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()),
101                             SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()));
102 }
103
104 Standard_Integer SketcherPrs_SensitivePoint::NbSubElements()
105 {
106   return 1;
107 }
108
109 void SketcherPrs_SensitivePoint::Clear()
110 {
111   return;
112 }