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>
19 #include <VInspectorAPI_Communicator.hxx>
21 #include <AppElements_MainWindow.h>
23 static bool VInspector_FirstCall = true;
26 #include <ModelAPI_Document.h>
27 #include <ModelAPI_Data.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Tools.h>
30 #include <ModelAPI_AttributeIntArray.h>
31 #include <ModelAPI_ResultCompSolid.h>
33 #include <ModuleBase_ResultPrs.h>
34 #include <ModuleBase_Tools.h>
35 #include <ModuleBase_IModule.h>
36 #include <ModuleBase_ViewerPrs.h>
37 #include <ModuleBase_Preferences.h>
39 #include <GeomAPI_Shape.h>
40 #include <GeomAPI_IPresentable.h>
41 #include <GeomAPI_ICustomPrs.h>
43 #include <SUIT_ResourceMgr.h>
45 #include <AIS_InteractiveContext.hxx>
46 #include <AIS_ListOfInteractive.hxx>
47 #include <AIS_ListIteratorOfListOfInteractive.hxx>
48 #include <AIS_DimensionSelectionMode.hxx>
49 #include <AIS_Shape.hxx>
50 #include <AIS_Dimension.hxx>
51 #include <AIS_Trihedron.hxx>
52 #include <AIS_Axis.hxx>
53 #include <AIS_Plane.hxx>
54 #include <AIS_Point.hxx>
55 #include <AIS_Selection.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <SelectMgr_ListOfFilter.hxx>
58 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
59 #include <Prs3d_Drawer.hxx>
60 #include <Prs3d_IsoAspect.hxx>
61 #include <SelectMgr_SelectionManager.hxx>
63 #include <StdSelect_ViewerSelector3d.hxx>
65 #include <TColStd_MapOfTransient.hxx>
66 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
69 #include <VInspectorAPI_CallBack.hxx>
72 #include <Events_Loop.h>
73 #include <ModelAPI_Events.h>
77 /// defines the local context mouse selection sensitivity
78 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
80 //#define DEBUG_ACTIVATE_OBJECTS
81 //#define DEBUG_DEACTIVATE
82 //#define DEBUG_ACTIVATE_AIS
83 //#define DEBUG_DEACTIVATE_AIS
85 //#define DEBUG_DISPLAY
86 //#define DEBUG_FEATURE_REDISPLAY
87 //#define DEBUG_SELECTION_FILTERS
89 //#define DEBUG_COMPOSILID_DISPLAY
91 //#define DEBUG_OCCT_SHAPE_SELECTION
93 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
95 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
97 // Get from null point
98 theAIS->DisplayedObjects(theList, true);
101 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
104 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
105 for (; anIt != aLast; anIt++) {
106 anInfo.append(QString::number(*anIt));
108 return anInfo.join(theSeparator);
111 void deselectPresentation(const Handle(AIS_InteractiveObject) theObject,
112 const Handle(AIS_InteractiveContext)& theContext)
114 NCollection_List<Handle(SelectBasics_EntityOwner)> aResultOwners;
116 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
117 Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
118 if (anOwner.IsNull()) // TODO: check why it is possible
120 if (anOwner->Selectable() == theObject && anOwner->IsSelected())
121 aResultOwners.Append(anOwner);
123 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (aResultOwners);
124 Handle(SelectMgr_EntityOwner) anOwner;
125 for (; anOwnersIt.More(); anOwnersIt.Next()) {
126 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
127 if (!anOwner.IsNull())
128 theContext->AddOrRemoveSelected(anOwner, false);
132 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
133 : myWorkshop(theWorkshop), myNeedUpdate(false),
134 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0),
135 myIsFirstAISContextUse(true)
140 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
143 XGUI_Displayer::~XGUI_Displayer()
147 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
149 return myResult2AISObjectMap.contains(theObject);
152 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
154 bool aDisplayed = false;
155 if (isVisible(theObject)) {
156 #ifdef DEBUG_COMPOSILID_DISPLAY
157 ResultCompSolidPtr aCompsolidResult =
158 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
159 if (aCompsolidResult.get()) {
160 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
161 ResultPtr aSubResult = aCompsolidResult->subResult(i);
162 if (aSubResult.get())
163 redisplay(aSubResult, false);
170 aDisplayed = redisplay(theObject, theUpdateViewer);
173 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
174 bool isShading = false;
175 if (aPrs.get() != NULL) {
176 anAIS = aPrs->getAISObject(anAIS);
178 // correct deviation coefficient for
179 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
180 if (!anAISPrs.IsNull()) {
181 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
182 if (!aShapePrs.IsNull()) {
183 TopoDS_Shape aShape = aShapePrs->Shape();
184 if (!aShape.IsNull())
185 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
190 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
191 if (aResult.get() != NULL) {
192 #ifdef DEBUG_COMPOSILID_DISPLAY
193 ResultCompSolidPtr aCompsolidResult =
194 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
195 if (aCompsolidResult.get()) {
196 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
197 ResultPtr aSubResult = aCompsolidResult->subResult(i);
198 if (aSubResult.get())
199 display(aSubResult, false);
206 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
207 if (aShapePtr.get() != NULL) {
208 anAIS = AISObjectPtr(new GeomAPI_AISObject());
209 Handle(AIS_InteractiveObject) anAISPrs =
210 myWorkshop->module()->createPresentation(aResult);
211 if (anAISPrs.IsNull())
212 anAISPrs = new ModuleBase_ResultPrs(aResult);
214 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
215 if (!aShapePrs.IsNull())
216 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
218 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
219 //anAIS->createShape(aShapePtr);
222 #ifdef DEBUG_COMPOSILID_DISPLAY
228 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
233 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
235 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
236 if (!aShapePrs.IsNull()) {
237 TopoDS_Shape aShape = aShapePrs->Shape();
240 TopAbs_ShapeEnum aType = aShape.ShapeType();
241 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
244 // Check that the presentation is not a sketch
245 return theModule->canBeShaded(theAIS);
251 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
252 bool isShading, bool theUpdateViewer)
254 bool aDisplayed = false;
256 Handle(AIS_InteractiveContext) aContext = AISContext();
257 if (aContext.IsNull())
260 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
261 if (!anAISIO.IsNull()) {
262 appendResultObject(theObject, theAIS);
264 bool isCustomized = customizeObject(theObject);
266 int aDispMode = isShading? Shading : Wireframe;
268 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
269 anAISIO->SetDisplayMode(aDispMode);
270 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
272 if (getCallBack()) getCallBack()->Display(anAISIO);
276 emit objectDisplayed(theObject, theAIS);
277 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
285 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
287 bool aErased = false;
288 if (!isVisible(theObject))
291 Handle(AIS_InteractiveContext) aContext = AISContext();
292 if (aContext.IsNull())
295 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
297 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
298 if (!anAIS.IsNull()) {
299 emit beforeObjectErase(theObject, anObject);
300 aContext->Remove(anAIS, false/*update viewer*/);
302 if (getCallBack()) getCallBack()->Remove(anAIS);
307 myResult2AISObjectMap.remove(theObject);
310 std::ostringstream aPtrStr;
311 aPtrStr << theObject.get();
312 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
313 qDebug(getResult2AISObjectMapInfo().c_str());
322 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
324 bool aRedisplayed = false;
325 if (!isVisible(theObject))
328 AISObjectPtr aAISObj = getAISObject(theObject);
329 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
331 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
333 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
335 aRedisplayed = erase(theObject, theUpdateViewer);
338 if (aAIS_Obj != aAISObj) {
339 appendResultObject(theObject, aAIS_Obj);
341 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
344 Handle(AIS_InteractiveContext) aContext = AISContext();
345 if (!aContext.IsNull() && !aAISIO.IsNull()) {
346 // Check that the visualized shape is the same and the redisplay is not necessary
347 // Redisplay of AIS object leads to this object selection compute and the selection
348 // in the browser is lost
349 // this check is not necessary anymore because the selection store/restore is realized
350 // before and after the values modification.
351 // Moreother, this check avoids customize and redisplay presentation if the presentable
352 // parameter is changed.
353 bool isEqualShapes = false;
354 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
355 if (aResult.get() != NULL) {
356 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
357 if (!aShapePrs.IsNull()) {
358 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
359 if (aShapePtr.get()) {
360 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
361 if (!aOldShape.IsNull())
362 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
366 // Customization of presentation
367 bool isCustomized = customizeObject(theObject);
368 #ifdef DEBUG_FEATURE_REDISPLAY
369 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
370 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
371 .arg(isCustomized).toStdString().c_str());
373 if (!isEqualShapes || isCustomized) {
374 /// if shapes are equal and presentation are customized, selection should be restored
375 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
376 if (aNeedToRestoreSelection)
377 myWorkshop->module()->storeSelection();
379 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
380 deselectPresentation(aAISIO, aContext);
382 aContext->Redisplay(aAISIO, false);
385 if (getCallBack()) getCallBack()->Redisplay(aAISIO);
388 if (aNeedToRestoreSelection)
389 myWorkshop->module()->restoreSelection();
392 #ifdef DEBUG_FEATURE_REDISPLAY
393 qDebug(" Redisplay happens");
402 void XGUI_Displayer::redisplayObjects()
404 // redisplay objects visualized in the viewer
405 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
406 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
407 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
408 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
409 for (; anIt != aLast; anIt++) {
410 aECreator->sendUpdated(*anIt, EVENT_DISP);
412 Events_Loop::loop()->flush(EVENT_DISP);
415 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
417 #ifdef DEBUG_DEACTIVATE
418 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
419 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
420 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
422 toStdString().c_str());
424 Handle(AIS_InteractiveContext) aContext = AISContext();
425 if (!aContext.IsNull() && isVisible(theObject)) {
426 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
427 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
429 deactivateAIS(anAIS);
430 // the selection from the previous activation modes should be cleared manually (#26172)
431 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
432 deselectPresentation(anAIS, aContext);
439 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
440 const bool theUpdateViewer)
442 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
443 //if (!aTrihedron.IsNull())
444 // deactivateAIS(aTrihedron);
446 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
447 for (; anIt != aLast; anIt++) {
448 deactivate(*anIt, false);
450 //VSV It seems that there is no necessity to update viewer on deactivation
451 //if (theUpdateViewer)
455 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
457 Handle(AIS_InteractiveContext) aContext = AISContext();
458 if (aContext.IsNull() || !isVisible(theObject))
461 AISObjectPtr aAISObj = getAISObject(theObject);
463 if (aAISObj.get() != NULL) {
464 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
465 TColStd_ListOfInteger aTColModes;
466 aContext->ActivatedModes(anAISIO, aTColModes);
467 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
468 for (; itr.More(); itr.Next() ) {
469 theModes.append(itr.Value());
474 int XGUI_Displayer::getSelectionMode(int theShapeType)
476 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
477 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
480 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
482 bool aVisible = false;
483 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
484 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
485 if (aPrs.get() || aResult.get()) {
486 aVisible = theDisplayer->isVisible(theObject);
487 // compsolid is not visualized in the viewer,
488 // but should have presentation when all sub solids are
489 // visible. It is useful for highlight presentation where compsolid shape is selectable
490 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
491 ResultCompSolidPtr aCompsolidResult =
492 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
493 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
494 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
495 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
496 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
498 aVisible = anAllSubsVisible;
502 // it is possible that feature is presentable and has results, so we should check visibility
503 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
505 // check if all results of the feature are visible
506 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
507 std::list<ResultPtr> aResults;
508 ModelAPI_Tools::allResults(aFeature, aResults);
509 std::list<ResultPtr>::const_iterator aIt;
510 aVisible = !aResults.empty();
511 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
512 aVisible = aVisible && theDisplayer->isVisible(*aIt);
518 #ifdef DEBUG_ACTIVATE_OBJECTS
519 QString getModeInfo(const int theMode)
521 QString anInfo = "Undefined";
523 case 0: anInfo = "SHAPE(0)"; break;
524 case 1: anInfo = "VERTEX(1)"; break;
525 case 2: anInfo = "EDGE(2)"; break;
526 case 3: anInfo = "WIRE(3)"; break;
527 case 4: anInfo = "FACE(4)"; break;
528 case 5: anInfo = "SHELL(5)"; break;
529 case 6: anInfo = "SOLID(6)"; break;
530 case 7: anInfo = "COMPSOLID(7)"; break;
531 case 8: anInfo = "COMPOUND(8)"; break;
532 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
533 case 101: anInfo = "Sel_Constraint(101)"; break;
534 case 102: anInfo = "Sel_Dimension_All(102)"; break;
535 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
536 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
542 QString getModesInfo(const QIntList& theModes)
544 QStringList aModesInfo;
545 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
546 aModesInfo.append(getModeInfo(theModes[i]));
547 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
551 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
552 const bool theUpdateViewer)
554 // Convert shape types to selection types
556 foreach(int aType, theModes) {
557 aModes.append(getSelectionMode(aType));
560 #ifdef DEBUG_ACTIVATE_OBJECTS
562 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
563 for (; anIt != aLast; ++anIt) {
564 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
566 QString anInfoStr = anInfo.join(", ");
568 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
569 arg(getModesInfo(aModes)).
570 arg(getModesInfo(myActiveSelectionModes)).
571 arg(theObjList.size()).
573 toStdString().c_str());
575 // In order to avoid doblications of selection modes
577 foreach (int aMode, aModes) {
578 if (!aNewModes.contains(aMode))
579 aNewModes.append(aMode);
581 myActiveSelectionModes = aNewModes;
582 Handle(AIS_InteractiveContext) aContext = AISContext();
583 // Open local context if there is no one
584 if (aContext.IsNull())
587 //aContext->UseDisplayedObjects();
588 //myUseExternalObjects = true;
590 Handle(AIS_InteractiveObject) anAISIO;
591 AIS_ListOfInteractive aPrsList;
592 //if (aObjList.isEmpty())
595 foreach(ObjectPtr aObj, theObjList) {
596 if (myResult2AISObjectMap.contains(aObj))
597 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
601 // Add trihedron because it has to partisipate in selection
602 Handle(AIS_InteractiveObject) aTrihedron;
603 if (isTrihedronActive()) {
604 aTrihedron = getTrihedron();
605 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
606 aPrsList.Append(aTrihedron);
608 if (aPrsList.Extent() == 0)
611 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
612 bool isActivationChanged = false;
613 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
614 anAISIO = aLIt.Value();
615 if (activate(anAISIO, myActiveSelectionModes, false))
616 isActivationChanged = true;
620 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
622 Handle(AIS_InteractiveContext) aContext = AISContext();
623 if (aContext.IsNull() || !isVisible(theObject))
626 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
627 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
629 TColStd_ListOfInteger aModes;
630 aContext->ActivatedModes(anAIS, aModes);
632 if (getCallBack()) getCallBack()->ActivatedModes(anAIS, aModes);
635 return aModes.Extent() > 0;
639 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
640 bool theUpdateViewer)
642 Handle(AIS_InteractiveContext) aContext = AISContext();
643 if (aContext.IsNull())
645 aContext->UnhilightSelected(false);
646 aContext->ClearSelected(false);
648 if (getCallBack()) getCallBack()->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 (getCallBack()) getCallBack()->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 (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
694 if (!aShapesToBeSelected.IsEmpty())
695 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
701 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
703 Handle(AIS_InteractiveContext) aContext = AISContext();
704 if (!aContext.IsNull()) {
705 aContext->UnhilightCurrents(false);
706 aContext->ClearSelected(theUpdateViewer);
708 if (getCallBack()) getCallBack()->ClearSelected();
713 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
715 bool aErased = false;
716 Handle(AIS_InteractiveContext) aContext = AISContext();
717 if (!aContext.IsNull()) {
718 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
719 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
721 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
722 if (!anIO.IsNull()) {
723 emit beforeObjectErase(aObj, aAISObj);
724 aContext->Remove(anIO, false/*update viewer*/);
726 if (getCallBack()) getCallBack()->Remove(anIO);
734 myResult2AISObjectMap.clear();
737 qDebug(getResult2AISObjectMapInfo().c_str());
742 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
743 Handle(AIS_InteractiveObject) theObject
745 , VInspectorAPI_CallBack* theCallBack
749 if (!theObject.IsNull()) {
750 theContext->Deactivate(theObject);
752 if (theCallBack) theCallBack->Deactivate(theObject);
757 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
759 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
760 Handle(AIS_InteractiveContext) aContext = AISContext();
761 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
762 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
763 deactivateObject(aContext, aTrie
769 /// #1136 hidden axis are selected in sketch
770 deactivateObject(aContext, aTrie->XAxis()
775 deactivateObject(aContext, aTrie->YAxis()
780 deactivateObject(aContext, aTrie->Axis()
785 deactivateObject(aContext, aTrie->Position()
791 deactivateObject(aContext, aTrie->XYPlane()
796 deactivateObject(aContext, aTrie->XZPlane()
801 deactivateObject(aContext, aTrie->YZPlane()
812 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
814 return myWorkshop->viewer()->trihedron();
817 /*void XGUI_Displayer::openLocalContext()
819 Handle(AIS_InteractiveContext) aContext = AISContext();
820 // Open local context if there is no one
821 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
822 // Preserve selected objects
823 //AIS_ListOfInteractive aAisList;
824 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
825 // aAisList.Append(aContext->Current());
827 // get the filters from the global context and append them to the local context
828 // a list of filters in the global context is not cleared and should be cleared here
829 SelectMgr_ListOfFilter aFilters;
830 aFilters.Assign(aContext->Filters());
831 // it is important to remove the filters in the global context, because there is a code
832 // in the closeLocalContex, which restore the global context filters
833 aContext->RemoveFilters();
835 //aContext->ClearCurrents();
836 aContext->OpenLocalContext();
837 //deactivateTrihedron();
838 //aContext->NotUseDisplayedObjects();
840 //myUseExternalObjects = false;
842 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
843 for (;aIt.More(); aIt.Next()) {
844 aContext->AddFilter(aIt.Value());
847 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
848 //for(; aIt2.More(); aIt2.Next()) {
849 // aContext->SetSelected(aIt2.Value(), false);
854 /*void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
856 Handle(AIS_InteractiveContext) aContext = AISContext();
857 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
858 // Preserve selected objects
859 //AIS_ListOfInteractive aAisList;
860 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
861 // aAisList.Append(aContext->SelectedInteractive());
863 // get the filters from the local context and append them to the global context
864 // a list of filters in the local context is cleared
865 SelectMgr_ListOfFilter aFilters;
866 aFilters.Assign(aContext->Filters());
868 //aContext->ClearSelected();
869 aContext->CloseAllContexts(false);
871 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
872 // this code is obsolete. It is temporaty commented and should be removed after
873 // the test campaign.
874 // Redisplay all object if they were displayed in localContext
875 /*Handle(AIS_InteractiveObject) aAISIO;
876 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
877 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
878 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
879 aContext->Display(aAISIO, false);
880 aContext->SetDisplayMode(aAISIO, Shading, false);
884 // Append the filters from the local selection in the global selection context
885 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
886 for (;aIt.More(); aIt.Next()) {
887 Handle(SelectMgr_Filter) aFilter = aIt.Value();
888 aContext->AddFilter(aFilter);
893 //myUseExternalObjects = false;
896 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
897 //for(; aIt2.More(); aIt2.Next()) {
898 // if (aContext->IsDisplayed(aIt2.Value()))
899 // aContext->SetCurrentObject(aIt2.Value(), false);
904 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
907 if (myResult2AISObjectMap.contains(theObject))
908 anIO = myResult2AISObjectMap[theObject];
912 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
914 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
915 return getObject(aRefAIS);
918 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
921 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
922 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
923 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
929 if (!anObject.get()) {
930 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
931 if (!theIO.IsNull()) {
932 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
934 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
939 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
941 bool aWasEnabled = isUpdateEnabled();
943 myViewerBlockedRecursiveCount--;
945 myViewerBlockedRecursiveCount++;
947 if (myNeedUpdate && isUpdateEnabled()) {
949 myNeedUpdate = false;
954 bool XGUI_Displayer::isUpdateEnabled() const
956 return myViewerBlockedRecursiveCount == 0;
959 void XGUI_Displayer::updateViewer() const
961 Handle(AIS_InteractiveContext) aContext = AISContext();
962 if (!aContext.IsNull() && isUpdateEnabled()) {
963 //myWorkshop->viewer()->Zfitall();
964 aContext->UpdateCurrentViewer();
970 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
971 const int theMode, const bool theUpdateViewer) const
973 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
974 if (!theIO.IsNull() && theIO == getTrihedron()) {
975 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
976 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
979 if (!aContext.IsNull()) {
980 if (myWorkshop->module()) {
981 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
982 aContext->Activate(theIO, theMode, false);
984 aContext->Activate(theIO, theMode, false);
986 if (getCallBack()) getCallBack()->Activate(theIO, theMode);
989 // the fix from VPA for more suitable selection of sketcher lines
990 if (theIO->Width() > 1) {
991 double aPrecision = theIO->Width() + 2;
992 if (theMode == getSelectionMode(TopAbs_VERTEX))
993 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
994 "point-selection-sensitivity",
996 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
997 (theMode == getSelectionMode(TopAbs_WIRE)))
998 aPrecision = theIO->Width() +
999 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1000 "edge-selection-sensitivity", 2);
1001 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
1004 #ifdef DEBUG_ACTIVATE_AIS
1005 ObjectPtr anObject = getObject(theIO);
1006 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1007 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1008 .arg(anInfo).toStdString().c_str());
1010 if (theUpdateViewer)
1015 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1016 const int theMode) const
1018 Handle(AIS_InteractiveContext) aContext = AISContext();
1019 if (!aContext.IsNull()) {
1020 if (theMode == -1) {
1021 aContext->Deactivate(theIO);
1023 if (getCallBack()) getCallBack()->Deactivate(theIO);
1027 aContext->Deactivate(theIO, theMode);
1029 if (getCallBack()) getCallBack()->Deactivate(theIO, theMode);
1033 #ifdef DEBUG_DEACTIVATE_AIS
1034 ObjectPtr anObject = getObject(theIO);
1035 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1036 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1037 .arg(anInfo).toStdString().c_str());
1042 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1044 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1045 if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
1047 if (VInspector_FirstCall) {
1048 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1050 VInspectorAPI_Communicator* aCommunicator =
1051 VInspectorAPI_Communicator::loadPluginLibrary("TKVInspector.dll");
1052 if (aCommunicator) {
1053 aCommunicator->setContext(aContext);
1055 aDisplayer->setCommunicator(aCommunicator);
1057 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
1059 aViewer->setCallBack(aCommunicator->getCallBack());
1062 VInspector_FirstCall = false;
1065 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1066 aDisplayer->myIsFirstAISContextUse = false;
1067 //aContext->OpenLocalContext();
1068 if (!isTrihedronActive())
1069 deactivateTrihedron(true);
1070 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1071 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1076 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1078 Handle(AIS_InteractiveContext) aContext = AISContext();
1079 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1080 myAndFilter = new SelectMgr_AndFilter();
1081 aContext->AddFilter(myAndFilter);
1086 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1087 bool theUpdateViewer)
1089 bool aDisplayed = false;
1090 Handle(AIS_InteractiveContext) aContext = AISContext();
1091 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1092 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1093 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1095 if (getCallBack()) getCallBack()->Display(anAISIO);
1098 aContext->Deactivate(anAISIO);
1100 if (getCallBack()) getCallBack()->Deactivate(anAISIO);
1102 aContext->Load(anAISIO);
1104 if (getCallBack()) getCallBack()->Load(anAISIO);
1106 if (toActivateInSelectionModes) {
1107 if (myActiveSelectionModes.size() == 0)
1108 activateAIS(anAISIO, 0, theUpdateViewer);
1110 foreach(int aMode, myActiveSelectionModes) {
1111 activateAIS(anAISIO, aMode, theUpdateViewer);
1115 if (theUpdateViewer)
1121 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1123 bool aErased = false;
1124 Handle(AIS_InteractiveContext) aContext = AISContext();
1125 if (!aContext.IsNull()) {
1126 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1127 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1128 aContext->Remove(anAISIO, false/*update viewer*/);
1130 if (getCallBack()) getCallBack()->Remove(anAISIO);
1135 if (aErased && theUpdateViewer)
1141 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1143 if (theMode == NoMode)
1146 Handle(AIS_InteractiveContext) aContext = AISContext();
1147 if (aContext.IsNull())
1150 AISObjectPtr aAISObj = getAISObject(theObject);
1154 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1155 aContext->SetDisplayMode(aAISIO, theMode, false);
1156 // Redisplay in order to update new mode because it could be not computed before
1157 if (theUpdateViewer)
1161 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1163 Handle(AIS_InteractiveContext) aContext = AISContext();
1164 if (aContext.IsNull())
1167 AISObjectPtr aAISObj = getAISObject(theObject);
1171 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1172 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1175 void XGUI_Displayer::deactivateSelectionFilters()
1177 Handle(AIS_InteractiveContext) aContext = AISContext();
1178 if (!myAndFilter.IsNull()) {
1179 bool aFound = false;
1180 if (!aContext.IsNull()) {
1181 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1182 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1183 for (; anIt.More() && !aFound; anIt.Next()) {
1184 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1185 aFound = aFilter == myAndFilter;
1188 aContext->RemoveFilter(myAndFilter);
1190 myAndFilter.Nullify();
1194 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1196 Handle(AIS_InteractiveContext) aContext = AISContext();
1197 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1200 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1201 if (!aCompositeFilter.IsNull()) {
1202 aCompositeFilter->Add(theFilter);
1203 #ifdef DEBUG_SELECTION_FILTERS
1204 int aCount = aCompositeFilter->StoredFilters().Extent();
1205 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1210 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1212 Handle(AIS_InteractiveContext) aContext = AISContext();
1213 if (aContext.IsNull())
1216 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1217 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1218 aCompositeFilter->Remove(theFilter);
1219 #ifdef DEBUG_SELECTION_FILTERS
1220 int aCount = aCompositeFilter->StoredFilters().Extent();
1221 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1222 .arg(aCount).toStdString().c_str());
1227 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1229 bool aFilterFound = false;
1231 Handle(AIS_InteractiveContext) aContext = AISContext();
1232 if (aContext.IsNull())
1233 return aFilterFound;
1234 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1235 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1236 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1237 if (theFilter.get() == aIt.Value().get())
1238 aFilterFound = true;
1240 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1241 if (!aCompositeFilter.IsNull()) {
1242 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1243 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1244 if (theFilter.get() == aIt.Value().get())
1245 aFilterFound = true;
1248 return aFilterFound;
1251 void XGUI_Displayer::removeFilters()
1253 Handle(AIS_InteractiveContext) aContext = AISContext();
1254 if (aContext.IsNull())
1257 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1258 if (!aCompositeFilter.IsNull())
1259 aCompositeFilter->Clear();
1262 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1264 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1265 foreach(ObjectPtr aObj, aDispList) {
1266 if (!theList.contains(aObj))
1269 foreach(ObjectPtr aObj, theList) {
1270 if (!isVisible(aObj))
1271 display(aObj, false);
1276 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1278 if (!isVisible(theObject))
1281 AISObjectPtr aAISObj = getAISObject(theObject);
1282 if (aAISObj.get() == NULL)
1285 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1286 return ::canBeShaded(anAIS, myWorkshop->module());
1289 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1290 const QIntList& theModes,
1291 const bool theUpdateViewer) const
1293 Handle(AIS_InteractiveContext) aContext = AISContext();
1294 if (aContext.IsNull() || theIO.IsNull())
1297 bool isActivationChanged = false;
1298 // deactivate object in all modes, which are not in the list of activation
1299 // It seems that after the IO deactivation the selected state of the IO's owners
1300 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1301 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1302 // only if there is a difference in the current modes and the parameters modes.
1303 // If the selection problem happens again, it is possible to write a test scenario and create
1304 // a bug. The bug steps are the following:
1305 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1306 // with clicked SHIFT select the second object.
1307 // The result is the selection of the first IO is lost.
1308 TColStd_ListOfInteger aTColModes;
1309 aContext->ActivatedModes(theIO, aTColModes);
1311 if (getCallBack()) getCallBack()->ActivatedModes(theIO, aTColModes);
1313 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1314 QIntList aModesActivatedForIO;
1315 bool isDeactivated = false;
1316 bool aHasValidMode = false;
1317 for (; itr.More(); itr.Next() ) {
1318 Standard_Integer aMode = itr.Value();
1319 aHasValidMode = aHasValidMode || aMode != -1;
1320 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1321 if (!theModes.contains(aMode)) {
1322 deactivateAIS(theIO, aMode);
1323 isDeactivated = true;
1326 aModesActivatedForIO.append(aMode);
1329 if (isDeactivated) {
1330 // the selection from the previous activation modes should be cleared manually (#26172)
1331 //theIO->ClearSelected();
1333 //if (getCallBack()) getCallBack()->ClearSelected(theIO);
1335 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
1336 deselectPresentation(theIO, aContext);
1338 // For performance issues
1339 //if (theUpdateViewer)
1341 isActivationChanged = true;
1344 // loading the interactive object allowing the decomposition
1345 if (aTColModes.IsEmpty() || !aHasValidMode) {
1346 aContext->Load(theIO, -1, true);
1347 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1348 if (!aTrihedron.IsNull()) {
1349 // Workaround for Trihedron. It should be loaded using the next Load method to
1350 // add this object to myGlobal map of selection manager
1351 // it is important to activate trihedron in two selection modes: edges and vertices
1352 aContext->SelectionManager()->Load(theIO);
1356 if (getCallBack()) getCallBack()->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());
1436 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1438 QStringList aContent;
1439 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1440 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1441 std::ostringstream aPtrStr;
1442 aPtrStr << "aObj = " << aObj.get() << ":";
1443 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1444 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1446 aContent.append(aPtrStr.str().c_str());
1448 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1449 arg(aContent.join("\n")).toStdString().c_str();
1453 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1454 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1456 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1457 if (aResult.get()) {
1458 AISObjectPtr aAISObj = getAISObject(aResult);
1459 if (aAISObj.get() != NULL) {
1460 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1461 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1462 thePresentations.Add(anAIS);
1466 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1467 // find presentation of the feature
1468 AISObjectPtr aAISObj = getAISObject(aFeature);
1469 if (aAISObj.get() != NULL) {
1470 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1471 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1472 thePresentations.Add(anAIS);
1474 // find presentations of the feature results
1475 std::list<ResultPtr> aResults;
1476 ModelAPI_Tools::allResults(aFeature, aResults);
1477 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1478 for (; anIt != aLast; ++anIt) {
1479 AISObjectPtr aAISObj = getAISObject(*anIt);
1480 if (aAISObj.get() != NULL) {
1481 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1482 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1483 thePresentations.Add(anAIS);
1489 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1491 myIsTrihedronActive = theIsActive;
1492 if (!myIsTrihedronActive) {
1493 deactivateTrihedron(true);
1497 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1499 Handle(AIS_InteractiveContext) aContext = AISContext();
1500 if (aContext.IsNull())
1503 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1506 if (!aContext->IsDisplayed(aTrihedron))
1507 aContext->Display(aTrihedron,
1509 -1 /* selection mode */,
1510 Standard_True /* update viewer*/,
1511 Standard_False /* allow decomposition */,
1512 AIS_DS_Displayed /* xdisplay status */);
1514 if (getCallBack()) getCallBack()->Display(aTrihedron);
1517 if (!isTrihedronActive())
1518 deactivateTrihedron(false);
1520 activate(aTrihedron, myActiveSelectionModes, false);
1522 deactivateTrihedron(false);
1524 aContext->Erase(aTrihedron);
1526 if (getCallBack()) getCallBack()->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::setCommunicator(VInspectorAPI_Communicator* theCommunicator)
1546 myCommunicator = theCommunicator;
1549 void XGUI_Displayer::setVInspectorVisible(const bool theVisible)
1552 myCommunicator->setVisible(true);
1555 VInspectorAPI_CallBack* XGUI_Displayer::getCallBack() const
1557 return myCommunicator ? myCommunicator->getCallBack() : NULL;
1561 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1562 const NCollection_DataMap<TopoDS_Shape,
1563 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1565 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1566 theContext->MainSelector()->ActiveOwners(anActiveOwners);
1567 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1568 Handle(SelectMgr_EntityOwner) anOwner;
1570 /// It is very important to check that the owner is processed only once and has a map of
1571 /// processed owners because SetSelected works as a switch.
1572 /// If count of calls setSelectec is even, the object stays in the previous state
1573 /// (selected, deselected)
1574 /// OCCT: to write about the problem that active owners method returns one owner several times
1575 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1576 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1577 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1578 if (aSelectedIds.contains((long)anOwner.get()))
1580 aSelectedIds.append((long)anOwner.get());
1582 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1583 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1584 const TopoDS_Shape& aShape = BROwnr->Shape();
1585 if (aShape.IsNull())
1588 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)> >
1589 ::Iterator aShapeIt(theShapesToBeSelected);
1590 for (; aShapeIt.More(); aShapeIt.Next()) {
1591 if (aShapeIt.Key().IsSame(aShape)) {
1592 const TopoDS_Shape& aParameterShape = aShapeIt.Key();
1593 // isSame should be used here as it does not check orientation of shapes
1594 // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
1595 // different for Edges shapes in model shape and owner even if this is the same shape
1596 if (aParameterShape.IsSame(aShape)) {
1597 Handle(AIS_InteractiveObject) anOwnerPresentation =
1598 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1599 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1600 theShapesToBeSelected.Find(aParameterShape);
1601 if (aPresentations.Contains(anOwnerPresentation)) {
1602 theContext->AddOrRemoveSelected(anOwner);
1603 anOwner->SetSelected (Standard_True);