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_PluginMgr.h>
20 #include <VInspectorAPI_Communicator.h>
22 #include <AppElements_MainWindow.h>
24 static bool VInspector_FirstCall = true;
27 #include <ModelAPI_Document.h>
28 #include <ModelAPI_Data.h>
29 #include <ModelAPI_Object.h>
30 #include <ModelAPI_Tools.h>
31 #include <ModelAPI_AttributeIntArray.h>
32 #include <ModelAPI_ResultCompSolid.h>
34 #include <ModuleBase_ResultPrs.h>
35 #include <ModuleBase_Tools.h>
36 #include <ModuleBase_IModule.h>
37 #include <ModuleBase_ViewerPrs.h>
38 #include <ModuleBase_Preferences.h>
40 #include <GeomAPI_Shape.h>
41 #include <GeomAPI_IPresentable.h>
42 #include <GeomAPI_ICustomPrs.h>
44 #include <SUIT_ResourceMgr.h>
46 #include <AIS_InteractiveContext.hxx>
47 #include <AIS_ListOfInteractive.hxx>
48 #include <AIS_ListIteratorOfListOfInteractive.hxx>
49 #include <AIS_DimensionSelectionMode.hxx>
50 #include <AIS_Shape.hxx>
51 #include <AIS_Dimension.hxx>
52 #include <AIS_Trihedron.hxx>
53 #include <AIS_Axis.hxx>
54 #include <AIS_Plane.hxx>
55 #include <AIS_Point.hxx>
56 #include <AIS_Selection.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <SelectMgr_ListOfFilter.hxx>
59 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
60 #include <Prs3d_Drawer.hxx>
61 #include <Prs3d_IsoAspect.hxx>
62 #include <SelectMgr_SelectionManager.hxx>
64 #include <StdSelect_ViewerSelector3d.hxx>
66 #include <TColStd_MapOfTransient.hxx>
67 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
70 #include <VInspectorAPI_CallBack.h>
73 #include <Events_Loop.h>
74 #include <ModelAPI_Events.h>
78 /// defines the local context mouse selection sensitivity
79 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
81 //#define DEBUG_ACTIVATE_OBJECTS
82 //#define DEBUG_DEACTIVATE
83 //#define DEBUG_ACTIVATE_AIS
84 //#define DEBUG_DEACTIVATE_AIS
86 //#define DEBUG_DISPLAY
87 //#define DEBUG_FEATURE_REDISPLAY
88 //#define DEBUG_SELECTION_FILTERS
90 //#define DEBUG_COMPOSILID_DISPLAY
92 //#define DEBUG_OCCT_SHAPE_SELECTION
94 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
96 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
98 // Get from null point
99 theAIS->DisplayedObjects(theList, true);
102 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
105 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
106 for (; anIt != aLast; anIt++) {
107 anInfo.append(QString::number(*anIt));
109 return anInfo.join(theSeparator);
112 void deselectPresentation(const Handle(AIS_InteractiveObject) theObject,
113 const Handle(AIS_InteractiveContext)& theContext)
115 NCollection_List<Handle(SelectBasics_EntityOwner)> aResultOwners;
117 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
118 Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
119 if (anOwner.IsNull()) // TODO: check why it is possible
121 if (anOwner->Selectable() == theObject && anOwner->IsSelected())
122 aResultOwners.Append(anOwner);
124 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (aResultOwners);
125 Handle(SelectMgr_EntityOwner) anOwner;
126 for (; anOwnersIt.More(); anOwnersIt.Next()) {
127 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
128 if (!anOwner.IsNull())
129 theContext->AddOrRemoveSelected(anOwner, false);
133 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
134 : myWorkshop(theWorkshop), myNeedUpdate(false),
135 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0),
136 myIsFirstAISContextUse(true)
141 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
144 XGUI_Displayer::~XGUI_Displayer()
148 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
150 return myResult2AISObjectMap.contains(theObject);
153 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
155 bool aDisplayed = false;
156 if (isVisible(theObject)) {
157 #ifdef DEBUG_COMPOSILID_DISPLAY
158 ResultCompSolidPtr aCompsolidResult =
159 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
160 if (aCompsolidResult.get()) {
161 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
162 ResultPtr aSubResult = aCompsolidResult->subResult(i);
163 if (aSubResult.get())
164 redisplay(aSubResult, false);
171 aDisplayed = redisplay(theObject, theUpdateViewer);
174 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
175 bool isShading = false;
176 if (aPrs.get() != NULL) {
177 anAIS = aPrs->getAISObject(anAIS);
179 // correct deviation coefficient for
180 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
181 if (!anAISPrs.IsNull()) {
182 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
183 if (!aShapePrs.IsNull()) {
184 TopoDS_Shape aShape = aShapePrs->Shape();
185 if (!aShape.IsNull())
186 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
191 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
192 if (aResult.get() != NULL) {
193 #ifdef DEBUG_COMPOSILID_DISPLAY
194 ResultCompSolidPtr aCompsolidResult =
195 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
196 if (aCompsolidResult.get()) {
197 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
198 ResultPtr aSubResult = aCompsolidResult->subResult(i);
199 if (aSubResult.get())
200 display(aSubResult, false);
207 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
208 if (aShapePtr.get() != NULL) {
209 anAIS = AISObjectPtr(new GeomAPI_AISObject());
210 Handle(AIS_InteractiveObject) anAISPrs =
211 myWorkshop->module()->createPresentation(aResult);
212 if (anAISPrs.IsNull())
213 anAISPrs = new ModuleBase_ResultPrs(aResult);
215 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
216 if (!aShapePrs.IsNull())
217 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
219 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
220 //anAIS->createShape(aShapePtr);
223 #ifdef DEBUG_COMPOSILID_DISPLAY
229 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
234 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
236 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
237 if (!aShapePrs.IsNull()) {
238 TopoDS_Shape aShape = aShapePrs->Shape();
241 TopAbs_ShapeEnum aType = aShape.ShapeType();
242 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
245 // Check that the presentation is not a sketch
246 return theModule->canBeShaded(theAIS);
252 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
253 bool isShading, bool theUpdateViewer)
255 bool aDisplayed = false;
257 Handle(AIS_InteractiveContext) aContext = AISContext();
258 if (aContext.IsNull())
261 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
262 if (!anAISIO.IsNull()) {
263 appendResultObject(theObject, theAIS);
265 bool isCustomized = customizeObject(theObject);
267 int aDispMode = isShading? Shading : Wireframe;
269 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
270 anAISIO->SetDisplayMode(aDispMode);
271 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
273 if (getCallBack()) getCallBack()->Display(anAISIO);
277 emit objectDisplayed(theObject, theAIS);
278 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
286 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
288 bool aErased = false;
289 if (!isVisible(theObject))
292 Handle(AIS_InteractiveContext) aContext = AISContext();
293 if (aContext.IsNull())
296 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
298 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
299 if (!anAIS.IsNull()) {
300 emit beforeObjectErase(theObject, anObject);
301 aContext->Remove(anAIS, false/*update viewer*/);
303 if (getCallBack()) getCallBack()->Remove(anAIS);
308 myResult2AISObjectMap.remove(theObject);
311 std::ostringstream aPtrStr;
312 aPtrStr << theObject.get();
313 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
314 qDebug(getResult2AISObjectMapInfo().c_str());
323 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
325 bool aRedisplayed = false;
326 if (!isVisible(theObject))
329 AISObjectPtr aAISObj = getAISObject(theObject);
330 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
332 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
334 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
336 aRedisplayed = erase(theObject, theUpdateViewer);
339 if (aAIS_Obj != aAISObj) {
340 appendResultObject(theObject, aAIS_Obj);
342 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
345 Handle(AIS_InteractiveContext) aContext = AISContext();
346 if (!aContext.IsNull() && !aAISIO.IsNull()) {
347 // Check that the visualized shape is the same and the redisplay is not necessary
348 // Redisplay of AIS object leads to this object selection compute and the selection
349 // in the browser is lost
350 // this check is not necessary anymore because the selection store/restore is realized
351 // before and after the values modification.
352 // Moreother, this check avoids customize and redisplay presentation if the presentable
353 // parameter is changed.
354 bool isEqualShapes = false;
355 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
356 if (aResult.get() != NULL) {
357 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
358 if (!aShapePrs.IsNull()) {
359 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
360 if (aShapePtr.get()) {
361 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
362 if (!aOldShape.IsNull())
363 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
367 // Customization of presentation
368 bool isCustomized = customizeObject(theObject);
369 #ifdef DEBUG_FEATURE_REDISPLAY
370 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
371 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
372 .arg(isCustomized).toStdString().c_str());
374 if (!isEqualShapes || isCustomized) {
375 /// if shapes are equal and presentation are customized, selection should be restored
376 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
377 if (aNeedToRestoreSelection)
378 myWorkshop->module()->storeSelection();
380 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
381 deselectPresentation(aAISIO, aContext);
383 aContext->Redisplay(aAISIO, false);
386 if (getCallBack()) getCallBack()->Redisplay(aAISIO);
389 if (aNeedToRestoreSelection)
390 myWorkshop->module()->restoreSelection();
393 #ifdef DEBUG_FEATURE_REDISPLAY
394 qDebug(" Redisplay happens");
403 void XGUI_Displayer::redisplayObjects()
405 // redisplay objects visualized in the viewer
406 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
407 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
408 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
409 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
410 for (; anIt != aLast; anIt++) {
411 aECreator->sendUpdated(*anIt, EVENT_DISP);
413 Events_Loop::loop()->flush(EVENT_DISP);
416 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
418 #ifdef DEBUG_DEACTIVATE
419 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
420 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
421 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
423 toStdString().c_str());
425 Handle(AIS_InteractiveContext) aContext = AISContext();
426 if (!aContext.IsNull() && isVisible(theObject)) {
427 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
428 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
430 deactivateAIS(anAIS);
431 // the selection from the previous activation modes should be cleared manually (#26172)
432 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
433 deselectPresentation(anAIS, aContext);
440 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
441 const bool theUpdateViewer)
443 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
444 //if (!aTrihedron.IsNull())
445 // deactivateAIS(aTrihedron);
447 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
448 for (; anIt != aLast; anIt++) {
449 deactivate(*anIt, false);
451 //VSV It seems that there is no necessity to update viewer on deactivation
452 //if (theUpdateViewer)
456 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
458 Handle(AIS_InteractiveContext) aContext = AISContext();
459 if (aContext.IsNull() || !isVisible(theObject))
462 AISObjectPtr aAISObj = getAISObject(theObject);
464 if (aAISObj.get() != NULL) {
465 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
466 TColStd_ListOfInteger aTColModes;
467 aContext->ActivatedModes(anAISIO, aTColModes);
468 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
469 for (; itr.More(); itr.Next() ) {
470 theModes.append(itr.Value());
475 int XGUI_Displayer::getSelectionMode(int theShapeType)
477 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
478 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
481 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
483 bool aVisible = false;
484 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
485 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
486 if (aPrs.get() || aResult.get()) {
487 aVisible = theDisplayer->isVisible(theObject);
488 // compsolid is not visualized in the viewer,
489 // but should have presentation when all sub solids are
490 // visible. It is useful for highlight presentation where compsolid shape is selectable
491 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
492 ResultCompSolidPtr aCompsolidResult =
493 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
494 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
495 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
496 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
497 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
499 aVisible = anAllSubsVisible;
503 // it is possible that feature is presentable and has results, so we should check visibility
504 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
506 // check if all results of the feature are visible
507 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
508 std::list<ResultPtr> aResults;
509 ModelAPI_Tools::allResults(aFeature, aResults);
510 std::list<ResultPtr>::const_iterator aIt;
511 aVisible = !aResults.empty();
512 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
513 aVisible = aVisible && theDisplayer->isVisible(*aIt);
519 #ifdef DEBUG_ACTIVATE_OBJECTS
520 QString getModeInfo(const int theMode)
522 QString anInfo = "Undefined";
524 case 0: anInfo = "SHAPE(0)"; break;
525 case 1: anInfo = "VERTEX(1)"; break;
526 case 2: anInfo = "EDGE(2)"; break;
527 case 3: anInfo = "WIRE(3)"; break;
528 case 4: anInfo = "FACE(4)"; break;
529 case 5: anInfo = "SHELL(5)"; break;
530 case 6: anInfo = "SOLID(6)"; break;
531 case 7: anInfo = "COMPSOLID(7)"; break;
532 case 8: anInfo = "COMPOUND(8)"; break;
533 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
534 case 101: anInfo = "Sel_Constraint(101)"; break;
535 case 102: anInfo = "Sel_Dimension_All(102)"; break;
536 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
537 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
543 QString getModesInfo(const QIntList& theModes)
545 QStringList aModesInfo;
546 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
547 aModesInfo.append(getModeInfo(theModes[i]));
548 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
552 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
553 const bool theUpdateViewer)
555 // Convert shape types to selection types
557 foreach(int aType, theModes) {
558 aModes.append(getSelectionMode(aType));
561 #ifdef DEBUG_ACTIVATE_OBJECTS
563 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
564 for (; anIt != aLast; ++anIt) {
565 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
567 QString anInfoStr = anInfo.join(", ");
569 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
570 arg(getModesInfo(aModes)).
571 arg(getModesInfo(myActiveSelectionModes)).
572 arg(theObjList.size()).
574 toStdString().c_str());
576 // In order to avoid doblications of selection modes
578 foreach (int aMode, aModes) {
579 if (!aNewModes.contains(aMode))
580 aNewModes.append(aMode);
582 myActiveSelectionModes = aNewModes;
583 Handle(AIS_InteractiveContext) aContext = AISContext();
584 // Open local context if there is no one
585 if (aContext.IsNull())
588 //aContext->UseDisplayedObjects();
589 //myUseExternalObjects = true;
591 Handle(AIS_InteractiveObject) anAISIO;
592 AIS_ListOfInteractive aPrsList;
593 //if (aObjList.isEmpty())
596 foreach(ObjectPtr aObj, theObjList) {
597 if (myResult2AISObjectMap.contains(aObj))
598 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
602 // Add trihedron because it has to partisipate in selection
603 Handle(AIS_InteractiveObject) aTrihedron;
604 if (isTrihedronActive()) {
605 aTrihedron = getTrihedron();
606 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
607 aPrsList.Append(aTrihedron);
609 if (aPrsList.Extent() == 0)
612 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
613 bool isActivationChanged = false;
614 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
615 anAISIO = aLIt.Value();
616 if (activate(anAISIO, myActiveSelectionModes, false))
617 isActivationChanged = true;
621 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
623 Handle(AIS_InteractiveContext) aContext = AISContext();
624 if (aContext.IsNull() || !isVisible(theObject))
627 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
628 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
630 TColStd_ListOfInteger aModes;
631 aContext->ActivatedModes(anAIS, aModes);
633 if (getCallBack()) getCallBack()->ActivatedModes(anAIS, aModes);
636 return aModes.Extent() > 0;
640 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
641 bool theUpdateViewer)
643 Handle(AIS_InteractiveContext) aContext = AISContext();
644 if (aContext.IsNull())
646 aContext->UnhilightSelected(false);
647 aContext->ClearSelected(false);
649 if (getCallBack()) getCallBack()->ClearSelected();
651 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
654 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
655 const GeomShapePtr& aGeomShape = aPrs->shape();
656 if (aGeomShape.get() && !aGeomShape->isNull()) {
657 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
658 #ifdef DEBUG_OCCT_SHAPE_SELECTION
659 // problem 1: performance
660 // problem 2: IO is not specified, so the first found owner is selected, as a result
661 // it might belong to another result
662 aContext->AddOrRemoveSelected(aShape, false);
664 if (getCallBack()) getCallBack()->AddOrRemoveSelected(aShape);
667 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
668 if (aShapesToBeSelected.IsBound(aShape))
669 aPresentations = aShapesToBeSelected.Find(aShape);
670 ObjectPtr anObject = aPrs->object();
671 getPresentations(anObject, aPresentations);
673 aShapesToBeSelected.Bind(aShape, aPresentations);
676 ObjectPtr anObject = aPrs->object();
677 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
678 if (aResult.get() && isVisible(aResult)) {
679 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
680 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
681 if (!anAIS.IsNull()) {
682 // The methods are replaced in order to provide multi-selection, e.g. restore selection
683 // by activating multi selector widget. It also gives an advantage that the multi
684 // selection in OB gives multi-selection in the viewer
685 //aContext->SetSelected(anAIS, false);
686 // The selection in the context was cleared, so the method sets the objects are selected
687 aContext->AddOrRemoveSelected(anAIS, false);
689 if (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
695 if (!aShapesToBeSelected.IsEmpty())
696 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
702 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
704 Handle(AIS_InteractiveContext) aContext = AISContext();
705 if (!aContext.IsNull()) {
706 aContext->UnhilightCurrents(false);
707 aContext->ClearSelected(theUpdateViewer);
709 if (getCallBack()) getCallBack()->ClearSelected();
714 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
716 bool aErased = false;
717 Handle(AIS_InteractiveContext) aContext = AISContext();
718 if (!aContext.IsNull()) {
719 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
720 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
722 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
723 if (!anIO.IsNull()) {
724 emit beforeObjectErase(aObj, aAISObj);
725 aContext->Remove(anIO, false/*update viewer*/);
727 if (getCallBack()) getCallBack()->Remove(anIO);
735 myResult2AISObjectMap.clear();
738 qDebug(getResult2AISObjectMapInfo().c_str());
743 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
744 Handle(AIS_InteractiveObject) theObject
746 , VInspectorAPI_CallBack* theCallBack
750 if (!theObject.IsNull()) {
751 theContext->Deactivate(theObject);
753 if (theCallBack) theCallBack->Deactivate(theObject);
758 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
760 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
761 Handle(AIS_InteractiveContext) aContext = AISContext();
762 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
763 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
764 deactivateObject(aContext, aTrie
770 /// #1136 hidden axis are selected in sketch
771 deactivateObject(aContext, aTrie->XAxis()
776 deactivateObject(aContext, aTrie->YAxis()
781 deactivateObject(aContext, aTrie->Axis()
786 deactivateObject(aContext, aTrie->Position()
792 deactivateObject(aContext, aTrie->XYPlane()
797 deactivateObject(aContext, aTrie->XZPlane()
802 deactivateObject(aContext, aTrie->YZPlane()
813 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
815 return myWorkshop->viewer()->trihedron();
818 /*void XGUI_Displayer::openLocalContext()
820 Handle(AIS_InteractiveContext) aContext = AISContext();
821 // Open local context if there is no one
822 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
823 // Preserve selected objects
824 //AIS_ListOfInteractive aAisList;
825 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
826 // aAisList.Append(aContext->Current());
828 // get the filters from the global context and append them to the local context
829 // a list of filters in the global context is not cleared and should be cleared here
830 SelectMgr_ListOfFilter aFilters;
831 aFilters.Assign(aContext->Filters());
832 // it is important to remove the filters in the global context, because there is a code
833 // in the closeLocalContex, which restore the global context filters
834 aContext->RemoveFilters();
836 //aContext->ClearCurrents();
837 aContext->OpenLocalContext();
838 //deactivateTrihedron();
839 //aContext->NotUseDisplayedObjects();
841 //myUseExternalObjects = false;
843 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
844 for (;aIt.More(); aIt.Next()) {
845 aContext->AddFilter(aIt.Value());
848 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
849 //for(; aIt2.More(); aIt2.Next()) {
850 // aContext->SetSelected(aIt2.Value(), false);
855 /*void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
857 Handle(AIS_InteractiveContext) aContext = AISContext();
858 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
859 // Preserve selected objects
860 //AIS_ListOfInteractive aAisList;
861 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
862 // aAisList.Append(aContext->SelectedInteractive());
864 // get the filters from the local context and append them to the global context
865 // a list of filters in the local context is cleared
866 SelectMgr_ListOfFilter aFilters;
867 aFilters.Assign(aContext->Filters());
869 //aContext->ClearSelected();
870 aContext->CloseAllContexts(false);
872 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
873 // this code is obsolete. It is temporaty commented and should be removed after
874 // the test campaign.
875 // Redisplay all object if they were displayed in localContext
876 /*Handle(AIS_InteractiveObject) aAISIO;
877 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
878 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
879 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
880 aContext->Display(aAISIO, false);
881 aContext->SetDisplayMode(aAISIO, Shading, false);
885 // Append the filters from the local selection in the global selection context
886 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
887 for (;aIt.More(); aIt.Next()) {
888 Handle(SelectMgr_Filter) aFilter = aIt.Value();
889 aContext->AddFilter(aFilter);
894 //myUseExternalObjects = false;
897 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
898 //for(; aIt2.More(); aIt2.Next()) {
899 // if (aContext->IsDisplayed(aIt2.Value()))
900 // aContext->SetCurrentObject(aIt2.Value(), false);
905 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
908 if (myResult2AISObjectMap.contains(theObject))
909 anIO = myResult2AISObjectMap[theObject];
913 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
915 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
916 return getObject(aRefAIS);
919 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
922 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
923 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
924 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
930 if (!anObject.get()) {
931 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
932 if (!theIO.IsNull()) {
933 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
935 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
940 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
942 bool aWasEnabled = isUpdateEnabled();
944 myViewerBlockedRecursiveCount--;
946 myViewerBlockedRecursiveCount++;
948 if (myNeedUpdate && isUpdateEnabled()) {
950 myNeedUpdate = false;
955 bool XGUI_Displayer::isUpdateEnabled() const
957 return myViewerBlockedRecursiveCount == 0;
960 void XGUI_Displayer::updateViewer() const
962 Handle(AIS_InteractiveContext) aContext = AISContext();
963 if (!aContext.IsNull() && isUpdateEnabled()) {
964 //myWorkshop->viewer()->Zfitall();
965 aContext->UpdateCurrentViewer();
971 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
972 const int theMode, const bool theUpdateViewer) const
974 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
975 if (!theIO.IsNull() && theIO == getTrihedron()) {
976 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
977 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
980 if (!aContext.IsNull()) {
981 if (myWorkshop->module()) {
982 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
983 aContext->Activate(theIO, theMode, false);
985 aContext->Activate(theIO, theMode, false);
987 if (getCallBack()) getCallBack()->Activate(theIO, theMode);
990 // the fix from VPA for more suitable selection of sketcher lines
991 if (theIO->Width() > 1) {
992 double aPrecision = theIO->Width() + 2;
993 if (theMode == getSelectionMode(TopAbs_VERTEX))
994 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
995 "point-selection-sensitivity",
997 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
998 (theMode == getSelectionMode(TopAbs_WIRE)))
999 aPrecision = theIO->Width() +
1000 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1001 "edge-selection-sensitivity", 2);
1002 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
1005 #ifdef DEBUG_ACTIVATE_AIS
1006 ObjectPtr anObject = getObject(theIO);
1007 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1008 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1009 .arg(anInfo).toStdString().c_str());
1011 if (theUpdateViewer)
1016 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1017 const int theMode) const
1019 Handle(AIS_InteractiveContext) aContext = AISContext();
1020 if (!aContext.IsNull()) {
1021 if (theMode == -1) {
1022 aContext->Deactivate(theIO);
1024 if (getCallBack()) getCallBack()->Deactivate(theIO);
1028 aContext->Deactivate(theIO, theMode);
1030 if (getCallBack()) getCallBack()->Deactivate(theIO, theMode);
1034 #ifdef DEBUG_DEACTIVATE_AIS
1035 ObjectPtr anObject = getObject(theIO);
1036 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1037 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1038 .arg(anInfo).toStdString().c_str());
1043 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1045 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1046 if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
1048 if (VInspector_FirstCall) {
1049 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1050 VInspectorAPI_Communicator* aCommunicator = VInspectorAPI_PluginMgr::activateVInspector(
1051 "VInspector.dll", aContext);
1052 aDisplayer->setCommunicator(aCommunicator);
1054 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
1056 aViewer->setCallBack(aCommunicator->getCallBack());
1058 VInspector_FirstCall = false;
1061 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1062 aDisplayer->myIsFirstAISContextUse = false;
1063 //aContext->OpenLocalContext();
1064 if (!isTrihedronActive())
1065 deactivateTrihedron(true);
1066 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1067 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1072 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1074 Handle(AIS_InteractiveContext) aContext = AISContext();
1075 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1076 myAndFilter = new SelectMgr_AndFilter();
1077 aContext->AddFilter(myAndFilter);
1082 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1083 bool theUpdateViewer)
1085 bool aDisplayed = false;
1086 Handle(AIS_InteractiveContext) aContext = AISContext();
1087 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1088 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1089 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1091 if (getCallBack()) getCallBack()->Display(anAISIO);
1094 aContext->Deactivate(anAISIO);
1096 if (getCallBack()) getCallBack()->Deactivate(anAISIO);
1098 aContext->Load(anAISIO);
1100 if (getCallBack()) getCallBack()->Load(anAISIO);
1102 if (toActivateInSelectionModes) {
1103 if (myActiveSelectionModes.size() == 0)
1104 activateAIS(anAISIO, 0, theUpdateViewer);
1106 foreach(int aMode, myActiveSelectionModes) {
1107 activateAIS(anAISIO, aMode, theUpdateViewer);
1111 if (theUpdateViewer)
1117 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1119 bool aErased = false;
1120 Handle(AIS_InteractiveContext) aContext = AISContext();
1121 if (!aContext.IsNull()) {
1122 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1123 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1124 aContext->Remove(anAISIO, false/*update viewer*/);
1126 if (getCallBack()) getCallBack()->Remove(anAISIO);
1131 if (aErased && theUpdateViewer)
1137 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1139 if (theMode == NoMode)
1142 Handle(AIS_InteractiveContext) aContext = AISContext();
1143 if (aContext.IsNull())
1146 AISObjectPtr aAISObj = getAISObject(theObject);
1150 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1151 aContext->SetDisplayMode(aAISIO, theMode, false);
1152 // Redisplay in order to update new mode because it could be not computed before
1153 if (theUpdateViewer)
1157 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1159 Handle(AIS_InteractiveContext) aContext = AISContext();
1160 if (aContext.IsNull())
1163 AISObjectPtr aAISObj = getAISObject(theObject);
1167 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1168 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1171 void XGUI_Displayer::deactivateSelectionFilters()
1173 Handle(AIS_InteractiveContext) aContext = AISContext();
1174 if (!myAndFilter.IsNull()) {
1175 bool aFound = false;
1176 if (!aContext.IsNull()) {
1177 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1178 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1179 for (; anIt.More() && !aFound; anIt.Next()) {
1180 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1181 aFound = aFilter == myAndFilter;
1184 aContext->RemoveFilter(myAndFilter);
1186 myAndFilter.Nullify();
1190 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1192 Handle(AIS_InteractiveContext) aContext = AISContext();
1193 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1196 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1197 if (!aCompositeFilter.IsNull()) {
1198 aCompositeFilter->Add(theFilter);
1199 #ifdef DEBUG_SELECTION_FILTERS
1200 int aCount = aCompositeFilter->StoredFilters().Extent();
1201 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1206 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1208 Handle(AIS_InteractiveContext) aContext = AISContext();
1209 if (aContext.IsNull())
1212 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1213 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1214 aCompositeFilter->Remove(theFilter);
1215 #ifdef DEBUG_SELECTION_FILTERS
1216 int aCount = aCompositeFilter->StoredFilters().Extent();
1217 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1218 .arg(aCount).toStdString().c_str());
1223 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1225 bool aFilterFound = false;
1227 Handle(AIS_InteractiveContext) aContext = AISContext();
1228 if (aContext.IsNull())
1229 return aFilterFound;
1230 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1231 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1232 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1233 if (theFilter.get() == aIt.Value().get())
1234 aFilterFound = true;
1236 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1237 if (!aCompositeFilter.IsNull()) {
1238 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1239 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1240 if (theFilter.get() == aIt.Value().get())
1241 aFilterFound = true;
1244 return aFilterFound;
1247 void XGUI_Displayer::removeFilters()
1249 Handle(AIS_InteractiveContext) aContext = AISContext();
1250 if (aContext.IsNull())
1253 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1254 if (!aCompositeFilter.IsNull())
1255 aCompositeFilter->Clear();
1258 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1260 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1261 foreach(ObjectPtr aObj, aDispList) {
1262 if (!theList.contains(aObj))
1265 foreach(ObjectPtr aObj, theList) {
1266 if (!isVisible(aObj))
1267 display(aObj, false);
1272 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1274 if (!isVisible(theObject))
1277 AISObjectPtr aAISObj = getAISObject(theObject);
1278 if (aAISObj.get() == NULL)
1281 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1282 return ::canBeShaded(anAIS, myWorkshop->module());
1285 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1286 const QIntList& theModes,
1287 const bool theUpdateViewer) const
1289 Handle(AIS_InteractiveContext) aContext = AISContext();
1290 if (aContext.IsNull() || theIO.IsNull())
1293 bool isActivationChanged = false;
1294 // deactivate object in all modes, which are not in the list of activation
1295 // It seems that after the IO deactivation the selected state of the IO's owners
1296 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1297 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1298 // only if there is a difference in the current modes and the parameters modes.
1299 // If the selection problem happens again, it is possible to write a test scenario and create
1300 // a bug. The bug steps are the following:
1301 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1302 // with clicked SHIFT select the second object.
1303 // The result is the selection of the first IO is lost.
1304 TColStd_ListOfInteger aTColModes;
1305 aContext->ActivatedModes(theIO, aTColModes);
1307 if (getCallBack()) getCallBack()->ActivatedModes(theIO, aTColModes);
1309 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1310 QIntList aModesActivatedForIO;
1311 bool isDeactivated = false;
1312 bool aHasValidMode = false;
1313 for (; itr.More(); itr.Next() ) {
1314 Standard_Integer aMode = itr.Value();
1315 aHasValidMode = aHasValidMode || aMode != -1;
1316 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1317 if (!theModes.contains(aMode)) {
1318 deactivateAIS(theIO, aMode);
1319 isDeactivated = true;
1322 aModesActivatedForIO.append(aMode);
1325 if (isDeactivated) {
1326 // the selection from the previous activation modes should be cleared manually (#26172)
1327 //theIO->ClearSelected();
1329 //if (getCallBack()) getCallBack()->ClearSelected(theIO);
1331 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
1332 deselectPresentation(theIO, aContext);
1334 // For performance issues
1335 //if (theUpdateViewer)
1337 isActivationChanged = true;
1340 // loading the interactive object allowing the decomposition
1341 if (aTColModes.IsEmpty() || !aHasValidMode) {
1342 aContext->Load(theIO, -1, true);
1343 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1344 if (!aTrihedron.IsNull()) {
1345 // Workaround for Trihedron. It should be loaded using the next Load method to
1346 // add this object to myGlobal map of selection manager
1347 // it is important to activate trihedron in two selection modes: edges and vertices
1348 aContext->SelectionManager()->Load(theIO);
1352 if (getCallBack()) getCallBack()->Load(theIO);
1356 // trihedron AIS check should be after the AIS loading.
1357 // If it is not loaded, it is steel selectable in the viewer.
1358 Handle(AIS_Trihedron) aTrihedron;
1359 if (!isTrihedronActive())
1360 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1361 if (aTrihedron.IsNull()) {
1362 // In order to clear active modes list
1363 if (theModes.size() == 0) {
1364 activateAIS(theIO, 0, theUpdateViewer);
1366 foreach(int aMode, theModes) {
1367 if (!aModesActivatedForIO.contains(aMode)) {
1368 activateAIS(theIO, aMode, theUpdateViewer);
1369 isActivationChanged = true;
1374 return isActivationChanged;
1377 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1379 AISObjectPtr anAISObj = getAISObject(theObject);
1380 // correct the result's color it it has the attribute
1381 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1383 // Customization of presentation
1384 GeomCustomPrsPtr aCustomPrs;
1385 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1386 if (aFeature.get() != NULL) {
1387 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1388 if (aCustPrs.get() != NULL)
1389 aCustomPrs = aCustPrs;
1391 if (aCustomPrs.get() == NULL) {
1392 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1393 // we ignore presentable not customized objects
1394 if (aPrs.get() == NULL)
1395 aCustomPrs = myCustomPrs;
1397 bool isCustomized = aCustomPrs.get() &&
1398 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1399 return isCustomized;
1403 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1404 const QColor& theColor,
1405 bool theUpdateViewer)
1407 if (!isVisible(theObject))
1410 AISObjectPtr anAISObj = getAISObject(theObject);
1412 anAISObj->getColor(aR, aG, aB);
1413 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1414 if (theUpdateViewer)
1416 return QColor(aR, aG, aB);
1419 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1421 myResult2AISObjectMap[theObject] = theAIS;
1423 #ifdef DEBUG_DISPLAY
1424 std::ostringstream aPtrStr;
1425 aPtrStr << theObject.get();
1426 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1427 qDebug(getResult2AISObjectMapInfo().c_str());
1432 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1434 QStringList aContent;
1435 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1436 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1437 std::ostringstream aPtrStr;
1438 aPtrStr << "aObj = " << aObj.get() << ":";
1439 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1440 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1442 aContent.append(aPtrStr.str().c_str());
1444 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1445 arg(aContent.join("\n")).toStdString().c_str();
1449 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1450 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1452 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1453 if (aResult.get()) {
1454 AISObjectPtr aAISObj = getAISObject(aResult);
1455 if (aAISObj.get() != NULL) {
1456 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1457 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1458 thePresentations.Add(anAIS);
1462 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1463 // find presentation of the feature
1464 AISObjectPtr aAISObj = getAISObject(aFeature);
1465 if (aAISObj.get() != NULL) {
1466 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1467 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1468 thePresentations.Add(anAIS);
1470 // find presentations of the feature results
1471 std::list<ResultPtr> aResults;
1472 ModelAPI_Tools::allResults(aFeature, aResults);
1473 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1474 for (; anIt != aLast; ++anIt) {
1475 AISObjectPtr aAISObj = getAISObject(*anIt);
1476 if (aAISObj.get() != NULL) {
1477 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1478 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1479 thePresentations.Add(anAIS);
1485 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1487 myIsTrihedronActive = theIsActive;
1488 if (!myIsTrihedronActive) {
1489 deactivateTrihedron(true);
1493 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1495 Handle(AIS_InteractiveContext) aContext = AISContext();
1496 if (aContext.IsNull())
1499 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1502 if (!aContext->IsDisplayed(aTrihedron))
1503 aContext->Display(aTrihedron,
1505 -1 /* selection mode */,
1506 Standard_True /* update viewer*/,
1507 Standard_False /* allow decomposition */,
1508 AIS_DS_Displayed /* xdisplay status */);
1510 if (getCallBack()) getCallBack()->Display(aTrihedron);
1513 if (!isTrihedronActive())
1514 deactivateTrihedron(false);
1516 activate(aTrihedron, myActiveSelectionModes, false);
1518 deactivateTrihedron(false);
1520 aContext->Erase(aTrihedron);
1522 if (getCallBack()) getCallBack()->Remove(aTrihedron);
1529 QIntList XGUI_Displayer::activeSelectionModes() const
1532 foreach (int aMode, myActiveSelectionModes) {
1533 // aMode < 9 is a Shape Enum values
1534 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1540 void XGUI_Displayer::setCommunicator(VInspectorAPI_Communicator* theCommunicator)
1542 myCommunicator = theCommunicator;
1545 void XGUI_Displayer::setVInspectorVisible(const bool theVisible)
1548 myCommunicator->setVisible(true);
1551 VInspectorAPI_CallBack* XGUI_Displayer::getCallBack() const
1553 return myCommunicator ? myCommunicator->getCallBack() : NULL;
1557 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1558 const NCollection_DataMap<TopoDS_Shape,
1559 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1561 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1562 theContext->MainSelector()->ActiveOwners(anActiveOwners);
1563 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1564 Handle(SelectMgr_EntityOwner) anOwner;
1566 /// It is very important to check that the owner is processed only once and has a map of
1567 /// processed owners because SetSelected works as a switch.
1568 /// If count of calls setSelectec is even, the object stays in the previous state
1569 /// (selected, deselected)
1570 /// OCCT: to write about the problem that active owners method returns one owner several times
1571 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1572 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1573 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1574 if (aSelectedIds.contains((long)anOwner.get()))
1576 aSelectedIds.append((long)anOwner.get());
1578 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1579 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1580 const TopoDS_Shape& aShape = BROwnr->Shape();
1581 if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
1582 Handle(AIS_InteractiveObject) anOwnerPresentation =
1583 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1584 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1585 theShapesToBeSelected.Find(aShape);
1586 if (aPresentations.Contains(anOwnerPresentation)) {
1587 theContext->AddOrRemoveSelected(anOwner);
1588 anOwner->SetSelected (Standard_True);