b311480e |
1 | // Created on: 2007-01-29 |
2 | // Created by: Sergey KOCHETKOV |
973c2be1 |
3 | // Copyright (c) 2007-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_SensitiveMesh.hxx> |
7fd59977 |
17 | |
18 | #include <TColgp_Array1OfPnt.hxx> |
19 | #include <TColStd_Array1OfReal.hxx> |
20 | #include <TColStd_HPackedMapOfInteger.hxx> |
f751596e |
21 | #include <Select3D_SensitiveEntity.hxx> |
7fd59977 |
22 | #include <TopLoc_Location.hxx> |
23 | #include <MeshVS_DataSource.hxx> |
24 | #include <MeshVS_MeshOwner.hxx> |
f751596e |
25 | #include <NCollection_Vec4.hxx> |
26 | |
7fd59977 |
27 | |
92efcf78 |
28 | IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveMesh,Select3D_SensitiveEntity) |
29 | |
7fd59977 |
30 | //======================================================================= |
31 | // name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh |
32 | // Purpose : |
33 | //======================================================================= |
0ef04197 |
34 | MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
7fd59977 |
35 | const Standard_Integer theMode) |
f751596e |
36 | : Select3D_SensitiveEntity (theOwnerId) |
7fd59977 |
37 | { |
38 | myMode = theMode; |
f751596e |
39 | Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId()); |
7fd59977 |
40 | if( !anOwner.IsNull() ) |
41 | { |
42 | Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource(); |
f751596e |
43 | if (!aDS.IsNull()) |
44 | { |
45 | Bnd_Box aBox = aDS->GetBoundingBox(); |
46 | Standard_Real aXMin, aYMin, aZMin; |
47 | Standard_Real aXMax, aYMax, aZMax; |
48 | aBox.Get (aXMin, aYMin, aZMin, |
49 | aXMax, aYMax, aZMax); |
50 | Select3D_Vec3 aMinPnt (aXMin, aYMin, aZMin); |
51 | Select3D_Vec3 aMaxPnt (aXMax, aYMax, aZMax); |
52 | myBndBox = Select3D_BndBox3d (aMinPnt, aMaxPnt); |
53 | } |
7fd59977 |
54 | } |
55 | } |
56 | |
57 | //================================================================ |
58 | // Function : GetMode |
59 | // Purpose : |
60 | //================================================================ |
f751596e |
61 | Standard_Integer MeshVS_SensitiveMesh::GetMode() const |
7fd59977 |
62 | { |
63 | return myMode; |
64 | } |
65 | |
66 | //======================================================================= |
f751596e |
67 | // name : GetConnected |
7fd59977 |
68 | // Purpose : |
69 | //======================================================================= |
f751596e |
70 | Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected() |
7fd59977 |
71 | { |
f751596e |
72 | Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh (myOwnerId); |
73 | return aMeshEnt; |
7fd59977 |
74 | } |
75 | |
76 | //======================================================================= |
f751596e |
77 | // function : NbSubElements |
78 | // purpose : Returns the amount of mesh nodes |
7fd59977 |
79 | //======================================================================= |
f751596e |
80 | Standard_Integer MeshVS_SensitiveMesh::NbSubElements() |
7fd59977 |
81 | { |
f751596e |
82 | Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId()); |
83 | if (anOwner.IsNull()) |
84 | return -1; |
85 | Handle(MeshVS_DataSource) aDataSource = anOwner->GetDataSource(); |
86 | if (aDataSource.IsNull()) |
87 | return -1; |
88 | return aDataSource->GetAllNodes().Extent(); |
7fd59977 |
89 | } |
90 | |
91 | //======================================================================= |
f751596e |
92 | // function : BoundingBox |
93 | // purpose : Returns bounding box of mesh |
7fd59977 |
94 | //======================================================================= |
f751596e |
95 | Select3D_BndBox3d MeshVS_SensitiveMesh::BoundingBox() |
7fd59977 |
96 | { |
f751596e |
97 | return myBndBox; |
7fd59977 |
98 | } |
99 | |
100 | //======================================================================= |
f751596e |
101 | // function : CenterOfGeometry |
102 | // purpose : Returns center of mesh |
7fd59977 |
103 | //======================================================================= |
f751596e |
104 | gp_Pnt MeshVS_SensitiveMesh::CenterOfGeometry() const |
7fd59977 |
105 | { |
f751596e |
106 | if (!myBndBox.IsValid()) |
107 | return gp_Pnt (0.0, 0.0, 0.0); |
7fd59977 |
108 | |
f751596e |
109 | SelectMgr_Vec3 aCenter = (myBndBox.CornerMax() + myBndBox.CornerMin()) * 0.5; |
110 | return gp_Pnt (aCenter.x(), aCenter.y(), aCenter.z()); |
7fd59977 |
111 | } |