X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FXGUI%2FXGUI_Tools.cpp;h=a60b1f2190ac49b646281c1a5fd8f4a8ac93d136;hb=d5b34eecbe818f8df6b353de5422183baa53a88e;hp=8b59da13739b25746a8c7de73e4137fbcb643e1f;hpb=7494964e67ade5c37d7a344be157381cabf465b9;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 8b59da137..a60b1f219 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -1,13 +1,33 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + #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 { //****************************************************************** @@ -43,6 +63,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) { @@ -69,4 +104,50 @@ 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) { + 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.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)) { + QString aErrMsg(QObject::tr("Selected parameter can not be renamed to: %1. \ + There is a parameter with the same name. Its value is: %2.").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(); +} + }