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