Salome HOME
Issue #1005: To improve user-friendship of error-messages for features and attributes
[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 <string>
17
18 //>> Forward declaration of xmlNodePtr.
19 typedef struct _xmlNode xmlNode;
20 typedef xmlNode *xmlNodePtr;
21 struct _xmlNode;
22 //<<
23
24 //>> Forward declaration of xmlDocPtr.
25 typedef struct _xmlDoc xmlDoc;
26 typedef xmlDoc *xmlDocPtr;
27 struct _xmlDoc;
28 //<<
29
30 /*!
31  * \class Config_WidgetAPI
32  * \ingroup Config
33  * \brief Provides low-level API for WidgetFactory for reading xml definitions of widgets
34  */
35 class CONFIG_EXPORT Config_WidgetAPI
36 {
37  public:
38   virtual ~Config_WidgetAPI();
39
40   //! Returns name of widget's node (attribute)
41   std::string widgetType() const;
42   //! Returns true if widget has container type, which means it able to contain other widgets
43   bool isGroupBoxWidget() const;
44   //! Returns true if widget has page type;
45   //! Page is container widget with combo box control to switch between pages
46   bool isPagedWidget() const;
47
48   //! Returns id of current feature
49   std::string featureId() const;
50   //! Returns id of current widget
51   std::string widgetId() const;
52   //! Returns icon of current widget
53   std::string widgetIcon() const;
54   //! Returns text for label of current widget
55   std::string widgetLabel() const;
56   //! Returns text for tooltip of current widget
57   std::string widgetTooltip() const;
58   //! Returns a custom property of current widget
59   std::string getProperty(const char* thePropName) const;
60
61   /*! Checks if the XML representation of widget has given attribute,
62    *  if yes - returns it's bool value, if no, or if the value can not
63    *  be converted to bool - returns theDefault.
64    *  \param theAttributeName attribute to check
65    *  \param theDefault default value on bad data
66    *  \return the boolean result
67    */
68   bool getBooleanAttribute(const char* theAttributeName, bool theDefault) const;
69
70  protected:
71   /// These fields are accessible for ModuleBase_WidgetFactory only
72   Config_WidgetAPI(std::string theRawXml);
73   //! Pass to the next (sibling) node of widget's xml definition. If impossible, returns false
74   bool toNextWidget();
75   //! Pass into the child node of widget's xml definition. If impossible, returns false
76   bool toChildWidget();
77   //! Pass into the parent node of widget's xml definition. If impossible, returns false
78   bool toParentWidget();
79
80  private:
81   xmlDocPtr myDoc; //!< Pointer to the root of widget's xml definition
82   xmlNodePtr myCurrentNode; //!< Pointer to the current node in the widget's xml definition
83   std::string myFeatureId;
84
85   friend class ModuleBase_WidgetFactory;
86 };
87
88 #endif /* CONFIG_WIDGETAPI_H_ */