LightweightRemoteGuiComponentPlugin.cpp
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::ArmarXGuiComponentPlugins
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
27// These are the headers which we try to avoid to include.
28// It is needed here to get the actual proxy.
29// But this is only in a source file, so only this file will compile slowly.
30// Any user of this plugin will not need to include it.
33
34#include <ArmarXGui/interface/RemoteGuiInterface.h>
36
37namespace armarx
38{
41
42 namespace plugins
43 {
44 static const std::string PROPERTY_NAME = "RemoteGuiName";
45
46 void
48 {
49 if (!remoteGuiObject)
50 {
51 parent<Component>().usingProxyFromProperty(PROPERTY_NAME);
52 }
53 }
54
55 void
57 {
58 if (!remoteGuiObject)
59 {
61 parent<Component>().getProxyFromProperty<RemoteGuiInterfacePrx>(PROPERTY_NAME);
62 }
63 }
64
65 void
69
70 void
72 {
73 if (runningTask)
74 {
75 RunningTaskPtr::dynamicCast(runningTask)->stop();
76 runningTask = nullptr;
77 }
78 }
79
80 void
84
85 void
87 PropertyDefinitionsPtr& properties)
88 {
89 if (!properties->hasDefinition(PROPERTY_NAME))
90 {
91 properties->defineOptionalProperty<std::string>(
92 "RemoteGuiName", "RemoteGuiProvider", "Name of the remote gui provider");
93 }
94 }
95 } // namespace plugins
96
101
102 void
104 std::string const& name,
105 RemoteGui::Client::Widget const& rootWidget,
107 {
108 if (!plugin->remoteGuiObject)
109 {
110 throw armarx::LocalException()
111 << "You tried to create a RemoteGui tab before the component was initialized.\n"
112 << "You can start creating tabs once you have entered your onConnectComponent().";
113 }
114 tab->create(name, plugin->remoteGuiObject, rootWidget);
115 plugin->tabs[name] = &tab->impl->proxy;
116 }
117
118 void
120 {
121 if (plugin->runningTask)
122 {
123 throw armarx::LocalException()
124 << "There is already a RunningTask which has not been stopped.";
125 }
126 RunningTaskPtr runningTask =
128 runningTask->start();
129 plugin->runningTask = runningTask;
130 }
131
132 bool
134 {
135 if (plugin->runningTask)
136 {
137 return !RunningTaskPtr::dynamicCast(plugin->runningTask)->isStopped();
138 }
139 else
140 {
141 return false;
142 }
143 }
144
145 void
147 {
149 while (RemoteGui_isRunning())
150 {
151 for (auto& tab : plugin->tabs)
152 {
153 tab.second->receiveUpdates();
154 }
156 for (auto& tab : plugin->tabs)
157 {
158 tab.second->sendUpdates();
159 }
160 c.waitForCycleDuration();
161 }
162 }
163
164} // namespace armarx
constexpr T c
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
IceUtil::Handle< RunningTask< LightweightRemoteGuiComponentPluginUser > > pointer_type
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
RunningTaskT::pointer_type RunningTaskPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
RunningTask< LightweightRemoteGuiComponentPluginUser > RunningTaskT
plugins::LightweightRemoteGuiComponentPlugin * plugin
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
std::unique_ptr< TabImpl > impl
Definition Tab.h:33
void create(std::string const &name, Ice::ObjectPrx const &remoteGuiObject, Widget const &rootWidget)
Definition Tab.cpp:31
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override