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