1 // Created on: 2016-03-02
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <MeshVS_SensitiveQuad.hxx>
18 IMPLEMENT_STANDARD_RTTIEXT (MeshVS_SensitiveQuad, Select3D_SensitiveEntity)
20 //=======================================================================
21 // function : Constructor
23 //=======================================================================
24 MeshVS_SensitiveQuad::MeshVS_SensitiveQuad (const Handle(SelectMgr_EntityOwner)& theOwner,
25 const TColgp_Array1OfPnt& theQuadVerts)
26 : Select3D_SensitiveEntity (theOwner)
28 const Standard_Integer aLowerIdx = theQuadVerts.Lower();
29 for (Standard_Integer aVertIdx = 0; aVertIdx < 4; ++aVertIdx)
31 myVertices[aVertIdx] = theQuadVerts.Value (aLowerIdx + aVertIdx);
35 //=======================================================================
36 // function : Constructor
38 //=======================================================================
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)
46 myVertices[0] = thePnt1;
47 myVertices[1] = thePnt2;
48 myVertices[2] = thePnt3;
49 myVertices[3] = thePnt4;
52 //=======================================================================
53 // function : GetConnected
55 //=======================================================================
56 Handle(Select3D_SensitiveEntity) MeshVS_SensitiveQuad::GetConnected()
58 return new MeshVS_SensitiveQuad (myOwnerId, myVertices[0], myVertices[1], myVertices[2], myVertices[3]);
61 //=======================================================================
63 // purpose : Checks whether the box overlaps current selecting volume
64 //=======================================================================
65 Standard_Boolean MeshVS_SensitiveQuad::Matches (SelectBasics_SelectingVolumeManager& theMgr,
66 SelectBasics_PickResult& thePickResult)
68 if (!theMgr.IsOverlapAllowed()) // check for inclusion
70 for (Standard_Integer aPntIdx = 0; aPntIdx < 4; ++aPntIdx)
72 if (!theMgr.Overlaps (myVertices[aPntIdx]))
73 return Standard_False;
80 SelectBasics_PickResult aPickResult1, aPickResult2;
81 if (!theMgr.Overlaps (myVertices[0], myVertices[1], myVertices[2], Select3D_TOS_INTERIOR, aPickResult1)
82 && !theMgr.Overlaps (myVertices[0], myVertices[2], myVertices[3], Select3D_TOS_INTERIOR, aPickResult2))
84 return Standard_False;
87 thePickResult = SelectBasics_PickResult::Min (aPickResult1, aPickResult2);
88 thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter(CenterOfGeometry()));
92 //=======================================================================
93 // function : CenterOfGeometry
95 //=======================================================================
96 gp_Pnt MeshVS_SensitiveQuad::CenterOfGeometry() const
98 gp_XYZ aSum (0.0, 0.0, 0.0);
99 for (Standard_Integer aPntIdx = 0; aPntIdx < 4; ++aPntIdx)
101 aSum += myVertices[aPntIdx].XYZ();
107 //=======================================================================
108 // function : BoundingBox
110 //=======================================================================
111 Select3D_BndBox3d MeshVS_SensitiveQuad::BoundingBox()
113 Select3D_BndBox3d aBox;
114 for (Standard_Integer aPntIdx = 0; aPntIdx < 4; ++aPntIdx)
116 aBox.Add (SelectMgr_Vec3 (myVertices[aPntIdx].X(),
117 myVertices[aPntIdx].Y(),
118 myVertices[aPntIdx].Z()));