]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Advanced version of plugin reader with ability to extract xml information about featu...
authorSergey Belash <sergey.belash@opencascade.com>
Fri, 21 Mar 2014 15:56:15 +0000 (19:56 +0400)
committerSergey Belash <sergey.belash@opencascade.com>
Fri, 21 Mar 2014 15:56:15 +0000 (19:56 +0400)
23 files changed:
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_Message.cpp
src/Config/Config_Message.h
src/Config/Config_ModuleReader.cpp
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/Config/plugin-PartSet.xml
src/Event/Event_Loop.cxx
src/Event/Event_Message.cxx
src/Event/Event_Message.hxx
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Message.cpp [new file with mode: 0644]
src/PartSet/PartSet_Message.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_Module.h
src/XGUI/XGUI_Workbench.cpp
src/XGUI/XGUI_Workbench.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 0eb2bfdaa5ac4975e8f554eae979df7dccb930a2..53c0d6c88dd4b5dcba8da1dc495c64d68887ae2c 100644 (file)
 
 //Hardcoded xml entities
 // * Nodes
+const static char* NODE_WORKBENCH = "workbench";
+const static char* NODE_GROUP = "group";
+const static char* NODE_FEATURE = "feature";
 
 // * Properties
-const static char* FEATURE_ID = "id";
+const static char* _ID = "id";
+//const static char* WORKBENCH_ID = "id";
+//const static char* GROUP_ID = "id";
+//const static char* FEATURE_ID = "id";
 const static char* FEATURE_TEXT = "text";
 const static char* FEATURE_TOOLTIP = "tooltip";
 const static char* FEATURE_ICON = "icon";
 const static char* FEATURE_KEYSEQUENCE = "keysequence";
-const static char* FEATURE_GROUP_NAME = "name";
-
-
 
 
 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile)
-    : Config_XMLReader(theXmlFile)
+    : Config_XMLReader(theXmlFile),
+      m_fetchWidgetCfg(false)
 {
   #ifdef _DEBUG
   if(!Event_Loop::Loop()) {
@@ -45,34 +49,51 @@ Config_FeatureReader::~Config_FeatureReader()
 {
 }
 
+std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName)
+{
+  m_fetchWidgetCfg = true;
+  readAll();
+  m_fetchWidgetCfg = false;
+  return m_widgetCfg;
+}
+
 void Config_FeatureReader::processNode(xmlNodePtr theNode)
 {
-  if(isNode(theNode,"feature")) {
-    Event_Loop* aEvLoop = Event_Loop::Loop();
-    Config_FeatureMessage aMessage(aEvLoop->EventByName("Feature"), this);
-    fillFeature(theNode, aMessage);
-    xmlNodePtr aGroupNode = theNode->parent;
-    if(aGroupNode) {
-      std::string aGroupName = getProperty(aGroupNode, FEATURE_GROUP_NAME);
-      aMessage.m_group = aGroupName;
+  if(isNode(theNode, NODE_FEATURE, NULL)) {
+    if(m_fetchWidgetCfg) {
+      xmlBufferPtr buffer = xmlBufferCreate();
+      int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
+      m_widgetCfg = std::string((char*)buffer->content);
+    } else {
+      Event_Loop* aEvLoop = Event_Loop::Loop();
+      Config_FeatureMessage aMessage(aEvLoop->EventByName("menu_item"), this);
+      fillFeature(theNode, aMessage);
+      aEvLoop->Send(aMessage);
     }
-    aEvLoop->Send(aMessage);
+  }
+  //The m_last* variables always defined before fillFeature() call. XML is a tree.
+  if(isNode(theNode, NODE_GROUP, NULL)) {
+    m_lastGroup = getProperty(theNode, _ID);
+  }
+  if(isNode(theNode, NODE_WORKBENCH, NULL)) {
+    m_lastWorkbench = getProperty(theNode, _ID);
   }
 }
 
 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
 {
-  return isNode(theNode, "workbench")
-      || isNode(theNode, "group");
-//      || isNode(theNode, "feature");
+  return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
 }
 
 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot,
                                        Config_FeatureMessage& outFtMessage)
 {
-  outFtMessage.m_id = getProperty(theRoot, FEATURE_ID);
-  outFtMessage.m_text = getProperty(theRoot, FEATURE_TEXT);
-  outFtMessage.m_tooltip = getProperty(theRoot, FEATURE_TOOLTIP);
-  outFtMessage.m_icon = getProperty(theRoot, FEATURE_ICON);
-  outFtMessage.m_keysequence = getProperty(theRoot, FEATURE_KEYSEQUENCE);
+  outFtMessage.setId(getProperty(theRoot, _ID));
+  outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
+  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);
+
 }
index 76d7635c03c1ed970c1737765042a9f717b2f7b6..bbc25ba274d94b3f9f3725df57ffcb799bf97090 100644 (file)
@@ -16,12 +16,19 @@ public:
   Config_FeatureReader(const std::string& theXmlFile);
   virtual ~Config_FeatureReader();
 
+  std::string featureWidgetCfg(std::string theFeatureName);
+
 protected:
   void processNode(xmlNodePtr aNode);
   bool processChildren(xmlNodePtr aNode);
 
   void fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFeatureMessage);
 
