Salome HOME
Issue #2362 Show dimensional and geometrical constraints is not activated
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "XGUI_Displayer.h"
22
23 #include "XGUI_CustomPrs.h"
24 #include "XGUI_FacesPanel.h"
25 #include "XGUI_Selection.h"
26 #include "XGUI_SelectionActivate.h"
27 #include "XGUI_SelectionMgr.h"
28 #include "XGUI_ViewerProxy.h"
29 #include "XGUI_Workshop.h"
30
31 #ifndef HAVE_SALOME
32 #include <AppElements_Viewer.h>
33 #endif
34
35 #include <ModelAPI_Document.h>
36 #include <ModelAPI_Data.h>
37 #include <ModelAPI_Object.h>
38 #include <ModelAPI_Tools.h>
39 #include <ModelAPI_AttributeIntArray.h>
40 #include <ModelAPI_ResultCompSolid.h>
41
42 #include <ModuleBase_BRepOwner.h>
43 #include <ModuleBase_IModule.h>
44 #include <ModuleBase_Preferences.h>
45 #include <ModuleBase_ResultPrs.h>
46 #include <ModuleBase_Tools.h>
47 #include <ModuleBase_ViewerPrs.h>
48
49 #include <GeomAPI_Shape.h>
50 #include <GeomAPI_IPresentable.h>
51 #include <GeomAPI_ICustomPrs.h>
52
53 #include <SUIT_ResourceMgr.h>
54
55 #include <AIS_InteractiveContext.hxx>
56 #include <AIS_ListOfInteractive.hxx>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
58 #include <AIS_DimensionSelectionMode.hxx>
59 #include <AIS_Shape.hxx>
60 #include <AIS_Dimension.hxx>
61 #include <AIS_Trihedron.hxx>
62 #ifdef BEFORE_TRIHEDRON_PATCH
63 #include <AIS_Axis.hxx>
64 #include <AIS_Plane.hxx>
65 #include <AIS_Point.hxx>
66 #endif
67 #include <AIS_Selection.hxx>
68 #include <Prs3d_Drawer.hxx>
69 #include <Prs3d_IsoAspect.hxx>
70 #include <SelectMgr_ListOfFilter.hxx>
71 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
72 #include <SelectMgr_SelectionManager.hxx>
73 #include <TColStd_ListIteratorOfListOfInteger.hxx>
74
75 #include <StdSelect_ViewerSelector3d.hxx>
76
77 #include <TColStd_MapOfTransient.hxx>
78 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
79
80 #ifdef TINSPECTOR
81 #include <inspector/VInspectorAPI_CallBack.hxx>
82 #endif
83
84 #include <Events_Loop.h>
85 #include <ModelAPI_Events.h>
86
87 #include <set>
88
89 /// defines the local context mouse selection sensitivity
90 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
91
92 //#define DEBUG_DISPLAY
93 //#define DEBUG_FEATURE_REDISPLAY
94 //#define DEBUG_SELECTION_FILTERS
95
96 //#define DEBUG_COMPOSILID_DISPLAY
97
98 //#define DEBUG_OCCT_SHAPE_SELECTION
99
100 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
101
102 //#define DEBUG_VIEWER_BLOCKED_COUNT
103
104 //**************************************************************
105 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
106 {
107   // Get from null point
108   theAIS->DisplayedObjects(theList, true);
109 }
110
111 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
112 {
113   QStringList anInfo;
114   QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
115   for (; anIt != aLast; anIt++) {
116     anInfo.append(QString::number(*anIt));
117   }
118   return anInfo.join(theSeparator);
119 }
120
121 //**************************************************************
122 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
123 : myWorkshop(theWorkshop), myNeedUpdate(false),
124   myViewerBlockedRecursiveCount(0), myIsFirstAISContextUse(true)
125 {
126   myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
127 }
128
129 //**************************************************************
130 XGUI_Displayer::~XGUI_Displayer()
131 {
132 }
133
134 //**************************************************************
135 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
136 {
137   return myResult2AISObjectMap.contains(theObject);
138 }
139
140 //**************************************************************
141 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
142 {
143   bool aDisplayed = false;
144   if (isVisible(theObject)) {
145 #ifdef DEBUG_COMPOSILID_DISPLAY
146     ResultCompSolidPtr aCompsolidResult =
147       std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
148     if (aCompsolidResult.get()) {
149       for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
150         ResultPtr aSubResult = aCompsolidResult->subResult(i);
151         if (aSubResult.get())
152           redisplay(aSubResult, false);
153       }
154       if (theUpdateViewer)
155         updateViewer();
156     }
157     else
158 #endif
159     aDisplayed = redisplay(theObject, theUpdateViewer);
160   } else {
161     AISObjectPtr anAIS;
162     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
163     bool isShading = false;
164     if (aPrs.get() != NULL) {
165       anAIS = aPrs->getAISObject(anAIS);
166       if (anAIS.get()) {
167         // correct deviation coefficient for
168         /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
169         if (!anAISPrs.IsNull()) {
170           Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
171           if (!aShapePrs.IsNull()) {
172             TopoDS_Shape aShape = aShapePrs->Shape();
173             if (!aShape.IsNull())
174               //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
175           }
176         }*/
177       }
178     } else {
179       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
180       if (aResult.get() != NULL) {
181 #ifdef DEBUG_COMPOSILID_DISPLAY
182         ResultCompSolidPtr aCompsolidResult =
183           std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
184         if (aCompsolidResult.get()) {
185           for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
186             ResultPtr aSubResult = aCompsolidResult->subResult(i);
187             if (aSubResult.get())
188               display(aSubResult, false);
189           }
190           if (theUpdateViewer)
191             updateViewer();
192         }
193         else {
194 #endif
195         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
196         if (aShapePtr.get() != NULL) {
197           anAIS = AISObjectPtr(new GeomAPI_AISObject());
198           Handle(AIS_InteractiveObject) anAISPrs =
199             myWorkshop->module()->createPresentation(aResult);
200           if (anAISPrs.IsNull())
201             anAISPrs = new ModuleBase_ResultPrs(aResult);
202           else {
203             Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
204             if (!aShapePrs.IsNull())
205               ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
206           }
207           anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
208           //anAIS->createShape(aShapePtr);
209           isShading = true;
210         }
211 #ifdef DEBUG_COMPOSILID_DISPLAY
212         } // close else
213 #endif
214       }
215     }
216     if (anAIS)
217       aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
218   }
219   return aDisplayed;
220 }
221
222 //**************************************************************
223 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
224 {
225   Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
226   if (!aShapePrs.IsNull()) {
227     TopoDS_Shape aShape = aShapePrs->Shape();
228     if (aShape.IsNull())
229       return false;
230     TopAbs_ShapeEnum aType = aShape.ShapeType();
231     if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
232       return false;
233     else {
234       // Check that the presentation is not a sketch
235       return theModule->canBeShaded(theAIS);
236     }
237   }
238   return false;
239 }
240
241 //**************************************************************
242 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
243                              bool isShading, bool theUpdateViewer)
244 {
245   bool aDisplayed = false;
246
247   Handle(AIS_InteractiveContext) aContext = AISContext();
248   if (aContext.IsNull())
249     return aDisplayed;
250
251   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
252   if (!anAISIO.IsNull()) {
253     appendResultObject(theObject, theAIS);
254
255     bool isCustomized = customizeObject(theObject);
256
257     int aDispMode = isShading? Shading : Wireframe;
258     if (isShading)
259       anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
260     anAISIO->SetDisplayMode(aDispMode);
261     aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
262     #ifdef TINSPECTOR
263     if (getCallBack()) getCallBack()->Display(anAISIO);
264     #endif
265     aDisplayed = true;
266
267     emit objectDisplayed(theObject, theAIS);
268     selectionActivate()->activate(anAISIO, theUpdateViewer);
269   }
270   if (theUpdateViewer)
271     updateViewer();
272
273   return aDisplayed;
274 }
275
276 //**************************************************************
277 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
278 {
279   bool aErased = false;
280   if (!isVisible(theObject))
281     return aErased;
282
283   Handle(AIS_InteractiveContext) aContext = AISContext();
284   if (aContext.IsNull())
285     return aErased;
286
287   AISObjectPtr anObject = myResult2AISObjectMap[theObject];
288   if (anObject) {
289     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
290     if (!anAIS.IsNull()) {
291       emit beforeObjectErase(theObject, anObject);
292       aContext->Remove(anAIS, false/*update viewer*/);
293       #ifdef TINSPECTOR
294       if (getCallBack()) getCallBack()->Remove(anAIS);
295       #endif
296       aErased = true;
297     }
298   }
299   myResult2AISObjectMap.remove(theObject);
300
301 #ifdef DEBUG_DISPLAY
302   std::ostringstream aPtrStr;
303   aPtrStr << theObject.get();
304   qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
305   qDebug(getResult2AISObjectMapInfo().c_str());
306 #endif
307
308   if (theUpdateViewer)
309     updateViewer();
310
311   return aErased;
312 }
313
314 //**************************************************************
315 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
316 {
317   bool aRedisplayed = false;
318   if (!isVisible(theObject))
319     return aRedisplayed;
320
321   AISObjectPtr aAISObj = getAISObject(theObject);
322   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
323
324   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
325   if (aPrs) {
326     AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
327     if (!aAIS_Obj) {
328       aRedisplayed = erase(theObject, theUpdateViewer);
329       return aRedisplayed;
330     }
331     if (aAIS_Obj != aAISObj) {
332       appendResultObject(theObject, aAIS_Obj);
333     }
334     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
335   }
336
337   Handle(AIS_InteractiveContext) aContext = AISContext();
338   if (!aContext.IsNull() && !aAISIO.IsNull()) {
339     // Check that the visualized shape is the same and the redisplay is not necessary
340     // Redisplay of AIS object leads to this object selection compute and the selection
341     // in the browser is lost
342     // this check is not necessary anymore because the selection store/restore is realized
343     // before and after the values modification.
344     // Moreother, this check avoids customize and redisplay presentation if the presentable
345     // parameter is changed.
346     bool isEqualShapes = false;
347     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
348     if (aResult.get() != NULL) {
349       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
350       if (!aShapePrs.IsNull()) {
351         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
352         if (aShapePtr.get()) {
353           const TopoDS_Shape& aOldShape = aShapePrs->Shape();
354           if (!aOldShape.IsNull())
355             isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
356         }
357       }
358     }
359     // Customization of presentation
360     bool isCustomized = customizeObject(theObject);
361     #ifdef DEBUG_FEATURE_REDISPLAY
362       qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
363         arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
364         .arg(isCustomized).toStdString().c_str());
365     #endif
366     if (!isEqualShapes || isCustomized) {
367       /// if shapes are equal and presentation are customized, selection should be restored
368       bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
369       if (aNeedToRestoreSelection)
370         myWorkshop->module()->storeSelection();
371
372 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
373       myWorkshop->selector()->deselectPresentation(aAISIO);
374 #endif
375       aContext->Redisplay(aAISIO, false);
376
377       #ifdef TINSPECTOR
378       if (getCallBack()) getCallBack()->Redisplay(aAISIO);
379       #endif
380
381       if (aNeedToRestoreSelection)
382         myWorkshop->module()->restoreSelection();
383
384       aRedisplayed = true;
385       #ifdef DEBUG_FEATURE_REDISPLAY
386         qDebug("  Redisplay happens");
387       #endif
388       if (theUpdateViewer)
389         updateViewer();
390     }
391   }
392   return aRedisplayed;
393 }
394
395 //**************************************************************
396 void XGUI_Displayer::redisplayObjects()
397 {
398   // redisplay objects visualized in the viewer
399   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
400   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
401   QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
402   QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
403   for (; anIt != aLast; anIt++) {
404     aECreator->sendUpdated(*anIt, EVENT_DISP);
405   }
406   Events_Loop::loop()->flush(EVENT_DISP);
407 }
408
409 //**************************************************************
410 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
411                                        const bool theUpdateViewer)
412 {
413   //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
414   //if (!aTrihedron.IsNull())
415   //  deactivateAIS(aTrihedron);
416
417   QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
418   for (; anIt != aLast; anIt++) {
419     selectionActivate()->deactivate(*anIt, false);
420   }
421   //VSV It seems that there is no necessity to update viewer on deactivation
422   //if (theUpdateViewer)
423   //  updateViewer();
424 }
425
426 //**************************************************************
427 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
428 {
429   bool aVisible = false;
430   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
431   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
432   if (aPrs.get() || aResult.get()) {
433     aVisible = theDisplayer->isVisible(theObject);
434     // compsolid is not visualized in the viewer,
435     // but should have presentation when all sub solids are
436     // visible. It is useful for highlight presentation where compsolid shape is selectable
437     if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
438       ResultCompSolidPtr aCompsolidResult =
439         std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
440       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
441         bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
442         for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
443           anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
444         }
445         aVisible = anAllSubsVisible;
446       }
447     }
448   }
449   // it is possible that feature is presentable and has results, so we should check visibility
450   // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
451   if (!aVisible) {
452     // check if all results of the feature are visible
453     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
454     std::list<ResultPtr> aResults;
455     ModelAPI_Tools::allResults(aFeature, aResults);
456     std::list<ResultPtr>::const_iterator aIt;
457     aVisible = !aResults.empty();
458     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
459       aVisible = aVisible && theDisplayer->isVisible(*aIt);
460     }
461   }
462   return aVisible;
463 }
464
465 //**************************************************************
466 void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrsPtr>& theValues,
467                                  bool theUpdateViewer)
468 {
469   Handle(AIS_InteractiveContext) aContext = AISContext();
470   if (aContext.IsNull())
471     return;
472   aContext->UnhilightSelected(false);
473   aContext->ClearSelected(false);
474   #ifdef TINSPECTOR
475   if (getCallBack()) getCallBack()->ClearSelected();
476   #endif
477   NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
478     aShapesToBeSelected;
479
480   foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
481     const GeomShapePtr& aGeomShape = aPrs->shape();
482     if (aGeomShape.get() && !aGeomShape->isNull()) {
483       const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
484 #ifdef DEBUG_OCCT_SHAPE_SELECTION
485       // problem 1: performance
486       // problem 2: IO is not specified, so the first found owner is selected, as a result
487       // it might belong to another result
488       aContext->AddOrRemoveSelected(aShape, false);
489       #ifdef TINSPECTOR
490       if (getCallBack()) getCallBack()->AddOrRemoveSelected(aShape);
491       #endif
492 #else
493       NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
494       if (aShapesToBeSelected.IsBound(aShape))
495         aPresentations = aShapesToBeSelected.Find(aShape);
496       ObjectPtr anObject = aPrs->object();
497       getPresentations(anObject, aPresentations);
498
499       aShapesToBeSelected.Bind(aShape, aPresentations);
500 #endif
501     } else {
502       ObjectPtr anObject = aPrs->object();
503       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
504       if (aResult.get() && isVisible(aResult)) {
505         AISObjectPtr anObj = myResult2AISObjectMap[aResult];
506         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
507         if (!anAIS.IsNull()) {
508           // The methods are replaced in order to provide multi-selection, e.g. restore selection
509           // by activating multi selector widget. It also gives an advantage that the multi
510           // selection in OB gives multi-selection in the viewer
511           //aContext->SetSelected(anAIS, false);
512           // The selection in the context was cleared, so the method sets the objects are selected
513           aContext->AddOrRemoveSelected(anAIS, false);
514           #ifdef TINSPECTOR
515           if (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
516           #endif
517         }
518       }
519     }
520   }
521   if (!aShapesToBeSelected.IsEmpty())
522     XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
523
524   if (theUpdateViewer)
525     updateViewer();
526 }
527
528 //**************************************************************
529 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
530 {
531   Handle(AIS_InteractiveContext) aContext = AISContext();
532   if (!aContext.IsNull()) {
533     aContext->UnhilightSelected(false);//UnhilightCurrents(false);
534     aContext->ClearSelected(theUpdateViewer);
535     #ifdef TINSPECTOR
536     if (getCallBack()) getCallBack()->ClearSelected();
537     #endif
538   }
539 }
540
541 //**************************************************************
542 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
543 {
544   bool aErased = false;
545   Handle(AIS_InteractiveContext) aContext = AISContext();
546   if (!aContext.IsNull()) {
547     foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
548       AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
549       // erase an object
550       Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
551       if (!anIO.IsNull()) {
552         emit beforeObjectErase(aObj, aAISObj);
553         aContext->Remove(anIO, false/*update viewer*/);
554         #ifdef TINSPECTOR
555         if (getCallBack()) getCallBack()->Remove(anIO);
556         #endif
557         aErased = true;
558       }
559     }
560     if (theUpdateViewer)
561       updateViewer();
562   }
563   myResult2AISObjectMap.clear();
564 #ifdef DEBUG_DISPLAY
565   qDebug("eraseAll");
566   qDebug(getResult2AISObjectMapInfo().c_str());
567 #endif
568   return aErased;
569 }
570
571
572 //**************************************************************
573 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
574 {
575   AISObjectPtr anIO;
576   if (myResult2AISObjectMap.contains(theObject))
577     anIO = myResult2AISObjectMap[theObject];
578   return anIO;
579 }
580
581 //**************************************************************
582 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
583 {
584   Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
585   return getObject(aRefAIS);
586 }
587
588 //**************************************************************
589 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
590 {
591   ObjectPtr anObject;
592   foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
593     AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
594     Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
595     if (anAIS == theIO)
596       anObject = anObj;
597     if (anObject.get())
598       break;
599   }
600   if (!anObject.get()) {
601     std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
602     if (!theIO.IsNull()) {
603       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
604     }
605     anObject = myWorkshop->module()->findPresentedObject(anAISObj);
606   }
607   return anObject;
608 }
609
610 //**************************************************************
611 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
612 {
613   bool aWasEnabled = isUpdateEnabled();
614   if (isEnabled)
615     myViewerBlockedRecursiveCount--;
616   else
617     myViewerBlockedRecursiveCount++;
618
619 #ifdef DEBUG_VIEWER_BLOCKED_COUNT
620   std::cout << "myViewerBlockedRecursiveCount = " << myViewerBlockedRecursiveCount << std::endl;
621 #endif
622
623   if (myNeedUpdate && isUpdateEnabled()) {
624     updateViewer();
625     myNeedUpdate = false;
626   }
627   return aWasEnabled;
628 }
629
630 //**************************************************************
631 bool XGUI_Displayer::isUpdateEnabled() const
632 {
633   return myViewerBlockedRecursiveCount == 0;
634 }
635
636 //**************************************************************
637 void XGUI_Displayer::updateViewer() const
638 {
639   Handle(AIS_InteractiveContext) aContext = AISContext();
640
641 #ifdef DEBUG_VIEWER_BLOCKED_COUNT
642   std::cout << "updateViewer: " << (myViewerBlockedRecursiveCount == 0 ? " done" : " later") << std::endl;
643 #endif
644
645   if (!aContext.IsNull() && isUpdateEnabled()) {
646     //myWorkshop->viewer()->Zfitall();
647     aContext->UpdateCurrentViewer();
648   } else {
649     myNeedUpdate = true;
650   }
651 }
652
653 //**************************************************************
654 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
655 {
656   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
657   if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
658     XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
659     aDisplayer->myIsFirstAISContextUse = false;
660     if (!myWorkshop->selectionActivate()->isTrihedronActive())
661       selectionActivate()->deactivateTrihedron(true);
662     aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
663     aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
664   }
665   return aContext;
666 }
667
668 //**************************************************************
669 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
670 {
671   Handle(AIS_InteractiveContext) aContext = AISContext();
672   if (!aContext.IsNull() && myAndFilter.IsNull()) {
673     myAndFilter = new SelectMgr_AndFilter();
674     aContext->AddFilter(myAndFilter);
675   }
676   return myAndFilter;
677 }
678
679 //**************************************************************
680 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
681                                 const Standard_Integer theDisplayMode, bool theUpdateViewer)
682 {
683   bool aDisplayed = false;
684   Handle(AIS_InteractiveContext) aContext = AISContext();
685   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
686   if (!aContext.IsNull() && !anAISIO.IsNull()) {
687     aContext->Display(anAISIO, theDisplayMode, 0, false/*update viewer*/, true, AIS_DS_Displayed);
688     #ifdef TINSPECTOR
689     if (getCallBack()) getCallBack()->Display(anAISIO);
690     #endif
691     aDisplayed = true;
692     aContext->Deactivate(anAISIO);
693     #ifdef TINSPECTOR
694     if (getCallBack()) getCallBack()->Deactivate(anAISIO);
695     #endif
696     aContext->Load(anAISIO);
697     #ifdef TINSPECTOR
698     if (getCallBack()) getCallBack()->Load(anAISIO);
699     #endif
700     if (toActivateInSelectionModes)
701       myWorkshop->selectionActivate()->activateOnDisplay(anAISIO, theUpdateViewer);
702
703     if (theUpdateViewer)
704       updateViewer();
705   }
706   return aDisplayed;
707 }
708
709 //**************************************************************
710 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
711 {
712   bool aErased = false;
713   Handle(AIS_InteractiveContext) aContext = AISContext();
714   if (!aContext.IsNull()) {
715     Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
716     if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
717       aContext->Remove(anAISIO, false/*update viewer*/);
718       #ifdef TINSPECTOR
719       if (getCallBack()) getCallBack()->Remove(anAISIO);
720       #endif
721       aErased = true;
722     }
723   }
724   if (aErased && theUpdateViewer)
725     updateViewer();
726   return aErased;
727 }
728
729 //**************************************************************
730 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
731 {
732   if (theMode == NoMode)
733     return;
734
735   Handle(AIS_InteractiveContext) aContext = AISContext();
736   if (aContext.IsNull())
737     return;
738
739   AISObjectPtr aAISObj = getAISObject(theObject);
740   if (!aAISObj)
741     return;
742
743   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
744   aContext->SetDisplayMode(aAISIO, theMode, false);
745   // Redisplay in order to update new mode because it could be not computed before
746   if (theUpdateViewer)
747     updateViewer();
748 }
749
750 //**************************************************************
751 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
752 {
753   Handle(AIS_InteractiveContext) aContext = AISContext();
754   if (aContext.IsNull())
755     return NoMode;
756
757   AISObjectPtr aAISObj = getAISObject(theObject);
758   if (!aAISObj)
759     return NoMode;
760
761   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
762   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
763 }
764
765 //**************************************************************
766 void XGUI_Displayer::deactivateSelectionFilters(const bool theAddFilterOnly)
767 {
768   Handle(AIS_InteractiveContext) aContext = AISContext();
769   if (!myAndFilter.IsNull()) {
770     bool aFound = false;
771     if (!aContext.IsNull()) {
772       const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
773       SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
774       for (; anIt.More() && !aFound; anIt.Next()) {
775         Handle(SelectMgr_Filter) aFilter = anIt.Value();
776         aFound = aFilter == myAndFilter;
777       }
778       if (aFound)
779         aContext->RemoveFilter(myAndFilter);
780     }
781     myAndFilter.Nullify();
782   }
783 }
784
785 //**************************************************************
786 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
787 {
788   Handle(AIS_InteractiveContext) aContext = AISContext();
789   if (aContext.IsNull() || hasSelectionFilter(theFilter))
790     return;
791
792   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
793   if (!aCompositeFilter.IsNull()) {
794     aCompositeFilter->Add(theFilter);
795 #ifdef DEBUG_SELECTION_FILTERS
796     int aCount = aCompositeFilter->StoredFilters().Extent();
797     qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
798 #endif
799   }
800 }
801
802 //**************************************************************
803 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
804 {
805   Handle(AIS_InteractiveContext) aContext = AISContext();
806   if (aContext.IsNull())
807     return;
808
809   Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
810   if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
811     aCompositeFilter->Remove(theFilter);
812 #ifdef DEBUG_SELECTION_FILTERS
813     int aCount = aCompositeFilter->StoredFilters().Extent();
814     qDebug(QString("removeSelectionFilter: filters.count() = %1")
815       .arg(aCount).toStdString().c_str());
816 #endif
817   }
818 }
819
820 //**************************************************************
821 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
822 {
823   bool aFilterFound = false;
824
825   Handle(AIS_InteractiveContext) aContext = AISContext();
826   if (aContext.IsNull())
827     return aFilterFound;
828   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
829   SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
830   for (; aIt.More() && !aFilterFound; aIt.Next()) {
831     if (theFilter.get() == aIt.Value().get())
832       aFilterFound = true;
833   }
834   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
835   if (!aCompositeFilter.IsNull()) {
836     const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
837     for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
838       if (theFilter.get() == aIt.Value().get())
839         aFilterFound = true;
840     }
841   }
842   return aFilterFound;
843 }
844
845 //**************************************************************
846 void XGUI_Displayer::removeFilters()
847 {
848   Handle(AIS_InteractiveContext) aContext = AISContext();
849   if (aContext.IsNull())
850     return;
851
852   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
853   if (!aCompositeFilter.IsNull())
854     aCompositeFilter->Clear();
855 }
856
857 //**************************************************************
858 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
859 {
860   QObjectPtrList aDispList = myResult2AISObjectMap.keys();
861   foreach(ObjectPtr aObj, aDispList) {
862     if (!theList.contains(aObj))
863       erase(aObj, false);
864   }
865   foreach(ObjectPtr aObj, theList) {
866     if (!isVisible(aObj))
867       display(aObj, false);
868   }
869   updateViewer();
870 }
871
872 //**************************************************************
873 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
874 {
875   if (!isVisible(theObject))
876     return false;
877
878   AISObjectPtr aAISObj = getAISObject(theObject);
879   if (aAISObj.get() == NULL)
880     return false;
881
882   Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
883   return ::canBeShaded(anAIS, myWorkshop->module());
884 }
885
886 //**************************************************************
887 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
888 {
889   AISObjectPtr anAISObj = getAISObject(theObject);
890   // correct the result's color it it has the attribute
891   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
892
893   // Customization of presentation
894   GeomCustomPrsPtr aCustomPrs;
895   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
896   if (aFeature.get() != NULL) {
897     GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
898     if (aCustPrs.get() != NULL)
899       aCustomPrs = aCustPrs;
900   }
901   if (aCustomPrs.get() == NULL) {
902     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
903     // we ignore presentable not customized objects
904     if (aPrs.get() == NULL)
905       aCustomPrs = myCustomPrs;
906   }
907   bool isCustomized = aCustomPrs.get() &&
908                       aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
909   isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
910                  || isCustomized;
911
912   // update presentation state if faces panel is active
913   if (anAISObj.get() && myWorkshop->facesPanel())
914     isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized;
915
916   return isCustomized;
917 }
918
919 //**************************************************************
920 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
921                                       const QColor& theColor,
922                                       bool theUpdateViewer)
923 {
924   if (!isVisible(theObject))
925     return Qt::black;
926
927   AISObjectPtr anAISObj = getAISObject(theObject);
928   int aR, aG, aB;
929   anAISObj->getColor(aR, aG, aB);
930   anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
931   if (theUpdateViewer)
932     updateViewer();
933   return QColor(aR, aG, aB);
934 }
935
936 //**************************************************************
937 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
938 {
939   myResult2AISObjectMap[theObject] = theAIS;
940
941 #ifdef DEBUG_DISPLAY
942   std::ostringstream aPtrStr;
943   aPtrStr << theObject.get();
944   qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
945   qDebug(getResult2AISObjectMapInfo().c_str());
946 #endif
947 }
948
949 #ifdef _DEBUG
950 //**************************************************************
951 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
952 {
953   QStringList aContent;
954   foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
955     AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
956     std::ostringstream aPtrStr;
957     aPtrStr << "aObj = " << aObj.get() << ":";
958     aPtrStr << "anAIS = " << aAISObj.get() << ":";
959     aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
960
961     aContent.append(aPtrStr.str().c_str());
962   }
963   return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
964                                             arg(aContent.join("\n")).toStdString().c_str();
965 }
966 #endif
967
968 //**************************************************************
969 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
970                                   NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
971 {
972   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
973   if (aResult.get()) {
974     AISObjectPtr aAISObj = getAISObject(aResult);
975     if (aAISObj.get() == NULL) {
976       // if result is a result of a composite feature, it is visualized by visualization of
977       // composite children, so we should get one of this presentations
978       ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
979       if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
980         aAISObj = getAISObject(aCompSolid->subResult(0));
981       }
982     }
983     if (aAISObj.get() != NULL) {
984       Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
985       if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
986         thePresentations.Add(anAIS);
987     }
988   }
989   else {
990     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
991     // find presentation of the feature
992     AISObjectPtr aAISObj = getAISObject(aFeature);
993     if (aAISObj.get() != NULL) {
994       Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
995       if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
996         thePresentations.Add(anAIS);
997     }
998     // find presentations of the feature results
999     std::list<ResultPtr> aResults;
1000     ModelAPI_Tools::allResults(aFeature, aResults);
1001     std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1002     for (; anIt != aLast; ++anIt) {
1003       AISObjectPtr aAISObj = getAISObject(*anIt);
1004       if (aAISObj.get() != NULL) {
1005         Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1006         if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1007           thePresentations.Add(anAIS);
1008       }
1009     }
1010   }
1011 }
1012
1013 //**************************************************************
1014 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1015 {
1016   Handle(AIS_InteractiveContext) aContext = AISContext();
1017   if (aContext.IsNull())
1018     return;
1019
1020   Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1021
1022   XGUI_SelectionActivate* aSelectionActive = selectionActivate();
1023   if (theToDisplay) {
1024     if (!aContext->IsDisplayed(aTrihedron))
1025       aContext->Display(aTrihedron,
1026                         0 /*wireframe*/,
1027                         -1 /* selection mode */,
1028                         Standard_True /* update viewer*/,
1029                         Standard_False /* allow decomposition */,
1030                         AIS_DS_Displayed /* xdisplay status */);
1031     #ifdef TINSPECTOR
1032     if (getCallBack()) getCallBack()->Display(aTrihedron);
1033     #endif
1034
1035     if (!aSelectionActive->isTrihedronActive())
1036       aSelectionActive->deactivateTrihedron(false);
1037     else
1038       aSelectionActive->activate(aTrihedron, false);
1039   } else {
1040     aSelectionActive->deactivateTrihedron(false);
1041
1042     aContext->Erase(aTrihedron, Standard_True);
1043     #ifdef TINSPECTOR
1044     if (getCallBack()) getCallBack()->Remove(aTrihedron);
1045     #endif
1046   }
1047
1048   updateViewer();
1049 }
1050
1051 //**************************************************************
1052 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1053                            const NCollection_DataMap<TopoDS_Shape,
1054                            NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1055 {
1056   NCollection_Map<Handle(AIS_InteractiveObject)> aCompsolidPresentations;
1057   NCollection_Map<Handle(AIS_InteractiveObject)> aSelectedPresentations;
1058
1059   NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1060   theContext->MainSelector()->ActiveOwners(anActiveOwners);
1061   NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1062   Handle(SelectMgr_EntityOwner) anOwner;
1063
1064   /// It is very important to check that the owner is processed only once and has a map of
1065   /// processed owners because SetSelected works as a switch.
1066   /// If count of calls setSelectec is even, the object stays in the previous state
1067   /// (selected, deselected)
1068   /// OCCT: to write about the problem that active owners method returns one owner several times
1069   QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1070   for (; anOwnersIt.More(); anOwnersIt.Next()) {
1071     anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1072     if (aSelectedIds.contains((long)anOwner.get()))
1073       continue;
1074     aSelectedIds.append((long)anOwner.get());
1075
1076     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1077     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1078       const TopoDS_Shape& aShape = BROwnr->Shape();
1079       if (aShape.IsNull())
1080         continue;
1081
1082       Handle(ModuleBase_BRepOwner) aCustomOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
1083
1084       NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)> >
1085                                              ::Iterator aShapeIt(theShapesToBeSelected);
1086       for (; aShapeIt.More(); aShapeIt.Next()) {
1087         const TopoDS_Shape& aParameterShape = aShapeIt.Key();
1088         // isSame should be used here as it does not check orientation of shapes
1089         // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
1090         // different for Edges shapes in model shape and owner even if this is the same shape
1091         if (aParameterShape.IsSame(aShape)) {
1092           Handle(AIS_InteractiveObject) anOwnerPresentation =
1093                             Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1094           NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1095                                       theShapesToBeSelected.Find(aParameterShape);
1096           if (aPresentations.Contains(anOwnerPresentation)) {
1097             theContext->AddOrRemoveSelected(anOwner, Standard_False);
1098             anOwner->SetSelected (Standard_True);
1099             // collect selected presentations to do not select them if compsolid is selected
1100             if (!aSelectedPresentations.Contains(anOwnerPresentation))
1101               aSelectedPresentations.Add(anOwnerPresentation);
1102           }
1103         }
1104         else if (!aCustomOwner.IsNull()) { // CompSolid processing #2219
1105           // shape of owner is compound, but shape to be selected is compsolid, so
1106           // we need to compare shape to AIS presentation of owner(rule of the owner creation)
1107           Handle(AIS_Shape) anOwnerPresentation =
1108                             Handle(AIS_Shape)::DownCast(anOwner->Selectable());
1109           const TopoDS_Shape& aPresentationShape = anOwnerPresentation->Shape();
1110           if (aParameterShape.IsSame(anOwnerPresentation->Shape()) &&
1111               !aCompsolidPresentations.Contains(anOwnerPresentation))
1112             aCompsolidPresentations.Add(anOwnerPresentation);
1113         }
1114       }
1115     }
1116   }
1117   // select CompSolid presentations if their owners was not selected yet
1118   NCollection_Map<Handle(AIS_InteractiveObject)>::Iterator anIt (aCompsolidPresentations);
1119   for (; anIt.More(); anIt.Next()) {
1120     if (aSelectedPresentations.Contains(anIt.Value()))
1121       continue;
1122     theContext->AddOrRemoveSelected(anIt.Value(), Standard_False);
1123   }
1124 }
1125
1126 //**************************************************************
1127 XGUI_SelectionActivate* XGUI_Displayer::selectionActivate() const
1128 {
1129   return myWorkshop->selectionActivate();
1130 }