1 // Created on: 2007-01-29
2 // Created by: Sergey KOCHETKOV
3 // Copyright (c) 2007-2014 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_SensitiveMesh.hxx>
18 #include <TColgp_Array1OfPnt.hxx>
19 #include <TColStd_Array1OfReal.hxx>
20 #include <TColStd_HPackedMapOfInteger.hxx>
21 #include <Select3D_SensitiveEntity.hxx>
22 #include <TopLoc_Location.hxx>
23 #include <MeshVS_DataSource.hxx>
24 #include <MeshVS_MeshOwner.hxx>
25 #include <NCollection_Vec4.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveMesh,Select3D_SensitiveEntity)
30 //=======================================================================
31 // name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
33 //=======================================================================
34 MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectMgr_EntityOwner)& theOwnerId,
35 const Standard_Integer theMode)
36 : Select3D_SensitiveEntity (theOwnerId)
39 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId());
40 if( !anOwner.IsNull() )
42 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
45 Bnd_Box aBox = aDS->GetBoundingBox();
46 Standard_Real aXMin, aYMin, aZMin;
47 Standard_Real aXMax, aYMax, aZMax;
48 aBox.Get (aXMin, aYMin, aZMin,
50 Select3D_Vec3 aMinPnt (aXMin, aYMin, aZMin);
51 Select3D_Vec3 aMaxPnt (aXMax, aYMax, aZMax);
52 myBndBox = Select3D_BndBox3d (aMinPnt, aMaxPnt);
57 //================================================================
60 //================================================================
61 Standard_Integer MeshVS_SensitiveMesh::GetMode() const
66 //=======================================================================
67 // name : GetConnected
69 //=======================================================================
70 Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected()
72 Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh (myOwnerId);
76 //=======================================================================
77 // function : NbSubElements
78 // purpose : Returns the amount of mesh nodes
79 //=======================================================================
80 Standard_Integer MeshVS_SensitiveMesh::NbSubElements()
82 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId());
85 Handle(MeshVS_DataSource) aDataSource = anOwner->GetDataSource();
86 if (aDataSource.IsNull())
88 return aDataSource->GetAllNodes().Extent();
91 //=======================================================================
92 // function : BoundingBox
93 // purpose : Returns bounding box of mesh
94 //=======================================================================
95 Select3D_BndBox3d MeshVS_SensitiveMesh::BoundingBox()
100 //=======================================================================
101 // function : CenterOfGeometry
102 // purpose : Returns center of mesh
103 //=======================================================================
104 gp_Pnt MeshVS_SensitiveMesh::CenterOfGeometry() const
106 if (!myBndBox.IsValid())
107 return gp_Pnt (0.0, 0.0, 0.0);
109 SelectMgr_Vec3 aCenter = (myBndBox.CornerMax() + myBndBox.CornerMin()) * 0.5;
110 return gp_Pnt (aCenter.x(), aCenter.y(), aCenter.z());