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