Config_ValidatorMessage.h
Config_Prop.h
Config_PropManager.h
+ Config_AttributeMessage.h
)
SET(PROJECT_SOURCES
Config_ValidatorMessage.cpp
Config_Prop.cpp
Config_PropManager.cpp
+ Config_AttributeMessage.cpp
)
SET(XML_RESOURCES
--- /dev/null
+/*
+ *
+ */
+#include "Config_AttributeMessage.h"
+
+Config_AttributeMessage::Config_AttributeMessage(const Events_ID theId, const void* theParent)
+ : Events_Message(theId, theParent)
+{
+ myAttributeId = ""; // Attribute unique id
+ myFeatureId = ""; // Feature unique id
+ myIsObligatory = true;
+ myIsConcealment = false;
+}
+
+Config_AttributeMessage::~Config_AttributeMessage()
+{
+
+}
+
+const std::string& Config_AttributeMessage::featureId() const
+{
+ return myFeatureId;
+}
+
+void Config_AttributeMessage::setFeatureId(const std::string& theId)
+{
+ myFeatureId = theId;
+}
+
+const std::string& Config_AttributeMessage::attributeId() const
+{
+ return myAttributeId;
+}
+
+void Config_AttributeMessage::setAttributeId(const std::string& theId)
+{
+ myAttributeId = theId;
+}
+
+bool Config_AttributeMessage::isConcealment() const
+{
+ return myIsConcealment;
+}
+
+void Config_AttributeMessage::setConcealment(bool theConcealment)
+{
+ this->myIsConcealment = theConcealment;
+}
+
+bool Config_AttributeMessage::isObligatory() const
+{
+ return myIsObligatory;
+}
+
+void Config_AttributeMessage::setObligatory(bool theObligatory)
+{
+ this->myIsObligatory = theObligatory;
+}
--- /dev/null
+#ifndef ATTRIBUTE_MESSAGE_H
+#define ATTRIBUTE_MESSAGE_H
+
+#include <Config_def.h>
+#include <Config_FeatureMessage.h>
+#include <Events_Message.h>
+
+#include <string>
+
+/*
+ * Class to pass an attribute's (widget's) entry info extracted from xml file.
+ * <widget id="tool_object" concealment="true" obligatory="0"/>
+ */
+class Config_AttributeMessage : public Events_Message
+{
+ std::string myAttributeId; //Feature unique id
+ std::string myFeatureId; //Feature unique id
+ bool myIsObligatory;
+ bool myIsConcealment;
+
+ public:
+ // Same event as Config_FeatureMessage::MODEL_EVENT()
+ inline static const char* MODEL_EVENT()
+ {
+ return Config_FeatureMessage::MODEL_EVENT();
+ }
+
+ //const Events_ID theID, const void* theSender = 0
+ CONFIG_EXPORT Config_AttributeMessage(const Events_ID theId, const void* theParent = 0);
+ CONFIG_EXPORT virtual ~Config_AttributeMessage();
+
+ //Auto-generated getters/setters
+ CONFIG_EXPORT const std::string& attributeId() const;
+ CONFIG_EXPORT const std::string& featureId() const;
+ CONFIG_EXPORT bool isObligatory() const;
+ CONFIG_EXPORT bool isConcealment() const;
+
+ CONFIG_EXPORT void setAttributeId(const std::string& theId);
+ CONFIG_EXPORT void setFeatureId(const std::string& id);
+ CONFIG_EXPORT void setConcealment(bool isConcealment);
+ CONFIG_EXPORT void setObligatory(bool isObligatory);
+};
+
+#endif // ATTRIBUTE_MESSAGE_H
#include <libxml/parser.h>\r
#include <libxml/tree.h>\r
\r
-#include <sstream> //for stringstream\r\r
+#include <sstream> // for stringstream\r
+\r
+#include <string>\r
+#include <algorithm> // for std::transform\r\r
bool isElementNode(xmlNodePtr theNode)\r
{\r
return theNode->type == XML_ELEMENT_NODE;\r
return false;\r
}\r
\r
+bool isWidgetNode(xmlNodePtr theNode)\r
+{\r
+ if(!isElementNode(theNode))\r
+ return false;\r
+ // it's parent is "feature" or "source"\r
+ xmlNodePtr aParentNode = theNode->parent;\r
+ if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL))\r
+ return false;\r
+\r
+ //it should not be a "source" or a "validator" node\r
+ return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NULL);\r
+}\r
+\r
bool hasChild(xmlNodePtr theNode)\r
{\r
xmlNodePtr aNode = theNode->children;\r
\r
return aLibName;\r
}\r
+\r
+std::string getProperty(xmlNodePtr theNode, const char* thePropName)\r
+{\r
+ std::string result = "";\r
+ char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName);\r
+ if (!aPropChars || aPropChars[0] == 0)\r
+ return result;\r
+ result = std::string(aPropChars);\r
+ return result;\r
+}\r
+\r
+bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault)\r
+{\r
+ std::string prop = getProperty(theNode, theAttributeName);\r
+ std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);\r
+ bool result = theDefault;\r
+ if (prop == "true" || prop == "1") {\r
+ result = true;\r
+ } else if (prop == "false" || prop == "0") {\r
+ result = false;\r
+ }\r
+ return result;\r
+}\r
* Author: sbh
*/
-#ifndef Config_Common_H_
-#define Config_Common_H_
+#ifndef CONFIG_COMMON_H_
+#define CONFIG_COMMON_H_
#include "Config_def.h"
*/
CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...);
+/*
+ * Checks is the given node is attribute (widget) node.
+ */
+CONFIG_EXPORT bool isWidgetNode(xmlNodePtr theNode);
+
/*
* Every xml node has child. Even if there is no explicit
* child nodes libxml gives the "Text node" as child.
*/
CONFIG_EXPORT std::string library(const std::string& theLibName);
+/*
+ * Returns named property for a given node as std::string.
+ */
+CONFIG_EXPORT std::string getProperty(xmlNodePtr theNode, const char* thePropName);
+
+/*
+ * Checks if the given XML node has the given attribute,
+ * if yes - returns it's bool value, if no, or if the value can not
+ * be converted to bool - returns theDefault value.
+ * \param theAttributeName attribute to check
+ * \param theDefault default value on bad data
+ * \return the boolean result
+ */
+CONFIG_EXPORT bool getBooleanAttribute(xmlNodePtr theNode,
+ const char* theAttributeName,
+ bool theDefault);
+
#endif
\r
#include <string>\r
\r
-/// Event ID that feature is loaded (comes with Config_FeatureMessage)\r
-static const char * EVENT_FEATURE_LOADED = "FeatureLoaded";\r
-\r
/*\r
* Class to pass a feature entry extracted from xml file.\r
* Example of the feature entry:\r
std::string myNestedFeatures;\r
\r
public:\r
+ /// Event ID that feature is loaded in workbench (GUI)\r
+ inline static const char* GUI_EVENT()\r
+ {\r
+ static const char * MY_GUI_EVENT_ID("WorkshopFeatureLoaded");\r
+ return MY_GUI_EVENT_ID;\r
+ }\r
+ inline static const char* MODEL_EVENT()\r
+ {\r
+ static const char * MY_MODEL_EVENT_ID("ModelFeatureLoaded");\r
+ return MY_MODEL_EVENT_ID;\r
+ }\r
+\r
//const Events_ID theID, const void* theSender = 0\r
CONFIG_EXPORT Config_FeatureMessage(const Events_ID theId, const void* theParent = 0);\r
CONFIG_EXPORT virtual ~Config_FeatureMessage();\r
#include <Config_Keywords.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
+#include <Config_AttributeMessage.h>
#include <Config_FeatureReader.h>
#include <Events_Message.h>
#include <Events_Loop.h>
const char* theEventGenerated)
: Config_XMLReader(theXmlFile),
myLibraryName(theLibraryName),
- myEventGenerated(theEventGenerated ? theEventGenerated : EVENT_FEATURE_LOADED)
+ myEventGenerated(theEventGenerated ? theEventGenerated : Config_FeatureMessage::GUI_EVENT()),
+ myIsProcessWidgets(theEventGenerated != NULL)
{
}
{
Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
if (isNode(theNode, NODE_FEATURE, NULL)) {
- Events_Loop* aEvLoop = Events_Loop::loop();
- boost::shared_ptr<Config_FeatureMessage> aMessage(
- new Config_FeatureMessage(aMenuItemEvent, this));
+ storeAttribute(theNode, _ID);
+ boost::shared_ptr<Config_FeatureMessage> aMessage(new Config_FeatureMessage(aMenuItemEvent, this));
fillFeature(theNode, aMessage);
myFeatures.push_back(getProperty(theNode, _ID));
//If a feature has xml definition for it's widget:
aMessage->setUseInput(hasChild(theNode));
- aEvLoop->send(aMessage);
+ Events_Loop::loop()->send(aMessage);
//The m_last* variables always defined before fillFeature() call. XML is a tree.
} else if (isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL)) {
storeAttribute(theNode, _ID);
storeAttribute(theNode, WORKBENCH_DOC);
+ } else if (myIsProcessWidgets && isWidgetNode(theNode)) {
+ boost::shared_ptr<Config_AttributeMessage> aMessage(new Config_AttributeMessage(aMenuItemEvent, this));
+ aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
+ aMessage->setAttributeId(getProperty(theNode, _ID));
+ aMessage->setObligatory(getBooleanAttribute(theNode, ATTRIBUTE_OBLIGATORY, true));
+ aMessage->setConcealment(getBooleanAttribute(theNode, ATTRIBUTE_CONCEALMENT, false));
+ Events_Loop::loop()->send(aMessage);
}
//Process SOURCE, VALIDATOR nodes.
Config_XMLReader::processNode(theNode);
bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
{
- return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NODE_FEATURE, NULL);
+ bool result = isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
+ if(!result && myIsProcessWidgets) {
+ result = isNode(theNode, NODE_FEATURE, NULL);
+ }
+ return result;
}
void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
outFeatureMessage->setPluginLibrary(myLibraryName);
outFeatureMessage->setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
- bool isInternal = isInternalFeature(theNode);
+ bool isInternal = getBooleanAttribute(theNode, ATTRIBUTE_INTERNAL, false);
outFeatureMessage->setInternal(isInternal);
if (isInternal) {
//Internal feature has no visual representation.
outFeatureMessage->setDocumentKind(restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC));
}
-bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
-{
- std::string prop = getProperty(theNode, ATTRIBUTE_INTERNAL);
- std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
- if (prop.empty() || prop == "false" || prop == "0") {
- return false;
- }
- return true;
-}
-
void Config_FeatureReader::storeAttribute(xmlNodePtr theNode,
const char* theNodeAttribute)
{
bool processChildren(xmlNodePtr aNode);
void fillFeature(xmlNodePtr theRoot,
- const boost::shared_ptr<Config_FeatureMessage>& outFeatureMessage);
- bool isInternalFeature(xmlNodePtr theRoot);
+ const boost::shared_ptr<Config_FeatureMessage>& outFeatureMessage);
void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
/// A map to store all parent's attributes.
/// The key has from "Node_Name:Node_Attribute"
std::map<std::string, std::string> myParentAttributes;
- //std::string myLastWorkbench;
- //std::string myLastGroup;
std::string myLibraryName;
std::list<std::string> myFeatures;
- /// event generated on feature data sending, by default it is EVENT_FEATURE_LOADED
+ /// event generated on feature data sending, by default it is Config_FeatureMessage::GUI_EVENT()
const char* myEventGenerated;
+ bool myIsProcessWidgets;
};
#endif /* CONFIG_FEATUREREADER_H_ */
const static char* NODE_VALIDATOR = "validator";
//Widgets
+const static char* WDG_INFO = "label";
const static char* WDG_DOUBLEVALUE = "doublevalue";
const static char* WDG_BOOLVALUE = "boolvalue";
const static char* WDG_STRINGVALUE = "stringvalue";
const static char* WDG_MULTISELECTOR = "multi_selector";
-//Widget containers
-const static char* WDG_INFO = "label";
-const static char* WDG_GROUP = "groupbox";
-const static char* WDG_CHECK_GROUP = "check_groupbox";
-const static char* WDG_TOOLBOX = "toolbox";
-const static char* WDG_TOOLBOX_BOX = "box";
-const static char* WDG_SWITCH = "switch";
-const static char* WDG_SWITCH_CASE = "case";
const static char* WDG_SHAPE_SELECTOR = "shape_selector";
const static char* WDG_CHOICE = "choice";
-
//Specific widgets
const static char* WDG_POINT_SELECTOR = "point_selector";
const static char* WDG_POINT2D_DISTANCE = "point2ddistance";
const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
const static char* WDG_FILE_SELECTOR= "file_selector";
+//Widget containers
+const static char* WDG_GROUP = "groupbox";
+const static char* WDG_CHECK_GROUP = "check_groupbox";
+const static char* WDG_TOOLBOX = "toolbox";
+const static char* WDG_TOOLBOX_BOX = "box";
+const static char* WDG_SWITCH = "switch";
+const static char* WDG_SWITCH_CASE = "case";
const static char* WORKBENCH_DOC = "document";
//Common Widget's or Feature's Properties
#include <libxml/tree.h>
#include <string>
-#include <algorithm>
Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
{
std::string Config_WidgetAPI::getProperty(const char* thePropName) const
{
- std::string result = "";
- char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName);
- if (!aPropChars || aPropChars[0] == 0)
- return result;
- result = std::string(aPropChars);
- return result;
+ return ::getProperty(myCurrentNode, thePropName);
}
bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
{
- std::string prop = getProperty(theAttributeName);
- std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
- bool result = theDefault;
- if (prop == "true" || prop == "1") {
- result = true;
- } else if (prop == "false" || prop == "0") {
- result = false;
- }
- return result;
+ return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
}
std::string Config_WidgetAPI::widgetId() const
return result;
}
-/*
- * Returns named property for a given node as std::string.
- */
-std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* theName)
-{
- std::string result = "";
- char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST theName);
- if (!aPropChars || aPropChars[0] == 0)
- return result;
- result = std::string(aPropChars);
- return result;
-}
-
void Config_XMLReader::processValidator(xmlNodePtr theNode)
{
Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
xmlNodePtr node(void* theNode);
std::string getNodeName(xmlNodePtr theNode);
- std::string getProperty(xmlNodePtr theNode, const char* property);
void processValidator(xmlNodePtr theNode);
protected:
ModelAPI_Session::setSession(boost::shared_ptr<ModelAPI_Session>(this));
// register the configuration reading listener
Events_Loop* aLoop = Events_Loop::loop();
- static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
+ static const Events_ID kFeatureEvent = Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
aLoop->registerListener(this, kFeatureEvent);
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
void Model_Session::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
{
- static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
+ static const Events_ID kFeatureEvent = Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
if (theMessage->eventID() == kFeatureEvent) {
const boost::shared_ptr<Config_FeatureMessage> aMsg =
return;
// Read plugins information from XML files
- Config_ModuleReader aXMLReader("FeatureRegisterEvent");
+ Config_ModuleReader aXMLReader(Config_FeatureMessage::MODEL_EVENT());
aXMLReader.readAll();
}
return result;
}
-void ModuleBase_WidgetFactory::processAttributes()
-{
- // register that this attribute in feature is not obligatory for the feature execution
- // so, it is not needed for the standard validation mechanism
- bool isObligatory = true;
- bool isConcealment = false;
- if( myWidgetApi ){
- isObligatory = myWidgetApi->getBooleanAttribute(ATTRIBUTE_OBLIGATORY, true);
- isConcealment = myWidgetApi->getBooleanAttribute(ATTRIBUTE_CONCEALMENT, false);
- }
- boost::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
- if (!isObligatory) {
- aSession->validators()->registerNotObligatory(myParentId, myWidgetApi->widgetId());
- }
- if(isConcealment) {
- aSession->validators()->registerConcealment(myParentId, myWidgetApi->widgetId());
- }
-}
-
QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
QWidget* theParent)
{
if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");}
#endif
}
- if (result) {
- processAttributes();
- }
-
return result;
}
QString qs(const std::string& theStdString) const;
- void processAttributes();
private:
Config_WidgetAPI* myWidgetApi;
//Initialize event listening
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
- //TODO(sbh): Implement static method to extract event id [SEID]
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LOADED));
- // TODO Is it good to use non standard event within workshop?
+ aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
}
//A message to start feature creation received.
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED)) {
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
boost::shared_ptr<Config_FeatureMessage> aFeatureMsg =
boost::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
if (!aFeatureMsg->isInternal()) {