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 Unhilight (myMapOfOwner (mylastindex), theView);
157 if (theToRedrawImmediate)
159 theView->RedrawImmediate();
164 return aDetectedNb == 0
169 // all owners detected by the selector are passed to the
170 // filters and correct ones are preserved...
172 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
173 manageDetected (anOwner, theView, theToRedrawImmediate);
174 if (myDetectedSeq.Length() == 1)
176 return aDetectedNb == 1
177 ? AIS_SOD_OnlyOneDetected
178 : AIS_SOD_OnlyOneGood;
182 return AIS_SOD_SeveralGood;
186 //=======================================================================
189 //=======================================================================
190 AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer)
194 UnhilightPicked (Standard_False);
197 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
199 Standard_Integer aDetIndex = DetectedIndex();
202 ClearSelected (toUpdateViewer);
203 return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
206 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex);
208 ClearSelected (Standard_False);
210 if (!anOwner->IsSelected()) // anOwner is not selected
212 anOwner->SetSelected (Standard_True);
213 AIS_Selection::Select (anOwner);
218 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
219 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
221 Unhilight (anOwner, aViewer->ActiveView());
224 // advanced selection highlighting mechanism
225 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
227 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
228 UpdateSelected (anIO, Standard_False);
233 myCTX->CurrentViewer()->Update();
237 return (AIS_Selection::Extent() == 1) ? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected;
240 //=======================================================================
243 //=======================================================================
244 AIS_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)
251 if (theView->Viewer() == myCTX->CurrentViewer())
253 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
256 UnhilightPicked (Standard_False);
259 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
260 Standard_Integer aSelNum = AIS_Selection::Extent();
263 if (!myMainVS->More())
265 ClearSelected (toUpdateViewer);
267 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
270 ClearSelected (Standard_False);
272 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
274 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
275 if (myFilters->IsOk (anOwner))
277 // it can be helpful to classify this owner immediately...
278 if (!anOwner->IsSelected())
280 anOwner->SetSelected (Standard_True);
281 AIS_Selection::Select (anOwner);
288 HilightPicked (toUpdateViewer);
292 Standard_Integer aSelNum = AIS_Selection::Extent();
294 return (aSelNum == 1) ? AIS_SOP_OneSelected
295 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
299 //==================================================
301 // Purpose : Selection by polyline
302 //==================================================
303 AIS_StatusOfPick AIS_LocalContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
304 const Handle(V3d_View)& theView,
305 const Standard_Boolean toUpdateViewer)
307 if (theView->Viewer() == myCTX->CurrentViewer())
309 myMainVS->Pick (thePolyline, theView);
311 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
313 Standard_Integer aLastSelNum = AIS_Selection::Extent();
315 if (!myMainVS->More())
317 // Nothing is selected clear selection.
318 ClearSelected (toUpdateViewer);
321 // Return state to know if something was unselected
322 return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
327 UnhilightPicked (Standard_False);
330 // Clear previous selection without update to process this selection
331 ClearSelected (Standard_False);
333 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
335 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
336 if (myFilters->IsOk (anOwner))
338 // it can be helpful to classify this owner immediately...
339 if (!anOwner->IsSelected())
341 AIS_Selection::AddSelect (anOwner);
342 anOwner->SetSelected (Standard_True);
349 HilightPicked (toUpdateViewer);
353 Standard_Integer aSelNum = AIS_Selection::Extent();
354 return (aSelNum == 1) ? AIS_SOP_OneSelected
355 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
359 //=======================================================================
360 //function : ShiftSelect
362 //=======================================================================
363 AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
365 Standard_Integer aDetIndex = DetectedIndex();
366 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
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);
379 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
380 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
382 Unhilight (anOwner, aViewer->ActiveView());
385 // advanced selection highlighting mechanism
386 if (!anOwner->IsAutoHilight() && anOwner->HasSelectable())
388 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
389 UpdateSelected (anIO, Standard_False);
394 myCTX->CurrentViewer()->Update();
399 Standard_Integer NS = AIS_Selection::Extent();
400 if( NS == 1 ) return AIS_SOP_OneSelected;
401 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
402 return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
405 return AIS_SOP_Error;
408 //=======================================================================
409 //function : ShiftSelect
411 //=======================================================================
412 AIS_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)
419 myMainPM->ClearImmediateDraw();
421 if (theView->Viewer() == myCTX->CurrentViewer())
423 myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
425 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
426 Standard_Integer aLastSelNum = AIS_Selection::Extent();
429 if (!myMainVS->More())
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;
439 UnhilightPicked (Standard_False);
442 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
444 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
445 if(myFilters->IsOk (anOwner))
447 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
448 AIS_Selection::Select (anOwner);
449 anOwner->SetSelected (toSelect);
455 HilightPicked (toUpdateViewer);
459 Standard_Integer aSelNum = AIS_Selection::Extent();
461 return (aSelNum == 1) ? AIS_SOP_OneSelected
462 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
466 //==================================================
468 // Purpose : Selection by polyline
469 //==================================================
470 AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
471 const Handle(V3d_View)& theView,
472 const Standard_Boolean toUpdateViewer)
474 if (theView->Viewer() == myCTX->CurrentViewer())
476 myMainVS->Pick (thePolyline, theView);
478 AIS_Selection::SetCurrentSelection (mySelName.ToCString());
480 Standard_Integer aLastSelNum = AIS_Selection::Extent();
482 if(!myMainVS->More())
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;
492 UnhilightPicked (Standard_False);
495 for (myMainVS->Init(); myMainVS->More(); myMainVS->Next())
497 const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked();
498 if (myFilters->IsOk (anOwner))
500 Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
501 AIS_Selection::Select (anOwner);
502 anOwner->SetSelected (toSelect);
507 HilightPicked (toUpdateViewer);
511 Standard_Integer aSelNum = AIS_Selection::Extent();
513 return (aSelNum == 1) ? AIS_SOP_OneSelected
514 : (aSelNum > 1) ? AIS_SOP_SeveralSelected
518 //==================================================
521 //==================================================
522 void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner,
523 const Handle(V3d_View)& theView)
525 if (theView.IsNull())
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);
536 //==================================================
537 // Function: Unhilight
539 //==================================================
540 void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner,
541 const Handle(V3d_View)& theView)
543 if (theView.IsNull())
548 myMainPM->ClearImmediateDraw();
549 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
550 if (IsSelected (theOwner))
552 if (theOwner->IsAutoHilight())
554 theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode);
559 theOwner->Unhilight (myMainPM, aHilightMode);
563 //=======================================================================
564 //function : HilightPicked
566 //=======================================================================
567 void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer)
569 Standard_Boolean updMain(Standard_False);
571 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
573 if( Sel.IsNull() ) return;
576 typedef NCollection_DataMap <Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > SelectMgr_DataMapOfObjectOwners;
577 SelectMgr_DataMapOfObjectOwners aMap;
579 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
581 // to avoid problems when there is a loop searching for selected objects...
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++)
586 const Handle(Standard_Transient)& Tr = Obj(i);
588 const AIS_NListTransient& Obj = Sel->Objects();
589 AIS_NListTransient::Iterator anIter( Obj );
590 for(; anIter.More(); anIter.Next())
592 const Handle(Standard_Transient)& Tr = anIter.Value();
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);
603 updMain = Standard_True;
606 updMain = Standard_True;
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) )
615 aMap(SO)->Append ( Ownr );
617 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq = new SelectMgr_SequenceOfOwner;
618 aSeq->Append ( Ownr );
619 aMap.Bind ( SO, aSeq );
624 for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap);
625 aMapIter.More(); aMapIter.Next() )
627 aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value());
632 myCTX->CurrentViewer()->Update();
636 //==================================================
639 //==================================================
640 void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer)
642 myMainPM->ClearImmediateDraw();
644 Standard_Boolean updMain(Standard_False);
646 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
648 if( Sel.IsNull() ) return;
650 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
651 NCollection_Map<Handle(SelectMgr_SelectableObject)> anObjMap;
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);
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();
664 const Handle(SelectMgr_EntityOwner)& Ownr =
665 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
666 Standard_Integer HM(0);
667 if(Ownr->HasSelectable()){
669 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
670 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
675 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
676 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
678 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
679 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
682 updMain = Standard_True;
685 updMain = Standard_True;
687 Ownr->Unhilight(PM,HM);
691 for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator anIter1 ( anObjMap );
692 anIter1.More(); anIter1.Next() )
694 if ( !anIter1.Key()->IsAutoHilight() )
695 anIter1.Key()->ClearSelected();
700 myCTX->CurrentViewer()->Update();
702 if(updMain) myCTX->CurrentViewer()->Update();
708 //=======================================================================
709 //function : IsSelected
711 //=======================================================================
712 Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
714 return (!FindSelectedOwnerFromIO(anIObj).IsNull());
717 //=======================================================================
718 //function : IsSelected
720 //=======================================================================
722 Standard_Boolean AIS_LocalContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
724 return !theOwner.IsNull() && theOwner->IsSelected();
727 //==================================================
730 //==================================================
731 void AIS_LocalContext::
734 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
735 AIS_Selection::CurrentSelection()->Init();
738 //==================================================
741 //==================================================
742 Standard_Boolean AIS_LocalContext::
745 return AIS_Selection::CurrentSelection()->More();
748 //==================================================
751 //==================================================
752 void AIS_LocalContext::
755 AIS_Selection::CurrentSelection()->Next();
758 //==================================================
761 //==================================================
762 Standard_Boolean AIS_LocalContext::
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);
775 //================================================================
776 // Function : HasSelectedShape
777 // Purpose : Checks if there is a selected shape regardless of its decomposition status
778 //================================================================
779 Standard_Boolean AIS_LocalContext::HasSelectedShape() const
781 if (AIS_Selection::CurrentSelection()->Extent() == 0)
782 return Standard_False;
784 Handle(Standard_Transient) aCurSelection = AIS_Selection::CurrentSelection()->Value();
785 if (aCurSelection.IsNull())
786 return Standard_False;
788 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSelection);
789 Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
790 if (aBrepOwner.IsNull())
792 return Standard_False;
794 return aBrepOwner->HasShape();
797 //==================================================
800 //==================================================
801 TopoDS_Shape AIS_LocalContext::SelectedShape() const
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);
808 return TopoDS_Shape();
811 return aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location());
814 //==================================================
817 //==================================================
818 Handle(AIS_InteractiveObject) AIS_LocalContext::
819 SelectedInteractive() const
821 Handle(AIS_InteractiveObject) IO;
822 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
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);
833 //==================================================
836 //==================================================
837 Handle(SelectMgr_EntityOwner) AIS_LocalContext::
838 SelectedOwner() const
840 Handle(SelectMgr_EntityOwner) EO;
841 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
843 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
847 //==================================================
850 //==================================================
851 Standard_Boolean AIS_LocalContext::
852 HasApplicative() const
854 Handle(AIS_InteractiveObject) IO = SelectedInteractive();
855 if( IO.IsNull() ) return Standard_False;
856 return IO->HasOwner();
859 //==================================================
862 //==================================================
863 const Handle(Standard_Transient)& AIS_LocalContext::
864 SelectedApplicative() const
866 return SelectedInteractive()->GetOwner();
871 //=======================================================================
872 //function : UpdateSelection
873 //purpose : should disappear...
874 //=======================================================================
875 void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer)
877 UnhilightPicked(Standard_False);
878 HilightPicked(updateviewer);
881 //================================================================
882 // Function : UpdateSelected
883 // Purpose : Part of advanced selection mechanism.
884 // Highlightes or clears selection presentation for the given IO
885 //================================================================
886 void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj,
887 const Standard_Boolean updateviewer)
889 if (anobj.IsNull() || anobj->IsAutoHilight())
892 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
893 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
895 SelectMgr_SequenceOfOwner aSeq;
896 for ( Sel->Init(); Sel->More(); Sel->Next() ){
897 Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value());
899 if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj )
900 aSeq.Append( aOwner );
904 anobj->HilightSelected( myMainPM, aSeq );
906 anobj->ClearSelected();
909 myCTX->CurrentViewer()->Update();
913 //==================================================
914 // Function: ClearSelected
916 //==================================================
917 void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer)
919 UnhilightPicked(updateviewer);
920 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
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);
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();
935 (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False);
938 AIS_Selection::Select();
942 //==================================================
943 // Function: ClearOutdatedSelection
945 //==================================================
946 void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObject)& theIO,
947 const Standard_Boolean toClearDeactivated)
949 // 1. Collect selectable entities
950 SelectMgr_IndexedMapOfOwner aValidOwners;
952 const TColStd_ListOfInteger& aModes = SelectionModes (theIO);
954 TColStd_ListIteratorOfListOfInteger aModeIter (aModes);
955 for (; aModeIter.More(); aModeIter.Next())
957 int aMode = aModeIter.Value();
958 if (!theIO->HasSelection(aMode))
963 if (toClearDeactivated && !mySM->IsActivated (theIO, myMainVS, aMode))
968 Handle(SelectMgr_Selection) aSelection = theIO->Selection(aMode);
969 for (aSelection->Init(); aSelection->More(); aSelection->Next())
971 Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
972 if (anEntity.IsNull())
977 Handle(SelectMgr_EntityOwner) anOwner =
978 Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
980 if (anOwner.IsNull())
985 aValidOwners.Add(anOwner);
989 // 2. Refresh context's detection and selection and keep only active owners
990 // Keep last detected object for lastindex initialization.
991 Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked();
993 // Remove entity owners from detected sequences
994 for (Standard_Integer anIdx = 1; anIdx <= myDetectedSeq.Length(); ++anIdx)
996 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (anIdx));
997 if (anOwner.IsNull() || anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
1002 myDetectedSeq.Remove (anIdx--);
1004 if (anIdx < myCurDetected)
1009 myCurDetected = Max (myCurDetected, 1);
1011 Standard_Boolean isAISRemainsDetected = Standard_False;
1013 // 3. Remove entity owners from AIS_Selection
1014 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
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())
1020 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anIter.Value());
1021 if (anOwner.IsNull() || anOwner->Selectable() != theIO)
1026 if (aValidOwners.Contains (anOwner))
1028 isAISRemainsDetected = Standard_True;
1031 aRemoveEntites.Append (anOwner);
1032 anOwner->SetSelected (Standard_False);
1033 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
1035 Unhilight (anOwner, aViewer->ActiveView());
1039 AIS_NListTransient::Iterator anIterRemove (aRemoveEntites);
1040 for (; anIterRemove.More(); anIterRemove.Next())
1042 aSelection->Select (anIterRemove.Value());
1045 // 4. Remove entity owners from myMapOfOwner
1046 SelectMgr_IndexedMapOfOwner anOwnersToKeep;
1047 for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++)
1049 Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner (anIdx);
1050 if (anOwner.IsNull())
1055 if (anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner))
1057 anOwnersToKeep.Add (anOwner);
1061 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
1063 Unhilight (anOwner, aViewer->ActiveView());
1067 myMapOfOwner.Clear();
1068 myMapOfOwner.Assign (anOwnersToKeep);
1069 mylastindex = myMapOfOwner.FindIndex (aLastPicked);
1071 if (!isAISRemainsDetected)
1073 // Remove the interactive object from detected sequences
1074 for (Standard_Integer anIdx = 1; anIdx <= myAISDetectedSeq.Length(); ++anIdx)
1076 Handle(AIS_InteractiveObject) aDetectedIO = myAISDetectedSeq.Value (anIdx);
1077 if (aDetectedIO.IsNull() || aDetectedIO != theIO)
1082 myAISDetectedSeq.Remove (anIdx--);
1084 if (anIdx < myAISCurDetected)
1089 myAISCurDetected = Max (myAISCurDetected, 1);
1093 //=======================================================================
1094 //function : SetSelected
1096 //=======================================================================
1097 void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
1098 const Standard_Boolean updateviewer)
1100 if(!IsValidForSelection(anIObj)) return;
1101 UnhilightPicked(Standard_False);
1103 //1st case, owner already <anIObj> as owner
1104 // and not separated is found...
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);
1111 //check if in selection number 0 there is an owner that can be triturated...
1112 if(anIObj->HasSelection(0)){
1113 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1116 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1117 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1121 EO = new SelectMgr_EntityOwner(anIObj);
1124 ClearSelected(Standard_False);
1126 AIS_Selection::Select(EO);
1127 EO->SetSelected (Standard_True);
1129 HilightPicked(updateviewer);
1132 //=======================================================================
1133 //function : AddOrRemoveSelected
1135 //=======================================================================
1137 void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1138 const Standard_Boolean updateviewer)
1140 if(!IsValidForSelection(anIObj)) return;
1141 UnhilightPicked(Standard_False);
1142 // first check if it is selected...
1143 Handle(SelectMgr_EntityOwner) EO;
1145 EO = FindSelectedOwnerFromIO(anIObj);
1149 if(anIObj->HasSelection(0))
1151 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1155 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1156 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1161 EO = new SelectMgr_EntityOwner(anIObj);
1165 // cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl;
1166 const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString());
1170 AIS_SelectStatus aStatus = S->Select(EO);
1171 EO->SetSelected (aStatus == AIS_SS_Added);
1174 HilightPicked(updateviewer);
1177 //=======================================================================
1178 //function : AddOrRemoveSelected
1179 //purpose : To check...
1180 //=======================================================================
1181 void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh,
1182 const Standard_Boolean updateviewer)
1184 UnhilightPicked (Standard_False);
1185 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh);
1188 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
1189 EO->SetSelected (Standard_True);
1191 HilightPicked (updateviewer);
1194 void AIS_LocalContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1195 const Standard_Boolean toUpdateViewer)
1199 UnhilightPicked (Standard_False);
1202 Standard_Boolean toSelect = theOwner->IsSelected() ? Standard_False : Standard_True;
1204 AIS_Selection::Selection (mySelName.ToCString())->Select (theOwner);
1205 theOwner->SetSelected (toSelect);
1209 HilightPicked (toUpdateViewer);
1213 //==================================================
1214 // Function: manageDetected
1216 //==================================================
1217 void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner,
1218 const Handle(V3d_View)& theView,
1219 const Standard_Boolean theToRedrawImmediate)
1221 if (thePickOwner.IsNull())
1223 if (theToRedrawImmediate)
1225 theView->RedrawImmediate();
1230 if (!myFilters->IsOk (thePickOwner))
1232 if (mylastindex != 0)
1234 mylastgood = mylastindex;
1236 if (theToRedrawImmediate)
1238 theView->RedrawImmediate();
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
1247 // - if lastindex = 0 (no object was detected at the last step)
1248 // the object presentation is highlighted and lastindex = index(objet)
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.
1260 //=======================================================================================================
1262 const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner)
1263 ? myMapOfOwner.FindIndex (thePickOwner)
1264 : myMapOfOwner.Add (thePickOwner);
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())
1274 if (mylastindex != 0
1275 && mylastindex <= myMapOfOwner.Extent())
1277 const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex);
1278 Unhilight (aLastOwner, theView);
1283 if (!thePickOwner->IsSelected() || myCTX->ToHilightSelected())
1285 Hilight (thePickOwner, theView);
1287 if (theToRedrawImmediate)
1289 theView->RedrawImmediate();
1293 mylastindex = aNewIndex;
1298 mylastgood = mylastindex;
1302 //=======================================================================
1303 //function : HasDetectedShape
1305 //=======================================================================
1307 Standard_Boolean AIS_LocalContext::HasDetectedShape() const
1309 if(mylastindex==0) return Standard_False;
1310 return IsShape(mylastindex);
1313 //=======================================================================
1314 //function : DetectedShape
1316 //=======================================================================
1319 AIS_LocalContext::DetectedShape() const
1321 static TopoDS_Shape bidsh;
1322 if(mylastindex != 0)
1324 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex));
1325 if(BROwnr.IsNull()) return bidsh;
1326 return BROwnr->Shape();
1331 //=======================================================================
1332 //function : DetectedInteractive
1334 //=======================================================================
1336 Handle(AIS_InteractiveObject)
1337 AIS_LocalContext::DetectedInteractive() const
1339 Handle(AIS_InteractiveObject) Iobj;
1340 if(IsValidIndex(mylastindex)){
1341 Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
1342 Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
1346 //=======================================================================
1347 //function : DetectedInteractive
1349 //=======================================================================
1350 Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
1352 Handle(SelectMgr_EntityOwner) bid;
1353 if(!IsValidIndex(mylastindex)) return bid;
1354 return myMapOfOwner.FindKey(mylastindex);
1358 //=======================================================================
1359 //function : ComesFromDecomposition
1361 //=======================================================================
1363 Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
1365 const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex);
1366 Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
1367 if (myActiveObjects.IsBound (aSel)) { // debug of jmi
1368 const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
1369 return Stat->Decomposed();
1371 return Standard_False;
1375 //=======================================================================
1376 //function : DisplayAreas
1378 //=======================================================================
1380 void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
1382 myMainVS->DisplayAreas(aviou);
1385 //=======================================================================
1386 //function : ClearAreas
1388 //=======================================================================
1390 void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
1392 myMainVS->ClearAreas(aviou);
1395 //=======================================================================
1396 //function : DisplaySensitive
1398 //=======================================================================
1400 void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou)
1402 myMainVS->DisplaySensitive(aviou);
1405 //=======================================================================
1406 //function : ClearSensitive
1408 //=======================================================================
1410 void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
1412 myMainVS->ClearSensitive(aviou);
1416 //=======================================================================
1417 //function : IsShape
1419 //=======================================================================
1420 Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
1423 if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull())
1424 return Standard_False;
1426 ComesFromDecomposition(Index);
1429 Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const
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));
1438 return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj));
1442 //=======================================================================
1443 //function : HilightNextDetected
1445 //=======================================================================
1446 Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView,
1447 const Standard_Boolean theToRedrawImmediate)
1449 // go to the next owner
1450 if (myDetectedSeq.IsEmpty())
1455 const Standard_Integer aLen = myDetectedSeq.Length();
1456 if (++myCurDetected > aLen)
1460 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
1461 if (anOwner.IsNull())
1465 manageDetected (anOwner, theView, theToRedrawImmediate);
1466 return myCurDetected;
1469 //=======================================================================
1470 //function : HilightPreviousDetected
1472 //=======================================================================
1473 Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1474 const Standard_Boolean theToRedrawImmediate)
1476 if (myDetectedSeq.IsEmpty())
1481 const Standard_Integer aLen = myDetectedSeq.Length();
1482 if (--myCurDetected < 1)
1484 myCurDetected = aLen;
1486 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
1487 if (anOwner.IsNull())
1492 manageDetected (anOwner, theView, theToRedrawImmediate);
1493 return myCurDetected;
1496 //=======================================================================
1497 //function : UnhilightLastDetected
1499 //=======================================================================
1500 Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView)
1502 if (!IsValidIndex (mylastindex))
1504 return Standard_False;
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()))
1513 myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode);
1514 myMainPM->EndImmediateDraw (theView);
1516 return Standard_True;
1519 //=======================================================================
1520 //function : FindSelectedOwnerFromIO
1521 //purpose : it is checked if one of the selected owners really presents IObj
1522 //=======================================================================
1523 Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO
1524 (const Handle(AIS_InteractiveObject)& anIObj) const
1526 Handle(SelectMgr_EntityOwner) EO,bid;
1527 if (anIObj.IsNull()) return EO;
1529 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1532 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "
1533 <<mySelName<<" Nulle "<<endl;
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);
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();
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;
1561 if(found) return EO;
1565 //=======================================================================
1566 //function : FindSelectedOwnerFromShape
1567 //purpose : it is checked if one of the selected owners really presents IObj
1568 //=======================================================================
1569 Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const
1572 Handle(SelectMgr_EntityOwner) EO, bid;
1574 Handle(SelectMgr_EntityOwner) EO;
1576 if (sh.IsNull()) return EO;
1578 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1581 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl;
1586 Standard_Boolean found(Standard_False);
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;
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);
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();
1613 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1615 if ( EO->Shape() == sh)
1616 found =Standard_True;
1622 if(found) return EO;
1627 //=======================================================================
1628 //function : AIS_LocalContext::InitDetected
1630 //=======================================================================
1631 void AIS_LocalContext::InitDetected()
1633 myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0;
1636 //=======================================================================
1637 //function : AIS_LocalContext::MoreDetected
1639 //=======================================================================
1640 Standard_Boolean AIS_LocalContext::MoreDetected() const
1642 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length());
1645 //=======================================================================
1646 //function : AIS_LocalContext::NextDetected
1648 //=======================================================================
1649 void AIS_LocalContext::NextDetected()
1654 //=======================================================================
1655 //function : DetectedCurrentShape
1657 //=======================================================================
1658 const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
1660 static TopoDS_Shape aDummyShape;
1662 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1664 if (aCurrentShape.IsNull())
1669 return aCurrentShape->Shape();
1671 //=======================================================================
1672 //function : DetectedCurrentObject
1674 //=======================================================================
1675 Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const
1677 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;