1 // Created on: 1996-10-30
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by rob Thu Apr 02 1998
18 // - use of optimisation in SelectMgr_ViewerSelector
19 // -> Best management in detected entities...
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)
30 // IMP230600 //GG Add protection on selection methodes
31 // when nothing is selected
33 #define BUC60726 //GG_040900 When nothing is detected,
34 // Clear the last temporary stuff in any case
36 #define BUC60765 //GG_121000 Avoid to raise when the same selection
37 // is attached to several local context.
39 #define BUC60771 //GG_261000 Avoid to crash after closing a view
40 // containing a selected entity and creating a new one.
42 #define BUC60774 //GG_261000 Returns right select status on
43 // bounding-box selection type.
45 #define BUC60818 //GG_300101 Enable detection even if
46 // SetAutomaticHilight(FALSE) has been used.
48 #define IMP300101 //GG Enable to use polygon highlighting
50 #define BUC60876 //GG_050401 Clear selection always even
51 // if the current highlight mode is not 0.
53 #define BUC60953 //SAV_060701 For Select optimization. Selection by rectangle case.
54 // for single selection no optimization done.
56 #define IMP120701 //SZV made a shape valid for selection
59 #define IMP160701 //SZV Add InitDetected(),MoreDetected(),NextDetected(),
60 // DetectedCurrentShape(),DetectedCurrentObject()
63 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveSelected method.
65 #define OCC189 //SAV: 18/03/02 AIS_Selection::Objects() returns ListOfTransient
68 #define USE_MAP //san : 18/04/03 USE_MAP - additional datamap is used to speed up access
69 //to certain owners in AIS_Selection::myresult list
71 #define OCC9026 //AEL Performance optimization of the FindSelectedOwnerFromShape() method.
73 #include <AIS_LocalContext.jxx>
74 #include <StdSelect_BRepOwner.hxx>
75 #include <TColStd_ListOfInteger.hxx>
76 #include <TColStd_ListIteratorOfListOfInteger.hxx>
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>
84 #include <Graphic3d_ArrayOfTriangles.hxx>
85 #include <Graphic3d_Group.hxx>
86 #include <Select3D_SensitiveTriangulation.hxx>
87 #include <SelectBasics_SensitiveEntity.hxx>
88 #include <TCollection_AsciiString.hxx>
89 #include <NCollection_Map.hxx>
92 #include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
94 #include <SelectMgr_Selection.hxx>
95 #include <SelectMgr_SequenceOfOwner.hxx>
96 #include <OSD_Environment.hxx>
98 #include <Geom_Transformation.hxx>
99 #include <AIS_Selection.hxx>
100 #include <Aspect_Grid.hxx>
102 #include <AIS_Shape.hxx>
106 static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO)
108 return IO->HasHilightMode() ? IO->HilightMode():0;
111 //==================================================
114 //==================================================
115 AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix,
116 const Standard_Integer theYpix,
117 const Handle(V3d_View)& theView,
118 const Standard_Boolean theToRedrawImmediate)
120 // check that ViewerSelector gives
121 if (theView->Viewer() != myCTX->CurrentViewer())
123 return AIS_SOD_Error;
126 myAISCurDetected = 0;
127 myAISDetectedSeq.Clear();
130 myDetectedSeq.Clear();
131 myMainVS->Pick (theXpix, theYpix, theView);
133 const Standard_Integer aDetectedNb = myMainVS->NbPicked();
134 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
136 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (aDetIter);
138 || !myFilters->IsOk (anOwner))
143 myDetectedSeq.Append (aDetIter); // normally they are already arranged in correct order...
144 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
147 myAISDetectedSeq.Append (anObj);
151 // result of courses..
152 if (aDetectedNb == 0 || myDetectedSeq.IsEmpty())
154 if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent())
156 myMainPM->ClearImmediateDraw();
157 Unhilight (myMapOfOwner (mylastindex), theView);
158 if (theToRedrawImmediate)
160 theView->RedrawImmediate();
165 return aDetectedNb == 0
170 // all owners detected by the selector are passed to the
171 // filters and correct ones are preserved...
173 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
174 manageDetected (anOwner, theView, theToRedrawImmediate);
175 if (myDetectedSeq.Length() == 1)
177 return aDetectedNb == 1
178 ? AIS_SOD_OnlyOneDetected
179 : AIS_SOD_OnlyOneGood;
183 return AIS_SOD_SeveralGood;
187 //=======================================================================
190 //=======================================================================
191 AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer)
195 UnhilightPicked (Standard_False);
198 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
200 Standard_Integer aDetIndex = DetectedIndex();
203 ClearSelected (toUpdateViewer);
204 return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
207 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
209 ClearSelected (Standard_False);
211 if (!anOwner->IsSelected()) // anOwner is not selected
213 anOwner->SetSelected (Standard_True);
214 AIS_Selection::Select (anOwner);
219 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
220 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
222 Unhilight (anOwner, aViewer->ActiveView());
225 // advanced selection highlighting mechanism
226 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
228 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
229 UpdateSelected (anIO, Standard_False);
234 myCTX->CurrentViewer()->Update();
238 return (AIS_Selection::Extent() == 1) ? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected;
241 //=======================================================================
244 //=======================================================================
245 AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Integer theXPMin,
246 const Standard_Integer theYPMin,
247 const Standard_Integer theXPMax,
248 const Standard_Integer theYPMax,
249 const Handle(V3d_View)& theView,
250 const Standard_Boolean toUpdateViewer)
252 if (theView->Viewer() == myCTX->CurrentViewer())
254 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
257 UnhilightPicked (Standard_False);
260 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
261 Standard_Integer aSelNum = AIS_Selection::Extent();
264 if (!myMainVS->More())
266 ClearSelected (toUpdateViewer);
268 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
271 ClearSelected (Standard_False);
273 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
275 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
276 if (myFilters->IsOk (anOwner))
278 // it can be helpful to classify this owner immediately...
279 if (!anOwner->IsSelected())
281 anOwner->SetSelected (Standard_True);
282 AIS_Selection::Select (anOwner);
289 HilightPicked (toUpdateViewer);
293 Standard_Integer aSelNum = AIS_Selection::Extent();
295 return (aSelNum == 1) ? AIS_SOP_OneSelected
296 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
300 //==================================================
302 // Purpose : Selection by polyline
303 //==================================================
304 AIS_StatusOfPick AIS_LocalContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
305 const Handle(V3d_View)& theView,
306 const Standard_Boolean toUpdateViewer)
308 if (theView->Viewer() == myCTX->CurrentViewer())
310 myMainVS->Pick (thePolyline, theView);
312 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
314 Standard_Integer aLastSelNum = AIS_Selection::Extent();
316 if (!myMainVS->More())
318 // Nothing is selected clear selection.
319 ClearSelected (toUpdateViewer);
322 // Return state to know if something was unselected
323 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
328 UnhilightPicked (Standard_False);
331 // Clear previous selection without update to process this selection
332 ClearSelected (Standard_False);
334 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
336 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
337 if (myFilters->IsOk (anOwner))
339 // it can be helpful to classify this owner immediately...
340 if (!anOwner->IsSelected())
342 AIS_Selection::AddSelect (anOwner);
343 anOwner->SetSelected (Standard_True);
350 HilightPicked (toUpdateViewer);
354 Standard_Integer aSelNum = AIS_Selection::Extent();
355 return (aSelNum == 1) ? AIS_SOP_OneSelected
356 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
360 //=======================================================================
361 //function : ShiftSelect
363 //=======================================================================
364 AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
366 Standard_Integer aDetIndex = DetectedIndex();
367 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
371 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
372 Standard_Integer aSelNum = AIS_Selection::Extent();
373 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
374 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
375 AIS_Selection::Select (anOwner);
376 anOwner->SetSelected (toSelect);
380 myMainPM->ClearImmediateDraw();
381 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
382 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
384 Unhilight (anOwner, aViewer->ActiveView());
387 // advanced selection highlighting mechanism
388 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
390 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
391 UpdateSelected (anIO, Standard_False);
396 myCTX->CurrentViewer()->Update();
401 Standard_Integer NS = AIS_Selection::Extent();
402 if( NS == 1 ) return AIS_SOP_OneSelected;
403 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
404 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
407 return AIS_SOP_Error;
410 //=======================================================================
411 //function : ShiftSelect
413 //=======================================================================
414 AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Integer theXPMin,
415 const Standard_Integer theYPMin,
416 const Standard_Integer theXPMax,
417 const Standard_Integer theYPMax,
418 const Handle(V3d_View)& theView,
419 const Standard_Boolean toUpdateViewer)
421 myMainPM->ClearImmediateDraw();
423 if (theView->Viewer() == myCTX->CurrentViewer())
425 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
427 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
428 Standard_Integer aLastSelNum = AIS_Selection::Extent();
431 if (!myMainVS->More())
433 // Nothing is selected clear selection, but don't clear the selection
434 // as it is shift selection and previous selection matters.
435 // Return state to know if something was unselected
436 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
441 UnhilightPicked (Standard_False);
444 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
446 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
447 if(myFilters->IsOk (anOwner))
449 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
450 AIS_Selection::Select (anOwner);
451 anOwner->SetSelected (toSelect);
457 HilightPicked (toUpdateViewer);
461 Standard_Integer aSelNum = AIS_Selection::Extent();
463 return (aSelNum == 1) ? AIS_SOP_OneSelected
464 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
468 //==================================================
470 // Purpose : Selection by polyline
471 //==================================================
472 AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
473 const Handle(V3d_View)& theView,
474 const Standard_Boolean toUpdateViewer)
476 if (theView->Viewer() == myCTX->CurrentViewer())
478 myMainVS->Pick (thePolyline, theView);
480 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
482 Standard_Integer aLastSelNum = AIS_Selection::Extent();
484 if(!myMainVS->More())
486 // Nothing is selected clear selection, but don't clear the selection
487 // as it is shift selection and previous selection matters.
488 // Return state to know if something was unselected
489 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
494 UnhilightPicked (Standard_False);
497 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
499 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
500 if (myFilters->IsOk (anOwner))
502 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
503 AIS_Selection::Select (anOwner);
504 anOwner->SetSelected (toSelect);
509 HilightPicked (toUpdateViewer);
513 Standard_Integer aSelNum = AIS_Selection::Extent();
515 return (aSelNum == 1) ? AIS_SOP_OneSelected
516 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
520 //==================================================
523 //==================================================
524 void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner,
525 const Handle(V3d_View)& theView)
527 if (theView.IsNull())
532 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
533 myMainPM->BeginImmediateDraw();
534 theOwner->HilightWithColor (myMainPM, myCTX->HilightColor(), aHilightMode);
535 myMainPM->EndImmediateDraw (theView);
538 //==================================================
539 // Function: Unhilight
541 //==================================================
542 void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner,
543 const Handle(V3d_View)& theView)
545 if (theView.IsNull())
550 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
551 if (IsSelected (theOwner))
553 if (theOwner->IsAutoHilight())
555 theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode);
560 theOwner->Unhilight (myMainPM, aHilightMode);
564 //=======================================================================
565 //function : HilightPicked
567 //=======================================================================
568 void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer)
570 Standard_Boolean updMain(Standard_False);
572 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
574 if( Sel.IsNull() ) return;
577 typedef NCollection_DataMap <Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > SelectMgr_DataMapOfObjectOwners;
578 SelectMgr_DataMapOfObjectOwners aMap;
580 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
582 // to avoid problems when there is a loop searching for selected objects...
583 #if !defined OCC189 && !defined USE_MAP
584 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
585 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++)
587 const Handle(Standard_Transient)& Tr = Obj(i);
589 const AIS_NListTransient& Obj = Sel->Objects();
590 AIS_NListTransient::Iterator anIter( Obj );
591 for(; anIter.More(); anIter.Next())
593 const Handle(Standard_Transient)& Tr = anIter.Value();
596 const Handle(SelectMgr_EntityOwner)& Ownr =
597 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
598 Handle(AIS_InteractiveObject) IO;
599 if(Ownr->HasSelectable()){
600 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
601 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
602 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
603 IO = *((Handle(AIS_InteractiveObject)*)&SO);
604 updMain = Standard_True;
607 updMain = Standard_True;
610 updMain = Standard_True;
611 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
612 Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO));
613 if ( Ownr->IsAutoHilight() )
614 Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM);
615 else if ( aMap.IsBound (SO) )
616 aMap(SO)->Append ( Ownr );
618 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq = new SelectMgr_SequenceOfOwner;
619 aSeq->Append ( Ownr );
620 aMap.Bind ( SO, aSeq );
625 for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap);
626 aMapIter.More(); aMapIter.Next() )
628 aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value());
633 myCTX->CurrentViewer()->Update();
637 //==================================================
640 //==================================================
641 void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer)
643 myMainPM->ClearImmediateDraw();
645 Standard_Boolean updMain(Standard_False);
647 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
649 if( Sel.IsNull() ) return;
651 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
652 NCollection_Map<Handle(SelectMgr_SelectableObject)> anObjMap;
654 #if !defined OCC189 && !defined USE_MAP
655 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
656 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
657 const Handle(Standard_Transient)& Tr = Obj(i);
659 const AIS_NListTransient& Obj = Sel->Objects();
660 AIS_NListTransient::Iterator anIter( Obj );
661 for(; anIter.More(); anIter.Next()){
662 const Handle(Standard_Transient)& Tr = anIter.Value();
665 const Handle(SelectMgr_EntityOwner)& Ownr =
666 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
667 Standard_Integer HM(0);
668 if(Ownr->HasSelectable()){
670 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
671 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
676 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
677 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
679 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
680 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
683 updMain = Standard_True;
686 updMain = Standard_True;
688 Ownr->Unhilight(PM,HM);
692 for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator anIter1 ( anObjMap );
693 anIter1.More(); anIter1.Next() )
695 if ( !anIter1.Key()->IsAutoHilight() )
696 anIter1.Key()->ClearSelected();
701 myCTX->CurrentViewer()->Update();
703 if(updMain) myCTX->CurrentViewer()->Update();
709 //=======================================================================
710 //function : IsSelected
712 //=======================================================================
713 Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
715 return (!FindSelectedOwnerFromIO(anIObj).IsNull());
718 //=======================================================================
719 //function : IsSelected
721 //=======================================================================
723 Standard_Boolean AIS_LocalContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
725 return !theOwner.IsNull() && theOwner->IsSelected();
728 //==================================================
731 //==================================================
732 void AIS_LocalContext::
735 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
736 AIS_Selection::CurrentSelection()->Init();
739 //==================================================
742 //==================================================
743 Standard_Boolean AIS_LocalContext::
746 return AIS_Selection::CurrentSelection()->More();
749 //==================================================
752 //==================================================
753 void AIS_LocalContext::
756 AIS_Selection::CurrentSelection()->Next();
759 //==================================================
762 //==================================================
763 Standard_Boolean AIS_LocalContext::
766 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
767 if( Tr.IsNull() ) return Standard_False;
768 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
769 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
770 if(BRO.IsNull()) return Standard_False;
771 Standard_Boolean hasshape = BRO->HasShape();
772 Standard_Boolean comes = BRO->ComesFromDecomposition();
773 return (hasshape&&comes);
776 //================================================================
777 // Function : HasSelectedShape
778 // Purpose : Checks if there is a selected shape regardless of its decomposition status
779 //================================================================
780 Standard_Boolean AIS_LocalContext::HasSelectedShape() const
782 if (AIS_Selection::CurrentSelection()->Extent() == 0)
783 return Standard_False;
785 Handle(Standard_Transient) aCurSelection = AIS_Selection::CurrentSelection()->Value();
786 if (aCurSelection.IsNull())
787 return Standard_False;
789 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSelection);
790 Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
791 if (aBrepOwner.IsNull())
793 return Standard_False;
795 return aBrepOwner->HasShape();
798 //==================================================
801 //==================================================
802 TopoDS_Shape AIS_LocalContext::SelectedShape() const
804 Handle(Standard_Transient) aTr = AIS_Selection::CurrentSelection()->Value();
805 Handle(SelectMgr_EntityOwner) anEO = *((Handle(SelectMgr_EntityOwner)*)&aTr);
806 Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(anEO);
809 return TopoDS_Shape();
812 return aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location());
815 //==================================================
818 //==================================================
819 Handle(AIS_InteractiveObject) AIS_LocalContext::
820 SelectedInteractive() const
822 Handle(AIS_InteractiveObject) IO;
823 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
825 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
826 Handle(SelectMgr_SelectableObject) SO;
827 if(EO->HasSelectable()){
828 SO = EO->Selectable();
829 IO = *((Handle(AIS_InteractiveObject)*)&SO);
834 //==================================================
837 //==================================================
838 Handle(SelectMgr_EntityOwner) AIS_LocalContext::
839 SelectedOwner() const
841 Handle(SelectMgr_EntityOwner) EO;
842 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
844 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
848 //==================================================
851 //==================================================
852 Standard_Boolean AIS_LocalContext::
853 HasApplicative() const
855 Handle(AIS_InteractiveObject) IO = SelectedInteractive();
856 if( IO.IsNull() ) return Standard_False;
857 return IO->HasOwner();
860 //==================================================
863 //==================================================
864 const Handle(Standard_Transient)& AIS_LocalContext::
865 SelectedApplicative() const
867 return SelectedInteractive()->GetOwner();
872 //=======================================================================
873 //function : UpdateSelection
874 //purpose : should disappear...
875 //=======================================================================
876 void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer)
878 UnhilightPicked(Standard_False);
879 HilightPicked(updateviewer);
882 //================================================================
883 // Function : UpdateSelected
884 // Purpose : Part of advanced selection mechanism.
885 // Highlightes or clears selection presentation for the given IO
886 //================================================================
887 void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj,
888 const Standard_Boolean updateviewer)
890 if (anobj.IsNull() || anobj->IsAutoHilight())
893 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
894 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
896 SelectMgr_SequenceOfOwner aSeq;
897 for ( Sel->Init(); Sel->More(); Sel->Next() ){
898 Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value());
900 if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj )
901 aSeq.Append( aOwner );
905 anobj->HilightSelected( myMainPM, aSeq );
907 anobj->ClearSelected();
910 myCTX->CurrentViewer()->Update();
914 //==================================================
915 // Function: ClearSelected
917 //==================================================
918 void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer)
920 UnhilightPicked(updateviewer);
921 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
923 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
924 #if !defined OCC189 && !defined USE_MAP
925 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
926 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
927 const Handle(Standard_Transient)& Tr = Obj(i);
929 const AIS_NListTransient& Obj = Sel->Objects();
930 AIS_NListTransient::Iterator anIter( Obj );
931 for(; anIter.More(); anIter.Next()){
932 const Handle(Standard_Transient)& Tr = anIter.Value();
936 (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False);
939 AIS_Selection::Select();
943 //==================================================
944 // Function: ClearOutdatedSelection
946 //==================================================
947 void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObject)& theIO,
948 const Standard_Boolean toClearDeactivated)
950 // 1. Collect selectable entities
951 SelectMgr_IndexedMapOfOwner aValidOwners;
953 const TColStd_ListOfInteger& aModes = SelectionModes (theIO);
955 TColStd_ListIteratorOfListOfInteger aModeIter (aModes);
956 for (; aModeIter.More(); aModeIter.Next())
958 int aMode = aModeIter.Value();
959 if (!theIO->HasSelection(aMode))
964 if (toClearDeactivated && !mySM->IsActivated (theIO, myMainVS, aMode))
969 Handle(SelectMgr_Selection) aSelection = theIO->Selection(aMode);
970 for (aSelection->Init(); aSelection->More(); aSelection->Next())
972 Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
973 if (anEntity.IsNull())
978 Handle(SelectMgr_EntityOwner) anOwner =
979 Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
981 if (anOwner.IsNull())
986 aValidOwners.Add(anOwner);
990 // 2. Refresh context's detection and selection and keep only active owners
991 // Keep last detected object for lastindex initialization.
992 Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked();
994 // Remove entity owners from detected sequences
995 for (Standard_Integer anIdx = 1; anIdx <= myDetectedSeq.Length(); ++anIdx)
997 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (anIdx));
998 if (anOwner.IsNull() || anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
1003 myDetectedSeq.Remove (anIdx--);
1005 if (anIdx < myCurDetected)
1010 myCurDetected = Max (myCurDetected, 1);
1012 Standard_Boolean isAISRemainsDetected = Standard_False;
1014 // 3. Remove entity owners from AIS_Selection
1015 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
1016 Handle(AIS_Selection) aSelection = AIS_Selection::Selection (mySelName.ToCString());
1017 AIS_NListTransient::Iterator anIter (aSelection->Objects());
1018 AIS_NListTransient aRemoveEntites;
1019 for (; anIter.More(); anIter.Next())
1021 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anIter.Value());
1022 if (anOwner.IsNull() || anOwner->Selectable() != theIO)
1027 if (aValidOwners.Contains (anOwner))
1029 isAISRemainsDetected = Standard_True;
1032 aRemoveEntites.Append (anOwner);
1033 anOwner->SetSelected (Standard_False);
1034 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
1036 Unhilight (anOwner, aViewer->ActiveView());
1040 AIS_NListTransient::Iterator anIterRemove (aRemoveEntites);
1041 for (; anIterRemove.More(); anIterRemove.Next())
1043 aSelection->Select (anIterRemove.Value());
1046 // 4. Remove entity owners from myMapOfOwner
1047 SelectMgr_IndexedMapOfOwner anOwnersToKeep;
1048 for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++)
1050 Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner (anIdx);
1051 if (anOwner.IsNull())
1056 if (anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
1058 anOwnersToKeep.Add (anOwner);
1062 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
1064 Unhilight (anOwner, aViewer->ActiveView());
1068 myMapOfOwner.Clear();
1069 myMapOfOwner.Assign (anOwnersToKeep);
1070 mylastindex = myMapOfOwner.FindIndex (aLastPicked);
1071 if (!IsValidIndex (mylastindex))
1073 myMainPM->ClearImmediateDraw();
1076 if (!isAISRemainsDetected)
1078 // Remove the interactive object from detected sequences
1079 for (Standard_Integer anIdx = 1; anIdx <= myAISDetectedSeq.Length(); ++anIdx)
1081 Handle(AIS_InteractiveObject) aDetectedIO = myAISDetectedSeq.Value (anIdx);
1082 if (aDetectedIO.IsNull() || aDetectedIO != theIO)
1087 myAISDetectedSeq.Remove (anIdx--);
1089 if (anIdx < myAISCurDetected)
1094 myAISCurDetected = Max (myAISCurDetected, 1);
1098 //=======================================================================
1099 //function : SetSelected
1101 //=======================================================================
1102 void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
1103 const Standard_Boolean updateviewer)
1105 if(!IsValidForSelection(anIObj)) return;
1106 UnhilightPicked(Standard_False);
1108 //1st case, owner already <anIObj> as owner
1109 // and not separated is found...
1111 Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString());
1112 //Standard_Boolean found(Standard_False);
1113 Handle(Standard_Transient) Tr;
1114 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj);
1116 //check if in selection number 0 there is an owner that can be triturated...
1117 if(anIObj->HasSelection(0)){
1118 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1121 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1122 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1126 EO = new SelectMgr_EntityOwner(anIObj);
1129 ClearSelected(Standard_False);
1131 AIS_Selection::Select(EO);
1132 EO->SetSelected (Standard_True);
1134 HilightPicked(updateviewer);
1137 //=======================================================================
1138 //function : AddOrRemoveSelected
1140 //=======================================================================
1142 void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1143 const Standard_Boolean updateviewer)
1145 if(!IsValidForSelection(anIObj)) return;
1146 UnhilightPicked(Standard_False);
1147 // first check if it is selected...
1148 Handle(SelectMgr_EntityOwner) EO;
1150 EO = FindSelectedOwnerFromIO(anIObj);
1154 if(anIObj->HasSelection(0))
1156 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1160 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1161 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1166 EO = new SelectMgr_EntityOwner(anIObj);
1170 // cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl;
1171 const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString());
1175 AIS_SelectStatus aStatus = S->Select(EO);
1176 EO->SetSelected (aStatus == AIS_SS_Added);
1179 HilightPicked(updateviewer);
1182 //=======================================================================
1183 //function : AddOrRemoveSelected
1184 //purpose : To check...
1185 //=======================================================================
1186 void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh,
1187 const Standard_Boolean updateviewer)
1189 UnhilightPicked (Standard_False);
1190 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh);
1193 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
1194 EO->SetSelected (Standard_True);
1196 HilightPicked (updateviewer);
1199 void AIS_LocalContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1200 const Standard_Boolean toUpdateViewer)
1204 UnhilightPicked (Standard_False);
1207 Standard_Boolean toSelect = theOwner->IsSelected() ? Standard_False : Standard_True;
1209 AIS_Selection::Selection (mySelName.ToCString())->Select (theOwner);
1210 theOwner->SetSelected (toSelect);
1214 HilightPicked (toUpdateViewer);
1218 //==================================================
1219 // Function: manageDetected
1221 //==================================================
1222 void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner,
1223 const Handle(V3d_View)& theView,
1224 const Standard_Boolean theToRedrawImmediate)
1226 if (thePickOwner.IsNull())
1228 myMainPM->ClearImmediateDraw();
1229 if (theToRedrawImmediate)
1231 theView->RedrawImmediate();
1236 if (!myFilters->IsOk (thePickOwner))
1238 if (mylastindex != 0)
1240 mylastgood = mylastindex;
1242 if (theToRedrawImmediate)
1244 theView->RedrawImmediate();
1249 //=======================================================================================================
1250 // 2 cases : a- object is in the map of picks:
1251 // 1. this is the same index as the last detected: -> Do nothing
1253 // - if lastindex = 0 (no object was detected at the last step)
1254 // the object presentation is highlighted and lastindex = index(objet)
1256 // the presentation of the object corresponding to lastindex is "unhighlighted"
1257 // it is removed if the object is not visualized but only active
1258 // then the presentation of the detected object is highlighted and lastindex = index(objet)
1259 // b- the object is not in the map of picked objects
1260 // - if lastindex != 0 (object detected at the last step) it is unhighlighted ...
1261 // if the object was decomposed, presentation is created for the detected shape and the couple
1262 // (Proprietaire,Prs)is added in the map.
1263 // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object
1264 // itself is highlighted.
1266 //=======================================================================================================
1268 const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner)
1269 ? myMapOfOwner.FindIndex (thePickOwner)
1270 : myMapOfOwner.Add (thePickOwner);
1272 // For the advanced mesh selection mode the owner indices comparison
1273 // is not effective because in that case only one owner manage the
1274 // selection in current selection mode. It is necessary to check the current detected
1275 // entity and hilight it only if the detected entity is not the same as
1276 // previous detected (IsForcedHilight call)
1277 if (aNewIndex != mylastindex
1278 || thePickOwner->IsForcedHilight())
1280 myMainPM->ClearImmediateDraw();
1281 if (mylastindex != 0
1282 && mylastindex <= myMapOfOwner.Extent())
1284 const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex);
1285 Unhilight (aLastOwner, theView);
1290 if (!thePickOwner->IsSelected() || myCTX->ToHilightSelected())
1292 Hilight (thePickOwner, theView);
1294 if (theToRedrawImmediate)
1296 theView->RedrawImmediate();
1300 mylastindex = aNewIndex;
1303 if (mylastindex != 0)
1305 mylastgood = mylastindex;
1309 //=======================================================================
1310 //function : HasDetectedShape
1312 //=======================================================================
1314 Standard_Boolean AIS_LocalContext::HasDetectedShape() const
1316 if(mylastindex==0) return Standard_False;
1317 return IsShape(mylastindex);
1320 //=======================================================================
1321 //function : DetectedShape
1323 //=======================================================================
1326 AIS_LocalContext::DetectedShape() const
1328 static TopoDS_Shape bidsh;
1329 if(mylastindex != 0)
1331 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex));
1332 if(BROwnr.IsNull()) return bidsh;
1333 return BROwnr->Shape();
1338 //=======================================================================
1339 //function : DetectedInteractive
1341 //=======================================================================
1343 Handle(AIS_InteractiveObject)
1344 AIS_LocalContext::DetectedInteractive() const
1346 Handle(AIS_InteractiveObject) Iobj;
1347 if(IsValidIndex(mylastindex)){
1348 Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
1349 Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
1353 //=======================================================================
1354 //function : DetectedInteractive
1356 //=======================================================================
1357 Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
1359 Handle(SelectMgr_EntityOwner) bid;
1360 if(!IsValidIndex(mylastindex)) return bid;
1361 return myMapOfOwner.FindKey(mylastindex);
1365 //=======================================================================
1366 //function : ComesFromDecomposition
1368 //=======================================================================
1370 Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
1372 const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex);
1373 Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
1374 if (myActiveObjects.IsBound (aSel)) { // debug of jmi
1375 const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
1376 return Stat->Decomposed();
1378 return Standard_False;
1382 //=======================================================================
1383 //function : DisplayAreas
1385 //=======================================================================
1387 void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
1389 myMainVS->DisplayAreas(aviou);
1392 //=======================================================================
1393 //function : ClearAreas
1395 //=======================================================================
1397 void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
1399 myMainVS->ClearAreas(aviou);
1402 //=======================================================================
1403 //function : DisplaySensitive
1405 //=======================================================================
1407 void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou)
1409 myMainVS->DisplaySensitive(aviou);
1412 //=======================================================================
1413 //function : ClearSensitive
1415 //=======================================================================
1417 void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
1419 myMainVS->ClearSensitive(aviou);
1423 //=======================================================================
1424 //function : IsShape
1426 //=======================================================================
1427 Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
1430 if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull())
1431 return Standard_False;
1433 ComesFromDecomposition(Index);
1436 Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const
1440 // Shape was not transfered from AIS_Shape to EntityOwner
1441 Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj);
1442 if( !shape.IsNull() )
1443 return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape));
1445 return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj));
1449 //=======================================================================
1450 //function : HilightNextDetected
1452 //=======================================================================
1453 Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView,
1454 const Standard_Boolean theToRedrawImmediate)
1456 // go to the next owner
1457 if (myDetectedSeq.IsEmpty())
1462 const Standard_Integer aLen = myDetectedSeq.Length();
1463 if (++myCurDetected > aLen)
1467 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
1468 if (anOwner.IsNull())
1472 manageDetected (anOwner, theView, theToRedrawImmediate);
1473 return myCurDetected;
1476 //=======================================================================
1477 //function : HilightPreviousDetected
1479 //=======================================================================
1480 Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1481 const Standard_Boolean theToRedrawImmediate)
1483 if (myDetectedSeq.IsEmpty())
1488 const Standard_Integer aLen = myDetectedSeq.Length();
1489 if (--myCurDetected < 1)
1491 myCurDetected = aLen;
1493 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
1494 if (anOwner.IsNull())
1499 manageDetected (anOwner, theView, theToRedrawImmediate);
1500 return myCurDetected;
1503 //=======================================================================
1504 //function : UnhilightLastDetected
1506 //=======================================================================
1507 Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView)
1509 if (!IsValidIndex (mylastindex))
1511 return Standard_False;
1514 myMainPM->BeginImmediateDraw();
1515 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex);
1516 const Standard_Integer aHilightMode = anOwner->HasSelectable()
1517 ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
1520 myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode);
1521 myMainPM->EndImmediateDraw (theView);
1523 return Standard_True;
1526 //=======================================================================
1527 //function : FindSelectedOwnerFromIO
1528 //purpose : it is checked if one of the selected owners really presents IObj
1529 //=======================================================================
1530 Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO
1531 (const Handle(AIS_InteractiveObject)& anIObj) const
1533 Handle(SelectMgr_EntityOwner) EO,bid;
1534 if (anIObj.IsNull()) return EO;
1536 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1539 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "
1540 <<mySelName<<" Nulle "<<endl;
1544 Standard_Boolean found(Standard_False);
1545 #if !defined OCC189 && !defined USE_MAP
1546 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
1547 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
1548 const Handle(Standard_Transient)& Tr = Obj(i);
1550 const AIS_NListTransient& Obj = Sel->Objects();
1551 AIS_NListTransient::Iterator anIter( Obj );
1552 for(; anIter.More(); anIter.Next()){
1553 const Handle(Standard_Transient)& Tr = anIter.Value();
1556 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1557 if(EO->HasSelectable()){
1558 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1559 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
1560 if (anIObj == EO->Selectable()){
1561 found =Standard_True;
1568 if(found) return EO;
1572 //=======================================================================
1573 //function : FindSelectedOwnerFromShape
1574 //purpose : it is checked if one of the selected owners really presents IObj
1575 //=======================================================================
1576 Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const
1579 Handle(SelectMgr_EntityOwner) EO, bid;
1581 Handle(SelectMgr_EntityOwner) EO;
1583 if (sh.IsNull()) return EO;
1585 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1588 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl;
1593 Standard_Boolean found(Standard_False);
1597 SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives());
1598 for (; aSensitiveIt.More(); aSensitiveIt.Next()) {
1599 EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId());
1600 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1601 if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) {
1602 found = Standard_True;
1608 #if !defined OCC189 && !defined USE_MAP
1609 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
1610 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
1611 const Handle(Standard_Transient)& Tr = Obj(i);
1613 const AIS_NListTransient& Obj = Sel->Objects();
1614 AIS_NListTransient::Iterator anIter( Obj );
1615 for(; anIter.More(); anIter.Next()){
1616 const Handle(Standard_Transient)& Tr = anIter.Value();
1620 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1622 if ( EO->Shape() == sh)
1623 found =Standard_True;
1629 if(found) return EO;
1634 //=======================================================================
1635 //function : AIS_LocalContext::InitDetected
1637 //=======================================================================
1638 void AIS_LocalContext::InitDetected()
1640 myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0;
1643 //=======================================================================
1644 //function : AIS_LocalContext::MoreDetected
1646 //=======================================================================
1647 Standard_Boolean AIS_LocalContext::MoreDetected() const
1649 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length());
1652 //=======================================================================
1653 //function : AIS_LocalContext::NextDetected
1655 //=======================================================================
1656 void AIS_LocalContext::NextDetected()
1661 //=======================================================================
1662 //function : DetectedCurrentShape
1664 //=======================================================================
1665 const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
1667 static TopoDS_Shape aDummyShape;
1669 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1671 if (aCurrentShape.IsNull())
1676 return aCurrentShape->Shape();
1678 //=======================================================================
1679 //function : DetectedCurrentObject
1681 //=======================================================================
1682 Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const
1684 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;