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
48 //#define DEBUG_FEATURE_REDISPLAY
49 //#define DEBUG_SELECTION_FILTERS
50 //#define DEBUG_USE_CLEAR_OUTDATED_SELECTION
52 // Workaround for bug #25637
53 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
55 // Get from null point
56 theAIS->DisplayedObjects(theList, true);
57 if (theAIS->HasOpenedContext()) {
58 // get from local context
59 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
60 TColStd_MapOfTransient aMap;
61 int NbDisp = aLC->DisplayedObjects(aMap);
62 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
64 Handle(AIS_InteractiveObject) curIO;
65 Handle(Standard_Transient) Tr;
66 for(; aIt.More(); aIt.Next()){
68 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
69 theList.Append(curIO);
75 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
76 : myWorkshop(theWorkshop)
78 enableUpdateViewer(true);
79 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
82 XGUI_Displayer::~XGUI_Displayer()
86 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
88 return myResult2AISObjectMap.contains(theObject);
91 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
93 if (isVisible(theObject)) {
94 redisplay(theObject, isUpdateViewer);
97 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
98 if (aFeature.get() != NULL) {
99 qDebug(QString("display feature: %1, displayed: %2").
100 arg(aFeature->data()->name().c_str()).
101 arg(displayedObjects().size()).toStdString().c_str());
106 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
107 bool isShading = false;
108 if (aPrs.get() != NULL) {
109 anAIS = aPrs->getAISObject(anAIS);
111 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
112 if (aResult.get() != NULL) {
113 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
114 if (aShapePtr.get() != NULL) {
115 anAIS = AISObjectPtr(new GeomAPI_AISObject());
116 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
117 //anAIS->createShape(aShapePtr);
123 display(theObject, anAIS, isShading, isUpdateViewer);
127 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
129 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
130 if (!aShapePrs.IsNull()) {
131 TopoDS_Shape aShape = aShapePrs->Shape();
132 TopAbs_ShapeEnum aType = aShape.ShapeType();
133 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
136 // Check that the presentation is not a sketch
137 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
139 return !aPrs->isSketchMode();
146 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
147 bool isShading, bool isUpdateViewer)
149 Handle(AIS_InteractiveContext) aContext = AISContext();
150 if (aContext.IsNull())
153 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
154 if (!anAISIO.IsNull()) {
155 myResult2AISObjectMap[theObject] = theAIS;
156 bool aCanBeShaded = ::canBeShaded(anAISIO);
157 // In order to avoid extra closing/opening context
158 SelectMgr_IndexedMapOfOwner aSelectedOwners;
160 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
161 closeLocalContexts(false);
163 aContext->Display(anAISIO, false);
164 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
166 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
167 emit objectDisplayed(theObject, theAIS);
169 bool isCustomized = customizeObject(theObject);
171 aContext->Redisplay(anAISIO, false);
175 activateObjects(myActiveSelectionModes);
176 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
179 activate(anAISIO, myActiveSelectionModes);
185 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
187 if (!isVisible(theObject))
190 Handle(AIS_InteractiveContext) aContext = AISContext();
191 if (aContext.IsNull())
193 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
195 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
196 if (!anAIS.IsNull()) {
197 emit beforeObjectErase(theObject, anObject);
198 aContext->Remove(anAIS, isUpdateViewer);
201 myResult2AISObjectMap.remove(theObject);
204 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
206 if (!isVisible(theObject))
209 AISObjectPtr aAISObj = getAISObject(theObject);
210 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
212 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
214 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
216 erase(theObject, isUpdateViewer);
219 if (aAIS_Obj != aAISObj) {
220 myResult2AISObjectMap[theObject] = aAIS_Obj;
222 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
225 if (!aAISIO.IsNull()) {
226 Handle(AIS_InteractiveContext) aContext = AISContext();
227 if (aContext.IsNull())
229 // Check that the visualized shape is the same and the redisplay is not necessary
230 // Redisplay of AIS object leads to this object selection compute and the selection
231 // in the browser is lost
233 // this check is not necessary anymore because the selection store/restore is realized
234 // before and after the values modification.
235 // Moreother, this check avoids customize and redisplay presentation if the presentable
236 // parameter is changed.
237 bool isEqualShapes = false;
238 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
239 if (aResult.get() != NULL) {
240 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
241 if (!aShapePrs.IsNull()) {
242 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
243 if (aShapePtr.get()) {
244 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
245 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
249 // Customization of presentation
250 bool isCustomized = customizeObject(theObject);
251 #ifdef DEBUG_FEATURE_REDISPLAY
252 //qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
253 // arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
255 if (!isEqualShapes || isCustomized) {
256 aContext->Redisplay(aAISIO, false);
257 #ifdef DEBUG_FEATURE_REDISPLAY
258 //qDebug(" Redisplay happens");
266 void XGUI_Displayer::deactivate(ObjectPtr theObject)
268 if (isVisible(theObject)) {
269 Handle(AIS_InteractiveContext) aContext = AISContext();
270 if (aContext.IsNull())
273 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
274 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
275 aContext->Deactivate(anAIS);
276 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
277 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
283 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
285 activate(theFeature, myActiveSelectionModes);
288 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
290 #ifdef DEBUG_ACTIVATE
291 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
293 if (aFeature.get() != NULL) {
295 getModesOfActivation(theObject, aModes);
298 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
299 arg(aFeature->data()->name().c_str()).
300 arg(theModes.size()).
301 arg(myActiveSelectionModes.size()).
302 arg(aModes.size()).toStdString().c_str());
306 if (isVisible(theObject)) {
307 Handle(AIS_InteractiveContext) aContext = AISContext();
308 if (aContext.IsNull())
311 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
312 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
314 activate(anAIS, theModes);
318 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
320 if (!isVisible(theObject))
323 Handle(AIS_InteractiveContext) aContext = AISContext();
324 if (aContext.IsNull())
327 AISObjectPtr aAISObj = getAISObject(theObject);
329 if (aAISObj.get() != NULL) {
330 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
331 TColStd_ListOfInteger aTColModes;
332 aContext->ActivatedModes(anAISIO, aTColModes);
333 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
334 for (; itr.More(); itr.Next() ) {
335 theModes.append(itr.Value());
340 void XGUI_Displayer::activateObjects(const QIntList& theModes)
342 #ifdef DEBUG_ACTIVATE
343 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
344 arg(theModes.size()).
345 arg(myActiveSelectionModes.size()).
346 toStdString().c_str());
348 // In order to avoid doblications of selection modes
350 foreach (int aMode, theModes) {
351 if (!aNewModes.contains(aMode))
352 aNewModes.append(aMode);
354 myActiveSelectionModes = aNewModes;
355 Handle(AIS_InteractiveContext) aContext = AISContext();
356 if (aContext.IsNull())
358 // Open local context if there is no one
359 if (!aContext->HasOpenedContext())
362 //aContext->UseDisplayedObjects();
363 //myUseExternalObjects = true;
365 AIS_ListOfInteractive aPrsList;
366 ::displayedObjects(aContext, aPrsList);
368 Handle(AIS_Trihedron) aTrihedron;
369 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
370 Handle(AIS_InteractiveObject) anAISIO;
371 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
372 anAISIO = aLIt.Value();
373 activate(anAISIO, myActiveSelectionModes);
378 void XGUI_Displayer::deactivateObjects()
380 myActiveSelectionModes.clear();
381 Handle(AIS_InteractiveContext) aContext = AISContext();
382 // Open local context if there is no one
383 if (!aContext->HasOpenedContext())
386 //aContext->NotUseDisplayedObjects();
387 AIS_ListOfInteractive aPrsList;
388 ::displayedObjects(aContext, aPrsList);
390 AIS_ListIteratorOfListOfInteractive aLIt;
391 //Handle(AIS_Trihedron) aTrihedron;
392 Handle(AIS_InteractiveObject) anAISIO;
393 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
394 anAISIO = aLIt.Value();
395 aContext->Deactivate(anAISIO);
396 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
397 aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
403 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
405 Handle(AIS_InteractiveContext) aContext = AISContext();
406 if (aContext.IsNull())
408 if (!isVisible(theObject))
411 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
412 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
414 TColStd_ListOfInteger aModes;
415 aContext->ActivatedModes(anAIS, aModes);
416 return aModes.Extent() > 0;
419 void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
421 Handle(AIS_InteractiveContext) aContext = AISContext();
422 if (aContext.IsNull())
424 if (aContext->HasOpenedContext()) {
425 aContext->UnhilightSelected();
426 aContext->ClearSelected();
427 foreach(ObjectPtr aResult, theResults) {
428 if (isVisible(aResult)) {
429 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
430 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
431 if (!anAIS.IsNull()) {
432 // The methods are replaced in order to provide multi-selection, e.g. restore selection
433 // by activating multi selector widget. It also gives an advantage that the multi
434 // selection in OB gives multi-selection in the viewer
435 //aContext->SetSelected(anAIS, false);
436 // The selection in the context was cleared, so the method sets the objects are selected
437 aContext->AddOrRemoveSelected(anAIS, false);
442 aContext->UnhilightCurrents();
443 aContext->ClearCurrents();
444 foreach(ObjectPtr aResult, theResults) {
445 if (isVisible(aResult)) {
446 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
447 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
449 aContext->SetCurrentObject(anAIS, false);
458 void XGUI_Displayer::clearSelected()
460 Handle(AIS_InteractiveContext) aContext = AISContext();
462 aContext->UnhilightCurrents(false);
463 aContext->ClearSelected();
467 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
469 Handle(AIS_InteractiveContext) aContext = AISContext();
470 if (!aContext.IsNull()) {
471 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
472 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
474 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
475 if (!anIO.IsNull()) {
476 emit beforeObjectErase(aObj, aAISObj);
477 aContext->Remove(anIO, false);
483 myResult2AISObjectMap.clear();
486 void XGUI_Displayer::openLocalContext()
488 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
489 if (aContext.IsNull())
491 // Open local context if there is no one
492 if (!aContext->HasOpenedContext()) {
493 // Preserve selected objects
494 //AIS_ListOfInteractive aAisList;
495 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
496 // aAisList.Append(aContext->Current());
498 // get the filters from the global context and append them to the local context
499 // a list of filters in the global context is not cleared and should be cleared here
500 SelectMgr_ListOfFilter aFilters;
501 aFilters.Assign(aContext->Filters());
502 // it is important to remove the filters in the global context, because there is a code
503 // in the closeLocalContex, which restore the global context filters
504 aContext->RemoveFilters();
506 //aContext->ClearCurrents();
507 aContext->OpenLocalContext();
508 //aContext->NotUseDisplayedObjects();
510 //myUseExternalObjects = false;
512 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
513 for (;aIt.More(); aIt.Next()) {
514 aContext->AddFilter(aIt.Value());
517 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
518 //for(; aIt2.More(); aIt2.Next()) {
519 // aContext->SetSelected(aIt2.Value(), false);
524 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
526 Handle(AIS_InteractiveContext) aContext = AISContext();
527 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
528 // Preserve selected objects
529 //AIS_ListOfInteractive aAisList;
530 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
531 // aAisList.Append(aContext->SelectedInteractive());
533 // get the filters from the local context and append them to the global context
534 // a list of filters in the local context is cleared
535 SelectMgr_ListOfFilter aFilters;
536 aFilters.Assign(aContext->Filters());
538 //aContext->ClearSelected();
539 aContext->CloseAllContexts(false);
541 // Redisplay all object if they were displayed in localContext
542 Handle(AIS_InteractiveObject) aAISIO;
543 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
544 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
545 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
546 aContext->Display(aAISIO, false);
547 aContext->SetDisplayMode(aAISIO, Shading, false);
551 // Append the filters from the local selection in the global selection context
552 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
553 for (;aIt.More(); aIt.Next()) {
554 Handle(SelectMgr_Filter) aFilter = aIt.Value();
555 aContext->AddFilter(aFilter);
560 //myUseExternalObjects = false;
563 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
564 //for(; aIt2.More(); aIt2.Next()) {
565 // if (aContext->IsDisplayed(aIt2.Value()))
566 // aContext->SetCurrentObject(aIt2.Value(), false);
571 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
574 if (myResult2AISObjectMap.contains(theObject))
575 anIO = myResult2AISObjectMap[theObject];
579 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
581 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
582 return getObject(aRefAIS);
585 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
588 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
589 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
590 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
597 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
599 bool aWasEnabled = myEnableUpdateViewer;
601 myEnableUpdateViewer = isEnabled;
606 void XGUI_Displayer::updateViewer() const
608 Handle(AIS_InteractiveContext) aContext = AISContext();
609 if (!aContext.IsNull() && myEnableUpdateViewer)
610 aContext->UpdateCurrentViewer();
613 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
615 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
616 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
617 aContext->OpenLocalContext();
622 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
624 Handle(AIS_InteractiveContext) aContext = AISContext();
625 if (myAndFilter.IsNull() && !aContext.IsNull()) {
626 myAndFilter = new SelectMgr_AndFilter();
627 aContext->AddFilter(myAndFilter);
632 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
634 Handle(AIS_InteractiveContext) aContext = AISContext();
635 if (aContext.IsNull())
637 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
638 if (!anAISIO.IsNull()) {
639 aContext->Display(anAISIO, isUpdate);
640 if (aContext->HasOpenedContext()) {
641 //if (myUseExternalObjects) {
642 if (myActiveSelectionModes.size() == 0)
643 aContext->Activate(anAISIO);
645 foreach(int aMode, myActiveSelectionModes) {
646 aContext->Activate(anAISIO, aMode);
654 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
656 Handle(AIS_InteractiveContext) aContext = AISContext();
657 if (aContext.IsNull())
659 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
660 if (!anAISIO.IsNull()) {
661 aContext->Remove(anAISIO, isUpdate);
666 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
668 if (theMode == NoMode)
671 Handle(AIS_InteractiveContext) aContext = AISContext();
672 if (aContext.IsNull())
675 AISObjectPtr aAISObj = getAISObject(theObject);
679 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
680 bool aCanBeShaded = ::canBeShaded(aAISIO);
681 // In order to avoid extra closing/opening context
682 SelectMgr_IndexedMapOfOwner aSelectedOwners;
684 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
685 closeLocalContexts(false);
687 aContext->SetDisplayMode(aAISIO, theMode, false);
688 // Redisplay in order to update new mode because it could be not computed before
689 aContext->Redisplay(aAISIO, false);
692 activateObjects(myActiveSelectionModes);
693 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
699 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
701 Handle(AIS_InteractiveContext) aContext = AISContext();
702 if (aContext.IsNull())
705 AISObjectPtr aAISObj = getAISObject(theObject);
709 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
710 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
713 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
715 Handle(AIS_InteractiveContext) aContext = AISContext();
716 if (aContext.IsNull())
718 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
719 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
720 for (; aIt.More(); aIt.Next()) {
721 if (theFilter.Access() == aIt.Value().Access())
724 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
725 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
726 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
727 if (theFilter.Access() == aIt.Value().Access())
730 aCompFilter->Add(theFilter);
731 #ifdef DEBUG_SELECTION_FILTERS
732 int aCount = GetFilter()->StoredFilters().Extent();
733 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
737 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
739 Handle(AIS_InteractiveContext) aContext = AISContext();
740 if (aContext.IsNull())
742 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
743 if (aCompositeFilter->IsIn(theFilter))
744 aCompositeFilter->Remove(theFilter);
745 #ifdef DEBUG_SELECTION_FILTERS
746 int aCount = GetFilter()->StoredFilters().Extent();
747 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
751 void XGUI_Displayer::removeFilters()
753 Handle(AIS_InteractiveContext) aContext = AISContext();
754 if (aContext.IsNull())
756 GetFilter()->Clear();
759 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
761 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
762 foreach(ObjectPtr aObj, aDispList) {
763 if (!theList.contains(aObj))
766 foreach(ObjectPtr aObj, theList) {
767 if (!isVisible(aObj))
768 display(aObj, false);
773 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
775 if (!isVisible(theObject))
778 AISObjectPtr aAISObj = getAISObject(theObject);
779 if (aAISObj.get() == NULL)
782 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
783 return ::canBeShaded(anAIS);
786 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
787 const QIntList& theModes) const
789 Handle(AIS_InteractiveContext) aContext = AISContext();
790 if (aContext.IsNull() || theIO.IsNull())
793 // deactivate object in all modes, which are not in the list of activation
794 // It seems that after the IO deactivation the selected state of the IO's owners
795 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
796 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
797 // only if there is a difference in the current modes and the parameters modes.
798 // If the selection problem happens again, it is possible to write a test scenario and create
799 // a bug. The bug steps are the following:
800 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
801 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
802 TColStd_ListOfInteger aTColModes;
803 aContext->ActivatedModes(theIO, aTColModes);
804 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
805 QIntList aModesActivatedForIO;
806 //bool isDeactivated = false;
807 for (; itr.More(); itr.Next() ) {
808 Standard_Integer aMode = itr.Value();
809 if (!theModes.contains(aMode)) {
810 #ifdef DEBUG_ACTIVATE
811 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
813 aContext->Deactivate(theIO, aMode);
814 //isDeactivated = true;
817 aModesActivatedForIO.append(aMode);
818 #ifdef DEBUG_ACTIVATE
819 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
823 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
825 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
829 // loading the interactive object allowing the decomposition
830 if (aTColModes.IsEmpty())
831 aContext->Load(theIO, -1, true);
833 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
834 //Deactivate trihedron which can be activated in local selector
835 if (aTrihedron.IsNull()) {
836 //aContext->Load(anAISIO, -1, true);
837 // In order to clear active modes list
838 if (theModes.size() == 0) {
839 //aContext->Load(anAISIO, 0, true);
840 aContext->Activate(theIO);
841 #ifdef DEBUG_ACTIVATE
842 qDebug("activate in all modes");
845 foreach(int aMode, theModes) {
846 //aContext->Load(anAISIO, aMode, true);
847 if (!aModesActivatedForIO.contains(aMode)) {
848 aContext->Activate(theIO, aMode);
849 #ifdef DEBUG_ACTIVATE
850 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
858 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
860 AISObjectPtr anAISObj = getAISObject(theObject);
861 // correct the result's color it it has the attribute
862 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
864 // Customization of presentation
865 GeomCustomPrsPtr aCustomPrs;
866 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
867 if (aFeature.get() != NULL) {
868 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
869 if (aCustPrs.get() != NULL)
870 aCustomPrs = aCustPrs;
872 if (aCustomPrs.get() == NULL) {
873 // we ignore presentable not customized objects
874 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
875 if (aPrs.get() != NULL)
877 aCustomPrs = myCustomPrs;
879 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
883 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
885 if (!isVisible(theObject))
888 AISObjectPtr anAISObj = getAISObject(theObject);
890 anAISObj->getColor(aR, aG, aB);
891 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
894 return QColor(aR, aG, aB);