]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.cpp
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
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
150     aContext->Load(anAISIO, -1, true);
151     activate(theObject);
152   }
153   if (isUpdateViewer)
154     updateViewer();
155 }
156
157 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
158 {
159   if (!isVisible(theObject))
160     return;
161
162   Handle(AIS_InteractiveContext) aContext = AISContext();
163   if (aContext.IsNull())
164     return;
165   AISObjectPtr anObject = myResult2AISObjectMap[theObject];
166   if (anObject) {
167     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
168     if (!anAIS.IsNull()) {
169       aContext->Remove(anAIS, isUpdateViewer);
170     }
171   }
172   myResult2AISObjectMap.remove(theObject);
173 }
174
175 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
176 {
177   if (!isVisible(theObject))
178     return;
179
180   AISObjectPtr aAISObj = getAISObject(theObject);
181   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
182
183   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
184   if (aPrs) {
185     AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
186     if (!aAIS_Obj) {
187       erase(theObject, isUpdateViewer);
188       return;
189     }
190     if (aAIS_Obj != aAISObj) {
191       myResult2AISObjectMap[theObject] = aAIS_Obj;
192     }
193     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
194   }
195
196   if (!aAISIO.IsNull()) {
197     Handle(AIS_InteractiveContext) aContext = AISContext();
198     if (aContext.IsNull())
199       return;
200     aContext->Redisplay(aAISIO, isUpdateViewer);
201   }
202 }
203
204 void XGUI_Displayer::deactivate(ObjectPtr theObject)
205 {
206   if (isVisible(theObject)) {
207     Handle(AIS_InteractiveContext) aContext = AISContext();
208     if (aContext.IsNull())
209       return;
210
211     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
212     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
213     aContext->Deactivate(anAIS);
214     qDebug("### Deactivate obj %i", (long)anAIS.Access());
215   }
216 }
217
218 void XGUI_Displayer::activate(ObjectPtr theFeature)
219 {
220   activate(theFeature, myActiveSelectionModes);
221 }
222
223 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
224 {
225   if (isVisible(theObject)) {
226     Handle(AIS_InteractiveContext) aContext = AISContext();
227     if (aContext.IsNull())
228       return;
229
230     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
231     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
232     aContext->Deactivate(anAIS);
233     //if (aContext->HasOpenedContext()) {
234     //  aContext->Load(anAIS, -1, true);
235     //}
236     // In order to clear active modes list
237     if (theModes.size() > 0) {
238       foreach(int aMode, theModes) {
239         aContext->Activate(anAIS, aMode);
240         qDebug("### 1. Activate obj %i, %i", (long)anAIS.Access(), aMode);
241       }
242     } else {
243       aContext->Activate(anAIS);
244       qDebug("### 2. Activate obj %i", (long)anAIS.Access());
245     }
246   }
247 }
248
249 void XGUI_Displayer::activateObjects(const QIntList& theModes)
250 {
251   // In order to avoid doblications of selection modes
252   myActiveSelectionModes.clear();
253   foreach (int aMode, theModes) {
254     if (!myActiveSelectionModes.contains(aMode))
255       myActiveSelectionModes.append(aMode);
256   }
257   Handle(AIS_InteractiveContext) aContext = AISContext();
258   // Open local context if there is no one
259   if (!aContext->HasOpenedContext()) 
260     return;
261
262   //aContext->UseDisplayedObjects();
263   //myUseExternalObjects = true;
264
265   AIS_ListOfInteractive aPrsList;
266   displayedObjects(aContext, aPrsList);
267
268   Handle(AIS_Trihedron) aTrihedron;
269   AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
270   Handle(AIS_InteractiveObject) anAISIO;
271   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
272     anAISIO = aLIt.Value();
273     aContext->Deactivate(anAISIO);
274     aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
275     //Deactivate trihedron which can be activated in local selector
276     if (aTrihedron.IsNull()) {
277       //aContext->Load(anAISIO, -1, true);
278       // In order to clear active modes list
279       if (myActiveSelectionModes.size() == 0) {
280         aContext->Activate(anAISIO);
281         qDebug("### 2. Activate all %i", (long)anAISIO.Access());
282       } else {
283         foreach(int aMode, myActiveSelectionModes) {
284           aContext->Activate(anAISIO, aMode);
285           qDebug("### 1. Activate all %i, %i", (long)anAISIO.Access(), aMode);
286         }
287       }
288     }
289   }
290 }
291
292
293 void XGUI_Displayer::deactivateObjects()
294 {
295   myActiveSelectionModes.clear();
296   Handle(AIS_InteractiveContext) aContext = AISContext();
297   // Open local context if there is no one
298   if (!aContext->HasOpenedContext()) 
299     return;
300
301   //aContext->NotUseDisplayedObjects();
302   AIS_ListOfInteractive aPrsList;
303   displayedObjects(aContext, aPrsList);
304
305   AIS_ListIteratorOfListOfInteractive aLIt;
306   Handle(AIS_Trihedron) aTrihedron;
307   Handle(AIS_InteractiveObject) anAISIO;
308   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
309     anAISIO = aLIt.Value();
310     aContext->Deactivate(anAISIO);
311     aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
312     if (aTrihedron.IsNull()) {
313       //aContext->Load(anAISIO, -1, true);
314       qDebug("### Deactivate all %i", (long)anAISIO.Access());
315       //aContext->Activate(anAISIO);
316     }
317   }
318 }
319
320 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
321 {
322   Handle(AIS_InteractiveContext) aContext = AISContext();
323   if (aContext.IsNull())
324     return false;
325   if (!isVisible(theObject))
326     return false;
327     
328   AISObjectPtr anObj = myResult2AISObjectMap[theObject];
329   Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
330
331   TColStd_ListOfInteger aModes;
332   aContext->ActivatedModes(anAIS, aModes);
333   return aModes.Extent() > 0;
334 }
335
336 void XGUI_Displayer::stopSelection(const QObjectPtrList& theResults, const bool isStop,
337                                    const bool isUpdateViewer)
338 {
339   Handle(AIS_InteractiveContext) aContext = AISContext();
340   if (aContext.IsNull())
341     return;
342
343   Handle(AIS_Shape) anAIS;
344   QObjectPtrList::const_iterator anIt = theResults.begin(), aLast = theResults.end();
345   ObjectPtr aFeature;
346   for (; anIt != aLast; anIt++) {
347     aFeature = *anIt;
348     if (isVisible(aFeature))
349       anAIS = Handle(AIS_Shape)::DownCast(
350           myResult2AISObjectMap[aFeature]->impl<Handle(AIS_InteractiveObject)>());
351     if (anAIS.IsNull())
352       continue;
353
354     if (isStop) {
355       QColor aColor(Qt::white);
356       anAIS->SetColor(
357           Quantity_Color(aColor.red() / 255., aColor.green() / 255., aColor.blue() / 255.,
358                          Quantity_TOC_RGB));
359       anAIS->Redisplay();
360     } else {
361       QColor aColor(Qt::red);
362       anAIS->SetColor(
363           Quantity_Color(aColor.red() / 255., aColor.green() / 255., aColor.blue() / 255.,
364                          Quantity_TOC_RGB));
365       anAIS->Redisplay();
366     }
367   }
368   if (isUpdateViewer)
369     updateViewer();
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::eraseDeletedResults(const bool isUpdateViewer)
432 //{
433 //  Handle(AIS_InteractiveContext) aContext = AISContext();
434 //  if (aContext.IsNull())
435 //    return;
436 //
437 //  QObjectPtrList aRemoved;
438 //  foreach (ObjectPtr aFeature, myResult2AISObjectMap.keys()) {
439 //    if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
440 //      AISObjectPtr anObj = myResult2AISObjectMap[aFeature];
441 //      if (!anObj)
442 //        continue;
443 //      Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
444 //      if (!anAIS.IsNull()) {
445 //        aContext->Remove(anAIS, false);
446 //        aRemoved.append(aFeature);
447 //      }
448 //    }
449 //  }
450 //  foreach(ObjectPtr aObj, aRemoved) {
451 //    myResult2AISObjectMap.remove(aObj);
452 //  }
453 //
454 //  if (isUpdateViewer)
455 //    updateViewer();
456 //}
457
458 void XGUI_Displayer::openLocalContext()
459 {
460   Handle(AIS_InteractiveContext) aContext = AISContext();
461   if (aContext.IsNull())
462     return;
463   // Open local context if there is no one
464   if (!aContext->HasOpenedContext()) {
465     // Preserve selected objects
466     //AIS_ListOfInteractive aAisList;
467     //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
468     //  aAisList.Append(aContext->Current());
469
470     // get the filters from the global context and append them to the local context
471     // a list of filters in the global context is not cleared and should be cleared here
472     SelectMgr_ListOfFilter aFilters;
473     aFilters.Assign(aContext->Filters());
474     // it is important to remove the filters in the global context, because there is a code
475     // in the closeLocalContex, which restore the global context filters
476     aContext->RemoveFilters();
477
478     //aContext->ClearCurrents();
479     aContext->OpenLocalContext();
480     qDebug("### Open context");
481     //aContext->NotUseDisplayedObjects();
482
483     //myUseExternalObjects = false;
484     myActiveSelectionModes.clear();
485
486     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
487     for (;aIt.More(); aIt.Next()) {
488       aContext->AddFilter(aIt.Value());
489     }
490     // Restore selection
491     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
492     //for(; aIt2.More(); aIt2.Next()) {
493     //  aContext->SetSelected(aIt2.Value(), false);
494     //}
495   }
496 }
497
498 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
499 {
500   Handle(AIS_InteractiveContext) aContext = AISContext();
501   if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
502     // Preserve selected objects
503     //AIS_ListOfInteractive aAisList;
504     //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
505     //  aAisList.Append(aContext->SelectedInteractive());
506
507     // get the filters from the local context and append them to the global context
508     // a list of filters in the local context is cleared
509     SelectMgr_ListOfFilter aFilters;
510     aFilters.Assign(aContext->Filters());
511
512     //aContext->ClearSelected();
513     aContext->CloseAllContexts(false);
514     qDebug("### Close context");
515
516     // Redisplay all object if they were displayed in localContext
517     Handle(AIS_InteractiveObject) aAISIO;
518     foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
519       aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
520       if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
521         aContext->Display(aAISIO, false);
522         aContext->SetDisplayMode(aAISIO, Shading, false);
523       }
524     }
525
526     // Append the filters from the local selection in the global selection context
527     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
528     for (;aIt.More(); aIt.Next()) {
529       Handle(SelectMgr_Filter) aFilter = aIt.Value();
530       aContext->AddFilter(aFilter);
531     }
532
533     if (isUpdateViewer)
534       updateViewer();
535     //myUseExternalObjects = false;
536     myActiveSelectionModes.clear();
537
538     // Restore selection
539     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
540     //for(; aIt2.More(); aIt2.Next()) {
541     //  if (aContext->IsDisplayed(aIt2.Value()))
542     //    aContext->SetCurrentObject(aIt2.Value(), false);
543     //}
544   }
545 }
546
547 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
548 {
549   AISObjectPtr anIO;
550   if (myResult2AISObjectMap.contains(theObject))
551     anIO = myResult2AISObjectMap[theObject];
552   return anIO;
553 }
554
555 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
556 {
557   Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
558   return getObject(aRefAIS);
559 }
560
561 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
562 {
563   ObjectPtr aFeature;
564   foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
565     AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
566     Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
567     if (anAIS == theIO)
568       return anObj;
569   }
570   return aFeature;
571 }
572
573 void XGUI_Displayer::updateViewer()
574 {
575   Handle(AIS_InteractiveContext) aContext = AISContext();
576   if (!aContext.IsNull())
577     aContext->UpdateCurrentViewer();
578 }
579
580 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
581 {
582   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
583   if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
584     aContext->OpenLocalContext();
585     qDebug("### Open context");
586   }
587   return aContext;
588 }
589
590 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
591 {
592   Handle(AIS_InteractiveContext) aContext = AISContext();
593   if (myAndFilter.IsNull() && !aContext.IsNull()) {
594     myAndFilter = new SelectMgr_AndFilter();
595     aContext->AddFilter(myAndFilter);
596   }
597   return myAndFilter;
598 }
599
600 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
601 {
602   Handle(AIS_InteractiveContext) aContext = AISContext();
603   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
604   if (!anAISIO.IsNull()) {
605     aContext->Display(anAISIO, isUpdate);
606     if (aContext->HasOpenedContext()) {
607       //if (myUseExternalObjects) {
608         if (myActiveSelectionModes.size() == 0)
609           aContext->Activate(anAISIO);
610         else {
611           foreach(int aMode, myActiveSelectionModes) {
612             aContext->Activate(anAISIO, aMode);
613           }
614         }
615       //}
616     }
617   }
618 }
619
620 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
621 {
622   Handle(AIS_InteractiveContext) aContext = AISContext();
623   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
624   if (!anAISIO.IsNull()) {
625     aContext->Remove(anAISIO, isUpdate);
626   }
627 }
628
629
630 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
631 {
632   if (theMode == NoMode)
633     return;
634
635   Handle(AIS_InteractiveContext) aContext = AISContext();
636   if (aContext.IsNull())
637     return;
638
639   AISObjectPtr aAISObj = getAISObject(theObject);
640   if (!aAISObj)
641     return;
642
643   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
644   aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
645 }
646
647 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
648 {
649   Handle(AIS_InteractiveContext) aContext = AISContext();
650   if (aContext.IsNull())
651     return NoMode;
652
653   AISObjectPtr aAISObj = getAISObject(theObject);
654   if (!aAISObj)
655     return NoMode;
656
657   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
658   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
659 }
660
661 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
662 {
663   Handle(AIS_InteractiveContext) aContext = AISContext();
664   if (aContext.IsNull())
665     return;
666   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
667   SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
668   for (; aIt.More(); aIt.Next()) {
669     if (theFilter.Access() == aIt.Value().Access())
670       return;
671   }
672   GetFilter()->Add(theFilter);
673 }
674
675 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
676 {
677   Handle(AIS_InteractiveContext) aContext = AISContext();
678   if (aContext.IsNull())
679     return;
680   GetFilter()->Remove(theFilter);
681 }
682
683 void XGUI_Displayer::removeFilters()
684 {
685   Handle(AIS_InteractiveContext) aContext = AISContext();
686   if (aContext.IsNull())
687     return;
688   GetFilter()->Clear();
689 }
690
691 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
692 {
693   QObjectPtrList aDispList = myResult2AISObjectMap.keys();
694   foreach(ObjectPtr aObj, aDispList) {
695     if (!theList.contains(aObj))
696       erase(aObj, false);
697   }
698   foreach(ObjectPtr aObj, theList) {
699     if (!isVisible(aObj))
700       display(aObj, false);
701   }
702   updateViewer();
703 }