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