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