1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_Displayer.cpp
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include "XGUI_Displayer.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_CustomPrs.h"
15 #include <AppElements_Viewer.h>
18 #include <ModelAPI_Document.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_Tools.h>
22 #include <ModelAPI_AttributeIntArray.h>
23 #include <ModelAPI_ResultCompSolid.h>
25 #include <ModuleBase_ResultPrs.h>
26 #include <ModuleBase_Tools.h>
27 #include <ModuleBase_IModule.h>
28 #include <ModuleBase_ViewerPrs.h>
29 #include <ModuleBase_Preferences.h>
31 #include <GeomAPI_Shape.h>
32 #include <GeomAPI_IPresentable.h>
33 #include <GeomAPI_ICustomPrs.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <AIS_InteractiveContext.hxx>
38 #include <AIS_LocalContext.hxx>
39 #include <AIS_ListOfInteractive.hxx>
40 #include <AIS_ListIteratorOfListOfInteractive.hxx>
41 #include <AIS_DimensionSelectionMode.hxx>
42 #include <AIS_Shape.hxx>
43 #include <AIS_Dimension.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Plane.hxx>
47 #include <AIS_Point.hxx>
48 #include <AIS_Selection.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
50 #include <SelectMgr_ListOfFilter.hxx>
51 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
52 #include <Prs3d_Drawer.hxx>
53 #include <Prs3d_IsoAspect.hxx>
54 #include <SelectMgr_SelectionManager.hxx>
56 #include <StdSelect_ViewerSelector3d.hxx>
58 #include <TColStd_MapOfTransient.hxx>
59 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
61 #include <Events_Loop.h>
62 #include <ModelAPI_Events.h>
66 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
68 //#define DEBUG_ACTIVATE_OBJECTS
69 //#define DEBUG_DEACTIVATE
70 //#define DEBUG_ACTIVATE_AIS
71 //#define DEBUG_DEACTIVATE_AIS
73 //#define DEBUG_DISPLAY
74 //#define DEBUG_FEATURE_REDISPLAY
75 //#define DEBUG_SELECTION_FILTERS
77 //#define DEBUG_COMPOSILID_DISPLAY
78 // Workaround for bug #25637
80 //#define DEBUG_OCCT_SHAPE_SELECTION
82 #define WORKAROUND_UNTIL_27523_IS_FIXED
84 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
86 // Get from null point
87 theAIS->DisplayedObjects(theList, true);
88 if (theAIS->HasOpenedContext()) {
89 // get from local context
90 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
91 TColStd_MapOfTransient aMap;
92 int NbDisp = aLC->DisplayedObjects(aMap);
93 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
95 Handle(AIS_InteractiveObject) curIO;
96 Handle(Standard_Transient) Tr;
97 for(; aIt.More(); aIt.Next()){
99 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
100 theList.Append(curIO);
105 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
108 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
109 for (; anIt != aLast; anIt++) {
110 anInfo.append(QString::number(*anIt));
112 return anInfo.join(theSeparator);
115 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
116 : myWorkshop(theWorkshop), myNeedUpdate(false),
117 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0)
119 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
122 XGUI_Displayer::~XGUI_Displayer()
126 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
128 return myResult2AISObjectMap.contains(theObject);
131 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
133 bool aDisplayed = false;
134 if (isVisible(theObject)) {
135 #ifdef DEBUG_COMPOSILID_DISPLAY
136 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
137 if (aCompsolidResult.get()) {
138 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
139 ResultPtr aSubResult = aCompsolidResult->subResult(i);
140 if (aSubResult.get())
141 redisplay(aSubResult, false);
148 aDisplayed = redisplay(theObject, theUpdateViewer);
151 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
152 bool isShading = false;
153 if (aPrs.get() != NULL) {
154 anAIS = aPrs->getAISObject(anAIS);
156 // correct deviation coefficient for
157 Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
158 if (!anAISPrs.IsNull()) {
159 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
160 if (!aShapePrs.IsNull()) {
161 TopoDS_Shape aShape = aShapePrs->Shape();
162 if (!aShape.IsNull())
163 ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
168 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
169 if (aResult.get() != NULL) {
170 #ifdef DEBUG_COMPOSILID_DISPLAY
171 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
172 if (aCompsolidResult.get()) {
173 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
174 ResultPtr aSubResult = aCompsolidResult->subResult(i);
175 if (aSubResult.get())
176 display(aSubResult, false);
183 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
184 if (aShapePtr.get() != NULL) {
185 anAIS = AISObjectPtr(new GeomAPI_AISObject());
186 Handle(AIS_InteractiveObject) anAISPrs = myWorkshop->module()->createPresentation(aResult);
187 if (anAISPrs.IsNull())
188 anAISPrs = new ModuleBase_ResultPrs(aResult);
189 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
190 //anAIS->createShape(aShapePtr);
193 #ifdef DEBUG_COMPOSILID_DISPLAY
199 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
204 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
206 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
207 if (!aShapePrs.IsNull()) {
208 TopoDS_Shape aShape = aShapePrs->Shape();
211 TopAbs_ShapeEnum aType = aShape.ShapeType();
212 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
215 // Check that the presentation is not a sketch
216 return theModule->canBeShaded(theAIS);
222 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
223 bool isShading, bool theUpdateViewer)
225 bool aDisplayed = false;
227 Handle(AIS_InteractiveContext) aContext = AISContext();
228 if (aContext.IsNull())
231 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
232 if (!anAISIO.IsNull()) {
233 appendResultObject(theObject, theAIS);
235 bool isCustomized = customizeObject(theObject);
237 int aDispMode = isShading? Shading : Wireframe;
239 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
240 anAISIO->SetDisplayMode(aDispMode);
241 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
244 emit objectDisplayed(theObject, theAIS);
245 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
253 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
255 bool aErased = false;
256 if (!isVisible(theObject))
259 Handle(AIS_InteractiveContext) aContext = AISContext();
260 if (aContext.IsNull())
263 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
265 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
266 if (!anAIS.IsNull()) {
267 emit beforeObjectErase(theObject, anObject);
268 aContext->Remove(anAIS, false/*update viewer*/);
269 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::erase -- Remove");
273 myResult2AISObjectMap.remove(theObject);
276 std::ostringstream aPtrStr;
277 aPtrStr << theObject.get();
278 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
279 qDebug(getResult2AISObjectMapInfo().c_str());
288 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
290 bool aRedisplayed = false;
291 if (!isVisible(theObject))
294 AISObjectPtr aAISObj = getAISObject(theObject);
295 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
297 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
299 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
301 aRedisplayed = erase(theObject, theUpdateViewer);
304 if (aAIS_Obj != aAISObj) {
305 appendResultObject(theObject, aAIS_Obj);
307 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
310 Handle(AIS_InteractiveContext) aContext = AISContext();
311 if (!aContext.IsNull() && !aAISIO.IsNull()) {
312 // Check that the visualized shape is the same and the redisplay is not necessary
313 // Redisplay of AIS object leads to this object selection compute and the selection
314 // in the browser is lost
315 // this check is not necessary anymore because the selection store/restore is realized
316 // before and after the values modification.
317 // Moreother, this check avoids customize and redisplay presentation if the presentable
318 // parameter is changed.
319 bool isEqualShapes = false;
320 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
321 if (aResult.get() != NULL) {
322 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
323 if (!aShapePrs.IsNull()) {
324 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
325 if (aShapePtr.get()) {
326 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
327 if (!aOldShape.IsNull())
328 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
332 // Customization of presentation
333 bool isCustomized = customizeObject(theObject);
334 #ifdef DEBUG_FEATURE_REDISPLAY
335 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
336 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
338 if (!isEqualShapes || isCustomized) {
339 /// if shapes are equal and presentation are customized, selection should be restored
340 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
341 if (aNeedToRestoreSelection)
342 myWorkshop->module()->storeSelection();
344 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
345 if (!myActiveSelectionModes.contains(0))
346 aContext->Activate(aAISIO, 0);
349 aContext->Redisplay(aAISIO, false);
351 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
352 if (!myActiveSelectionModes.contains(0))
353 aContext->Deactivate(aAISIO, 0);
356 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::redisplay -- Redisplay");
358 if (aNeedToRestoreSelection)
359 myWorkshop->module()->restoreSelection();
362 #ifdef DEBUG_FEATURE_REDISPLAY
363 qDebug(" Redisplay happens");
372 void XGUI_Displayer::redisplayObjects()
374 // redisplay objects visualized in the viewer
375 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
376 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
377 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
378 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
379 for (; anIt != aLast; anIt++) {
380 aECreator->sendUpdated(*anIt, EVENT_DISP);
382 Events_Loop::loop()->flush(EVENT_DISP);
385 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
387 #ifdef DEBUG_DEACTIVATE
388 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
389 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
390 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
392 toStdString().c_str());
394 Handle(AIS_InteractiveContext) aContext = AISContext();
395 if (!aContext.IsNull() && isVisible(theObject)) {
396 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
397 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
399 deactivateAIS(anAIS);
400 // the selection from the previous activation modes should be cleared manually (#26172)
401 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
402 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivate -- ClearOutdatedSelection");
408 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
409 const bool theUpdateViewer)
411 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
412 //if (!aTrihedron.IsNull())
413 // deactivateAIS(aTrihedron);
415 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
416 for (; anIt != aLast; anIt++) {
417 deactivate(*anIt, false);
419 //VSV It seems that there is no necessity to update viewer on deactivation
420 //if (theUpdateViewer)
424 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
426 Handle(AIS_InteractiveContext) aContext = AISContext();
427 if (aContext.IsNull() || !isVisible(theObject))
430 AISObjectPtr aAISObj = getAISObject(theObject);
432 if (aAISObj.get() != NULL) {
433 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
434 TColStd_ListOfInteger aTColModes;
435 aContext->ActivatedModes(anAISIO, aTColModes);
436 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
437 for (; itr.More(); itr.Next() ) {
438 theModes.append(itr.Value());
443 int XGUI_Displayer::getSelectionMode(int theShapeType)
445 return (theShapeType >= TopAbs_SHAPE)? theShapeType :
446 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
449 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
451 bool aVisible = false;
452 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
453 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
454 if (aPrs.get() || aResult.get()) {
455 aVisible = theDisplayer->isVisible(theObject);
456 // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
457 // visible. It is useful for highlight presentation where compsolid shape is selectable
458 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
459 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
460 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
461 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
462 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
463 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
465 aVisible = anAllSubsVisible;
469 // it is possible that feature is presentable and has results, so we should check visibility
470 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
472 // check if all results of the feature are visible
473 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
474 std::list<ResultPtr> aResults = aFeature->results();
475 std::list<ResultPtr>::const_iterator aIt;
476 aVisible = !aResults.empty();
477 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
478 aVisible = aVisible && theDisplayer->isVisible(*aIt);
484 #ifdef DEBUG_ACTIVATE_OBJECTS
485 QString getModeInfo(const int theMode)
487 QString anInfo = "Undefined";
489 case 0: anInfo = "SHAPE(0)"; break;
490 case 1: anInfo = "VERTEX(1)"; break;
491 case 2: anInfo = "EDGE(2)"; break;
492 case 3: anInfo = "WIRE(3)"; break;
493 case 4: anInfo = "FACE(4)"; break;
494 case 5: anInfo = "SHELL(5)"; break;
495 case 6: anInfo = "SOLID(6)"; break;
496 case 7: anInfo = "COMPSOLID(7)"; break;
497 case 8: anInfo = "COMPOUND(8)"; break;
498 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
499 case 101: anInfo = "Sel_Constraint(101)"; break;
500 case 102: anInfo = "Sel_Dimension_All(102)"; break;
501 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
502 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
508 QString getModesInfo(const QIntList& theModes)
510 QStringList aModesInfo;
511 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
512 aModesInfo.append(getModeInfo(theModes[i]));
513 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
517 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
518 const bool theUpdateViewer)
520 // Convert shape types to selection types
522 foreach(int aType, theModes) {
523 aModes.append(getSelectionMode(aType));
526 #ifdef DEBUG_ACTIVATE_OBJECTS
528 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
529 for (; anIt != aLast; ++anIt) {
530 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
532 QString anInfoStr = anInfo.join(", ");
534 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
535 arg(getModesInfo(aModes)).
536 arg(getModesInfo(myActiveSelectionModes)).
537 arg(theObjList.size()).
539 toStdString().c_str());
541 // In order to avoid doblications of selection modes
543 foreach (int aMode, aModes) {
544 if (!aNewModes.contains(aMode))
545 aNewModes.append(aMode);
547 myActiveSelectionModes = aNewModes;
548 Handle(AIS_InteractiveContext) aContext = AISContext();
549 // Open local context if there is no one
550 if (aContext.IsNull() || !aContext->HasOpenedContext())
553 //aContext->UseDisplayedObjects();
554 //myUseExternalObjects = true;
556 Handle(AIS_InteractiveObject) anAISIO;
557 AIS_ListOfInteractive aPrsList;
558 //if (aObjList.isEmpty())
561 foreach(ObjectPtr aObj, theObjList) {
562 if (myResult2AISObjectMap.contains(aObj))
563 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
567 // Add trihedron because it has to partisipate in selection
568 Handle(AIS_InteractiveObject) aTrihedron;
569 if (isTrihedronActive()) {
570 aTrihedron = getTrihedron();
571 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
572 aPrsList.Append(aTrihedron);
574 if (aPrsList.Extent() == 0)
577 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
578 bool isActivationChanged = false;
579 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
580 anAISIO = aLIt.Value();
581 if (activate(anAISIO, myActiveSelectionModes, false))
582 isActivationChanged = true;
586 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
588 Handle(AIS_InteractiveContext) aContext = AISContext();
589 if (aContext.IsNull() || !isVisible(theObject))
592 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
593 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
595 TColStd_ListOfInteger aModes;
596 aContext->ActivatedModes(anAIS, aModes);
597 return aModes.Extent() > 0;
599 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
601 Handle(AIS_InteractiveContext) aContext = AISContext();
602 if (aContext.IsNull())
604 if (aContext->HasOpenedContext()) {
605 aContext->UnhilightSelected(false);
606 aContext->ClearSelected(false);
607 NCollection_Map<TopoDS_Shape> aShapesToBeSelected;
609 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
610 const GeomShapePtr& aGeomShape = aPrs->shape();
611 if (aGeomShape.get() && !aGeomShape->isNull()) {
612 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
613 #ifdef DEBUG_OCCT_SHAPE_SELECTION
614 aContext->AddOrRemoveSelected(aShape, false);
616 aShapesToBeSelected.Add(aShape);
619 ObjectPtr anObject = aPrs->object();
620 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
621 if (aResult.get() && isVisible(aResult)) {
622 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
623 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
624 if (!anAIS.IsNull()) {
625 // The methods are replaced in order to provide multi-selection, e.g. restore selection
626 // by activating multi selector widget. It also gives an advantage that the multi
627 // selection in OB gives multi-selection in the viewer
628 //aContext->SetSelected(anAIS, false);
629 // The selection in the context was cleared, so the method sets the objects are selected
630 aContext->AddOrRemoveSelected(anAIS, false);
635 if (!aShapesToBeSelected.IsEmpty())
636 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
637 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
638 aContext->UnhilightCurrents(false);
639 aContext->ClearCurrents(false);
640 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
641 ObjectPtr anObject = aPrs->object();
642 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
643 if (aResult.get() && isVisible(aResult)) {
644 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
645 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
647 aContext->SetCurrentObject(anAIS, false);
651 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::setSelected -- AddOrRemoveSelected/UnhilightCurrents(no local context)");
656 void XGUI_Displayer::clearSelected()
658 Handle(AIS_InteractiveContext) aContext = AISContext();
659 if (!aContext.IsNull()) {
660 aContext->UnhilightCurrents(false);
661 aContext->ClearSelected();
665 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
667 bool aErased = false;
668 Handle(AIS_InteractiveContext) aContext = AISContext();
669 if (!aContext.IsNull()) {
670 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
671 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
673 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
674 if (!anIO.IsNull()) {
675 emit beforeObjectErase(aObj, aAISObj);
676 aContext->Remove(anIO, false/*update viewer*/);
683 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAll -- Remove");
684 myResult2AISObjectMap.clear();
687 qDebug(getResult2AISObjectMapInfo().c_str());
692 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
693 Handle(AIS_InteractiveObject) theObject,
694 const bool theClear = true)
696 if (!theObject.IsNull()) {
697 theContext->Deactivate(theObject);
698 ModuleBase_Tools::selectionInfo(theContext, "XGUI_Displayer::deactivateObject -- Deactivate");
700 //theObject->ClearSelected();
701 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
706 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
708 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
709 Handle(AIS_InteractiveContext) aContext = AISContext();
710 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
711 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
712 deactivateObject(aContext, aTrie);
714 /// #1136 hidden axis are selected in sketch
715 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
716 /// for Position AIS object in SelectionModes.
717 deactivateObject(aContext, aTrie->XAxis());
718 deactivateObject(aContext, aTrie->YAxis());
719 deactivateObject(aContext, aTrie->Axis());
720 deactivateObject(aContext, aTrie->Position());
722 deactivateObject(aContext, aTrie->XYPlane());
723 deactivateObject(aContext, aTrie->XZPlane());
724 deactivateObject(aContext, aTrie->YZPlane());
731 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
733 return myWorkshop->viewer()->trihedron();
736 void XGUI_Displayer::openLocalContext()
738 Handle(AIS_InteractiveContext) aContext = AISContext();
739 // Open local context if there is no one
740 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
741 // Preserve selected objects
742 //AIS_ListOfInteractive aAisList;
743 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
744 // aAisList.Append(aContext->Current());
746 // get the filters from the global context and append them to the local context
747 // a list of filters in the global context is not cleared and should be cleared here
748 SelectMgr_ListOfFilter aFilters;
749 aFilters.Assign(aContext->Filters());
750 // it is important to remove the filters in the global context, because there is a code
751 // in the closeLocalContex, which restore the global context filters
752 aContext->RemoveFilters();
754 //aContext->ClearCurrents();
755 aContext->OpenLocalContext();
756 //deactivateTrihedron();
757 //aContext->NotUseDisplayedObjects();
759 //myUseExternalObjects = false;
761 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
762 for (;aIt.More(); aIt.Next()) {
763 aContext->AddFilter(aIt.Value());
766 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
767 //for(; aIt2.More(); aIt2.Next()) {
768 // aContext->SetSelected(aIt2.Value(), false);
773 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
775 Handle(AIS_InteractiveContext) aContext = AISContext();
776 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
777 // Preserve selected objects
778 //AIS_ListOfInteractive aAisList;
779 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
780 // aAisList.Append(aContext->SelectedInteractive());
782 // get the filters from the local context and append them to the global context
783 // a list of filters in the local context is cleared
784 SelectMgr_ListOfFilter aFilters;
785 aFilters.Assign(aContext->Filters());
787 //aContext->ClearSelected();
788 aContext->CloseAllContexts(false);
790 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
791 // this code is obsolete. It is temporaty commented and should be removed after
792 // the test campaign.
793 // Redisplay all object if they were displayed in localContext
794 /*Handle(AIS_InteractiveObject) aAISIO;
795 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
796 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
797 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
798 aContext->Display(aAISIO, false);
799 aContext->SetDisplayMode(aAISIO, Shading, false);
803 // Append the filters from the local selection in the global selection context
804 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
805 for (;aIt.More(); aIt.Next()) {
806 Handle(SelectMgr_Filter) aFilter = aIt.Value();
807 aContext->AddFilter(aFilter);
812 //myUseExternalObjects = false;
815 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
816 //for(; aIt2.More(); aIt2.Next()) {
817 // if (aContext->IsDisplayed(aIt2.Value()))
818 // aContext->SetCurrentObject(aIt2.Value(), false);
823 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
826 if (myResult2AISObjectMap.contains(theObject))
827 anIO = myResult2AISObjectMap[theObject];
831 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
833 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
834 return getObject(aRefAIS);
837 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
840 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
841 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
842 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
848 if (!anObject.get()) {
849 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
850 if (!theIO.IsNull()) {
851 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
853 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
858 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
860 bool aWasEnabled = isUpdateEnabled();
862 myViewerBlockedRecursiveCount--;
864 myViewerBlockedRecursiveCount++;
866 if (myNeedUpdate && isUpdateEnabled()) {
868 myNeedUpdate = false;
873 bool XGUI_Displayer::isUpdateEnabled() const
875 return myViewerBlockedRecursiveCount == 0;
878 void XGUI_Displayer::updateViewer() const
880 Handle(AIS_InteractiveContext) aContext = AISContext();
881 if (!aContext.IsNull() && isUpdateEnabled()) {
882 myWorkshop->viewer()->Zfitall();
883 aContext->UpdateCurrentViewer();
889 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
890 const int theMode, const bool theUpdateViewer) const
892 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
893 if (!aContext.IsNull()) {
894 if (myWorkshop->module()) {
895 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
896 aContext->Activate(theIO, theMode, false);
898 aContext->Activate(theIO, theMode, false);
900 // the fix from VPA for more suitable selection of sketcher lines
901 double aPrecision = theIO->Width() + 2;
902 if (theMode == getSelectionMode(TopAbs_VERTEX))
903 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer", "point-selection-sensitivity", 20);
904 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
906 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activateAIS -- Activate");
908 #ifdef DEBUG_ACTIVATE_AIS
909 ObjectPtr anObject = getObject(theIO);
910 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
911 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
918 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
920 Handle(AIS_InteractiveContext) aContext = AISContext();
921 if (!aContext.IsNull()) {
923 aContext->Deactivate(theIO);
925 aContext->Deactivate(theIO, theMode);
926 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivateAIS -- Deactivate");
928 #ifdef DEBUG_DEACTIVATE_AIS
929 ObjectPtr anObject = getObject(theIO);
930 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
931 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
936 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
938 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
939 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
940 aContext->OpenLocalContext();
941 if (!isTrihedronActive())
942 deactivateTrihedron(true);
943 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
944 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
949 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
951 Handle(AIS_InteractiveContext) aContext = AISContext();
952 if (!aContext.IsNull() && myAndFilter.IsNull()) {
953 myAndFilter = new SelectMgr_AndFilter();
954 aContext->AddFilter(myAndFilter);
959 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
960 bool theUpdateViewer)
962 bool aDisplayed = false;
963 Handle(AIS_InteractiveContext) aContext = AISContext();
964 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
965 if (!aContext.IsNull() && !anAISIO.IsNull()) {
966 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
968 aContext->Deactivate(anAISIO);
969 aContext->Load(anAISIO);
970 if (toActivateInSelectionModes) {
971 if (aContext->HasOpenedContext()) {
972 if (myActiveSelectionModes.size() == 0)
973 activateAIS(anAISIO, 0, theUpdateViewer);
975 foreach(int aMode, myActiveSelectionModes) {
976 activateAIS(anAISIO, aMode, theUpdateViewer);
987 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
989 bool aErased = false;
990 Handle(AIS_InteractiveContext) aContext = AISContext();
991 if (!aContext.IsNull()) {
992 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
993 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
994 aContext->Remove(anAISIO, false/*update viewer*/);
995 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAIS -- Remove");
999 if (aErased && theUpdateViewer)
1005 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1007 if (theMode == NoMode)
1010 Handle(AIS_InteractiveContext) aContext = AISContext();
1011 if (aContext.IsNull())
1014 AISObjectPtr aAISObj = getAISObject(theObject);
1018 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1019 aContext->SetDisplayMode(aAISIO, theMode, false);
1020 // Redisplay in order to update new mode because it could be not computed before
1021 if (theUpdateViewer)
1025 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1027 Handle(AIS_InteractiveContext) aContext = AISContext();
1028 if (aContext.IsNull())
1031 AISObjectPtr aAISObj = getAISObject(theObject);
1035 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1036 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1039 void XGUI_Displayer::deactivateSelectionFilters()
1041 Handle(AIS_InteractiveContext) aContext = AISContext();
1042 if (!myAndFilter.IsNull()) {
1043 bool aFound = false;
1044 if (!aContext.IsNull()) {
1045 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1046 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1047 for (; anIt.More() && !aFound; anIt.Next()) {
1048 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1049 aFound = aFilter == myAndFilter;
1052 aContext->RemoveFilter(myAndFilter);
1054 myAndFilter.Nullify();
1058 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1060 Handle(AIS_InteractiveContext) aContext = AISContext();
1061 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1064 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1065 if (!aCompositeFilter.IsNull()) {
1066 aCompositeFilter->Add(theFilter);
1067 #ifdef DEBUG_SELECTION_FILTERS
1068 int aCount = aCompositeFilter->StoredFilters().Extent();
1069 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1074 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1076 Handle(AIS_InteractiveContext) aContext = AISContext();
1077 if (aContext.IsNull())
1080 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1081 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1082 aCompositeFilter->Remove(theFilter);
1083 #ifdef DEBUG_SELECTION_FILTERS
1084 int aCount = aCompositeFilter->StoredFilters().Extent();
1085 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1090 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1092 bool aFilterFound = false;
1094 Handle(AIS_InteractiveContext) aContext = AISContext();
1095 if (aContext.IsNull())
1096 return aFilterFound;
1097 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1098 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1099 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1100 if (theFilter.Access() == aIt.Value().Access())
1101 aFilterFound = true;
1103 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1104 if (!aCompositeFilter.IsNull()) {
1105 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1106 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1107 if (theFilter.Access() == aIt.Value().Access())
1108 aFilterFound = true;
1111 return aFilterFound;
1114 void XGUI_Displayer::removeFilters()
1116 Handle(AIS_InteractiveContext) aContext = AISContext();
1117 if (aContext.IsNull())
1120 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1121 if (!aCompositeFilter.IsNull())
1122 aCompositeFilter->Clear();
1125 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1127 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1128 foreach(ObjectPtr aObj, aDispList) {
1129 if (!theList.contains(aObj))
1132 foreach(ObjectPtr aObj, theList) {
1133 if (!isVisible(aObj))
1134 display(aObj, false);
1139 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1141 if (!isVisible(theObject))
1144 AISObjectPtr aAISObj = getAISObject(theObject);
1145 if (aAISObj.get() == NULL)
1148 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1149 return ::canBeShaded(anAIS, myWorkshop->module());
1152 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1153 const QIntList& theModes,
1154 const bool theUpdateViewer) const
1156 Handle(AIS_InteractiveContext) aContext = AISContext();
1157 if (aContext.IsNull() || theIO.IsNull())
1160 bool isActivationChanged = false;
1161 // deactivate object in all modes, which are not in the list of activation
1162 // It seems that after the IO deactivation the selected state of the IO's owners
1163 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1164 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1165 // only if there is a difference in the current modes and the parameters modes.
1166 // If the selection problem happens again, it is possible to write a test scenario and create
1167 // a bug. The bug steps are the following:
1168 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1169 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1170 TColStd_ListOfInteger aTColModes;
1171 aContext->ActivatedModes(theIO, aTColModes);
1172 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1173 QIntList aModesActivatedForIO;
1174 bool isDeactivated = false;
1175 for (; itr.More(); itr.Next() ) {
1176 Standard_Integer aMode = itr.Value();
1177 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1178 if (!theModes.contains(aMode)) {
1179 deactivateAIS(theIO, aMode);
1180 isDeactivated = true;
1183 aModesActivatedForIO.append(aMode);
1186 if (isDeactivated) {
1187 // the selection from the previous activation modes should be cleared manually (#26172)
1188 theIO->ClearSelected();
1189 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1190 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activate -- ClearSelected/ClearOutdatedSelection");
1191 // For performance issues
1192 //if (theUpdateViewer)
1194 isActivationChanged = true;
1197 // loading the interactive object allowing the decomposition
1198 if (aTColModes.IsEmpty()) {
1199 aContext->Load(theIO, -1, true);
1202 // trihedron AIS check should be after the AIS loading.
1203 // If it is not loaded, it is steel selectable in the viewer.
1204 Handle(AIS_Trihedron) aTrihedron;
1205 if (!isTrihedronActive())
1206 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1207 if (aTrihedron.IsNull()) {
1208 // In order to clear active modes list
1209 if (theModes.size() == 0) {
1210 activateAIS(theIO, 0, theUpdateViewer);
1212 foreach(int aMode, theModes) {
1213 if (!aModesActivatedForIO.contains(aMode)) {
1214 activateAIS(theIO, aMode, theUpdateViewer);
1215 isActivationChanged = true;
1220 return isActivationChanged;
1223 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1225 AISObjectPtr anAISObj = getAISObject(theObject);
1226 // correct the result's color it it has the attribute
1227 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1229 // Customization of presentation
1230 GeomCustomPrsPtr aCustomPrs;
1231 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1232 if (aFeature.get() != NULL) {
1233 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1234 if (aCustPrs.get() != NULL)
1235 aCustomPrs = aCustPrs;
1237 if (aCustomPrs.get() == NULL) {
1238 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1239 // we ignore presentable not customized objects
1240 if (aPrs.get() == NULL)
1241 aCustomPrs = myCustomPrs;
1243 bool isCustomized = aCustomPrs.get() &&
1244 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1245 return isCustomized;
1249 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1251 if (!isVisible(theObject))
1254 AISObjectPtr anAISObj = getAISObject(theObject);
1256 anAISObj->getColor(aR, aG, aB);
1257 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1258 if (theUpdateViewer)
1260 return QColor(aR, aG, aB);
1263 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1265 myResult2AISObjectMap[theObject] = theAIS;
1267 #ifdef DEBUG_DISPLAY
1268 std::ostringstream aPtrStr;
1269 aPtrStr << theObject.get();
1270 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1271 qDebug(getResult2AISObjectMapInfo().c_str());
1275 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1277 QStringList aContent;
1278 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1279 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1280 std::ostringstream aPtrStr;
1281 aPtrStr << "aObj = " << aObj.get() << ":";
1282 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1283 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1285 aContent.append(aPtrStr.str().c_str());
1287 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1288 arg(aContent.join("\n")).toStdString().c_str();
1291 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1293 myIsTrihedronActive = theIsActive;
1294 if (!myIsTrihedronActive) {
1295 deactivateTrihedron(true);
1299 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1301 Handle(AIS_InteractiveContext) aContext = AISContext();
1302 if (aContext.IsNull())
1305 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1308 if (!aContext->IsDisplayed(aTrihedron))
1309 aContext->Display(aTrihedron,
1311 -1 /* selection mode */,
1312 Standard_True /* update viewer*/,
1313 Standard_False /* allow decomposition */,
1314 AIS_DS_Displayed /* xdisplay status */);
1316 if (!isTrihedronActive())
1317 deactivateTrihedron(false);
1319 activate(aTrihedron, myActiveSelectionModes, false);
1321 deactivateTrihedron(false);
1322 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1323 // the selection from the previous activation modes should be cleared manually (#26172)
1325 aContext->Erase(aTrihedron);
1331 QIntList XGUI_Displayer::activeSelectionModes() const
1334 foreach (int aMode, myActiveSelectionModes) {
1335 // aMode < 9 is a Shape Enum values
1336 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1341 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1342 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1344 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1345 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1346 aLContext->UnhilightPicked(Standard_False);
1348 NCollection_Map<TopoDS_Shape> aShapesSelected;
1350 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1351 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1352 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1353 Handle(SelectMgr_EntityOwner) anOwner;
1354 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1355 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1356 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1357 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1358 if (aShapesSelected.Contains(BROwnr->Shape()))
1360 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1361 anOwner->SetSelected (Standard_True);
1362 aShapesSelected.Add(BROwnr->Shape());
1365 aLContext->HilightPicked(Standard_False);