OpenWalnut  1.5.0dev
WUIWidgetFactory.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WUIWIDGETFACTORY_H
26 #define WUIWIDGETFACTORY_H
27 
28 #include <memory>
29 #include <string>
30 
31 
32 #include "WUIGridWidget.h"
33 #include "WUIPropertyGroupWidget.h"
34 #include "WUITabbedWidget.h"
35 #include "WUIViewWidget.h"
36 #include "core/common/WException.h"
37 #include "core/common/WPropertyTypes.h"
38 
39 /**
40  * Create instances of WUI widgets. This needs to be implemented by the UI/GUI developer.
41  */
43 {
44 public:
45  /**
46  * Convenience typedef for a std::shared_ptr< WUIWidgetFactory >.
47  */
48  typedef std::shared_ptr< WUIWidgetFactory > SPtr;
49 
50  /**
51  * Convenience typedef for a std::shared_ptr< const WUIWidgetFactory >.
52  */
53  typedef std::shared_ptr< const WUIWidgetFactory > ConstSPtr;
54 
55  /**
56  * Create a grid widget. This kind of widget is basically empty. Add others to it. Parentless widgets are initially invisible. Use
57  * WUIWidgetBase::show() to make them visible.
58  *
59  * \note this function blocks until the widget was created. Check the resulting pointer for NULL.
60  * \throw WException if something was wrong (like parent does not allow nesting). You need to catch this.
61  *
62  * \param title the title
63  * \param parent the parent widget which will contain this widget. Can be NULL.
64  *
65  * \return the widget. Might be NULL if something goes wrong.
66  */
67  virtual WUIGridWidget::SPtr createGridWidget( const std::string& title, WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const
68  {
69  if( parent )
70  {
71  if( !parent->allowNesting() )
72  {
73  throw WException( "Parent of widget \"" + title + "\" does not allow nesting." );
74  }
75  }
76  return createGridWidgetImpl( title, parent );
77  }
78 
79  /**
80  * Create a tabed widget. This kind of widget is basically empty. Add others to it. Parentless widgets are initially invisible. Use
81  * WUIWidgetBase::show() to make them visible.
82  *
83  * \note this function blocks until the widget was created. Check the resulting pointer for NULL.
84  * \throw WException if something was wrong (like parent does not allow nesting). You need to catch this.
85  *
86  * \param title the title
87  * \param parent the parent widget which will contain this widget. Can be NULL.
88  *
89  * \return the widget. Might be NULL if something goes wrong.
90  */
91  virtual WUITabbedWidget::SPtr createTabbedWidget( const std::string& title, WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const
92  {
93  if( parent )
94  {
95  if( !parent->allowNesting() )
96  {
97  throw WException( "Parent of widget \"" + title + "\" does not allow nesting." );
98  }
99  }
100  return createTabbedWidgetImpl( title, parent );
101  }
102 
103 
104  /**
105  * Create a property widget. Parentless widgets are initially invisible. Use
106  * WUIWidgetBase::show() to make them visible.
107  *
108  * \note this function blocks until the widget was created. Check the resulting pointer for NULL.
109  * \throw WException if something was wrong (like parent does not allow nesting). You need to catch this.
110  *
111  * \param title the title
112  * \param properties the property group
113  * \param parent the parent widget which will contain this widget. Can be NULL.
114  *
115  * \return the widget. Might be NULL if something goes wrong.
116  */
117  virtual WUIPropertyGroupWidget::SPtr createPropertyGroupWidget( const std::string& title, WPropGroup properties,
118  WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const
119  {
120  if( parent )
121  {
122  if( !parent->allowNesting() )
123  {
124  throw WException( "Parent of widget \"" + title + "\" does not allow nesting." );
125  }
126  }
127  return createPropertyGroupWidgetImpl( title, properties, parent );
128  }
129 
130  /**
131  * Instruct to open a new view widget. The specified condition should be the shutdown condition of the module, as the function returns only
132  * if the widget was created. To ensure that the creation is aborted properly if the module shuts down in the meantime, this condition is
133  * used. Parentless widgets are initially invisible. Use WUIWidgetBase::show() to make them visible.
134  *
135  * \note this function blocks until the widget was created. Check the resulting pointer for NULL.
136  *
137  * \throw WException if something was wrong (like parent does not allow nesting). You need to catch this.
138  *
139  * \param title the title of the widget
140  * \param projectionMode the kind of projection which should be used
141  * \param abordCondition a condition enforcing abort of widget creation. Can be NULL
142  * \param parent the parent widget which will contain this widget. Can be NULL.
143  *
144  * \return the created widget
145  */
147  std::string title,
148  WGECamera::ProjectionMode projectionMode,
149  std::shared_ptr< WCondition > abordCondition = WCondition::SPtr(),
150  WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const
151  {
152  if( parent )
153  {
154  if( !parent->allowNesting() )
155  {
156  throw WException( "Parent of widget \"" + title + "\" does not allow nesting." );
157  }
158  }
159  return createViewWidgetImpl( title, projectionMode, abordCondition, parent );
160  }
161 
162  /**
163  * Destructor.
164  */
166  {
167  }
168 
169  /**
170  * Query whether the WUI instance supports the WUI Widget interface properly as UIs can simply ignore the WUIWidgetFactory calls done in
171  * modules. This is used mainly by \ref WUIRequirement.
172  *
173  * \return true if the UI properly implements the WUI widget interface.
174  */
175  virtual bool implementsUI() const = 0;
176 protected:
177  /**
178  * Set the parent of a widget and notify parent about new child widget.
179  * This is needed as WUIWidgetBase and WUIWidgetFactory are friends. Friendship is not derivable.
180  *
181  * \param widget the widget to set the parent to
182  * \param parent the parent
183  */
184  void setParent( WUIWidgetBase::SPtr widget, WUIWidgetBase::SPtr parent ) const
185  {
186  if( parent )
187  {
188  widget->setParent( parent );
189 
190  // NOTE: the parent keeps a shared_ptr of its child. This avoids deletion of widgets. Only a call to WUIWidgetBase::close() cleans this
191  // up and thus releases the shared_ptr properly.
192  parent->registerChild( widget );
193  }
194  }
195 
196  /**
197  * Implementation of \ref createGridWidget.
198  *
199  * \param title the title
200  * \param parent the parent widget which will contain this widget. Can be NULL.
201  *
202  * \return the widget. Might be NULL if something goes wrong.
203  */
204  virtual WUIGridWidget::SPtr createGridWidgetImpl( const std::string& title, WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const = 0;
205 
206  /**
207  * Implementation of \ref createTabbedWidget.
208  *
209  * \param title the title
210  * \param parent the parent widget which will contain this widget. Can be NULL.
211  *
212  * \return the widget. Might be NULL if something goes wrong.
213  */
214  virtual WUITabbedWidget::SPtr createTabbedWidgetImpl( const std::string& title, WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const = 0;
215 
216  /**
217  * Implementation of \ref createPropertyGroupWidget.
218  *
219  * \param title the title
220  * \param properties the property group
221  * \param parent the parent widget which will contain this widget. Can be NULL.
222  *
223  * \return the widget. Might be NULL if something goes wrong.
224  */
225  virtual WUIPropertyGroupWidget::SPtr createPropertyGroupWidgetImpl( const std::string& title, WPropGroup properties,
226  WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const = 0;
227 
228  /**
229  * Implementation of \ref createViewWidget.
230  *
231  * \param title the title of the widget
232  * \param projectionMode the kind of projection which should be used
233  * \param abordCondition a condition enforcing abort of widget creation. Can be NULL
234  * \param parent the parent widget which will contain this widget. Can be NULL.
235  *
236  * \return the created widget
237  */
239  std::string title,
240  WGECamera::ProjectionMode projectionMode,
241  std::shared_ptr< WCondition > abordCondition = WCondition::SPtr(),
242  WUIWidgetBase::SPtr parent = WUIWidgetBase::SPtr() ) const = 0;
243 
244 private:
245 };
246 
247 #endif // WUIWIDGETFACTORY_H
248 
std::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
Definition: WCondition.h:48
Basic exception handler.
Definition: WException.h:39
ProjectionMode
List of possible camera modes.
Definition: WGECamera.h:44
std::shared_ptr< WUIGridWidget > SPtr
Convenience typedef for a std::shared_ptr< WUIGridWidget >.
Definition: WUIGridWidget.h:46
std::shared_ptr< WUIPropertyGroupWidget > SPtr
Convenience typedef for a std::shared_ptr< WUIPropertyGroupWidget >.
std::shared_ptr< WUITabbedWidget > SPtr
Convenience typedef for a std::shared_ptr< WUITabbedWidget >.
std::shared_ptr< WUIViewWidget > SPtr
Abbreviation for a shared pointer on a instance of this class.
Definition: WUIViewWidget.h:72
std::shared_ptr< WUIWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIWidgetBase >.
Definition: WUIWidgetBase.h:51
Create instances of WUI widgets.
virtual bool implementsUI() const =0
Query whether the WUI instance supports the WUI Widget interface properly as UIs can simply ignore th...
virtual WUITabbedWidget::SPtr createTabbedWidget(const std::string &title, WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const
Create a tabed widget.
virtual WUIPropertyGroupWidget::SPtr createPropertyGroupWidgetImpl(const std::string &title, WPropGroup properties, WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const =0
Implementation of createPropertyGroupWidget.
std::shared_ptr< const WUIWidgetFactory > ConstSPtr
Convenience typedef for a std::shared_ptr< const WUIWidgetFactory >.
virtual WUIGridWidget::SPtr createGridWidgetImpl(const std::string &title, WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const =0
Implementation of createGridWidget.
std::shared_ptr< WUIWidgetFactory > SPtr
Convenience typedef for a std::shared_ptr< WUIWidgetFactory >.
virtual WUITabbedWidget::SPtr createTabbedWidgetImpl(const std::string &title, WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const =0
Implementation of createTabbedWidget.
virtual WUIViewWidget::SPtr createViewWidgetImpl(std::string title, WGECamera::ProjectionMode projectionMode, std::shared_ptr< WCondition > abordCondition=WCondition::SPtr(), WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const =0
Implementation of createViewWidget.
virtual WUIGridWidget::SPtr createGridWidget(const std::string &title, WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const
Create a grid widget.
virtual WUIViewWidget::SPtr createViewWidget(std::string title, WGECamera::ProjectionMode projectionMode, std::shared_ptr< WCondition > abordCondition=WCondition::SPtr(), WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const
Instruct to open a new view widget.
void setParent(WUIWidgetBase::SPtr widget, WUIWidgetBase::SPtr parent) const
Set the parent of a widget and notify parent about new child widget.
virtual ~WUIWidgetFactory()
Destructor.
virtual WUIPropertyGroupWidget::SPtr createPropertyGroupWidget(const std::string &title, WPropGroup properties, WUIWidgetBase::SPtr parent=WUIWidgetBase::SPtr()) const
Create a property widget.