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 = aFeature->results();
480 std::list<ResultPtr>::const_iterator aIt;
481 aVisible = !aResults.empty();
482 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
483 aVisible = aVisible && theDisplayer->isVisible(*aIt);
489 #ifdef DEBUG_ACTIVATE_OBJECTS
490 QString getModeInfo(const int theMode)
492 QString anInfo = "Undefined";
494 case 0: anInfo = "SHAPE(0)"; break;
495 case 1: anInfo = "VERTEX(1)"; break;
496 case 2: anInfo = "EDGE(2)"; break;
497 case 3: anInfo = "WIRE(3)"; break;
498 case 4: anInfo = "FACE(4)"; break;
499 case 5: anInfo = "SHELL(5)"; break;
500 case 6: anInfo = "SOLID(6)"; break;
501 case 7: anInfo = "COMPSOLID(7)"; break;
502 case 8: anInfo = "COMPOUND(8)"; break;
503 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
504 case 101: anInfo = "Sel_Constraint(101)"; break;
505 case 102: anInfo = "Sel_Dimension_All(102)"; break;
506 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
507 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
513 QString getModesInfo(const QIntList& theModes)
515 QStringList aModesInfo;
516 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
517 aModesInfo.append(getModeInfo(theModes[i]));
518 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
522 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
523 const bool theUpdateViewer)
525 // Convert shape types to selection types
527 foreach(int aType, theModes) {
528 aModes.append(getSelectionMode(aType));
531 #ifdef DEBUG_ACTIVATE_OBJECTS
533 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
534 for (; anIt != aLast; ++anIt) {
535 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
537 QString anInfoStr = anInfo.join(", ");
539 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
540 arg(getModesInfo(aModes)).
541 arg(getModesInfo(myActiveSelectionModes)).
542 arg(theObjList.size()).
544 toStdString().c_str());
546 // In order to avoid doblications of selection modes
548 foreach (int aMode, aModes) {
549 if (!aNewModes.contains(aMode))
550 aNewModes.append(aMode);
552 myActiveSelectionModes = aNewModes;
553 Handle(AIS_InteractiveContext) aContext = AISContext();
554 // Open local context if there is no one
555 if (aContext.IsNull() || !aContext->HasOpenedContext())
558 //aContext->UseDisplayedObjects();
559 //myUseExternalObjects = true;
561 Handle(AIS_InteractiveObject) anAISIO;
562 AIS_ListOfInteractive aPrsList;
563 //if (aObjList.isEmpty())
566 foreach(ObjectPtr aObj, theObjList) {
567 if (myResult2AISObjectMap.contains(aObj))
568 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
572 // Add trihedron because it has to partisipate in selection
573 Handle(AIS_InteractiveObject) aTrihedron;
574 if (isTrihedronActive()) {
575 aTrihedron = getTrihedron();
576 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
577 aPrsList.Append(aTrihedron);
579 if (aPrsList.Extent() == 0)
582 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
583 bool isActivationChanged = false;
584 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
585 anAISIO = aLIt.Value();
586 if (activate(anAISIO, myActiveSelectionModes, false))
587 isActivationChanged = true;
591 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
593 Handle(AIS_InteractiveContext) aContext = AISContext();
594 if (aContext.IsNull() || !isVisible(theObject))
597 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
598 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
600 TColStd_ListOfInteger aModes;
601 aContext->ActivatedModes(anAIS, aModes);
602 return aModes.Extent() > 0;
604 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues, bool theUpdateViewer)
606 Handle(AIS_InteractiveContext) aContext = AISContext();
607 if (aContext.IsNull())
609 if (aContext->HasOpenedContext()) {
610 aContext->UnhilightSelected(false);
611 aContext->ClearSelected(false);
612 NCollection_Map<TopoDS_Shape> aShapesToBeSelected;
614 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
615 const GeomShapePtr& aGeomShape = aPrs->shape();
616 if (aGeomShape.get() && !aGeomShape->isNull()) {
617 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
618 #ifdef DEBUG_OCCT_SHAPE_SELECTION
619 aContext->AddOrRemoveSelected(aShape, false);
621 aShapesToBeSelected.Add(aShape);
624 ObjectPtr anObject = aPrs->object();
625 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
626 if (aResult.get() && isVisible(aResult)) {
627 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
628 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
629 if (!anAIS.IsNull()) {
630 // The methods are replaced in order to provide multi-selection, e.g. restore selection
631 // by activating multi selector widget. It also gives an advantage that the multi
632 // selection in OB gives multi-selection in the viewer
633 //aContext->SetSelected(anAIS, false);
634 // The selection in the context was cleared, so the method sets the objects are selected
635 aContext->AddOrRemoveSelected(anAIS, false);
640 if (!aShapesToBeSelected.IsEmpty())
641 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
642 } else { // it seems the next code is obsolete as the context is always opened in SHAPER
643 aContext->UnhilightCurrents(false);
644 aContext->ClearCurrents(false);
645 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
646 ObjectPtr anObject = aPrs->object();
647 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
648 if (aResult.get() && isVisible(aResult)) {
649 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
650 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
652 aContext->SetCurrentObject(anAIS, false);
656 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::setSelected -- AddOrRemoveSelected/UnhilightCurrents(no local context)");
661 void XGUI_Displayer::clearSelected()
663 Handle(AIS_InteractiveContext) aContext = AISContext();
664 if (!aContext.IsNull()) {
665 aContext->UnhilightCurrents(false);
666 aContext->ClearSelected();
670 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
672 bool aErased = false;
673 Handle(AIS_InteractiveContext) aContext = AISContext();
674 if (!aContext.IsNull()) {
675 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
676 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
678 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
679 if (!anIO.IsNull()) {
680 emit beforeObjectErase(aObj, aAISObj);
681 aContext->Remove(anIO, false/*update viewer*/);
688 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAll -- Remove");
689 myResult2AISObjectMap.clear();
692 qDebug(getResult2AISObjectMapInfo().c_str());
697 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
698 Handle(AIS_InteractiveObject) theObject,
699 const bool theClear = true)
701 if (!theObject.IsNull()) {
702 theContext->Deactivate(theObject);
703 ModuleBase_Tools::selectionInfo(theContext, "XGUI_Displayer::deactivateObject -- Deactivate");
705 //theObject->ClearSelected();
706 // theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
711 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
713 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
714 Handle(AIS_InteractiveContext) aContext = AISContext();
715 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
716 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
717 deactivateObject(aContext, aTrie);
719 /// #1136 hidden axis are selected in sketch
720 /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
721 /// for Position AIS object in SelectionModes.
722 deactivateObject(aContext, aTrie->XAxis());
723 deactivateObject(aContext, aTrie->YAxis());
724 deactivateObject(aContext, aTrie->Axis());
725 deactivateObject(aContext, aTrie->Position());
727 deactivateObject(aContext, aTrie->XYPlane());
728 deactivateObject(aContext, aTrie->XZPlane());
729 deactivateObject(aContext, aTrie->YZPlane());
736 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
738 return myWorkshop->viewer()->trihedron();
741 void XGUI_Displayer::openLocalContext()
743 Handle(AIS_InteractiveContext) aContext = AISContext();
744 // Open local context if there is no one
745 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
746 // Preserve selected objects
747 //AIS_ListOfInteractive aAisList;
748 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
749 // aAisList.Append(aContext->Current());
751 // get the filters from the global context and append them to the local context
752 // a list of filters in the global context is not cleared and should be cleared here
753 SelectMgr_ListOfFilter aFilters;
754 aFilters.Assign(aContext->Filters());
755 // it is important to remove the filters in the global context, because there is a code
756 // in the closeLocalContex, which restore the global context filters
757 aContext->RemoveFilters();
759 //aContext->ClearCurrents();
760 aContext->OpenLocalContext();
761 //deactivateTrihedron();
762 //aContext->NotUseDisplayedObjects();
764 //myUseExternalObjects = false;
766 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
767 for (;aIt.More(); aIt.Next()) {
768 aContext->AddFilter(aIt.Value());
771 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
772 //for(; aIt2.More(); aIt2.Next()) {
773 // aContext->SetSelected(aIt2.Value(), false);
778 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
780 Handle(AIS_InteractiveContext) aContext = AISContext();
781 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
782 // Preserve selected objects
783 //AIS_ListOfInteractive aAisList;
784 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
785 // aAisList.Append(aContext->SelectedInteractive());
787 // get the filters from the local context and append them to the global context
788 // a list of filters in the local context is cleared
789 SelectMgr_ListOfFilter aFilters;
790 aFilters.Assign(aContext->Filters());
792 //aContext->ClearSelected();
793 aContext->CloseAllContexts(false);
795 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
796 // this code is obsolete. It is temporaty commented and should be removed after
797 // the test campaign.
798 // Redisplay all object if they were displayed in localContext
799 /*Handle(AIS_InteractiveObject) aAISIO;
800 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
801 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
802 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
803 aContext->Display(aAISIO, false);
804 aContext->SetDisplayMode(aAISIO, Shading, false);
808 // Append the filters from the local selection in the global selection context
809 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
810 for (;aIt.More(); aIt.Next()) {
811 Handle(SelectMgr_Filter) aFilter = aIt.Value();
812 aContext->AddFilter(aFilter);
817 //myUseExternalObjects = false;
820 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
821 //for(; aIt2.More(); aIt2.Next()) {
822 // if (aContext->IsDisplayed(aIt2.Value()))
823 // aContext->SetCurrentObject(aIt2.Value(), false);
828 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
831 if (myResult2AISObjectMap.contains(theObject))
832 anIO = myResult2AISObjectMap[theObject];
836 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
838 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
839 return getObject(aRefAIS);
842 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
845 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
846 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
847 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
853 if (!anObject.get()) {
854 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
855 if (!theIO.IsNull()) {
856 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
858 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
863 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
865 bool aWasEnabled = isUpdateEnabled();
867 myViewerBlockedRecursiveCount--;
869 myViewerBlockedRecursiveCount++;
871 if (myNeedUpdate && isUpdateEnabled()) {
873 myNeedUpdate = false;
878 bool XGUI_Displayer::isUpdateEnabled() const
880 return myViewerBlockedRecursiveCount == 0;
883 void XGUI_Displayer::updateViewer() const
885 Handle(AIS_InteractiveContext) aContext = AISContext();
886 if (!aContext.IsNull() && isUpdateEnabled()) {
887 myWorkshop->viewer()->Zfitall();
888 aContext->UpdateCurrentViewer();
894 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
895 const int theMode, const bool theUpdateViewer) const
897 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
898 if (!aContext.IsNull()) {
899 if (myWorkshop->module()) {
900 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
901 aContext->Activate(theIO, theMode, false);
903 aContext->Activate(theIO, theMode, false);
905 // the fix from VPA for more suitable selection of sketcher lines
906 if (theIO->Width() > 1) {
907 double aPrecision = theIO->Width() + 2;
908 if (theMode == getSelectionMode(TopAbs_VERTEX))
909 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer", "point-selection-sensitivity", 20);
910 else if ((theMode == getSelectionMode(TopAbs_EDGE)) || (theMode == getSelectionMode(TopAbs_WIRE)))
911 aPrecision = theIO->Width() +
912 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer", "edge-selection-sensitivity", 2);
913 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
915 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activateAIS -- Activate");
917 #ifdef DEBUG_ACTIVATE_AIS
918 ObjectPtr anObject = getObject(theIO);
919 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
920 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
927 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
929 Handle(AIS_InteractiveContext) aContext = AISContext();
930 if (!aContext.IsNull()) {
932 aContext->Deactivate(theIO);
934 aContext->Deactivate(theIO, theMode);
935 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::deactivateAIS -- Deactivate");
937 #ifdef DEBUG_DEACTIVATE_AIS
938 ObjectPtr anObject = getObject(theIO);
939 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
940 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
945 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
947 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
948 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
949 aContext->OpenLocalContext();
950 if (!isTrihedronActive())
951 deactivateTrihedron(true);
952 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
953 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
958 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
960 Handle(AIS_InteractiveContext) aContext = AISContext();
961 if (!aContext.IsNull() && myAndFilter.IsNull()) {
962 myAndFilter = new SelectMgr_AndFilter();
963 aContext->AddFilter(myAndFilter);
968 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
969 bool theUpdateViewer)
971 bool aDisplayed = false;
972 Handle(AIS_InteractiveContext) aContext = AISContext();
973 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
974 if (!aContext.IsNull() && !anAISIO.IsNull()) {
975 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
977 aContext->Deactivate(anAISIO);
978 aContext->Load(anAISIO);
979 if (toActivateInSelectionModes) {
980 if (aContext->HasOpenedContext()) {
981 if (myActiveSelectionModes.size() == 0)
982 activateAIS(anAISIO, 0, theUpdateViewer);
984 foreach(int aMode, myActiveSelectionModes) {
985 activateAIS(anAISIO, aMode, theUpdateViewer);
996 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
998 bool aErased = false;
999 Handle(AIS_InteractiveContext) aContext = AISContext();
1000 if (!aContext.IsNull()) {
1001 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1002 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1003 aContext->Remove(anAISIO, false/*update viewer*/);
1004 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::eraseAIS -- Remove");
1008 if (aErased && theUpdateViewer)
1014 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1016 if (theMode == NoMode)
1019 Handle(AIS_InteractiveContext) aContext = AISContext();
1020 if (aContext.IsNull())
1023 AISObjectPtr aAISObj = getAISObject(theObject);
1027 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1028 aContext->SetDisplayMode(aAISIO, theMode, false);
1029 // Redisplay in order to update new mode because it could be not computed before
1030 if (theUpdateViewer)
1034 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
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 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1048 void XGUI_Displayer::deactivateSelectionFilters()
1050 Handle(AIS_InteractiveContext) aContext = AISContext();
1051 if (!myAndFilter.IsNull()) {
1052 bool aFound = false;
1053 if (!aContext.IsNull()) {
1054 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1055 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1056 for (; anIt.More() && !aFound; anIt.Next()) {
1057 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1058 aFound = aFilter == myAndFilter;
1061 aContext->RemoveFilter(myAndFilter);
1063 myAndFilter.Nullify();
1067 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1069 Handle(AIS_InteractiveContext) aContext = AISContext();
1070 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1073 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1074 if (!aCompositeFilter.IsNull()) {
1075 aCompositeFilter->Add(theFilter);
1076 #ifdef DEBUG_SELECTION_FILTERS
1077 int aCount = aCompositeFilter->StoredFilters().Extent();
1078 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1083 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1085 Handle(AIS_InteractiveContext) aContext = AISContext();
1086 if (aContext.IsNull())
1089 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1090 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1091 aCompositeFilter->Remove(theFilter);
1092 #ifdef DEBUG_SELECTION_FILTERS
1093 int aCount = aCompositeFilter->StoredFilters().Extent();
1094 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1099 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1101 bool aFilterFound = false;
1103 Handle(AIS_InteractiveContext) aContext = AISContext();
1104 if (aContext.IsNull())
1105 return aFilterFound;
1106 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1107 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1108 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1109 if (theFilter.Access() == aIt.Value().Access())
1110 aFilterFound = true;
1112 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1113 if (!aCompositeFilter.IsNull()) {
1114 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1115 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1116 if (theFilter.Access() == aIt.Value().Access())
1117 aFilterFound = true;
1120 return aFilterFound;
1123 void XGUI_Displayer::removeFilters()
1125 Handle(AIS_InteractiveContext) aContext = AISContext();
1126 if (aContext.IsNull())
1129 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1130 if (!aCompositeFilter.IsNull())
1131 aCompositeFilter->Clear();
1134 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1136 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1137 foreach(ObjectPtr aObj, aDispList) {
1138 if (!theList.contains(aObj))
1141 foreach(ObjectPtr aObj, theList) {
1142 if (!isVisible(aObj))
1143 display(aObj, false);
1148 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1150 if (!isVisible(theObject))
1153 AISObjectPtr aAISObj = getAISObject(theObject);
1154 if (aAISObj.get() == NULL)
1157 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1158 return ::canBeShaded(anAIS, myWorkshop->module());
1161 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1162 const QIntList& theModes,
1163 const bool theUpdateViewer) const
1165 Handle(AIS_InteractiveContext) aContext = AISContext();
1166 if (aContext.IsNull() || theIO.IsNull())
1169 bool isActivationChanged = false;
1170 // deactivate object in all modes, which are not in the list of activation
1171 // It seems that after the IO deactivation the selected state of the IO's owners
1172 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1173 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1174 // only if there is a difference in the current modes and the parameters modes.
1175 // If the selection problem happens again, it is possible to write a test scenario and create
1176 // a bug. The bug steps are the following:
1177 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1178 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
1179 TColStd_ListOfInteger aTColModes;
1180 aContext->ActivatedModes(theIO, aTColModes);
1181 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1182 QIntList aModesActivatedForIO;
1183 bool isDeactivated = false;
1184 for (; itr.More(); itr.Next() ) {
1185 Standard_Integer aMode = itr.Value();
1186 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1187 if (!theModes.contains(aMode)) {
1188 deactivateAIS(theIO, aMode);
1189 isDeactivated = true;
1192 aModesActivatedForIO.append(aMode);
1195 if (isDeactivated) {
1196 // the selection from the previous activation modes should be cleared manually (#26172)
1197 theIO->ClearSelected();
1198 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
1199 ModuleBase_Tools::selectionInfo(aContext, "XGUI_Displayer::activate -- ClearSelected/ClearOutdatedSelection");
1200 // For performance issues
1201 //if (theUpdateViewer)
1203 isActivationChanged = true;
1206 // loading the interactive object allowing the decomposition
1207 if (aTColModes.IsEmpty()) {
1208 aContext->Load(theIO, -1, true);
1211 // trihedron AIS check should be after the AIS loading.
1212 // If it is not loaded, it is steel selectable in the viewer.
1213 Handle(AIS_Trihedron) aTrihedron;
1214 if (!isTrihedronActive())
1215 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1216 if (aTrihedron.IsNull()) {
1217 // In order to clear active modes list
1218 if (theModes.size() == 0) {
1219 activateAIS(theIO, 0, theUpdateViewer);
1221 foreach(int aMode, theModes) {
1222 if (!aModesActivatedForIO.contains(aMode)) {
1223 activateAIS(theIO, aMode, theUpdateViewer);
1224 isActivationChanged = true;
1229 return isActivationChanged;
1232 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1234 AISObjectPtr anAISObj = getAISObject(theObject);
1235 // correct the result's color it it has the attribute
1236 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1238 // Customization of presentation
1239 GeomCustomPrsPtr aCustomPrs;
1240 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1241 if (aFeature.get() != NULL) {
1242 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1243 if (aCustPrs.get() != NULL)
1244 aCustomPrs = aCustPrs;
1246 if (aCustomPrs.get() == NULL) {
1247 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1248 // we ignore presentable not customized objects
1249 if (aPrs.get() == NULL)
1250 aCustomPrs = myCustomPrs;
1252 bool isCustomized = aCustomPrs.get() &&
1253 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1254 return isCustomized;
1258 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
1260 if (!isVisible(theObject))
1263 AISObjectPtr anAISObj = getAISObject(theObject);
1265 anAISObj->getColor(aR, aG, aB);
1266 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1267 if (theUpdateViewer)
1269 return QColor(aR, aG, aB);
1272 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1274 myResult2AISObjectMap[theObject] = theAIS;
1276 #ifdef DEBUG_DISPLAY
1277 std::ostringstream aPtrStr;
1278 aPtrStr << theObject.get();
1279 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1280 qDebug(getResult2AISObjectMapInfo().c_str());
1284 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1286 QStringList aContent;
1287 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1288 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1289 std::ostringstream aPtrStr;
1290 aPtrStr << "aObj = " << aObj.get() << ":";
1291 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1292 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1294 aContent.append(aPtrStr.str().c_str());
1296 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1297 arg(aContent.join("\n")).toStdString().c_str();
1300 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1302 myIsTrihedronActive = theIsActive;
1303 if (!myIsTrihedronActive) {
1304 deactivateTrihedron(true);
1308 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1310 Handle(AIS_InteractiveContext) aContext = AISContext();
1311 if (aContext.IsNull())
1314 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1317 if (!aContext->IsDisplayed(aTrihedron))
1318 aContext->Display(aTrihedron,
1320 -1 /* selection mode */,
1321 Standard_True /* update viewer*/,
1322 Standard_False /* allow decomposition */,
1323 AIS_DS_Displayed /* xdisplay status */);
1325 if (!isTrihedronActive())
1326 deactivateTrihedron(false);
1328 activate(aTrihedron, myActiveSelectionModes, false);
1330 deactivateTrihedron(false);
1331 //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
1332 // the selection from the previous activation modes should be cleared manually (#26172)
1334 aContext->Erase(aTrihedron);
1340 QIntList XGUI_Displayer::activeSelectionModes() const
1343 foreach (int aMode, myActiveSelectionModes) {
1344 // aMode < 9 is a Shape Enum values
1345 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1350 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1351 const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected)
1353 Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
1354 TCollection_AsciiString aSelectionName = aLContext->SelectionName();
1355 aLContext->UnhilightPicked(Standard_False);
1357 NCollection_Map<TopoDS_Shape> aShapesSelected;
1359 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1360 aLContext->MainSelector()->ActiveOwners(anActiveOwners);
1361 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1362 Handle(SelectMgr_EntityOwner) anOwner;
1363 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1364 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1365 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1366 if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) {
1367 if (aShapesSelected.Contains(BROwnr->Shape()))
1369 AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
1370 anOwner->SetSelected (Standard_True);
1371 aShapesSelected.Add(BROwnr->Shape());
1374 aLContext->HilightPicked(Standard_False);