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";
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;
#include <string>
-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);
return myCurrentNode != NULL;
}
+std::list<xmlNodePtr> Config_WidgetAPI::attributes() const
+{
+ std::list<xmlNodePtr> 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 = "";
{
return getProperty(ATTR_TOOLTIP);
}
+
+std::list<std::string> Config_WidgetAPI::getAttributes(const std::string& theRole/* = std::string()*/) const
+{
+ std::list<std::string> aResult;
+
+ if (theRole.empty() || theRole == ATTR_MAIN_ROLE)
+ aResult.push_back(widgetId());
+
+ if (theRole == ATTR_MAIN_ROLE)
+ return aResult;
+
+ std::list<xmlNodePtr> 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<xmlNodePtr> 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();
+}
+
#include <Config_def.h>
#include <cstdarg>
+#include <list>
#include <string>
//>> Forward declaration of xmlNodePtr.
//! 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<std::string> 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.
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
//! Pass into the parent node of widget's xml definition. If impossible, returns false
bool toParentWidget();
+ std::list<xmlNodePtr> 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
<feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
<export_file_selector id="export_file_selector" type="save" title="Export file" path="">
<validator id="ExchangePlugin_ExportFormat" parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES-5.1,IGES|IGS:IGES-5.3" />
+ <attributes>
+ <attribute id="export_file_format" role="format" />
+ </attributes>
</export_file_selector>
<multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids" />
</feature>
</group>
</workbench>
-</plugin>
\ No newline at end of file
+</plugin>
myAttributeID = theData ? theData->widgetId() : "";
myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true);
+ std::list<std::string> 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()));
}
}
}
+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;
#include <ModelAPI_Feature.h>
+#include <QList>
+#include <QMap>
#include <QWidget>
#include <memory>
/// 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
/// The attribute name of the model feature
std::string myAttributeID;
+ /// The list of attribute names of the model feature for a role
+ QMap<std::string, QList<std::string> > myRoleAttributesID;
+
/// Name of parent
std::string myParentId;
/**
* \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
{
std::list<ModelAPI_Validator*> allValidators;
std::list<std::list<std::string> > allArguments;
- aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments);
+ aFactory->validators(myFeature->getKind(), attributeID(), allValidators, allArguments);
QStringList aResult;
std::list<std::string> anArgumentList = allArguments.front();
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();
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();
/**
* \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
/// 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);
/// \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
bool myIsInVaildate;
};
-#endif
\ No newline at end of file
+#endif