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>
30 #include <GeomAPI_Shape.h>
31 #include <GeomAPI_IPresentable.h>
32 #include <GeomAPI_ICustomPrs.h>
34 #include <AIS_InteractiveContext.hxx>
35 #include <AIS_LocalContext.hxx>
36 #include <AIS_ListOfInteractive.hxx>
37 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 #include <AIS_DimensionSelectionMode.hxx>
39 #include <AIS_Shape.hxx>
40 #include <AIS_Dimension.hxx>
41 #include <AIS_Trihedron.hxx>
42 #include <AIS_Axis.hxx>
43 #include <AIS_Plane.hxx>
44 #include <AIS_Point.hxx>
45 #include <AIS_Selection.hxx>
46 #include <TColStd_ListIteratorOfListOfInteger.hxx>
47 #include <SelectMgr_ListOfFilter.hxx>
48 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
49 #include <Prs3d_Drawer.hxx>
50 #include <Prs3d_IsoAspect.hxx>
51 #include <SelectMgr_SelectionManager.hxx>
53 #include <StdSelect_ViewerSelector3d.hxx>
55 #include <TColStd_MapOfTransient.hxx>
56 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
58 #include <Events_Loop.h>
59 #include <ModelAPI_Events.h>
63 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
65 //#define DEBUG_ACTIVATE_OBJECTS
66 //#define DEBUG_DEACTIVATE
67 //#define DEBUG_ACTIVATE_AIS
68 //#define DEBUG_DEACTIVATE_AIS
70 //#define DEBUG_DISPLAY
71 //#define DEBUG_FEATURE_REDISPLAY
72 //#define DEBUG_SELECTION_FILTERS
74 //#define DEBUG_COMPOSILID_DISPLAY
75 // Workaround for bug #25637
77 //#define DEBUG_OCCT_SHAPE_SELECTION
79 #define WORKAROUND_UNTIL_27523_IS_FIXED
81 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
83 // Get from null point
84 theAIS->DisplayedObjects(theList, true);
85 if (theAIS->HasOpenedContext()) {
86 // get from local context
87 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
88 TColStd_MapOfTransient aMap;
89 int NbDisp = aLC->DisplayedObjects(aMap);
90 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
92 Handle(AIS_InteractiveObject) curIO;
93 Handle(Standard_Transient) Tr;
94 for(; aIt.More(); aIt.Next()){
96 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
97 theList.Append(curIO);
102 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
105 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
106 for (; anIt != aLast; anIt++) {
107 anInfo.append(QString::number(*anIt));
109 return anInfo.join(theSeparator);
112 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
113 : myWorkshop(theWorkshop), myNeedUpdate(false),
114 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0)
116 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
119 XGUI_Displayer::~XGUI_Displayer()
123 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
125 return myResult2AISObjectMap.contains(theObject);
128 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
130 bool aDisplayed = false;
131 if (isVisible(theObject)) {
132 #ifdef DEBUG_COMPOSILID_DISPLAY
133 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
134 if (aCompsolidResult.get()) {
135 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
136 ResultPtr aSubResult = aCompsolidResult->subResult(i);
137 if (aSubResult.get())
138 redisplay(aSubResult, false);
145 aDisplayed = redisplay(theObject, theUpdateViewer);
148 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
149 bool isShading = false;
150 if (aPrs.get() != NULL) {
151 anAIS = aPrs->getAISObject(anAIS);
153 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
154 if (aResult.get() != NULL) {
155 #ifdef DEBUG_COMPOSILID_DISPLAY
156 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
157 if (aCompsolidResult.get()) {
158 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
159 ResultPtr aSubResult = aCompsolidResult->subResult(i);
160 if (aSubResult.get())
161 display(aSubResult, false);
168 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
169 if (aShapePtr.get() != NULL) {
170 anAIS = AISObjectPtr(new GeomAPI_AISObject());
171 Handle(AIS_InteractiveObject) anAISPrs = myWorkshop->module()->createPresentation(aResult);
172 if (anAISPrs.IsNull())
173 anAISPrs = new ModuleBase_ResultPrs(aResult);
174 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
175 //anAIS->createShape(aShapePtr);
178 #ifdef DEBUG_COMPOSILID_DISPLAY
184 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
189 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
191 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
192 if (!aShapePrs.IsNull()) {
193 TopoDS_Shape aShape = aShapePrs->Shape();
196 TopAbs_ShapeEnum aType = aShape.ShapeType();
197 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
200 // Check that the presentation is not a sketch
201 return theModule->canBeShaded(theAIS);
207 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
208 bool isShading, bool theUpdateViewer)
210 bool aDisplayed = false;
212 Handle(AIS_InteractiveContext) aContext = AISContext();
213 if (aContext.IsNull())
216 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
217 if (!anAISIO.IsNull()) {
218 appendResultObject(theObject, theAIS);
220 bool isCustomized = customizeObject(theObject);
222 int aDispMode = isShading? Shading : Wireframe;
224 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
225 anAISIO->SetDisplayMode(aDispMode);
226 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
229 emit objectDisplayed(theObject, theAIS);
230 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
231 // the fix from VPA for more suitable selection of sketcher lines
232 if(anAISIO->Width() > 1) {
233 for(int aModeIdx = 0; aModeIdx < myActiveSelectionModes.length(); ++aModeIdx) {
234 int aMode = myActiveSelectionModes.value(aModeIdx);
235 double aPrecision = (aMode == getSelectionMode(TopAbs_VERTEX))? 20 :
236 (anAISIO->Width() + 2);
237 aContext->SetSelectionSensitivity(anAISIO, aMode, aPrecision);
247 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
249 bool aErased = false;
250 if (!isVisible(theObject))
253 Handle(AIS_InteractiveContext) aContext = AISContext();
254 if (aContext.IsNull())
257 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
259 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
260 if (!anAIS.IsNull()) {
261 emit beforeObjectErase(theObject, anObject);
262 aContext->Remove(anAIS, false/*update viewer*/);
266 myResult2AISObjectMap.remove(theObject);
269 std::ostringstream aPtrStr;
270 aPtrStr << theObject.get();
271 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
272 qDebug(getResult2AISObjectMapInfo().c_str());
281 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
283 bool aRedisplayed = false;
284 if (!isVisible(theObject))
287 AISObjectPtr aAISObj = getAISObject(theObject);
288 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
290 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
292 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
294 aRedisplayed = erase(theObject, theUpdateViewer);
297 if (aAIS_Obj != aAISObj) {
298 appendResultObject(theObject, aAIS_Obj);
300 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
303 Handle(AIS_InteractiveContext) aContext = AISContext();
304 if (!aContext.IsNull() && !aAISIO.IsNull()) {
305 // Check that the visualized shape is the same and the redisplay is not necessary
306 // Redisplay of AIS object leads to this object selection compute and the selection
307 // in the browser is lost
308 // this check is not necessary anymore because the selection store/restore is realized
309 // before and after the values modification.
310 // Moreother, this check avoids customize and redisplay presentation if the presentable
311 // parameter is changed.
312 bool isEqualShapes = false;
313 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
314 if (aResult.get() != NULL) {
315 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
316 if (!aShapePrs.IsNull()) {
317 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
318 if (aShapePtr.get()) {
319 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
320 if (!aOldShape.IsNull())
321 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
325 // Customization of presentation
326 bool isCustomized = customizeObject(theObject);
327 #ifdef DEBUG_FEATURE_REDISPLAY
328 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
329 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
331 if (!isEqualShapes || isCustomized) {
332 /// if shapes are equal and presentation are customized, selection should be restored
333 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
334 if (aNeedToRestoreSelection)
335 myWorkshop->module()->storeSelection();
337 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
338 if (!myActiveSelectionModes.contains(0))
339 aContext->Activate(aAISIO, 0);
342 aContext->Redisplay(aAISIO, false);
344 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
345 if (!myActiveSelectionModes.contains(0))
346 aContext->Deactivate(aAISIO, 0);
349 if (aNeedToRestoreSelection)
350 myWorkshop->module()->restoreSelection();
353 #ifdef DEBUG_FEATURE_REDISPLAY
354 qDebug(" Redisplay happens");
363 void XGUI_Displayer::redisplayObjects()
365 // redisplay objects visualized in the viewer
366 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
367 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
368 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
369 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
370 for (; anIt != aLast; anIt++) {
371 aECreator->sendUpdated(*anIt, EVENT_DISP);
373 Events_Loop::loop()->flush(EVENT_DISP);
376 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
378 #ifdef DEBUG_DEACTIVATE
379 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
380 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
381 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
383 toStdString().c_str());
385 Handle(AIS_InteractiveContext) aContext = AISContext();
386 if (!aContext.IsNull() && isVisible(theObject)) {
387 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
388 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
390 deactivateAIS(anAIS);
391 // the selection from the previous activation modes should be cleared manually (#26172)
392 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
398 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
399 const bool theUpdateViewer)
401 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
402 //if (!aTrihedron.IsNull())
403 // deactivateAIS(aTrihedron);
405 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
406 for (; anIt != aLast; anIt++) {
407 deactivate(*anIt, false);
409 //VSV It seems that there is no necessity to update viewer on deactivation
410 //if (theUpdateViewer)
414 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
416 Handle(AIS_InteractiveContext) aContext = AISContext();
417 if (aContext.IsNull() || !isVisible(theObject))
420 AISObjectPtr aAISObj = getAISObject(theObject);
422 if (aAISObj.get() != NULL) {
423 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
424 TColStd_ListOfInteger aTColModes;
425 aContext->ActivatedModes(anAISIO, aTColModes);
426 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
427 for (; itr.More(); itr.Next() ) {
428 theModes.append(itr.Value());
433 int XGUI_Displayer::getSelectionMode(int theShapeType)
435 return (theShapeType >= TopAbs_SHAPE)? theShapeType :
436 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
439 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
441 bool aVisible = false;
442 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
443 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
444 if (aPrs.get() || aResult.get()) {
445 aVisible = theDisplayer->isVisible(theObject);
446 // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
447 // visible. It is useful for highlight presentation where compsolid shape is selectable
448 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
449 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
450 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
451 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
452 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
453 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
455 aVisible = anAllSubsVisible;
459 // it is possible that feature is presentable and has results, so we should check visibility
460 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
462 // check if all results of the feature are visible
463 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
464 std::list<ResultPtr> aResults = aFeature->results();
465 std::list<ResultPtr>::const_iterator aIt;
466 aVisible = !aResults.empty();
467 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
468 aVisible = aVisible && theDisplayer->isVisible(*aIt);
474 #ifdef DEBUG_ACTIVATE_OBJECTS
475 QString getModeInfo(const int theMode)
477 QString anInfo = "Undefined";
479 case 0: anInfo = "SHAPE(0)"; break;
480 case 1: anInfo = "VERTEX(1)"; break;
481 case 2: anInfo = "EDGE(2)"; break;
482 case 3: anInfo = "WIRE(3)"; break;
483 case 4: anInfo = "FACE(4)"; break;
484 case 5: anInfo = "SHELL(5)"; break;
485 case 6: anInfo = "SOLID(6)"; break;
486 case 7: anInfo = "COMPSOLID(7)"; break;
487 case 8: anInfo = "COMPOUND(8)"; break;
488 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
489 case 101: anInfo = "Sel_Constraint(101)"; break;
490 case 102: anInfo = "Sel_Dimension_All(102)"; break;
491 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
492 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
498 QString getModesInfo(const QIntList& theModes)
500 QStringList aModesInfo;
501 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
502 aModesInfo.append(getModeInfo(theModes[i]));
503 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
507 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
508 const bool theUpdateViewer)
510 // Convert shape types to selection types
512 foreach(int aType, theModes) {
513 aModes.append(getSelectionMode(aType));
516 #ifdef DEBUG_ACTIVATE_OBJECTS
518 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
519 for (; anIt != aLast; ++anIt) {
520 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
522 QString anInfoStr = anInfo.join(", ");
524 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
525 arg(getModesInfo(aModes)).
526 arg(getModesInfo(myActiveSelectionModes)).
527 arg(theObjList.size()).
529 toStdString().c_str());
531 // In order to avoid doblications of selection modes
533 foreach (int aMode, aModes) {
534 if (!aNewModes.contains(aMode))
535 aNewModes.append(aMode);
537 myActiveSelectionModes = aNewModes;
538 Handle(AIS_InteractiveContext) aContext = AISContext();
539 // Open local context if there is no one
540 if (aContext.IsNull() || !aContext->HasOpenedContext())
543 //aContext->UseDisplayedObjects();
544 //myUseExternalObjects = true;
546 Handle(AIS_InteractiveObject) anAISIO;
547 AIS_ListOfInteractive aPrsList;
548 //if (aObjList.isEmpty())
551 foreach(ObjectPtr aObj, theObjList) {
552 if (myResult2AISObjectMap.contains(aObj))
553 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
557 // Add trihedron because it has to partisipate in selection
558 Handle(AIS_InteractiveObject) aTrihedron;
559 if (isTrihedronActive()) {
560 aTrihedron = getTrihedron();
561 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
562 aPrsList.Append(aTrihedron);
564 if (aPrsList.Extent() == 0)
567 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
568 bool isActivationChanged = false;
569 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
570 anAISIO = aLIt.Value();
571 if (activate(anAISIO, myActiveSelectionModes, false))
572 isActivationChanged = true;
574 if (!aTrihedron.IsNull()) {
575 foreach(int aMode, myActiveSelectionModes)
576 aContext->SetSelectionSensitivity(aTrihedron, aMode, 20);
578 // VSV It seems that there is no necessity to update viewer on activation
579 //if (theUpdateViewer && isActivationChanged)
583 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
585 Handle(AIS_InteractiveContext) aContext = AISContext();
586 if (aContext.IsNull() || !isVisible(theObject))
589 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
590 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
592 TColStd_ListOfInteger aModes;
593 aContext->ActivatedModes(anAIS, aModes);
594 return aModes.Extent() > 0;
596 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
598 Handle(AIS_InteractiveContext) aContext = AISContext();
599 if (aContext.IsNull())
601 if (aContext->HasOpenedContext()) {
602 aContext->UnhilightSelected(false);
603 aContext->ClearSelected(false);
604 NCollection_Map<TopoDS_Shape> aShapesToBeSelected;
606 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
607 const GeomShapePtr& aGeomShape = aPrs->shape();
608 if (aGeomShape.get() && !aGeomShape->isNull()) {
609 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
610 #ifdef DEBUG_OCCT_SHAPE_SELECTION
611 aContext->AddOrRemoveSelected(aShape, false);
613 aShapesToBeSelected.Add(aShape);
616 ObjectPtr anObject = aPrs->object();
617 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
618 if (aResult.get() && isVisible(aResult)) {
619 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
620 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
621 if (!anAIS.IsNull()) {
622 // The methods are replaced in order to provide multi-selection, e.g. restore selection
623 // by activating multi selector widget. It also gives an advantage that the multi
624 // selection in OB gives multi-selection in the viewer
625 //aContext->SetSelected(anAIS, false);
626 // The selection in the context was cleared, so the method sets the objects are selected
627 aContext->AddOrRemoveSelected(anAIS, false);
632 if (!aShapesToBeSelected.IsEmpty())
633 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
635 aContext->UnhilightCurrents(false);
636 aContext->ClearCurrents(false);
637 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
638 ObjectPtr anObject = aPrs->object();
639 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
640 if (aResult.get() && isVisible(aResult)) {
641 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
642 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
644 aContext->SetCurrentObject(anAIS, false);
652 void XGUI_Displayer::clearSelected()
654 Handle(AIS_InteractiveContext) aContext = AISContext();
655 if (!aContext.IsNull()) {
656 aContext->UnhilightCurrents(false);
657 aContext->ClearSelected();
661 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
663 bool aErased = false;
664 Handle(AIS_InteractiveContext) aContext = AISContext();
665 if (!aContext.IsNull()) {
666 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
667 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
669 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
670 if (!anIO.IsNull()) {
671 emit beforeObjectErase(aObj, aAISObj);
672 aContext->Remove(anIO, false/*update viewer*/);
679 myResult2AISObjectMap.clear();
682 qDebug(getResult2AISObjectMapInfo().c_str());
687 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
688 Handle(AIS_InteractiveObject) theObject,
689 const bool theClear = true)
691 if (!theObject.IsNull()) {
692 theContext->Deactivate(theObject);
694 //theObject->ClearSelected();
695 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
700 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
702 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
703 Handle(AIS_InteractiveContext) aContext = AISContext();
704 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
705 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
706 deactivateObject(aContext, aTrie);
708 /// #1136 hidden axis are selected in sketch
709 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
710 /// for Position AIS object in SelectionModes.
711 deactivateObject(aContext, aTrie->XAxis());
712 deactivateObject(aContext, aTrie->YAxis());
713 deactivateObject(aContext, aTrie->Axis());
714 deactivateObject(aContext, aTrie->Position());
716 deactivateObject(aContext, aTrie->XYPlane());
717 deactivateObject(aContext, aTrie->XZPlane());
718 deactivateObject(aContext, aTrie->YZPlane());
725 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
727 return myWorkshop->viewer()->trihedron();
730 void XGUI_Displayer::openLocalContext()
732 Handle(AIS_InteractiveContext) aContext = AISContext();
733 // Open local context if there is no one
734 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
735 // Preserve selected objects
736 //AIS_ListOfInteractive aAisList;
737 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
738 // aAisList.Append(aContext->Current());
740 // get the filters from the global context and append them to the local context
741 // a list of filters in the global context is not cleared and should be cleared here
742 SelectMgr_ListOfFilter aFilters;
743 aFilters.Assign(aContext->Filters());
744 // it is important to remove the filters in the global context, because there is a code
745 // in the closeLocalContex, which restore the global context filters
746 aContext->RemoveFilters();
748 //aContext->ClearCurrents();
749 aContext->OpenLocalContext();
750 //deactivateTrihedron();
751 //aContext->NotUseDisplayedObjects();
753 //myUseExternalObjects = false;
755 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
756 for (;aIt.More(); aIt.Next()) {
757 aContext->AddFilter(aIt.Value());
760 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
761 //for(; aIt2.More(); aIt2.Next()) {
762 // aContext->SetSelected(aIt2.Value(), false);
767 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
769 Handle(AIS_InteractiveContext) aContext = AISContext();
770 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
771 // Preserve selected objects
772 //AIS_ListOfInteractive aAisList;
773 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
774 // aAisList.Append(aContext->SelectedInteractive());
776 // get the filters from the local context and append them to the global context
777 // a list of filters in the local context is cleared
778 SelectMgr_ListOfFilter aFilters;
779 aFilters.Assign(aContext->Filters());
781 //aContext->ClearSelected();
782 aContext->CloseAllContexts(false);
784 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
785 // this code is obsolete. It is temporaty commented and should be removed after
786 // the test campaign.
787 // Redisplay all object if they were displayed in localContext
788 /*Handle(AIS_InteractiveObject) aAISIO;
789 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
790 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
791 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
792 aContext->Display(aAISIO, false);
793 aContext->SetDisplayMode(aAISIO, Shading, false);
797 // Append the filters from the local selection in the global selection context
798 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
799 for (;aIt.More(); aIt.Next()) {
800 Handle(SelectMgr_Filter) aFilter = aIt.Value();
801 aContext->AddFilter(aFilter);
806 //myUseExternalObjects = false;
809 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
810 //for(; aIt2.More(); aIt2.Next()) {
811 // if (aContext->IsDisplayed(aIt2.Value()))
812 // aContext->SetCurrentObject(aIt2.Value(), false);
817 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
820 if (myResult2AISObjectMap.contains(theObject))
821 anIO = myResult2AISObjectMap[theObject];
825 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
827 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
828 return getObject(aRefAIS);
831 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
834 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
835 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
836 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
842 if (!anObject.get()) {
843 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
844 if (!theIO.IsNull()) {
845 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
847 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
852 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
854 bool aWasEnabled = isUpdateEnabled();
856 myViewerBlockedRecursiveCount--;
858 myViewerBlockedRecursiveCount++;
860 if (myNeedUpdate && isUpdateEnabled()) {
862 myNeedUpdate = false;
867 bool XGUI_Displayer::isUpdateEnabled() const
869 return myViewerBlockedRecursiveCount == 0;
872 void XGUI_Displayer::updateViewer() const
874 Handle(AIS_InteractiveContext) aContext = AISContext();
875 if (!aContext.IsNull() && isUpdateEnabled()) {
876 myWorkshop->viewer()->Zfitall();
877 aContext->UpdateCurrentViewer();
883 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
884 const int theMode, const bool theUpdateViewer) const
886 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
887 if (!aContext.IsNull()) {
888 if (myWorkshop->module()) {
889 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
890 if (myWorkshop->module()->canActivateSelectionMode(theIO, aMode))
891 aContext->Activate(theIO, theMode, false);
893 aContext->Activate(theIO, theMode, false);
895 #ifdef DEBUG_ACTIVATE_AIS
896 ObjectPtr anObject = getObject(theIO);
897 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
898 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
905 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
907 Handle(AIS_InteractiveContext) aContext = AISContext();
908 if (!aContext.IsNull()) {
910 aContext->Deactivate(theIO);
912 aContext->Deactivate(theIO, theMode);
914 #ifdef DEBUG_DEACTIVATE_AIS
915 ObjectPtr anObject = getObject(theIO);
916 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
917 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
922 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
924 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
925 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
926 aContext->OpenLocalContext();
927 if (!isTrihedronActive())
928 deactivateTrihedron(true);
929 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
930 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
935 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
937 Handle(AIS_InteractiveContext) aContext = AISContext();
938 if (!aContext.IsNull() && myAndFilter.IsNull()) {
939 myAndFilter = new SelectMgr_AndFilter();
940 aContext->AddFilter(myAndFilter);
945 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
946 bool theUpdateViewer)
948 bool aDisplayed = false;
949 Handle(AIS_InteractiveContext) aContext = AISContext();
950 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
951 if (!aContext.IsNull() && !anAISIO.IsNull()) {
952 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
954 aContext->Deactivate(anAISIO);
955 aContext->Load(anAISIO);
956 if (toActivateInSelectionModes) {
957 if (aContext->HasOpenedContext()) {
958 if (myActiveSelectionModes.size() == 0)
959 activateAIS(anAISIO, 0, theUpdateViewer);
961 foreach(int aMode, myActiveSelectionModes) {
962 activateAIS(anAISIO, aMode, theUpdateViewer);
973 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
975 bool aErased = false;
976 Handle(AIS_InteractiveContext) aContext = AISContext();
977 if (!aContext.IsNull()) {
978 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
979 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
980 aContext->Remove(anAISIO, false/*update viewer*/);
984 if (aErased && theUpdateViewer)
990 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
992 if (theMode == NoMode)
995 Handle(AIS_InteractiveContext) aContext = AISContext();
996 if (aContext.IsNull())
999 AISObjectPtr aAISObj = getAISObject(theObject);
1003 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1004 aContext->SetDisplayMode(aAISIO, theMode, false);
1005 // Redisplay in order to update new mode because it could be not computed before
1006 if (theUpdateViewer)
1010 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1012 Handle(AIS_InteractiveContext) aContext = AISContext();
1013 if (aContext.IsNull())
1016 AISObjectPtr aAISObj = getAISObject(theObject);
1020 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1021 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1024 void XGUI_Displayer::deactivateSelectionFilters()
1026 Handle(AIS_InteractiveContext) aContext = AISContext();
1027 if (!myAndFilter.IsNull()) {
1028 bool aFound = false;
1029 if (!aContext.IsNull()) {
1030 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1031 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1032 for (; anIt.More() && !aFound; anIt.Next()) {
1033 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1034 aFound = aFilter == myAndFilter;
1037 aContext->RemoveFilter(myAndFilter);
1039 myAndFilter.Nullify();
1043 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1045 Handle(AIS_InteractiveContext) aContext = AISContext();
1046 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1049 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1050 if (!aCompositeFilter.IsNull()) {
1051 aCompositeFilter->Add(theFilter);
1052 #ifdef DEBUG_SELECTION_FILTERS
1053 int aCount = aCompositeFilter->StoredFilters().Extent();
1054 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1059 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1061 Handle(AIS_InteractiveContext) aContext = AISContext();
1062 if (aContext.IsNull())
1065 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1066 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1067 aCompositeFilter->Remove(theFilter);
1068 #ifdef DEBUG_SELECTION_FILTERS
1069 int aCount = aCompositeFilter->StoredFilters().Extent();
1070 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1075 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1077 bool aFilterFound = false;
1079 Handle(AIS_InteractiveContext) aContext = AISContext();
1080 if (aContext.IsNull())
1081 return aFilterFound;
1082 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1083 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1084 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1085 if (theFilter.Access() == aIt.Value().Access())
1086 aFilterFound = true;
1088 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1089 if (!aCompositeFilter.IsNull()) {
1090 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1091 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1092 if (theFilter.Access() == aIt.Value().Access())
1093 aFilterFound = true;
1096 return aFilterFound;
1099 void XGUI_Displayer::removeFilters()
1101 Handle(AIS_InteractiveContext) aContext = AISContext();
1102 if (aContext.IsNull())
1105 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1106 if (!aCompositeFilter.IsNull())
1107 aCompositeFilter->Clear();
1110 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1112 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1113 foreach(ObjectPtr aObj, aDispList) {
1114 if (!theList.contains(aObj))
1117 foreach(ObjectPtr aObj, theList) {
1118 if (!isVisible(aObj))
1119 display(aObj, false);
1124 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1126 if (!isVisible(theObject))
1129 AISObjectPtr aAISObj = getAISObject(theObject);
1130 if (aAISObj.get() == NULL)
1133 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1134 return ::canBeShaded(anAIS, myWorkshop->module());
1137 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1138 const QIntList& theModes,
1139 const bool theUpdateViewer) const
1141 Handle(AIS_InteractiveContext) aContext = AISContext();
1142 if (aContext.IsNull() || theIO.IsNull())
1145 bool isActivationChanged = false;
1146 // deactivate object in all modes, which are not in the list of activation
1147 // It seems that after the IO deactivation the selected state of the IO's owners
1148 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1149 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1150 // only if there is a difference in the current modes and the parameters modes.
1151 // If the selection problem happens again, it is possible to write a test scenario and create
1152 // a bug. The bug steps are the following:
1153 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1154 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1155 TColStd_ListOfInteger aTColModes;
1156 aContext->ActivatedModes(theIO, aTColModes);
1157 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1158 QIntList aModesActivatedForIO;
1159 bool isDeactivated = false;
1160 for (; itr.More(); itr.Next() ) {
1161 Standard_Integer aMode = itr.Value();
1162 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1163 if (!theModes.contains(aMode) || (myWorkshop->module()->needDeactivateSelectionMode(theIO, aShapeMode))) {
1164 deactivateAIS(theIO, aMode);
1165 isDeactivated = true;
1168 aModesActivatedForIO.append(aMode);
1171 if (isDeactivated) {
1172 // the selection from the previous activation modes should be cleared manually (#26172)
1173 theIO->ClearSelected();
1174 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1175 // For performance issues
1176 //if (theUpdateViewer)
1178 isActivationChanged = true;
1181 // loading the interactive object allowing the decomposition
1182 if (aTColModes.IsEmpty()) {
1183 aContext->Load(theIO, -1, true);
1186 // trihedron AIS check should be after the AIS loading.
1187 // If it is not loaded, it is steel selectable in the viewer.
1188 Handle(AIS_Trihedron) aTrihedron;
1189 if (!isTrihedronActive())
1190 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1191 if (aTrihedron.IsNull()) {
1192 // In order to clear active modes list
1193 if (theModes.size() == 0) {
1194 activateAIS(theIO, 0, theUpdateViewer);
1196 foreach(int aMode, theModes) {
1197 if (!aModesActivatedForIO.contains(aMode)) {
1198 activateAIS(theIO, aMode, theUpdateViewer);
1199 isActivationChanged = true;
1204 return isActivationChanged;
1207 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1209 AISObjectPtr anAISObj = getAISObject(theObject);
1210 // correct the result's color it it has the attribute
1211 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1213 // Customization of presentation
1214 GeomCustomPrsPtr aCustomPrs;
1215 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1216 if (aFeature.get() != NULL) {
1217 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1218 if (aCustPrs.get() != NULL)
1219 aCustomPrs = aCustPrs;
1221 if (aCustomPrs.get() == NULL) {
1222 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1223 // we ignore presentable not customized objects
1224 if (aPrs.get() == NULL)
1225 aCustomPrs = myCustomPrs;
1227 bool isCustomized = aCustomPrs.get() &&
1228 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1229 return isCustomized;
1233 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1235 if (!isVisible(theObject))
1238 AISObjectPtr anAISObj = getAISObject(theObject);
1240 anAISObj->getColor(aR, aG, aB);
1241 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1242 if (theUpdateViewer)
1244 return QColor(aR, aG, aB);
1247 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1249 myResult2AISObjectMap[theObject] = theAIS;
1251 #ifdef DEBUG_DISPLAY
1252 std::ostringstream aPtrStr;
1253 aPtrStr << theObject.get();
1254 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1255 qDebug(getResult2AISObjectMapInfo().c_str());
1259 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1261 QStringList aContent;
1262 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1263 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1264 std::ostringstream aPtrStr;
1265 aPtrStr << "aObj = " << aObj.get() << ":";
1266 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1267 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1269 aContent.append(aPtrStr.str().c_str());
1271 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1272 arg(aContent.join("\n")).toStdString().c_str();
1275 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1277 myIsTrihedronActive = theIsActive;
1278 if (!myIsTrihedronActive) {
1279 deactivateTrihedron(true);
1283 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1285 Handle(AIS_InteractiveContext) aContext = AISContext();
1286 if (aContext.IsNull())
1289 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1292 if (!aContext->IsDisplayed(aTrihedron))
1293 aContext->Display(aTrihedron,
1295 -1 /* selection mode */,
1296 Standard_True /* update viewer*/,
1297 Standard_False /* allow decomposition */,
1298 AIS_DS_Displayed /* xdisplay status */);
1300 if (!isTrihedronActive())
1301 deactivateTrihedron(false);
1303 activate(aTrihedron, myActiveSelectionModes, false);
1305 deactivateTrihedron(false);
1306 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1307 // the selection from the previous activation modes should be cleared manually (#26172)
1309 aContext->Erase(aTrihedron);
1315 QIntList XGUI_Displayer::activeSelectionModes() const
1318 foreach (int aMode, myActiveSelectionModes) {
1319 // aMode < 9 is a Shape Enum values
1320 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1325 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1326 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1328 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1329 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1330 aLContext->UnhilightPicked(Standard_False);
1332 NCollection_Map<TopoDS_Shape> aShapesSelected;
1334 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1335 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1336 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1337 Handle(SelectMgr_EntityOwner) anOwner;
1338 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1339 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1340 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1341 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1342 if (aShapesSelected.Contains(BROwnr->Shape()))
1344 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1345 anOwner->SetSelected (Standard_True);
1346 aShapesSelected.Add(BROwnr->Shape());
1349 aLContext->HilightPicked(Standard_False);