0024070: OpenGL capped object-level clipping planes
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <Select3D_SensitiveWire.ixx>
23#include <SelectBasics_BasicTool.hxx>
24#include <Select3D_SensitiveEntity.hxx>
25#include <Select3D_SensitiveEntitySequence.hxx>
26#include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
27#include <SelectBasics_ListOfBox2d.hxx>
28#include <Precision.hxx>
29
30#include <Bnd_Box2d.hxx>
31#include <ElCLib.hxx>
32
33//static Standard_Boolean debugmode=Standard_False;
34
35//=====================================================
36// Function : Create
37// Purpose :Constructor
38//=====================================================
39
7fd59977 40Select3D_SensitiveWire::
41Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId,
258ff83b 42 const Standard_Integer /*MaxRect*/):
7fd59977 43Select3D_SensitiveEntity(OwnerId),
7fd59977 44myDetectedIndex(-1)
45{}
46
47//=====================================================
48// Function : Add
49// Purpose :
50//=====================================================
ac04d101 51
7fd59977 52void Select3D_SensitiveWire
53::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
54{
ac04d101
SA
55 if(!aSensitive.IsNull())
56 mysensitive.Append(aSensitive);
7fd59977 57}
58
59//=======================================================================
60//function : SetLocation
4952a30a 61//purpose :
7fd59977 62//=======================================================================
63
64void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc)
65{
66
67 // evitons les problemes...
68 if(aLoc.IsIdentity()) return;
69
70 if(HasLocation())
71 if(aLoc == Location()) return;
4952a30a 72
7fd59977 73 Select3D_SensitiveEntity::SetLocation(aLoc);
74 for(Standard_Integer i=1;i<=mysensitive.Length();i++){
75 if(mysensitive(i)->HasLocation()){
ac04d101
SA
76 if(mysensitive(i)->Location()!=aLoc)
77 mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
7fd59977 78 }
79 else
80 mysensitive(i)->SetLocation(aLoc);
4952a30a 81
7fd59977 82 }
83}
ac04d101 84
7fd59977 85//=======================================================================
86//function : ResetLocation
4952a30a 87//purpose :
7fd59977 88//=======================================================================
89
90void Select3D_SensitiveWire::ResetLocation()
91{
92 if(!HasLocation()) return;
93 for(Standard_Integer i=1;i<=mysensitive.Length();i++){
94 if(mysensitive(i)->HasLocation() && mysensitive(i)->Location()!=Location())
95 mysensitive(i)->SetLocation(mysensitive(i)->Location()*Location().Inverted());
96 else
97 mysensitive(i)->ResetLocation();
4952a30a 98
7fd59977 99 }
100 Select3D_SensitiveEntity::ResetLocation();
101}
ac04d101 102
7fd59977 103//=====================================================
104// Function : Project
105// Purpose :
106//=====================================================
4269bd1b 107void Select3D_SensitiveWire::Project(const Handle(Select3D_Projector)& aProj)
7fd59977 108{
4269bd1b 109 for (Standard_Integer aSensIt = 1; aSensIt <= mysensitive.Length(); aSensIt++)
110 {
111 mysensitive (aSensIt)->Project (aProj);
112 }
7fd59977 113}
114
115//=====================================================
116// Function : Areas
117// Purpose :
118//=====================================================
ac04d101 119
7fd59977 120void Select3D_SensitiveWire
121::Areas(SelectBasics_ListOfBox2d& theareas)
122{
123 Bnd_Box2d BB; // en attendant un nouveau champ rob-18-jun-97
124 SelectBasics_ListOfBox2d BidL;
125 Standard_Integer i;
126 for (i=1; i<=mysensitive.Length(); i++)
127 mysensitive.Value(i)->Areas(BidL);
4952a30a 128
7fd59977 129 for(SelectBasics_ListIteratorOfListOfBox2d it(BidL);it.More();it.Next())
130 BB.Add(it.Value());
4952a30a 131
7fd59977 132 theareas.Append(BB);
7fd59977 133}
134
135//=====================================================
136// Function : Matches
137// Purpose :
138//=====================================================
4269bd1b 139
140Standard_Boolean Select3D_SensitiveWire::Matches (const SelectBasics_PickArgs& thePickArgs,
141 Standard_Real& theMatchDMin,
142 Standard_Real& theMatchDepth)
7fd59977 143{
4269bd1b 144 theMatchDMin = RealLast();
145 theMatchDepth = RealLast();
146 Standard_Real aSegDMin, aSegDepth;
147 Standard_Boolean isMatched = Standard_False;
148 myDetectedIndex = -1;
149
150 for (Standard_Integer aSegIt = 1; aSegIt <= mysensitive.Length(); aSegIt++)
ac04d101 151 {
4269bd1b 152 const Handle(SelectBasics_SensitiveEntity)& aSeg = mysensitive.Value (aSegIt);
153 if (!aSeg->Matches (thePickArgs, aSegDMin, aSegDepth))
ac04d101 154 {
4269bd1b 155 continue;
7fd59977 156 }
4269bd1b 157
158 isMatched = Standard_True;
159 if (aSegDMin > theMatchDMin)
160 {
161 continue;
162 }
163
164 myDetectedIndex = aSegIt;
165 theMatchDMin = aSegDMin;
166 theMatchDepth = aSegDepth;
7fd59977 167 }
4952a30a 168
4269bd1b 169 return isMatched;
7fd59977 170}
171
172//=====================================================
173// Function : Matches
174// Purpose :
175//=====================================================
ac04d101
SA
176
177Standard_Boolean Select3D_SensitiveWire::
7fd59977 178Matches (const Standard_Real XMin,
ac04d101
SA
179 const Standard_Real YMin,
180 const Standard_Real XMax,
181 const Standard_Real YMax,
182 const Standard_Real aTol)
7fd59977 183{
184 Standard_Integer i;
ac04d101
SA
185 for (i=1; i<=mysensitive.Length(); i++)
186 {
4952a30a 187 if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol)))
7fd59977 188 return Standard_False;
189 }
190 return Standard_True;
191}
192
193//=======================================================================
194//function : Matches
4952a30a 195//purpose :
7fd59977 196//=======================================================================
197
198Standard_Boolean Select3D_SensitiveWire::
199Matches (const TColgp_Array1OfPnt2d& aPoly,
ac04d101
SA
200 const Bnd_Box2d& aBox,
201 const Standard_Real aTol)
4952a30a 202{
7fd59977 203 Standard_Integer i;
ac04d101
SA
204 for (i=1; i<=mysensitive.Length(); i++)
205 {
4952a30a 206 if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol)))
7fd59977 207 return Standard_False;
208 }
209 return Standard_True;
210}
211
212
213//=====================================================
214// Function : MaxBoxes
215// Purpose :
216//=====================================================
ac04d101 217
7fd59977 218Standard_Integer Select3D_SensitiveWire::
219MaxBoxes () const
220{
221 return 1;
222}
223
224//=======================================================================
225//function : GetConnected
4952a30a 226//purpose :
7fd59977 227//=======================================================================
ac04d101 228
4952a30a 229Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc)
7fd59977 230{
231 Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId);
232 for(Standard_Integer i=1;i<=mysensitive.Length();i++)
ac04d101 233 SWIR->Add(mysensitive(i)->GetConnected(aLoc));
4952a30a 234
7fd59977 235 if(HasLocation())
236 SWIR->SetLocation(Location()*aLoc);
237 else
238 SWIR->SetLocation(aLoc);
239 return SWIR;
240}
241
242
243//=======================================================================
244//function : Dump
4952a30a 245//purpose :
7fd59977 246//=======================================================================
247
248void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
249{
250 S<<"\tSensitiveWire 3D :"<<endl;;
251 if(HasLocation())
252 S<<"\t\tExisting Location"<<endl;
253 S<<"\t\tComposed Of "<<mysensitive.Length()<<" Sensitive Entities"<<endl;
254
255 for(Standard_Integer i=1;i<= mysensitive.Length();i++){
256 S<<"Sensitive #"<<i<<" : "<<endl;
257 mysensitive(i)->Dump(S,FullDump);}
258
259 S<<"\tEnd Of Sensitive Wire"<<endl;
260
261}
262
7fd59977 263//=======================================================================
264//function : GetEdges
4952a30a 265//purpose : returns the sensitive edges stored in this wire
7fd59977 266//=======================================================================
ac04d101 267
7fd59977 268void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges )
269{
270 theEdges.Clear();
271 theEdges.Append(mysensitive);
272}
273
274//=============================================================================
275// Function : GetLastDetected
4952a30a 276// Purpose :
7fd59977 277//=============================================================================
ac04d101 278
7fd59977 279Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
280{
281 Handle(Select3D_SensitiveEntity) aRes;
282
283 if ( myDetectedIndex >= 1 && myDetectedIndex <= mysensitive.Length() )
284 aRes = mysensitive.Value( myDetectedIndex );
285
286 return aRes;
287}
ac04d101
SA
288
289//=======================================================================
290//function : Set
291//purpose :
292//=======================================================================
293
294void Select3D_SensitiveWire::Set(const Handle_SelectBasics_EntityOwner &TheOwnerId)
295{
296 Select3D_SensitiveEntity::Set(TheOwnerId);
297
298 // Set TheOwnerId for each element of sensitive wire
299 for (Standard_Integer i = 1; i <= mysensitive.Length(); ++i)
300 {
301 mysensitive.Value(i)->Set(TheOwnerId);
302 }
303}