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 // In order to avoid extra closing/opening context
153 SelectMgr_IndexedMapOfOwner aSelectedOwners;
154 aContext->Display(anAISIO, false);
155 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
157 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
158 emit objectDisplayed(theObject, theAIS);
160 bool isCustomized = customizeObject(theObject);
162 aContext->Redisplay(anAISIO, false);
164 activate(anAISIO, myActiveSelectionModes);
170 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
172 if (!isVisible(theObject))
175 Handle(AIS_InteractiveContext) aContext = AISContext();
176 if (aContext.IsNull())
178 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
180 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
181 if (!anAIS.IsNull()) {
182 emit beforeObjectErase(theObject, anObject);
183 aContext->Remove(anAIS, isUpdateViewer);
186 myResult2AISObjectMap.remove(theObject);
189 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
191 if (!isVisible(theObject))
194 AISObjectPtr aAISObj = getAISObject(theObject);
195 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
197 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
199 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
201 erase(theObject, isUpdateViewer);
204 if (aAIS_Obj != aAISObj) {
205 appendResultObject(theObject, aAIS_Obj);
207 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
210 if (!aAISIO.IsNull()) {
211 Handle(AIS_InteractiveContext) aContext = AISContext();
212 if (aContext.IsNull())
214 // Check that the visualized shape is the same and the redisplay is not necessary
215 // Redisplay of AIS object leads to this object selection compute and the selection
216 // in the browser is lost
218 // this check is not necessary anymore because the selection store/restore is realized
219 // before and after the values modification.
220 // Moreother, this check avoids customize and redisplay presentation if the presentable
221 // parameter is changed.
222 bool isEqualShapes = false;
223 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
224 if (aResult.get() != NULL) {
225 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
226 if (!aShapePrs.IsNull()) {
227 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
228 if (aShapePtr.get()) {
229 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
230 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
234 // Customization of presentation
235 bool isCustomized = customizeObject(theObject);
236 #ifdef DEBUG_FEATURE_REDISPLAY
237 //qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
238 // arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
240 if (!isEqualShapes || isCustomized) {
241 aContext->Redisplay(aAISIO, false);
242 #ifdef DEBUG_FEATURE_REDISPLAY
243 //qDebug(" Redisplay happens");
251 void XGUI_Displayer::deactivate(ObjectPtr theObject)
253 if (isVisible(theObject)) {
254 Handle(AIS_InteractiveContext) aContext = AISContext();
255 if (aContext.IsNull())
258 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
259 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
260 aContext->Deactivate(anAIS);
261 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
262 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
268 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
270 activate(theFeature, myActiveSelectionModes);
273 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
275 #ifdef DEBUG_ACTIVATE
276 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
278 if (aFeature.get() != NULL) {
280 getModesOfActivation(theObject, aModes);
283 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
284 arg(aFeature->data()->name().c_str()).
285 arg(theModes.size()).
286 arg(myActiveSelectionModes.size()).
287 arg(aModes.size()).toStdString().c_str());
291 if (isVisible(theObject)) {
292 Handle(AIS_InteractiveContext) aContext = AISContext();
293 if (aContext.IsNull())
296 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
297 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
299 activate(anAIS, theModes);
303 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
305 if (!isVisible(theObject))
308 Handle(AIS_InteractiveContext) aContext = AISContext();
309 if (aContext.IsNull())
312 AISObjectPtr aAISObj = getAISObject(theObject);
314 if (aAISObj.get() != NULL) {
315 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
316 TColStd_ListOfInteger aTColModes;
317 aContext->ActivatedModes(anAISIO, aTColModes);
318 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
319 for (; itr.More(); itr.Next() ) {
320 theModes.append(itr.Value());
325 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList)
327 #ifdef DEBUG_ACTIVATE
328 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
329 arg(theModes.size()).
330 arg(myActiveSelectionModes.size()).
331 toStdString().c_str());
333 // In order to avoid doblications of selection modes
335 foreach (int aMode, theModes) {
336 if (!aNewModes.contains(aMode))
337 aNewModes.append(aMode);
339 myActiveSelectionModes = aNewModes;
340 Handle(AIS_InteractiveContext) aContext = AISContext();
341 if (aContext.IsNull())
343 // Open local context if there is no one
344 if (!aContext->HasOpenedContext())
347 // we need to block the sort of the viewer selector during deactivate/activate because
348 // it takes a lot of time if there are a many objects are processed. It can be performed
349 // manualy after the activation is peformed
350 Handle(StdSelect_ViewerSelector3d) aSelector = aContext->LocalContext()->MainSelector();
351 bool isUpdateSortPossible = !aSelector.IsNull() && aSelector->IsUpdateSortPossible();
352 if (!aSelector.IsNull())
353 aSelector->SetUpdateSortPossible(false);
355 //aContext->UseDisplayedObjects();
356 //myUseExternalObjects = true;
358 Handle(AIS_InteractiveObject) anAISIO;
359 AIS_ListOfInteractive aPrsList;
360 if (theObjList.isEmpty())
361 ::displayedObjects(aContext, aPrsList);
363 foreach(ObjectPtr aObj, theObjList) {
364 if (myResult2AISObjectMap.contains(aObj))
365 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
369 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
370 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
371 anAISIO = aLIt.Value();
372 activate(anAISIO, myActiveSelectionModes);
374 // restore the sorting flag and perform the sort of selection
375 if (!aSelector.IsNull()) {
376 aSelector->SetUpdateSortPossible(isUpdateSortPossible);
377 aSelector->UpdateSort();
382 void XGUI_Displayer::deactivateObjects()
384 myActiveSelectionModes.clear();
385 Handle(AIS_InteractiveContext) aContext = AISContext();
386 // Open local context if there is no one
387 if (!aContext->HasOpenedContext())
390 //aContext->NotUseDisplayedObjects();
391 AIS_ListOfInteractive aPrsList;
392 ::displayedObjects(aContext, aPrsList);
394 AIS_ListIteratorOfListOfInteractive aLIt;
395 //Handle(AIS_Trihedron) aTrihedron;
396 Handle(AIS_InteractiveObject) anAISIO;
397 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
398 anAISIO = aLIt.Value();
399 aContext->Deactivate(anAISIO);
400 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
401 aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
407 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
409 Handle(AIS_InteractiveContext) aContext = AISContext();
410 if (aContext.IsNull())
412 if (!isVisible(theObject))
415 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
416 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
418 TColStd_ListOfInteger aModes;
419 aContext->ActivatedModes(anAIS, aModes);
420 return aModes.Extent() > 0;
423 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer)
425 Handle(AIS_InteractiveContext) aContext = AISContext();
426 if (aContext.IsNull())
428 if (aContext->HasOpenedContext()) {
429 aContext->UnhilightSelected();
430 aContext->ClearSelected();
431 //if (aSelected.size() > 0) {
432 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
433 const TopoDS_Shape& aShape = aPrs.shape();
434 if (!aShape.IsNull()) {
435 aContext->AddOrRemoveSelected(aShape, false);
437 ObjectPtr anObject = aPrs.object();
438 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
439 if (aResult.get() && isVisible(aResult)) {
440 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
441 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
442 if (!anAIS.IsNull()) {
443 // The methods are replaced in order to provide multi-selection, e.g. restore selection
444 // by activating multi selector widget. It also gives an advantage that the multi
445 // selection in OB gives multi-selection in the viewer
446 //aContext->SetSelected(anAIS, false);
447 // The selection in the context was cleared, so the method sets the objects are selected
448 aContext->AddOrRemoveSelected(anAIS, false);
454 aContext->UnhilightCurrents();
455 aContext->ClearCurrents();
456 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
457 ObjectPtr anObject = aPrs.object();
458 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
459 if (aResult.get() && isVisible(aResult)) {
460 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
461 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
463 aContext->SetCurrentObject(anAIS, false);
471 void XGUI_Displayer::clearSelected()
473 Handle(AIS_InteractiveContext) aContext = AISContext();
475 aContext->UnhilightCurrents(false);
476 aContext->ClearSelected();
480 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
482 Handle(AIS_InteractiveContext) aContext = AISContext();
483 if (!aContext.IsNull()) {
484 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
485 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
487 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
488 if (!anIO.IsNull()) {
489 emit beforeObjectErase(aObj, aAISObj);
490 aContext->Remove(anIO, false);
496 myResult2AISObjectMap.clear();
499 void XGUI_Displayer::openLocalContext()
501 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
502 if (aContext.IsNull())
504 // Open local context if there is no one
505 if (!aContext->HasOpenedContext()) {
506 // Preserve selected objects
507 //AIS_ListOfInteractive aAisList;
508 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
509 // aAisList.Append(aContext->Current());
511 // get the filters from the global context and append them to the local context
512 // a list of filters in the global context is not cleared and should be cleared here
513 SelectMgr_ListOfFilter aFilters;
514 aFilters.Assign(aContext->Filters());
515 // it is important to remove the filters in the global context, because there is a code
516 // in the closeLocalContex, which restore the global context filters
517 aContext->RemoveFilters();
519 //aContext->ClearCurrents();
520 aContext->OpenLocalContext();
521 //aContext->NotUseDisplayedObjects();
523 //myUseExternalObjects = false;
525 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
526 for (;aIt.More(); aIt.Next()) {
527 aContext->AddFilter(aIt.Value());
530 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
531 //for(; aIt2.More(); aIt2.Next()) {
532 // aContext->SetSelected(aIt2.Value(), false);
537 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
539 Handle(AIS_InteractiveContext) aContext = AISContext();
540 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
541 // Preserve selected objects
542 //AIS_ListOfInteractive aAisList;
543 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
544 // aAisList.Append(aContext->SelectedInteractive());
546 // get the filters from the local context and append them to the global context
547 // a list of filters in the local context is cleared
548 SelectMgr_ListOfFilter aFilters;
549 aFilters.Assign(aContext->Filters());
551 //aContext->ClearSelected();
552 aContext->CloseAllContexts(false);
554 // Redisplay all object if they were displayed in localContext
555 Handle(AIS_InteractiveObject) aAISIO;
556 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
557 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
558 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
559 aContext->Display(aAISIO, false);
560 aContext->SetDisplayMode(aAISIO, Shading, false);
564 // Append the filters from the local selection in the global selection context
565 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
566 for (;aIt.More(); aIt.Next()) {
567 Handle(SelectMgr_Filter) aFilter = aIt.Value();
568 aContext->AddFilter(aFilter);
573 //myUseExternalObjects = false;
576 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
577 //for(; aIt2.More(); aIt2.Next()) {
578 // if (aContext->IsDisplayed(aIt2.Value()))
579 // aContext->SetCurrentObject(aIt2.Value(), false);
584 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
587 if (myResult2AISObjectMap.contains(theObject))
588 anIO = myResult2AISObjectMap[theObject];
592 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
594 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
595 return getObject(aRefAIS);
598 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
601 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
602 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
603 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
610 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
612 bool aWasEnabled = myEnableUpdateViewer;
614 myEnableUpdateViewer = isEnabled;
619 void XGUI_Displayer::updateViewer() const
621 Handle(AIS_InteractiveContext) aContext = AISContext();
622 if (!aContext.IsNull() && myEnableUpdateViewer)
623 aContext->UpdateCurrentViewer();
626 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
628 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
629 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
630 aContext->OpenLocalContext();
635 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
637 Handle(AIS_InteractiveContext) aContext = AISContext();
638 if (myAndFilter.IsNull() && !aContext.IsNull()) {
639 myAndFilter = new SelectMgr_AndFilter();
640 aContext->AddFilter(myAndFilter);
645 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
647 Handle(AIS_InteractiveContext) aContext = AISContext();
648 if (aContext.IsNull())
650 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
651 if (!anAISIO.IsNull()) {
652 aContext->Display(anAISIO, isUpdate);
653 if (aContext->HasOpenedContext()) {
654 //if (myUseExternalObjects) {
655 if (myActiveSelectionModes.size() == 0)
656 aContext->Activate(anAISIO);
658 foreach(int aMode, myActiveSelectionModes) {
659 aContext->Activate(anAISIO, aMode);
667 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
669 Handle(AIS_InteractiveContext) aContext = AISContext();
670 if (aContext.IsNull())
672 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
673 if (!anAISIO.IsNull()) {
674 aContext->Remove(anAISIO, isUpdate);
679 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
681 if (theMode == NoMode)
684 Handle(AIS_InteractiveContext) aContext = AISContext();
685 if (aContext.IsNull())
688 AISObjectPtr aAISObj = getAISObject(theObject);
692 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
693 SelectMgr_IndexedMapOfOwner aSelectedOwners;
694 aContext->SetDisplayMode(aAISIO, theMode, false);
695 // Redisplay in order to update new mode because it could be not computed before
696 aContext->Redisplay(aAISIO, false);
701 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
703 Handle(AIS_InteractiveContext) aContext = AISContext();
704 if (aContext.IsNull())
707 AISObjectPtr aAISObj = getAISObject(theObject);
711 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
712 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
715 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
717 Handle(AIS_InteractiveContext) aContext = AISContext();
718 if (aContext.IsNull())
720 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
721 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
722 for (; aIt.More(); aIt.Next()) {
723 if (theFilter.Access() == aIt.Value().Access())
726 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
727 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
728 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
729 if (theFilter.Access() == aIt.Value().Access())
732 aCompFilter->Add(theFilter);
733 #ifdef DEBUG_SELECTION_FILTERS
734 int aCount = GetFilter()->StoredFilters().Extent();
735 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
739 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
741 Handle(AIS_InteractiveContext) aContext = AISContext();
742 if (aContext.IsNull())
744 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
745 if (aCompositeFilter->IsIn(theFilter))
746 aCompositeFilter->Remove(theFilter);
747 #ifdef DEBUG_SELECTION_FILTERS
748 int aCount = GetFilter()->StoredFilters().Extent();
749 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
753 void XGUI_Displayer::removeFilters()
755 Handle(AIS_InteractiveContext) aContext = AISContext();
756 if (aContext.IsNull())
758 GetFilter()->Clear();
761 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
763 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
764 foreach(ObjectPtr aObj, aDispList) {
765 if (!theList.contains(aObj))
768 foreach(ObjectPtr aObj, theList) {
769 if (!isVisible(aObj))
770 display(aObj, false);
775 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
777 if (!isVisible(theObject))
780 AISObjectPtr aAISObj = getAISObject(theObject);
781 if (aAISObj.get() == NULL)
784 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
785 return ::canBeShaded(anAIS);
788 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
789 const QIntList& theModes) const
791 Handle(AIS_InteractiveContext) aContext = AISContext();
792 if (aContext.IsNull() || theIO.IsNull())
795 // deactivate object in all modes, which are not in the list of activation
796 // It seems that after the IO deactivation the selected state of the IO's owners
797 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
798 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
799 // only if there is a difference in the current modes and the parameters modes.
800 // If the selection problem happens again, it is possible to write a test scenario and create
801 // a bug. The bug steps are the following:
802 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
803 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
804 TColStd_ListOfInteger aTColModes;
805 aContext->ActivatedModes(theIO, aTColModes);
806 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
807 QIntList aModesActivatedForIO;
808 //bool isDeactivated = false;
809 for (; itr.More(); itr.Next() ) {
810 Standard_Integer aMode = itr.Value();
811 if (!theModes.contains(aMode)) {
812 #ifdef DEBUG_ACTIVATE
813 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
815 aContext->Deactivate(theIO, aMode);
816 //isDeactivated = true;
819 aModesActivatedForIO.append(aMode);
820 #ifdef DEBUG_ACTIVATE
821 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
825 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
827 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
831 // loading the interactive object allowing the decomposition
832 if (aTColModes.IsEmpty())
833 aContext->Load(theIO, -1, true);
835 // trihedron AIS check should be after the AIS loading.
836 // If it is not loaded, it is steel selectable in the viewer.
837 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
838 if (aTrihedron.IsNull()) {
839 //aContext->Load(anAISIO, -1, true);
840 // In order to clear active modes list
841 if (theModes.size() == 0) {
842 //aContext->Load(anAISIO, 0, true);
843 aContext->Activate(theIO);
844 #ifdef DEBUG_ACTIVATE
845 qDebug("activate in all modes");
848 foreach(int aMode, theModes) {
849 //aContext->Load(anAISIO, aMode, true);
850 if (!aModesActivatedForIO.contains(aMode)) {
851 aContext->Activate(theIO, aMode);
852 #ifdef DEBUG_ACTIVATE
853 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
861 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
863 AISObjectPtr anAISObj = getAISObject(theObject);
864 // correct the result's color it it has the attribute
865 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
867 // Customization of presentation
868 GeomCustomPrsPtr aCustomPrs;
869 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
870 if (aFeature.get() != NULL) {
871 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
872 if (aCustPrs.get() != NULL)
873 aCustomPrs = aCustPrs;
875 if (aCustomPrs.get() == NULL) {
876 // we ignore presentable not customized objects
877 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
878 if (aPrs.get() != NULL)
880 aCustomPrs = myCustomPrs;
882 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
886 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
888 if (!isVisible(theObject))
891 AISObjectPtr anAISObj = getAISObject(theObject);
893 anAISObj->getColor(aR, aG, aB);
894 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
897 return QColor(aR, aG, aB);
900 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
902 myResult2AISObjectMap[theObject] = theAIS;
905 std::ostringstream aPtrStr;
906 aPtrStr << theObject.get();
907 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
908 qDebug(getResult2AISObjectMapInfo().c_str());
912 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
914 QStringList aContent;
915 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
916 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
917 std::ostringstream aPtrStr;
918 aPtrStr << "aObj = " << aObj.get() << ":";
919 aPtrStr << "anAIS = " << aAISObj.get() << ":";
920 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
922 aContent.append(aPtrStr.str().c_str());
924 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
925 arg(aContent.join("\n")).toStdString().c_str();