From 76a9a89762ea30333347f341bb558b2ebcdeb3e3 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 27 May 2016 17:58:32 +0300 Subject: [PATCH] Issue #1505 Bug in parameters management (with parts not loaded) --- .../ParametersPlugin_EvalListener.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index 624b92319..31582bc90 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -355,6 +355,27 @@ 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) { @@ -379,6 +400,18 @@ void ParametersPlugin_EvalListener::processObjectRenamedEvent( if (!aParameter.get()) return; + QString aNotActivatedNames; + if (!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), + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); + if (aRes != QMessageBox::Yes) { + setParameterName(aResultParameter, aMessage->oldName()); + return; + } + } + // try to update the parameter feature according the new name setParameterName(aResultParameter, aMessage->newName()); // TODO(spo): replace with ModelAPI_Session::get()->validators()->validate(aParameter, ParametersPlugin_Parameter::VARIABLE_ID()) -- 2.39.2