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