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);
162 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
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 aContext->Remove(anAIS, isUpdateViewer);
195 myResult2AISObjectMap.remove(theObject);
198 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
200 if (!isVisible(theObject))
203 AISObjectPtr aAISObj = getAISObject(theObject);
204 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
206 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
208 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
210 erase(theObject, isUpdateViewer);
213 if (aAIS_Obj != aAISObj) {
214 myResult2AISObjectMap[theObject] = aAIS_Obj;
216 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
219 if (!aAISIO.IsNull()) {
220 Handle(AIS_InteractiveContext) aContext = AISContext();
221 if (aContext.IsNull())
223 // Check that the visualized shape is the same and the redisplay is not necessary
224 // Redisplay of AIS object leads to this object selection compute and the selection
225 // in the browser is lost
227 // this check is not necessary anymore because the selection store/restore is realized
228 // before and after the values modification.
229 // Moreother, this check avoids customize and redisplay presentation if the presentable
230 // parameter is changed.
231 bool isEqualShapes = false;
232 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
233 if (aResult.get() != NULL) {
234 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
235 if (!aShapePrs.IsNull()) {
236 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
237 if (aShapePtr.get()) {
238 const TopoDS_Shape& aShape = aShapePrs->Shape();
239 std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
240 anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
242 isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
246 // Customization of presentation
247 bool isCustomized = customizeObject(theObject);
248 if (!isEqualShapes || isCustomized) {
249 aContext->Redisplay(aAISIO, false);
256 void XGUI_Displayer::deactivate(ObjectPtr theObject)
258 if (isVisible(theObject)) {
259 Handle(AIS_InteractiveContext) aContext = AISContext();
260 if (aContext.IsNull())
263 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
264 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
265 aContext->Deactivate(anAIS);
269 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
271 activate(theFeature, myActiveSelectionModes);
274 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
276 #ifdef DEBUG_ACTIVATE
277 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
279 if (aFeature.get() != NULL) {
281 getModesOfActivation(theObject, aModes);
284 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
285 arg(aFeature->data()->name().c_str()).
286 arg(theModes.size()).
287 arg(myActiveSelectionModes.size()).
288 arg(aModes.size()).toStdString().c_str());
292 if (isVisible(theObject)) {
293 Handle(AIS_InteractiveContext) aContext = AISContext();
294 if (aContext.IsNull())
297 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
298 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
300 activate(anAIS, theModes);
304 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
306 if (!isVisible(theObject))
309 Handle(AIS_InteractiveContext) aContext = AISContext();
310 if (aContext.IsNull())
313 AISObjectPtr aAISObj = getAISObject(theObject);
315 if (aAISObj.get() != NULL) {
316 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
317 TColStd_ListOfInteger aTColModes;
318 aContext->ActivatedModes(anAISIO, aTColModes);
319 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
320 for (; itr.More(); itr.Next() ) {
321 theModes.append(itr.Value());
326 void XGUI_Displayer::activateObjects(const QIntList& theModes)
328 #ifdef DEBUG_ACTIVATE
329 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
330 arg(theModes.size()).
331 arg(myActiveSelectionModes.size()).
332 toStdString().c_str());
334 // In order to avoid doblications of selection modes
336 foreach (int aMode, theModes) {
337 if (!aNewModes.contains(aMode))
338 aNewModes.append(aMode);
340 myActiveSelectionModes = aNewModes;
341 Handle(AIS_InteractiveContext) aContext = AISContext();
342 if (aContext.IsNull())
344 // Open local context if there is no one
345 if (!aContext->HasOpenedContext())
348 //aContext->UseDisplayedObjects();
349 //myUseExternalObjects = true;
351 AIS_ListOfInteractive aPrsList;
352 ::displayedObjects(aContext, aPrsList);
354 Handle(AIS_Trihedron) aTrihedron;
355 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
356 Handle(AIS_InteractiveObject) anAISIO;
357 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
358 anAISIO = aLIt.Value();
359 activate(anAISIO, myActiveSelectionModes);
364 void XGUI_Displayer::deactivateObjects()
366 myActiveSelectionModes.clear();
367 Handle(AIS_InteractiveContext) aContext = AISContext();
368 // Open local context if there is no one
369 if (!aContext->HasOpenedContext())
372 //aContext->NotUseDisplayedObjects();
373 AIS_ListOfInteractive aPrsList;
374 ::displayedObjects(aContext, aPrsList);
376 AIS_ListIteratorOfListOfInteractive aLIt;
377 //Handle(AIS_Trihedron) aTrihedron;
378 Handle(AIS_InteractiveObject) anAISIO;
379 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
380 anAISIO = aLIt.Value();
381 aContext->Deactivate(anAISIO);
385 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
387 Handle(AIS_InteractiveContext) aContext = AISContext();
388 if (aContext.IsNull())
390 if (!isVisible(theObject))
393 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
394 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
396 TColStd_ListOfInteger aModes;
397 aContext->ActivatedModes(anAIS, aModes);
398 return aModes.Extent() > 0;
401 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
403 Handle(AIS_InteractiveContext) aContext = AISContext();
404 if (aContext.IsNull())
406 if (aContext->HasOpenedContext()) {
407 aContext->UnhilightSelected();
408 aContext->ClearSelected();
409 foreach(ObjectPtr aResult, theResults) {
410 if (isVisible(aResult)) {
411 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
412 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
414 aContext->SetSelected(anAIS, false);
418 aContext->UnhilightCurrents();
419 aContext->ClearCurrents();
420 foreach(ObjectPtr aResult, theResults) {
421 if (isVisible(aResult)) {
422 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
423 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
425 aContext->SetCurrentObject(anAIS, false);
434 void XGUI_Displayer::clearSelected()
436 Handle(AIS_InteractiveContext) aContext = AISContext();
438 aContext->UnhilightCurrents(false);
439 aContext->ClearSelected();
443 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
445 Handle(AIS_InteractiveContext) aContext = AISContext();
446 if (!aContext.IsNull()) {
447 foreach (AISObjectPtr aAISObj, myResult2AISObjectMap) {
449 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
451 aContext->Remove(anIO, false);
456 myResult2AISObjectMap.clear();
459 void XGUI_Displayer::openLocalContext()
461 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
462 if (aContext.IsNull())
464 // Open local context if there is no one
465 if (!aContext->HasOpenedContext()) {
466 // Preserve selected objects
467 //AIS_ListOfInteractive aAisList;
468 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
469 // aAisList.Append(aContext->Current());
471 // get the filters from the global context and append them to the local context
472 // a list of filters in the global context is not cleared and should be cleared here
473 SelectMgr_ListOfFilter aFilters;
474 aFilters.Assign(aContext->Filters());
475 // it is important to remove the filters in the global context, because there is a code
476 // in the closeLocalContex, which restore the global context filters
477 aContext->RemoveFilters();
479 //aContext->ClearCurrents();
480 aContext->OpenLocalContext();
481 //aContext->NotUseDisplayedObjects();
483 //myUseExternalObjects = false;
485 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
486 for (;aIt.More(); aIt.Next()) {
487 aContext->AddFilter(aIt.Value());
490 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
491 //for(; aIt2.More(); aIt2.Next()) {
492 // aContext->SetSelected(aIt2.Value(), false);
497 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
499 Handle(AIS_InteractiveContext) aContext = AISContext();
500 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
501 // Preserve selected objects
502 //AIS_ListOfInteractive aAisList;
503 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
504 // aAisList.Append(aContext->SelectedInteractive());
506 // get the filters from the local context and append them to the global context
507 // a list of filters in the local context is cleared
508 SelectMgr_ListOfFilter aFilters;
509 aFilters.Assign(aContext->Filters());
511 //aContext->ClearSelected();
512 aContext->CloseAllContexts(false);
514 // Redisplay all object if they were displayed in localContext
515 Handle(AIS_InteractiveObject) aAISIO;
516 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
517 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
518 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
519 aContext->Display(aAISIO, false);
520 aContext->SetDisplayMode(aAISIO, Shading, false);
524 // Append the filters from the local selection in the global selection context
525 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
526 for (;aIt.More(); aIt.Next()) {
527 Handle(SelectMgr_Filter) aFilter = aIt.Value();
528 aContext->AddFilter(aFilter);
533 //myUseExternalObjects = false;
536 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
537 //for(; aIt2.More(); aIt2.Next()) {
538 // if (aContext->IsDisplayed(aIt2.Value()))
539 // aContext->SetCurrentObject(aIt2.Value(), false);
544 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
547 if (myResult2AISObjectMap.contains(theObject))
548 anIO = myResult2AISObjectMap[theObject];
552 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
554 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
555 return getObject(aRefAIS);
558 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
561 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
562 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
563 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
570 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
572 bool aWasEnabled = myEnableUpdateViewer;
574 myEnableUpdateViewer = isEnabled;
579 void XGUI_Displayer::updateViewer()
581 Handle(AIS_InteractiveContext) aContext = AISContext();
582 if (!aContext.IsNull() && myEnableUpdateViewer)
583 aContext->UpdateCurrentViewer();
586 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
588 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
589 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
590 aContext->OpenLocalContext();
595 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
597 Handle(AIS_InteractiveContext) aContext = AISContext();
598 if (myAndFilter.IsNull() && !aContext.IsNull()) {
599 myAndFilter = new SelectMgr_AndFilter();
600 aContext->AddFilter(myAndFilter);
605 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
607 Handle(AIS_InteractiveContext) aContext = AISContext();
608 if (aContext.IsNull())
610 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
611 if (!anAISIO.IsNull()) {
612 aContext->Display(anAISIO, isUpdate);
613 if (aContext->HasOpenedContext()) {
614 //if (myUseExternalObjects) {
615 if (myActiveSelectionModes.size() == 0)
616 aContext->Activate(anAISIO);
618 foreach(int aMode, myActiveSelectionModes) {
619 aContext->Activate(anAISIO, aMode);
627 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
629 Handle(AIS_InteractiveContext) aContext = AISContext();
630 if (aContext.IsNull())
632 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
633 if (!anAISIO.IsNull()) {
634 aContext->Remove(anAISIO, isUpdate);
639 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
641 if (theMode == NoMode)
644 Handle(AIS_InteractiveContext) aContext = AISContext();
645 if (aContext.IsNull())
648 AISObjectPtr aAISObj = getAISObject(theObject);
652 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
653 bool aCanBeShaded = ::canBeShaded(aAISIO);
654 // In order to avoid extra closing/opening context
655 SelectMgr_IndexedMapOfOwner aSelectedOwners;
657 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
658 closeLocalContexts(false);
660 aContext->SetDisplayMode(aAISIO, theMode, false);
663 activateObjects(myActiveSelectionModes);
664 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
670 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
672 Handle(AIS_InteractiveContext) aContext = AISContext();
673 if (aContext.IsNull())
676 AISObjectPtr aAISObj = getAISObject(theObject);
680 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
681 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
684 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
686 Handle(AIS_InteractiveContext) aContext = AISContext();
687 if (aContext.IsNull())
689 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
690 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
691 for (; aIt.More(); aIt.Next()) {
692 if (theFilter.Access() == aIt.Value().Access())
695 GetFilter()->Add(theFilter);
698 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
700 Handle(AIS_InteractiveContext) aContext = AISContext();
701 if (aContext.IsNull())
703 GetFilter()->Remove(theFilter);
706 void XGUI_Displayer::removeFilters()
708 Handle(AIS_InteractiveContext) aContext = AISContext();
709 if (aContext.IsNull())
711 GetFilter()->Clear();
714 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
716 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
717 foreach(ObjectPtr aObj, aDispList) {
718 if (!theList.contains(aObj))
721 foreach(ObjectPtr aObj, theList) {
722 if (!isVisible(aObj))
723 display(aObj, false);
728 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
730 if (!isVisible(theObject))
733 AISObjectPtr aAISObj = getAISObject(theObject);
734 if (aAISObj.get() == NULL)
737 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
738 return ::canBeShaded(anAIS);
741 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
742 const QIntList& theModes) const
744 Handle(AIS_InteractiveContext) aContext = AISContext();
745 if (aContext.IsNull() || theIO.IsNull())
748 aContext->Load(theIO, -1, true);
749 aContext->Deactivate(theIO);
750 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
751 //Deactivate trihedron which can be activated in local selector
752 if (aTrihedron.IsNull()) {
753 //aContext->Load(anAISIO, -1, true);
754 // In order to clear active modes list
755 if (theModes.size() == 0) {
756 //aContext->Load(anAISIO, 0, true);
757 aContext->Activate(theIO);
759 foreach(int aMode, theModes) {
760 //aContext->Load(anAISIO, aMode, true);
761 aContext->Activate(theIO, aMode);
767 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
769 AISObjectPtr anAISObj = getAISObject(theObject);
770 // correct the result's color it it has the attribute
771 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
773 // Customization of presentation
774 GeomCustomPrsPtr aCustomPrs;
775 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
776 if (aFeature.get() != NULL) {
777 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
778 if (aCustPrs.get() != NULL)
779 aCustomPrs = aCustPrs;
781 if (aCustomPrs.get() == NULL) {
782 // we ignore presentable not customized objects
783 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
784 if (aPrs.get() != NULL)
786 aCustomPrs = myCustomPrs;
788 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);