From: sbh Date: Thu, 3 Apr 2014 14:34:38 +0000 (+0400) Subject: Xml --> Widget processing added for "value" (spinbox) entities. X-Git-Tag: V_0.1~42 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a002dc2fe33da6b7ab8e0faff3b6b591efaf17b0;p=modules%2Fshaper.git Xml --> Widget processing added for "value" (spinbox) entities. --- diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index e971c39a0..8e6369fa3 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -11,6 +11,9 @@ SET(PROJECT_HEADERS Config_XMLReader.h Config_ModuleReader.h Config_FeatureReader.h + Config_WidgetAPI.h + Config_WidgetReader.h + Config_WidgetMessage.h ) SET(PROJECT_SOURCES @@ -18,6 +21,9 @@ SET(PROJECT_SOURCES Config_XMLReader.cpp Config_ModuleReader.cpp Config_FeatureReader.cpp + Config_WidgetAPI.cpp + Config_WidgetReader.cpp + Config_WidgetMessage.cpp ) SET(XML_RESOURCES diff --git a/src/Config/Config_FeatureMessage.h b/src/Config/Config_FeatureMessage.h index ba0c64c7b..1309ae898 100644 --- a/src/Config/Config_FeatureMessage.h +++ b/src/Config/Config_FeatureMessage.h @@ -1,9 +1,9 @@ #ifndef CONFIG_MESSAGE_H #define CONFIG_MESSAGE_H -#include "Config.h" - +#include #include + #include /* @@ -27,6 +27,9 @@ public: //const Event_ID theID, const void* theSender = 0 Config_FeatureMessage(const Event_ID theId, const void* theParent = 0); + //TODO(sbh): Implement static method to extract event id [SEID] + //static const char* eventId() { return ""; } + //Auto-generated getters/setters const std::string& icon() const; const std::string& id() const; diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 73a5c07fb..1cb2ef83d 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -5,87 +5,42 @@ * Author: sbh */ +#include +#include #include - +#include #include #include #include +#include + +#include #ifdef _DEBUG #include #endif -//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* _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"; - -Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile) - : Config_XMLReader(theXmlFile), - myFetchWidgetCfg(false) -{ - myLibraryName = ""; - -#ifdef _DEBUG - if (!Event_Loop::loop()) { - std::cout << "Config_FeatureReader::importWorkbench: " - << "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) + myLibraryName(theLibraryName) { -#ifdef _DEBUG - if (!Event_Loop::loop()) { - std::cout << "Config_FeatureReader::importWorkbench: " - << "No event loop registered" << std::endl; - } -#endif } Config_FeatureReader::~Config_FeatureReader() { } -std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName) -{ - myFetchWidgetCfg = true; - readAll(); - myFetchWidgetCfg = false; - return myWidgetCfg; -} - void Config_FeatureReader::processNode(xmlNodePtr theNode) { - static Event_ID aMenuItemEvent = Event_Loop::eventByName("RegisterFeature"); + static Event_ID aMenuItemEvent = Event_Loop::eventByName("FeatureEvent"); if (isNode(theNode, NODE_FEATURE, NULL)) { - if (myFetchWidgetCfg) { - xmlBufferPtr buffer = xmlBufferCreate(); - int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1); - myWidgetCfg = std::string((char*) buffer->content); - } else { - Event_Loop* aEvLoop = Event_Loop::loop(); - Config_FeatureMessage aMessage(aMenuItemEvent, this); - fillFeature(theNode, aMessage); - aEvLoop->send(aMessage); - } + Event_Loop* aEvLoop = Event_Loop::loop(); + Config_FeatureMessage aMessage(aMenuItemEvent, this); + fillFeature(theNode, aMessage); + aEvLoop->send(aMessage); } //The m_last* variables always defined before fillFeature() call. XML is a tree. if (isNode(theNode, NODE_GROUP, NULL)) { diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index cb16d9ea2..117e8bd6c 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -8,30 +8,31 @@ #ifndef CONFIG_FEATUREREADER_H_ #define CONFIG_FEATUREREADER_H_ +#include #include +#include + + +class Config_FeatureMessage; + 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); + const std::string& theLibraryName = ""); 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); +private: std::string myLastWorkbench; std::string myLastGroup; std::string myLibraryName; - - bool myFetchWidgetCfg; - std::string myWidgetCfg; }; #endif /* CONFIG_FEATUREREADER_H_ */ diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h new file mode 100644 index 000000000..107ba9ec7 --- /dev/null +++ b/src/Config/Config_Keywords.h @@ -0,0 +1,38 @@ +/* + * Config_Keywords.h + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + +#ifndef CONFIG_KEYWORDS_H_ +#define CONFIG_KEYWORDS_H_ + +/* + * Hardcoded xml entities of plugin-*.xml + */ +const static char* NODE_WORKBENCH = "workbench"; +const static char* NODE_GROUP = "group"; +const static char* NODE_FEATURE = "feature"; +const static char* NODE_WIDGET = "value"; + +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"; + +/* + * Hardcoded xml entities of plugins.xml + */ +const static char* NODE_PLUGIN = "plugin"; +const static char* NODE_PLUGINS = "plugins"; + +const static char* PLUGINS_MODULE = "module"; +const static char* PLUGIN_CONFIG = "configuration"; +const static char* PLUGIN_LIBRARY = "library"; + +#endif /* CONFIG_KEYWORDS_H_ */ diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 85e653c7e..d77e6b830 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -5,6 +5,7 @@ * Author: sbh */ +#include #include #include @@ -15,15 +16,7 @@ #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"), myIsAutoImport(false) diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index 4b59f622e..5a19c24c0 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -8,9 +8,12 @@ #ifndef CONFIG_MODULEREADER_H_ #define CONFIG_MODULEREADER_H_ +#include #include #include +#include + class CONFIG_EXPORT Config_ModuleReader: public Config_XMLReader { diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp new file mode 100644 index 000000000..38b4476ad --- /dev/null +++ b/src/Config/Config_WidgetAPI.cpp @@ -0,0 +1,83 @@ +/* + * Config_WidgetAPI.cpp + * + * Created on: Apr 1, 2014 + * Author: sbh + */ + +#include + +#include +#include + + +Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml) +{ + myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str()); + myCurrentNode = NULL; +} + + +Config_WidgetAPI::~Config_WidgetAPI() +{ + xmlFreeDoc(myDoc); +} + +void Config_WidgetAPI::reset() +{ + xmlNodePtr aRoot = xmlDocGetRootElement(myDoc); + if(aRoot) { + myCurrentNode = aRoot->children; + } + +} + +bool Config_WidgetAPI::nextWidget() +{ + myCurrentNode = myCurrentNode->next; + return myCurrentNode != NULL; +} + +std::string Config_WidgetAPI::widgetType() +{ + std::string result = ""; + if(myCurrentNode) { + result = std::string((char *) myCurrentNode->name); + } + return result; +} + +std::string Config_WidgetAPI::getProperty(const char* thePropName) +{ + std::string result = ""; + char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName); + if (!aPropChars || aPropChars[0] == 0) + return result; + result = std::string(aPropChars); + return result; +} + +bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* 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_WidgetAPI.h b/src/Config/Config_WidgetAPI.h new file mode 100644 index 000000000..0bcb4a454 --- /dev/null +++ b/src/Config/Config_WidgetAPI.h @@ -0,0 +1,49 @@ +/* + * Config_WidgetAPI.h + * + * Created on: Apr 1, 2014 + * Author: sbh + */ + +#ifndef CONFIG_WIDGETAPI_H_ +#define CONFIG_WIDGETAPI_H_ + +#include + +#include +#include + +//>> Forward declaration of xmlNodePtr. +typedef struct _xmlNode xmlNode; +typedef xmlNode *xmlNodePtr; +struct _xmlNode; +//<< + +//>> Forward declaration of xmlDocPtr. +typedef struct _xmlDoc xmlDoc; +typedef xmlDoc *xmlDocPtr; +struct _xmlDoc; +//<< + + +class CONFIG_EXPORT Config_WidgetAPI +{ +public: + Config_WidgetAPI(std::string theRawXml); + virtual ~Config_WidgetAPI(); + + void reset(); + bool nextWidget(); + std::string widgetType(); + std::string getProperty(const char* thePropName); + +protected: + bool isNode(xmlNodePtr theNode, const char* name, ...); + +private: + xmlDocPtr myDoc; + xmlNodePtr myCurrentNode; + +}; + +#endif /* CONFIG_WIDGETAPI_H_ */ diff --git a/src/Config/Config_WidgetMessage.cpp b/src/Config/Config_WidgetMessage.cpp new file mode 100644 index 000000000..846359f39 --- /dev/null +++ b/src/Config/Config_WidgetMessage.cpp @@ -0,0 +1,38 @@ +/* + * Config_WidgetMessage.cpp + * + * Created on: Mar 21, 2014 + * Author: sbh + */ + +#include + +Config_WidgetMessage::Config_WidgetMessage(const Event_ID theId, const void* theParent) + : Event_Message(theId, theParent) +{ + +} + +Config_WidgetMessage::~Config_WidgetMessage() +{ +} + +const std::string& Config_WidgetMessage::featureId() const +{ + return myFeatureId; +} + +void Config_WidgetMessage::setFeatureId(const std::string& theFeatureId) +{ + myFeatureId = theFeatureId; +} + +const std::string& Config_WidgetMessage::xmlRepresentation() const +{ + return myXMLRepr; +} + +void Config_WidgetMessage::setXmlRepresentation(const std::string& theXmlRep) +{ + myXMLRepr = theXmlRep; +} diff --git a/src/Config/Config_WidgetMessage.h b/src/Config/Config_WidgetMessage.h new file mode 100644 index 000000000..1aa00d86d --- /dev/null +++ b/src/Config/Config_WidgetMessage.h @@ -0,0 +1,31 @@ +/* + * Config_WidgetMessage.h + * + * Created on: Mar 21, 2014 + * Author: sbh + */ + +#ifndef PARTSET_MESSAGE_H_ +#define PARTSET_MESSAGE_H_ + +#include + +#include +#include + +class CONFIG_EXPORT Config_WidgetMessage: public Event_Message +{ +public: + Config_WidgetMessage(const Event_ID theId, const void* theParent = 0); + virtual ~Config_WidgetMessage(); + + const std::string& featureId() const; + const std::string& xmlRepresentation() const; + void setFeatureId(const std::string& featureId); + void setXmlRepresentation(const std::string& xmlRepresentation); + + std::string myFeatureId; + std::string myXMLRepr; +}; + +#endif /* PARTSET_MESSAGE_H_ */ diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp new file mode 100644 index 000000000..3558c6596 --- /dev/null +++ b/src/Config/Config_WidgetReader.cpp @@ -0,0 +1,49 @@ +/* + * Config_WidgetReader.cpp + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + +#include +#include + +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + + +Config_WidgetReader::Config_WidgetReader(const std::string& theXmlFile) + : Config_XMLReader(theXmlFile) + +{ +} + +Config_WidgetReader::~Config_WidgetReader() +{ +} + +std::string Config_WidgetReader::featureWidgetCfg(std::string theFeatureName) +{ + return myWidgetCache[theFeatureName]; +} + +void Config_WidgetReader::processNode(xmlNodePtr theNode) +{ + if (isNode(theNode, NODE_FEATURE, NULL)) { + xmlBufferPtr buffer = xmlBufferCreate(); + int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1); + std::string aNodeName = getProperty(theNode, _ID); + myWidgetCache[aNodeName] = std::string((char*) buffer->content); + } +} + +bool Config_WidgetReader::processChildren(xmlNodePtr theNode) +{ + return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL); +} diff --git a/src/Config/Config_WidgetReader.h b/src/Config/Config_WidgetReader.h new file mode 100644 index 000000000..58fd904b0 --- /dev/null +++ b/src/Config/Config_WidgetReader.h @@ -0,0 +1,35 @@ +/* + * Config_WidgetReader.h + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + +#ifndef CONFIG_WIDGETREADER_H_ +#define CONFIG_WIDGETREADER_H_ + +#include +#include + +#include +#include + + +class CONFIG_EXPORT Config_WidgetReader: public Config_XMLReader +{ +public: + Config_WidgetReader(const std::string& theXmlFile); + virtual ~Config_WidgetReader(); + + std::string featureWidgetCfg(std::string theFeatureName); + +protected: + void processNode(xmlNodePtr theNode); + bool processChildren(xmlNodePtr theNode); + +private: + std::map myWidgetCache; + +}; + +#endif /* CONFIG_WIDGETREADER_H_ */ diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 1b206af82..6abf8ea7b 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -23,28 +23,15 @@ #endif Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) + : myXmlDoc(NULL) { - std::string prefix; - /* the problem: application may be launched using python execuable, to use environment variable - (at least for the current moment) - //Get path to *.xml files (typically ./bin/../plugins/) -#ifdef WIN32 - HMODULE hModule = GetModuleHandleW(NULL); - WCHAR wchar_path[MAX_PATH]; - GetModuleFileNameW(hModule, wchar_path, MAX_PATH); - char char_path[MAX_PATH]; - char DefChar = ' '; - WideCharToMultiByte(CP_ACP, 0, wchar_path, -1, char_path, MAX_PATH, &DefChar, NULL); - prefix = std::string(char_path); - //chop "bin\XGUI.exe" - unsigned found = prefix.rfind("bin"); - if (found != std::string::npos) - prefix.replace(found, prefix.length(), "plugins\\"); -#else - //TODO(sbh): Find full path to binary on linux - prefix = "../plugins/"; -#endif - */ + std::string prefix = ""; + /* + * Get path to *.xml files (typically ./bin/../plugins/) + + * the problem: application may be launched using python executable, + * to use environment variable (at least for the current moment) + */ char* anEnv = getenv("NEW_GEOM_CONFIG_FILE"); if (anEnv) { prefix = std::string(anEnv) + "/"; @@ -55,12 +42,13 @@ Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) Config_XMLReader::~Config_XMLReader() { + xmlFreeDoc(myXmlDoc); } /* - * Read all nodes (recursively if processChildren() is true - * for a node). For each read node the processNode will be - * called. + * Read all nodes in associated xml file, + * recursively if processChildren(xmlNode) is true for the xmlNode. + * For each read node the processNode will be called. */ void Config_XMLReader::readAll() { @@ -84,25 +72,28 @@ void Config_XMLReader::processNode(xmlNodePtr aNode) /* * Defines which nodes should be processed recursively. Virtual. - * The default implementation to read all nodes. + * The default implementation is to read all nodes. */ bool Config_XMLReader::processChildren(xmlNodePtr aNode) { return true; } +/* + * + */ xmlNodePtr Config_XMLReader::findRoot() { - xmlDocPtr aDoc; - aDoc = xmlParseFile(myDocumentPath.c_str()); - if (aDoc == NULL) { + myXmlDoc = xmlParseFile(myDocumentPath.c_str()); + if (myXmlDoc == NULL) { #ifdef _DEBUG std::cout << "Config_XMLReader::import: " << "Document " << myDocumentPath << " is not parsed successfully." << std::endl; #endif return NULL; } - xmlNodePtr aRoot = xmlDocGetRootElement(aDoc); + + xmlNodePtr aRoot = xmlDocGetRootElement(myXmlDoc); #ifdef _DEBUG if(aRoot == NULL) { std::cout << "Config_XMLReader::import: " << "Error: empty document"; @@ -166,7 +157,7 @@ bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName, ...) 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 + char *anArg = va_arg (args, char*); // get next argument if (anArg == NULL) break; if (!xmlStrcmp(aName, (const xmlChar *) anArg)) { diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index bdff8a00e..01ad541a4 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -8,17 +8,28 @@ #ifndef CONFIG_XMLREADER_H_ #define CONFIG_XMLREADER_H_ -#include "Config.h" -#include "Config_FeatureMessage.h" +#include -#include #include +#include -//Forward declaration for xmlNodePtr. +//>> Forward declaration of xmlNodePtr. typedef struct _xmlNode xmlNode; typedef xmlNode *xmlNodePtr; struct _xmlNode; +//<< +//>> Forward declaration of xmlDocPtr. +typedef struct _xmlDoc xmlDoc; +typedef xmlDoc *xmlDocPtr; +struct _xmlDoc; +//<< + +/* + * Base class for all libxml readers. Provides high-level API + * for all xml operations. + * + */ class CONFIG_EXPORT Config_XMLReader { public: @@ -44,8 +55,9 @@ protected: */ bool isNode(xmlNodePtr theNode, const char* name, ...); -private: +protected: std::string myDocumentPath; + xmlDocPtr myXmlDoc; }; #endif /* CONFIG_XMLREADER_H_ */ diff --git a/src/Config/plugin-PartSet.xml b/src/Config/plugin-PartSet.xml index 2785659ef..fff9a54aa 100644 --- a/src/Config/plugin-PartSet.xml +++ b/src/Config/plugin-PartSet.xml @@ -10,8 +10,8 @@ - - + + diff --git a/src/Model/Model_PluginManager.cxx b/src/Model/Model_PluginManager.cxx index c4e28665d..daeb60176 100644 --- a/src/Model/Model_PluginManager.cxx +++ b/src/Model/Model_PluginManager.cxx @@ -36,7 +36,8 @@ boost::shared_ptr Model_PluginManager::createFeature(string th Model_PluginManager::Model_PluginManager() { myPluginsInfoLoaded = false; - static Event_ID aFeatureEvent = Event_Loop::eventByName("RegisterFeature"); + //TODO(sbh): Implement static method to extract event id [SEID] + static Event_ID aFeatureEvent = Event_Loop::eventByName("FeatureEvent"); ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr(this)); // register the configuration reading listener diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 0ed6de6f1..bb9960d9a 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -6,12 +6,10 @@ 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 diff --git a/src/PartSet/PartSet_Message.cpp b/src/PartSet/PartSet_Message.cpp deleted file mode 100644 index 7ac2400e3..000000000 --- a/src/PartSet/PartSet_Message.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 deleted file mode 100644 index 9d15f0863..000000000 --- a/src/PartSet/PartSet_Message.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 ad4add3f1..7f87997da 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,14 +1,18 @@ -#include "PartSet_Module.h" +#include +#include #include -#include - +#include #include +#include + +#include +#include + +#ifdef _DEBUG +#include +#endif -#include -#include -#include -#include /*!Create and return new instance of XGUI_Module*/ extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop) @@ -45,9 +49,17 @@ void PartSet_Module::onCommandTriggered() { Config_ModuleReader aModuleReader = Config_ModuleReader(); aModuleReader.readAll(); -// std::string aPluginName = aModuleReader.plugins().front(); -// Config_FeatureReader* aReader = new Config_FeatureReader(aPluginName); -// XGUI_Command* aCmd = dynamic_cast(sender()); -// std::string aXMLWidgetCfg = aReader->featureWidgetCfg(aCmd->getId().toStdString()); -// delete aReader; + std::map aPluginMap = aModuleReader.plugins(); + std::string aPluginName = aPluginMap["PartSetPlugin"]; + Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName); + aWdgReader.readAll(); + XGUI_Command* aCmd = dynamic_cast(sender()); + std::string aCmdId = aCmd->getId().toStdString(); + std::string aXMLWidgetCfg = aWdgReader.featureWidgetCfg(aCmdId); + //TODO(sbh): Implement static method to extract event id [SEID] + static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent"); + Config_WidgetMessage aMessage(aModuleEvent, this); + aMessage.setFeatureId(aCmdId); + aMessage.setXmlRepresentation(aXMLWidgetCfg); + Event_Loop::loop()->send(aMessage); } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index db601db2f..913616725 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -22,7 +22,6 @@ public slots: void onCommandTriggered(); private: - QString myMenuXML; XGUI_Workshop* myWorkshop; }; diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index e749048fc..5ac769adc 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -19,6 +19,7 @@ SET(PROJECT_HEADERS XGUI_RubberBand.h XGUI_Constants.h XGUI_ViewBackground.h + XGUI_WidgetFactory.h ) SET(PROJECT_AUTOMOC @@ -39,6 +40,7 @@ SET(PROJECT_SOURCES XGUI_Viewer.cpp XGUI_RubberBand.cpp XGUI_ViewBackground.cpp + XGUI_WidgetFactory.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 7ab8aafdf..6841b795e 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -129,27 +129,33 @@ void XGUI_MainWindow::fillObjectBrowser() void XGUI_MainWindow::addPropertyPanel() { QDockWidget* aPropPanel = new QDockWidget(this); - aPropPanel->setWindowTitle("Point"); + aPropPanel->setWindowTitle("Property Panel"); QWidget* aContent = new QWidget(aPropPanel); QVBoxLayout* aMainLay = new QVBoxLayout(aContent); aMainLay->setContentsMargins(3, 3, 3, 3); aPropPanel->setWidget(aContent); - /*QWidget* aNameWgt = new QWidget(aContent); - QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt); - aNameLay->setContentsMargins(0,0,0,0); - aMainLay->addWidget(aNameWgt); + QWidget* aCustomWidget = new QWidget(aContent); + aCustomWidget->setObjectName("PropertyPanelWidget"); + aMainLay->addWidget(aCustomWidget); - aNameLay->addWidget(new QLabel("Name", aNameWgt)); - aNameLay->addWidget(new QLineEdit(aNameWgt));*/ + /* + QWidget* aNameWgt = new QWidget(aContent); + QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt); + aNameLay->setContentsMargins(0,0,0,0); + aMainLay->addWidget(aNameWgt); + aNameLay->addWidget(new QLabel("Name", aNameWgt)); + aNameLay->addWidget(new QLineEdit(aNameWgt)); + */ + +/* Moved into PartSetModule by sbh QComboBox* aCombo = new QComboBox(aContent); aCombo->addItem("By coordinates"); aMainLay->addWidget(aCombo); QWidget* aGrpBox1 = new QWidget(aContent); - //aGrpBox1->setFlat(true); QFormLayout* aFrmLay = new QFormLayout(aGrpBox1); aFrmLay->setContentsMargins(0, 6, 0, 0); aMainLay->addWidget(aGrpBox1); @@ -165,24 +171,27 @@ void XGUI_MainWindow::addPropertyPanel() aLbl = new QLabel(aGrpBox1); aLbl->setPixmap(QPixmap(":pictures/z_point.png")); aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + */ - /* aGrpBox1 = new QGroupBox("Normal vector", aContent); - aGrpBox1->setFlat(true); - aFrmLay = new QFormLayout(aGrpBox1); - aFrmLay->setContentsMargins(0, 6, 0, 0); - aMainLay->addWidget(aGrpBox1); + /* + aGrpBox1 = new QGroupBox("Normal vector", aContent); + aGrpBox1->setFlat(true); + aFrmLay = new QFormLayout(aGrpBox1); + aFrmLay->setContentsMargins(0, 6, 0, 0); + aMainLay->addWidget(aGrpBox1); - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/x_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/x_size.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/y_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/y_size.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/z_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));*/ + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/z_size.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + */ aMainLay->addStretch(1); diff --git a/src/XGUI/XGUI_WidgetFactory.cpp b/src/XGUI/XGUI_WidgetFactory.cpp new file mode 100644 index 000000000..9cc69af89 --- /dev/null +++ b/src/XGUI/XGUI_WidgetFactory.cpp @@ -0,0 +1,92 @@ +/* + * XGUI_WidgetFactory.cpp + * + * Created on: Apr 3, 2014 + * Author: sbh + */ + +#include + +#include + +#include +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + +XGUI_WidgetFactory::XGUI_WidgetFactory(const std::string& theXml) +{ + myWidgetApi = new Config_WidgetAPI(theXml); +} + +XGUI_WidgetFactory::~XGUI_WidgetFactory() +{ +} + +void XGUI_WidgetFactory::fillWidget(QWidget* theParent) +{ + myWidgetApi->reset(); + if (theParent->layout()) { + theParent->layout()->deleteLater(); + } + + QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent); + do { + std::string aWdgType = myWidgetApi->widgetType(); + QWidget* aWidget = NULL; + if (aWdgType == "value") { + aWidget = valueWidget(); + } else { + #ifdef _DEBUG + qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type"; + #endif + } + if (aWidget) { + aWidgetLay->addWidget(aWidget); + } + } while(myWidgetApi->nextWidget()); + aWidgetLay->addStretch(1); + theParent->setLayout(aWidgetLay); +} + +QWidget* XGUI_WidgetFactory::valueWidget() +{ + QWidget* result = new QWidget(); + QHBoxLayout* aControlLay = new QHBoxLayout(result); + QString aLabelVal = qs(myWidgetApi->getProperty("label")); + QLabel* aLabel = new QLabel(aLabelVal); + aControlLay->addWidget(aLabel); + QDoubleSpinBox* aBox = new QDoubleSpinBox(result); + bool isOk = false; + double aMinVal = qs(myWidgetApi->getProperty("min")).toDouble(&isOk); + if (isOk) { + aBox->setMinimum(aMinVal); + } + double aMaxVal = qs(myWidgetApi->getProperty("max")).toDouble(&isOk); + if (isOk) { + aBox->setMaximum(aMaxVal); + } + double aStepVal = qs(myWidgetApi->getProperty("step")).toDouble(&isOk); + if (isOk) { + aBox->setSingleStep(aStepVal); + } + double aDefVal = qs(myWidgetApi->getProperty("default")).toDouble(&isOk); + if (isOk) { + aBox->setValue(aDefVal); + } + aControlLay->addWidget(aBox); + aControlLay->addStretch(); + + result->setLayout(aControlLay); + return result; +} + +QString XGUI_WidgetFactory::qs(const std::string& theStdString) const +{ + return QString::fromStdString(theStdString); +} diff --git a/src/XGUI/XGUI_WidgetFactory.h b/src/XGUI/XGUI_WidgetFactory.h new file mode 100644 index 000000000..cd02f6382 --- /dev/null +++ b/src/XGUI/XGUI_WidgetFactory.h @@ -0,0 +1,34 @@ +/* + * XGUI_WidgetFactory.h + * + * Created on: Apr 3, 2014 + * Author: sbh + */ + +#ifndef XGUI_WIDGETFACTORY_H_ +#define XGUI_WIDGETFACTORY_H_ + +#include +#include + +class QWidget; +class Config_WidgetAPI; + +class XGUI_WidgetFactory +{ +public: + XGUI_WidgetFactory(const std::string&); + virtual ~XGUI_WidgetFactory(); + + void fillWidget(QWidget* theParent); + +protected: + QWidget* valueWidget(); + +private: + QString qs(const std::string& theStdString) const; + + Config_WidgetAPI* myWidgetApi; +}; + +#endif /* XGUI_WIDGETFACTORY_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 16d693278..28519d6de 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -7,9 +7,11 @@ #include "XGUI_Workbench.h" #include "XGUI_Workshop.h" #include "XGUI_Viewer.h" +#include "XGUI_WidgetFactory.h" -#include #include +#include +#include #include #include @@ -44,9 +46,10 @@ void XGUI_Workshop::startApplication() initMenu(); //Initialize event listening Event_Loop* aLoop = Event_Loop::loop(); - Event_ID aFeatureId = aLoop->eventByName("RegisterFeature"); + //TODO(sbh): Implement static method to extract event id [SEID] + Event_ID aFeatureId = aLoop->eventByName("FeatureEvent"); aLoop->registerListener(this, aFeatureId); - Event_ID aPartSetId = aLoop->eventByName("partset_module"); + Event_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent"); aLoop->registerListener(this, aPartSetId); activateModule(); myMainWindow->show(); @@ -107,11 +110,18 @@ XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName) //****************************************************** void XGUI_Workshop::processEvent(const Event_Message* theMessage) { - const Config_FeatureMessage* aFeatureMsg = dynamic_cast(theMessage); + const Config_FeatureMessage* aFeatureMsg = + dynamic_cast(theMessage); if (aFeatureMsg) { addFeature(aFeatureMsg); return; } + const Config_WidgetMessage* aPartSetMsg = dynamic_cast(theMessage); + if (aPartSetMsg) { + fillPropertyPanel(aPartSetMsg); + return; + } + #ifdef _DEBUG qDebug() << "XGUI_Workshop::ProcessEvent: " << "Catch message, but it can not be processed."; @@ -154,6 +164,23 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) myPartSetModule->featureCreated(aCommand); } +/* + * + */ +void XGUI_Workshop::fillPropertyPanel(const Config_WidgetMessage* theMessage) +{ + QWidget* aPropWidget = myMainWindow->findChild("PropertyPanelWidget"); + if (!aPropWidget) { + #ifdef _DEBUG + qDebug() << "XGUI_Workshop::fillPropertyPanel: " << "Unable to find property panel"; + #endif + return; + } + std::string aXml = theMessage->xmlRepresentation(); + XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aXml); + aFactory.fillWidget(aPropWidget); +} + //****************************************************** void XGUI_Workshop::onExit() { @@ -252,4 +279,3 @@ bool XGUI_Workshop::activateModule() myPartSetModule->createFeatures(); return true; } - diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 3e021badd..68300e96b 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -15,6 +15,7 @@ class XGUI_Module; class XGUI_Workbench; class Config_FeatureMessage; +class Config_WidgetMessage; class XGUI_Workshop: public QObject, public Event_Listener { @@ -45,6 +46,7 @@ public slots: protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); + void fillPropertyPanel(const Config_WidgetMessage*); private: void initMenu();