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 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
81 // Get from null point
82 theAIS->DisplayedObjects(theList, true);
83 if (theAIS->HasOpenedContext()) {
84 // get from local context
85 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
86 TColStd_MapOfTransient aMap;
87 int NbDisp = aLC->DisplayedObjects(aMap);
88 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
90 Handle(AIS_InteractiveObject) curIO;
91 Handle(Standard_Transient) Tr;
92 for(; aIt.More(); aIt.Next()){
94 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
95 theList.Append(curIO);
100 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
103 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
104 for (; anIt != aLast; anIt++) {
105 anInfo.append(QString::number(*anIt));
107 return anInfo.join(theSeparator);
110 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
111 : myWorkshop(theWorkshop), myNeedUpdate(false),
112 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0)
114 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
117 XGUI_Displayer::~XGUI_Displayer()
121 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
123 return myResult2AISObjectMap.contains(theObject);
126 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
128 bool aDisplayed = false;
129 if (isVisible(theObject)) {
130 #ifdef DEBUG_COMPOSILID_DISPLAY
131 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
132 if (aCompsolidResult.get()) {
133 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
134 ResultPtr aSubResult = aCompsolidResult->subResult(i);
135 if (aSubResult.get())
136 redisplay(aSubResult, false);
143 aDisplayed = redisplay(theObject, theUpdateViewer);
146 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
147 bool isShading = false;
148 if (aPrs.get() != NULL) {
149 anAIS = aPrs->getAISObject(anAIS);
151 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
152 if (aResult.get() != NULL) {
153 #ifdef DEBUG_COMPOSILID_DISPLAY
154 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
155 if (aCompsolidResult.get()) {
156 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
157 ResultPtr aSubResult = aCompsolidResult->subResult(i);
158 if (aSubResult.get())
159 display(aSubResult, false);
166 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
167 if (aShapePtr.get() != NULL) {
168 anAIS = AISObjectPtr(new GeomAPI_AISObject());
169 Handle(AIS_InteractiveObject) anAISPrs = myWorkshop->module()->createPresentation(aResult);
170 if (anAISPrs.IsNull())
171 anAISPrs = new ModuleBase_ResultPrs(aResult);
172 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
173 //anAIS->createShape(aShapePtr);
176 #ifdef DEBUG_COMPOSILID_DISPLAY
182 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
187 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
189 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
190 if (!aShapePrs.IsNull()) {
191 TopoDS_Shape aShape = aShapePrs->Shape();
194 TopAbs_ShapeEnum aType = aShape.ShapeType();
195 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
198 // Check that the presentation is not a sketch
199 return theModule->canBeShaded(theAIS);
205 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
206 bool isShading, bool theUpdateViewer)
208 bool aDisplayed = false;
210 Handle(AIS_InteractiveContext) aContext = AISContext();
211 if (aContext.IsNull())
214 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
215 if (!anAISIO.IsNull()) {
216 appendResultObject(theObject, theAIS);
218 bool isCustomized = customizeObject(theObject);
220 int aDispMode = isShading? Shading : Wireframe;
222 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
223 anAISIO->SetDisplayMode(aDispMode);
224 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
227 emit objectDisplayed(theObject, theAIS);
228 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
229 // the fix from VPA for more suitable selection of sketcher lines
230 if(anAISIO->Width() > 1) {
231 for(int aModeIdx = 0; aModeIdx < myActiveSelectionModes.length(); ++aModeIdx) {
232 int aMode = myActiveSelectionModes.value(aModeIdx);
233 double aPrecision = (aMode == getSelectionMode(TopAbs_VERTEX))? 20 :
234 (anAISIO->Width() + 2);
235 aContext->SetSelectionSensitivity(anAISIO, aMode, aPrecision);
245 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
247 bool aErased = false;
248 if (!isVisible(theObject))
251 Handle(AIS_InteractiveContext) aContext = AISContext();
252 if (aContext.IsNull())
255 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
257 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
258 if (!anAIS.IsNull()) {
259 emit beforeObjectErase(theObject, anObject);
260 aContext->Remove(anAIS, false/*update viewer*/);
264 myResult2AISObjectMap.remove(theObject);
267 std::ostringstream aPtrStr;
268 aPtrStr << theObject.get();
269 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
270 qDebug(getResult2AISObjectMapInfo().c_str());
279 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
281 bool aRedisplayed = false;
282 if (!isVisible(theObject))
285 AISObjectPtr aAISObj = getAISObject(theObject);
286 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
288 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
290 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
292 aRedisplayed = erase(theObject, theUpdateViewer);
295 if (aAIS_Obj != aAISObj) {
296 appendResultObject(theObject, aAIS_Obj);
298 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
301 Handle(AIS_InteractiveContext) aContext = AISContext();
302 if (!aContext.IsNull() && !aAISIO.IsNull()) {
303 // Check that the visualized shape is the same and the redisplay is not necessary
304 // Redisplay of AIS object leads to this object selection compute and the selection
305 // in the browser is lost
306 // this check is not necessary anymore because the selection store/restore is realized
307 // before and after the values modification.
308 // Moreother, this check avoids customize and redisplay presentation if the presentable
309 // parameter is changed.
310 bool isEqualShapes = false;
311 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
312 if (aResult.get() != NULL) {
313 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
314 if (!aShapePrs.IsNull()) {
315 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
316 if (aShapePtr.get()) {
317 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
318 if (!aOldShape.IsNull())
319 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
323 // Customization of presentation
324 bool isCustomized = customizeObject(theObject);
325 #ifdef DEBUG_FEATURE_REDISPLAY
326 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
327 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
329 if (!isEqualShapes || isCustomized) {
330 /// if shapes are equal and presentation are customized, selection should be restored
331 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
332 if (aNeedToRestoreSelection)
333 myWorkshop->module()->storeSelection();
335 aContext->Redisplay(aAISIO, false);
337 if (aNeedToRestoreSelection)
338 myWorkshop->module()->restoreSelection();
341 #ifdef DEBUG_FEATURE_REDISPLAY
342 qDebug(" Redisplay happens");
351 void XGUI_Displayer::redisplayObjects()
353 // redisplay objects visualized in the viewer
354 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
355 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
356 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
357 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
358 for (; anIt != aLast; anIt++) {
359 aECreator->sendUpdated(*anIt, EVENT_DISP);
361 Events_Loop::loop()->flush(EVENT_DISP);
364 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
366 #ifdef DEBUG_DEACTIVATE
367 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
368 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
369 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
371 toStdString().c_str());
373 Handle(AIS_InteractiveContext) aContext = AISContext();
374 if (!aContext.IsNull() && isVisible(theObject)) {
375 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
376 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
378 deactivateAIS(anAIS);
379 // the selection from the previous activation modes should be cleared manually (#26172)
380 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
386 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
387 const bool theUpdateViewer)
389 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
390 //if (!aTrihedron.IsNull())
391 // deactivateAIS(aTrihedron);
393 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
394 for (; anIt != aLast; anIt++) {
395 deactivate(*anIt, false);
397 //VSV It seems that there is no necessity to update viewer on deactivation
398 //if (theUpdateViewer)
402 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
404 Handle(AIS_InteractiveContext) aContext = AISContext();
405 if (aContext.IsNull() || !isVisible(theObject))
408 AISObjectPtr aAISObj = getAISObject(theObject);
410 if (aAISObj.get() != NULL) {
411 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
412 TColStd_ListOfInteger aTColModes;
413 aContext->ActivatedModes(anAISIO, aTColModes);
414 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
415 for (; itr.More(); itr.Next() ) {
416 theModes.append(itr.Value());
421 int XGUI_Displayer::getSelectionMode(int theShapeType)
423 return (theShapeType >= TopAbs_SHAPE)? theShapeType :
424 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
427 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
429 bool aVisible = false;
430 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
431 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
432 if (aPrs.get() || aResult.get()) {
433 aVisible = theDisplayer->isVisible(theObject);
434 // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
435 // visible. It is useful for highlight presentation where compsolid shape is selectable
436 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
437 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
438 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
439 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
440 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
441 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
443 aVisible = anAllSubsVisible;
447 // it is possible that feature is presentable and has results, so we should check visibility
448 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
450 // check if all results of the feature are visible
451 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
452 std::list<ResultPtr> aResults = aFeature->results();
453 std::list<ResultPtr>::const_iterator aIt;
454 aVisible = !aResults.empty();
455 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
456 aVisible = aVisible && theDisplayer->isVisible(*aIt);
462 #ifdef DEBUG_ACTIVATE_OBJECTS
463 QString getModeInfo(const int theMode)
465 QString anInfo = "Undefined";
467 case 0: anInfo = "SHAPE(0)"; break;
468 case 1: anInfo = "VERTEX(1)"; break;
469 case 2: anInfo = "EDGE(2)"; break;
470 case 3: anInfo = "WIRE(3)"; break;
471 case 4: anInfo = "FACE(4)"; break;
472 case 5: anInfo = "SHELL(5)"; break;
473 case 6: anInfo = "SOLID(6)"; break;
474 case 7: anInfo = "COMPSOLID(7)"; break;
475 case 8: anInfo = "COMPOUND(8)"; break;
476 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
477 case 101: anInfo = "Sel_Constraint(101)"; break;
478 case 102: anInfo = "Sel_Dimension_All(102)"; break;
479 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
480 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
486 QString getModesInfo(const QIntList& theModes)
488 QStringList aModesInfo;
489 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
490 aModesInfo.append(getModeInfo(theModes[i]));
491 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
495 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
496 const bool theUpdateViewer)
498 // Convert shape types to selection types
500 foreach(int aType, theModes) {
501 aModes.append(getSelectionMode(aType));
504 #ifdef DEBUG_ACTIVATE_OBJECTS
506 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
507 for (; anIt != aLast; ++anIt) {
508 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
510 QString anInfoStr = anInfo.join(", ");
512 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
513 arg(getModesInfo(aModes)).
514 arg(getModesInfo(myActiveSelectionModes)).
515 arg(theObjList.size()).
517 toStdString().c_str());
519 // In order to avoid doblications of selection modes
521 foreach (int aMode, aModes) {
522 if (!aNewModes.contains(aMode))
523 aNewModes.append(aMode);
525 myActiveSelectionModes = aNewModes;
526 Handle(AIS_InteractiveContext) aContext = AISContext();
527 // Open local context if there is no one
528 if (aContext.IsNull() || !aContext->HasOpenedContext())
531 //aContext->UseDisplayedObjects();
532 //myUseExternalObjects = true;
534 Handle(AIS_InteractiveObject) anAISIO;
535 AIS_ListOfInteractive aPrsList;
536 //if (aObjList.isEmpty())
539 foreach(ObjectPtr aObj, theObjList) {
540 if (myResult2AISObjectMap.contains(aObj))
541 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
545 // Add trihedron because it has to partisipate in selection
546 Handle(AIS_InteractiveObject) aTrihedron;
547 if (isTrihedronActive()) {
548 aTrihedron = getTrihedron();
549 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
550 aPrsList.Append(aTrihedron);
552 if (aPrsList.Extent() == 0)
555 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
556 bool isActivationChanged = false;
557 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
558 anAISIO = aLIt.Value();
559 if (activate(anAISIO, myActiveSelectionModes, false))
560 isActivationChanged = true;
562 if (!aTrihedron.IsNull()) {
563 foreach(int aMode, myActiveSelectionModes)
564 aContext->SetSelectionSensitivity(aTrihedron, aMode, 20);
566 // VSV It seems that there is no necessity to update viewer on activation
567 //if (theUpdateViewer && isActivationChanged)
571 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
573 Handle(AIS_InteractiveContext) aContext = AISContext();
574 if (aContext.IsNull() || !isVisible(theObject))
577 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
578 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
580 TColStd_ListOfInteger aModes;
581 aContext->ActivatedModes(anAIS, aModes);
582 return aModes.Extent() > 0;
584 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
586 Handle(AIS_InteractiveContext) aContext = AISContext();
587 if (aContext.IsNull())
589 if (aContext->HasOpenedContext()) {
590 aContext->UnhilightSelected(false);
591 aContext->ClearSelected(false);
592 NCollection_Map<TopoDS_Shape> aShapesToBeSelected;
594 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
595 const GeomShapePtr& aGeomShape = aPrs->shape();
596 if (aGeomShape.get() && !aGeomShape->isNull()) {
597 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
598 #ifdef DEBUG_OCCT_SHAPE_SELECTION
599 aContext->AddOrRemoveSelected(aShape, false);
601 aShapesToBeSelected.Add(aShape);
604 ObjectPtr anObject = aPrs->object();
605 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
606 if (aResult.get() && isVisible(aResult)) {
607 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
608 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
609 if (!anAIS.IsNull()) {
610 // The methods are replaced in order to provide multi-selection, e.g. restore selection
611 // by activating multi selector widget. It also gives an advantage that the multi
612 // selection in OB gives multi-selection in the viewer
613 //aContext->SetSelected(anAIS, false);
614 // The selection in the context was cleared, so the method sets the objects are selected
615 aContext->AddOrRemoveSelected(anAIS, false);
620 if (!aShapesToBeSelected.IsEmpty())
621 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
623 aContext->UnhilightCurrents(false);
624 aContext->ClearCurrents(false);
625 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
626 ObjectPtr anObject = aPrs->object();
627 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
628 if (aResult.get() && isVisible(aResult)) {
629 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
630 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
632 aContext->SetCurrentObject(anAIS, false);
640 void XGUI_Displayer::clearSelected()
642 Handle(AIS_InteractiveContext) aContext = AISContext();
643 if (!aContext.IsNull()) {
644 aContext->UnhilightCurrents(false);
645 aContext->ClearSelected();
649 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
651 bool aErased = false;
652 Handle(AIS_InteractiveContext) aContext = AISContext();
653 if (!aContext.IsNull()) {
654 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
655 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
657 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
658 if (!anIO.IsNull()) {
659 emit beforeObjectErase(aObj, aAISObj);
660 aContext->Remove(anIO, false/*update viewer*/);
667 myResult2AISObjectMap.clear();
670 qDebug(getResult2AISObjectMapInfo().c_str());
675 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
676 Handle(AIS_InteractiveObject) theObject,
677 const bool theClear = true)
679 if (!theObject.IsNull()) {
680 theContext->Deactivate(theObject);
682 //theObject->ClearSelected();
683 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
688 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
690 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
691 Handle(AIS_InteractiveContext) aContext = AISContext();
692 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
693 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
694 deactivateObject(aContext, aTrie);
696 /// #1136 hidden axis are selected in sketch
697 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
698 /// for Position AIS object in SelectionModes.
699 deactivateObject(aContext, aTrie->XAxis());
700 deactivateObject(aContext, aTrie->YAxis());
701 deactivateObject(aContext, aTrie->Axis());
702 deactivateObject(aContext, aTrie->Position());
704 deactivateObject(aContext, aTrie->XYPlane());
705 deactivateObject(aContext, aTrie->XZPlane());
706 deactivateObject(aContext, aTrie->YZPlane());
713 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
715 return myWorkshop->viewer()->trihedron();
718 void XGUI_Displayer::openLocalContext()
720 Handle(AIS_InteractiveContext) aContext = AISContext();
721 // Open local context if there is no one
722 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
723 // Preserve selected objects
724 //AIS_ListOfInteractive aAisList;
725 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
726 // aAisList.Append(aContext->Current());
728 // get the filters from the global context and append them to the local context
729 // a list of filters in the global context is not cleared and should be cleared here
730 SelectMgr_ListOfFilter aFilters;
731 aFilters.Assign(aContext->Filters());
732 // it is important to remove the filters in the global context, because there is a code
733 // in the closeLocalContex, which restore the global context filters
734 aContext->RemoveFilters();
736 //aContext->ClearCurrents();
737 aContext->OpenLocalContext();
738 //deactivateTrihedron();
739 //aContext->NotUseDisplayedObjects();
741 //myUseExternalObjects = false;
743 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
744 for (;aIt.More(); aIt.Next()) {
745 aContext->AddFilter(aIt.Value());
748 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
749 //for(; aIt2.More(); aIt2.Next()) {
750 // aContext->SetSelected(aIt2.Value(), false);
755 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
757 Handle(AIS_InteractiveContext) aContext = AISContext();
758 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
759 // Preserve selected objects
760 //AIS_ListOfInteractive aAisList;
761 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
762 // aAisList.Append(aContext->SelectedInteractive());
764 // get the filters from the local context and append them to the global context
765 // a list of filters in the local context is cleared
766 SelectMgr_ListOfFilter aFilters;
767 aFilters.Assign(aContext->Filters());
769 //aContext->ClearSelected();
770 aContext->CloseAllContexts(false);
772 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
773 // this code is obsolete. It is temporaty commented and should be removed after
774 // the test campaign.
775 // Redisplay all object if they were displayed in localContext
776 /*Handle(AIS_InteractiveObject) aAISIO;
777 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
778 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
779 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
780 aContext->Display(aAISIO, false);
781 aContext->SetDisplayMode(aAISIO, Shading, false);
785 // Append the filters from the local selection in the global selection context
786 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
787 for (;aIt.More(); aIt.Next()) {
788 Handle(SelectMgr_Filter) aFilter = aIt.Value();
789 aContext->AddFilter(aFilter);
794 //myUseExternalObjects = false;
797 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
798 //for(; aIt2.More(); aIt2.Next()) {
799 // if (aContext->IsDisplayed(aIt2.Value()))
800 // aContext->SetCurrentObject(aIt2.Value(), false);
805 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
808 if (myResult2AISObjectMap.contains(theObject))
809 anIO = myResult2AISObjectMap[theObject];
813 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
815 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
816 return getObject(aRefAIS);
819 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
822 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
823 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
824 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
830 if (!anObject.get()) {
831 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
832 if (!theIO.IsNull()) {
833 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
835 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
840 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
842 bool aWasEnabled = isUpdateEnabled();
844 myViewerBlockedRecursiveCount--;
846 myViewerBlockedRecursiveCount++;
848 if (myNeedUpdate && isUpdateEnabled()) {
850 myNeedUpdate = false;
855 bool XGUI_Displayer::isUpdateEnabled() const
857 return myViewerBlockedRecursiveCount == 0;
860 void XGUI_Displayer::updateViewer() const
862 Handle(AIS_InteractiveContext) aContext = AISContext();
863 if (!aContext.IsNull() && isUpdateEnabled()) {
864 myWorkshop->viewer()->Zfitall();
865 aContext->UpdateCurrentViewer();
871 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
872 const int theMode, const bool theUpdateViewer) const
874 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
875 if (!aContext.IsNull()) {
876 aContext->Activate(theIO, theMode, false);
878 #ifdef DEBUG_ACTIVATE_AIS
879 ObjectPtr anObject = getObject(theIO);
880 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
881 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
888 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
890 Handle(AIS_InteractiveContext) aContext = AISContext();
891 if (!aContext.IsNull()) {
893 aContext->Deactivate(theIO);
895 aContext->Deactivate(theIO, theMode);
897 #ifdef DEBUG_DEACTIVATE_AIS
898 ObjectPtr anObject = getObject(theIO);
899 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
900 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
905 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
907 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
908 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
909 aContext->OpenLocalContext();
910 if (!isTrihedronActive())
911 deactivateTrihedron(true);
912 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
913 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
918 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
920 Handle(AIS_InteractiveContext) aContext = AISContext();
921 if (!aContext.IsNull() && myAndFilter.IsNull()) {
922 myAndFilter = new SelectMgr_AndFilter();
923 aContext->AddFilter(myAndFilter);
928 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
929 bool theUpdateViewer)
931 bool aDisplayed = false;
932 Handle(AIS_InteractiveContext) aContext = AISContext();
933 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
934 if (!aContext.IsNull() && !anAISIO.IsNull()) {
935 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
937 aContext->Deactivate(anAISIO);
938 aContext->Load(anAISIO);
939 if (toActivateInSelectionModes) {
940 if (aContext->HasOpenedContext()) {
941 if (myActiveSelectionModes.size() == 0)
942 activateAIS(anAISIO, 0, theUpdateViewer);
944 foreach(int aMode, myActiveSelectionModes) {
945 activateAIS(anAISIO, aMode, theUpdateViewer);
956 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
958 bool aErased = false;
959 Handle(AIS_InteractiveContext) aContext = AISContext();
960 if (!aContext.IsNull()) {
961 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
962 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
963 aContext->Remove(anAISIO, false/*update viewer*/);
967 if (aErased && theUpdateViewer)
973 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
975 if (theMode == NoMode)
978 Handle(AIS_InteractiveContext) aContext = AISContext();
979 if (aContext.IsNull())
982 AISObjectPtr aAISObj = getAISObject(theObject);
986 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
987 aContext->SetDisplayMode(aAISIO, theMode, false);
988 // Redisplay in order to update new mode because it could be not computed before
993 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
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 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1007 void XGUI_Displayer::deactivateSelectionFilters()
1009 Handle(AIS_InteractiveContext) aContext = AISContext();
1010 if (!myAndFilter.IsNull()) {
1011 bool aFound = false;
1012 if (!aContext.IsNull()) {
1013 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1014 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1015 for (; anIt.More() && !aFound; anIt.Next()) {
1016 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1017 aFound = aFilter == myAndFilter;
1020 aContext->RemoveFilter(myAndFilter);
1022 myAndFilter.Nullify();
1026 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1028 Handle(AIS_InteractiveContext) aContext = AISContext();
1029 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1032 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1033 if (!aCompositeFilter.IsNull()) {
1034 aCompositeFilter->Add(theFilter);
1035 #ifdef DEBUG_SELECTION_FILTERS
1036 int aCount = aCompositeFilter->StoredFilters().Extent();
1037 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1042 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1044 Handle(AIS_InteractiveContext) aContext = AISContext();
1045 if (aContext.IsNull())
1048 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1049 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1050 aCompositeFilter->Remove(theFilter);
1051 #ifdef DEBUG_SELECTION_FILTERS
1052 int aCount = aCompositeFilter->StoredFilters().Extent();
1053 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1058 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1060 bool aFilterFound = false;
1062 Handle(AIS_InteractiveContext) aContext = AISContext();
1063 if (aContext.IsNull())
1064 return aFilterFound;
1065 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1066 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1067 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1068 if (theFilter.Access() == aIt.Value().Access())
1069 aFilterFound = true;
1071 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1072 if (!aCompositeFilter.IsNull()) {
1073 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1074 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1075 if (theFilter.Access() == aIt.Value().Access())
1076 aFilterFound = true;
1079 return aFilterFound;
1082 void XGUI_Displayer::removeFilters()
1084 Handle(AIS_InteractiveContext) aContext = AISContext();
1085 if (aContext.IsNull())
1088 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1089 if (!aCompositeFilter.IsNull())
1090 aCompositeFilter->Clear();
1093 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1095 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1096 foreach(ObjectPtr aObj, aDispList) {
1097 if (!theList.contains(aObj))
1100 foreach(ObjectPtr aObj, theList) {
1101 if (!isVisible(aObj))
1102 display(aObj, false);
1107 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1109 if (!isVisible(theObject))
1112 AISObjectPtr aAISObj = getAISObject(theObject);
1113 if (aAISObj.get() == NULL)
1116 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1117 return ::canBeShaded(anAIS, myWorkshop->module());
1120 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1121 const QIntList& theModes,
1122 const bool theUpdateViewer) const
1124 Handle(AIS_InteractiveContext) aContext = AISContext();
1125 if (aContext.IsNull() || theIO.IsNull())
1128 bool isActivationChanged = false;
1129 // deactivate object in all modes, which are not in the list of activation
1130 // It seems that after the IO deactivation the selected state of the IO's owners
1131 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1132 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1133 // only if there is a difference in the current modes and the parameters modes.
1134 // If the selection problem happens again, it is possible to write a test scenario and create
1135 // a bug. The bug steps are the following:
1136 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1137 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1138 TColStd_ListOfInteger aTColModes;
1139 aContext->ActivatedModes(theIO, aTColModes);
1140 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1141 QIntList aModesActivatedForIO;
1142 bool isDeactivated = false;
1143 for (; itr.More(); itr.Next() ) {
1144 Standard_Integer aMode = itr.Value();
1145 if (!theModes.contains(aMode)) {
1146 deactivateAIS(theIO, aMode);
1147 isDeactivated = true;
1150 aModesActivatedForIO.append(aMode);
1153 if (isDeactivated) {
1154 // the selection from the previous activation modes should be cleared manually (#26172)
1155 theIO->ClearSelected();
1156 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1157 // For performance issues
1158 //if (theUpdateViewer)
1160 isActivationChanged = true;
1163 // loading the interactive object allowing the decomposition
1164 if (aTColModes.IsEmpty()) {
1165 aContext->Load(theIO, -1, true);
1168 // trihedron AIS check should be after the AIS loading.
1169 // If it is not loaded, it is steel selectable in the viewer.
1170 Handle(AIS_Trihedron) aTrihedron;
1171 if (!isTrihedronActive())
1172 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1173 if (aTrihedron.IsNull()) {
1174 // In order to clear active modes list
1175 if (theModes.size() == 0) {
1176 activateAIS(theIO, 0, theUpdateViewer);
1178 foreach(int aMode, theModes) {
1179 if (!aModesActivatedForIO.contains(aMode)) {
1180 activateAIS(theIO, aMode, theUpdateViewer);
1181 isActivationChanged = true;
1186 return isActivationChanged;
1189 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1191 AISObjectPtr anAISObj = getAISObject(theObject);
1192 // correct the result's color it it has the attribute
1193 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1195 // Customization of presentation
1196 GeomCustomPrsPtr aCustomPrs;
1197 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1198 if (aFeature.get() != NULL) {
1199 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1200 if (aCustPrs.get() != NULL)
1201 aCustomPrs = aCustPrs;
1203 if (aCustomPrs.get() == NULL) {
1204 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1205 // we ignore presentable not customized objects
1206 if (aPrs.get() == NULL)
1207 aCustomPrs = myCustomPrs;
1209 bool isCustomized = aCustomPrs.get() &&
1210 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1211 return isCustomized;
1215 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1217 if (!isVisible(theObject))
1220 AISObjectPtr anAISObj = getAISObject(theObject);
1222 anAISObj->getColor(aR, aG, aB);
1223 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1224 if (theUpdateViewer)
1226 return QColor(aR, aG, aB);
1229 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1231 myResult2AISObjectMap[theObject] = theAIS;
1233 #ifdef DEBUG_DISPLAY
1234 std::ostringstream aPtrStr;
1235 aPtrStr << theObject.get();
1236 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1237 qDebug(getResult2AISObjectMapInfo().c_str());
1241 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1243 QStringList aContent;
1244 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1245 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1246 std::ostringstream aPtrStr;
1247 aPtrStr << "aObj = " << aObj.get() << ":";
1248 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1249 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1251 aContent.append(aPtrStr.str().c_str());
1253 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1254 arg(aContent.join("\n")).toStdString().c_str();
1257 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1259 myIsTrihedronActive = theIsActive;
1260 if (!myIsTrihedronActive) {
1261 deactivateTrihedron(true);
1265 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1267 Handle(AIS_InteractiveContext) aContext = AISContext();
1268 if (aContext.IsNull())
1271 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1274 if (!aContext->IsDisplayed(aTrihedron))
1275 aContext->Display(aTrihedron,
1277 -1 /* selection mode */,
1278 Standard_True /* update viewer*/,
1279 Standard_False /* allow decomposition */,
1280 AIS_DS_Displayed /* xdisplay status */);
1282 if (!isTrihedronActive())
1283 deactivateTrihedron(false);
1285 activate(aTrihedron, myActiveSelectionModes, false);
1287 deactivateTrihedron(false);
1288 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1289 // the selection from the previous activation modes should be cleared manually (#26172)
1291 aContext->Erase(aTrihedron);
1297 QIntList XGUI_Displayer::activeSelectionModes() const
1300 foreach (int aMode, myActiveSelectionModes) {
1301 // aMode < 9 is a Shape Enum values
1302 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1307 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1308 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1310 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1311 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1312 aLContext->UnhilightPicked(Standard_False);
1314 NCollection_Map<TopoDS_Shape> aShapesSelected;
1316 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1317 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1318 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1319 Handle(SelectMgr_EntityOwner) anOwner;
1320 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1321 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1322 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1323 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1324 if (aShapesSelected.Contains(BROwnr->Shape()))
1326 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1327 anOwner->SetSelected (Standard_True);
1328 aShapesSelected.Add(BROwnr->Shape());
1331 aLContext->HilightPicked(Standard_False);