DebugDrawerHelperComponentPlugin.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 RobotAPI::ArmarXObjects::RobotAPIComponentPlugins
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 
25 
27 
28 
29 namespace armarx::plugins
30 {
32  ComponentPlugin(parent, pre),
33  _pre{pre}
34  {
36  addPlugin(_robotStateComponentPlugin, pre);
37  addPluginDependency(_robotStateComponentPlugin);
38  }
39 
41  {
43  ARMARX_CHECK_NOT_NULL(_debugDrawerHelper);
44  return *_debugDrawerHelper;
45  }
46 
48  {
50  ARMARX_CHECK_NOT_NULL(_debugDrawerHelper);
51  return *_debugDrawerHelper;
52  }
53 
55  {
58  }
59 
60  std::unique_lock<std::recursive_mutex> DebugDrawerHelperComponentPlugin::getDebugDrawerHelperLock() const
61  {
63  return std::unique_lock{_debugDrawerHelperMutex};
64  }
65 
67  {
69  if (_pre.empty())
70  {
71  return parent().getName();
72  }
73  return _pre + "_" + parent().getName();
74  }
75 
77  {
79  if (!_debugDrawerTopic)
80  {
81  parent<Component>().offeringTopicFromProperty(_propertyName);
82  }
83  }
84 
86  {
88  if (!_debugDrawerTopic)
89  {
90  parent<Component>().getTopicFromProperty(_debugDrawerTopic, _propertyName);
91  }
92  if (!_debugDrawerHelper)
93  {
94  const auto robotID = _pre + "_DebugDrawerHelperComponentPlugin_" + parent().getName();
95  if (!_robotStateComponentPlugin->hasRobot(robotID))
96  {
97  _robotStateComponentPlugin->addRobot(robotID,
98  VirtualRobot::RobotIO::eStructure);
99  }
100 
101  const auto robot = _robotStateComponentPlugin->getRobot(robotID);
102  ARMARX_CHECK_NOT_NULL(_debugDrawerTopic);
103  ARMARX_CHECK_NOT_NULL(robot);
104  _debugDrawerHelper = std::make_unique<DebugDrawerHelper>(
105  _debugDrawerTopic,
107  robot);
108  }
109  }
110 
112  {
113  ARMARX_TRACE;
114  if (!_doNotClearLayersOnDisconnect)
115  {
116  try
117  {
118  _debugDrawerHelper->cyclicCleanup();
119  _debugDrawerHelper->cyclicCleanup();
120  _debugDrawerHelper->clearLayer();
121  }
122  catch (...) {}
123  }
124  _debugDrawerTopic = nullptr;
125  }
126 
128  {
129  ARMARX_TRACE;
130  if (!properties->hasDefinition(_propertyName))
131  {
132  properties->defineOptionalProperty<std::string>(
133  _propertyName,
134  "DebugDrawerUpdates",
135  "Name of the debug drawer topic");
136  }
137  }
138 
140  {
141  ARMARX_TRACE;
142  return _debugDrawerHelper->getRobot();
143  }
144 
146  {
147  ARMARX_TRACE;
148  const auto g = getDebugDrawerHelperLock();
150  return _robotStateComponentPlugin->synchronizeLocalClone(getDebugDrawerHelperRobot());
151  }
152 
154  {
155  ARMARX_TRACE;
156  const auto g = getDebugDrawerHelperLock();
158  return _robotStateComponentPlugin->synchronizeLocalClone(getDebugDrawerHelperRobot(), timestamp);
159  }
160 
162  {
163  ARMARX_TRACE;
164  const auto g = getDebugDrawerHelperLock();
166  return _robotStateComponentPlugin->synchronizeLocalClone(getDebugDrawerHelperRobot(), state);
167  }
168 
170  {
171  ARMARX_TRACE;
172  _doNotClearLayersOnDisconnect = !b;
173  }
174 }
175 
176 namespace armarx
177 {
179  {
180  ARMARX_TRACE;
181  addPlugin(_debugDrawerHelperComponentPlugin);
182  }
183 
185  {
186  ARMARX_TRACE;
187  return *_debugDrawerHelperComponentPlugin;
188  }
189 
191  {
192  ARMARX_TRACE;
193  return *_debugDrawerHelperComponentPlugin;
194  }
195 
197  {
198  ARMARX_TRACE;
200  }
201 
203  {
204  ARMARX_TRACE;
206  }
207 
209  {
210  ARMARX_TRACE;
212  }
213 
214  std::unique_lock<std::recursive_mutex> DebugDrawerHelperComponentPluginUser::getDebugDrawerHelperLock() const
215  {
216  ARMARX_TRACE;
218  }
220  {
221  ARMARX_TRACE;
223  }
224 
226  {
227  ARMARX_TRACE;
229  }
230 
232  {
233  ARMARX_TRACE;
235  }
237  {
238  ARMARX_TRACE;
240  }
242  {
243  ARMARX_TRACE;
245  }
246 }
armarx::DebugDrawerHelperComponentPluginUser::getDebugDrawerHelperLock
std::unique_lock< std::recursive_mutex > getDebugDrawerHelperLock() const
Definition: DebugDrawerHelperComponentPlugin.cpp:214
armarx::plugins::DebugDrawerHelperComponentPlugin::getDebugDrawerLayerName
std::string getDebugDrawerLayerName() const
Definition: DebugDrawerHelperComponentPlugin.cpp:66
armarx::plugins::DebugDrawerHelperComponentPlugin::getDebugDrawerTopic
const DebugDrawerInterfacePrx & getDebugDrawerTopic() const
Definition: DebugDrawerHelperComponentPlugin.cpp:54
armarx::plugins::DebugDrawerHelperComponentPlugin::setClearLayersOnDisconnect
void setClearLayersOnDisconnect(bool b)
Definition: DebugDrawerHelperComponentPlugin.cpp:169
armarx::plugins::DebugDrawerHelperComponentPlugin::DebugDrawerHelperComponentPlugin
DebugDrawerHelperComponentPlugin(ManagedIceObject &parent, std::string pre)
Definition: DebugDrawerHelperComponentPlugin.cpp:31
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
armarx::plugins::DebugDrawerHelperComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: DebugDrawerHelperComponentPlugin.cpp:76
armarx::DebugDrawerHelperComponentPluginUser::getDebugDrawerLayerName
std::string getDebugDrawerLayerName() const
Definition: DebugDrawerHelperComponentPlugin.cpp:219
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
trace.h
armarx::plugins::DebugDrawerHelperComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: DebugDrawerHelperComponentPlugin.cpp:85
armarx::ManagedIceObject::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObject.h:182
armarx::DebugDrawerHelperComponentPluginUser::synchronizeDebugDrawerHelperRobot
bool synchronizeDebugDrawerHelperRobot() const
Definition: DebugDrawerHelperComponentPlugin.cpp:231
DebugDrawerHelperComponentPlugin.h
armarx::DebugDrawerHelperComponentPluginUser::DebugDrawerHelperComponentPluginUser
DebugDrawerHelperComponentPluginUser()
Definition: DebugDrawerHelperComponentPlugin.cpp:178
armarx::plugins::RobotStateComponentPlugin::hasRobot
bool hasRobot(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:45
armarx::plugins::RobotStateComponentPlugin::synchronizeLocalClone
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
Definition: RobotStateComponentPlugin.cpp:155
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::plugins::DebugDrawerHelperComponentPlugin::getDebugDrawerHelperRobot
VirtualRobot::RobotPtr getDebugDrawerHelperRobot() const
Definition: DebugDrawerHelperComponentPlugin.cpp:139
armarx::DebugDrawerHelperComponentPluginUser::getDebugDrawerHelper
const DebugDrawerHelper & getDebugDrawerHelper() const
Definition: DebugDrawerHelperComponentPlugin.cpp:196
armarx::plugins::RobotStateComponentPlugin::getRobot
VirtualRobot::RobotPtr getRobot(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:113
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::ComponentPlugin
Definition: ComponentPlugin.h:38
armarx::plugins::DebugDrawerHelperComponentPlugin::synchronizeDebugDrawerHelperRobot
bool synchronizeDebugDrawerHelperRobot() const
Definition: DebugDrawerHelperComponentPlugin.cpp:145
armarx::plugins::DebugDrawerHelperComponentPlugin::postOnDisconnectComponent
void postOnDisconnectComponent() override
Definition: DebugDrawerHelperComponentPlugin.cpp:111
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::DebugDrawerHelperComponentPluginUser::getDebugDrawerHelperPlugin
const DebugDrawerHelperComponentPlugin & getDebugDrawerHelperPlugin() const
Definition: DebugDrawerHelperComponentPlugin.cpp:184
armarx::DebugDrawerHelper
The DebugDrawerHelper class provides draw functions in a given frame (static matrix or robot node) an...
Definition: DebugDrawerHelper.h:124
armarx::plugins::RobotStateComponentPlugin::addRobot
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
Definition: RobotStateComponentPlugin.cpp:51
armarx::plugins::DebugDrawerHelperComponentPlugin::getDebugDrawerHelper
const DebugDrawerHelper & getDebugDrawerHelper() const
Definition: DebugDrawerHelperComponentPlugin.cpp:40
Component.h
armarx::DebugDrawerHelper::getDebugDrawer
const DebugDrawerInterfacePrx & getDebugDrawer() const
Definition: DebugDrawerHelper.cpp:358
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
armarx::plugins::DebugDrawerHelperComponentPlugin
Brief description of class RobotAPIComponentPlugins.
Definition: DebugDrawerHelperComponentPlugin.h:40
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::DebugDrawerHelperComponentPluginUser::getDebugDrawerTopic
const DebugDrawerInterfacePrx & getDebugDrawerTopic() const
Definition: DebugDrawerHelperComponentPlugin.cpp:208
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::plugins::DebugDrawerHelperComponentPlugin::getDebugDrawerHelperLock
std::unique_lock< std::recursive_mutex > getDebugDrawerHelperLock() const
Definition: DebugDrawerHelperComponentPlugin.cpp:60
armarx::plugins::DebugDrawerHelperComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: DebugDrawerHelperComponentPlugin.cpp:127
armarx::DebugDrawerHelperComponentPluginUser::getDebugDrawerHelperRobot
VirtualRobot::RobotPtr getDebugDrawerHelperRobot() const
Definition: DebugDrawerHelperComponentPlugin.cpp:225
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18