Salome HOME
Support of additional attributes if ModelWidget and features
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 11 Aug 2015 10:28:44 +0000 (13:28 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Wed, 12 Aug 2015 11:29:31 +0000 (14:29 +0300)
src/Config/Config_Keywords.h
src/Config/Config_WidgetAPI.cpp
src/Config/Config_WidgetAPI.h
src/ExchangePlugin/plugin-Exchange.xml
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetFactory.h
src/PartSet/PartSet_WidgetFileSelector.cpp
src/PartSet/PartSet_WidgetMultiSelector.h

index 4a39432139760c4e7fca8f5b8411cb537822669a..3cad01b2853d37b6582b3a3ec21ece5ba1f35471 100644 (file)
@@ -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;
index 1249f9ab817ecd59e05b037d57a0390ad19caa40..214b4bdd5240c2d1280677a42161b677851b2e2f 100644 (file)
@@ -16,7 +16,7 @@
 
 #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);
@@ -63,6 +63,29 @@ bool Config_WidgetAPI::toParentWidget()
   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_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<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();
+}
+
index e9531e49fb7af27c9615c666c2e172a0a7af2df9..a99ba1a588de0d6cb19945ddf7dbca184821784a 100644 (file)
@@ -13,6 +13,7 @@
 #include <Config_def.h>
 
 #include <cstdarg>
+#include <list>
 #include <string>
 
 //>> 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<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.
@@ -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<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
index e98d9f710036f7a02d88559ddd2edfa116c290de..061e231800be0469db064462791aaed05835a07b 100644 (file)
       <feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
         <export_file_selector id="file_path" 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="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>
index 63d8095fcc206036af95483e000fb618a4d20c3b..c9e21b2c4a8c3b4141cb65954474222962be97b1 100644 (file)
@@ -35,6 +35,12 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
   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()));
 }
 
@@ -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;
index cad3f174ca4166c214b8571c2c3f58b31d409789..b74bf54f7040a477ee0a2665300a97ca1bffa5ea 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <ModelAPI_Feature.h>
 
+#include <QList>
+#include <QMap>
 #include <QWidget>
 
 #include <memory>
@@ -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<std::string, QList<std::string> > myRoleAttributesID;
+
   /// Name of parent
   std::string myParentId;    
 
index 1e1f29fa76e8dfc54e6de9b682f1efc2881cc0f5..f7e7bd4927beee3e177948cac8cddb1419fdc287 100644 (file)
@@ -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
 {
index 117a8c866fcda85762ecff8fbca710757e5f16b6..db26f45a7a982cbe4b5f949d6a95fa012abe0df4 100644 (file)
@@ -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();
index e0479547ed5b09fda35eb3d9ca34c9b03d73dc5c..a7f19df947bdc4b4c5f79989d8628b17bfc89d6f 100644 (file)
@@ -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