From 50999d5a0e5de71194dc677f630f6ca4a4bdeff4 Mon Sep 17 00:00:00 2001 From: spo Date: Mon, 14 Sep 2015 15:47:10 +0300 Subject: [PATCH] Issue #627 - Crashes on problems in new features and plugins --- src/Config/Config_ModuleReader.cpp | 19 +++++++++++++++++-- src/Config/Config_ModuleReader.h | 2 ++ src/XGUI/XGUI_Workshop.cpp | 17 +++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index d298a412c..71d160378 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -65,13 +65,28 @@ std::string Config_ModuleReader::getModuleName() return getProperty(aRoot, PLUGINS_MODULE); } + +void Config_ModuleReader::addFeature(const std::string& theFeatureName, + const std::string& thePluginConfig) +{ + if (myFeaturesInFiles.count(theFeatureName)) { + std::string anErrorMsg = "Can not register feature '" + theFeatureName + "' in plugin '" + + thePluginConfig + "'. There is a feature with the same ID."; + Events_Error::send(anErrorMsg); + return; + } + + myFeaturesInFiles[theFeatureName] = thePluginConfig; +} + void Config_ModuleReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_PLUGIN, NULL)) { if (!hasRequiredModules(theNode)) return; std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG); - if (!aPluginConf.empty()) myPluginFiles.insert(aPluginConf); + if (!aPluginConf.empty()) + myPluginFiles.insert(aPluginConf); std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY); std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT); std::string aPluginName = addPlugin(aPluginLibrary, aPluginScript, aPluginConf); @@ -79,7 +94,7 @@ void Config_ModuleReader::processNode(xmlNodePtr theNode) std::list aFeatures = importPlugin(aPluginName, aPluginConf); std::list::iterator it = aFeatures.begin(); for (; it != aFeatures.end(); it++) { - myFeaturesInFiles[*it] = aPluginConf; + addFeature(*it, aPluginConf); } } } diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index bef9c6124..a50fd028c 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -69,6 +69,8 @@ class Config_ModuleReader : public Config_XMLReader std::string addPlugin(const std::string& aPluginLibrary, const std::string& aPluginScript, const std::string& aPluginConf); + /// Save feature in myFeaturesInFiles. Generates an error if the feature name is already registered. + void addFeature(const std::string& theFeatureName, const std::string& thePluginConfig); private: std::map myFeaturesInFiles; ///< a feature name is key, a file is value diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 3a45b647f..b5f3d0e02 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -564,13 +564,26 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) showPropertyPanel(); QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation(); - ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), - myModuleConnector); + ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector); myPropertyPanel->cleanContent(); aFactory.createWidget(myPropertyPanel->contentWidget()); QList aWidgets = aFactory.getModelWidgets(); + + // check compatibility of feature and widgets + FeaturePtr aFeature = aFOperation->feature(); + foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { + if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) { + std::string anErrorMsg = "The feature '" + aFeature->getKind() + "' has no attribute '" + + aWidget->attributeID() + "' used by widget '" + + aWidget->metaObject()->className() + "'."; + Events_Error::send(anErrorMsg); + myPropertyPanel->cleanContent(); + return; + } + } + foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { bool isStoreValue = !aFOperation->isEditOperation() && !aWidget->getDefaultValue().empty() && -- 2.39.2