30 #include <SimoxUtility/algorithm/string/string_tools.h>
64 return "NoUserCodeState";
73 VariantContainerBasePtr
77 std::string defaultValueJsonString)
79 VariantContainerBasePtr result;
80 std::map<std::string, std::string> defaultValueMap;
83 if (defaultValueNode.has_attribute(
"profile"))
85 defaultValueMap.insert(std::make_pair(defaultValueNode.attribute_value(
"profile"),
86 defaultValueNode.attribute_value(
"value")));
90 defaultValueJsonString = defaultValueNode.attribute_value(
"value");
98 if (defaultValueMap.find(profile->getName()) != defaultValueMap.end())
100 defaultValueJsonString = defaultValueMap.at(profile->getName());
104 profile = profile->getParent();
109 if (!defaultValueJsonString.empty())
113 json->fromString(defaultValueJsonString);
114 result = VariantContainerBasePtr::dynamicCast(json->deserializeIceObject());
118 ARMARX_WARNING_S <<
"Could not deserialize param: " << defaultValueJsonString;
121 catch (JSONException& e)
124 << defaultValueJsonString;
169 VariantContainerBasePtr
191 setXMLStateData(stateData);
204 if (!privateStateData->stateReader && privateStateData->xmlFilepath.empty())
206 throw LocalException(
"Either a xml node or a filepath must be given.");
208 else if (!privateStateData->stateReader)
210 privateStateData->stateNode =
215 privateStateData->stateNode = privateStateData->stateReader->getRoot(
"State");
216 privateStateData->xmlFilepath.clear();
227 return privateStateData->selectedProfile;
234 if (!privateStateData->stateNode.is_valid())
239 if (!privateStateData->ic && context && context->
getIceManager()->getCommunicator())
241 privateStateData->ic = context->
getIceManager()->getCommunicator();
244 this->StateBase::inputParameters =
245 getParameters(privateStateData->stateNode.first_node(
"InputParameters"));
246 this->StateBase::outputParameters =
247 getParameters(privateStateData->stateNode.first_node(
"OutputParameters"));
248 this->StateBase::localParameters =
249 getParameters(privateStateData->stateNode.first_node(
"LocalParameters"));
266 curParameterNode, privateStateData->ic, privateStateData->selectedProfile);
281 <<
"' is unknown, Parameter '" << deserialization.
getName()
293 if (!privateStateData->stateNode.is_valid())
300 const std::string stateName = privateStateData->stateNode.attribute_value(
"name");
302 addXMLSubstates(privateStateData->stateNode.first_node(
"Substates"), stateName);
304 addTransitions(privateStateData->stateNode.first_node(
"Transitions"));
306 setStartState(privateStateData->stateNode.first_node(
"StartState"));
319 curSubstateNode = curSubstateNode.next_sibling())
330 const std::string stateType = stateNode.
name();
335 std::string stateTypeL = simox::alg::to_lower(stateType);
337 if (stateTypeL ==
"localstate")
342 auto it = privateStateData->uuidToXMLMap->find(refuuid);
344 if (it == privateStateData->uuidToXMLMap->end())
346 throw LocalException(
"Could not find local state with UUID ") << refuuid;
350 const std::string stateName = substateReader->getRoot(
"State").attribute_value(
"name");
356 privateStateData->selectedProfile,
357 privateStateData->uuidToXMLMap,
358 privateStateData->ic)));
359 state = StateBasePtr::dynamicCast(xmlStateInstance);
363 ARMARX_DEBUG <<
"Using state with no code for " << stateName <<
" refuuid: " << refuuid
364 <<
" instanceName: " << instanceName;
368 privateStateData->selectedProfile,
369 privateStateData->uuidToXMLMap,
370 privateStateData->ic)));
375 state->stateName = instanceName;
376 state =
addState(StatePtr::dynamicCast(state));
377 ARMARX_DEBUG <<
"Added " << stateName <<
" with instanceName " << instanceName;
379 else if (stateTypeL ==
"remotestate")
383 const std::string proxyName = ((!privateStateData->selectedProfile->isRoot())
384 ? privateStateData->selectedProfile->getName()
387 ARMARX_DEBUG <<
"Adding remote state with refuuid " << refuuid
388 <<
" and instance name: " << instanceName;
392 else if (stateTypeL ==
"dynamicremotestate")
395 ARMARX_DEBUG <<
"Adding dynamic remote state with instance name: " << instanceName;
398 else if (stateTypeL ==
"endstate")
401 ARMARX_DEBUG <<
"Adding end state with event " << eventName;
409 throw LocalException(
"Unknown state type in XML - found state type: ") << stateType;
425 "There exists already a substate with name '" + state->StateBase::stateName +
426 "' in this hierarchy level. In one hierarchy level (aka one substatelist) the names "
430 if (state->stateName.empty())
436 state->__setParentState(
this);
437 this->StateBase::subStateList.push_back(state);
456 curTransitionNode = curTransitionNode.next_sibling(
"Transition"))
458 const std::string eventName = curTransitionNode.attribute_value(
"eventName");
460 const std::string sourceStateName = curTransitionNode.attribute_value(
"from");
462 if (!curTransitionNode.has_attribute(
"to"))
464 ARMARX_INFO <<
"Skipping detached transition " << eventName;
468 const std::string destinationStateName = curTransitionNode.attribute_value(
"to");
476 throw LocalException(
"Could not find source state with name :") << sourceStateName;
481 throw LocalException(
"Could not find source state with name :") << destinationStateName;
484 if (eventName.empty())
486 throw LocalException(
"Event name must not bet empty");
490 ARMARX_DEBUG <<
"Adding Transition on event " << eventName;
492 getMapping(curTransitionNode.first_node(
"ParameterMappings"));
494 getMapping(curTransitionNode.first_node(
"ParameterMappingsToParentsLocal"));
496 getMapping(curTransitionNode.first_node(
"ParameterMappingsToParentsOutput"));
501 mappingToNextStateInput,
502 mappingsToParentsLocal,
503 mappingsToParentsOutput);
532 curMappingNode = curMappingNode.next_sibling(
"ParameterMapping"))
534 MappingSource sourceType =
536 const std::string fromParamName = curMappingNode.attribute_value(
"from");
537 const std::string targetParamName = curMappingNode.attribute_value(
"to");
539 mapping->addMappingEntry(sourceType,
543 privateStateData->selectedProfile,
544 privateStateData->ic));
555 xmlFilepath(xmlFilepath),
557 selectedProfile(selectedProfile),
558 uuidToXMLMap(uuidToXMLMap),