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"
14 #include <AppElements_Viewer.h>
16 #include <ModelAPI_Document.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Object.h>
19 #include <ModelAPI_Tools.h>
20 #include <ModelAPI_AttributeIntArray.h>
22 #include <ModuleBase_ResultPrs.h>
23 #include <ModuleBase_Tools.h>
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_IPresentable.h>
27 #include <GeomAPI_ICustomPrs.h>
29 #include <AIS_InteractiveContext.hxx>
30 #include <AIS_LocalContext.hxx>
31 #include <AIS_ListOfInteractive.hxx>
32 #include <AIS_ListIteratorOfListOfInteractive.hxx>
33 #include <AIS_DimensionSelectionMode.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_Dimension.hxx>
36 #include <TColStd_ListIteratorOfListOfInteger.hxx>
37 #include <SelectMgr_ListOfFilter.hxx>
38 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
40 #include <StdSelect_ViewerSelector3d.hxx>
42 #include <TColStd_MapOfTransient.hxx>
43 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
47 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
49 #define DEBUG_CRASH_RESTORE_SELECTION
51 //#define DEBUG_ACTIVATE_OBJECTS
52 //#define DEBUG_DEACTIVATE
53 //#define DEBUG_ACTIVATE_AIS
54 //#define DEBUG_DEACTIVATE_AIS
56 //#define DEBUG_DISPLAY
57 //#define DEBUG_FEATURE_REDISPLAY
58 //#define DEBUG_SELECTION_FILTERS
60 // Workaround for bug #25637
61 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
63 // Get from null point
64 theAIS->DisplayedObjects(theList, true);
65 if (theAIS->HasOpenedContext()) {
66 // get from local context
67 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
68 TColStd_MapOfTransient aMap;
69 int NbDisp = aLC->DisplayedObjects(aMap);
70 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
72 Handle(AIS_InteractiveObject) curIO;
73 Handle(Standard_Transient) Tr;
74 for(; aIt.More(); aIt.Next()){
76 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
77 theList.Append(curIO);
82 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
85 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
86 for (; anIt != aLast; anIt++) {
87 anInfo.append(QString::number(*anIt));
89 return anInfo.join(theSeparator);
92 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
93 : myWorkshop(theWorkshop)
95 enableUpdateViewer(true);
96 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
99 XGUI_Displayer::~XGUI_Displayer()
103 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
105 return myResult2AISObjectMap.contains(theObject);
108 void XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
110 if (isVisible(theObject)) {
111 redisplay(theObject, theUpdateViewer);
115 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
116 bool isShading = false;
117 if (aPrs.get() != NULL) {
118 anAIS = aPrs->getAISObject(anAIS);
120 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
121 if (aResult.get() != NULL) {
122 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
123 if (aShapePtr.get() != NULL) {
124 anAIS = AISObjectPtr(new GeomAPI_AISObject());
125 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
126 //anAIS->createShape(aShapePtr);
132 display(theObject, anAIS, isShading, theUpdateViewer);
136 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
138 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
139 if (!aShapePrs.IsNull()) {
140 TopoDS_Shape aShape = aShapePrs->Shape();
141 TopAbs_ShapeEnum aType = aShape.ShapeType();
142 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
145 // Check that the presentation is not a sketch
146 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
148 return !aPrs->isSketchMode();
155 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
156 bool isShading, bool theUpdateViewer)
158 Handle(AIS_InteractiveContext) aContext = AISContext();
159 if (aContext.IsNull())
162 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
163 if (!anAISIO.IsNull()) {
164 appendResultObject(theObject, theAIS);
166 bool isCustomized = customizeObject(theObject);
168 int aDispMode = isShading? Shading : Wireframe;
170 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
171 anAISIO->SetDisplayMode(aDispMode);
172 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
174 emit objectDisplayed(theObject, theAIS);
175 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
181 void XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
183 if (!isVisible(theObject))
186 Handle(AIS_InteractiveContext) aContext = AISContext();
187 if (aContext.IsNull())
189 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
191 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
192 if (!anAIS.IsNull()) {
193 emit beforeObjectErase(theObject, anObject);
194 aContext->Remove(anAIS, theUpdateViewer);
197 myResult2AISObjectMap.remove(theObject);
200 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
202 if (!isVisible(theObject))
205 AISObjectPtr aAISObj = getAISObject(theObject);
206 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
208 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
210 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
212 erase(theObject, theUpdateViewer);
215 if (aAIS_Obj != aAISObj) {
216 appendResultObject(theObject, aAIS_Obj);
218 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
221 if (!aAISIO.IsNull()) {
222 Handle(AIS_InteractiveContext) aContext = AISContext();
223 if (aContext.IsNull())
225 // Check that the visualized shape is the same and the redisplay is not necessary
226 // Redisplay of AIS object leads to this object selection compute and the selection
227 // in the browser is lost
229 // this check is not necessary anymore because the selection store/restore is realized
230 // before and after the values modification.
231 // Moreother, this check avoids customize and redisplay presentation if the presentable
232 // parameter is changed.
233 bool isEqualShapes = false;
234 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
235 if (aResult.get() != NULL) {
236 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
237 if (!aShapePrs.IsNull()) {
238 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
239 if (aShapePtr.get()) {
240 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
241 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
245 // Customization of presentation
246 bool isCustomized = customizeObject(theObject);
247 #ifdef DEBUG_FEATURE_REDISPLAY
248 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
249 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
251 if (!isEqualShapes || isCustomized) {
252 aContext->Redisplay(aAISIO, false);
253 #ifdef DEBUG_FEATURE_REDISPLAY
254 qDebug(" Redisplay happens");
262 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
264 #ifdef DEBUG_DEACTIVATE
265 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
266 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
267 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
269 toStdString().c_str());
271 if (isVisible(theObject)) {
272 Handle(AIS_InteractiveContext) aContext = AISContext();
273 if (aContext.IsNull())
276 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
277 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
279 deactivateAIS(anAIS);
280 // the selection from the previous activation modes should be cleared manually (#26172)
281 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
287 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
289 if (!isVisible(theObject))
292 Handle(AIS_InteractiveContext) aContext = AISContext();
293 if (aContext.IsNull())
296 AISObjectPtr aAISObj = getAISObject(theObject);
298 if (aAISObj.get() != NULL) {
299 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
300 TColStd_ListOfInteger aTColModes;
301 aContext->ActivatedModes(anAISIO, aTColModes);
302 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
303 for (; itr.More(); itr.Next() ) {
304 theModes.append(itr.Value());
309 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
310 const bool theUpdateViewer)
312 // Convert shape types to selection types
314 foreach(int aType, theModes) {
315 if (aType > TopAbs_SHAPE)
316 aModes.append(aType);
318 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
321 #ifdef DEBUG_ACTIVATE_OBJECTS
323 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
324 for (; anIt != aLast; ++anIt) {
325 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
327 QString anInfoStr = anInfo.join(", ");
329 qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
330 arg(aModes.size()).arg(qIntListInfo(aModes)).
331 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
333 toStdString().c_str());
335 // In order to avoid doblications of selection modes
337 foreach (int aMode, aModes) {
338 if (!aNewModes.contains(aMode))
339 aNewModes.append(aMode);
341 myActiveSelectionModes = aNewModes;
342 Handle(AIS_InteractiveContext) aContext = AISContext();
343 if (aContext.IsNull())
345 // Open local context if there is no one
346 if (!aContext->HasOpenedContext())
349 //aContext->UseDisplayedObjects();
350 //myUseExternalObjects = true;
352 Handle(AIS_InteractiveObject) anAISIO;
353 AIS_ListOfInteractive aPrsList;
354 if (theObjList.isEmpty())
357 foreach(ObjectPtr aObj, theObjList) {
358 if (myResult2AISObjectMap.contains(aObj))
359 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
363 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
364 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
365 anAISIO = aLIt.Value();
366 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
370 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
372 Handle(AIS_InteractiveContext) aContext = AISContext();
373 if (aContext.IsNull())
375 if (!isVisible(theObject))
378 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
379 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
381 TColStd_ListOfInteger aModes;
382 aContext->ActivatedModes(anAIS, aModes);
383 return aModes.Extent() > 0;
385 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer)
387 Handle(AIS_InteractiveContext) aContext = AISContext();
388 if (aContext.IsNull())
390 if (aContext->HasOpenedContext()) {
391 aContext->UnhilightSelected();
392 aContext->ClearSelected();
393 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
394 const TopoDS_Shape& aShape = aPrs.shape();
395 if (!aShape.IsNull()) {
396 #ifdef DEBUG_CRASH_RESTORE_SELECTION
398 aContext->AddOrRemoveSelected(aShape, false);
401 ObjectPtr anObject = aPrs.object();
402 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
403 if (aResult.get() && isVisible(aResult)) {
404 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
405 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
406 if (!anAIS.IsNull()) {
407 // The methods are replaced in order to provide multi-selection, e.g. restore selection
408 // by activating multi selector widget. It also gives an advantage that the multi
409 // selection in OB gives multi-selection in the viewer
410 //aContext->SetSelected(anAIS, false);
411 // The selection in the context was cleared, so the method sets the objects are selected
412 aContext->AddOrRemoveSelected(anAIS, false);
418 aContext->UnhilightCurrents();
419 aContext->ClearCurrents();
420 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
421 ObjectPtr anObject = aPrs.object();
422 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
423 if (aResult.get() && isVisible(aResult)) {
424 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
425 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
427 aContext->SetCurrentObject(anAIS, false);
435 void XGUI_Displayer::clearSelected()
437 Handle(AIS_InteractiveContext) aContext = AISContext();
439 aContext->UnhilightCurrents(false);
440 aContext->ClearSelected();
444 void XGUI_Displayer::eraseAll(const bool theUpdateViewer)
446 Handle(AIS_InteractiveContext) aContext = AISContext();
447 if (!aContext.IsNull()) {
448 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
449 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
451 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
452 if (!anIO.IsNull()) {
453 emit beforeObjectErase(aObj, aAISObj);
454 aContext->Remove(anIO, false);
460 myResult2AISObjectMap.clear();
463 void XGUI_Displayer::deactivateTrihedron() const
465 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
467 AIS_ListOfInteractive aList;
468 aContext->DisplayedObjects(aList, true);
469 AIS_ListIteratorOfListOfInteractive aIt;
470 for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
471 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
472 if (!aTrihedron.IsNull()) {
473 aContext->Deactivate(aTrihedron);
478 void XGUI_Displayer::openLocalContext()
480 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
481 if (aContext.IsNull())
483 // Open local context if there is no one
484 if (!aContext->HasOpenedContext()) {
485 // Preserve selected objects
486 //AIS_ListOfInteractive aAisList;
487 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
488 // aAisList.Append(aContext->Current());
490 // get the filters from the global context and append them to the local context
491 // a list of filters in the global context is not cleared and should be cleared here
492 SelectMgr_ListOfFilter aFilters;
493 aFilters.Assign(aContext->Filters());
494 // it is important to remove the filters in the global context, because there is a code
495 // in the closeLocalContex, which restore the global context filters
496 aContext->RemoveFilters();
498 //aContext->ClearCurrents();
499 aContext->OpenLocalContext();
500 deactivateTrihedron();
501 //aContext->NotUseDisplayedObjects();
503 //myUseExternalObjects = false;
505 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
506 for (;aIt.More(); aIt.Next()) {
507 aContext->AddFilter(aIt.Value());
510 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
511 //for(; aIt2.More(); aIt2.Next()) {
512 // aContext->SetSelected(aIt2.Value(), false);
517 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
519 Handle(AIS_InteractiveContext) aContext = AISContext();
520 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
521 // Preserve selected objects
522 //AIS_ListOfInteractive aAisList;
523 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
524 // aAisList.Append(aContext->SelectedInteractive());
526 // get the filters from the local context and append them to the global context
527 // a list of filters in the local context is cleared
528 SelectMgr_ListOfFilter aFilters;
529 aFilters.Assign(aContext->Filters());
531 //aContext->ClearSelected();
532 aContext->CloseAllContexts(false);
534 // Redisplay all object if they were displayed in localContext
535 Handle(AIS_InteractiveObject) aAISIO;
536 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
537 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
538 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
539 aContext->Display(aAISIO, false);
540 aContext->SetDisplayMode(aAISIO, Shading, false);
544 // Append the filters from the local selection in the global selection context
545 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
546 for (;aIt.More(); aIt.Next()) {
547 Handle(SelectMgr_Filter) aFilter = aIt.Value();
548 aContext->AddFilter(aFilter);
553 //myUseExternalObjects = false;
556 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
557 //for(; aIt2.More(); aIt2.Next()) {
558 // if (aContext->IsDisplayed(aIt2.Value()))
559 // aContext->SetCurrentObject(aIt2.Value(), false);
564 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
567 if (myResult2AISObjectMap.contains(theObject))
568 anIO = myResult2AISObjectMap[theObject];
572 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
574 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
575 return getObject(aRefAIS);
578 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
581 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
582 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
583 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
590 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
592 bool aWasEnabled = myEnableUpdateViewer;
594 myEnableUpdateViewer = isEnabled;
599 void XGUI_Displayer::updateViewer() const
601 Handle(AIS_InteractiveContext) aContext = AISContext();
602 if (!aContext.IsNull() && myEnableUpdateViewer)
603 aContext->UpdateCurrentViewer();
606 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
607 const int theMode, const bool theUpdateViewer) const
609 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
610 aContext->Activate(theIO, theMode, theUpdateViewer);
612 #ifdef DEBUG_ACTIVATE_AIS
613 ObjectPtr anObject = getObject(theIO);
614 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
615 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
619 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
621 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
623 aContext->Deactivate(theIO);
625 aContext->Deactivate(theIO, theMode);
627 #ifdef DEBUG_DEACTIVATE_AIS
628 ObjectPtr anObject = getObject(theIO);
629 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
630 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
634 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
636 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
637 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
638 aContext->OpenLocalContext();
639 deactivateTrihedron();
644 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
646 Handle(AIS_InteractiveContext) aContext = AISContext();
647 if (myAndFilter.IsNull() && !aContext.IsNull()) {
648 myAndFilter = new SelectMgr_AndFilter();
649 aContext->AddFilter(myAndFilter);
654 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer)
656 Handle(AIS_InteractiveContext) aContext = AISContext();
657 if (aContext.IsNull())
659 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
660 if (!anAISIO.IsNull()) {
661 aContext->Display(anAISIO, theUpdateViewer);
662 if (aContext->HasOpenedContext()) {
663 if (myActiveSelectionModes.size() == 0)
664 activateAIS(anAISIO, 0, theUpdateViewer);
666 foreach(int aMode, myActiveSelectionModes) {
667 activateAIS(anAISIO, aMode, theUpdateViewer);
674 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
676 Handle(AIS_InteractiveContext) aContext = AISContext();
677 if (aContext.IsNull())
679 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
680 if (!anAISIO.IsNull()) {
681 aContext->Remove(anAISIO, theUpdateViewer);
686 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
688 if (theMode == NoMode)
691 Handle(AIS_InteractiveContext) aContext = AISContext();
692 if (aContext.IsNull())
695 AISObjectPtr aAISObj = getAISObject(theObject);
699 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
700 aContext->SetDisplayMode(aAISIO, theMode, false);
701 // Redisplay in order to update new mode because it could be not computed before
706 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
708 Handle(AIS_InteractiveContext) aContext = AISContext();
709 if (aContext.IsNull())
712 AISObjectPtr aAISObj = getAISObject(theObject);
716 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
717 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
720 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
722 Handle(AIS_InteractiveContext) aContext = AISContext();
723 if (aContext.IsNull())
725 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
726 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
727 for (; aIt.More(); aIt.Next()) {
728 if (theFilter.Access() == aIt.Value().Access())
731 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
732 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
733 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
734 if (theFilter.Access() == aIt.Value().Access())
737 aCompFilter->Add(theFilter);
738 #ifdef DEBUG_SELECTION_FILTERS
739 int aCount = GetFilter()->StoredFilters().Extent();
740 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
744 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
746 Handle(AIS_InteractiveContext) aContext = AISContext();
747 if (aContext.IsNull())
749 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
750 if (aCompositeFilter->IsIn(theFilter))
751 aCompositeFilter->Remove(theFilter);
752 #ifdef DEBUG_SELECTION_FILTERS
753 int aCount = GetFilter()->StoredFilters().Extent();
754 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
758 void XGUI_Displayer::removeFilters()
760 Handle(AIS_InteractiveContext) aContext = AISContext();
761 if (aContext.IsNull())
763 GetFilter()->Clear();
766 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
768 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
769 foreach(ObjectPtr aObj, aDispList) {
770 if (!theList.contains(aObj))
773 foreach(ObjectPtr aObj, theList) {
774 if (!isVisible(aObj))
775 display(aObj, false);
780 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
782 if (!isVisible(theObject))
785 AISObjectPtr aAISObj = getAISObject(theObject);
786 if (aAISObj.get() == NULL)
789 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
790 return ::canBeShaded(anAIS);
793 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
794 const QIntList& theModes,
795 const bool theUpdateViewer) const
797 Handle(AIS_InteractiveContext) aContext = AISContext();
798 if (aContext.IsNull() || theIO.IsNull())
801 // deactivate object in all modes, which are not in the list of activation
802 // It seems that after the IO deactivation the selected state of the IO's owners
803 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
804 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
805 // only if there is a difference in the current modes and the parameters modes.
806 // If the selection problem happens again, it is possible to write a test scenario and create
807 // a bug. The bug steps are the following:
808 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
809 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
810 TColStd_ListOfInteger aTColModes;
811 aContext->ActivatedModes(theIO, aTColModes);
812 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
813 QIntList aModesActivatedForIO;
814 bool isDeactivated = false;
815 for (; itr.More(); itr.Next() ) {
816 Standard_Integer aMode = itr.Value();
817 if (!theModes.contains(aMode)) {
818 deactivateAIS(theIO, aMode);
819 isDeactivated = true;
822 aModesActivatedForIO.append(aMode);
826 // the selection from the previous activation modes should be cleared manually (#26172)
827 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
832 // loading the interactive object allowing the decomposition
833 if (aTColModes.IsEmpty()) {
834 aContext->Load(theIO, -1, true);
837 // trihedron AIS check should be after the AIS loading.
838 // If it is not loaded, it is steel selectable in the viewer.
839 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
840 if (aTrihedron.IsNull()) {
841 //aContext->Load(anAISIO, -1, true);
842 // In order to clear active modes list
843 if (theModes.size() == 0) {
844 //aContext->Load(anAISIO, 0, true);
845 activateAIS(theIO, 0, theUpdateViewer);
847 foreach(int aMode, theModes) {
848 //aContext->Load(anAISIO, aMode, true);
849 if (!aModesActivatedForIO.contains(aMode)) {
850 activateAIS(theIO, aMode, theUpdateViewer);
857 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
859 AISObjectPtr anAISObj = getAISObject(theObject);
860 // correct the result's color it it has the attribute
861 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
863 // Customization of presentation
864 GeomCustomPrsPtr aCustomPrs;
865 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
866 if (aFeature.get() != NULL) {
867 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
868 if (aCustPrs.get() != NULL)
869 aCustomPrs = aCustPrs;
871 if (aCustomPrs.get() == NULL) {
872 // we ignore presentable not customized objects
873 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
874 if (aPrs.get() != NULL)
876 aCustomPrs = myCustomPrs;
878 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
882 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
884 if (!isVisible(theObject))
887 AISObjectPtr anAISObj = getAISObject(theObject);
889 anAISObj->getColor(aR, aG, aB);
890 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
893 return QColor(aR, aG, aB);
896 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
898 myResult2AISObjectMap[theObject] = theAIS;
901 std::ostringstream aPtrStr;
902 aPtrStr << theObject.get();
903 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
904 qDebug(getResult2AISObjectMapInfo().c_str());
908 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
910 QStringList aContent;
911 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
912 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
913 std::ostringstream aPtrStr;
914 aPtrStr << "aObj = " << aObj.get() << ":";
915 aPtrStr << "anAIS = " << aAISObj.get() << ":";
916 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
918 aContent.append(aPtrStr.str().c_str());
920 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
921 arg(aContent.join("\n")).toStdString().c_str();