+  std::string m_lastWorkbench;
+  std::string m_lastGroup;
+
+  bool m_fetchWidgetCfg;
+  std::string m_widgetCfg;
 };
 
 #endif /* CONFIG_FEATUREREADER_H_ */
index ea701ffd52390934c68047273c0b36c5bcf1cbb3..8dd2b4131ea2d39279eb9b771b2e5cc99e359c83 100644 (file)
 /*
  *
  */
-
 #include "Config_Message.h"
 
-Config_FeatureMessage::Config_FeatureMessage(const Event_ID theId, const void* theParent) :
-  Event_Message(theId, theParent)
+Config_FeatureMessage::Config_FeatureMessage(const Event_ID theId,
+                                             const void* theParent)
+    : Event_Message(theId, theParent)
 {
-  m_group = "";
   m_id = "";
   m_text = "";
   m_tooltip = "";
   m_icon = "";
   m_keysequence = "";
+
+  m_groupId = "";
+  m_groupText = "";
+  m_workbenchId = "";
+  m_workbenchText = "";
+}
+
+const std::string& Config_FeatureMessage::icon() const
+{
+  return m_icon;
+}
+
+void Config_FeatureMessage::setIcon(const std::string& icon)
+{
+  m_icon = icon;
+}
+
+const std::string& Config_FeatureMessage::id() const
+{
+  return m_id;
+}
+
+void Config_FeatureMessage::setId(const std::string& id)
+{
+  m_id = id;
 }
 
+const std::string& Config_FeatureMessage::keysequence() const
+{
+  return m_keysequence;
+}
+
+void Config_FeatureMessage::setKeysequence(const std::string& keysequence)
+{
+  m_keysequence = keysequence;
+}
+
+const std::string& Config_FeatureMessage::text() const
+{
+  return m_text;
+}
+
+void Config_FeatureMessage::setText(const std::string& text)
+{
+  m_text = text;
+}
+
+const std::string& Config_FeatureMessage::tooltip() const
+{
+  return m_tooltip;
+}
+
+const std::string& Config_FeatureMessage::groupId() const
+{
+  return m_groupId;
+}
+
+void Config_FeatureMessage::setGroupId(const std::string& groupId)
+{
+  m_groupId = groupId;
+}
+
+const std::string& Config_FeatureMessage::groupText() const
+{
+  return m_groupText;
+}
+
+void Config_FeatureMessage::setGroupText(const std::string& groupText)
+{
+  m_groupText = groupText;
+}
+
+const std::string& Config_FeatureMessage::workbenchId() const
+{
+  return m_workbenchId;
+}
+
+void Config_FeatureMessage::setWorkbenchId(const std::string& workbenchId)
+{
+  m_workbenchId = workbenchId;
+}
+
+const std::string& Config_FeatureMessage::workbenchText() const
+{
+  return m_workbenchText;
+}
+
+void Config_FeatureMessage::setWorkbenchText(const std::string& workbenchText)
+{
+  m_workbenchText = workbenchText;
+}
+
+void Config_FeatureMessage::setTooltip(const std::string& tooltip)
+{
+  m_tooltip = tooltip;
+}
index 2e3d567a87229d189a2442befb62b6f46c3e11fa..5f39cbc01014dcf132e3fd3079903e3f5895e807 100644 (file)
@@ -8,20 +8,41 @@
 
 class CONFIG_EXPORT Config_FeatureMessage : public Event_Message
 {
-public:
   std::string m_id;
   std::string m_text;
   std::string m_tooltip;
   std::string m_icon;
   std::string m_keysequence;
 
-  std::string m_group;
+  std::string m_groupId;
+  std::string m_groupText;
+  std::string m_workbenchId;
+  std::string m_workbenchText;
 
 public:
   //const Event_ID theID, const void* theSender = 0
   Config_FeatureMessage(const Event_ID theId, const void* theParent = 0);
 
+  //Auto-generated getters/setters
+  const std::string& icon() const;
+  const std::string& id() const;
+  const std::string& keysequence() const;
+  const std::string& text() const;
+  const std::string& tooltip() const;
+  const std::string& groupId() const;
+  const std::string& groupText() const;
+  const std::string& workbenchId() const;
+  const std::string& workbenchText() const;
+
+  void setIcon(const std::string& icon);
+  void setId(const std::string& id);
+  void setKeysequence(const std::string& keysequence);
+  void setText(const std::string& text);
+  void setTooltip(const std::string& tooltip);
+  void setGroupId(const std::string& groupId);
+  void setGroupText(const std::string& groupText);
+  void setWorkbenchId(const std::string& workbenchId);
+  void setWorkbenchText(const std::string& workbenchText);
 };
 
