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 <SelectBasics_EntityOwner.hxx>
23 #include <TopLoc_Location.hxx>
24 #include <MeshVS_DataSource.hxx>
25 #include <MeshVS_MeshOwner.hxx>
26 #include <NCollection_Vec4.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveMesh,Select3D_SensitiveEntity)
31 //=======================================================================
32 // name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
34 //=======================================================================
35 MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId,
36 const Standard_Integer theMode)
37 : Select3D_SensitiveEntity (theOwnerId)
40 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId());
41 if( !anOwner.IsNull() )
43 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
46 Bnd_Box aBox = aDS->GetBoundingBox();
47 Standard_Real aXMin, aYMin, aZMin;
48 Standard_Real aXMax, aYMax, aZMax;
49 aBox.Get (aXMin, aYMin, aZMin,
51 Select3D_Vec3 aMinPnt (aXMin, aYMin, aZMin);
52 Select3D_Vec3 aMaxPnt (aXMax, aYMax, aZMax);
53 myBndBox = Select3D_BndBox3d (aMinPnt, aMaxPnt);
58 //================================================================
61 //================================================================
62 Standard_Integer MeshVS_SensitiveMesh::GetMode() const
67 //=======================================================================
68 // name : GetConnected
70 //=======================================================================
71 Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected()
73 Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh (myOwnerId);
77 //=======================================================================
78 // function : NbSubElements
79 // purpose : Returns the amount of mesh nodes
80 //=======================================================================
81 Standard_Integer MeshVS_SensitiveMesh::NbSubElements()
83 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId());
86 Handle(MeshVS_DataSource) aDataSource = anOwner->GetDataSource();
87 if (aDataSource.IsNull())
89 return aDataSource->GetAllNodes().Extent();
92 //=======================================================================
93 // function : BoundingBox
94 // purpose : Returns bounding box of mesh
95 //=======================================================================
96 Select3D_BndBox3d MeshVS_SensitiveMesh::BoundingBox()
101 //=======================================================================
102 // function : CenterOfGeometry
103 // purpose : Returns center of mesh
104 //=======================================================================
105 gp_Pnt MeshVS_SensitiveMesh::CenterOfGeometry() const
107 if (!myBndBox.IsValid())
108 return gp_Pnt (0.0, 0.0, 0.0);
110 SelectMgr_Vec3 aCenter = (myBndBox.CornerMax() + myBndBox.CornerMin()) * 0.5;
111 return gp_Pnt (aCenter.x(), aCenter.y(), aCenter.z());