Salome HOME
Set plugin's library name as field of feature message.
authorSergey Belash <sergey.belash@opencascade.com>
Mon, 31 Mar 2014 13:12:17 +0000 (17:12 +0400)
committerSergey Belash <sergey.belash@opencascade.com>
Mon, 31 Mar 2014 13:12:17 +0000 (17:12 +0400)
src/Config/Config_FeatureMessage.cpp
src/Config/Config_FeatureMessage.h
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_ModuleReader.cpp
src/Config/Config_ModuleReader.h
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/PartSet/PartSet_Module.cpp

index 3146e37c505531353526a935a1c636a508916a90..85102857bea420483f1c2a7ef2f33cb9f9887ea6 100644 (file)
@@ -85,3 +85,13 @@ void Config_FeatureMessage::setTooltip(const std::string& tooltip)
 {
   myTooltip = tooltip;
 }
+
+const std::string& Config_FeatureMessage::pluginLibrary() const
+{
+  return myPluginLibrary;
+}
+
+void Config_FeatureMessage::setPluginLibrary(const std::string& myPluginLibrary)
+{
+  this->myPluginLibrary = myPluginLibrary;
+}
index 1a0f99477a8a39ce592ea42fe01fa4d529c472f0..8f5fc335418b5d17f55c522774ff4a9ce0b3306a 100644 (file)
@@ -6,17 +6,22 @@
 #include <Event_Message.hxx>\r
 #include <string>\r
 \r
+/*\r
+ * Class to pass a feature entry extracted from xml file.\r
+ * Example of the feature entry:\r
+ * <feature id="new_part" text="Part" tooltip="Creates a new part" icon=":pictures/part_ico.png"/>\r
+ */\r
 class CONFIG_EXPORT Config_FeatureMessage: public Event_Message\r
 {\r
+  std::string myId;  //Feature unique id\r
+  std::string myText; //Represents action's text\r
+  std::string myTooltip;  //Represents action's tooltip\r
+  std::string myIcon; //Represents action's icon\r
+  std::string myKeysequence;  //Represents action's key sequence\r
 \r
-  std::string myId;\r
-  std::string myText;\r
-  std::string myTooltip;\r
-  std::string myIcon;\r
-  std::string myKeysequence;\r
-\r
-  std::string myGroupId;\r
-  std::string myWorkbenchId;\r
+  std::string myGroupId;  //Id of feature's group\r
+  std::string myWorkbenchId;  //Id of feature's workbench\r
+  std::string myPluginLibrary;  //Name of feature's library\r
 \r
 public:\r
   //const Event_ID theID, const void* theSender = 0\r
@@ -31,6 +36,7 @@ public:
 \r
   const std::string& groupId() const;\r
   const std::string& workbenchId() const;\r
+  const std::string& pluginLibrary() const;\r
 \r
   void setIcon(const std::string& icon);\r
   void setId(const std::string& id);\r
@@ -40,6 +46,7 @@ public:
 \r
   void setGroupId(const std::string& groupId);\r
   void setWorkbenchId(const std::string& workbenchId);\r
+  void setPluginLibrary(const std::string& thePluginLibrary);\r
 };\r
 \r
 #endif // CONFIG_MESSAGE_H\r
\ No newline at end of file
index 03e5f3abdbb76aab0749033ea713f8165ef76f5d..524c881e6929c62f66fb170adee0dbc8427789be 100644 (file)
@@ -33,12 +33,29 @@ const static char* FEATURE_ICON = "icon";
 const static char* FEATURE_KEYSEQUENCE = "keysequence";
 
 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile)
-    : Config_XMLReader(theXmlFile), m_fetchWidgetCfg(false)
+    : Config_XMLReader(theXmlFile),
+      myFetchWidgetCfg(false)
 {
+  myLibraryName = "";
+
 #ifdef _DEBUG
-  if(!Event_Loop::Loop()) {
+  if (!Event_Loop::Loop()) {
     std::cout << "Config_FeatureReader::importWorkbench: "
-    << "No event loop registered" << std::endl;
+        << "No event loop registered" << std::endl;
+  }
+#endif
+}
+
+Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
+                                           const std::string& theLibraryName)
+    : Config_XMLReader(theXmlFile),
+      myLibraryName(theLibraryName),
+      myFetchWidgetCfg(false)
+{
+#ifdef _DEBUG
+  if (!Event_Loop::Loop()) {
+    std::cout << "Config_FeatureReader::importWorkbench: "
+        << "No event loop registered" << std::endl;
   }
 #endif
 }
