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 <TColStd_MapOfTransient.hxx>
41 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
45 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
47 //#define DEBUG_DISPLAY
48 //#define DEBUG_ACTIVATE
49 //#define DEBUG_FEATURE_REDISPLAY
50 //#define DEBUG_SELECTION_FILTERS
51 //#define DEBUG_USE_CLEAR_OUTDATED_SELECTION
53 // Workaround for bug #25637
54 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
56 // Get from null point
57 theAIS->DisplayedObjects(theList, true);
58 if (theAIS->HasOpenedContext()) {
59 // get from local context
60 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
61 TColStd_MapOfTransient aMap;
62 int NbDisp = aLC->DisplayedObjects(aMap);
63 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
65 Handle(AIS_InteractiveObject) curIO;
66 Handle(Standard_Transient) Tr;
67 for(; aIt.More(); aIt.Next()){
69 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
70 theList.Append(curIO);
76 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
77 : myWorkshop(theWorkshop)
79 enableUpdateViewer(true);
80 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
83 XGUI_Displayer::~XGUI_Displayer()
87 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
89 return myResult2AISObjectMap.contains(theObject);
92 void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
94 if (isVisible(theObject)) {
95 redisplay(theObject, isUpdateViewer);
99 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
100 bool isShading = false;
101 if (aPrs.get() != NULL) {
102 anAIS = aPrs->getAISObject(anAIS);
104 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
105 if (aResult.get() != NULL) {
106 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
107 if (aShapePtr.get() != NULL) {
108 anAIS = AISObjectPtr(new GeomAPI_AISObject());
109 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
110 //anAIS->createShape(aShapePtr);
116 display(theObject, anAIS, isShading, isUpdateViewer);
120 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
122 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
123 if (!aShapePrs.IsNull()) {
124 TopoDS_Shape aShape = aShapePrs->Shape();
125 TopAbs_ShapeEnum aType = aShape.ShapeType();
126 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
129 // Check that the presentation is not a sketch
130 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
132 return !aPrs->isSketchMode();
139 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
140 bool isShading, bool isUpdateViewer)
142 Handle(AIS_InteractiveContext) aContext = AISContext();
143 if (aContext.IsNull())
146 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
147 if (!anAISIO.IsNull()) {
148 appendResultObject(theObject, theAIS);
150 bool aCanBeShaded = ::canBeShaded(anAISIO);
151 // In order to avoid extra closing/opening context
152 SelectMgr_IndexedMapOfOwner aSelectedOwners;
154 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
155 closeLocalContexts(false);
157 aContext->Display(anAISIO, false);
158 aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
160 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
161 emit objectDisplayed(theObject, theAIS);
163 bool isCustomized = customizeObject(theObject);
165 aContext->Redisplay(anAISIO, false);
169 activateObjects(myActiveSelectionModes);
170 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
173 activate(anAISIO, myActiveSelectionModes);
179 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
181 if (!isVisible(theObject))
184 Handle(AIS_InteractiveContext) aContext = AISContext();
185 if (aContext.IsNull())
187 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
189 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
190 if (!anAIS.IsNull()) {
191 emit beforeObjectErase(theObject, anObject);
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 appendResultObject(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& aOldShape = aShapePrs->Shape();
239 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
243 // Customization of presentation
244 bool isCustomized = customizeObject(theObject);
245 #ifdef DEBUG_FEATURE_REDISPLAY
246 //qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
247 // arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
249 if (!isEqualShapes || isCustomized) {
250 aContext->Redisplay(aAISIO, false);
251 #ifdef DEBUG_FEATURE_REDISPLAY
252 //qDebug(" Redisplay happens");
260 void XGUI_Displayer::deactivate(ObjectPtr theObject)
262 if (isVisible(theObject)) {
263 Handle(AIS_InteractiveContext) aContext = AISContext();
264 if (aContext.IsNull())
267 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
268 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
269 aContext->Deactivate(anAIS);
270 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
271 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
277 /*void XGUI_Displayer::activate(ObjectPtr theFeature)
279 activate(theFeature, myActiveSelectionModes);
282 void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
284 #ifdef DEBUG_ACTIVATE
285 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
287 if (aFeature.get() != NULL) {
289 getModesOfActivation(theObject, aModes);
292 qDebug(QString("activate feature: %1, theModes: %2, myActiveSelectionModes: %3, getModesOf: %4").
293 arg(aFeature->data()->name().c_str()).
294 arg(theModes.size()).
295 arg(myActiveSelectionModes.size()).
296 arg(aModes.size()).toStdString().c_str());
300 if (isVisible(theObject)) {
301 Handle(AIS_InteractiveContext) aContext = AISContext();
302 if (aContext.IsNull())
305 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
306 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
308 activate(anAIS, theModes);
312 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
314 if (!isVisible(theObject))
317 Handle(AIS_InteractiveContext) aContext = AISContext();
318 if (aContext.IsNull())
321 AISObjectPtr aAISObj = getAISObject(theObject);
323 if (aAISObj.get() != NULL) {
324 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
325 TColStd_ListOfInteger aTColModes;
326 aContext->ActivatedModes(anAISIO, aTColModes);
327 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
328 for (; itr.More(); itr.Next() ) {
329 theModes.append(itr.Value());
334 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList)
336 #ifdef DEBUG_ACTIVATE
337 qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
338 arg(theModes.size()).
339 arg(myActiveSelectionModes.size()).
340 toStdString().c_str());
342 // In order to avoid doblications of selection modes
344 foreach (int aMode, theModes) {
345 if (!aNewModes.contains(aMode))
346 aNewModes.append(aMode);
348 myActiveSelectionModes = aNewModes;
349 Handle(AIS_InteractiveContext) aContext = AISContext();
350 if (aContext.IsNull())
352 // Open local context if there is no one
353 if (!aContext->HasOpenedContext())
356 //aContext->UseDisplayedObjects();
357 //myUseExternalObjects = true;
359 Handle(AIS_InteractiveObject) anAISIO;
360 AIS_ListOfInteractive aPrsList;
361 if (theObjList.isEmpty())
362 ::displayedObjects(aContext, aPrsList);
364 foreach(ObjectPtr aObj, theObjList) {
365 if (myResult2AISObjectMap.contains(aObj))
366 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
370 Handle(AIS_Trihedron) aTrihedron;
371 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
372 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
373 anAISIO = aLIt.Value();
374 aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
375 if (aTrihedron.IsNull())
376 activate(anAISIO, myActiveSelectionModes);
381 void XGUI_Displayer::deactivateObjects()
383 myActiveSelectionModes.clear();
384 Handle(AIS_InteractiveContext) aContext = AISContext();
385 // Open local context if there is no one
386 if (!aContext->HasOpenedContext())
389 //aContext->NotUseDisplayedObjects();
390 AIS_ListOfInteractive aPrsList;
391 ::displayedObjects(aContext, aPrsList);
393 AIS_ListIteratorOfListOfInteractive aLIt;
394 //Handle(AIS_Trihedron) aTrihedron;
395 Handle(AIS_InteractiveObject) anAISIO;
396 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
397 anAISIO = aLIt.Value();
398 aContext->Deactivate(anAISIO);
399 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
400 aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
406 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
408 Handle(AIS_InteractiveContext) aContext = AISContext();
409 if (aContext.IsNull())
411 if (!isVisible(theObject))
414 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
415 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
417 TColStd_ListOfInteger aModes;
418 aContext->ActivatedModes(anAIS, aModes);
419 return aModes.Extent() > 0;
422 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer)
424 Handle(AIS_InteractiveContext) aContext = AISContext();
425 if (aContext.IsNull())
427 if (aContext->HasOpenedContext()) {
428 aContext->UnhilightSelected();
429 aContext->ClearSelected();
430 //if (aSelected.size() > 0) {
431 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
432 const TopoDS_Shape& aShape = aPrs.shape();
433 if (!aShape.IsNull()) {
434 aContext->AddOrRemoveSelected(aShape, false);
436 ObjectPtr anObject = aPrs.object();
437 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
438 if (aResult.get() && isVisible(aResult)) {
439 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
440 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
441 if (!anAIS.IsNull()) {
442 // The methods are replaced in order to provide multi-selection, e.g. restore selection
443 // by activating multi selector widget. It also gives an advantage that the multi
444 // selection in OB gives multi-selection in the viewer
445 //aContext->SetSelected(anAIS, false);
446 // The selection in the context was cleared, so the method sets the objects are selected
447 aContext->AddOrRemoveSelected(anAIS, false);
453 aContext->UnhilightCurrents();
454 aContext->ClearCurrents();
455 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
456 ObjectPtr anObject = aPrs.object();
457 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
458 if (aResult.get() && isVisible(aResult)) {
459 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
460 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
462 aContext->SetCurrentObject(anAIS, false);
470 void XGUI_Displayer::clearSelected()
472 Handle(AIS_InteractiveContext) aContext = AISContext();
474 aContext->UnhilightCurrents(false);
475 aContext->ClearSelected();
479 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
481 Handle(AIS_InteractiveContext) aContext = AISContext();
482 if (!aContext.IsNull()) {
483 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
484 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
486 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
487 if (!anIO.IsNull()) {
488 emit beforeObjectErase(aObj, aAISObj);
489 aContext->Remove(anIO, false);
495 myResult2AISObjectMap.clear();
498 void XGUI_Displayer::openLocalContext()
500 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
501 if (aContext.IsNull())
503 // Open local context if there is no one
504 if (!aContext->HasOpenedContext()) {
505 // Preserve selected objects
506 //AIS_ListOfInteractive aAisList;
507 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
508 // aAisList.Append(aContext->Current());
510 // get the filters from the global context and append them to the local context
511 // a list of filters in the global context is not cleared and should be cleared here
512 SelectMgr_ListOfFilter aFilters;
513 aFilters.Assign(aContext->Filters());
514 // it is important to remove the filters in the global context, because there is a code
515 // in the closeLocalContex, which restore the global context filters
516 aContext->RemoveFilters();
518 //aContext->ClearCurrents();
519 aContext->OpenLocalContext();
520 //aContext->NotUseDisplayedObjects();
522 //myUseExternalObjects = false;
524 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
525 for (;aIt.More(); aIt.Next()) {
526 aContext->AddFilter(aIt.Value());
529 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
530 //for(; aIt2.More(); aIt2.Next()) {
531 // aContext->SetSelected(aIt2.Value(), false);
536 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
538 Handle(AIS_InteractiveContext) aContext = AISContext();
539 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
540 // Preserve selected objects
541 //AIS_ListOfInteractive aAisList;
542 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
543 // aAisList.Append(aContext->SelectedInteractive());
545 // get the filters from the local context and append them to the global context
546 // a list of filters in the local context is cleared
547 SelectMgr_ListOfFilter aFilters;
548 aFilters.Assign(aContext->Filters());
550 //aContext->ClearSelected();
551 aContext->CloseAllContexts(false);
553 // Redisplay all object if they were displayed in localContext
554 Handle(AIS_InteractiveObject) aAISIO;
555 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
556 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
557 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
558 aContext->Display(aAISIO, false);
559 aContext->SetDisplayMode(aAISIO, Shading, false);
563 // Append the filters from the local selection in the global selection context
564 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
565 for (;aIt.More(); aIt.Next()) {
566 Handle(SelectMgr_Filter) aFilter = aIt.Value();
567 aContext->AddFilter(aFilter);
572 //myUseExternalObjects = false;
575 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
576 //for(; aIt2.More(); aIt2.Next()) {
577 // if (aContext->IsDisplayed(aIt2.Value()))
578 // aContext->SetCurrentObject(aIt2.Value(), false);
583 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
586 if (myResult2AISObjectMap.contains(theObject))
587 anIO = myResult2AISObjectMap[theObject];
591 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
593 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
594 return getObject(aRefAIS);
597 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
600 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
601 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
602 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
609 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
611 bool aWasEnabled = myEnableUpdateViewer;
613 myEnableUpdateViewer = isEnabled;
618 void XGUI_Displayer::updateViewer() const
620 Handle(AIS_InteractiveContext) aContext = AISContext();
621 if (!aContext.IsNull() && myEnableUpdateViewer)
622 aContext->UpdateCurrentViewer();
625 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
627 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
628 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
629 aContext->OpenLocalContext();
634 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
636 Handle(AIS_InteractiveContext) aContext = AISContext();
637 if (myAndFilter.IsNull() && !aContext.IsNull()) {
638 myAndFilter = new SelectMgr_AndFilter();
639 aContext->AddFilter(myAndFilter);
644 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
646 Handle(AIS_InteractiveContext) aContext = AISContext();
647 if (aContext.IsNull())
649 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
650 if (!anAISIO.IsNull()) {
651 aContext->Display(anAISIO, isUpdate);
652 if (aContext->HasOpenedContext()) {
653 //if (myUseExternalObjects) {
654 if (myActiveSelectionModes.size() == 0)
655 aContext->Activate(anAISIO);
657 foreach(int aMode, myActiveSelectionModes) {
658 aContext->Activate(anAISIO, aMode);
666 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
668 Handle(AIS_InteractiveContext) aContext = AISContext();
669 if (aContext.IsNull())
671 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
672 if (!anAISIO.IsNull()) {
673 aContext->Remove(anAISIO, isUpdate);
678 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
680 if (theMode == NoMode)
683 Handle(AIS_InteractiveContext) aContext = AISContext();
684 if (aContext.IsNull())
687 AISObjectPtr aAISObj = getAISObject(theObject);
691 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
692 bool aCanBeShaded = ::canBeShaded(aAISIO);
693 // In order to avoid extra closing/opening context
694 SelectMgr_IndexedMapOfOwner aSelectedOwners;
696 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
697 closeLocalContexts(false);
699 aContext->SetDisplayMode(aAISIO, theMode, false);
700 // Redisplay in order to update new mode because it could be not computed before
701 aContext->Redisplay(aAISIO, false);
704 activateObjects(myActiveSelectionModes);
705 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
711 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
713 Handle(AIS_InteractiveContext) aContext = AISContext();
714 if (aContext.IsNull())
717 AISObjectPtr aAISObj = getAISObject(theObject);
721 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
722 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
725 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
727 Handle(AIS_InteractiveContext) aContext = AISContext();
728 if (aContext.IsNull())
730 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
731 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
732 for (; aIt.More(); aIt.Next()) {
733 if (theFilter.Access() == aIt.Value().Access())
736 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
737 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
738 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
739 if (theFilter.Access() == aIt.Value().Access())
742 aCompFilter->Add(theFilter);
743 #ifdef DEBUG_SELECTION_FILTERS
744 int aCount = GetFilter()->StoredFilters().Extent();
745 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
749 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
751 Handle(AIS_InteractiveContext) aContext = AISContext();
752 if (aContext.IsNull())
754 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
755 if (aCompositeFilter->IsIn(theFilter))
756 aCompositeFilter->Remove(theFilter);
757 #ifdef DEBUG_SELECTION_FILTERS
758 int aCount = GetFilter()->StoredFilters().Extent();
759 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
763 void XGUI_Displayer::removeFilters()
765 Handle(AIS_InteractiveContext) aContext = AISContext();
766 if (aContext.IsNull())
768 GetFilter()->Clear();
771 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
773 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
774 foreach(ObjectPtr aObj, aDispList) {
775 if (!theList.contains(aObj))
778 foreach(ObjectPtr aObj, theList) {
779 if (!isVisible(aObj))
780 display(aObj, false);
785 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
787 if (!isVisible(theObject))
790 AISObjectPtr aAISObj = getAISObject(theObject);
791 if (aAISObj.get() == NULL)
794 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
795 return ::canBeShaded(anAIS);
798 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
799 const QIntList& theModes) const
801 Handle(AIS_InteractiveContext) aContext = AISContext();
802 if (aContext.IsNull() || theIO.IsNull())
805 // deactivate object in all modes, which are not in the list of activation
806 // It seems that after the IO deactivation the selected state of the IO's owners
807 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
808 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
809 // only if there is a difference in the current modes and the parameters modes.
810 // If the selection problem happens again, it is possible to write a test scenario and create
811 // a bug. The bug steps are the following:
812 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
813 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
814 TColStd_ListOfInteger aTColModes;
815 aContext->ActivatedModes(theIO, aTColModes);
816 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
817 QIntList aModesActivatedForIO;
818 //bool isDeactivated = false;
819 for (; itr.More(); itr.Next() ) {
820 Standard_Integer aMode = itr.Value();
821 if (!theModes.contains(aMode)) {
822 #ifdef DEBUG_ACTIVATE
823 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
825 aContext->Deactivate(theIO, aMode);
826 //isDeactivated = true;
829 aModesActivatedForIO.append(aMode);
830 #ifdef DEBUG_ACTIVATE
831 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
835 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
837 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
841 // loading the interactive object allowing the decomposition
842 if (aTColModes.IsEmpty())
843 aContext->Load(theIO, -1, true);
845 //aContext->Load(anAISIO, -1, true);
846 // In order to clear active modes list
847 if (theModes.size() == 0) {
848 //aContext->Load(anAISIO, 0, true);
849 aContext->Activate(theIO);
850 #ifdef DEBUG_ACTIVATE
851 qDebug("activate in all modes");
854 foreach(int aMode, theModes) {
855 //aContext->Load(anAISIO, aMode, true);
856 if (!aModesActivatedForIO.contains(aMode)) {
857 aContext->Activate(theIO, aMode);
858 #ifdef DEBUG_ACTIVATE
859 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
866 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
868 AISObjectPtr anAISObj = getAISObject(theObject);
869 // correct the result's color it it has the attribute
870 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
872 // Customization of presentation
873 GeomCustomPrsPtr aCustomPrs;
874 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
875 if (aFeature.get() != NULL) {
876 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
877 if (aCustPrs.get() != NULL)
878 aCustomPrs = aCustPrs;
880 if (aCustomPrs.get() == NULL) {
881 // we ignore presentable not customized objects
882 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
883 if (aPrs.get() != NULL)
885 aCustomPrs = myCustomPrs;
887 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
891 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
893 if (!isVisible(theObject))
896 AISObjectPtr anAISObj = getAISObject(theObject);
898 anAISObj->getColor(aR, aG, aB);
899 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
902 return QColor(aR, aG, aB);
905 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
907 myResult2AISObjectMap[theObject] = theAIS;
910 std::ostringstream aPtrStr;
911 aPtrStr << theObject.get();
912 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
913 qDebug(getResult2AISObjectMapInfo().c_str());
917 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
919 QStringList aContent;
920 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
921 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
922 std::ostringstream aPtrStr;
923 aPtrStr << "aObj = " << aObj.get() << ":";
924 aPtrStr << "anAIS = " << aAISObj.get() << ":";
925 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
927 aContent.append(aPtrStr.str().c_str());
929 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
930 arg(aContent.join("\n")).toStdString().c_str();