RemoteGuiExample2.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ArmarXGui::ArmarXObjects::RemoteGuiExample2
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
26 
28 
31 
32 
33 namespace armarx
34 {
35  using namespace armarx::RemoteGui::Client;
36 
37  struct WidgetsTab : Tab
38  {
43 
46 
49 
51  };
52 
53  struct EventsTab : Tab
54  {
58  };
59 
60 
61 
62  /**
63  * @defgroup Component-RemoteGuiExample2 RemoteGuiExample2
64  * @ingroup ArmarXGui-Components
65  *
66  * An example for how to use the remote gui framework for building simple
67  * user interfaces over ice.
68  *
69  * Often, you want to allow simple user interactions with an ArmarX
70  * component, e.g. to tweak a parameter, enable a feature or visualization
71  * or trigger an action. Building a dedicated, full-blown gui plugin can
72  * be very tedious for simple cases.
73  * For this use case, ArmarX offers a remote gui framework for building
74  * user interfaces over ice.
75  *
76  * This component demonstrates how to do this based on two examples:
77  * \li A *widgets* tab focusing on how to add different widget types,
78  * such as sliders, spinners, check boxes and buttons.
79  * \li An *events* tab showing how you can change the remote gui as a
80  * reaction to events triggered by the user via the remote gui.
81  *
82  * To run the example:
83  * \li Start the component `RemoteGuiProvider`
84  * \li Open the gui plugin `RemoteGui`
85  * \li Start the component `RemoteGuiExample2`
86  * \li Observe and interact with the created tabs in the `RemoteGui` widget.
87  *
88  * The scenario `RemoteGuiTest` starts the necessary components,
89  * including the example component.
90  *
91  * A component which wants to offer a remote gui needs to:
92  * \li `#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>`
93  * \li Inherit from the `armarx::LightweightRemoteGuiComponentPluginUser`
94  * \li Build and create a `armarx::RemoteGui::Client::Tab` in its
95  * `onConnectComponent()` using `RemoteGui_createTab()`
96  * \li Start the update processing thread in `onConnectComponent()`
97  * using `RemoteGui_startRunningTask()`
98  * \li Implement the virtual function `RemoteGui_update()` to process gui
99  * events (e.g. changed values, pressed buttons)
100  *
101  * `RemoteGui_createTab()` can be called once by the component to create
102  * a tab in the `RemoteGui` widget. In can be called again later to
103  * rebuild the tab, e.g. if the gui's structure should change.
104  *
105  * `RemoteGui_update()` is called by a processing thread at a regular
106  * interval. There, you can check the widgets for whether their value has
107  * changed (`.hasValueChanged()`) or whether a button was pressed
108  * (`.wasClicked()`).
109  *
110  * **Important note:** `RemoteGui_update()` is called from a separate thread,
111  * so you have to use synchronization mechanisms such as `std::mutex` and
112  * `std::scoped_lock` to synchronize access to variables which are
113  * accessed by different threads.
114  *
115  * \see RemoteGuiExample2
116  *
117  *
118  * @class RemoteGuiExample2
119  * @ingroup Component-RemoteGuiExample2
120  *
121  * @brief Brief description of class RemoteGuiExample2.
122  *
123  * @see @ref Component-RemoteGuiExample2
124  */
126  : virtual public armarx::Component
128  {
129  public:
130 
132 
133  /// @see armarx::ManagedIceObject::getDefaultName()
134  std::string getDefaultName() const override;
135  static std::string GetDefaultName();
136 
137 
138  protected:
139 
140  /// @see PropertyUser::createPropertyDefinitions()
141  armarx::PropertyDefinitionsPtr createPropertyDefinitions() override;
142 
143  /// @see armarx::ManagedIceObject::onInitComponent()
144  void onInitComponent() override;
145 
146  /// @see armarx::ManagedIceObject::onConnectComponent()
147  void onConnectComponent() override;
148 
149  /// @see armarx::ManagedIceObject::onDisconnectComponent()
150  void onDisconnectComponent() override;
151 
152  /// @see armarx::ManagedIceObject::onExitComponent()
153  void onExitComponent() override;
154 
155 
156  private:
157 
158  void RemoteGui_update() override;
159 
160  void createTab_Widgets();
161  void updateTab_Widgets();
162 
163  void createTab_Events();
164  void updateTab_Events();
165 
166 
167  private:
168 
169  EventsTab eventsTab;
170  WidgetsTab widgetsTab;
171 
172  };
173 }
armarx::WidgetsTab::lineEdit
LineEdit lineEdit
Definition: RemoteGuiExample2.h:39
armarx::RemoteGui::Client::ToggleButton
Definition: Widgets.h:139
armarx::WidgetsTab::floatSpin
FloatSpinBox floatSpin
Definition: RemoteGuiExample2.h:47
armarx::WidgetsTab::checkBox
CheckBox checkBox
Definition: RemoteGuiExample2.h:41
armarx::EventsTab
Definition: RemoteGuiExample2.h:53
armarx::WidgetsTab
Definition: RemoteGuiExample2.h:37
armarx::RemoteGui::Client::Tab
Definition: Tab.h:15
armarx::WidgetsTab::toggle
ToggleButton toggle
Definition: RemoteGuiExample2.h:42
armarx::WidgetsTab::combo
ComboBox combo
Definition: RemoteGuiExample2.h:40
Tab.h
LightweightRemoteGuiComponentPlugin.h
armarx::WidgetsTab::intSpin
IntSpinBox intSpin
Definition: RemoteGuiExample2.h:44
armarx::EventsTab::buttonDown
Button buttonDown
Definition: RemoteGuiExample2.h:57
armarx::RemoteGui::Client::FloatSlider
Definition: Widgets.h:107
armarx::RemoteGui::Client::IntSlider
Definition: Widgets.h:81
armarx::WidgetsTab::button
Button button
Definition: RemoteGuiExample2.h:50
armarx::RemoteGui::Client::LineEdit
Definition: Widgets.h:40
armarx::RemoteGui::Client::ComboBox
Definition: Widgets.h:50
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:73
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::WidgetsTab::intSlider
IntSlider intSlider
Definition: RemoteGuiExample2.h:45
armarx::RemoteGuiExample2
Brief description of class RemoteGuiExample2.
Definition: RemoteGuiExample2.h:125
armarx::EventsTab::buttonUp
Button buttonUp
Definition: RemoteGuiExample2.h:56
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGui::Client::IntSpinBox
Definition: Widgets.h:69
armarx::RemoteGui::Client::CheckBox
Definition: Widgets.h:129
Widgets.h
armarx::RemoteGui::Client::Button
Definition: Widgets.h:120
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::WidgetsTab::floatSlider
FloatSlider floatSlider
Definition: RemoteGuiExample2.h:48
armarx::RemoteGui::Client::FloatSpinBox
Definition: Widgets.h:93
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::EventsTab::spinInt
IntSpinBox spinInt
Definition: RemoteGuiExample2.h:55