@@ -49,19 +66,19 @@ Config_FeatureReader::~Config_FeatureReader()
 
 std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName)
 {
-  m_fetchWidgetCfg = true;
+  myFetchWidgetCfg = true;
   readAll();
-  m_fetchWidgetCfg = false;
-  return m_widgetCfg;
+  myFetchWidgetCfg = false;
+  return myWidgetCfg;
 }
 
 void Config_FeatureReader::processNode(xmlNodePtr theNode)
 {
   if (isNode(theNode, NODE_FEATURE, NULL)) {
-    if (m_fetchWidgetCfg) {
+    if (myFetchWidgetCfg) {
       xmlBufferPtr buffer = xmlBufferCreate();
       int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
-      m_widgetCfg = std::string((char*) buffer->content);
+      myWidgetCfg = std::string((char*) buffer->content);
     } else {
       Event_Loop* aEvLoop = Event_Loop::Loop();
       Config_FeatureMessage aMessage(aEvLoop->EventByName("menu_item"), this);
@@ -71,10 +88,10 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
   }
   //The m_last* variables always defined before fillFeature() call. XML is a tree.
   if (isNode(theNode, NODE_GROUP, NULL)) {
-    m_lastGroup = getProperty(theNode, _ID);
+    myLastGroup = getProperty(theNode, _ID);
   }
   if (isNode(theNode, NODE_WORKBENCH, NULL)) {
-    m_lastWorkbench = getProperty(theNode, _ID);
+    myLastWorkbench = getProperty(theNode, _ID);
   }
 }
 
@@ -90,7 +107,7 @@ void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage
   outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
   outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
   outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
-  outFtMessage.setGroupId(m_lastGroup);
-  outFtMessage.setWorkbenchId(m_lastWorkbench);
-
+  outFtMessage.setGroupId(myLastGroup);
+  outFtMessage.setWorkbenchId(myLastWorkbench);
+  outFtMessage.setPluginLibrary(myLibraryName);
 }
index bbc25ba274d94b3f9f3725df57ffcb799bf97090..cb16d9ea2313debe02a577ceb4b678b8edab5d74 100644 (file)
@@ -14,6 +14,8 @@ class CONFIG_EXPORT Config_FeatureReader: public Config_XMLReader
 {
 public:
   Config_FeatureReader(const std::string& theXmlFile);
+  Config_FeatureReader(const std::string& theXmlFile,
+                       const std::string& theLibraryName);
   virtual ~Config_FeatureReader();
 
   std::string featureWidgetCfg(std::string theFeatureName);
@@ -24,11 +26,12 @@ protected:
 
   void fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFeatureMessage);
 
-  std::string m_lastWorkbench;
-  std::string m_lastGroup;
+  std::string myLastWorkbench;
+  std::string myLastGroup;
+  std::string myLibraryName;
 
-  bool m_fetchWidgetCfg;
-  std::string m_widgetCfg;
+  bool myFetchWidgetCfg;
+  std::string myWidgetCfg;
 };
 
 #endif /* CONFIG_FEATUREREADER_H_ */
index 5b536141da5370dcf4f2882ce10231dcfdd4d42c..85e653c7e6f0fdedc0557da2540b7d7e7207d9d7 100644 (file)
@@ -26,7 +26,7 @@ const static char* PLUGIN_CONFIG = "configuration";
 const static char* PLUGIN_LIBRARY = "library";
 
 Config_ModuleReader::Config_ModuleReader()
-    : Config_XMLReader("plugins.xml"), m_isAutoImport(false)
+    : Config_XMLReader("plugins.xml"), myIsAutoImport(false)
 {
 }
 
@@ -50,10 +50,11 @@ std::string Config_ModuleReader::getModuleName()
 void Config_ModuleReader::processNode(xmlNodePtr theNode)
 {
   if (isNode(theNode, NODE_PLUGIN, NULL)) {
-    std::string aPluginName = getProperty(theNode, PLUGIN_CONFIG);
-    if (m_isAutoImport)
-      importPlugin(aPluginName);
-    m_pluginsList.push_back(aPluginName);
+    std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
+    std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
+    if (myIsAutoImport)
+      importPlugin(aPluginConf, aPluginLibrary);
+    myPluginsMap[aPluginLibrary] = aPluginConf;
   }
 }
 
@@ -62,18 +63,24 @@ bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
   return isNode(theNode, NODE_PLUGINS, NULL);
 }
 
