Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1997-05-14 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1997-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_SensitiveTriangle.hxx> |
7fd59977 | 18 | |
7fd59977 | 19 | #include <TopLoc_Location.hxx> |
20 | ||
92efcf78 | 21 | IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveTriangle,Select3D_SensitiveEntity) |
22 | ||
7fd59977 | 23 | //================================================== |
ac04d101 | 24 | // Function: Creation |
7fd59977 | 25 | // Purpose : |
26 | //================================================== | |
0ef04197 | 27 | Select3D_SensitiveTriangle::Select3D_SensitiveTriangle (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
f751596e | 28 | const gp_Pnt& thePnt0, |
29 | const gp_Pnt& thePnt1, | |
30 | const gp_Pnt& thePnt2, | |
31 | const Select3D_TypeOfSensitivity theType) | |
2157d6ac | 32 | : Select3D_SensitiveEntity (theOwnerId), |
f751596e | 33 | mySensType (theType) |
7fd59977 | 34 | { |
2157d6ac | 35 | myPoints[0] = thePnt0; |
36 | myPoints[1] = thePnt1; | |
37 | myPoints[2] = thePnt2; | |
38 | myCentroid = (thePnt0.XYZ() + thePnt1.XYZ() + thePnt2.XYZ()) * (1.0 / 3.0); | |
7fd59977 | 39 | } |
40 | ||
ac04d101 SA |
41 | //================================================== |
42 | // Function: Matches | |
f751596e | 43 | // Purpose : Checks whether the triangle overlaps |
44 | // current selecting volume | |
ac04d101 | 45 | //================================================== |
f751596e | 46 | Standard_Boolean Select3D_SensitiveTriangle::Matches (SelectBasics_SelectingVolumeManager& theMgr, |
47 | SelectBasics_PickResult& thePickResult) | |
7fd59977 | 48 | { |
2157d6ac | 49 | if (!theMgr.IsOverlapAllowed()) |
ac04d101 | 50 | { |
e1eb39d2 | 51 | if (theMgr.GetActiveSelectionType() == SelectMgr_SelectionType_Polyline) |
a24a7821 | 52 | { |
53 | SelectBasics_PickResult aDummy; | |
03c9cc86 | 54 | return theMgr.OverlapsTriangle (myPoints[0], myPoints[1], myPoints[2], mySensType, aDummy); |
a24a7821 | 55 | } |
03c9cc86 | 56 | return theMgr.OverlapsPoint (myPoints[0]) |
57 | && theMgr.OverlapsPoint (myPoints[1]) | |
58 | && theMgr.OverlapsPoint (myPoints[2]); | |
ac04d101 | 59 | } |
7fd59977 | 60 | |
03c9cc86 | 61 | if (!theMgr.OverlapsTriangle (myPoints[0], myPoints[1], myPoints[2], mySensType, thePickResult)) |
2157d6ac | 62 | { |
2157d6ac | 63 | return Standard_False; |
64 | } | |
7fd59977 | 65 | |
17017555 | 66 | thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter(myCentroid)); |
2157d6ac | 67 | return Standard_True; |
7fd59977 | 68 | } |
69 | ||
ac04d101 | 70 | //================================================== |
f751596e | 71 | // Function: GetConnected |
ac04d101 SA |
72 | // Purpose : |
73 | //================================================== | |
f751596e | 74 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangle::GetConnected() |
ceae62f0 | 75 | { |
f751596e | 76 | // Create a copy of this |
77 | Handle(Select3D_SensitiveEntity) aNewEntity = | |
2157d6ac | 78 | new Select3D_SensitiveTriangle (myOwnerId, myPoints[0], myPoints[1], myPoints[2], mySensType); |
ceae62f0 | 79 | |
f751596e | 80 | return aNewEntity; |
7fd59977 | 81 | } |
ac04d101 | 82 | |
f751596e | 83 | //================================================== |
84 | // Function: BoundingBox | |
85 | // Purpose : Returns bounding box of the triangle. | |
86 | // If location transformation is set, it | |
87 | // will be applied | |
88 | //================================================== | |
89 | Select3D_BndBox3d Select3D_SensitiveTriangle::BoundingBox() | |
7fd59977 | 90 | { |
2157d6ac | 91 | const SelectMgr_Vec3 aMinPnt = SelectMgr_Vec3 (Min (myPoints[0].X(), Min (myPoints[1].X(), myPoints[2].X())), |
92 | Min (myPoints[0].Y(), Min (myPoints[1].Y(), myPoints[2].Y())), | |
93 | Min (myPoints[0].Z(), Min (myPoints[1].Z(), myPoints[2].Z()))); | |
94 | const SelectMgr_Vec3 aMaxPnt = SelectMgr_Vec3 (Max (myPoints[0].X(), Max (myPoints[1].X(), myPoints[2].X())), | |
95 | Max (myPoints[0].Y(), Max (myPoints[1].Y(), myPoints[2].Y())), | |
96 | Max (myPoints[0].Z(), Max (myPoints[1].Z(), myPoints[2].Z()))); | |
f751596e | 97 | return Select3D_BndBox3d (aMinPnt, aMaxPnt); |
7fd59977 | 98 | } |
bc73b006 | 99 | |
100 | //======================================================================= | |
101 | //function : DumpJson | |
102 | //purpose : | |
103 | //======================================================================= | |
104 | void Select3D_SensitiveTriangle::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const | |
105 | { | |
106 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) | |
107 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Select3D_SensitiveEntity) | |
108 | ||
109 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySensType) | |
110 | ||
111 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPoints[0]) | |
112 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPoints[1]) | |
113 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPoints[2]) | |
114 | ||
115 | Select3D_BndBox3d aBoundingBox = ((Select3D_SensitiveTriangle*)this)->BoundingBox(); | |
116 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aBoundingBox) | |
117 | } |