Salome HOME
SketchPoint feature appeared in origin by restart. Correction: the viewer update...
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_Displayer.cpp
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include "XGUI_Displayer.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_CustomPrs.h"
13
14 #ifndef HAVE_SALOME
15 #include <AppElements_Viewer.h>
16 #endif
17
18 #include <ModelAPI_Document.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_Tools.h>
22 #include <ModelAPI_AttributeIntArray.h>
23 #include <ModelAPI_ResultCompSolid.h>
24
25 #include <ModuleBase_ResultPrs.h>
26 #include <ModuleBase_Tools.h>
27 #include <ModuleBase_IModule.h>
28
29 #include <GeomAPI_Shape.h>
30 #include <GeomAPI_IPresentable.h>
31 #include <GeomAPI_ICustomPrs.h>
32
33 #include <AIS_InteractiveContext.hxx>
34 #include <AIS_LocalContext.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_ListIteratorOfListOfInteractive.hxx>
37 #include <AIS_DimensionSelectionMode.hxx>
38 #include <AIS_Shape.hxx>
39 #include <AIS_Dimension.hxx>
40 #include <AIS_Trihedron.hxx>
41 #include <AIS_Axis.hxx>
42 #include <AIS_Plane.hxx>
43 #include <AIS_Point.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <SelectMgr_ListOfFilter.hxx>
46 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
47 #include <Prs3d_Drawer.hxx>
48 #include <Prs3d_IsoAspect.hxx>
49 #include <SelectMgr_SelectionManager.hxx>
50
51 #include <StdSelect_ViewerSelector3d.hxx>
52
53 #include <TColStd_MapOfTransient.hxx>
54 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
55
56 #include <Events_Loop.h>
57 #include <ModelAPI_Events.h>
58
59 #include <set>
60
61 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;  ///< defines the local context mouse selection sensitivity
62
63 //#define DEBUG_ACTIVATE_OBJECTS
64 //#define DEBUG_DEACTIVATE
65 //#define DEBUG_ACTIVATE_AIS
66 //#define DEBUG_DEACTIVATE_AIS
67
68 //#define DEBUG_DISPLAY
69 //#define DEBUG_FEATURE_REDISPLAY
70 //#define DEBUG_SELECTION_FILTERS
71
72 //#define DEBUG_COMPOSILID_DISPLAY
73 // Workaround for bug #25637
74 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
75 {
76   // Get from null point
77   theAIS->DisplayedObjects(theList, true);
78   if (theAIS->HasOpenedContext()) {
79     // get from local context
80     const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
81     TColStd_MapOfTransient aMap;
82     int NbDisp = aLC->DisplayedObjects(aMap);
83     TColStd_MapIteratorOfMapOfTransient aIt(aMap);
84
85     Handle(AIS_InteractiveObject) curIO;
86     Handle(Standard_Transient) Tr;
87     for(; aIt.More(); aIt.Next()){
88       Tr = aIt.Key();
89       curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
90       theList.Append(curIO);
91     }
92   }
93 }
94
95 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
96 {
97   QStringList anInfo;
98   QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
99   for (; anIt != aLast; anIt++) {
100     anInfo.append(QString::number(*anIt));
101   }
102   return anInfo.join(theSeparator);
103 }
104
105 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
106   : myWorkshop(theWorkshop), myNeedUpdate(false),
107   myIsTrihedronActive(false), myViewerBlockedRecursiveCount(0)
108 {
109   myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
110 }
111
112 XGUI_Displayer::~XGUI_Displayer()
113 {
114 }
115
116 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
117 {
118   return myResult2AISObjectMap.contains(theObject);
119 }
120
121 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
122 {
123   bool aDisplayed = false;
124   if (isVisible(theObject)) {
125 #ifdef DEBUG_COMPOSILID_DISPLAY
126     ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
127     if (aCompsolidResult.get()) {
128       for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
129         ResultPtr aSubResult = aCompsolidResult->subResult(i);
130         if (aSubResult.get())
131           redisplay(aSubResult, false);
132       }
133       if (theUpdateViewer)
134         updateViewer();
135     }
136     else
137 #endif
138     aDisplayed = redisplay(theObject, theUpdateViewer);
139   } else {
140     AISObjectPtr anAIS;
141     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
142     bool isShading = false;
143     if (aPrs.get() != NULL) {
144       anAIS = aPrs->getAISObject(anAIS);
145     } else {
146       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
147       if (aResult.get() != NULL) {
148 #ifdef DEBUG_COMPOSILID_DISPLAY
149         ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
150         if (aCompsolidResult.get()) {
151           for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
152             ResultPtr aSubResult = aCompsolidResult->subResult(i);
153             if (aSubResult.get())
154               display(aSubResult, false);
155           }
156           if (theUpdateViewer)
157             updateViewer();
158         }
159         else {
160 #endif
161         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
162         if (aShapePtr.get() != NULL) {
163           anAIS = AISObjectPtr(new GeomAPI_AISObject());
164           anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
165           //anAIS->createShape(aShapePtr);
166           isShading = true;
167         }
168 #ifdef DEBUG_COMPOSILID_DISPLAY
169         } // close else
170 #endif
171       }
172     }
173     if (anAIS)
174       aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
175   }
176   return aDisplayed;
177 }
178
179 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
180 {
181   Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
182   if (!aShapePrs.IsNull()) {
183     TopoDS_Shape aShape = aShapePrs->Shape();
184     if (aShape.IsNull())
185       return false;
186     TopAbs_ShapeEnum aType = aShape.ShapeType();
187     if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
188       return false;
189     else {
190       // Check that the presentation is not a sketch
191       Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
192       if (!aPrs.IsNull()) 
193         return !aPrs->isSketchMode();
194       return true;
195     }
196   }
197   return false;
198 }
199
200 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, 
201                              bool isShading, bool theUpdateViewer)
202 {
203   bool aDisplayed = false;
204
205   Handle(AIS_InteractiveContext) aContext = AISContext();
206   if (aContext.IsNull())
207     return aDisplayed;
208
209   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
210   if (!anAISIO.IsNull()) {
211     appendResultObject(theObject, theAIS);
212
213     bool isCustomized = customizeObject(theObject);
214
215     int aDispMode = isShading? Shading : Wireframe;
216     if (isShading)
217       anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
218     anAISIO->SetDisplayMode(aDispMode);
219     aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed); 
220     aDisplayed = true;
221
222     emit objectDisplayed(theObject, theAIS);
223     activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
224     // the fix from VPA for more suitable selection of sketcher lines
225     if(anAISIO->Width() > 1) {
226       for(int aModeIdx = 0; aModeIdx < myActiveSelectionModes.length(); ++aModeIdx) {
227         int aMode = myActiveSelectionModes.value(aModeIdx);
228         double aPrecision = (aMode == getSelectionMode(TopAbs_VERTEX))? 20 : 
229                                                     (anAISIO->Width() + 2);
230         aContext->SetSelectionSensitivity(anAISIO, aMode, aPrecision);
231       }
232     }
233   } 
234   if (theUpdateViewer)
235     updateViewer();
236
237   return aDisplayed;
238 }
239
240 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
241 {
242   bool aErased = false;
243   if (!isVisible(theObject))
244     return aErased;
245
246   Handle(AIS_InteractiveContext) aContext = AISContext();
247   if (aContext.IsNull())
248     return aErased;
249
250   AISObjectPtr anObject = myResult2AISObjectMap[theObject];
251   if (anObject) {
252     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
253     if (!anAIS.IsNull()) {
254       emit beforeObjectErase(theObject, anObject);
255       aContext->Remove(anAIS);
256       aErased = true;
257     }
258   }
259   myResult2AISObjectMap.remove(theObject);
260
261 #ifdef DEBUG_DISPLAY
262   std::ostringstream aPtrStr;
263   aPtrStr << theObject.get();
264   qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
265   qDebug(getResult2AISObjectMapInfo().c_str());
266 #endif
267
268   if (theUpdateViewer)
269     updateViewer();
270
271   return aErased;
272 }
273
274 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
275 {
276   bool aRedisplayed = false;
277   if (!isVisible(theObject))
278     return aRedisplayed;
279
280   AISObjectPtr aAISObj = getAISObject(theObject);
281   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
282
283   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
284   if (aPrs) {
285     AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
286     if (!aAIS_Obj) {
287       aRedisplayed = erase(theObject, theUpdateViewer);
288       return aRedisplayed;
289     }
290     if (aAIS_Obj != aAISObj) {
291       appendResultObject(theObject, aAIS_Obj);
292     }
293     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
294   }
295
296   Handle(AIS_InteractiveContext) aContext = AISContext();
297   if (!aContext.IsNull() && !aAISIO.IsNull()) {
298     // Check that the visualized shape is the same and the redisplay is not necessary
299     // Redisplay of AIS object leads to this object selection compute and the selection 
300     // in the browser is lost
301     // this check is not necessary anymore because the selection store/restore is realized
302     // before and after the values modification.
303     // Moreother, this check avoids customize and redisplay presentation if the presentable
304     // parameter is changed.
305     bool isEqualShapes = false;
306     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
307     if (aResult.get() != NULL) {
308       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
309       if (!aShapePrs.IsNull()) {
310         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
311         if (aShapePtr.get()) {
312           const TopoDS_Shape& aOldShape = aShapePrs->Shape();
313           if (!aOldShape.IsNull())
314             isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
315         }
316       }
317     }
318     // Customization of presentation
319     bool isCustomized = customizeObject(theObject);
320     #ifdef DEBUG_FEATURE_REDISPLAY
321       qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
322         arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
323     #endif
324     if (!isEqualShapes || isCustomized) {
325       aContext->Redisplay(aAISIO, false);
326       aRedisplayed = true;
327       #ifdef DEBUG_FEATURE_REDISPLAY
328         qDebug("  Redisplay happens");
329       #endif
330       if (theUpdateViewer)
331         updateViewer();
332     }
333   }
334   return aRedisplayed;
335 }
336
337 void XGUI_Displayer::redisplayObjects()
338 {
339   // redisplay objects visualized in the viewer
340   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
341   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
342   QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
343   QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
344   for (; anIt != aLast; anIt++) {
345     aECreator->sendUpdated(*anIt, EVENT_DISP);
346   }
347   Events_Loop::loop()->flush(EVENT_DISP);
348 }
349
350 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
351 {
352 #ifdef DEBUG_DEACTIVATE
353   QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
354   qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
355     arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
356     arg(anInfoStr).
357     toStdString().c_str());
358 #endif
359   Handle(AIS_InteractiveContext) aContext = AISContext();
360   if (!aContext.IsNull() && isVisible(theObject)) {
361     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
362     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
363
364     deactivateAIS(anAIS);
365     // the selection from the previous activation modes should be cleared manually (#26172)
366     aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
367     if (theUpdateViewer)
368       updateViewer();
369   }
370 }
371
372 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
373                                        const bool theUpdateViewer)
374 {
375   //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
376   //if (!aTrihedron.IsNull())
377   //  deactivateAIS(aTrihedron);
378
379   QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
380   for (; anIt != aLast; anIt++) {
381     deactivate(*anIt, false);
382   }
383   //VSV It seems that there is no necessity to update viewer on deactivation
384   //if (theUpdateViewer)
385   //  updateViewer();
386 }
387
388 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
389 {
390   Handle(AIS_InteractiveContext) aContext = AISContext();
391   if (aContext.IsNull() || !isVisible(theObject))
392     return;
393
394   AISObjectPtr aAISObj = getAISObject(theObject);
395
396   if (aAISObj.get() != NULL) {
397     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
398     TColStd_ListOfInteger aTColModes;
399     aContext->ActivatedModes(anAISIO, aTColModes);
400     TColStd_ListIteratorOfListOfInteger itr( aTColModes );
401     for (; itr.More(); itr.Next() ) {
402       theModes.append(itr.Value());
403     }
404   }
405 }
406
407 int XGUI_Displayer::getSelectionMode(int theShapeType)
408 {
409   return (theShapeType >= TopAbs_SHAPE)? theShapeType : 
410     AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
411 }
412
413 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
414                                      const bool theUpdateViewer)
415 {
416   // Convert shape types to selection types
417   QIntList aModes;
418   foreach(int aType, theModes) {
419     aModes.append(getSelectionMode(aType));
420   }
421
422 #ifdef DEBUG_ACTIVATE_OBJECTS
423   QStringList anInfo;
424   QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
425   for (; anIt != aLast; ++anIt) {
426     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
427   }
428   QString anInfoStr = anInfo.join(", ");
429
430   qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
431     arg(aModes.size()).arg(qIntListInfo(aModes)).
432     arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
433     arg(anInfoStr).
434     toStdString().c_str());
435 #endif
436   // In order to avoid doblications of selection modes
437   QIntList aNewModes;
438   foreach (int aMode, aModes) {
439     if (!aNewModes.contains(aMode))
440       aNewModes.append(aMode);
441   }
442   myActiveSelectionModes = aNewModes;
443   Handle(AIS_InteractiveContext) aContext = AISContext();
444   // Open local context if there is no one
445   if (aContext.IsNull() || !aContext->HasOpenedContext()) 
446     return;
447
448   //aContext->UseDisplayedObjects();
449   //myUseExternalObjects = true;
450
451   Handle(AIS_InteractiveObject) anAISIO;
452   AIS_ListOfInteractive aPrsList;
453   //if (aObjList.isEmpty())
454   //  return;
455   //else {
456   foreach(ObjectPtr aObj, theObjList) {
457     if (myResult2AISObjectMap.contains(aObj))
458       aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
459   }
460   //}
461
462   // Add trihedron because it has to partisipate in selection
463   Handle(AIS_InteractiveObject) aTrihedron;
464   if (isTrihedronActive()) {
465     aTrihedron = getTrihedron();
466     if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
467       aPrsList.Append(aTrihedron);
468   }
469   if (aPrsList.Extent() == 0)
470     return;
471
472   AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
473   bool isActivationChanged = false;
474   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
475     anAISIO = aLIt.Value();
476     if (activate(anAISIO, myActiveSelectionModes, false))
477       isActivationChanged = true;
478   }
479   if (!aTrihedron.IsNull()) {
480     foreach(int aMode, myActiveSelectionModes)
481       aContext->SetSelectionSensitivity(aTrihedron, aMode, 20);
482   }
483   // VSV It seems that there is no necessity to update viewer on activation
484   //if (theUpdateViewer && isActivationChanged)
485   //  updateViewer();
486 }
487
488 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
489 {
490   Handle(AIS_InteractiveContext) aContext = AISContext();
491   if (aContext.IsNull() || !isVisible(theObject))
492     return false;
493     
494   AISObjectPtr anObj = myResult2AISObjectMap[theObject];
495   Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
496
497   TColStd_ListOfInteger aModes;
498   aContext->ActivatedModes(anAIS, aModes);
499   return aModes.Extent() > 0;
500 }
501 void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer)
502 {
503   Handle(AIS_InteractiveContext) aContext = AISContext();
504   if (aContext.IsNull())
505     return;
506   if (aContext->HasOpenedContext()) {
507     aContext->UnhilightSelected(false);
508     aContext->ClearSelected(false);
509     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
510       const TopoDS_Shape& aShape = aPrs.shape();
511       if (!aShape.IsNull()) {
512         aContext->AddOrRemoveSelected(aShape, false);
513       } else {
514         ObjectPtr anObject = aPrs.object();
515         ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
516         if (aResult.get() && isVisible(aResult)) {
517           AISObjectPtr anObj = myResult2AISObjectMap[aResult];
518           Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
519           if (!anAIS.IsNull()) {
520             // The methods are replaced in order to provide multi-selection, e.g. restore selection
521             // by activating multi selector widget. It also gives an advantage that the multi
522             // selection in OB gives multi-selection in the viewer
523             //aContext->SetSelected(anAIS, false);
524             // The selection in the context was cleared, so the method sets the objects are selected
525             aContext->AddOrRemoveSelected(anAIS, false);
526           }
527         }
528       }
529     }
530   } else {
531     aContext->UnhilightCurrents(false);
532     aContext->ClearCurrents(false);
533     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
534       ObjectPtr anObject = aPrs.object();
535       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
536       if (aResult.get() && isVisible(aResult)) {
537         AISObjectPtr anObj = myResult2AISObjectMap[aResult];
538         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
539         if (!anAIS.IsNull())
540           aContext->SetCurrentObject(anAIS, false);
541       }
542     }
543   }
544   if (theUpdateViewer)
545     updateViewer();
546 }
547
548 void XGUI_Displayer::clearSelected()
549 {
550   Handle(AIS_InteractiveContext) aContext = AISContext();
551   if (!aContext.IsNull()) {
552     aContext->UnhilightCurrents(false);
553     aContext->ClearSelected();
554   }
555 }
556
557 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
558 {
559   bool aErased = false;
560   Handle(AIS_InteractiveContext) aContext = AISContext();
561   if (!aContext.IsNull()) {
562     foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
563       AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
564       // erase an object
565       Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
566       if (!anIO.IsNull()) {
567         emit beforeObjectErase(aObj, aAISObj);
568         aContext->Remove(anIO, false);
569         aErased = true;
570       }
571     }
572     if (theUpdateViewer)
573       updateViewer();
574   }
575   myResult2AISObjectMap.clear();
576 #ifdef DEBUG_DISPLAY
577   qDebug("eraseAll");
578   qDebug(getResult2AISObjectMapInfo().c_str());
579 #endif
580   return aErased;
581 }
582
583 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
584                       Handle(AIS_InteractiveObject) theObject,
585                       const bool theClear = true)
586 {
587   if (!theObject.IsNull()) {
588     theContext->Deactivate(theObject);
589     //if (theClear) {
590       //theObject->ClearSelected();
591       //  theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
592     //}
593   }
594 }
595
596 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
597 {
598   Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
599   Handle(AIS_InteractiveContext) aContext = AISContext();
600   if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
601     Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
602     deactivateObject(aContext, aTrie);
603
604     /// #1136 hidden axis are selected in sketch
605     /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
606     /// for Position AIS object in SelectionModes.
607     deactivateObject(aContext, aTrie->XAxis());
608     deactivateObject(aContext, aTrie->YAxis());
609     deactivateObject(aContext, aTrie->Axis());
610     deactivateObject(aContext, aTrie->Position());
611
612     deactivateObject(aContext, aTrie->XYPlane());
613     deactivateObject(aContext, aTrie->XZPlane());
614     deactivateObject(aContext, aTrie->YZPlane());
615
616     if (theUpdateViewer)
617       updateViewer();
618   }
619 }
620
621 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
622 {
623   return myWorkshop->viewer()->trihedron();
624 }
625
626 void XGUI_Displayer::openLocalContext()
627 {
628   Handle(AIS_InteractiveContext) aContext = AISContext();
629   // Open local context if there is no one
630   if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
631     // Preserve selected objects
632     //AIS_ListOfInteractive aAisList;
633     //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
634     //  aAisList.Append(aContext->Current());
635
636     // get the filters from the global context and append them to the local context
637     // a list of filters in the global context is not cleared and should be cleared here
638     SelectMgr_ListOfFilter aFilters;
639     aFilters.Assign(aContext->Filters());
640     // it is important to remove the filters in the global context, because there is a code
641     // in the closeLocalContex, which restore the global context filters
642     aContext->RemoveFilters();
643
644     //aContext->ClearCurrents();
645     aContext->OpenLocalContext();
646     //deactivateTrihedron();
647     //aContext->NotUseDisplayedObjects();
648
649     //myUseExternalObjects = false;
650
651     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
652     for (;aIt.More(); aIt.Next()) {
653       aContext->AddFilter(aIt.Value());
654     }
655     // Restore selection
656     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
657     //for(; aIt2.More(); aIt2.Next()) {
658     //  aContext->SetSelected(aIt2.Value(), false);
659     //}
660   }
661 }
662
663 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
664 {
665   Handle(AIS_InteractiveContext) aContext = AISContext();
666   if (!aContext.IsNull() && aContext->HasOpenedContext()) {
667     // Preserve selected objects
668     //AIS_ListOfInteractive aAisList;
669     //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
670     //  aAisList.Append(aContext->SelectedInteractive());
671
672     // get the filters from the local context and append them to the global context
673     // a list of filters in the local context is cleared
674     SelectMgr_ListOfFilter aFilters;
675     aFilters.Assign(aContext->Filters());
676
677     //aContext->ClearSelected();
678     aContext->CloseAllContexts(false);
679
680     // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
681     // this code is obsolete. It is temporaty commented and should be removed after
682     // the test campaign.
683     // Redisplay all object if they were displayed in localContext
684     /*Handle(AIS_InteractiveObject) aAISIO;
685     foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
686       aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
687       if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
688         aContext->Display(aAISIO, false);
689         aContext->SetDisplayMode(aAISIO, Shading, false);
690       }
691     }*/
692
693     // Append the filters from the local selection in the global selection context
694     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
695     for (;aIt.More(); aIt.Next()) {
696       Handle(SelectMgr_Filter) aFilter = aIt.Value();
697       aContext->AddFilter(aFilter);
698     }
699
700     if (theUpdateViewer)
701       updateViewer();
702     //myUseExternalObjects = false;
703
704     // Restore selection
705     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
706     //for(; aIt2.More(); aIt2.Next()) {
707     //  if (aContext->IsDisplayed(aIt2.Value()))
708     //    aContext->SetCurrentObject(aIt2.Value(), false);
709     //}
710   }
711 }
712
713 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
714 {
715   AISObjectPtr anIO;
716   if (myResult2AISObjectMap.contains(theObject))
717     anIO = myResult2AISObjectMap[theObject];
718   return anIO;
719 }
720
721 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
722 {
723   Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
724   return getObject(aRefAIS);
725 }
726
727 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
728 {
729   ObjectPtr anObject;
730   foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
731     AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
732     Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
733     if (anAIS == theIO)
734       anObject = anObj;
735     if (anObject.get())
736       break;
737   }
738   if (!anObject.get()) {
739     std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
740     if (!theIO.IsNull()) {
741       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
742     }
743     anObject = myWorkshop->module()->findPresentedObject(anAISObj);
744   }
745   return anObject;
746 }
747
748 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
749 {
750   bool aWasEnabled = isUpdateEnabled();
751   if (isEnabled)
752     myViewerBlockedRecursiveCount--;
753   else
754     myViewerBlockedRecursiveCount++;
755
756   if (myNeedUpdate && isUpdateEnabled()) {
757     updateViewer();
758     myNeedUpdate = false;
759   }
760   return aWasEnabled;
761 }
762
763 bool XGUI_Displayer::isUpdateEnabled() const
764 {
765   return myViewerBlockedRecursiveCount == 0;
766 }
767
768 void XGUI_Displayer::updateViewer() const
769 {
770   Handle(AIS_InteractiveContext) aContext = AISContext();
771   if (!aContext.IsNull() && isUpdateEnabled()) {
772     myWorkshop->viewer()->Zfitall();
773     aContext->UpdateCurrentViewer();
774   } else {
775     myNeedUpdate = true;
776   }
777 }
778
779 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
780                                  const int theMode, const bool theUpdateViewer) const
781 {
782   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
783   if (!aContext.IsNull()) {
784     aContext->Activate(theIO, theMode, false);
785
786 #ifdef DEBUG_ACTIVATE_AIS
787     ObjectPtr anObject = getObject(theIO);
788     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
789     qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
790 #endif
791     if (theUpdateViewer)
792       updateViewer();
793   }
794 }
795
796 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
797 {
798   Handle(AIS_InteractiveContext) aContext = AISContext();
799   if (!aContext.IsNull()) {
800     if (theMode == -1)
801       aContext->Deactivate(theIO);
802     else
803       aContext->Deactivate(theIO, theMode);
804
805 #ifdef DEBUG_DEACTIVATE_AIS
806     ObjectPtr anObject = getObject(theIO);
807     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
808     qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
809 #endif
810   }
811 }
812
813 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
814 {
815   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
816   if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
817     aContext->OpenLocalContext();
818     if (!isTrihedronActive())
819       deactivateTrihedron(true);
820     aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
821     aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
822   }
823   return aContext;
824 }
825
826 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
827 {
828   Handle(AIS_InteractiveContext) aContext = AISContext();
829   if (!aContext.IsNull() && myAndFilter.IsNull()) {
830     myAndFilter = new SelectMgr_AndFilter();
831     aContext->AddFilter(myAndFilter);
832   }
833   return myAndFilter;
834 }
835
836 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
837                                 bool theUpdateViewer)
838 {
839   bool aDisplayed = false;
840   Handle(AIS_InteractiveContext) aContext = AISContext();
841   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
842   if (!aContext.IsNull() && !anAISIO.IsNull()) {
843     aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
844     aDisplayed = true;
845     aContext->Deactivate(anAISIO);
846     aContext->Load(anAISIO);
847     if (toActivateInSelectionModes) {
848       if (aContext->HasOpenedContext()) {
849         if (myActiveSelectionModes.size() == 0)
850           activateAIS(anAISIO, 0, theUpdateViewer);
851         else {
852           foreach(int aMode, myActiveSelectionModes) {
853             activateAIS(anAISIO, aMode, theUpdateViewer);
854           }
855         }
856       }
857     }
858     if (theUpdateViewer)
859       updateViewer();
860   }
861   return aDisplayed;
862 }
863
864 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
865 {
866   bool aErased = false;
867   Handle(AIS_InteractiveContext) aContext = AISContext();
868   if (!aContext.IsNull()) {
869     Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
870     if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
871       aContext->Remove(anAISIO, false/*update viewer*/);
872       aErased = true;
873     }
874   }
875   if (aErased && theUpdateViewer)
876     updateViewer();
877   return aErased;
878 }
879
880
881 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
882 {
883   if (theMode == NoMode)
884     return;
885
886   Handle(AIS_InteractiveContext) aContext = AISContext();
887   if (aContext.IsNull())
888     return;
889
890   AISObjectPtr aAISObj = getAISObject(theObject);
891   if (!aAISObj)
892     return;
893
894   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
895   aContext->SetDisplayMode(aAISIO, theMode, false);
896   // Redisplay in order to update new mode because it could be not computed before
897   if (theUpdateViewer)
898     updateViewer();
899 }
900
901 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
902 {
903   Handle(AIS_InteractiveContext) aContext = AISContext();
904   if (aContext.IsNull())
905     return NoMode;
906
907   AISObjectPtr aAISObj = getAISObject(theObject);
908   if (!aAISObj)
909     return NoMode;
910
911   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
912   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
913 }
914
915 void XGUI_Displayer::deactivateSelectionFilters()
916 {
917   Handle(AIS_InteractiveContext) aContext = AISContext();
918   if (!myAndFilter.IsNull()) {
919     bool aFound = false;
920     if (!aContext.IsNull()) {
921       const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
922       SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
923       for (; anIt.More() && !aFound; anIt.Next()) {
924         Handle(SelectMgr_Filter) aFilter = anIt.Value();
925         aFound = aFilter == myAndFilter;
926       }
927       if (aFound)
928         aContext->RemoveFilter(myAndFilter);
929     }
930     myAndFilter.Nullify();
931   }
932 }
933
934 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
935 {
936   Handle(AIS_InteractiveContext) aContext = AISContext();
937   if (aContext.IsNull() || hasSelectionFilter(theFilter))
938     return;
939
940   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
941   if (!aCompositeFilter.IsNull()) {
942     aCompositeFilter->Add(theFilter);
943 #ifdef DEBUG_SELECTION_FILTERS
944     int aCount = aCompositeFilter->StoredFilters().Extent();
945     qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
946 #endif
947   }
948 }
949
950 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
951 {
952   Handle(AIS_InteractiveContext) aContext = AISContext();
953   if (aContext.IsNull())
954     return;
955
956   Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
957   if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
958     aCompositeFilter->Remove(theFilter);
959 #ifdef DEBUG_SELECTION_FILTERS
960     int aCount = aCompositeFilter->StoredFilters().Extent();
961     qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
962 #endif
963   }
964 }
965
966 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
967 {
968   bool aFilterFound = false;
969
970   Handle(AIS_InteractiveContext) aContext = AISContext();
971   if (aContext.IsNull())
972     return aFilterFound;
973   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
974   SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
975   for (; aIt.More() && !aFilterFound; aIt.Next()) {
976     if (theFilter.Access() == aIt.Value().Access())
977       aFilterFound = true;
978   }
979   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
980   if (!aCompositeFilter.IsNull()) {
981     const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
982     for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
983       if (theFilter.Access() == aIt.Value().Access())
984         aFilterFound = true;
985     }
986   }
987   return aFilterFound;
988 }
989
990 void XGUI_Displayer::removeFilters()
991 {
992   Handle(AIS_InteractiveContext) aContext = AISContext();
993   if (aContext.IsNull())
994     return;
995
996   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
997   if (!aCompositeFilter.IsNull())
998     aCompositeFilter->Clear();
999 }
1000
1001 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1002 {
1003   QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1004   foreach(ObjectPtr aObj, aDispList) {
1005     if (!theList.contains(aObj))
1006       erase(aObj, false);
1007   }
1008   foreach(ObjectPtr aObj, theList) {
1009     if (!isVisible(aObj))
1010       display(aObj, false);
1011   }
1012   updateViewer();
1013 }
1014
1015 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1016
1017   if (!isVisible(theObject))
1018     return false;
1019
1020   AISObjectPtr aAISObj = getAISObject(theObject);
1021   if (aAISObj.get() == NULL)
1022     return false;
1023
1024   Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1025   return ::canBeShaded(anAIS);
1026 }
1027
1028 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1029                               const QIntList& theModes,
1030                               const bool theUpdateViewer) const
1031 {
1032   Handle(AIS_InteractiveContext) aContext = AISContext();
1033   if (aContext.IsNull() || theIO.IsNull())
1034     return false;
1035   
1036   bool isActivationChanged = false;
1037   // deactivate object in all modes, which are not in the list of activation
1038   // It seems that after the IO deactivation the selected state of the IO's owners
1039   // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1040   // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1041   // only if there is a difference in the current modes and the parameters modes.
1042   // If the selection problem happens again, it is possible to write a test scenario and create
1043   // a bug. The bug steps are the following:
1044   // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1045   // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1046   TColStd_ListOfInteger aTColModes;
1047   aContext->ActivatedModes(theIO, aTColModes);
1048   TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1049   QIntList aModesActivatedForIO;
1050   bool isDeactivated = false;
1051   for (; itr.More(); itr.Next() ) {
1052     Standard_Integer aMode = itr.Value();
1053     if (!theModes.contains(aMode)) {
1054       deactivateAIS(theIO, aMode);
1055       isDeactivated = true;
1056     }
1057     else {
1058       aModesActivatedForIO.append(aMode);
1059     }
1060   }
1061   if (isDeactivated) {
1062     // the selection from the previous activation modes should be cleared manually (#26172)
1063     theIO->ClearSelected();
1064     aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1065     // For performance issues
1066     //if (theUpdateViewer)
1067     //  updateViewer();
1068     isActivationChanged = true;
1069   }
1070
1071   // loading the interactive object allowing the decomposition
1072   if (aTColModes.IsEmpty()) {
1073     aContext->Load(theIO, -1, true);
1074   }
1075
1076   // trihedron AIS check should be after the AIS loading.
1077   // If it is not loaded, it is steel selectable in the viewer.
1078   Handle(AIS_Trihedron) aTrihedron;
1079   if (!isTrihedronActive())
1080     aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1081   if (aTrihedron.IsNull()) {
1082       // In order to clear active modes list
1083     if (theModes.size() == 0) {
1084       activateAIS(theIO, 0, theUpdateViewer);
1085     } else {
1086       foreach(int aMode, theModes) {
1087         if (!aModesActivatedForIO.contains(aMode)) {
1088           activateAIS(theIO, aMode, theUpdateViewer);
1089           isActivationChanged = true;
1090         }
1091       }
1092     }
1093   }
1094   return isActivationChanged;
1095 }
1096
1097 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1098 {
1099   AISObjectPtr anAISObj = getAISObject(theObject);
1100   // correct the result's color it it has the attribute
1101   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1102
1103   // Customization of presentation
1104   GeomCustomPrsPtr aCustomPrs;
1105   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1106   if (aFeature.get() != NULL) {
1107     GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1108     if (aCustPrs.get() != NULL)
1109       aCustomPrs = aCustPrs;
1110   }
1111   if (aCustomPrs.get() == NULL) {
1112     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1113     // we ignore presentable not customized objects
1114     if (aPrs.get() == NULL)
1115       aCustomPrs = myCustomPrs;
1116   }
1117   bool isCustomized = aCustomPrs.get() &&
1118                       aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1119   return isCustomized;
1120 }
1121
1122
1123 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1124 {
1125   if (!isVisible(theObject))
1126     return Qt::black;
1127
1128   AISObjectPtr anAISObj = getAISObject(theObject);
1129   int aR, aG, aB;
1130   anAISObj->getColor(aR, aG, aB);
1131   anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1132   if (theUpdateViewer)
1133     updateViewer();
1134   return QColor(aR, aG, aB);
1135 }
1136
1137 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1138 {
1139   myResult2AISObjectMap[theObject] = theAIS;
1140
1141 #ifdef DEBUG_DISPLAY
1142   std::ostringstream aPtrStr;
1143   aPtrStr << theObject.get();
1144   qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1145   qDebug(getResult2AISObjectMapInfo().c_str());
1146 #endif
1147 }
1148
1149 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1150 {
1151   QStringList aContent;
1152   foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1153     AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1154     std::ostringstream aPtrStr;
1155     aPtrStr << "aObj = " << aObj.get() << ":";
1156     aPtrStr << "anAIS = " << aAISObj.get() << ":";
1157     aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1158     
1159     aContent.append(aPtrStr.str().c_str());
1160   }
1161   return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1162                                             arg(aContent.join("\n")).toStdString().c_str();
1163 }
1164
1165 void XGUI_Displayer::activateTrihedron(bool theIsActive) 
1166 {  
1167   myIsTrihedronActive = theIsActive; 
1168   if (!myIsTrihedronActive) {
1169     deactivateTrihedron(true);
1170   }
1171 }
1172
1173 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1174 {
1175   Handle(AIS_InteractiveContext) aContext = AISContext();
1176   if (aContext.IsNull())
1177     return;
1178
1179   Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1180
1181   if (theToDisplay) {
1182     if (!aContext->IsDisplayed(aTrihedron))
1183       aContext->Display(aTrihedron,
1184                         0 /*wireframe*/,
1185                         -1 /* selection mode */,
1186                         Standard_True /* update viewer*/,
1187                         Standard_False /* allow decomposition */,
1188                         AIS_DS_Displayed /* xdisplay status */);
1189
1190     if (!isTrihedronActive())
1191       deactivateTrihedron(false);
1192     else
1193       activate(aTrihedron, myActiveSelectionModes, false);
1194   } else {
1195     deactivateTrihedron(false);
1196     //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1197     // the selection from the previous activation modes should be cleared manually (#26172)
1198
1199     aContext->Erase(aTrihedron);
1200   }
1201
1202   updateViewer();
1203 }