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*/);
263 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::erase -- Remove");
267 myResult2AISObjectMap.remove(theObject);
270 std::ostringstream aPtrStr;
271 aPtrStr << theObject.get();
272 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
273 qDebug(getResult2AISObjectMapInfo().c_str());
282 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
284 bool aRedisplayed = false;
285 if (!isVisible(theObject))
288 AISObjectPtr aAISObj = getAISObject(theObject);
289 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
291 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
293 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
295 aRedisplayed = erase(theObject, theUpdateViewer);
298 if (aAIS_Obj != aAISObj) {
299 appendResultObject(theObject, aAIS_Obj);
301 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
304 Handle(AIS_InteractiveContext) aContext = AISContext();
305 if (!aContext.IsNull() && !aAISIO.IsNull()) {
306 // Check that the visualized shape is the same and the redisplay is not necessary
307 // Redisplay of AIS object leads to this object selection compute and the selection
308 // in the browser is lost
309 // this check is not necessary anymore because the selection store/restore is realized
310 // before and after the values modification.
311 // Moreother, this check avoids customize and redisplay presentation if the presentable
312 // parameter is changed.
313 bool isEqualShapes = false;
314 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
315 if (aResult.get() != NULL) {
316 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
317 if (!aShapePrs.IsNull()) {
318 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
319 if (aShapePtr.get()) {
320 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
321 if (!aOldShape.IsNull())
322 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
326 // Customization of presentation
327 bool isCustomized = customizeObject(theObject);
328 #ifdef DEBUG_FEATURE_REDISPLAY
329 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
330 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
332 if (!isEqualShapes || isCustomized) {
333 /// if shapes are equal and presentation are customized, selection should be restored
334 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
335 if (aNeedToRestoreSelection)
336 myWorkshop->module()->storeSelection();
338 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
339 if (!myActiveSelectionModes.contains(0))
340 aContext->Activate(aAISIO, 0);
343 aContext->Redisplay(aAISIO, false);
345 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
346 if (!myActiveSelectionModes.contains(0))
347 aContext->Deactivate(aAISIO, 0);
350 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::redisplay -- Redisplay");
352 if (aNeedToRestoreSelection)
353 myWorkshop->module()->restoreSelection();
356 #ifdef DEBUG_FEATURE_REDISPLAY
357 qDebug(" Redisplay happens");
366 void XGUI_Displayer::redisplayObjects()
368 // redisplay objects visualized in the viewer
369 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
370 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
371 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
372 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
373 for (; anIt != aLast; anIt++) {
374 aECreator->sendUpdated(*anIt, EVENT_DISP);
376 Events_Loop::loop()->flush(EVENT_DISP);
379 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
381 #ifdef DEBUG_DEACTIVATE
382 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
383 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
384 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
386 toStdString().c_str());
388 Handle(AIS_InteractiveContext) aContext = AISContext();
389 if (!aContext.IsNull() && isVisible(theObject)) {
390 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
391 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
393 deactivateAIS(anAIS);
394 // the selection from the previous activation modes should be cleared manually (#26172)
395 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
396 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivate -- ClearOutdatedSelection");
402 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
403 const bool theUpdateViewer)
405 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
406 //if (!aTrihedron.IsNull())
407 // deactivateAIS(aTrihedron);
409 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
410 for (; anIt != aLast; anIt++) {
411 deactivate(*anIt, false);
413 //VSV It seems that there is no necessity to update viewer on deactivation
414 //if (theUpdateViewer)
418 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
420 Handle(AIS_InteractiveContext) aContext = AISContext();
421 if (aContext.IsNull() || !isVisible(theObject))
424 AISObjectPtr aAISObj = getAISObject(theObject);
426 if (aAISObj.get() != NULL) {
427 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
428 TColStd_ListOfInteger aTColModes;
429 aContext->ActivatedModes(anAISIO, aTColModes);
430 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
431 for (; itr.More(); itr.Next() ) {
432 theModes.append(itr.Value());
437 int XGUI_Displayer::getSelectionMode(int theShapeType)
439 return (theShapeType >= TopAbs_SHAPE)? theShapeType :
440 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
443 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
445 bool aVisible = false;
446 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
447 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
448 if (aPrs.get() || aResult.get()) {
449 aVisible = theDisplayer->isVisible(theObject);
450 // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
451 // visible. It is useful for highlight presentation where compsolid shape is selectable
452 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
453 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
454 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
455 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
456 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
457 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
459 aVisible = anAllSubsVisible;
463 // it is possible that feature is presentable and has results, so we should check visibility
464 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
466 // check if all results of the feature are visible
467 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
468 std::list<ResultPtr> aResults = aFeature->results();
469 std::list<ResultPtr>::const_iterator aIt;
470 aVisible = !aResults.empty();
471 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
472 aVisible = aVisible && theDisplayer->isVisible(*aIt);
478 #ifdef DEBUG_ACTIVATE_OBJECTS
479 QString getModeInfo(const int theMode)
481 QString anInfo = "Undefined";
483 case 0: anInfo = "SHAPE(0)"; break;
484 case 1: anInfo = "VERTEX(1)"; break;
485 case 2: anInfo = "EDGE(2)"; break;
486 case 3: anInfo = "WIRE(3)"; break;
487 case 4: anInfo = "FACE(4)"; break;
488 case 5: anInfo = "SHELL(5)"; break;
489 case 6: anInfo = "SOLID(6)"; break;
490 case 7: anInfo = "COMPSOLID(7)"; break;
491 case 8: anInfo = "COMPOUND(8)"; break;
492 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
493 case 101: anInfo = "Sel_Constraint(101)"; break;
494 case 102: anInfo = "Sel_Dimension_All(102)"; break;
495 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
496 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
502 QString getModesInfo(const QIntList& theModes)
504 QStringList aModesInfo;
505 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
506 aModesInfo.append(getModeInfo(theModes[i]));
507 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
511 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
512 const bool theUpdateViewer)
514 // Convert shape types to selection types
516 foreach(int aType, theModes) {
517 aModes.append(getSelectionMode(aType));
520 #ifdef DEBUG_ACTIVATE_OBJECTS
522 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
523 for (; anIt != aLast; ++anIt) {
524 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
526 QString anInfoStr = anInfo.join(", ");
528 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
529 arg(getModesInfo(aModes)).
530 arg(getModesInfo(myActiveSelectionModes)).
531 arg(theObjList.size()).
533 toStdString().c_str());
535 // In order to avoid doblications of selection modes
537 foreach (int aMode, aModes) {
538 if (!aNewModes.contains(aMode))
539 aNewModes.append(aMode);
541 myActiveSelectionModes = aNewModes;
542 Handle(AIS_InteractiveContext) aContext = AISContext();
543 // Open local context if there is no one
544 if (aContext.IsNull() || !aContext->HasOpenedContext())
547 //aContext->UseDisplayedObjects();
548 //myUseExternalObjects = true;
550 Handle(AIS_InteractiveObject) anAISIO;
551 AIS_ListOfInteractive aPrsList;
552 //if (aObjList.isEmpty())
555 foreach(ObjectPtr aObj, theObjList) {
556 if (myResult2AISObjectMap.contains(aObj))
557 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
561 // Add trihedron because it has to partisipate in selection
562 Handle(AIS_InteractiveObject) aTrihedron;
563 if (isTrihedronActive()) {
564 aTrihedron = getTrihedron();
565 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
566 aPrsList.Append(aTrihedron);
568 if (aPrsList.Extent() == 0)
571 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
572 bool isActivationChanged = false;
573 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
574 anAISIO = aLIt.Value();
575 if (activate(anAISIO, myActiveSelectionModes, false))
576 isActivationChanged = true;
578 if (!aTrihedron.IsNull()) {
579 foreach(int aMode, myActiveSelectionModes)
580 aContext->SetSelectionSensitivity(aTrihedron, aMode, 20);
582 // VSV It seems that there is no necessity to update viewer on activation
583 //if (theUpdateViewer && isActivationChanged)
587 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
589 Handle(AIS_InteractiveContext) aContext = AISContext();
590 if (aContext.IsNull() || !isVisible(theObject))
593 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
594 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
596 TColStd_ListOfInteger aModes;
597 aContext->ActivatedModes(anAIS, aModes);
598 return aModes.Extent() > 0;
600 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
602 Handle(AIS_InteractiveContext) aContext = AISContext();
603 if (aContext.IsNull())
605 if (aContext->HasOpenedContext()) {
606 aContext->UnhilightSelected(false);
607 aContext->ClearSelected(false);
608 NCollection_Map<TopoDS_Shape> aShapesToBeSelected;
610 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
611 const GeomShapePtr& aGeomShape = aPrs->shape();
612 if (aGeomShape.get() && !aGeomShape->isNull()) {
613 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
614 #ifdef DEBUG_OCCT_SHAPE_SELECTION
615 aContext->AddOrRemoveSelected(aShape, false);
617 aShapesToBeSelected.Add(aShape);
620 ObjectPtr anObject = aPrs->object();
621 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
622 if (aResult.get() && isVisible(aResult)) {
623 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
624 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
625 if (!anAIS.IsNull()) {
626 // The methods are replaced in order to provide multi-selection, e.g. restore selection
627 // by activating multi selector widget. It also gives an advantage that the multi
628 // selection in OB gives multi-selection in the viewer
629 //aContext->SetSelected(anAIS, false);
630 // The selection in the context was cleared, so the method sets the objects are selected
631 aContext->AddOrRemoveSelected(anAIS, false);
636 if (!aShapesToBeSelected.IsEmpty())
637 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
638 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
639 aContext->UnhilightCurrents(false);
640 aContext->ClearCurrents(false);
641 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
642 ObjectPtr anObject = aPrs->object();
643 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
644 if (aResult.get() && isVisible(aResult)) {
645 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
646 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
648 aContext->SetCurrentObject(anAIS, false);
652 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::setSelected -- AddOrRemoveSelected/UnhilightCurrents(no local context)");
657 void XGUI_Displayer::clearSelected()
659 Handle(AIS_InteractiveContext) aContext = AISContext();
660 if (!aContext.IsNull()) {
661 aContext->UnhilightCurrents(false);
662 aContext->ClearSelected();
666 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
668 bool aErased = false;
669 Handle(AIS_InteractiveContext) aContext = AISContext();
670 if (!aContext.IsNull()) {
671 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
672 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
674 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
675 if (!anIO.IsNull()) {
676 emit beforeObjectErase(aObj, aAISObj);
677 aContext->Remove(anIO, false/*update viewer*/);
684 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAll -- Remove");
685 myResult2AISObjectMap.clear();
688 qDebug(getResult2AISObjectMapInfo().c_str());
693 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
694 Handle(AIS_InteractiveObject) theObject,
695 const bool theClear = true)
697 if (!theObject.IsNull()) {
698 theContext->Deactivate(theObject);
699 ModuleBase_Tools::selectionInfo(theContext, "XGUI_Displayer::deactivateObject -- Deactivate");
701 //theObject->ClearSelected();
702 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
707 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
709 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
710 Handle(AIS_InteractiveContext) aContext = AISContext();
711 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
712 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
713 deactivateObject(aContext, aTrie);
715 /// #1136 hidden axis are selected in sketch
716 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
717 /// for Position AIS object in SelectionModes.
718 deactivateObject(aContext, aTrie->XAxis());
719 deactivateObject(aContext, aTrie->YAxis());
720 deactivateObject(aContext, aTrie->Axis());
721 deactivateObject(aContext, aTrie->Position());
723 deactivateObject(aContext, aTrie->XYPlane());
724 deactivateObject(aContext, aTrie->XZPlane());
725 deactivateObject(aContext, aTrie->YZPlane());
732 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
734 return myWorkshop->viewer()->trihedron();
737 void XGUI_Displayer::openLocalContext()
739 Handle(AIS_InteractiveContext) aContext = AISContext();
740 // Open local context if there is no one
741 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
742 // Preserve selected objects
743 //AIS_ListOfInteractive aAisList;
744 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
745 // aAisList.Append(aContext->Current());
747 // get the filters from the global context and append them to the local context
748 // a list of filters in the global context is not cleared and should be cleared here
749 SelectMgr_ListOfFilter aFilters;
750 aFilters.Assign(aContext->Filters());
751 // it is important to remove the filters in the global context, because there is a code
752 // in the closeLocalContex, which restore the global context filters
753 aContext->RemoveFilters();
755 //aContext->ClearCurrents();
756 aContext->OpenLocalContext();
757 //deactivateTrihedron();
758 //aContext->NotUseDisplayedObjects();
760 //myUseExternalObjects = false;
762 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
763 for (;aIt.More(); aIt.Next()) {
764 aContext->AddFilter(aIt.Value());
767 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
768 //for(; aIt2.More(); aIt2.Next()) {
769 // aContext->SetSelected(aIt2.Value(), false);
774 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
776 Handle(AIS_InteractiveContext) aContext = AISContext();
777 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
778 // Preserve selected objects
779 //AIS_ListOfInteractive aAisList;
780 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
781 // aAisList.Append(aContext->SelectedInteractive());
783 // get the filters from the local context and append them to the global context
784 // a list of filters in the local context is cleared
785 SelectMgr_ListOfFilter aFilters;
786 aFilters.Assign(aContext->Filters());
788 //aContext->ClearSelected();
789 aContext->CloseAllContexts(false);
791 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
792 // this code is obsolete. It is temporaty commented and should be removed after
793 // the test campaign.
794 // Redisplay all object if they were displayed in localContext
795 /*Handle(AIS_InteractiveObject) aAISIO;
796 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
797 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
798 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
799 aContext->Display(aAISIO, false);
800 aContext->SetDisplayMode(aAISIO, Shading, false);
804 // Append the filters from the local selection in the global selection context
805 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
806 for (;aIt.More(); aIt.Next()) {
807 Handle(SelectMgr_Filter) aFilter = aIt.Value();
808 aContext->AddFilter(aFilter);
813 //myUseExternalObjects = false;
816 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
817 //for(; aIt2.More(); aIt2.Next()) {
818 // if (aContext->IsDisplayed(aIt2.Value()))
819 // aContext->SetCurrentObject(aIt2.Value(), false);
824 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
827 if (myResult2AISObjectMap.contains(theObject))
828 anIO = myResult2AISObjectMap[theObject];
832 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
834 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
835 return getObject(aRefAIS);
838 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
841 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
842 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
843 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
849 if (!anObject.get()) {
850 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
851 if (!theIO.IsNull()) {
852 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
854 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
859 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
861 bool aWasEnabled = isUpdateEnabled();
863 myViewerBlockedRecursiveCount--;
865 myViewerBlockedRecursiveCount++;
867 if (myNeedUpdate && isUpdateEnabled()) {
869 myNeedUpdate = false;
874 bool XGUI_Displayer::isUpdateEnabled() const
876 return myViewerBlockedRecursiveCount == 0;
879 void XGUI_Displayer::updateViewer() const
881 Handle(AIS_InteractiveContext) aContext = AISContext();
882 if (!aContext.IsNull() && isUpdateEnabled()) {
883 myWorkshop->viewer()->Zfitall();
884 aContext->UpdateCurrentViewer();
890 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
891 const int theMode, const bool theUpdateViewer) const
893 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
894 if (!aContext.IsNull()) {
895 if (myWorkshop->module()) {
896 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
897 aContext->Activate(theIO, theMode, false);
899 aContext->Activate(theIO, theMode, false);
901 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activateAIS -- Activate");
903 #ifdef DEBUG_ACTIVATE_AIS
904 ObjectPtr anObject = getObject(theIO);
905 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
906 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
913 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
915 Handle(AIS_InteractiveContext) aContext = AISContext();
916 if (!aContext.IsNull()) {
918 aContext->Deactivate(theIO);
920 aContext->Deactivate(theIO, theMode);
921 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivateAIS -- Deactivate");
923 #ifdef DEBUG_DEACTIVATE_AIS
924 ObjectPtr anObject = getObject(theIO);
925 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
926 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
931 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
933 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
934 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
935 aContext->OpenLocalContext();
936 if (!isTrihedronActive())
937 deactivateTrihedron(true);
938 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
939 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
944 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
946 Handle(AIS_InteractiveContext) aContext = AISContext();
947 if (!aContext.IsNull() && myAndFilter.IsNull()) {
948 myAndFilter = new SelectMgr_AndFilter();
949 aContext->AddFilter(myAndFilter);
954 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
955 bool theUpdateViewer)
957 bool aDisplayed = false;
958 Handle(AIS_InteractiveContext) aContext = AISContext();
959 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
960 if (!aContext.IsNull() && !anAISIO.IsNull()) {
961 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
963 aContext->Deactivate(anAISIO);
964 aContext->Load(anAISIO);
965 if (toActivateInSelectionModes) {
966 if (aContext->HasOpenedContext()) {
967 if (myActiveSelectionModes.size() == 0)
968 activateAIS(anAISIO, 0, theUpdateViewer);
970 foreach(int aMode, myActiveSelectionModes) {
971 activateAIS(anAISIO, aMode, theUpdateViewer);
982 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
984 bool aErased = false;
985 Handle(AIS_InteractiveContext) aContext = AISContext();
986 if (!aContext.IsNull()) {
987 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
988 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
989 aContext->Remove(anAISIO, false/*update viewer*/);
990 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAIS -- Remove");
994 if (aErased && theUpdateViewer)
1000 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1002 if (theMode == NoMode)
1005 Handle(AIS_InteractiveContext) aContext = AISContext();
1006 if (aContext.IsNull())
1009 AISObjectPtr aAISObj = getAISObject(theObject);
1013 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1014 aContext->SetDisplayMode(aAISIO, theMode, false);
1015 // Redisplay in order to update new mode because it could be not computed before
1016 if (theUpdateViewer)
1020 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1022 Handle(AIS_InteractiveContext) aContext = AISContext();
1023 if (aContext.IsNull())
1026 AISObjectPtr aAISObj = getAISObject(theObject);
1030 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1031 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1034 void XGUI_Displayer::deactivateSelectionFilters()
1036 Handle(AIS_InteractiveContext) aContext = AISContext();
1037 if (!myAndFilter.IsNull()) {
1038 bool aFound = false;
1039 if (!aContext.IsNull()) {
1040 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1041 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1042 for (; anIt.More() && !aFound; anIt.Next()) {
1043 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1044 aFound = aFilter == myAndFilter;
1047 aContext->RemoveFilter(myAndFilter);
1049 myAndFilter.Nullify();
1053 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1055 Handle(AIS_InteractiveContext) aContext = AISContext();
1056 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1059 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1060 if (!aCompositeFilter.IsNull()) {
1061 aCompositeFilter->Add(theFilter);
1062 #ifdef DEBUG_SELECTION_FILTERS
1063 int aCount = aCompositeFilter->StoredFilters().Extent();
1064 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1069 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1071 Handle(AIS_InteractiveContext) aContext = AISContext();
1072 if (aContext.IsNull())
1075 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1076 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1077 aCompositeFilter->Remove(theFilter);
1078 #ifdef DEBUG_SELECTION_FILTERS
1079 int aCount = aCompositeFilter->StoredFilters().Extent();
1080 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1085 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1087 bool aFilterFound = false;
1089 Handle(AIS_InteractiveContext) aContext = AISContext();
1090 if (aContext.IsNull())
1091 return aFilterFound;
1092 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1093 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1094 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1095 if (theFilter.Access() == aIt.Value().Access())
1096 aFilterFound = true;
1098 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1099 if (!aCompositeFilter.IsNull()) {
1100 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1101 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1102 if (theFilter.Access() == aIt.Value().Access())
1103 aFilterFound = true;
1106 return aFilterFound;
1109 void XGUI_Displayer::removeFilters()
1111 Handle(AIS_InteractiveContext) aContext = AISContext();
1112 if (aContext.IsNull())
1115 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1116 if (!aCompositeFilter.IsNull())
1117 aCompositeFilter->Clear();
1120 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1122 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1123 foreach(ObjectPtr aObj, aDispList) {
1124 if (!theList.contains(aObj))
1127 foreach(ObjectPtr aObj, theList) {
1128 if (!isVisible(aObj))
1129 display(aObj, false);
1134 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1136 if (!isVisible(theObject))
1139 AISObjectPtr aAISObj = getAISObject(theObject);
1140 if (aAISObj.get() == NULL)
1143 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1144 return ::canBeShaded(anAIS, myWorkshop->module());
1147 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1148 const QIntList& theModes,
1149 const bool theUpdateViewer) const
1151 Handle(AIS_InteractiveContext) aContext = AISContext();
1152 if (aContext.IsNull() || theIO.IsNull())
1155 bool isActivationChanged = false;
1156 // deactivate object in all modes, which are not in the list of activation
1157 // It seems that after the IO deactivation the selected state of the IO's owners
1158 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1159 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1160 // only if there is a difference in the current modes and the parameters modes.
1161 // If the selection problem happens again, it is possible to write a test scenario and create
1162 // a bug. The bug steps are the following:
1163 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1164 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1165 TColStd_ListOfInteger aTColModes;
1166 aContext->ActivatedModes(theIO, aTColModes);
1167 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1168 QIntList aModesActivatedForIO;
1169 bool isDeactivated = false;
1170 for (; itr.More(); itr.Next() ) {
1171 Standard_Integer aMode = itr.Value();
1172 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1173 if (!theModes.contains(aMode)) {
1174 deactivateAIS(theIO, aMode);
1175 isDeactivated = true;
1178 aModesActivatedForIO.append(aMode);
1181 if (isDeactivated) {
1182 // the selection from the previous activation modes should be cleared manually (#26172)
1183 theIO->ClearSelected();
1184 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1185 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activate -- ClearSelected/ClearOutdatedSelection");
1186 // For performance issues
1187 //if (theUpdateViewer)
1189 isActivationChanged = true;
1192 // loading the interactive object allowing the decomposition
1193 if (aTColModes.IsEmpty()) {
1194 aContext->Load(theIO, -1, true);
1197 // trihedron AIS check should be after the AIS loading.
1198 // If it is not loaded, it is steel selectable in the viewer.
1199 Handle(AIS_Trihedron) aTrihedron;
1200 if (!isTrihedronActive())
1201 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1202 if (aTrihedron.IsNull()) {
1203 // In order to clear active modes list
1204 if (theModes.size() == 0) {
1205 activateAIS(theIO, 0, theUpdateViewer);
1207 foreach(int aMode, theModes) {
1208 if (!aModesActivatedForIO.contains(aMode)) {
1209 activateAIS(theIO, aMode, theUpdateViewer);
1210 isActivationChanged = true;
1215 return isActivationChanged;
1218 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1220 AISObjectPtr anAISObj = getAISObject(theObject);
1221 // correct the result's color it it has the attribute
1222 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1224 // Customization of presentation
1225 GeomCustomPrsPtr aCustomPrs;
1226 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1227 if (aFeature.get() != NULL) {
1228 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1229 if (aCustPrs.get() != NULL)
1230 aCustomPrs = aCustPrs;
1232 if (aCustomPrs.get() == NULL) {
1233 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1234 // we ignore presentable not customized objects
1235 if (aPrs.get() == NULL)
1236 aCustomPrs = myCustomPrs;
1238 bool isCustomized = aCustomPrs.get() &&
1239 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1240 return isCustomized;
1244 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1246 if (!isVisible(theObject))
1249 AISObjectPtr anAISObj = getAISObject(theObject);
1251 anAISObj->getColor(aR, aG, aB);
1252 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1253 if (theUpdateViewer)
1255 return QColor(aR, aG, aB);
1258 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1260 myResult2AISObjectMap[theObject] = theAIS;
1262 #ifdef DEBUG_DISPLAY
1263 std::ostringstream aPtrStr;
1264 aPtrStr << theObject.get();
1265 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1266 qDebug(getResult2AISObjectMapInfo().c_str());
1270 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1272 QStringList aContent;
1273 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1274 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1275 std::ostringstream aPtrStr;
1276 aPtrStr << "aObj = " << aObj.get() << ":";
1277 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1278 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1280 aContent.append(aPtrStr.str().c_str());
1282 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1283 arg(aContent.join("\n")).toStdString().c_str();
1286 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1288 myIsTrihedronActive = theIsActive;
1289 if (!myIsTrihedronActive) {
1290 deactivateTrihedron(true);
1294 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1296 Handle(AIS_InteractiveContext) aContext = AISContext();
1297 if (aContext.IsNull())
1300 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1303 if (!aContext->IsDisplayed(aTrihedron))
1304 aContext->Display(aTrihedron,
1306 -1 /* selection mode */,
1307 Standard_True /* update viewer*/,
1308 Standard_False /* allow decomposition */,
1309 AIS_DS_Displayed /* xdisplay status */);
1311 if (!isTrihedronActive())
1312 deactivateTrihedron(false);
1314 activate(aTrihedron, myActiveSelectionModes, false);
1316 deactivateTrihedron(false);
1317 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1318 // the selection from the previous activation modes should be cleared manually (#26172)
1320 aContext->Erase(aTrihedron);
1326 QIntList XGUI_Displayer::activeSelectionModes() const
1329 foreach (int aMode, myActiveSelectionModes) {
1330 // aMode < 9 is a Shape Enum values
1331 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1336 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1337 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1339 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1340 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1341 aLContext->UnhilightPicked(Standard_False);
1343 NCollection_Map<TopoDS_Shape> aShapesSelected;
1345 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1346 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1347 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1348 Handle(SelectMgr_EntityOwner) anOwner;
1349 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1350 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1351 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1352 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1353 if (aShapesSelected.Contains(BROwnr->Shape()))
1355 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1356 anOwner->SetSelected (Standard_True);
1357 aShapesSelected.Add(BROwnr->Shape());
1360 aLContext->HilightPicked(Standard_False);