b311480e |
1 | // Created on: 1995-04-13 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
f751596e |
17 | #include <Select3D_SensitiveBox.hxx> |
7fd59977 |
18 | |
92efcf78 |
19 | IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveBox,Select3D_SensitiveEntity) |
20 | |
7fd59977 |
21 | //================================================== |
f751596e |
22 | // Function: Select3D_SensitiveBox |
7fd59977 |
23 | // Purpose : |
24 | //================================================== |
0ef04197 |
25 | Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
f751596e |
26 | const Bnd_Box& theBox) |
27 | : Select3D_SensitiveEntity (theOwnerId) |
7fd59977 |
28 | { |
f751596e |
29 | Standard_Real aXMax, aYMax, aZMax; |
30 | Standard_Real aXMin, aYMin, aZMin; |
31 | theBox.Get (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax); |
32 | myBox = Select3D_BndBox3d (SelectMgr_Vec3 (aXMin, aYMin, aZMin), |
33 | SelectMgr_Vec3 (aXMax, aYMax, aZMax)); |
34 | myCenter3d = (gp_XYZ (aXMin, aYMin, aZMin) + gp_XYZ (aXMax, aYMax, aZMax)) |
35 | * (1.0 / 2.0); |
7fd59977 |
36 | } |
37 | |
7fd59977 |
38 | //================================================== |
f751596e |
39 | // Function: Select3D_SensitiveBox |
7fd59977 |
40 | // Purpose : |
41 | //================================================== |
ac04d101 |
42 | |
0ef04197 |
43 | Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
f751596e |
44 | const Standard_Real theXMin, |
45 | const Standard_Real theYMin, |
46 | const Standard_Real theZMin, |
47 | const Standard_Real theXMax, |
48 | const Standard_Real theYMax, |
49 | const Standard_Real theZMax) |
50 | : Select3D_SensitiveEntity (theOwnerId) |
7fd59977 |
51 | { |
f751596e |
52 | myBox = Select3D_BndBox3d (SelectMgr_Vec3 (theXMin, theYMin, theZMin), |
53 | SelectMgr_Vec3 (theXMax, theYMax, theZMax)); |
54 | myCenter3d = (gp_XYZ (theXMin, theYMin, theZMin) + gp_XYZ (theXMax, theYMax, theZMax)) |
55 | * (1.0 / 2.0); |
7fd59977 |
56 | } |
57 | |
f751596e |
58 | //======================================================================= |
59 | // function : NbSubElements |
60 | // purpose : Returns the amount of sub-entities in sensitive |
61 | //======================================================================= |
fe758dbe |
62 | Standard_Integer Select3D_SensitiveBox::NbSubElements() const |
f751596e |
63 | { |
64 | return 1; |
65 | } |
7fd59977 |
66 | |
7fd59977 |
67 | //======================================================================= |
68 | //function : GetConnected |
69 | //purpose : |
70 | //======================================================================= |
71 | |
f751596e |
72 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected() |
7fd59977 |
73 | { |
f751596e |
74 | Bnd_Box aBox; |
75 | aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(), |
76 | myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z()); |
77 | Handle(Select3D_SensitiveBox) aNewEntity = new Select3D_SensitiveBox (myOwnerId, aBox); |
7fd59977 |
78 | |
f751596e |
79 | return aNewEntity; |
80 | } |
4269bd1b |
81 | |
f751596e |
82 | //======================================================================= |
83 | // function : Matches |
84 | // purpose : Checks whether the box overlaps current selecting volume |
85 | //======================================================================= |
86 | Standard_Boolean Select3D_SensitiveBox::Matches (SelectBasics_SelectingVolumeManager& theMgr, |
87 | SelectBasics_PickResult& thePickResult) |
7fd59977 |
88 | { |
2157d6ac |
89 | if (!theMgr.IsOverlapAllowed()) // check for inclusion |
4269bd1b |
90 | { |
2157d6ac |
91 | Standard_Boolean isInside = Standard_True; |
03c9cc86 |
92 | return theMgr.OverlapsBox (myBox.CornerMin(), myBox.CornerMax(), &isInside) && isInside; |
4269bd1b |
93 | } |
94 | |
03c9cc86 |
95 | if (!theMgr.OverlapsBox (myBox.CornerMin(), myBox.CornerMax(), thePickResult)) // check for overlap |
2157d6ac |
96 | { |
97 | return Standard_False; |
98 | } |
99 | |
17017555 |
100 | thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter(myCenter3d)); |
2157d6ac |
101 | return Standard_True; |
7fd59977 |
102 | } |
103 | |
7fd59977 |
104 | //======================================================================= |
f751596e |
105 | // function : CenterOfGeometry |
106 | // purpose : Returns center of the box. If location transformation |
107 | // is set, it will be applied |
7fd59977 |
108 | //======================================================================= |
f751596e |
109 | gp_Pnt Select3D_SensitiveBox::CenterOfGeometry() const |
ac04d101 |
110 | { |
f751596e |
111 | return myCenter3d; |
7fd59977 |
112 | } |
113 | |
7fd59977 |
114 | //======================================================================= |
f751596e |
115 | // function : BoundingBox |
116 | // purpose : Returns coordinates of the box. If location transformation |
117 | // is set, it will be applied |
7fd59977 |
118 | //======================================================================= |
f751596e |
119 | Select3D_BndBox3d Select3D_SensitiveBox::BoundingBox() |
7fd59977 |
120 | { |
f751596e |
121 | return myBox; |
7fd59977 |
122 | } |
bc73b006 |
123 | |
124 | //======================================================================= |
125 | //function : DumpJson |
126 | //purpose : |
127 | //======================================================================= |
128 | void Select3D_SensitiveBox::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
129 | { |
130 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
131 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Select3D_SensitiveEntity) |
132 | |
133 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBox) |
134 | } |