From: vsv Date: Tue, 27 Nov 2018 15:16:44 +0000 (+0300) Subject: Issue #2754: Prevent renaming of object with a name which already exists X-Git-Tag: End2018~142 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5f8c57345f356fb9bfdb4dcb9f811a880c7a7db8;p=modules%2Fshaper.git Issue #2754: Prevent renaming of object with a name which already exists --- diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index e5bc7a308..3f5ba6636 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include #include @@ -149,14 +151,29 @@ bool canRemoveOrRename(QWidget* theParent, const std::set& theFeatur //****************************************************************** bool canRename(const ObjectPtr& theObject, const QString& theName) { - if (std::dynamic_pointer_cast(theObject).get()) { + std::string aType = theObject->groupName(); + if (aType == ModelAPI_ResultParameter::group()) { double aValue; ResultParameterPtr aParam; if (ModelAPI_Tools::findVariable(theObject->document(), FeaturePtr(), qPrintable(theName), aValue, aParam)) { const char* aKeyStr = "Selected parameter can not be renamed to: %1. " "There is a parameter with the same name. Its value is: %2."; - QString aErrMsg(QObject::tr(aKeyStr).arg(qPrintable(theName)).arg(aValue)); + QString aErrMsg(QObject::tr(aKeyStr).arg(theName).arg(aValue)); + // We can not use here a dialog box for message - + // it will crash editing process in ObjectBrowser + Events_InfoMessage("XGUI_Tools", aErrMsg.toStdString()).send(); + return false; + } + } + else if ((aType == ModelAPI_ResultConstruction::group()) || (aType == ModelAPI_ResultBody::group())) { + DocumentPtr aDoc = theObject->document(); + ObjectPtr aObj = aDoc->objectByName(ModelAPI_ResultConstruction::group(), theName.toStdString()); + if (!aObj.get()) + aObj = aDoc->objectByName(ModelAPI_ResultBody::group(), theName.toStdString()); + + if (aObj.get()) { + QString aErrMsg(QObject::tr("Object with name %1 already exists.").arg(theName)); // We can not use here a dialog box for message - // it will crash editing process in ObjectBrowser Events_InfoMessage("XGUI_Tools", aErrMsg.toStdString()).send();