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_LocalContext.hxx>
39 #include <AIS_ListOfInteractive.hxx>
40 #include <AIS_ListIteratorOfListOfInteractive.hxx>
41 #include <AIS_DimensionSelectionMode.hxx>
42 #include <AIS_Shape.hxx>
43 #include <AIS_Dimension.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Plane.hxx>
47 #include <AIS_Point.hxx>
48 #include <AIS_Selection.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
50 #include <SelectMgr_ListOfFilter.hxx>
51 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
52 #include <Prs3d_Drawer.hxx>
53 #include <Prs3d_IsoAspect.hxx>
54 #include <SelectMgr_SelectionManager.hxx>
56 #include <StdSelect_ViewerSelector3d.hxx>
58 #include <TColStd_MapOfTransient.hxx>
59 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
61 #include <Events_Loop.h>
62 #include <ModelAPI_Events.h>
66 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
68 //#define DEBUG_ACTIVATE_OBJECTS
69 //#define DEBUG_DEACTIVATE
70 //#define DEBUG_ACTIVATE_AIS
71 //#define DEBUG_DEACTIVATE_AIS
73 //#define DEBUG_DISPLAY
74 //#define DEBUG_FEATURE_REDISPLAY
75 //#define DEBUG_SELECTION_FILTERS
77 //#define DEBUG_COMPOSILID_DISPLAY
78 // Workaround for bug #25637
80 //#define DEBUG_OCCT_SHAPE_SELECTION
82 //#define WORKAROUND_UNTIL_27523_IS_FIXED
84 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
86 // Get from null point
87 theAIS->DisplayedObjects(theList, true);
88 if (theAIS->HasOpenedContext()) {
89 // get from local context
90 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
91 TColStd_MapOfTransient aMap;
92 int NbDisp = aLC->DisplayedObjects(aMap);
93 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
95 Handle(AIS_InteractiveObject) curIO;
96 Handle(Standard_Transient) Tr;
97 for(; aIt.More(); aIt.Next()){
99 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
100 theList.Append(curIO);
105 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
108 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
109 for (; anIt != aLast; anIt++) {
110 anInfo.append(QString::number(*anIt));
112 return anInfo.join(theSeparator);
115 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
116 : myWorkshop(theWorkshop), myNeedUpdate(false),
117 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0)
119 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
122 XGUI_Displayer::~XGUI_Displayer()
126 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
128 return myResult2AISObjectMap.contains(theObject);
131 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
133 bool aDisplayed = false;
134 if (isVisible(theObject)) {
135 #ifdef DEBUG_COMPOSILID_DISPLAY
136 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
137 if (aCompsolidResult.get()) {
138 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
139 ResultPtr aSubResult = aCompsolidResult->subResult(i);
140 if (aSubResult.get())
141 redisplay(aSubResult, false);
148 aDisplayed = redisplay(theObject, theUpdateViewer);
151 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
152 bool isShading = false;
153 if (aPrs.get() != NULL) {
154 anAIS = aPrs->getAISObject(anAIS);
156 // correct deviation coefficient for
157 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
158 if (!anAISPrs.IsNull()) {
159 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
160 if (!aShapePrs.IsNull()) {
161 TopoDS_Shape aShape = aShapePrs->Shape();
162 if (!aShape.IsNull())
163 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
168 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
169 if (aResult.get() != NULL) {
170 #ifdef DEBUG_COMPOSILID_DISPLAY
171 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
172 if (aCompsolidResult.get()) {
173 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
174 ResultPtr aSubResult = aCompsolidResult->subResult(i);
175 if (aSubResult.get())
176 display(aSubResult, false);
183 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
184 if (aShapePtr.get() != NULL) {
185 anAIS = AISObjectPtr(new GeomAPI_AISObject());
186 Handle(AIS_InteractiveObject) anAISPrs = myWorkshop->module()->createPresentation(aResult);
187 if (anAISPrs.IsNull())
188 anAISPrs = new ModuleBase_ResultPrs(aResult);
190 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
191 if (!aShapePrs.IsNull())
192 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.Access());
194 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
195 //anAIS->createShape(aShapePtr);
198 #ifdef DEBUG_COMPOSILID_DISPLAY
204 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
209 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
211 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
212 if (!aShapePrs.IsNull()) {
213 TopoDS_Shape aShape = aShapePrs->Shape();
216 TopAbs_ShapeEnum aType = aShape.ShapeType();
217 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
220 // Check that the presentation is not a sketch
221 return theModule->canBeShaded(theAIS);
227 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
228 bool isShading, bool theUpdateViewer)
230 bool aDisplayed = false;
232 Handle(AIS_InteractiveContext) aContext = AISContext();
233 if (aContext.IsNull())
236 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
237 if (!anAISIO.IsNull()) {
238 appendResultObject(theObject, theAIS);
240 bool isCustomized = customizeObject(theObject);
242 int aDispMode = isShading? Shading : Wireframe;
244 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
245 anAISIO->SetDisplayMode(aDispMode);
246 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
249 emit objectDisplayed(theObject, theAIS);
250 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
258 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
260 bool aErased = false;
261 if (!isVisible(theObject))
264 Handle(AIS_InteractiveContext) aContext = AISContext();
265 if (aContext.IsNull())
268 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
270 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
271 if (!anAIS.IsNull()) {
272 emit beforeObjectErase(theObject, anObject);
273 aContext->Remove(anAIS, false/*update viewer*/);
274 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::erase -- Remove");
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).arg(isCustomized).toStdString().c_str());
343 if (!isEqualShapes || isCustomized) {
344 /// if shapes are equal and presentation are customized, selection should be restored
345 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
346 if (aNeedToRestoreSelection)
347 myWorkshop->module()->storeSelection();
349 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
350 if (!myActiveSelectionModes.contains(0))
351 aContext->Activate(aAISIO, 0);
354 aContext->Redisplay(aAISIO, false);
356 #ifdef WORKAROUND_UNTIL_27523_IS_FIXED
357 if (!myActiveSelectionModes.contains(0))
358 aContext->Deactivate(aAISIO, 0);
361 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::redisplay -- Redisplay");
363 if (aNeedToRestoreSelection)
364 myWorkshop->module()->restoreSelection();
367 #ifdef DEBUG_FEATURE_REDISPLAY
368 qDebug(" Redisplay happens");
377 void XGUI_Displayer::redisplayObjects()
379 // redisplay objects visualized in the viewer
380 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
381 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
382 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
383 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
384 for (; anIt != aLast; anIt++) {
385 aECreator->sendUpdated(*anIt, EVENT_DISP);
387 Events_Loop::loop()->flush(EVENT_DISP);
390 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
392 #ifdef DEBUG_DEACTIVATE
393 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
394 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
395 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
397 toStdString().c_str());
399 Handle(AIS_InteractiveContext) aContext = AISContext();
400 if (!aContext.IsNull() && isVisible(theObject)) {
401 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
402 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
404 deactivateAIS(anAIS);
405 // the selection from the previous activation modes should be cleared manually (#26172)
406 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
407 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivate -- ClearOutdatedSelection");
413 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
414 const bool theUpdateViewer)
416 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
417 //if (!aTrihedron.IsNull())
418 // deactivateAIS(aTrihedron);
420 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
421 for (; anIt != aLast; anIt++) {
422 deactivate(*anIt, false);
424 //VSV It seems that there is no necessity to update viewer on deactivation
425 //if (theUpdateViewer)
429 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
431 Handle(AIS_InteractiveContext) aContext = AISContext();
432 if (aContext.IsNull() || !isVisible(theObject))
435 AISObjectPtr aAISObj = getAISObject(theObject);
437 if (aAISObj.get() != NULL) {
438 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
439 TColStd_ListOfInteger aTColModes;
440 aContext->ActivatedModes(anAISIO, aTColModes);
441 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
442 for (; itr.More(); itr.Next() ) {
443 theModes.append(itr.Value());
448 int XGUI_Displayer::getSelectionMode(int theShapeType)
450 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
451 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
454 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
456 bool aVisible = false;
457 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
458 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
459 if (aPrs.get() || aResult.get()) {
460 aVisible = theDisplayer->isVisible(theObject);
461 // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
462 // visible. It is useful for highlight presentation where compsolid shape is selectable
463 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
464 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
465 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
466 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
467 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
468 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
470 aVisible = anAllSubsVisible;
474 // it is possible that feature is presentable and has results, so we should check visibility
475 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
477 // check if all results of the feature are visible
478 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
479 std::list<ResultPtr> aResults;
480 ModelAPI_Tools::allResults(aFeature, aResults);
481 std::list<ResultPtr>::const_iterator aIt;
482 aVisible = !aResults.empty();
483 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
484 aVisible = aVisible && theDisplayer->isVisible(*aIt);
490 #ifdef DEBUG_ACTIVATE_OBJECTS
491 QString getModeInfo(const int theMode)
493 QString anInfo = "Undefined";
495 case 0: anInfo = "SHAPE(0)"; break;
496 case 1: anInfo = "VERTEX(1)"; break;
497 case 2: anInfo = "EDGE(2)"; break;
498 case 3: anInfo = "WIRE(3)"; break;
499 case 4: anInfo = "FACE(4)"; break;
500 case 5: anInfo = "SHELL(5)"; break;
501 case 6: anInfo = "SOLID(6)"; break;
502 case 7: anInfo = "COMPSOLID(7)"; break;
503 case 8: anInfo = "COMPOUND(8)"; break;
504 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
505 case 101: anInfo = "Sel_Constraint(101)"; break;
506 case 102: anInfo = "Sel_Dimension_All(102)"; break;
507 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
508 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
514 QString getModesInfo(const QIntList& theModes)
516 QStringList aModesInfo;
517 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
518 aModesInfo.append(getModeInfo(theModes[i]));
519 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
523 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
524 const bool theUpdateViewer)
526 // Convert shape types to selection types
528 foreach(int aType, theModes) {
529 aModes.append(getSelectionMode(aType));
532 #ifdef DEBUG_ACTIVATE_OBJECTS
534 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
535 for (; anIt != aLast; ++anIt) {
536 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
538 QString anInfoStr = anInfo.join(", ");
540 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
541 arg(getModesInfo(aModes)).
542 arg(getModesInfo(myActiveSelectionModes)).
543 arg(theObjList.size()).
545 toStdString().c_str());
547 // In order to avoid doblications of selection modes
549 foreach (int aMode, aModes) {
550 if (!aNewModes.contains(aMode))
551 aNewModes.append(aMode);
553 myActiveSelectionModes = aNewModes;
554 Handle(AIS_InteractiveContext) aContext = AISContext();
555 // Open local context if there is no one
556 if (aContext.IsNull() || !aContext->HasOpenedContext())
559 //aContext->UseDisplayedObjects();
560 //myUseExternalObjects = true;
562 Handle(AIS_InteractiveObject) anAISIO;
563 AIS_ListOfInteractive aPrsList;
564 //if (aObjList.isEmpty())
567 foreach(ObjectPtr aObj, theObjList) {
568 if (myResult2AISObjectMap.contains(aObj))
569 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
573 // Add trihedron because it has to partisipate in selection
574 Handle(AIS_InteractiveObject) aTrihedron;
575 if (isTrihedronActive()) {
576 aTrihedron = getTrihedron();
577 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
578 aPrsList.Append(aTrihedron);
580 if (aPrsList.Extent() == 0)
583 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
584 bool isActivationChanged = false;
585 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
586 anAISIO = aLIt.Value();
587 if (activate(anAISIO, myActiveSelectionModes, false))
588 isActivationChanged = true;
592 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
594 Handle(AIS_InteractiveContext) aContext = AISContext();
595 if (aContext.IsNull() || !isVisible(theObject))
598 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
599 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
601 TColStd_ListOfInteger aModes;
602 aContext->ActivatedModes(anAIS, aModes);
603 return aModes.Extent() > 0;
607 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
609 Handle(AIS_InteractiveContext) aContext = AISContext();
610 if (aContext.IsNull())
612 if (aContext->HasOpenedContext()) {
613 aContext->UnhilightSelected(false);
614 aContext->ClearSelected(false);
615 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>> aShapesToBeSelected;
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 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
628 if (aShapesToBeSelected.IsBound(aShape))
629 aPresentations = aShapesToBeSelected.Find(aShape);
630 ObjectPtr anObject = aPrs->object();
631 getPresentations(anObject, aPresentations);
633 aShapesToBeSelected.Bind(aShape, aPresentations);
636 ObjectPtr anObject = aPrs->object();
637 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
638 if (aResult.get() && isVisible(aResult)) {
639 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
640 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
641 if (!anAIS.IsNull()) {
642 // The methods are replaced in order to provide multi-selection, e.g. restore selection
643 // by activating multi selector widget. It also gives an advantage that the multi
644 // selection in OB gives multi-selection in the viewer
645 //aContext->SetSelected(anAIS, false);
646 // The selection in the context was cleared, so the method sets the objects are selected
647 aContext->AddOrRemoveSelected(anAIS, false);
652 if (!aShapesToBeSelected.IsEmpty())
653 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
654 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
655 aContext->UnhilightCurrents(false);
656 aContext->ClearCurrents(false);
657 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
658 ObjectPtr anObject = aPrs->object();
659 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
660 if (aResult.get() && isVisible(aResult)) {
661 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
662 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
664 aContext->SetCurrentObject(anAIS, false);
668 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::setSelected -- AddOrRemoveSelected/UnhilightCurrents(no local context)");
673 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
675 Handle(AIS_InteractiveContext) aContext = AISContext();
676 if (!aContext.IsNull()) {
677 aContext->UnhilightCurrents(false);
678 aContext->ClearSelected(theUpdateViewer);
682 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
684 bool aErased = false;
685 Handle(AIS_InteractiveContext) aContext = AISContext();
686 if (!aContext.IsNull()) {
687 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
688 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
690 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
691 if (!anIO.IsNull()) {
692 emit beforeObjectErase(aObj, aAISObj);
693 aContext->Remove(anIO, false/*update viewer*/);
700 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAll -- Remove");
701 myResult2AISObjectMap.clear();
704 qDebug(getResult2AISObjectMapInfo().c_str());
709 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
710 Handle(AIS_InteractiveObject) theObject,
711 const bool theClear = true)
713 if (!theObject.IsNull()) {
714 theContext->Deactivate(theObject);
715 ModuleBase_Tools::selectionInfo(theContext, "XGUI_Displayer::deactivateObject -- Deactivate");
717 //theObject->ClearSelected();
718 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
723 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
725 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
726 Handle(AIS_InteractiveContext) aContext = AISContext();
727 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
728 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
729 deactivateObject(aContext, aTrie);
731 /// #1136 hidden axis are selected in sketch
732 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
733 /// for Position AIS object in SelectionModes.
734 deactivateObject(aContext, aTrie->XAxis());
735 deactivateObject(aContext, aTrie->YAxis());
736 deactivateObject(aContext, aTrie->Axis());
737 deactivateObject(aContext, aTrie->Position());
739 deactivateObject(aContext, aTrie->XYPlane());
740 deactivateObject(aContext, aTrie->XZPlane());
741 deactivateObject(aContext, aTrie->YZPlane());
748 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
750 return myWorkshop->viewer()->trihedron();
753 void XGUI_Displayer::openLocalContext()
755 Handle(AIS_InteractiveContext) aContext = AISContext();
756 // Open local context if there is no one
757 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
758 // Preserve selected objects
759 //AIS_ListOfInteractive aAisList;
760 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
761 // aAisList.Append(aContext->Current());
763 // get the filters from the global context and append them to the local context
764 // a list of filters in the global context is not cleared and should be cleared here
765 SelectMgr_ListOfFilter aFilters;
766 aFilters.Assign(aContext->Filters());
767 // it is important to remove the filters in the global context, because there is a code
768 // in the closeLocalContex, which restore the global context filters
769 aContext->RemoveFilters();
771 //aContext->ClearCurrents();
772 aContext->OpenLocalContext();
773 //deactivateTrihedron();
774 //aContext->NotUseDisplayedObjects();
776 //myUseExternalObjects = false;
778 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
779 for (;aIt.More(); aIt.Next()) {
780 aContext->AddFilter(aIt.Value());
783 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
784 //for(; aIt2.More(); aIt2.Next()) {
785 // aContext->SetSelected(aIt2.Value(), false);
790 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
792 Handle(AIS_InteractiveContext) aContext = AISContext();
793 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
794 // Preserve selected objects
795 //AIS_ListOfInteractive aAisList;
796 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
797 // aAisList.Append(aContext->SelectedInteractive());
799 // get the filters from the local context and append them to the global context
800 // a list of filters in the local context is cleared
801 SelectMgr_ListOfFilter aFilters;
802 aFilters.Assign(aContext->Filters());
804 //aContext->ClearSelected();
805 aContext->CloseAllContexts(false);
807 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
808 // this code is obsolete. It is temporaty commented and should be removed after
809 // the test campaign.
810 // Redisplay all object if they were displayed in localContext
811 /*Handle(AIS_InteractiveObject) aAISIO;
812 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
813 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
814 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
815 aContext->Display(aAISIO, false);
816 aContext->SetDisplayMode(aAISIO, Shading, false);
820 // Append the filters from the local selection in the global selection context
821 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
822 for (;aIt.More(); aIt.Next()) {
823 Handle(SelectMgr_Filter) aFilter = aIt.Value();
824 aContext->AddFilter(aFilter);
829 //myUseExternalObjects = false;
832 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
833 //for(; aIt2.More(); aIt2.Next()) {
834 // if (aContext->IsDisplayed(aIt2.Value()))
835 // aContext->SetCurrentObject(aIt2.Value(), false);
840 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
843 if (myResult2AISObjectMap.contains(theObject))
844 anIO = myResult2AISObjectMap[theObject];
848 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
850 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
851 return getObject(aRefAIS);
854 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
857 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
858 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
859 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
865 if (!anObject.get()) {
866 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
867 if (!theIO.IsNull()) {
868 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
870 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
875 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
877 bool aWasEnabled = isUpdateEnabled();
879 myViewerBlockedRecursiveCount--;
881 myViewerBlockedRecursiveCount++;
883 if (myNeedUpdate && isUpdateEnabled()) {
885 myNeedUpdate = false;
890 bool XGUI_Displayer::isUpdateEnabled() const
892 return myViewerBlockedRecursiveCount == 0;
895 void XGUI_Displayer::updateViewer() const
897 Handle(AIS_InteractiveContext) aContext = AISContext();
898 if (!aContext.IsNull() && isUpdateEnabled()) {
899 myWorkshop->viewer()->Zfitall();
900 aContext->UpdateCurrentViewer();
906 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
907 const int theMode, const bool theUpdateViewer) const
909 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
910 if (!theIO.IsNull() && theIO == getTrihedron()) {
911 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
912 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
915 if (!aContext.IsNull()) {
916 if (myWorkshop->module()) {
917 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
918 aContext->Activate(theIO, theMode, false);
920 aContext->Activate(theIO, theMode, false);
922 // the fix from VPA for more suitable selection of sketcher lines
923 if (theIO->Width() > 1) {
924 double aPrecision = theIO->Width() + 2;
925 if (theMode == getSelectionMode(TopAbs_VERTEX))
926 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer", "point-selection-sensitivity", 20);
927 else if ((theMode == getSelectionMode(TopAbs_EDGE)) || (theMode == getSelectionMode(TopAbs_WIRE)))
928 aPrecision = theIO->Width() +
929 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer", "edge-selection-sensitivity", 2);
930 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
932 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activateAIS -- Activate");
934 #ifdef DEBUG_ACTIVATE_AIS
935 ObjectPtr anObject = getObject(theIO);
936 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
937 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
944 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
946 Handle(AIS_InteractiveContext) aContext = AISContext();
947 if (!aContext.IsNull()) {
949 aContext->Deactivate(theIO);
951 aContext->Deactivate(theIO, theMode);
952 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivateAIS -- Deactivate");
954 #ifdef DEBUG_DEACTIVATE_AIS
955 ObjectPtr anObject = getObject(theIO);
956 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
957 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
962 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
964 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
965 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
966 aContext->OpenLocalContext();
967 if (!isTrihedronActive())
968 deactivateTrihedron(true);
969 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
970 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
975 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
977 Handle(AIS_InteractiveContext) aContext = AISContext();
978 if (!aContext.IsNull() && myAndFilter.IsNull()) {
979 myAndFilter = new SelectMgr_AndFilter();
980 aContext->AddFilter(myAndFilter);
985 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
986 bool theUpdateViewer)
988 bool aDisplayed = false;
989 Handle(AIS_InteractiveContext) aContext = AISContext();
990 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
991 if (!aContext.IsNull() && !anAISIO.IsNull()) {
992 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
994 aContext->Deactivate(anAISIO);
995 aContext->Load(anAISIO);
996 if (toActivateInSelectionModes) {
997 if (aContext->HasOpenedContext()) {
998 if (myActiveSelectionModes.size() == 0)
999 activateAIS(anAISIO, 0, theUpdateViewer);
1001 foreach(int aMode, myActiveSelectionModes) {
1002 activateAIS(anAISIO, aMode, theUpdateViewer);
1007 if (theUpdateViewer)
1013 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1015 bool aErased = false;
1016 Handle(AIS_InteractiveContext) aContext = AISContext();
1017 if (!aContext.IsNull()) {
1018 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1019 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1020 aContext->Remove(anAISIO, false/*update viewer*/);
1021 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAIS -- Remove");
1025 if (aErased && theUpdateViewer)
1031 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1033 if (theMode == NoMode)
1036 Handle(AIS_InteractiveContext) aContext = AISContext();
1037 if (aContext.IsNull())
1040 AISObjectPtr aAISObj = getAISObject(theObject);
1044 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1045 aContext->SetDisplayMode(aAISIO, theMode, false);
1046 // Redisplay in order to update new mode because it could be not computed before
1047 if (theUpdateViewer)
1051 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1053 Handle(AIS_InteractiveContext) aContext = AISContext();
1054 if (aContext.IsNull())
1057 AISObjectPtr aAISObj = getAISObject(theObject);
1061 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1062 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1065 void XGUI_Displayer::deactivateSelectionFilters()
1067 Handle(AIS_InteractiveContext) aContext = AISContext();
1068 if (!myAndFilter.IsNull()) {
1069 bool aFound = false;
1070 if (!aContext.IsNull()) {
1071 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1072 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1073 for (; anIt.More() && !aFound; anIt.Next()) {
1074 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1075 aFound = aFilter == myAndFilter;
1078 aContext->RemoveFilter(myAndFilter);
1080 myAndFilter.Nullify();
1084 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1086 Handle(AIS_InteractiveContext) aContext = AISContext();
1087 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1090 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1091 if (!aCompositeFilter.IsNull()) {
1092 aCompositeFilter->Add(theFilter);
1093 #ifdef DEBUG_SELECTION_FILTERS
1094 int aCount = aCompositeFilter->StoredFilters().Extent();
1095 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1100 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1102 Handle(AIS_InteractiveContext) aContext = AISContext();
1103 if (aContext.IsNull())
1106 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1107 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1108 aCompositeFilter->Remove(theFilter);
1109 #ifdef DEBUG_SELECTION_FILTERS
1110 int aCount = aCompositeFilter->StoredFilters().Extent();
1111 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1116 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1118 bool aFilterFound = false;
1120 Handle(AIS_InteractiveContext) aContext = AISContext();
1121 if (aContext.IsNull())
1122 return aFilterFound;
1123 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1124 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1125 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1126 if (theFilter.Access() == aIt.Value().Access())
1127 aFilterFound = true;
1129 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1130 if (!aCompositeFilter.IsNull()) {
1131 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1132 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1133 if (theFilter.Access() == aIt.Value().Access())
1134 aFilterFound = true;
1137 return aFilterFound;
1140 void XGUI_Displayer::removeFilters()
1142 Handle(AIS_InteractiveContext) aContext = AISContext();
1143 if (aContext.IsNull())
1146 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1147 if (!aCompositeFilter.IsNull())
1148 aCompositeFilter->Clear();
1151 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1153 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1154 foreach(ObjectPtr aObj, aDispList) {
1155 if (!theList.contains(aObj))
1158 foreach(ObjectPtr aObj, theList) {
1159 if (!isVisible(aObj))
1160 display(aObj, false);
1165 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1167 if (!isVisible(theObject))
1170 AISObjectPtr aAISObj = getAISObject(theObject);
1171 if (aAISObj.get() == NULL)
1174 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1175 return ::canBeShaded(anAIS, myWorkshop->module());
1178 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1179 const QIntList& theModes,
1180 const bool theUpdateViewer) const
1182 Handle(AIS_InteractiveContext) aContext = AISContext();
1183 if (aContext.IsNull() || theIO.IsNull())
1186 bool isActivationChanged = false;
1187 // deactivate object in all modes, which are not in the list of activation
1188 // It seems that after the IO deactivation the selected state of the IO's owners
1189 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1190 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1191 // only if there is a difference in the current modes and the parameters modes.
1192 // If the selection problem happens again, it is possible to write a test scenario and create
1193 // a bug. The bug steps are the following:
1194 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1195 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1196 TColStd_ListOfInteger aTColModes;
1197 aContext->ActivatedModes(theIO, aTColModes);
1198 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1199 QIntList aModesActivatedForIO;
1200 bool isDeactivated = false;
1201 for (; itr.More(); itr.Next() ) {
1202 Standard_Integer aMode = itr.Value();
1203 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1204 if (!theModes.contains(aMode)) {
1205 deactivateAIS(theIO, aMode);
1206 isDeactivated = true;
1209 aModesActivatedForIO.append(aMode);
1212 if (isDeactivated) {
1213 // the selection from the previous activation modes should be cleared manually (#26172)
1214 theIO->ClearSelected();
1215 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1216 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activate -- ClearSelected/ClearOutdatedSelection");
1217 // For performance issues
1218 //if (theUpdateViewer)
1220 isActivationChanged = true;
1223 // loading the interactive object allowing the decomposition
1224 if (aTColModes.IsEmpty()) {
1225 aContext->Load(theIO, -1, true);
1228 // trihedron AIS check should be after the AIS loading.
1229 // If it is not loaded, it is steel selectable in the viewer.
1230 Handle(AIS_Trihedron) aTrihedron;
1231 if (!isTrihedronActive())
1232 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1233 if (aTrihedron.IsNull()) {
1234 // In order to clear active modes list
1235 if (theModes.size() == 0) {
1236 activateAIS(theIO, 0, theUpdateViewer);
1238 foreach(int aMode, theModes) {
1239 if (!aModesActivatedForIO.contains(aMode)) {
1240 activateAIS(theIO, aMode, theUpdateViewer);
1241 isActivationChanged = true;
1246 return isActivationChanged;
1249 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1251 AISObjectPtr anAISObj = getAISObject(theObject);
1252 // correct the result's color it it has the attribute
1253 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1255 // Customization of presentation
1256 GeomCustomPrsPtr aCustomPrs;
1257 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1258 if (aFeature.get() != NULL) {
1259 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1260 if (aCustPrs.get() != NULL)
1261 aCustomPrs = aCustPrs;
1263 if (aCustomPrs.get() == NULL) {
1264 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1265 // we ignore presentable not customized objects
1266 if (aPrs.get() == NULL)
1267 aCustomPrs = myCustomPrs;
1269 bool isCustomized = aCustomPrs.get() &&
1270 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1271 return isCustomized;
1275 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1277 if (!isVisible(theObject))
1280 AISObjectPtr anAISObj = getAISObject(theObject);
1282 anAISObj->getColor(aR, aG, aB);
1283 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1284 if (theUpdateViewer)
1286 return QColor(aR, aG, aB);
1289 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1291 myResult2AISObjectMap[theObject] = theAIS;
1293 #ifdef DEBUG_DISPLAY
1294 std::ostringstream aPtrStr;
1295 aPtrStr << theObject.get();
1296 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1297 qDebug(getResult2AISObjectMapInfo().c_str());
1301 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1303 QStringList aContent;
1304 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1305 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1306 std::ostringstream aPtrStr;
1307 aPtrStr << "aObj = " << aObj.get() << ":";
1308 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1309 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1311 aContent.append(aPtrStr.str().c_str());
1313 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1314 arg(aContent.join("\n")).toStdString().c_str();
1317 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1318 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1320 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1321 if (aResult.get()) {
1322 AISObjectPtr aAISObj = getAISObject(aResult);
1323 if (aAISObj.get() != NULL) {
1324 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1325 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1326 thePresentations.Add(anAIS);
1330 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1331 // find presentation of the feature
1332 AISObjectPtr aAISObj = getAISObject(aFeature);
1333 if (aAISObj.get() != NULL) {
1334 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1335 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1336 thePresentations.Add(anAIS);
1338 // find presentations of the feature results
1339 std::list<ResultPtr> aResults;
1340 ModelAPI_Tools::allResults(aFeature, aResults);
1341 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1342 for (; anIt != aLast; ++anIt) {
1343 AISObjectPtr aAISObj = getAISObject(*anIt);
1344 if (aAISObj.get() != NULL) {
1345 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1346 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1347 thePresentations.Add(anAIS);
1353 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1355 myIsTrihedronActive = theIsActive;
1356 if (!myIsTrihedronActive) {
1357 deactivateTrihedron(true);
1361 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1363 Handle(AIS_InteractiveContext) aContext = AISContext();
1364 if (aContext.IsNull())
1367 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1370 if (!aContext->IsDisplayed(aTrihedron))
1371 aContext->Display(aTrihedron,
1373 -1 /* selection mode */,
1374 Standard_True /* update viewer*/,
1375 Standard_False /* allow decomposition */,
1376 AIS_DS_Displayed /* xdisplay status */);
1378 if (!isTrihedronActive())
1379 deactivateTrihedron(false);
1381 activate(aTrihedron, myActiveSelectionModes, false);
1383 deactivateTrihedron(false);
1384 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1385 // the selection from the previous activation modes should be cleared manually (#26172)
1387 aContext->Erase(aTrihedron);
1393 QIntList XGUI_Displayer::activeSelectionModes() const
1396 foreach (int aMode, myActiveSelectionModes) {
1397 // aMode < 9 is a Shape Enum values
1398 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1403 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1404 const NCollection_DataMap<TopoDS_Shape,
1405 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1407 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1408 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1409 aLContext->UnhilightPicked(Standard_False);
1411 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1412 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1413 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1414 Handle(SelectMgr_EntityOwner) anOwner;
1416 /// It is very important to check that the owner is processed only once and has a map of
1417 /// processed owners because SetSelected works as a switch.
1418 /// If count of calls setSelectec is even, the object stays in the previous state
1419 /// (selected, deselected)
1420 /// OCCT: to write about the problem that active owners method returns one owner several times
1421 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1422 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1423 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1424 if (aSelectedIds.contains((long)anOwner.Access()))
1426 aSelectedIds.append((long)anOwner.Access());
1428 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1429 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1430 const TopoDS_Shape& aShape = BROwnr->Shape();
1431 if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
1432 Handle(AIS_InteractiveObject) anOwnerPresentation =
1433 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1434 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1435 theShapesToBeSelected.Find(aShape);
1436 if (aPresentations.Contains(anOwnerPresentation)) {
1437 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1438 anOwner->SetSelected (Standard_True);
1443 aLContext->HilightPicked(Standard_False);