-void Config_ModuleReader::importPlugin(const std::string& thePluginName)
+void Config_ModuleReader::importPlugin(const std::string& thePluginName,
+                                       const std::string& thePluginLibrary)
 {
-  Config_FeatureReader aReader(thePluginName);
-  aReader.readAll();
+  Config_FeatureReader* aReader;
+  if(thePluginLibrary.empty()) {
+    aReader = new Config_FeatureReader(thePluginName);
+  } else {
+    aReader = new Config_FeatureReader(thePluginName, thePluginLibrary);
+  }
+  aReader->readAll();
 }
 
-void Config_ModuleReader::setAutoImport(bool enabled)
+void Config_ModuleReader::setAutoImport(bool theEnabled)
 {
-  m_isAutoImport = enabled;
+  myIsAutoImport = theEnabled;
 }
 
-const std::list<std::string>& Config_ModuleReader::pluginsList() const
+const std::map<std::string, std::string>& Config_ModuleReader::plugins() const
 {
-  return m_pluginsList;
+  return myPluginsMap;
 }
index 4bd958f5150cdd2b8439a85fcefb3bfbfe20812a..4b59f622e0f21872da594d9b6460b3d2fbd76da4 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <Config_XMLReader.h>
 
-#include <list>
+#include <map>
 
 class CONFIG_EXPORT Config_ModuleReader: public Config_XMLReader
 {
@@ -20,7 +20,7 @@ public:
   virtual ~Config_ModuleReader();
 
   void setAutoImport(bool enabled);
-  const std::list<std::string>& pluginsList() const;
+  const std::map<std::string, std::string>& plugins() const;
 
   std::string getModuleName();
 
@@ -28,11 +28,13 @@ protected:
   void processNode(xmlNodePtr aNode);
   bool processChildren(xmlNodePtr aNode);
 
-  void importPlugin(const std::string& thePluginName);
+  void importPlugin(const std::string& thePluginName,
+                    const std::string& thePluginLibrary = "");
 
 private:
-  bool m_isAutoImport;
-  std::list<std::string> m_pluginsList;
+  bool myIsAutoImport;
+  std::map<std::string, std::string> myPluginsMap;
+
 
 };
 
index e9a31e207aae6a58b86624c3aa513dc1fe74a617..723ddf089af402c16613507a5f6ca163931f1c0d 100644 (file)
@@ -41,7 +41,7 @@ Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName)
   prefix = "../plugins/";
 #endif
 
-  m_DocumentPath = prefix + theXmlFileName;
+  myDocumentPath = prefix + theXmlFileName;
 }
 
 Config_XMLReader::~Config_XMLReader()
@@ -85,10 +85,10 @@ bool Config_XMLReader::processChildren(xmlNodePtr aNode)
 xmlNodePtr Config_XMLReader::findRoot()
 {
   xmlDocPtr aDoc;
-  aDoc = xmlParseFile(m_DocumentPath.c_str());
+  aDoc = xmlParseFile(myDocumentPath.c_str());
   if (aDoc == NULL) {
 #ifdef _DEBUG
-    std::cout << "Config_XMLReader::import: " << "Document " << m_DocumentPath
+    std::cout << "Config_XMLReader::import: " << "Document " << myDocumentPath
     << " is not parsed successfully." << std::endl;
 #endif
     return NULL;
index 785dca9c266d08016b13057db37cc1d9390d8eab..bdff8a00e9bf94425e747adecaf46ac370f9c41a 100644 (file)
@@ -45,7 +45,7 @@ protected:
   bool isNode(xmlNodePtr theNode, const char* name, ...);
 
 private:
-  std::string m_DocumentPath;
+  std::string myDocumentPath;
 };
 
 #endif /* CONFIG_XMLREADER_H_ */
index 908587d524a0d1f91005591bf53c07760bab7158..ba04d395c19ff3572b01fbac351bfee2bad620ae 100644 (file)
@@ -45,9 +45,9 @@ void PartSet_Module::onCommandTriggered()
 {
   Config_ModuleReader aModuleReader = Config_ModuleReader();
   aModuleReader.readAll();
-  std::string aPluginName = aModuleReader.pluginsList().front();
-  Config_FeatureReader* aReader = new Config_FeatureReader(aPluginName);
-  XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
-  std::string aXMLWidgetCfg = aReader->featureWidgetCfg(aCmd->getId().toStdString());
-  delete aReader;
+//  std::string aPluginName = aModuleReader.plugins().front();
+//  Config_FeatureReader* aReader = new Config_FeatureReader(aPluginName);
+//  XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+//  std::string aXMLWidgetCfg = aReader->featureWidgetCfg(aCmd->getId().toStdString());
+//  delete aReader;
 }