X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Tools.cpp;h=cd310eef0b4351b893282063740d80f47618ed6e;hb=116001f1015b8567ac4426e3a13c8cb8a0b32052;hp=26672cd89bc4cdf295c2152632fe497bdb6c8048;hpb=7bf19255421b34594c7b0a76d0ce28166d0ce895;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 26672cd89..cd310eef0 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -2,14 +2,32 @@ #include "XGUI_Tools.h" +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" + +#include "ModuleBase_IWorkshop.h" +#include "ModuleBase_Tools.h" + #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include +#include #include #include +#include namespace XGUI_Tools { //****************************************************************** @@ -26,7 +44,8 @@ QString dir(const QString& path, bool isAbs) QString file(const QString& path, bool withExt) { QString fPath = path; - while (!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/')) + while (!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || + fPath[fPath.length() - 1] == '/')) fPath.remove(fPath.length() - 1, 1); if (withExt) @@ -45,6 +64,21 @@ QString addSlash(const QString& path) return res; } +//****************************************************************** +QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theSeparator) +{ + QStringList aObjectNames; + foreach (ObjectPtr aObj, theObjects) { + if (aObj->data()->isValid()) + aObjectNames << QString::fromStdString(aObj->data()->name()); + } + if (aObjectNames.count() == 0) + return QString(); + if (aObjectNames.count() == 1) + return aObjectNames.first(); + return aObjectNames.join(theSeparator); +} + //****************************************************************** bool isModelObject(FeaturePtr theFeature) { @@ -71,4 +105,53 @@ std::string featureInfo(FeaturePtr theFeature) } }*/ + +//****************************************************************** +bool canRemoveOrRename(QWidget* theParent, const std::set& theFeatures) +{ + bool aResult = true; + std::string 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(aNotActivatedNames.c_str()), + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); + aResult = aRes == QMessageBox::Yes; + } + } + return aResult; +} + +//****************************************************************** +bool canRename(const ObjectPtr& theObject, const QString& theName) +{ + if (std::dynamic_pointer_cast(theObject).get()) { + 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)); + // 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) +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + return aConnector->workshop(); +} + }