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 aContext->Activate(theIO, theMode, false);
892 aContext->Activate(theIO, theMode, false);
894 #ifdef DEBUG_ACTIVATE_AIS
895 ObjectPtr anObject = getObject(theIO);
896 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
897 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
904 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
906 Handle(AIS_InteractiveContext) aContext = AISContext();
907 if (!aContext.IsNull()) {
909 aContext->Deactivate(theIO);
911 aContext->Deactivate(theIO, theMode);
913 #ifdef DEBUG_DEACTIVATE_AIS
914 ObjectPtr anObject = getObject(theIO);
915 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
916 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
921 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
923 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
924 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
925 aContext->OpenLocalContext();
926 if (!isTrihedronActive())
927 deactivateTrihedron(true);
928 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
929 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
934 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
936 Handle(AIS_InteractiveContext) aContext = AISContext();
937 if (!aContext.IsNull() && myAndFilter.IsNull()) {
938 myAndFilter = new SelectMgr_AndFilter();
939 aContext->AddFilter(myAndFilter);
944 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
945 bool theUpdateViewer)
947 bool aDisplayed = false;
948 Handle(AIS_InteractiveContext) aContext = AISContext();
949 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
950 if (!aContext.IsNull() && !anAISIO.IsNull()) {
951 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
953 aContext->Deactivate(anAISIO);
954 aContext->Load(anAISIO);
955 if (toActivateInSelectionModes) {
956 if (aContext->HasOpenedContext()) {
957 if (myActiveSelectionModes.size() == 0)
958 activateAIS(anAISIO, 0, theUpdateViewer);
960 foreach(int aMode, myActiveSelectionModes) {
961 activateAIS(anAISIO, aMode, theUpdateViewer);
972 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
974 bool aErased = false;
975 Handle(AIS_InteractiveContext) aContext = AISContext();
976 if (!aContext.IsNull()) {
977 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
978 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
979 aContext->Remove(anAISIO, false/*update viewer*/);
983 if (aErased && theUpdateViewer)
989 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
991 if (theMode == NoMode)
994 Handle(AIS_InteractiveContext) aContext = AISContext();
995 if (aContext.IsNull())
998 AISObjectPtr aAISObj = getAISObject(theObject);
1002 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1003 aContext->SetDisplayMode(aAISIO, theMode, false);
1004 // Redisplay in order to update new mode because it could be not computed before
1005 if (theUpdateViewer)
1009 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1011 Handle(AIS_InteractiveContext) aContext = AISContext();
1012 if (aContext.IsNull())
1015 AISObjectPtr aAISObj = getAISObject(theObject);
1019 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1020 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1023 void XGUI_Displayer::deactivateSelectionFilters()
1025 Handle(AIS_InteractiveContext) aContext = AISContext();
1026 if (!myAndFilter.IsNull()) {
1027 bool aFound = false;
1028 if (!aContext.IsNull()) {
1029 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1030 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1031 for (; anIt.More() && !aFound; anIt.Next()) {
1032 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1033 aFound = aFilter == myAndFilter;
1036 aContext->RemoveFilter(myAndFilter);
1038 myAndFilter.Nullify();
1042 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1044 Handle(AIS_InteractiveContext) aContext = AISContext();
1045 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1048 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1049 if (!aCompositeFilter.IsNull()) {
1050 aCompositeFilter->Add(theFilter);
1051 #ifdef DEBUG_SELECTION_FILTERS
1052 int aCount = aCompositeFilter->StoredFilters().Extent();
1053 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1058 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1060 Handle(AIS_InteractiveContext) aContext = AISContext();
1061 if (aContext.IsNull())
1064 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1065 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1066 aCompositeFilter->Remove(theFilter);
1067 #ifdef DEBUG_SELECTION_FILTERS
1068 int aCount = aCompositeFilter->StoredFilters().Extent();
1069 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1074 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1076 bool aFilterFound = false;
1078 Handle(AIS_InteractiveContext) aContext = AISContext();
1079 if (aContext.IsNull())
1080 return aFilterFound;
1081 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1082 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1083 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1084 if (theFilter.Access() == aIt.Value().Access())
1085 aFilterFound = true;
1087 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1088 if (!aCompositeFilter.IsNull()) {
1089 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1090 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1091 if (theFilter.Access() == aIt.Value().Access())
1092 aFilterFound = true;
1095 return aFilterFound;
1098 void XGUI_Displayer::removeFilters()
1100 Handle(AIS_InteractiveContext) aContext = AISContext();
1101 if (aContext.IsNull())
1104 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1105 if (!aCompositeFilter.IsNull())
1106 aCompositeFilter->Clear();
1109 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1111 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1112 foreach(ObjectPtr aObj, aDispList) {
1113 if (!theList.contains(aObj))
1116 foreach(ObjectPtr aObj, theList) {
1117 if (!isVisible(aObj))
1118 display(aObj, false);
1123 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1125 if (!isVisible(theObject))
1128 AISObjectPtr aAISObj = getAISObject(theObject);
1129 if (aAISObj.get() == NULL)
1132 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1133 return ::canBeShaded(anAIS, myWorkshop->module());
1136 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1137 const QIntList& theModes,
1138 const bool theUpdateViewer) const
1140 Handle(AIS_InteractiveContext) aContext = AISContext();
1141 if (aContext.IsNull() || theIO.IsNull())
1144 bool isActivationChanged = false;
1145 // deactivate object in all modes, which are not in the list of activation
1146 // It seems that after the IO deactivation the selected state of the IO's owners
1147 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1148 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1149 // only if there is a difference in the current modes and the parameters modes.
1150 // If the selection problem happens again, it is possible to write a test scenario and create
1151 // a bug. The bug steps are the following:
1152 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1153 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1154 TColStd_ListOfInteger aTColModes;
1155 aContext->ActivatedModes(theIO, aTColModes);
1156 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1157 QIntList aModesActivatedForIO;
1158 bool isDeactivated = false;
1159 for (; itr.More(); itr.Next() ) {
1160 Standard_Integer aMode = itr.Value();
1161 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1162 if (!theModes.contains(aMode)) {
1163 deactivateAIS(theIO, aMode);
1164 isDeactivated = true;
1167 aModesActivatedForIO.append(aMode);
1170 if (isDeactivated) {
1171 // the selection from the previous activation modes should be cleared manually (#26172)
1172 theIO->ClearSelected();
1173 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1174 // For performance issues
1175 //if (theUpdateViewer)
1177 isActivationChanged = true;
1180 // loading the interactive object allowing the decomposition
1181 if (aTColModes.IsEmpty()) {
1182 aContext->Load(theIO, -1, true);
1185 // trihedron AIS check should be after the AIS loading.
1186 // If it is not loaded, it is steel selectable in the viewer.
1187 Handle(AIS_Trihedron) aTrihedron;
1188 if (!isTrihedronActive())
1189 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1190 if (aTrihedron.IsNull()) {
1191 // In order to clear active modes list
1192 if (theModes.size() == 0) {
1193 activateAIS(theIO, 0, theUpdateViewer);
1195 foreach(int aMode, theModes) {
1196 if (!aModesActivatedForIO.contains(aMode)) {
1197 activateAIS(theIO, aMode, theUpdateViewer);
1198 isActivationChanged = true;
1203 return isActivationChanged;
1206 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1208 AISObjectPtr anAISObj = getAISObject(theObject);
1209 // correct the result's color it it has the attribute
1210 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1212 // Customization of presentation
1213 GeomCustomPrsPtr aCustomPrs;
1214 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1215 if (aFeature.get() != NULL) {
1216 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1217 if (aCustPrs.get() != NULL)
1218 aCustomPrs = aCustPrs;
1220 if (aCustomPrs.get() == NULL) {
1221 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1222 // we ignore presentable not customized objects
1223 if (aPrs.get() == NULL)
1224 aCustomPrs = myCustomPrs;
1226 bool isCustomized = aCustomPrs.get() &&
1227 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1228 return isCustomized;
1232 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1234 if (!isVisible(theObject))
1237 AISObjectPtr anAISObj = getAISObject(theObject);
1239 anAISObj->getColor(aR, aG, aB);
1240 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1241 if (theUpdateViewer)
1243 return QColor(aR, aG, aB);
1246 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1248 myResult2AISObjectMap[theObject] = theAIS;
1250 #ifdef DEBUG_DISPLAY
1251 std::ostringstream aPtrStr;
1252 aPtrStr << theObject.get();
1253 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1254 qDebug(getResult2AISObjectMapInfo().c_str());
1258 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1260 QStringList aContent;
1261 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1262 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1263 std::ostringstream aPtrStr;
1264 aPtrStr << "aObj = " << aObj.get() << ":";
1265 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1266 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1268 aContent.append(aPtrStr.str().c_str());
1270 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1271 arg(aContent.join("\n")).toStdString().c_str();
1274 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1276 myIsTrihedronActive = theIsActive;
1277 if (!myIsTrihedronActive) {
1278 deactivateTrihedron(true);
1282 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1284 Handle(AIS_InteractiveContext) aContext = AISContext();
1285 if (aContext.IsNull())
1288 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1291 if (!aContext->IsDisplayed(aTrihedron))
1292 aContext->Display(aTrihedron,
1294 -1 /* selection mode */,
1295 Standard_True /* update viewer*/,
1296 Standard_False /* allow decomposition */,
1297 AIS_DS_Displayed /* xdisplay status */);
1299 if (!isTrihedronActive())
1300 deactivateTrihedron(false);
1302 activate(aTrihedron, myActiveSelectionModes, false);
1304 deactivateTrihedron(false);
1305 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1306 // the selection from the previous activation modes should be cleared manually (#26172)
1308 aContext->Erase(aTrihedron);
1314 QIntList XGUI_Displayer::activeSelectionModes() const
1317 foreach (int aMode, myActiveSelectionModes) {
1318 // aMode < 9 is a Shape Enum values
1319 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1324 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1325 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1327 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1328 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1329 aLContext->UnhilightPicked(Standard_False);
1331 NCollection_Map<TopoDS_Shape> aShapesSelected;
1333 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1334 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1335 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1336 Handle(SelectMgr_EntityOwner) anOwner;
1337 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1338 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1339 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1340 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1341 if (aShapesSelected.Contains(BROwnr->Shape()))
1343 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1344 anOwner->SetSelected (Standard_True);
1345 aShapesSelected.Add(BROwnr->Shape());
1348 aLContext->HilightPicked(Standard_False);