X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConfig%2FConfig_FeatureReader.cpp;h=839eca2410e55d74eaab5aa26e70778309e5bd30;hb=d77e6639d89abdcbf327cc73d13bf955064b8524;hp=0eb2bfdaa5ac4975e8f554eae979df7dccb930a2;hpb=733ef3a952e2cd2d5df92667569eb9096200da27;p=modules%2Fshaper.git diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 0eb2bfdaa..839eca241 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + /* * Config_FeatureReader.cpp * @@ -5,74 +7,134 @@ * Author: sbh */ +#include +#include +#include +#include #include +#include +#include -#include +#include +#include +#include -#include -#include +#include +#include +#include #ifdef _DEBUG #include #endif -//Hardcoded xml entities -// * Nodes - -// * Properties -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"; -const static char* FEATURE_GROUP_NAME = "name"; - - - - -Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile) - : Config_XMLReader(theXmlFile) +Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile, + const std::string& theLibraryName, + const char* theEventGenerated) + : Config_XMLReader(theXmlFile), + myLibraryName(theLibraryName), + myEventGenerated(theEventGenerated ? theEventGenerated : Config_FeatureMessage::GUI_EVENT()), + myIsProcessWidgets(theEventGenerated != NULL) { - #ifdef _DEBUG - if(!Event_Loop::Loop()) { - std::cout << "Config_FeatureReader::importWorkbench: " - << "No event loop registered" << std::endl; - } - #endif } Config_FeatureReader::~Config_FeatureReader() { } +std::list Config_FeatureReader::features() const +{ + return myFeatures; +} + void Config_FeatureReader::processNode(xmlNodePtr theNode) { - if(isNode(theNode,"feature")) { - Event_Loop* aEvLoop = Event_Loop::Loop(); - Config_FeatureMessage aMessage(aEvLoop->EventByName("Feature"), this); + Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated); + if (isNode(theNode, NODE_FEATURE, NULL)) { + storeAttribute(theNode, _ID); + std::shared_ptr aMessage(new Config_FeatureMessage(aMenuItemEvent, this)); fillFeature(theNode, aMessage); - xmlNodePtr aGroupNode = theNode->parent; - if(aGroupNode) { - std::string aGroupName = getProperty(aGroupNode, FEATURE_GROUP_NAME); - aMessage.m_group = aGroupName; + myFeatures.push_back(getProperty(theNode, _ID)); + //If a feature has xml definition for it's widget: + aMessage->setUseInput(hasChild(theNode)); + 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)) { + std::shared_ptr aMessage(new Config_AttributeMessage(aMenuItemEvent, this)); + aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + std::string anAttributeID = getProperty(theNode, _ID); + if (!anAttributeID.empty()) { + aMessage->setAttributeId(anAttributeID); + aMessage->setObligatory(getBooleanAttribute(theNode, ATTR_OBLIGATORY, true)); + aMessage->setConcealment(getBooleanAttribute(theNode, ATTR_CONCEALMENT, false)); + Events_Loop::loop()->send(aMessage); } - aEvLoop->Send(aMessage); } + //Process SOURCE, VALIDATOR nodes. + Config_XMLReader::processNode(theNode); } bool Config_FeatureReader::processChildren(xmlNodePtr theNode) { - return isNode(theNode, "workbench") - || isNode(theNode, "group"); -// || isNode(theNode, "feature"); + 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 theFeatureNode, + const std::shared_ptr& outFeatureMessage) +{ + outFeatureMessage->setId(getProperty(theFeatureNode, _ID)); + outFeatureMessage->setPluginLibrary(myLibraryName); + outFeatureMessage->setNestedFeatures(getProperty(theFeatureNode, FEATURE_NESTED)); + outFeatureMessage->setActionsWhenNested(getNormalizedProperty(theFeatureNode, FEATURE_WHEN_NESTED)); + + bool isInternal = getBooleanAttribute(theFeatureNode, ATTR_INTERNAL, false); + outFeatureMessage->setInternal(isInternal); + if (isInternal) { + //Internal feature has no visual representation. + return; + } + outFeatureMessage->setText(getProperty(theFeatureNode, FEATURE_TEXT)); + outFeatureMessage->setTooltip(getProperty(theFeatureNode, FEATURE_TOOLTIP)); + outFeatureMessage->setIcon(getProperty(theFeatureNode, FEATURE_ICON)); + outFeatureMessage->setKeysequence(getProperty(theFeatureNode, FEATURE_KEYSEQUENCE)); + outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID)); + outFeatureMessage->setWorkbenchId(restoreAttribute(NODE_WORKBENCH, _ID)); + // Get document kind of a feature, if empty set workbench's kind (might be empty too) + std::string aDocKind = getProperty(theFeatureNode, FEATURE_DOC); + if(aDocKind.empty()) { + aDocKind = restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC); + } + outFeatureMessage->setDocumentKind(aDocKind); +} + +void Config_FeatureReader::storeAttribute(xmlNodePtr theNode, + const char* theNodeAttribute) +{ + std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute); + std::string aValue = getProperty(theNode, theNodeAttribute); + if(!aValue.empty()) { + myParentAttributes[aKey] = aValue; + } } -void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, - Config_FeatureMessage& outFtMessage) +std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode, + const char* theNodeAttribute) { - outFtMessage.m_id = getProperty(theRoot, FEATURE_ID); - outFtMessage.m_text = getProperty(theRoot, FEATURE_TEXT); - outFtMessage.m_tooltip = getProperty(theRoot, FEATURE_TOOLTIP); - outFtMessage.m_icon = getProperty(theRoot, FEATURE_ICON); - outFtMessage.m_keysequence = getProperty(theRoot, FEATURE_KEYSEQUENCE); + return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute); +} +std::string Config_FeatureReader::restoreAttribute(const char* theNodeName, + const char* theNodeAttribute) +{ + std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute); + std::string result = ""; + if(myParentAttributes.find(aKey) != myParentAttributes.end()) { + result = myParentAttributes[aKey]; + } + return result; }