Salome HOME
Issue #29 processing of "source" tags added
authorsbh <sergey.belash@opencascade.com>
Thu, 24 Apr 2014 11:59:31 +0000 (15:59 +0400)
committersbh <sergey.belash@opencascade.com>
Thu, 24 Apr 2014 11:59:31 +0000 (15:59 +0400)
src/Config/Config_FeatureReader.cpp
src/Config/Config_Keywords.h
src/Config/Config_WidgetReader.cpp
src/Config/Config_WidgetReader.h
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/plugin-Construction.xml
src/ConstructionPlugin/point_widget.xml [new file with mode: 0644]

index b9454e04d26d1ade98511b4daa5edb76bc2ea6c9..1b574cfbac4fd3b4e8e125a91e83fcee577d2c2f 100644 (file)
@@ -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)
index 3c7bb936c57207f65388b778bd4703856b5aa299..f5bfe19e80d16a2929efa6b9181370957503a6d9 100644 (file)
@@ -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";
index 8f47a62007bf55be12b8fd4039af25843a183480..7ba92f9961f5f6b7a5d7e08f4e2fd54ff1e8b29d 100644 (file)
@@ -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;
+}
index ae76cc996254fa681044ffd1e6578fa6c766d606..cfc1519a56b62fcc46eafeaeb39e489d3fba599d 100644 (file)
@@ -27,6 +27,7 @@ public:
 protected:
   void processNode(xmlNodePtr theNode);
   bool processChildren(xmlNodePtr theNode);
+  std::string dumpNode(xmlNodePtr theNode);
 
 private:
   std::map<std::string, std::string> myWidgetCache;
index 002c9df493ab611ef9d22774d6147ce70e2800e3..0ac45babf63b02f277520d2e0e6e5802a6cc8542 100644 (file)
@@ -6,6 +6,8 @@
  */
 
 #include <Config_XMLReader.h>
+#include <Config_Keywords.h>
+#include <Config_Common.h>
 
 #include <Event_Loop.h>
 #include <libxml/parser.h>
@@ -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) {
index a44d49364a9cb8d4c95b60ea1d62ca8f06fe9146..bcd8ddfdf4bfe5d27bdd6305060a40298cb714eb 100644 (file)
@@ -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);
index 430ffb9abd36f7f9c75fde70ee31944e18039e53..7fe6d649c3b671b6cb6dacc3581a394fb47920c1 100644 (file)
@@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES(
 
 SET(XML_RESOURCES
   plugin-Construction.xml
+  point_widget.xml
 )
 
 INSTALL(TARGETS ConstructionPlugin DESTINATION plugins)
index a5e402f06a616d1b1f326d18c5f773a26609370b..912d04e0ca636ce6e2acd9dfd7598ccde8300029 100644 (file)
@@ -2,9 +2,7 @@
   <workbench id="Construction">
     <group id="Basic">
       <feature id="Point" text="Point" tooltip="Create a new point" icon=":icons/point.png">
-        <doublevalue id="x" label="X:" max="50" step="1.0" default="0" icon=":pictures/x_point.png" tooltip="Set X"/>
-        <doublevalue id="y" label="Y:" min="x" default="1" icon=":pictures/y_point.png" tooltip="Set Y"/>
-        <doublevalue id="z" label="Z:" min="-20" step="0.1" default="2" icon=":pictures/z_point.png" tooltip="Set Z"/>
+        <source path="point_widget.xml"/>
       </feature>
       <feature id="Axis" text="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence=""/>
       <feature id="Plane" text="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence=""/>
diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml
new file mode 100644 (file)
index 0000000..920d8e0
--- /dev/null
@@ -0,0 +1,5 @@
+<source>
+  <doublevalue id="x" label="X:" max="50" step="1.0" default="0" icon=":pictures/x_point.png" tooltip="Set X"/>
+  <doublevalue id="y" label="Y:" min="x" default="1" icon=":pictures/y_point.png" tooltip="Set Y"/>
+  <doublevalue id="z" label="Z:" min="-20" step="0.1" default="2" icon=":pictures/z_point.png" tooltip="Set Z"/>
+</source>