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)
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 AIS_ListOfInteractive aPrsList;
360 ::displayedObjects(aContext, aPrsList);
362 Handle(AIS_Trihedron) aTrihedron;
363 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
364 Handle(AIS_InteractiveObject) anAISIO;
365 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
366 anAISIO = aLIt.Value();
367 activate(anAISIO, myActiveSelectionModes);
372 void XGUI_Displayer::deactivateObjects()
374 myActiveSelectionModes.clear();
375 Handle(AIS_InteractiveContext) aContext = AISContext();
376 // Open local context if there is no one
377 if (!aContext->HasOpenedContext())
380 //aContext->NotUseDisplayedObjects();
381 AIS_ListOfInteractive aPrsList;
382 ::displayedObjects(aContext, aPrsList);
384 AIS_ListIteratorOfListOfInteractive aLIt;
385 //Handle(AIS_Trihedron) aTrihedron;
386 Handle(AIS_InteractiveObject) anAISIO;
387 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
388 anAISIO = aLIt.Value();
389 aContext->Deactivate(anAISIO);
390 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
391 aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
397 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
399 Handle(AIS_InteractiveContext) aContext = AISContext();
400 if (aContext.IsNull())
402 if (!isVisible(theObject))
405 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
406 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
408 TColStd_ListOfInteger aModes;
409 aContext->ActivatedModes(anAIS, aModes);
410 return aModes.Extent() > 0;
413 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer)
415 Handle(AIS_InteractiveContext) aContext = AISContext();
416 if (aContext.IsNull())
418 if (aContext->HasOpenedContext()) {
419 aContext->UnhilightSelected();
420 aContext->ClearSelected();
421 //if (aSelected.size() > 0) {
422 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
423 const TopoDS_Shape& aShape = aPrs.shape();
424 if (!aShape.IsNull()) {
425 aContext->AddOrRemoveSelected(aShape, false);
427 ObjectPtr anObject = aPrs.object();
428 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
429 if (aResult.get() && isVisible(aResult)) {
430 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
431 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
432 if (!anAIS.IsNull()) {
433 // The methods are replaced in order to provide multi-selection, e.g. restore selection
434 // by activating multi selector widget. It also gives an advantage that the multi
435 // selection in OB gives multi-selection in the viewer
436 //aContext->SetSelected(anAIS, false);
437 // The selection in the context was cleared, so the method sets the objects are selected
438 aContext->AddOrRemoveSelected(anAIS, false);
444 aContext->UnhilightCurrents();
445 aContext->ClearCurrents();
446 foreach (ModuleBase_ViewerPrs aPrs, theValues) {
447 ObjectPtr anObject = aPrs.object();
448 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
449 if (aResult.get() && isVisible(aResult)) {
450 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
451 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
453 aContext->SetCurrentObject(anAIS, false);
461 void XGUI_Displayer::clearSelected()
463 Handle(AIS_InteractiveContext) aContext = AISContext();
465 aContext->UnhilightCurrents(false);
466 aContext->ClearSelected();
470 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
472 Handle(AIS_InteractiveContext) aContext = AISContext();
473 if (!aContext.IsNull()) {
474 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
475 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
477 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
478 if (!anIO.IsNull()) {
479 emit beforeObjectErase(aObj, aAISObj);
480 aContext->Remove(anIO, false);
486 myResult2AISObjectMap.clear();
489 void XGUI_Displayer::openLocalContext()
491 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
492 if (aContext.IsNull())
494 // Open local context if there is no one
495 if (!aContext->HasOpenedContext()) {
496 // Preserve selected objects
497 //AIS_ListOfInteractive aAisList;
498 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
499 // aAisList.Append(aContext->Current());
501 // get the filters from the global context and append them to the local context
502 // a list of filters in the global context is not cleared and should be cleared here
503 SelectMgr_ListOfFilter aFilters;
504 aFilters.Assign(aContext->Filters());
505 // it is important to remove the filters in the global context, because there is a code
506 // in the closeLocalContex, which restore the global context filters
507 aContext->RemoveFilters();
509 //aContext->ClearCurrents();
510 aContext->OpenLocalContext();
511 //aContext->NotUseDisplayedObjects();
513 //myUseExternalObjects = false;
515 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
516 for (;aIt.More(); aIt.Next()) {
517 aContext->AddFilter(aIt.Value());
520 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
521 //for(; aIt2.More(); aIt2.Next()) {
522 // aContext->SetSelected(aIt2.Value(), false);
527 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
529 Handle(AIS_InteractiveContext) aContext = AISContext();
530 if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
531 // Preserve selected objects
532 //AIS_ListOfInteractive aAisList;
533 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
534 // aAisList.Append(aContext->SelectedInteractive());
536 // get the filters from the local context and append them to the global context
537 // a list of filters in the local context is cleared
538 SelectMgr_ListOfFilter aFilters;
539 aFilters.Assign(aContext->Filters());
541 //aContext->ClearSelected();
542 aContext->CloseAllContexts(false);
544 // Redisplay all object if they were displayed in localContext
545 Handle(AIS_InteractiveObject) aAISIO;
546 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
547 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
548 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
549 aContext->Display(aAISIO, false);
550 aContext->SetDisplayMode(aAISIO, Shading, false);
554 // Append the filters from the local selection in the global selection context
555 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
556 for (;aIt.More(); aIt.Next()) {
557 Handle(SelectMgr_Filter) aFilter = aIt.Value();
558 aContext->AddFilter(aFilter);
563 //myUseExternalObjects = false;
566 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
567 //for(; aIt2.More(); aIt2.Next()) {
568 // if (aContext->IsDisplayed(aIt2.Value()))
569 // aContext->SetCurrentObject(aIt2.Value(), false);
574 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
577 if (myResult2AISObjectMap.contains(theObject))
578 anIO = myResult2AISObjectMap[theObject];
582 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
584 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
585 return getObject(aRefAIS);
588 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
591 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
592 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
593 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
600 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
602 bool aWasEnabled = myEnableUpdateViewer;
604 myEnableUpdateViewer = isEnabled;
609 void XGUI_Displayer::updateViewer() const
611 Handle(AIS_InteractiveContext) aContext = AISContext();
612 if (!aContext.IsNull() && myEnableUpdateViewer)
613 aContext->UpdateCurrentViewer();
616 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
618 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
619 if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
620 aContext->OpenLocalContext();
625 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
627 Handle(AIS_InteractiveContext) aContext = AISContext();
628 if (myAndFilter.IsNull() && !aContext.IsNull()) {
629 myAndFilter = new SelectMgr_AndFilter();
630 aContext->AddFilter(myAndFilter);
635 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
637 Handle(AIS_InteractiveContext) aContext = AISContext();
638 if (aContext.IsNull())
640 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
641 if (!anAISIO.IsNull()) {
642 aContext->Display(anAISIO, isUpdate);
643 if (aContext->HasOpenedContext()) {
644 //if (myUseExternalObjects) {
645 if (myActiveSelectionModes.size() == 0)
646 aContext->Activate(anAISIO);
648 foreach(int aMode, myActiveSelectionModes) {
649 aContext->Activate(anAISIO, aMode);
657 void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
659 Handle(AIS_InteractiveContext) aContext = AISContext();
660 if (aContext.IsNull())
662 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
663 if (!anAISIO.IsNull()) {
664 aContext->Remove(anAISIO, isUpdate);
669 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
671 if (theMode == NoMode)
674 Handle(AIS_InteractiveContext) aContext = AISContext();
675 if (aContext.IsNull())
678 AISObjectPtr aAISObj = getAISObject(theObject);
682 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
683 bool aCanBeShaded = ::canBeShaded(aAISIO);
684 // In order to avoid extra closing/opening context
685 SelectMgr_IndexedMapOfOwner aSelectedOwners;
687 myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
688 closeLocalContexts(false);
690 aContext->SetDisplayMode(aAISIO, theMode, false);
691 // Redisplay in order to update new mode because it could be not computed before
692 aContext->Redisplay(aAISIO, false);
695 activateObjects(myActiveSelectionModes);
696 myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
702 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
704 Handle(AIS_InteractiveContext) aContext = AISContext();
705 if (aContext.IsNull())
708 AISObjectPtr aAISObj = getAISObject(theObject);
712 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
713 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
716 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
718 Handle(AIS_InteractiveContext) aContext = AISContext();
719 if (aContext.IsNull())
721 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
722 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
723 for (; aIt.More(); aIt.Next()) {
724 if (theFilter.Access() == aIt.Value().Access())
727 Handle(SelectMgr_CompositionFilter) aCompFilter = GetFilter();
728 const SelectMgr_ListOfFilter& aStoredFilters = aCompFilter->StoredFilters();
729 for (aIt.Initialize(aStoredFilters); aIt.More(); aIt.Next()) {
730 if (theFilter.Access() == aIt.Value().Access())
733 aCompFilter->Add(theFilter);
734 #ifdef DEBUG_SELECTION_FILTERS
735 int aCount = GetFilter()->StoredFilters().Extent();
736 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
740 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
742 Handle(AIS_InteractiveContext) aContext = AISContext();
743 if (aContext.IsNull())
745 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
746 if (aCompositeFilter->IsIn(theFilter))
747 aCompositeFilter->Remove(theFilter);
748 #ifdef DEBUG_SELECTION_FILTERS
749 int aCount = GetFilter()->StoredFilters().Extent();
750 qDebug(QString("removeSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
754 void XGUI_Displayer::removeFilters()
756 Handle(AIS_InteractiveContext) aContext = AISContext();
757 if (aContext.IsNull())
759 GetFilter()->Clear();
762 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
764 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
765 foreach(ObjectPtr aObj, aDispList) {
766 if (!theList.contains(aObj))
769 foreach(ObjectPtr aObj, theList) {
770 if (!isVisible(aObj))
771 display(aObj, false);
776 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
778 if (!isVisible(theObject))
781 AISObjectPtr aAISObj = getAISObject(theObject);
782 if (aAISObj.get() == NULL)
785 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
786 return ::canBeShaded(anAIS);
789 void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
790 const QIntList& theModes) const
792 Handle(AIS_InteractiveContext) aContext = AISContext();
793 if (aContext.IsNull() || theIO.IsNull())
796 // deactivate object in all modes, which are not in the list of activation
797 // It seems that after the IO deactivation the selected state of the IO's owners
798 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
799 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
800 // only if there is a difference in the current modes and the parameters modes.
801 // If the selection problem happens again, it is possible to write a test scenario and create
802 // a bug. The bug steps are the following:
803 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
804 // with clicked SHIFT select the second object. The result is the selection of the first IO is lost.
805 TColStd_ListOfInteger aTColModes;
806 aContext->ActivatedModes(theIO, aTColModes);
807 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
808 QIntList aModesActivatedForIO;
809 //bool isDeactivated = false;
810 for (; itr.More(); itr.Next() ) {
811 Standard_Integer aMode = itr.Value();
812 if (!theModes.contains(aMode)) {
813 #ifdef DEBUG_ACTIVATE
814 qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
816 aContext->Deactivate(theIO, aMode);
817 //isDeactivated = true;
820 aModesActivatedForIO.append(aMode);
821 #ifdef DEBUG_ACTIVATE
822 qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
826 #ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
828 aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
832 // loading the interactive object allowing the decomposition
833 if (aTColModes.IsEmpty())
834 aContext->Load(theIO, -1, true);
836 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
837 //Deactivate trihedron which can be activated in local selector
838 if (aTrihedron.IsNull()) {
839 //aContext->Load(anAISIO, -1, true);
840 // In order to clear active modes list
841 if (theModes.size() == 0) {
842 //aContext->Load(anAISIO, 0, true);
843 aContext->Activate(theIO);
844 #ifdef DEBUG_ACTIVATE
845 qDebug("activate in all modes");
848 foreach(int aMode, theModes) {
849 //aContext->Load(anAISIO, aMode, true);
850 if (!aModesActivatedForIO.contains(aMode)) {
851 aContext->Activate(theIO, aMode);
852 #ifdef DEBUG_ACTIVATE
853 qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
861 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
863 AISObjectPtr anAISObj = getAISObject(theObject);
864 // correct the result's color it it has the attribute
865 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
867 // Customization of presentation
868 GeomCustomPrsPtr aCustomPrs;
869 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
870 if (aFeature.get() != NULL) {
871 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
872 if (aCustPrs.get() != NULL)
873 aCustomPrs = aCustPrs;
875 if (aCustomPrs.get() == NULL) {
876 // we ignore presentable not customized objects
877 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
878 if (aPrs.get() != NULL)
880 aCustomPrs = myCustomPrs;
882 return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
886 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
888 if (!isVisible(theObject))
891 AISObjectPtr anAISObj = getAISObject(theObject);
893 anAISObj->getColor(aR, aG, aB);
894 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
897 return QColor(aR, aG, aB);
900 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
902 myResult2AISObjectMap[theObject] = theAIS;
905 std::ostringstream aPtrStr;
906 aPtrStr << theObject.get();
907 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
908 qDebug(getResult2AISObjectMapInfo().c_str());
912 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
914 QStringList aContent;
915 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
916 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
917 std::ostringstream aPtrStr;
918 aPtrStr << "aObj = " << aObj.get() << ":";
919 aPtrStr << "anAIS = " << aAISObj.get() << ":";
920 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
922 aContent.append(aPtrStr.str().c_str());
924 return QString("myResult2AISObjectMap: size = %1\n%2").arg(myResult2AISObjectMap.size()).
925 arg(aContent.join("\n")).toStdString().c_str();