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& aOldShape = aShapePrs->Shape();
244 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
248 // Customization of presentation
249 bool isCustomized = customizeObject(theObject);
250 #ifdef DEBUG_FEATURE_REDISPLAY
251 //qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
252 // arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
254 if (!isEqualShapes || isCustomized) {
255 aContext->Redisplay(aAISIO, false);
256 #ifdef DEBUG_FEATURE_REDISPLAY
257 //qDebug(" Redisplay happens");
265 void XGUI_Displayer::deactivate(ObjectPtr theObject)
267 if (isVisible(theObject)) {
268 Handle(AIS_InteractiveContext) aContext = AISContext();
269 if (aContext.IsNull())
272 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
273 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
274 aContext->Deactivate(anAIS);
278 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
280 activate(theFeature, myActiveSelectionModes);
283 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
285 #ifdef DEBUG_ACTIVATE
286 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
288 if (aFeature.get() != NULL) {
290 getModesOfActivation(theObject, aModes);
293 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
294 arg(aFeature->data()->name().c_str()).
295 arg(theModes.size()).
296 arg(myActiveSelectionModes.size()).
297 arg(aModes.size()).toStdString().c_str());
301 if (isVisible(theObject)) {
302 Handle(AIS_InteractiveContext) aContext = AISContext();
303 if (aContext.IsNull())
306 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
307 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
309 activate(anAIS, theModes);
313 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
315 if (!isVisible(theObject))
318 Handle(AIS_InteractiveContext) aContext = AISContext();
319 if (aContext.IsNull())
322 AISObjectPtr aAISObj = getAISObject(theObject);
324 if (aAISObj.get() != NULL) {
325 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
326 TColStd_ListOfInteger aTColModes;
327 aContext->ActivatedModes(anAISIO, aTColModes);
328 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
329 for (; itr.More(); itr.Next() ) {
330 theModes.append(itr.Value());
335 void XGUI_Displayer::activateObjects(const QIntList& theModes)
337 #ifdef DEBUG_ACTIVATE
338 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
339 arg(theModes.size()).
340 arg(myActiveSelectionModes.size()).
341 toStdString().c_str());
343 // In order to avoid doblications of selection modes
345 foreach (int aMode, theModes) {
346 if (!aNewModes.contains(aMode))
347 aNewModes.append(aMode);
349 myActiveSelectionModes = aNewModes;
350 Handle(AIS_InteractiveContext) aContext = AISContext();
351 if (aContext.IsNull())
353 // Open local context if there is no one
354 if (!aContext->HasOpenedContext())
357 //aContext->UseDisplayedObjects();
358 //myUseExternalObjects = true;
360 AIS_ListOfInteractive aPrsList;
361 ::displayedObjects(aContext, aPrsList);
363 Handle(AIS_Trihedron) aTrihedron;
364 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
365 Handle(AIS_InteractiveObject) anAISIO;
366 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
367 anAISIO = aLIt.Value();
368 activate(anAISIO, myActiveSelectionModes);
373 void XGUI_Displayer::deactivateObjects()
375 myActiveSelectionModes.clear();
376 Handle(AIS_InteractiveContext) aContext = AISContext();
377 // Open local context if there is no one
378 if (!aContext->HasOpenedContext())
381 //aContext->NotUseDisplayedObjects();
382 AIS_ListOfInteractive aPrsList;
383 ::displayedObjects(aContext, aPrsList);
385 AIS_ListIteratorOfListOfInteractive aLIt;
386 //Handle(AIS_Trihedron) aTrihedron;
387 Handle(AIS_InteractiveObject) anAISIO;
388 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
389 anAISIO = aLIt.Value();
390 aContext->Deactivate(anAISIO);
394 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
396 Handle(AIS_InteractiveContext) aContext = AISContext();
397 if (aContext.IsNull())
399 if (!isVisible(theObject))
402 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
403 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
405 TColStd_ListOfInteger aModes;
406 aContext->ActivatedModes(anAIS, aModes);
407 return aModes.Extent() > 0;
410 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
412 Handle(AIS_InteractiveContext) aContext = AISContext();
413 if (aContext.IsNull())
415 if (aContext->HasOpenedContext()) {
416 aContext->UnhilightSelected();
417 aContext->ClearSelected();
418 foreach(ObjectPtr aResult, theResults) {
419 if (isVisible(aResult)) {
420 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
421 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
423 aContext->SetSelected(anAIS, false);
427 aContext->UnhilightCurrents();
428 aContext->ClearCurrents();
429 foreach(ObjectPtr aResult, theResults) {
430 if (isVisible(aResult)) {
431 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
432 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
434 aContext->SetCurrentObject(anAIS, false);
443 void XGUI_Displayer::clearSelected()
445 Handle(AIS_InteractiveContext) aContext = AISContext();
447 aContext->UnhilightCurrents(false);
448 aContext->ClearSelected();
452 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
454 Handle(AIS_InteractiveContext) aContext = AISContext();
455 if (!aContext.IsNull()) {
456 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
457 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
459 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
460 if (!anIO.IsNull()) {
461 emit beforeObjectErase(aObj, aAISObj);
462 aContext->Remove(anIO, false);
468 myResult2AISObjectMap.clear();
471 void XGUI_Displayer::openLocalContext()
473 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
474 if (aContext.IsNull())
476 // Open local context if there is no one
477 if (!aContext->HasOpenedContext()) {
478 // Preserve selected objects
479 //AIS_ListOfInteractive aAisList;
480 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
481 // aAisList.Append(aContext->Current());
483 // get the filters from the global context and append them to the local context
484 // a list of filters in the global context is not cleared and should be cleared here
485 SelectMgr_ListOfFilter aFilters;
486 aFilters.Assign(aContext->Filters());
487 // it is important to remove the filters in the global context, because there is a code
488 // in the closeLocalContex, which restore the global context filters
489 aContext->RemoveFilters();
491 //aContext->ClearCurrents();
492 aContext->OpenLocalContext();
493 //aContext->NotUseDisplayedObjects();
495 //myUseExternalObjects = false;
497 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
498 for (;aIt.More(); aIt.Next()) {
499 aContext->AddFilter(aIt.Value());
502 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
503 //for(; aIt2.More(); aIt2.Next()) {
504 // aContext->SetSelected(aIt2.Value(), false);
509 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
511 Handle(AIS_InteractiveContext) aContext = AISContext();
512 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
513 // Preserve selected objects
514 //AIS_ListOfInteractive aAisList;
515 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
516 // aAisList.Append(aContext->SelectedInteractive());
518 // get the filters from the local context and append them to the global context
519 // a list of filters in the local context is cleared
520 SelectMgr_ListOfFilter aFilters;
521 aFilters.Assign(aContext->Filters());
523 //aContext->ClearSelected();
524 aContext->CloseAllContexts(false);
526 // Redisplay all object if they were displayed in localContext
527 Handle(AIS_InteractiveObject) aAISIO;
528 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
529 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
530 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
531 aContext->Display(aAISIO, false);
532 aContext->SetDisplayMode(aAISIO, Shading, false);
536 // Append the filters from the local selection in the global selection context
537 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
538 for (;aIt.More(); aIt.Next()) {
539 Handle(SelectMgr_Filter) aFilter = aIt.Value();
540 aContext->AddFilter(aFilter);
545 //myUseExternalObjects = false;
548 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
549 //for(; aIt2.More(); aIt2.Next()) {
550 // if (aContext->IsDisplayed(aIt2.Value()))
551 // aContext->SetCurrentObject(aIt2.Value(), false);
556 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
559 if (myResult2AISObjectMap.contains(theObject))
560 anIO = myResult2AISObjectMap[theObject];
564 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
566 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
567 return getObject(aRefAIS);
570 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
573 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
574 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
575 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
582 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
584 bool aWasEnabled = myEnableUpdateViewer;
586 myEnableUpdateViewer = isEnabled;
591 void XGUI_Displayer::updateViewer()
593 Handle(AIS_InteractiveContext) aContext = AISContext();
594 if (!aContext.IsNull() && myEnableUpdateViewer)
595 aContext->UpdateCurrentViewer();
598 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
600 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
601 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
602 aContext->OpenLocalContext();
607 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
609 Handle(AIS_InteractiveContext) aContext = AISContext();
610 if (myAndFilter.IsNull() && !aContext.IsNull()) {
611 myAndFilter = new SelectMgr_AndFilter();
612 aContext->AddFilter(myAndFilter);
617 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
619 Handle(AIS_InteractiveContext) aContext = AISContext();
620 if (aContext.IsNull())
622 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
623 if (!anAISIO.IsNull()) {
624 aContext->Display(anAISIO, isUpdate);
625 if (aContext->HasOpenedContext()) {
626 //if (myUseExternalObjects) {
627 if (myActiveSelectionModes.size() == 0)
628 aContext->Activate(anAISIO);
630 foreach(int aMode, myActiveSelectionModes) {
631 aContext->Activate(anAISIO, aMode);
639 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
641 Handle(AIS_InteractiveContext) aContext = AISContext();
642 if (aContext.IsNull())
644 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
645 if (!anAISIO.IsNull()) {
646 aContext->Remove(anAISIO, isUpdate);
651 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
653 if (theMode == NoMode)
656 Handle(AIS_InteractiveContext) aContext = AISContext();
657 if (aContext.IsNull())
660 AISObjectPtr aAISObj = getAISObject(theObject);
664 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
665 bool aCanBeShaded = ::canBeShaded(aAISIO);
666 // In order to avoid extra closing/opening context
667 SelectMgr_IndexedMapOfOwner aSelectedOwners;
669 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
670 closeLocalContexts(false);
672 aContext->SetDisplayMode(aAISIO, theMode, false);
673 // Redisplay in order to update new mode because it could be not computed before
674 aContext->Redisplay(aAISIO, 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);