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 #include <ArmarXGui/interface/RemoteGuiInterface.h>
35 
36 
37 namespace armarx
38 {
41 
42  namespace plugins
43  {
44  static const std::string PROPERTY_NAME = "RemoteGuiName";
45 
47  {
48  if (!remoteGuiObject)
49  {
50  parent<Component>().usingProxyFromProperty(PROPERTY_NAME);
51  }
52  }
53 
55  {
56  if (!remoteGuiObject)
57  {
58  remoteGuiObject = parent<Component>().getProxyFromProperty<RemoteGuiInterfacePrx>(PROPERTY_NAME);
59  }
60  }
62  {
63  }
64 
66  {
67  if (runningTask)
68  {
69  RunningTaskPtr::dynamicCast(runningTask)->stop();
70  runningTask = nullptr;
71  }
72  }
73 
75  {
76  }
77 
79  {
80  if (!properties->hasDefinition(PROPERTY_NAME))
81  {
82  properties->defineOptionalProperty<std::string>(
83  "RemoteGuiName",
84  "RemoteGuiProvider",
85  "Name of the remote gui provider");
86  }
87  }
88  }
89 
91  {
93  }
94 
96  std::string const& name,
97  RemoteGui::Client::Widget const& rootWidget,
99  {
100  if (!plugin->remoteGuiObject)
101  {
102  throw armarx::LocalException()
103  << "You tried to create a RemoteGui tab before the component was initialized.\n"
104  << "You can start creating tabs once you have entered your onConnectComponent().";
105  }
106  tab->create(name, plugin->remoteGuiObject, rootWidget);
107  plugin->tabs[name] = &tab->impl->proxy;
108  }
109 
111  {
112  if (plugin->runningTask)
113  {
114  throw armarx::LocalException()
115  << "There is already a RunningTask which has not been stopped.";
116  }
117  RunningTaskPtr runningTask = new RunningTaskT(
118  this,
120  runningTask->start();
121  plugin->runningTask = runningTask;
122  }
123 
125  {
126  if (plugin->runningTask)
127  {
128  return !RunningTaskPtr::dynamicCast(plugin->runningTask)->isStopped();
129  }
130  else
131  {
132  return false;
133  }
134  }
135 
137  {
139  while (RemoteGui_isRunning())
140  {
141  for (auto& tab : plugin->tabs)
142  {
143  tab.second->receiveUpdates();
144  }
146  for (auto& tab : plugin->tabs)
147  {
148  tab.second->sendUpdates();
149  }
150  c.waitForCycleDuration();
151  }
152  }
153 
154 }
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_isRunning
bool RemoteGui_isRunning()
Definition: LightweightRemoteGuiComponentPlugin.cpp:124
armarx::plugins::LightweightRemoteGuiComponentPlugin::tabs
std::map< std::string, RemoteGui::TabProxy * > tabs
Definition: LightweightRemoteGuiComponentPlugin.h:64
armarx::plugins::LightweightRemoteGuiComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: LightweightRemoteGuiComponentPlugin.cpp:46
armarx::plugins::LightweightRemoteGuiComponentPlugin::remoteGuiObject
Ice::ObjectPrx remoteGuiObject
Definition: LightweightRemoteGuiComponentPlugin.h:62
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_run
void RemoteGui_run()
Definition: LightweightRemoteGuiComponentPlugin.cpp:136
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_updatePeriodInMS
int RemoteGui_updatePeriodInMS
Definition: LightweightRemoteGuiComponentPlugin.h:88
armarx::LightweightRemoteGuiComponentPluginUser::plugin
plugins::LightweightRemoteGuiComponentPlugin * plugin
Definition: LightweightRemoteGuiComponentPlugin.h:89
armarx::plugins::LightweightRemoteGuiComponentPlugin::postOnConnectComponent
void postOnConnectComponent() override
Definition: LightweightRemoteGuiComponentPlugin.cpp:61
armarx::RemoteGui::Client::Tab
Definition: Tab.h:15
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::RemoteGui::Client::Tab::impl
std::unique_ptr< TabImpl > impl
Definition: Tab.h:33
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ManagedIceObject::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObject.h:182
armarx::plugins::LightweightRemoteGuiComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: LightweightRemoteGuiComponentPlugin.cpp:54
RunningTask.h
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
plugins
LightweightRemoteGuiComponentPlugin.h
armarx::RemoteGui::Client::Widget
Definition: Widgets.h:21
armarx::plugins::LightweightRemoteGuiComponentPlugin::preOnDisconnectComponent
void preOnDisconnectComponent() override
Definition: LightweightRemoteGuiComponentPlugin.cpp:65
armarx::RemoteGui::Client::Tab::create
void create(std::string const &name, Ice::ObjectPrx const &remoteGuiObject, Widget const &rootWidget)
Definition: Tab.cpp:31
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_update
virtual void RemoteGui_update()=0
Component.h
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:110
CycleUtil.h
armarx::plugins::LightweightRemoteGuiComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: LightweightRemoteGuiComponentPlugin.cpp:78
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_createTab
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
Definition: LightweightRemoteGuiComponentPlugin.cpp:95
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::RunningTaskT
RunningTask< LightweightRemoteGuiComponentPluginUser > RunningTaskT
Definition: LightweightRemoteGuiComponentPlugin.cpp:39
armarx::RunningTask::pointer_type
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
Definition: RunningTask.h:178
armarx::LightweightRemoteGuiComponentPluginUser::LightweightRemoteGuiComponentPluginUser
LightweightRemoteGuiComponentPluginUser()
Definition: LightweightRemoteGuiComponentPlugin.cpp:90
armarx::plugins::LightweightRemoteGuiComponentPlugin::postOnDisconnectComponent
void postOnDisconnectComponent() override
Definition: LightweightRemoteGuiComponentPlugin.cpp:74
armarx::plugins::LightweightRemoteGuiComponentPlugin::runningTask
IceUtil::Handle< IceUtil::Shared > runningTask
Definition: LightweightRemoteGuiComponentPlugin.h:63
Impl.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28