From: nds Date: Mon, 25 Apr 2016 05:17:10 +0000 (+0300) Subject: Issue #1440 Crash when edit box with parameter: erase custom presentation if it is... X-Git-Tag: V_2.3.0~119 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=855bb904d0114182e0b5b0ced0cb3a15d05a4408;p=modules%2Fshaper.git Issue #1440 Crash when edit box with parameter: erase custom presentation if it is empty --- diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index bf4a8b8d6..e5a52ac7e 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include #include @@ -26,8 +28,11 @@ //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) - : myWorkshop(theWorkshop), myFeature(FeaturePtr()) + : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false) { + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)); + initPresentation(ModuleBase_IModule::CustomizeArguments); initPresentation(ModuleBase_IModule::CustomizeResults); initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); @@ -106,7 +111,9 @@ bool PartSet_CustomPrs::displayPresentation( return isModified; } + myPresentationIsEmpty = false; // redisplay AIS objects + bool aRedisplayed = false; Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) { // when the feature can not be visualized in the module, the operation preview should not @@ -118,8 +125,8 @@ bool PartSet_CustomPrs::displayPresentation( PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); XGUI_Workshop* aWorkshop = workshop(); - aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/, - theUpdateViewer); + aRedisplayed = aWorkshop->displayer()->displayAIS(myPresentations[theFlag], + false/*load object in selection*/, false); aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); isModified = true; } @@ -128,25 +135,32 @@ bool PartSet_CustomPrs::displayPresentation( // when the feature can not be visualized in the module, the operation preview should not // be visualized also if (!anOperationPrs->hasShapes() || !myWorkshop->module()->canDisplayObject(myFeature)) { - erasePresentation(theFlag, theUpdateViewer); + aRedisplayed = erasePresentation(theFlag, false); isModified = true; } else { anOperationPrs->Redisplay(); isModified = true; - if (theUpdateViewer) - workshop()->displayer()->updateViewer(); + aRedisplayed = true; } } + if (myPresentationIsEmpty) { + aRedisplayed = erasePresentation(theFlag, false); + } + if (aRedisplayed && theUpdateViewer) + workshop()->displayer()->updateViewer(); + return isModified; } -void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, +bool PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, const bool theUpdateViewer) { + bool isErased = false; XGUI_Workshop* aWorkshop = workshop(); if (myPresentations.contains(theFlag)) - aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + isErased = aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + return isErased; } void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) @@ -202,6 +216,12 @@ void PartSet_CustomPrs::clearPrs() clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); } +void PartSet_CustomPrs::processEvent(const std::shared_ptr& theMessage) +{ + if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)) + myPresentationIsEmpty = true; /// store state to analize it after display/erase is finished +} + void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index 69393817f..ac99ab167 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -16,6 +16,8 @@ #include #include +#include + #include #include #include @@ -27,7 +29,7 @@ class XGUI_Workshop; * This is the module custom presentation, which manage an AIS presentation, that can be filled * by a feature and visualized in the viewer additionally to usual workshop objects. */ -class PartSet_CustomPrs +class PartSet_CustomPrs : public Events_Listener { public: /// Returns yellow color @@ -79,6 +81,9 @@ public: /// it caused erroneus case because the presentation has linkage to the previous context. void clearPrs(); + //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty + virtual void processEvent(const std::shared_ptr& theMessage); + private: /// Creates the AIS operation presentation /// \param theFlag an object AIS presentation type @@ -104,7 +109,8 @@ private: /// Erases the internal presentation from the viewer of workshop /// \param theFlag an object AIS presentation type /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly - void erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + /// \param returns whether the presentation is erased + bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, const bool theUpdateViewer); /// Nullify the operation presentation. For example, it can be useful when the viewer/context @@ -119,6 +125,7 @@ private: Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); private: + bool myPresentationIsEmpty; /// Boolean state about empty presentation FeaturePtr myFeature; /// Reference to a feature object ModuleBase_IWorkshop* myWorkshop; /// current workshop /// map of presentation type to AIS object diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index c7180c56c..7c0de6f90 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -124,9 +124,9 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t if (!aReadyToDisplay) { Events_Error::throwException("An empty AIS presentation: PartSet_OperationPrs"); - //std::shared_ptr aMsg = std::shared_ptr( - // new Events_Message(Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION))); - //Events_Loop::loop()->send(aMsg); + std::shared_ptr aMsg = std::shared_ptr( + new Events_Message(Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION))); + Events_Loop::loop()->send(aMsg); } } diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index cd9e9482c..0d417f819 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -94,7 +94,6 @@ void XGUI_WorkshopListener::initializeEventListening() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)); } //******************************************************