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