XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
: myWorkshop(theWorkshop)
{
+ enableUpdateViewer(true);
}
XGUI_Displayer::~XGUI_Displayer()
TopAbs_ShapeEnum aType = aShape.ShapeType();
if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
return false;
- else
+ else {
+ // Check that the presentation is not a sketch
+ Handle(ModuleBase_ResultPrs) aPrs = Handle(ModuleBase_ResultPrs)::DownCast(theAIS);
+ if (!aPrs.IsNull())
+ return !aPrs->isSketchMode();
return true;
+ }
}
return false;
}
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
if (!anAISIO.IsNull()) {
myResult2AISObjectMap[theObject] = theAIS;
- bool aCanBeShaded = canBeShaded(anAISIO);
+ bool aCanBeShaded = ::canBeShaded(anAISIO);
// In order to avoid extra closing/opening context
SelectMgr_IndexedMapOfOwner aSelectedOwners;
if (aCanBeShaded) {
if (aCanBeShaded) {
openLocalContext();
activateObjects(myActiveSelectionModes);
- myWorkshop->selector()->setSelectedOwners(aSelectedOwners);
+ myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
}
}
if (isUpdateViewer)
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
- bool aToSelect = aContext->IsSelected(aAISIO);
+ // Check that the visualized shape is the same and the redisplay is not necessary
+ // Redisplay of AIS object leads to this object selection compute and the selection
+ // in the browser is lost
+ // become
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aResult.get() != NULL) {
+ Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
+ if (!aShapePrs.IsNull()) {
+ std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
+ const TopoDS_Shape& aShape = aShapePrs->Shape();
+ std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
+ anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
+
+ if (aShapePtr->isEqual(anAISShapePtr))
+ return;
+ }
+ }
aContext->Redisplay(aAISIO, false);
- // Restore selection state after redisplay
- if (aToSelect)
- aContext->SetSelected(aAISIO);
if (isUpdateViewer)
updateViewer();
}
//myUseExternalObjects = true;
AIS_ListOfInteractive aPrsList;
- displayedObjects(aContext, aPrsList);
+ ::displayedObjects(aContext, aPrsList);
Handle(AIS_Trihedron) aTrihedron;
AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
//aContext->NotUseDisplayedObjects();
AIS_ListOfInteractive aPrsList;
- displayedObjects(aContext, aPrsList);
+ ::displayedObjects(aContext, aPrsList);
AIS_ListIteratorOfListOfInteractive aLIt;
//Handle(AIS_Trihedron) aTrihedron;
void XGUI_Displayer::openLocalContext()
{
- Handle(AIS_InteractiveContext) aContext = AISContext();
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (aContext.IsNull())
return;
// Open local context if there is no one
return aFeature;
}
+bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
+{
+ bool aWasEnabled = myEnableUpdateViewer;
+
+ myEnableUpdateViewer = isEnabled;
+
+ return aWasEnabled;
+}
+
void XGUI_Displayer::updateViewer()
{
Handle(AIS_InteractiveContext) aContext = AISContext();
- if (!aContext.IsNull())
+ if (!aContext.IsNull() && myEnableUpdateViewer)
aContext->UpdateCurrentViewer();
}
return;
Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
- aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
+ bool aCanBeShaded = ::canBeShaded(aAISIO);
+ // In order to avoid extra closing/opening context
+ SelectMgr_IndexedMapOfOwner aSelectedOwners;
+ if (aCanBeShaded) {
+ myWorkshop->selector()->selection()->selectedOwners(aSelectedOwners);
+ closeLocalContexts(false);
+ }
+ aContext->SetDisplayMode(aAISIO, theMode, false);
+ if (aCanBeShaded) {
+ openLocalContext();
+ activateObjects(myActiveSelectionModes);
+ myWorkshop->selector()->setSelectedOwners(aSelectedOwners, false);
+ }
+ if (toUpdate)
+ updateViewer();
}
XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
}
updateViewer();
}
+
+bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
+{
+ if (!isVisible(theObject))
+ return false;
+
+ AISObjectPtr aAISObj = getAISObject(theObject);
+ if (aAISObj.get() == NULL)
+ return false;
+
+ Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+ return ::canBeShaded(anAIS);
+}