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 // correct deviation coefficient for
154 Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
155 if (!anAISPrs.IsNull()) {
156 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
157 if (!aShapePrs.IsNull()) {
158 TopoDS_Shape aShape = aShapePrs->Shape();
159 if (!aShape.IsNull())
160 ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
165 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
166 if (aResult.get() != NULL) {
167 #ifdef DEBUG_COMPOSILID_DISPLAY
168 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
169 if (aCompsolidResult.get()) {
170 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
171 ResultPtr aSubResult = aCompsolidResult->subResult(i);
172 if (aSubResult.get())
173 display(aSubResult, false);
180 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
181 if (aShapePtr.get() != NULL) {
182 anAIS = AISObjectPtr(new GeomAPI_AISObject());
183 Handle(AIS_InteractiveObject) anAISPrs = myWorkshop->module()->createPresentation(aResult);
184 if (anAISPrs.IsNull())
185 anAISPrs = new ModuleBase_ResultPrs(aResult);
186 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
187 //anAIS->createShape(aShapePtr);
190 #ifdef DEBUG_COMPOSILID_DISPLAY
196 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
201 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
203 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
204 if (!aShapePrs.IsNull()) {
205 TopoDS_Shape aShape = aShapePrs->Shape();
208 TopAbs_ShapeEnum aType = aShape.ShapeType();
209 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
212 // Check that the presentation is not a sketch
213 return theModule->canBeShaded(theAIS);
219 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
220 bool isShading, bool theUpdateViewer)
222 bool aDisplayed = false;
224 Handle(AIS_InteractiveContext) aContext = AISContext();
225 if (aContext.IsNull())
228 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
229 if (!anAISIO.IsNull()) {
230 appendResultObject(theObject, theAIS);
232 bool isCustomized = customizeObject(theObject);
234 int aDispMode = isShading? Shading : Wireframe;
236 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
237 anAISIO->SetDisplayMode(aDispMode);
238 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
241 emit objectDisplayed(theObject, theAIS);
242 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
243 // the fix from VPA for more suitable selection of sketcher lines
244 if(anAISIO->Width() > 1) {
245 for(int aModeIdx = 0; aModeIdx < myActiveSelectionModes.length(); ++aModeIdx) {
246 int aMode = myActiveSelectionModes.value(aModeIdx);
247 double aPrecision = (aMode == getSelectionMode(TopAbs_VERTEX))? 20 :
248 (anAISIO->Width() + 2);
249 aContext->SetSelectionSensitivity(anAISIO, aMode, aPrecision);
259 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
261 bool aErased = false;
262 if (!isVisible(theObject))
265 Handle(AIS_InteractiveContext) aContext = AISContext();
266 if (aContext.IsNull())
269 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
271 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
272 if (!anAIS.IsNull()) {
273 emit beforeObjectErase(theObject, anObject);
274 aContext->Remove(anAIS, false/*update viewer*/);
275 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::erase -- Remove");
279 myResult2AISObjectMap.remove(theObject);
282 std::ostringstream aPtrStr;
283 aPtrStr << theObject.get();
284 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
285 qDebug(getResult2AISObjectMapInfo().c_str());
294 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
296 bool aRedisplayed = false;
297 if (!isVisible(theObject))
300 AISObjectPtr aAISObj = getAISObject(theObject);
301 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
303 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
305 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
307 aRedisplayed = erase(theObject, theUpdateViewer);
310 if (aAIS_Obj != aAISObj) {
311 appendResultObject(theObject, aAIS_Obj);
313 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
316 Handle(AIS_InteractiveContext) aContext = AISContext();
317 if (!aContext.IsNull() && !aAISIO.IsNull()) {
318 // Check that the visualized shape is the same and the redisplay is not necessary
319 // Redisplay of AIS object leads to this object selection compute and the selection
320 // in the browser is lost
321 // this check is not necessary anymore because the selection store/restore is realized
322 // before and after the values modification.
323 // Moreother, this check avoids customize and redisplay presentation if the presentable
324 // parameter is changed.
325 bool isEqualShapes = false;
326 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
327 if (aResult.get() != NULL) {
328 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
329 if (!aShapePrs.IsNull()) {
330 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
331 if (aShapePtr.get()) {
332 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
333 if (!aOldShape.IsNull())
334 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
338 // Customization of presentation
339 bool isCustomized = customizeObject(theObject);
340 #ifdef DEBUG_FEATURE_REDISPLAY
341 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
342 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
344 if (!isEqualShapes || isCustomized) {
345 /// if shapes are equal and presentation are customized, selection should be restored
346 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
347 if (aNeedToRestoreSelection)
348 myWorkshop->module()->storeSelection();
350 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
351 if (!myActiveSelectionModes.contains(0))
352 aContext->Activate(aAISIO, 0);
355 aContext->Redisplay(aAISIO, false);
357 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
358 if (!myActiveSelectionModes.contains(0))
359 aContext->Deactivate(aAISIO, 0);
362 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::redisplay -- Redisplay");
364 if (aNeedToRestoreSelection)
365 myWorkshop->module()->restoreSelection();
368 #ifdef DEBUG_FEATURE_REDISPLAY
369 qDebug(" Redisplay happens");
378 void XGUI_Displayer::redisplayObjects()
380 // redisplay objects visualized in the viewer
381 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
382 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
383 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
384 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
385 for (; anIt != aLast; anIt++) {
386 aECreator->sendUpdated(*anIt, EVENT_DISP);
388 Events_Loop::loop()->flush(EVENT_DISP);
391 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
393 #ifdef DEBUG_DEACTIVATE
394 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
395 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
396 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
398 toStdString().c_str());
400 Handle(AIS_InteractiveContext) aContext = AISContext();
401 if (!aContext.IsNull() && isVisible(theObject)) {
402 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
403 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
405 deactivateAIS(anAIS);
406 // the selection from the previous activation modes should be cleared manually (#26172)
407 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
408 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivate -- ClearOutdatedSelection");
414 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
415 const bool theUpdateViewer)
417 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
418 //if (!aTrihedron.IsNull())
419 // deactivateAIS(aTrihedron);
421 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
422 for (; anIt != aLast; anIt++) {
423 deactivate(*anIt, false);
425 //VSV It seems that there is no necessity to update viewer on deactivation
426 //if (theUpdateViewer)
430 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
432 Handle(AIS_InteractiveContext) aContext = AISContext();
433 if (aContext.IsNull() || !isVisible(theObject))
436 AISObjectPtr aAISObj = getAISObject(theObject);
438 if (aAISObj.get() != NULL) {
439 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
440 TColStd_ListOfInteger aTColModes;
441 aContext->ActivatedModes(anAISIO, aTColModes);
442 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
443 for (; itr.More(); itr.Next() ) {
444 theModes.append(itr.Value());
449 int XGUI_Displayer::getSelectionMode(int theShapeType)
451 return (theShapeType >= TopAbs_SHAPE)? theShapeType :
452 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
455 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
457 bool aVisible = false;
458 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
459 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
460 if (aPrs.get() || aResult.get()) {
461 aVisible = theDisplayer->isVisible(theObject);
462 // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
463 // visible. It is useful for highlight presentation where compsolid shape is selectable
464 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
465 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
466 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
467 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
468 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
469 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
471 aVisible = anAllSubsVisible;
475 // it is possible that feature is presentable and has results, so we should check visibility
476 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
478 // check if all results of the feature are visible
479 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
480 std::list<ResultPtr> aResults = aFeature->results();
481 std::list<ResultPtr>::const_iterator aIt;
482 aVisible = !aResults.empty();
483 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
484 aVisible = aVisible && theDisplayer->isVisible(*aIt);
490 #ifdef DEBUG_ACTIVATE_OBJECTS
491 QString getModeInfo(const int theMode)
493 QString anInfo = "Undefined";
495 case 0: anInfo = "SHAPE(0)"; break;
496 case 1: anInfo = "VERTEX(1)"; break;
497 case 2: anInfo = "EDGE(2)"; break;
498 case 3: anInfo = "WIRE(3)"; break;
499 case 4: anInfo = "FACE(4)"; break;
500 case 5: anInfo = "SHELL(5)"; break;
501 case 6: anInfo = "SOLID(6)"; break;
502 case 7: anInfo = "COMPSOLID(7)"; break;
503 case 8: anInfo = "COMPOUND(8)"; break;
504 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
505 case 101: anInfo = "Sel_Constraint(101)"; break;
506 case 102: anInfo = "Sel_Dimension_All(102)"; break;
507 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
508 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
514 QString getModesInfo(const QIntList& theModes)
516 QStringList aModesInfo;
517 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
518 aModesInfo.append(getModeInfo(theModes[i]));
519 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
523 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
524 const bool theUpdateViewer)
526 // Convert shape types to selection types
528 foreach(int aType, theModes) {
529 aModes.append(getSelectionMode(aType));
532 #ifdef DEBUG_ACTIVATE_OBJECTS
534 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
535 for (; anIt != aLast; ++anIt) {
536 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
538 QString anInfoStr = anInfo.join(", ");
540 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
541 arg(getModesInfo(aModes)).
542 arg(getModesInfo(myActiveSelectionModes)).
543 arg(theObjList.size()).
545 toStdString().c_str());
547 // In order to avoid doblications of selection modes
549 foreach (int aMode, aModes) {
550 if (!aNewModes.contains(aMode))
551 aNewModes.append(aMode);
553 myActiveSelectionModes = aNewModes;
554 Handle(AIS_InteractiveContext) aContext = AISContext();
555 // Open local context if there is no one
556 if (aContext.IsNull() || !aContext->HasOpenedContext())
559 //aContext->UseDisplayedObjects();
560 //myUseExternalObjects = true;
562 Handle(AIS_InteractiveObject) anAISIO;
563 AIS_ListOfInteractive aPrsList;
564 //if (aObjList.isEmpty())
567 foreach(ObjectPtr aObj, theObjList) {
568 if (myResult2AISObjectMap.contains(aObj))
569 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
573 // Add trihedron because it has to partisipate in selection
574 Handle(AIS_InteractiveObject) aTrihedron;
575 if (isTrihedronActive()) {
576 aTrihedron = getTrihedron();
577 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
578 aPrsList.Append(aTrihedron);
580 if (aPrsList.Extent() == 0)
583 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
584 bool isActivationChanged = false;
585 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
586 anAISIO = aLIt.Value();
587 if (activate(anAISIO, myActiveSelectionModes, false))
588 isActivationChanged = true;
590 if (!aTrihedron.IsNull()) {
591 foreach(int aMode, myActiveSelectionModes)
592 aContext->SetSelectionSensitivity(aTrihedron, aMode, 20);
594 // VSV It seems that there is no necessity to update viewer on activation
595 //if (theUpdateViewer && isActivationChanged)
599 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
601 Handle(AIS_InteractiveContext) aContext = AISContext();
602 if (aContext.IsNull() || !isVisible(theObject))
605 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
606 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
608 TColStd_ListOfInteger aModes;
609 aContext->ActivatedModes(anAIS, aModes);
610 return aModes.Extent() > 0;
612 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
614 Handle(AIS_InteractiveContext) aContext = AISContext();
615 if (aContext.IsNull())
617 if (aContext->HasOpenedContext()) {
618 aContext->UnhilightSelected(false);
619 aContext->ClearSelected(false);
620 NCollection_Map<TopoDS_Shape> aShapesToBeSelected;
622 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
623 const GeomShapePtr& aGeomShape = aPrs->shape();
624 if (aGeomShape.get() && !aGeomShape->isNull()) {
625 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
626 #ifdef DEBUG_OCCT_SHAPE_SELECTION
627 aContext->AddOrRemoveSelected(aShape, false);
629 aShapesToBeSelected.Add(aShape);
632 ObjectPtr anObject = aPrs->object();
633 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
634 if (aResult.get() && isVisible(aResult)) {
635 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
636 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
637 if (!anAIS.IsNull()) {
638 // The methods are replaced in order to provide multi-selection, e.g. restore selection
639 // by activating multi selector widget. It also gives an advantage that the multi
640 // selection in OB gives multi-selection in the viewer
641 //aContext->SetSelected(anAIS, false);
642 // The selection in the context was cleared, so the method sets the objects are selected
643 aContext->AddOrRemoveSelected(anAIS, false);
648 if (!aShapesToBeSelected.IsEmpty())
649 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
650 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
651 aContext->UnhilightCurrents(false);
652 aContext->ClearCurrents(false);
653 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
654 ObjectPtr anObject = aPrs->object();
655 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
656 if (aResult.get() && isVisible(aResult)) {
657 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
658 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
660 aContext->SetCurrentObject(anAIS, false);
664 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::setSelected -- AddOrRemoveSelected/UnhilightCurrents(no local context)");
669 void XGUI_Displayer::clearSelected()
671 Handle(AIS_InteractiveContext) aContext = AISContext();
672 if (!aContext.IsNull()) {
673 aContext->UnhilightCurrents(false);
674 aContext->ClearSelected();
678 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
680 bool aErased = false;
681 Handle(AIS_InteractiveContext) aContext = AISContext();
682 if (!aContext.IsNull()) {
683 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
684 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
686 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
687 if (!anIO.IsNull()) {
688 emit beforeObjectErase(aObj, aAISObj);
689 aContext->Remove(anIO, false/*update viewer*/);
696 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAll -- Remove");
697 myResult2AISObjectMap.clear();
700 qDebug(getResult2AISObjectMapInfo().c_str());
705 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
706 Handle(AIS_InteractiveObject) theObject,
707 const bool theClear = true)
709 if (!theObject.IsNull()) {
710 theContext->Deactivate(theObject);
711 ModuleBase_Tools::selectionInfo(theContext, "XGUI_Displayer::deactivateObject -- Deactivate");
713 //theObject->ClearSelected();
714 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
719 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
721 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
722 Handle(AIS_InteractiveContext) aContext = AISContext();
723 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
724 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
725 deactivateObject(aContext, aTrie);
727 /// #1136 hidden axis are selected in sketch
728 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
729 /// for Position AIS object in SelectionModes.
730 deactivateObject(aContext, aTrie->XAxis());
731 deactivateObject(aContext, aTrie->YAxis());
732 deactivateObject(aContext, aTrie->Axis());
733 deactivateObject(aContext, aTrie->Position());
735 deactivateObject(aContext, aTrie->XYPlane());
736 deactivateObject(aContext, aTrie->XZPlane());
737 deactivateObject(aContext, aTrie->YZPlane());
744 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
746 return myWorkshop->viewer()->trihedron();
749 void XGUI_Displayer::openLocalContext()
751 Handle(AIS_InteractiveContext) aContext = AISContext();
752 // Open local context if there is no one
753 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
754 // Preserve selected objects
755 //AIS_ListOfInteractive aAisList;
756 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
757 // aAisList.Append(aContext->Current());
759 // get the filters from the global context and append them to the local context
760 // a list of filters in the global context is not cleared and should be cleared here
761 SelectMgr_ListOfFilter aFilters;
762 aFilters.Assign(aContext->Filters());
763 // it is important to remove the filters in the global context, because there is a code
764 // in the closeLocalContex, which restore the global context filters
765 aContext->RemoveFilters();
767 //aContext->ClearCurrents();
768 aContext->OpenLocalContext();
769 //deactivateTrihedron();
770 //aContext->NotUseDisplayedObjects();
772 //myUseExternalObjects = false;
774 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
775 for (;aIt.More(); aIt.Next()) {
776 aContext->AddFilter(aIt.Value());
779 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
780 //for(; aIt2.More(); aIt2.Next()) {
781 // aContext->SetSelected(aIt2.Value(), false);
786 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
788 Handle(AIS_InteractiveContext) aContext = AISContext();
789 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
790 // Preserve selected objects
791 //AIS_ListOfInteractive aAisList;
792 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
793 // aAisList.Append(aContext->SelectedInteractive());
795 // get the filters from the local context and append them to the global context
796 // a list of filters in the local context is cleared
797 SelectMgr_ListOfFilter aFilters;
798 aFilters.Assign(aContext->Filters());
800 //aContext->ClearSelected();
801 aContext->CloseAllContexts(false);
803 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
804 // this code is obsolete. It is temporaty commented and should be removed after
805 // the test campaign.
806 // Redisplay all object if they were displayed in localContext
807 /*Handle(AIS_InteractiveObject) aAISIO;
808 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
809 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
810 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
811 aContext->Display(aAISIO, false);
812 aContext->SetDisplayMode(aAISIO, Shading, false);
816 // Append the filters from the local selection in the global selection context
817 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
818 for (;aIt.More(); aIt.Next()) {
819 Handle(SelectMgr_Filter) aFilter = aIt.Value();
820 aContext->AddFilter(aFilter);
825 //myUseExternalObjects = false;
828 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
829 //for(; aIt2.More(); aIt2.Next()) {
830 // if (aContext->IsDisplayed(aIt2.Value()))
831 // aContext->SetCurrentObject(aIt2.Value(), false);
836 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
839 if (myResult2AISObjectMap.contains(theObject))
840 anIO = myResult2AISObjectMap[theObject];
844 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
846 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
847 return getObject(aRefAIS);
850 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
853 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
854 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
855 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
861 if (!anObject.get()) {
862 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
863 if (!theIO.IsNull()) {
864 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
866 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
871 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
873 bool aWasEnabled = isUpdateEnabled();
875 myViewerBlockedRecursiveCount--;
877 myViewerBlockedRecursiveCount++;
879 if (myNeedUpdate && isUpdateEnabled()) {
881 myNeedUpdate = false;
886 bool XGUI_Displayer::isUpdateEnabled() const
888 return myViewerBlockedRecursiveCount == 0;
891 void XGUI_Displayer::updateViewer() const
893 Handle(AIS_InteractiveContext) aContext = AISContext();
894 if (!aContext.IsNull() && isUpdateEnabled()) {
895 myWorkshop->viewer()->Zfitall();
896 aContext->UpdateCurrentViewer();
902 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
903 const int theMode, const bool theUpdateViewer) const
905 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
906 if (!aContext.IsNull()) {
907 if (myWorkshop->module()) {
908 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
909 aContext->Activate(theIO, theMode, false);
911 aContext->Activate(theIO, theMode, false);
913 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activateAIS -- Activate");
915 #ifdef DEBUG_ACTIVATE_AIS
916 ObjectPtr anObject = getObject(theIO);
917 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
918 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
925 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
927 Handle(AIS_InteractiveContext) aContext = AISContext();
928 if (!aContext.IsNull()) {
930 aContext->Deactivate(theIO);
932 aContext->Deactivate(theIO, theMode);
933 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivateAIS -- Deactivate");
935 #ifdef DEBUG_DEACTIVATE_AIS
936 ObjectPtr anObject = getObject(theIO);
937 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
938 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
943 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
945 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
946 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
947 aContext->OpenLocalContext();
948 if (!isTrihedronActive())
949 deactivateTrihedron(true);
950 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
951 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
956 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
958 Handle(AIS_InteractiveContext) aContext = AISContext();
959 if (!aContext.IsNull() && myAndFilter.IsNull()) {
960 myAndFilter = new SelectMgr_AndFilter();
961 aContext->AddFilter(myAndFilter);
966 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
967 bool theUpdateViewer)
969 bool aDisplayed = false;
970 Handle(AIS_InteractiveContext) aContext = AISContext();
971 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
972 if (!aContext.IsNull() && !anAISIO.IsNull()) {
973 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
975 aContext->Deactivate(anAISIO);
976 aContext->Load(anAISIO);
977 if (toActivateInSelectionModes) {
978 if (aContext->HasOpenedContext()) {
979 if (myActiveSelectionModes.size() == 0)
980 activateAIS(anAISIO, 0, theUpdateViewer);
982 foreach(int aMode, myActiveSelectionModes) {
983 activateAIS(anAISIO, aMode, theUpdateViewer);
994 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
996 bool aErased = false;
997 Handle(AIS_InteractiveContext) aContext = AISContext();
998 if (!aContext.IsNull()) {
999 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1000 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1001 aContext->Remove(anAISIO, false/*update viewer*/);
1002 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAIS -- Remove");
1006 if (aErased && theUpdateViewer)
1012 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1014 if (theMode == NoMode)
1017 Handle(AIS_InteractiveContext) aContext = AISContext();
1018 if (aContext.IsNull())
1021 AISObjectPtr aAISObj = getAISObject(theObject);
1025 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1026 aContext->SetDisplayMode(aAISIO, theMode, false);
1027 // Redisplay in order to update new mode because it could be not computed before
1028 if (theUpdateViewer)
1032 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1034 Handle(AIS_InteractiveContext) aContext = AISContext();
1035 if (aContext.IsNull())
1038 AISObjectPtr aAISObj = getAISObject(theObject);
1042 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1043 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1046 void XGUI_Displayer::deactivateSelectionFilters()
1048 Handle(AIS_InteractiveContext) aContext = AISContext();
1049 if (!myAndFilter.IsNull()) {
1050 bool aFound = false;
1051 if (!aContext.IsNull()) {
1052 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1053 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1054 for (; anIt.More() && !aFound; anIt.Next()) {
1055 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1056 aFound = aFilter == myAndFilter;
1059 aContext->RemoveFilter(myAndFilter);
1061 myAndFilter.Nullify();
1065 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1067 Handle(AIS_InteractiveContext) aContext = AISContext();
1068 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1071 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1072 if (!aCompositeFilter.IsNull()) {
1073 aCompositeFilter->Add(theFilter);
1074 #ifdef DEBUG_SELECTION_FILTERS
1075 int aCount = aCompositeFilter->StoredFilters().Extent();
1076 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1081 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1083 Handle(AIS_InteractiveContext) aContext = AISContext();
1084 if (aContext.IsNull())
1087 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1088 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1089 aCompositeFilter->Remove(theFilter);
1090 #ifdef DEBUG_SELECTION_FILTERS
1091 int aCount = aCompositeFilter->StoredFilters().Extent();
1092 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1097 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1099 bool aFilterFound = false;
1101 Handle(AIS_InteractiveContext) aContext = AISContext();
1102 if (aContext.IsNull())
1103 return aFilterFound;
1104 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1105 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1106 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1107 if (theFilter.Access() == aIt.Value().Access())
1108 aFilterFound = true;
1110 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1111 if (!aCompositeFilter.IsNull()) {
1112 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1113 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1114 if (theFilter.Access() == aIt.Value().Access())
1115 aFilterFound = true;
1118 return aFilterFound;
1121 void XGUI_Displayer::removeFilters()
1123 Handle(AIS_InteractiveContext) aContext = AISContext();
1124 if (aContext.IsNull())
1127 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1128 if (!aCompositeFilter.IsNull())
1129 aCompositeFilter->Clear();
1132 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1134 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1135 foreach(ObjectPtr aObj, aDispList) {
1136 if (!theList.contains(aObj))
1139 foreach(ObjectPtr aObj, theList) {
1140 if (!isVisible(aObj))
1141 display(aObj, false);
1146 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1148 if (!isVisible(theObject))
1151 AISObjectPtr aAISObj = getAISObject(theObject);
1152 if (aAISObj.get() == NULL)
1155 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1156 return ::canBeShaded(anAIS, myWorkshop->module());
1159 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1160 const QIntList& theModes,
1161 const bool theUpdateViewer) const
1163 Handle(AIS_InteractiveContext) aContext = AISContext();
1164 if (aContext.IsNull() || theIO.IsNull())
1167 bool isActivationChanged = false;
1168 // deactivate object in all modes, which are not in the list of activation
1169 // It seems that after the IO deactivation the selected state of the IO's owners
1170 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1171 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1172 // only if there is a difference in the current modes and the parameters modes.
1173 // If the selection problem happens again, it is possible to write a test scenario and create
1174 // a bug. The bug steps are the following:
1175 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1176 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1177 TColStd_ListOfInteger aTColModes;
1178 aContext->ActivatedModes(theIO, aTColModes);
1179 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1180 QIntList aModesActivatedForIO;
1181 bool isDeactivated = false;
1182 for (; itr.More(); itr.Next() ) {
1183 Standard_Integer aMode = itr.Value();
1184 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1185 if (!theModes.contains(aMode)) {
1186 deactivateAIS(theIO, aMode);
1187 isDeactivated = true;
1190 aModesActivatedForIO.append(aMode);
1193 if (isDeactivated) {
1194 // the selection from the previous activation modes should be cleared manually (#26172)
1195 theIO->ClearSelected();
1196 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1197 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activate -- ClearSelected/ClearOutdatedSelection");
1198 // For performance issues
1199 //if (theUpdateViewer)
1201 isActivationChanged = true;
1204 // loading the interactive object allowing the decomposition
1205 if (aTColModes.IsEmpty()) {
1206 aContext->Load(theIO, -1, true);
1209 // trihedron AIS check should be after the AIS loading.
1210 // If it is not loaded, it is steel selectable in the viewer.
1211 Handle(AIS_Trihedron) aTrihedron;
1212 if (!isTrihedronActive())
1213 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1214 if (aTrihedron.IsNull()) {
1215 // In order to clear active modes list
1216 if (theModes.size() == 0) {
1217 activateAIS(theIO, 0, theUpdateViewer);
1219 foreach(int aMode, theModes) {
1220 if (!aModesActivatedForIO.contains(aMode)) {
1221 activateAIS(theIO, aMode, theUpdateViewer);
1222 isActivationChanged = true;
1227 return isActivationChanged;
1230 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1232 AISObjectPtr anAISObj = getAISObject(theObject);
1233 // correct the result's color it it has the attribute
1234 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1236 // Customization of presentation
1237 GeomCustomPrsPtr aCustomPrs;
1238 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1239 if (aFeature.get() != NULL) {
1240 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1241 if (aCustPrs.get() != NULL)
1242 aCustomPrs = aCustPrs;
1244 if (aCustomPrs.get() == NULL) {
1245 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1246 // we ignore presentable not customized objects
1247 if (aPrs.get() == NULL)
1248 aCustomPrs = myCustomPrs;
1250 bool isCustomized = aCustomPrs.get() &&
1251 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1252 return isCustomized;
1256 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1258 if (!isVisible(theObject))
1261 AISObjectPtr anAISObj = getAISObject(theObject);
1263 anAISObj->getColor(aR, aG, aB);
1264 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1265 if (theUpdateViewer)
1267 return QColor(aR, aG, aB);
1270 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1272 myResult2AISObjectMap[theObject] = theAIS;
1274 #ifdef DEBUG_DISPLAY
1275 std::ostringstream aPtrStr;
1276 aPtrStr << theObject.get();
1277 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1278 qDebug(getResult2AISObjectMapInfo().c_str());
1282 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1284 QStringList aContent;
1285 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1286 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1287 std::ostringstream aPtrStr;
1288 aPtrStr << "aObj = " << aObj.get() << ":";
1289 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1290 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1292 aContent.append(aPtrStr.str().c_str());
1294 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1295 arg(aContent.join("\n")).toStdString().c_str();
1298 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1300 myIsTrihedronActive = theIsActive;
1301 if (!myIsTrihedronActive) {
1302 deactivateTrihedron(true);
1306 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1308 Handle(AIS_InteractiveContext) aContext = AISContext();
1309 if (aContext.IsNull())
1312 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1315 if (!aContext->IsDisplayed(aTrihedron))
1316 aContext->Display(aTrihedron,
1318 -1 /* selection mode */,
1319 Standard_True /* update viewer*/,
1320 Standard_False /* allow decomposition */,
1321 AIS_DS_Displayed /* xdisplay status */);
1323 if (!isTrihedronActive())
1324 deactivateTrihedron(false);
1326 activate(aTrihedron, myActiveSelectionModes, false);
1328 deactivateTrihedron(false);
1329 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1330 // the selection from the previous activation modes should be cleared manually (#26172)
1332 aContext->Erase(aTrihedron);
1338 QIntList XGUI_Displayer::activeSelectionModes() const
1341 foreach (int aMode, myActiveSelectionModes) {
1342 // aMode < 9 is a Shape Enum values
1343 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1348 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1349 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1351 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1352 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1353 aLContext->UnhilightPicked(Standard_False);
1355 NCollection_Map<TopoDS_Shape> aShapesSelected;
1357 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1358 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1359 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1360 Handle(SelectMgr_EntityOwner) anOwner;
1361 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1362 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1363 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1364 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1365 if (aShapesSelected.Contains(BROwnr->Shape()))
1367 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1368 anOwner->SetSelected (Standard_True);
1369 aShapesSelected.Add(BROwnr->Shape());
1372 aLContext->HilightPicked(Standard_False);