0025991: Cyclic dependency in OCCT detected by WOK compiler
[occt.git] / src / AIS / AIS_LocalContext_1.cxx
CommitLineData
b311480e 1// Created on: 1996-10-30
2// Created by: Robert COUBLANC
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.
b311480e 16
7fd59977 17// Modified by rob Thu Apr 02 1998
18// - use of optimisation in SelectMgr_ViewerSelector
19// -> Best management in detected entities...
20
7fd59977 21#include <AIS_LocalContext.jxx>
22#include <StdSelect_BRepOwner.hxx>
bc677575 23#include <TColStd_ListOfInteger.hxx>
24#include <TColStd_ListIteratorOfListOfInteger.hxx>
7fd59977 25#include <TColStd_MapOfTransient.hxx>
26#include <TColStd_MapIteratorOfMapOfTransient.hxx>
27#include <Prs3d_Presentation.hxx>
28#include <Prs3d_Drawer.hxx>
29#include <Prs3d_ShadingAspect.hxx>
30#include <AIS_LocalStatus.hxx>
b8ddfc2f 31#include <Graphic3d_ArrayOfTriangles.hxx>
7fd59977 32#include <Graphic3d_Group.hxx>
33#include <Select3D_SensitiveTriangulation.hxx>
34#include <SelectBasics_SensitiveEntity.hxx>
35#include <TCollection_AsciiString.hxx>
e3a6386d 36#include <NCollection_Map.hxx>
a272ed94 37#include <Visual3d_View.hxx>
e3a6386d 38
7fd59977 39#include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
7fd59977 40#include <SelectMgr_Selection.hxx>
e3a6386d 41#include <SelectMgr_SequenceOfOwner.hxx>
7fd59977 42#include <OSD_Environment.hxx>
7fd59977 43
44#include <Geom_Transformation.hxx>
45#include <AIS_Selection.hxx>
679ecdee 46#include <Aspect_Grid.hxx>
7fd59977 47#include <AIS_Shape.hxx>
7fd59977 48
49static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO)
50{
51 return IO->HasHilightMode() ? IO->HilightMode():0;
52}
53
54//==================================================
679ecdee 55// Function: MoveTo
7fd59977 56// Purpose :
57//==================================================
679ecdee 58AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix,
59 const Standard_Integer theYpix,
60 const Handle(V3d_View)& theView,
61 const Standard_Boolean theToRedrawImmediate)
7fd59977 62{
679ecdee 63 // check that ViewerSelector gives
64 if (theView->Viewer() != myCTX->CurrentViewer())
65 {
66 return AIS_SOD_Error;
67 }
68
69 myAISCurDetected = 0;
70 myAISDetectedSeq.Clear();
71
72 myCurDetected = 0;
73 myDetectedSeq.Clear();
a272ed94 74 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
679ecdee 75 myMainVS->Pick (theXpix, theYpix, theView);
76
77 const Standard_Integer aDetectedNb = myMainVS->NbPicked();
78 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
79 {
80 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (aDetIter);
81 if (anOwner.IsNull()
82 || !myFilters->IsOk (anOwner))
83 {
84 continue;
7fd59977 85 }
679ecdee 86
57ad5cbd 87 myDetectedSeq.Append (aDetIter); // normally they are already arranged in correct order...
679ecdee 88 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
57ad5cbd 89 if (!anObj.IsNull())
679ecdee 90 {
91 myAISDetectedSeq.Append (anObj);
7fd59977 92 }
679ecdee 93 }
7fd59977 94
679ecdee 95 // result of courses..
96 if (aDetectedNb == 0 || myDetectedSeq.IsEmpty())
97 {
98 if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent())
99 {
63d907e7 100 myMainPM->ClearImmediateDraw();
679ecdee 101 Unhilight (myMapOfOwner (mylastindex), theView);
102 if (theToRedrawImmediate)
103 {
104 theView->RedrawImmediate();
7fd59977 105 }
7fd59977 106 }
679ecdee 107
108 mylastindex = 0;
109 return aDetectedNb == 0
110 ? AIS_SOD_Nothing
111 : AIS_SOD_AllBad;
112 }
113
114 // all owners detected by the selector are passed to the
115 // filters and correct ones are preserved...
116 myCurDetected = 1;
117 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
118 manageDetected (anOwner, theView, theToRedrawImmediate);
119 if (myDetectedSeq.Length() == 1)
120 {
121 return aDetectedNb == 1
122 ? AIS_SOD_OnlyOneDetected
123 : AIS_SOD_OnlyOneGood;
124 }
125 else
126 {
127 return AIS_SOD_SeveralGood;
7fd59977 128 }
7fd59977 129}
130
c398b00e 131//=======================================================================
132//function : Select
133//purpose :
134//=======================================================================
135AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 136{
c398b00e 137 if (myAutoHilight)
138 {
139 UnhilightPicked (Standard_False);
140 }
7fd59977 141
c398b00e 142 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
143
144 Standard_Integer aDetIndex = DetectedIndex();
145 if (aDetIndex <= 0)
146 {
147 ClearSelected (toUpdateViewer);
148 return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 149 }
150
c398b00e 151 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
7fd59977 152
c398b00e 153 ClearSelected (Standard_False);
154
155 if (!anOwner->IsSelected()) // anOwner is not selected
156 {
157 anOwner->SetSelected (Standard_True);
158 AIS_Selection::Select (anOwner);
7fd59977 159 }
c398b00e 160
679ecdee 161 if (myAutoHilight)
162 {
7fd59977 163 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
679ecdee 164 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
165 {
c398b00e 166 Unhilight (anOwner, aViewer->ActiveView());
7fd59977 167 }
168
679ecdee 169 // advanced selection highlighting mechanism
c398b00e 170 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
679ecdee 171 {
c398b00e 172 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
679ecdee 173 UpdateSelected (anIO, Standard_False);
174 }
175
c398b00e 176 if (toUpdateViewer)
679ecdee 177 {
178 myCTX->CurrentViewer()->Update();
179 }
7fd59977 180 }
c398b00e 181
182 return (AIS_Selection::Extent() == 1) ? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected;
7fd59977 183}
c398b00e 184
185//=======================================================================
186//function : Select
187//purpose :
188//=======================================================================
189AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Integer theXPMin,
190 const Standard_Integer theYPMin,
191 const Standard_Integer theXPMax,
192 const Standard_Integer theYPMax,
193 const Handle(V3d_View)& theView,
194 const Standard_Boolean toUpdateViewer)
7fd59977 195{
c398b00e 196 if (theView->Viewer() == myCTX->CurrentViewer())
197 {
198 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
199 if (myAutoHilight)
200 {
201 UnhilightPicked (Standard_False);
202 }
203
204 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
205 Standard_Integer aSelNum = AIS_Selection::Extent();
206
7fd59977 207 myMainVS->Init();
c398b00e 208 if (!myMainVS->More())
209 {
210 ClearSelected (toUpdateViewer);
211 mylastindex = 0;
212 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 213 }
214
c398b00e 215 ClearSelected (Standard_False);
216
217 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
218 {
219 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
220 if (myFilters->IsOk (anOwner))
221 {
222 // it can be helpful to classify this owner immediately...
223 if (!anOwner->IsSelected())
224 {
225 anOwner->SetSelected (Standard_True);
226 AIS_Selection::Select (anOwner);
227 }
7fd59977 228 }
229 }
c398b00e 230
231 if (myAutoHilight)
232 {
233 HilightPicked (toUpdateViewer);
234 }
7fd59977 235 }
7fd59977 236
c398b00e 237 Standard_Integer aSelNum = AIS_Selection::Extent();
7fd59977 238
c398b00e 239 return (aSelNum == 1) ? AIS_SOP_OneSelected
240 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
241 : AIS_SOP_Error;
242}
7fd59977 243
244//==================================================
c398b00e 245// Function: Select
246// Purpose : Selection by polyline
7fd59977 247//==================================================
c398b00e 248AIS_StatusOfPick AIS_LocalContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
249 const Handle(V3d_View)& theView,
250 const Standard_Boolean toUpdateViewer)
7fd59977 251{
c398b00e 252 if (theView->Viewer() == myCTX->CurrentViewer())
253 {
254 myMainVS->Pick (thePolyline, theView);
7fd59977 255
c398b00e 256 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
257
258 Standard_Integer aLastSelNum = AIS_Selection::Extent();
259 myMainVS->Init();
260 if (!myMainVS->More())
261 {
262 // Nothing is selected clear selection.
263 ClearSelected (toUpdateViewer);
264 mylastindex = 0;
265
266 // Return state to know if something was unselected
267 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
268 }
269
270 if (myAutoHilight)
271 {
272 UnhilightPicked (Standard_False);
273 }
274
275 // Clear previous selection without update to process this selection
276 ClearSelected (Standard_False);
277
278 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
279 {
280 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
281 if (myFilters->IsOk (anOwner))
282 {
283 // it can be helpful to classify this owner immediately...
284 if (!anOwner->IsSelected())
285 {
286 AIS_Selection::AddSelect (anOwner);
287 anOwner->SetSelected (Standard_True);
288 }
289 }
290 }
291
292 if (myAutoHilight)
293 {
294 HilightPicked (toUpdateViewer);
295 }
296 }
297
298 Standard_Integer aSelNum = AIS_Selection::Extent();
299 return (aSelNum == 1) ? AIS_SOP_OneSelected
300 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
301 : AIS_SOP_Error;
302}
303
304//=======================================================================
305//function : ShiftSelect
306//purpose :
307//=======================================================================
308AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
309{
310 Standard_Integer aDetIndex = DetectedIndex();
311 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
312
313 if(aDetIndex > 0)
314 {
315 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
316 Standard_Integer aSelNum = AIS_Selection::Extent();
317 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
318 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
319 AIS_Selection::Select (anOwner);
320 anOwner->SetSelected (toSelect);
7fd59977 321
679ecdee 322 if(myAutoHilight)
323 {
63d907e7 324 myMainPM->ClearImmediateDraw();
7fd59977 325 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
679ecdee 326 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
327 {
c398b00e 328 Unhilight (anOwner, aViewer->ActiveView());
679ecdee 329 }
330
331 // advanced selection highlighting mechanism
c398b00e 332 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
679ecdee 333 {
c398b00e 334 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
679ecdee 335 UpdateSelected (anIO, Standard_False);
7fd59977 336 }
337
c398b00e 338 if (toUpdateViewer)
679ecdee 339 {
7fd59977 340 myCTX->CurrentViewer()->Update();
679ecdee 341 }
7fd59977 342 }
c398b00e 343
7fd59977 344 Standard_Integer NS = AIS_Selection::Extent();
345 if( NS == 1 ) return AIS_SOP_OneSelected;
346 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
c398b00e 347 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 348 }
349 return AIS_SOP_Error;
350}
c398b00e 351
352//=======================================================================
353//function : ShiftSelect
354//purpose :
355//=======================================================================
356AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Integer theXPMin,
357 const Standard_Integer theYPMin,
358 const Standard_Integer theXPMax,
359 const Standard_Integer theYPMax,
360 const Handle(V3d_View)& theView,
361 const Standard_Boolean toUpdateViewer)
7fd59977 362{
679ecdee 363 myMainPM->ClearImmediateDraw();
364
c398b00e 365 if (theView->Viewer() == myCTX->CurrentViewer())
366 {
367 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
368
369 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
370 Standard_Integer aLastSelNum = AIS_Selection::Extent();
371
7fd59977 372 myMainVS->Init();
c398b00e 373 if (!myMainVS->More())
374 {
375 // Nothing is selected clear selection, but don't clear the selection
376 // as it is shift selection and previous selection matters.
377 // Return state to know if something was unselected
378 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
379 }
7fd59977 380
c398b00e 381 if (myAutoHilight)
382 {
383 UnhilightPicked (Standard_False);
384 }
7fd59977 385
c398b00e 386 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
387 {
388 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
389 if(myFilters->IsOk (anOwner))
390 {
391 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
392 AIS_Selection::Select (anOwner);
393 anOwner->SetSelected (toSelect);
7fd59977 394 }
395 }
c398b00e 396
397 if (myAutoHilight)
398 {
399 HilightPicked (toUpdateViewer);
400 }
7fd59977 401 }
c398b00e 402
403 Standard_Integer aSelNum = AIS_Selection::Extent();
404
405 return (aSelNum == 1) ? AIS_SOP_OneSelected
406 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
407 : AIS_SOP_Error;
7fd59977 408}
409
410//==================================================
411// Function: Select
412// Purpose : Selection by polyline
413//==================================================
c398b00e 414AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
415 const Handle(V3d_View)& theView,
416 const Standard_Boolean toUpdateViewer)
7fd59977 417{
c398b00e 418 if (theView->Viewer() == myCTX->CurrentViewer())
419 {
420 myMainVS->Pick (thePolyline, theView);
421
422 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
423
424 Standard_Integer aLastSelNum = AIS_Selection::Extent();
7fd59977 425 myMainVS->Init();
c398b00e 426 if(!myMainVS->More())
427 {
428 // Nothing is selected clear selection, but don't clear the selection
429 // as it is shift selection and previous selection matters.
430 // Return state to know if something was unselected
431 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
7fd59977 432 }
433
c398b00e 434 if (myAutoHilight)
435 {
436 UnhilightPicked (Standard_False);
7fd59977 437 }
438
c398b00e 439 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
440 {
441 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
442 if (myFilters->IsOk (anOwner))
443 {
444 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
445 AIS_Selection::Select (anOwner);
446 anOwner->SetSelected (toSelect);
447 }
448 }
449 if (myAutoHilight)
450 {
451 HilightPicked (toUpdateViewer);
452 }
7fd59977 453 }
7fd59977 454
c398b00e 455 Standard_Integer aSelNum = AIS_Selection::Extent();
456
457 return (aSelNum == 1) ? AIS_SOP_OneSelected
458 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
459 : AIS_SOP_Error;
7fd59977 460}
461
462//==================================================
679ecdee 463// Function: Hilight
7fd59977 464// Purpose :
465//==================================================
679ecdee 466void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner,
467 const Handle(V3d_View)& theView)
7fd59977 468{
679ecdee 469 if (theView.IsNull())
470 {
471 return;
472 }
7fd59977 473
679ecdee 474 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
475 myMainPM->BeginImmediateDraw();
476 theOwner->HilightWithColor (myMainPM, myCTX->HilightColor(), aHilightMode);
477 myMainPM->EndImmediateDraw (theView);
7fd59977 478}
479
480//==================================================
679ecdee 481// Function: Unhilight
7fd59977 482// Purpose :
483//==================================================
679ecdee 484void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner,
485 const Handle(V3d_View)& theView)
7fd59977 486{
679ecdee 487 if (theView.IsNull())
488 {
489 return;
490 }
7fd59977 491
679ecdee 492 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
493 if (IsSelected (theOwner))
7fd59977 494 {
679ecdee 495 if (theOwner->IsAutoHilight())
496 {
497 theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode);
498 }
499 }
500 else
501 {
502 theOwner->Unhilight (myMainPM, aHilightMode);
7fd59977 503 }
7fd59977 504}
505
506//=======================================================================
507//function : HilightPicked
508//purpose :
509//=======================================================================
510void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer)
511{
7fd59977 512 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
7fd59977 513 if( Sel.IsNull() ) return;
7fd59977 514
e3a6386d 515 typedef NCollection_DataMap <Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > SelectMgr_DataMapOfObjectOwners;
7fd59977 516 SelectMgr_DataMapOfObjectOwners aMap;
e3a6386d 517
518 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
7fd59977 519
81bba717 520 // to avoid problems when there is a loop searching for selected objects...
7fd59977 521 const AIS_NListTransient& Obj = Sel->Objects();
522 AIS_NListTransient::Iterator anIter( Obj );
523 for(; anIter.More(); anIter.Next())
524 {
525 const Handle(Standard_Transient)& Tr = anIter.Value();
7fd59977 526 if(!Tr.IsNull()){
527 const Handle(SelectMgr_EntityOwner)& Ownr =
528 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
529 Handle(AIS_InteractiveObject) IO;
530 if(Ownr->HasSelectable()){
531 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
532 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
533 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
534 IO = *((Handle(AIS_InteractiveObject)*)&SO);
7fd59977 535 }
7fd59977 536 }
7fd59977 537 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
538 Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO));
539 if ( Ownr->IsAutoHilight() )
540 Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM);
541 else if ( aMap.IsBound (SO) )
e3a6386d 542 aMap(SO)->Append ( Ownr );
7fd59977 543 else {
e3a6386d 544 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq = new SelectMgr_SequenceOfOwner;
545 aSeq->Append ( Ownr );
7fd59977 546 aMap.Bind ( SO, aSeq );
547 }
548 }
549 }
550
e3a6386d 551 for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap);
7fd59977 552 aMapIter.More(); aMapIter.Next() )
e3a6386d 553 {
554 aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value());
555 }
7fd59977 556
679ecdee 557 if (updateviewer)
558 {
559 myCTX->CurrentViewer()->Update();
7fd59977 560 }
561}
562
563//==================================================
564// Function:
565// Purpose :
566//==================================================
679ecdee 567void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer)
7fd59977 568{
679ecdee 569 myMainPM->ClearImmediateDraw();
570
7fd59977 571 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
7fd59977 572 if( Sel.IsNull() ) return;
7fd59977 573 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
e3a6386d 574 NCollection_Map<Handle(SelectMgr_SelectableObject)> anObjMap;
7fd59977 575
7fd59977 576 const AIS_NListTransient& Obj = Sel->Objects();
577 AIS_NListTransient::Iterator anIter( Obj );
578 for(; anIter.More(); anIter.Next()){
579 const Handle(Standard_Transient)& Tr = anIter.Value();
7fd59977 580 if(!Tr.IsNull()){
581 const Handle(SelectMgr_EntityOwner)& Ownr =
582 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
583 Standard_Integer HM(0);
584 if(Ownr->HasSelectable()){
7fd59977 585 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
586 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
e3a6386d 587 anObjMap.Add (IO);
7fd59977 588
e3a6386d 589 HM = GetHiMod(IO);
7fd59977 590 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
591 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
7fd59977 592 }
7fd59977 593 }
594 Ownr->Unhilight(PM,HM);
595 }
596 }
597
e3a6386d 598 for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator anIter1 ( anObjMap );
7fd59977 599 anIter1.More(); anIter1.Next() )
e3a6386d 600 {
7fd59977 601 if ( !anIter1.Key()->IsAutoHilight() )
602 anIter1.Key()->ClearSelected();
e3a6386d 603 }
7fd59977 604
bcf50875 605 if(updateviewer)
7fd59977 606 myCTX->CurrentViewer()->Update();
7fd59977 607}
608
609//=======================================================================
610//function : IsSelected
611//purpose :
612//=======================================================================
613Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
614{
615 return (!FindSelectedOwnerFromIO(anIObj).IsNull());
616}
617
618//=======================================================================
619//function : IsSelected
620//purpose :
621//=======================================================================
622
c398b00e 623Standard_Boolean AIS_LocalContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
7fd59977 624{
c398b00e 625 return !theOwner.IsNull() && theOwner->IsSelected();
7fd59977 626}
627
628//==================================================
629// Function:
630// Purpose :
631//==================================================
632void AIS_LocalContext::
633InitSelected()
634{
635 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
636 AIS_Selection::CurrentSelection()->Init();
637}
638
639//==================================================
640// Function:
641// Purpose :
642//==================================================
643Standard_Boolean AIS_LocalContext::
644MoreSelected() const
645{
646 return AIS_Selection::CurrentSelection()->More();
647}
648
649//==================================================
650// Function:
651// Purpose :
652//==================================================
653void AIS_LocalContext::
654NextSelected()
655{
656 AIS_Selection::CurrentSelection()->Next();
657}
658
659//==================================================
660// Function:
661// Purpose :
662//==================================================
663Standard_Boolean AIS_LocalContext::
664HasShape() const
665{
666 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
667 if( Tr.IsNull() ) return Standard_False;
668 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
669 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
670 if(BRO.IsNull()) return Standard_False;
671 Standard_Boolean hasshape = BRO->HasShape();
672 Standard_Boolean comes = BRO->ComesFromDecomposition();
673 return (hasshape&&comes);
674}
675
51023771 676//================================================================
677// Function : HasSelectedShape
678// Purpose : Checks if there is a selected shape regardless of its decomposition status
679//================================================================
680Standard_Boolean AIS_LocalContext::HasSelectedShape() const
681{
682 if (AIS_Selection::CurrentSelection()->Extent() == 0)
683 return Standard_False;
684
685 Handle(Standard_Transient) aCurSelection = AIS_Selection::CurrentSelection()->Value();
686 if (aCurSelection.IsNull())
687 return Standard_False;
688
689 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSelection);
690 Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
691 if (aBrepOwner.IsNull())
692 {
693 return Standard_False;
694 }
695 return aBrepOwner->HasShape();
696}
697
7fd59977 698//==================================================
699// Function:
700// Purpose :
701//==================================================
0717ddc1 702TopoDS_Shape AIS_LocalContext::SelectedShape() const
7fd59977 703{
d8110103 704 Handle(Standard_Transient) aTr = AIS_Selection::CurrentSelection()->Value();
705 Handle(SelectMgr_EntityOwner) anEO = *((Handle(SelectMgr_EntityOwner)*)&aTr);
706 Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(anEO);
707 if( aBRO.IsNull() )
7fd59977 708 {
d8110103 709 return TopoDS_Shape();
7fd59977 710 }
51023771 711
d8110103 712 return aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location());
7fd59977 713}
714
715//==================================================
716// Function:
717// Purpose :
718//==================================================
719Handle(AIS_InteractiveObject) AIS_LocalContext::
720SelectedInteractive() const
721{
722 Handle(AIS_InteractiveObject) IO;
723 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
724 if( !Tr.IsNull() ) {
725 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
726 Handle(SelectMgr_SelectableObject) SO;
727 if(EO->HasSelectable()){
728 SO = EO->Selectable();
729 IO = *((Handle(AIS_InteractiveObject)*)&SO);
730 }
731 }
732 return IO;
733}
734//==================================================
735// Function:
736// Purpose :
737//==================================================
738Handle(SelectMgr_EntityOwner) AIS_LocalContext::
739SelectedOwner() const
740{
741 Handle(SelectMgr_EntityOwner) EO;
742 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
743 if( !Tr.IsNull() )
744 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
745 return EO;
746}
747
748//==================================================
749// Function:
750// Purpose :
751//==================================================
752Standard_Boolean AIS_LocalContext::
753HasApplicative() const
754{
755 Handle(AIS_InteractiveObject) IO = SelectedInteractive();
756 if( IO.IsNull() ) return Standard_False;
757 return IO->HasOwner();
758}
759
760//==================================================
761// Function:
762// Purpose :
763//==================================================
764const Handle(Standard_Transient)& AIS_LocalContext::
765SelectedApplicative() const
766{
767 return SelectedInteractive()->GetOwner();
768}
769
770
771
772//=======================================================================
773//function : UpdateSelection
81bba717 774//purpose : should disappear...
7fd59977 775//=======================================================================
776void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer)
777{
778 UnhilightPicked(Standard_False);
779 HilightPicked(updateviewer);
780}
781
782//================================================================
783// Function : UpdateSelected
784// Purpose : Part of advanced selection mechanism.
785// Highlightes or clears selection presentation for the given IO
786//================================================================
787void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj,
788 const Standard_Boolean updateviewer)
789{
790 if (anobj.IsNull() || anobj->IsAutoHilight())
791 return;
792
793 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
794 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
795
796 SelectMgr_SequenceOfOwner aSeq;
797 for ( Sel->Init(); Sel->More(); Sel->Next() ){
798 Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value());
799
800 if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj )
801 aSeq.Append( aOwner );
802 }
803
804 if ( aSeq.Length() )
805 anobj->HilightSelected( myMainPM, aSeq );
806 else
807 anobj->ClearSelected();
808
809 if(updateviewer){
810 myCTX->CurrentViewer()->Update();
811 }
812}
813
814//==================================================
815// Function: ClearSelected
816// Purpose :
817//==================================================
c398b00e 818void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer)
7fd59977 819{
820 UnhilightPicked(updateviewer);
821 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
822
823 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
7fd59977 824 const AIS_NListTransient& Obj = Sel->Objects();
825 AIS_NListTransient::Iterator anIter( Obj );
826 for(; anIter.More(); anIter.Next()){
827 const Handle(Standard_Transient)& Tr = anIter.Value();
c398b00e 828 if(!Tr.IsNull())
829 {
830 (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False);
7fd59977 831 }
832 }
833 AIS_Selection::Select();
834 mylastindex = 0;
835}
836
fb4b684a 837//==================================================
bc677575 838// Function: ClearOutdatedSelection
fb4b684a 839// Purpose :
840//==================================================
bc677575 841void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObject)& theIO,
842 const Standard_Boolean toClearDeactivated)
fb4b684a 843{
bc677575 844 // 1. Collect selectable entities
845 SelectMgr_IndexedMapOfOwner aValidOwners;
846
847 const TColStd_ListOfInteger& aModes = SelectionModes (theIO);
848
849 TColStd_ListIteratorOfListOfInteger aModeIter (aModes);
850 for (; aModeIter.More(); aModeIter.Next())
851 {
852 int aMode = aModeIter.Value();
853 if (!theIO->HasSelection(aMode))
854 {
855 continue;
856 }
857
858 if (toClearDeactivated && !mySM->IsActivated (theIO, myMainVS, aMode))
859 {
860 continue;
861 }
862
863 Handle(SelectMgr_Selection) aSelection = theIO->Selection(aMode);
864 for (aSelection->Init(); aSelection->More(); aSelection->Next())
865 {
866 Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
867 if (anEntity.IsNull())
868 {
869 continue;
870 }
871
872 Handle(SelectMgr_EntityOwner) anOwner =
873 Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
874
875 if (anOwner.IsNull())
876 {
877 continue;
878 }
879
880 aValidOwners.Add(anOwner);
881 }
882 }
883
884 // 2. Refresh context's detection and selection and keep only active owners
fb4b684a 885 // Keep last detected object for lastindex initialization.
886 Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked();
887
bc677575 888 // Remove entity owners from detected sequences
889 for (Standard_Integer anIdx = 1; anIdx <= myDetectedSeq.Length(); ++anIdx)
fb4b684a 890 {
bc677575 891 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (anIdx));
892 if (anOwner.IsNull() || anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
fb4b684a 893 {
bc677575 894 continue;
895 }
896
897 myDetectedSeq.Remove (anIdx--);
898
899 if (anIdx < myCurDetected)
900 {
901 myCurDetected--;
fb4b684a 902 }
903 }
bc677575 904 myCurDetected = Max (myCurDetected, 1);
fb4b684a 905
bc677575 906 Standard_Boolean isAISRemainsDetected = Standard_False;
fb4b684a 907
bc677575 908 // 3. Remove entity owners from AIS_Selection
909 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
fb4b684a 910 Handle(AIS_Selection) aSelection = AIS_Selection::Selection (mySelName.ToCString());
911 AIS_NListTransient::Iterator anIter (aSelection->Objects());
912 AIS_NListTransient aRemoveEntites;
913 for (; anIter.More(); anIter.Next())
914 {
915 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anIter.Value());
916 if (anOwner.IsNull() || anOwner->Selectable() != theIO)
917 {
918 continue;
919 }
920
bc677575 921 if (aValidOwners.Contains (anOwner))
922 {
923 isAISRemainsDetected = Standard_True;
924 }
fb4b684a 925
bc677575 926 aRemoveEntites.Append (anOwner);
927 anOwner->SetSelected (Standard_False);
928 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
fb4b684a 929 {
bc677575 930 Unhilight (anOwner, aViewer->ActiveView());
fb4b684a 931 }
932 }
bc677575 933
fb4b684a 934 AIS_NListTransient::Iterator anIterRemove (aRemoveEntites);
935 for (; anIterRemove.More(); anIterRemove.Next())
936 {
937 aSelection->Select (anIterRemove.Value());
938 }
939
bc677575 940 // 4. Remove entity owners from myMapOfOwner
fb4b684a 941 SelectMgr_IndexedMapOfOwner anOwnersToKeep;
fb4b684a 942 for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++)
943 {
944 Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner (anIdx);
945 if (anOwner.IsNull())
946 {
947 continue;
948 }
949
bc677575 950 if (anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
fb4b684a 951 {
952 anOwnersToKeep.Add (anOwner);
953 }
954 else
955 {
956 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
957 {
958 Unhilight (anOwner, aViewer->ActiveView());
959 }
960 }
961 }
962 myMapOfOwner.Clear();
963 myMapOfOwner.Assign (anOwnersToKeep);
964 mylastindex = myMapOfOwner.FindIndex (aLastPicked);
63d907e7 965 if (!IsValidIndex (mylastindex))
966 {
967 myMainPM->ClearImmediateDraw();
968 }
fb4b684a 969
bc677575 970 if (!isAISRemainsDetected)
fb4b684a 971 {
bc677575 972 // Remove the interactive object from detected sequences
973 for (Standard_Integer anIdx = 1; anIdx <= myAISDetectedSeq.Length(); ++anIdx)
974 {
975 Handle(AIS_InteractiveObject) aDetectedIO = myAISDetectedSeq.Value (anIdx);
976 if (aDetectedIO.IsNull() || aDetectedIO != theIO)
977 {
978 continue;
979 }
980
981 myAISDetectedSeq.Remove (anIdx--);
982
983 if (anIdx < myAISCurDetected)
984 {
985 myAISCurDetected--;
986 }
987 }
988 myAISCurDetected = Max (myAISCurDetected, 1);
fb4b684a 989 }
990}
7fd59977 991
992//=======================================================================
993//function : SetSelected
994//purpose :
995//=======================================================================
996void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
997 const Standard_Boolean updateviewer)
998{
999 if(!IsValidForSelection(anIObj)) return;
1000 UnhilightPicked(Standard_False);
1001
81bba717 1002 //1st case, owner already <anIObj> as owner
1003 // and not separated is found...
7fd59977 1004
1005 Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString());
1006 //Standard_Boolean found(Standard_False);
1007 Handle(Standard_Transient) Tr;
1008 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj);
1009 if(EO.IsNull()){
81bba717 1010 //check if in selection number 0 there is an owner that can be triturated...
7fd59977 1011 if(anIObj->HasSelection(0)){
1012 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1013 SIOBJ->Init();
1014 if(SIOBJ->More()){
1015 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1016 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1017 }
1018 }
1019 if(EO.IsNull())
1020 EO = new SelectMgr_EntityOwner(anIObj);
1021 }
1022
1023 ClearSelected(Standard_False);
c398b00e 1024
7fd59977 1025 AIS_Selection::Select(EO);
c398b00e 1026 EO->SetSelected (Standard_True);
1027
7fd59977 1028 HilightPicked(updateviewer);
1029}
1030
1031//=======================================================================
1032//function : AddOrRemoveSelected
1033//purpose :
1034//=======================================================================
1035
1036void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1037 const Standard_Boolean updateviewer)
1038{
1039 if(!IsValidForSelection(anIObj)) return;
1040 UnhilightPicked(Standard_False);
81bba717 1041 // first check if it is selected...
7fd59977 1042 Handle(SelectMgr_EntityOwner) EO;
1043
1044 EO = FindSelectedOwnerFromIO(anIObj);
c398b00e 1045
1046 if (EO.IsNull())
1047 {
1048 if(anIObj->HasSelection(0))
1049 {
7fd59977 1050 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1051 SIOBJ->Init();
c398b00e 1052 if(SIOBJ->More())
1053 {
1054 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1055 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
7fd59977 1056 }
1057 }
c398b00e 1058 if(EO.IsNull())
1059 {
7fd59977 1060 EO = new SelectMgr_EntityOwner(anIObj);
c398b00e 1061 }
7fd59977 1062 }
1063
1064// cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl;
1065 const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString());
c398b00e 1066
1067 if (!S.IsNull())
1068 {
7fd59977 1069 AIS_SelectStatus aStatus = S->Select(EO);
c398b00e 1070 EO->SetSelected (aStatus == AIS_SS_Added);
7fd59977 1071 }
c398b00e 1072
7fd59977 1073 HilightPicked(updateviewer);
1074}
1075
1076//=======================================================================
1077//function : AddOrRemoveSelected
81bba717 1078//purpose : To check...
7fd59977 1079//=======================================================================
1080void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh,
1081 const Standard_Boolean updateviewer)
1082{
c398b00e 1083 UnhilightPicked (Standard_False);
7fd59977 1084 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh);
c398b00e 1085 if (!EO.IsNull())
1086 {
7fd59977 1087 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
c398b00e 1088 EO->SetSelected (Standard_True);
7fd59977 1089 }
c398b00e 1090 HilightPicked (updateviewer);
7fd59977 1091}
1092
c398b00e 1093void AIS_LocalContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1094 const Standard_Boolean toUpdateViewer)
1095{
7fd59977 1096 if(myAutoHilight)
c398b00e 1097 {
1098 UnhilightPicked (Standard_False);
1099 }
7fd59977 1100
c398b00e 1101 Standard_Boolean toSelect = theOwner->IsSelected() ? Standard_False : Standard_True;
1102
1103 AIS_Selection::Selection (mySelName.ToCString())->Select (theOwner);
1104 theOwner->SetSelected (toSelect);
7fd59977 1105
7fd59977 1106 if(myAutoHilight)
c398b00e 1107 {
1108 HilightPicked (toUpdateViewer);
1109 }
7fd59977 1110}
1111
1112//==================================================
679ecdee 1113// Function: manageDetected
7fd59977 1114// Purpose :
1115//==================================================
679ecdee 1116void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner,
1117 const Handle(V3d_View)& theView,
1118 const Standard_Boolean theToRedrawImmediate)
7fd59977 1119{
679ecdee 1120 if (thePickOwner.IsNull())
1121 {
63d907e7 1122 myMainPM->ClearImmediateDraw();
679ecdee 1123 if (theToRedrawImmediate)
1124 {
1125 theView->RedrawImmediate();
1126 }
1127 return;
1128 }
7fd59977 1129
679ecdee 1130 if (!myFilters->IsOk (thePickOwner))
1131 {
1132 if (mylastindex != 0)
1133 {
1134 mylastgood = mylastindex;
1135 }
1136 if (theToRedrawImmediate)
1137 {
1138 theView->RedrawImmediate();
1139 }
1140 return;
1141 }
7fd59977 1142
679ecdee 1143 //=======================================================================================================
1144 // 2 cases : a- object is in the map of picks:
1145 // 1. this is the same index as the last detected: -> Do nothing
1146 // 2. otherwise :
1147 // - if lastindex = 0 (no object was detected at the last step)
1148 // the object presentation is highlighted and lastindex = index(objet)
1149 // - othrwise :
1150 // the presentation of the object corresponding to lastindex is "unhighlighted"
1151 // it is removed if the object is not visualized but only active
1152 // then the presentation of the detected object is highlighted and lastindex = index(objet)
1153 // b- the object is not in the map of picked objects
1154 // - if lastindex != 0 (object detected at the last step) it is unhighlighted ...
1155 // if the object was decomposed, presentation is created for the detected shape and the couple
1156 // (Proprietaire,Prs)is added in the map.
1157 // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object
1158 // itself is highlighted.
1159 //
1160 //=======================================================================================================
1161
1162 const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner)
1163 ? myMapOfOwner.FindIndex (thePickOwner)
1164 : myMapOfOwner.Add (thePickOwner);
1165
1166 // For the advanced mesh selection mode the owner indices comparison
1167 // is not effective because in that case only one owner manage the
1168 // selection in current selection mode. It is necessary to check the current detected
1169 // entity and hilight it only if the detected entity is not the same as
1170 // previous detected (IsForcedHilight call)
1171 if (aNewIndex != mylastindex
1172 || thePickOwner->IsForcedHilight())
1173 {
63d907e7 1174 myMainPM->ClearImmediateDraw();
679ecdee 1175 if (mylastindex != 0
1176 && mylastindex <= myMapOfOwner.Extent())
1177 {
1178 const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex);
1179 Unhilight (aLastOwner, theView);
1180 }
7fd59977 1181
679ecdee 1182 if (myAutoHilight)
1183 {
c398b00e 1184 if (!thePickOwner->IsSelected() || myCTX->ToHilightSelected())
679ecdee 1185 {
1186 Hilight (thePickOwner, theView);
7fd59977 1187 }
679ecdee 1188 if (theToRedrawImmediate)
1189 {
1190 theView->RedrawImmediate();
7fd59977 1191 }
7fd59977 1192 }
679ecdee 1193
1194 mylastindex = aNewIndex;
7fd59977 1195 }
1196
63d907e7 1197 if (mylastindex != 0)
679ecdee 1198 {
1199 mylastgood = mylastindex;
1200 }
7fd59977 1201}
1202
7fd59977 1203//=======================================================================
1204//function : HasDetectedShape
1205//purpose :
1206//=======================================================================
1207
1208Standard_Boolean AIS_LocalContext::HasDetectedShape() const
1209{
1210 if(mylastindex==0) return Standard_False;
1211 return IsShape(mylastindex);
1212}
1213
1214//=======================================================================
1215//function : DetectedShape
1216//purpose :
1217//=======================================================================
1218
1219const TopoDS_Shape&
1220AIS_LocalContext::DetectedShape() const
1221{
1222 static TopoDS_Shape bidsh;
1223 if(mylastindex != 0)
1224 {
1225 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex));
1226 if(BROwnr.IsNull()) return bidsh;
1227 return BROwnr->Shape();
1228 }
1229 return bidsh;
1230}
1231
1232//=======================================================================
1233//function : DetectedInteractive
1234//purpose :
1235//=======================================================================
1236
1237Handle(AIS_InteractiveObject)
1238AIS_LocalContext::DetectedInteractive() const
1239{
1240 Handle(AIS_InteractiveObject) Iobj;
1241 if(IsValidIndex(mylastindex)){
1242 Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
1243 Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
1244 }
1245 return Iobj;
1246}
1247//=======================================================================
1248//function : DetectedInteractive
1249//purpose :
1250//=======================================================================
1251Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
1252{
1253 Handle(SelectMgr_EntityOwner) bid;
1254 if(!IsValidIndex(mylastindex)) return bid;
1255 return myMapOfOwner.FindKey(mylastindex);
1256}
1257
1258
1259//=======================================================================
1260//function : ComesFromDecomposition
1261//purpose :
1262//=======================================================================
1263
1264Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
1265{
1266 const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex);
1267 Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
81bba717 1268 if (myActiveObjects.IsBound (aSel)) { // debug of jmi
7fd59977 1269 const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
1270 return Stat->Decomposed();
1271 }
1272 return Standard_False;
1273}
1274
1275
1276//=======================================================================
1277//function : DisplayAreas
1278//purpose :
1279//=======================================================================
1280
1281void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
1282{
1283 myMainVS->DisplayAreas(aviou);
1284}
1285
1286//=======================================================================
1287//function : ClearAreas
1288//purpose :
1289//=======================================================================
1290
1291void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
1292{
1293 myMainVS->ClearAreas(aviou);
1294}
1295
1296//=======================================================================
1297//function : DisplaySensitive
1298//purpose :
1299//=======================================================================
1300
1301void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou)
1302{
1303 myMainVS->DisplaySensitive(aviou);
1304}
1305
1306//=======================================================================
1307//function : ClearSensitive
1308//purpose :
1309//=======================================================================
1310
1311void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
1312{
1313 myMainVS->ClearSensitive(aviou);
1314}
1315
1316
1317//=======================================================================
1318//function : IsShape
1319//purpose :
1320//=======================================================================
1321Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
1322{
1323
1324 if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull())
1325 return Standard_False;
1326 return
1327 ComesFromDecomposition(Index);
1328}
1329
1330Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const
1331{
1332
7fd59977 1333 // Shape was not transfered from AIS_Shape to EntityOwner
1334 Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj);
1335 if( !shape.IsNull() )
1336 return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape));
7fd59977 1337 return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj));
1338}
1339
1340
1341//=======================================================================
1342//function : HilightNextDetected
679ecdee 1343//purpose :
7fd59977 1344//=======================================================================
679ecdee 1345Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView,
1346 const Standard_Boolean theToRedrawImmediate)
7fd59977 1347{
81bba717 1348 // go to the next owner
679ecdee 1349 if (myDetectedSeq.IsEmpty())
1350 {
1351 return 0;
1352 }
7fd59977 1353
679ecdee 1354 const Standard_Integer aLen = myDetectedSeq.Length();
1355 if (++myCurDetected > aLen)
1356 {
7fd59977 1357 myCurDetected = 1;
7fd59977 1358 }
bc677575 1359 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
679ecdee 1360 if (anOwner.IsNull())
1361 {
1362 return 0;
1363 }
1364 manageDetected (anOwner, theView, theToRedrawImmediate);
7fd59977 1365 return myCurDetected;
1366}
1367
1368//=======================================================================
1369//function : HilightPreviousDetected
679ecdee 1370//purpose :
7fd59977 1371//=======================================================================
679ecdee 1372Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1373 const Standard_Boolean theToRedrawImmediate)
7fd59977 1374{
679ecdee 1375 if (myDetectedSeq.IsEmpty())
1376 {
1377 return 0;
1378 }
7fd59977 1379
4ca4bbe8 1380 const Standard_Integer aLen = myDetectedSeq.Length();
679ecdee 1381 if (--myCurDetected < 1)
1382 {
4ca4bbe8 1383 myCurDetected = aLen;
679ecdee 1384 }
bc677575 1385 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
679ecdee 1386 if (anOwner.IsNull())
1387 {
1388 return 0;
7fd59977 1389 }
1390
679ecdee 1391 manageDetected (anOwner, theView, theToRedrawImmediate);
7fd59977 1392 return myCurDetected;
1393}
1394
1395//=======================================================================
1396//function : UnhilightLastDetected
679ecdee 1397//purpose :
7fd59977 1398//=======================================================================
679ecdee 1399Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView)
7fd59977 1400{
679ecdee 1401 if (!IsValidIndex (mylastindex))
1402 {
1403 return Standard_False;
7fd59977 1404 }
7fd59977 1405
679ecdee 1406 myMainPM->BeginImmediateDraw();
1407 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex);
1408 const Standard_Integer aHilightMode = anOwner->HasSelectable()
1409 ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
1410 : 0;
7fd59977 1411
679ecdee 1412 myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode);
1413 myMainPM->EndImmediateDraw (theView);
1414 mylastindex = 0;
1415 return Standard_True;
7fd59977 1416}
1417
1418//=======================================================================
1419//function : FindSelectedOwnerFromIO
81bba717 1420//purpose : it is checked if one of the selected owners really presents IObj
7fd59977 1421//=======================================================================
1422Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO
1423 (const Handle(AIS_InteractiveObject)& anIObj) const
1424{
1425 Handle(SelectMgr_EntityOwner) EO,bid;
1426 if (anIObj.IsNull()) return EO;
1427
1428 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1429 if(Sel.IsNull()) {
0797d9d3 1430#ifdef OCCT_DEBUG
7fd59977 1431 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "
1432 <<mySelName<<" Nulle "<<endl;
1433#endif
1434 return EO;
1435 }
1436 Standard_Boolean found(Standard_False);
7fd59977 1437 const AIS_NListTransient& Obj = Sel->Objects();
1438 AIS_NListTransient::Iterator anIter( Obj );
1439 for(; anIter.More(); anIter.Next()){
1440 const Handle(Standard_Transient)& Tr = anIter.Value();
7fd59977 1441 if(!Tr.IsNull()){
1442 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1443 if(EO->HasSelectable()){
1444 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1445 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
1446 if (anIObj == EO->Selectable()){
1447 found =Standard_True;
1448 break;
1449 }
1450 }
1451 }
1452 }
1453 }
1454 if(found) return EO;
1455 return bid;
1456}
1457
1458//=======================================================================
1459//function : FindSelectedOwnerFromShape
81bba717 1460//purpose : it is checked if one of the selected owners really presents IObj
7fd59977 1461//=======================================================================
1462Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const
1463{
7fd59977 1464 Handle(SelectMgr_EntityOwner) EO, bid;
7fd59977 1465 if (sh.IsNull()) return EO;
1466
1467 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1468 if(Sel.IsNull()) {
0797d9d3 1469#ifdef OCCT_DEBUG
7fd59977 1470 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl;
1471#endif
1472 return EO;
1473 }
1474
1475 Standard_Boolean found(Standard_False);
1476
7fd59977 1477 if (!found) {
7fd59977 1478 SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives());
1479 for (; aSensitiveIt.More(); aSensitiveIt.Next()) {
1480 EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId());
1481 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1482 if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) {
1483 found = Standard_True;
1484 break;
1485 }
1486 }
1487 }
7fd59977 1488
1489 if(found) return EO;
1490 return bid;
1491}
1492
7fd59977 1493//=======================================================================
1494//function : AIS_LocalContext::InitDetected
1495//purpose :
1496//=======================================================================
7fd59977 1497void AIS_LocalContext::InitDetected()
1498{
1499 myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0;
1500}
1501
1502//=======================================================================
1503//function : AIS_LocalContext::MoreDetected
1504//purpose :
1505//=======================================================================
7fd59977 1506Standard_Boolean AIS_LocalContext::MoreDetected() const
1507{
1508 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length());
1509}
1510
7fd59977 1511//=======================================================================
1512//function : AIS_LocalContext::NextDetected
1513//purpose :
1514//=======================================================================
7fd59977 1515void AIS_LocalContext::NextDetected()
1516{
57ad5cbd 1517 myAISCurDetected++;
7fd59977 1518}
1519
1520//=======================================================================
1521//function : DetectedCurrentShape
1522//purpose :
1523//=======================================================================
7fd59977 1524const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
1525{
57ad5cbd 1526 static TopoDS_Shape aDummyShape;
7fd59977 1527
57ad5cbd 1528 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1529
1530 if (aCurrentShape.IsNull())
1531 {
1532 return aDummyShape;
1533 }
1534
1535 return aCurrentShape->Shape();
1536}
7fd59977 1537//=======================================================================
1538//function : DetectedCurrentObject
1539//purpose :
1540//=======================================================================
7fd59977 1541Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const
1542{
57ad5cbd 1543 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
7fd59977 1544}