From e2e9a14b1e74a37bf804b665c728ab71cc2f6e26 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 24 Apr 2014 15:59:31 +0400 Subject: [PATCH] Issue #29 processing of "source" tags added --- src/Config/Config_FeatureReader.cpp | 2 ++ src/Config/Config_Keywords.h | 5 ++- src/Config/Config_WidgetReader.cpp | 31 ++++++++++++++----- src/Config/Config_WidgetReader.h | 1 + src/Config/Config_XMLReader.cpp | 18 ++++++----- src/Config/Config_XMLReader.h | 4 ++- src/ConstructionPlugin/CMakeLists.txt | 1 + .../plugin-Construction.xml | 4 +-- src/ConstructionPlugin/point_widget.xml | 5 +++ 9 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 src/ConstructionPlugin/point_widget.xml diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index b9454e04d..1b574cfba 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -60,6 +60,8 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) if (isNode(theNode, NODE_WORKBENCH, NULL)) { myLastWorkbench = getProperty(theNode, _ID); } + //Process SOURCE nodes. + Config_XMLReader::processNode(theNode); } bool Config_FeatureReader::processChildren(xmlNodePtr theNode) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 3c7bb936c..f5bfe19e8 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -14,6 +14,8 @@ const static char* NODE_WORKBENCH = "workbench"; const static char* NODE_GROUP = "group"; const static char* NODE_FEATURE = "feature"; +const static char* NODE_SOURCE = "source"; + //Widgets const static char* WDG_DOUBLEVALUE = "doublevalue"; //Widget containers @@ -24,7 +26,6 @@ const static char* WDG_TOOLBOX_BOX = "box"; const static char* WDG_SWITCH = "switch"; const static char* WDG_SWITCH_CASE = "case"; - const static char* _ID = "id"; //const static char* WORKBENCH_ID = "id"; //const static char* GROUP_ID = "id"; @@ -33,6 +34,8 @@ 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* SOURCE_FILE = "path"; + // doublevalue properties: const static char* DOUBLE_WDG_MIN = "min"; diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp index 8f47a6200..7ba92f996 100644 --- a/src/Config/Config_WidgetReader.cpp +++ b/src/Config/Config_WidgetReader.cpp @@ -39,22 +39,39 @@ std::string Config_WidgetReader::featureDescription(const std::string& theFeatur return myDescriptionCache[theFeatureName]; } + void Config_WidgetReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_FEATURE, NULL)) { - std::string result = ""; std::string aNodeName = getProperty(theNode, _ID); - if (hasChild(theNode)) { - xmlBufferPtr buffer = xmlBufferCreate(); - int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1); - result = std::string((char*) buffer->content); - } - myWidgetCache[aNodeName] = result; + myWidgetCache[aNodeName] = dumpNode(theNode);; myDescriptionCache[aNodeName] = getProperty(theNode, FEATURE_TEXT); } + //Process SOURCE nodes. + Config_XMLReader::processNode(theNode); } bool Config_WidgetReader::processChildren(xmlNodePtr theNode) { return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL); } + +std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode) +{ + std::string result = ""; + if (!hasChild(theNode)) { + return result; + } + xmlNodePtr aChildrenNode = xmlFirstElementChild(theNode); + xmlBufferPtr buffer = xmlBufferCreate(); + if (isNode(aChildrenNode, NODE_SOURCE, NULL)) { + Config_XMLReader aSourceReader = + Config_XMLReader(getProperty(aChildrenNode, SOURCE_FILE)); + xmlNodePtr aSourceRoot = aSourceReader.findRoot(); + int size = xmlNodeDump(buffer, aSourceRoot->doc, aSourceRoot, 0, 1); + } else { + int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1); + } + result = std::string((char*) (buffer->content)); + return result; +} diff --git a/src/Config/Config_WidgetReader.h b/src/Config/Config_WidgetReader.h index ae76cc996..cfc1519a5 100644 --- a/src/Config/Config_WidgetReader.h +++ b/src/Config/Config_WidgetReader.h @@ -27,6 +27,7 @@ public: protected: void processNode(xmlNodePtr theNode); bool processChildren(xmlNodePtr theNode); + std::string dumpNode(xmlNodePtr theNode); private: std::map myWidgetCache; diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 002c9df49..0ac45babf 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include #include #include @@ -61,13 +63,16 @@ void Config_XMLReader::readAll() * The default implementation does nothing. (In debug mode prints * some info) */ -void Config_XMLReader::processNode(xmlNodePtr aNode) +void Config_XMLReader::processNode(xmlNodePtr theNode) { -#ifdef _DEBUG - std::cout << "Config_XMLReader::processNode: " - << aNode->name << " content: " - << aNode->content << std::endl; -#endif + if (isNode(theNode, NODE_SOURCE, NULL)) { + std::string aSourceFile = getProperty(theNode, SOURCE_FILE); + Config_XMLReader aSourceReader = Config_XMLReader(aSourceFile); + readRecursively(aSourceReader.findRoot()); + #ifdef _DEBUG + std::cout << "Config_XMLReader::sourced node: " << aSourceFile << std::endl; + #endif + } } /* @@ -92,7 +97,6 @@ xmlNodePtr Config_XMLReader::findRoot() #endif return NULL; } - xmlNodePtr aRoot = xmlDocGetRootElement(myXmlDoc); #ifdef _DEBUG if(aRoot == NULL) { diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index a44d49364..bcd8ddfdf 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -38,11 +38,13 @@ public: CONFIG_EXPORT void readAll(); +public: + CONFIG_EXPORT xmlNodePtr findRoot(); + protected: virtual void processNode(xmlNodePtr aNode); virtual bool processChildren(xmlNodePtr aNode); - xmlNodePtr findRoot(); void readRecursively(xmlNodePtr theParent); xmlNodePtr node(void* theNode); diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 430ffb9ab..7fe6d649c 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES( SET(XML_RESOURCES plugin-Construction.xml + point_widget.xml ) INSTALL(TARGETS ConstructionPlugin DESTINATION plugins) diff --git a/src/ConstructionPlugin/plugin-Construction.xml b/src/ConstructionPlugin/plugin-Construction.xml index a5e402f06..912d04e0c 100644 --- a/src/ConstructionPlugin/plugin-Construction.xml +++ b/src/ConstructionPlugin/plugin-Construction.xml @@ -2,9 +2,7 @@ - - - + diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml new file mode 100644 index 000000000..920d8e0a5 --- /dev/null +++ b/src/ConstructionPlugin/point_widget.xml @@ -0,0 +1,5 @@ + + + + + -- 2.39.2