]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Search module's features in different plugins.
authorsbh <sergey.belash@opencascade.com>
Thu, 24 Apr 2014 07:02:10 +0000 (11:02 +0400)
committersbh <sergey.belash@opencascade.com>
Thu, 24 Apr 2014 07:02:10 +0000 (11:02 +0400)
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_ModuleReader.cpp
src/Config/Config_ModuleReader.h
src/Model/Model_PluginManager.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h

index 50d72e99230ebcc07bf48e30e017140644a6d25d..b9454e04d26d1ade98511b4daa5edb76bc2ea6c9 100644 (file)
@@ -36,6 +36,11 @@ Config_FeatureReader::~Config_FeatureReader()
 {
 }
 
+std::list<std::string> Config_FeatureReader::features() const
+{
+  return myFeatures;
+}
+
 void Config_FeatureReader::processNode(xmlNodePtr theNode)
 {
   Event_ID aMenuItemEvent = Event_Loop::eventByName(myEventGenerated);
@@ -43,6 +48,7 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
     Event_Loop* aEvLoop = Event_Loop::loop();
     Config_FeatureMessage aMessage(aMenuItemEvent, this);
     fillFeature(theNode, aMessage);
+    myFeatures.push_back(getProperty(theNode, _ID));
     //If a feature has xml definition for it's widget:
     aMessage.setUseInput(hasChild(theNode));
     aEvLoop->send(aMessage);
index 7b5322bba036468272244794f370455f610c1fdb..12517a5df395849fdaeac3753325411305347047 100644 (file)
@@ -12,7 +12,7 @@
 #include <Config_XMLReader.h>
 
 #include <string>
-
+#include <list>
 
 class Config_FeatureMessage;
 
@@ -20,10 +20,12 @@ class Config_FeatureReader: public Config_XMLReader
 {
 public:
   Config_FeatureReader(const std::string& theXmlFile,
-                       const std::string& theLibraryName = "",
+                       const std::string& theLibraryName,
                        const char* theEventGenerated = 0);
   virtual ~Config_FeatureReader();
 
+  std::list<std::string> features() const;
+
 protected:
   void processNode(xmlNodePtr aNode);
   bool processChildren(xmlNodePtr aNode);
@@ -34,6 +36,8 @@ private:
   std::string myLastWorkbench;
   std::string myLastGroup;
   std::string myLibraryName;
+
+  std::list<std::string> myFeatures;
   /// event generated on feature data sending, by default it is "FeatureEvent"
   const char* myEventGenerated;
 };
index 6153bd04dc727f5f761b870d6879f8e831a7edb1..4e67ea46de0b1eb78ebc2edf92038aa7cc40fb0c 100644 (file)
@@ -20,7 +20,8 @@
 
 
 Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
-    : Config_XMLReader("plugins.xml"), myIsAutoImport(false), myEventGenerated(theEventGenerated)
+    : Config_XMLReader("plugins.xml"),
+      myEventGenerated(theEventGenerated)
 {
 }
 
@@ -28,6 +29,11 @@ Config_ModuleReader::~Config_ModuleReader()
 {
 }
 
+const std::map<std::string, std::string>& Config_ModuleReader::featuresInFiles() const
+{
+  return myFeaturesInFiles;
+}
+
 /*
  * Get module name from plugins.xml
  * (property "module")
@@ -46,9 +52,11 @@ void Config_ModuleReader::processNode(xmlNodePtr theNode)
   if (isNode(theNode, NODE_PLUGIN, NULL)) {
     std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
     std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
-    if (myIsAutoImport)
-      importPlugin(aPluginConf, aPluginLibrary);
-    myPluginsMap[aPluginLibrary] = aPluginConf;
+    std::list<std::string> aFeatures = importPlugin(aPluginConf, aPluginLibrary);
+    std::list<std::string>::iterator it = aFeatures.begin();
+    for( ; it != aFeatures.end(); it++ ) {
+      myFeaturesInFiles[*it] = aPluginConf;
+    }
   }
 }
 
@@ -57,24 +65,14 @@ bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
   return isNode(theNode, NODE_PLUGINS, NULL);
 }
 
-void Config_ModuleReader::importPlugin(const std::string& thePluginName,
-                                       const std::string& thePluginLibrary)
+std::list<std::string>
+Config_ModuleReader::importPlugin(const std::string& thePluginFile,
+                                  const std::string& thePluginLibrary)
 {
-  Config_FeatureReader* aReader;
-  if(thePluginLibrary.empty()) {
-    aReader = new Config_FeatureReader(thePluginName);
-  } else {
-    aReader = new Config_FeatureReader(thePluginName, thePluginLibrary, myEventGenerated);
-  }
-  aReader->readAll();
+  Config_FeatureReader aReader = Config_FeatureReader(thePluginFile,
+                                                      thePluginLibrary,
+                                                      myEventGenerated);
+  aReader.readAll();
+  return aReader.features();
 }
 
-void Config_ModuleReader::setAutoImport(bool theEnabled)
-{
-  myIsAutoImport = theEnabled;
-}
-
-const std::map<std::string, std::string>& Config_ModuleReader::plugins() const
-{
-  return myPluginsMap;
-}
index 7083315b1426b42a3bbedfd57e521c2d7081a503..4f9b61a77a86dc40056b40a8f82d3964c5f1ed63 100644 (file)
@@ -12,6 +12,7 @@
 #include <Config_XMLReader.h>
 
 #include <map>
+#include <list>
 #include <string>
 
 
@@ -22,8 +23,7 @@ public:
   CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
   CONFIG_EXPORT virtual ~Config_ModuleReader();
 
-  CONFIG_EXPORT void setAutoImport(bool enabled);
-  CONFIG_EXPORT const std::map<std::string, std::string>& plugins() const;
+  CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
 
   CONFIG_EXPORT std::string getModuleName();
 
@@ -31,12 +31,11 @@ protected:
   void processNode(xmlNodePtr aNode);
   bool processChildren(xmlNodePtr aNode);
 
-  void importPlugin(const std::string& thePluginName,
-                    const std::string& thePluginLibrary = "");
+  std::list<std::string> importPlugin(const std::string& thePluginFile,
+                                      const std::string& thePluginLibrary);
 
 private:
-  bool myIsAutoImport;
-  std::map<std::string, std::string> myPluginsMap;
+  std::map<std::string, std::string> myFeaturesInFiles;
   const char* myEventGenerated;
 
 };
index eb279208afff32ba365016d136eac30c71cb7297..cf18adc564e4b4e210b5c09075389f7e252507bc 100644 (file)
@@ -93,7 +93,6 @@ void Model_PluginManager::LoadPluginsInfo()
 
   // Read plugins information from XML files
   Config_ModuleReader aXMLReader("FeatureRegisterEvent");
-  aXMLReader.setAutoImport(true);
   aXMLReader.readAll();
 }
 
index 92cea614c7d0722109798636382b9e090cc2fdcf..bbdde0c198ea928a24a19b0d40d01551e41c28d3 100644 (file)
@@ -38,8 +38,8 @@ PartSet_Module::~PartSet_Module()
 void PartSet_Module::createFeatures()
 {
   Config_ModuleReader aXMLReader = Config_ModuleReader();
-  aXMLReader.setAutoImport(true);
   aXMLReader.readAll();
+  myFeaturesInFiles = aXMLReader.featuresInFiles();
 }
 
 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
@@ -47,13 +47,9 @@ void PartSet_Module::featureCreated(XGUI_Command* theFeature)
   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
 }
 
-std::string PartSet_Module::modulePlugin()
+std::string PartSet_Module::featureFile(const std::string& theFeatureId)
 {
-  Config_ModuleReader aModuleReader = Config_ModuleReader();
-  aModuleReader.readAll();
-  std::map < std::string, std::string > aPluginMap = aModuleReader.plugins();
-  std::string aPluginName = aPluginMap["PartSetPlugin"];
-  return aPluginName;
+  return myFeaturesInFiles[theFeatureId];
 }
 
 /*
@@ -61,13 +57,14 @@ std::string PartSet_Module::modulePlugin()
  */
 void PartSet_Module::onFeatureTriggered()
 {
-  std::string aPluginName = modulePlugin();
-  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
-  aWdgReader.readAll();
   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
   QString aCmdId = aCmd->id();
-  std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
-  std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
+  std::string aStdCmdId = aCmdId.toStdString();
+  std::string aPluginFileName = featureFile(aStdCmdId);
+  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
+  aWdgReader.readAll();
+  std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
+  std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
   ModuleBase_PropPanelOperation* aPartSetOp;
   if (aCmdId == "Sketch" ) {
     aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
@@ -75,9 +72,9 @@ void PartSet_Module::onFeatureTriggered()
     aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
   }
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(aPartSetOp);
-  if (aPreviewOp)
+  if (aPreviewOp) {
     connect(aPreviewOp, SIGNAL(visualizePreview()), this, SLOT(onVisualizePreview()));
-
+  }
   aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
   aPartSetOp->setDescription(QString::fromStdString(aDescription));
 
index 676c1494a81ce01cce6b2217e8c83c06a4700313..7f8f9cea5df4360c39345a078137c29f322351f9 100644 (file)
@@ -6,12 +6,14 @@
 #include <XGUI_Module.h>
 #include <XGUI_Command.h>
 
+#include <QMap>
 #include <QObject>
 
+#include <string>
+
 class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
 {
 Q_OBJECT
-  std::string modulePlugin();
 
 public:
   PartSet_Module(XGUI_Workshop* theWshop);
@@ -19,6 +21,7 @@ public:
 
   virtual void createFeatures();
   virtual void featureCreated(XGUI_Command* theFeature);
+  std::string featureFile(const std::string&);
 
 public slots:
   void onFeatureTriggered();
@@ -26,6 +29,8 @@ public slots:
 
 private:
   XGUI_Workshop* myWorkshop;
+
+  std::map<std::string, std::string> myFeaturesInFiles;
 };
 
 #endif