+//******************************************************************
+bool canRemoveOrRename(QWidget* theParent, const std::set<FeaturePtr>& theFeatures)
+{
+ bool aResult = true;
+ std::wstring aNotActivatedNames;
+ if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
+ bool aFoundPartSetObject = ModuleBase_Tools::hasModuleDocumentFeature(theFeatures);
+ if (aFoundPartSetObject) {
+ const char* aKeyStr = "Selected objects can be used in Part documents which are not loaded: "
+ "%1. Whould you like to continue?";
+ QMessageBox::StandardButton aRes = QMessageBox::warning(theParent, QObject::tr("Warning"),
+ QObject::tr(aKeyStr).arg(QString::fromStdWString(aNotActivatedNames)),
+ QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+ aResult = aRes == QMessageBox::Yes;
+ }
+ }
+ return aResult;
+}
+
+//******************************************************************
+bool isAscii(const QString& theStr)
+{
+ char aCh;
+ for (int i = 0; i < theStr.size(); i++) {
+ aCh = theStr[i].toLatin1();
+ if (aCh == 0)
+ return false;
+ if ((aCh >= 0x30) && (aCh <= 0x39))
+ continue;
+ else if ((aCh >= 0x41) && (aCh <= 0x5A))
+ continue;
+ else if ((aCh >= 0x61) && (aCh <= 0x7A))
+ continue;
+ else if (aCh == 0x5f)
+ continue;
+ else
+ return false;
+ }
+ return true;
+}
+
+//******************************************************************
+bool isValidName(const QString& theName)
+{
+ QChar aChar;
+ for (int i = 0; i < theName.size(); i++) {
+ aChar = theName[i];
+ if (!aChar.isLetterOrNumber()) {
+ if ((aChar != "_") && (!aChar.isSpace()))
+ return false;
+ }
+ }
+ return true;
+}
+
+//******************************************************************
+bool canRename(const ObjectPtr& theObject, const QString& theName)
+{
+ std::string aType = theObject->groupName();
+ if (aType == ModelAPI_ResultParameter::group()) {
+ // For parameters names only ASCII symbols have to be used
+ if (!isAscii(theName))
+ return false;
+
+ double aValue;
+ ResultParameterPtr aParam;
+ if (ModelAPI_Tools::findVariable(theObject->document(),
+ FeaturePtr(), theName.toStdWString(), 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(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 (!isValidName(theName))
+ return false;
+
+ DocumentPtr aDoc = theObject->document();
+ ObjectPtr aObj =
+ aDoc->objectByName(aType, theName.toStdWString());
+
+ if (aObj.get() && theObject != aObj) {
+ QString aErrMsg(QObject::tr("Name %2 already exists in %1.").
+ arg(aType.c_str()).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();
+ return false;
+ }
+ }
+
+ return true;
+}
+
+//**************************************************************
+
+XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop)