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 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
96 // Get from null point
97 theAIS->DisplayedObjects(theList, true);
100 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
103 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
104 for (; anIt != aLast; anIt++) {
105 anInfo.append(QString::number(*anIt));
107 return anInfo.join(theSeparator);
110 void deselectPresentation(const Handle(AIS_InteractiveObject) theObject,
111 const Handle(AIS_InteractiveContext)& theContext)
113 NCollection_List<Handle(SelectBasics_EntityOwner)> aResultOwners;
115 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
116 Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
117 if (anOwner.IsNull()) // TODO: check why it is possible
119 if (anOwner->Selectable() == theObject && anOwner->IsSelected())
120 aResultOwners.Append(anOwner);
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 deselectPresentation(aAISIO, aContext);
381 aContext->Redisplay(aAISIO, false);
384 if (getCallBack()) getCallBack()->Redisplay(aAISIO);
387 if (aNeedToRestoreSelection)
388 myWorkshop->module()->restoreSelection();
391 #ifdef DEBUG_FEATURE_REDISPLAY
392 qDebug(" Redisplay happens");
401 void XGUI_Displayer::redisplayObjects()
403 // redisplay objects visualized in the viewer
404 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
405 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
406 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
407 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
408 for (; anIt != aLast; anIt++) {
409 aECreator->sendUpdated(*anIt, EVENT_DISP);
411 Events_Loop::loop()->flush(EVENT_DISP);
414 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
416 #ifdef DEBUG_DEACTIVATE
417 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
418 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
419 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
421 toStdString().c_str());
423 Handle(AIS_InteractiveContext) aContext = AISContext();
424 if (!aContext.IsNull() && isVisible(theObject)) {
425 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
426 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
428 deactivateAIS(anAIS);
434 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
435 const bool theUpdateViewer)
437 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
438 //if (!aTrihedron.IsNull())
439 // deactivateAIS(aTrihedron);
441 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
442 for (; anIt != aLast; anIt++) {
443 deactivate(*anIt, false);
445 //VSV It seems that there is no necessity to update viewer on deactivation
446 //if (theUpdateViewer)
450 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
452 Handle(AIS_InteractiveContext) aContext = AISContext();
453 if (aContext.IsNull() || !isVisible(theObject))
456 AISObjectPtr aAISObj = getAISObject(theObject);
458 if (aAISObj.get() != NULL) {
459 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
460 TColStd_ListOfInteger aTColModes;
461 aContext->ActivatedModes(anAISIO, aTColModes);
462 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
463 for (; itr.More(); itr.Next() ) {
464 theModes.append(itr.Value());
469 int XGUI_Displayer::getSelectionMode(int theShapeType)
471 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
472 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
475 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
477 bool aVisible = false;
478 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
479 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
480 if (aPrs.get() || aResult.get()) {
481 aVisible = theDisplayer->isVisible(theObject);
482 // compsolid is not visualized in the viewer,
483 // but should have presentation when all sub solids are
484 // visible. It is useful for highlight presentation where compsolid shape is selectable
485 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
486 ResultCompSolidPtr aCompsolidResult =
487 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
488 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
489 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
490 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
491 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
493 aVisible = anAllSubsVisible;
497 // it is possible that feature is presentable and has results, so we should check visibility
498 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
500 // check if all results of the feature are visible
501 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
502 std::list<ResultPtr> aResults;
503 ModelAPI_Tools::allResults(aFeature, aResults);
504 std::list<ResultPtr>::const_iterator aIt;
505 aVisible = !aResults.empty();
506 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
507 aVisible = aVisible && theDisplayer->isVisible(*aIt);
513 #ifdef DEBUG_ACTIVATE_OBJECTS
514 QString getModeInfo(const int theMode)
516 QString anInfo = "Undefined";
518 case 0: anInfo = "SHAPE(0)"; break;
519 case 1: anInfo = "VERTEX(1)"; break;
520 case 2: anInfo = "EDGE(2)"; break;
521 case 3: anInfo = "WIRE(3)"; break;
522 case 4: anInfo = "FACE(4)"; break;
523 case 5: anInfo = "SHELL(5)"; break;
524 case 6: anInfo = "SOLID(6)"; break;
525 case 7: anInfo = "COMPSOLID(7)"; break;
526 case 8: anInfo = "COMPOUND(8)"; break;
527 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
528 case 101: anInfo = "Sel_Constraint(101)"; break;
529 case 102: anInfo = "Sel_Dimension_All(102)"; break;
530 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
531 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
537 QString getModesInfo(const QIntList& theModes)
539 QStringList aModesInfo;
540 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
541 aModesInfo.append(getModeInfo(theModes[i]));
542 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
546 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
547 const bool theUpdateViewer)
549 // Convert shape types to selection types
551 foreach(int aType, theModes) {
552 aModes.append(getSelectionMode(aType));
555 #ifdef DEBUG_ACTIVATE_OBJECTS
557 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
558 for (; anIt != aLast; ++anIt) {
559 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
561 QString anInfoStr = anInfo.join(", ");
563 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
564 arg(getModesInfo(aModes)).
565 arg(getModesInfo(myActiveSelectionModes)).
566 arg(theObjList.size()).
568 toStdString().c_str());
570 // In order to avoid doblications of selection modes
572 foreach (int aMode, aModes) {
573 if (!aNewModes.contains(aMode))
574 aNewModes.append(aMode);
576 myActiveSelectionModes = aNewModes;
577 Handle(AIS_InteractiveContext) aContext = AISContext();
578 // Open local context if there is no one
579 if (aContext.IsNull())
582 //aContext->UseDisplayedObjects();
583 //myUseExternalObjects = true;
585 Handle(AIS_InteractiveObject) anAISIO;
586 AIS_ListOfInteractive aPrsList;
587 //if (aObjList.isEmpty())
590 foreach(ObjectPtr aObj, theObjList) {
591 if (myResult2AISObjectMap.contains(aObj))
592 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
596 // Add trihedron because it has to partisipate in selection
597 Handle(AIS_InteractiveObject) aTrihedron;
598 if (isTrihedronActive()) {
599 aTrihedron = getTrihedron();
600 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
601 aPrsList.Append(aTrihedron);
603 if (aPrsList.Extent() == 0)
606 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
607 bool isActivationChanged = false;
608 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
609 anAISIO = aLIt.Value();
610 if (activate(anAISIO, myActiveSelectionModes, false))
611 isActivationChanged = true;
615 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
617 Handle(AIS_InteractiveContext) aContext = AISContext();
618 if (aContext.IsNull() || !isVisible(theObject))
621 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
622 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
624 TColStd_ListOfInteger aModes;
625 aContext->ActivatedModes(anAIS, aModes);
627 if (getCallBack()) getCallBack()->ActivatedModes(anAIS, aModes);
630 return aModes.Extent() > 0;
634 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
635 bool theUpdateViewer)
637 Handle(AIS_InteractiveContext) aContext = AISContext();
638 if (aContext.IsNull())
640 aContext->UnhilightSelected(false);
641 aContext->ClearSelected(false);
643 if (getCallBack()) getCallBack()->ClearSelected();
645 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
648 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
649 const GeomShapePtr& aGeomShape = aPrs->shape();
650 if (aGeomShape.get() && !aGeomShape->isNull()) {
651 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
652 #ifdef DEBUG_OCCT_SHAPE_SELECTION
653 // problem 1: performance
654 // problem 2: IO is not specified, so the first found owner is selected, as a result
655 // it might belong to another result
656 aContext->AddOrRemoveSelected(aShape, false);
658 if (getCallBack()) getCallBack()->AddOrRemoveSelected(aShape);
661 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
662 if (aShapesToBeSelected.IsBound(aShape))
663 aPresentations = aShapesToBeSelected.Find(aShape);
664 ObjectPtr anObject = aPrs->object();
665 getPresentations(anObject, aPresentations);
667 aShapesToBeSelected.Bind(aShape, aPresentations);
670 ObjectPtr anObject = aPrs->object();
671 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
672 if (aResult.get() && isVisible(aResult)) {
673 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
674 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
675 if (!anAIS.IsNull()) {
676 // The methods are replaced in order to provide multi-selection, e.g. restore selection
677 // by activating multi selector widget. It also gives an advantage that the multi
678 // selection in OB gives multi-selection in the viewer
679 //aContext->SetSelected(anAIS, false);
680 // The selection in the context was cleared, so the method sets the objects are selected
681 aContext->AddOrRemoveSelected(anAIS, false);
683 if (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
689 if (!aShapesToBeSelected.IsEmpty())
690 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
696 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
698 Handle(AIS_InteractiveContext) aContext = AISContext();
699 if (!aContext.IsNull()) {
700 aContext->UnhilightCurrents(false);
701 aContext->ClearSelected(theUpdateViewer);
703 if (getCallBack()) getCallBack()->ClearSelected();
708 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
710 bool aErased = false;
711 Handle(AIS_InteractiveContext) aContext = AISContext();
712 if (!aContext.IsNull()) {
713 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
714 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
716 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
717 if (!anIO.IsNull()) {
718 emit beforeObjectErase(aObj, aAISObj);
719 aContext->Remove(anIO, false/*update viewer*/);
721 if (getCallBack()) getCallBack()->Remove(anIO);
729 myResult2AISObjectMap.clear();
732 qDebug(getResult2AISObjectMapInfo().c_str());
737 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
738 Handle(AIS_InteractiveObject) theObject
740 , VInspectorAPI_CallBack* theCallBack
744 if (!theObject.IsNull()) {
745 theContext->Deactivate(theObject);
747 if (theCallBack) theCallBack->Deactivate(theObject);
752 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
754 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
755 Handle(AIS_InteractiveContext) aContext = AISContext();
756 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
757 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
758 deactivateObject(aContext, aTrie
764 /// #1136 hidden axis are selected in sketch
765 deactivateObject(aContext, aTrie->XAxis()
770 deactivateObject(aContext, aTrie->YAxis()
775 deactivateObject(aContext, aTrie->Axis()
780 deactivateObject(aContext, aTrie->Position()
786 deactivateObject(aContext, aTrie->XYPlane()
791 deactivateObject(aContext, aTrie->XZPlane()
796 deactivateObject(aContext, aTrie->YZPlane()
807 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
809 return myWorkshop->viewer()->trihedron();
812 /*void XGUI_Displayer::openLocalContext()
814 Handle(AIS_InteractiveContext) aContext = AISContext();
815 // Open local context if there is no one
816 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
817 // Preserve selected objects
818 //AIS_ListOfInteractive aAisList;
819 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
820 // aAisList.Append(aContext->Current());
822 // get the filters from the global context and append them to the local context
823 // a list of filters in the global context is not cleared and should be cleared here
824 SelectMgr_ListOfFilter aFilters;
825 aFilters.Assign(aContext->Filters());
826 // it is important to remove the filters in the global context, because there is a code
827 // in the closeLocalContex, which restore the global context filters
828 aContext->RemoveFilters();
830 //aContext->ClearCurrents();
831 aContext->OpenLocalContext();
832 //deactivateTrihedron();
833 //aContext->NotUseDisplayedObjects();
835 //myUseExternalObjects = false;
837 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
838 for (;aIt.More(); aIt.Next()) {
839 aContext->AddFilter(aIt.Value());
842 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
843 //for(; aIt2.More(); aIt2.Next()) {
844 // aContext->SetSelected(aIt2.Value(), false);
849 /*void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
851 Handle(AIS_InteractiveContext) aContext = AISContext();
852 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
853 // Preserve selected objects
854 //AIS_ListOfInteractive aAisList;
855 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
856 // aAisList.Append(aContext->SelectedInteractive());
858 // get the filters from the local context and append them to the global context
859 // a list of filters in the local context is cleared
860 SelectMgr_ListOfFilter aFilters;
861 aFilters.Assign(aContext->Filters());
863 //aContext->ClearSelected();
864 aContext->CloseAllContexts(false);
866 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
867 // this code is obsolete. It is temporaty commented and should be removed after
868 // the test campaign.
869 // Redisplay all object if they were displayed in localContext
870 /*Handle(AIS_InteractiveObject) aAISIO;
871 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
872 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
873 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
874 aContext->Display(aAISIO, false);
875 aContext->SetDisplayMode(aAISIO, Shading, false);
879 // Append the filters from the local selection in the global selection context
880 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
881 for (;aIt.More(); aIt.Next()) {
882 Handle(SelectMgr_Filter) aFilter = aIt.Value();
883 aContext->AddFilter(aFilter);
888 //myUseExternalObjects = false;
891 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
892 //for(; aIt2.More(); aIt2.Next()) {
893 // if (aContext->IsDisplayed(aIt2.Value()))
894 // aContext->SetCurrentObject(aIt2.Value(), false);
899 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
902 if (myResult2AISObjectMap.contains(theObject))
903 anIO = myResult2AISObjectMap[theObject];
907 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
909 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
910 return getObject(aRefAIS);
913 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
916 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
917 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
918 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
924 if (!anObject.get()) {
925 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
926 if (!theIO.IsNull()) {
927 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
929 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
934 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
936 bool aWasEnabled = isUpdateEnabled();
938 myViewerBlockedRecursiveCount--;
940 myViewerBlockedRecursiveCount++;
942 if (myNeedUpdate && isUpdateEnabled()) {
944 myNeedUpdate = false;
949 bool XGUI_Displayer::isUpdateEnabled() const
951 return myViewerBlockedRecursiveCount == 0;
954 void XGUI_Displayer::updateViewer() const
956 Handle(AIS_InteractiveContext) aContext = AISContext();
957 if (!aContext.IsNull() && isUpdateEnabled()) {
958 myWorkshop->viewer()->Zfitall();
959 aContext->UpdateCurrentViewer();
965 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
966 const int theMode, const bool theUpdateViewer) const
968 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
969 if (!theIO.IsNull() && theIO == getTrihedron()) {
970 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
971 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
974 if (!aContext.IsNull()) {
975 if (myWorkshop->module()) {
976 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
977 aContext->Activate(theIO, theMode, false);
979 aContext->Activate(theIO, theMode, false);
981 if (getCallBack()) getCallBack()->Activate(theIO, theMode);
984 // the fix from VPA for more suitable selection of sketcher lines
985 if (theIO->Width() > 1) {
986 double aPrecision = theIO->Width() + 2;
987 if (theMode == getSelectionMode(TopAbs_VERTEX))
988 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
989 "point-selection-sensitivity",
991 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
992 (theMode == getSelectionMode(TopAbs_WIRE)))
993 aPrecision = theIO->Width() +
994 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
995 "edge-selection-sensitivity", 2);
996 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
999 #ifdef DEBUG_ACTIVATE_AIS
1000 ObjectPtr anObject = getObject(theIO);
1001 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1002 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1003 .arg(anInfo).toStdString().c_str());
1005 if (theUpdateViewer)
1010 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1011 const int theMode) const
1013 Handle(AIS_InteractiveContext) aContext = AISContext();
1014 if (!aContext.IsNull()) {
1015 if (theMode == -1) {
1016 aContext->Deactivate(theIO);
1018 if (getCallBack()) getCallBack()->Deactivate(theIO);
1022 aContext->Deactivate(theIO, theMode);
1024 if (getCallBack()) getCallBack()->Deactivate(theIO, theMode);
1028 #ifdef DEBUG_DEACTIVATE_AIS
1029 ObjectPtr anObject = getObject(theIO);
1030 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1031 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1032 .arg(anInfo).toStdString().c_str());
1037 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1039 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1040 if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
1042 if (VInspector_FirstCall) {
1043 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1044 VInspectorAPI_Communicator* aCommunicator = VInspectorAPI_PluginMgr::activateVInspector(
1045 "VInspector.dll", aContext);
1046 aDisplayer->setCommunicator(aCommunicator);
1048 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
1050 aViewer->setCallBack(aCommunicator->getCallBack());
1052 VInspector_FirstCall = false;
1055 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1056 aDisplayer->myIsFirstAISContextUse = false;
1057 //aContext->OpenLocalContext();
1058 if (!isTrihedronActive())
1059 deactivateTrihedron(true);
1060 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1061 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1066 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1068 Handle(AIS_InteractiveContext) aContext = AISContext();
1069 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1070 myAndFilter = new SelectMgr_AndFilter();
1071 aContext->AddFilter(myAndFilter);
1076 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1077 bool theUpdateViewer)
1079 bool aDisplayed = false;
1080 Handle(AIS_InteractiveContext) aContext = AISContext();
1081 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1082 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1083 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1085 if (getCallBack()) getCallBack()->Display(anAISIO);
1088 aContext->Deactivate(anAISIO);
1090 if (getCallBack()) getCallBack()->Deactivate(anAISIO);
1092 aContext->Load(anAISIO);
1094 if (getCallBack()) getCallBack()->Load(anAISIO);
1096 if (toActivateInSelectionModes) {
1097 if (myActiveSelectionModes.size() == 0)
1098 activateAIS(anAISIO, 0, theUpdateViewer);
1100 foreach(int aMode, myActiveSelectionModes) {
1101 activateAIS(anAISIO, aMode, theUpdateViewer);
1105 if (theUpdateViewer)
1111 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1113 bool aErased = false;
1114 Handle(AIS_InteractiveContext) aContext = AISContext();
1115 if (!aContext.IsNull()) {
1116 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1117 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1118 aContext->Remove(anAISIO, false/*update viewer*/);
1120 if (getCallBack()) getCallBack()->Remove(anAISIO);
1125 if (aErased && theUpdateViewer)
1131 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1133 if (theMode == NoMode)
1136 Handle(AIS_InteractiveContext) aContext = AISContext();
1137 if (aContext.IsNull())
1140 AISObjectPtr aAISObj = getAISObject(theObject);
1144 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1145 aContext->SetDisplayMode(aAISIO, theMode, false);
1146 // Redisplay in order to update new mode because it could be not computed before
1147 if (theUpdateViewer)
1151 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1153 Handle(AIS_InteractiveContext) aContext = AISContext();
1154 if (aContext.IsNull())
1157 AISObjectPtr aAISObj = getAISObject(theObject);
1161 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1162 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1165 void XGUI_Displayer::deactivateSelectionFilters()
1167 Handle(AIS_InteractiveContext) aContext = AISContext();
1168 if (!myAndFilter.IsNull()) {
1169 bool aFound = false;
1170 if (!aContext.IsNull()) {
1171 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1172 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1173 for (; anIt.More() && !aFound; anIt.Next()) {
1174 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1175 aFound = aFilter == myAndFilter;
1178 aContext->RemoveFilter(myAndFilter);
1180 myAndFilter.Nullify();
1184 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1186 Handle(AIS_InteractiveContext) aContext = AISContext();
1187 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1190 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1191 if (!aCompositeFilter.IsNull()) {
1192 aCompositeFilter->Add(theFilter);
1193 #ifdef DEBUG_SELECTION_FILTERS
1194 int aCount = aCompositeFilter->StoredFilters().Extent();
1195 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1200 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1202 Handle(AIS_InteractiveContext) aContext = AISContext();
1203 if (aContext.IsNull())
1206 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1207 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1208 aCompositeFilter->Remove(theFilter);
1209 #ifdef DEBUG_SELECTION_FILTERS
1210 int aCount = aCompositeFilter->StoredFilters().Extent();
1211 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1212 .arg(aCount).toStdString().c_str());
1217 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1219 bool aFilterFound = false;
1221 Handle(AIS_InteractiveContext) aContext = AISContext();
1222 if (aContext.IsNull())
1223 return aFilterFound;
1224 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1225 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1226 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1227 if (theFilter.get() == aIt.Value().get())
1228 aFilterFound = true;
1230 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1231 if (!aCompositeFilter.IsNull()) {
1232 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1233 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1234 if (theFilter.get() == aIt.Value().get())
1235 aFilterFound = true;
1238 return aFilterFound;
1241 void XGUI_Displayer::removeFilters()
1243 Handle(AIS_InteractiveContext) aContext = AISContext();
1244 if (aContext.IsNull())
1247 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1248 if (!aCompositeFilter.IsNull())
1249 aCompositeFilter->Clear();
1252 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1254 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1255 foreach(ObjectPtr aObj, aDispList) {
1256 if (!theList.contains(aObj))
1259 foreach(ObjectPtr aObj, theList) {
1260 if (!isVisible(aObj))
1261 display(aObj, false);
1266 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1268 if (!isVisible(theObject))
1271 AISObjectPtr aAISObj = getAISObject(theObject);
1272 if (aAISObj.get() == NULL)
1275 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1276 return ::canBeShaded(anAIS, myWorkshop->module());
1279 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1280 const QIntList& theModes,
1281 const bool theUpdateViewer) const
1283 Handle(AIS_InteractiveContext) aContext = AISContext();
1284 if (aContext.IsNull() || theIO.IsNull())
1287 bool isActivationChanged = false;
1288 // deactivate object in all modes, which are not in the list of activation
1289 // It seems that after the IO deactivation the selected state of the IO's owners
1290 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1291 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1292 // only if there is a difference in the current modes and the parameters modes.
1293 // If the selection problem happens again, it is possible to write a test scenario and create
1294 // a bug. The bug steps are the following:
1295 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1296 // with clicked SHIFT select the second object.
1297 // The result is the selection of the first IO is lost.
1298 TColStd_ListOfInteger aTColModes;
1299 aContext->ActivatedModes(theIO, aTColModes);
1301 if (getCallBack()) getCallBack()->ActivatedModes(theIO, aTColModes);
1303 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1304 QIntList aModesActivatedForIO;
1305 bool isDeactivated = false;
1306 bool aHasValidMode = false;
1307 for (; itr.More(); itr.Next() ) {
1308 Standard_Integer aMode = itr.Value();
1309 aHasValidMode = aHasValidMode || aMode != -1;
1310 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1311 if (!theModes.contains(aMode)) {
1312 deactivateAIS(theIO, aMode);
1313 isDeactivated = true;
1316 aModesActivatedForIO.append(aMode);
1319 if (isDeactivated) {
1320 // For performance issues
1321 //if (theUpdateViewer)
1323 isActivationChanged = true;
1326 // loading the interactive object allowing the decomposition
1327 if (aTColModes.IsEmpty() || !aHasValidMode) {
1328 aContext->Load(theIO, -1, true);
1329 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1330 if (!aTrihedron.IsNull()) {
1331 // Workaround for Trihedron. It should be loaded using the next Load method to
1332 // add this object to myGlobal map of selection manager
1333 // it is important to activate trihedron in two selection modes: edges and vertices
1334 aContext->SelectionManager()->Load(theIO);
1338 if (getCallBack()) getCallBack()->Load(theIO);
1342 // trihedron AIS check should be after the AIS loading.
1343 // If it is not loaded, it is steel selectable in the viewer.
1344 Handle(AIS_Trihedron) aTrihedron;
1345 if (!isTrihedronActive())
1346 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1347 if (aTrihedron.IsNull()) {
1348 // In order to clear active modes list
1349 if (theModes.size() == 0) {
1350 activateAIS(theIO, 0, theUpdateViewer);
1352 foreach(int aMode, theModes) {
1353 if (!aModesActivatedForIO.contains(aMode)) {
1354 activateAIS(theIO, aMode, theUpdateViewer);
1355 isActivationChanged = true;
1360 return isActivationChanged;
1363 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1365 AISObjectPtr anAISObj = getAISObject(theObject);
1366 // correct the result's color it it has the attribute
1367 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1369 // Customization of presentation
1370 GeomCustomPrsPtr aCustomPrs;
1371 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1372 if (aFeature.get() != NULL) {
1373 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1374 if (aCustPrs.get() != NULL)
1375 aCustomPrs = aCustPrs;
1377 if (aCustomPrs.get() == NULL) {
1378 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1379 // we ignore presentable not customized objects
1380 if (aPrs.get() == NULL)
1381 aCustomPrs = myCustomPrs;
1383 bool isCustomized = aCustomPrs.get() &&
1384 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1385 return isCustomized;
1389 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1390 const QColor& theColor,
1391 bool theUpdateViewer)
1393 if (!isVisible(theObject))
1396 AISObjectPtr anAISObj = getAISObject(theObject);
1398 anAISObj->getColor(aR, aG, aB);
1399 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1400 if (theUpdateViewer)
1402 return QColor(aR, aG, aB);
1405 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1407 myResult2AISObjectMap[theObject] = theAIS;
1409 #ifdef DEBUG_DISPLAY
1410 std::ostringstream aPtrStr;
1411 aPtrStr << theObject.get();
1412 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1413 qDebug(getResult2AISObjectMapInfo().c_str());
1418 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1420 QStringList aContent;
1421 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1422 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1423 std::ostringstream aPtrStr;
1424 aPtrStr << "aObj = " << aObj.get() << ":";
1425 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1426 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1428 aContent.append(aPtrStr.str().c_str());
1430 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1431 arg(aContent.join("\n")).toStdString().c_str();
1435 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1436 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1438 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1439 if (aResult.get()) {
1440 AISObjectPtr aAISObj = getAISObject(aResult);
1441 if (aAISObj.get() != NULL) {
1442 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1443 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1444 thePresentations.Add(anAIS);
1448 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1449 // find presentation of the feature
1450 AISObjectPtr aAISObj = getAISObject(aFeature);
1451 if (aAISObj.get() != NULL) {
1452 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1453 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1454 thePresentations.Add(anAIS);
1456 // find presentations of the feature results
1457 std::list<ResultPtr> aResults;
1458 ModelAPI_Tools::allResults(aFeature, aResults);
1459 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1460 for (; anIt != aLast; ++anIt) {
1461 AISObjectPtr aAISObj = getAISObject(*anIt);
1462 if (aAISObj.get() != NULL) {
1463 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1464 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1465 thePresentations.Add(anAIS);
1471 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1473 myIsTrihedronActive = theIsActive;
1474 if (!myIsTrihedronActive) {
1475 deactivateTrihedron(true);
1479 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1481 Handle(AIS_InteractiveContext) aContext = AISContext();
1482 if (aContext.IsNull())
1485 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1488 if (!aContext->IsDisplayed(aTrihedron))
1489 aContext->Display(aTrihedron,
1491 -1 /* selection mode */,
1492 Standard_True /* update viewer*/,
1493 Standard_False /* allow decomposition */,
1494 AIS_DS_Displayed /* xdisplay status */);
1496 if (getCallBack()) getCallBack()->Display(aTrihedron);
1499 if (!isTrihedronActive())
1500 deactivateTrihedron(false);
1502 activate(aTrihedron, myActiveSelectionModes, false);
1504 deactivateTrihedron(false);
1506 aContext->Erase(aTrihedron);
1508 if (getCallBack()) getCallBack()->Remove(aTrihedron);
1515 QIntList XGUI_Displayer::activeSelectionModes() const
1518 foreach (int aMode, myActiveSelectionModes) {
1519 // aMode < 9 is a Shape Enum values
1520 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1526 void XGUI_Displayer::setCommunicator(VInspectorAPI_Communicator* theCommunicator)
1528 myCommunicator = theCommunicator;
1531 void XGUI_Displayer::setVInspectorVisible(const bool theVisible)
1534 myCommunicator->setVisible(true);
1537 VInspectorAPI_CallBack* XGUI_Displayer::getCallBack() const
1539 return myCommunicator ? myCommunicator->getCallBack() : NULL;
1543 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1544 const NCollection_DataMap<TopoDS_Shape,
1545 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1547 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1548 theContext->MainSelector()->ActiveOwners(anActiveOwners);
1549 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1550 Handle(SelectMgr_EntityOwner) anOwner;
1552 /// It is very important to check that the owner is processed only once and has a map of
1553 /// processed owners because SetSelected works as a switch.
1554 /// If count of calls setSelectec is even, the object stays in the previous state
1555 /// (selected, deselected)
1556 /// OCCT: to write about the problem that active owners method returns one owner several times
1557 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1558 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1559 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1560 if (aSelectedIds.contains((long)anOwner.get()))
1562 aSelectedIds.append((long)anOwner.get());
1564 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1565 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1566 const TopoDS_Shape& aShape = BROwnr->Shape();
1567 if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
1568 Handle(AIS_InteractiveObject) anOwnerPresentation =
1569 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1570 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1571 theShapesToBeSelected.Find(aShape);
1572 if (aPresentations.Contains(anOwnerPresentation)) {
1573 theContext->AddOrRemoveSelected(anOwner);
1574 anOwner->SetSelected (Standard_True);