53 qRegisterMetaType<statechartmodel::TransitionCPtr>(
"TransitionCPtr");
54 qRegisterMetaType<statechartmodel::StateInstancePtr>(
"StateInstancePtr");
79 ARMARX_DEBUG << tempList.size() <<
" new subscriptions received";
80 for (
auto& elem : tempList)
82 StateIceBasePtr iceState = elem.first;
84 StateItem* stateItem = elem.second.second;
85 StateListenerDataMap::iterator it;
88 it =
stateMap.find(iceState->globalStateIdentifier);
89 if (it !=
stateMap.end() && state && it->second.states.count(state) > 0)
93 if (it !=
stateMap.end() && stateItem && it->second.stateItems.count(stateItem) > 0)
98 ARMARX_VERBOSE <<
"subscribing : " << iceState->globalStateIdentifier;
107 data.iceState = iceState;
110 data.states.insert(state);
114 data.stateItems.insert(stateItem);
139 ARMARX_WARNING <<
"State NULL: " << iceState->globalStateIdentifier;
143 subscriptionQueue.push_back(std::make_pair(iceState, std::make_pair(state, item)));
152 for (
auto item : pair.second.stateItems)
156 pair.second.stateItems.erase(state);
174 ARMARX_WARNING <<
"State NULL: " << iceState->globalStateIdentifier;
186 for (
const auto& stateData :
stateMap)
188 if (stateData.second.states.count(state))
192 for (
auto& entry : stateData.second.parameters.at(paramMapType))
194 map.
addElement(entry.first, entry.second->value);
213 for (
const auto& stateData :
stateMap)
215 if (stateData.second.states.count(state))
218 ARMARX_INFO <<
"query state: " << stateData.second.iceState->globalStateIdentifier;
220 auto it = stateData.second.parameters.find(paramMapType);
221 if (it == stateData.second.parameters.end())
224 for (
auto& e : stateData.second.parameters)
226 s << e.first <<
", ";
228 throw LocalException() <<
"could not find " << paramMapType <<
" available: " <<
s.str();
252 if (globalIdString.find(
"->") == std::string::npos)
254 return globalIdString;
256 return globalIdString.substr(globalIdString.find_last_of(
"->") + 1);
262 return "StateWatcher";
274 std::string stateIdentifier =
event.parentName;
278 auto it =
stateMap.find(stateIdentifier);
281 ARMARX_VERBOSE <<
"Could not find state with id " << stateIdentifier;
285 for (
auto& state :
data.states)
312 ARMARX_DEBUG <<
"Got event reported for active state changed: " <<
event.parentStateIdentifier;
313 auto it =
stateMap.find(event.parentStateIdentifier);
316 ARMARX_VERBOSE <<
"Could not find state with id " <<
event.parentStateIdentifier;
322 auto activeSubstate = state->getActiveSubstate();
327 std::string activeSubstateName =
ExtractStateName(event.targetStateIdentifier);
328 if (!activeSubstateName.empty())
330 auto it = state->getSubstates().find(QString::fromStdString(activeSubstateName));
331 if (it != state->getSubstates().end())
336 ARMARX_DEBUG <<
"Invoking setActive for " << activeSubstateName;
343 ARMARX_INFO <<
"could not find state " << activeSubstateName;
351 for (
auto item :
data.stateItems)
353 std::string activeSubstateName =
ExtractStateName(event.targetStateIdentifier);
354 QMetaObject::invokeMethod(item,
"setActiveSubstate", Q_ARG(QString, QString::fromStdString(activeSubstateName)));
362 auto it =
stateMap.find(event.parentStateIdentifier);
365 ARMARX_VERBOSE <<
"Could not find state with id " <<
event.parentStateIdentifier;
373 std::string eventName =
event.eventName;
374 std::string sourceStateName =
ExtractStateName(event.sourceStateIdentifier);
375 std::string destinationStateName =
ExtractStateName(event.targetStateIdentifier);
377 if (state && !eventName.empty() && !destinationStateName.empty())
379 if (
auto t = state->findTransition(QString::fromStdString(eventName), QString::fromStdString(sourceStateName), QString::fromStdString(destinationStateName)))
381 ARMARX_DEBUG <<
"Invoking transition highlight for " << eventName <<
" from " << sourceStateName <<
" to " << destinationStateName;
386 auto ct = cstate->getStartTransition();
387 if (ct && eventName ==
"InitialTransition")
389 ARMARX_DEBUG <<
"Invoking inital transition highlight for " << state->getStateName();
394 ARMARX_VERBOSE <<
"Cannot find transition " << eventName <<
" for highlighting " << QString::fromStdString(sourceStateName) <<
" -> " << QString::fromStdString(destinationStateName);
399 for (
auto item :
data.stateItems)
401 QString eventName = QString::fromStdString(event.eventName);
402 QString sourceStateName = QString::fromStdString(
ExtractStateName(event.sourceStateIdentifier));
403 QString destinationStateName = QString::fromStdString(
ExtractStateName(event.targetStateIdentifier));
404 if (item && !eventName.isEmpty() && !destinationStateName.isEmpty())
406 for (
auto t : item->getTransitionItems())
409 if ((t->getTransition()->eventName == eventName && t->getTransition()->sourceState->getInstanceName() == sourceStateName)
410 || (stateclass && t->getTransition() == stateclass->getStartTransition() && eventName ==
"InitialTransition"))
412 QMetaObject::invokeMethod(t,
"highlightAnimation", Q_ARG(
int, 10000));
422 ARMARX_DEBUG <<
"updating state " <<
event.parentStateIdentifier <<
" failed";
433 stateMap[
event.stateIdentifier].parameters[
"inputParameters"] =
event.parameterMap;
440 stateMap[
event.stateIdentifier].parameters[
"localParameters"] =
event.parameterMap;
447 stateMap[
event.stateIdentifier].parameters[
"outputParameters"] =
event.parameterMap;
465 for (
auto& elem :
data)
473 for (
auto& elem :
data)
481 for (
auto& elem :
data)
489 for (
auto& elem :
data)