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