From: sbh Date: Mon, 14 Jul 2014 08:24:59 +0000 (+0400) Subject: Advanced processing of the "SOURCE" and "VALIDATOR" nodes: X-Git-Tag: V_0.4.4~185^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b2198f0640fcbd74365265ed8c65936823a75d6;p=modules%2Fshaper.git Advanced processing of the "SOURCE" and "VALIDATOR" nodes: * Support of mixing the "SOURCE" with any other nodes * Support of the "VALIDATOR" nodes in sourced files --- diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp index 7ce67a2e7..f0214657b 100644 --- a/src/Config/Config_WidgetReader.cpp +++ b/src/Config/Config_WidgetReader.cpp @@ -14,6 +14,8 @@ #include #include +#include + #ifdef _DEBUG #include #endif @@ -43,9 +45,9 @@ std::string Config_WidgetReader::featureDescription(const std::string& theFeatur void Config_WidgetReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_FEATURE, NULL)) { - std::string aNodeName = getProperty(theNode, _ID); - myWidgetCache[aNodeName] = dumpNode(theNode); - myDescriptionCache[aNodeName] = getProperty(theNode, FEATURE_TEXT); + myCurrentFeature = getProperty(theNode, _ID); + myWidgetCache[myCurrentFeature] = dumpNode(theNode); + myDescriptionCache[myCurrentFeature] = getProperty(theNode, FEATURE_TEXT); } //Process SOURCE nodes. Config_XMLReader::processNode(theNode); @@ -53,7 +55,38 @@ void Config_WidgetReader::processNode(xmlNodePtr theNode) bool Config_WidgetReader::processChildren(xmlNodePtr theNode) { - return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL); + //Read all nodes recursively, source and validator nodes have no children + return !isNode(theNode, NODE_VALIDATOR, NODE_SOURCE, NULL); +} + +void Config_WidgetReader::resolveSourceNodes(xmlNodePtr theNode) +{ + xmlNodePtr aNode = xmlFirstElementChild(theNode); + std::list aSourceNodes; + while(aNode != NULL) { + if (isNode(aNode, NODE_SOURCE, NULL)) { + Config_XMLReader aSourceReader = Config_XMLReader(getProperty(aNode, SOURCE_FILE)); + xmlNodePtr aSourceRoot = aSourceReader.findRoot(); + if (!aSourceRoot) { + continue; + } + xmlNodePtr aSourceNode = xmlFirstElementChild(aSourceRoot); + xmlNodePtr aTargetNode = xmlDocCopyNodeList(aNode->doc, aSourceNode); + while(aTargetNode != NULL) { + xmlNodePtr aNextNode = xmlNextElementSibling(aTargetNode); + xmlAddPrevSibling(aNode, aTargetNode); + aTargetNode = aNextNode; + } + aSourceNodes.push_back(aNode); + } + aNode = xmlNextElementSibling(aNode); + } + //Remove "SOURCE" node. + std::list::iterator it = aSourceNodes.begin(); + for(; it != aSourceNodes.end(); it++) { + xmlUnlinkNode(*it); + xmlFreeNode(*it); + } } std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode) @@ -62,19 +95,11 @@ std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode) if (!hasChild(theNode)) { return result; } - xmlNodePtr aChildrenNode = xmlFirstElementChild(theNode); + //Replace all "source" nodes with content; + resolveSourceNodes(theNode); xmlBufferPtr buffer = xmlBufferCreate(); - if (isNode(aChildrenNode, NODE_SOURCE, NULL)) { - Config_XMLReader aSourceReader = - Config_XMLReader(getProperty(aChildrenNode, SOURCE_FILE)); - //Register all validators in the sourced xml - aSourceReader.readAll(); - //Dump! - xmlNodePtr aSourceRoot = aSourceReader.findRoot(); - int size = xmlNodeDump(buffer, aSourceRoot->doc, aSourceRoot, 0, 1); - } else { - int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1); - } + int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0); result = std::string((char*) (buffer->content)); + xmlBufferFree(buffer); return result; } diff --git a/src/Config/Config_WidgetReader.h b/src/Config/Config_WidgetReader.h index 96f35ac19..c9c2f0602 100644 --- a/src/Config/Config_WidgetReader.h +++ b/src/Config/Config_WidgetReader.h @@ -28,6 +28,7 @@ protected: void processNode(xmlNodePtr theNode); bool processChildren(xmlNodePtr theNode); std::string dumpNode(xmlNodePtr theNode); + void resolveSourceNodes(xmlNodePtr theNode); private: std::map myWidgetCache; diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index a9bf87dc6..8d618b102 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -123,9 +123,10 @@ void Config_XMLReader::readRecursively(xmlNodePtr theParent) xmlNodePtr aNode = theParent->xmlChildrenNode; for(; aNode; aNode = aNode->next) { //Still no text processing in features... - if(isElementNode(aNode)) { - processNode(aNode); + if(!isElementNode(aNode)) { + continue; } + processNode(aNode); if (processChildren(aNode)) { readRecursively(aNode); } @@ -163,12 +164,12 @@ void Config_XMLReader::processValidator(xmlNodePtr theNode) getValidatorInfo(theNode, aValidatorId, aValidatorParameters); aMessage.setValidatorId(aValidatorId); aMessage.setValidatorParameters(aValidatorParameters); - if(isNode(theNode->parent, NODE_FEATURE, NULL)) { - aMessage.setFeatureId(getProperty(theNode->parent, _ID)); + xmlNodePtr aFeatureOrWdgNode = theNode->parent; + if(isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { + aMessage.setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); } else { - xmlNodePtr aWdgNode = theNode->parent; - aMessage.setAttributeId(getProperty(aWdgNode, _ID)); - aMessage.setFeatureId(getProperty(aWdgNode->parent, _ID)); + aMessage.setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); + aMessage.setFeatureId(myCurrentFeature); } aEvLoop->send(aMessage); } diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 47fc97b7b..3a8219cda 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -51,6 +51,9 @@ protected: std::string getProperty(xmlNodePtr theNode, const char* property); void processValidator(xmlNodePtr theNode); +protected: + std::string myCurrentFeature; + protected: std::string myDocumentPath; xmlDocPtr myXmlDoc; diff --git a/src/ConstructionPlugin/plugin-Construction.xml b/src/ConstructionPlugin/plugin-Construction.xml index b3fdc4608..0918dc9cd 100644 --- a/src/ConstructionPlugin/plugin-Construction.xml +++ b/src/ConstructionPlugin/plugin-Construction.xml @@ -2,9 +2,12 @@ + - + + + diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 920d8e0a5..35397224f 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -1,5 +1,7 @@ - + + +