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_ListOfInteractive.hxx>
39 #include <AIS_ListIteratorOfListOfInteractive.hxx>
40 #include <AIS_DimensionSelectionMode.hxx>
41 #include <AIS_Shape.hxx>
42 #include <AIS_Dimension.hxx>
43 #include <AIS_Trihedron.hxx>
44 #ifdef BEFORE_TRIHEDRON_PATCH
45 #include <AIS_Axis.hxx>
46 #include <AIS_Plane.hxx>
47 #include <AIS_Point.hxx>
49 #include <AIS_Selection.hxx>
50 #include <TColStd_ListIteratorOfListOfInteger.hxx>
51 #include <SelectMgr_ListOfFilter.hxx>
52 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
53 #include <Prs3d_Drawer.hxx>
54 #include <Prs3d_IsoAspect.hxx>
55 #include <SelectMgr_SelectionManager.hxx>
57 #include <StdSelect_ViewerSelector3d.hxx>
59 #include <TColStd_MapOfTransient.hxx>
60 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
63 #include <VInspectorAPI_CallBack.hxx>
66 #include <Events_Loop.h>
67 #include <ModelAPI_Events.h>
71 /// defines the local context mouse selection sensitivity
72 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
74 //#define DEBUG_ACTIVATE_OBJECTS
75 //#define DEBUG_DEACTIVATE
76 //#define DEBUG_ACTIVATE_AIS
77 //#define DEBUG_DEACTIVATE_AIS
79 //#define DEBUG_DISPLAY
80 //#define DEBUG_FEATURE_REDISPLAY
81 //#define DEBUG_SELECTION_FILTERS
83 //#define DEBUG_COMPOSILID_DISPLAY
85 //#define DEBUG_OCCT_SHAPE_SELECTION
87 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
89 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
91 // Get from null point
92 theAIS->DisplayedObjects(theList, true);
95 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
98 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
99 for (; anIt != aLast; anIt++) {
100 anInfo.append(QString::number(*anIt));
102 return anInfo.join(theSeparator);
105 void deselectPresentation(const Handle(AIS_InteractiveObject) theObject,
106 const Handle(AIS_InteractiveContext)& theContext)
108 NCollection_List<Handle(SelectBasics_EntityOwner)> aResultOwners;
110 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
111 Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
112 if (anOwner.IsNull()) // TODO: check why it is possible
114 if (anOwner->Selectable() == theObject && anOwner->IsSelected())
115 aResultOwners.Append(anOwner);
117 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (aResultOwners);
118 Handle(SelectMgr_EntityOwner) anOwner;
119 for (; anOwnersIt.More(); anOwnersIt.Next()) {
120 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
121 if (!anOwner.IsNull())
122 theContext->AddOrRemoveSelected(anOwner, false);
126 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
127 : myWorkshop(theWorkshop), myNeedUpdate(false),
128 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0),
129 myIsFirstAISContextUse(true)
131 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
134 XGUI_Displayer::~XGUI_Displayer()
138 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
140 return myResult2AISObjectMap.contains(theObject);
143 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
145 bool aDisplayed = false;
146 if (isVisible(theObject)) {
147 #ifdef DEBUG_COMPOSILID_DISPLAY
148 ResultCompSolidPtr aCompsolidResult =
149 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
150 if (aCompsolidResult.get()) {
151 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
152 ResultPtr aSubResult = aCompsolidResult->subResult(i);
153 if (aSubResult.get())
154 redisplay(aSubResult, false);
161 aDisplayed = redisplay(theObject, theUpdateViewer);
164 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
165 bool isShading = false;
166 if (aPrs.get() != NULL) {
167 anAIS = aPrs->getAISObject(anAIS);
169 // correct deviation coefficient for
170 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
171 if (!anAISPrs.IsNull()) {
172 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
173 if (!aShapePrs.IsNull()) {
174 TopoDS_Shape aShape = aShapePrs->Shape();
175 if (!aShape.IsNull())
176 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
181 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
182 if (aResult.get() != NULL) {
183 #ifdef DEBUG_COMPOSILID_DISPLAY
184 ResultCompSolidPtr aCompsolidResult =
185 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
186 if (aCompsolidResult.get()) {
187 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
188 ResultPtr aSubResult = aCompsolidResult->subResult(i);
189 if (aSubResult.get())
190 display(aSubResult, false);
197 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
198 if (aShapePtr.get() != NULL) {
199 anAIS = AISObjectPtr(new GeomAPI_AISObject());
200 Handle(AIS_InteractiveObject) anAISPrs =
201 myWorkshop->module()->createPresentation(aResult);
202 if (anAISPrs.IsNull())
203 anAISPrs = new ModuleBase_ResultPrs(aResult);
205 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
206 if (!aShapePrs.IsNull())
207 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
209 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
210 //anAIS->createShape(aShapePtr);
213 #ifdef DEBUG_COMPOSILID_DISPLAY
219 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
224 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
226 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
227 if (!aShapePrs.IsNull()) {
228 TopoDS_Shape aShape = aShapePrs->Shape();
231 TopAbs_ShapeEnum aType = aShape.ShapeType();
232 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
235 // Check that the presentation is not a sketch
236 return theModule->canBeShaded(theAIS);
242 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
243 bool isShading, bool theUpdateViewer)
245 bool aDisplayed = false;
247 Handle(AIS_InteractiveContext) aContext = AISContext();
248 if (aContext.IsNull())
251 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
252 if (!anAISIO.IsNull()) {
253 appendResultObject(theObject, theAIS);
255 bool isCustomized = customizeObject(theObject);
257 int aDispMode = isShading? Shading : Wireframe;
259 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
260 anAISIO->SetDisplayMode(aDispMode);
261 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
263 if (getCallBack()) getCallBack()->Display(anAISIO);
267 emit objectDisplayed(theObject, theAIS);
268 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
276 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
278 bool aErased = false;
279 if (!isVisible(theObject))
282 Handle(AIS_InteractiveContext) aContext = AISContext();
283 if (aContext.IsNull())
286 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
288 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
289 if (!anAIS.IsNull()) {
290 emit beforeObjectErase(theObject, anObject);
291 aContext->Remove(anAIS, false/*update viewer*/);
293 if (getCallBack()) getCallBack()->Remove(anAIS);
298 myResult2AISObjectMap.remove(theObject);
301 std::ostringstream aPtrStr;
302 aPtrStr << theObject.get();
303 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
304 qDebug(getResult2AISObjectMapInfo().c_str());
313 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
315 bool aRedisplayed = false;
316 if (!isVisible(theObject))
319 AISObjectPtr aAISObj = getAISObject(theObject);
320 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
322 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
324 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
326 aRedisplayed = erase(theObject, theUpdateViewer);
329 if (aAIS_Obj != aAISObj) {
330 appendResultObject(theObject, aAIS_Obj);
332 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
335 Handle(AIS_InteractiveContext) aContext = AISContext();
336 if (!aContext.IsNull() && !aAISIO.IsNull()) {
337 // Check that the visualized shape is the same and the redisplay is not necessary
338 // Redisplay of AIS object leads to this object selection compute and the selection
339 // in the browser is lost
340 // this check is not necessary anymore because the selection store/restore is realized
341 // before and after the values modification.
342 // Moreother, this check avoids customize and redisplay presentation if the presentable
343 // parameter is changed.
344 bool isEqualShapes = false;
345 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
346 if (aResult.get() != NULL) {
347 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
348 if (!aShapePrs.IsNull()) {
349 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
350 if (aShapePtr.get()) {
351 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
352 if (!aOldShape.IsNull())
353 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
357 // Customization of presentation
358 bool isCustomized = customizeObject(theObject);
359 #ifdef DEBUG_FEATURE_REDISPLAY
360 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
361 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
362 .arg(isCustomized).toStdString().c_str());
364 if (!isEqualShapes || isCustomized) {
365 /// if shapes are equal and presentation are customized, selection should be restored
366 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
367 if (aNeedToRestoreSelection)
368 myWorkshop->module()->storeSelection();
370 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
371 deselectPresentation(aAISIO, aContext);
373 aContext->Redisplay(aAISIO, false);
376 if (getCallBack()) getCallBack()->Redisplay(aAISIO);
379 if (aNeedToRestoreSelection)
380 myWorkshop->module()->restoreSelection();
383 #ifdef DEBUG_FEATURE_REDISPLAY
384 qDebug(" Redisplay happens");
393 void XGUI_Displayer::redisplayObjects()
395 // redisplay objects visualized in the viewer
396 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
397 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
398 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
399 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
400 for (; anIt != aLast; anIt++) {
401 aECreator->sendUpdated(*anIt, EVENT_DISP);
403 Events_Loop::loop()->flush(EVENT_DISP);
406 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
408 #ifdef DEBUG_DEACTIVATE
409 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
410 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
411 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
413 toStdString().c_str());
415 Handle(AIS_InteractiveContext) aContext = AISContext();
416 if (!aContext.IsNull() && isVisible(theObject)) {
417 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
418 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
420 deactivateAIS(anAIS);
421 // the selection from the previous activation modes should be cleared manually (#26172)
422 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
423 deselectPresentation(anAIS, aContext);
430 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
431 const bool theUpdateViewer)
433 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
434 //if (!aTrihedron.IsNull())
435 // deactivateAIS(aTrihedron);
437 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
438 for (; anIt != aLast; anIt++) {
439 deactivate(*anIt, false);
441 //VSV It seems that there is no necessity to update viewer on deactivation
442 //if (theUpdateViewer)
446 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
448 Handle(AIS_InteractiveContext) aContext = AISContext();
449 if (aContext.IsNull() || !isVisible(theObject))
452 AISObjectPtr aAISObj = getAISObject(theObject);
454 if (aAISObj.get() != NULL) {
455 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
456 TColStd_ListOfInteger aTColModes;
457 aContext->ActivatedModes(anAISIO, aTColModes);
458 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
459 for (; itr.More(); itr.Next() ) {
460 theModes.append(itr.Value());
465 int XGUI_Displayer::getSelectionMode(int theShapeType)
467 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
468 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
471 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
473 bool aVisible = false;
474 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
475 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
476 if (aPrs.get() || aResult.get()) {
477 aVisible = theDisplayer->isVisible(theObject);
478 // compsolid is not visualized in the viewer,
479 // but should have presentation when all sub solids are
480 // visible. It is useful for highlight presentation where compsolid shape is selectable
481 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
482 ResultCompSolidPtr aCompsolidResult =
483 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
484 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
485 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
486 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
487 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
489 aVisible = anAllSubsVisible;
493 // it is possible that feature is presentable and has results, so we should check visibility
494 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
496 // check if all results of the feature are visible
497 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
498 std::list<ResultPtr> aResults;
499 ModelAPI_Tools::allResults(aFeature, aResults);
500 std::list<ResultPtr>::const_iterator aIt;
501 aVisible = !aResults.empty();
502 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
503 aVisible = aVisible && theDisplayer->isVisible(*aIt);
509 #ifdef DEBUG_ACTIVATE_OBJECTS
510 QString getModeInfo(const int theMode)
512 QString anInfo = "Undefined";
514 case 0: anInfo = "SHAPE(0)"; break;
515 case 1: anInfo = "VERTEX(1)"; break;
516 case 2: anInfo = "EDGE(2)"; break;
517 case 3: anInfo = "WIRE(3)"; break;
518 case 4: anInfo = "FACE(4)"; break;
519 case 5: anInfo = "SHELL(5)"; break;
520 case 6: anInfo = "SOLID(6)"; break;
521 case 7: anInfo = "COMPSOLID(7)"; break;
522 case 8: anInfo = "COMPOUND(8)"; break;
523 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
524 case 101: anInfo = "Sel_Constraint(101)"; break;
525 case 102: anInfo = "Sel_Dimension_All(102)"; break;
526 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
527 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
533 QString getModesInfo(const QIntList& theModes)
535 QStringList aModesInfo;
536 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
537 aModesInfo.append(getModeInfo(theModes[i]));
538 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
542 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
543 const bool theUpdateViewer)
545 // Convert shape types to selection types
547 foreach(int aType, theModes) {
548 aModes.append(getSelectionMode(aType));
551 #ifdef DEBUG_ACTIVATE_OBJECTS
553 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
554 for (; anIt != aLast; ++anIt) {
555 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
557 QString anInfoStr = anInfo.join(", ");
559 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
560 arg(getModesInfo(aModes)).
561 arg(getModesInfo(myActiveSelectionModes)).
562 arg(theObjList.size()).
564 toStdString().c_str());
566 // In order to avoid doblications of selection modes
568 foreach (int aMode, aModes) {
569 if (!aNewModes.contains(aMode))
570 aNewModes.append(aMode);
572 myActiveSelectionModes = aNewModes;
573 Handle(AIS_InteractiveContext) aContext = AISContext();
574 // Open local context if there is no one
575 if (aContext.IsNull())
578 //aContext->UseDisplayedObjects();
579 //myUseExternalObjects = true;
581 Handle(AIS_InteractiveObject) anAISIO;
582 AIS_ListOfInteractive aPrsList;
583 //if (aObjList.isEmpty())
586 foreach(ObjectPtr aObj, theObjList) {
587 if (myResult2AISObjectMap.contains(aObj))
588 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
592 // Add trihedron because it has to partisipate in selection
593 Handle(AIS_InteractiveObject) aTrihedron;
594 if (isTrihedronActive()) {
595 aTrihedron = getTrihedron();
596 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
597 aPrsList.Append(aTrihedron);
599 if (aPrsList.Extent() == 0)
602 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
603 bool isActivationChanged = false;
604 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
605 anAISIO = aLIt.Value();
606 if (activate(anAISIO, myActiveSelectionModes, false))
607 isActivationChanged = true;
611 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
613 Handle(AIS_InteractiveContext) aContext = AISContext();
614 if (aContext.IsNull() || !isVisible(theObject))
617 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
618 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
620 TColStd_ListOfInteger aModes;
621 aContext->ActivatedModes(anAIS, aModes);
623 if (getCallBack()) getCallBack()->ActivatedModes(anAIS, aModes);
626 return aModes.Extent() > 0;
630 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
631 bool theUpdateViewer)
633 Handle(AIS_InteractiveContext) aContext = AISContext();
634 if (aContext.IsNull())
636 aContext->UnhilightSelected(false);
637 aContext->ClearSelected(false);
639 if (getCallBack()) getCallBack()->ClearSelected();
641 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
644 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
645 const GeomShapePtr& aGeomShape = aPrs->shape();
646 if (aGeomShape.get() && !aGeomShape->isNull()) {
647 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
648 #ifdef DEBUG_OCCT_SHAPE_SELECTION
649 // problem 1: performance
650 // problem 2: IO is not specified, so the first found owner is selected, as a result
651 // it might belong to another result
652 aContext->AddOrRemoveSelected(aShape, false);
654 if (getCallBack()) getCallBack()->AddOrRemoveSelected(aShape);
657 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
658 if (aShapesToBeSelected.IsBound(aShape))
659 aPresentations = aShapesToBeSelected.Find(aShape);
660 ObjectPtr anObject = aPrs->object();
661 getPresentations(anObject, aPresentations);
663 aShapesToBeSelected.Bind(aShape, aPresentations);
666 ObjectPtr anObject = aPrs->object();
667 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
668 if (aResult.get() && isVisible(aResult)) {
669 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
670 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
671 if (!anAIS.IsNull()) {
672 // The methods are replaced in order to provide multi-selection, e.g. restore selection
673 // by activating multi selector widget. It also gives an advantage that the multi
674 // selection in OB gives multi-selection in the viewer
675 //aContext->SetSelected(anAIS, false);
676 // The selection in the context was cleared, so the method sets the objects are selected
677 aContext->AddOrRemoveSelected(anAIS, false);
679 if (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
685 if (!aShapesToBeSelected.IsEmpty())
686 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
692 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
694 Handle(AIS_InteractiveContext) aContext = AISContext();
695 if (!aContext.IsNull()) {
696 aContext->UnhilightSelected(false);//UnhilightCurrents(false);
697 aContext->ClearSelected(theUpdateViewer);
699 if (getCallBack()) getCallBack()->ClearSelected();
704 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
706 bool aErased = false;
707 Handle(AIS_InteractiveContext) aContext = AISContext();
708 if (!aContext.IsNull()) {
709 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
710 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
712 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
713 if (!anIO.IsNull()) {
714 emit beforeObjectErase(aObj, aAISObj);
715 aContext->Remove(anIO, false/*update viewer*/);
717 if (getCallBack()) getCallBack()->Remove(anIO);
725 myResult2AISObjectMap.clear();
728 qDebug(getResult2AISObjectMapInfo().c_str());
733 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
734 Handle(AIS_InteractiveObject) theObject
736 , Handle(VInspectorAPI_CallBack) theCallBack
740 if (!theObject.IsNull()) {
741 theContext->Deactivate(theObject);
743 if (theCallBack) theCallBack->Deactivate(theObject);
748 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
750 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
751 Handle(AIS_InteractiveContext) aContext = AISContext();
752 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
753 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
754 deactivateObject(aContext, aTrie
760 /// #1136 hidden axis are selected in sketch
761 #ifdef BEFORE_TRIHEDRON_PATCH
762 deactivateObject(aContext, aTrie->XAxis()
767 deactivateObject(aContext, aTrie->YAxis()
772 deactivateObject(aContext, aTrie->Axis()
777 deactivateObject(aContext, aTrie->Position()
783 deactivateObject(aContext, aTrie->XYPlane()
788 deactivateObject(aContext, aTrie->XZPlane()
793 deactivateObject(aContext, aTrie->YZPlane()
804 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
806 return myWorkshop->viewer()->trihedron();
809 /*void XGUI_Displayer::openLocalContext()
811 Handle(AIS_InteractiveContext) aContext = AISContext();
812 // Open local context if there is no one
813 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
814 // Preserve selected objects
815 //AIS_ListOfInteractive aAisList;
816 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
817 // aAisList.Append(aContext->Current());
819 // get the filters from the global context and append them to the local context
820 // a list of filters in the global context is not cleared and should be cleared here
821 SelectMgr_ListOfFilter aFilters;
822 aFilters.Assign(aContext->Filters());
823 // it is important to remove the filters in the global context, because there is a code
824 // in the closeLocalContex, which restore the global context filters
825 aContext->RemoveFilters();
827 //aContext->ClearCurrents();
828 aContext->OpenLocalContext();
829 //deactivateTrihedron();
830 //aContext->NotUseDisplayedObjects();
832 //myUseExternalObjects = false;
834 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
835 for (;aIt.More(); aIt.Next()) {
836 aContext->AddFilter(aIt.Value());
839 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
840 //for(; aIt2.More(); aIt2.Next()) {
841 // aContext->SetSelected(aIt2.Value(), false);
846 /*void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
848 Handle(AIS_InteractiveContext) aContext = AISContext();
849 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
850 // Preserve selected objects
851 //AIS_ListOfInteractive aAisList;
852 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
853 // aAisList.Append(aContext->SelectedInteractive());
855 // get the filters from the local context and append them to the global context
856 // a list of filters in the local context is cleared
857 SelectMgr_ListOfFilter aFilters;
858 aFilters.Assign(aContext->Filters());
860 //aContext->ClearSelected();
861 aContext->CloseAllContexts(false);
863 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
864 // this code is obsolete. It is temporaty commented and should be removed after
865 // the test campaign.
866 // Redisplay all object if they were displayed in localContext
867 /*Handle(AIS_InteractiveObject) aAISIO;
868 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
869 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
870 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
871 aContext->Display(aAISIO, false);
872 aContext->SetDisplayMode(aAISIO, Shading, false);
876 // Append the filters from the local selection in the global selection context
877 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
878 for (;aIt.More(); aIt.Next()) {
879 Handle(SelectMgr_Filter) aFilter = aIt.Value();
880 aContext->AddFilter(aFilter);
885 //myUseExternalObjects = false;
888 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
889 //for(; aIt2.More(); aIt2.Next()) {
890 // if (aContext->IsDisplayed(aIt2.Value()))
891 // aContext->SetCurrentObject(aIt2.Value(), false);
896 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
899 if (myResult2AISObjectMap.contains(theObject))
900 anIO = myResult2AISObjectMap[theObject];
904 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
906 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
907 return getObject(aRefAIS);
910 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
913 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
914 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
915 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
921 if (!anObject.get()) {
922 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
923 if (!theIO.IsNull()) {
924 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
926 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
931 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
933 bool aWasEnabled = isUpdateEnabled();
935 myViewerBlockedRecursiveCount--;
937 myViewerBlockedRecursiveCount++;
939 if (myNeedUpdate && isUpdateEnabled()) {
941 myNeedUpdate = false;
946 bool XGUI_Displayer::isUpdateEnabled() const
948 return myViewerBlockedRecursiveCount == 0;
951 void XGUI_Displayer::updateViewer() const
953 Handle(AIS_InteractiveContext) aContext = AISContext();
954 if (!aContext.IsNull() && isUpdateEnabled()) {
955 //myWorkshop->viewer()->Zfitall();
956 aContext->UpdateCurrentViewer();
962 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
963 const int theMode, const bool theUpdateViewer) const
965 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
966 if (!theIO.IsNull() && theIO == getTrihedron()) {
967 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
968 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
971 if (!aContext.IsNull()) {
972 if (myWorkshop->module()) {
973 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
974 aContext->Activate(theIO, theMode, false);
976 aContext->Activate(theIO, theMode, false);
978 if (getCallBack()) getCallBack()->Activate(theIO, theMode);
981 // the fix from VPA for more suitable selection of sketcher lines
982 if (theIO->Width() > 1) {
983 double aPrecision = theIO->Width() + 2;
984 if (theMode == getSelectionMode(TopAbs_VERTEX))
985 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
986 "point-selection-sensitivity",
988 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
989 (theMode == getSelectionMode(TopAbs_WIRE)))
990 aPrecision = theIO->Width() +
991 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
992 "edge-selection-sensitivity", 2);
993 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
996 #ifdef DEBUG_ACTIVATE_AIS
997 ObjectPtr anObject = getObject(theIO);
998 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
999 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1000 .arg(anInfo).toStdString().c_str());
1002 if (theUpdateViewer)
1007 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1008 const int theMode) const
1010 Handle(AIS_InteractiveContext) aContext = AISContext();
1011 if (!aContext.IsNull()) {
1012 if (theMode == -1) {
1013 aContext->Deactivate(theIO);
1015 if (getCallBack()) getCallBack()->Deactivate(theIO);
1019 aContext->Deactivate(theIO, theMode);
1021 if (getCallBack()) getCallBack()->Deactivate(theIO, theMode);
1025 #ifdef DEBUG_DEACTIVATE_AIS
1026 ObjectPtr anObject = getObject(theIO);
1027 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1028 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1029 .arg(anInfo).toStdString().c_str());
1034 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1036 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1037 if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
1038 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1039 aDisplayer->myIsFirstAISContextUse = false;
1040 //aContext->OpenLocalContext();
1041 if (!isTrihedronActive())
1042 deactivateTrihedron(true);
1043 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1044 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1049 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1051 Handle(AIS_InteractiveContext) aContext = AISContext();
1052 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1053 myAndFilter = new SelectMgr_AndFilter();
1054 aContext->AddFilter(myAndFilter);
1059 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1060 bool theUpdateViewer)
1062 bool aDisplayed = false;
1063 Handle(AIS_InteractiveContext) aContext = AISContext();
1064 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1065 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1066 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1068 if (getCallBack()) getCallBack()->Display(anAISIO);
1071 aContext->Deactivate(anAISIO);
1073 if (getCallBack()) getCallBack()->Deactivate(anAISIO);
1075 aContext->Load(anAISIO);
1077 if (getCallBack()) getCallBack()->Load(anAISIO);
1079 if (toActivateInSelectionModes) {
1080 if (myActiveSelectionModes.size() == 0)
1081 activateAIS(anAISIO, 0, theUpdateViewer);
1083 foreach(int aMode, myActiveSelectionModes) {
1084 activateAIS(anAISIO, aMode, theUpdateViewer);
1088 if (theUpdateViewer)
1094 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1096 bool aErased = false;
1097 Handle(AIS_InteractiveContext) aContext = AISContext();
1098 if (!aContext.IsNull()) {
1099 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1100 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1101 aContext->Remove(anAISIO, false/*update viewer*/);
1103 if (getCallBack()) getCallBack()->Remove(anAISIO);
1108 if (aErased && theUpdateViewer)
1114 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1116 if (theMode == NoMode)
1119 Handle(AIS_InteractiveContext) aContext = AISContext();
1120 if (aContext.IsNull())
1123 AISObjectPtr aAISObj = getAISObject(theObject);
1127 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1128 aContext->SetDisplayMode(aAISIO, theMode, false);
1129 // Redisplay in order to update new mode because it could be not computed before
1130 if (theUpdateViewer)
1134 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1136 Handle(AIS_InteractiveContext) aContext = AISContext();
1137 if (aContext.IsNull())
1140 AISObjectPtr aAISObj = getAISObject(theObject);
1144 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1145 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1148 void XGUI_Displayer::deactivateSelectionFilters()
1150 Handle(AIS_InteractiveContext) aContext = AISContext();
1151 if (!myAndFilter.IsNull()) {
1152 bool aFound = false;
1153 if (!aContext.IsNull()) {
1154 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1155 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1156 for (; anIt.More() && !aFound; anIt.Next()) {
1157 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1158 aFound = aFilter == myAndFilter;
1161 aContext->RemoveFilter(myAndFilter);
1163 myAndFilter.Nullify();
1167 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1169 Handle(AIS_InteractiveContext) aContext = AISContext();
1170 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1173 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1174 if (!aCompositeFilter.IsNull()) {
1175 aCompositeFilter->Add(theFilter);
1176 #ifdef DEBUG_SELECTION_FILTERS
1177 int aCount = aCompositeFilter->StoredFilters().Extent();
1178 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1183 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1185 Handle(AIS_InteractiveContext) aContext = AISContext();
1186 if (aContext.IsNull())
1189 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1190 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1191 aCompositeFilter->Remove(theFilter);
1192 #ifdef DEBUG_SELECTION_FILTERS
1193 int aCount = aCompositeFilter->StoredFilters().Extent();
1194 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1195 .arg(aCount).toStdString().c_str());
1200 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1202 bool aFilterFound = false;
1204 Handle(AIS_InteractiveContext) aContext = AISContext();
1205 if (aContext.IsNull())
1206 return aFilterFound;
1207 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1208 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1209 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1210 if (theFilter.get() == aIt.Value().get())
1211 aFilterFound = true;
1213 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1214 if (!aCompositeFilter.IsNull()) {
1215 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1216 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1217 if (theFilter.get() == aIt.Value().get())
1218 aFilterFound = true;
1221 return aFilterFound;
1224 void XGUI_Displayer::removeFilters()
1226 Handle(AIS_InteractiveContext) aContext = AISContext();
1227 if (aContext.IsNull())
1230 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1231 if (!aCompositeFilter.IsNull())
1232 aCompositeFilter->Clear();
1235 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1237 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1238 foreach(ObjectPtr aObj, aDispList) {
1239 if (!theList.contains(aObj))
1242 foreach(ObjectPtr aObj, theList) {
1243 if (!isVisible(aObj))
1244 display(aObj, false);
1249 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1251 if (!isVisible(theObject))
1254 AISObjectPtr aAISObj = getAISObject(theObject);
1255 if (aAISObj.get() == NULL)
1258 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1259 return ::canBeShaded(anAIS, myWorkshop->module());
1262 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1263 const QIntList& theModes,
1264 const bool theUpdateViewer) const
1266 Handle(AIS_InteractiveContext) aContext = AISContext();
1267 if (aContext.IsNull() || theIO.IsNull())
1270 bool isActivationChanged = false;
1271 // deactivate object in all modes, which are not in the list of activation
1272 // It seems that after the IO deactivation the selected state of the IO's owners
1273 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1274 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1275 // only if there is a difference in the current modes and the parameters modes.
1276 // If the selection problem happens again, it is possible to write a test scenario and create
1277 // a bug. The bug steps are the following:
1278 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1279 // with clicked SHIFT select the second object.
1280 // The result is the selection of the first IO is lost.
1281 TColStd_ListOfInteger aTColModes;
1282 aContext->ActivatedModes(theIO, aTColModes);
1284 if (getCallBack()) getCallBack()->ActivatedModes(theIO, aTColModes);
1286 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1287 QIntList aModesActivatedForIO;
1288 bool isDeactivated = false;
1289 bool aHasValidMode = false;
1290 for (; itr.More(); itr.Next() ) {
1291 Standard_Integer aMode = itr.Value();
1292 aHasValidMode = aHasValidMode || aMode != -1;
1293 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1294 if (!theModes.contains(aMode)) {
1295 deactivateAIS(theIO, aMode);
1296 isDeactivated = true;
1299 aModesActivatedForIO.append(aMode);
1302 if (isDeactivated) {
1303 // the selection from the previous activation modes should be cleared manually (#26172)
1304 //theIO->ClearSelected();
1306 //if (getCallBack()) getCallBack()->ClearSelected(theIO);
1308 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
1309 deselectPresentation(theIO, aContext);
1311 // For performance issues
1312 //if (theUpdateViewer)
1314 isActivationChanged = true;
1317 // loading the interactive object allowing the decomposition
1318 if (aTColModes.IsEmpty() || !aHasValidMode) {
1319 aContext->Load(theIO, -1, true);
1320 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1321 if (!aTrihedron.IsNull()) {
1322 // Workaround for Trihedron. It should be loaded using the next Load method to
1323 // add this object to myGlobal map of selection manager
1324 // it is important to activate trihedron in two selection modes: edges and vertices
1325 aContext->SelectionManager()->Load(theIO);
1329 if (getCallBack()) getCallBack()->Load(theIO);
1333 // trihedron AIS check should be after the AIS loading.
1334 // If it is not loaded, it is steel selectable in the viewer.
1335 Handle(AIS_Trihedron) aTrihedron;
1336 if (!isTrihedronActive())
1337 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1338 if (aTrihedron.IsNull()) {
1339 // In order to clear active modes list
1340 if (theModes.size() == 0) {
1341 activateAIS(theIO, 0, theUpdateViewer);
1343 foreach(int aMode, theModes) {
1344 if (!aModesActivatedForIO.contains(aMode)) {
1345 activateAIS(theIO, aMode, theUpdateViewer);
1346 isActivationChanged = true;
1351 return isActivationChanged;
1354 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1356 AISObjectPtr anAISObj = getAISObject(theObject);
1357 // correct the result's color it it has the attribute
1358 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1360 // Customization of presentation
1361 GeomCustomPrsPtr aCustomPrs;
1362 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1363 if (aFeature.get() != NULL) {
1364 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1365 if (aCustPrs.get() != NULL)
1366 aCustomPrs = aCustPrs;
1368 if (aCustomPrs.get() == NULL) {
1369 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1370 // we ignore presentable not customized objects
1371 if (aPrs.get() == NULL)
1372 aCustomPrs = myCustomPrs;
1374 bool isCustomized = aCustomPrs.get() &&
1375 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1376 isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
1378 return isCustomized;
1382 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1383 const QColor& theColor,
1384 bool theUpdateViewer)
1386 if (!isVisible(theObject))
1389 AISObjectPtr anAISObj = getAISObject(theObject);
1391 anAISObj->getColor(aR, aG, aB);
1392 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1393 if (theUpdateViewer)
1395 return QColor(aR, aG, aB);
1398 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1400 myResult2AISObjectMap[theObject] = theAIS;
1402 #ifdef DEBUG_DISPLAY
1403 std::ostringstream aPtrStr;
1404 aPtrStr << theObject.get();
1405 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1406 qDebug(getResult2AISObjectMapInfo().c_str());
1411 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1413 QStringList aContent;
1414 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1415 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1416 std::ostringstream aPtrStr;
1417 aPtrStr << "aObj = " << aObj.get() << ":";
1418 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1419 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1421 aContent.append(aPtrStr.str().c_str());
1423 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1424 arg(aContent.join("\n")).toStdString().c_str();
1428 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1429 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1431 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1432 if (aResult.get()) {
1433 AISObjectPtr aAISObj = getAISObject(aResult);
1434 if (aAISObj.get() == NULL) {
1435 // if result is a result of a composite feature, it is visualized by visualization of
1436 // composite children, so we should get one of this presentations
1437 ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1438 if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
1439 aAISObj = getAISObject(aCompSolid->subResult(0));
1442 if (aAISObj.get() != NULL) {
1443 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1444 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1445 thePresentations.Add(anAIS);
1449 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1450 // find presentation of the feature
1451 AISObjectPtr aAISObj = getAISObject(aFeature);
1452 if (aAISObj.get() != NULL) {
1453 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1454 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1455 thePresentations.Add(anAIS);
1457 // find presentations of the feature results
1458 std::list<ResultPtr> aResults;
1459 ModelAPI_Tools::allResults(aFeature, aResults);
1460 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1461 for (; anIt != aLast; ++anIt) {
1462 AISObjectPtr aAISObj = getAISObject(*anIt);
1463 if (aAISObj.get() != NULL) {
1464 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1465 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1466 thePresentations.Add(anAIS);
1472 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1474 myIsTrihedronActive = theIsActive;
1475 if (!myIsTrihedronActive) {
1476 deactivateTrihedron(true);
1480 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1482 Handle(AIS_InteractiveContext) aContext = AISContext();
1483 if (aContext.IsNull())
1486 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1489 if (!aContext->IsDisplayed(aTrihedron))
1490 aContext->Display(aTrihedron,
1492 -1 /* selection mode */,
1493 Standard_True /* update viewer*/,
1494 Standard_False /* allow decomposition */,
1495 AIS_DS_Displayed /* xdisplay status */);
1497 if (getCallBack()) getCallBack()->Display(aTrihedron);
1500 if (!isTrihedronActive())
1501 deactivateTrihedron(false);
1503 activate(aTrihedron, myActiveSelectionModes, false);
1505 deactivateTrihedron(false);
1507 aContext->Erase(aTrihedron);
1509 if (getCallBack()) getCallBack()->Remove(aTrihedron);
1516 QIntList XGUI_Displayer::activeSelectionModes() const
1519 foreach (int aMode, myActiveSelectionModes) {
1520 // aMode < 9 is a Shape Enum values
1521 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1526 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1527 const NCollection_DataMap<TopoDS_Shape,
1528 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1530 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1531 theContext->MainSelector()->ActiveOwners(anActiveOwners);
1532 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1533 Handle(SelectMgr_EntityOwner) anOwner;
1535 /// It is very important to check that the owner is processed only once and has a map of
1536 /// processed owners because SetSelected works as a switch.
1537 /// If count of calls setSelectec is even, the object stays in the previous state
1538 /// (selected, deselected)
1539 /// OCCT: to write about the problem that active owners method returns one owner several times
1540 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1541 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1542 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1543 if (aSelectedIds.contains((long)anOwner.get()))
1545 aSelectedIds.append((long)anOwner.get());
1547 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1548 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1549 const TopoDS_Shape& aShape = BROwnr->Shape();
1550 if (aShape.IsNull())
1553 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)> >
1554 ::Iterator aShapeIt(theShapesToBeSelected);
1555 for (; aShapeIt.More(); aShapeIt.Next()) {
1556 if (aShapeIt.Key().IsSame(aShape)) {
1557 const TopoDS_Shape& aParameterShape = aShapeIt.Key();
1558 // isSame should be used here as it does not check orientation of shapes
1559 // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
1560 // different for Edges shapes in model shape and owner even if this is the same shape
1561 if (aParameterShape.IsSame(aShape)) {
1562 Handle(AIS_InteractiveObject) anOwnerPresentation =
1563 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1564 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1565 theShapesToBeSelected.Find(aParameterShape);
1566 if (aPresentations.Contains(anOwnerPresentation)) {
1567 theContext->AddOrRemoveSelected(anOwner);
1568 anOwner->SetSelected (Standard_True);