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_ACTIVATE_OBJECTS
50 //#define DEBUG_DEACTIVATE
51 //#define DEBUG_ACTIVATE_AIS
52 //#define DEBUG_DEACTIVATE_AIS
54 //#define DEBUG_DISPLAY
55 //#define DEBUG_FEATURE_REDISPLAY
56 //#define DEBUG_SELECTION_FILTERS
58 // Workaround for bug #25637
59 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
61 // Get from null point
62 theAIS->DisplayedObjects(theList, true);
63 if (theAIS->HasOpenedContext()) {
64 // get from local context
65 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
66 TColStd_MapOfTransient aMap;
67 int NbDisp = aLC->DisplayedObjects(aMap);
68 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
70 Handle(AIS_InteractiveObject) curIO;
71 Handle(Standard_Transient) Tr;
72 for(; aIt.More(); aIt.Next()){
74 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
75 theList.Append(curIO);
80 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
83 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
84 for (; anIt != aLast; anIt++) {
85 anInfo.append(QString::number(*anIt));
87 return anInfo.join(theSeparator);
90 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
91 : myWorkshop(theWorkshop)
93 enableUpdateViewer(true);
94 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
97 XGUI_Displayer::~XGUI_Displayer()
101 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
103 return myResult2AISObjectMap.contains(theObject);
106 void XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
108 if (isVisible(theObject)) {
109 redisplay(theObject, theUpdateViewer);
113 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
114 bool isShading = false;
115 if (aPrs.get() != NULL) {
116 anAIS = aPrs->getAISObject(anAIS);
118 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
119 if (aResult.get() != NULL) {
120 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
121 if (aShapePtr.get() != NULL) {
122 anAIS = AISObjectPtr(new GeomAPI_AISObject());
123 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
124 //anAIS->createShape(aShapePtr);
130 display(theObject, anAIS, isShading, theUpdateViewer);
134 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
136 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
137 if (!aShapePrs.IsNull()) {
138 TopoDS_Shape aShape = aShapePrs->Shape();
139 TopAbs_ShapeEnum aType = aShape.ShapeType();
140 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
143 // Check that the presentation is not a sketch
144 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
146 return !aPrs->isSketchMode();
153 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
154 bool isShading, bool theUpdateViewer)
156 Handle(AIS_InteractiveContext) aContext = AISContext();
157 if (aContext.IsNull())
160 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
161 if (!anAISIO.IsNull()) {
162 appendResultObject(theObject, theAIS);
164 bool isCustomized = customizeObject(theObject);
166 int aDispMode = isShading? Shading : Wireframe;
168 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
169 anAISIO->SetDisplayMode(aDispMode);
170 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
172 emit objectDisplayed(theObject, theAIS);
173 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
179 void XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
181 if (!isVisible(theObject))
184 Handle(AIS_InteractiveContext) aContext = AISContext();
185 if (aContext.IsNull())
187 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
189 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
190 if (!anAIS.IsNull()) {
191 emit beforeObjectErase(theObject, anObject);
192 aContext->Remove(anAIS, theUpdateViewer);
195 myResult2AISObjectMap.remove(theObject);
198 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
200 if (!isVisible(theObject))
203 AISObjectPtr aAISObj = getAISObject(theObject);
204 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
206 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
208 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
210 erase(theObject, theUpdateViewer);
213 if (aAIS_Obj != aAISObj) {
214 appendResultObject(theObject, aAIS_Obj);
216 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
219 if (!aAISIO.IsNull()) {
220 Handle(AIS_InteractiveContext) aContext = AISContext();
221 if (aContext.IsNull())
223 // Check that the visualized shape is the same and the redisplay is not necessary
224 // Redisplay of AIS object leads to this object selection compute and the selection
225 // in the browser is lost
227 // this check is not necessary anymore because the selection store/restore is realized
228 // before and after the values modification.
229 // Moreother, this check avoids customize and redisplay presentation if the presentable
230 // parameter is changed.
231 bool isEqualShapes = false;
232 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
233 if (aResult.get() != NULL) {
234 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
235 if (!aShapePrs.IsNull()) {
236 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
237 if (aShapePtr.get()) {
238 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
239 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
243 // Customization of presentation
244 bool isCustomized = customizeObject(theObject);
245 #ifdef DEBUG_FEATURE_REDISPLAY
246 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
247 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
249 if (!isEqualShapes || isCustomized) {
250 aContext->Redisplay(aAISIO, false);
251 #ifdef DEBUG_FEATURE_REDISPLAY
252 qDebug(" Redisplay happens");
260 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
262 #ifdef DEBUG_DEACTIVATE
263 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
264 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
265 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
267 toStdString().c_str());
269 if (isVisible(theObject)) {
270 Handle(AIS_InteractiveContext) aContext = AISContext();
271 if (aContext.IsNull())
274 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
275 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
277 deactivateAIS(anAIS);
278 // the selection from the previous activation modes should be cleared manually (#26172)
279 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
285 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
287 if (!isVisible(theObject))
290 Handle(AIS_InteractiveContext) aContext = AISContext();
291 if (aContext.IsNull())
294 AISObjectPtr aAISObj = getAISObject(theObject);
296 if (aAISObj.get() != NULL) {
297 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
298 TColStd_ListOfInteger aTColModes;
299 aContext->ActivatedModes(anAISIO, aTColModes);
300 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
301 for (; itr.More(); itr.Next() ) {
302 theModes.append(itr.Value());
307 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
308 const bool theUpdateViewer)
310 // Convert shape types to selection types
312 foreach(int aType, theModes) {
313 if (aType > TopAbs_SHAPE)
314 aModes.append(aType);
316 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
319 #ifdef DEBUG_ACTIVATE_OBJECTS
321 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
322 for (; anIt != aLast; ++anIt) {
323 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
325 QString anInfoStr = anInfo.join(", ");
327 qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
328 arg(aModes.size()).arg(qIntListInfo(aModes)).
329 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
331 toStdString().c_str());
333 // In order to avoid doblications of selection modes
335 foreach (int aMode, aModes) {
336 if (!aNewModes.contains(aMode))
337 aNewModes.append(aMode);
339 myActiveSelectionModes = aNewModes;
340 Handle(AIS_InteractiveContext) aContext = AISContext();
341 if (aContext.IsNull())
343 // Open local context if there is no one
344 if (!aContext->HasOpenedContext())
347 //aContext->UseDisplayedObjects();
348 //myUseExternalObjects = true;
350 Handle(AIS_InteractiveObject) anAISIO;
351 AIS_ListOfInteractive aPrsList;
352 if (theObjList.isEmpty())
355 foreach(ObjectPtr aObj, theObjList) {
356 if (myResult2AISObjectMap.contains(aObj))
357 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
361 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
362 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
363 anAISIO = aLIt.Value();
364 activate(anAISIO, myActiveSelectionModes, false);
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 aContext->AddOrRemoveSelected(aShape, false);
398 ObjectPtr anObject = aPrs.object();
399 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
400 if (aResult.get() && isVisible(aResult)) {
401 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
402 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
403 if (!anAIS.IsNull()) {
404 // The methods are replaced in order to provide multi-selection, e.g. restore selection
405 // by activating multi selector widget. It also gives an advantage that the multi
406 // selection in OB gives multi-selection in the viewer
407 //aContext->SetSelected(anAIS, false);
408 // The selection in the context was cleared, so the method sets the objects are selected
409 aContext->AddOrRemoveSelected(anAIS, false);
415 aContext->UnhilightCurrents();
416 aContext->ClearCurrents();
417 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
418 ObjectPtr anObject = aPrs.object();
419 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
420 if (aResult.get() && isVisible(aResult)) {
421 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
422 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
424 aContext->SetCurrentObject(anAIS, false);
432 void XGUI_Displayer::clearSelected()
434 Handle(AIS_InteractiveContext) aContext = AISContext();
436 aContext->UnhilightCurrents(false);
437 aContext->ClearSelected();
441 void XGUI_Displayer::eraseAll(const bool theUpdateViewer)
443 Handle(AIS_InteractiveContext) aContext = AISContext();
444 if (!aContext.IsNull()) {
445 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
446 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
448 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
449 if (!anIO.IsNull()) {
450 emit beforeObjectErase(aObj, aAISObj);
451 aContext->Remove(anIO, false);
457 myResult2AISObjectMap.clear();
460 void XGUI_Displayer::deactivateTrihedron() const
462 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
464 AIS_ListOfInteractive aList;
465 aContext->DisplayedObjects(aList, true);
466 AIS_ListIteratorOfListOfInteractive aIt;
467 for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
468 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
469 if (!aTrihedron.IsNull()) {
470 aContext->Deactivate(aTrihedron);
475 void XGUI_Displayer::openLocalContext()
477 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
478 if (aContext.IsNull())
480 // Open local context if there is no one
481 if (!aContext->HasOpenedContext()) {
482 // Preserve selected objects
483 //AIS_ListOfInteractive aAisList;
484 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
485 // aAisList.Append(aContext->Current());
487 // get the filters from the global context and append them to the local context
488 // a list of filters in the global context is not cleared and should be cleared here
489 SelectMgr_ListOfFilter aFilters;
490 aFilters.Assign(aContext->Filters());
491 // it is important to remove the filters in the global context, because there is a code
492 // in the closeLocalContex, which restore the global context filters
493 aContext->RemoveFilters();
495 //aContext->ClearCurrents();
496 aContext->OpenLocalContext();
497 deactivateTrihedron();
498 //aContext->NotUseDisplayedObjects();
500 //myUseExternalObjects = false;
502 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
503 for (;aIt.More(); aIt.Next()) {
504 aContext->AddFilter(aIt.Value());
507 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
508 //for(; aIt2.More(); aIt2.Next()) {
509 // aContext->SetSelected(aIt2.Value(), false);
514 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
516 Handle(AIS_InteractiveContext) aContext = AISContext();
517 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
518 // Preserve selected objects
519 //AIS_ListOfInteractive aAisList;
520 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
521 // aAisList.Append(aContext->SelectedInteractive());
523 // get the filters from the local context and append them to the global context
524 // a list of filters in the local context is cleared
525 SelectMgr_ListOfFilter aFilters;
526 aFilters.Assign(aContext->Filters());
528 //aContext->ClearSelected();
529 aContext->CloseAllContexts(false);
531 // Redisplay all object if they were displayed in localContext
532 Handle(AIS_InteractiveObject) aAISIO;
533 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
534 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
535 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
536 aContext->Display(aAISIO, false);
537 aContext->SetDisplayMode(aAISIO, Shading, false);
541 // Append the filters from the local selection in the global selection context
542 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
543 for (;aIt.More(); aIt.Next()) {
544 Handle(SelectMgr_Filter) aFilter = aIt.Value();
545 aContext->AddFilter(aFilter);
550 //myUseExternalObjects = false;
553 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
554 //for(; aIt2.More(); aIt2.Next()) {
555 // if (aContext->IsDisplayed(aIt2.Value()))
556 // aContext->SetCurrentObject(aIt2.Value(), false);
561 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
564 if (myResult2AISObjectMap.contains(theObject))
565 anIO = myResult2AISObjectMap[theObject];
569 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
571 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
572 return getObject(aRefAIS);
575 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
578 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
579 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
580 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
587 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
589 bool aWasEnabled = myEnableUpdateViewer;
591 myEnableUpdateViewer = isEnabled;
596 void XGUI_Displayer::updateViewer() const
598 Handle(AIS_InteractiveContext) aContext = AISContext();
599 if (!aContext.IsNull() && myEnableUpdateViewer)
600 aContext->UpdateCurrentViewer();
603 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
604 const int theMode, const bool theUpdateViewer) const
606 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
607 aContext->Activate(theIO, theMode, theUpdateViewer);
609 #ifdef DEBUG_ACTIVATE_AIS
610 ObjectPtr anObject = getObject(theIO);
611 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
612 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
616 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
618 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
620 aContext->Deactivate(theIO);
622 aContext->Deactivate(theIO, theMode);
624 #ifdef DEBUG_DEACTIVATE_AIS
625 ObjectPtr anObject = getObject(theIO);
626 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
627 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
631 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
633 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
634 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
635 aContext->OpenLocalContext();
636 deactivateTrihedron();
641 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
643 Handle(AIS_InteractiveContext) aContext = AISContext();
644 if (myAndFilter.IsNull() && !aContext.IsNull()) {
645 myAndFilter = new SelectMgr_AndFilter();
646 aContext->AddFilter(myAndFilter);
651 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer)
653 Handle(AIS_InteractiveContext) aContext = AISContext();
654 if (aContext.IsNull())
656 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
657 if (!anAISIO.IsNull()) {
658 aContext->Display(anAISIO, theUpdateViewer);
659 if (aContext->HasOpenedContext()) {
660 if (myActiveSelectionModes.size() == 0)
661 activateAIS(anAISIO, 0, theUpdateViewer);
663 foreach(int aMode, myActiveSelectionModes) {
664 activateAIS(anAISIO, aMode, theUpdateViewer);
671 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
673 Handle(AIS_InteractiveContext) aContext = AISContext();
674 if (aContext.IsNull())
676 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
677 if (!anAISIO.IsNull()) {
678 aContext->Remove(anAISIO, theUpdateViewer);
683 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
685 if (theMode == NoMode)
688 Handle(AIS_InteractiveContext) aContext = AISContext();
689 if (aContext.IsNull())
692 AISObjectPtr aAISObj = getAISObject(theObject);
696 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
697 aContext->SetDisplayMode(aAISIO, theMode, false);
698 // Redisplay in order to update new mode because it could be not computed before
703 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
705 Handle(AIS_InteractiveContext) aContext = AISContext();
706 if (aContext.IsNull())
709 AISObjectPtr aAISObj = getAISObject(theObject);
713 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
714 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
717 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
719 Handle(AIS_InteractiveContext) aContext = AISContext();
720 if (aContext.IsNull())
722 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
723 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
724 for (; aIt.More(); aIt.Next()) {
725 if (theFilter.Access() == aIt.Value().Access())
728 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
729 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
730 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
731 if (theFilter.Access() == aIt.Value().Access())
734 aCompFilter->Add(theFilter);
735 #ifdef DEBUG_SELECTION_FILTERS
736 int aCount = GetFilter()->StoredFilters().Extent();
737 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
741 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
743 Handle(AIS_InteractiveContext) aContext = AISContext();
744 if (aContext.IsNull())
746 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
747 if (aCompositeFilter->IsIn(theFilter))
748 aCompositeFilter->Remove(theFilter);
749 #ifdef DEBUG_SELECTION_FILTERS
750 int aCount = GetFilter()->StoredFilters().Extent();
751 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
755 void XGUI_Displayer::removeFilters()
757 Handle(AIS_InteractiveContext) aContext = AISContext();
758 if (aContext.IsNull())
760 GetFilter()->Clear();
763 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
765 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
766 foreach(ObjectPtr aObj, aDispList) {
767 if (!theList.contains(aObj))
770 foreach(ObjectPtr aObj, theList) {
771 if (!isVisible(aObj))
772 display(aObj, false);
777 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
779 if (!isVisible(theObject))
782 AISObjectPtr aAISObj = getAISObject(theObject);
783 if (aAISObj.get() == NULL)
786 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
787 return ::canBeShaded(anAIS);
790 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
791 const QIntList& theModes,
792 const bool theUpdateViewer) const
794 Handle(AIS_InteractiveContext) aContext = AISContext();
795 if (aContext.IsNull() || theIO.IsNull())
798 // deactivate object in all modes, which are not in the list of activation
799 // It seems that after the IO deactivation the selected state of the IO's owners
800 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
801 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
802 // only if there is a difference in the current modes and the parameters modes.
803 // If the selection problem happens again, it is possible to write a test scenario and create
804 // a bug. The bug steps are the following:
805 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
806 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
807 TColStd_ListOfInteger aTColModes;
808 aContext->ActivatedModes(theIO, aTColModes);
809 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
810 QIntList aModesActivatedForIO;
811 bool isDeactivated = false;
812 for (; itr.More(); itr.Next() ) {
813 Standard_Integer aMode = itr.Value();
814 if (!theModes.contains(aMode)) {
815 deactivateAIS(theIO, aMode);
816 isDeactivated = true;
819 aModesActivatedForIO.append(aMode);
823 // the selection from the previous activation modes should be cleared manually (#26172)
824 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
829 // loading the interactive object allowing the decomposition
830 if (aTColModes.IsEmpty()) {
831 aContext->Load(theIO, -1, true);
834 // trihedron AIS check should be after the AIS loading.
835 // If it is not loaded, it is steel selectable in the viewer.
836 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
837 if (aTrihedron.IsNull()) {
838 //aContext->Load(anAISIO, -1, true);
839 // In order to clear active modes list
840 if (theModes.size() == 0) {
841 //aContext->Load(anAISIO, 0, true);
842 activateAIS(theIO, 0, theUpdateViewer);
844 foreach(int aMode, theModes) {
845 //aContext->Load(anAISIO, aMode, true);
846 if (!aModesActivatedForIO.contains(aMode)) {
847 activateAIS(theIO, aMode, theUpdateViewer);
854 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
856 AISObjectPtr anAISObj = getAISObject(theObject);
857 // correct the result's color it it has the attribute
858 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
860 // Customization of presentation
861 GeomCustomPrsPtr aCustomPrs;
862 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
863 if (aFeature.get() != NULL) {
864 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
865 if (aCustPrs.get() != NULL)
866 aCustomPrs = aCustPrs;
868 if (aCustomPrs.get() == NULL) {
869 // we ignore presentable not customized objects
870 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
871 if (aPrs.get() != NULL)
873 aCustomPrs = myCustomPrs;
875 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
879 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
881 if (!isVisible(theObject))
884 AISObjectPtr anAISObj = getAISObject(theObject);
886 anAISObj->getColor(aR, aG, aB);
887 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
890 return QColor(aR, aG, aB);
893 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
895 myResult2AISObjectMap[theObject] = theAIS;
898 std::ostringstream aPtrStr;
899 aPtrStr << theObject.get();
900 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
901 qDebug(getResult2AISObjectMapInfo().c_str());
905 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
907 QStringList aContent;
908 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
909 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
910 std::ostringstream aPtrStr;
911 aPtrStr << "aObj = " << aObj.get() << ":";
912 aPtrStr << "anAIS = " << aAISObj.get() << ":";
913 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
915 aContent.append(aPtrStr.str().c_str());
917 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
918 arg(aContent.join("\n")).toStdString().c_str();