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);
163 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
164 emit objectDisplayed(theObject, theAIS);
166 bool isCustomized = customizeObject(theObject);
168 aContext->Redisplay(anAISIO, false);
172 activateObjects(myActiveSelectionModes);
173 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
176 activate(anAISIO, myActiveSelectionModes);
182 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
184 if (!isVisible(theObject))
187 Handle(AIS_InteractiveContext) aContext = AISContext();
188 if (aContext.IsNull())
190 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
192 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
193 if (!anAIS.IsNull()) {
194 emit beforeObjectErase(theObject, anObject);
195 aContext->Remove(anAIS, isUpdateViewer);
198 myResult2AISObjectMap.remove(theObject);
201 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
203 if (!isVisible(theObject))
206 AISObjectPtr aAISObj = getAISObject(theObject);
207 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
209 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
211 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
213 erase(theObject, isUpdateViewer);
216 if (aAIS_Obj != aAISObj) {
217 myResult2AISObjectMap[theObject] = aAIS_Obj;
219 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
222 if (!aAISIO.IsNull()) {
223 Handle(AIS_InteractiveContext) aContext = AISContext();
224 if (aContext.IsNull())
226 // Check that the visualized shape is the same and the redisplay is not necessary
227 // Redisplay of AIS object leads to this object selection compute and the selection
228 // in the browser is lost
230 // this check is not necessary anymore because the selection store/restore is realized
231 // before and after the values modification.
232 // Moreother, this check avoids customize and redisplay presentation if the presentable
233 // parameter is changed.
234 bool isEqualShapes = false;
235 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
236 if (aResult.get() != NULL) {
237 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
238 if (!aShapePrs.IsNull()) {
239 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
240 if (aShapePtr.get()) {
241 const TopoDS_Shape& aShape = aShapePrs->Shape();
242 std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
243 anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
245 isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
249 // Customization of presentation
250 bool isCustomized = customizeObject(theObject);
251 if (!isEqualShapes || isCustomized) {
252 aContext->Redisplay(aAISIO, false);
259 void XGUI_Displayer::deactivate(ObjectPtr theObject)
261 if (isVisible(theObject)) {
262 Handle(AIS_InteractiveContext) aContext = AISContext();
263 if (aContext.IsNull())
266 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
267 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
268 aContext->Deactivate(anAIS);
272 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
274 activate(theFeature, myActiveSelectionModes);
277 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
279 #ifdef DEBUG_ACTIVATE
280 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
282 if (aFeature.get() != NULL) {
284 getModesOfActivation(theObject, aModes);
287 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
288 arg(aFeature->data()->name().c_str()).
289 arg(theModes.size()).
290 arg(myActiveSelectionModes.size()).
291 arg(aModes.size()).toStdString().c_str());
295 if (isVisible(theObject)) {
296 Handle(AIS_InteractiveContext) aContext = AISContext();
297 if (aContext.IsNull())
300 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
301 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
303 activate(anAIS, theModes);
307 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
309 if (!isVisible(theObject))
312 Handle(AIS_InteractiveContext) aContext = AISContext();
313 if (aContext.IsNull())
316 AISObjectPtr aAISObj = getAISObject(theObject);
318 if (aAISObj.get() != NULL) {
319 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
320 TColStd_ListOfInteger aTColModes;
321 aContext->ActivatedModes(anAISIO, aTColModes);
322 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
323 for (; itr.More(); itr.Next() ) {
324 theModes.append(itr.Value());
329 void XGUI_Displayer::activateObjects(const QIntList& theModes)
331 #ifdef DEBUG_ACTIVATE
332 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
333 arg(theModes.size()).
334 arg(myActiveSelectionModes.size()).
335 toStdString().c_str());
337 // In order to avoid doblications of selection modes
339 foreach (int aMode, theModes) {
340 if (!aNewModes.contains(aMode))
341 aNewModes.append(aMode);
343 myActiveSelectionModes = aNewModes;
344 Handle(AIS_InteractiveContext) aContext = AISContext();
345 if (aContext.IsNull())
347 // Open local context if there is no one
348 if (!aContext->HasOpenedContext())
351 //aContext->UseDisplayedObjects();
352 //myUseExternalObjects = true;
354 AIS_ListOfInteractive aPrsList;
355 ::displayedObjects(aContext, aPrsList);
357 Handle(AIS_Trihedron) aTrihedron;
358 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
359 Handle(AIS_InteractiveObject) anAISIO;
360 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
361 anAISIO = aLIt.Value();
362 activate(anAISIO, myActiveSelectionModes);
367 void XGUI_Displayer::deactivateObjects()
369 myActiveSelectionModes.clear();
370 Handle(AIS_InteractiveContext) aContext = AISContext();
371 // Open local context if there is no one
372 if (!aContext->HasOpenedContext())
375 //aContext->NotUseDisplayedObjects();
376 AIS_ListOfInteractive aPrsList;
377 ::displayedObjects(aContext, aPrsList);
379 AIS_ListIteratorOfListOfInteractive aLIt;
380 //Handle(AIS_Trihedron) aTrihedron;
381 Handle(AIS_InteractiveObject) anAISIO;
382 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
383 anAISIO = aLIt.Value();
384 aContext->Deactivate(anAISIO);
388 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
390 Handle(AIS_InteractiveContext) aContext = AISContext();
391 if (aContext.IsNull())
393 if (!isVisible(theObject))
396 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
397 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
399 TColStd_ListOfInteger aModes;
400 aContext->ActivatedModes(anAIS, aModes);
401 return aModes.Extent() > 0;
404 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
406 Handle(AIS_InteractiveContext) aContext = AISContext();
407 if (aContext.IsNull())
409 if (aContext->HasOpenedContext()) {
410 aContext->UnhilightSelected();
411 aContext->ClearSelected();
412 foreach(ObjectPtr aResult, theResults) {
413 if (isVisible(aResult)) {
414 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
415 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
417 aContext->SetSelected(anAIS, false);
421 aContext->UnhilightCurrents();
422 aContext->ClearCurrents();
423 foreach(ObjectPtr aResult, theResults) {
424 if (isVisible(aResult)) {
425 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
426 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
428 aContext->SetCurrentObject(anAIS, false);
437 void XGUI_Displayer::clearSelected()
439 Handle(AIS_InteractiveContext) aContext = AISContext();
441 aContext->UnhilightCurrents(false);
442 aContext->ClearSelected();
446 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
448 Handle(AIS_InteractiveContext) aContext = AISContext();
449 if (!aContext.IsNull()) {
450 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
451 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
453 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
454 if (!anIO.IsNull()) {
455 emit beforeObjectErase(aObj, aAISObj);
456 aContext->Remove(anIO, false);
462 myResult2AISObjectMap.clear();
465 void XGUI_Displayer::openLocalContext()
467 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
468 if (aContext.IsNull())
470 // Open local context if there is no one
471 if (!aContext->HasOpenedContext()) {
472 // Preserve selected objects
473 //AIS_ListOfInteractive aAisList;
474 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
475 // aAisList.Append(aContext->Current());
477 // get the filters from the global context and append them to the local context
478 // a list of filters in the global context is not cleared and should be cleared here
479 SelectMgr_ListOfFilter aFilters;
480 aFilters.Assign(aContext->Filters());
481 // it is important to remove the filters in the global context, because there is a code
482 // in the closeLocalContex, which restore the global context filters
483 aContext->RemoveFilters();
485 //aContext->ClearCurrents();
486 aContext->OpenLocalContext();
487 //aContext->NotUseDisplayedObjects();
489 //myUseExternalObjects = false;
491 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
492 for (;aIt.More(); aIt.Next()) {
493 aContext->AddFilter(aIt.Value());
496 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
497 //for(; aIt2.More(); aIt2.Next()) {
498 // aContext->SetSelected(aIt2.Value(), false);
503 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
505 Handle(AIS_InteractiveContext) aContext = AISContext();
506 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
507 // Preserve selected objects
508 //AIS_ListOfInteractive aAisList;
509 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
510 // aAisList.Append(aContext->SelectedInteractive());
512 // get the filters from the local context and append them to the global context
513 // a list of filters in the local context is cleared
514 SelectMgr_ListOfFilter aFilters;
515 aFilters.Assign(aContext->Filters());
517 //aContext->ClearSelected();
518 aContext->CloseAllContexts(false);
520 // Redisplay all object if they were displayed in localContext
521 Handle(AIS_InteractiveObject) aAISIO;
522 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
523 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
524 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
525 aContext->Display(aAISIO, false);
526 aContext->SetDisplayMode(aAISIO, Shading, false);
530 // Append the filters from the local selection in the global selection context
531 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
532 for (;aIt.More(); aIt.Next()) {
533 Handle(SelectMgr_Filter) aFilter = aIt.Value();
534 aContext->AddFilter(aFilter);
539 //myUseExternalObjects = false;
542 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
543 //for(; aIt2.More(); aIt2.Next()) {
544 // if (aContext->IsDisplayed(aIt2.Value()))
545 // aContext->SetCurrentObject(aIt2.Value(), false);
550 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
553 if (myResult2AISObjectMap.contains(theObject))
554 anIO = myResult2AISObjectMap[theObject];
558 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
560 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
561 return getObject(aRefAIS);
564 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
567 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
568 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
569 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
576 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
578 bool aWasEnabled = myEnableUpdateViewer;
580 myEnableUpdateViewer = isEnabled;
585 void XGUI_Displayer::updateViewer()
587 Handle(AIS_InteractiveContext) aContext = AISContext();
588 if (!aContext.IsNull() && myEnableUpdateViewer)
589 aContext->UpdateCurrentViewer();
592 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
594 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
595 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
596 aContext->OpenLocalContext();
601 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
603 Handle(AIS_InteractiveContext) aContext = AISContext();
604 if (myAndFilter.IsNull() && !aContext.IsNull()) {
605 myAndFilter = new SelectMgr_AndFilter();
606 aContext->AddFilter(myAndFilter);
611 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
613 Handle(AIS_InteractiveContext) aContext = AISContext();
614 if (aContext.IsNull())
616 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
617 if (!anAISIO.IsNull()) {
618 aContext->Display(anAISIO, isUpdate);
619 if (aContext->HasOpenedContext()) {
620 //if (myUseExternalObjects) {
621 if (myActiveSelectionModes.size() == 0)
622 aContext->Activate(anAISIO);
624 foreach(int aMode, myActiveSelectionModes) {
625 aContext->Activate(anAISIO, aMode);
633 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
635 Handle(AIS_InteractiveContext) aContext = AISContext();
636 if (aContext.IsNull())
638 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
639 if (!anAISIO.IsNull()) {
640 aContext->Remove(anAISIO, isUpdate);
645 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
647 if (theMode == NoMode)
650 Handle(AIS_InteractiveContext) aContext = AISContext();
651 if (aContext.IsNull())
654 AISObjectPtr aAISObj = getAISObject(theObject);
658 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
659 bool aCanBeShaded = ::canBeShaded(aAISIO);
660 // In order to avoid extra closing/opening context
661 SelectMgr_IndexedMapOfOwner aSelectedOwners;
663 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
664 closeLocalContexts(false);
666 aContext->SetDisplayMode(aAISIO, theMode, false);
669 activateObjects(myActiveSelectionModes);
670 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
676 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
678 Handle(AIS_InteractiveContext) aContext = AISContext();
679 if (aContext.IsNull())
682 AISObjectPtr aAISObj = getAISObject(theObject);
686 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
687 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
690 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
692 Handle(AIS_InteractiveContext) aContext = AISContext();
693 if (aContext.IsNull())
695 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
696 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
697 for (; aIt.More(); aIt.Next()) {
698 if (theFilter.Access() == aIt.Value().Access())
701 GetFilter()->Add(theFilter);
704 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
706 Handle(AIS_InteractiveContext) aContext = AISContext();
707 if (aContext.IsNull())
709 GetFilter()->Remove(theFilter);
712 void XGUI_Displayer::removeFilters()
714 Handle(AIS_InteractiveContext) aContext = AISContext();
715 if (aContext.IsNull())
717 GetFilter()->Clear();
720 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
722 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
723 foreach(ObjectPtr aObj, aDispList) {
724 if (!theList.contains(aObj))
727 foreach(ObjectPtr aObj, theList) {
728 if (!isVisible(aObj))
729 display(aObj, false);
734 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
736 if (!isVisible(theObject))
739 AISObjectPtr aAISObj = getAISObject(theObject);
740 if (aAISObj.get() == NULL)
743 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
744 return ::canBeShaded(anAIS);
747 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
748 const QIntList& theModes) const
750 Handle(AIS_InteractiveContext) aContext = AISContext();
751 if (aContext.IsNull() || theIO.IsNull())
754 aContext->Load(theIO, -1, true);
755 aContext->Deactivate(theIO);
756 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
757 //Deactivate trihedron which can be activated in local selector
758 if (aTrihedron.IsNull()) {
759 //aContext->Load(anAISIO, -1, true);
760 // In order to clear active modes list
761 if (theModes.size() == 0) {
762 //aContext->Load(anAISIO, 0, true);
763 aContext->Activate(theIO);
765 foreach(int aMode, theModes) {
766 //aContext->Load(anAISIO, aMode, true);
767 aContext->Activate(theIO, aMode);
773 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
775 AISObjectPtr anAISObj = getAISObject(theObject);
776 // correct the result's color it it has the attribute
777 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
779 // Customization of presentation
780 GeomCustomPrsPtr aCustomPrs;
781 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
782 if (aFeature.get() != NULL) {
783 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
784 if (aCustPrs.get() != NULL)
785 aCustomPrs = aCustPrs;
787 if (aCustomPrs.get() == NULL) {
788 // we ignore presentable not customized objects
789 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
790 if (aPrs.get() != NULL)
792 aCustomPrs = myCustomPrs;
794 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);