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"
13 #include <AppElements_Viewer.h>
15 #include <ModelAPI_Document.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Object.h>
18 #include <ModelAPI_Tools.h>
19 #include <ModelAPI_AttributeColor.h>
21 #include <ModuleBase_ResultPrs.h>
23 #include <GeomAPI_Shape.h>
24 #include <GeomAPI_IPresentable.h>
25 #include <GeomAPI_ICustomPrs.h>
27 #include <AIS_InteractiveContext.hxx>
28 #include <AIS_LocalContext.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30 #include <AIS_ListIteratorOfListOfInteractive.hxx>
31 #include <AIS_DimensionSelectionMode.hxx>
32 #include <AIS_Shape.hxx>
33 #include <AIS_Dimension.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <SelectMgr_ListOfFilter.hxx>
36 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
38 #include <TColStd_MapOfTransient.hxx>
39 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
43 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
45 //#define DEBUG_DISPLAY
46 //#define DEBUG_ACTIVATE
48 // Workaround for bug #25637
49 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
51 // Get from null point
52 theAIS->DisplayedObjects(theList, true);
53 if (theAIS->HasOpenedContext()) {
54 // get from local context
55 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
56 TColStd_MapOfTransient aMap;
57 int NbDisp = aLC->DisplayedObjects(aMap);
58 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
60 Handle(AIS_InteractiveObject) curIO;
61 Handle(Standard_Transient) Tr;
62 for(; aIt.More(); aIt.Next()){
64 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
65 theList.Append(curIO);
71 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
72 : myWorkshop(theWorkshop)
74 enableUpdateViewer(true);
77 XGUI_Displayer::~XGUI_Displayer()
81 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
83 return myResult2AISObjectMap.contains(theObject);
86 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
88 if (isVisible(theObject)) {
89 redisplay(theObject, isUpdateViewer);
92 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
93 if (aFeature.get() != NULL) {
94 qDebug(QString("display feature: %1, displayed: %2").
95 arg(aFeature->data()->name().c_str()).
96 arg(displayedObjects().size()).toStdString().c_str());
101 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
102 bool isShading = false;
103 if (aPrs.get() != NULL) {
104 anAIS = aPrs->getAISObject(AISObjectPtr());
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 myResult2AISObjectMap[theObject] = theAIS;
151 bool aCanBeShaded = ::canBeShaded(anAISIO);
152 // In order to avoid extra closing/opening context
153 SelectMgr_IndexedMapOfOwner aSelectedOwners;
155 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
156 closeLocalContexts(false);
158 aContext->Display(anAISIO, false);
160 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
162 customizeObject(theObject);
165 activateObjects(myActiveSelectionModes);
166 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
169 activate(anAISIO, myActiveSelectionModes);
175 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
177 if (!isVisible(theObject))
180 Handle(AIS_InteractiveContext) aContext = AISContext();
181 if (aContext.IsNull())
183 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
185 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
186 if (!anAIS.IsNull()) {
187 aContext->Remove(anAIS, isUpdateViewer);
190 myResult2AISObjectMap.remove(theObject);
193 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
195 if (!isVisible(theObject))
198 AISObjectPtr aAISObj = getAISObject(theObject);
199 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
201 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
203 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
205 erase(theObject, isUpdateViewer);
208 if (aAIS_Obj != aAISObj) {
209 myResult2AISObjectMap[theObject] = aAIS_Obj;
211 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
214 if (!aAISIO.IsNull()) {
215 Handle(AIS_InteractiveContext) aContext = AISContext();
216 if (aContext.IsNull())
218 // Check that the visualized shape is the same and the redisplay is not necessary
219 // Redisplay of AIS object leads to this object selection compute and the selection
220 // in the browser is lost
222 // this check is not necessary anymore because the selection store/restore is realized
223 // before and after the values modification.
224 // Moreother, this check avoids customize and redisplay presentation if the presentable
225 // parameter is changed.
226 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
227 if (aResult.get() != NULL) {
228 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
229 if (!aShapePrs.IsNull()) {
230 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
231 if (aShapePtr.get()) {
232 const TopoDS_Shape& aShape = aShapePrs->Shape();
233 std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
234 anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
236 if (aShapePtr->isEqual(anAISShapePtr))
241 // Customization of presentation
242 customizeObject(theObject);
244 aContext->Redisplay(aAISIO, false);
250 void XGUI_Displayer::deactivate(ObjectPtr theObject)
252 if (isVisible(theObject)) {
253 Handle(AIS_InteractiveContext) aContext = AISContext();
254 if (aContext.IsNull())
257 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
258 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
259 aContext->Deactivate(anAIS);
263 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
265 activate(theFeature, myActiveSelectionModes);
268 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
270 #ifdef DEBUG_ACTIVATE
271 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
273 if (aFeature.get() != NULL) {
275 getModesOfActivation(theObject, aModes);
278 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
279 arg(aFeature->data()->name().c_str()).
280 arg(theModes.size()).
281 arg(myActiveSelectionModes.size()).
282 arg(aModes.size()).toStdString().c_str());
286 if (isVisible(theObject)) {
287 Handle(AIS_InteractiveContext) aContext = AISContext();
288 if (aContext.IsNull())
291 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
292 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
294 activate(anAIS, theModes);
298 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
300 if (!isVisible(theObject))
303 Handle(AIS_InteractiveContext) aContext = AISContext();
304 if (aContext.IsNull())
307 AISObjectPtr aAISObj = getAISObject(theObject);
309 if (aAISObj.get() != NULL) {
310 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
311 TColStd_ListOfInteger aTColModes;
312 aContext->ActivatedModes(anAISIO, aTColModes);
313 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
314 for (; itr.More(); itr.Next() ) {
315 theModes.append(itr.Value());
320 void XGUI_Displayer::activateObjects(const QIntList& theModes)
322 #ifdef DEBUG_ACTIVATE
323 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
324 arg(theModes.size()).
325 arg(myActiveSelectionModes.size()).
326 toStdString().c_str());
328 // In order to avoid doblications of selection modes
330 foreach (int aMode, theModes) {
331 if (!aNewModes.contains(aMode))
332 aNewModes.append(aMode);
334 myActiveSelectionModes = aNewModes;
335 Handle(AIS_InteractiveContext) aContext = AISContext();
336 if (aContext.IsNull())
338 // Open local context if there is no one
339 if (!aContext->HasOpenedContext())
342 //aContext->UseDisplayedObjects();
343 //myUseExternalObjects = true;
345 AIS_ListOfInteractive aPrsList;
346 ::displayedObjects(aContext, aPrsList);
348 Handle(AIS_Trihedron) aTrihedron;
349 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
350 Handle(AIS_InteractiveObject) anAISIO;
351 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
352 anAISIO = aLIt.Value();
353 activate(anAISIO, myActiveSelectionModes);
358 void XGUI_Displayer::deactivateObjects()
360 myActiveSelectionModes.clear();
361 Handle(AIS_InteractiveContext) aContext = AISContext();
362 // Open local context if there is no one
363 if (!aContext->HasOpenedContext())
366 //aContext->NotUseDisplayedObjects();
367 AIS_ListOfInteractive aPrsList;
368 ::displayedObjects(aContext, aPrsList);
370 AIS_ListIteratorOfListOfInteractive aLIt;
371 //Handle(AIS_Trihedron) aTrihedron;
372 Handle(AIS_InteractiveObject) anAISIO;
373 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
374 anAISIO = aLIt.Value();
375 aContext->Deactivate(anAISIO);
379 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
381 Handle(AIS_InteractiveContext) aContext = AISContext();
382 if (aContext.IsNull())
384 if (!isVisible(theObject))
387 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
388 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
390 TColStd_ListOfInteger aModes;
391 aContext->ActivatedModes(anAIS, aModes);
392 return aModes.Extent() > 0;
395 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
397 Handle(AIS_InteractiveContext) aContext = AISContext();
398 if (aContext.IsNull())
400 if (aContext->HasOpenedContext()) {
401 aContext->UnhilightSelected();
402 aContext->ClearSelected();
403 foreach(ObjectPtr aResult, theResults) {
404 if (isVisible(aResult)) {
405 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
406 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
408 aContext->SetSelected(anAIS, false);
412 aContext->UnhilightCurrents();
413 aContext->ClearCurrents();
414 foreach(ObjectPtr aResult, theResults) {
415 if (isVisible(aResult)) {
416 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
417 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
419 aContext->SetCurrentObject(anAIS, false);
428 void XGUI_Displayer::clearSelected()
430 Handle(AIS_InteractiveContext) aContext = AISContext();
432 aContext->UnhilightCurrents(false);
433 aContext->ClearSelected();
437 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
439 Handle(AIS_InteractiveContext) aContext = AISContext();
440 if (!aContext.IsNull()) {
441 foreach (AISObjectPtr aAISObj, myResult2AISObjectMap) {
443 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
445 aContext->Remove(anIO, false);
450 myResult2AISObjectMap.clear();
453 void XGUI_Displayer::openLocalContext()
455 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
456 if (aContext.IsNull())
458 // Open local context if there is no one
459 if (!aContext->HasOpenedContext()) {
460 // Preserve selected objects
461 //AIS_ListOfInteractive aAisList;
462 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
463 // aAisList.Append(aContext->Current());
465 // get the filters from the global context and append them to the local context
466 // a list of filters in the global context is not cleared and should be cleared here
467 SelectMgr_ListOfFilter aFilters;
468 aFilters.Assign(aContext->Filters());
469 // it is important to remove the filters in the global context, because there is a code
470 // in the closeLocalContex, which restore the global context filters
471 aContext->RemoveFilters();
473 //aContext->ClearCurrents();
474 aContext->OpenLocalContext();
475 //aContext->NotUseDisplayedObjects();
477 //myUseExternalObjects = false;
479 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
480 for (;aIt.More(); aIt.Next()) {
481 aContext->AddFilter(aIt.Value());
484 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
485 //for(; aIt2.More(); aIt2.Next()) {
486 // aContext->SetSelected(aIt2.Value(), false);
491 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
493 Handle(AIS_InteractiveContext) aContext = AISContext();
494 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
495 // Preserve selected objects
496 //AIS_ListOfInteractive aAisList;
497 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
498 // aAisList.Append(aContext->SelectedInteractive());
500 // get the filters from the local context and append them to the global context
501 // a list of filters in the local context is cleared
502 SelectMgr_ListOfFilter aFilters;
503 aFilters.Assign(aContext->Filters());
505 //aContext->ClearSelected();
506 aContext->CloseAllContexts(false);
508 // Redisplay all object if they were displayed in localContext
509 Handle(AIS_InteractiveObject) aAISIO;
510 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
511 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
512 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
513 aContext->Display(aAISIO, false);
514 aContext->SetDisplayMode(aAISIO, Shading, false);
518 // Append the filters from the local selection in the global selection context
519 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
520 for (;aIt.More(); aIt.Next()) {
521 Handle(SelectMgr_Filter) aFilter = aIt.Value();
522 aContext->AddFilter(aFilter);
527 //myUseExternalObjects = false;
530 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
531 //for(; aIt2.More(); aIt2.Next()) {
532 // if (aContext->IsDisplayed(aIt2.Value()))
533 // aContext->SetCurrentObject(aIt2.Value(), false);
538 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
541 if (myResult2AISObjectMap.contains(theObject))
542 anIO = myResult2AISObjectMap[theObject];
546 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
548 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
549 return getObject(aRefAIS);
552 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
555 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
556 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
557 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
564 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
566 bool aWasEnabled = myEnableUpdateViewer;
568 myEnableUpdateViewer = isEnabled;
573 void XGUI_Displayer::updateViewer()
575 Handle(AIS_InteractiveContext) aContext = AISContext();
576 if (!aContext.IsNull() && myEnableUpdateViewer)
577 aContext->UpdateCurrentViewer();
580 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
582 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
583 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
584 aContext->OpenLocalContext();
589 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
591 Handle(AIS_InteractiveContext) aContext = AISContext();
592 if (myAndFilter.IsNull() && !aContext.IsNull()) {
593 myAndFilter = new SelectMgr_AndFilter();
594 aContext->AddFilter(myAndFilter);
599 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
601 Handle(AIS_InteractiveContext) aContext = AISContext();
602 if (aContext.IsNull())
604 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
605 if (!anAISIO.IsNull()) {
606 aContext->Display(anAISIO, isUpdate);
607 if (aContext->HasOpenedContext()) {
608 //if (myUseExternalObjects) {
609 if (myActiveSelectionModes.size() == 0)
610 aContext->Activate(anAISIO);
612 foreach(int aMode, myActiveSelectionModes) {
613 aContext->Activate(anAISIO, aMode);
621 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
623 Handle(AIS_InteractiveContext) aContext = AISContext();
624 if (aContext.IsNull())
626 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
627 if (!anAISIO.IsNull()) {
628 aContext->Remove(anAISIO, isUpdate);
633 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
635 if (theMode == NoMode)
638 Handle(AIS_InteractiveContext) aContext = AISContext();
639 if (aContext.IsNull())
642 AISObjectPtr aAISObj = getAISObject(theObject);
646 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
647 bool aCanBeShaded = ::canBeShaded(aAISIO);
648 // In order to avoid extra closing/opening context
649 SelectMgr_IndexedMapOfOwner aSelectedOwners;
651 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
652 closeLocalContexts(false);
654 aContext->SetDisplayMode(aAISIO, theMode, false);
657 activateObjects(myActiveSelectionModes);
658 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
664 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
666 Handle(AIS_InteractiveContext) aContext = AISContext();
667 if (aContext.IsNull())
670 AISObjectPtr aAISObj = getAISObject(theObject);
674 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
675 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
678 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
680 Handle(AIS_InteractiveContext) aContext = AISContext();
681 if (aContext.IsNull())
683 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
684 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
685 for (; aIt.More(); aIt.Next()) {
686 if (theFilter.Access() == aIt.Value().Access())
689 GetFilter()->Add(theFilter);
692 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
694 Handle(AIS_InteractiveContext) aContext = AISContext();
695 if (aContext.IsNull())
697 GetFilter()->Remove(theFilter);
700 void XGUI_Displayer::removeFilters()
702 Handle(AIS_InteractiveContext) aContext = AISContext();
703 if (aContext.IsNull())
705 GetFilter()->Clear();
708 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
710 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
711 foreach(ObjectPtr aObj, aDispList) {
712 if (!theList.contains(aObj))
715 foreach(ObjectPtr aObj, theList) {
716 if (!isVisible(aObj))
717 display(aObj, false);
722 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
724 if (!isVisible(theObject))
727 AISObjectPtr aAISObj = getAISObject(theObject);
728 if (aAISObj.get() == NULL)
731 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
732 return ::canBeShaded(anAIS);
735 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
736 const QIntList& theModes) const
738 Handle(AIS_InteractiveContext) aContext = AISContext();
739 if (aContext.IsNull() || theIO.IsNull())
742 aContext->Load(theIO, -1, true);
743 aContext->Deactivate(theIO);
744 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
745 //Deactivate trihedron which can be activated in local selector
746 if (aTrihedron.IsNull()) {
747 //aContext->Load(anAISIO, -1, true);
748 // In order to clear active modes list
749 if (theModes.size() == 0) {
750 //aContext->Load(anAISIO, 0, true);
751 aContext->Activate(theIO);
753 foreach(int aMode, theModes) {
754 //aContext->Load(anAISIO, aMode, true);
755 aContext->Activate(theIO, aMode);
761 void XGUI_Displayer::customizeObject(ObjectPtr theObject)
763 AISObjectPtr anAISObj = getAISObject(theObject);
764 // correct the result's color it it has the attribute
765 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
766 if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
767 int aRed, aGreen, aBlue;
769 AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(
770 aResult->data()->attribute(ModelAPI_Result::COLOR_ID()));
771 aColorAttr->values(aRed, aGreen, aBlue);
772 anAISObj->setColor(aRed, aGreen, aBlue);
775 // Customization of presentation
776 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
777 if (aFeature.get() != NULL) {
778 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
779 if (aCustPrs.get() != NULL)
780 aCustPrs->customisePresentation(anAISObj);