0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Select3D / Select3D_SensitiveWire.cxx
CommitLineData
b311480e 1// Created on: 1996-10-17
2// Created by: Odile OLIVIER
3// Copyright (c) 1996-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_SensitiveWire.hxx>
7fd59977 18#include <Select3D_SensitiveEntity.hxx>
f751596e 19#include <TopLoc_Location.hxx>
7fd59977 20
f751596e 21#include <Select3D_SensitiveSegment.hxx>
7fd59977 22
7fd59977 23
92efcf78 24IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveWire,Select3D_SensitiveSet)
25
7fd59977 26//=====================================================
f751596e 27// Function : Select3D_SensitiveWire
28// Purpose :
7fd59977 29//=====================================================
0ef04197 30Select3D_SensitiveWire::Select3D_SensitiveWire (const Handle(SelectMgr_EntityOwner)& theOwnerId)
f751596e 31: Select3D_SensitiveSet (theOwnerId),
32 myCenter (0.0, 0.0, 0.0)
7fd59977 33{}
34
35//=====================================================
36// Function : Add
37// Purpose :
38//=====================================================
f751596e 39void Select3D_SensitiveWire::Add (const Handle(Select3D_SensitiveEntity)& theSensitive)
7fd59977 40{
f751596e 41 if (!theSensitive.IsNull())
42 myEntities.Append (theSensitive);
43
44 Select3D_BndBox3d aBndBox = theSensitive->BoundingBox();
45 myBndBox.Combine (aBndBox);
46 myCenter.ChangeCoord() += theSensitive->CenterOfGeometry().XYZ();
47 if (myEntities.Length() != 1)
48 myCenter.ChangeCoord().Divide (2.0);
49 myEntityIndexes.Append (myEntities.Length() - 1);
7fd59977 50}
51
52//=======================================================================
f751596e 53// function : NbSubElements
54// purpose : Returns the amount of sub-entities
7fd59977 55//=======================================================================
fe758dbe 56Standard_Integer Select3D_SensitiveWire::NbSubElements() const
7fd59977 57{
f751596e 58 return myEntities.Length();
7fd59977 59}
ac04d101 60
7fd59977 61//=======================================================================
f751596e 62// function : Size
63// purpose : Returns the length of vector of sensitive entities
7fd59977 64//=======================================================================
f751596e 65Standard_Integer Select3D_SensitiveWire::Size() const
7fd59977 66{
f751596e 67 return myEntities.Length();
7fd59977 68}
ac04d101 69
f751596e 70//=======================================================================
71// function : Box
72// purpose : Returns bounding box of sensitive entity with index theIdx
73//=======================================================================
74Select3D_BndBox3d Select3D_SensitiveWire::Box (const Standard_Integer theIdx) const
7fd59977 75{
f751596e 76 const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (theIdx);
77 return myEntities.Value (aSensitiveIdx)->BoundingBox();
7fd59977 78}
79
f751596e 80//=======================================================================
81// function : Center
82// purpose : Returns geometry center of sensitive entity with index
83// theIdx in the vector along the given axis theAxis
84//=======================================================================
85Standard_Real Select3D_SensitiveWire::Center (const Standard_Integer theIdx,
86 const Standard_Integer theAxis) const
7fd59977 87{
f751596e 88 const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (theIdx);
89 const gp_Pnt& aCenter = myEntities.Value (aSensitiveIdx)->CenterOfGeometry();
90 Standard_Real aCenterCoord = 0.0;
91 aCenterCoord = theAxis == 0 ? aCenter.X() : (theAxis == 1 ? aCenter.Y() : aCenter.Z());
4952a30a 92
f751596e 93 return aCenterCoord;
7fd59977 94}
95
f751596e 96//=======================================================================
97// function : Swap
98// purpose : Swaps items with indexes theIdx1 and theIdx2 in the vector
99//=======================================================================
100void Select3D_SensitiveWire::Swap (const Standard_Integer theIdx1,
101 const Standard_Integer theIdx2)
7fd59977 102{
f751596e 103 const Standard_Integer aSensitiveIdx1 = myEntityIndexes.Value (theIdx1);
104 const Standard_Integer aSensitiveIdx2 = myEntityIndexes.Value (theIdx2);
105 myEntityIndexes.ChangeValue (theIdx1) = aSensitiveIdx2;
106 myEntityIndexes.ChangeValue (theIdx2) = aSensitiveIdx1;
7fd59977 107}
108
f751596e 109// =======================================================================
110// function : overlapsElement
111// purpose : Checks whether the entity with index theIdx overlaps the
112// current selecting volume
113// =======================================================================
4a056d20 114Standard_Boolean Select3D_SensitiveWire::overlapsElement (SelectBasics_PickResult& thePickResult,
115 SelectBasics_SelectingVolumeManager& theMgr,
f751596e 116 Standard_Integer theElemIdx,
4a056d20 117 Standard_Boolean )
7fd59977 118{
f751596e 119 const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (theElemIdx);
bbd92927 120 const Handle(Select3D_SensitiveEntity)& aSeg = myEntities.Value (aSensitiveIdx);
17017555 121 return aSeg->Matches (theMgr, thePickResult);
7fd59977 122}
123
2157d6ac 124// =======================================================================
125// function : elementIsInside
126// purpose :
127// =======================================================================
128Standard_Boolean Select3D_SensitiveWire::elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
4a056d20 129 Standard_Integer theElemIdx,
130 Standard_Boolean )
2157d6ac 131{
132 SelectBasics_PickResult aMatchResult;
133 return myEntities.Value (myEntityIndexes.Value (theElemIdx))->Matches (theMgr, aMatchResult);
134}
135
f751596e 136// =======================================================================
137// function : distanceToCOG
138// purpose : Calculates distance from the 3d projection of used-picked
139// screen point to center of the geometry
140// =======================================================================
141Standard_Real Select3D_SensitiveWire::distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr)
7fd59977 142{
f751596e 143 return theMgr.DistToGeometryCenter (myCenter);
7fd59977 144}
145
146//=======================================================================
147//function : GetConnected
4952a30a 148//purpose :
7fd59977 149//=======================================================================
ac04d101 150
f751596e 151Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected()
7fd59977 152{
f751596e 153 Handle(Select3D_SensitiveWire) aNewEntity = new Select3D_SensitiveWire (myOwnerId);
154 for (Standard_Integer anEntityIdx = 0; anEntityIdx < myEntities.Length(); anEntityIdx++)
155 aNewEntity->Add (myEntities(anEntityIdx)->GetConnected());
7fd59977 156
f751596e 157 return aNewEntity;
7fd59977 158}
159
7fd59977 160//=======================================================================
161//function : GetEdges
4952a30a 162//purpose : returns the sensitive edges stored in this wire
7fd59977 163//=======================================================================
f751596e 164const NCollection_Vector<Handle(Select3D_SensitiveEntity)>& Select3D_SensitiveWire::GetEdges()
7fd59977 165{
f751596e 166 return myEntities;
7fd59977 167}
168
169//=============================================================================
170// Function : GetLastDetected
4952a30a 171// Purpose :
7fd59977 172//=============================================================================
173Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
174{
175 Handle(Select3D_SensitiveEntity) aRes;
176
f751596e 177 if (myDetectedIdx >= 0 && myDetectedIdx < myEntities.Length())
178 {
179 const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (myDetectedIdx);
180 aRes = myEntities.Value (aSensitiveIdx);
181 }
7fd59977 182
183 return aRes;
184}
ac04d101
SA
185
186//=======================================================================
187//function : Set
188//purpose :
189//=======================================================================
0ef04197 190void Select3D_SensitiveWire::Set (const Handle(SelectMgr_EntityOwner)& theOwnerId)
ac04d101 191{
f751596e 192 Select3D_SensitiveEntity::Set (theOwnerId);
ac04d101
SA
193
194 // Set TheOwnerId for each element of sensitive wire
f751596e 195 for (Standard_Integer anEntityIdx = 0; anEntityIdx < myEntities.Length(); ++anEntityIdx)
ac04d101 196 {
f751596e 197 myEntities.Value (anEntityIdx)->Set (theOwnerId);
ac04d101
SA
198 }
199}
f751596e 200
201//=======================================================================
202// function : BoundingBox
203// purpose : Returns bounding box of the wire. If location
204// transformation is set, it will be applied
205//=======================================================================
206Select3D_BndBox3d Select3D_SensitiveWire::BoundingBox()
207{
208 if (myBndBox.IsValid())
209 return myBndBox;
210
211 for (Standard_Integer aSensitiveIdx = 0; aSensitiveIdx < myEntities.Length(); ++aSensitiveIdx)
212 {
213 myBndBox.Combine (myEntities.Value (aSensitiveIdx)->BoundingBox());
214 }
215
216 return myBndBox;
217}
218
219//=======================================================================
220// function : CenterOfGeometry
221// purpose : Returns center of the wire. If location transformation
222// is set, it will be applied
223//=======================================================================
224gp_Pnt Select3D_SensitiveWire::CenterOfGeometry() const
225{
226 return myCenter;
227}
bc73b006 228
229// =======================================================================
230// function : DumpJson
231// purpose :
232// =======================================================================
233void Select3D_SensitiveWire::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
234{
235 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
236 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Select3D_SensitiveSet)
237
238 for (NCollection_Vector<Handle(Select3D_SensitiveEntity)>::Iterator anIterator (myEntities); anIterator.More(); anIterator.Next())
239 {
240 const Handle(Select3D_SensitiveEntity)& anEntity = anIterator.Value();
241 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anEntity.get())
242 }
243 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBndBox)
244}