]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.cpp
Salome HOME
#1330 Multiply selection when Create fillet using Shift button
[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, false/*update viewer*/);
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 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
414 {
415   bool aVisible = false;
416   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
417   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
418   if (aPrs.get() || aResult.get()) {
419     aVisible = theDisplayer->isVisible(theObject);
420     // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
421     // visible. It is useful for highlight presentation where compsolid shape is selectable
422     if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
423       ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
424       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
425         bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
426         for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
427           anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
428         }
429         aVisible = anAllSubsVisible;
430       }
431     }
432   }
433   else {
434     // check if all results of the feature are visible
435     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
436     std::list<ResultPtr> aResults = aFeature->results();
437     std::list<ResultPtr>::const_iterator aIt;
438     aVisible = !aResults.empty();
439     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
440       aVisible = aVisible && theDisplayer->isVisible(*aIt);
441     }
442   }
443   return aVisible;
444 }
445
446
447 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
448                                      const bool theUpdateViewer)
449 {
450   // Convert shape types to selection types
451   QIntList aModes;
452   foreach(int aType, theModes) {
453     aModes.append(getSelectionMode(aType));
454   }
455
456 #ifdef DEBUG_ACTIVATE_OBJECTS
457   QStringList anInfo;
458   QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
459   for (; anIt != aLast; ++anIt) {
460     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
461   }
462   QString anInfoStr = anInfo.join(", ");
463
464   qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
465     arg(aModes.size()).arg(qIntListInfo(aModes)).
466     arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
467     arg(anInfoStr).
468     toStdString().c_str());
469 #endif
470   // In order to avoid doblications of selection modes
471   QIntList aNewModes;
472   foreach (int aMode, aModes) {
473     if (!aNewModes.contains(aMode))
474       aNewModes.append(aMode);
475   }
476   myActiveSelectionModes = aNewModes;
477   Handle(AIS_InteractiveContext) aContext = AISContext();
478   // Open local context if there is no one
479   if (aContext.IsNull() || !aContext->HasOpenedContext()) 
480     return;
481
482   //aContext->UseDisplayedObjects();
483   //myUseExternalObjects = true;
484
485   Handle(AIS_InteractiveObject) anAISIO;
486   AIS_ListOfInteractive aPrsList;
487   //if (aObjList.isEmpty())
488   //  return;
489   //else {
490   foreach(ObjectPtr aObj, theObjList) {
491     if (myResult2AISObjectMap.contains(aObj))
492       aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
493   }
494   //}
495
496   // Add trihedron because it has to partisipate in selection
497   Handle(AIS_InteractiveObject) aTrihedron;
498   if (isTrihedronActive()) {
499     aTrihedron = getTrihedron();
500     if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
501       aPrsList.Append(aTrihedron);
502   }
503   if (aPrsList.Extent() == 0)
504     return;
505
506   AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
507   bool isActivationChanged = false;
508   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
509     anAISIO = aLIt.Value();
510     if (activate(anAISIO, myActiveSelectionModes, false))
511       isActivationChanged = true;
512   }
513   if (!aTrihedron.IsNull()) {
514     foreach(int aMode, myActiveSelectionModes)
515       aContext->SetSelectionSensitivity(aTrihedron, aMode, 20);
516   }
517   // VSV It seems that there is no necessity to update viewer on activation
518   //if (theUpdateViewer && isActivationChanged)
519   //  updateViewer();
520 }
521
522 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
523 {
524   Handle(AIS_InteractiveContext) aContext = AISContext();
525   if (aContext.IsNull() || !isVisible(theObject))
526     return false;
527     
528   AISObjectPtr anObj = myResult2AISObjectMap[theObject];
529   Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
530
531   TColStd_ListOfInteger aModes;
532   aContext->ActivatedModes(anAIS, aModes);
533   return aModes.Extent() > 0;
534 }
535 void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer)
536 {
537   Handle(AIS_InteractiveContext) aContext = AISContext();
538   if (aContext.IsNull())
539     return;
540   if (aContext->HasOpenedContext()) {
541     aContext->UnhilightSelected(false);
542     aContext->ClearSelected(false);
543     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
544       const TopoDS_Shape& aShape = aPrs.shape();
545       if (!aShape.IsNull()) {
546         aContext->AddOrRemoveSelected(aShape, false);
547       } else {
548         ObjectPtr anObject = aPrs.object();
549         ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
550         if (aResult.get() && isVisible(aResult)) {
551           AISObjectPtr anObj = myResult2AISObjectMap[aResult];
552           Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
553           if (!anAIS.IsNull()) {
554             // The methods are replaced in order to provide multi-selection, e.g. restore selection
555             // by activating multi selector widget. It also gives an advantage that the multi
556             // selection in OB gives multi-selection in the viewer
557             //aContext->SetSelected(anAIS, false);
558             // The selection in the context was cleared, so the method sets the objects are selected
559             aContext->AddOrRemoveSelected(anAIS, false);
560           }
561         }
562       }
563     }
564   } else {
565     aContext->UnhilightCurrents(false);
566     aContext->ClearCurrents(false);
567     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
568       ObjectPtr anObject = aPrs.object();
569       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
570       if (aResult.get() && isVisible(aResult)) {
571         AISObjectPtr anObj = myResult2AISObjectMap[aResult];
572         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
573         if (!anAIS.IsNull())
574           aContext->SetCurrentObject(anAIS, false);
575       }
576     }
577   }
578   if (theUpdateViewer)
579     updateViewer();
580 }
581
582 void XGUI_Displayer::clearSelected()
583 {
584   Handle(AIS_InteractiveContext) aContext = AISContext();
585   if (!aContext.IsNull()) {
586     aContext->UnhilightCurrents(false);
587     aContext->ClearSelected();
588   }
589 }
590
591 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
592 {
593   bool aErased = false;
594   Handle(AIS_InteractiveContext) aContext = AISContext();
595   if (!aContext.IsNull()) {
596     foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
597       AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
598       // erase an object
599       Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
600       if (!anIO.IsNull()) {
601         emit beforeObjectErase(aObj, aAISObj);
602         aContext->Remove(anIO, false/*update viewer*/);
603         aErased = true;
604       }
605     }
606     if (theUpdateViewer)
607       updateViewer();
608   }
609   myResult2AISObjectMap.clear();
610 #ifdef DEBUG_DISPLAY
611   qDebug("eraseAll");
612   qDebug(getResult2AISObjectMapInfo().c_str());
613 #endif
614   return aErased;
615 }
616
617 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
618                       Handle(AIS_InteractiveObject) theObject,
619                       const bool theClear = true)
620 {
621   if (!theObject.IsNull()) {
622     theContext->Deactivate(theObject);
623     //if (theClear) {
624       //theObject->ClearSelected();
625       //  theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
626     //}
627   }
628 }
629
630 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
631 {
632   Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
633   Handle(AIS_InteractiveContext) aContext = AISContext();
634   if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
635     Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
636     deactivateObject(aContext, aTrie);
637
638     /// #1136 hidden axis are selected in sketch
639     /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
640     /// for Position AIS object in SelectionModes.
641     deactivateObject(aContext, aTrie->XAxis());
642     deactivateObject(aContext, aTrie->YAxis());
643     deactivateObject(aContext, aTrie->Axis());
644     deactivateObject(aContext, aTrie->Position());
645
646     deactivateObject(aContext, aTrie->XYPlane());
647     deactivateObject(aContext, aTrie->XZPlane());
648     deactivateObject(aContext, aTrie->YZPlane());
649
650     if (theUpdateViewer)
651       updateViewer();
652   }
653 }
654
655 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
656 {
657   return myWorkshop->viewer()->trihedron();
658 }
659
660 void XGUI_Displayer::openLocalContext()
661 {
662   Handle(AIS_InteractiveContext) aContext = AISContext();
663   // Open local context if there is no one
664   if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
665     // Preserve selected objects
666     //AIS_ListOfInteractive aAisList;
667     //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
668     //  aAisList.Append(aContext->Current());
669
670     // get the filters from the global context and append them to the local context
671     // a list of filters in the global context is not cleared and should be cleared here
672     SelectMgr_ListOfFilter aFilters;
673     aFilters.Assign(aContext->Filters());
674     // it is important to remove the filters in the global context, because there is a code
675     // in the closeLocalContex, which restore the global context filters
676     aContext->RemoveFilters();
677
678     //aContext->ClearCurrents();
679     aContext->OpenLocalContext();
680     //deactivateTrihedron();
681     //aContext->NotUseDisplayedObjects();
682
683     //myUseExternalObjects = false;
684
685     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
686     for (;aIt.More(); aIt.Next()) {
687       aContext->AddFilter(aIt.Value());
688     }
689     // Restore selection
690     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
691     //for(; aIt2.More(); aIt2.Next()) {
692     //  aContext->SetSelected(aIt2.Value(), false);
693     //}
694   }
695 }
696
697 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
698 {
699   Handle(AIS_InteractiveContext) aContext = AISContext();
700   if (!aContext.IsNull() && aContext->HasOpenedContext()) {
701     // Preserve selected objects
702     //AIS_ListOfInteractive aAisList;
703     //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
704     //  aAisList.Append(aContext->SelectedInteractive());
705
706     // get the filters from the local context and append them to the global context
707     // a list of filters in the local context is cleared
708     SelectMgr_ListOfFilter aFilters;
709     aFilters.Assign(aContext->Filters());
710
711     //aContext->ClearSelected();
712     aContext->CloseAllContexts(false);
713
714     // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
715     // this code is obsolete. It is temporaty commented and should be removed after
716     // the test campaign.
717     // Redisplay all object if they were displayed in localContext
718     /*Handle(AIS_InteractiveObject) aAISIO;
719     foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
720       aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
721       if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
722         aContext->Display(aAISIO, false);
723         aContext->SetDisplayMode(aAISIO, Shading, false);
724       }
725     }*/
726
727     // Append the filters from the local selection in the global selection context
728     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
729     for (;aIt.More(); aIt.Next()) {
730       Handle(SelectMgr_Filter) aFilter = aIt.Value();
731       aContext->AddFilter(aFilter);
732     }
733
734     if (theUpdateViewer)
735       updateViewer();
736     //myUseExternalObjects = false;
737
738     // Restore selection
739     //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
740     //for(; aIt2.More(); aIt2.Next()) {
741     //  if (aContext->IsDisplayed(aIt2.Value()))
742     //    aContext->SetCurrentObject(aIt2.Value(), false);
743     //}
744   }
745 }
746
747 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
748 {
749   AISObjectPtr anIO;
750   if (myResult2AISObjectMap.contains(theObject))
751     anIO = myResult2AISObjectMap[theObject];
752   return anIO;
753 }
754
755 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
756 {
757   Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
758   return getObject(aRefAIS);
759 }
760
761 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
762 {
763   ObjectPtr anObject;
764   foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
765     AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
766     Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
767     if (anAIS == theIO)
768       anObject = anObj;
769     if (anObject.get())
770       break;
771   }
772   if (!anObject.get()) {
773     std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
774     if (!theIO.IsNull()) {
775       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
776     }
777     anObject = myWorkshop->module()->findPresentedObject(anAISObj);
778   }
779   return anObject;
780 }
781
782 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
783 {
784   bool aWasEnabled = isUpdateEnabled();
785   if (isEnabled)
786     myViewerBlockedRecursiveCount--;
787   else
788     myViewerBlockedRecursiveCount++;
789
790   if (myNeedUpdate && isUpdateEnabled()) {
791     updateViewer();
792     myNeedUpdate = false;
793   }
794   return aWasEnabled;
795 }
796
797 bool XGUI_Displayer::isUpdateEnabled() const
798 {
799   return myViewerBlockedRecursiveCount == 0;
800 }
801
802 void XGUI_Displayer::updateViewer() const
803 {
804   Handle(AIS_InteractiveContext) aContext = AISContext();
805   if (!aContext.IsNull() && isUpdateEnabled()) {
806     myWorkshop->viewer()->Zfitall();
807     aContext->UpdateCurrentViewer();
808   } else {
809     myNeedUpdate = true;
810   }
811 }
812
813 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
814                                  const int theMode, const bool theUpdateViewer) const
815 {
816   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
817   if (!aContext.IsNull()) {
818     aContext->Activate(theIO, theMode, false);
819
820 #ifdef DEBUG_ACTIVATE_AIS
821     ObjectPtr anObject = getObject(theIO);
822     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
823     qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
824 #endif
825     if (theUpdateViewer)
826       updateViewer();
827   }
828 }
829
830 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
831 {
832   Handle(AIS_InteractiveContext) aContext = AISContext();
833   if (!aContext.IsNull()) {
834     if (theMode == -1)
835       aContext->Deactivate(theIO);
836     else
837       aContext->Deactivate(theIO, theMode);
838
839 #ifdef DEBUG_DEACTIVATE_AIS
840     ObjectPtr anObject = getObject(theIO);
841     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
842     qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
843 #endif
844   }
845 }
846
847 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
848 {
849   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
850   if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
851     aContext->OpenLocalContext();
852     if (!isTrihedronActive())
853       deactivateTrihedron(true);
854     aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
855     aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
856   }
857   return aContext;
858 }
859
860 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
861 {
862   Handle(AIS_InteractiveContext) aContext = AISContext();
863   if (!aContext.IsNull() && myAndFilter.IsNull()) {
864     myAndFilter = new SelectMgr_AndFilter();
865     aContext->AddFilter(myAndFilter);
866   }
867   return myAndFilter;
868 }
869
870 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
871                                 bool theUpdateViewer)
872 {
873   bool aDisplayed = false;
874   Handle(AIS_InteractiveContext) aContext = AISContext();
875   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
876   if (!aContext.IsNull() && !anAISIO.IsNull()) {
877     aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
878     aDisplayed = true;
879     aContext->Deactivate(anAISIO);
880     aContext->Load(anAISIO);
881     if (toActivateInSelectionModes) {
882       if (aContext->HasOpenedContext()) {
883         if (myActiveSelectionModes.size() == 0)
884           activateAIS(anAISIO, 0, theUpdateViewer);
885         else {
886           foreach(int aMode, myActiveSelectionModes) {
887             activateAIS(anAISIO, aMode, theUpdateViewer);
888           }
889         }
890       }
891     }
892     if (theUpdateViewer)
893       updateViewer();
894   }
895   return aDisplayed;
896 }
897
898 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
899 {
900   bool aErased = false;
901   Handle(AIS_InteractiveContext) aContext = AISContext();
902   if (!aContext.IsNull()) {
903     Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
904     if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
905       aContext->Remove(anAISIO, false/*update viewer*/);
906       aErased = true;
907     }
908   }
909   if (aErased && theUpdateViewer)
910     updateViewer();
911   return aErased;
912 }
913
914
915 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
916 {
917   if (theMode == NoMode)
918     return;
919
920   Handle(AIS_InteractiveContext) aContext = AISContext();
921   if (aContext.IsNull())
922     return;
923
924   AISObjectPtr aAISObj = getAISObject(theObject);
925   if (!aAISObj)
926     return;
927
928   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
929   aContext->SetDisplayMode(aAISIO, theMode, false);
930   // Redisplay in order to update new mode because it could be not computed before
931   if (theUpdateViewer)
932     updateViewer();
933 }
934
935 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
936 {
937   Handle(AIS_InteractiveContext) aContext = AISContext();
938   if (aContext.IsNull())
939     return NoMode;
940
941   AISObjectPtr aAISObj = getAISObject(theObject);
942   if (!aAISObj)
943     return NoMode;
944
945   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
946   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
947 }
948
949 void XGUI_Displayer::deactivateSelectionFilters()
950 {
951   Handle(AIS_InteractiveContext) aContext = AISContext();
952   if (!myAndFilter.IsNull()) {
953     bool aFound = false;
954     if (!aContext.IsNull()) {
955       const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
956       SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
957       for (; anIt.More() && !aFound; anIt.Next()) {
958         Handle(SelectMgr_Filter) aFilter = anIt.Value();
959         aFound = aFilter == myAndFilter;
960       }
961       if (aFound)
962         aContext->RemoveFilter(myAndFilter);
963     }
964     myAndFilter.Nullify();
965   }
966 }
967
968 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
969 {
970   Handle(AIS_InteractiveContext) aContext = AISContext();
971   if (aContext.IsNull() || hasSelectionFilter(theFilter))
972     return;
973
974   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
975   if (!aCompositeFilter.IsNull()) {
976     aCompositeFilter->Add(theFilter);
977 #ifdef DEBUG_SELECTION_FILTERS
978     int aCount = aCompositeFilter->StoredFilters().Extent();
979     qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
980 #endif
981   }
982 }
983
984 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
985 {
986   Handle(AIS_InteractiveContext) aContext = AISContext();
987   if (aContext.IsNull())
988     return;
989
990   Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
991   if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
992     aCompositeFilter->Remove(theFilter);
993 #ifdef DEBUG_SELECTION_FILTERS
994     int aCount = aCompositeFilter->StoredFilters().Extent();
995     qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
996 #endif
997   }
998 }
999
1000 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1001 {
1002   bool aFilterFound = false;
1003
1004   Handle(AIS_InteractiveContext) aContext = AISContext();
1005   if (aContext.IsNull())
1006     return aFilterFound;
1007   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1008   SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1009   for (; aIt.More() && !aFilterFound; aIt.Next()) {
1010     if (theFilter.Access() == aIt.Value().Access())
1011       aFilterFound = true;
1012   }
1013   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1014   if (!aCompositeFilter.IsNull()) {
1015     const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1016     for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1017       if (theFilter.Access() == aIt.Value().Access())
1018         aFilterFound = true;
1019     }
1020   }
1021   return aFilterFound;
1022 }
1023
1024 void XGUI_Displayer::removeFilters()
1025 {
1026   Handle(AIS_InteractiveContext) aContext = AISContext();
1027   if (aContext.IsNull())
1028     return;
1029
1030   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1031   if (!aCompositeFilter.IsNull())
1032     aCompositeFilter->Clear();
1033 }
1034
1035 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1036 {
1037   QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1038   foreach(ObjectPtr aObj, aDispList) {
1039     if (!theList.contains(aObj))
1040       erase(aObj, false);
1041   }
1042   foreach(ObjectPtr aObj, theList) {
1043     if (!isVisible(aObj))
1044       display(aObj, false);
1045   }
1046   updateViewer();
1047 }
1048
1049 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1050
1051   if (!isVisible(theObject))
1052     return false;
1053
1054   AISObjectPtr aAISObj = getAISObject(theObject);
1055   if (aAISObj.get() == NULL)
1056     return false;
1057
1058   Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1059   return ::canBeShaded(anAIS);
1060 }
1061
1062 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1063                               const QIntList& theModes,
1064                               const bool theUpdateViewer) const
1065 {
1066   Handle(AIS_InteractiveContext) aContext = AISContext();
1067   if (aContext.IsNull() || theIO.IsNull())
1068     return false;
1069   
1070   bool isActivationChanged = false;
1071   // deactivate object in all modes, which are not in the list of activation
1072   // It seems that after the IO deactivation the selected state of the IO's owners
1073   // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1074   // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1075   // only if there is a difference in the current modes and the parameters modes.
1076   // If the selection problem happens again, it is possible to write a test scenario and create
1077   // a bug. The bug steps are the following:
1078   // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1079   // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1080   TColStd_ListOfInteger aTColModes;
1081   aContext->ActivatedModes(theIO, aTColModes);
1082   TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1083   QIntList aModesActivatedForIO;
1084   bool isDeactivated = false;
1085   for (; itr.More(); itr.Next() ) {
1086     Standard_Integer aMode = itr.Value();
1087     if (!theModes.contains(aMode)) {
1088       deactivateAIS(theIO, aMode);
1089       isDeactivated = true;
1090     }
1091     else {
1092       aModesActivatedForIO.append(aMode);
1093     }
1094   }
1095   if (isDeactivated) {
1096     // the selection from the previous activation modes should be cleared manually (#26172)
1097     theIO->ClearSelected();
1098     aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1099     // For performance issues
1100     //if (theUpdateViewer)
1101     //  updateViewer();
1102     isActivationChanged = true;
1103   }
1104
1105   // loading the interactive object allowing the decomposition
1106   if (aTColModes.IsEmpty()) {
1107     aContext->Load(theIO, -1, true);
1108   }
1109
1110   // trihedron AIS check should be after the AIS loading.
1111   // If it is not loaded, it is steel selectable in the viewer.
1112   Handle(AIS_Trihedron) aTrihedron;
1113   if (!isTrihedronActive())
1114     aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1115   if (aTrihedron.IsNull()) {
1116       // In order to clear active modes list
1117     if (theModes.size() == 0) {
1118       activateAIS(theIO, 0, theUpdateViewer);
1119     } else {
1120       foreach(int aMode, theModes) {
1121         if (!aModesActivatedForIO.contains(aMode)) {
1122           activateAIS(theIO, aMode, theUpdateViewer);
1123           isActivationChanged = true;
1124         }
1125       }
1126     }
1127   }
1128   return isActivationChanged;
1129 }
1130
1131 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1132 {
1133   AISObjectPtr anAISObj = getAISObject(theObject);
1134   // correct the result's color it it has the attribute
1135   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1136
1137   // Customization of presentation
1138   GeomCustomPrsPtr aCustomPrs;
1139   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1140   if (aFeature.get() != NULL) {
1141     GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1142     if (aCustPrs.get() != NULL)
1143       aCustomPrs = aCustPrs;
1144   }
1145   if (aCustomPrs.get() == NULL) {
1146     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1147     // we ignore presentable not customized objects
1148     if (aPrs.get() == NULL)
1149       aCustomPrs = myCustomPrs;
1150   }
1151   bool isCustomized = aCustomPrs.get() &&
1152                       aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1153   return isCustomized;
1154 }
1155
1156
1157 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1158 {
1159   if (!isVisible(theObject))
1160     return Qt::black;
1161
1162   AISObjectPtr anAISObj = getAISObject(theObject);
1163   int aR, aG, aB;
1164   anAISObj->getColor(aR, aG, aB);
1165   anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1166   if (theUpdateViewer)
1167     updateViewer();
1168   return QColor(aR, aG, aB);
1169 }
1170
1171 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1172 {
1173   myResult2AISObjectMap[theObject] = theAIS;
1174
1175 #ifdef DEBUG_DISPLAY
1176   std::ostringstream aPtrStr;
1177   aPtrStr << theObject.get();
1178   qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1179   qDebug(getResult2AISObjectMapInfo().c_str());
1180 #endif
1181 }
1182
1183 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1184 {
1185   QStringList aContent;
1186   foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1187     AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1188     std::ostringstream aPtrStr;
1189     aPtrStr << "aObj = " << aObj.get() << ":";
1190     aPtrStr << "anAIS = " << aAISObj.get() << ":";
1191     aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1192     
1193     aContent.append(aPtrStr.str().c_str());
1194   }
1195   return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1196                                             arg(aContent.join("\n")).toStdString().c_str();
1197 }
1198
1199 void XGUI_Displayer::activateTrihedron(bool theIsActive) 
1200 {  
1201   myIsTrihedronActive = theIsActive; 
1202   if (!myIsTrihedronActive) {
1203     deactivateTrihedron(true);
1204   }
1205 }
1206
1207 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1208 {
1209   Handle(AIS_InteractiveContext) aContext = AISContext();
1210   if (aContext.IsNull())
1211     return;
1212
1213   Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1214
1215   if (theToDisplay) {
1216     if (!aContext->IsDisplayed(aTrihedron))
1217       aContext->Display(aTrihedron,
1218                         0 /*wireframe*/,
1219                         -1 /* selection mode */,
1220                         Standard_True /* update viewer*/,
1221                         Standard_False /* allow decomposition */,
1222                         AIS_DS_Displayed /* xdisplay status */);
1223
1224     if (!isTrihedronActive())
1225       deactivateTrihedron(false);
1226     else
1227       activate(aTrihedron, myActiveSelectionModes, false);
1228   } else {
1229     deactivateTrihedron(false);
1230     //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1231     // the selection from the previous activation modes should be cleared manually (#26172)
1232
1233     aContext->Erase(aTrihedron);
1234   }
1235
1236   updateViewer();
1237 }