1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_Displayer.cpp
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include "XGUI_Displayer.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_CustomPrs.h"
15 #include <AppElements_Viewer.h>
18 #include <ModelAPI_Document.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_Tools.h>
22 #include <ModelAPI_AttributeIntArray.h>
23 #include <ModelAPI_ResultCompSolid.h>
25 #include <ModuleBase_ResultPrs.h>
26 #include <ModuleBase_Tools.h>
27 #include <ModuleBase_IModule.h>
28 #include <ModuleBase_ViewerPrs.h>
29 #include <ModuleBase_Preferences.h>
31 #include <GeomAPI_Shape.h>
32 #include <GeomAPI_IPresentable.h>
33 #include <GeomAPI_ICustomPrs.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <AIS_InteractiveContext.hxx>
38 #include <AIS_ListOfInteractive.hxx>
39 #include <AIS_ListIteratorOfListOfInteractive.hxx>
40 #include <AIS_DimensionSelectionMode.hxx>
41 #include <AIS_Shape.hxx>
42 #include <AIS_Dimension.hxx>
43 #include <AIS_Trihedron.hxx>
44 #include <AIS_Axis.hxx>
45 #include <AIS_Plane.hxx>
46 #include <AIS_Point.hxx>
47 #include <AIS_Selection.hxx>
48 #include <TColStd_ListIteratorOfListOfInteger.hxx>
49 #include <SelectMgr_ListOfFilter.hxx>
50 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
51 #include <Prs3d_Drawer.hxx>
52 #include <Prs3d_IsoAspect.hxx>
53 #include <SelectMgr_SelectionManager.hxx>
55 #include <StdSelect_ViewerSelector3d.hxx>
57 #include <TColStd_MapOfTransient.hxx>
58 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
61 #include <VInspectorAPI_CallBack.h>
64 #include <Events_Loop.h>
65 #include <ModelAPI_Events.h>
69 /// defines the local context mouse selection sensitivity
70 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
72 //#define DEBUG_ACTIVATE_OBJECTS
73 //#define DEBUG_DEACTIVATE
74 //#define DEBUG_ACTIVATE_AIS
75 //#define DEBUG_DEACTIVATE_AIS
77 //#define DEBUG_DISPLAY
78 //#define DEBUG_FEATURE_REDISPLAY
79 //#define DEBUG_SELECTION_FILTERS
81 //#define DEBUG_COMPOSILID_DISPLAY
83 //#define DEBUG_OCCT_SHAPE_SELECTION
85 //#define DEBUG_OCCT_26172
87 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
89 // Get from null point
90 theAIS->DisplayedObjects(theList, true);
93 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
96 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
97 for (; anIt != aLast; anIt++) {
98 anInfo.append(QString::number(*anIt));
100 return anInfo.join(theSeparator);
103 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
104 : myWorkshop(theWorkshop), myNeedUpdate(false),
105 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0),
106 myIsFirstAISContextUse(true)
109 myContextCallBack = 0;
111 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
114 XGUI_Displayer::~XGUI_Displayer()
118 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
120 return myResult2AISObjectMap.contains(theObject);
123 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
125 bool aDisplayed = false;
126 if (isVisible(theObject)) {
127 #ifdef DEBUG_COMPOSILID_DISPLAY
128 ResultCompSolidPtr aCompsolidResult =
129 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
130 if (aCompsolidResult.get()) {
131 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
132 ResultPtr aSubResult = aCompsolidResult->subResult(i);
133 if (aSubResult.get())
134 redisplay(aSubResult, false);
141 aDisplayed = redisplay(theObject, theUpdateViewer);
144 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
145 bool isShading = false;
146 if (aPrs.get() != NULL) {
147 anAIS = aPrs->getAISObject(anAIS);
149 // correct deviation coefficient for
150 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
151 if (!anAISPrs.IsNull()) {
152 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
153 if (!aShapePrs.IsNull()) {
154 TopoDS_Shape aShape = aShapePrs->Shape();
155 if (!aShape.IsNull())
156 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
161 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
162 if (aResult.get() != NULL) {
163 #ifdef DEBUG_COMPOSILID_DISPLAY
164 ResultCompSolidPtr aCompsolidResult =
165 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
166 if (aCompsolidResult.get()) {
167 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
168 ResultPtr aSubResult = aCompsolidResult->subResult(i);
169 if (aSubResult.get())
170 display(aSubResult, false);
177 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
178 if (aShapePtr.get() != NULL) {
179 anAIS = AISObjectPtr(new GeomAPI_AISObject());
180 Handle(AIS_InteractiveObject) anAISPrs =
181 myWorkshop->module()->createPresentation(aResult);
182 if (anAISPrs.IsNull())
183 anAISPrs = new ModuleBase_ResultPrs(aResult);
185 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
186 if (!aShapePrs.IsNull())
187 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
189 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
190 //anAIS->createShape(aShapePtr);
193 #ifdef DEBUG_COMPOSILID_DISPLAY
199 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
204 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
206 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
207 if (!aShapePrs.IsNull()) {
208 TopoDS_Shape aShape = aShapePrs->Shape();
211 TopAbs_ShapeEnum aType = aShape.ShapeType();
212 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
215 // Check that the presentation is not a sketch
216 return theModule->canBeShaded(theAIS);
222 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
223 bool isShading, bool theUpdateViewer)
225 bool aDisplayed = false;
227 Handle(AIS_InteractiveContext) aContext = AISContext();
228 if (aContext.IsNull())
231 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
232 if (!anAISIO.IsNull()) {
233 appendResultObject(theObject, theAIS);
235 bool isCustomized = customizeObject(theObject);
237 int aDispMode = isShading? Shading : Wireframe;
239 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
240 anAISIO->SetDisplayMode(aDispMode);
241 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
243 if (myContextCallBack) myContextCallBack->Display(anAISIO);
247 emit objectDisplayed(theObject, theAIS);
248 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
256 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
258 bool aErased = false;
259 if (!isVisible(theObject))
262 Handle(AIS_InteractiveContext) aContext = AISContext();
263 if (aContext.IsNull())
266 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
268 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
269 if (!anAIS.IsNull()) {
270 emit beforeObjectErase(theObject, anObject);
271 aContext->Remove(anAIS, false/*update viewer*/);
273 if (myContextCallBack) myContextCallBack->Remove(anAIS);
278 myResult2AISObjectMap.remove(theObject);
281 std::ostringstream aPtrStr;
282 aPtrStr << theObject.get();
283 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
284 qDebug(getResult2AISObjectMapInfo().c_str());
293 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
295 bool aRedisplayed = false;
296 if (!isVisible(theObject))
299 AISObjectPtr aAISObj = getAISObject(theObject);
300 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
302 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
304 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
306 aRedisplayed = erase(theObject, theUpdateViewer);
309 if (aAIS_Obj != aAISObj) {
310 appendResultObject(theObject, aAIS_Obj);
312 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
315 Handle(AIS_InteractiveContext) aContext = AISContext();
316 if (!aContext.IsNull() && !aAISIO.IsNull()) {
317 // Check that the visualized shape is the same and the redisplay is not necessary
318 // Redisplay of AIS object leads to this object selection compute and the selection
319 // in the browser is lost
320 // this check is not necessary anymore because the selection store/restore is realized
321 // before and after the values modification.
322 // Moreother, this check avoids customize and redisplay presentation if the presentable
323 // parameter is changed.
324 bool isEqualShapes = false;
325 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
326 if (aResult.get() != NULL) {
327 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
328 if (!aShapePrs.IsNull()) {
329 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
330 if (aShapePtr.get()) {
331 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
332 if (!aOldShape.IsNull())
333 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
337 // Customization of presentation
338 bool isCustomized = customizeObject(theObject);
339 #ifdef DEBUG_FEATURE_REDISPLAY
340 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
341 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
342 .arg(isCustomized).toStdString().c_str());
344 if (!isEqualShapes || isCustomized) {
345 /// if shapes are equal and presentation are customized, selection should be restored
346 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
347 if (aNeedToRestoreSelection)
348 myWorkshop->module()->storeSelection();
350 aContext->Redisplay(aAISIO, false);
353 if (myContextCallBack) myContextCallBack->Redisplay(aAISIO);
356 if (aNeedToRestoreSelection)
357 myWorkshop->module()->restoreSelection();
360 #ifdef DEBUG_FEATURE_REDISPLAY
361 qDebug(" Redisplay happens");
370 void XGUI_Displayer::redisplayObjects()
372 // redisplay objects visualized in the viewer
373 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
374 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
375 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
376 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
377 for (; anIt != aLast; anIt++) {
378 aECreator->sendUpdated(*anIt, EVENT_DISP);
380 Events_Loop::loop()->flush(EVENT_DISP);
383 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
385 #ifdef DEBUG_DEACTIVATE
386 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
387 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
388 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
390 toStdString().c_str());
392 Handle(AIS_InteractiveContext) aContext = AISContext();
393 if (!aContext.IsNull() && isVisible(theObject)) {
394 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
395 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
397 deactivateAIS(anAIS);
403 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
404 const bool theUpdateViewer)
406 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
407 //if (!aTrihedron.IsNull())
408 // deactivateAIS(aTrihedron);
410 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
411 for (; anIt != aLast; anIt++) {
412 deactivate(*anIt, false);
414 //VSV It seems that there is no necessity to update viewer on deactivation
415 //if (theUpdateViewer)
419 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
421 Handle(AIS_InteractiveContext) aContext = AISContext();
422 if (aContext.IsNull() || !isVisible(theObject))
425 AISObjectPtr aAISObj = getAISObject(theObject);
427 if (aAISObj.get() != NULL) {
428 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
429 TColStd_ListOfInteger aTColModes;
430 aContext->ActivatedModes(anAISIO, aTColModes);
431 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
432 for (; itr.More(); itr.Next() ) {
433 theModes.append(itr.Value());
438 int XGUI_Displayer::getSelectionMode(int theShapeType)
440 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
441 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
444 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
446 bool aVisible = false;
447 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
448 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
449 if (aPrs.get() || aResult.get()) {
450 aVisible = theDisplayer->isVisible(theObject);
451 // compsolid is not visualized in the viewer,
452 // but should have presentation when all sub solids are
453 // visible. It is useful for highlight presentation where compsolid shape is selectable
454 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
455 ResultCompSolidPtr aCompsolidResult =
456 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
457 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
458 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
459 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
460 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
462 aVisible = anAllSubsVisible;
466 // it is possible that feature is presentable and has results, so we should check visibility
467 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
469 // check if all results of the feature are visible
470 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
471 std::list<ResultPtr> aResults;
472 ModelAPI_Tools::allResults(aFeature, aResults);
473 std::list<ResultPtr>::const_iterator aIt;
474 aVisible = !aResults.empty();
475 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
476 aVisible = aVisible && theDisplayer->isVisible(*aIt);
482 #ifdef DEBUG_ACTIVATE_OBJECTS
483 QString getModeInfo(const int theMode)
485 QString anInfo = "Undefined";
487 case 0: anInfo = "SHAPE(0)"; break;
488 case 1: anInfo = "VERTEX(1)"; break;
489 case 2: anInfo = "EDGE(2)"; break;
490 case 3: anInfo = "WIRE(3)"; break;
491 case 4: anInfo = "FACE(4)"; break;
492 case 5: anInfo = "SHELL(5)"; break;
493 case 6: anInfo = "SOLID(6)"; break;
494 case 7: anInfo = "COMPSOLID(7)"; break;
495 case 8: anInfo = "COMPOUND(8)"; break;
496 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
497 case 101: anInfo = "Sel_Constraint(101)"; break;
498 case 102: anInfo = "Sel_Dimension_All(102)"; break;
499 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
500 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
506 QString getModesInfo(const QIntList& theModes)
508 QStringList aModesInfo;
509 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
510 aModesInfo.append(getModeInfo(theModes[i]));
511 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
515 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
516 const bool theUpdateViewer)
518 // Convert shape types to selection types
520 foreach(int aType, theModes) {
521 aModes.append(getSelectionMode(aType));
524 #ifdef DEBUG_ACTIVATE_OBJECTS
526 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
527 for (; anIt != aLast; ++anIt) {
528 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
530 QString anInfoStr = anInfo.join(", ");
532 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
533 arg(getModesInfo(aModes)).
534 arg(getModesInfo(myActiveSelectionModes)).
535 arg(theObjList.size()).
537 toStdString().c_str());
539 // In order to avoid doblications of selection modes
541 foreach (int aMode, aModes) {
542 if (!aNewModes.contains(aMode))
543 aNewModes.append(aMode);
545 myActiveSelectionModes = aNewModes;
546 Handle(AIS_InteractiveContext) aContext = AISContext();
547 // Open local context if there is no one
548 if (aContext.IsNull())
551 //aContext->UseDisplayedObjects();
552 //myUseExternalObjects = true;
554 Handle(AIS_InteractiveObject) anAISIO;
555 AIS_ListOfInteractive aPrsList;
556 //if (aObjList.isEmpty())
559 foreach(ObjectPtr aObj, theObjList) {
560 if (myResult2AISObjectMap.contains(aObj))
561 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
565 // Add trihedron because it has to partisipate in selection
566 Handle(AIS_InteractiveObject) aTrihedron;
567 if (isTrihedronActive()) {
568 aTrihedron = getTrihedron();
569 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
570 aPrsList.Append(aTrihedron);
572 if (aPrsList.Extent() == 0)
575 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
576 bool isActivationChanged = false;
577 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
578 anAISIO = aLIt.Value();
579 if (activate(anAISIO, myActiveSelectionModes, false))
580 isActivationChanged = true;
584 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
586 Handle(AIS_InteractiveContext) aContext = AISContext();
587 if (aContext.IsNull() || !isVisible(theObject))
590 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
591 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
593 TColStd_ListOfInteger aModes;
594 aContext->ActivatedModes(anAIS, aModes);
596 if (myContextCallBack) myContextCallBack->ActivatedModes(anAIS, aModes);
599 return aModes.Extent() > 0;
603 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
604 bool theUpdateViewer)
606 Handle(AIS_InteractiveContext) aContext = AISContext();
607 if (aContext.IsNull())
609 aContext->UnhilightSelected(false);
610 aContext->ClearSelected(false);
612 if (myContextCallBack) myContextCallBack->ClearSelected();
614 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
617 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
618 const GeomShapePtr& aGeomShape = aPrs->shape();
619 if (aGeomShape.get() && !aGeomShape->isNull()) {
620 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
621 #ifdef DEBUG_OCCT_SHAPE_SELECTION
622 // problem 1: performance
623 // problem 2: IO is not specified, so the first found owner is selected, as a result
624 // it might belong to another result
625 aContext->AddOrRemoveSelected(aShape, false);
627 if (myContextCallBack) myContextCallBack->AddOrRemoveSelected(aShape);
630 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
631 if (aShapesToBeSelected.IsBound(aShape))
632 aPresentations = aShapesToBeSelected.Find(aShape);
633 ObjectPtr anObject = aPrs->object();
634 getPresentations(anObject, aPresentations);
636 aShapesToBeSelected.Bind(aShape, aPresentations);
639 ObjectPtr anObject = aPrs->object();
640 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
641 if (aResult.get() && isVisible(aResult)) {
642 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
643 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
644 if (!anAIS.IsNull()) {
645 // The methods are replaced in order to provide multi-selection, e.g. restore selection
646 // by activating multi selector widget. It also gives an advantage that the multi
647 // selection in OB gives multi-selection in the viewer
648 //aContext->SetSelected(anAIS, false);
649 // The selection in the context was cleared, so the method sets the objects are selected
650 aContext->AddOrRemoveSelected(anAIS, false);
652 if (myContextCallBack) myContextCallBack->AddOrRemoveSelected(anAIS);
658 if (!aShapesToBeSelected.IsEmpty())
659 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
665 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
667 Handle(AIS_InteractiveContext) aContext = AISContext();
668 if (!aContext.IsNull()) {
669 aContext->UnhilightCurrents(false);
670 aContext->ClearSelected(theUpdateViewer);
672 if (myContextCallBack) myContextCallBack->ClearSelected();
677 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
679 bool aErased = false;
680 Handle(AIS_InteractiveContext) aContext = AISContext();
681 if (!aContext.IsNull()) {
682 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
683 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
685 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
686 if (!anIO.IsNull()) {
687 emit beforeObjectErase(aObj, aAISObj);
688 aContext->Remove(anIO, false/*update viewer*/);
690 if (myContextCallBack) myContextCallBack->Remove(anIO);
698 myResult2AISObjectMap.clear();
701 qDebug(getResult2AISObjectMapInfo().c_str());
706 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
707 Handle(AIS_InteractiveObject) theObject
709 , VInspectorAPI_CallBack* theCallBack
713 if (!theObject.IsNull()) {
714 theContext->Deactivate(theObject);
716 if (theCallBack) theCallBack->Deactivate(theObject);
721 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
723 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
724 Handle(AIS_InteractiveContext) aContext = AISContext();
725 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
726 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
727 deactivateObject(aContext, aTrie
733 /// #1136 hidden axis are selected in sketch
734 deactivateObject(aContext, aTrie->XAxis()
739 deactivateObject(aContext, aTrie->YAxis()
744 deactivateObject(aContext, aTrie->Axis()
749 deactivateObject(aContext, aTrie->Position()
755 deactivateObject(aContext, aTrie->XYPlane()
760 deactivateObject(aContext, aTrie->XZPlane()
765 deactivateObject(aContext, aTrie->YZPlane()
776 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
778 return myWorkshop->viewer()->trihedron();
781 /*void XGUI_Displayer::openLocalContext()
783 Handle(AIS_InteractiveContext) aContext = AISContext();
784 // Open local context if there is no one
785 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
786 // Preserve selected objects
787 //AIS_ListOfInteractive aAisList;
788 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
789 // aAisList.Append(aContext->Current());
791 // get the filters from the global context and append them to the local context
792 // a list of filters in the global context is not cleared and should be cleared here
793 SelectMgr_ListOfFilter aFilters;
794 aFilters.Assign(aContext->Filters());
795 // it is important to remove the filters in the global context, because there is a code
796 // in the closeLocalContex, which restore the global context filters
797 aContext->RemoveFilters();
799 //aContext->ClearCurrents();
800 aContext->OpenLocalContext();
801 //deactivateTrihedron();
802 //aContext->NotUseDisplayedObjects();
804 //myUseExternalObjects = false;
806 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
807 for (;aIt.More(); aIt.Next()) {
808 aContext->AddFilter(aIt.Value());
811 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
812 //for(; aIt2.More(); aIt2.Next()) {
813 // aContext->SetSelected(aIt2.Value(), false);
818 /*void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
820 Handle(AIS_InteractiveContext) aContext = AISContext();
821 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
822 // Preserve selected objects
823 //AIS_ListOfInteractive aAisList;
824 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
825 // aAisList.Append(aContext->SelectedInteractive());
827 // get the filters from the local context and append them to the global context
828 // a list of filters in the local context is cleared
829 SelectMgr_ListOfFilter aFilters;
830 aFilters.Assign(aContext->Filters());
832 //aContext->ClearSelected();
833 aContext->CloseAllContexts(false);
835 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
836 // this code is obsolete. It is temporaty commented and should be removed after
837 // the test campaign.
838 // Redisplay all object if they were displayed in localContext
839 /*Handle(AIS_InteractiveObject) aAISIO;
840 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
841 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
842 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
843 aContext->Display(aAISIO, false);
844 aContext->SetDisplayMode(aAISIO, Shading, false);
848 // Append the filters from the local selection in the global selection context
849 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
850 for (;aIt.More(); aIt.Next()) {
851 Handle(SelectMgr_Filter) aFilter = aIt.Value();
852 aContext->AddFilter(aFilter);
857 //myUseExternalObjects = false;
860 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
861 //for(; aIt2.More(); aIt2.Next()) {
862 // if (aContext->IsDisplayed(aIt2.Value()))
863 // aContext->SetCurrentObject(aIt2.Value(), false);
868 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
871 if (myResult2AISObjectMap.contains(theObject))
872 anIO = myResult2AISObjectMap[theObject];
876 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
878 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
879 return getObject(aRefAIS);
882 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
885 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
886 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
887 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
893 if (!anObject.get()) {
894 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
895 if (!theIO.IsNull()) {
896 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
898 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
903 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
905 bool aWasEnabled = isUpdateEnabled();
907 myViewerBlockedRecursiveCount--;
909 myViewerBlockedRecursiveCount++;
911 if (myNeedUpdate && isUpdateEnabled()) {
913 myNeedUpdate = false;
918 bool XGUI_Displayer::isUpdateEnabled() const
920 return myViewerBlockedRecursiveCount == 0;
923 void XGUI_Displayer::updateViewer() const
925 Handle(AIS_InteractiveContext) aContext = AISContext();
926 if (!aContext.IsNull() && isUpdateEnabled()) {
927 myWorkshop->viewer()->Zfitall();
928 aContext->UpdateCurrentViewer();
934 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
935 const int theMode, const bool theUpdateViewer) const
937 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
938 if (!theIO.IsNull() && theIO == getTrihedron()) {
939 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
940 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
943 if (!aContext.IsNull()) {
944 if (myWorkshop->module()) {
945 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
946 aContext->Activate(theIO, theMode, false);
948 aContext->Activate(theIO, theMode, false);
950 if (myContextCallBack) myContextCallBack->Activate(theIO, theMode);
953 // the fix from VPA for more suitable selection of sketcher lines
954 if (theIO->Width() > 1) {
955 double aPrecision = theIO->Width() + 2;
956 if (theMode == getSelectionMode(TopAbs_VERTEX))
957 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
958 "point-selection-sensitivity",
960 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
961 (theMode == getSelectionMode(TopAbs_WIRE)))
962 aPrecision = theIO->Width() +
963 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
964 "edge-selection-sensitivity", 2);
965 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
968 #ifdef DEBUG_ACTIVATE_AIS
969 ObjectPtr anObject = getObject(theIO);
970 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
971 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
972 .arg(anInfo).toStdString().c_str());
979 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
980 const int theMode) const
982 Handle(AIS_InteractiveContext) aContext = AISContext();
983 if (!aContext.IsNull()) {
985 aContext->Deactivate(theIO);
987 if (myContextCallBack) myContextCallBack->Deactivate(theIO);
991 aContext->Deactivate(theIO, theMode);
993 if (myContextCallBack) myContextCallBack->Deactivate(theIO, theMode);
997 #ifdef DEBUG_DEACTIVATE_AIS
998 ObjectPtr anObject = getObject(theIO);
999 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1000 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1001 .arg(anInfo).toStdString().c_str());
1006 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1008 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1009 if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
1010 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1011 aDisplayer->myIsFirstAISContextUse = false;
1012 //aContext->OpenLocalContext();
1013 if (!isTrihedronActive())
1014 deactivateTrihedron(true);
1015 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1016 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1021 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1023 Handle(AIS_InteractiveContext) aContext = AISContext();
1024 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1025 myAndFilter = new SelectMgr_AndFilter();
1026 aContext->AddFilter(myAndFilter);
1031 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1032 bool theUpdateViewer)
1034 bool aDisplayed = false;
1035 Handle(AIS_InteractiveContext) aContext = AISContext();
1036 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1037 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1038 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1040 if (myContextCallBack) myContextCallBack->Display(anAISIO);
1043 aContext->Deactivate(anAISIO);
1045 if (myContextCallBack) myContextCallBack->Deactivate(anAISIO);
1047 aContext->Load(anAISIO);
1049 if (myContextCallBack) myContextCallBack->Load(anAISIO);
1051 if (toActivateInSelectionModes) {
1052 if (myActiveSelectionModes.size() == 0)
1053 activateAIS(anAISIO, 0, theUpdateViewer);
1055 foreach(int aMode, myActiveSelectionModes) {
1056 activateAIS(anAISIO, aMode, theUpdateViewer);
1060 if (theUpdateViewer)
1066 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1068 bool aErased = false;
1069 Handle(AIS_InteractiveContext) aContext = AISContext();
1070 if (!aContext.IsNull()) {
1071 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1072 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1073 aContext->Remove(anAISIO, false/*update viewer*/);
1075 if (myContextCallBack) myContextCallBack->Remove(anAISIO);
1080 if (aErased && theUpdateViewer)
1086 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1088 if (theMode == NoMode)
1091 Handle(AIS_InteractiveContext) aContext = AISContext();
1092 if (aContext.IsNull())
1095 AISObjectPtr aAISObj = getAISObject(theObject);
1099 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1100 aContext->SetDisplayMode(aAISIO, theMode, false);
1101 // Redisplay in order to update new mode because it could be not computed before
1102 if (theUpdateViewer)
1106 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1108 Handle(AIS_InteractiveContext) aContext = AISContext();
1109 if (aContext.IsNull())
1112 AISObjectPtr aAISObj = getAISObject(theObject);
1116 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1117 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1120 void XGUI_Displayer::deactivateSelectionFilters()
1122 Handle(AIS_InteractiveContext) aContext = AISContext();
1123 if (!myAndFilter.IsNull()) {
1124 bool aFound = false;
1125 if (!aContext.IsNull()) {
1126 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1127 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1128 for (; anIt.More() && !aFound; anIt.Next()) {
1129 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1130 aFound = aFilter == myAndFilter;
1133 aContext->RemoveFilter(myAndFilter);
1135 myAndFilter.Nullify();
1139 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1141 Handle(AIS_InteractiveContext) aContext = AISContext();
1142 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1145 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1146 if (!aCompositeFilter.IsNull()) {
1147 aCompositeFilter->Add(theFilter);
1148 #ifdef DEBUG_SELECTION_FILTERS
1149 int aCount = aCompositeFilter->StoredFilters().Extent();
1150 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1155 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1157 Handle(AIS_InteractiveContext) aContext = AISContext();
1158 if (aContext.IsNull())
1161 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1162 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1163 aCompositeFilter->Remove(theFilter);
1164 #ifdef DEBUG_SELECTION_FILTERS
1165 int aCount = aCompositeFilter->StoredFilters().Extent();
1166 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1167 .arg(aCount).toStdString().c_str());
1172 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1174 bool aFilterFound = false;
1176 Handle(AIS_InteractiveContext) aContext = AISContext();
1177 if (aContext.IsNull())
1178 return aFilterFound;
1179 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1180 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1181 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1182 if (theFilter.get() == aIt.Value().get())
1183 aFilterFound = true;
1185 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1186 if (!aCompositeFilter.IsNull()) {
1187 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1188 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1189 if (theFilter.get() == aIt.Value().get())
1190 aFilterFound = true;
1193 return aFilterFound;
1196 void XGUI_Displayer::removeFilters()
1198 Handle(AIS_InteractiveContext) aContext = AISContext();
1199 if (aContext.IsNull())
1202 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1203 if (!aCompositeFilter.IsNull())
1204 aCompositeFilter->Clear();
1207 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1209 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1210 foreach(ObjectPtr aObj, aDispList) {
1211 if (!theList.contains(aObj))
1214 foreach(ObjectPtr aObj, theList) {
1215 if (!isVisible(aObj))
1216 display(aObj, false);
1221 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1223 if (!isVisible(theObject))
1226 AISObjectPtr aAISObj = getAISObject(theObject);
1227 if (aAISObj.get() == NULL)
1230 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1231 return ::canBeShaded(anAIS, myWorkshop->module());
1234 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1235 const QIntList& theModes,
1236 const bool theUpdateViewer) const
1238 Handle(AIS_InteractiveContext) aContext = AISContext();
1239 if (aContext.IsNull() || theIO.IsNull())
1242 bool isActivationChanged = false;
1243 // deactivate object in all modes, which are not in the list of activation
1244 // It seems that after the IO deactivation the selected state of the IO's owners
1245 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1246 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1247 // only if there is a difference in the current modes and the parameters modes.
1248 // If the selection problem happens again, it is possible to write a test scenario and create
1249 // a bug. The bug steps are the following:
1250 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1251 // with clicked SHIFT select the second object.
1252 // The result is the selection of the first IO is lost.
1253 TColStd_ListOfInteger aTColModes;
1254 aContext->ActivatedModes(theIO, aTColModes);
1256 if (myContextCallBack) myContextCallBack->ActivatedModes(theIO, aTColModes);
1258 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1259 QIntList aModesActivatedForIO;
1260 bool isDeactivated = false;
1261 for (; itr.More(); itr.Next() ) {
1262 Standard_Integer aMode = itr.Value();
1263 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1264 if (!theModes.contains(aMode)) {
1265 deactivateAIS(theIO, aMode);
1266 isDeactivated = true;
1269 aModesActivatedForIO.append(aMode);
1272 if (isDeactivated) {
1273 #ifdef DEBUG_OCCT_26172
1274 // the selection from the previous activation modes should be cleared manually (#26172)
1275 theIO->ClearSelected();
1277 if (myContextCallBack) myContextCallBack->ClearSelected(theIO);
1280 // For performance issues
1281 //if (theUpdateViewer)
1283 isActivationChanged = true;
1286 // loading the interactive object allowing the decomposition
1287 if (aTColModes.IsEmpty()) {
1288 aContext->Load(theIO, -1, true);
1290 if (myContextCallBack) myContextCallBack->Load(theIO);
1294 // trihedron AIS check should be after the AIS loading.
1295 // If it is not loaded, it is steel selectable in the viewer.
1296 Handle(AIS_Trihedron) aTrihedron;
1297 if (!isTrihedronActive())
1298 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1299 if (aTrihedron.IsNull()) {
1300 // In order to clear active modes list
1301 if (theModes.size() == 0) {
1302 activateAIS(theIO, 0, theUpdateViewer);
1304 foreach(int aMode, theModes) {
1305 if (!aModesActivatedForIO.contains(aMode)) {
1306 activateAIS(theIO, aMode, theUpdateViewer);
1307 isActivationChanged = true;
1312 return isActivationChanged;
1315 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1317 AISObjectPtr anAISObj = getAISObject(theObject);
1318 // correct the result's color it it has the attribute
1319 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1321 // Customization of presentation
1322 GeomCustomPrsPtr aCustomPrs;
1323 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1324 if (aFeature.get() != NULL) {
1325 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1326 if (aCustPrs.get() != NULL)
1327 aCustomPrs = aCustPrs;
1329 if (aCustomPrs.get() == NULL) {
1330 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1331 // we ignore presentable not customized objects
1332 if (aPrs.get() == NULL)
1333 aCustomPrs = myCustomPrs;
1335 bool isCustomized = aCustomPrs.get() &&
1336 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1337 return isCustomized;
1341 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1342 const QColor& theColor,
1343 bool theUpdateViewer)
1345 if (!isVisible(theObject))
1348 AISObjectPtr anAISObj = getAISObject(theObject);
1350 anAISObj->getColor(aR, aG, aB);
1351 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1352 if (theUpdateViewer)
1354 return QColor(aR, aG, aB);
1357 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1359 myResult2AISObjectMap[theObject] = theAIS;
1361 #ifdef DEBUG_DISPLAY
1362 std::ostringstream aPtrStr;
1363 aPtrStr << theObject.get();
1364 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1365 qDebug(getResult2AISObjectMapInfo().c_str());
1370 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1372 QStringList aContent;
1373 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1374 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1375 std::ostringstream aPtrStr;
1376 aPtrStr << "aObj = " << aObj.get() << ":";
1377 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1378 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1380 aContent.append(aPtrStr.str().c_str());
1382 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1383 arg(aContent.join("\n")).toStdString().c_str();
1387 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1388 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1390 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1391 if (aResult.get()) {
1392 AISObjectPtr aAISObj = getAISObject(aResult);
1393 if (aAISObj.get() != NULL) {
1394 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1395 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1396 thePresentations.Add(anAIS);
1400 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1401 // find presentation of the feature
1402 AISObjectPtr aAISObj = getAISObject(aFeature);
1403 if (aAISObj.get() != NULL) {
1404 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1405 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1406 thePresentations.Add(anAIS);
1408 // find presentations of the feature results
1409 std::list<ResultPtr> aResults;
1410 ModelAPI_Tools::allResults(aFeature, aResults);
1411 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1412 for (; anIt != aLast; ++anIt) {
1413 AISObjectPtr aAISObj = getAISObject(*anIt);
1414 if (aAISObj.get() != NULL) {
1415 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1416 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1417 thePresentations.Add(anAIS);
1423 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1425 myIsTrihedronActive = theIsActive;
1426 if (!myIsTrihedronActive) {
1427 deactivateTrihedron(true);
1431 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1433 Handle(AIS_InteractiveContext) aContext = AISContext();
1434 if (aContext.IsNull())
1437 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1440 if (!aContext->IsDisplayed(aTrihedron))
1441 aContext->Display(aTrihedron,
1443 -1 /* selection mode */,
1444 Standard_True /* update viewer*/,
1445 Standard_False /* allow decomposition */,
1446 AIS_DS_Displayed /* xdisplay status */);
1448 if (myContextCallBack) myContextCallBack->Display(aTrihedron);
1451 if (!isTrihedronActive())
1452 deactivateTrihedron(false);
1454 activate(aTrihedron, myActiveSelectionModes, false);
1456 deactivateTrihedron(false);
1458 aContext->Erase(aTrihedron);
1460 if (myContextCallBack) myContextCallBack->Remove(aTrihedron);
1467 QIntList XGUI_Displayer::activeSelectionModes() const
1470 foreach (int aMode, myActiveSelectionModes) {
1471 // aMode < 9 is a Shape Enum values
1472 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1478 void XGUI_Displayer::setCallBack(VInspectorAPI_CallBack* theCallBack)
1480 myContextCallBack = theCallBack;
1483 VInspectorAPI_CallBack* XGUI_Displayer::getCallBack() const
1485 return myContextCallBack;
1489 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1490 const NCollection_DataMap<TopoDS_Shape,
1491 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1493 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1494 theContext->MainSelector()->ActiveOwners(anActiveOwners);
1495 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1496 Handle(SelectMgr_EntityOwner) anOwner;
1498 /// It is very important to check that the owner is processed only once and has a map of
1499 /// processed owners because SetSelected works as a switch.
1500 /// If count of calls setSelectec is even, the object stays in the previous state
1501 /// (selected, deselected)
1502 /// OCCT: to write about the problem that active owners method returns one owner several times
1503 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1504 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1505 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1506 if (aSelectedIds.contains((long)anOwner.get()))
1508 aSelectedIds.append((long)anOwner.get());
1510 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1511 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1512 const TopoDS_Shape& aShape = BROwnr->Shape();
1513 if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
1514 Handle(AIS_InteractiveObject) anOwnerPresentation =
1515 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1516 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1517 theShapesToBeSelected.Find(aShape);
1518 if (aPresentations.Contains(anOwnerPresentation)) {
1519 theContext->AddOrRemoveSelected(anOwner);
1520 anOwner->SetSelected (Standard_True);