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