From 424c4d0d681755b6901d769e1e93c5d749174ba0 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 21 Apr 2016 16:56:34 +0300 Subject: [PATCH] #1423 Create Parameters problems --- src/PartSet/PartSet_CustomPrs.cpp | 48 +++++++++++++++++++------------ src/PartSet/PartSet_CustomPrs.h | 9 +++--- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 31c07ca07..bf4a8b8d6 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -84,7 +84,10 @@ bool PartSet_CustomPrs::displayPresentation( bool isModified = false; // update the AIS objects content - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag); + AISObjectPtr aPresentation = getPresentation(theFlag, true); + Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); + Handle(PartSet_OperationPrs) anOperationPrs = Handle(PartSet_OperationPrs)::DownCast(anAISIO); + // do nothing if the feature can not be displayed [is moved from presentation, to be checked] if (!myFeature.get()) return isModified; @@ -142,33 +145,40 @@ void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_C const bool theUpdateViewer) { XGUI_Workshop* aWorkshop = workshop(); - aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + if (myPresentations.contains(theFlag)) + aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); } void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag); - anOperationPrs->featureShapes().clear(); - if (!anOperationPrs.IsNull()) - anOperationPrs.Nullify(); - myPresentations[theFlag] = AISObjectPtr(); + AISObjectPtr aPresentation = getPresentation(theFlag, false); + if (aPresentation.get()) { + Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); + Handle(PartSet_OperationPrs) anOperationPrs = Handle(PartSet_OperationPrs)::DownCast(anAISIO); + + anOperationPrs->featureShapes().clear(); + if (!anOperationPrs.IsNull()) + anOperationPrs.Nullify(); + myPresentations.remove(theFlag); + } } -Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation( - const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) +AISObjectPtr PartSet_CustomPrs::getPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theToCreate) { Handle(PartSet_OperationPrs) aPresentation; - if (myPresentations.contains(theFlag)) { - AISObjectPtr anOperationPrs = myPresentations[theFlag]; - if (!anOperationPrs.get()) { - initPresentation(theFlag); - anOperationPrs = myPresentations[theFlag]; - } - Handle(AIS_InteractiveObject) anAISIO = anOperationPrs->impl(); - aPresentation = Handle(PartSet_OperationPrs)::DownCast(anAISIO); + AISObjectPtr anOperationPrs; + if (myPresentations.contains(theFlag)) + anOperationPrs = myPresentations[theFlag]; + + if (!anOperationPrs.get() && theToCreate) { + initPresentation(theFlag); + anOperationPrs = myPresentations[theFlag]; } - return aPresentation; + + return anOperationPrs; } bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, @@ -181,7 +191,7 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, bool aRedisplayed = false; if (myIsActive[theFlag]) aRedisplayed = displayPresentation(theFlag, theUpdateViewer); - + return aRedisplayed; } diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index da5c24773..69393817f 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -84,11 +84,12 @@ private: /// \param theFlag an object AIS presentation type void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); - /// Gets an AIS presentation by the flag + /// Gets an AIS presentation by the flag or create new if there is no a presentation by the flag /// \param theFlag an object AIS presentation type - /// \return the AIS prsentation - Handle(PartSet_OperationPrs) getPresentation( - const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); + /// \param theToCreate a flag if a new presentation should be created + /// \return wrap of AIS prsentation + AISObjectPtr getPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theToCreate); //! Returns workshop XGUI_Workshop* workshop() const; -- 2.39.2