0031322: Visualization, Select3D_SensitiveEntity - method NbSubElements() should...
[occt.git] / src / MeshVS / MeshVS_SensitivePolyhedron.cxx
CommitLineData
b311480e 1// Created on: 2005-01-21
2// Created by: Alexander SOLOVYOV
973c2be1 3// Copyright (c) 2005-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
f751596e 16#include <MeshVS_SensitivePolyhedron.hxx>
7fd59977 17
f751596e 18#include <gp_Lin.hxx>
19#include <MeshVS_HArray1OfSequenceOfInteger.hxx>
7fd59977 20#include <MeshVS_Tool.hxx>
f751596e 21#include <NCollection_Vec4.hxx>
22#include <Select3D_SensitiveEntity.hxx>
f751596e 23#include <TColgp_Array1OfPnt.hxx>
24#include <TColgp_HArray1OfPnt.hxx>
25#include <TColgp_Array1OfPnt2d.hxx>
26#include <TColStd_SequenceOfInteger.hxx>
7fd59977 27
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitivePolyhedron,Select3D_SensitiveEntity)
30
7fd59977 31//================================================================
f751596e 32// Function : Constructor MeshVS_SensitivePolyhedron
7fd59977 33// Purpose :
34//================================================================
0ef04197 35MeshVS_SensitivePolyhedron::MeshVS_SensitivePolyhedron (const Handle(SelectMgr_EntityOwner)& theOwner,
f751596e 36 const TColgp_Array1OfPnt& theNodes,
37 const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo)
38: Select3D_SensitiveEntity (theOwner),
39 myTopo (theTopo)
7fd59977 40{
f751596e 41 Standard_Integer aPlaneLowIdx = theTopo->Lower();
42 Standard_Integer aPlaneUpIdx = theTopo->Upper();
43 Standard_Integer aNodesLowerIdx = theNodes.Lower();
44 myNodes = new TColgp_HArray1OfPnt (aNodesLowerIdx, theNodes.Upper());
45 myCenter = gp_XYZ (0.0, 0.0, 0.0);
7fd59977 46
f751596e 47 for (Standard_Integer aPlaneIdx = aPlaneLowIdx; aPlaneIdx <= aPlaneUpIdx; ++aPlaneIdx)
7fd59977 48 {
f751596e 49 Standard_Integer aVertNb = theTopo->Value (aPlaneIdx).Length();
50 Handle(TColgp_HArray1OfPnt) aVertArray = new TColgp_HArray1OfPnt (0, aVertNb - 1);
51 for (Standard_Integer aVertIdx = 1; aVertIdx <= aVertNb; ++aVertIdx)
52 {
53 Standard_Integer aNodeIdx = theTopo->Value (aPlaneIdx).Value (aVertIdx);
54 const gp_Pnt& aVert = theNodes.Value (aNodeIdx + aNodesLowerIdx);
55 aVertArray->SetValue (aVertIdx - 1, aVert);
56 myNodes->SetValue (aNodeIdx + aNodesLowerIdx, aVert);
57 myBndBox.Add (SelectMgr_Vec3 (aVert.X(), aVert.Y(), aVert.Z()));
58 myCenter += aVert.XYZ();
59 }
7fd59977 60
f751596e 61 myTopology.Append (aVertArray);
7fd59977 62 }
63
f751596e 64 myCenter.Divide (theNodes.Length());
7fd59977 65}
66
67//================================================================
68// Function : GetConnected
69// Purpose :
70//================================================================
f751596e 71Handle(Select3D_SensitiveEntity) MeshVS_SensitivePolyhedron::GetConnected()
7fd59977 72{
f751596e 73 Handle(MeshVS_SensitivePolyhedron) aNewEnt = new
74 MeshVS_SensitivePolyhedron (myOwnerId, myNodes->Array1(), myTopo);
7fd59977 75
f751596e 76 return aNewEnt;
7fd59977 77}
78
f751596e 79//=======================================================================
80// function : Matches
81// purpose :
82//=======================================================================
83Standard_Boolean MeshVS_SensitivePolyhedron::Matches (SelectBasics_SelectingVolumeManager& theMgr,
84 SelectBasics_PickResult& thePickResult)
7fd59977 85{
17017555 86 SelectBasics_PickResult aPickResult;
f751596e 87 for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next())
7fd59977 88 {
17017555 89 if (theMgr.Overlaps (aIter.Value(), Select3D_TOS_INTERIOR, aPickResult))
7fd59977 90 {
17017555 91 thePickResult = SelectBasics_PickResult::Min (thePickResult, aPickResult);
7fd59977 92 }
4952a30a 93 }
17017555 94 if (!thePickResult.IsValid())
95 {
96 return Standard_False;
97 }
4269bd1b 98
17017555 99 thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter (CenterOfGeometry()));
100 return Standard_True;
7fd59977 101}
102
f751596e 103//=======================================================================
104// function : NbSubElements
105// purpose : Returns the amount of nodes of polyhedron
106//=======================================================================
fe758dbe 107Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements() const
7fd59977 108{
f751596e 109 return myNodes->Length();
7fd59977 110}
111
f751596e 112//=======================================================================
113// function : BoundingBox
114// purpose :
115//=======================================================================
116Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox()
7fd59977 117{
f751596e 118 return myBndBox;
7fd59977 119}
120
f751596e 121//=======================================================================
122// function : CenterOfGeometry
123// purpose :
124//=======================================================================
125gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const
7fd59977 126{
f751596e 127 return myCenter;
7fd59977 128}