1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_Displayer.cpp
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include "XGUI_Displayer.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_CustomPrs.h"
15 #include <AppElements_Viewer.h>
18 #include <ModelAPI_Document.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_Tools.h>
22 #include <ModelAPI_AttributeIntArray.h>
23 #include <ModelAPI_ResultCompSolid.h>
25 #include <ModuleBase_ResultPrs.h>
26 #include <ModuleBase_Tools.h>
27 #include <ModuleBase_IModule.h>
28 #include <ModuleBase_ViewerPrs.h>
29 #include <ModuleBase_Preferences.h>
31 #include <GeomAPI_Shape.h>
32 #include <GeomAPI_IPresentable.h>
33 #include <GeomAPI_ICustomPrs.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <AIS_InteractiveContext.hxx>
38 #include <AIS_LocalContext.hxx>
39 #include <AIS_ListOfInteractive.hxx>
40 #include <AIS_ListIteratorOfListOfInteractive.hxx>
41 #include <AIS_DimensionSelectionMode.hxx>
42 #include <AIS_Shape.hxx>
43 #include <AIS_Dimension.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Plane.hxx>
47 #include <AIS_Point.hxx>
48 #include <AIS_Selection.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
50 #include <SelectMgr_ListOfFilter.hxx>
51 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
52 #include <Prs3d_Drawer.hxx>
53 #include <Prs3d_IsoAspect.hxx>
54 #include <SelectMgr_SelectionManager.hxx>
56 #include <StdSelect_ViewerSelector3d.hxx>
58 #include <TColStd_MapOfTransient.hxx>
59 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
62 #include <VInspectorAPI_CallBack.h>
65 #include <Events_Loop.h>
66 #include <ModelAPI_Events.h>
70 /// defines the local context mouse selection sensitivity
71 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
73 //#define DEBUG_ACTIVATE_OBJECTS
74 //#define DEBUG_DEACTIVATE
75 //#define DEBUG_ACTIVATE_AIS
76 //#define DEBUG_DEACTIVATE_AIS
78 //#define DEBUG_DISPLAY
79 //#define DEBUG_FEATURE_REDISPLAY
80 //#define DEBUG_SELECTION_FILTERS
82 //#define DEBUG_COMPOSILID_DISPLAY
83 // Workaround for bug #25637
85 //#define DEBUG_OCCT_SHAPE_SELECTION
87 //#define WORKAROUND_UNTIL_27523_IS_FIXED
89 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
91 // Get from null point
92 theAIS->DisplayedObjects(theList, true);
93 if (theAIS->HasOpenedContext()) {
94 // get from local context
95 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
96 TColStd_MapOfTransient aMap;
97 int NbDisp = aLC->DisplayedObjects(aMap);
98 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
100 Handle(AIS_InteractiveObject) curIO;
101 Handle(Standard_Transient) Tr;
102 for(; aIt.More(); aIt.Next()){
104 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
105 theList.Append(curIO);
110 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
113 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
114 for (; anIt != aLast; anIt++) {
115 anInfo.append(QString::number(*anIt));
117 return anInfo.join(theSeparator);
120 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
121 : myWorkshop(theWorkshop), myNeedUpdate(false),
122 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0)
125 myContextCallBack = 0;
127 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
130 XGUI_Displayer::~XGUI_Displayer()
134 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
136 return myResult2AISObjectMap.contains(theObject);
139 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
141 bool aDisplayed = false;
142 if (isVisible(theObject)) {
143 #ifdef DEBUG_COMPOSILID_DISPLAY
144 ResultCompSolidPtr aCompsolidResult =
145 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
146 if (aCompsolidResult.get()) {
147 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
148 ResultPtr aSubResult = aCompsolidResult->subResult(i);
149 if (aSubResult.get())
150 redisplay(aSubResult, false);
157 aDisplayed = redisplay(theObject, theUpdateViewer);
160 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
161 bool isShading = false;
162 if (aPrs.get() != NULL) {
163 anAIS = aPrs->getAISObject(anAIS);
165 // correct deviation coefficient for
166 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
167 if (!anAISPrs.IsNull()) {
168 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
169 if (!aShapePrs.IsNull()) {
170 TopoDS_Shape aShape = aShapePrs->Shape();
171 if (!aShape.IsNull())
172 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
177 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
178 if (aResult.get() != NULL) {
179 #ifdef DEBUG_COMPOSILID_DISPLAY
180 ResultCompSolidPtr aCompsolidResult =
181 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
182 if (aCompsolidResult.get()) {
183 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
184 ResultPtr aSubResult = aCompsolidResult->subResult(i);
185 if (aSubResult.get())
186 display(aSubResult, false);
193 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
194 if (aShapePtr.get() != NULL) {
195 anAIS = AISObjectPtr(new GeomAPI_AISObject());
196 Handle(AIS_InteractiveObject) anAISPrs =
197 myWorkshop->module()->createPresentation(aResult);
198 if (anAISPrs.IsNull())
199 anAISPrs = new ModuleBase_ResultPrs(aResult);
201 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
202 if (!aShapePrs.IsNull())
203 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.Access());
205 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
206 //anAIS->createShape(aShapePtr);
209 #ifdef DEBUG_COMPOSILID_DISPLAY
215 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
220 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
222 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
223 if (!aShapePrs.IsNull()) {
224 TopoDS_Shape aShape = aShapePrs->Shape();
227 TopAbs_ShapeEnum aType = aShape.ShapeType();
228 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
231 // Check that the presentation is not a sketch
232 return theModule->canBeShaded(theAIS);
238 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
239 bool isShading, bool theUpdateViewer)
241 bool aDisplayed = false;
243 Handle(AIS_InteractiveContext) aContext = AISContext();
244 if (aContext.IsNull())
247 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
248 if (!anAISIO.IsNull()) {
249 appendResultObject(theObject, theAIS);
251 bool isCustomized = customizeObject(theObject);
253 int aDispMode = isShading? Shading : Wireframe;
255 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
256 anAISIO->SetDisplayMode(aDispMode);
257 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
259 if (myContextCallBack) myContextCallBack->Display(anAISIO);
263 emit objectDisplayed(theObject, theAIS);
264 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
272 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
274 bool aErased = false;
275 if (!isVisible(theObject))
278 Handle(AIS_InteractiveContext) aContext = AISContext();
279 if (aContext.IsNull())
282 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
284 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
285 if (!anAIS.IsNull()) {
286 emit beforeObjectErase(theObject, anObject);
287 aContext->Remove(anAIS, false/*update viewer*/);
289 if (myContextCallBack) myContextCallBack->Remove(anAIS);
294 myResult2AISObjectMap.remove(theObject);
297 std::ostringstream aPtrStr;
298 aPtrStr << theObject.get();
299 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
300 qDebug(getResult2AISObjectMapInfo().c_str());
309 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
311 bool aRedisplayed = false;
312 if (!isVisible(theObject))
315 AISObjectPtr aAISObj = getAISObject(theObject);
316 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
318 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
320 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
322 aRedisplayed = erase(theObject, theUpdateViewer);
325 if (aAIS_Obj != aAISObj) {
326 appendResultObject(theObject, aAIS_Obj);
328 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
331 Handle(AIS_InteractiveContext) aContext = AISContext();
332 if (!aContext.IsNull() && !aAISIO.IsNull()) {
333 // Check that the visualized shape is the same and the redisplay is not necessary
334 // Redisplay of AIS object leads to this object selection compute and the selection
335 // in the browser is lost
336 // this check is not necessary anymore because the selection store/restore is realized
337 // before and after the values modification.
338 // Moreother, this check avoids customize and redisplay presentation if the presentable
339 // parameter is changed.
340 bool isEqualShapes = false;
341 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
342 if (aResult.get() != NULL) {
343 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
344 if (!aShapePrs.IsNull()) {
345 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
346 if (aShapePtr.get()) {
347 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
348 if (!aOldShape.IsNull())
349 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
353 // Customization of presentation
354 bool isCustomized = customizeObject(theObject);
355 #ifdef DEBUG_FEATURE_REDISPLAY
356 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
357 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
358 .arg(isCustomized).toStdString().c_str());
360 if (!isEqualShapes || isCustomized) {
361 /// if shapes are equal and presentation are customized, selection should be restored
362 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
363 if (aNeedToRestoreSelection)
364 myWorkshop->module()->storeSelection();
366 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
367 if (!myActiveSelectionModes.contains(0))
368 aContext->Activate(aAISIO, 0);
371 aContext->Redisplay(aAISIO, false);
373 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
374 if (!myActiveSelectionModes.contains(0))
375 aContext->Deactivate(aAISIO, 0);
379 if (myContextCallBack) myContextCallBack->Redisplay(aAISIO);
382 if (aNeedToRestoreSelection)
383 myWorkshop->module()->restoreSelection();
386 #ifdef DEBUG_FEATURE_REDISPLAY
387 qDebug(" Redisplay happens");
396 void XGUI_Displayer::redisplayObjects()
398 // redisplay objects visualized in the viewer
399 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
400 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
401 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
402 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
403 for (; anIt != aLast; anIt++) {
404 aECreator->sendUpdated(*anIt, EVENT_DISP);
406 Events_Loop::loop()->flush(EVENT_DISP);
409 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
411 #ifdef DEBUG_DEACTIVATE
412 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
413 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
414 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
416 toStdString().c_str());
418 Handle(AIS_InteractiveContext) aContext = AISContext();
419 if (!aContext.IsNull() && isVisible(theObject)) {
420 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
421 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
423 deactivateAIS(anAIS);
424 // the selection from the previous activation modes should be cleared manually (#26172)
425 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
427 if (myContextCallBack) myContextCallBack->ClearOutdatedSelection(anAIS);
434 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
435 const bool theUpdateViewer)
437 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
438 //if (!aTrihedron.IsNull())
439 // deactivateAIS(aTrihedron);
441 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
442 for (; anIt != aLast; anIt++) {
443 deactivate(*anIt, false);
445 //VSV It seems that there is no necessity to update viewer on deactivation
446 //if (theUpdateViewer)
450 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
452 Handle(AIS_InteractiveContext) aContext = AISContext();
453 if (aContext.IsNull() || !isVisible(theObject))
456 AISObjectPtr aAISObj = getAISObject(theObject);
458 if (aAISObj.get() != NULL) {
459 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
460 TColStd_ListOfInteger aTColModes;
461 aContext->ActivatedModes(anAISIO, aTColModes);
462 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
463 for (; itr.More(); itr.Next() ) {
464 theModes.append(itr.Value());
469 int XGUI_Displayer::getSelectionMode(int theShapeType)
471 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
472 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
475 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
477 bool aVisible = false;
478 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
479 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
480 if (aPrs.get() || aResult.get()) {
481 aVisible = theDisplayer->isVisible(theObject);
482 // compsolid is not visualized in the viewer,
483 // but should have presentation when all sub solids are
484 // visible. It is useful for highlight presentation where compsolid shape is selectable
485 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
486 ResultCompSolidPtr aCompsolidResult =
487 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
488 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
489 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
490 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
491 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
493 aVisible = anAllSubsVisible;
497 // it is possible that feature is presentable and has results, so we should check visibility
498 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
500 // check if all results of the feature are visible
501 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
502 std::list<ResultPtr> aResults;
503 ModelAPI_Tools::allResults(aFeature, aResults);
504 std::list<ResultPtr>::const_iterator aIt;
505 aVisible = !aResults.empty();
506 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
507 aVisible = aVisible && theDisplayer->isVisible(*aIt);
513 #ifdef DEBUG_ACTIVATE_OBJECTS
514 QString getModeInfo(const int theMode)
516 QString anInfo = "Undefined";
518 case 0: anInfo = "SHAPE(0)"; break;
519 case 1: anInfo = "VERTEX(1)"; break;
520 case 2: anInfo = "EDGE(2)"; break;
521 case 3: anInfo = "WIRE(3)"; break;
522 case 4: anInfo = "FACE(4)"; break;
523 case 5: anInfo = "SHELL(5)"; break;
524 case 6: anInfo = "SOLID(6)"; break;
525 case 7: anInfo = "COMPSOLID(7)"; break;
526 case 8: anInfo = "COMPOUND(8)"; break;
527 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
528 case 101: anInfo = "Sel_Constraint(101)"; break;
529 case 102: anInfo = "Sel_Dimension_All(102)"; break;
530 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
531 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
537 QString getModesInfo(const QIntList& theModes)
539 QStringList aModesInfo;
540 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
541 aModesInfo.append(getModeInfo(theModes[i]));
542 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
546 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
547 const bool theUpdateViewer)
549 // Convert shape types to selection types
551 foreach(int aType, theModes) {
552 aModes.append(getSelectionMode(aType));
555 #ifdef DEBUG_ACTIVATE_OBJECTS
557 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
558 for (; anIt != aLast; ++anIt) {
559 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
561 QString anInfoStr = anInfo.join(", ");
563 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
564 arg(getModesInfo(aModes)).
565 arg(getModesInfo(myActiveSelectionModes)).
566 arg(theObjList.size()).
568 toStdString().c_str());
570 // In order to avoid doblications of selection modes
572 foreach (int aMode, aModes) {
573 if (!aNewModes.contains(aMode))
574 aNewModes.append(aMode);
576 myActiveSelectionModes = aNewModes;
577 Handle(AIS_InteractiveContext) aContext = AISContext();
578 // Open local context if there is no one
579 if (aContext.IsNull() || !aContext->HasOpenedContext())
582 //aContext->UseDisplayedObjects();
583 //myUseExternalObjects = true;
585 Handle(AIS_InteractiveObject) anAISIO;
586 AIS_ListOfInteractive aPrsList;
587 //if (aObjList.isEmpty())
590 foreach(ObjectPtr aObj, theObjList) {
591 if (myResult2AISObjectMap.contains(aObj))
592 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
596 // Add trihedron because it has to partisipate in selection
597 Handle(AIS_InteractiveObject) aTrihedron;
598 if (isTrihedronActive()) {
599 aTrihedron = getTrihedron();
600 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
601 aPrsList.Append(aTrihedron);
603 if (aPrsList.Extent() == 0)
606 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
607 bool isActivationChanged = false;
608 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
609 anAISIO = aLIt.Value();
610 if (activate(anAISIO, myActiveSelectionModes, false))
611 isActivationChanged = true;
615 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
617 Handle(AIS_InteractiveContext) aContext = AISContext();
618 if (aContext.IsNull() || !isVisible(theObject))
621 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
622 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
624 TColStd_ListOfInteger aModes;
625 aContext->ActivatedModes(anAIS, aModes);
627 if (myContextCallBack) myContextCallBack->ActivatedModes(anAIS, aModes);
630 return aModes.Extent() > 0;
634 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
635 bool theUpdateViewer)
637 Handle(AIS_InteractiveContext) aContext = AISContext();
638 if (aContext.IsNull())
640 if (aContext->HasOpenedContext()) {
641 aContext->UnhilightSelected(false);
642 aContext->ClearSelected(false);
644 if (myContextCallBack) myContextCallBack->ClearSelected();
646 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
649 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
650 const GeomShapePtr& aGeomShape = aPrs->shape();
651 if (aGeomShape.get() && !aGeomShape->isNull()) {
652 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
653 #ifdef DEBUG_OCCT_SHAPE_SELECTION
654 // problem 1: performance
655 // problem 2: IO is not specified, so the first found owner is selected, as a result
656 // it might belong to another result
657 aContext->AddOrRemoveSelected(aShape, false);
659 if (myContextCallBack) myContextCallBack->AddOrRemoveSelected(aShape);
662 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
663 if (aShapesToBeSelected.IsBound(aShape))
664 aPresentations = aShapesToBeSelected.Find(aShape);
665 ObjectPtr anObject = aPrs->object();
666 getPresentations(anObject, aPresentations);
668 aShapesToBeSelected.Bind(aShape, aPresentations);
671 ObjectPtr anObject = aPrs->object();
672 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
673 if (aResult.get() && isVisible(aResult)) {
674 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
675 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
676 if (!anAIS.IsNull()) {
677 // The methods are replaced in order to provide multi-selection, e.g. restore selection
678 // by activating multi selector widget. It also gives an advantage that the multi
679 // selection in OB gives multi-selection in the viewer
680 //aContext->SetSelected(anAIS, false);
681 // The selection in the context was cleared, so the method sets the objects are selected
682 aContext->AddOrRemoveSelected(anAIS, false);
684 if (myContextCallBack) myContextCallBack->AddOrRemoveSelected(anAIS);
690 if (!aShapesToBeSelected.IsEmpty())
691 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
692 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
693 aContext->UnhilightCurrents(false);
694 aContext->ClearCurrents(false);
695 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
696 ObjectPtr anObject = aPrs->object();
697 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
698 if (aResult.get() && isVisible(aResult)) {
699 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
700 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
702 aContext->SetCurrentObject(anAIS, false);
710 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
712 Handle(AIS_InteractiveContext) aContext = AISContext();
713 if (!aContext.IsNull()) {
714 aContext->UnhilightCurrents(false);
715 aContext->ClearSelected(theUpdateViewer);
717 if (myContextCallBack) myContextCallBack->ClearSelected();
722 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
724 bool aErased = false;
725 Handle(AIS_InteractiveContext) aContext = AISContext();
726 if (!aContext.IsNull()) {
727 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
728 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
730 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
731 if (!anIO.IsNull()) {
732 emit beforeObjectErase(aObj, aAISObj);
733 aContext->Remove(anIO, false/*update viewer*/);
735 if (myContextCallBack) myContextCallBack->Remove(anIO);
743 myResult2AISObjectMap.clear();
746 qDebug(getResult2AISObjectMapInfo().c_str());
751 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
752 Handle(AIS_InteractiveObject) theObject,
754 VInspectorAPI_CallBack* theCallBack,
756 const bool theClear = true)
758 if (!theObject.IsNull()) {
759 theContext->Deactivate(theObject);
761 if (theCallBack) theCallBack->Deactivate(theObject);
764 //theObject->ClearSelected();
765 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
770 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
772 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
773 Handle(AIS_InteractiveContext) aContext = AISContext();
774 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
775 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
776 deactivateObject(aContext, aTrie
782 /// #1136 hidden axis are selected in sketch
783 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
784 /// for Position AIS object in SelectionModes.
785 deactivateObject(aContext, aTrie->XAxis()
790 deactivateObject(aContext, aTrie->YAxis()
795 deactivateObject(aContext, aTrie->Axis()
800 deactivateObject(aContext, aTrie->Position()
806 deactivateObject(aContext, aTrie->XYPlane()
811 deactivateObject(aContext, aTrie->XZPlane()
816 deactivateObject(aContext, aTrie->YZPlane()
827 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
829 return myWorkshop->viewer()->trihedron();
832 void XGUI_Displayer::openLocalContext()
834 Handle(AIS_InteractiveContext) aContext = AISContext();
835 // Open local context if there is no one
836 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
837 // Preserve selected objects
838 //AIS_ListOfInteractive aAisList;
839 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
840 // aAisList.Append(aContext->Current());
842 // get the filters from the global context and append them to the local context
843 // a list of filters in the global context is not cleared and should be cleared here
844 SelectMgr_ListOfFilter aFilters;
845 aFilters.Assign(aContext->Filters());
846 // it is important to remove the filters in the global context, because there is a code
847 // in the closeLocalContex, which restore the global context filters
848 aContext->RemoveFilters();
850 //aContext->ClearCurrents();
851 aContext->OpenLocalContext();
852 //deactivateTrihedron();
853 //aContext->NotUseDisplayedObjects();
855 //myUseExternalObjects = false;
857 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
858 for (;aIt.More(); aIt.Next()) {
859 aContext->AddFilter(aIt.Value());
862 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
863 //for(; aIt2.More(); aIt2.Next()) {
864 // aContext->SetSelected(aIt2.Value(), false);
869 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
871 Handle(AIS_InteractiveContext) aContext = AISContext();
872 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
873 // Preserve selected objects
874 //AIS_ListOfInteractive aAisList;
875 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
876 // aAisList.Append(aContext->SelectedInteractive());
878 // get the filters from the local context and append them to the global context
879 // a list of filters in the local context is cleared
880 SelectMgr_ListOfFilter aFilters;
881 aFilters.Assign(aContext->Filters());
883 //aContext->ClearSelected();
884 aContext->CloseAllContexts(false);
886 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
887 // this code is obsolete. It is temporaty commented and should be removed after
888 // the test campaign.
889 // Redisplay all object if they were displayed in localContext
890 /*Handle(AIS_InteractiveObject) aAISIO;
891 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
892 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
893 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
894 aContext->Display(aAISIO, false);
895 aContext->SetDisplayMode(aAISIO, Shading, false);
899 // Append the filters from the local selection in the global selection context
900 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
901 for (;aIt.More(); aIt.Next()) {
902 Handle(SelectMgr_Filter) aFilter = aIt.Value();
903 aContext->AddFilter(aFilter);
908 //myUseExternalObjects = false;
911 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
912 //for(; aIt2.More(); aIt2.Next()) {
913 // if (aContext->IsDisplayed(aIt2.Value()))
914 // aContext->SetCurrentObject(aIt2.Value(), false);
919 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
922 if (myResult2AISObjectMap.contains(theObject))
923 anIO = myResult2AISObjectMap[theObject];
927 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
929 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
930 return getObject(aRefAIS);
933 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
936 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
937 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
938 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
944 if (!anObject.get()) {
945 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
946 if (!theIO.IsNull()) {
947 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
949 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
954 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
956 bool aWasEnabled = isUpdateEnabled();
958 myViewerBlockedRecursiveCount--;
960 myViewerBlockedRecursiveCount++;
962 if (myNeedUpdate && isUpdateEnabled()) {
964 myNeedUpdate = false;
969 bool XGUI_Displayer::isUpdateEnabled() const
971 return myViewerBlockedRecursiveCount == 0;
974 void XGUI_Displayer::updateViewer() const
976 Handle(AIS_InteractiveContext) aContext = AISContext();
977 if (!aContext.IsNull() && isUpdateEnabled()) {
978 myWorkshop->viewer()->Zfitall();
979 aContext->UpdateCurrentViewer();
985 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
986 const int theMode, const bool theUpdateViewer) const
988 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
989 if (!theIO.IsNull() && theIO == getTrihedron()) {
990 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
991 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
994 if (!aContext.IsNull()) {
995 if (myWorkshop->module()) {
996 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
997 aContext->Activate(theIO, theMode, false);
999 aContext->Activate(theIO, theMode, false);
1001 if (myContextCallBack) myContextCallBack->Activate(theIO, theMode);
1004 // the fix from VPA for more suitable selection of sketcher lines
1005 if (theIO->Width() > 1) {
1006 double aPrecision = theIO->Width() + 2;
1007 if (theMode == getSelectionMode(TopAbs_VERTEX))
1008 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1009 "point-selection-sensitivity",
1011 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
1012 (theMode == getSelectionMode(TopAbs_WIRE)))
1013 aPrecision = theIO->Width() +
1014 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1015 "edge-selection-sensitivity", 2);
1016 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
1019 #ifdef DEBUG_ACTIVATE_AIS
1020 ObjectPtr anObject = getObject(theIO);
1021 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1022 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1023 .arg(anInfo).toStdString().c_str());
1025 if (theUpdateViewer)
1030 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1031 const int theMode) const
1033 Handle(AIS_InteractiveContext) aContext = AISContext();
1034 if (!aContext.IsNull()) {
1035 if (theMode == -1) {
1036 aContext->Deactivate(theIO);
1038 if (myContextCallBack) myContextCallBack->Deactivate(theIO);
1042 aContext->Deactivate(theIO, theMode);
1044 if (myContextCallBack) myContextCallBack->Deactivate(theIO, theMode);
1048 #ifdef DEBUG_DEACTIVATE_AIS
1049 ObjectPtr anObject = getObject(theIO);
1050 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1051 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1052 .arg(anInfo).toStdString().c_str());
1057 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1059 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1060 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
1061 aContext->OpenLocalContext();
1062 if (!isTrihedronActive())
1063 deactivateTrihedron(true);
1064 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1065 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1070 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1072 Handle(AIS_InteractiveContext) aContext = AISContext();
1073 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1074 myAndFilter = new SelectMgr_AndFilter();
1075 aContext->AddFilter(myAndFilter);
1080 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1081 bool theUpdateViewer)
1083 bool aDisplayed = false;
1084 Handle(AIS_InteractiveContext) aContext = AISContext();
1085 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1086 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1087 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1089 if (myContextCallBack) myContextCallBack->Display(anAISIO);
1092 aContext->Deactivate(anAISIO);
1094 if (myContextCallBack) myContextCallBack->Deactivate(anAISIO);
1096 aContext->Load(anAISIO);
1098 if (myContextCallBack) myContextCallBack->Load(anAISIO);
1100 if (toActivateInSelectionModes) {
1101 if (aContext->HasOpenedContext()) {
1102 if (myActiveSelectionModes.size() == 0)
1103 activateAIS(anAISIO, 0, theUpdateViewer);
1105 foreach(int aMode, myActiveSelectionModes) {
1106 activateAIS(anAISIO, aMode, theUpdateViewer);
1111 if (theUpdateViewer)
1117 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1119 bool aErased = false;
1120 Handle(AIS_InteractiveContext) aContext = AISContext();
1121 if (!aContext.IsNull()) {
1122 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1123 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1124 aContext->Remove(anAISIO, false/*update viewer*/);
1126 if (myContextCallBack) myContextCallBack->Remove(anAISIO);
1131 if (aErased && theUpdateViewer)
1137 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1139 if (theMode == NoMode)
1142 Handle(AIS_InteractiveContext) aContext = AISContext();
1143 if (aContext.IsNull())
1146 AISObjectPtr aAISObj = getAISObject(theObject);
1150 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1151 aContext->SetDisplayMode(aAISIO, theMode, false);
1152 // Redisplay in order to update new mode because it could be not computed before
1153 if (theUpdateViewer)
1157 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1159 Handle(AIS_InteractiveContext) aContext = AISContext();
1160 if (aContext.IsNull())
1163 AISObjectPtr aAISObj = getAISObject(theObject);
1167 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1168 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1171 void XGUI_Displayer::deactivateSelectionFilters()
1173 Handle(AIS_InteractiveContext) aContext = AISContext();
1174 if (!myAndFilter.IsNull()) {
1175 bool aFound = false;
1176 if (!aContext.IsNull()) {
1177 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1178 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1179 for (; anIt.More() && !aFound; anIt.Next()) {
1180 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1181 aFound = aFilter == myAndFilter;
1184 aContext->RemoveFilter(myAndFilter);
1186 myAndFilter.Nullify();
1190 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1192 Handle(AIS_InteractiveContext) aContext = AISContext();
1193 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1196 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1197 if (!aCompositeFilter.IsNull()) {
1198 aCompositeFilter->Add(theFilter);
1199 #ifdef DEBUG_SELECTION_FILTERS
1200 int aCount = aCompositeFilter->StoredFilters().Extent();
1201 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1206 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1208 Handle(AIS_InteractiveContext) aContext = AISContext();
1209 if (aContext.IsNull())
1212 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1213 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1214 aCompositeFilter->Remove(theFilter);
1215 #ifdef DEBUG_SELECTION_FILTERS
1216 int aCount = aCompositeFilter->StoredFilters().Extent();
1217 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1218 .arg(aCount).toStdString().c_str());
1223 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1225 bool aFilterFound = false;
1227 Handle(AIS_InteractiveContext) aContext = AISContext();
1228 if (aContext.IsNull())
1229 return aFilterFound;
1230 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1231 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1232 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1233 if (theFilter.Access() == aIt.Value().Access())
1234 aFilterFound = true;
1236 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1237 if (!aCompositeFilter.IsNull()) {
1238 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1239 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1240 if (theFilter.Access() == aIt.Value().Access())
1241 aFilterFound = true;
1244 return aFilterFound;
1247 void XGUI_Displayer::removeFilters()
1249 Handle(AIS_InteractiveContext) aContext = AISContext();
1250 if (aContext.IsNull())
1253 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1254 if (!aCompositeFilter.IsNull())
1255 aCompositeFilter->Clear();
1258 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1260 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1261 foreach(ObjectPtr aObj, aDispList) {
1262 if (!theList.contains(aObj))
1265 foreach(ObjectPtr aObj, theList) {
1266 if (!isVisible(aObj))
1267 display(aObj, false);
1272 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1274 if (!isVisible(theObject))
1277 AISObjectPtr aAISObj = getAISObject(theObject);
1278 if (aAISObj.get() == NULL)
1281 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1282 return ::canBeShaded(anAIS, myWorkshop->module());
1285 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1286 const QIntList& theModes,
1287 const bool theUpdateViewer) const
1289 Handle(AIS_InteractiveContext) aContext = AISContext();
1290 if (aContext.IsNull() || theIO.IsNull())
1293 bool isActivationChanged = false;
1294 // deactivate object in all modes, which are not in the list of activation
1295 // It seems that after the IO deactivation the selected state of the IO's owners
1296 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1297 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1298 // only if there is a difference in the current modes and the parameters modes.
1299 // If the selection problem happens again, it is possible to write a test scenario and create
1300 // a bug. The bug steps are the following:
1301 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1302 // with clicked SHIFT select the second object.
1303 // The result is the selection of the first IO is lost.
1304 TColStd_ListOfInteger aTColModes;
1305 aContext->ActivatedModes(theIO, aTColModes);
1307 if (myContextCallBack) myContextCallBack->ActivatedModes(theIO, aTColModes);
1309 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1310 QIntList aModesActivatedForIO;
1311 bool isDeactivated = false;
1312 for (; itr.More(); itr.Next() ) {
1313 Standard_Integer aMode = itr.Value();
1314 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1315 if (!theModes.contains(aMode)) {
1316 deactivateAIS(theIO, aMode);
1317 isDeactivated = true;
1320 aModesActivatedForIO.append(aMode);
1323 if (isDeactivated) {
1324 // the selection from the previous activation modes should be cleared manually (#26172)
1325 theIO->ClearSelected();
1327 if (myContextCallBack) myContextCallBack->ClearSelected(theIO);
1329 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1331 if (myContextCallBack) myContextCallBack->ClearOutdatedSelection(theIO);
1333 // For performance issues
1334 //if (theUpdateViewer)
1336 isActivationChanged = true;
1339 // loading the interactive object allowing the decomposition
1340 if (aTColModes.IsEmpty()) {
1341 aContext->Load(theIO, -1, true);
1343 if (myContextCallBack) myContextCallBack->Load(theIO);
1347 // trihedron AIS check should be after the AIS loading.
1348 // If it is not loaded, it is steel selectable in the viewer.
1349 Handle(AIS_Trihedron) aTrihedron;
1350 if (!isTrihedronActive())
1351 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1352 if (aTrihedron.IsNull()) {
1353 // In order to clear active modes list
1354 if (theModes.size() == 0) {
1355 activateAIS(theIO, 0, theUpdateViewer);
1357 foreach(int aMode, theModes) {
1358 if (!aModesActivatedForIO.contains(aMode)) {
1359 activateAIS(theIO, aMode, theUpdateViewer);
1360 isActivationChanged = true;
1365 return isActivationChanged;
1368 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1370 AISObjectPtr anAISObj = getAISObject(theObject);
1371 // correct the result's color it it has the attribute
1372 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1374 // Customization of presentation
1375 GeomCustomPrsPtr aCustomPrs;
1376 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1377 if (aFeature.get() != NULL) {
1378 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1379 if (aCustPrs.get() != NULL)
1380 aCustomPrs = aCustPrs;
1382 if (aCustomPrs.get() == NULL) {
1383 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1384 // we ignore presentable not customized objects
1385 if (aPrs.get() == NULL)
1386 aCustomPrs = myCustomPrs;
1388 bool isCustomized = aCustomPrs.get() &&
1389 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1390 return isCustomized;
1394 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1395 const QColor& theColor,
1396 bool theUpdateViewer)
1398 if (!isVisible(theObject))
1401 AISObjectPtr anAISObj = getAISObject(theObject);
1403 anAISObj->getColor(aR, aG, aB);
1404 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1405 if (theUpdateViewer)
1407 return QColor(aR, aG, aB);
1410 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1412 myResult2AISObjectMap[theObject] = theAIS;
1414 #ifdef DEBUG_DISPLAY
1415 std::ostringstream aPtrStr;
1416 aPtrStr << theObject.get();
1417 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1418 qDebug(getResult2AISObjectMapInfo().c_str());
1422 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1424 QStringList aContent;
1425 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1426 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1427 std::ostringstream aPtrStr;
1428 aPtrStr << "aObj = " << aObj.get() << ":";
1429 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1430 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1432 aContent.append(aPtrStr.str().c_str());
1434 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1435 arg(aContent.join("\n")).toStdString().c_str();
1438 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1439 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1441 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1442 if (aResult.get()) {
1443 AISObjectPtr aAISObj = getAISObject(aResult);
1444 if (aAISObj.get() != NULL) {
1445 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1446 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1447 thePresentations.Add(anAIS);
1451 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1452 // find presentation of the feature
1453 AISObjectPtr aAISObj = getAISObject(aFeature);
1454 if (aAISObj.get() != NULL) {
1455 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1456 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1457 thePresentations.Add(anAIS);
1459 // find presentations of the feature results
1460 std::list<ResultPtr> aResults;
1461 ModelAPI_Tools::allResults(aFeature, aResults);
1462 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1463 for (; anIt != aLast; ++anIt) {
1464 AISObjectPtr aAISObj = getAISObject(*anIt);
1465 if (aAISObj.get() != NULL) {
1466 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1467 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1468 thePresentations.Add(anAIS);
1474 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1476 myIsTrihedronActive = theIsActive;
1477 if (!myIsTrihedronActive) {
1478 deactivateTrihedron(true);
1482 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1484 Handle(AIS_InteractiveContext) aContext = AISContext();
1485 if (aContext.IsNull())
1488 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1491 if (!aContext->IsDisplayed(aTrihedron))
1492 aContext->Display(aTrihedron,
1494 -1 /* selection mode */,
1495 Standard_True /* update viewer*/,
1496 Standard_False /* allow decomposition */,
1497 AIS_DS_Displayed /* xdisplay status */);
1499 if (myContextCallBack) myContextCallBack->Display(aTrihedron);
1502 if (!isTrihedronActive())
1503 deactivateTrihedron(false);
1505 activate(aTrihedron, myActiveSelectionModes, false);
1507 deactivateTrihedron(false);
1508 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1509 // the selection from the previous activation modes should be cleared manually (#26172)
1511 aContext->Erase(aTrihedron);
1513 if (myContextCallBack) myContextCallBack->Remove(aTrihedron);
1520 QIntList XGUI_Displayer::activeSelectionModes() const
1523 foreach (int aMode, myActiveSelectionModes) {
1524 // aMode < 9 is a Shape Enum values
1525 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1531 void XGUI_Displayer::setCallBack(VInspectorAPI_CallBack* theCallBack)
1533 myContextCallBack = theCallBack;
1536 VInspectorAPI_CallBack* XGUI_Displayer::getCallBack() const
1538 return myContextCallBack;
1542 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1543 const NCollection_DataMap<TopoDS_Shape,
1544 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1546 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1547 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1548 aLContext->UnhilightPicked(Standard_False);
1550 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1551 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1552 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1553 Handle(SelectMgr_EntityOwner) anOwner;
1555 /// It is very important to check that the owner is processed only once and has a map of
1556 /// processed owners because SetSelected works as a switch.
1557 /// If count of calls setSelectec is even, the object stays in the previous state
1558 /// (selected, deselected)
1559 /// OCCT: to write about the problem that active owners method returns one owner several times
1560 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1561 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1562 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1563 if (aSelectedIds.contains((long)anOwner.Access()))
1565 aSelectedIds.append((long)anOwner.Access());
1567 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1568 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1569 const TopoDS_Shape& aShape = BROwnr->Shape();
1570 if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
1571 Handle(AIS_InteractiveObject) anOwnerPresentation =
1572 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1573 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1574 theShapesToBeSelected.Find(aShape);
1575 if (aPresentations.Contains(anOwnerPresentation)) {
1576 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1577 anOwner->SetSelected (Standard_True);
1582 aLContext->HilightPicked(Standard_False);