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>
62 #include <VInspectorAPI_CallBack.h>
65 #include <Events_Loop.h>
66 #include <ModelAPI_Events.h>
70 /// defines the local context mouse selection sensitivity
71 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
73 //#define DEBUG_ACTIVATE_OBJECTS
74 //#define DEBUG_DEACTIVATE
75 //#define DEBUG_ACTIVATE_AIS
76 //#define DEBUG_DEACTIVATE_AIS
78 //#define DEBUG_DISPLAY
79 //#define DEBUG_FEATURE_REDISPLAY
80 //#define DEBUG_SELECTION_FILTERS
82 //#define DEBUG_COMPOSILID_DISPLAY
83 // Workaround for bug #25637
85 //#define DEBUG_OCCT_SHAPE_SELECTION
87 //#define WORKAROUND_UNTIL_27523_IS_FIXED
89 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
91 // Get from null point
92 theAIS->DisplayedObjects(theList, true);
93 if (theAIS->HasOpenedContext()) {
94 // get from local context
95 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
96 TColStd_MapOfTransient aMap;
97 int NbDisp = aLC->DisplayedObjects(aMap);
98 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
100 Handle(AIS_InteractiveObject) curIO;
101 Handle(Standard_Transient) Tr;
102 for(; aIt.More(); aIt.Next()){
104 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
105 theList.Append(curIO);
110 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
113 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
114 for (; anIt != aLast; anIt++) {
115 anInfo.append(QString::number(*anIt));
117 return anInfo.join(theSeparator);
120 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
121 : myWorkshop(theWorkshop), myNeedUpdate(false),
122 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0)
125 myContextCallBack = 0;
127 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
130 XGUI_Displayer::~XGUI_Displayer()
134 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
136 return myResult2AISObjectMap.contains(theObject);
139 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
141 bool aDisplayed = false;
142 if (isVisible(theObject)) {
143 #ifdef DEBUG_COMPOSILID_DISPLAY
144 ResultCompSolidPtr aCompsolidResult =
145 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
146 if (aCompsolidResult.get()) {
147 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
148 ResultPtr aSubResult = aCompsolidResult->subResult(i);
149 if (aSubResult.get())
150 redisplay(aSubResult, false);
157 aDisplayed = redisplay(theObject, theUpdateViewer);
160 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
161 bool isShading = false;
162 if (aPrs.get() != NULL) {
163 anAIS = aPrs->getAISObject(anAIS);
165 // correct deviation coefficient for
166 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
167 if (!anAISPrs.IsNull()) {
168 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
169 if (!aShapePrs.IsNull()) {
170 TopoDS_Shape aShape = aShapePrs->Shape();
171 if (!aShape.IsNull())
172 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
177 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
178 if (aResult.get() != NULL) {
179 #ifdef DEBUG_COMPOSILID_DISPLAY
180 ResultCompSolidPtr aCompsolidResult =
181 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
182 if (aCompsolidResult.get()) {
183 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
184 ResultPtr aSubResult = aCompsolidResult->subResult(i);
185 if (aSubResult.get())
186 display(aSubResult, false);
193 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
194 if (aShapePtr.get() != NULL) {
195 anAIS = AISObjectPtr(new GeomAPI_AISObject());
196 Handle(AIS_InteractiveObject) anAISPrs =
197 myWorkshop->module()->createPresentation(aResult);
198 if (anAISPrs.IsNull())
199 anAISPrs = new ModuleBase_ResultPrs(aResult);
201 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
202 if (!aShapePrs.IsNull())
203 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.Access());
205 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
206 //anAIS->createShape(aShapePtr);
209 #ifdef DEBUG_COMPOSILID_DISPLAY
215 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
220 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
222 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
223 if (!aShapePrs.IsNull()) {
224 TopoDS_Shape aShape = aShapePrs->Shape();
227 TopAbs_ShapeEnum aType = aShape.ShapeType();
228 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
231 // Check that the presentation is not a sketch
232 return theModule->canBeShaded(theAIS);
238 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
239 bool isShading, bool theUpdateViewer)
241 bool aDisplayed = false;
243 Handle(AIS_InteractiveContext) aContext = AISContext();
244 if (aContext.IsNull())
247 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
248 if (!anAISIO.IsNull()) {
249 appendResultObject(theObject, theAIS);
251 bool isCustomized = customizeObject(theObject);
253 int aDispMode = isShading? Shading : Wireframe;
255 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
256 anAISIO->SetDisplayMode(aDispMode);
257 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
259 if (myContextCallBack) myContextCallBack->Display(anAISIO);
263 emit objectDisplayed(theObject, theAIS);
264 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
272 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
274 bool aErased = false;
275 if (!isVisible(theObject))
278 Handle(AIS_InteractiveContext) aContext = AISContext();
279 if (aContext.IsNull())
282 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
284 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
285 if (!anAIS.IsNull()) {
286 emit beforeObjectErase(theObject, anObject);
287 aContext->Remove(anAIS, false/*update viewer*/);
289 if (myContextCallBack) myContextCallBack->Remove(anAIS);
291 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::erase -- Remove");
295 myResult2AISObjectMap.remove(theObject);
298 std::ostringstream aPtrStr;
299 aPtrStr << theObject.get();
300 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
301 qDebug(getResult2AISObjectMapInfo().c_str());
310 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
312 bool aRedisplayed = false;
313 if (!isVisible(theObject))
316 AISObjectPtr aAISObj = getAISObject(theObject);
317 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
319 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
321 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
323 aRedisplayed = erase(theObject, theUpdateViewer);
326 if (aAIS_Obj != aAISObj) {
327 appendResultObject(theObject, aAIS_Obj);
329 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
332 Handle(AIS_InteractiveContext) aContext = AISContext();
333 if (!aContext.IsNull() && !aAISIO.IsNull()) {
334 // Check that the visualized shape is the same and the redisplay is not necessary
335 // Redisplay of AIS object leads to this object selection compute and the selection
336 // in the browser is lost
337 // this check is not necessary anymore because the selection store/restore is realized
338 // before and after the values modification.
339 // Moreother, this check avoids customize and redisplay presentation if the presentable
340 // parameter is changed.
341 bool isEqualShapes = false;
342 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
343 if (aResult.get() != NULL) {
344 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
345 if (!aShapePrs.IsNull()) {
346 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
347 if (aShapePtr.get()) {
348 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
349 if (!aOldShape.IsNull())
350 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
354 // Customization of presentation
355 bool isCustomized = customizeObject(theObject);
356 #ifdef DEBUG_FEATURE_REDISPLAY
357 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
358 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
359 .arg(isCustomized).toStdString().c_str());
361 if (!isEqualShapes || isCustomized) {
362 /// if shapes are equal and presentation are customized, selection should be restored
363 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
364 if (aNeedToRestoreSelection)
365 myWorkshop->module()->storeSelection();
367 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
368 if (!myActiveSelectionModes.contains(0))
369 aContext->Activate(aAISIO, 0);
372 aContext->Redisplay(aAISIO, false);
374 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
375 if (!myActiveSelectionModes.contains(0))
376 aContext->Deactivate(aAISIO, 0);
380 if (myContextCallBack) myContextCallBack->Redisplay(aAISIO);
382 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::redisplay -- Redisplay");
384 if (aNeedToRestoreSelection)
385 myWorkshop->module()->restoreSelection();
388 #ifdef DEBUG_FEATURE_REDISPLAY
389 qDebug(" Redisplay happens");
398 void XGUI_Displayer::redisplayObjects()
400 // redisplay objects visualized in the viewer
401 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
402 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
403 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
404 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
405 for (; anIt != aLast; anIt++) {
406 aECreator->sendUpdated(*anIt, EVENT_DISP);
408 Events_Loop::loop()->flush(EVENT_DISP);
411 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
413 #ifdef DEBUG_DEACTIVATE
414 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
415 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
416 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
418 toStdString().c_str());
420 Handle(AIS_InteractiveContext) aContext = AISContext();
421 if (!aContext.IsNull() && isVisible(theObject)) {
422 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
423 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
425 deactivateAIS(anAIS);
426 // the selection from the previous activation modes should be cleared manually (#26172)
427 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
429 if (myContextCallBack) myContextCallBack->ClearOutdatedSelection(anAIS);
431 ModuleBase_Tools::selectionInfo(aContext,
432 "XGUI_Displayer::deactivate -- ClearOutdatedSelection");
438 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
439 const bool theUpdateViewer)
441 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
442 //if (!aTrihedron.IsNull())
443 // deactivateAIS(aTrihedron);
445 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
446 for (; anIt != aLast; anIt++) {
447 deactivate(*anIt, false);
449 //VSV It seems that there is no necessity to update viewer on deactivation
450 //if (theUpdateViewer)
454 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
456 Handle(AIS_InteractiveContext) aContext = AISContext();
457 if (aContext.IsNull() || !isVisible(theObject))
460 AISObjectPtr aAISObj = getAISObject(theObject);
462 if (aAISObj.get() != NULL) {
463 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
464 TColStd_ListOfInteger aTColModes;
465 aContext->ActivatedModes(anAISIO, aTColModes);
466 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
467 for (; itr.More(); itr.Next() ) {
468 theModes.append(itr.Value());
473 int XGUI_Displayer::getSelectionMode(int theShapeType)
475 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
476 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
479 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
481 bool aVisible = false;
482 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
483 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
484 if (aPrs.get() || aResult.get()) {
485 aVisible = theDisplayer->isVisible(theObject);
486 // compsolid is not visualized in the viewer,
487 // but should have presentation when all sub solids are
488 // visible. It is useful for highlight presentation where compsolid shape is selectable
489 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
490 ResultCompSolidPtr aCompsolidResult =
491 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
492 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
493 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
494 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
495 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
497 aVisible = anAllSubsVisible;
501 // it is possible that feature is presentable and has results, so we should check visibility
502 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
504 // check if all results of the feature are visible
505 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
506 std::list<ResultPtr> aResults;
507 ModelAPI_Tools::allResults(aFeature, aResults);
508 std::list<ResultPtr>::const_iterator aIt;
509 aVisible = !aResults.empty();
510 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
511 aVisible = aVisible && theDisplayer->isVisible(*aIt);
517 #ifdef DEBUG_ACTIVATE_OBJECTS
518 QString getModeInfo(const int theMode)
520 QString anInfo = "Undefined";
522 case 0: anInfo = "SHAPE(0)"; break;
523 case 1: anInfo = "VERTEX(1)"; break;
524 case 2: anInfo = "EDGE(2)"; break;
525 case 3: anInfo = "WIRE(3)"; break;
526 case 4: anInfo = "FACE(4)"; break;
527 case 5: anInfo = "SHELL(5)"; break;
528 case 6: anInfo = "SOLID(6)"; break;
529 case 7: anInfo = "COMPSOLID(7)"; break;
530 case 8: anInfo = "COMPOUND(8)"; break;
531 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
532 case 101: anInfo = "Sel_Constraint(101)"; break;
533 case 102: anInfo = "Sel_Dimension_All(102)"; break;
534 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
535 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
541 QString getModesInfo(const QIntList& theModes)
543 QStringList aModesInfo;
544 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
545 aModesInfo.append(getModeInfo(theModes[i]));
546 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
550 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
551 const bool theUpdateViewer)
553 // Convert shape types to selection types
555 foreach(int aType, theModes) {
556 aModes.append(getSelectionMode(aType));
559 #ifdef DEBUG_ACTIVATE_OBJECTS
561 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
562 for (; anIt != aLast; ++anIt) {
563 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
565 QString anInfoStr = anInfo.join(", ");
567 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
568 arg(getModesInfo(aModes)).
569 arg(getModesInfo(myActiveSelectionModes)).
570 arg(theObjList.size()).
572 toStdString().c_str());
574 // In order to avoid doblications of selection modes
576 foreach (int aMode, aModes) {
577 if (!aNewModes.contains(aMode))
578 aNewModes.append(aMode);
580 myActiveSelectionModes = aNewModes;
581 Handle(AIS_InteractiveContext) aContext = AISContext();
582 // Open local context if there is no one
583 if (aContext.IsNull() || !aContext->HasOpenedContext())
586 //aContext->UseDisplayedObjects();
587 //myUseExternalObjects = true;
589 Handle(AIS_InteractiveObject) anAISIO;
590 AIS_ListOfInteractive aPrsList;
591 //if (aObjList.isEmpty())
594 foreach(ObjectPtr aObj, theObjList) {
595 if (myResult2AISObjectMap.contains(aObj))
596 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
600 // Add trihedron because it has to partisipate in selection
601 Handle(AIS_InteractiveObject) aTrihedron;
602 if (isTrihedronActive()) {
603 aTrihedron = getTrihedron();
604 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
605 aPrsList.Append(aTrihedron);
607 if (aPrsList.Extent() == 0)
610 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
611 bool isActivationChanged = false;
612 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
613 anAISIO = aLIt.Value();
614 if (activate(anAISIO, myActiveSelectionModes, false))
615 isActivationChanged = true;
619 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
621 Handle(AIS_InteractiveContext) aContext = AISContext();
622 if (aContext.IsNull() || !isVisible(theObject))
625 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
626 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
628 TColStd_ListOfInteger aModes;
629 aContext->ActivatedModes(anAIS, aModes);
631 if (myContextCallBack) myContextCallBack->ActivatedModes(anAIS, aModes);
634 return aModes.Extent() > 0;
638 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
639 bool theUpdateViewer)
641 Handle(AIS_InteractiveContext) aContext = AISContext();
642 if (aContext.IsNull())
644 if (aContext->HasOpenedContext()) {
645 aContext->UnhilightSelected(false);
646 aContext->ClearSelected(false);
648 if (myContextCallBack) myContextCallBack->ClearSelected();
650 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
653 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
654 const GeomShapePtr& aGeomShape = aPrs->shape();
655 if (aGeomShape.get() && !aGeomShape->isNull()) {
656 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
657 #ifdef DEBUG_OCCT_SHAPE_SELECTION
658 // problem 1: performance
659 // problem 2: IO is not specified, so the first found owner is selected, as a result
660 // it might belong to another result
661 aContext->AddOrRemoveSelected(aShape, false);
663 if (myContextCallBack) myContextCallBack->AddOrRemoveSelected(aShape);
666 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
667 if (aShapesToBeSelected.IsBound(aShape))
668 aPresentations = aShapesToBeSelected.Find(aShape);
669 ObjectPtr anObject = aPrs->object();
670 getPresentations(anObject, aPresentations);
672 aShapesToBeSelected.Bind(aShape, aPresentations);
675 ObjectPtr anObject = aPrs->object();
676 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
677 if (aResult.get() && isVisible(aResult)) {
678 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
679 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
680 if (!anAIS.IsNull()) {
681 // The methods are replaced in order to provide multi-selection, e.g. restore selection
682 // by activating multi selector widget. It also gives an advantage that the multi
683 // selection in OB gives multi-selection in the viewer
684 //aContext->SetSelected(anAIS, false);
685 // The selection in the context was cleared, so the method sets the objects are selected
686 aContext->AddOrRemoveSelected(anAIS, false);
688 if (myContextCallBack) myContextCallBack->AddOrRemoveSelected(anAIS);
694 if (!aShapesToBeSelected.IsEmpty())
695 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
696 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
697 aContext->UnhilightCurrents(false);
698 aContext->ClearCurrents(false);
699 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
700 ObjectPtr anObject = aPrs->object();
701 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
702 if (aResult.get() && isVisible(aResult)) {
703 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
704 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
706 aContext->SetCurrentObject(anAIS, false);
710 ModuleBase_Tools::selectionInfo(aContext,
711 "XGUI_Displayer::setSelected -- AddOrRemoveSelected/UnhilightCurrents(no local context)");
716 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
718 Handle(AIS_InteractiveContext) aContext = AISContext();
719 if (!aContext.IsNull()) {
720 aContext->UnhilightCurrents(false);
721 aContext->ClearSelected(theUpdateViewer);
723 if (myContextCallBack) myContextCallBack->ClearSelected();
728 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
730 bool aErased = false;
731 Handle(AIS_InteractiveContext) aContext = AISContext();
732 if (!aContext.IsNull()) {
733 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
734 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
736 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
737 if (!anIO.IsNull()) {
738 emit beforeObjectErase(aObj, aAISObj);
739 aContext->Remove(anIO, false/*update viewer*/);
741 if (myContextCallBack) myContextCallBack->Remove(anIO);
749 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAll -- Remove");
750 myResult2AISObjectMap.clear();
753 qDebug(getResult2AISObjectMapInfo().c_str());
758 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
759 Handle(AIS_InteractiveObject) theObject,
761 VInspectorAPI_CallBack* theCallBack,
763 const bool theClear = true)
765 if (!theObject.IsNull()) {
766 theContext->Deactivate(theObject);
768 if (theCallBack) theCallBack->Deactivate(theObject);
770 ModuleBase_Tools::selectionInfo(theContext, "XGUI_Displayer::deactivateObject -- Deactivate");
772 //theObject->ClearSelected();
773 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
778 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
780 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
781 Handle(AIS_InteractiveContext) aContext = AISContext();
782 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
783 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
784 deactivateObject(aContext, aTrie
790 /// #1136 hidden axis are selected in sketch
791 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
792 /// for Position AIS object in SelectionModes.
793 deactivateObject(aContext, aTrie->XAxis()
798 deactivateObject(aContext, aTrie->YAxis()
803 deactivateObject(aContext, aTrie->Axis()
808 deactivateObject(aContext, aTrie->Position()
814 deactivateObject(aContext, aTrie->XYPlane()
819 deactivateObject(aContext, aTrie->XZPlane()
824 deactivateObject(aContext, aTrie->YZPlane()
835 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
837 return myWorkshop->viewer()->trihedron();
840 void XGUI_Displayer::openLocalContext()
842 Handle(AIS_InteractiveContext) aContext = AISContext();
843 // Open local context if there is no one
844 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
845 // Preserve selected objects
846 //AIS_ListOfInteractive aAisList;
847 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
848 // aAisList.Append(aContext->Current());
850 // get the filters from the global context and append them to the local context
851 // a list of filters in the global context is not cleared and should be cleared here
852 SelectMgr_ListOfFilter aFilters;
853 aFilters.Assign(aContext->Filters());
854 // it is important to remove the filters in the global context, because there is a code
855 // in the closeLocalContex, which restore the global context filters
856 aContext->RemoveFilters();
858 //aContext->ClearCurrents();
859 aContext->OpenLocalContext();
860 //deactivateTrihedron();
861 //aContext->NotUseDisplayedObjects();
863 //myUseExternalObjects = false;
865 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
866 for (;aIt.More(); aIt.Next()) {
867 aContext->AddFilter(aIt.Value());
870 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
871 //for(; aIt2.More(); aIt2.Next()) {
872 // aContext->SetSelected(aIt2.Value(), false);
877 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
879 Handle(AIS_InteractiveContext) aContext = AISContext();
880 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
881 // Preserve selected objects
882 //AIS_ListOfInteractive aAisList;
883 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
884 // aAisList.Append(aContext->SelectedInteractive());
886 // get the filters from the local context and append them to the global context
887 // a list of filters in the local context is cleared
888 SelectMgr_ListOfFilter aFilters;
889 aFilters.Assign(aContext->Filters());
891 //aContext->ClearSelected();
892 aContext->CloseAllContexts(false);
894 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
895 // this code is obsolete. It is temporaty commented and should be removed after
896 // the test campaign.
897 // Redisplay all object if they were displayed in localContext
898 /*Handle(AIS_InteractiveObject) aAISIO;
899 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
900 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
901 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
902 aContext->Display(aAISIO, false);
903 aContext->SetDisplayMode(aAISIO, Shading, false);
907 // Append the filters from the local selection in the global selection context
908 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
909 for (;aIt.More(); aIt.Next()) {
910 Handle(SelectMgr_Filter) aFilter = aIt.Value();
911 aContext->AddFilter(aFilter);
916 //myUseExternalObjects = false;
919 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
920 //for(; aIt2.More(); aIt2.Next()) {
921 // if (aContext->IsDisplayed(aIt2.Value()))
922 // aContext->SetCurrentObject(aIt2.Value(), false);
927 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
930 if (myResult2AISObjectMap.contains(theObject))
931 anIO = myResult2AISObjectMap[theObject];
935 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
937 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
938 return getObject(aRefAIS);
941 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
944 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
945 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
946 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
952 if (!anObject.get()) {
953 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
954 if (!theIO.IsNull()) {
955 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
957 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
962 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
964 bool aWasEnabled = isUpdateEnabled();
966 myViewerBlockedRecursiveCount--;
968 myViewerBlockedRecursiveCount++;
970 if (myNeedUpdate && isUpdateEnabled()) {
972 myNeedUpdate = false;
977 bool XGUI_Displayer::isUpdateEnabled() const
979 return myViewerBlockedRecursiveCount == 0;
982 void XGUI_Displayer::updateViewer() const
984 Handle(AIS_InteractiveContext) aContext = AISContext();
985 if (!aContext.IsNull() && isUpdateEnabled()) {
986 myWorkshop->viewer()->Zfitall();
987 aContext->UpdateCurrentViewer();
993 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
994 const int theMode, const bool theUpdateViewer) const
996 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
997 if (!theIO.IsNull() && theIO == getTrihedron()) {
998 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
999 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
1002 if (!aContext.IsNull()) {
1003 if (myWorkshop->module()) {
1004 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
1005 aContext->Activate(theIO, theMode, false);
1007 aContext->Activate(theIO, theMode, false);
1009 if (myContextCallBack) myContextCallBack->Activate(theIO, theMode);
1012 // the fix from VPA for more suitable selection of sketcher lines
1013 if (theIO->Width() > 1) {
1014 double aPrecision = theIO->Width() + 2;
1015 if (theMode == getSelectionMode(TopAbs_VERTEX))
1016 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1017 "point-selection-sensitivity",
1019 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
1020 (theMode == getSelectionMode(TopAbs_WIRE)))
1021 aPrecision = theIO->Width() +
1022 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1023 "edge-selection-sensitivity", 2);
1024 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
1026 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activateAIS -- Activate");
1028 #ifdef DEBUG_ACTIVATE_AIS
1029 ObjectPtr anObject = getObject(theIO);
1030 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1031 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1032 .arg(anInfo).toStdString().c_str());
1034 if (theUpdateViewer)
1039 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1040 const int theMode) const
1042 Handle(AIS_InteractiveContext) aContext = AISContext();
1043 if (!aContext.IsNull()) {
1044 if (theMode == -1) {
1045 aContext->Deactivate(theIO);
1047 if (myContextCallBack) myContextCallBack->Deactivate(theIO);
1051 aContext->Deactivate(theIO, theMode);
1053 if (myContextCallBack) myContextCallBack->Deactivate(theIO, theMode);
1056 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivateAIS -- Deactivate");
1058 #ifdef DEBUG_DEACTIVATE_AIS
1059 ObjectPtr anObject = getObject(theIO);
1060 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1061 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1062 .arg(anInfo).toStdString().c_str());
1067 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1069 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1070 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
1071 aContext->OpenLocalContext();
1072 if (!isTrihedronActive())
1073 deactivateTrihedron(true);
1074 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1075 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1080 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1082 Handle(AIS_InteractiveContext) aContext = AISContext();
1083 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1084 myAndFilter = new SelectMgr_AndFilter();
1085 aContext->AddFilter(myAndFilter);
1090 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1091 bool theUpdateViewer)
1093 bool aDisplayed = false;
1094 Handle(AIS_InteractiveContext) aContext = AISContext();
1095 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1096 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1097 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1099 if (myContextCallBack) myContextCallBack->Display(anAISIO);
1102 aContext->Deactivate(anAISIO);
1104 if (myContextCallBack) myContextCallBack->Deactivate(anAISIO);
1106 aContext->Load(anAISIO);
1108 if (myContextCallBack) myContextCallBack->Load(anAISIO);
1110 if (toActivateInSelectionModes) {
1111 if (aContext->HasOpenedContext()) {
1112 if (myActiveSelectionModes.size() == 0)
1113 activateAIS(anAISIO, 0, theUpdateViewer);
1115 foreach(int aMode, myActiveSelectionModes) {
1116 activateAIS(anAISIO, aMode, theUpdateViewer);
1121 if (theUpdateViewer)
1127 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1129 bool aErased = false;
1130 Handle(AIS_InteractiveContext) aContext = AISContext();
1131 if (!aContext.IsNull()) {
1132 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1133 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1134 aContext->Remove(anAISIO, false/*update viewer*/);
1136 if (myContextCallBack) myContextCallBack->Remove(anAISIO);
1138 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAIS -- Remove");
1142 if (aErased && theUpdateViewer)
1148 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1150 if (theMode == NoMode)
1153 Handle(AIS_InteractiveContext) aContext = AISContext();
1154 if (aContext.IsNull())
1157 AISObjectPtr aAISObj = getAISObject(theObject);
1161 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1162 aContext->SetDisplayMode(aAISIO, theMode, false);
1163 // Redisplay in order to update new mode because it could be not computed before
1164 if (theUpdateViewer)
1168 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1170 Handle(AIS_InteractiveContext) aContext = AISContext();
1171 if (aContext.IsNull())
1174 AISObjectPtr aAISObj = getAISObject(theObject);
1178 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1179 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1182 void XGUI_Displayer::deactivateSelectionFilters()
1184 Handle(AIS_InteractiveContext) aContext = AISContext();
1185 if (!myAndFilter.IsNull()) {
1186 bool aFound = false;
1187 if (!aContext.IsNull()) {
1188 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1189 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1190 for (; anIt.More() && !aFound; anIt.Next()) {
1191 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1192 aFound = aFilter == myAndFilter;
1195 aContext->RemoveFilter(myAndFilter);
1197 myAndFilter.Nullify();
1201 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1203 Handle(AIS_InteractiveContext) aContext = AISContext();
1204 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1207 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1208 if (!aCompositeFilter.IsNull()) {
1209 aCompositeFilter->Add(theFilter);
1210 #ifdef DEBUG_SELECTION_FILTERS
1211 int aCount = aCompositeFilter->StoredFilters().Extent();
1212 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1217 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1219 Handle(AIS_InteractiveContext) aContext = AISContext();
1220 if (aContext.IsNull())
1223 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1224 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1225 aCompositeFilter->Remove(theFilter);
1226 #ifdef DEBUG_SELECTION_FILTERS
1227 int aCount = aCompositeFilter->StoredFilters().Extent();
1228 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1229 .arg(aCount).toStdString().c_str());
1234 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1236 bool aFilterFound = false;
1238 Handle(AIS_InteractiveContext) aContext = AISContext();
1239 if (aContext.IsNull())
1240 return aFilterFound;
1241 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1242 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1243 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1244 if (theFilter.Access() == aIt.Value().Access())
1245 aFilterFound = true;
1247 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1248 if (!aCompositeFilter.IsNull()) {
1249 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1250 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1251 if (theFilter.Access() == aIt.Value().Access())
1252 aFilterFound = true;
1255 return aFilterFound;
1258 void XGUI_Displayer::removeFilters()
1260 Handle(AIS_InteractiveContext) aContext = AISContext();
1261 if (aContext.IsNull())
1264 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1265 if (!aCompositeFilter.IsNull())
1266 aCompositeFilter->Clear();
1269 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1271 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1272 foreach(ObjectPtr aObj, aDispList) {
1273 if (!theList.contains(aObj))
1276 foreach(ObjectPtr aObj, theList) {
1277 if (!isVisible(aObj))
1278 display(aObj, false);
1283 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1285 if (!isVisible(theObject))
1288 AISObjectPtr aAISObj = getAISObject(theObject);
1289 if (aAISObj.get() == NULL)
1292 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1293 return ::canBeShaded(anAIS, myWorkshop->module());
1296 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1297 const QIntList& theModes,
1298 const bool theUpdateViewer) const
1300 Handle(AIS_InteractiveContext) aContext = AISContext();
1301 if (aContext.IsNull() || theIO.IsNull())
1304 bool isActivationChanged = false;
1305 // deactivate object in all modes, which are not in the list of activation
1306 // It seems that after the IO deactivation the selected state of the IO's owners
1307 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1308 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1309 // only if there is a difference in the current modes and the parameters modes.
1310 // If the selection problem happens again, it is possible to write a test scenario and create
1311 // a bug. The bug steps are the following:
1312 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1313 // with clicked SHIFT select the second object.
1314 // The result is the selection of the first IO is lost.
1315 TColStd_ListOfInteger aTColModes;
1316 aContext->ActivatedModes(theIO, aTColModes);
1318 if (myContextCallBack) myContextCallBack->ActivatedModes(theIO, aTColModes);
1320 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1321 QIntList aModesActivatedForIO;
1322 bool isDeactivated = false;
1323 for (; itr.More(); itr.Next() ) {
1324 Standard_Integer aMode = itr.Value();
1325 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1326 if (!theModes.contains(aMode)) {
1327 deactivateAIS(theIO, aMode);
1328 isDeactivated = true;
1331 aModesActivatedForIO.append(aMode);
1334 if (isDeactivated) {
1335 // the selection from the previous activation modes should be cleared manually (#26172)
1336 theIO->ClearSelected();
1338 if (myContextCallBack) myContextCallBack->ClearSelected(theIO);
1340 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1342 if (myContextCallBack) myContextCallBack->ClearOutdatedSelection(theIO);
1344 ModuleBase_Tools::selectionInfo(aContext,
1345 "XGUI_Displayer::activate -- ClearSelected/ClearOutdatedSelection");
1346 // For performance issues
1347 //if (theUpdateViewer)
1349 isActivationChanged = true;
1352 // loading the interactive object allowing the decomposition
1353 if (aTColModes.IsEmpty()) {
1354 aContext->Load(theIO, -1, true);
1356 if (myContextCallBack) myContextCallBack->Load(theIO);
1360 // trihedron AIS check should be after the AIS loading.
1361 // If it is not loaded, it is steel selectable in the viewer.
1362 Handle(AIS_Trihedron) aTrihedron;
1363 if (!isTrihedronActive())
1364 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1365 if (aTrihedron.IsNull()) {
1366 // In order to clear active modes list
1367 if (theModes.size() == 0) {
1368 activateAIS(theIO, 0, theUpdateViewer);
1370 foreach(int aMode, theModes) {
1371 if (!aModesActivatedForIO.contains(aMode)) {
1372 activateAIS(theIO, aMode, theUpdateViewer);
1373 isActivationChanged = true;
1378 return isActivationChanged;
1381 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1383 AISObjectPtr anAISObj = getAISObject(theObject);
1384 // correct the result's color it it has the attribute
1385 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1387 // Customization of presentation
1388 GeomCustomPrsPtr aCustomPrs;
1389 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1390 if (aFeature.get() != NULL) {
1391 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1392 if (aCustPrs.get() != NULL)
1393 aCustomPrs = aCustPrs;
1395 if (aCustomPrs.get() == NULL) {
1396 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1397 // we ignore presentable not customized objects
1398 if (aPrs.get() == NULL)
1399 aCustomPrs = myCustomPrs;
1401 bool isCustomized = aCustomPrs.get() &&
1402 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1403 return isCustomized;
1407 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1408 const QColor& theColor,
1409 bool theUpdateViewer)
1411 if (!isVisible(theObject))
1414 AISObjectPtr anAISObj = getAISObject(theObject);
1416 anAISObj->getColor(aR, aG, aB);
1417 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1418 if (theUpdateViewer)
1420 return QColor(aR, aG, aB);
1423 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1425 myResult2AISObjectMap[theObject] = theAIS;
1427 #ifdef DEBUG_DISPLAY
1428 std::ostringstream aPtrStr;
1429 aPtrStr << theObject.get();
1430 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1431 qDebug(getResult2AISObjectMapInfo().c_str());
1435 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1437 QStringList aContent;
1438 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1439 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1440 std::ostringstream aPtrStr;
1441 aPtrStr << "aObj = " << aObj.get() << ":";
1442 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1443 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1445 aContent.append(aPtrStr.str().c_str());
1447 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1448 arg(aContent.join("\n")).toStdString().c_str();
1451 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1452 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1454 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1455 if (aResult.get()) {
1456 AISObjectPtr aAISObj = getAISObject(aResult);
1457 if (aAISObj.get() != NULL) {
1458 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1459 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1460 thePresentations.Add(anAIS);
1464 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1465 // find presentation of the feature
1466 AISObjectPtr aAISObj = getAISObject(aFeature);
1467 if (aAISObj.get() != NULL) {
1468 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1469 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1470 thePresentations.Add(anAIS);
1472 // find presentations of the feature results
1473 std::list<ResultPtr> aResults;
1474 ModelAPI_Tools::allResults(aFeature, aResults);
1475 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1476 for (; anIt != aLast; ++anIt) {
1477 AISObjectPtr aAISObj = getAISObject(*anIt);
1478 if (aAISObj.get() != NULL) {
1479 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1480 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1481 thePresentations.Add(anAIS);
1487 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1489 myIsTrihedronActive = theIsActive;
1490 if (!myIsTrihedronActive) {
1491 deactivateTrihedron(true);
1495 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1497 Handle(AIS_InteractiveContext) aContext = AISContext();
1498 if (aContext.IsNull())
1501 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1504 if (!aContext->IsDisplayed(aTrihedron))
1505 aContext->Display(aTrihedron,
1507 -1 /* selection mode */,
1508 Standard_True /* update viewer*/,
1509 Standard_False /* allow decomposition */,
1510 AIS_DS_Displayed /* xdisplay status */);
1512 if (myContextCallBack) myContextCallBack->Display(aTrihedron);
1515 if (!isTrihedronActive())
1516 deactivateTrihedron(false);
1518 activate(aTrihedron, myActiveSelectionModes, false);
1520 deactivateTrihedron(false);
1521 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1522 // the selection from the previous activation modes should be cleared manually (#26172)
1524 aContext->Erase(aTrihedron);
1526 if (myContextCallBack) myContextCallBack->Remove(aTrihedron);
1533 QIntList XGUI_Displayer::activeSelectionModes() const
1536 foreach (int aMode, myActiveSelectionModes) {
1537 // aMode < 9 is a Shape Enum values
1538 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1544 void XGUI_Displayer::setCallBack(VInspectorAPI_CallBack* theCallBack)
1546 myContextCallBack = theCallBack;
1549 VInspectorAPI_CallBack* XGUI_Displayer::getCallBack() const
1551 return myContextCallBack;
1555 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1556 const NCollection_DataMap<TopoDS_Shape,
1557 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1559 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1560 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1561 aLContext->UnhilightPicked(Standard_False);
1563 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1564 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1565 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1566 Handle(SelectMgr_EntityOwner) anOwner;
1568 /// It is very important to check that the owner is processed only once and has a map of
1569 /// processed owners because SetSelected works as a switch.
1570 /// If count of calls setSelectec is even, the object stays in the previous state
1571 /// (selected, deselected)
1572 /// OCCT: to write about the problem that active owners method returns one owner several times
1573 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1574 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1575 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1576 if (aSelectedIds.contains((long)anOwner.Access()))
1578 aSelectedIds.append((long)anOwner.Access());
1580 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1581 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1582 const TopoDS_Shape& aShape = BROwnr->Shape();
1583 if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
1584 Handle(AIS_InteractiveObject) anOwnerPresentation =
1585 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1586 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1587 theShapesToBeSelected.Find(aShape);
1588 if (aPresentations.Contains(anOwnerPresentation)) {
1589 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1590 anOwner->SetSelected (Standard_True);
1595 aLContext->HilightPicked(Standard_False);