]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Xml --> Widget processing added for "value" (spinbox) entities.
authorsbh <sergey.belash@opencascade.com>
Thu, 3 Apr 2014 14:34:38 +0000 (18:34 +0400)
committersbh <sergey.belash@opencascade.com>
Thu, 3 Apr 2014 14:34:38 +0000 (18:34 +0400)
28 files changed:
src/Config/CMakeLists.txt
src/Config/Config_FeatureMessage.h
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_Keywords.h [new file with mode: 0644]
src/Config/Config_ModuleReader.cpp
src/Config/Config_ModuleReader.h
src/Config/Config_WidgetAPI.cpp [new file with mode: 0644]
src/Config/Config_WidgetAPI.h [new file with mode: 0644]
src/Config/Config_WidgetMessage.cpp [new file with mode: 0644]
src/Config/Config_WidgetMessage.h [new file with mode: 0644]
src/Config/Config_WidgetReader.cpp [new file with mode: 0644]
src/Config/Config_WidgetReader.h [new file with mode: 0644]
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/Config/plugin-PartSet.xml
src/Model/Model_PluginManager.cxx
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Message.cpp [deleted file]
src/PartSet/PartSet_Message.h [deleted file]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_WidgetFactory.cpp [new file with mode: 0644]
src/XGUI/XGUI_WidgetFactory.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index e971c39a0475b7841db210292bc42c97b0df471b..8e6369fa3c329aae86f959c32d8a458c03050a9a 100644 (file)
@@ -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
index ba0c64c7bd47e3ab1daf4f5566b56850de3c1524..1309ae898f4a3c8ede56e790c7401e93179c96ac 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef CONFIG_MESSAGE_H\r
 #define CONFIG_MESSAGE_H\r
 \r
-#include "Config.h"\r
-\r
+#include <Config.h>\r
 #include <Event_Message.h>\r
+\r
 #include <string>\r
 \r
 /*\r
@@ -27,6 +27,9 @@ public:
   //const Event_ID theID, const void* theSender = 0\r
   Config_FeatureMessage(const Event_ID theId, const void* theParent = 0);\r
 \r
+  //TODO(sbh): Implement static method to extract event id [SEID]\r
+  //static const char* eventId() { return ""; }\r
+\r
   //Auto-generated getters/setters\r
   const std::string& icon() const;\r
   const std::string& id() const;\r
index 73a5c07fbcfddde72c466e6ea4c84725df7f7743..1cb2ef83da1768002d6d7df81ad528b8c6e61bea 100644 (file)
@@ -5,87 +5,42 @@
  *      Author: sbh
  */
 
+#include <Config_Keywords.h>
+#include <Config_FeatureMessage.h>
 #include <Config_FeatureReader.h>
-
+#include <Event_Message.h>
 #include <Event_Loop.h>
 
 #include <libxml\parser.h>
 #include <libxml\tree.h>
+#include <libxml\xmlstring.h>
+
+#include <string>
 
 #ifdef _DEBUG
 #include <iostream>
 #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)) {
index cb16d9ea2313debe02a577ceb4b678b8edab5d74..117e8bd6ce18748c66e0e6bfedf2d05857cca997 100644 (file)
@@ -8,30 +8,31 @@
 #ifndef CONFIG_FEATUREREADER_H_
 #define CONFIG_FEATUREREADER_H_
 
+#include <Config.h>
 #include <Config_XMLReader.h>
 
+#include <string>
+
+
+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 (file)
index 0000000..107ba9e
--- /dev/null
@@ -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_ */
index 85e653c7e6f0fdedc0557da2540b7d7e7207d9d7..d77e6b830fd7ee091cf6d1ab7b5083c768d65de9 100644 (file)
@@ -5,6 +5,7 @@
  *      Author: sbh
  */
 
+#include <Config_Keywords.h>
 #include <Config_ModuleReader.h>
 #include <Config_FeatureReader.h>
 
 #include <iostream>
 #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)
index 4b59f622e0f21872da594d9b6460b3d2fbd76da4..5a19c24c04667d9d738a51b814a9392e467aee65 100644 (file)
@@ -8,9 +8,12 @@
 #ifndef CONFIG_MODULEREADER_H_
 #define CONFIG_MODULEREADER_H_
 