-
 #endif // CONFIG_MESSAGE_H
index e09904422da317927f2ee127120cb91f92c3ccee..1a6d1c7ce989770fc0433bb75f44c041b1faa1df 100644 (file)
 #include <iostream>
 #endif
 
+//Hardcoded xml entities
+// * Nodes
+const static char* NODE_PLUGIN = "plugin";
+const static char* NODE_PLUGINS = "plugins";
+
+// * Properties
+const static char* PLUGINS_MODULE = "module";
+const static char* PLUGIN_CONFIG = "configuration";
+const static char* PLUGIN_LIBRARY = "library";
+
+
 Config_ModuleReader::Config_ModuleReader()
     : Config_XMLReader("plugins.xml"),
       m_isAutoImport(false)
@@ -32,7 +43,7 @@ Config_ModuleReader::~Config_ModuleReader()
 std::string Config_ModuleReader::getModuleName()
 {
   xmlNodePtr aRoot = findRoot();
-  return getProperty(aRoot, "module");
+  return getProperty(aRoot, PLUGINS_MODULE);
 }
 
 /*
@@ -40,8 +51,8 @@ std::string Config_ModuleReader::getModuleName()
  */
 void Config_ModuleReader::processNode(xmlNodePtr theNode)
 {
-  if(isNode(theNode, "plugin")) {
-    std::string aPluginName = getProperty(theNode, "configuration");
+  if(isNode(theNode, NODE_PLUGIN, NULL)) {
+    std::string aPluginName = getProperty(theNode, PLUGIN_CONFIG);
     if(m_isAutoImport)
       importPlugin(aPluginName);
     m_pluginsList.push_back(aPluginName);
@@ -50,7 +61,7 @@ void Config_ModuleReader::processNode(xmlNodePtr theNode)
 
 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
 {
-  return isNode(theNode, "plugins");
+  return isNode(theNode, NODE_PLUGINS, NULL);
 }
 
 void Config_ModuleReader::importPlugin(const std::string& thePluginName)
index adce851dc03fb2da012c3e1473c44ef7d80eb65e..c235c3355922ad97b13d54e04a08a906bcc1a9d2 100644 (file)
@@ -146,9 +146,27 @@ std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* name)
 /*
  * Returns true if theNode is XML node with a given name.
  */
-bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName)
+bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
 {
-  const char* emptyLine = "";
-  return theNode->type == XML_ELEMENT_NODE
-      && !xmlStrcmp(theNode->name, (const xmlChar *) theNodeName);
+  bool result = false;
+  const xmlChar* aName = theNode->name;
+  if(!aName || theNode->type != XML_ELEMENT_NODE)
+    return false;
+
+  if(!xmlStrcmp(aName, (const xmlChar *) theNodeName))
+    return true;
+
+  va_list args; // define argument list variable
+  va_start (args, theNodeName); // init list; point to last defined argument
+  while(true) {
+    char *anArg = va_arg (args, char *); // get next argument
+    if(anArg == NULL)
+      break;
+    if(!xmlStrcmp(aName, (const xmlChar *) anArg)) {
+      va_end (args); // cleanup the system stack
+      return true;
+    }
+  }
+  va_end (args); // cleanup the system stack
+  return false;
 }
index 9761ada43e82222dcfb5a9e762c5ffd806e86810..7a42fcb09ed58821906493a58ace61396d4150fa 100644 (file)
 #include "Config_Message.h"
 
 #include <string>
+#include <cstdarg>
 
 //Forward declaration for xmlNodePtr.
 typedef struct _xmlNode xmlNode;
 typedef xmlNode *xmlNodePtr;
 struct _xmlNode;
 
+
 class CONFIG_EXPORT Config_XMLReader {
 public:
   Config_XMLReader(const std::string& theXmlFile);
@@ -34,7 +36,13 @@ protected:
 
   xmlNodePtr node(void* theNode);
   std::string getProperty(xmlNodePtr theNode, const char* property);
-  bool isNode(xmlNodePtr theNode, const char* name);
+  /*
+   * Please note that this function should be called with NULL last argument. 
+   * In example: isNode(aNode, "type1", ["type2", ...], NULL);
+   * ", NULL" is required to use unlimited number of arguments.
+   * TODO(sbh): find a way to simplify calling this method.
+   */
+  bool isNode(xmlNodePtr theNode, const char* name, ...);
 
 private:
   std::string m_DocumentPath;
index d3d7d4cb22a1ffd8dcb041293f54e84166387b62..2785659ef9a5ab09b5e80e8aea8bfa77e5f2586e 100644 (file)
@@ -1,12 +1,18 @@
-<plugin name="PartSet">
-  <workbench>
-    <group name="Part">
+<plugin>
+  <workbench id="Part">
+    <group id="Operations">
       <feature id="new_part" text="Part" tooltip="Creates a new part" icon=":pictures/part_ico.png"/>
       <feature id="duplicate" text="Duplicate" tooltip="Duplicate selected object" icon=":icons/duplicate.png"/>
       <feature id="remove" text="Remove"  tooltip="Remove selected object" icon=":icons/remove.png"/>
     </group>
-    <group name="Construction">
-      <feature id="new_point" text="Point" tooltip="Create a new point" icon=":icons/point.png"/>
+  </workbench>
+  <workbench id="Construction">
+    <group id="Basic">
+      <feature id="new_point" text="Point" tooltip="Create a new point" icon=":icons/point.png">
+        <value id="x" type="double" label="X:" min="0" max="" step="0.1" default="0"/>
+        <value id="y" type="double" label="Y:" min="0" max="" step="0.1" default="0"/>
+        <value id="z" type="double" label="Z:" min="0" max="" step="0.1" default="0"/>
+      </feature>
       <feature id="new_axis" text="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence=""/>
       <feature id="new_plane" text="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence=""/>
     </group>
index e997c8b8fb3a8bacad7049081a981c75307c4c40..d5981a823b573059deb50dfeaace39d969e11347 100644 (file)
@@ -35,7 +35,7 @@ void Event_Loop::Send(Event_Message& theMessage)
   // TO DO: make it in thread and wit husage of semaphores
 
   map<char*, map<void*, list<Event_Listener*> > >::iterator aFindID = 
-    myListeners.find(theMessage.ID().EventText());
+    myListeners.find(theMessage.EventID().EventText());
   if (aFindID != myListeners.end()) {
     map<void*, list<Event_Listener*> >::iterator aFindSender = 
       aFindID->second.find(theMessage.Sender());
index e9dc311b32fdb1060d05895fc48e19234b41fc0c..53186da3134dcc2dfe7f7212d625168b8df9e255 100644 (file)
@@ -5,6 +5,6 @@
 #include <Event_Message.hxx>
 
 Event_Message::Event_Message(const Event_ID theID, const void* theSender) :
-myID(theID), mySender((void*)theSender)
+myEventId(theID), mySender((void*)theSender)
 {
 }
index 4e5337c8362ceb1fb8fdaa7bad5eb494850197e3..bb700a75da44696946d1da76e996d0b9103c93bf 100644 (file)
@@ -36,7 +36,7 @@ public:
  * Normally it is inherited by the higher-level 
  */
 class EVENT_EXPORT Event_Message {
-  Event_ID myID; ///< identifier of the event
+  Event_ID myEventId; ///< identifier of the event
   void* mySender; ///< the sender object
 
 public:
@@ -46,7 +46,7 @@ public:
   virtual ~Event_Message() {}
 
   //! Returns identifier of the message
-  const Event_ID& ID() const {return myID;}
+  const Event_ID& EventID() const {return myEventId;}
 
   //! Returns sender of the message or NULL if it is anonymous message
   void* Sender() {return mySender;}
index b8c89c47cf07b83cbb63d4811a637b8a6515b6e7..0ed6de6f142124c0e534788cea1eb9fa941faa26 100644 (file)
@@ -1,14 +1,17 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
 
 INCLUDE(Common)
+SET(CMAKE_AUTOMOC ON)
 
 SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Module.h
+       PartSet_Message.h
 )
 
 SET(PROJECT_SOURCES
        PartSet_Module.cpp
+       PartSet_Message.cpp
 )
 
 SET(PROJECT_RESOURCES 
@@ -24,10 +27,14 @@ SET(PROJECT_LIBRARIES
     ${Qt5Widgets_LIBRARIES}
 )
 
+SET(PROJECT_AUTOMOC 
+    ${CMAKE_CURRENT_BINARY_DIR}/PartSet_automoc.cpp
+)
+
 QT5_ADD_RESOURCES(PROJECT_COMPILED_RESOURCES ${PROJECT_RESOURCES})
 QT5_ADD_TRANSLATION(QM_RESOURCES ${TEXT_RESOURCES})
 
-SOURCE_GROUP ("Generated Files" FILES ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES})
+SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES})
 SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES})
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI)
diff --git a/src/PartSet/PartSet_Message.cpp b/src/PartSet/PartSet_Message.cpp
new file mode 100644 (file)
index 0000000..0c3d72c
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * PartSet_Message.cpp
+ *
+ *  Created on: Mar 21, 2014
+ *      Author: sbh
+ */
+
+#include <PartSet_Message.h>
+
+PartSet_Message::PartSet_Message(const Event_ID theId,
+                                 const void* theParent)
+    : Event_Message(theId, theParent)
+{
+
+}
+
+PartSet_Message::~PartSet_Message()
+{
+}
+
diff --git a/src/PartSet/PartSet_Message.h b/src/PartSet/PartSet_Message.h
new file mode 100644 (file)
index 0000000..4ceccc1
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * PartSet_Message.h
+ *
+ *  Created on: Mar 21, 2014
+ *      Author: sbh
+ */
+
+#ifndef PARTSET_MESSAGE_H_
+#define PARTSET_MESSAGE_H_
+
+#include <PartSet.h>
+
+#include <QString>
+
+#include <Event_Message.hxx>
+
+class PARTSET_EXPORT PartSet_Message: public Event_Message
+{
+public:
+  PartSet_Message(const Event_ID theId, const void* theParent = 0);
+  virtual ~PartSet_Message();
+};
+
+#endif /* PARTSET_MESSAGE_H_ */
index 26d8b724340483bccfa7ec116ee32c20c63c250d..6b02152ce4c8165150cc921eed4e97dac89784d8 100644 (file)
@@ -1,6 +1,9 @@
 #include "PartSet_Module.h"
 
 #include <Config_ModuleReader.h>
