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