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