]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.cpp
Salome HOME
Correction for colors of sketcher and for selection of trihedron
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XGUI_Displayer.h"
21
22 #include "XGUI_FacesPanel.h"
23 #include "XGUI_Selection.h"
24 #include "XGUI_SelectionActivate.h"
25 #include "XGUI_SelectionMgr.h"
26 #include "XGUI_ViewerProxy.h"
27 #include "XGUI_Workshop.h"
28
29 #ifndef HAVE_SALOME
30 #include <AppElements_Viewer.h>
31 #endif
32
33 #include <ModelAPI_Document.h>
34 #include <ModelAPI_Data.h>
35 #include <ModelAPI_Object.h>
36 #include <ModelAPI_Tools.h>
37 #include <ModelAPI_AttributeIntArray.h>
38 #include <ModelAPI_ResultBody.h>
39 #include <ModelAPI_ResultConstruction.h>
40
41 #include <ModuleBase_BRepOwner.h>
42 #include <ModuleBase_IModule.h>
43 #include <ModuleBase_Preferences.h>
44 #include <ModuleBase_Tools.h>
45 #include <ModuleBase_ViewerPrs.h>
46 #include <ModuleBase_IViewer.h>
47
48 #include <GeomAPI_Shape.h>
49 #include <GeomAPI_IPresentable.h>
50 #include <GeomAPI_ICustomPrs.h>
51 #include <GeomAPI_Pnt.h>
52 #include <GeomAPI_IScreenParams.h>
53
54 #include <SUIT_ResourceMgr.h>
55
56 #include <AIS_InteractiveContext.hxx>
57 #include <AIS_ListOfInteractive.hxx>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
59 #include <AIS_DimensionSelectionMode.hxx>
60 #include <AIS_Shape.hxx>
61 #include <AIS_Dimension.hxx>
62 #include <AIS_Trihedron.hxx>
63 #ifdef BEFORE_TRIHEDRON_PATCH
64 #include <AIS_Axis.hxx>
65 #include <AIS_Plane.hxx>
66 #include <AIS_Point.hxx>
67 #endif
68 #include <AIS_Selection.hxx>
69 #include <Prs3d_Drawer.hxx>
70 #include <Prs3d_IsoAspect.hxx>
71 #include <SelectMgr_ListOfFilter.hxx>
72 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
73 #include <SelectMgr_SelectionManager.hxx>
74 #include <TColStd_ListIteratorOfListOfInteger.hxx>
75
76 #include <StdSelect_ViewerSelector3d.hxx>
77
78 #include <TColStd_MapOfTransient.hxx>
79 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
80
81 #ifdef TINSPECTOR
82 #include <inspector/VInspectorAPI_CallBack.hxx>
83 #endif
84
85 #include <Events_Loop.h>
86 #include <ModelAPI_Events.h>
87 #include <Config_PropManager.h>
88
89 #include <set>
90
91 /// defines the local context mouse selection sensitivity
92 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
93
94 //#define DEBUG_DISPLAY
95 //#define DEBUG_FEATURE_REDISPLAY
96 //#define DEBUG_SELECTION_FILTERS
97
98 //#define DEBUG_OCCT_SHAPE_SELECTION
99
100 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
101
102 //#define DEBUG_VIEWER_BLOCKED_COUNT
103
104 //**************************************************************
105 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
106 {
107   // Get from null point
108   theAIS->DisplayedObjects(theList, true);
109 }
110
111 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
112 {
113   QStringList anInfo;
114   QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
115   for (; anIt != aLast; anIt++) {
116     anInfo.append(QString::number(*anIt));
117   }
118   return anInfo.join(theSeparator);
119 }
120
121 //**************************************************************
122 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
123 : myWorkshop(theWorkshop), myNeedUpdate(false),
124   myViewerBlockedRecursiveCount(0), myContextId(0)
125 {
126 }
127
128 //**************************************************************
129 XGUI_Displayer::~XGUI_Displayer()
130 {
131 }
132
133 //**************************************************************
134 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
135 {
136   return myResult2AISObjectMap.contains(theObject);
137 }
138
139 //**************************************************************
140 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
141 {
142   bool aDisplayed = false;
143   if (isVisible(theObject)) {
144     aDisplayed = redisplay(theObject, theUpdateViewer);
145   } else {
146     AISObjectPtr anAIS;
147     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
148     bool isShading = false;
149     if (aPrs.get() != NULL) {
150       GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast<GeomAPI_IScreenParams>(theObject);
151       if (aScreen.get()) {
152         aScreen->setScreenPlane(getScreenPlane());
153         aScreen->setViewScale(getViewScale());
154       }
155       anAIS = aPrs->getAISObject(anAIS);
156     } else {
157       anAIS = myWorkshop->module()->createPresentation(theObject);
158       isShading = true;
159     }
160     if (anAIS.get())
161       aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
162   }
163   return aDisplayed;
164 }
165
166
167 //**************************************************************
168 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
169 {
170   Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
171   if (!aShapePrs.IsNull()) {
172     TopoDS_Shape aShape = aShapePrs->Shape();
173     if (aShape.IsNull())
174       return false;
175     TopAbs_ShapeEnum aType = aShape.ShapeType();
176     if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
177       return false;
178     else {
179       // Check that the presentation is not a sketch
180       return theModule->canBeShaded(theAIS);
181     }
182   }
183   return false;
184 }
185
186 //**************************************************************
187 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
188                              bool isShading, bool theUpdateViewer)
189 {
190   bool aDisplayed = false;
191
192   Handle(AIS_InteractiveContext) aContext = AISContext();
193   if (aContext.IsNull())
194     return aDisplayed;
195
196   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
197   if (!anAISIO.IsNull()) {
198     appendResultObject(theObject, theAIS);
199
200     //bool isCustomized = customizeObject(theObject);
201
202     int aDispMode = isShading? Shading : Wireframe;
203     if (isShading)
204       anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
205     anAISIO->SetDisplayMode(aDispMode);
206     aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
207     #ifdef TINSPECTOR
208     if (getCallBack()) getCallBack()->Display(anAISIO);
209     #endif
210     aDisplayed = true;
211
212     emit objectDisplayed(theObject, theAIS);
213     selectionActivate()->activate(anAISIO, theUpdateViewer);
214   }
215   if (theUpdateViewer)
216     updateViewer();
217
218   return aDisplayed;
219 }
220
221 //**************************************************************
222 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
223 {
224   bool aErased = false;
225   if (!isVisible(theObject))
226     return aErased;
227
228   Handle(AIS_InteractiveContext) aContext = AISContext();
229   if (aContext.IsNull())
230     return aErased;
231
232   AISObjectPtr anObject = myResult2AISObjectMap.value(theObject);
233   if (anObject) {
234     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
235     if (!anAIS.IsNull()) {
236       emit beforeObjectErase(theObject, anObject);
237       aContext->Remove(anAIS, false/*update viewer*/);
238       #ifdef TINSPECTOR
239       if (getCallBack()) getCallBack()->Remove(anAIS);
240       #endif
241       aErased = true;
242     }
243   }
244   myResult2AISObjectMap.remove(theObject);
245
246 #ifdef DEBUG_DISPLAY
247   std::ostringstream aPtrStr;
248   aPtrStr << theObject.get();
249   qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
250   qDebug(getResult2AISObjectMapInfo().c_str());
251 #endif
252
253   if (theUpdateViewer)
254     updateViewer();
255
256   return aErased;
257 }
258
259 //**************************************************************
260 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
261 {
262   bool aRedisplayed = false;
263   Handle(AIS_InteractiveContext) aContext = AISContext();
264   if (aContext.IsNull())
265     return aRedisplayed;
266
267   if (!isVisible(theObject))
268     return aRedisplayed;
269
270   AISObjectPtr aAISObj = getAISObject(theObject);
271   Handle(AIS_InteractiveObject) aAISIO;
272
273   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
274   if (aPrs) {
275     GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast<GeomAPI_IScreenParams>(theObject);
276     if (aScreen.get()) {
277       aScreen->setScreenPlane(getScreenPlane());
278       aScreen->setViewScale(getViewScale());
279     }
280     AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
281     if (!aAIS_Obj) {
282       aRedisplayed = erase(theObject, theUpdateViewer);
283       return aRedisplayed;
284     }
285     if (aAIS_Obj != aAISObj) {
286       erase(theObject, theUpdateViewer);
287       appendResultObject(theObject, aAIS_Obj);
288     }
289     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
290   }
291   else {
292     aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
293   }
294
295   if (!aAISIO.IsNull()) {
296     // Check that the visualized shape is the same and the redisplay is not necessary
297     // Redisplay of AIS object leads to this object selection compute and the selection
298     // in the browser is lost
299     // this check is not necessary anymore because the selection store/restore is realized
300     // before and after the values modification.
301     // Moreother, this check avoids customize and redisplay presentation if the presentable
302     // parameter is changed.
303     //bool isEqualShapes = false;
304     //ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
305     //if (aResult.get() != NULL) {
306     //  Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
307     //  if (!aShapePrs.IsNull()) {
308     //    std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
309     //    if (aShapePtr.get()) {
310     //      const TopoDS_Shape& aOldShape = aShapePrs->Shape();
311     //      if (!aOldShape.IsNull())
312     //        isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
313     //    }
314     //  }
315     //}
316     // Customization of presentation
317     //bool isCustomized = customizeObject(theObject);
318     #ifdef DEBUG_FEATURE_REDISPLAY
319       qDebug(QString("Redisplay: %1, isEqualShapes=%2").
320         arg(!isEqualShapes/* || isCustomized*/).arg(isEqualShapes)
321         .toStdString().c_str());
322     #endif
323     //if (!isEqualShapes/* || isCustomized*/) {
324     //  /// if shapes are equal and presentation are customized, selection should be restored
325     //  bool aNeedToRestoreSelection = isEqualShapes/* && isCustomized*/;
326     //  if (aNeedToRestoreSelection)
327       if (aAISObj.get() && myWorkshop->facesPanel())
328         myWorkshop->facesPanel()->customizeObject(theObject, aAISObj);
329
330     myWorkshop->module()->storeSelection();
331
332 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
333     myWorkshop->selector()->deselectPresentation(aAISIO);
334 #endif
335     if (aContext->IsDisplayed(aAISIO))
336       aContext->Redisplay(aAISIO, false);
337     else {
338       aContext->Display(aAISIO, false);
339     }
340       #ifdef TINSPECTOR
341       if (getCallBack()) getCallBack()->Redisplay(aAISIO);
342       #endif
343
344       //if (aNeedToRestoreSelection)
345     myWorkshop->module()->restoreSelection();
346
347     aRedisplayed = true;
348     #ifdef DEBUG_FEATURE_REDISPLAY
349       qDebug("  Redisplay happens");
350     #endif
351     if (theUpdateViewer)
352       updateViewer();
353   }
354   return aRedisplayed;
355 }
356
357 //**************************************************************
358 void XGUI_Displayer::redisplayObjects()
359 {
360   // redisplay objects visualized in the viewer
361   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
362   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
363   QObjectPtrList aDisplayed = displayedObjects();
364   QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
365   for (; anIt != aLast; anIt++) {
366     aECreator->sendUpdated(*anIt, EVENT_DISP);
367   }
368   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
369   if (aViewer->isColorScaleVisible()) {
370     aViewer->setupColorScale();
371     aViewer->setColorScaleShown(true);
372   }
373   Events_Loop::loop()->flush(EVENT_DISP);
374 }
375
376 //**************************************************************
377 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
378                                        const bool theUpdateViewer)
379 {
380   //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
381   //if (!aTrihedron.IsNull())
382   //  deactivateAIS(aTrihedron);
383
384   QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
385   for (; anIt != aLast; anIt++) {
386     selectionActivate()->deactivate(*anIt, false);
387   }
388   //VSV It seems that there is no necessity to update viewer on deactivation
389   //if (theUpdateViewer)
390   //  updateViewer();
391 }
392
393 //**************************************************************
394 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
395 {
396   bool aVisible = false;
397   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
398   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
399   if (aPrs.get() || aResult.get()) {
400     aVisible = theDisplayer->isVisible(theObject);
401     // compsolid is not visualized in the viewer,
402     // but should have presentation when all sub solids are
403     // visible. It is useful for highlight presentation where compsolid shape is selectable
404     if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) {
405       ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
406       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
407         int aNumberOfSubs = aCompsolidResult->numberOfSubs();
408         bool anAllSubsVisible = aNumberOfSubs > 0;
409         for(int i = 0; i < aNumberOfSubs && anAllSubsVisible; i++) {
410           anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
411         }
412         aVisible = anAllSubsVisible;
413       }
414     }
415   }
416   // it is possible that feature is presentable and has results, so we should check visibility
417   // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
418   if (!aVisible) {
419     // check if all results of the feature are visible
420     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
421     std::list<ResultPtr> aResults;
422     ModelAPI_Tools::allResults(aFeature, aResults);
423     std::list<ResultPtr>::const_iterator aIt;
424     aVisible = !aResults.empty();
425     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
426       aVisible = aVisible && theDisplayer->isVisible(*aIt);
427     }
428   }
429   return aVisible;
430 }
431
432 //**************************************************************
433 void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrsPtr>& theValues,
434                                  bool theUpdateViewer)
435 {
436   Handle(AIS_InteractiveContext) aContext = AISContext();
437   if (aContext.IsNull())
438     return;
439   aContext->UnhilightSelected(false);
440   aContext->ClearSelected(false);
441   #ifdef TINSPECTOR
442   if (getCallBack()) getCallBack()->ClearSelected();
443   #endif
444   NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
445     aShapesToBeSelected;
446
447   foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
448     const GeomShapePtr& aGeomShape = aPrs->shape();
449     if (aGeomShape.get() && !aGeomShape->isNull()) {
450       const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
451 #ifdef DEBUG_OCCT_SHAPE_SELECTION
452       // problem 1: performance
453       // problem 2: IO is not specified, so the first found owner is selected, as a result
454       // it might belong to another result
455       aContext->AddOrRemoveSelected(aShape, false);
456       #ifdef TINSPECTOR
457       if (getCallBack()) getCallBack()->AddOrRemoveSelected(aShape);
458       #endif
459 #else
460       NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
461       if (aShapesToBeSelected.IsBound(aShape))
462         aPresentations = aShapesToBeSelected.Find(aShape);
463       ObjectPtr anObject = aPrs->object();
464       getPresentations(anObject, aPresentations);
465
466       aShapesToBeSelected.Bind(aShape, aPresentations);
467 #endif
468     } else {
469       ObjectPtr anObject = aPrs->object();
470       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
471       if (aResult.get() && isVisible(aResult)) {
472         AISObjectPtr anObj = myResult2AISObjectMap.value(aResult);
473         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
474         if (!anAIS.IsNull()) {
475           // The methods are replaced in order to provide multi-selection, e.g. restore selection
476           // by activating multi selector widget. It also gives an advantage that the multi
477           // selection in OB gives multi-selection in the viewer
478           //aContext->SetSelected(anAIS, false);
479           // The selection in the context was cleared, so the method sets the objects are selected
480           aContext->AddOrRemoveSelected(anAIS, false);
481           #ifdef TINSPECTOR
482           if (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
483           #endif
484         }
485       }
486     }
487   }
488   if (!aShapesToBeSelected.IsEmpty())
489     XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
490
491   if (theUpdateViewer)
492     updateViewer();
493 }
494
495 //**************************************************************
496 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
497 {
498   Handle(AIS_InteractiveContext) aContext = AISContext();
499   if (!aContext.IsNull()) {
500     aContext->UnhilightSelected(false);//UnhilightCurrents(false);
501     aContext->ClearSelected(theUpdateViewer);
502     #ifdef TINSPECTOR
503     if (getCallBack()) getCallBack()->ClearSelected();
504     #endif
505   }
506 }
507
508 //**************************************************************
509 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
510 {
511   bool aErased = false;
512   Handle(AIS_InteractiveContext) aContext = AISContext();
513   if (!aContext.IsNull()) {
514 #ifdef OPTIMIZE_PRS
515     foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) {
516       AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
517 #else
518     foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) {
519       AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
520 #endif
521       // erase an object
522       Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
523       if (!anIO.IsNull()) {
524         emit beforeObjectErase(aObj, aAISObj);
525         aContext->Remove(anIO, false/*update viewer*/);
526         #ifdef TINSPECTOR
527         if (getCallBack()) getCallBack()->Remove(anIO);
528         #endif
529         aErased = true;
530       }
531     }
532     if (theUpdateViewer)
533       updateViewer();
534   }
535   myResult2AISObjectMap.clear();
536 #ifdef DEBUG_DISPLAY
537   qDebug("eraseAll");
538   qDebug(getResult2AISObjectMapInfo().c_str());
539 #endif
540   return aErased;
541 }
542
543
544 //**************************************************************
545 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
546 {
547 #ifdef OPTIMIZE_PRS
548   return myResult2AISObjectMap.value(theObject);
549 #else
550   AISObjectPtr anIO;
551   if (myResult2AISObjectMap.contains(theObject))
552     anIO = myResult2AISObjectMap[theObject];
553   return anIO;
554 #endif
555 }
556
557 //**************************************************************
558 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
559 {
560   Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
561   return getObject(aRefAIS);
562 }
563
564 //**************************************************************
565 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
566 {
567 #ifdef OPTIMIZE_PRS
568   ObjectPtr anObject = myResult2AISObjectMap.value(theIO);
569 #else
570   ObjectPtr anObject;
571   ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin();
572   for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) {
573     const AISObjectPtr& aAIS = aMapIter.value();
574     Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
575     if (anAIS == theIO)
576       anObject = aMapIter.key();
577     if (anObject.get())
578       break;
579   }
580 #endif
581   if (!anObject.get()) {
582     std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
583     if (!theIO.IsNull()) {
584       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
585     }
586     anObject = myWorkshop->module()->findPresentedObject(anAISObj);
587   }
588   return anObject;
589 }
590
591 //**************************************************************
592 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
593 {
594   bool aWasEnabled = isUpdateEnabled();
595   if (isEnabled)
596     myViewerBlockedRecursiveCount--;
597   else
598     myViewerBlockedRecursiveCount++;
599
600 #ifdef DEBUG_VIEWER_BLOCKED_COUNT
601   std::cout << "myViewerBlockedRecursiveCount = " << myViewerBlockedRecursiveCount << std::endl;
602 #endif
603
604   if (myNeedUpdate && isUpdateEnabled()) {
605     updateViewer();
606     myNeedUpdate = false;
607   }
608   return aWasEnabled;
609 }
610
611 //**************************************************************
612 void XGUI_Displayer::updateViewer() const
613 {
614   Handle(AIS_InteractiveContext) aContext = AISContext();
615
616 #ifdef DEBUG_VIEWER_BLOCKED_COUNT
617   std::cout << "updateViewer: " << (myViewerBlockedRecursiveCount == 0 ? " done" : " later")
618             << std::endl;
619 #endif
620
621   if (!aContext.IsNull() && isUpdateEnabled()) {
622     //myWorkshop->viewer()->Zfitall();
623     aContext->UpdateCurrentViewer();
624   } else {
625     myNeedUpdate = true;
626   }
627 }
628
629 //**************************************************************
630 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
631 {
632   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
633   if (!aContext.IsNull() && (myContextId != aContext.get())) {
634     myContextId = aContext.get();
635     if (!myWorkshop->selectionActivate()->isTrihedronActive())
636       selectionActivate()->deactivateTrihedron(true);
637     aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
638     aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
639
640     //Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
641     //aTrihedron->getHighlightPointAspect()->SetScale(2.0);
642     //aTrihedron->getHighlightPointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
643
644     // Commented out according to discussion in bug #2825
645     //ModuleBase_IViewer::DefaultHighlightDrawer = aContext->HighlightStyle();
646     //Handle(Prs3d_Drawer) aSelStyle = aContext->SelectionStyle();
647     //double aDeflection =
648     //  QString(ModelAPI_ResultConstruction::DEFAULT_DEFLECTION().c_str()).toDouble();
649     //try {
650     //  aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
651     //} catch (...) {}
652
653     //ModuleBase_IViewer::DefaultHighlightDrawer->SetDeviationCoefficient(aDeflection);
654     //aSelStyle->SetDeviationCoefficient(aDeflection);
655   }
656   return aContext;
657 }
658
659 //**************************************************************
660 void XGUI_Displayer::setSelectionColor(const std::vector<int>& theColor)
661 {
662   Handle(AIS_InteractiveContext) aContext = AISContext();
663   if (!aContext.IsNull()) {
664     Quantity_Color aQColor(theColor[0] / 255.,
665                            theColor[1] / 255.,
666                            theColor[2] / 255., Quantity_TOC_RGB);
667     aContext->SelectionStyle()->SetColor(aQColor);
668     aContext->SelectionStyle()->PointAspect()->SetColor(aQColor);
669     aContext->SelectionStyle()->LineAspect()->SetColor(aQColor);
670     aContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor(aQColor);
671   }
672 }
673
674
675 //**************************************************************
676 std::vector<int> XGUI_Displayer::selectionColor() const
677 {
678   std::vector<int> aColor;
679   Handle(AIS_InteractiveContext) aContext = AISContext();
680   if (!aContext.IsNull()) {
681     Quantity_Color aQColor = aContext->SelectionStyle()->Color();
682     aColor.push_back((int)(aQColor.Red() * 255));
683     aColor.push_back((int)(aQColor.Green() * 255));
684     aColor.push_back((int)(aQColor.Blue() * 255));
685   }
686   return aColor;
687 }
688
689
690 //**************************************************************
691 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
692 {
693   Handle(AIS_InteractiveContext) aContext = AISContext();
694   if (!aContext.IsNull() && myAndFilter.IsNull()) {
695     myAndFilter = new SelectMgr_AndFilter();
696     aContext->AddFilter(myAndFilter);
697   }
698   return myAndFilter;
699 }
700
701 //**************************************************************
702 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
703                                 const Standard_Integer theDisplayMode, bool theUpdateViewer)
704 {
705   bool aDisplayed = false;
706   Handle(AIS_InteractiveContext) aContext = AISContext();
707   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
708   if (!aContext.IsNull() && !anAISIO.IsNull()) {
709     aContext->Display(anAISIO, theDisplayMode, 0, false/*update viewer*/, true, AIS_DS_Displayed);
710     #ifdef TINSPECTOR
711     if (getCallBack()) getCallBack()->Display(anAISIO);
712     #endif
713     aDisplayed = true;
714     aContext->Deactivate(anAISIO);
715     #ifdef TINSPECTOR
716     if (getCallBack()) getCallBack()->Deactivate(anAISIO);
717     #endif
718     aContext->Load(anAISIO);
719     #ifdef TINSPECTOR
720     if (getCallBack()) getCallBack()->Load(anAISIO);
721     #endif
722     if (toActivateInSelectionModes)
723       myWorkshop->selectionActivate()->activateOnDisplay(anAISIO, theUpdateViewer);
724
725     if (theUpdateViewer)
726       updateViewer();
727   }
728   return aDisplayed;
729 }
730
731 //**************************************************************
732 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
733 {
734   bool aErased = false;
735   Handle(AIS_InteractiveContext) aContext = AISContext();
736   if (!aContext.IsNull()) {
737     Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
738     if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
739       aContext->Remove(anAISIO, false/*update viewer*/);
740       #ifdef TINSPECTOR
741       if (getCallBack()) getCallBack()->Remove(anAISIO);
742       #endif
743       aErased = true;
744     }
745   }
746   if (aErased && theUpdateViewer)
747     updateViewer();
748   return aErased;
749 }
750
751 //**************************************************************
752 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
753 {
754   if (theMode == NoMode)
755     return;
756
757   Handle(AIS_InteractiveContext) aContext = AISContext();
758   if (aContext.IsNull())
759     return;
760
761   AISObjectPtr aAISObj = getAISObject(theObject);
762   if (!aAISObj)
763     return;
764
765   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
766   aContext->SetDisplayMode(aAISIO, theMode, false);
767   // Redisplay in order to update new mode because it could be not computed before
768   if (theUpdateViewer)
769     updateViewer();
770 }
771
772 //**************************************************************
773 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
774 {
775   Handle(AIS_InteractiveContext) aContext = AISContext();
776   if (aContext.IsNull())
777     return NoMode;
778
779   AISObjectPtr aAISObj = getAISObject(theObject);
780   if (!aAISObj)
781     return NoMode;
782
783   Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
784   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
785 }
786
787 //**************************************************************
788 void XGUI_Displayer::deactivateSelectionFilters(const bool theAddFilterOnly)
789 {
790   Handle(AIS_InteractiveContext) aContext = AISContext();
791   if (!myAndFilter.IsNull()) {
792     bool aFound = false;
793     if (!aContext.IsNull()) {
794       const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
795       SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
796       for (; anIt.More() && !aFound; anIt.Next()) {
797         Handle(SelectMgr_Filter) aFilter = anIt.Value();
798         aFound = aFilter == myAndFilter;
799       }
800       if (aFound)
801         aContext->RemoveFilter(myAndFilter);
802     }
803     myAndFilter.Nullify();
804   }
805 }
806
807 //**************************************************************
808 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
809 {
810   Handle(AIS_InteractiveContext) aContext = AISContext();
811   if (aContext.IsNull() || hasSelectionFilter(theFilter))
812     return;
813
814   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
815   if (!aCompositeFilter.IsNull()) {
816     aCompositeFilter->Add(theFilter);
817 #ifdef DEBUG_SELECTION_FILTERS
818     int aCount = aCompositeFilter->StoredFilters().Extent();
819     qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
820 #endif
821   }
822 }
823
824 //**************************************************************
825 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
826 {
827   Handle(AIS_InteractiveContext) aContext = AISContext();
828   if (aContext.IsNull())
829     return;
830
831   Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
832   if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
833     aCompositeFilter->Remove(theFilter);
834 #ifdef DEBUG_SELECTION_FILTERS
835     int aCount = aCompositeFilter->StoredFilters().Extent();
836     qDebug(QString("removeSelectionFilter: filters.count() = %1")
837       .arg(aCount).toStdString().c_str());
838 #endif
839   }
840 }
841
842 //**************************************************************
843 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
844 {
845   bool aFilterFound = false;
846
847   Handle(AIS_InteractiveContext) aContext = AISContext();
848   if (aContext.IsNull())
849     return aFilterFound;
850   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
851   SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
852   for (; aIt.More() && !aFilterFound; aIt.Next()) {
853     if (theFilter.get() == aIt.Value().get())
854       aFilterFound = true;
855   }
856   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
857   if (!aCompositeFilter.IsNull()) {
858     const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
859     for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
860       if (theFilter.get() == aIt.Value().get())
861         aFilterFound = true;
862     }
863   }
864   return aFilterFound;
865 }
866
867 //**************************************************************
868 void XGUI_Displayer::removeFilters()
869 {
870   Handle(AIS_InteractiveContext) aContext = AISContext();
871   if (aContext.IsNull())
872     return;
873
874   Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
875   if (!aCompositeFilter.IsNull())
876     aCompositeFilter->Clear();
877 }
878
879 //**************************************************************
880 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
881 {
882 #ifdef OPTIMIZE_PRS
883   QObjectPtrList aDispList = myResult2AISObjectMap.objects();
884 #else
885   QObjectPtrList aDispList = myResult2AISObjectMap.keys();
886 #endif
887   foreach(ObjectPtr aObj, aDispList) {
888     if (!theList.contains(aObj))
889       erase(aObj, false);
890   }
891   foreach(ObjectPtr aObj, theList) {
892     if (!isVisible(aObj))
893       display(aObj, false);
894   }
895   updateViewer();
896 }
897
898 //**************************************************************
899 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
900 {
901   if (!isVisible(theObject))
902     return false;
903
904   AISObjectPtr aAISObj = getAISObject(theObject);
905   if (aAISObj.get() == NULL)
906     return false;
907
908   Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
909   return ::canBeShaded(anAIS, myWorkshop->module());
910 }
911
912 //**************************************************************
913 //bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
914 //{
915 //  AISObjectPtr anAISObj = getAISObject(theObject);
916 //  // correct the result's color it it has the attribute
917 //  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
918 //
919 //  // Customization of presentation
920 //  GeomCustomPrsPtr aCustomPrs;
921 //  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
922 //  if (aFeature.get() != NULL) {
923 //    GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
924 //    if (aCustPrs.get() != NULL)
925 //      aCustomPrs = aCustPrs;
926 //  }
927 //  if (aCustomPrs.get() == NULL) {
928 //    GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
929 //    // we ignore presentable not customized objects
930 //    if (aPrs.get() == NULL)
931 //      aCustomPrs = myCustomPrs;
932 //  }
933 //  bool isCustomized = aCustomPrs.get() &&
934 //                      aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
935 //  isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
936 //                 || isCustomized;
937 //
938 //  // update presentation state if faces panel is active
939 //  if (anAISObj.get() && myWorkshop->facesPanel())
940 //    isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized;
941 //
942 //  return isCustomized;
943 //}
944
945 //**************************************************************
946 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
947                                       const QColor& theColor,
948                                       bool theUpdateViewer)
949 {
950   if (!isVisible(theObject))
951     return Qt::black;
952
953   AISObjectPtr anAISObj = getAISObject(theObject);
954   int aR, aG, aB;
955   anAISObj->getColor(aR, aG, aB);
956   anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
957   if (theUpdateViewer)
958     updateViewer();
959   return QColor(aR, aG, aB);
960 }
961
962 //**************************************************************
963 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
964 {
965 #ifdef OPTIMIZE_PRS
966   myResult2AISObjectMap.add(theObject, theAIS);
967 #else
968   myResult2AISObjectMap[theObject] = theAIS;
969 #endif
970
971 #ifdef DEBUG_DISPLAY
972   std::ostringstream aPtrStr;
973   aPtrStr << theObject.get();
974   qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
975   qDebug(getResult2AISObjectMapInfo().c_str());
976 #endif
977 }
978
979 #ifdef _DEBUG
980 //**************************************************************
981 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
982 {
983   QStringList aContent;
984 #ifdef OPTIMIZE_PRS
985   foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) {
986     AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
987 #else
988   foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) {
989     AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
990 #endif
991     std::ostringstream aPtrStr;
992     aPtrStr << "aObj = " << aObj.get() << ":";
993     aPtrStr << "anAIS = " << aAISObj.get() << ":";
994     aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
995
996     aContent.append(aPtrStr.str().c_str());
997   }
998   return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
999                                             arg(aContent.join("\n")).toStdString().c_str();
1000 }
1001 #endif
1002
1003 //**************************************************************
1004 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1005                                   NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1006 {
1007   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1008   if (aResult.get()) {
1009     AISObjectPtr aAISObj = getAISObject(aResult);
1010     if (aAISObj.get() == NULL) {
1011       // if result is a result of a composite feature, it is visualized by visualization of
1012       // composite children, so we should get one of this presentations
1013       ResultBodyPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
1014       if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
1015         aAISObj = getAISObject(aCompSolid->subResult(0));
1016       }
1017     }
1018     if (aAISObj.get() != NULL) {
1019       Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1020       if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1021         thePresentations.Add(anAIS);
1022     }
1023   }
1024   else {
1025     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1026     // find presentation of the feature
1027     AISObjectPtr aAISObj = getAISObject(aFeature);
1028     if (aAISObj.get() != NULL) {
1029       Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1030       if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1031         thePresentations.Add(anAIS);
1032     }
1033     // find presentations of the feature results
1034     std::list<ResultPtr> aResults;
1035     ModelAPI_Tools::allResults(aFeature, aResults);
1036     std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1037     for (; anIt != aLast; ++anIt) {
1038       AISObjectPtr aAISObj = getAISObject(*anIt);
1039       if (aAISObj.get() != NULL) {
1040         Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1041         if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1042           thePresentations.Add(anAIS);
1043       }
1044     }
1045   }
1046 }
1047
1048 //**************************************************************
1049 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1050 {
1051   Handle(AIS_InteractiveContext) aContext = AISContext();
1052   if (aContext.IsNull())
1053     return;
1054
1055   Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1056
1057   XGUI_SelectionActivate* aSelectionActive = selectionActivate();
1058   if (theToDisplay) {
1059     if (!aContext->IsDisplayed(aTrihedron))
1060       aContext->Display(aTrihedron,
1061                         0 /*wireframe*/,
1062                         -1 /* selection mode */,
1063                         Standard_True /* update viewer*/,
1064                         Standard_False /* allow decomposition */,
1065                         AIS_DS_Displayed /* xdisplay status */);
1066     #ifdef TINSPECTOR
1067     if (getCallBack()) getCallBack()->Display(aTrihedron);
1068     #endif
1069
1070     if (!aSelectionActive->isTrihedronActive())
1071       aSelectionActive->deactivateTrihedron(false);
1072     else
1073       aSelectionActive->activate(aTrihedron, false);
1074   } else {
1075     aSelectionActive->deactivateTrihedron(false);
1076
1077     aContext->Erase(aTrihedron, Standard_True);
1078     #ifdef TINSPECTOR
1079     if (getCallBack()) getCallBack()->Remove(aTrihedron);
1080     #endif
1081   }
1082 }
1083
1084 //**************************************************************
1085 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1086                            const NCollection_DataMap<TopoDS_Shape,
1087                            NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1088 {
1089   NCollection_Map<Handle(AIS_InteractiveObject)> aCompsolidPresentations;
1090   NCollection_Map<Handle(AIS_InteractiveObject)> aSelectedPresentations;
1091
1092   NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1093   theContext->MainSelector()->ActiveOwners(anActiveOwners);
1094   NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1095   Handle(SelectMgr_EntityOwner) anOwner;
1096
1097   /// It is very important to check that the owner is processed only once and has a map of
1098   /// processed owners because SetSelected works as a switch.
1099   /// If count of calls setSelectec is even, the object stays in the previous state
1100   /// (selected, deselected)
1101   /// OCCT: to write about the problem that active owners method returns one owner several times
1102   QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
1103   for (; anOwnersIt.More(); anOwnersIt.Next()) {
1104     anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1105     if (aSelectedIds.contains((size_t)anOwner.get()))
1106       continue;
1107     aSelectedIds.append((size_t)anOwner.get());
1108
1109     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1110     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1111       const TopoDS_Shape& aShape = BROwnr->Shape();
1112       if (aShape.IsNull())
1113         continue;
1114
1115       Handle(ModuleBase_BRepOwner) aCustomOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
1116
1117       NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)> >
1118                                              ::Iterator aShapeIt(theShapesToBeSelected);
1119       for (; aShapeIt.More(); aShapeIt.Next()) {
1120         const TopoDS_Shape& aParameterShape = aShapeIt.Key();
1121         // In case of compound we cannot rely on simple comparison method.
1122         // If the compound is generated by Group feature then this compound is alwais new.
1123         // So, we have to compare content of these compounds
1124
1125           // isSame should be used here as it does not check orientation of shapes
1126           // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
1127           // different for Edges shapes in model shape and owner even if this is the same shape
1128         if (ModuleBase_Tools::isSameShape(aParameterShape, aShape)) {
1129           Handle(AIS_InteractiveObject) anOwnerPresentation =
1130             Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1131           NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1132             theShapesToBeSelected.Find(aParameterShape);
1133           if (aPresentations.Contains(anOwnerPresentation)) {
1134             theContext->AddOrRemoveSelected(anOwner, Standard_False);
1135             anOwner->SetSelected(Standard_True);
1136             // collect selected presentations to do not select them if compsolid is selected
1137             if (!aSelectedPresentations.Contains(anOwnerPresentation))
1138               aSelectedPresentations.Add(anOwnerPresentation);
1139           }
1140         }
1141         else if (!aCustomOwner.IsNull()) { // CompSolid processing #2219
1142           // shape of owner is compound, but shape to be selected is compsolid, so
1143           // we need to compare shape to AIS presentation of owner(rule of the owner creation)
1144           Handle(AIS_Shape) anOwnerPresentation =
1145                             Handle(AIS_Shape)::DownCast(anOwner->Selectable());
1146           const TopoDS_Shape& aPresentationShape = anOwnerPresentation->Shape();
1147           if (aParameterShape.IsSame(anOwnerPresentation->Shape()) &&
1148               !aCompsolidPresentations.Contains(anOwnerPresentation))
1149             aCompsolidPresentations.Add(anOwnerPresentation);
1150         }
1151       }
1152     }
1153   }
1154   // select CompSolid presentations if their owners was not selected yet
1155   NCollection_Map<Handle(AIS_InteractiveObject)>::Iterator anIt (aCompsolidPresentations);
1156   for (; anIt.More(); anIt.Next()) {
1157     if (aSelectedPresentations.Contains(anIt.Value()))
1158       continue;
1159     theContext->AddOrRemoveSelected(anIt.Value(), Standard_False);
1160   }
1161 }
1162
1163 //**************************************************************
1164 XGUI_SelectionActivate* XGUI_Displayer::selectionActivate() const
1165 {
1166   return myWorkshop->selectionActivate();
1167 }
1168
1169 //**************************************************************
1170 GeomPlanePtr XGUI_Displayer::getScreenPlane() const
1171 {
1172   GeomPlanePtr aResult;
1173   Handle(AIS_InteractiveContext) aContext = AISContext();
1174   if (!aContext.IsNull()) {
1175     Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1176     Handle(V3d_View) aView;
1177     for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) {
1178       aView = aViewer->ActiveView();
1179       break;
1180     }
1181     if (!aView.IsNull()) {
1182       double aEyeX, aEyeY, aEyeZ;
1183       aView->Eye(aEyeX, aEyeY, aEyeZ);
1184
1185       double aProjX, aProjY, aProjZ;
1186       aView->Proj(aProjX, aProjY, aProjZ);
1187
1188       GeomPointPtr aPnt = GeomPointPtr(new GeomAPI_Pnt(aEyeX, aEyeY, aEyeZ));
1189       GeomDirPtr aDir = GeomDirPtr(new GeomAPI_Dir(aProjX, aProjY, aProjZ));
1190
1191       aResult = GeomPlanePtr(new GeomAPI_Pln(aPnt, aDir));
1192     }
1193   }
1194   return aResult;
1195 }
1196
1197 double XGUI_Displayer::getViewScale() const
1198 {
1199   Handle(AIS_InteractiveContext) aContext = AISContext();
1200   if (!aContext.IsNull()) {
1201     Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1202     Handle(V3d_View) aView;
1203     for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) {
1204       aView = aViewer->ActiveView();
1205       break;
1206     }
1207     return aView->Camera()->Scale();
1208   }
1209   return 1;
1210 }