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