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