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>
24 #include <ModuleBase_IModule.h>
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_IPresentable.h>
28 #include <GeomAPI_ICustomPrs.h>
30 #include <AIS_InteractiveContext.hxx>
31 #include <AIS_LocalContext.hxx>
32 #include <AIS_ListOfInteractive.hxx>
33 #include <AIS_ListIteratorOfListOfInteractive.hxx>
34 #include <AIS_DimensionSelectionMode.hxx>
35 #include <AIS_Shape.hxx>
36 #include <AIS_Dimension.hxx>
37 #include <TColStd_ListIteratorOfListOfInteger.hxx>
38 #include <SelectMgr_ListOfFilter.hxx>
39 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
41 #include <StdSelect_ViewerSelector3d.hxx>
43 #include <TColStd_MapOfTransient.hxx>
44 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
48 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
50 //#define DEBUG_ACTIVATE_OBJECTS
51 //#define DEBUG_DEACTIVATE
52 //#define DEBUG_ACTIVATE_AIS
53 //#define DEBUG_DEACTIVATE_AIS
55 //#define DEBUG_DISPLAY
56 //#define DEBUG_FEATURE_REDISPLAY
57 //#define DEBUG_SELECTION_FILTERS
59 // Workaround for bug #25637
60 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
62 // Get from null point
63 theAIS->DisplayedObjects(theList, true);
64 if (theAIS->HasOpenedContext()) {
65 // get from local context
66 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
67 TColStd_MapOfTransient aMap;
68 int NbDisp = aLC->DisplayedObjects(aMap);
69 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
71 Handle(AIS_InteractiveObject) curIO;
72 Handle(Standard_Transient) Tr;
73 for(; aIt.More(); aIt.Next()){
75 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
76 theList.Append(curIO);
81 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
84 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
85 for (; anIt != aLast; anIt++) {
86 anInfo.append(QString::number(*anIt));
88 return anInfo.join(theSeparator);
91 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
92 : myWorkshop(theWorkshop)
94 enableUpdateViewer(true);
95 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
98 XGUI_Displayer::~XGUI_Displayer()
102 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
104 return myResult2AISObjectMap.contains(theObject);
107 void XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
109 if (isVisible(theObject)) {
110 redisplay(theObject, theUpdateViewer);
114 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
115 bool isShading = false;
116 if (aPrs.get() != NULL) {
117 anAIS = aPrs->getAISObject(anAIS);
119 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
120 if (aResult.get() != NULL) {
121 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
122 if (aShapePtr.get() != NULL) {
123 anAIS = AISObjectPtr(new GeomAPI_AISObject());
124 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
125 //anAIS->createShape(aShapePtr);
131 display(theObject, anAIS, isShading, theUpdateViewer);
135 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
137 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
138 if (!aShapePrs.IsNull()) {
139 TopoDS_Shape aShape = aShapePrs->Shape();
140 TopAbs_ShapeEnum aType = aShape.ShapeType();
141 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
144 // Check that the presentation is not a sketch
145 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
147 return !aPrs->isSketchMode();
154 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
155 bool isShading, bool theUpdateViewer)
157 Handle(AIS_InteractiveContext) aContext = AISContext();
158 if (aContext.IsNull())
161 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
162 if (!anAISIO.IsNull()) {
163 appendResultObject(theObject, theAIS);
165 bool isCustomized = customizeObject(theObject);
167 int aDispMode = isShading? Shading : Wireframe;
169 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
170 anAISIO->SetDisplayMode(aDispMode);
171 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
173 emit objectDisplayed(theObject, theAIS);
174 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
180 void XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
182 if (!isVisible(theObject))
185 Handle(AIS_InteractiveContext) aContext = AISContext();
186 if (aContext.IsNull())
188 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
190 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
191 if (!anAIS.IsNull()) {
192 emit beforeObjectErase(theObject, anObject);
193 aContext->Remove(anAIS, theUpdateViewer);
196 myResult2AISObjectMap.remove(theObject);
199 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
201 if (!isVisible(theObject))
204 AISObjectPtr aAISObj = getAISObject(theObject);
205 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
207 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
209 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
211 erase(theObject, theUpdateViewer);
214 if (aAIS_Obj != aAISObj) {
215 appendResultObject(theObject, aAIS_Obj);
217 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
220 if (!aAISIO.IsNull()) {
221 Handle(AIS_InteractiveContext) aContext = AISContext();
222 if (aContext.IsNull())
224 // Check that the visualized shape is the same and the redisplay is not necessary
225 // Redisplay of AIS object leads to this object selection compute and the selection
226 // in the browser is lost
228 // this check is not necessary anymore because the selection store/restore is realized
229 // before and after the values modification.
230 // Moreother, this check avoids customize and redisplay presentation if the presentable
231 // parameter is changed.
232 bool isEqualShapes = false;
233 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
234 if (aResult.get() != NULL) {
235 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
236 if (!aShapePrs.IsNull()) {
237 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
238 if (aShapePtr.get()) {
239 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
240 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
244 // Customization of presentation
245 bool isCustomized = customizeObject(theObject);
246 #ifdef DEBUG_FEATURE_REDISPLAY
247 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
248 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
250 if (!isEqualShapes || isCustomized) {
251 aContext->Redisplay(aAISIO, false);
252 #ifdef DEBUG_FEATURE_REDISPLAY
253 qDebug(" Redisplay happens");
261 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
263 #ifdef DEBUG_DEACTIVATE
264 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
265 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
266 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
268 toStdString().c_str());
270 if (isVisible(theObject)) {
271 Handle(AIS_InteractiveContext) aContext = AISContext();
272 if (aContext.IsNull())
275 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
276 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
278 deactivateAIS(anAIS);
279 // the selection from the previous activation modes should be cleared manually (#26172)
280 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
286 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
288 if (!isVisible(theObject))
291 Handle(AIS_InteractiveContext) aContext = AISContext();
292 if (aContext.IsNull())
295 AISObjectPtr aAISObj = getAISObject(theObject);
297 if (aAISObj.get() != NULL) {
298 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
299 TColStd_ListOfInteger aTColModes;
300 aContext->ActivatedModes(anAISIO, aTColModes);
301 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
302 for (; itr.More(); itr.Next() ) {
303 theModes.append(itr.Value());
308 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
309 const bool theUpdateViewer)
311 // Convert shape types to selection types
313 foreach(int aType, theModes) {
314 if (aType > TopAbs_SHAPE)
315 aModes.append(aType);
317 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
320 #ifdef DEBUG_ACTIVATE_OBJECTS
322 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
323 for (; anIt != aLast; ++anIt) {
324 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
326 QString anInfoStr = anInfo.join(", ");
328 qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
329 arg(aModes.size()).arg(qIntListInfo(aModes)).
330 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
332 toStdString().c_str());
334 // In order to avoid doblications of selection modes
336 foreach (int aMode, aModes) {
337 if (!aNewModes.contains(aMode))
338 aNewModes.append(aMode);
340 myActiveSelectionModes = aNewModes;
341 Handle(AIS_InteractiveContext) aContext = AISContext();
342 if (aContext.IsNull())
344 // Open local context if there is no one
345 if (!aContext->HasOpenedContext())
348 //aContext->UseDisplayedObjects();
349 //myUseExternalObjects = true;
351 Handle(AIS_InteractiveObject) anAISIO;
352 AIS_ListOfInteractive aPrsList;
353 if (theObjList.isEmpty())
356 foreach(ObjectPtr aObj, theObjList) {
357 if (myResult2AISObjectMap.contains(aObj))
358 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
362 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
363 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
364 anAISIO = aLIt.Value();
365 activate(anAISIO, myActiveSelectionModes, false);
371 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
373 Handle(AIS_InteractiveContext) aContext = AISContext();
374 if (aContext.IsNull())
376 if (!isVisible(theObject))
379 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
380 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
382 TColStd_ListOfInteger aModes;
383 aContext->ActivatedModes(anAIS, aModes);
384 return aModes.Extent() > 0;
386 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer)
388 Handle(AIS_InteractiveContext) aContext = AISContext();
389 if (aContext.IsNull())
391 if (aContext->HasOpenedContext()) {
392 aContext->UnhilightSelected();
393 aContext->ClearSelected();
394 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
395 const TopoDS_Shape& aShape = aPrs.shape();
396 if (!aShape.IsNull()) {
397 aContext->AddOrRemoveSelected(aShape, false);
399 ObjectPtr anObject = aPrs.object();
400 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
401 if (aResult.get() && isVisible(aResult)) {
402 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
403 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
404 if (!anAIS.IsNull()) {
405 // The methods are replaced in order to provide multi-selection, e.g. restore selection
406 // by activating multi selector widget. It also gives an advantage that the multi
407 // selection in OB gives multi-selection in the viewer
408 //aContext->SetSelected(anAIS, false);
409 // The selection in the context was cleared, so the method sets the objects are selected
410 aContext->AddOrRemoveSelected(anAIS, false);
416 aContext->UnhilightCurrents();
417 aContext->ClearCurrents();
418 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
419 ObjectPtr anObject = aPrs.object();
420 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
421 if (aResult.get() && isVisible(aResult)) {
422 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
423 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
425 aContext->SetCurrentObject(anAIS, false);
433 void XGUI_Displayer::clearSelected()
435 Handle(AIS_InteractiveContext) aContext = AISContext();
437 aContext->UnhilightCurrents(false);
438 aContext->ClearSelected();
442 void XGUI_Displayer::eraseAll(const bool theUpdateViewer)
444 Handle(AIS_InteractiveContext) aContext = AISContext();
445 if (!aContext.IsNull()) {
446 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
447 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
449 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
450 if (!anIO.IsNull()) {
451 emit beforeObjectErase(aObj, aAISObj);
452 aContext->Remove(anIO, false);
458 myResult2AISObjectMap.clear();
461 void XGUI_Displayer::deactivateTrihedron() const
463 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
465 AIS_ListOfInteractive aList;
466 aContext->DisplayedObjects(aList, true);
467 AIS_ListIteratorOfListOfInteractive aIt;
468 for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
469 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
470 if (!aTrihedron.IsNull()) {
471 aContext->Deactivate(aTrihedron);
476 void XGUI_Displayer::openLocalContext()
478 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
479 if (aContext.IsNull())
481 // Open local context if there is no one
482 if (!aContext->HasOpenedContext()) {
483 // Preserve selected objects
484 //AIS_ListOfInteractive aAisList;
485 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
486 // aAisList.Append(aContext->Current());
488 // get the filters from the global context and append them to the local context
489 // a list of filters in the global context is not cleared and should be cleared here
490 SelectMgr_ListOfFilter aFilters;
491 aFilters.Assign(aContext->Filters());
492 // it is important to remove the filters in the global context, because there is a code
493 // in the closeLocalContex, which restore the global context filters
494 aContext->RemoveFilters();
496 //aContext->ClearCurrents();
497 aContext->OpenLocalContext();
498 deactivateTrihedron();
499 //aContext->NotUseDisplayedObjects();
501 //myUseExternalObjects = false;
503 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
504 for (;aIt.More(); aIt.Next()) {
505 aContext->AddFilter(aIt.Value());
508 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
509 //for(; aIt2.More(); aIt2.Next()) {
510 // aContext->SetSelected(aIt2.Value(), false);
515 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
517 Handle(AIS_InteractiveContext) aContext = AISContext();
518 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
519 // Preserve selected objects
520 //AIS_ListOfInteractive aAisList;
521 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
522 // aAisList.Append(aContext->SelectedInteractive());
524 // get the filters from the local context and append them to the global context
525 // a list of filters in the local context is cleared
526 SelectMgr_ListOfFilter aFilters;
527 aFilters.Assign(aContext->Filters());
529 //aContext->ClearSelected();
530 aContext->CloseAllContexts(false);
532 // Redisplay all object if they were displayed in localContext
533 Handle(AIS_InteractiveObject) aAISIO;
534 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
535 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
536 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
537 aContext->Display(aAISIO, false);
538 aContext->SetDisplayMode(aAISIO, Shading, false);
542 // Append the filters from the local selection in the global selection context
543 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
544 for (;aIt.More(); aIt.Next()) {
545 Handle(SelectMgr_Filter) aFilter = aIt.Value();
546 aContext->AddFilter(aFilter);
551 //myUseExternalObjects = false;
554 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
555 //for(; aIt2.More(); aIt2.Next()) {
556 // if (aContext->IsDisplayed(aIt2.Value()))
557 // aContext->SetCurrentObject(aIt2.Value(), false);
562 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
565 if (myResult2AISObjectMap.contains(theObject))
566 anIO = myResult2AISObjectMap[theObject];
570 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
572 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
573 return getObject(aRefAIS);
576 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
579 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
580 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
581 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
587 if (!anObject.get()) {
588 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
589 if (!theIO.IsNull()) {
590 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
592 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
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 myWorkshop->viewer()->Zfitall();
611 aContext->UpdateCurrentViewer();
615 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
616 const int theMode, const bool theUpdateViewer) const
618 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
619 aContext->Activate(theIO, theMode, theUpdateViewer);
621 #ifdef DEBUG_ACTIVATE_AIS
622 ObjectPtr anObject = getObject(theIO);
623 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
624 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
628 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
630 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
632 aContext->Deactivate(theIO);
634 aContext->Deactivate(theIO, theMode);
636 #ifdef DEBUG_DEACTIVATE_AIS
637 ObjectPtr anObject = getObject(theIO);
638 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
639 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
643 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
645 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
646 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
647 aContext->OpenLocalContext();
648 deactivateTrihedron();
653 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
655 Handle(AIS_InteractiveContext) aContext = AISContext();
656 if (myAndFilter.IsNull() && !aContext.IsNull()) {
657 myAndFilter = new SelectMgr_AndFilter();
658 aContext->AddFilter(myAndFilter);
663 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer)
665 Handle(AIS_InteractiveContext) aContext = AISContext();
666 if (aContext.IsNull())
668 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
669 if (!anAISIO.IsNull()) {
670 aContext->Display(anAISIO, theUpdateViewer);
671 if (aContext->HasOpenedContext()) {
672 if (myActiveSelectionModes.size() == 0)
673 activateAIS(anAISIO, 0, theUpdateViewer);
675 foreach(int aMode, myActiveSelectionModes) {
676 activateAIS(anAISIO, aMode, theUpdateViewer);
683 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
685 Handle(AIS_InteractiveContext) aContext = AISContext();
686 if (aContext.IsNull())
688 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
689 if (!anAISIO.IsNull()) {
690 aContext->Remove(anAISIO, theUpdateViewer);
695 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
697 if (theMode == NoMode)
700 Handle(AIS_InteractiveContext) aContext = AISContext();
701 if (aContext.IsNull())
704 AISObjectPtr aAISObj = getAISObject(theObject);
708 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
709 aContext->SetDisplayMode(aAISIO, theMode, false);
710 // Redisplay in order to update new mode because it could be not computed before
715 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
717 Handle(AIS_InteractiveContext) aContext = AISContext();
718 if (aContext.IsNull())
721 AISObjectPtr aAISObj = getAISObject(theObject);
725 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
726 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
729 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
731 Handle(AIS_InteractiveContext) aContext = AISContext();
732 if (aContext.IsNull() || hasSelectionFilter(theFilter))
735 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
736 aCompFilter->Add(theFilter);
737 #ifdef DEBUG_SELECTION_FILTERS
738 int aCount = GetFilter()->StoredFilters().Extent();
739 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
743 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
745 Handle(AIS_InteractiveContext) aContext = AISContext();
746 if (aContext.IsNull())
748 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
749 if (aCompositeFilter->IsIn(theFilter))
750 aCompositeFilter->Remove(theFilter);
751 #ifdef DEBUG_SELECTION_FILTERS
752 int aCount = GetFilter()->StoredFilters().Extent();
753 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
757 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
759 bool aFilterFound = false;
761 Handle(AIS_InteractiveContext) aContext = AISContext();
762 if (aContext.IsNull())
764 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
765 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
766 for (; aIt.More() && !aFilterFound; aIt.Next()) {
767 if (theFilter.Access() == aIt.Value().Access())
770 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
771 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
772 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
773 if (theFilter.Access() == aIt.Value().Access())
779 void XGUI_Displayer::removeFilters()
781 Handle(AIS_InteractiveContext) aContext = AISContext();
782 if (aContext.IsNull())
784 GetFilter()->Clear();
787 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
789 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
790 foreach(ObjectPtr aObj, aDispList) {
791 if (!theList.contains(aObj))
794 foreach(ObjectPtr aObj, theList) {
795 if (!isVisible(aObj))
796 display(aObj, false);
801 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
803 if (!isVisible(theObject))
806 AISObjectPtr aAISObj = getAISObject(theObject);
807 if (aAISObj.get() == NULL)
810 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
811 return ::canBeShaded(anAIS);
814 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
815 const QIntList& theModes,
816 const bool theUpdateViewer) const
818 Handle(AIS_InteractiveContext) aContext = AISContext();
819 if (aContext.IsNull() || theIO.IsNull())
822 // deactivate object in all modes, which are not in the list of activation
823 // It seems that after the IO deactivation the selected state of the IO's owners
824 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
825 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
826 // only if there is a difference in the current modes and the parameters modes.
827 // If the selection problem happens again, it is possible to write a test scenario and create
828 // a bug. The bug steps are the following:
829 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
830 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
831 TColStd_ListOfInteger aTColModes;
832 aContext->ActivatedModes(theIO, aTColModes);
833 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
834 QIntList aModesActivatedForIO;
835 bool isDeactivated = false;
836 for (; itr.More(); itr.Next() ) {
837 Standard_Integer aMode = itr.Value();
838 if (!theModes.contains(aMode)) {
839 deactivateAIS(theIO, aMode);
840 isDeactivated = true;
843 aModesActivatedForIO.append(aMode);
847 // the selection from the previous activation modes should be cleared manually (#26172)
848 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
853 // loading the interactive object allowing the decomposition
854 if (aTColModes.IsEmpty()) {
855 aContext->Load(theIO, -1, true);
858 // trihedron AIS check should be after the AIS loading.
859 // If it is not loaded, it is steel selectable in the viewer.
860 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
861 if (aTrihedron.IsNull()) {
862 //aContext->Load(anAISIO, -1, true);
863 // In order to clear active modes list
864 if (theModes.size() == 0) {
865 //aContext->Load(anAISIO, 0, true);
866 activateAIS(theIO, 0, theUpdateViewer);
868 foreach(int aMode, theModes) {
869 //aContext->Load(anAISIO, aMode, true);
870 if (!aModesActivatedForIO.contains(aMode)) {
871 activateAIS(theIO, aMode, theUpdateViewer);
878 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
880 AISObjectPtr anAISObj = getAISObject(theObject);
881 // correct the result's color it it has the attribute
882 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
884 // Customization of presentation
885 GeomCustomPrsPtr aCustomPrs;
886 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
887 if (aFeature.get() != NULL) {
888 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
889 if (aCustPrs.get() != NULL)
890 aCustomPrs = aCustPrs;
892 if (aCustomPrs.get() == NULL) {
893 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
894 // we ignore presentable not customized objects
895 if (aPrs.get() == NULL)
896 aCustomPrs = myCustomPrs;
898 bool isCustomized = aCustomPrs.get() &&
899 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
900 myWorkshop->module()->customizeObject(theObject);
905 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
907 if (!isVisible(theObject))
910 AISObjectPtr anAISObj = getAISObject(theObject);
912 anAISObj->getColor(aR, aG, aB);
913 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
916 return QColor(aR, aG, aB);
919 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
921 myResult2AISObjectMap[theObject] = theAIS;
924 std::ostringstream aPtrStr;
925 aPtrStr << theObject.get();
926 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
927 qDebug(getResult2AISObjectMapInfo().c_str());
931 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
933 QStringList aContent;
934 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
935 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
936 std::ostringstream aPtrStr;
937 aPtrStr << "aObj = " << aObj.get() << ":";
938 aPtrStr << "anAIS = " << aAISObj.get() << ":";
939 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
941 aContent.append(aPtrStr.str().c_str());
943 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
944 arg(aContent.join("\n")).toStdString().c_str();