Config_XMLReader.h
Config_ModuleReader.h
Config_FeatureReader.h
+ Config_WidgetAPI.h
+ Config_WidgetReader.h
+ Config_WidgetMessage.h
)
SET(PROJECT_SOURCES
Config_XMLReader.cpp
Config_ModuleReader.cpp
Config_FeatureReader.cpp
+ Config_WidgetAPI.cpp
+ Config_WidgetReader.cpp
+ Config_WidgetMessage.cpp
)
SET(XML_RESOURCES
#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
//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
* 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)) {
#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_ */
--- /dev/null
+/*
+ * 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_ */
* 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)
#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
{
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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_ */
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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_ */
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_ */
#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) + "/";
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()
{
/*
* 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";
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)) {
#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:
*/
bool isNode(xmlNodePtr theNode, const char* name, ...);
-private:
+protected:
std::string myDocumentPath;
+ xmlDocPtr myXmlDoc;
};
#endif /* CONFIG_XMLREADER_H_ */
<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=""/>
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
SET(PROJECT_HEADERS
PartSet.h
PartSet_Module.h
- PartSet_Message.h
)
SET(PROJECT_SOURCES
PartSet_Module.cpp
- PartSet_Message.cpp
)
SET(PROJECT_RESOURCES
+++ /dev/null
-/*
- * 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()
-{
-}
-
+++ /dev/null
-/*
- * 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_ */
-#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)
{
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);
}
void onCommandTriggered();
private:
- QString myMenuXML;
XGUI_Workshop* myWorkshop;
};
XGUI_RubberBand.h
XGUI_Constants.h
XGUI_ViewBackground.h
+ XGUI_WidgetFactory.h
)
SET(PROJECT_AUTOMOC
XGUI_Viewer.cpp
XGUI_RubberBand.cpp
XGUI_ViewBackground.cpp
+ XGUI_WidgetFactory.cpp
)
SET(PROJECT_RESOURCES
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);
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);
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_ */
#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>
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();
//******************************************************
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.";
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()
{
myPartSetModule->createFeatures();
return true;
}
-
class XGUI_Workbench;
class Config_FeatureMessage;
+class Config_WidgetMessage;
class XGUI_Workshop: public QObject, public Event_Listener
{
protected:
//Event-loop processing methods:
void addFeature(const Config_FeatureMessage*);
+ void fillPropertyPanel(const Config_WidgetMessage*);
private:
void initMenu();