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
24
27
28namespace armarx::plugins
29{
31 std::string pre) :
32 ComponentPlugin(parent, pre), _pre{pre}
33 {
35 addPlugin(_robotStateComponentPlugin, pre);
36 addPluginDependency(_robotStateComponentPlugin);
37 }
38
41 {
43 ARMARX_CHECK_NOT_NULL(_debugDrawerHelper);
44 return *_debugDrawerHelper;
45 }
46
49 {
51 ARMARX_CHECK_NOT_NULL(_debugDrawerHelper);
52 return *_debugDrawerHelper;
53 }
54
61
62 std::unique_lock<std::recursive_mutex>
64 {
66 return std::unique_lock{_debugDrawerHelperMutex};
67 }
68
69 std::string
71 {
73 if (_pre.empty())
74 {
75 return parent().getName();
76 }
77 return _pre + "_" + parent().getName();
78 }
79
80 void
82 {
84 if (!_debugDrawerTopic)
85 {
86 parent<Component>().offeringTopicFromProperty(_propertyName);
87 }
88 }
89
90 void
92 {
94 if (!_debugDrawerTopic)
95 {
96 parent<Component>().getTopicFromProperty(_debugDrawerTopic, _propertyName);
97 }
98 if (!_debugDrawerHelper)
99 {
100 const auto robotID = _pre + "_DebugDrawerHelperComponentPlugin_" + parent().getName();
101 if (!_robotStateComponentPlugin->hasRobot(robotID))
102 {
103 _robotStateComponentPlugin->addRobot(robotID, VirtualRobot::RobotIO::eStructure);
104 }
105
106 const auto robot = _robotStateComponentPlugin->getRobot(robotID);
107 ARMARX_CHECK_NOT_NULL(_debugDrawerTopic);
109 _debugDrawerHelper = std::make_unique<DebugDrawerHelper>(
110 _debugDrawerTopic, getDebugDrawerLayerName(), robot);
111 }
112 }
113
114 void
116 {
118 if (!_doNotClearLayersOnDisconnect)
119 {
120 try
121 {
122 _debugDrawerHelper->cyclicCleanup();
123 _debugDrawerHelper->cyclicCleanup();
124 _debugDrawerHelper->clearLayer();
125 }
126 catch (...)
127 {
128 }
129 }
130 _debugDrawerTopic = nullptr;
131 }
132
133 void
135 PropertyDefinitionsPtr& properties)
136 {
138 if (!properties->hasDefinition(_propertyName))
139 {
140 properties->defineOptionalProperty<std::string>(
141 _propertyName, "DebugDrawerUpdates", "Name of the debug drawer topic");
142 }
143 }
144
147 {
149 return _debugDrawerHelper->getRobot();
150 }
151
152 bool
154 {
156 const auto g = getDebugDrawerHelperLock();
158 return _robotStateComponentPlugin->synchronizeLocalClone(getDebugDrawerHelperRobot());
159 }
160
161 bool
163 {
165 const auto g = getDebugDrawerHelperLock();
167 return _robotStateComponentPlugin->synchronizeLocalClone(getDebugDrawerHelperRobot(),
168 timestamp);
169 }
170
171 bool
173 const RobotStateConfig& state) const
174 {
176 const auto g = getDebugDrawerHelperLock();
178 return _robotStateComponentPlugin->synchronizeLocalClone(getDebugDrawerHelperRobot(),
179 state);
180 }
181
182 void
184 {
186 _doNotClearLayersOnDisconnect = !b;
187 }
188} // namespace armarx::plugins
189
190namespace armarx
191{
197
200 {
202 return *_debugDrawerHelperComponentPlugin;
203 }
204
207 {
209 return *_debugDrawerHelperComponentPlugin;
210 }
211
212 const DebugDrawerHelper&
218
225
232
233 std::unique_lock<std::recursive_mutex>
239
240 std::string
246
253
254 bool
260
261 bool
268
269 bool
276} // namespace armarx
std::string timestamp()
armarx::plugins::DebugDrawerHelperComponentPlugin DebugDrawerHelperComponentPlugin
std::unique_lock< std::recursive_mutex > getDebugDrawerHelperLock() const
const DebugDrawerHelperComponentPlugin & getDebugDrawerHelperPlugin() const
const DebugDrawerInterfacePrx & getDebugDrawerTopic() const
The DebugDrawerHelper class provides draw functions in a given frame (static matrix or robot node) an...
const DebugDrawerInterfacePrx & getDebugDrawer() const
void addPluginDependency(ManagedIceObjectPlugin *dependedOn)
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
std::string getName() const
Retrieve name of object.
DebugDrawerHelperComponentPlugin(ManagedIceObject &parent, std::string pre)
std::unique_lock< std::recursive_mutex > getDebugDrawerHelperLock() const
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
#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...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
#define ARMARX_TRACE
Definition trace.h:77