]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_SensitivePoint.cpp
Salome HOME
Issue #3086: Avoid crash when FeatureInfo is null.
[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
22 #include <Graphic3d_ArrayOfPoints.hxx>
23 #include "SketcherPrs_SymbolPrs.h"
24
25 #define DEBUG_SENSITIVE_TO_BE_CORRECTED
26
27 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
28
29 SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(
30   const Handle(SelectBasics_EntityOwner)& anOwner, int theId)
31 :Select3D_SensitiveEntity(anOwner), myId(theId)
32 {
33   SetSensitivityFactor(12);
34 }
35
36 Standard_Boolean SketcherPrs_SensitivePoint::Matches(SelectBasics_SelectingVolumeManager& theMgr,
37                                                    SelectBasics_PickResult& thePickResult)
38 {
39   Standard_Real aDepth      = RealLast();
40   Standard_Real aDistToCOG  = RealLast();
41   gp_Pnt aPnt = Point();
42   if (!theMgr.Overlaps (aPnt, aDepth))
43   {
44     thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
45     return Standard_False;
46   }
47
48   aDistToCOG = aDepth;
49   thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
50   return Standard_True;
51 }
52
53 gp_Pnt SketcherPrs_SensitivePoint::Point() const
54 {
55   const Handle(SelectMgr_EntityOwner)& anOwner =
56     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
57   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
58     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
59   return aSymbPrs->pointsArray()->Vertice(myId);
60 }
61
62 Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected()
63 {
64   Handle(SketcherPrs_SensitivePoint) aNewEntity = new SketcherPrs_SensitivePoint (myOwnerId, myId);
65   return aNewEntity;
66 }
67
68 gp_Pnt SketcherPrs_SensitivePoint::CenterOfGeometry() const
69 {
70 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
71   const Handle(SelectMgr_EntityOwner)& anOwner =
72     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
73   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
74     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
75   if (aSymbPrs->pointsArray()->VertexNumber() < myId)
76     return gp_Pnt();
77 #endif
78   return Point();
79 }
80
81 Select3D_BndBox3d SketcherPrs_SensitivePoint::BoundingBox()
82 {
83 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
84   const Handle(SelectMgr_EntityOwner)& anOwner =
85     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
86   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
87     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
88   if (aSymbPrs->pointsArray()->VertexNumber() < myId)
89     return Select3D_BndBox3d();
90 #endif
91   gp_Pnt aPnt = Point();
92   return Select3D_BndBox3d (SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()),
93                             SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()));
94 }
95
96 Standard_Integer SketcherPrs_SensitivePoint::NbSubElements()
97 {
98   return 1;
99 }
100
101 void SketcherPrs_SensitivePoint::Clear()
102 {
103   return;
104 }