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));
246 isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
250 // Customization of presentation
251 bool isCustomized = customizeObject(theObject);
252 #ifdef DEBUG_FEATURE_REDISPLAY
253 //qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
254 // arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
256 if (!isEqualShapes || isCustomized) {
257 aContext->Redisplay(aAISIO, false);
258 #ifdef DEBUG_FEATURE_REDISPLAY
259 //qDebug(" Redisplay happens");
267 void XGUI_Displayer::deactivate(ObjectPtr theObject)
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)>();
276 aContext->Deactivate(anAIS);
280 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
282 activate(theFeature, myActiveSelectionModes);
285 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
287 #ifdef DEBUG_ACTIVATE
288 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
290 if (aFeature.get() != NULL) {
292 getModesOfActivation(theObject, aModes);
295 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
296 arg(aFeature->data()->name().c_str()).
297 arg(theModes.size()).
298 arg(myActiveSelectionModes.size()).
299 arg(aModes.size()).toStdString().c_str());
303 if (isVisible(theObject)) {
304 Handle(AIS_InteractiveContext) aContext = AISContext();
305 if (aContext.IsNull())
308 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
309 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
311 activate(anAIS, theModes);
315 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
317 if (!isVisible(theObject))
320 Handle(AIS_InteractiveContext) aContext = AISContext();
321 if (aContext.IsNull())
324 AISObjectPtr aAISObj = getAISObject(theObject);
326 if (aAISObj.get() != NULL) {
327 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
328 TColStd_ListOfInteger aTColModes;
329 aContext->ActivatedModes(anAISIO, aTColModes);
330 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
331 for (; itr.More(); itr.Next() ) {
332 theModes.append(itr.Value());
337 void XGUI_Displayer::activateObjects(const QIntList& theModes)
339 #ifdef DEBUG_ACTIVATE
340 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
341 arg(theModes.size()).
342 arg(myActiveSelectionModes.size()).
343 toStdString().c_str());
345 // In order to avoid doblications of selection modes
347 foreach (int aMode, theModes) {
348 if (!aNewModes.contains(aMode))
349 aNewModes.append(aMode);
351 myActiveSelectionModes = aNewModes;
352 Handle(AIS_InteractiveContext) aContext = AISContext();
353 if (aContext.IsNull())
355 // Open local context if there is no one
356 if (!aContext->HasOpenedContext())
359 //aContext->UseDisplayedObjects();
360 //myUseExternalObjects = true;
362 AIS_ListOfInteractive aPrsList;
363 ::displayedObjects(aContext, aPrsList);
365 Handle(AIS_Trihedron) aTrihedron;
366 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
367 Handle(AIS_InteractiveObject) anAISIO;
368 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
369 anAISIO = aLIt.Value();
370 activate(anAISIO, myActiveSelectionModes);
375 void XGUI_Displayer::deactivateObjects()
377 myActiveSelectionModes.clear();
378 Handle(AIS_InteractiveContext) aContext = AISContext();
379 // Open local context if there is no one
380 if (!aContext->HasOpenedContext())
383 //aContext->NotUseDisplayedObjects();
384 AIS_ListOfInteractive aPrsList;
385 ::displayedObjects(aContext, aPrsList);
387 AIS_ListIteratorOfListOfInteractive aLIt;
388 //Handle(AIS_Trihedron) aTrihedron;
389 Handle(AIS_InteractiveObject) anAISIO;
390 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
391 anAISIO = aLIt.Value();
392 aContext->Deactivate(anAISIO);
396 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
398 Handle(AIS_InteractiveContext) aContext = AISContext();
399 if (aContext.IsNull())
401 if (!isVisible(theObject))
404 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
405 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
407 TColStd_ListOfInteger aModes;
408 aContext->ActivatedModes(anAIS, aModes);
409 return aModes.Extent() > 0;
412 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
414 Handle(AIS_InteractiveContext) aContext = AISContext();
415 if (aContext.IsNull())
417 if (aContext->HasOpenedContext()) {
418 aContext->UnhilightSelected();
419 aContext->ClearSelected();
420 foreach(ObjectPtr aResult, theResults) {
421 if (isVisible(aResult)) {
422 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
423 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
425 aContext->SetSelected(anAIS, false);
429 aContext->UnhilightCurrents();
430 aContext->ClearCurrents();
431 foreach(ObjectPtr aResult, theResults) {
432 if (isVisible(aResult)) {
433 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
434 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
436 aContext->SetCurrentObject(anAIS, false);
445 void XGUI_Displayer::clearSelected()
447 Handle(AIS_InteractiveContext) aContext = AISContext();
449 aContext->UnhilightCurrents(false);
450 aContext->ClearSelected();
454 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
456 Handle(AIS_InteractiveContext) aContext = AISContext();
457 if (!aContext.IsNull()) {
458 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
459 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
461 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
462 if (!anIO.IsNull()) {
463 emit beforeObjectErase(aObj, aAISObj);
464 aContext->Remove(anIO, false);
470 myResult2AISObjectMap.clear();
473 void XGUI_Displayer::openLocalContext()
475 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
476 if (aContext.IsNull())
478 // Open local context if there is no one
479 if (!aContext->HasOpenedContext()) {
480 // Preserve selected objects
481 //AIS_ListOfInteractive aAisList;
482 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
483 // aAisList.Append(aContext->Current());
485 // get the filters from the global context and append them to the local context
486 // a list of filters in the global context is not cleared and should be cleared here
487 SelectMgr_ListOfFilter aFilters;
488 aFilters.Assign(aContext->Filters());
489 // it is important to remove the filters in the global context, because there is a code
490 // in the closeLocalContex, which restore the global context filters
491 aContext->RemoveFilters();
493 //aContext->ClearCurrents();
494 aContext->OpenLocalContext();
495 //aContext->NotUseDisplayedObjects();
497 //myUseExternalObjects = false;
499 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
500 for (;aIt.More(); aIt.Next()) {
501 aContext->AddFilter(aIt.Value());
504 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
505 //for(; aIt2.More(); aIt2.Next()) {
506 // aContext->SetSelected(aIt2.Value(), false);
511 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
513 Handle(AIS_InteractiveContext) aContext = AISContext();
514 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
515 // Preserve selected objects
516 //AIS_ListOfInteractive aAisList;
517 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
518 // aAisList.Append(aContext->SelectedInteractive());
520 // get the filters from the local context and append them to the global context
521 // a list of filters in the local context is cleared
522 SelectMgr_ListOfFilter aFilters;
523 aFilters.Assign(aContext->Filters());
525 //aContext->ClearSelected();
526 aContext->CloseAllContexts(false);
528 // Redisplay all object if they were displayed in localContext
529 Handle(AIS_InteractiveObject) aAISIO;
530 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
531 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
532 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
533 aContext->Display(aAISIO, false);
534 aContext->SetDisplayMode(aAISIO, Shading, false);
538 // Append the filters from the local selection in the global selection context
539 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
540 for (;aIt.More(); aIt.Next()) {
541 Handle(SelectMgr_Filter) aFilter = aIt.Value();
542 aContext->AddFilter(aFilter);
547 //myUseExternalObjects = false;
550 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
551 //for(; aIt2.More(); aIt2.Next()) {
552 // if (aContext->IsDisplayed(aIt2.Value()))
553 // aContext->SetCurrentObject(aIt2.Value(), false);
558 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
561 if (myResult2AISObjectMap.contains(theObject))
562 anIO = myResult2AISObjectMap[theObject];
566 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
568 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
569 return getObject(aRefAIS);
572 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
575 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
576 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
577 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
584 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
586 bool aWasEnabled = myEnableUpdateViewer;
588 myEnableUpdateViewer = isEnabled;
593 void XGUI_Displayer::updateViewer()
595 Handle(AIS_InteractiveContext) aContext = AISContext();
596 if (!aContext.IsNull() && myEnableUpdateViewer)
597 aContext->UpdateCurrentViewer();
600 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
602 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
603 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
604 aContext->OpenLocalContext();
609 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
611 Handle(AIS_InteractiveContext) aContext = AISContext();
612 if (myAndFilter.IsNull() && !aContext.IsNull()) {
613 myAndFilter = new SelectMgr_AndFilter();
614 aContext->AddFilter(myAndFilter);
619 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
621 Handle(AIS_InteractiveContext) aContext = AISContext();
622 if (aContext.IsNull())
624 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
625 if (!anAISIO.IsNull()) {
626 aContext->Display(anAISIO, isUpdate);
627 if (aContext->HasOpenedContext()) {
628 //if (myUseExternalObjects) {
629 if (myActiveSelectionModes.size() == 0)
630 aContext->Activate(anAISIO);
632 foreach(int aMode, myActiveSelectionModes) {
633 aContext->Activate(anAISIO, aMode);
641 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
643 Handle(AIS_InteractiveContext) aContext = AISContext();
644 if (aContext.IsNull())
646 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
647 if (!anAISIO.IsNull()) {
648 aContext->Remove(anAISIO, isUpdate);
653 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
655 if (theMode == NoMode)
658 Handle(AIS_InteractiveContext) aContext = AISContext();
659 if (aContext.IsNull())
662 AISObjectPtr aAISObj = getAISObject(theObject);
666 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
667 bool aCanBeShaded = ::canBeShaded(aAISIO);
668 // In order to avoid extra closing/opening context
669 SelectMgr_IndexedMapOfOwner aSelectedOwners;
671 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
672 closeLocalContexts(false);
674 aContext->SetDisplayMode(aAISIO, theMode, false);
677 activateObjects(myActiveSelectionModes);
678 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
684 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
686 Handle(AIS_InteractiveContext) aContext = AISContext();
687 if (aContext.IsNull())
690 AISObjectPtr aAISObj = getAISObject(theObject);
694 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
695 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
698 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
700 Handle(AIS_InteractiveContext) aContext = AISContext();
701 if (aContext.IsNull())
703 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
704 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
705 for (; aIt.More(); aIt.Next()) {
706 if (theFilter.Access() == aIt.Value().Access())
709 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
710 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
711 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
712 if (theFilter.Access() == aIt.Value().Access())
715 aCompFilter->Add(theFilter);
716 #ifdef DEBUG_SELECTION_FILTERS
717 int aCount = GetFilter()->StoredFilters().Extent();
718 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
722 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
724 Handle(AIS_InteractiveContext) aContext = AISContext();
725 if (aContext.IsNull())
727 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
728 if (aCompositeFilter->IsIn(theFilter))
729 aCompositeFilter->Remove(theFilter);
730 #ifdef DEBUG_SELECTION_FILTERS
731 int aCount = GetFilter()->StoredFilters().Extent();
732 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
736 void XGUI_Displayer::removeFilters()
738 Handle(AIS_InteractiveContext) aContext = AISContext();
739 if (aContext.IsNull())
741 GetFilter()->Clear();
744 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
746 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
747 foreach(ObjectPtr aObj, aDispList) {
748 if (!theList.contains(aObj))
751 foreach(ObjectPtr aObj, theList) {
752 if (!isVisible(aObj))
753 display(aObj, false);
758 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
760 if (!isVisible(theObject))
763 AISObjectPtr aAISObj = getAISObject(theObject);
764 if (aAISObj.get() == NULL)
767 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
768 return ::canBeShaded(anAIS);
771 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
772 const QIntList& theModes) const
774 Handle(AIS_InteractiveContext) aContext = AISContext();
775 if (aContext.IsNull() || theIO.IsNull())
778 // deactivate object in all modes, which are not in the list of activation
779 // It seems that after the IO deactivation the selected state of the IO's owners
780 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
781 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
782 // only if there is a difference in the current modes and the parameters modes.
783 // If the selection problem happens again, it is possible to write a test scenario and create
784 // a bug. The bug steps are the following:
785 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
786 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
787 TColStd_ListOfInteger aTColModes;
788 aContext->ActivatedModes(theIO, aTColModes);
789 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
790 QIntList aModesActivatedForIO;
791 for (; itr.More(); itr.Next() ) {
792 Standard_Integer aMode = itr.Value();
793 if (!theModes.contains(aMode)) {
794 #ifdef DEBUG_ACTIVATE
795 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
797 aContext->Deactivate(theIO, aMode);
800 aModesActivatedForIO.append(aMode);
801 #ifdef DEBUG_ACTIVATE
802 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
806 // loading the interactive object allowing the decomposition
807 if (aTColModes.IsEmpty())
808 aContext->Load(theIO, -1, true);
810 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
811 //Deactivate trihedron which can be activated in local selector
812 if (aTrihedron.IsNull()) {
813 //aContext->Load(anAISIO, -1, true);
814 // In order to clear active modes list
815 if (theModes.size() == 0) {
816 //aContext->Load(anAISIO, 0, true);
817 aContext->Activate(theIO);
818 #ifdef DEBUG_ACTIVATE
819 qDebug("activate in all modes");
822 foreach(int aMode, theModes) {
823 //aContext->Load(anAISIO, aMode, true);
824 if (!aModesActivatedForIO.contains(aMode)) {
825 aContext->Activate(theIO, aMode);
826 #ifdef DEBUG_ACTIVATE
827 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
835 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
837 AISObjectPtr anAISObj = getAISObject(theObject);
838 // correct the result's color it it has the attribute
839 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
841 // Customization of presentation
842 GeomCustomPrsPtr aCustomPrs;
843 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
844 if (aFeature.get() != NULL) {
845 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
846 if (aCustPrs.get() != NULL)
847 aCustomPrs = aCustPrs;
849 if (aCustomPrs.get() == NULL) {
850 // we ignore presentable not customized objects
851 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
852 if (aPrs.get() != NULL)
854 aCustomPrs = myCustomPrs;
856 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
860 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
862 if (!isVisible(theObject))
865 AISObjectPtr anAISObj = getAISObject(theObject);
867 anAISObj->getColor(aR, aG, aB);
868 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
871 return QColor(aR, aG, aB);