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_DISPLAY
50 //#define DEBUG_ACTIVATE
51 //#define DEBUG_FEATURE_REDISPLAY
52 //#define DEBUG_SELECTION_FILTERS
53 //#define DEBUG_USE_CLEAR_OUTDATED_SELECTION
55 // Workaround for bug #25637
56 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
58 // Get from null point
59 theAIS->DisplayedObjects(theList, true);
60 if (theAIS->HasOpenedContext()) {
61 // get from local context
62 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
63 TColStd_MapOfTransient aMap;
64 int NbDisp = aLC->DisplayedObjects(aMap);
65 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
67 Handle(AIS_InteractiveObject) curIO;
68 Handle(Standard_Transient) Tr;
69 for(; aIt.More(); aIt.Next()){
71 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
72 theList.Append(curIO);
78 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
79 : myWorkshop(theWorkshop)
81 enableUpdateViewer(true);
82 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
85 XGUI_Displayer::~XGUI_Displayer()
89 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
91 return myResult2AISObjectMap.contains(theObject);
94 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
96 if (isVisible(theObject)) {
97 redisplay(theObject, isUpdateViewer);
101 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
102 bool isShading = false;
103 if (aPrs.get() != NULL) {
104 anAIS = aPrs->getAISObject(anAIS);
106 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
107 if (aResult.get() != NULL) {
108 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
109 if (aShapePtr.get() != NULL) {
110 anAIS = AISObjectPtr(new GeomAPI_AISObject());
111 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
112 //anAIS->createShape(aShapePtr);
118 display(theObject, anAIS, isShading, isUpdateViewer);
122 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
124 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
125 if (!aShapePrs.IsNull()) {
126 TopoDS_Shape aShape = aShapePrs->Shape();
127 TopAbs_ShapeEnum aType = aShape.ShapeType();
128 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
131 // Check that the presentation is not a sketch
132 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
134 return !aPrs->isSketchMode();
141 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
142 bool isShading, bool isUpdateViewer)
144 Handle(AIS_InteractiveContext) aContext = AISContext();
145 if (aContext.IsNull())
148 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
149 if (!anAISIO.IsNull()) {
150 appendResultObject(theObject, theAIS);
152 bool isCustomized = customizeObject(theObject);
154 int aDispMode = isShading? Shading : Wireframe;
156 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
157 anAISIO->SetDisplayMode(aDispMode);
158 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
160 emit objectDisplayed(theObject, theAIS);
161 activate(anAISIO, myActiveSelectionModes);
167 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
169 if (!isVisible(theObject))
172 Handle(AIS_InteractiveContext) aContext = AISContext();
173 if (aContext.IsNull())
175 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
177 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
178 if (!anAIS.IsNull()) {
179 emit beforeObjectErase(theObject, anObject);
180 aContext->Remove(anAIS, isUpdateViewer);
183 myResult2AISObjectMap.remove(theObject);
186 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
188 if (!isVisible(theObject))
191 AISObjectPtr aAISObj = getAISObject(theObject);
192 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
194 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
196 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
198 erase(theObject, isUpdateViewer);
201 if (aAIS_Obj != aAISObj) {
202 appendResultObject(theObject, aAIS_Obj);
204 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
207 if (!aAISIO.IsNull()) {
208 Handle(AIS_InteractiveContext) aContext = AISContext();
209 if (aContext.IsNull())
211 // Check that the visualized shape is the same and the redisplay is not necessary
212 // Redisplay of AIS object leads to this object selection compute and the selection
213 // in the browser is lost
215 // this check is not necessary anymore because the selection store/restore is realized
216 // before and after the values modification.
217 // Moreother, this check avoids customize and redisplay presentation if the presentable
218 // parameter is changed.
219 bool isEqualShapes = false;
220 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
221 if (aResult.get() != NULL) {
222 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
223 if (!aShapePrs.IsNull()) {
224 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
225 if (aShapePtr.get()) {
226 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
227 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
231 // Customization of presentation
232 bool isCustomized = customizeObject(theObject);
233 #ifdef DEBUG_FEATURE_REDISPLAY
234 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
235 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
237 if (!isEqualShapes || isCustomized) {
238 aContext->Redisplay(aAISIO, false);
239 #ifdef DEBUG_FEATURE_REDISPLAY
240 qDebug(" Redisplay happens");
248 void XGUI_Displayer::deactivate(ObjectPtr theObject)
250 if (isVisible(theObject)) {
251 Handle(AIS_InteractiveContext) aContext = AISContext();
252 if (aContext.IsNull())
255 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
256 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
257 aContext->Deactivate(anAIS);
258 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
259 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
265 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
267 if (!isVisible(theObject))
270 Handle(AIS_InteractiveContext) aContext = AISContext();
271 if (aContext.IsNull())
274 AISObjectPtr aAISObj = getAISObject(theObject);
276 if (aAISObj.get() != NULL) {
277 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
278 TColStd_ListOfInteger aTColModes;
279 aContext->ActivatedModes(anAISIO, aTColModes);
280 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
281 for (; itr.More(); itr.Next() ) {
282 theModes.append(itr.Value());
287 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList)
289 #ifdef DEBUG_ACTIVATE
290 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
291 arg(theModes.size()).
292 arg(myActiveSelectionModes.size()).
293 toStdString().c_str());
295 // In order to avoid doblications of selection modes
297 foreach (int aMode, theModes) {
298 if (!aNewModes.contains(aMode))
299 aNewModes.append(aMode);
301 myActiveSelectionModes = aNewModes;
302 Handle(AIS_InteractiveContext) aContext = AISContext();
303 if (aContext.IsNull())
305 // Open local context if there is no one
306 if (!aContext->HasOpenedContext())
309 // we need to block the sort of the viewer selector during deactivate/activate because
310 // it takes a lot of time if there are a many objects are processed. It can be performed
311 // manualy after the activation is peformed
312 //Handle(StdSelect_ViewerSelector3d) aSelector = aContext->LocalContext()->MainSelector();
313 //bool isUpdateSortPossible = !aSelector.IsNull() && aSelector->IsUpdateSortPossible();
314 //if (!aSelector.IsNull())
315 // aSelector->SetUpdateSortPossible(false);
317 //aContext->UseDisplayedObjects();
318 //myUseExternalObjects = true;
320 Handle(AIS_InteractiveObject) anAISIO;
321 AIS_ListOfInteractive aPrsList;
322 if (theObjList.isEmpty())
323 ::displayedObjects(aContext, aPrsList);
325 foreach(ObjectPtr aObj, theObjList) {
326 if (myResult2AISObjectMap.contains(aObj))
327 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
331 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
332 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
333 anAISIO = aLIt.Value();
334 activate(anAISIO, myActiveSelectionModes);
336 // restore the sorting flag and perform the sort of selection
337 //if (!aSelector.IsNull()) {
338 // aSelector->SetUpdateSortPossible(isUpdateSortPossible);
339 // aSelector->UpdateSort();
344 void XGUI_Displayer::deactivateObjects()
346 myActiveSelectionModes.clear();
347 Handle(AIS_InteractiveContext) aContext = AISContext();
348 // Open local context if there is no one
349 if (!aContext->HasOpenedContext())
352 //aContext->NotUseDisplayedObjects();
353 AIS_ListOfInteractive aPrsList;
354 ::displayedObjects(aContext, aPrsList);
356 AIS_ListIteratorOfListOfInteractive aLIt;
357 //Handle(AIS_Trihedron) aTrihedron;
358 Handle(AIS_InteractiveObject) anAISIO;
359 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
360 anAISIO = aLIt.Value();
361 aContext->Deactivate(anAISIO);
362 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
363 aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
369 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
371 Handle(AIS_InteractiveContext) aContext = AISContext();
372 if (aContext.IsNull())
374 if (!isVisible(theObject))
377 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
378 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
380 TColStd_ListOfInteger aModes;
381 aContext->ActivatedModes(anAIS, aModes);
382 return aModes.Extent() > 0;
385 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer)
387 Handle(AIS_InteractiveContext) aContext = AISContext();
388 if (aContext.IsNull())
390 if (aContext->HasOpenedContext()) {
391 aContext->UnhilightSelected();
392 aContext->ClearSelected();
393 //if (aSelected.size() > 0) {
394 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
395 const TopoDS_Shape& aShape = aPrs.shape();
396 if (!aShape.IsNull()) {
397 aContext->AddOrRemoveSelected(aShape, false);
399 ObjectPtr anObject = aPrs.object();
400 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
401 if (aResult.get() && isVisible(aResult)) {
402 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
403 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
404 if (!anAIS.IsNull()) {
405 // The methods are replaced in order to provide multi-selection, e.g. restore selection
406 // by activating multi selector widget. It also gives an advantage that the multi
407 // selection in OB gives multi-selection in the viewer
408 //aContext->SetSelected(anAIS, false);
409 // The selection in the context was cleared, so the method sets the objects are selected
410 aContext->AddOrRemoveSelected(anAIS, false);
416 aContext->UnhilightCurrents();
417 aContext->ClearCurrents();
418 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
419 ObjectPtr anObject = aPrs.object();
420 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
421 if (aResult.get() && isVisible(aResult)) {
422 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
423 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
425 aContext->SetCurrentObject(anAIS, false);
433 void XGUI_Displayer::clearSelected()
435 Handle(AIS_InteractiveContext) aContext = AISContext();
437 aContext->UnhilightCurrents(false);
438 aContext->ClearSelected();
442 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
444 Handle(AIS_InteractiveContext) aContext = AISContext();
445 if (!aContext.IsNull()) {
446 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
447 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
449 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
450 if (!anIO.IsNull()) {
451 emit beforeObjectErase(aObj, aAISObj);
452 aContext->Remove(anIO, false);
458 myResult2AISObjectMap.clear();
461 void XGUI_Displayer::openLocalContext()
463 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
464 if (aContext.IsNull())
466 // Open local context if there is no one
467 if (!aContext->HasOpenedContext()) {
468 // Preserve selected objects
469 //AIS_ListOfInteractive aAisList;
470 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
471 // aAisList.Append(aContext->Current());
473 // get the filters from the global context and append them to the local context
474 // a list of filters in the global context is not cleared and should be cleared here
475 SelectMgr_ListOfFilter aFilters;
476 aFilters.Assign(aContext->Filters());
477 // it is important to remove the filters in the global context, because there is a code
478 // in the closeLocalContex, which restore the global context filters
479 aContext->RemoveFilters();
481 //aContext->ClearCurrents();
482 aContext->OpenLocalContext();
483 //aContext->NotUseDisplayedObjects();
485 //myUseExternalObjects = false;
487 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
488 for (;aIt.More(); aIt.Next()) {
489 aContext->AddFilter(aIt.Value());
492 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
493 //for(; aIt2.More(); aIt2.Next()) {
494 // aContext->SetSelected(aIt2.Value(), false);
499 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
501 Handle(AIS_InteractiveContext) aContext = AISContext();
502 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
503 // Preserve selected objects
504 //AIS_ListOfInteractive aAisList;
505 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
506 // aAisList.Append(aContext->SelectedInteractive());
508 // get the filters from the local context and append them to the global context
509 // a list of filters in the local context is cleared
510 SelectMgr_ListOfFilter aFilters;
511 aFilters.Assign(aContext->Filters());
513 //aContext->ClearSelected();
514 aContext->CloseAllContexts(false);
516 // Redisplay all object if they were displayed in localContext
517 Handle(AIS_InteractiveObject) aAISIO;
518 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
519 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
520 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
521 aContext->Display(aAISIO, false);
522 aContext->SetDisplayMode(aAISIO, Shading, false);
526 // Append the filters from the local selection in the global selection context
527 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
528 for (;aIt.More(); aIt.Next()) {
529 Handle(SelectMgr_Filter) aFilter = aIt.Value();
530 aContext->AddFilter(aFilter);
535 //myUseExternalObjects = false;
538 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
539 //for(; aIt2.More(); aIt2.Next()) {
540 // if (aContext->IsDisplayed(aIt2.Value()))
541 // aContext->SetCurrentObject(aIt2.Value(), false);
546 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
549 if (myResult2AISObjectMap.contains(theObject))
550 anIO = myResult2AISObjectMap[theObject];
554 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
556 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
557 return getObject(aRefAIS);
560 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
563 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
564 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
565 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
572 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
574 bool aWasEnabled = myEnableUpdateViewer;
576 myEnableUpdateViewer = isEnabled;
581 void XGUI_Displayer::updateViewer() const
583 Handle(AIS_InteractiveContext) aContext = AISContext();
584 if (!aContext.IsNull() && myEnableUpdateViewer)
585 aContext->UpdateCurrentViewer();
588 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
590 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
591 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
592 aContext->OpenLocalContext();
597 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
599 Handle(AIS_InteractiveContext) aContext = AISContext();
600 if (myAndFilter.IsNull() && !aContext.IsNull()) {
601 myAndFilter = new SelectMgr_AndFilter();
602 aContext->AddFilter(myAndFilter);
607 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
609 Handle(AIS_InteractiveContext) aContext = AISContext();
610 if (aContext.IsNull())
612 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
613 if (!anAISIO.IsNull()) {
614 aContext->Display(anAISIO, isUpdate);
615 if (aContext->HasOpenedContext()) {
616 //if (myUseExternalObjects) {
617 if (myActiveSelectionModes.size() == 0)
618 aContext->Activate(anAISIO);
620 foreach(int aMode, myActiveSelectionModes) {
621 aContext->Activate(anAISIO, aMode);
629 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
631 Handle(AIS_InteractiveContext) aContext = AISContext();
632 if (aContext.IsNull())
634 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
635 if (!anAISIO.IsNull()) {
636 aContext->Remove(anAISIO, isUpdate);
641 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
643 if (theMode == NoMode)
646 Handle(AIS_InteractiveContext) aContext = AISContext();
647 if (aContext.IsNull())
650 AISObjectPtr aAISObj = getAISObject(theObject);
654 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
655 aContext->SetDisplayMode(aAISIO, theMode, false);
656 // Redisplay in order to update new mode because it could be not computed before
661 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
663 Handle(AIS_InteractiveContext) aContext = AISContext();
664 if (aContext.IsNull())
667 AISObjectPtr aAISObj = getAISObject(theObject);
671 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
672 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
675 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
677 Handle(AIS_InteractiveContext) aContext = AISContext();
678 if (aContext.IsNull())
680 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
681 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
682 for (; aIt.More(); aIt.Next()) {
683 if (theFilter.Access() == aIt.Value().Access())
686 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
687 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
688 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
689 if (theFilter.Access() == aIt.Value().Access())
692 aCompFilter->Add(theFilter);
693 #ifdef DEBUG_SELECTION_FILTERS
694 int aCount = GetFilter()->StoredFilters().Extent();
695 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
699 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
701 Handle(AIS_InteractiveContext) aContext = AISContext();
702 if (aContext.IsNull())
704 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
705 if (aCompositeFilter->IsIn(theFilter))
706 aCompositeFilter->Remove(theFilter);
707 #ifdef DEBUG_SELECTION_FILTERS
708 int aCount = GetFilter()->StoredFilters().Extent();
709 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
713 void XGUI_Displayer::removeFilters()
715 Handle(AIS_InteractiveContext) aContext = AISContext();
716 if (aContext.IsNull())
718 GetFilter()->Clear();
721 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
723 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
724 foreach(ObjectPtr aObj, aDispList) {
725 if (!theList.contains(aObj))
728 foreach(ObjectPtr aObj, theList) {
729 if (!isVisible(aObj))
730 display(aObj, false);
735 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
737 if (!isVisible(theObject))
740 AISObjectPtr aAISObj = getAISObject(theObject);
741 if (aAISObj.get() == NULL)
744 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
745 return ::canBeShaded(anAIS);
748 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
749 const QIntList& theModes) const
751 Handle(AIS_InteractiveContext) aContext = AISContext();
752 if (aContext.IsNull() || theIO.IsNull())
755 // deactivate object in all modes, which are not in the list of activation
756 // It seems that after the IO deactivation the selected state of the IO's owners
757 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
758 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
759 // only if there is a difference in the current modes and the parameters modes.
760 // If the selection problem happens again, it is possible to write a test scenario and create
761 // a bug. The bug steps are the following:
762 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
763 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
764 TColStd_ListOfInteger aTColModes;
765 aContext->ActivatedModes(theIO, aTColModes);
766 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
767 QIntList aModesActivatedForIO;
768 //bool isDeactivated = false;
769 for (; itr.More(); itr.Next() ) {
770 Standard_Integer aMode = itr.Value();
771 if (!theModes.contains(aMode)) {
772 #ifdef DEBUG_ACTIVATE
773 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
775 aContext->Deactivate(theIO, aMode);
776 //isDeactivated = true;
779 aModesActivatedForIO.append(aMode);
780 #ifdef DEBUG_ACTIVATE
781 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
785 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
787 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
791 // loading the interactive object allowing the decomposition
792 if (aTColModes.IsEmpty())
793 aContext->Load(theIO, -1, true);
795 // trihedron AIS check should be after the AIS loading.
796 // If it is not loaded, it is steel selectable in the viewer.
797 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
798 if (aTrihedron.IsNull()) {
799 //aContext->Load(anAISIO, -1, true);
800 // In order to clear active modes list
801 if (theModes.size() == 0) {
802 //aContext->Load(anAISIO, 0, true);
803 aContext->Activate(theIO);
804 #ifdef DEBUG_ACTIVATE
805 qDebug("activate in all modes");
808 foreach(int aMode, theModes) {
809 //aContext->Load(anAISIO, aMode, true);
810 if (!aModesActivatedForIO.contains(aMode)) {
811 aContext->Activate(theIO, aMode);
812 #ifdef DEBUG_ACTIVATE
813 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
821 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
823 AISObjectPtr anAISObj = getAISObject(theObject);
824 // correct the result's color it it has the attribute
825 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
827 // Customization of presentation
828 GeomCustomPrsPtr aCustomPrs;
829 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
830 if (aFeature.get() != NULL) {
831 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
832 if (aCustPrs.get() != NULL)
833 aCustomPrs = aCustPrs;
835 if (aCustomPrs.get() == NULL) {
836 // we ignore presentable not customized objects
837 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
838 if (aPrs.get() != NULL)
840 aCustomPrs = myCustomPrs;
842 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
846 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
848 if (!isVisible(theObject))
851 AISObjectPtr anAISObj = getAISObject(theObject);
853 anAISObj->getColor(aR, aG, aB);
854 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
857 return QColor(aR, aG, aB);
860 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
862 myResult2AISObjectMap[theObject] = theAIS;
865 std::ostringstream aPtrStr;
866 aPtrStr << theObject.get();
867 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
868 qDebug(getResult2AISObjectMapInfo().c_str());
872 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
874 QStringList aContent;
875 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
876 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
877 std::ostringstream aPtrStr;
878 aPtrStr << "aObj = " << aObj.get() << ":";
879 aPtrStr << "anAIS = " << aAISObj.get() << ":";
880 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
882 aContent.append(aPtrStr.str().c_str());
884 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
885 arg(aContent.join("\n")).toStdString().c_str();