From e607e2c793a83dc30d483e1819f44c3497a08555 Mon Sep 17 00:00:00 2001 From: Sergey Belash Date: Fri, 21 Mar 2014 19:56:15 +0400 Subject: [PATCH] Advanced version of plugin reader with ability to extract xml information about feature widget --- src/Config/Config_FeatureReader.cpp | 65 ++++++++++++------ src/Config/Config_FeatureReader.h | 7 ++ src/Config/Config_Message.cpp | 101 ++++++++++++++++++++++++++-- src/Config/Config_Message.h | 27 +++++++- src/Config/Config_ModuleReader.cpp | 19 ++++-- src/Config/Config_XMLReader.cpp | 26 +++++-- src/Config/Config_XMLReader.h | 10 ++- src/Config/plugin-PartSet.xml | 16 +++-- src/Event/Event_Loop.cxx | 2 +- src/Event/Event_Message.cxx | 2 +- src/Event/Event_Message.hxx | 4 +- src/PartSet/CMakeLists.txt | 9 ++- src/PartSet/PartSet_Message.cpp | 20 ++++++ src/PartSet/PartSet_Message.h | 24 +++++++ src/PartSet/PartSet_Module.cpp | 24 ++++++- src/PartSet/PartSet_Module.h | 11 ++- src/XGUI/XGUI_MainMenu.cpp | 50 ++++++-------- src/XGUI/XGUI_MainMenu.h | 7 +- src/XGUI/XGUI_Module.h | 8 +-- src/XGUI/XGUI_Workbench.cpp | 19 ++---- src/XGUI/XGUI_Workbench.h | 2 +- src/XGUI/XGUI_Workshop.cpp | 56 ++++++++------- src/XGUI/XGUI_Workshop.h | 1 + 23 files changed, 382 insertions(+), 128 deletions(-) create mode 100644 src/PartSet/PartSet_Message.cpp create mode 100644 src/PartSet/PartSet_Message.h diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 0eb2bfdaa..53c0d6c88 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -18,20 +18,24 @@ //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); + } diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index 76d7635c0..bbc25ba27 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -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_ */ diff --git a/src/Config/Config_Message.cpp b/src/Config/Config_Message.cpp index ea701ffd5..8dd2b4131 100644 --- a/src/Config/Config_Message.cpp +++ b/src/Config/Config_Message.cpp @@ -1,17 +1,110 @@ /* * */ - #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; +} diff --git a/src/Config/Config_Message.h b/src/Config/Config_Message.h index 2e3d567a8..5f39cbc01 100644 --- a/src/Config/Config_Message.h +++ b/src/Config/Config_Message.h @@ -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 diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index e09904422..1a6d1c7ce 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -15,6 +15,17 @@ #include #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) diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index adce851dc..c235c3355 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -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; } diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 9761ada43..7a42fcb09 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -12,12 +12,14 @@ #include "Config_Message.h" #include +#include //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; diff --git a/src/Config/plugin-PartSet.xml b/src/Config/plugin-PartSet.xml index d3d7d4cb2..2785659ef 100644 --- a/src/Config/plugin-PartSet.xml +++ b/src/Config/plugin-PartSet.xml @@ -1,12 +1,18 @@ - - - + + + - - + + + + + + + + diff --git a/src/Event/Event_Loop.cxx b/src/Event/Event_Loop.cxx index e997c8b8f..d5981a823 100644 --- a/src/Event/Event_Loop.cxx +++ b/src/Event/Event_Loop.cxx @@ -35,7 +35,7 @@ void Event_Loop::Send(Event_Message& theMessage) // TO DO: make it in thread and wit husage of semaphores map > >::iterator aFindID = - myListeners.find(theMessage.ID().EventText()); + myListeners.find(theMessage.EventID().EventText()); if (aFindID != myListeners.end()) { map >::iterator aFindSender = aFindID->second.find(theMessage.Sender()); diff --git a/src/Event/Event_Message.cxx b/src/Event/Event_Message.cxx index e9dc311b3..53186da31 100644 --- a/src/Event/Event_Message.cxx +++ b/src/Event/Event_Message.cxx @@ -5,6 +5,6 @@ #include Event_Message::Event_Message(const Event_ID theID, const void* theSender) : -myID(theID), mySender((void*)theSender) +myEventId(theID), mySender((void*)theSender) { } diff --git a/src/Event/Event_Message.hxx b/src/Event/Event_Message.hxx index 4e5337c83..bb700a75d 100644 --- a/src/Event/Event_Message.hxx +++ b/src/Event/Event_Message.hxx @@ -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;} diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index b8c89c47c..0ed6de6f1 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -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 index 000000000..0c3d72cbe --- /dev/null +++ b/src/PartSet/PartSet_Message.cpp @@ -0,0 +1,20 @@ +/* + * PartSet_Message.cpp + * + * Created on: Mar 21, 2014 + * Author: sbh + */ + +#include + +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 index 000000000..4ceccc1a3 --- /dev/null +++ b/src/PartSet/PartSet_Message.h @@ -0,0 +1,24 @@ +/* + * PartSet_Message.h + * + * Created on: Mar 21, 2014 + * Author: sbh + */ + +#ifndef PARTSET_MESSAGE_H_ +#define PARTSET_MESSAGE_H_ + +#include + +#include + +#include + +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_ */ diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 26d8b7243..6b02152ce 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,6 +1,9 @@ #include "PartSet_Module.h" #include +#include + +#include #include #include @@ -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(sender()); + std::string aXMLWidgetCfg = + aReader->featureWidgetCfg(aCmd->getId().toStdString()); + delete aReader; +} diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 3f792d21f..049e3e424 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -5,20 +5,25 @@ #include "PartSet.h" #include +#include -class Config_FeatureReader; +#include -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; }; diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index f1926acf0..04033692e 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -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(theObjName); - if(aDoc) { - return dynamic_cast(aDoc->widget()); - } - return NULL; -} - - -XGUI_MenuGroupPanel* XGUI_MainMenu::addGroup(int thePageId) -{ - XGUI_Workbench* aPage = dynamic_cast(myMenuTabs[thePageId]->widget()); - return aPage->addGroup(); + return myDesktop->findChild(theObjName); } - diff --git a/src/XGUI/XGUI_MainMenu.h b/src/XGUI/XGUI_MainMenu.h index ca45fe030..3a00d4c66 100644 --- a/src/XGUI/XGUI_MainMenu.h +++ b/src/XGUI/XGUI_MainMenu.h @@ -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; diff --git a/src/XGUI/XGUI_Module.h b/src/XGUI/XGUI_Module.h index e27066743..cfb4d314e 100644 --- a/src/XGUI/XGUI_Module.h +++ b/src/XGUI/XGUI_Module.h @@ -1,17 +1,15 @@ - #ifndef XGUI_Module_H #define XGUI_Module_H -#include -#include -#include - #include +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. diff --git a/src/XGUI/XGUI_Workbench.cpp b/src/XGUI/XGUI_Workbench.cpp index 4661f5791..61da43fa2 100644 --- a/src/XGUI/XGUI_Workbench.cpp +++ b/src/XGUI/XGUI_Workbench.cpp @@ -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; } } diff --git a/src/XGUI/XGUI_Workbench.h b/src/XGUI/XGUI_Workbench.h index 26d7d6918..2564f21ce 100644 --- a/src/XGUI/XGUI_Workbench.h +++ b/src/XGUI/XGUI_Workbench.h @@ -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: diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 7b857b5af..21a334db5 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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( 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; } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index e6aa99707..c84925f6c 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -51,6 +51,7 @@ private: bool activateModule(); XGUI_MainWindow* myMainWindow; + XGUI_Module* myPartSetModule; }; #endif -- 2.39.2