41 #include <SimoxUtility/algorithm/string/string_tools.h>
69 return "NoUserCodeState";
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"), defaultValueNode.attribute_value(
"value")));
89 defaultValueJsonString = defaultValueNode.attribute_value(
"value");
97 if (defaultValueMap.find(profile->getName()) != defaultValueMap.end())
99 defaultValueJsonString = defaultValueMap.at(profile->getName());
103 profile = profile->getParent();
108 if (!defaultValueJsonString.empty())
112 json->fromString(defaultValueJsonString);
113 result = VariantContainerBasePtr::dynamicCast(json->deserializeIceObject());
117 ARMARX_WARNING_S <<
"Could not deserialize param: " << defaultValueJsonString;
121 catch (JSONException& e)
123 ARMARX_WARNING_S <<
"Could not read default value for param: " << defaultValueJsonString;
187 setXMLStateData(stateData);
202 if (!privateStateData->stateReader && privateStateData->xmlFilepath.empty())
204 throw LocalException(
"Either a xml node or a filepath must be given.");
206 else if (!privateStateData->stateReader)
212 privateStateData->stateNode = privateStateData->stateReader->getRoot(
"State");
213 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 =
getParameters(privateStateData->stateNode.first_node(
"InputParameters"));
245 this->StateBase::outputParameters =
getParameters(privateStateData->stateNode.first_node(
"OutputParameters"));
246 this->StateBase::localParameters =
getParameters(privateStateData->stateNode.first_node(
"LocalParameters"));
287 if (!privateStateData->stateNode.is_valid())
294 const std::string stateName = privateStateData->stateNode.attribute_value(
"name");
296 addXMLSubstates(privateStateData->stateNode.first_node(
"Substates"), stateName);
298 addTransitions(privateStateData->stateNode.first_node(
"Transitions"));
300 setStartState(privateStateData->stateNode.first_node(
"StartState"));
315 curSubstateNode = curSubstateNode.next_sibling())
328 const std::string stateType = stateNode.
name();
334 std::string stateTypeL = simox::alg::to_lower(stateType);
336 if (stateTypeL ==
"localstate")
341 auto it = privateStateData->uuidToXMLMap->find(refuuid);
343 if (it == privateStateData->uuidToXMLMap->end())
345 throw LocalException(
"Could not find local state with UUID ") << refuuid;
349 const std::string stateName = substateReader->getRoot(
"State").attribute_value(
"name");
351 state = StateBasePtr::dynamicCast(xmlStateInstance);
355 ARMARX_DEBUG <<
"Using state with no code for " << stateName <<
" refuuid: " << refuuid <<
" instanceName: " << instanceName;
362 state->stateName = instanceName;
363 state =
addState(StatePtr::dynamicCast(state));
364 ARMARX_DEBUG <<
"Added " << stateName <<
" with instanceName " << instanceName;
367 else if (stateTypeL ==
"remotestate")
371 const std::string proxyName = ((!privateStateData->selectedProfile->isRoot()) ? privateStateData->selectedProfile->getName() :
"") + stateNode.
attribute_value(
"proxyName");
372 ARMARX_DEBUG <<
"Adding remote state with refuuid " << refuuid <<
" and instance name: " << instanceName;
376 else if (stateTypeL ==
"dynamicremotestate")
379 ARMARX_DEBUG <<
"Adding dynamic remote state with instance name: " << instanceName;
382 else if (stateTypeL ==
"endstate")
385 ARMARX_DEBUG <<
"Adding end state with event " << eventName;
393 throw LocalException(
"Unknown state type in XML - found state type: ") << stateType;
408 throw exceptions::local::eStatechartLogicError(
"There exists already a substate with name '" + state->StateBase::stateName +
"' in this hierarchy level. In one hierarchy level (aka one substatelist) the names must be unique.");
411 if (state->stateName.empty())
417 state->__setParentState(
this);
418 this->StateBase::subStateList.push_back(state);
441 curTransitionNode = curTransitionNode.next_sibling(
"Transition"))
443 const std::string eventName = curTransitionNode.attribute_value(
"eventName");
445 const std::string sourceStateName = curTransitionNode.attribute_value(
"from");
447 if (!curTransitionNode.has_attribute(
"to"))
449 ARMARX_INFO <<
"Skipping detached transition " << eventName;
453 const std::string destinationStateName = curTransitionNode.attribute_value(
"to");
461 throw LocalException(
"Could not find source state with name :") << sourceStateName;
466 throw LocalException(
"Could not find source state with name :") << destinationStateName;
469 if (eventName.empty())
471 throw LocalException(
"Event name must not bet empty");
475 ARMARX_DEBUG <<
"Adding Transition on event " << eventName;
476 ParameterMappingPtr mappingToNextStateInput = getMapping(curTransitionNode.first_node(
"ParameterMappings"));
477 ParameterMappingPtr mappingsToParentsLocal = getMapping(curTransitionNode.first_node(
"ParameterMappingsToParentsLocal"));
478 ParameterMappingPtr mappingsToParentsOutput = getMapping(curTransitionNode.first_node(
"ParameterMappingsToParentsOutput"));
481 mappingToNextStateInput, mappingsToParentsLocal, mappingsToParentsOutput);
511 curMappingNode = curMappingNode.next_sibling(
"ParameterMapping"))
514 const std::string fromParamName = curMappingNode.attribute_value(
"from");
515 const std::string targetParamName = curMappingNode.attribute_value(
"to");
517 mapping->addMappingEntry(sourceType, fromParamName, targetParamName,
GetSelectedProfileValue(curMappingNode, privateStateData->selectedProfile, privateStateData->ic));
524 : xmlFilepath(xmlFilepath),
526 selectedProfile(selectedProfile),
527 uuidToXMLMap(uuidToXMLMap),