From 8f9631c551573523a4dd93f582efd70105bd3c82 Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 11 Aug 2015 13:28:44 +0300 Subject: [PATCH] Support of additional attributes if ModelWidget and features --- src/Config/Config_Keywords.h | 5 ++ src/Config/Config_WidgetAPI.cpp | 61 +++++++++++++++++++++- src/Config/Config_WidgetAPI.h | 14 ++++- src/ExchangePlugin/plugin-Exchange.xml | 5 +- src/ModuleBase/ModuleBase_ModelWidget.cpp | 17 ++++++ src/ModuleBase/ModuleBase_ModelWidget.h | 10 ++-- src/ModuleBase/ModuleBase_WidgetFactory.h | 4 +- src/PartSet/PartSet_WidgetFileSelector.cpp | 4 +- src/PartSet/PartSet_WidgetMultiSelector.h | 8 +-- 9 files changed, 113 insertions(+), 15 deletions(-) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 4a3943213..3cad01b28 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -18,6 +18,8 @@ const static char* NODE_GROUP = "group"; const static char* NODE_FEATURE = "feature"; const static char* NODE_SOURCE = "source"; const static char* NODE_VALIDATOR = "validator"; +const static char* NODE_NAME_ATTRIBUTES = "attributes"; +const static char* NODE_NAME_ATTRIBUTE = "attribute"; const static char* NODE_SELFILTER = "selection_filter"; const static char* NODE_XMLPARENT = "libxml_parent"; @@ -66,6 +68,9 @@ const static char* ATTR_INTERNAL = "internal"; const static char* ATTR_OBLIGATORY = "obligatory"; const static char* ATTR_CONCEALMENT = "concealment"; const static char* ATTR_USE_RESET = "use_reset"; +const static char* ATTR_ID = _ID; +const static char* ATTR_ROLE = "role"; +const static char* ATTR_MAIN_ROLE = "main"; // WDG_INFO properties const static char* INFO_WDG_TEXT = FEATURE_TEXT; diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 1249f9ab8..214b4bdd5 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -16,7 +16,7 @@ #include -Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml) +Config_WidgetAPI::Config_WidgetAPI(const std::string& theRawXml) { myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str()); myCurrentNode = xmlDocGetRootElement(myDoc); @@ -63,6 +63,29 @@ bool Config_WidgetAPI::toParentWidget() return myCurrentNode != NULL; } +std::list Config_WidgetAPI::attributes() const +{ + std::list aResult; + if (myCurrentNode && hasChild(myCurrentNode)) { + xmlNodePtr anAttributesNode = myCurrentNode->children; + while (anAttributesNode && + (!isElementNode(anAttributesNode) || + std::string((char *) anAttributesNode->name) != NODE_NAME_ATTRIBUTES)) { + anAttributesNode = anAttributesNode->next; + } + if (anAttributesNode && hasChild(anAttributesNode)) { + xmlNodePtr anAttributeNode = anAttributesNode->children; + while (anAttributeNode) { + if (isElementNode(anAttributeNode) && + std::string((char *) anAttributeNode->name) == NODE_NAME_ATTRIBUTE) + aResult.push_back(anAttributeNode); + anAttributeNode = anAttributeNode->next; + } + } + } + return aResult; +} + std::string Config_WidgetAPI::widgetType() const { std::string result = ""; @@ -113,3 +136,39 @@ std::string Config_WidgetAPI::widgetTooltip() const { return getProperty(ATTR_TOOLTIP); } + +std::list Config_WidgetAPI::getAttributes(const std::string& theRole/* = std::string()*/) const +{ + std::list aResult; + + if (theRole.empty() || theRole == ATTR_MAIN_ROLE) + aResult.push_back(widgetId()); + + if (theRole == ATTR_MAIN_ROLE) + return aResult; + + std::list anAttributes = attributes(); + for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) { + if (theRole.empty() || theRole == ::getProperty(*it, ATTR_ROLE)) + aResult.push_back(::getProperty(*it, ATTR_ID)); + } + return aResult; +} + +std::string Config_WidgetAPI::getAttributeProperty(const std::string& theAttribute, + const std::string& thePropName) const +{ + if (theAttribute == widgetId()) { + if (thePropName == ATTR_ROLE) + return ATTR_MAIN_ROLE; + return ::getProperty(myCurrentNode, thePropName.c_str()); + } + + std::list anAttributes = attributes(); + for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) { + if (theAttribute == ::getProperty(*it, ATTR_ID)) + return ::getProperty(*it, thePropName.c_str()); + } + return std::string(); +} + diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index e9531e49f..a99ba1a58 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -13,6 +13,7 @@ #include #include +#include #include //>> Forward declaration of xmlNodePtr. @@ -56,6 +57,15 @@ class CONFIG_EXPORT Config_WidgetAPI //! Returns a custom property of current widget std::string getProperty(const char* thePropName) const; + /*! Returns a list of attributes. + * If theRole is 0 then returns all attributes. + * If theRole is "main" then returns widgetId(). + */ + std::list getAttributes(const std::string& theRole = std::string()) const; + //! Returns a custom property of attribute + std::string getAttributeProperty(const std::string& theAttribute, + const std::string& thePropName) const; + /*! Checks if the XML representation of widget has given attribute, * if yes - returns it's bool value, if no, or if the value can not * be converted to bool - returns theDefault. @@ -67,7 +77,7 @@ class CONFIG_EXPORT Config_WidgetAPI protected: /// These fields are accessible for ModuleBase_WidgetFactory only - Config_WidgetAPI(std::string theRawXml); + Config_WidgetAPI(const std::string& theRawXml); //! Pass to the next (sibling) node of widget's xml definition. If impossible, returns false bool toNextWidget(); //! Pass into the child node of widget's xml definition. If impossible, returns false @@ -75,6 +85,8 @@ class CONFIG_EXPORT Config_WidgetAPI //! Pass into the parent node of widget's xml definition. If impossible, returns false bool toParentWidget(); + std::list attributes() const; + private: xmlDocPtr myDoc; //!< Pointer to the root of widget's xml definition xmlNodePtr myCurrentNode; //!< Pointer to the current node in the widget's xml definition diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index e98d9f710..061e23180 100644 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -11,9 +11,12 @@ + + + - \ No newline at end of file + diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 63d8095fc..c9e21b2c4 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -35,6 +35,12 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, myAttributeID = theData ? theData->widgetId() : ""; myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true); + std::list anAttributes = theData->getAttributes(); + for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) { + std::string aRole = theData->getAttributeProperty(*it, ATTR_ROLE); + myRoleAttributesID[aRole] << *it; + } + connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); } @@ -82,6 +88,17 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted) } } +std::string ModuleBase_ModelWidget::attributeID(const std::string& theRole/* = std::string()*/) const +{ + if (theRole.empty()) + return myAttributeID; + + if (myRoleAttributesID.contains(theRole) && !myRoleAttributesID[theRole].isEmpty()) + return myRoleAttributesID[theRole].last(); + + return std::string(); +} + void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue) { myFeature = theFeature; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index cad3f174c..b74bf54f7 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -12,6 +12,8 @@ #include +#include +#include #include #include @@ -121,10 +123,7 @@ Q_OBJECT /// Returns the attribute name /// \returns the string value - std::string attributeID() const - { - return myAttributeID; - } + std::string attributeID(const std::string& theRole = std::string()) const; /// Returns the parent of the attribute /// \returns the string value @@ -216,6 +215,9 @@ protected slots: /// The attribute name of the model feature std::string myAttributeID; + /// The list of attribute names of the model feature for a role + QMap > myRoleAttributesID; + /// Name of parent std::string myParentId; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 1e1f29fa7..f7e7bd492 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -24,8 +24,8 @@ class ModuleBase_PageBase; /** * \ingroup GUI -* A class for creation of widgets instances in for property panel using XML deskription of -* a feature +* A class for creation of widgets instances in for property panel using +* XML description of a feature */ class MODULEBASE_EXPORT ModuleBase_WidgetFactory { diff --git a/src/PartSet/PartSet_WidgetFileSelector.cpp b/src/PartSet/PartSet_WidgetFileSelector.cpp index 117a8c866..db26f45a7 100644 --- a/src/PartSet/PartSet_WidgetFileSelector.cpp +++ b/src/PartSet/PartSet_WidgetFileSelector.cpp @@ -27,7 +27,7 @@ bool PartSet_WidgetFileSelector::restoreValueCustom() return false; DataPtr aData = myFeature->data(); - AttributeStringPtr aStringAttr = aData->string("export_file_format"); + AttributeStringPtr aStringAttr = aData->string(attributeID("format")); mySelectedFilter = formatToFilter(shortFormatToFullFormat(QString::fromStdString(aStringAttr->value()))); return ModuleBase_WidgetFileSelector::restoreValueCustom(); @@ -40,7 +40,7 @@ bool PartSet_WidgetFileSelector::storeValueCustom() const return false; DataPtr aData = myFeature->data(); - AttributeStringPtr aStringAttr = aData->string("export_file_format"); + AttributeStringPtr aStringAttr = aData->string(attributeID("format")); aStringAttr->setValue(filterToShortFormat(mySelectedFilter).toStdString()); return ModuleBase_WidgetFileSelector::storeValueCustom(); diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h index e0479547e..a7f19df94 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.h +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -19,7 +19,7 @@ class PartSet_ExternalObjectsMgr; /** * \ingroup Modules -* Customosation of ModuleBase_WidgetMultiSelector in order to provide +* Customization of ModuleBase_WidgetMultiSelector in order to provide * working with sketch specific objects and creation of external objects. */ class PARTSET_EXPORT PartSet_WidgetMultiSelector: public ModuleBase_WidgetMultiSelector @@ -29,7 +29,7 @@ Q_OBJECT /// Constructor /// \param theParent the parent object /// \param theWorkshop instance of workshop interface - /// \param theData the widget configuation. The attribute of the model widget is obtained from + /// \param theData the widget configuration. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute PartSet_WidgetMultiSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId); @@ -43,7 +43,7 @@ Q_OBJECT /// \param theSketch a sketcher object void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } - /// Retrurns installed sketcher + /// Returns installed sketcher CompositeFeaturePtr sketch() const { return mySketch; } /// Set the given wrapped value to the current widget @@ -85,4 +85,4 @@ protected: bool myIsInVaildate; }; -#endif \ No newline at end of file +#endif -- 2.39.2