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>
21 #include <ModelAPI_ResultCompSolid.h>
23 #include <ModuleBase_ResultPrs.h>
24 #include <ModuleBase_Tools.h>
25 #include <ModuleBase_IModule.h>
27 #include <GeomAPI_Shape.h>
28 #include <GeomAPI_IPresentable.h>
29 #include <GeomAPI_ICustomPrs.h>
31 #include <AIS_InteractiveContext.hxx>
32 #include <AIS_LocalContext.hxx>
33 #include <AIS_ListOfInteractive.hxx>
34 #include <AIS_ListIteratorOfListOfInteractive.hxx>
35 #include <AIS_DimensionSelectionMode.hxx>
36 #include <AIS_Shape.hxx>
37 #include <AIS_Dimension.hxx>
38 #include <TColStd_ListIteratorOfListOfInteger.hxx>
39 #include <SelectMgr_ListOfFilter.hxx>
40 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
41 #include <Prs3d_Drawer.hxx>
42 #include <Prs3d_IsoAspect.hxx>
44 #include <StdSelect_ViewerSelector3d.hxx>
46 #include <TColStd_MapOfTransient.hxx>
47 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
51 const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
53 //#define DEBUG_ACTIVATE_OBJECTS
54 //#define DEBUG_DEACTIVATE
55 //#define DEBUG_ACTIVATE_AIS
56 //#define DEBUG_DEACTIVATE_AIS
58 //#define DEBUG_DISPLAY
59 //#define DEBUG_FEATURE_REDISPLAY
60 //#define DEBUG_SELECTION_FILTERS
62 //#define DEBUG_COMPOSILID_DISPLAY
63 // Workaround for bug #25637
64 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
66 // Get from null point
67 theAIS->DisplayedObjects(theList, true);
68 if (theAIS->HasOpenedContext()) {
69 // get from local context
70 const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
71 TColStd_MapOfTransient aMap;
72 int NbDisp = aLC->DisplayedObjects(aMap);
73 TColStd_MapIteratorOfMapOfTransient aIt(aMap);
75 Handle(AIS_InteractiveObject) curIO;
76 Handle(Standard_Transient) Tr;
77 for(; aIt.More(); aIt.Next()){
79 curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
80 theList.Append(curIO);
85 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
88 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
89 for (; anIt != aLast; anIt++) {
90 anInfo.append(QString::number(*anIt));
92 return anInfo.join(theSeparator);
95 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
96 : myWorkshop(theWorkshop)
98 enableUpdateViewer(true);
99 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
102 XGUI_Displayer::~XGUI_Displayer()
106 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
108 return myResult2AISObjectMap.contains(theObject);
111 void XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
113 if (isVisible(theObject)) {
114 #ifdef DEBUG_COMPOSILID_DISPLAY
115 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
116 if (aCompsolidResult.get()) {
117 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
118 ResultPtr aSubResult = aCompsolidResult->subResult(i);
119 if (aSubResult.get())
120 redisplay(aSubResult, false);
127 redisplay(theObject, theUpdateViewer);
131 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
132 bool isShading = false;
133 if (aPrs.get() != NULL) {
134 anAIS = aPrs->getAISObject(anAIS);
136 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
137 if (aResult.get() != NULL) {
138 #ifdef DEBUG_COMPOSILID_DISPLAY
139 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
140 if (aCompsolidResult.get()) {
141 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
142 ResultPtr aSubResult = aCompsolidResult->subResult(i);
143 if (aSubResult.get())
144 display(aSubResult, false);
151 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
152 if (aShapePtr.get() != NULL) {
153 anAIS = AISObjectPtr(new GeomAPI_AISObject());
154 anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
155 //anAIS->createShape(aShapePtr);
158 #ifdef DEBUG_COMPOSILID_DISPLAY
164 display(theObject, anAIS, isShading, theUpdateViewer);
168 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
170 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
171 if (!aShapePrs.IsNull()) {
172 TopoDS_Shape aShape = aShapePrs->Shape();
173 TopAbs_ShapeEnum aType = aShape.ShapeType();
174 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
177 // Check that the presentation is not a sketch
178 Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
180 return !aPrs->isSketchMode();
187 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
188 bool isShading, bool theUpdateViewer)
190 Handle(AIS_InteractiveContext) aContext = AISContext();
191 if (aContext.IsNull())
194 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
195 if (!anAISIO.IsNull()) {
196 appendResultObject(theObject, theAIS);
198 bool isCustomized = customizeObject(theObject);
200 int aDispMode = isShading? Shading : Wireframe;
202 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
203 anAISIO->SetDisplayMode(aDispMode);
204 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
206 emit objectDisplayed(theObject, theAIS);
207 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
213 void XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
215 if (!isVisible(theObject))
218 Handle(AIS_InteractiveContext) aContext = AISContext();
219 if (aContext.IsNull())
221 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
223 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
224 if (!anAIS.IsNull()) {
225 emit beforeObjectErase(theObject, anObject);
226 aContext->Remove(anAIS, theUpdateViewer);
229 myResult2AISObjectMap.remove(theObject);
232 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
234 if (!isVisible(theObject))
237 AISObjectPtr aAISObj = getAISObject(theObject);
238 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
240 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
242 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
244 erase(theObject, theUpdateViewer);
247 if (aAIS_Obj != aAISObj) {
248 appendResultObject(theObject, aAIS_Obj);
250 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
253 if (!aAISIO.IsNull()) {
254 Handle(AIS_InteractiveContext) aContext = AISContext();
255 if (aContext.IsNull())
257 // Check that the visualized shape is the same and the redisplay is not necessary
258 // Redisplay of AIS object leads to this object selection compute and the selection
259 // in the browser is lost
261 // this check is not necessary anymore because the selection store/restore is realized
262 // before and after the values modification.
263 // Moreother, this check avoids customize and redisplay presentation if the presentable
264 // parameter is changed.
265 bool isEqualShapes = false;
266 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
267 if (aResult.get() != NULL) {
268 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
269 if (!aShapePrs.IsNull()) {
270 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
271 if (aShapePtr.get()) {
272 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
273 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
277 // Customization of presentation
278 bool isCustomized = customizeObject(theObject);
279 #ifdef DEBUG_FEATURE_REDISPLAY
280 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
281 arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str());
283 if (!isEqualShapes || isCustomized) {
284 aContext->Redisplay(aAISIO, false);
285 #ifdef DEBUG_FEATURE_REDISPLAY
286 qDebug(" Redisplay happens");
294 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
296 #ifdef DEBUG_DEACTIVATE
297 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
298 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
299 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
301 toStdString().c_str());
303 if (isVisible(theObject)) {
304 Handle(AIS_InteractiveContext) aContext = AISContext();
305 if (aContext.IsNull())
308 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
309 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
311 deactivateAIS(anAIS);
312 // the selection from the previous activation modes should be cleared manually (#26172)
313 aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
319 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
321 if (!isVisible(theObject))
324 Handle(AIS_InteractiveContext) aContext = AISContext();
325 if (aContext.IsNull())
328 AISObjectPtr aAISObj = getAISObject(theObject);
330 if (aAISObj.get() != NULL) {
331 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
332 TColStd_ListOfInteger aTColModes;
333 aContext->ActivatedModes(anAISIO, aTColModes);
334 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
335 for (; itr.More(); itr.Next() ) {
336 theModes.append(itr.Value());
341 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
342 const bool theUpdateViewer)
344 // Convert shape types to selection types
346 foreach(int aType, theModes) {
347 if (aType > TopAbs_SHAPE)
348 aModes.append(aType);
350 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
353 #ifdef DEBUG_ACTIVATE_OBJECTS
355 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
356 for (; anIt != aLast; ++anIt) {
357 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
359 QString anInfoStr = anInfo.join(", ");
361 qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
362 arg(aModes.size()).arg(qIntListInfo(aModes)).
363 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
365 toStdString().c_str());
367 // In order to avoid doblications of selection modes
369 foreach (int aMode, aModes) {
370 if (!aNewModes.contains(aMode))
371 aNewModes.append(aMode);
373 myActiveSelectionModes = aNewModes;
374 Handle(AIS_InteractiveContext) aContext = AISContext();
375 if (aContext.IsNull())
377 // Open local context if there is no one
378 if (!aContext->HasOpenedContext())
381 //aContext->UseDisplayedObjects();
382 //myUseExternalObjects = true;
384 Handle(AIS_InteractiveObject) anAISIO;
385 AIS_ListOfInteractive aPrsList;
386 if (theObjList.isEmpty())
389 foreach(ObjectPtr aObj, theObjList) {
390 if (myResult2AISObjectMap.contains(aObj))
391 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
395 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
396 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
397 anAISIO = aLIt.Value();
398 activate(anAISIO, myActiveSelectionModes, false);
404 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
406 Handle(AIS_InteractiveContext) aContext = AISContext();
407 if (aContext.IsNull())
409 if (!isVisible(theObject))
412 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
413 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
415 TColStd_ListOfInteger aModes;
416 aContext->ActivatedModes(anAIS, aModes);
417 return aModes.Extent() > 0;
419 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer)
421 Handle(AIS_InteractiveContext) aContext = AISContext();
422 if (aContext.IsNull())
424 if (aContext->HasOpenedContext()) {
425 aContext->UnhilightSelected();
426 aContext->ClearSelected();
427 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
428 const TopoDS_Shape& aShape = aPrs.shape();
429 if (!aShape.IsNull()) {
430 aContext->AddOrRemoveSelected(aShape, false);
432 ObjectPtr anObject = aPrs.object();
433 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
434 if (aResult.get() && isVisible(aResult)) {
435 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
436 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
437 if (!anAIS.IsNull()) {
438 // The methods are replaced in order to provide multi-selection, e.g. restore selection
439 // by activating multi selector widget. It also gives an advantage that the multi
440 // selection in OB gives multi-selection in the viewer
441 //aContext->SetSelected(anAIS, false);
442 // The selection in the context was cleared, so the method sets the objects are selected
443 aContext->AddOrRemoveSelected(anAIS, false);
449 aContext->UnhilightCurrents();
450 aContext->ClearCurrents();
451 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
452 ObjectPtr anObject = aPrs.object();
453 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
454 if (aResult.get() && isVisible(aResult)) {
455 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
456 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
458 aContext->SetCurrentObject(anAIS, false);
466 void XGUI_Displayer::clearSelected()
468 Handle(AIS_InteractiveContext) aContext = AISContext();
470 aContext->UnhilightCurrents(false);
471 aContext->ClearSelected();
475 void XGUI_Displayer::eraseAll(const bool theUpdateViewer)
477 Handle(AIS_InteractiveContext) aContext = AISContext();
478 if (!aContext.IsNull()) {
479 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
480 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
482 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
483 if (!anIO.IsNull()) {
484 emit beforeObjectErase(aObj, aAISObj);
485 aContext->Remove(anIO, false);
491 myResult2AISObjectMap.clear();
494 void XGUI_Displayer::deactivateTrihedron() const
496 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
498 AIS_ListOfInteractive aList;
499 aContext->DisplayedObjects(aList, true);
500 AIS_ListIteratorOfListOfInteractive aIt;
501 for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
502 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
503 if (!aTrihedron.IsNull()) {
504 aContext->Deactivate(aTrihedron);
509 void XGUI_Displayer::openLocalContext()
511 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
512 if (aContext.IsNull())
514 // Open local context if there is no one
515 if (!aContext->HasOpenedContext()) {
516 // Preserve selected objects
517 //AIS_ListOfInteractive aAisList;
518 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
519 // aAisList.Append(aContext->Current());
521 // get the filters from the global context and append them to the local context
522 // a list of filters in the global context is not cleared and should be cleared here
523 SelectMgr_ListOfFilter aFilters;
524 aFilters.Assign(aContext->Filters());
525 // it is important to remove the filters in the global context, because there is a code
526 // in the closeLocalContex, which restore the global context filters
527 aContext->RemoveFilters();
529 //aContext->ClearCurrents();
530 aContext->OpenLocalContext();
531 deactivateTrihedron();
532 //aContext->NotUseDisplayedObjects();
534 //myUseExternalObjects = false;
536 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
537 for (;aIt.More(); aIt.Next()) {
538 aContext->AddFilter(aIt.Value());
541 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
542 //for(; aIt2.More(); aIt2.Next()) {
543 // aContext->SetSelected(aIt2.Value(), false);
548 void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
550 Handle(AIS_InteractiveContext) aContext = AISContext();
551 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
552 // Preserve selected objects
553 //AIS_ListOfInteractive aAisList;
554 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
555 // aAisList.Append(aContext->SelectedInteractive());
557 // get the filters from the local context and append them to the global context
558 // a list of filters in the local context is cleared
559 SelectMgr_ListOfFilter aFilters;
560 aFilters.Assign(aContext->Filters());
562 //aContext->ClearSelected();
563 aContext->CloseAllContexts(false);
565 // Redisplay all object if they were displayed in localContext
566 Handle(AIS_InteractiveObject) aAISIO;
567 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
568 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
569 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
570 aContext->Display(aAISIO, false);
571 aContext->SetDisplayMode(aAISIO, Shading, false);
575 // Append the filters from the local selection in the global selection context
576 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
577 for (;aIt.More(); aIt.Next()) {
578 Handle(SelectMgr_Filter) aFilter = aIt.Value();
579 aContext->AddFilter(aFilter);
584 //myUseExternalObjects = false;
587 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
588 //for(; aIt2.More(); aIt2.Next()) {
589 // if (aContext->IsDisplayed(aIt2.Value()))
590 // aContext->SetCurrentObject(aIt2.Value(), false);
595 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
598 if (myResult2AISObjectMap.contains(theObject))
599 anIO = myResult2AISObjectMap[theObject];
603 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
605 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
606 return getObject(aRefAIS);
609 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
612 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
613 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
614 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
620 if (!anObject.get()) {
621 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
622 if (!theIO.IsNull()) {
623 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
625 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
630 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
632 bool aWasEnabled = myEnableUpdateViewer;
634 myEnableUpdateViewer = isEnabled;
639 void XGUI_Displayer::updateViewer() const
641 Handle(AIS_InteractiveContext) aContext = AISContext();
642 if (!aContext.IsNull() && myEnableUpdateViewer) {
643 myWorkshop->viewer()->Zfitall();
644 aContext->UpdateCurrentViewer();
648 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
649 const int theMode, const bool theUpdateViewer) const
651 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
652 aContext->Activate(theIO, theMode, theUpdateViewer);
654 #ifdef DEBUG_ACTIVATE_AIS
655 ObjectPtr anObject = getObject(theIO);
656 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
657 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
661 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
663 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
665 aContext->Deactivate(theIO);
667 aContext->Deactivate(theIO, theMode);
669 #ifdef DEBUG_DEACTIVATE_AIS
670 ObjectPtr anObject = getObject(theIO);
671 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
672 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
676 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
678 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
679 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
680 aContext->OpenLocalContext();
681 deactivateTrihedron();
682 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
683 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
688 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
690 Handle(AIS_InteractiveContext) aContext = AISContext();
691 if (myAndFilter.IsNull() && !aContext.IsNull()) {
692 myAndFilter = new SelectMgr_AndFilter();
693 aContext->AddFilter(myAndFilter);
698 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer)
700 Handle(AIS_InteractiveContext) aContext = AISContext();
701 if (aContext.IsNull())
703 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
704 if (!anAISIO.IsNull()) {
705 aContext->Display(anAISIO, theUpdateViewer);
706 if (aContext->HasOpenedContext()) {
707 if (myActiveSelectionModes.size() == 0)
708 activateAIS(anAISIO, 0, theUpdateViewer);
710 foreach(int aMode, myActiveSelectionModes) {
711 activateAIS(anAISIO, aMode, theUpdateViewer);
718 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
720 Handle(AIS_InteractiveContext) aContext = AISContext();
721 if (aContext.IsNull())
723 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
724 if (!anAISIO.IsNull()) {
725 aContext->Remove(anAISIO, theUpdateViewer);
730 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
732 if (theMode == NoMode)
735 Handle(AIS_InteractiveContext) aContext = AISContext();
736 if (aContext.IsNull())
739 AISObjectPtr aAISObj = getAISObject(theObject);
743 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
744 aContext->SetDisplayMode(aAISIO, theMode, false);
745 // Redisplay in order to update new mode because it could be not computed before
750 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
752 Handle(AIS_InteractiveContext) aContext = AISContext();
753 if (aContext.IsNull())
756 AISObjectPtr aAISObj = getAISObject(theObject);
760 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
761 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
764 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
766 Handle(AIS_InteractiveContext) aContext = AISContext();
767 if (aContext.IsNull() || hasSelectionFilter(theFilter))
770 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
771 aCompFilter->Add(theFilter);
772 #ifdef DEBUG_SELECTION_FILTERS
773 int aCount = GetFilter()->StoredFilters().Extent();
774 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
778 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
780 Handle(AIS_InteractiveContext) aContext = AISContext();
781 if (aContext.IsNull())
783 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
784 if (aCompositeFilter->IsIn(theFilter))
785 aCompositeFilter->Remove(theFilter);
786 #ifdef DEBUG_SELECTION_FILTERS
787 int aCount = GetFilter()->StoredFilters().Extent();
788 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
792 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
794 bool aFilterFound = false;
796 Handle(AIS_InteractiveContext) aContext = AISContext();
797 if (aContext.IsNull())
799 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
800 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
801 for (; aIt.More() && !aFilterFound; aIt.Next()) {
802 if (theFilter.Access() == aIt.Value().Access())
805 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
806 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
807 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
808 if (theFilter.Access() == aIt.Value().Access())
814 void XGUI_Displayer::removeFilters()
816 Handle(AIS_InteractiveContext) aContext = AISContext();
817 if (aContext.IsNull())
819 GetFilter()->Clear();
822 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
824 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
825 foreach(ObjectPtr aObj, aDispList) {
826 if (!theList.contains(aObj))
829 foreach(ObjectPtr aObj, theList) {
830 if (!isVisible(aObj))
831 display(aObj, false);
836 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
838 if (!isVisible(theObject))
841 AISObjectPtr aAISObj = getAISObject(theObject);
842 if (aAISObj.get() == NULL)
845 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
846 return ::canBeShaded(anAIS);
849 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
850 const QIntList& theModes,
851 const bool theUpdateViewer) const
853 Handle(AIS_InteractiveContext) aContext = AISContext();
854 if (aContext.IsNull() || theIO.IsNull())
857 // deactivate object in all modes, which are not in the list of activation
858 // It seems that after the IO deactivation the selected state of the IO's owners
859 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
860 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
861 // only if there is a difference in the current modes and the parameters modes.
862 // If the selection problem happens again, it is possible to write a test scenario and create
863 // a bug. The bug steps are the following:
864 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
865 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
866 TColStd_ListOfInteger aTColModes;
867 aContext->ActivatedModes(theIO, aTColModes);
868 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
869 QIntList aModesActivatedForIO;
870 bool isDeactivated = false;
871 for (; itr.More(); itr.Next() ) {
872 Standard_Integer aMode = itr.Value();
873 if (!theModes.contains(aMode)) {
874 deactivateAIS(theIO, aMode);
875 isDeactivated = true;
878 aModesActivatedForIO.append(aMode);
882 // the selection from the previous activation modes should be cleared manually (#26172)
883 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
888 // loading the interactive object allowing the decomposition
889 if (aTColModes.IsEmpty()) {
890 aContext->Load(theIO, -1, true);
893 // trihedron AIS check should be after the AIS loading.
894 // If it is not loaded, it is steel selectable in the viewer.
895 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
896 if (aTrihedron.IsNull()) {
897 //aContext->Load(anAISIO, -1, true);
898 // In order to clear active modes list
899 if (theModes.size() == 0) {
900 //aContext->Load(anAISIO, 0, true);
901 activateAIS(theIO, 0, theUpdateViewer);
903 foreach(int aMode, theModes) {
904 //aContext->Load(anAISIO, aMode, true);
905 if (!aModesActivatedForIO.contains(aMode)) {
906 activateAIS(theIO, aMode, theUpdateViewer);
913 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
915 AISObjectPtr anAISObj = getAISObject(theObject);
916 // correct the result's color it it has the attribute
917 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
919 // Customization of presentation
920 GeomCustomPrsPtr aCustomPrs;
921 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
922 if (aFeature.get() != NULL) {
923 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
924 if (aCustPrs.get() != NULL)
925 aCustomPrs = aCustPrs;
927 if (aCustomPrs.get() == NULL) {
928 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
929 // we ignore presentable not customized objects
930 if (aPrs.get() == NULL)
931 aCustomPrs = myCustomPrs;
933 bool isCustomized = aCustomPrs.get() &&
934 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
935 myWorkshop->module()->customizeObject(theObject);
940 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
942 if (!isVisible(theObject))
945 AISObjectPtr anAISObj = getAISObject(theObject);
947 anAISObj->getColor(aR, aG, aB);
948 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
951 return QColor(aR, aG, aB);
954 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
956 myResult2AISObjectMap[theObject] = theAIS;
959 std::ostringstream aPtrStr;
960 aPtrStr << theObject.get();
961 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
962 qDebug(getResult2AISObjectMapInfo().c_str());
966 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
968 QStringList aContent;
969 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
970 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
971 std::ostringstream aPtrStr;
972 aPtrStr << "aObj = " << aObj.get() << ":";
973 aPtrStr << "anAIS = " << aAISObj.get() << ":";
974 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
976 aContent.append(aPtrStr.str().c_str());
978 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
979 arg(aContent.join("\n")).toStdString().c_str();