+#include <Config_FeatureReader.h>
+
+#include <Event_Loop.hxx>
 
 #include <QFile>
 #include <QDir>
@@ -27,8 +30,27 @@ PartSet_Module::~PartSet_Module()
 void PartSet_Module::createFeatures()
 {
   Config_ModuleReader* aXMLReader = new Config_ModuleReader();
-  aXMLReader->getModuleName();
   aXMLReader->setAutoImport(true);
   aXMLReader->readAll();
   delete aXMLReader;
 }
+
+void PartSet_Module::featureCreated(XGUI_Command* theFeature)
+{
+  QString aFtId = theFeature->getId();
+  if(aFtId == "new_point") {
+    theFeature->connectTo(this, SLOT(onCommandTriggered()));
+  }
+}
+
+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;
+}
index 3f792d21f6613bedcce640652381e7f63f4178d4..049e3e424f9b8d2fb2267e7c362229f9de9b6ba2 100644 (file)
@@ -5,20 +5,25 @@
 #include "PartSet.h"
 
 #include <XGUI_Module.h>
+#include <XGUI_Command.h>
 
-class Config_FeatureReader;
+#include <QObject>
 
-class PARTSET_EXPORT PartSet_Module : public XGUI_Module
+class PARTSET_EXPORT PartSet_Module : public QObject, public XGUI_Module
 {
+    Q_OBJECT
 public:
     PartSet_Module(XGUI_Workshop* theWshop);
     virtual ~PartSet_Module();
 
     virtual void createFeatures();
+    virtual void featureCreated(XGUI_Command* theFeature);
+
+public slots:
+    void onCommandTriggered();
 
 private:
     QString myMenuXML;
-
     XGUI_Workshop* myWorkshop;
 };
 
