1 // Created on: 2016-03-02
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2016 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <MeshVS_SensitiveQuad.hxx>
17
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveQuad,Select3D_SensitiveEntity)18 IMPLEMENT_STANDARD_RTTIEXT (MeshVS_SensitiveQuad, Select3D_SensitiveEntity)
19
20 //=======================================================================
21 // function : Constructor
22 // purpose :
23 //=======================================================================
24 MeshVS_SensitiveQuad::MeshVS_SensitiveQuad (const Handle(SelectMgr_EntityOwner)& theOwner,
25 const TColgp_Array1OfPnt& theQuadVerts)
26 : Select3D_SensitiveEntity (theOwner)
27 {
28 const Standard_Integer aLowerIdx = theQuadVerts.Lower();
29 for (Standard_Integer aVertIdx = 0; aVertIdx < 4; ++aVertIdx)
30 {
31 myVertices[aVertIdx] = theQuadVerts.Value (aLowerIdx + aVertIdx);
32 }
33 }
34
35 //=======================================================================
36 // function : Constructor
37 // purpose :
38 //=======================================================================
MeshVS_SensitiveQuad(const Handle (SelectMgr_EntityOwner)& theOwner,const gp_Pnt & thePnt1,const gp_Pnt & thePnt2,const gp_Pnt & thePnt3,const gp_Pnt & thePnt4)39 MeshVS_SensitiveQuad::MeshVS_SensitiveQuad (const Handle(SelectMgr_EntityOwner)& theOwner,
40 const gp_Pnt& thePnt1,
41 const gp_Pnt& thePnt2,
42 const gp_Pnt& thePnt3,
43 const gp_Pnt& thePnt4)
44 : Select3D_SensitiveEntity (theOwner)
45 {
46 myVertices[0] = thePnt1;
47 myVertices[1] = thePnt2;
48 myVertices[2] = thePnt3;
49 myVertices[3] = thePnt4;
50 }
51
52 //=======================================================================
53 // function : GetConnected
54 // purpose :
55 //=======================================================================
Handle(Select3D_SensitiveEntity)56 Handle(Select3D_SensitiveEntity) MeshVS_SensitiveQuad::GetConnected()
57 {
58 return new MeshVS_SensitiveQuad (myOwnerId, myVertices[0], myVertices[1], myVertices[2], myVertices[3]);
59 }
60
61 //=======================================================================
62 // function : Matches
63 // purpose : Checks whether the box overlaps current selecting volume
64 //=======================================================================
Matches(SelectBasics_SelectingVolumeManager & theMgr,SelectBasics_PickResult & thePickResult)65 Standard_Boolean MeshVS_SensitiveQuad::Matches (SelectBasics_SelectingVolumeManager& theMgr,
66 SelectBasics_PickResult& thePickResult)
67 {
68 if (!theMgr.IsOverlapAllowed()) // check for inclusion
69 {
70 if (theMgr.GetActiveSelectionType() == SelectMgr_SelectionType_Polyline)
71 {
72 SelectBasics_PickResult aDummy;
73 return theMgr.OverlapsTriangle (myVertices[0], myVertices[1], myVertices[2], Select3D_TOS_INTERIOR, aDummy)
74 && theMgr.OverlapsTriangle (myVertices[0], myVertices[2], myVertices[3], Select3D_TOS_INTERIOR, aDummy);
75 }
76 for (Standard_Integer aPntIdx = 0; aPntIdx < 4; ++aPntIdx)
77 {
78 if (!theMgr.OverlapsPoint (myVertices[aPntIdx]))
79 return Standard_False;
80 }
81
82 return Standard_True;
83 }
84
85 // check for overlap
86 SelectBasics_PickResult aPickResult1, aPickResult2;
87 if (!theMgr.OverlapsTriangle (myVertices[0], myVertices[1], myVertices[2], Select3D_TOS_INTERIOR, aPickResult1)
88 && !theMgr.OverlapsTriangle (myVertices[0], myVertices[2], myVertices[3], Select3D_TOS_INTERIOR, aPickResult2))
89 {
90 return Standard_False;
91 }
92
93 thePickResult = SelectBasics_PickResult::Min (aPickResult1, aPickResult2);
94 thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter(CenterOfGeometry()));
95 return Standard_True;
96 }
97
98 //=======================================================================
99 // function : CenterOfGeometry
100 // purpose :
101 //=======================================================================
CenterOfGeometry() const102 gp_Pnt MeshVS_SensitiveQuad::CenterOfGeometry() const
103 {
104 gp_XYZ aSum (0.0, 0.0, 0.0);
105 for (Standard_Integer aPntIdx = 0; aPntIdx < 4; ++aPntIdx)
106 {
107 aSum += myVertices[aPntIdx].XYZ();
108 }
109
110 return aSum / 4.0;
111 }
112
113 //=======================================================================
114 // function : BoundingBox
115 // purpose :
116 //=======================================================================
BoundingBox()117 Select3D_BndBox3d MeshVS_SensitiveQuad::BoundingBox()
118 {
119 Select3D_BndBox3d aBox;
120 for (Standard_Integer aPntIdx = 0; aPntIdx < 4; ++aPntIdx)
121 {
122 aBox.Add (SelectMgr_Vec3 (myVertices[aPntIdx].X(),
123 myVertices[aPntIdx].Y(),
124 myVertices[aPntIdx].Z()));
125 }
126
127 return aBox;
128 }
129