FluxioNode.cpp
Go to the documentation of this file.
1#include "FluxioNode.h"
2
3#include <experimental/memory>
4
6
10#include <RobotAPI/interface/skills/SkillManagerInterface.h>
11#include <RobotAPI/libraries/skills/core/aron/FluxioIdentificator.aron.generated.h>
12#include <RobotAPI/libraries/skills/core/aron/FluxioNode.aron.generated.h>
13
14namespace armarx
15{
16 namespace skills
17 {
19 FluxioNodeTypeFromString(const std::string& type)
20 {
21 if (type == "PARAMETER")
22 {
24 }
25 else if (type == "CONTROL")
26 {
28 }
29 else if (type == "SUBSKILL")
30 {
32 }
33 else
34 {
35 ARMARX_WARNING << "Unknown node type: " << type;
37 }
38 }
39
40 std::optional<std::string>
42 {
43 switch (type)
44 {
46 return "PARAMETER";
48 return "CONTROL";
50 return "SUBSKILL";
52 default:
53 ARMARX_WARNING << "Unknown node type: " << static_cast<int>(type);
54 return std::nullopt;
55 }
56 }
57
58 std::optional<manager::dto::FluxioNode>
60 {
61 manager::dto::FluxioNode ret;
62
63 const auto& nt = FluxioNodeTypeToString(nodeType);
64 if (!nt.has_value())
65 {
66 return std::nullopt;
67 }
68
69 ret.nodeType = nt.value();
70 ret.nodeId = nodeId;
71 ret.name = name;
72 ret.xPos = xPos;
73 ret.yPos = yPos;
74 ret.controlType = "";
75 ret.parameters = {};
76
77 manager::dto::FluxioIdentificator emptyId;
78 emptyId.id = "";
79 emptyId.hint = "";
80
81 ret.parameterId = emptyId;
82 ret.skillId = emptyId;
83 ret.slottedNodeId = emptyId;
84
85 return ret;
86 }
87
88 std::optional<manager::arondto::FluxioNode>
90 {
91 manager::arondto::FluxioNode ret;
92
93 const auto& nt = FluxioNodeTypeToString(nodeType);
94 if (!nt.has_value())
95 {
96 return std::nullopt;
97 }
98
99 ret.nodeType = nt.value();
100 ret.nodeId = nodeId;
101 ret.name = name;
102 ret.xPos = xPos;
103 ret.yPos = yPos;
104 ret.controlType = "";
105 ret.parameters = {};
106
107 manager::arondto::FluxioIdentificator emptyId;
108 emptyId.id = "";
109 emptyId.hint = "";
110
111 ret.parameterId = emptyId;
112 ret.skillId = emptyId;
113 ret.slottedNodeId = emptyId;
114
115 return ret;
116 }
117
118 manager::dto::FluxioIdentificator
120 {
121 manager::dto::FluxioIdentificator ret;
122 ret.id = nodeId;
123 ret.hint = name;
124 return ret;
125 }
126
127 manager::arondto::FluxioIdentificator
129 {
130 manager::arondto::FluxioIdentificator ret;
131 ret.id = nodeId;
132 ret.hint = name;
133 return ret;
134 }
135
138 const manager::dto::FluxioIdentificator& i,
139 const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
140 {
141 const auto& nodeIt = nodesMap.find(i.id);
142
143 if (nodeIt == nodesMap.end())
144 {
145 ARMARX_WARNING << "Node with id " << i.id << " not found";
146 return nullptr;
147 }
148
149 return std::experimental::make_observer(nodeIt->second.get());
150 }
151
154 const manager::arondto::FluxioIdentificator& i,
155 const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
156 {
157 const auto& nodeIt = nodesMap.find(i.id);
158
159 if (nodeIt == nodesMap.end())
160 {
161 ARMARX_WARNING << "Node with id " << i.id << " not found";
162 return nullptr;
163 }
164
165 return std::experimental::make_observer(nodeIt->second.get());
166 }
167
169 FluxioNode::FromIce(const manager::dto::FluxioNode& i)
170 {
171 FluxioNode ret;
172
173 ret.nodeType = FluxioNodeTypeFromString(i.nodeType);
174 ret.nodeId = i.nodeId;
175 ret.xPos = i.xPos;
176 ret.yPos = i.yPos;
177
178 return ret;
179 }
180 } // namespace skills
181} // namespace armarx
#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)
This file offers overloads of toIce() and fromIce() functions for STL container types.
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
manager::arondto::FluxioIdentificator toFluxioIdentificatorAron() const
static FluxioNode FromIce(const manager::dto::FluxioNode &i)
virtual std::optional< manager::dto::FluxioNode > toManagerIce() const
static std::experimental::observer_ptr< const FluxioNode > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, const std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
virtual std::optional< manager::arondto::FluxioNode > toAron() const
static std::experimental::observer_ptr< const FluxioNode > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, const std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
FluxioNodeType nodeType
Definition FluxioNode.h:26
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const