Salome HOME
Support of additional attributes if ModelWidget and features
[modules/shaper.git] / src / Config / Config_WidgetAPI.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_WidgetAPI.h
5  *
6  *  Created on: Apr 1, 2014
7  *      Author: sbh
8  */
9
10 #ifndef CONFIG_WIDGETAPI_H_
11 #define CONFIG_WIDGETAPI_H_
12
13 #include <Config_def.h>
14
15 #include <cstdarg>
16 #include <list>
17 #include <string>
18
19 //>> Forward declaration of xmlNodePtr.
20 typedef struct _xmlNode xmlNode;
21 typedef xmlNode *xmlNodePtr;
22 struct _xmlNode;
23 //<<
24
25 //>> Forward declaration of xmlDocPtr.
26 typedef struct _xmlDoc xmlDoc;
27 typedef xmlDoc *xmlDocPtr;
28 struct _xmlDoc;
29 //<<
30
31 /*!
32  * \class Config_WidgetAPI
33  * \ingroup Config
34  * \brief Provides low-level API for WidgetFactory for reading xml definitions of widgets
35  */
36 class CONFIG_EXPORT Config_WidgetAPI
37 {
38  public:
39   virtual ~Config_WidgetAPI();
40
41   //! Returns name of widget's node (attribute)
42   std::string widgetType() const;
43   //! Returns true if widget has container type, which means it able to contain other widgets
44   bool isGroupBoxWidget() const;
45   //! Returns true if widget has page type;
46   //! Page is container widget with combo box control to switch between pages
47   bool isPagedWidget() const;
48
49   //! Returns id of current widget
50   std::string widgetId() const;
51   //! Returns icon of current widget
52   std::string widgetIcon() const;
53   //! Returns text for label of current widget
54   std::string widgetLabel() const;
55   //! Returns text for tooltip of current widget
56   std::string widgetTooltip() const;
57   //! Returns a custom property of current widget
58   std::string getProperty(const char* thePropName) const;
59
60   /*! Returns a list of attributes.
61    *  If theRole is 0 then returns all attributes.
62    *  If theRole is "main" then returns widgetId().
63    */
64   std::list<std::string> getAttributes(const std::string& theRole = std::string()) const;
65   //! Returns a custom property of attribute
66   std::string getAttributeProperty(const std::string& theAttribute,
67                                    const std::string& thePropName) const;
68
69   /*! Checks if the XML representation of widget has given attribute,
70    *  if yes - returns it's bool value, if no, or if the value can not
71    *  be converted to bool - returns theDefault.
72    *  \param theAttributeName attribute to check
73    *  \param theDefault default value on bad data
74    *  \return the boolean result
75    */
76   bool getBooleanAttribute(const char* theAttributeName, bool theDefault) const;
77
78  protected:
79   /// These fields are accessible for ModuleBase_WidgetFactory only
80   Config_WidgetAPI(const std::string& theRawXml);
81   //! Pass to the next (sibling) node of widget's xml definition. If impossible, returns false
82   bool toNextWidget();
83   //! Pass into the child node of widget's xml definition. If impossible, returns false
84   bool toChildWidget();
85   //! Pass into the parent node of widget's xml definition. If impossible, returns false
86   bool toParentWidget();
87
88   std::list<xmlNodePtr> attributes() const;
89
90  private:
91   xmlDocPtr myDoc; //!< Pointer to the root of widget's xml definition
92   xmlNodePtr myCurrentNode; //!< Pointer to the current node in the widget's xml definition
93
94   friend class ModuleBase_WidgetFactory;
95 };
96
97 #endif /* CONFIG_WIDGETAPI_H_ */