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
49 // Workaround for bug #25637
50 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
52 // Get from null point
53 theAIS->DisplayedObjects(theList, true);
54 if (theAIS->HasOpenedContext()) {
55 // get from local context
56 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
57 TColStd_MapOfTransient aMap;
58 int NbDisp = aLC->DisplayedObjects(aMap);
59 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
61 Handle(AIS_InteractiveObject) curIO;
62 Handle(Standard_Transient) Tr;
63 for(; aIt.More(); aIt.Next()){
65 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
66 theList.Append(curIO);
72 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
73 : myWorkshop(theWorkshop)
75 enableUpdateViewer(true);
76 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
79 XGUI_Displayer::~XGUI_Displayer()
83 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
85 return myResult2AISObjectMap.contains(theObject);
88 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
90 if (isVisible(theObject)) {
91 redisplay(theObject, isUpdateViewer);
94 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
95 if (aFeature.get() != NULL) {
96 qDebug(QString("display feature: %1, displayed: %2").
97 arg(aFeature->data()->name().c_str()).
98 arg(displayedObjects().size()).toStdString().c_str());
103 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
104 bool isShading = false;
105 if (aPrs.get() != NULL) {
106 anAIS = aPrs->getAISObject(AISObjectPtr());
108 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
109 if (aResult.get() != NULL) {
110 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
111 if (aShapePtr.get() != NULL) {
112 anAIS = AISObjectPtr(new GeomAPI_AISObject());
113 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
114 //anAIS->createShape(aShapePtr);
120 display(theObject, anAIS, isShading, isUpdateViewer);
124 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
126 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
127 if (!aShapePrs.IsNull()) {
128 TopoDS_Shape aShape = aShapePrs->Shape();
129 TopAbs_ShapeEnum aType = aShape.ShapeType();
130 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
133 // Check that the presentation is not a sketch
134 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
136 return !aPrs->isSketchMode();
143 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
144 bool isShading, bool isUpdateViewer)
146 Handle(AIS_InteractiveContext) aContext = AISContext();
147 if (aContext.IsNull())
150 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
151 if (!anAISIO.IsNull()) {
152 myResult2AISObjectMap[theObject] = theAIS;
153 bool aCanBeShaded = ::canBeShaded(anAISIO);
154 // In order to avoid extra closing/opening context
155 SelectMgr_IndexedMapOfOwner aSelectedOwners;
157 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
158 closeLocalContexts(false);
160 aContext->Display(anAISIO, false);
161 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
162 emit objectDisplayed(theObject, theAIS);
164 bool isCustomized = customizeObject(theObject);
166 aContext->Redisplay(anAISIO, false);
170 activateObjects(myActiveSelectionModes);
171 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
174 activate(anAISIO, myActiveSelectionModes);
180 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
182 if (!isVisible(theObject))
185 Handle(AIS_InteractiveContext) aContext = AISContext();
186 if (aContext.IsNull())
188 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
190 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
191 if (!anAIS.IsNull()) {
192 emit beforeObjectErase(theObject, anObject);
193 aContext->Remove(anAIS, isUpdateViewer);
196 myResult2AISObjectMap.remove(theObject);
199 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
201 if (!isVisible(theObject))
204 AISObjectPtr aAISObj = getAISObject(theObject);
205 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
207 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
209 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
211 erase(theObject, isUpdateViewer);
214 if (aAIS_Obj != aAISObj) {
215 myResult2AISObjectMap[theObject] = aAIS_Obj;
217 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
220 if (!aAISIO.IsNull()) {
221 Handle(AIS_InteractiveContext) aContext = AISContext();
222 if (aContext.IsNull())
224 // Check that the visualized shape is the same and the redisplay is not necessary
225 // Redisplay of AIS object leads to this object selection compute and the selection
226 // in the browser is lost
228 // this check is not necessary anymore because the selection store/restore is realized
229 // before and after the values modification.
230 // Moreother, this check avoids customize and redisplay presentation if the presentable
231 // parameter is changed.
232 bool isEqualShapes = false;
233 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
234 if (aResult.get() != NULL) {
235 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
236 if (!aShapePrs.IsNull()) {
237 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
238 if (aShapePtr.get()) {
239 const TopoDS_Shape& aShape = aShapePrs->Shape();
240 std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
241 anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
243 isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
247 // Customization of presentation
248 bool isCustomized = customizeObject(theObject);
249 if (!isEqualShapes || isCustomized) {
250 aContext->Redisplay(aAISIO, false);
257 void XGUI_Displayer::deactivate(ObjectPtr theObject)
259 if (isVisible(theObject)) {
260 Handle(AIS_InteractiveContext) aContext = AISContext();
261 if (aContext.IsNull())
264 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
265 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
266 aContext->Deactivate(anAIS);
270 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
272 activate(theFeature, myActiveSelectionModes);
275 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
277 #ifdef DEBUG_ACTIVATE
278 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
280 if (aFeature.get() != NULL) {
282 getModesOfActivation(theObject, aModes);
285 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
286 arg(aFeature->data()->name().c_str()).
287 arg(theModes.size()).
288 arg(myActiveSelectionModes.size()).
289 arg(aModes.size()).toStdString().c_str());
293 if (isVisible(theObject)) {
294 Handle(AIS_InteractiveContext) aContext = AISContext();
295 if (aContext.IsNull())
298 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
299 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
301 activate(anAIS, theModes);
305 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
307 if (!isVisible(theObject))
310 Handle(AIS_InteractiveContext) aContext = AISContext();
311 if (aContext.IsNull())
314 AISObjectPtr aAISObj = getAISObject(theObject);
316 if (aAISObj.get() != NULL) {
317 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
318 TColStd_ListOfInteger aTColModes;
319 aContext->ActivatedModes(anAISIO, aTColModes);
320 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
321 for (; itr.More(); itr.Next() ) {
322 theModes.append(itr.Value());
327 void XGUI_Displayer::activateObjects(const QIntList& theModes)
329 #ifdef DEBUG_ACTIVATE
330 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
331 arg(theModes.size()).
332 arg(myActiveSelectionModes.size()).
333 toStdString().c_str());
335 // In order to avoid doblications of selection modes
337 foreach (int aMode, theModes) {
338 if (!aNewModes.contains(aMode))
339 aNewModes.append(aMode);
341 myActiveSelectionModes = aNewModes;
342 Handle(AIS_InteractiveContext) aContext = AISContext();
343 if (aContext.IsNull())
345 // Open local context if there is no one
346 if (!aContext->HasOpenedContext())
349 //aContext->UseDisplayedObjects();
350 //myUseExternalObjects = true;
352 AIS_ListOfInteractive aPrsList;
353 ::displayedObjects(aContext, aPrsList);
355 Handle(AIS_Trihedron) aTrihedron;
356 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
357 Handle(AIS_InteractiveObject) anAISIO;
358 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
359 anAISIO = aLIt.Value();
360 activate(anAISIO, myActiveSelectionModes);
365 void XGUI_Displayer::deactivateObjects()
367 myActiveSelectionModes.clear();
368 Handle(AIS_InteractiveContext) aContext = AISContext();
369 // Open local context if there is no one
370 if (!aContext->HasOpenedContext())
373 //aContext->NotUseDisplayedObjects();
374 AIS_ListOfInteractive aPrsList;
375 ::displayedObjects(aContext, aPrsList);
377 AIS_ListIteratorOfListOfInteractive aLIt;
378 //Handle(AIS_Trihedron) aTrihedron;
379 Handle(AIS_InteractiveObject) anAISIO;
380 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
381 anAISIO = aLIt.Value();
382 aContext->Deactivate(anAISIO);
386 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
388 Handle(AIS_InteractiveContext) aContext = AISContext();
389 if (aContext.IsNull())
391 if (!isVisible(theObject))
394 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
395 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
397 TColStd_ListOfInteger aModes;
398 aContext->ActivatedModes(anAIS, aModes);
399 return aModes.Extent() > 0;
402 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
404 Handle(AIS_InteractiveContext) aContext = AISContext();
405 if (aContext.IsNull())
407 if (aContext->HasOpenedContext()) {
408 aContext->UnhilightSelected();
409 aContext->ClearSelected();
410 foreach(ObjectPtr aResult, theResults) {
411 if (isVisible(aResult)) {
412 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
413 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
415 aContext->SetSelected(anAIS, false);
419 aContext->UnhilightCurrents();
420 aContext->ClearCurrents();
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->SetCurrentObject(anAIS, false);
435 void XGUI_Displayer::clearSelected()
437 Handle(AIS_InteractiveContext) aContext = AISContext();
439 aContext->UnhilightCurrents(false);
440 aContext->ClearSelected();
444 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
446 Handle(AIS_InteractiveContext) aContext = AISContext();
447 if (!aContext.IsNull()) {
448 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
449 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
451 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
452 if (!anIO.IsNull()) {
453 emit beforeObjectErase(aObj, aAISObj);
454 aContext->Remove(anIO, false);
460 myResult2AISObjectMap.clear();
463 void XGUI_Displayer::openLocalContext()
465 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
466 if (aContext.IsNull())
468 // Open local context if there is no one
469 if (!aContext->HasOpenedContext()) {
470 // Preserve selected objects
471 //AIS_ListOfInteractive aAisList;
472 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
473 // aAisList.Append(aContext->Current());
475 // get the filters from the global context and append them to the local context
476 // a list of filters in the global context is not cleared and should be cleared here
477 SelectMgr_ListOfFilter aFilters;
478 aFilters.Assign(aContext->Filters());
479 // it is important to remove the filters in the global context, because there is a code
480 // in the closeLocalContex, which restore the global context filters
481 aContext->RemoveFilters();
483 //aContext->ClearCurrents();
484 aContext->OpenLocalContext();
485 //aContext->NotUseDisplayedObjects();
487 //myUseExternalObjects = false;
489 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
490 for (;aIt.More(); aIt.Next()) {
491 aContext->AddFilter(aIt.Value());
494 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
495 //for(; aIt2.More(); aIt2.Next()) {
496 // aContext->SetSelected(aIt2.Value(), false);
501 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
503 Handle(AIS_InteractiveContext) aContext = AISContext();
504 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
505 // Preserve selected objects
506 //AIS_ListOfInteractive aAisList;
507 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
508 // aAisList.Append(aContext->SelectedInteractive());
510 // get the filters from the local context and append them to the global context
511 // a list of filters in the local context is cleared
512 SelectMgr_ListOfFilter aFilters;
513 aFilters.Assign(aContext->Filters());
515 //aContext->ClearSelected();
516 aContext->CloseAllContexts(false);
518 // Redisplay all object if they were displayed in localContext
519 Handle(AIS_InteractiveObject) aAISIO;
520 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
521 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
522 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
523 aContext->Display(aAISIO, false);
524 aContext->SetDisplayMode(aAISIO, Shading, false);
528 // Append the filters from the local selection in the global selection context
529 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
530 for (;aIt.More(); aIt.Next()) {
531 Handle(SelectMgr_Filter) aFilter = aIt.Value();
532 aContext->AddFilter(aFilter);
537 //myUseExternalObjects = false;
540 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
541 //for(; aIt2.More(); aIt2.Next()) {
542 // if (aContext->IsDisplayed(aIt2.Value()))
543 // aContext->SetCurrentObject(aIt2.Value(), false);
548 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
551 if (myResult2AISObjectMap.contains(theObject))
552 anIO = myResult2AISObjectMap[theObject];
556 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
558 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
559 return getObject(aRefAIS);
562 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
565 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
566 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
567 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
574 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
576 bool aWasEnabled = myEnableUpdateViewer;
578 myEnableUpdateViewer = isEnabled;
583 void XGUI_Displayer::updateViewer()
585 Handle(AIS_InteractiveContext) aContext = AISContext();
586 if (!aContext.IsNull() && myEnableUpdateViewer)
587 aContext->UpdateCurrentViewer();
590 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
592 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
593 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
594 aContext->OpenLocalContext();
599 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
601 Handle(AIS_InteractiveContext) aContext = AISContext();
602 if (myAndFilter.IsNull() && !aContext.IsNull()) {
603 myAndFilter = new SelectMgr_AndFilter();
604 aContext->AddFilter(myAndFilter);
609 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
611 Handle(AIS_InteractiveContext) aContext = AISContext();
612 if (aContext.IsNull())
614 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
615 if (!anAISIO.IsNull()) {
616 aContext->Display(anAISIO, isUpdate);
617 if (aContext->HasOpenedContext()) {
618 //if (myUseExternalObjects) {
619 if (myActiveSelectionModes.size() == 0)
620 aContext->Activate(anAISIO);
622 foreach(int aMode, myActiveSelectionModes) {
623 aContext->Activate(anAISIO, aMode);
631 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
633 Handle(AIS_InteractiveContext) aContext = AISContext();
634 if (aContext.IsNull())
636 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
637 if (!anAISIO.IsNull()) {
638 aContext->Remove(anAISIO, isUpdate);
643 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
645 if (theMode == NoMode)
648 Handle(AIS_InteractiveContext) aContext = AISContext();
649 if (aContext.IsNull())
652 AISObjectPtr aAISObj = getAISObject(theObject);
656 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
657 bool aCanBeShaded = ::canBeShaded(aAISIO);
658 // In order to avoid extra closing/opening context
659 SelectMgr_IndexedMapOfOwner aSelectedOwners;
661 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
662 closeLocalContexts(false);
664 aContext->SetDisplayMode(aAISIO, theMode, false);
667 activateObjects(myActiveSelectionModes);
668 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
674 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
676 Handle(AIS_InteractiveContext) aContext = AISContext();
677 if (aContext.IsNull())
680 AISObjectPtr aAISObj = getAISObject(theObject);
684 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
685 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
688 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
690 Handle(AIS_InteractiveContext) aContext = AISContext();
691 if (aContext.IsNull())
693 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
694 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
695 for (; aIt.More(); aIt.Next()) {
696 if (theFilter.Access() == aIt.Value().Access())
699 GetFilter()->Add(theFilter);
702 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
704 Handle(AIS_InteractiveContext) aContext = AISContext();
705 if (aContext.IsNull())
707 GetFilter()->Remove(theFilter);
710 void XGUI_Displayer::removeFilters()
712 Handle(AIS_InteractiveContext) aContext = AISContext();
713 if (aContext.IsNull())
715 GetFilter()->Clear();
718 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
720 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
721 foreach(ObjectPtr aObj, aDispList) {
722 if (!theList.contains(aObj))
725 foreach(ObjectPtr aObj, theList) {
726 if (!isVisible(aObj))
727 display(aObj, false);
732 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
734 if (!isVisible(theObject))
737 AISObjectPtr aAISObj = getAISObject(theObject);
738 if (aAISObj.get() == NULL)
741 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
742 return ::canBeShaded(anAIS);
745 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
746 const QIntList& theModes) const
748 Handle(AIS_InteractiveContext) aContext = AISContext();
749 if (aContext.IsNull() || theIO.IsNull())
752 aContext->Load(theIO, -1, true);
753 aContext->Deactivate(theIO);
754 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
755 //Deactivate trihedron which can be activated in local selector
756 if (aTrihedron.IsNull()) {
757 //aContext->Load(anAISIO, -1, true);
758 // In order to clear active modes list
759 if (theModes.size() == 0) {
760 //aContext->Load(anAISIO, 0, true);
761 aContext->Activate(theIO);
763 foreach(int aMode, theModes) {
764 //aContext->Load(anAISIO, aMode, true);
765 aContext->Activate(theIO, aMode);
771 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
773 AISObjectPtr anAISObj = getAISObject(theObject);
774 // correct the result's color it it has the attribute
775 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
777 // Customization of presentation
778 GeomCustomPrsPtr aCustomPrs;
779 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
780 if (aFeature.get() != NULL) {
781 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
782 if (aCustPrs.get() != NULL)
783 aCustomPrs = aCustPrs;
785 if (aCustomPrs.get() == NULL) {
786 // we ignore presentable not customized objects
787 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
788 if (aPrs.get() != NULL)
790 aCustomPrs = myCustomPrs;
792 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);