aron_conversions.cpp
Go to the documentation of this file.
1 #include "aron_conversions.h"
2 
5 
6 namespace armarx::armem
7 {
8  std::map<armarx::eStateType, armarx::skills::arondto::Statechart::StateType>
10  {eNormalState,
11  (armarx::skills::arondto::Statechart::StateType)
12  armarx::skills::arondto::Statechart::StateType::NORMAL},
13  {eFinalState,
14  (armarx::skills::arondto::Statechart::StateType)
15  armarx::skills::arondto::Statechart::StateType::FINAL},
16  {eRemoteState,
17  (armarx::skills::arondto::Statechart::StateType)
18  armarx::skills::arondto::Statechart::StateType::REMOTE},
19  {eDynamicRemoteState,
20  (armarx::skills::arondto::Statechart::StateType)
21  armarx::skills::arondto::Statechart::StateType::DYNAMIC_REMOTE},
22  {eUndefined,
23  (armarx::skills::arondto::Statechart::StateType)
24  armarx::skills::arondto::Statechart::StateType::UNDEFINED},
25  };
26 
27  std::map<armarx::skills::arondto::Statechart::StateType, armarx::eStateType>
29  {(armarx::skills::arondto::Statechart::StateType)
30  armarx::skills::arondto::Statechart::StateType::NORMAL,
31  eNormalState},
32  {(armarx::skills::arondto::Statechart::StateType)
33  armarx::skills::arondto::Statechart::StateType::FINAL,
34  eFinalState},
35  {(armarx::skills::arondto::Statechart::StateType)
36  armarx::skills::arondto::Statechart::StateType::REMOTE,
37  eRemoteState},
38  {(armarx::skills::arondto::Statechart::StateType)
39  armarx::skills::arondto::Statechart::StateType::DYNAMIC_REMOTE,
40  eDynamicRemoteState},
41  {(armarx::skills::arondto::Statechart::StateType)
42  armarx::skills::arondto::Statechart::StateType::UNDEFINED,
43  eUndefined},
44  };
45 
46  void
47  fromAron(const skills::arondto::Statechart::StateType& dto, eStateType& bo)
48  {
49  if (fromAronStateTypeMap.find(dto) != fromAronStateTypeMap.end())
50  {
51  bo = fromAronStateTypeMap[dto];
52  }
53  else
54  {
55  bo = eStateType::eUndefined;
56  }
57  }
58 
59  void
60  toAron(skills::arondto::Statechart::StateType& dto, const eStateType& bo)
61  {
62  if (toAronStateTypeMap.find(bo) != toAronStateTypeMap.end())
63  {
64  dto.value = toAronStateTypeMap[bo].value;
65  }
66  else
67  {
68  dto.value = skills::arondto::Statechart::StateType::UNDEFINED;
69  }
70  }
71 
72  void
73  fromAron(const skills::arondto::Statechart::ParameterMap& dto, StateParameterMap& bo)
74  {
75  // todo: implement
76  // for (auto const& [key, val] : dto.parameters)
77  // {
78  // fromAron(val, ...)
79  // bo.insert(key, val);
80  // }
81  }
82 
83  void
84  toAron(skills::arondto::Statechart::ParameterMap& dto, const StateParameterMap& bo)
85  {
86  for (auto const& [key, val] : bo)
87  {
88  dto.parameters[key] = val->value->toString();
89  }
90  }
91 
92  void
93  fromAron(const skills::arondto::Statechart::Transition& dto,
94  ProfilerStatechartTransitionWithParameters& bo)
95  {
96  bo.processId = dto.processId;
97  bo.sourceStateIdentifier = dto.sourceStateIdentifier;
98  bo.targetStateIdentifier = dto.targetStateIdentifier;
99  bo.eventName = dto.eventName;
100  fromAron(dto.targetStateType, bo.targetStateType);
101  fromAron(dto.inputParameters, bo.inputParameters);
102  fromAron(dto.localParameters, bo.localParameters);
103  fromAron(dto.outputParameters, bo.outputParameters);
104  }
105 
106  void
107  toAron(skills::arondto::Statechart::Transition& dto,
108  const ProfilerStatechartTransitionWithParameters& bo)
109  {
110  dto.processId = bo.processId;
111  dto.sourceStateIdentifier = bo.sourceStateIdentifier;
112  dto.targetStateIdentifier = bo.targetStateIdentifier;
113  dto.eventName = bo.eventName;
114  toAron(dto.targetStateType, bo.targetStateType);
115  toAron(dto.inputParameters, bo.inputParameters);
116  toAron(dto.localParameters, bo.localParameters);
117  toAron(dto.outputParameters, bo.outputParameters);
118  }
119 
120  void
121  fromAron(const armarx::skills::arondto::ProviderID& dto, skills::ProviderID& bo)
122  {
123  bo.providerName = dto.providerName;
124  }
125 
126  void
127  toAron(armarx::skills::arondto::ProviderID& dto, const skills::ProviderID& bo)
128  {
129  dto.providerName = bo.providerName;
130  }
131 
132  void
133  fromAron(const armarx::skills::arondto::SkillID& dto, skills::SkillID& bo)
134  {
135  bo.skillName = dto.skillName;
136  bo.providerId = skills::ProviderID{.providerName = ""};
137  fromAron(dto.providerId, *bo.providerId);
138  }
139 
140  void
141  toAron(armarx::skills::arondto::SkillID& dto, const skills::SkillID& bo)
142  {
143  dto.skillName = bo.skillName;
144  dto.providerId.resetHard();
145  if (bo.providerId.has_value())
146  {
147  toAron(dto.providerId, *bo.providerId);
148  }
149  }
150 
151  void
152  fromAron(const armarx::skills::arondto::SkillDescription& dto, skills::SkillDescription& bo)
153  {
154  fromAron(dto.skillId, bo.skillId);
155  bo.description = dto.description;
156  bo.timeout = dto.timeout;
157  bo.rootProfileDefaults = dto.rootProfileParameterization;
158  if (dto.parametersType)
159  {
160  throw armarx::LocalException("Not implemented yet");
161  }
162  }
163 
164  void
165  toAron(armarx::skills::arondto::SkillDescription& dto, const skills::SkillDescription& bo)
166  {
167  toAron(dto.skillId, bo.skillId);
168  dto.description = bo.description;
169  dto.timeout = bo.timeout;
170  dto.rootProfileParameterization = bo.rootProfileDefaults;
171  if (bo.parametersType)
172  {
174  aron::type::visit(c, bo.parametersType);
175 
176  dto.parametersType = aron::data::Dict::DynamicCastAndCheck(c.latest);
177  }
178  }
179 
180  void
181  fromAron(const armarx::skills::arondto::SkillExecutionRequest& dto,
183  {
184  fromAron(dto.skillId, bo.skillId);
185  bo.executorName = dto.executorName;
186  bo.parameters = dto.parameters;
187  }
188 
189  void
190  toAron(armarx::skills::arondto::SkillExecutionRequest& dto,
192  {
193  toAron(dto.skillId, bo.skillId);
194  dto.executorName = bo.executorName;
195  dto.parameters = bo.parameters;
196  }
197 
198  void
199  fromAron(const armarx::skills::arondto::SkillStatusUpdate& dto, skills::SkillStatusUpdate& bo)
200  {
201  static std::map<std::string, skills::SkillStatus> map{
202  {"Constructing", skills::SkillStatus::Constructing},
203  {"Initializing", skills::SkillStatus::Initializing},
204  {"Preparing", skills::SkillStatus::Preparing},
205  {"Running", skills::SkillStatus::Running},
206  {"Failed", skills::SkillStatus::Failed},
207  {"Aborted", skills::SkillStatus::Aborted},
208  {"Succeeded", skills::SkillStatus::Succeeded}};
209 
210  fromAron(dto.skillId, bo.executionId.skillId);
211  bo.executionId.executionStartedTime = dto.executionStartedTimestamp;
212  bo.executionId.executorName = dto.executorName;
213  bo.parameters = dto.parameters;
214  bo.result = dto.result;
215  bo.status = map.at(dto.status);
216  }
217 
218  void
219  toAron(armarx::skills::arondto::SkillStatusUpdate& dto, const skills::SkillStatusUpdate& bo)
220  {
221  static std::map<skills::SkillStatus, std::string> map{
222  {skills::SkillStatus::Constructing, "Constructing"},
223  {skills::SkillStatus::Initializing, "Initializing"},
224  {skills::SkillStatus::Preparing, "Preparing"},
225  {skills::SkillStatus::Running, "Running"},
226  {skills::SkillStatus::Failed, "Failed"},
227  {skills::SkillStatus::Aborted, "Aborted"},
228  {skills::SkillStatus::Succeeded, "Succeeded"}};
229 
230  toAron(dto.skillId, bo.executionId.skillId);
231  dto.executorName = bo.executionId.executorName;
232  dto.executionStartedTimestamp = bo.executionId.executionStartedTime;
233  dto.parameters = bo.parameters;
234  dto.result = bo.result;
235  dto.status = map.at(bo.status);
236  }
237 } // namespace armarx::armem
armarx::skills::SkillStatus::Aborted
@ Aborted
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::armem::fromAronStateTypeMap
std::map< armarx::skills::arondto::Statechart::StateType, armarx::eStateType > fromAronStateTypeMap
Definition: aron_conversions.cpp:28
armarx::armem::toAron
void toAron(arondto::MemoryID &dto, const MemoryID &bo)
Definition: aron_conversions.cpp:19
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
armarx::skills::ProviderID::providerName
std::string providerName
Definition: ProviderID.h:31
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
NLohmannJSONConverter.h
armarx::skills::SkillExecutionRequest
Definition: SkillExecutionRequest.h:21
armarx::skills::SkillStatusUpdate
Definition: SkillStatusUpdate.h:139
armarx::skills::ProviderID
Definition: ProviderID.h:15
armarx::armem::toAronStateTypeMap
std::map< armarx::eStateType, armarx::skills::arondto::Statechart::StateType > toAronStateTypeMap
Definition: aron_conversions.cpp:9
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
aron_conversions.h
armarx::skills::SkillStatus::Preparing
@ Preparing
DatatypeConverterVisitor.h
armarx::armem::fromAron
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
Definition: aron_conversions.cpp:8
armarx::skills::SkillStatus::Initializing
@ Initializing
armarx::aron::type::converter::AronDatatypeConverterVisitor
Definition: DatatypeConverterVisitor.h:32
armarx::skills::SkillStatus::Running
@ Running
armarx::aron::type::visit
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &t)
The visit function.
Definition: Visitor.h:42
armarx::skills::SkillStatus::Constructing
@ Constructing
armarx::skills::SkillID
Definition: SkillID.h:17
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:168
armarx::skills::SkillStatus::Succeeded
@ Succeeded
armarx::skills::SkillStatus::Failed
@ Failed