From 2e51a6b7ff98a8b27e415eb1271115f36e297899 Mon Sep 17 00:00:00 2001 From: Sergey POKHODENKO Date: Wed, 27 May 2015 17:44:54 +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 +- .../ModuleBase_WidgetFileSelector.cpp | 2 +- src/PartSet/PartSet_WidgetFileSelector.cpp | 4 +- src/PartSet/PartSet_WidgetMultiSelector.h | 8 +-- 10 files changed, 114 insertions(+), 16 deletions(-) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 96adf95b2..59af2f8aa 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_ATTRIBUTES = "attributes"; +const static char* NODE_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..3224d7a18 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_ATTRIBUTES)) { + anAttributesNode = anAttributesNode->next; + } + if (anAttributesNode && hasChild(anAttributesNode)) { + xmlNodePtr anAttributeNode = anAttributesNode->children; + while (anAttributeNode) { + if (isElementNode(anAttributeNode) && + std::string((char *) anAttributeNode->name) == NODE_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 f601a8f72..b335af3bd 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 b22c1f3b1..b7b855d56 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 6ba89d2cc..1b3c60774 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -12,6 +12,8 @@ #include +#include +#include #include #include @@ -117,10 +119,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 @@ -204,6 +203,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/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index ee47d10c9..0c7caa10b 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -164,7 +164,7 @@ QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const std::list allValidators; std::list > allArguments; - aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments); + aFactory->validators(myFeature->getKind(), attributeID(), allValidators, allArguments); QStringList aResult; std::list anArgumentList = allArguments.front(); diff --git a/src/PartSet/PartSet_WidgetFileSelector.cpp b/src/PartSet/PartSet_WidgetFileSelector.cpp index 4f4f9531d..e38ee8674 100644 --- a/src/PartSet/PartSet_WidgetFileSelector.cpp +++ b/src/PartSet/PartSet_WidgetFileSelector.cpp @@ -27,7 +27,7 @@ bool PartSet_WidgetFileSelector::restoreValue() 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::restoreValue(); @@ -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 8b71001e8..e93df15a9 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; } /// Fills the attribute with the value of the selected owner @@ -81,4 +81,4 @@ protected: bool myIsInVaildate; }; -#endif \ No newline at end of file +#endif -- 2.39.2