From 58ed04fa9426f8dd99fcf76a1f3ef9e60c5f3b9b Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 30 May 2016 09:17:29 +0300 Subject: [PATCH] Issue #1505 Bug in parameters management (with parts not loaded) --- src/ModelAPI/ModelAPI_Tools.cpp | 21 ++++++++++++++ src/ModelAPI/ModelAPI_Tools.h | 7 +++++ src/ModuleBase/ModuleBase_ModelWidget.cpp | 13 +++++---- src/ModuleBase/ModuleBase_ModelWidget.h | 3 ++ .../ParametersPlugin_EvalListener.cpp | 29 ++++--------------- src/XGUI/XGUI_PropertyPanel.cpp | 1 + src/XGUI/XGUI_Tools.cpp | 27 +++-------------- src/XGUI/XGUI_Tools.h | 7 ----- 8 files changed, 49 insertions(+), 59 deletions(-) diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 658def2ef..1270db2ec 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -358,6 +358,27 @@ void allResults(const FeaturePtr& theFeature, std::list& theResults) } } +//****************************************************************** +bool allDocumentsActivated(std::string& theNotActivatedNames) +{ + theNotActivatedNames = ""; + bool anAllPartActivated = true; + + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); + for (int i = 0; i < aSize; i++) { + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i); + ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); + if (!aPart->isActivated()) { + anAllPartActivated = false; + if (!theNotActivatedNames.empty()) + theNotActivatedNames += ", "; + theNotActivatedNames += aObject->data()->name().c_str(); + } + } + return anAllPartActivated; +} + bool removeFeaturesAndReferences(const std::set& theFeatures, const bool theFlushRedisplay, const bool theUseComposite, diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 9085e6d77..00f6cd4fd 100755 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -100,6 +100,13 @@ MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult); */ MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list& theResults); +/*! + Returns true if there are no parts in the document, which are not activated + \param theNotActivatedNames out string which contains not activated names + \return a boolean value + */ +MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames); + /*! Removes features from the document * \param theFeatures a list of features to be removed diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 8a85cd6f4..62e16b483 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -61,6 +61,14 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const return theObject->data()->attribute(attributeID())->isInitialized(); } +void ModuleBase_ModelWidget::processValueState() +{ + myIsValueStateBlocked = false; + if (myState == ModifiedInPP || myState == ModifiedInViewer) + storeValue(); + myState = Stored; +} + QString ModuleBase_ModelWidget::getValueStateError() const { QString anError = ""; @@ -185,11 +193,6 @@ void ModuleBase_ModelWidget::activate() void ModuleBase_ModelWidget::deactivate() { - myIsValueStateBlocked = false; - if (myState == ModifiedInPP || myState == ModifiedInViewer) - storeValue(); - myState = Stored; - if (myWidgetValidator) myWidgetValidator->activateFilters(false); } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 97e388511..c21ef7e8a 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -85,6 +85,9 @@ Q_OBJECT /// \return the enumeration result ValueState getValueState() const { return myState; } + /// Stores the widget value if it is modified + void processValueState(); + /// Returns an attribute error according to the value state /// It exists in all cases excepring the "Store" case QString getValueStateError() const; diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index 31582bc90..a588fc793 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -355,27 +357,6 @@ void setParameterName(ResultParameterPtr theResultParameter, const std::string& aParameter->data()->blockSendAttributeUpdated(false); } -#include -#include -bool allDocumentsActivated(QString& theNotActivatedNames) -{ - bool anAllPartActivated = true; - QStringList aRefNames; - - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); - for (int i = 0; i < aSize; i++) { - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i); - ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); - if (!aPart->isActivated()) { - anAllPartActivated = false; - aRefNames.append(aObject->data()->name().c_str()); - } - } - theNotActivatedNames = aRefNames.join(", "); - return anAllPartActivated; -} - void ParametersPlugin_EvalListener::processObjectRenamedEvent( const std::shared_ptr& theMessage) { @@ -400,11 +381,11 @@ void ParametersPlugin_EvalListener::processObjectRenamedEvent( if (!aParameter.get()) return; - QString aNotActivatedNames; - if (!allDocumentsActivated(aNotActivatedNames)) { + std::string aNotActivatedNames; + if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) { QMessageBox::StandardButton aRes = QMessageBox::warning(0, QObject::tr("Warning"), QObject::tr("Selected objects can be used in Part documents which are not loaded: \ -%1. Whould you like to continue?").arg(aNotActivatedNames), +%1. Whould you like to continue?").arg(aNotActivatedNames.c_str()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); if (aRes != QMessageBox::Yes) { setParameterName(aResultParameter, aMessage->oldName()); diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index c2c318683..10d39b798 100755 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -426,6 +426,7 @@ bool XGUI_PropertyPanel::setActiveWidget(ModuleBase_ModelWidget* theWidget) std::string aPreviosAttributeID; if(myActiveWidget) { aPreviosAttributeID = myActiveWidget->attributeID(); + myActiveWidget->processValueState(); myActiveWidget->deactivate(); myActiveWidget->setHighlighted(false); } diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 9a7556e40..64982ec4f 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace XGUI_Tools { //****************************************************************** @@ -106,8 +107,8 @@ std::string featureInfo(FeaturePtr theFeature) bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects) { bool aResult = true; - QString aNotActivatedNames; - if (!XGUI_Tools::allDocumentsActivated(aNotActivatedNames)) { + std::string aNotActivatedNames; + if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) { DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument(); bool aFoundPartSetObject = false; foreach (ObjectPtr aObj, theObjects) { @@ -118,7 +119,7 @@ bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects) if (aFoundPartSetObject) { QMessageBox::StandardButton aRes = QMessageBox::warning(theParent, QObject::tr("Warning"), QObject::tr("Selected objects can be used in Part documents which are not loaded: \ -%1. Whould you like to continue?").arg(aNotActivatedNames), +%1. Whould you like to continue?").arg(aNotActivatedNames.c_str()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); aResult = aRes == QMessageBox::Yes; } @@ -145,26 +146,6 @@ bool canRename(const ObjectPtr& theObject, const QString& theName) return true; } -//****************************************************************** -bool allDocumentsActivated(QString& theNotActivatedNames) -{ - bool anAllPartActivated = true; - QStringList aRefNames; - - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); - for (int i = 0; i < aSize; i++) { - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i); - ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); - if (!aPart->isActivated()) { - anAllPartActivated = false; - aRefNames.append(aObject->data()->name().c_str()); - } - } - theNotActivatedNames = aRefNames.join(", "); - return anAllPartActivated; -} - //************************************************************** XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop) diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 9215bf6ac..924454cf7 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -93,13 +93,6 @@ bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const QObjectPtrList& aLi */ bool canRename(const ObjectPtr& theObject, const QString& theName); -/*! - Returns true if there are no parts in the document, which are not activated - \param theNotActivatedNames out string which contains not activated names - \return a boolean value - */ -bool XGUI_EXPORT allDocumentsActivated(QString& theNotActivatedNames); - /*! Returns converted workshop \param theWorkshop an interface workshop -- 2.39.2