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>
24 #include <GeomAPI_Shape.h>
25 #include <GeomAPI_IPresentable.h>
26 #include <GeomAPI_ICustomPrs.h>
28 #include <AIS_InteractiveContext.hxx>
29 #include <AIS_LocalContext.hxx>
30 #include <AIS_ListOfInteractive.hxx>
31 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <AIS_DimensionSelectionMode.hxx>
33 #include <AIS_Shape.hxx>
34 #include <AIS_Dimension.hxx>
35 #include <TColStd_ListIteratorOfListOfInteger.hxx>
36 #include <SelectMgr_ListOfFilter.hxx>
37 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
39 #include <TColStd_MapOfTransient.hxx>
40 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
44 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
46 //#define DEBUG_DISPLAY
47 //#define DEBUG_ACTIVATE
48 //#define DEBUG_FEATURE_REDISPLAY
49 #define DEBUG_SELECTION_FILTERS
51 // Workaround for bug #25637
52 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
54 // Get from null point
55 theAIS->DisplayedObjects(theList, true);
56 if (theAIS->HasOpenedContext()) {
57 // get from local context
58 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
59 TColStd_MapOfTransient aMap;
60 int NbDisp = aLC->DisplayedObjects(aMap);
61 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
63 Handle(AIS_InteractiveObject) curIO;
64 Handle(Standard_Transient) Tr;
65 for(; aIt.More(); aIt.Next()){
67 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
68 theList.Append(curIO);
74 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
75 : myWorkshop(theWorkshop)
77 enableUpdateViewer(true);
78 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
81 XGUI_Displayer::~XGUI_Displayer()
85 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
87 return myResult2AISObjectMap.contains(theObject);
90 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
92 if (isVisible(theObject)) {
93 redisplay(theObject, isUpdateViewer);
96 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
97 if (aFeature.get() != NULL) {
98 qDebug(QString("display feature: %1, displayed: %2").
99 arg(aFeature->data()->name().c_str()).
100 arg(displayedObjects().size()).toStdString().c_str());
105 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
106 bool isShading = false;
107 if (aPrs.get() != NULL) {
108 anAIS = aPrs->getAISObject(anAIS);
110 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
111 if (aResult.get() != NULL) {
112 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
113 if (aShapePtr.get() != NULL) {
114 anAIS = AISObjectPtr(new GeomAPI_AISObject());
115 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
116 //anAIS->createShape(aShapePtr);
122 display(theObject, anAIS, isShading, isUpdateViewer);
126 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
128 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
129 if (!aShapePrs.IsNull()) {
130 TopoDS_Shape aShape = aShapePrs->Shape();
131 TopAbs_ShapeEnum aType = aShape.ShapeType();
132 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
135 // Check that the presentation is not a sketch
136 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
138 return !aPrs->isSketchMode();
145 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
146 bool isShading, bool isUpdateViewer)
148 Handle(AIS_InteractiveContext) aContext = AISContext();
149 if (aContext.IsNull())
152 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
153 if (!anAISIO.IsNull()) {
154 myResult2AISObjectMap[theObject] = theAIS;
155 bool aCanBeShaded = ::canBeShaded(anAISIO);
156 // In order to avoid extra closing/opening context
157 SelectMgr_IndexedMapOfOwner aSelectedOwners;
159 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
160 closeLocalContexts(false);
162 aContext->Display(anAISIO, false);
163 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
165 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
166 emit objectDisplayed(theObject, theAIS);
168 bool isCustomized = customizeObject(theObject);
170 aContext->Redisplay(anAISIO, false);
174 activateObjects(myActiveSelectionModes);
175 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
178 activate(anAISIO, myActiveSelectionModes);
184 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
186 if (!isVisible(theObject))
189 Handle(AIS_InteractiveContext) aContext = AISContext();
190 if (aContext.IsNull())
192 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
194 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
195 if (!anAIS.IsNull()) {
196 emit beforeObjectErase(theObject, anObject);
197 aContext->Remove(anAIS, isUpdateViewer);
200 myResult2AISObjectMap.remove(theObject);
203 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
205 if (!isVisible(theObject))
208 AISObjectPtr aAISObj = getAISObject(theObject);
209 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
211 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
213 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
215 erase(theObject, isUpdateViewer);
218 if (aAIS_Obj != aAISObj) {
219 myResult2AISObjectMap[theObject] = aAIS_Obj;
221 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
224 if (!aAISIO.IsNull()) {
225 Handle(AIS_InteractiveContext) aContext = AISContext();
226 if (aContext.IsNull())
228 // Check that the visualized shape is the same and the redisplay is not necessary
229 // Redisplay of AIS object leads to this object selection compute and the selection
230 // in the browser is lost
232 // this check is not necessary anymore because the selection store/restore is realized
233 // before and after the values modification.
234 // Moreother, this check avoids customize and redisplay presentation if the presentable
235 // parameter is changed.
236 bool isEqualShapes = false;
237 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
238 if (aResult.get() != NULL) {
239 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
240 if (!aShapePrs.IsNull()) {
241 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
242 if (aShapePtr.get()) {
243 const TopoDS_Shape& aShape = aShapePrs->Shape();
244 std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
245 anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
247 isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
251 // Customization of presentation
252 bool isCustomized = customizeObject(theObject);
253 #ifdef DEBUG_FEATURE_REDISPLAY
254 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
255 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
257 if (!isEqualShapes || isCustomized) {
258 aContext->Redisplay(aAISIO, false);
259 #ifdef DEBUG_FEATURE_REDISPLAY
260 //qDebug(" Redisplay happens");
268 void XGUI_Displayer::deactivate(ObjectPtr theObject)
270 if (isVisible(theObject)) {
271 Handle(AIS_InteractiveContext) aContext = AISContext();
272 if (aContext.IsNull())
275 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
276 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
277 aContext->Deactivate(anAIS);
281 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
283 activate(theFeature, myActiveSelectionModes);
286 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
288 #ifdef DEBUG_ACTIVATE
289 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
291 if (aFeature.get() != NULL) {
293 getModesOfActivation(theObject, aModes);
296 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
297 arg(aFeature->data()->name().c_str()).
298 arg(theModes.size()).
299 arg(myActiveSelectionModes.size()).
300 arg(aModes.size()).toStdString().c_str());
304 if (isVisible(theObject)) {
305 Handle(AIS_InteractiveContext) aContext = AISContext();
306 if (aContext.IsNull())
309 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
310 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
312 activate(anAIS, theModes);
316 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
318 if (!isVisible(theObject))
321 Handle(AIS_InteractiveContext) aContext = AISContext();
322 if (aContext.IsNull())
325 AISObjectPtr aAISObj = getAISObject(theObject);
327 if (aAISObj.get() != NULL) {
328 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
329 TColStd_ListOfInteger aTColModes;
330 aContext->ActivatedModes(anAISIO, aTColModes);
331 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
332 for (; itr.More(); itr.Next() ) {
333 theModes.append(itr.Value());
338 void XGUI_Displayer::activateObjects(const QIntList& theModes)
340 #ifdef DEBUG_ACTIVATE
341 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
342 arg(theModes.size()).
343 arg(myActiveSelectionModes.size()).
344 toStdString().c_str());
346 // In order to avoid doblications of selection modes
348 foreach (int aMode, theModes) {
349 if (!aNewModes.contains(aMode))
350 aNewModes.append(aMode);
352 myActiveSelectionModes = aNewModes;
353 Handle(AIS_InteractiveContext) aContext = AISContext();
354 if (aContext.IsNull())
356 // Open local context if there is no one
357 if (!aContext->HasOpenedContext())
360 //aContext->UseDisplayedObjects();
361 //myUseExternalObjects = true;
363 AIS_ListOfInteractive aPrsList;
364 ::displayedObjects(aContext, aPrsList);
366 Handle(AIS_Trihedron) aTrihedron;
367 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
368 Handle(AIS_InteractiveObject) anAISIO;
369 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
370 anAISIO = aLIt.Value();
371 activate(anAISIO, myActiveSelectionModes);
376 void XGUI_Displayer::deactivateObjects()
378 myActiveSelectionModes.clear();
379 Handle(AIS_InteractiveContext) aContext = AISContext();
380 // Open local context if there is no one
381 if (!aContext->HasOpenedContext())
384 //aContext->NotUseDisplayedObjects();
385 AIS_ListOfInteractive aPrsList;
386 ::displayedObjects(aContext, aPrsList);
388 AIS_ListIteratorOfListOfInteractive aLIt;
389 //Handle(AIS_Trihedron) aTrihedron;
390 Handle(AIS_InteractiveObject) anAISIO;
391 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
392 anAISIO = aLIt.Value();
393 aContext->Deactivate(anAISIO);
397 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
399 Handle(AIS_InteractiveContext) aContext = AISContext();
400 if (aContext.IsNull())
402 if (!isVisible(theObject))
405 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
406 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
408 TColStd_ListOfInteger aModes;
409 aContext->ActivatedModes(anAIS, aModes);
410 return aModes.Extent() > 0;
413 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
415 Handle(AIS_InteractiveContext) aContext = AISContext();
416 if (aContext.IsNull())
418 if (aContext->HasOpenedContext()) {
419 aContext->UnhilightSelected();
420 aContext->ClearSelected();
421 foreach(ObjectPtr aResult, theResults) {
422 if (isVisible(aResult)) {
423 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
424 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
426 aContext->SetSelected(anAIS, false);
430 aContext->UnhilightCurrents();
431 aContext->ClearCurrents();
432 foreach(ObjectPtr aResult, theResults) {
433 if (isVisible(aResult)) {
434 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
435 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
437 aContext->SetCurrentObject(anAIS, false);
446 void XGUI_Displayer::clearSelected()
448 Handle(AIS_InteractiveContext) aContext = AISContext();
450 aContext->UnhilightCurrents(false);
451 aContext->ClearSelected();
455 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
457 Handle(AIS_InteractiveContext) aContext = AISContext();
458 if (!aContext.IsNull()) {
459 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
460 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
462 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
463 if (!anIO.IsNull()) {
464 emit beforeObjectErase(aObj, aAISObj);
465 aContext->Remove(anIO, false);
471 myResult2AISObjectMap.clear();
474 void XGUI_Displayer::openLocalContext()
476 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
477 if (aContext.IsNull())
479 // Open local context if there is no one
480 if (!aContext->HasOpenedContext()) {
481 // Preserve selected objects
482 //AIS_ListOfInteractive aAisList;
483 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
484 // aAisList.Append(aContext->Current());
486 // get the filters from the global context and append them to the local context
487 // a list of filters in the global context is not cleared and should be cleared here
488 SelectMgr_ListOfFilter aFilters;
489 aFilters.Assign(aContext->Filters());
490 // it is important to remove the filters in the global context, because there is a code
491 // in the closeLocalContex, which restore the global context filters
492 aContext->RemoveFilters();
494 //aContext->ClearCurrents();
495 aContext->OpenLocalContext();
496 //aContext->NotUseDisplayedObjects();
498 //myUseExternalObjects = false;
500 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
501 for (;aIt.More(); aIt.Next()) {
502 aContext->AddFilter(aIt.Value());
505 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
506 //for(; aIt2.More(); aIt2.Next()) {
507 // aContext->SetSelected(aIt2.Value(), false);
512 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
514 Handle(AIS_InteractiveContext) aContext = AISContext();
515 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
516 // Preserve selected objects
517 //AIS_ListOfInteractive aAisList;
518 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
519 // aAisList.Append(aContext->SelectedInteractive());
521 // get the filters from the local context and append them to the global context
522 // a list of filters in the local context is cleared
523 SelectMgr_ListOfFilter aFilters;
524 aFilters.Assign(aContext->Filters());
526 //aContext->ClearSelected();
527 aContext->CloseAllContexts(false);
529 // Redisplay all object if they were displayed in localContext
530 Handle(AIS_InteractiveObject) aAISIO;
531 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
532 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
533 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
534 aContext->Display(aAISIO, false);
535 aContext->SetDisplayMode(aAISIO, Shading, false);
539 // Append the filters from the local selection in the global selection context
540 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
541 for (;aIt.More(); aIt.Next()) {
542 Handle(SelectMgr_Filter) aFilter = aIt.Value();
543 aContext->AddFilter(aFilter);
548 //myUseExternalObjects = false;
551 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
552 //for(; aIt2.More(); aIt2.Next()) {
553 // if (aContext->IsDisplayed(aIt2.Value()))
554 // aContext->SetCurrentObject(aIt2.Value(), false);
559 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
562 if (myResult2AISObjectMap.contains(theObject))
563 anIO = myResult2AISObjectMap[theObject];
567 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
569 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
570 return getObject(aRefAIS);
573 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
576 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
577 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
578 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
585 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
587 bool aWasEnabled = myEnableUpdateViewer;
589 myEnableUpdateViewer = isEnabled;
594 void XGUI_Displayer::updateViewer()
596 Handle(AIS_InteractiveContext) aContext = AISContext();
597 if (!aContext.IsNull() && myEnableUpdateViewer)
598 aContext->UpdateCurrentViewer();
601 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
603 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
604 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
605 aContext->OpenLocalContext();
610 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
612 Handle(AIS_InteractiveContext) aContext = AISContext();
613 if (myAndFilter.IsNull() && !aContext.IsNull()) {
614 myAndFilter = new SelectMgr_AndFilter();
615 aContext->AddFilter(myAndFilter);
620 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
622 Handle(AIS_InteractiveContext) aContext = AISContext();
623 if (aContext.IsNull())
625 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
626 if (!anAISIO.IsNull()) {
627 aContext->Display(anAISIO, isUpdate);
628 if (aContext->HasOpenedContext()) {
629 //if (myUseExternalObjects) {
630 if (myActiveSelectionModes.size() == 0)
631 aContext->Activate(anAISIO);
633 foreach(int aMode, myActiveSelectionModes) {
634 aContext->Activate(anAISIO, aMode);
642 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
644 Handle(AIS_InteractiveContext) aContext = AISContext();
645 if (aContext.IsNull())
647 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
648 if (!anAISIO.IsNull()) {
649 aContext->Remove(anAISIO, isUpdate);
654 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
656 if (theMode == NoMode)
659 Handle(AIS_InteractiveContext) aContext = AISContext();
660 if (aContext.IsNull())
663 AISObjectPtr aAISObj = getAISObject(theObject);
667 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
668 bool aCanBeShaded = ::canBeShaded(aAISIO);
669 // In order to avoid extra closing/opening context
670 SelectMgr_IndexedMapOfOwner aSelectedOwners;
672 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
673 closeLocalContexts(false);
675 aContext->SetDisplayMode(aAISIO, theMode, false);
678 activateObjects(myActiveSelectionModes);
679 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
685 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
687 Handle(AIS_InteractiveContext) aContext = AISContext();
688 if (aContext.IsNull())
691 AISObjectPtr aAISObj = getAISObject(theObject);
695 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
696 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
699 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
701 Handle(AIS_InteractiveContext) aContext = AISContext();
702 if (aContext.IsNull())
704 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
705 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
706 for (; aIt.More(); aIt.Next()) {
707 if (theFilter.Access() == aIt.Value().Access())
710 GetFilter()->Add(theFilter);
711 #ifdef DEBUG_SELECTION_FILTERS
712 int aCount = GetFilter()->StoredFilters().Extent();
713 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
717 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
719 Handle(AIS_InteractiveContext) aContext = AISContext();
720 if (aContext.IsNull())
722 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
723 if (aCompositeFilter->IsIn(theFilter))
724 aCompositeFilter->Remove(theFilter);
725 #ifdef DEBUG_SELECTION_FILTERS
726 int aCount = GetFilter()->StoredFilters().Extent();
727 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
731 void XGUI_Displayer::removeFilters()
733 Handle(AIS_InteractiveContext) aContext = AISContext();
734 if (aContext.IsNull())
736 GetFilter()->Clear();
739 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
741 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
742 foreach(ObjectPtr aObj, aDispList) {
743 if (!theList.contains(aObj))
746 foreach(ObjectPtr aObj, theList) {
747 if (!isVisible(aObj))
748 display(aObj, false);
753 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
755 if (!isVisible(theObject))
758 AISObjectPtr aAISObj = getAISObject(theObject);
759 if (aAISObj.get() == NULL)
762 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
763 return ::canBeShaded(anAIS);
766 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
767 const QIntList& theModes) const
769 Handle(AIS_InteractiveContext) aContext = AISContext();
770 if (aContext.IsNull() || theIO.IsNull())
773 // deactivate object in all modes, which are not in the list of activation
774 // It seems that after the IO deactivation the selected state of the IO's owners
775 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
776 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
777 // only if there is a difference in the current modes and the parameters modes.
778 // If the selection problem happens again, it is possible to write a test scenario and create
779 // a bug. The bug steps are the following:
780 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
781 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
782 TColStd_ListOfInteger aTColModes;
783 aContext->ActivatedModes(theIO, aTColModes);
784 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
785 QIntList aModesActivatedForIO;
786 for (; itr.More(); itr.Next() ) {
787 Standard_Integer aMode = itr.Value();
788 if (!theModes.contains(aMode)) {
789 #ifdef DEBUG_ACTIVATE
790 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
792 aContext->Deactivate(theIO, aMode);
795 aModesActivatedForIO.append(aMode);
796 #ifdef DEBUG_ACTIVATE
797 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
801 // loading the interactive object allowing the decomposition
802 if (aTColModes.IsEmpty())
803 aContext->Load(theIO, -1, true);
805 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
806 //Deactivate trihedron which can be activated in local selector
807 if (aTrihedron.IsNull()) {
808 //aContext->Load(anAISIO, -1, true);
809 // In order to clear active modes list
810 if (theModes.size() == 0) {
811 //aContext->Load(anAISIO, 0, true);
812 aContext->Activate(theIO);
813 #ifdef DEBUG_ACTIVATE
814 qDebug("activate in all modes");
817 foreach(int aMode, theModes) {
818 //aContext->Load(anAISIO, aMode, true);
819 if (!aModesActivatedForIO.contains(aMode)) {
820 aContext->Activate(theIO, aMode);
821 #ifdef DEBUG_ACTIVATE
822 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
830 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
832 AISObjectPtr anAISObj = getAISObject(theObject);
833 // correct the result's color it it has the attribute
834 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
836 // Customization of presentation
837 GeomCustomPrsPtr aCustomPrs;
838 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
839 if (aFeature.get() != NULL) {
840 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
841 if (aCustPrs.get() != NULL)
842 aCustomPrs = aCustPrs;
844 if (aCustomPrs.get() == NULL) {
845 // we ignore presentable not customized objects
846 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
847 if (aPrs.get() != NULL)
849 aCustomPrs = myCustomPrs;
851 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
855 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
857 if (!isVisible(theObject))
860 AISObjectPtr anAISObj = getAISObject(theObject);
862 anAISObj->getColor(aR, aG, aB);
863 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
866 return QColor(aR, aG, aB);