+#include <Config.h>
 #include <Config_XMLReader.h>
 
 #include <map>
+#include <string>
+
 
 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 (file)
index 0000000..38b4476
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Config_WidgetAPI.cpp
+ *
+ *  Created on: Apr 1, 2014
+ *      Author: sbh
+ */
+
+#include <Config_WidgetAPI.h>
+
+#include <libxml\parser.h>
+#include <libxml\tree.h>
+
+
+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 (file)
index 0000000..0bcb4a4
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Config_WidgetAPI.h
+ *
+ *  Created on: Apr 1, 2014
+ *      Author: sbh
+ */
+
+#ifndef CONFIG_WIDGETAPI_H_
+#define CONFIG_WIDGETAPI_H_
+
+#include <Config.h>
+
+#include <cstdarg>
+#include <string>
+
+//>> 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 (file)
index 0000000..846359f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Config_WidgetMessage.cpp
+ *
+ *  Created on: Mar 21, 2014
+ *      Author: sbh
+ */
+
+#include <Config_WidgetMessage.h>
+
+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 (file)
index 0000000..1aa00d8
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Config_WidgetMessage.h
+ *
+ *  Created on: Mar 21, 2014
+ *      Author: sbh
+ */
+
+#ifndef PARTSET_MESSAGE_H_
+#define PARTSET_MESSAGE_H_
+
+#include <Config.h>
+
+#include <Event_Message.h>
+#include <string>
+
+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 (file)
index 0000000..3558c65
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Config_WidgetReader.cpp
+ *
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
+ */
+
+#include <Config_WidgetReader.h>
+#include <Config_Keywords.h>
+
+#include <libxml\parser.h>
+#include <libxml\tree.h>
+#include <libxml\xpath.h>
+#include <libxml\xmlstring.h>
+
+#ifdef _DEBUG
+#include <iostream>
+#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 (file)
index 0000000..58fd904
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Config_WidgetReader.h
+ *
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
+ */
+
+#ifndef CONFIG_WIDGETREADER_H_
+#define CONFIG_WIDGETREADER_H_
+
+#include <Config.h>
+#include <Config_XMLReader.h>
+
+#include <map>
+#include <string>
+
+
+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<std::string, std::string> myWidgetCache;
+
+};
+
+#endif /* CONFIG_WIDGETREADER_H_ */
index 1b206af8223add70ded12b6f69ca69a619f8d4f2..6abf8ea7b04359857add3f1488cecdc19cb2d683 100644 (file)
 #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)) {
index bdff8a00e9bf94425e747adecaf46ac370f9c41a..01ad541a4eefcb0c036aa70abad39d184f669016 100644 (file)
@@ -8,17 +8,28 @@
 #ifndef CONFIG_XMLREADER_H_
 #define CONFIG_XMLREADER_H_
 
-#include "Config.h"
-#include "Config_FeatureMessage.h"
+#include <Config.h>
 
-#include <string>
 #include <cstdarg>
+#include <string>
 
-//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_ */
index 2785659ef9a5ab09b5e80e8aea8bfa77e5f2586e..fff9a54aa47c345d3fc74197e92336f54f8a24b9 100644 (file)
@@ -10,8 +10,8 @@
     <group id="Basic">
       <feature id="new_point" text="Point" tooltip="Create a new point" icon=":icons/point.png">
         <value id="x" type="double" label="X:" min="0" max="" step="0.1" default="0"/>
-        <value id="y" type="double" label="Y:" min="0" max="" step="0.1" default="0"/>
-        <value id="z" type="double" label="Z:" min="0" max="" step="0.1" default="0"/>
+        <value id="y" type="double" label="Y:" min="0" max="" step="0.1" default="1"/>
+        <value id="z" type="double" label="Z:" min="0" max="10" step="0.1" default="2"/>
       </feature>
       <feature id="new_axis" text="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence=""/>
       <feature id="new_plane" text="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence=""/>
index c4e28665dcd82d3e7d086d489d0ca02ac801caeb..daeb60176f6d47f49b147aa21cea8f14874bf38a 100644 (file)
@@ -36,7 +36,8 @@ boost::shared_ptr<ModelAPI_Feature> 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<ModelAPI_PluginManager>(this));
   // register the configuration reading listener
