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