0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[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{
f751596e 87 Standard_Real aDepthMin = RealLast();
88 Standard_Real aDistToCOG = RealLast();
7fd59977 89
f751596e 90 for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next())
7fd59977 91 {
f751596e 92 Standard_Real aDepth = RealLast();
93 if (theMgr.Overlaps (aIter.Value(), Select3D_TOS_INTERIOR, aDepth))
7fd59977 94 {
f751596e 95 aDepthMin = Min (aDepth, aDepthMin);
7fd59977 96 }
4952a30a 97 }
4269bd1b 98
f751596e 99 aDistToCOG = aDepthMin == RealLast() ? RealLast() : theMgr.DistToGeometryCenter (myCenter);
100 thePickResult = SelectBasics_PickResult (aDepthMin, aDistToCOG);
7fd59977 101
f751596e 102 return aDepthMin != RealLast();
7fd59977 103}
104
f751596e 105//=======================================================================
106// function : NbSubElements
107// purpose : Returns the amount of nodes of polyhedron
108//=======================================================================
109Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements()
7fd59977 110{
f751596e 111 return myNodes->Length();
7fd59977 112}
113
f751596e 114//=======================================================================
115// function : BoundingBox
116// purpose :
117//=======================================================================
118Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox()
7fd59977 119{
f751596e 120 return myBndBox;
7fd59977 121}
122
f751596e 123//=======================================================================
124// function : CenterOfGeometry
125// purpose :
126//=======================================================================
127gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const
7fd59977 128{
f751596e 129 return myCenter;
7fd59977 130}