FluxioControlNode.cpp
Go to the documentation of this file.
1#include "FluxioControlNode.h"
2
3#include <experimental/memory>
4#include <memory>
5#include <optional>
6#include <vector>
7
9
14#include <RobotAPI/interface/skills/SkillManagerInterface.h>
15#include <RobotAPI/libraries/skills/core/aron/FluxioParameter.aron.generated.h>
16
17#include "FluxioParameter.h"
18
19namespace armarx
20{
21 namespace skills
22 {
24 FluxioControlNodeTypeFromString(const std::string& type)
25 {
26 if (type == "SPLITTER")
27 {
29 }
30 else if (type == "AND_MERGER")
31 {
33 }
34 else if (type == "LOOP_REPEAT")
35 {
37 }
38 else if (type == "LOOP_RETRY")
39 {
41 }
42 else
43 {
44 ARMARX_WARNING << "Unknown control node type: " << type;
46 }
47 }
48
49 std::optional<std::string>
51 {
52 switch (type)
53 {
55 return "SPLITTER";
57 return "AND_MERGER";
59 return "LOOP_REPEAT";
61 return "LOOP_RETRY";
63 default:
64 ARMARX_WARNING << "Unknown control node type: " << static_cast<int>(type);
65 return std::nullopt;
66 }
67 }
68
69 std::optional<manager::dto::FluxioNode>
71 {
72 const auto& nt = FluxioNodeTypeToString(nodeType);
73 if (!nt.has_value())
74 {
75 return std::nullopt;
76 }
78 if (!nt.has_value())
79 {
80 return std::nullopt;
81 }
82
83 manager::dto::FluxioNode ret;
84 ret.nodeId = nodeId;
85 ret.nodeType = nt.value();
86 ret.name = name;
87 ret.xPos = xPos;
88 ret.yPos = yPos;
89 ret.controlType = ct.value();
90
91 manager::dto::FluxioIdentificator slottedNodeIdentificator;
92 if (slottedNode != nullptr)
93 {
94 slottedNodeIdentificator.id = slottedNode->nodeId;
95 slottedNodeIdentificator.hint = slottedNode->name;
96 }
97
98 ret.slottedNodeId = slottedNodeIdentificator;
99
100 manager::dto::FluxioParameterList params;
101 for (const auto& [id, parameter] : parametersMap)
102 {
103 params.push_back(parameter.toManagerIce());
104 }
105 ret.parameters = params;
106
107 manager::dto::FluxioIdentificator emptyId;
108 emptyId.id = "";
109 emptyId.hint = "";
110
111 ret.parameterId = emptyId;
112 ret.skillId = emptyId;
113
114 return ret;
115 }
116
117 std::optional<manager::arondto::FluxioNode>
119 {
120 const auto& nt = FluxioNodeTypeToString(nodeType);
121 if (!nt.has_value())
122 {
123 return std::nullopt;
124 }
126 if (!nt.has_value())
127 {
128 return std::nullopt;
129 }
130
131 manager::arondto::FluxioNode ret;
132 ret.nodeId = nodeId;
133 ret.nodeType = nt.value();
134 ret.name = name;
135 ret.xPos = xPos;
136 ret.yPos = yPos;
137 ret.controlType = ct.value();
138
139 manager::arondto::FluxioIdentificator slottedNodeIdentificator;
140 if (slottedNode != nullptr)
141 {
142 slottedNodeIdentificator.id = slottedNode->nodeId;
143 slottedNodeIdentificator.hint = slottedNode->name;
144 }
145
146 ret.slottedNodeId = slottedNodeIdentificator;
147
148
149 std::vector<manager::arondto::FluxioParameter> params;
150 for (const auto& [id, parameter] : parametersMap)
151 {
152 params.push_back(parameter.toAron());
153 }
154 ret.parameters = params;
155
156 manager::arondto::FluxioIdentificator emptyId;
157 emptyId.id = "";
158 emptyId.hint = "";
159
160 ret.parameterId = emptyId;
161 ret.skillId = emptyId;
162
163 return ret;
164 }
165
166 std::optional<FluxioControlNode>
168 const manager::dto::FluxioNode& i,
169 std::map<std::string, FluxioProfile>& profilesMap,
170 std::map<std::string, aron::type::ObjectPtr>& typesMap,
171 std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
172 {
174
175 ret.nodeId = i.nodeId;
176 ret.nodeType = FluxioNodeTypeFromString(i.nodeType);
177 ret.name = i.name;
178 ret.xPos = i.xPos;
179 ret.yPos = i.yPos;
181 const auto& slottedNodeIt = nodesMap.find(i.slottedNodeId.id);
182 if (slottedNodeIt == nodesMap.end())
183 {
184 ARMARX_INFO << "Slotted node not found: " << i.slottedNodeId.id;
185 ret.slottedNode = nullptr;
186 }
187 else
188 {
189 ret.slottedNode = std::experimental::make_observer(slottedNodeIt->second.get());
190 }
191
192 std::map<std::string, FluxioParameter> paramsMap;
193 for (const auto& parameter : i.parameters)
194 {
195 const auto& param = FluxioParameter::FromIce(parameter, profilesMap, typesMap);
196 paramsMap.insert({parameter.id, param});
197 }
198
199 ret.parametersMap = paramsMap;
200
201 return ret;
202 }
203
204 std::optional<FluxioControlNode>
206 const manager::arondto::FluxioNode& i,
207 std::map<std::string, FluxioProfile>& profilesMap,
208 std::map<std::string, aron::type::ObjectPtr>& typesMap,
209 std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
210 {
212
213 ret.nodeId = i.nodeId;
214 ret.nodeType = FluxioNodeTypeFromString(i.nodeType);
215 ret.name = i.name;
216 ret.xPos = i.xPos;
217 ret.yPos = i.yPos;
219 const auto& slottedNodeIt = nodesMap.find(i.slottedNodeId.id);
220 if (slottedNodeIt == nodesMap.end())
221 {
222 ARMARX_INFO << "Slotted node not found: " << i.slottedNodeId.id;
223 ret.slottedNode = nullptr;
224 }
225 else
226 {
227 ret.slottedNode = std::experimental::make_observer(slottedNodeIt->second.get());
228 }
229
230 std::map<std::string, FluxioParameter> paramsMap;
231 for (const auto& parameter : i.parameters)
232 {
233 const auto& param = FluxioParameter::FromAron(parameter, profilesMap, typesMap);
234 paramsMap.insert({parameter.id, param});
235 }
236
237 ret.parametersMap = paramsMap;
238
239 return ret;
240 }
241 } // namespace skills
242} // namespace armarx
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file is part of ArmarX.
FluxioNodeType FluxioNodeTypeFromString(const std::string &type)
std::optional< std::string > FluxioNodeTypeToString(const FluxioNodeType &type)
std::optional< std::string > FluxioControlNodeTypeToString(const FluxioControlNodeType &type)
FluxioControlNodeType FluxioControlNodeTypeFromString(const std::string &type)
This file offers overloads of toIce() and fromIce() functions for STL container types.
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
std::experimental::observer_ptr< FluxioNode > slottedNode
static std::optional< FluxioControlNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap, std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
std::optional< manager::arondto::FluxioNode > toAron() const override
std::optional< manager::dto::FluxioNode > toManagerIce() const override
std::map< std::string, FluxioParameter > parametersMap
static std::optional< FluxioControlNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap, std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
FluxioNodeType nodeType
Definition FluxioNode.h:26
static FluxioParameter FromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
static FluxioParameter FromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)