index f1926acf0ca3cc204cefc561985ba9bbb2521287..04033692e68a3263dfd18e662489dcde0af8202c 100644 (file)
@@ -18,26 +18,30 @@ XGUI_MainMenu::~XGUI_MainMenu(void)
 {
 }
 
-XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theTitle)
+XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId,
+                                            const QString& theTitle)
 {
-    QDockWidget* aDoc = new QDockWidget(myDesktop);
-    QString workbenchObjName = theTitle + "_Workbench";
-    aDoc->setObjectName(workbenchObjName);
-    aDoc->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
-    aDoc->setAllowedAreas(Qt::TopDockWidgetArea);
-    aDoc->setWindowTitle(theTitle);
-    aDoc->setMinimumHeight(30);
-    aDoc->setContentsMargins(0, 0, 0, 0);
-
-    XGUI_Workbench* aPage = new XGUI_Workbench(aDoc);
-    aDoc->setWidget(aPage);
-
-    myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDoc);
+    QDockWidget* aDock = new QDockWidget(myDesktop);
+    aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
+    aDock->setAllowedAreas(Qt::TopDockWidgetArea);
+    QString aTitle = theTitle;
+    if(aTitle.isEmpty()){
+      aTitle = tr(theId.toLatin1().constData());
+    }
+    aDock->setWindowTitle(aTitle);
+    aDock->setMinimumHeight(30);
+    aDock->setContentsMargins(0, 0, 0, 0);
+
+    XGUI_Workbench* aPage = new XGUI_Workbench(aDock);
+    aPage->setObjectName(theId);
+    aDock->setWidget(aPage);
+
+    myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock);
     if (myMenuTabs.length() > 1) {
-        myDesktop->tabifyDockWidget(myMenuTabs.last(), aDoc);
+        myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock);
     }
 
