1 // Created on: 1997-01-17
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-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 : Traque des UpdateConversion intempestifs.
19 #include <AIS_LocalContext.ixx>
20 #include <SelectMgr_OrFilter.hxx>
21 #include <SelectMgr_CompositionFilter.hxx>
22 #include <AIS_LocalStatus.hxx>
23 #include <AIS_Shape.hxx>
24 #include <TColStd_ListIteratorOfListOfInteger.hxx>
25 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <AIS_ListOfInteractive.hxx>
27 #include <AIS_DataMapIteratorOfDataMapOfSelStat.hxx>
28 #include <TopAbs_ShapeEnum.hxx>
29 #include <Graphic3d_Structure.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_PlaneAspect.hxx>
32 #include <Prs3d_PointAspect.hxx>
33 #include <Prs3d_Presentation.hxx>
34 #include <Aspect_TypeOfMarker.hxx>
35 #include <StdSelect_ShapeTypeFilter.hxx>
36 #include <StdSelect_ViewerSelector3d.hxx>
37 #include <AIS_Selection.hxx>
38 #include <V3d_Viewer.hxx>
39 #include <V3d_View.hxx>
40 #include <Visual3d_View.hxx>
41 #include <AIS_InteractiveObject.hxx>
45 static TCollection_AsciiString AIS_Local_SelName(const Standard_Address address,
46 const Standard_Integer anIndex)
48 // TCollection_AsciiString SelName;
50 sprintf(string,"%p_%d", address, anIndex); // works under any system
51 TCollection_AsciiString SelName(string);
56 //=======================================================================
57 //function : AIS_LocalContext
59 //=======================================================================
62 AIS_LocalContext::AIS_LocalContext(){}
64 AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx,
65 const Standard_Integer Index,
66 const Standard_Boolean LoadDisplayed,
67 const Standard_Boolean AcceptStandardModes,
68 const Standard_Boolean AcceptEraseOfTemp,
69 const Standard_Boolean /*BothViewers*/):
71 myLoadDisplayed(LoadDisplayed),
72 myAcceptStdMode(AcceptStandardModes),
73 myAcceptErase(AcceptEraseOfTemp),
74 mySM(aCtx->SelectionManager()),
75 myMainVS(aCtx->MainSelector()),
76 myFilters(new SelectMgr_OrFilter()),
77 myAutoHilight(Standard_True),
78 myMapOfOwner (new SelectMgr_IndexedMapOfOwner()),
85 // bind self to AIS_InteractiveContext::myLocalContexts. Further, the
86 // constructor executes logic that implies that the context is already
87 // created and mapped.
88 aCtx->myLocalContexts.Bind (Index, this);
90 myMainVS->ResetSelectionActivationStatus();
91 myMainPM = aCtx->MainPrsMgr();
92 mySelName = AIS_Local_SelName(this, Index);
93 AIS_Selection::CreateSelection(mySelName.ToCString());
96 if(myLoadDisplayed) LoadContextObjects();
102 //=======================================================================
103 //function : SetContext
105 //=======================================================================
107 void AIS_LocalContext::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
110 //=======================================================================
113 //=======================================================================
115 Standard_Boolean AIS_LocalContext::Display(const Handle(AIS_InteractiveObject)& anInteractive,
116 const Standard_Integer WhichMode,
117 const Standard_Boolean AllowShapeDecomposition,
118 const Standard_Integer ActivationMode)
120 if(myActiveObjects.IsBound(anInteractive)){
121 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
123 if(STAT->DisplayMode() == -1){
124 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
125 myMainPM->Display(anInteractive,WhichMode);
126 if(STAT->IsTemporary())
127 STAT->SetDisplayMode(WhichMode);
129 else if(STAT->DisplayMode()!=WhichMode && STAT->IsTemporary()){
130 myMainPM->Erase(anInteractive,STAT->DisplayMode());
131 STAT->SetDisplayMode(WhichMode);
132 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
133 myMainPM->Display(anInteractive,WhichMode);
136 if(ActivationMode!=-1){
137 if(!STAT->IsActivated(ActivationMode)){
138 STAT->ClearSelectionModes();
139 mySM->Load(anInteractive,myMainVS);
140 STAT->AddSelectionMode(ActivationMode);
141 mySM->Activate(anInteractive,ActivationMode,myMainVS);
146 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
148 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
149 Att->SetDecomposition(Standard_True);
151 Att->SetDecomposition(Standard_False);
152 // status temporary or not
153 if(myCTX->DisplayStatus(anInteractive) == AIS_DS_None ||
154 myCTX->DisplayStatus(anInteractive) == AIS_DS_Temporary)
155 Att->SetTemporary(Standard_True);
157 Att->SetTemporary(Standard_False);
161 if(!myCTX->IsDisplayed(anInteractive,WhichMode)){
163 //storing information....
164 Att->SetDisplayMode(WhichMode);
165 if (ActivationMode!=-1)
166 Att->AddSelectionMode(ActivationMode);
167 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
168 Att->SetHilightMode(HiMod);
170 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
171 myMainPM->Display(anInteractive,WhichMode);
173 if(ActivationMode!=-1){
174 mySM->Load(anInteractive,myMainVS);
175 mySM->Activate(anInteractive,ActivationMode,myMainVS);
179 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
180 Att->SetHilightMode(HiMod);
182 myActiveObjects.Bind(anInteractive,Att);
184 Process(anInteractive);
189 return Standard_True;
192 //=======================================================================
195 //=======================================================================
197 Standard_Boolean AIS_LocalContext::
198 Load(const Handle(AIS_InteractiveObject)& anInteractive,
199 const Standard_Boolean AllowShapeDecomposition,
200 const Standard_Integer ActivationMode)
202 if (myActiveObjects.IsBound (anInteractive))
204 if (anInteractive->HasSelection (ActivationMode))
206 const Handle(SelectMgr_Selection)& aSel = anInteractive->Selection (ActivationMode);
207 if (aSel->GetSelectionState() != SelectMgr_SOS_Activated)
209 if (!myMainVS->Contains (anInteractive))
211 mySM->Load (anInteractive, myMainVS);
213 mySM->Activate (anInteractive, ActivationMode, myMainVS);
214 return Standard_True;
217 return Standard_False;
220 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
222 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
223 Att->SetDecomposition(Standard_True);
225 Att->SetDecomposition(Standard_False);
227 if(!myCTX->IsDisplayed(anInteractive))
228 Att->SetTemporary(Standard_True);
230 Att->SetTemporary(Standard_False);
231 Att->SetDisplayMode(-1);
233 //storing information....
234 if(ActivationMode!=-1)
235 Att->AddSelectionMode(ActivationMode);
236 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0;
237 Att->SetHilightMode(HiMod);
240 mySM->Load(anInteractive,myMainVS);
241 if(ActivationMode != -1){
242 mySM->Activate(anInteractive,ActivationMode,myMainVS);
244 myActiveObjects.Bind(anInteractive,Att);
245 Process(anInteractive);
246 return Standard_True;
249 //=======================================================================
250 //function : ClearPrs
252 //=======================================================================
254 Standard_Boolean AIS_LocalContext::
255 ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive,
256 const Standard_Integer aMode)
258 if(!myActiveObjects.IsBound(anInteractive))
259 return Standard_False;
261 Standard_Boolean jobdone(Standard_False);
262 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
265 if(STAT->IsSubIntensityOn()) {
266 STAT->SubIntensityOff();
267 if(STAT->HilightMode()==aMode)
268 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
270 myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97
271 jobdone = Standard_True;
272 if(STAT->DisplayMode()==aMode)
273 STAT->SetDisplayMode(-1);
276 //=======================================================================
279 //=======================================================================
281 Standard_Boolean AIS_LocalContext::
282 Erase(const Handle(AIS_InteractiveObject)& anInteractive)
284 if(!myActiveObjects.IsBound(anInteractive))
285 return Standard_False;
286 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
289 if(STAT->IsSubIntensityOn()) {
290 STAT->SubIntensityOff();
291 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
294 Standard_Boolean status(Standard_False);
296 if(STAT->DisplayMode()!=-1) {
297 if(IsSelected(anInteractive))
298 AddOrRemoveSelected(anInteractive);
299 if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode()))
300 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
301 myMainPM->SetVisibility (anInteractive, STAT->DisplayMode(), Standard_False);
302 STAT->SetDisplayMode(-1);
303 status = Standard_True;
305 if(STAT->IsTemporary()){
306 if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode()))
307 myMainPM->SetVisibility (anInteractive, STAT->HilightMode(), Standard_False);
310 // Deactivate selectable entities of interactive object
311 const Handle(SelectMgr_SelectableObject)& anObj = anInteractive; // to avoid ambiguity
312 if (mySM->Contains (anObj))
314 TColStd_ListIteratorOfListOfInteger aModeIter (STAT->SelectionModes());
315 for (; aModeIter.More(); aModeIter.Next())
317 mySM->Deactivate (anInteractive, aModeIter.Value(), myMainVS);
321 ClearOutdatedSelection (anInteractive, Standard_True);
327 //=======================================================================
328 //function : SetShapeDecomposition
330 //=======================================================================
332 void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject,
333 const Standard_Boolean aStatus)
335 if(!myActiveObjects.IsBound(aStoredObject)) return;
337 if(aStatus == myActiveObjects(aStoredObject)->Decomposed())
340 myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
342 Process(aStoredObject);
345 //=======================================================================
348 //=======================================================================
350 void AIS_LocalContext::Clear(const AIS_ClearMode aType)
357 while(!myListOfStandardMode.IsEmpty())
358 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
361 case AIS_CM_Interactive:
367 case AIS_CM_StandardModes:
369 while(!myListOfStandardMode.IsEmpty())
370 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
373 case AIS_CM_TemporaryShapePrs:
377 //=======================================================================
378 //function : ActivateMode
380 //=======================================================================
382 void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
383 const Standard_Integer aMode)
385 if(!myActiveObjects.IsBound(aSelectable)) return;
386 // if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
387 // mySM->Deactivate(aSelectable,aMode,myMainVS);
389 myActiveObjects(aSelectable)->AddSelectionMode(aMode);
390 mySM->Activate(aSelectable,aMode,myMainVS);
393 //=======================================================================
394 //function : ActivateMode
396 //=======================================================================
398 void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
399 const Standard_Integer aMode)
401 if(!myActiveObjects.IsBound(aSelectable)) return;
403 if(aMode==-1) return;
405 myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
406 mySM->Deactivate(aSelectable,aMode,myMainVS);
408 //=======================================================================
409 //function : ActivateMode
411 //=======================================================================
413 void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
415 if(!myActiveObjects.IsBound(aSelectable)) return;
417 mySM->Deactivate(aSelectable, -1, myMainVS);
418 myActiveObjects(aSelectable)->ClearSelectionModes();
421 //=======================================================================
424 //=======================================================================
426 Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
428 if(!myActiveObjects.IsBound (aSelectable))
430 return Standard_False;
433 if (IsSelected (aSelectable))
435 AddOrRemoveSelected (aSelectable, Standard_False);
438 const Handle(AIS_LocalStatus)& Att = myActiveObjects (aSelectable);
440 TColStd_ListIteratorOfListOfInteger It;
442 // Deactivate standard modes
443 if (Att->Decomposed())
445 for (It.Initialize (myListOfStandardMode); It.More(); It.Next())
447 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
451 // If object or temporary presentations
452 if (Att->IsTemporary())
454 if (Att->IsSubIntensityOn())
456 myMainPM->Unhighlight (aSelectable, Att->HilightMode());
459 myMainPM->Erase (aSelectable, Att->DisplayMode());
460 myMainPM->Clear (aSelectable, Att->DisplayMode());
461 if (myMainPM->IsDisplayed (aSelectable, Att->HilightMode()))
463 myMainPM->Erase (aSelectable, Att->HilightMode());
466 // If subintensity used
467 else if (Att->IsSubIntensityOn())
469 myCTX->SubIntensityOff (aSelectable);
472 // Deactivate stored selection modes
473 for (It.Initialize (Att->SelectionModes()); It.More(); It.Next())
475 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
478 // Remove the interactive object from selection manager
479 const Handle(SelectMgr_SelectableObject)& anObj = aSelectable; // to avoid ambiguity
480 if (mySM->Contains (anObj))
482 mySM->Remove (anObj);
484 ClearOutdatedSelection (aSelectable, Standard_True);
486 // This should be done at the very end because most methods use
487 // myActiveObjects even during clean-up
488 myActiveObjects.UnBind (aSelectable);
489 return Standard_True;
492 //=======================================================================
493 //function : ActivateStandardMode
495 //=======================================================================
497 void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
500 //check if it is not in the list
501 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
502 for(;It.More();It.Next())
503 if(It.Value()==aType) return;
504 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
507 // create a hidden filter answering ok to the type except for :
508 // if the type is shape...
509 // if the filters already impact at the type <aType>
510 if(aType != TopAbs_SHAPE){
511 if(myStdFilters[IMode].IsNull())
512 myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
513 if(!HasFilters(aType))
514 myFilters->Add(myStdFilters[IMode]);
517 // the mode is activated for all objects of type Shape
518 // accepting the decomposition in standard mode.
519 myListOfStandardMode.Append(IMode);
521 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
523 for(;ItM.More();ItM.Next()){
524 if(ItM.Value()->Decomposed())
525 myCTX->SelectionManager()->Activate(ItM.Key(),
532 //=======================================================================
533 //function : DeActivateStandardMode
535 //=======================================================================
537 void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
539 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
540 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
541 for(;It.More();It.Next())
542 if(It.Value()==IMode) {
543 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
545 for(;ItM.More();ItM.Next()){
546 if(ItM.Value()->Decomposed()){
547 myCTX->SelectionManager()->Deactivate(ItM.Key(),
550 ItM.Value()->RemoveSelectionMode(IMode);
553 myListOfStandardMode.Remove(It);
554 if(myFilters->IsIn(myStdFilters[IMode]))
555 myFilters->Remove(myStdFilters[IMode]);
560 //=======================================================================
561 //function : AddFilter
563 //=======================================================================
565 void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
567 // it is checked if the filter impacts at the type of active sub-shape
568 // for which a filter of type has been already implemented...
570 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
572 for(;It.More();It.Next()){
573 if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
574 if(myFilters->IsIn(myStdFilters[It.Value()]))
575 myFilters->Remove(myStdFilters[It.Value()]);
577 myFilters->Add(aFilter);
580 //=======================================================================
581 //function : RemoveFilter
583 //=======================================================================
585 void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
587 if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
589 // it is checked if the filter for type standard is active.
590 // if yes, it is checked there are still similarities among the
591 // remaining filters...
592 // otherwise, the standard filter is restored to
593 // continu selecting active modes...
594 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
596 for(;It.More();It.Next()){
597 SE = AIS_Shape::SelectionType(It.Value());
598 if(aFilter->ActsOn(SE))
600 myFilters->Add(myStdFilters[It.Value()]);
604 //=======================================================================
605 //function : Terminate
607 //=======================================================================
609 void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
613 myMapOfOwner->Clear();
616 // clear the selector...
620 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
621 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
622 Handle(Standard_Transient) Tr;
623 for(S->Init();S->More();S->Next()){
625 Handle(SelectMgr_EntityOwner)::DownCast (Tr)->SetSelected (Standard_False);
629 AIS_Selection::Select();
630 AIS_Selection::Remove(mySelName.ToCString());
632 Handle(V3d_Viewer) aViewer = myCTX->CurrentViewer();
633 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
635 Handle(V3d_View) aView = aViewer->ActiveView();
636 aView->View()->ClearImmediate();
639 Handle(V3d_View) aDummyView;
640 myMainVS->ClearSensitive (aDummyView);
644 myCTX->UpdateCurrentViewer();
649 //=======================================================================
650 //function : SubIntensity
652 //=======================================================================
654 void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
656 if(!myActiveObjects.IsBound(anObject)) return;
658 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
660 if(Att->IsTemporary())
661 myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode());
663 Att->SubIntensityOn();
665 //=======================================================================
666 //function : SubIntensity
668 //=======================================================================
670 void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
672 if(!myActiveObjects.IsBound(anObject)) return;
674 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
676 if(Att->IsTemporary())
677 myMainPM->Unhighlight(anObject);
678 Att->SubIntensityOff();
682 //=======================================================================
685 //=======================================================================
687 void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject)
689 if(!myActiveObjects.IsBound(anObject)){
690 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
691 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
694 myActiveObjects.Bind(anObject,Att);
697 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
698 myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode());
699 Att->SubIntensityOn();
701 //=======================================================================
704 //=======================================================================
706 void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject,
707 const Quantity_NameOfColor Col)
709 if(!myActiveObjects.IsBound(anObject)){
710 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
711 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
714 myActiveObjects.Bind(anObject,Att);
717 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
718 myMainPM->Color(anObject,Col,Att->HilightMode());
719 Att->SubIntensityOn();
720 Att->SetHilightColor(Col);
723 //=======================================================================
724 //function : Unhilight
726 //=======================================================================
728 void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
730 if(!myActiveObjects.IsBound(anObject)) return;
732 // chieck if by hazard the object is somewhere else...
733 Standard_Integer Indx;
734 Standard_Boolean IsSomeWhereElse =
735 myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
737 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
738 myMainPM->Unhighlight(anObject,Att->HilightMode());
739 if(Att->IsTemporary() && Att->DisplayMode()==-1)
741 myMainPM->SetVisibility (anObject, Att->HilightMode(), Standard_False);
743 Att->SubIntensityOff();
744 Att->SetHilightColor(Quantity_NOC_WHITE);
748 //=======================================================================
751 //=======================================================================
753 Standard_Boolean AIS_LocalContext::
754 IsIn(const Handle(AIS_InteractiveObject)& anObject) const
756 return myActiveObjects.IsBound(anObject);
759 //=======================================================================
760 //function : IsHilighted
762 //=======================================================================
764 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const
766 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
767 return myActiveObjects(anObject)->IsSubIntensityOn();
770 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject,
771 Standard_Boolean& WithColor,
772 Quantity_NameOfColor& HiCol) const
774 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
775 if( myActiveObjects(anObject)->IsSubIntensityOn()){
776 HiCol = myActiveObjects(anObject)->HilightColor();
777 if(HiCol==Quantity_NOC_WHITE)
778 WithColor = Standard_True;
780 WithColor = Standard_False;
781 return Standard_True;
783 return Standard_False;
787 void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
788 const Standard_Integer Prior)
790 if(!myActiveObjects.IsBound(anObject)) return;
791 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
792 if(STAT->DisplayMode()==-1) return;
793 myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
794 if(STAT->IsSubIntensityOn())
795 myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
800 //=======================================================================
801 //function : DisplayedObjects
803 //=======================================================================
804 Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
806 Standard_Integer NbDisp(0);
807 for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
808 const Handle(SelectMgr_SelectableObject)& SO = it.Key();
809 if(!theMap.Contains(SO))
810 if(it.Value()->DisplayMode()!=-1){
819 //=======================================================================
820 //function : IsDisplayed
822 //=======================================================================
824 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const
826 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
827 return (myActiveObjects(anObject)->DisplayMode()!=-1);
830 //=======================================================================
831 //function : IsDisplayed
833 //=======================================================================
835 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
836 const Standard_Integer aMode) const
838 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
839 return (myActiveObjects(anObject)->DisplayMode()==aMode);
842 //=======================================================================
843 //function : SelectionModes
845 //=======================================================================
847 const TColStd_ListOfInteger& AIS_LocalContext::
848 SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const
850 return myActiveObjects(anObject)->SelectionModes();
853 //=======================================================================
856 //=======================================================================
858 TCollection_AsciiString AIS_LocalContext::Status() const
860 TCollection_AsciiString t;
864 const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const
866 return myActiveObjects(anObject);
869 //=======================================================================
870 //function : LoadContextObjects
872 //=======================================================================
874 void AIS_LocalContext::LoadContextObjects()
876 AIS_ListIteratorOfListOfInteractive It;
877 if(myLoadDisplayed) {
878 AIS_ListOfInteractive LL;
879 myCTX->DisplayedObjects(LL,Standard_True);
880 Handle(AIS_LocalStatus) Att;
881 for (It.Initialize(LL);It.More();It.Next()){
882 const Handle(AIS_InteractiveObject)& anObj = It.Value();
883 Att= new AIS_LocalStatus();
884 Att->SetDecomposition((anObj->AcceptShapeDecomposition() && myAcceptStdMode));
885 Att->SetTemporary(Standard_False);
886 Att->SetHilightMode(anObj->HasHilightMode()? anObj->HilightMode(): 0);
887 for (anObj->Init(); anObj->More(); anObj->Next())
889 const Handle(SelectMgr_Selection)& aSel = anObj->CurrentSelection();
890 aSel->SetSelectionState (SelectMgr_SOS_Deactivated);
892 myActiveObjects.Bind(anObj,Att);
897 void AIS_LocalContext::UnloadContextObjects()
899 AIS_ListIteratorOfListOfInteractive It;
902 AIS_ListOfInteractive LL;
903 myCTX->DisplayedObjects(LL,Standard_True);
905 for (It.Initialize(LL);It.More();It.Next())
907 myActiveObjects.UnBind(It.Value());
911 //=======================================================================
914 //=======================================================================
916 void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject)
918 if(!myActiveObjects.IsBound(anObject)) return;
919 if(myActiveObjects(anObject)->Decomposed())
920 ActivateStandardModes(anObject);
923 TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
924 for(;It.More();It.Next())
925 myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS);
929 //=======================================================================
932 //=======================================================================
934 void AIS_LocalContext::Process()
939 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
941 for(;It.More();It.Next()){
942 myCTX->SelectionManager()->Load(It.Key(),myMainVS);
943 if(It.Value()->Decomposed())
944 ActivateStandardModes(It.Key());
945 else if( myCTX->GetAutoActivateSelection() )
947 It.Value()->AddSelectionMode(0);
948 myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS);
954 //=======================================================================
955 //function : ActivateModes
957 //=======================================================================
959 void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject)
961 if(!myActiveObjects.IsBound(anObject)) return;
963 TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
965 const Handle(AIS_LocalStatus)& LS = myActiveObjects(anObject);
966 if(LS->Decomposed()){
967 for(;itl.More();itl.Next()){
968 myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS);
969 LS->AddSelectionMode(itl.Value());
975 //=======================================================================
976 //function : ClearObjects
978 //=======================================================================
980 void AIS_LocalContext::ClearObjects()
982 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
983 for(;It.More();It.Next())
985 Handle(AIS_InteractiveObject) SO =
986 Handle(AIS_InteractiveObject)::DownCast(It.Key());
988 const Handle(AIS_LocalStatus)& CurAtt = It.Value();
989 //TColStd_ListIteratorOfListOfInteger ItL;
990 // if object is temporary the presentations managed by myMainPM are removed
991 AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
993 if(TheDS != AIS_DS_Displayed){
994 if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){
995 if(CurAtt->IsSubIntensityOn()&&
996 myMainPM->IsHighlighted(SO,CurAtt->HilightMode()))
997 myMainPM->Unhighlight(SO,CurAtt->HilightMode());
998 myMainPM->Erase(SO,CurAtt->DisplayMode());
1001 if(CurAtt->IsTemporary()){
1002 myMainPM->Erase(SO,CurAtt->DisplayMode());}
1003 // myMainPM->Clear(SO,CurAtt->DisplayMode());}
1006 if (CurAtt->IsSubIntensityOn()){
1007 myCTX->SubIntensityOff(Handle(AIS_InteractiveObject)::DownCast(SO));}
1008 Standard_Integer DiMo = SO->HasDisplayMode()?
1009 SO->DisplayMode():myCTX->DisplayMode();
1010 if(CurAtt->DisplayMode()!=-1 &&
1011 CurAtt->DisplayMode()!= DiMo)
1012 myMainPM->Erase(SO,CurAtt->DisplayMode());
1015 TColStd_ListIteratorOfListOfInteger aSelModeIter (CurAtt->SelectionModes());
1016 for ( ; aSelModeIter.More(); aSelModeIter.Next())
1018 Standard_Integer aSelMode = aSelModeIter.Value();
1019 mySM->Deactivate (SO, aSelMode, myMainVS);
1023 ClearSelected( Standard_False );
1025 // Clear selection structures for temporary objects, created in local context
1026 for (AIS_DataMapIteratorOfDataMapOfSelStat anIter (myActiveObjects); anIter.More(); anIter.Next())
1028 if (anIter.Value()->IsTemporary())
1030 mySM->Remove (anIter.Key(), myMainVS);
1034 myActiveObjects.Clear();
1038 Standard_Boolean AIS_LocalContext::IsDecompositionOn() const
1039 {return !myListOfStandardMode.IsEmpty();}
1044 //=======================================================================
1045 //function : HasAlreadyFilters
1047 //=======================================================================
1049 Standard_Boolean AIS_LocalContext::
1050 HasFilters(const TopAbs_ShapeEnum aType) const
1052 return myFilters->ActsOn(aType);
1055 void AIS_LocalContext::ClearDetected()
1057 for(Standard_Integer I=1;I<=myMapOfOwner->Extent();I++)
1059 if(!myMapOfOwner->FindKey (I).IsNull())
1061 if(myMapOfOwner->FindKey (I)->IsHilighted(myMainPM))
1062 myMapOfOwner->FindKey (I)->Unhilight(myMainPM);
1065 const Handle(SelectMgr_SelectableObject)& SO =
1066 myMapOfOwner->FindKey (I)->Selectable();
1067 if(myActiveObjects.IsBound(SO))
1069 const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1071 if(Att->IsTemporary() &&
1072 Att->DisplayMode()==-1 &&
1073 Att->SelectionModes().IsEmpty())
1075 myMapOfOwner->FindKey (I)->Clear(myMainPM);
1083 //=======================================================================
1084 //function : BeginImmediateDraw
1086 //=======================================================================
1087 Standard_Boolean AIS_LocalContext::BeginImmediateDraw()
1089 if (myMainPM->IsImmediateModeOn())
1091 myMainPM->BeginImmediateDraw();
1092 return Standard_True;
1094 return Standard_False;
1097 //=======================================================================
1098 //function : ImmediateAdd
1100 //=======================================================================
1101 Standard_Boolean AIS_LocalContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
1102 const Standard_Integer theMode)
1104 if (!myMainPM->IsImmediateModeOn())
1106 return Standard_False;
1109 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)->Presentation());
1110 return Standard_True;
1113 //=======================================================================
1114 //function : EndImmediateDraw
1116 //=======================================================================
1117 Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_View)& theView)
1119 if (!myMainPM->IsImmediateModeOn())
1121 return Standard_False;
1124 myMainPM->EndImmediateDraw (theView);
1125 return Standard_True;
1128 // =======================================================================
1129 // function : ClearImmediateDraw
1131 // =======================================================================
1132 void AIS_LocalContext::ClearImmediateDraw()
1134 myMainPM->ClearImmediateDraw();
1137 //=======================================================================
1138 //function : IsImmediateModeOn
1140 //=======================================================================
1141 Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
1143 return myMainPM->IsImmediateModeOn();
1146 void AIS_LocalContext::SetPixelTolerance(const Standard_Real aPrecision) {
1148 myMainVS->SetPixelTolerance(aPrecision);
1151 Standard_Real AIS_LocalContext::PixelTolerance() const {
1153 return myMainVS->PixelTolerance();