0029938: Visualization - SelectMgr_ViewerSelector::PickedPoint() should return point...
[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>
23#include <SelectBasics_EntityOwner.hxx>
24#include <TColgp_Array1OfPnt.hxx>
25#include <TColgp_HArray1OfPnt.hxx>
26#include <TColgp_Array1OfPnt2d.hxx>
27#include <TColStd_SequenceOfInteger.hxx>
7fd59977 28
7fd59977 29
92efcf78 30IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitivePolyhedron,Select3D_SensitiveEntity)
31
7fd59977 32//================================================================
f751596e 33// Function : Constructor MeshVS_SensitivePolyhedron
7fd59977 34// Purpose :
35//================================================================
f751596e 36MeshVS_SensitivePolyhedron::MeshVS_SensitivePolyhedron (const Handle(SelectBasics_EntityOwner)& theOwner,
37 const TColgp_Array1OfPnt& theNodes,
38 const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo)
39: Select3D_SensitiveEntity (theOwner),
40 myTopo (theTopo)
7fd59977 41{
f751596e 42 Standard_Integer aPlaneLowIdx = theTopo->Lower();
43 Standard_Integer aPlaneUpIdx = theTopo->Upper();
44 Standard_Integer aNodesLowerIdx = theNodes.Lower();
45 myNodes = new TColgp_HArray1OfPnt (aNodesLowerIdx, theNodes.Upper());
46 myCenter = gp_XYZ (0.0, 0.0, 0.0);
7fd59977 47
f751596e 48 for (Standard_Integer aPlaneIdx = aPlaneLowIdx; aPlaneIdx <= aPlaneUpIdx; ++aPlaneIdx)
7fd59977 49 {
f751596e 50 Standard_Integer aVertNb = theTopo->Value (aPlaneIdx).Length();
51 Handle(TColgp_HArray1OfPnt) aVertArray = new TColgp_HArray1OfPnt (0, aVertNb - 1);
52 for (Standard_Integer aVertIdx = 1; aVertIdx <= aVertNb; ++aVertIdx)
53 {
54 Standard_Integer aNodeIdx = theTopo->Value (aPlaneIdx).Value (aVertIdx);
55 const gp_Pnt& aVert = theNodes.Value (aNodeIdx + aNodesLowerIdx);
56 aVertArray->SetValue (aVertIdx - 1, aVert);
57 myNodes->SetValue (aNodeIdx + aNodesLowerIdx, aVert);
58 myBndBox.Add (SelectMgr_Vec3 (aVert.X(), aVert.Y(), aVert.Z()));
59 myCenter += aVert.XYZ();
60 }
7fd59977 61
f751596e 62 myTopology.Append (aVertArray);
7fd59977 63 }
64
f751596e 65 myCenter.Divide (theNodes.Length());
7fd59977 66}
67
68//================================================================
69// Function : GetConnected
70// Purpose :
71//================================================================
f751596e 72Handle(Select3D_SensitiveEntity) MeshVS_SensitivePolyhedron::GetConnected()
7fd59977 73{
f751596e 74 Handle(MeshVS_SensitivePolyhedron) aNewEnt = new
75 MeshVS_SensitivePolyhedron (myOwnerId, myNodes->Array1(), myTopo);
7fd59977 76
f751596e 77 return aNewEnt;
7fd59977 78}
79
f751596e 80//=======================================================================
81// function : Matches
82// purpose :
83//=======================================================================
84Standard_Boolean MeshVS_SensitivePolyhedron::Matches (SelectBasics_SelectingVolumeManager& theMgr,
85 SelectBasics_PickResult& thePickResult)
7fd59977 86{
17017555 87 SelectBasics_PickResult aPickResult;
f751596e 88 for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next())
7fd59977 89 {
17017555 90 if (theMgr.Overlaps (aIter.Value(), Select3D_TOS_INTERIOR, aPickResult))
7fd59977 91 {
17017555 92 thePickResult = SelectBasics_PickResult::Min (thePickResult, aPickResult);
7fd59977 93 }
4952a30a 94 }
17017555 95 if (!thePickResult.IsValid())
96 {
97 return Standard_False;
98 }
4269bd1b 99
17017555 100 thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter (CenterOfGeometry()));
101 return Standard_True;
7fd59977 102}
103
f751596e 104//=======================================================================
105// function : NbSubElements
106// purpose : Returns the amount of nodes of polyhedron
107//=======================================================================
108Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements()
7fd59977 109{
f751596e 110 return myNodes->Length();
7fd59977 111}
112
f751596e 113//=======================================================================
114// function : BoundingBox
115// purpose :
116//=======================================================================
117Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox()
7fd59977 118{
f751596e 119 return myBndBox;
7fd59977 120}
121
f751596e 122//=======================================================================
123// function : CenterOfGeometry
124// purpose :
125//=======================================================================
126gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const
7fd59977 127{
f751596e 128 return myCenter;
7fd59977 129}