-    myMenuTabs.append(aDoc);
+    myMenuTabs.append(aDock);
     return aPage;
 }
 
@@ -46,17 +50,5 @@ XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theTitle)
  */
 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
 {
-  QDockWidget* aDoc = myDesktop->findChild<QDockWidget*>(theObjName);
-  if(aDoc) {
-    return dynamic_cast<XGUI_Workbench*>(aDoc->widget());
-  }
-  return NULL;
-}
-
-
-XGUI_MenuGroupPanel* XGUI_MainMenu::addGroup(int thePageId)
-{
-    XGUI_Workbench* aPage = dynamic_cast<XGUI_Workbench*>(myMenuTabs[thePageId]->widget());
-    return aPage->addGroup();
+  return myDesktop->findChild<XGUI_Workbench*>(theObjName);
 }
-
index ca45fe030f7a8f2ffa60243b2f087c2bda07455e..3a00d4c667c66f7c54f953b085918417540e1963 100644 (file)
@@ -23,10 +23,9 @@ public:
     XGUI_MainMenu(XGUI_MainWindow *parent);
     virtual ~XGUI_MainMenu();
 
-    XGUI_Workbench* addWorkbench(const QString& theTitle);
-    XGUI_Workbench* findWorkbench(const QString& theObjName);
-
-    XGUI_MenuGroupPanel* addGroup(int thePageId);
+    XGUI_Workbench* addWorkbench(const QString& theId,
+                                 const QString& theText = "");
+    XGUI_Workbench* findWorkbench(const QString& theId);
 
 private:
     XGUI_MainWindow* myDesktop;
