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