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_MapOfTransient.hxx>
76 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
77 #include <Prs3d_Presentation.hxx>
78 #include <Prs3d_Drawer.hxx>
79 #include <Prs3d_ShadingAspect.hxx>
80 #include <AIS_LocalStatus.hxx>
81 #include <StdPrs_WFShape.hxx>
82 #include <Graphic3d_ArrayOfTriangles.hxx>
83 #include <Graphic3d_Group.hxx>
84 #include <Select3D_SensitiveTriangulation.hxx>
85 #include <SelectBasics_SensitiveEntity.hxx>
86 #include <TCollection_AsciiString.hxx>
88 #include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
90 #include <SelectMgr_Selection.hxx>
91 #include <OSD_Environment.hxx>
92 #include <SelectMgr_DataMapOfObjectOwners.hxx>
94 #include <Geom_Transformation.hxx>
95 #include <AIS_Selection.hxx>
96 #include <Aspect_Grid.hxx>
98 #include <AIS_Shape.hxx>
102 static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO)
104 return IO->HasHilightMode() ? IO->HilightMode():0;
107 //==================================================
110 //==================================================
111 AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix,
112 const Standard_Integer theYpix,
113 const Handle(V3d_View)& theView,
114 const Standard_Boolean theToRedrawImmediate)
116 // check that ViewerSelector gives
117 if (theView->Viewer() != myCTX->CurrentViewer())
119 return AIS_SOD_Error;
122 myAISCurDetected = 0;
123 myAISDetectedSeq.Clear();
126 myDetectedSeq.Clear();
127 myMainVS->Pick (theXpix, theYpix, theView);
129 const Standard_Integer aDetectedNb = myMainVS->NbPicked();
130 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
132 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (aDetIter);
134 || !myFilters->IsOk (anOwner))
139 myDetectedSeq.Append (aDetIter); // normallly they are already arranged in correct order...
140 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
141 if (!Handle(AIS_Shape)::DownCast (anObj).IsNull())
143 myAISDetectedSeq.Append (anObj);
147 // result of courses..
148 if (aDetectedNb == 0 || myDetectedSeq.IsEmpty())
150 if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent())
152 Unhilight (myMapOfOwner (mylastindex), theView);
153 if (theToRedrawImmediate)
155 theView->RedrawImmediate();
160 return aDetectedNb == 0
165 // all owners detected by the selector are passed to the
166 // filters and correct ones are preserved...
168 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected));
169 manageDetected (anOwner, theView, theToRedrawImmediate);
170 if (myDetectedSeq.Length() == 1)
172 return aDetectedNb == 1
173 ? AIS_SOD_OnlyOneDetected
174 : AIS_SOD_OnlyOneGood;
178 return AIS_SOD_SeveralGood;
182 //==================================================
185 //==================================================
186 AIS_StatusOfPick AIS_LocalContext::Select(const Standard_Boolean updateviewer)
189 UnhilightPicked(Standard_False);
191 Standard_Integer DI = DetectedIndex();
192 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
193 Standard_Integer NbSel = AIS_Selection::Extent();
196 ClearSelected(updateviewer);
197 return NbSel== 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
200 const Handle(SelectMgr_EntityOwner)& EO = myMapOfOwner(DI);
203 ClearSelected(Standard_False);
204 Standard_Integer state = EO->State();
207 if( state == 0 ) AIS_Selection::Select(EO);
211 AIS_Selection::ClearAndSelect(EO);
216 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
217 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
219 Unhilight (EO, aViewer->ActiveView());
222 // advanced selection highlighting mechanism
223 if (!EO->IsAutoHilight() && EO->HasSelectable())
225 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
226 UpdateSelected (anIO, Standard_False);
231 myCTX->CurrentViewer()->Update();
234 return ( AIS_Selection::Extent() == 1)? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected ;
236 //==================================================
239 //==================================================
240 AIS_StatusOfPick AIS_LocalContext::Select(const Standard_Integer XPMin,
241 const Standard_Integer YPMin,
242 const Standard_Integer XPMax,
243 const Standard_Integer YPMax,
244 const Handle(V3d_View)& aView,
245 const Standard_Boolean updateviewer)
247 if(aView->Viewer()== myCTX->CurrentViewer()){
248 myMainVS->Pick( XPMin,YPMin,XPMax,YPMax,aView);
249 if (myAutoHilight) UnhilightPicked(Standard_False);
251 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
252 Standard_Integer LastExt = AIS_Selection::Extent();
255 if(!myMainVS->More()) {
256 ClearSelected(updateviewer);
258 return LastExt == 0 ? AIS_SOP_NothingSelected:AIS_SOP_Removed;
261 ClearSelected(Standard_False);
263 for(myMainVS->Init();myMainVS->More();myMainVS->Next()){
264 const Handle(SelectMgr_EntityOwner)& OWNR = myMainVS->Picked();
265 if(myFilters->IsOk(OWNR)){
266 // it can be helpfil to classify this owner immediately...
268 Standard_Integer state = OWNR->State();
271 if( state == 0 ) AIS_Selection::Select(OWNR);
275 if( state == 0 ) AIS_Selection::Select(OWNR);
279 if(!IsSelected(OWNR)){
281 AIS_Selection::Select(OWNR);
287 HilightPicked(updateviewer);
290 Standard_Integer NS = AIS_Selection::Extent();
291 if( NS == 1 ) return AIS_SOP_OneSelected;
292 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
294 return AIS_SOP_Error;
299 //==================================================
302 //==================================================
303 AIS_StatusOfPick AIS_LocalContext::ShiftSelect(const Standard_Boolean updateviewer)
305 Standard_Integer I = DetectedIndex();
308 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
310 Standard_Integer NbSel = AIS_Selection::Extent();
312 const Handle(SelectMgr_EntityOwner)& EO = myMapOfOwner(I);
314 Standard_Integer mod = EO->State()==0 ? -1 : 0;
316 Standard_Integer mod = EO->State()==0 ? 1 : 0;
320 AIS_Selection::Select(EO);
325 AIS_Selection::Select(EO);
330 const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
331 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
333 Unhilight (EO, aViewer->ActiveView());
336 // advanced selection highlighting mechanism
337 if (!EO->IsAutoHilight() && EO->HasSelectable())
339 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (EO->Selectable());
340 UpdateSelected (anIO, Standard_False);
345 myCTX->CurrentViewer()->Update();
349 Standard_Integer NS = AIS_Selection::Extent();
350 if( NS == 1 ) return AIS_SOP_OneSelected;
351 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
352 return NbSel== 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
355 return AIS_SOP_Error;
357 //==================================================
358 // Function: the already selected objects are unselected
359 // Purpose : others are selected.
360 //==================================================
361 AIS_StatusOfPick AIS_LocalContext::ShiftSelect(const Standard_Integer XPMin,
362 const Standard_Integer YPMin,
363 const Standard_Integer XPMax,
364 const Standard_Integer YPMax,
365 const Handle(V3d_View)& aView,
366 const Standard_Boolean updateviewer)
368 myMainPM->ClearImmediateDraw();
370 if(aView->Viewer()== myCTX->CurrentViewer()) {
371 myMainVS->Pick( XPMin,YPMin,XPMax,YPMax,aView);
373 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
374 Standard_Integer LastExt = AIS_Selection::Extent();
377 if(!myMainVS->More())
379 return LastExt == 0 ? AIS_SOP_NothingSelected:AIS_SOP_Removed;
381 return AIS_SOP_NothingSelected; // no effet if click on empty space
384 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
385 if (myAutoHilight) UnhilightPicked(Standard_False);
387 for(myMainVS->Init();myMainVS->More();myMainVS->Next()){
388 const Handle(SelectMgr_EntityOwner)& EO = myMainVS->Picked();
389 if(myFilters->IsOk(EO)){
391 Standard_Integer mod = EO->State()==0 ? -1 : 0;
393 Standard_Integer mod = EO->State()==0 ? 1 : 0;
397 AIS_Selection::Select(EO);
401 AIS_Selection::Select(EO);
405 if (myAutoHilight) HilightPicked(updateviewer);
409 Standard_Integer NS = AIS_Selection::Extent();
410 if( NS == 1 ) return AIS_SOP_OneSelected;
411 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
413 return AIS_SOP_Error;
416 //==================================================
418 // Purpose : Selection by polyline
419 //==================================================
420 AIS_StatusOfPick AIS_LocalContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
421 const Handle(V3d_View)& aView,
422 const Standard_Boolean updateviewer)
424 if(aView->Viewer()== myCTX->CurrentViewer()){
425 myMainVS->Pick(aPolyline,aView);
426 if (myAutoHilight) UnhilightPicked(Standard_False);
428 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
429 Standard_Integer LastExt = AIS_Selection::Extent();
432 if(!myMainVS->More()) {
433 ClearSelected(updateviewer);
435 return LastExt == 0 ? AIS_SOP_NothingSelected:AIS_SOP_Removed;
438 ClearSelected(Standard_False);
440 for(myMainVS->Init();myMainVS->More();myMainVS->Next()){
441 const Handle(SelectMgr_EntityOwner)& OWNR = myMainVS->Picked();
442 if(myFilters->IsOk(OWNR)){
443 // it can be helpfil to classify this owner immediately...
445 Standard_Integer state = OWNR->State();
447 if( state == 0 ) AIS_Selection::AddSelect(OWNR);
451 if(!IsSelected(OWNR)){
453 AIS_Selection::AddSelect(OWNR);
460 HilightPicked(updateviewer);
463 Standard_Integer NS = AIS_Selection::Extent();
464 if( NS == 1 ) return AIS_SOP_OneSelected;
465 else if( NS > 1 ) return AIS_SOP_SeveralSelected;
467 return AIS_SOP_Error;
470 //==================================================
472 // Purpose : Selection by polyline
473 //==================================================
474 AIS_StatusOfPick AIS_LocalContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
475 const Handle(V3d_View)& aView,
476 const Standard_Boolean updateviewer )
478 if( aView->Viewer() == myCTX->CurrentViewer() ) {
479 myMainVS->Pick( aPolyline, aView );
481 AIS_Selection::SetCurrentSelection( mySelName.ToCString() );
482 Standard_Integer LastExt = AIS_Selection::Extent();
484 if( !myMainVS->More() )
485 return LastExt == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
487 AIS_Selection::SetCurrentSelection( mySelName.ToCString() );
490 UnhilightPicked( Standard_False );
491 for( myMainVS->Init(); myMainVS->More(); myMainVS->Next() ) {
492 const Handle(SelectMgr_EntityOwner)& EO = myMainVS->Picked();
493 if( myFilters->IsOk( EO ) ) {
494 Standard_Integer mod = EO->State() == 0 ? -1 : 0;
495 AIS_Selection::Select(EO);
500 HilightPicked( updateviewer );
502 Standard_Integer NS = AIS_Selection::Extent();
504 return AIS_SOP_OneSelected;
506 return AIS_SOP_SeveralSelected;
507 return AIS_SOP_Error;
510 //==================================================
513 //==================================================
514 void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner,
515 const Handle(V3d_View)& theView)
517 if (theView.IsNull())
522 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
523 myMainPM->BeginImmediateDraw();
524 theOwner->HilightWithColor (myMainPM, myCTX->HilightColor(), aHilightMode);
525 myMainPM->EndImmediateDraw (theView);
528 //==================================================
529 // Function: Unhilight
531 //==================================================
532 void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner,
533 const Handle(V3d_View)& theView)
535 if (theView.IsNull())
540 myMainPM->ClearImmediateDraw();
541 const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
542 if (IsSelected (theOwner))
544 if (theOwner->IsAutoHilight())
546 theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode);
551 theOwner->Unhilight (myMainPM, aHilightMode);
555 //=======================================================================
556 //function : HilightPicked
558 //=======================================================================
559 void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer)
561 Standard_Boolean updMain(Standard_False);
563 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
565 if( Sel.IsNull() ) return;
568 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
569 SelectMgr_DataMapOfObjectOwners aMap;
571 // to avoid problems when there is a loop searching for selected objects...
572 #if !defined OCC189 && !defined USE_MAP
573 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
574 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++)
576 const Handle(Standard_Transient)& Tr = Obj(i);
578 const AIS_NListTransient& Obj = Sel->Objects();
579 AIS_NListTransient::Iterator anIter( Obj );
580 for(; anIter.More(); anIter.Next())
582 const Handle(Standard_Transient)& Tr = anIter.Value();
585 const Handle(SelectMgr_EntityOwner)& Ownr =
586 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
587 Handle(AIS_InteractiveObject) IO;
588 if(Ownr->HasSelectable()){
589 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
590 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
591 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
592 IO = *((Handle(AIS_InteractiveObject)*)&SO);
593 updMain = Standard_True;
596 updMain = Standard_True;
599 updMain = Standard_True;
600 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
601 Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO));
602 if ( Ownr->IsAutoHilight() )
603 Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM);
604 else if ( aMap.IsBound (SO) )
605 aMap.ChangeFind(SO).Append ( Ownr );
607 SelectMgr_SequenceOfOwner aSeq;
608 aSeq.Append ( Ownr );
609 aMap.Bind ( SO, aSeq );
614 for ( SelectMgr_DataMapIteratorOfMapOfObjectOwners aMapIter(aMap);
615 aMapIter.More(); aMapIter.Next() )
616 aMapIter.Key()->HilightSelected ( myMainPM, aMapIter.Value() );
620 myCTX->CurrentViewer()->Update();
624 //==================================================
627 //==================================================
628 void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer)
630 myMainPM->ClearImmediateDraw();
632 Standard_Boolean updMain(Standard_False);
634 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
636 if( Sel.IsNull() ) return;
638 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
639 SelectMgr_DataMapOfObjectOwners anObjMap;
640 SelectMgr_SequenceOfOwner anOwnSeq;
642 #if !defined OCC189 && !defined USE_MAP
643 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
644 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
645 const Handle(Standard_Transient)& Tr = Obj(i);
647 const AIS_NListTransient& Obj = Sel->Objects();
648 AIS_NListTransient::Iterator anIter( Obj );
649 for(; anIter.More(); anIter.Next()){
650 const Handle(Standard_Transient)& Tr = anIter.Value();
653 const Handle(SelectMgr_EntityOwner)& Ownr =
654 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
655 Standard_Integer HM(0);
656 if(Ownr->HasSelectable()){
658 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
659 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
660 anObjMap.Bind ( IO, anOwnSeq );
664 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
665 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
667 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
668 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
671 updMain = Standard_True;
674 updMain = Standard_True;
676 Ownr->Unhilight(PM,HM);
680 for ( SelectMgr_DataMapIteratorOfMapOfObjectOwners anIter1 ( anObjMap );
681 anIter1.More(); anIter1.Next() )
682 if ( !anIter1.Key()->IsAutoHilight() )
683 anIter1.Key()->ClearSelected();
687 myCTX->CurrentViewer()->Update();
689 if(updMain) myCTX->CurrentViewer()->Update();
695 //=======================================================================
696 //function : IsSelected
698 //=======================================================================
699 Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
701 return (!FindSelectedOwnerFromIO(anIObj).IsNull());
704 //=======================================================================
705 //function : IsSelected
707 //=======================================================================
709 Standard_Boolean AIS_LocalContext::IsSelected(const Handle(SelectMgr_EntityOwner)& Ownr) const
711 if (Ownr.IsNull()) return Standard_False;
713 Standard_Boolean state = (Ownr->State()!=0);
715 Standard_Boolean state = (Ownr->State()==1);
720 //==================================================
723 //==================================================
724 void AIS_LocalContext::
727 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
728 AIS_Selection::CurrentSelection()->Init();
731 //==================================================
734 //==================================================
735 Standard_Boolean AIS_LocalContext::
738 return AIS_Selection::CurrentSelection()->More();
741 //==================================================
744 //==================================================
745 void AIS_LocalContext::
748 AIS_Selection::CurrentSelection()->Next();
751 //==================================================
754 //==================================================
755 Standard_Boolean AIS_LocalContext::
758 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
759 if( Tr.IsNull() ) return Standard_False;
760 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
761 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
762 if(BRO.IsNull()) return Standard_False;
763 Standard_Boolean hasshape = BRO->HasShape();
764 Standard_Boolean comes = BRO->ComesFromDecomposition();
765 return (hasshape&&comes);
768 //==================================================
771 //==================================================
772 const TopoDS_Shape& AIS_LocalContext::
773 SelectedShape() const
775 static TopoDS_Shape aSh;
776 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
777 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
778 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
786 //==================================================
789 //==================================================
790 Handle(AIS_InteractiveObject) AIS_LocalContext::
791 SelectedInteractive() const
793 Handle(AIS_InteractiveObject) IO;
794 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
796 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
797 Handle(SelectMgr_SelectableObject) SO;
798 if(EO->HasSelectable()){
799 SO = EO->Selectable();
800 IO = *((Handle(AIS_InteractiveObject)*)&SO);
805 //==================================================
808 //==================================================
809 Handle(SelectMgr_EntityOwner) AIS_LocalContext::
810 SelectedOwner() const
812 Handle(SelectMgr_EntityOwner) EO;
813 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
815 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
819 //==================================================
822 //==================================================
823 Standard_Boolean AIS_LocalContext::
824 HasApplicative() const
826 Handle(AIS_InteractiveObject) IO = SelectedInteractive();
827 if( IO.IsNull() ) return Standard_False;
828 return IO->HasOwner();
831 //==================================================
834 //==================================================
835 const Handle(Standard_Transient)& AIS_LocalContext::
836 SelectedApplicative() const
838 return SelectedInteractive()->GetOwner();
843 //=======================================================================
844 //function : UpdateSelection
845 //purpose : should disappear...
846 //=======================================================================
847 void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer)
849 UnhilightPicked(Standard_False);
850 HilightPicked(updateviewer);
853 //================================================================
854 // Function : UpdateSelected
855 // Purpose : Part of advanced selection mechanism.
856 // Highlightes or clears selection presentation for the given IO
857 //================================================================
858 void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj,
859 const Standard_Boolean updateviewer)
861 if (anobj.IsNull() || anobj->IsAutoHilight())
864 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
865 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
867 SelectMgr_SequenceOfOwner aSeq;
868 for ( Sel->Init(); Sel->More(); Sel->Next() ){
869 Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value());
871 if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj )
872 aSeq.Append( aOwner );
876 anobj->HilightSelected( myMainPM, aSeq );
878 anobj->ClearSelected();
881 myCTX->CurrentViewer()->Update();
885 //==================================================
886 // Function: ClearSelected
888 //==================================================
889 void AIS_LocalContext::ClearSelected(const Standard_Boolean updateviewer)
891 UnhilightPicked(updateviewer);
892 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
894 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
895 #if !defined OCC189 && !defined USE_MAP
896 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
897 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
898 const Handle(Standard_Transient)& Tr = Obj(i);
900 const AIS_NListTransient& Obj = Sel->Objects();
901 AIS_NListTransient::Iterator anIter( Obj );
902 for(; anIter.More(); anIter.Next()){
903 const Handle(Standard_Transient)& Tr = anIter.Value();
906 (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
909 AIS_Selection::Select();
914 //=======================================================================
915 //function : SetSelected
917 //=======================================================================
918 void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
919 const Standard_Boolean updateviewer)
921 if(!IsValidForSelection(anIObj)) return;
922 UnhilightPicked(Standard_False);
924 //1st case, owner already <anIObj> as owner
925 // and not separated is found...
927 Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString());
928 //Standard_Boolean found(Standard_False);
929 Handle(Standard_Transient) Tr;
930 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj);
932 //check if in selection number 0 there is an owner that can be triturated...
933 if(anIObj->HasSelection(0)){
934 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
937 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
938 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
942 EO = new SelectMgr_EntityOwner(anIObj);
945 ClearSelected(Standard_False);
947 AIS_Selection::Select(EO);
951 AIS_Selection::Select(EO);
953 HilightPicked(updateviewer);
956 //=======================================================================
957 //function : AddOrRemoveSelected
959 //=======================================================================
961 void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
962 const Standard_Boolean updateviewer)
964 if(!IsValidForSelection(anIObj)) return;
965 UnhilightPicked(Standard_False);
966 // first check if it is selected...
967 Handle(SelectMgr_EntityOwner) EO;
969 EO = FindSelectedOwnerFromIO(anIObj);
977 if(anIObj->HasSelection(0)){
978 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
981 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
982 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
986 EO = new SelectMgr_EntityOwner(anIObj);
992 // cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl;
993 const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString());
996 AIS_SelectStatus aStatus = S->Select(EO);
997 if(aStatus == AIS_SS_Added)
1006 HilightPicked(updateviewer);
1009 //=======================================================================
1010 //function : AddOrRemoveSelected
1011 //purpose : To check...
1012 //=======================================================================
1013 void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh,
1014 const Standard_Boolean updateviewer)
1016 UnhilightPicked(Standard_False);
1017 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh);
1019 // cout<<"AIS_LocalContext::AddOrRemoveSelected(sh) : Selection = "<<mySelName<<endl;
1022 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
1026 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
1029 HilightPicked(updateviewer);
1032 void AIS_LocalContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Ownr,
1033 const Standard_Boolean updateviewer)
1035 //Not Yet Implemented
1037 UnhilightPicked(Standard_False);
1038 // cout<<"AIS_LocalContext::AddOrRemoveSelected(ownr) : Selection = "<<mySelName<<endl;
1040 Standard_Integer mod = Ownr->State()==0 ? 1 : 0;
1042 AIS_Selection::Selection(mySelName.ToCString())->Select(Ownr);
1048 AIS_Selection::Selection(mySelName.ToCString())->Select(Ownr);
1051 HilightPicked(updateviewer);
1054 //==================================================
1055 // Function: manageDetected
1057 //==================================================
1058 void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner,
1059 const Handle(V3d_View)& theView,
1060 const Standard_Boolean theToRedrawImmediate)
1062 if (thePickOwner.IsNull())
1064 if (theToRedrawImmediate)
1066 theView->RedrawImmediate();
1071 if (!myFilters->IsOk (thePickOwner))
1073 if (mylastindex != 0)
1075 mylastgood = mylastindex;
1077 if (theToRedrawImmediate)
1079 theView->RedrawImmediate();
1084 //=======================================================================================================
1085 // 2 cases : a- object is in the map of picks:
1086 // 1. this is the same index as the last detected: -> Do nothing
1088 // - if lastindex = 0 (no object was detected at the last step)
1089 // the object presentation is highlighted and lastindex = index(objet)
1091 // the presentation of the object corresponding to lastindex is "unhighlighted"
1092 // it is removed if the object is not visualized but only active
1093 // then the presentation of the detected object is highlighted and lastindex = index(objet)
1094 // b- the object is not in the map of picked objects
1095 // - if lastindex != 0 (object detected at the last step) it is unhighlighted ...
1096 // if the object was decomposed, presentation is created for the detected shape and the couple
1097 // (Proprietaire,Prs)is added in the map.
1098 // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object
1099 // itself is highlighted.
1101 //=======================================================================================================
1103 const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner)
1104 ? myMapOfOwner.FindIndex (thePickOwner)
1105 : myMapOfOwner.Add (thePickOwner);
1107 // For the advanced mesh selection mode the owner indices comparison
1108 // is not effective because in that case only one owner manage the
1109 // selection in current selection mode. It is necessary to check the current detected
1110 // entity and hilight it only if the detected entity is not the same as
1111 // previous detected (IsForcedHilight call)
1112 if (aNewIndex != mylastindex
1113 || thePickOwner->IsForcedHilight())
1115 if (mylastindex != 0
1116 && mylastindex <= myMapOfOwner.Extent())
1118 const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex);
1119 Unhilight (aLastOwner, theView);
1124 if (thePickOwner->State() <= 0
1125 || myCTX->ToHilightSelected())
1127 Hilight (thePickOwner, theView);
1129 if (theToRedrawImmediate)
1131 theView->RedrawImmediate();
1135 mylastindex = aNewIndex;
1140 mylastgood = mylastindex;
1144 //=======================================================================
1145 //function : HasDetectedShape
1147 //=======================================================================
1149 Standard_Boolean AIS_LocalContext::HasDetectedShape() const
1151 if(mylastindex==0) return Standard_False;
1152 return IsShape(mylastindex);
1155 //=======================================================================
1156 //function : DetectedShape
1158 //=======================================================================
1161 AIS_LocalContext::DetectedShape() const
1163 static TopoDS_Shape bidsh;
1164 if(mylastindex != 0)
1166 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex));
1167 if(BROwnr.IsNull()) return bidsh;
1168 return BROwnr->Shape();
1173 //=======================================================================
1174 //function : DetectedInteractive
1176 //=======================================================================
1178 Handle(AIS_InteractiveObject)
1179 AIS_LocalContext::DetectedInteractive() const
1181 Handle(AIS_InteractiveObject) Iobj;
1182 if(IsValidIndex(mylastindex)){
1183 Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
1184 Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
1188 //=======================================================================
1189 //function : DetectedInteractive
1191 //=======================================================================
1192 Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
1194 Handle(SelectMgr_EntityOwner) bid;
1195 if(!IsValidIndex(mylastindex)) return bid;
1196 return myMapOfOwner.FindKey(mylastindex);
1200 //=======================================================================
1201 //function : ComesFromDecomposition
1203 //=======================================================================
1205 Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
1207 const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex);
1208 Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
1209 if (myActiveObjects.IsBound (aSel)) { // debug of jmi
1210 const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
1211 return Stat->Decomposed();
1213 return Standard_False;
1217 //=======================================================================
1218 //function : DisplayAreas
1220 //=======================================================================
1222 void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
1224 myMainVS->DisplayAreas(aviou);
1227 //=======================================================================
1228 //function : ClearAreas
1230 //=======================================================================
1232 void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
1234 myMainVS->ClearAreas(aviou);
1237 //=======================================================================
1238 //function : DisplaySensitive
1240 //=======================================================================
1242 void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou)
1244 myMainVS->DisplaySensitive(aviou);
1247 //=======================================================================
1248 //function : ClearSensitive
1250 //=======================================================================
1252 void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
1254 myMainVS->ClearSensitive(aviou);
1258 //=======================================================================
1259 //function : IsShape
1261 //=======================================================================
1262 Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
1265 if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull())
1266 return Standard_False;
1268 ComesFromDecomposition(Index);
1271 Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const
1275 // Shape was not transfered from AIS_Shape to EntityOwner
1276 Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj);
1277 if( !shape.IsNull() )
1278 return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape));
1280 return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj));
1284 //=======================================================================
1285 //function : HilightNextDetected
1287 //=======================================================================
1288 Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView,
1289 const Standard_Boolean theToRedrawImmediate)
1291 // go to the next owner
1292 if (myDetectedSeq.IsEmpty())
1297 const Standard_Integer aLen = myDetectedSeq.Length();
1298 if (++myCurDetected > aLen)
1302 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myCurDetected);
1303 if (anOwner.IsNull())
1307 manageDetected (anOwner, theView, theToRedrawImmediate);
1308 return myCurDetected;
1311 //=======================================================================
1312 //function : HilightPreviousDetected
1314 //=======================================================================
1315 Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1316 const Standard_Boolean theToRedrawImmediate)
1318 if (myDetectedSeq.IsEmpty())
1323 if (--myCurDetected < 1)
1327 Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myCurDetected);
1328 if (anOwner.IsNull())
1333 manageDetected (anOwner, theView, theToRedrawImmediate);
1334 return myCurDetected;
1337 //=======================================================================
1338 //function : UnhilightLastDetected
1340 //=======================================================================
1341 Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView)
1343 if (!IsValidIndex (mylastindex))
1345 return Standard_False;
1348 myMainPM->BeginImmediateDraw();
1349 const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex);
1350 const Standard_Integer aHilightMode = anOwner->HasSelectable()
1351 ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
1354 myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode);
1355 myMainPM->EndImmediateDraw (theView);
1357 return Standard_True;
1360 //=======================================================================
1361 //function : FindSelectedOwnerFromIO
1362 //purpose : it is checked if one of the selected owners really presents IObj
1363 //=======================================================================
1364 Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO
1365 (const Handle(AIS_InteractiveObject)& anIObj) const
1367 Handle(SelectMgr_EntityOwner) EO,bid;
1368 if (anIObj.IsNull()) return EO;
1370 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1373 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "
1374 <<mySelName<<" Nulle "<<endl;
1378 Standard_Boolean found(Standard_False);
1379 #if !defined OCC189 && !defined USE_MAP
1380 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
1381 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
1382 const Handle(Standard_Transient)& Tr = Obj(i);
1384 const AIS_NListTransient& Obj = Sel->Objects();
1385 AIS_NListTransient::Iterator anIter( Obj );
1386 for(; anIter.More(); anIter.Next()){
1387 const Handle(Standard_Transient)& Tr = anIter.Value();
1390 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1391 if(EO->HasSelectable()){
1392 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1393 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
1394 if (anIObj == EO->Selectable()){
1395 found =Standard_True;
1402 if(found) return EO;
1406 //=======================================================================
1407 //function : FindSelectedOwnerFromShape
1408 //purpose : it is checked if one of the selected owners really presents IObj
1409 //=======================================================================
1410 Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const
1413 Handle(SelectMgr_EntityOwner) EO, bid;
1415 Handle(SelectMgr_EntityOwner) EO;
1417 if (sh.IsNull()) return EO;
1419 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1422 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl;
1427 Standard_Boolean found(Standard_False);
1431 SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives());
1432 for (; aSensitiveIt.More(); aSensitiveIt.Next()) {
1433 EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId());
1434 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1435 if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) {
1436 found = Standard_True;
1442 #if !defined OCC189 && !defined USE_MAP
1443 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
1444 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
1445 const Handle(Standard_Transient)& Tr = Obj(i);
1447 const AIS_NListTransient& Obj = Sel->Objects();
1448 AIS_NListTransient::Iterator anIter( Obj );
1449 for(; anIter.More(); anIter.Next()){
1450 const Handle(Standard_Transient)& Tr = anIter.Value();
1454 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1456 if ( EO->Shape() == sh)
1457 found =Standard_True;
1463 if(found) return EO;
1468 //=======================================================================
1469 //function : AIS_LocalContext::InitDetected
1471 //=======================================================================
1473 void AIS_LocalContext::InitDetected()
1475 myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0;
1478 //=======================================================================
1479 //function : AIS_LocalContext::MoreDetected
1481 //=======================================================================
1483 Standard_Boolean AIS_LocalContext::MoreDetected() const
1485 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length());
1489 //=======================================================================
1490 //function : AIS_LocalContext::NextDetected
1492 //=======================================================================
1494 void AIS_LocalContext::NextDetected()
1496 if (MoreDetected()) myAISCurDetected++;
1499 //=======================================================================
1500 //function : DetectedCurrentShape
1502 //=======================================================================
1504 const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
1506 static TopoDS_Shape bidsh;
1508 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1512 //=======================================================================
1513 //function : DetectedCurrentObject
1515 //=======================================================================
1517 Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const
1519 Handle(AIS_InteractiveObject) theIObj;
1521 theIObj = myAISDetectedSeq(myAISCurDetected);