Salome HOME
Issue 2229: additional fix for the interactive creation of the constraint.
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SensitivePoint.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "SketcherPrs_SensitivePoint.h"
22
23 #include <Graphic3d_ArrayOfPoints.hxx>
24 #include "SketcherPrs_SymbolPrs.h"
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   Standard_Real aDepth      = RealLast();
41   Standard_Real aDistToCOG  = RealLast();
42   gp_Pnt aPnt = Point();
43   if (!theMgr.Overlaps (aPnt, aDepth))
44   {
45     thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
46     return Standard_False;
47   }
48
49   aDistToCOG = aDepth;
50   thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
51   return Standard_True;
52 }
53
54 gp_Pnt SketcherPrs_SensitivePoint::Point() const
55 {
56   const Handle(SelectMgr_EntityOwner)& anOwner =
57     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
58   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
59     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
60   return aSymbPrs->pointsArray()->Vertice(myId);
61 }
62
63 Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected()
64 {
65   Handle(SketcherPrs_SensitivePoint) aNewEntity = new SketcherPrs_SensitivePoint (myOwnerId, myId);
66   return aNewEntity;
67 }
68
69 gp_Pnt SketcherPrs_SensitivePoint::CenterOfGeometry() const
70 {
71 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
72   const Handle(SelectMgr_EntityOwner)& anOwner =
73     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
74   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
75     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
76   if (aSymbPrs->pointsArray()->VertexNumber() < myId)
77     return gp_Pnt();
78 #endif
79   return Point();
80 }
81
82 Select3D_BndBox3d SketcherPrs_SensitivePoint::BoundingBox()
83 {
84 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
85   const Handle(SelectMgr_EntityOwner)& anOwner =
86     Handle(SelectMgr_EntityOwner)::DownCast(OwnerId());
87   const Handle(SketcherPrs_SymbolPrs)& aSymbPrs =
88     Handle(SketcherPrs_SymbolPrs)::DownCast(anOwner->Selectable());
89   if (aSymbPrs->pointsArray()->VertexNumber() < myId)
90     return Select3D_BndBox3d();
91 #endif
92   gp_Pnt aPnt = Point();
93   return Select3D_BndBox3d (SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()),
94                             SelectMgr_Vec3 (aPnt.X(), aPnt.Y(), aPnt.Z()));
95 }
96
97 Standard_Integer SketcherPrs_SensitivePoint::NbSubElements()
98 {
99   return 1;
100 }
101
102 void SketcherPrs_SensitivePoint::Clear()
103 {
104   return;
105 }