Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_Displayer.cpp
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include "XGUI_Displayer.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12
13 #include <AppElements_Viewer.h>
14
15 #include <ModelAPI_Document.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Object.h>
18 #include <ModelAPI_Tools.h>
19
20 #include <ModuleBase_ResultPrs.h>
21
22 #include <GeomAPI_Shape.h>
23 #include <GeomAPI_IPresentable.h>
24 #include <GeomAPI_ICustomPrs.h>
25
26 #include <AIS_InteractiveContext.hxx>
27 #include <AIS_LocalContext.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <AIS_DimensionSelectionMode.hxx>
31 #include <AIS_Shape.hxx>
32 #include <AIS_Dimension.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 #include <SelectMgr_ListOfFilter.hxx>
35 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
36
37 #include <TColStd_MapOfTransient.hxx>
38 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
39
40 #include <set>
41
42 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;  ///< defines the local context mouse selection sensitivity
43
44
45 // Workaround for bug #25637
46 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
47 {
48   // Get from null point
49   theAIS->DisplayedObjects(theList, true);
50   if (theAIS->HasOpenedContext()) {
51     // get from local context
52     const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
53     TColStd_MapOfTransient aMap;
54     int NbDisp = aLC->DisplayedObjects(aMap);
55     TColStd_MapIteratorOfMapOfTransient aIt(aMap);
56
57     Handle(AIS_InteractiveObject) curIO;
58     Handle(Standard_Transient) Tr;
59     for(; aIt.More(); aIt.Next()){
60       Tr = aIt.Key();
61       curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
62       theList.Append(curIO);
63     }
64   }
65 }
66
67
68 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
69   : myWorkshop(theWorkshop)
70 {
71 }
72
73 XGUI_Displayer::~XGUI_Displayer()
74 {
75 }
76
77 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
78 {
79   return myResult2AISObjectMap.contains(theObject);
80 }
81
82 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
83 {
84   if (isVisible(theObject)) {
85     redisplay(theObject, isUpdateViewer);
86   } else {
87     AISObjectPtr anAIS;
88
89     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
90     bool isShading = false;
91     if (aPrs.get() != NULL) {
92       anAIS = aPrs->getAISObject(AISObjectPtr());
93     } else {
94       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
95       if (aResult.get() != NULL) {
96         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
97         if (aShapePtr.get() != NULL) {
98           anAIS = AISObjectPtr(new GeomAPI_AISObject());
99           anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
100           //anAIS->createShape(aShapePtr);
101           isShading = true;
102         }
103       }
104     }
105     if (anAIS)
106       display(theObject, anAIS, isShading, isUpdateViewer);
107   }
108 }
109
110 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
111 {
112   Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
113   if (!aShapePrs.IsNull()) {
114     TopoDS_Shape aShape = aShapePrs->Shape();
115     TopAbs_ShapeEnum aType = aShape.ShapeType();
116     if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
117       return false;
118     else
119       return true;
120   }
121   return false;
122 }
123
124 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, 
125                              bool isShading, bool isUpdateViewer)
126 {
127   Handle(AIS_InteractiveContext) aContext = AISContext();
128   if (aContext.IsNull())
129     return;
130
131   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
132   if (!anAISIO.IsNull()) {
133     myResult2AISObjectMap[theObject] = theAIS;
134     bool aCanBeShaded = ::canBeShaded(anAISIO);
135     // In order to avoid extra closing/opening context
136     SelectMgr_IndexedMapOfOwner aSelectedOwners;
137     if (aCanBeShaded) {
138       myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
139       closeLocalContexts(false);
140     }
141     aContext->Display(anAISIO, false);
142     qDebug("### Display %i", (long)anAISIO.Access());
143
144     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
145     // Customization of presentation
146     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
147     if (aFeature.get() != NULL) {
148       GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
149       if (aCustPrs.get() != NULL)
150         aCustPrs->customisePresentation(theAIS);
151     }
152     if (aCanBeShaded) {
153       openLocalContext();
154       activateObjects(myActiveSelectionModes);
155       myWorkshop->selector()->setSelectedOwners(aSelectedOwners);
156     }
157   }
158   if (isUpdateViewer)
159     updateViewer();
160 }
161
162 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
163 {
164   if (!isVisible(theObject))
165     return;
166
167   Handle(AIS_InteractiveContext) aContext = AISContext();
168   if (aContext.IsNull())
169     return;
170   AISObjectPtr anObject = myResult2AISObjectMap[theObject];
171   if (anObject) {
172     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
173     if (!anAIS.IsNull()) {
174       aContext->Remove(anAIS, isUpdateViewer);
175     }
176   }
177   myResult2AISObjectMap.remove(theObject);
178 }
179
180 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
181 {
182   if (!isVisible(theObject))
183     return;
184
185   AISObjectPtr aAISObj = getAISObject(theObject);
186   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
187
188   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
189   if (aPrs) {
190     AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
191     if (!aAIS_Obj) {
192       erase(theObject, isUpdateViewer);
193       return;
194     }
195     if (aAIS_Obj != aAISObj) {
196       myResult2AISObjectMap[theObject] = aAIS_Obj;
197     }
198     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
199   }
200
201   if (!aAISIO.IsNull()) {
202     Handle(AIS_InteractiveContext) aContext = AISContext();
203     if (aContext.IsNull())
204       return;
205     bool aToSelect = aContext->IsSelected(aAISIO);
206     aContext->Redisplay(aAISIO, false);
207     // Restore selection state after redisplay
208     if (aToSelect) 
209       aContext->SetSelected(aAISIO);
210     if (isUpdateViewer)
211       updateViewer();
212   }
213 }
214
215 void XGUI_Displayer::deactivate(ObjectPtr theObject)
216 {
217   if (isVisible(theObject)) {
218     Handle(AIS_InteractiveContext) aContext = AISContext();
219     if (aContext.IsNull())
220       return;
221
222     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
223     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
224     aContext->Deactivate(anAIS);
225     qDebug("### Deactivate obj %i", (long)anAIS.Access());
226   }
227 }
228
229 void XGUI_Displayer::activate(ObjectPtr theFeature)
230 {
231   activate(theFeature, myActiveSelectionModes);
232 }
233
234 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
235 {
236   if (isVisible(theObject)) {
237     Handle(AIS_InteractiveContext) aContext = AISContext();
238     if (aContext.IsNull())
239       return;
240
241     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
242     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
243     aContext->Deactivate(anAIS);
244     aContext->Load(anAIS, -1, true);
245     // In order to clear active modes list
246     if (theModes.size() > 0) {
247       foreach(int aMode, theModes) {
248         //aContext->Load(anAIS, aMode, true);
249         aContext->Activate(anAIS, aMode);
250         qDebug("### 1. Activate obj %i, %i", (long)anAIS.Access(), aMode);
251       }
252     } else {
253       //aContext->Load(anAIS, 0, true);
254       aContext->Activate(anAIS);
255       qDebug("### 2. Activate obj %i", (long)anAIS.Access());
256     }
257   }
258 }
259
260 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
261 {
262   if (!isVisible(theObject))
263     return;
264
265   Handle(AIS_InteractiveContext) aContext = AISContext();
266   if (aContext.IsNull())
267     return;
268
269   AISObjectPtr aAISObj = getAISObject(theObject);
270
271   if (aAISObj.get() != NULL) {
272     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
273     TColStd_ListOfInteger aTColModes;
274     aContext->ActivatedModes(anAISIO, aTColModes);
275     TColStd_ListIteratorOfListOfInteger itr( aTColModes );
276     for (; itr.More(); itr.Next() ) {
277       theModes.append(itr.Value());
278     }
279   }
280 }
281
282 void XGUI_Displayer::activateObjects(const QIntList& theModes)
283 {
284   // In order to avoid doblications of selection modes
285   QIntList aNewModes;
286   foreach (int aMode, theModes) {
287     if (!aNewModes.contains(aMode))
288       aNewModes.append(aMode);
289   }
290   myActiveSelectionModes = aNewModes;
291   Handle(AIS_InteractiveContext) aContext = AISContext();
292   // Open local context if there is no one
293   if (!aContext->HasOpenedContext()) 
294     return;
295
296   //aContext->UseDisplayedObjects();
297   //myUseExternalObjects = true;
298
299   AIS_ListOfInteractive aPrsList;
300   displayedObjects(aContext, aPrsList);
301
302   Handle(AIS_Trihedron) aTrihedron;
303   AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
304   Handle(AIS_InteractiveObject) anAISIO;
305   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
306     anAISIO = aLIt.Value();
307     aContext->Load(anAISIO, -1, true);
308     aContext->Deactivate(anAISIO);
309     aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
310     //Deactivate trihedron which can be activated in local selector
311     if (aTrihedron.IsNull()) {
312       //aContext->Load(anAISIO, -1, true);
313       // In order to clear active modes list
314       if (myActiveSelectionModes.size() == 0) {
315         //aContext->Load(anAISIO, 0, true);
316         aContext->Activate(anAISIO);
317         qDebug("### 2. Activate all %i", (long)anAISIO.Access());
318       } else {
319         foreach(int aMode, myActiveSelectionModes) {
320           //aContext->Load(anAISIO, aMode, true);
321           aContext->Activate(anAISIO, aMode);
322           qDebug("### 1. Activate all %i, %i", (long)anAISIO.Access(), aMode);
323         }
324       }
325     }
326   }
327 }
328
329
330 void XGUI_Displayer::deactivateObjects()
331 {
332   myActiveSelectionModes.clear();
333   Handle(AIS_InteractiveContext) aContext = AISContext();
334   // Open local context if there is no one
335   if (!aContext->HasOpenedContext()) 
336     return;
337
338   //aContext->NotUseDisplayedObjects();
339   AIS_ListOfInteractive aPrsList;
340   displayedObjects(aContext, aPrsList);
341
342   AIS_ListIteratorOfListOfInteractive aLIt;
343   //Handle(AIS_Trihedron) aTrihedron;
344   Handle(AIS_InteractiveObject) anAISIO;
345   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
346     anAISIO = aLIt.Value();
347     aContext->Deactivate(anAISIO);
348     //aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
349     //if (aTrihedron.IsNull()) {
350     //  qDebug("### Deactivate all %i", (long)anAISIO.Access());
351     //  //aContext->Activate(anAISIO);
352     //}
353   }
354 }
355
356 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
357 {
358   Handle(AIS_InteractiveContext) aContext = AISContext();
359   if (aContext.IsNull())
360     return false;
361   if (!isVisible(theObject))
362     return false;
363     
364   AISObjectPtr anObj = myResult2AISObjectMap[theObject];
365   Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
366
367   TColStd_ListOfInteger aModes;
368   aContext->ActivatedModes(anAIS, aModes);
369   return aModes.Extent() > 0;
370 }
371
372 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
373 {
374   Handle(AIS_InteractiveContext) aContext = AISContext();
375   if (aContext.IsNull())
376     return;
377   if (aContext->HasOpenedContext()) {
378     aContext->UnhilightSelected();
379     aContext->ClearSelected();
380     foreach(ObjectPtr aResult, theResults) {
381       if (isVisible(aResult)) {
382         AISObjectPtr anObj = myResult2AISObjectMap[aResult];
383         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
384         if (!anAIS.IsNull())
385           aContext->SetSelected(anAIS, false);
386       }
387     }
388   } else {
389     aContext->UnhilightCurrents();
390     aContext->ClearCurrents();
391     foreach(ObjectPtr aResult, theResults) {
392       if (isVisible(aResult)) {
393         AISObjectPtr anObj = myResult2AISObjectMap[aResult];
394         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
395         if (!anAIS.IsNull())
396           aContext->SetCurrentObject(anAIS, false);
397       }
398     }
399   }
400   if (isUpdateViewer)
401     updateViewer();
402 }
403
404
405 void XGUI_Displayer::clearSelected()
406 {
407   Handle(AIS_InteractiveContext) aContext = AISContext();
408   if (aContext) {
409     aContext->UnhilightCurrents(false);
410     aContext->ClearSelected();
411   }
412 }
413
414 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
415 {
416   Handle(AIS_InteractiveContext) aContext = AISContext();
417   if (aContext.IsNull())
418     return;
419
420    foreach (AISObjectPtr aAISObj, myResult2AISObjectMap) {
421      // erase an object
422      Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
423      if (!anIO.IsNull())
424        aContext->Remove(anIO, false);
425    }
426    myResult2AISObjectMap.clear();
427    if (isUpdateViewer)
428      updateViewer();
429  }
430
431 void XGUI_Displayer::openLocalContext()
432 {
433   Handle(AIS_InteractiveContext) aContext = AISContext();
434   if (aContext.IsNull())
435     return;
436   // Open local context if there is no one
437   if (!aContext->HasOpenedContext()) {
438     // Preserve selected objects
439     //AIS_ListOfInteractive aAisList;
440     //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
441     //  aAisList.Append(aContext->Current());
442
443     // get the filters from the global context and append them to the local context
444     // a list of filters in the global context is not cleared and should be cleared here
445     SelectMgr_ListOfFilter aFilters;
446     aFilters.Assign(aContext->Filters());
447     // it is important to remove the filters in the global context, because there is a code
448     // in the closeLocalContex, which restore the global context filters
449     aContext->RemoveFilters();
450
451     //aContext->ClearCurrents();
452     aContext->OpenLocalContext();
453     qDebug("### Open context");
454     //aContext->NotUseDisplayedObjects();
455
456     //myUseExternalObjects = false;
457
458     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
459     for (;aIt.More(); aIt.Next()) {
460       aContext->AddFilter(aIt.Value());
461     }
462     // Restore selection
463     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
464     //for(; aIt2.More(); aIt2.Next()) {
465     //  aContext->SetSelected(aIt2.Value(), false);
466     //}
467   }
468 }
469
470 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
471 {
472   Handle(AIS_InteractiveContext) aContext = AISContext();
473   if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
474     // Preserve selected objects
475     //AIS_ListOfInteractive aAisList;
476     //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
477     //  aAisList.Append(aContext->SelectedInteractive());
478
479     // get the filters from the local context and append them to the global context
480     // a list of filters in the local context is cleared
481     SelectMgr_ListOfFilter aFilters;
482     aFilters.Assign(aContext->Filters());
483
484     //aContext->ClearSelected();
485     aContext->CloseAllContexts(false);
486     qDebug("### Close context");
487
488     // Redisplay all object if they were displayed in localContext
489     Handle(AIS_InteractiveObject) aAISIO;
490     foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
491       aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
492       if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
493         aContext->Display(aAISIO, false);
494         aContext->SetDisplayMode(aAISIO, Shading, false);
495       }
496     }
497
498     // Append the filters from the local selection in the global selection context
499     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
500     for (;aIt.More(); aIt.Next()) {
501       Handle(SelectMgr_Filter) aFilter = aIt.Value();
502       aContext->AddFilter(aFilter);
503     }
504
505     if (isUpdateViewer)
506       updateViewer();
507     //myUseExternalObjects = false;
508
509     // Restore selection
510     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
511     //for(; aIt2.More(); aIt2.Next()) {
512     //  if (aContext->IsDisplayed(aIt2.Value()))
513     //    aContext->SetCurrentObject(aIt2.Value(), false);
514     //}
515   }
516 }
517
518 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
519 {
520   AISObjectPtr anIO;
521   if (myResult2AISObjectMap.contains(theObject))
522     anIO = myResult2AISObjectMap[theObject];
523   return anIO;
524 }
525
526 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
527 {
528   Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
529   return getObject(aRefAIS);
530 }
531
532 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
533 {
534   ObjectPtr aFeature;
535   foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
536     AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
537     Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
538     if (anAIS == theIO)
539       return anObj;
540   }
541   return aFeature;
542 }
543
544 void XGUI_Displayer::updateViewer()
545 {
546   Handle(AIS_InteractiveContext) aContext = AISContext();
547   if (!aContext.IsNull())
548     aContext->UpdateCurrentViewer();
549 }
550
551 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
552 {
553   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
554   if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
555     aContext->OpenLocalContext();
556     qDebug("### Open context");
557   }
558   return aContext;
559 }
560
561 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
562 {
563   Handle(AIS_InteractiveContext) aContext = AISContext();
564   if (myAndFilter.IsNull() && !aContext.IsNull()) {
565     myAndFilter = new SelectMgr_AndFilter();
566     aContext->AddFilter(myAndFilter);
567   }
568   return myAndFilter;
569 }
570
571 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
572 {
573   Handle(AIS_InteractiveContext) aContext = AISContext();
574   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
575   if (!anAISIO.IsNull()) {
576     aContext->Display(anAISIO, isUpdate);
577     if (aContext->HasOpenedContext()) {
578       //if (myUseExternalObjects) {
579         if (myActiveSelectionModes.size() == 0)
580           aContext->Activate(anAISIO);
581         else {
582           foreach(int aMode, myActiveSelectionModes) {
583             aContext->Activate(anAISIO, aMode);
584           }
585         }
586       //}
587     }
588   }
589 }
590
591 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
592 {
593   Handle(AIS_InteractiveContext) aContext = AISContext();
594   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
595   if (!anAISIO.IsNull()) {
596     aContext->Remove(anAISIO, isUpdate);
597   }
598 }
599
600
601 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
602 {
603   if (theMode == NoMode)
604     return;
605
606   Handle(AIS_InteractiveContext) aContext = AISContext();
607   if (aContext.IsNull())
608     return;
609
610   AISObjectPtr aAISObj = getAISObject(theObject);
611   if (!aAISObj)
612     return;
613
614   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
615   bool aCanBeShaded = ::canBeShaded(aAISIO);
616   // In order to avoid extra closing/opening context
617   if (aCanBeShaded)
618     closeLocalContexts(false);
619   aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
620   if (aCanBeShaded) {
621     openLocalContext();
622     activateObjects(myActiveSelectionModes);
623   }
624 }
625
626 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
627 {
628   Handle(AIS_InteractiveContext) aContext = AISContext();
629   if (aContext.IsNull())
630     return NoMode;
631
632   AISObjectPtr aAISObj = getAISObject(theObject);
633   if (!aAISObj)
634     return NoMode;
635
636   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
637   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
638 }
639
640 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
641 {
642   Handle(AIS_InteractiveContext) aContext = AISContext();
643   if (aContext.IsNull())
644     return;
645   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
646   SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
647   for (; aIt.More(); aIt.Next()) {
648     if (theFilter.Access() == aIt.Value().Access())
649       return;
650   }
651   GetFilter()->Add(theFilter);
652 }
653
654 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
655 {
656   Handle(AIS_InteractiveContext) aContext = AISContext();
657   if (aContext.IsNull())
658     return;
659   GetFilter()->Remove(theFilter);
660 }
661
662 void XGUI_Displayer::removeFilters()
663 {
664   Handle(AIS_InteractiveContext) aContext = AISContext();
665   if (aContext.IsNull())
666     return;
667   GetFilter()->Clear();
668 }
669
670 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
671 {
672   QObjectPtrList aDispList = myResult2AISObjectMap.keys();
673   foreach(ObjectPtr aObj, aDispList) {
674     if (!theList.contains(aObj))
675       erase(aObj, false);
676   }
677   foreach(ObjectPtr aObj, theList) {
678     if (!isVisible(aObj))
679       display(aObj, false);
680   }
681   updateViewer();
682 }
683
684 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
685
686   if (!isVisible(theObject))
687     return false;
688
689   AISObjectPtr aAISObj = getAISObject(theObject);
690   if (aAISObj.get() == NULL)
691     return false;
692
693   Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
694   return ::canBeShaded(anAIS);
695 }