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