Salome HOME
Issue #627 - Crashes on problems in new features and plugins
authorspo <sergey.pokhodenko@opencascade.com>
Mon, 14 Sep 2015 12:47:10 +0000 (15:47 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 15 Sep 2015 13:33:13 +0000 (16:33 +0300)
src/Config/Config_ModuleReader.cpp
src/Config/Config_ModuleReader.h
src/XGUI/XGUI_Workshop.cpp

index d298a412c0b4282a6c4151049791aaa62fb4480e..71d16037846caf06c17a3cf3b40f7c0dda860790 100644 (file)
@@ -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<std::string> aFeatures = importPlugin(aPluginName, aPluginConf);
     std::list<std::string>::iterator it = aFeatures.begin();
     for (; it != aFeatures.end(); it++) {
-      myFeaturesInFiles[*it] = aPluginConf;
+      addFeature(*it, aPluginConf);
     }
   }
 }
index bef9c61246a6c149cce31154c9c9dc5eb1d2d5a1..a50fd028c75e90540dd09235a2e5382dd608a790 100644 (file)
@@ -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<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
index 3a45b647fc5bea4bcee24752cd7358754bc3d358..b5f3d0e02b0c18c43095514917facdac9513b37a 100644 (file)
@@ -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<ModuleBase_ModelWidget*> 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() &&