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