index e27066743d21050b9bd792e86ce60bc09a0fac52..cfb4d314e2ea5da7cbbdc5309946ee1b5bec5828 100644 (file)
@@ -1,17 +1,15 @@
-
 #ifndef XGUI_Module_H
 #define XGUI_Module_H
 
-#include <QString>
-#include <QIcon>
-#include <QKeySequence>
-
 #include <XGUI_Workshop.h>
 
+class XGUI_Command;
+
 class XGUI_Module
 {
 public:
     virtual void createFeatures() = 0;
+    virtual void featureCreated(XGUI_Command*) = 0;
 };
 
 //! This function must return a new module instance.
index 4661f5791fd73c2baf829e907b5bd7c319bdeac9..61da43fa236f0fcb7f2ee8c7d3ed3bdf535fd31b 100644 (file)
@@ -70,25 +70,17 @@ XGUI_Workbench::XGUI_Workbench(QWidget *theParent) :
 }
 
 /*
- * Creates a new group in the workbench with given name.
- * If no name provided it would be defined as {workbench_name}_Group_N.
+ * Creates a new group in the workbench with given object name.
  */
-XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theName)
+XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theId)
 {
-    QString aGroupName = theName;
-    //Generate a group name.
-    if(theName.isEmpty()){
-      QString aGroupName = objectName();
-      aGroupName = aGroupName.replace("_Workbench", "_Group_%1");
-      aGroupName = aGroupName.arg(myGroups.count());
-    }
     if (!myLayout->isEmpty()) {
         int aNb = myLayout->count();
         QLayoutItem* aItem = myLayout->itemAt(aNb - 1);
         myLayout->removeItem(aItem);
     }
     XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget);
-    aGroup->setObjectName(aGroupName);
+    aGroup->setObjectName(theId);
     myLayout->addWidget(aGroup);
     addSeparator();
     myLayout->addStretch();
@@ -99,12 +91,11 @@ XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theName)
 /*
  * Searches for already created group with given name.
  */