index 0ed6de6f142124c0e534788cea1eb9fa941faa26..bb9960d9a646660448531b0e102b76cedf3739ab 100644 (file)
@@ -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 (file)
index 7ac2400..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * PartSet_Message.cpp
- *
- *  Created on: Mar 21, 2014
- *      Author: sbh
- */
-
-#include <PartSet_Message.h>
-
-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 (file)
index 9d15f08..0000000
+++ /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 <PartSet.h>
-
-#include <QString>
-
-#include <Event_Message.h>
-
-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_ */
index ad4add3f1a5340494385c3b3217c471bba240bec..7f87997da0b2c0c3b1ad50f5bba8f66445f7da28 100644 (file)
@@ -1,14 +1,18 @@
-#include "PartSet_Module.h"
+#include <PartSet_Module.h>
+#include <Config_WidgetMessage.h>
 
 #include <Config_ModuleReader.h>
-#include <Config_FeatureReader.h>
-
+#include <Config_WidgetReader.h>
 #include <Event_Loop.h>
+#include <Event_Message.h>
+
+#include <QObject>
+#include <QString>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
 
-#include <QFile>
-#include <QDir>
-#include <QApplication>
-#include <QTextStream>
 
 /*!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<XGUI_Command*>(sender());
-//  std::string aXMLWidgetCfg = aReader->featureWidgetCfg(aCmd->getId().toStdString());
-//  delete aReader;
+  std::map<std::string, std::string> aPluginMap = aModuleReader.plugins();
+  std::string aPluginName = aPluginMap["PartSetPlugin"];
+  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
+  aWdgReader.readAll();
+  XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(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);
 }
index db601db2f4a0c9cb3b927b587f3fd164971e3146..9136167253166db81dc25f1d3fab1388488365d6 100644 (file)
@@ -22,7 +22,6 @@ public slots:
   void onCommandTriggered();
 
 private:
-  QString myMenuXML;
   XGUI_Workshop* myWorkshop;
 };
 
index e749048fcf4f0eee8709f7198062ccd42e0cb37d..5ac769adc3ad6bb765d0f36310e2972802e48830 100644 (file)
@@ -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 
index 7ab8aafdf48b4900e39871401114b0b0a2a770fd..6841b795e93d022e0a94717c284a01b7259bd97f 100644 (file)
@@ -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 (file)
index 0000000..9cc69af
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * XGUI_WidgetFactory.cpp
+ *
+ *  Created on: Apr 3, 2014
+ *      Author: sbh
+ */
+
+#include <XGUI_WidgetFactory.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QWidget>
+#include <QHBoxLayout>
+#include <QSpinBox>
+#include <QMetaProperty>
+#include <QLabel>
+
+#ifdef _DEBUG
+#include <QDebug>
+#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 (file)
index 0000000..cd02f63
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * XGUI_WidgetFactory.h
+ *
+ *  Created on: Apr 3, 2014
+ *      Author: sbh
+ */
+
+#ifndef XGUI_WIDGETFACTORY_H_
+#define XGUI_WIDGETFACTORY_H_
+
+#include <QString>
+#include <string>
+
+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_ */
index 16d693278652bd746ff7c47e044ceed8cf07ae8e..28519d6dead5b63c1a79503a22d5e1ade8589c04 100644 (file)
@@ -7,9 +7,11 @@
 #include "XGUI_Workbench.h"
 #include "XGUI_Workshop.h"
 #include "XGUI_Viewer.h"
+#include "XGUI_WidgetFactory.h"
 
-#include <Config_FeatureMessage.h>
 #include <Event_Loop.h>
+#include <Config_FeatureMessage.h>
+#include <Config_WidgetMessage.h>
 
 #include <QApplication>
 #include <QFileDialog>
@@ -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<const Config_FeatureMessage*>(theMessage);
+  const Config_FeatureMessage* aFeatureMsg =
+      dynamic_cast<const Config_FeatureMessage*>(theMessage);
   if (aFeatureMsg) {
     addFeature(aFeatureMsg);
     return;
   }
+  const Config_WidgetMessage* aPartSetMsg = dynamic_cast<const Config_WidgetMessage*>(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<QWidget*>("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;
 }
-
index 3e021baddee022e98dd9defbddeef77933565d66..68300e96bde568391335d49c97793d96c25aa069 100644 (file)
@@ -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();