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