-XGUI_MenuGroupPanel* XGUI_Workbench::findGroup(const QString& theName)
+XGUI_MenuGroupPanel* XGUI_Workbench::findGroup(const QString& theId)
 {
-  QString aGroupName = theName;
   XGUI_MenuGroupPanel* aPanel;
   foreach(aPanel, myGroups) {
-    if(aPanel->objectName() == theName) {
+    if(aPanel->objectName() == theId) {
       return aPanel;
     }
   }
index 26d7d6918bb486860d3b69eecd5a82521a46d00f..2564f21ce7eaf980f5c7670b1f33200c9b7f604a 100644 (file)
@@ -21,7 +21,7 @@ class XGUI_Workbench : public QWidget
 public:
     XGUI_Workbench(QWidget* theParent);
 
-    XGUI_MenuGroupPanel* addGroup(const QString& theName = "");
+    XGUI_MenuGroupPanel* addGroup(const QString& theId);
     XGUI_MenuGroupPanel* findGroup(const QString& theName);
 
 private slots:
index 7b857b5afa1df0e896cb2baa9302600788b6c6c0..21a334db5fb81e7856e71c34817f302bb9643040 100644 (file)
@@ -27,6 +27,7 @@ XGUI_Workshop::XGUI_Workshop() :
     QObject()
 {
     myMainWindow = new XGUI_MainWindow();
+    myPartSetModule = NULL;
 }
 
 //******************************************************
@@ -40,8 +41,10 @@ void XGUI_Workshop::startApplication()
     initMenu();
     //Initialize event listening
     Event_Loop* aLoop =  Event_Loop::Loop();
-    Event_ID aFeatureId = aLoop->EventByName("Feature");
+    Event_ID aFeatureId = aLoop->EventByName("menu_item");
     aLoop->RegisterListener(this, aFeatureId);
+    Event_ID aPartSetId = aLoop->EventByName("partset_module");
+    aLoop->RegisterListener(this, aPartSetId);
     activateModule();
     myMainWindow->show();
 }
@@ -52,7 +55,7 @@ void XGUI_Workshop::initMenu()
     XGUI_Workbench* aPage = addWorkbench(tr("GEN_MENU_TITLE"));
 
     // File commands group
-    XGUI_MenuGroupPanel* aGroup = aPage->addGroup();
+    XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default");
 
     XGUI_Command* aCommand;
 
@@ -100,10 +103,10 @@ XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
 //******************************************************
 void XGUI_Workshop::ProcessEvent(const Event_Message* theMessage)
 {
-  const Config_FeatureMessage* aMsg =
+  const Config_FeatureMessage* aFeatureMsg =
       dynamic_cast<const Config_FeatureMessage*>( theMessage );
-  if(aMsg) {
-    addFeature(aMsg);
+  if(aFeatureMsg) {
+    addFeature(aFeatureMsg);
     return;
   }
   #ifdef _DEBUG
@@ -118,27 +121,35 @@ void XGUI_Workshop::ProcessEvent(const Event_Message* theMessage)
  */
 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
 {
-  XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
-  XGUI_Workbench* aPage = aMenuBar->findWorkbench(tr( "GEN_MENU_TITLE" ) + "_Workbench");
-  if(!aPage) {
+  if(!theMessage) {
     #ifdef _DEBUG
-    qDebug() << "XGUI_Workshop::ProcessEvent: "
-             << "Creating a workbench " << tr( "GEN_MENU_TITLE" );
+    qDebug() << "XGUI_Workshop::addFeature: NULL message.";
     #endif
-    aPage = addWorkbench(tr( "GEN_MENU_TITLE" ));
+    return;
+  }
+  //Find or create Workbench
+  XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+  QString aWchName = QString::fromStdString(theMessage->workbenchId());
+  XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
+  if(!aPage) {
+    aPage = addWorkbench(aWchName);
   }
-  QString aGroupName = QString::fromStdString(theMessage->m_group);
-  QString aFeatureId = QString::fromStdString(theMessage->m_id);
+  //Find or create Group
+  QString aGroupName = QString::fromStdString(theMessage->groupId());
   XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
   if(!aGroup) {
     aGroup = aPage->addGroup(aGroupName);
   }
-  XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
-    QString::fromStdString(theMessage->m_text),
-    QString::fromStdString(theMessage->m_tooltip),
-    QIcon(theMessage->m_icon.c_str())
+  //Create feature...
+  QString aFeatureId = QString::fromStdString(theMessage->id());
+  XGUI_Command* aCommand = aGroup->addFeature(
+    QString::fromStdString(theMessage->id()),
+    QString::fromStdString(theMessage->text()),
+    QString::fromStdString(theMessage->tooltip()),
+    QIcon(theMessage->icon().c_str())
     //TODO(sbh): QKeySequence
   );
+  myPartSetModule->featureCreated(aCommand);
 }
 
 //******************************************************
@@ -234,11 +245,10 @@ XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
 //******************************************************
 bool XGUI_Workshop::activateModule()
 {
-    // Test of modules loading
-    XGUI_Module* aModule = loadModule("PartSet");
-    if (!aModule)
-        return false;
-    aModule->createFeatures();
-    return true;
+  myPartSetModule = loadModule("PartSet");
+  if (!myPartSetModule)
+    return false;
+  myPartSetModule->createFeatures();
+  return true;
 }
 
index e6aa9970758c5918f38437c2c8ddaa97b9c1bae9..c84925f6c8cc2760a1568a3f06a078a41b288bdd 100644 (file)
@@ -51,6 +51,7 @@ private:
     bool activateModule();
 
     XGUI_MainWindow* myMainWindow;
+    XGUI_Module* myPartSetModule;
 };
 
 #endif