25 #include "../../StatechartViewerPlugin/model/State.h"
26 #include "../../StatechartViewerPlugin/model/stateinstance/EndState.h"
27 #include "../../StatechartViewerPlugin/model/stateinstance/LocalState.h"
28 #include "../../StatechartViewerPlugin/model/stateinstance/RemoteState.h"
29 #include "../../StatechartViewerPlugin/model/stateinstance/DynamicRemoteState.h"
36 #include <SimoxUtility/algorithm/string/string_tools.h>
42 : variantInfo(variantInfo)
49 document.append_node(buildXmlDeclaration());
54 rootNode->
append_attribute(document.allocate_attribute(
"name", cloneQString(state->getStateName())));
55 rootNode->
append_attribute(document.allocate_attribute(
"uuid", cloneQString(state->getUUID())));
56 rootNode->
append_attribute(document.allocate_attribute(
"width", cloneQString(QString::number(state->getSize().width()))));
57 rootNode->
append_attribute(document.allocate_attribute(
"height", cloneQString(QString::number(state->getSize().height()))));
60 const QString& description = state->getDescription();
62 if (!description.isEmpty())
64 rootNode->
append_node(buildDescription(description));
67 rootNode->
append_node(buildParameterList(
"InputParameters", state->getInputParameters()));
68 rootNode->
append_node(buildParameterList(
"OutputParameters", state->getOutputParameters()));
69 rootNode->
append_node(buildParameterList(
"LocalParameters", state->getLocalParameters()));
70 rootNode->
append_node(buildSubstateList(state->getSubstates()));
71 rootNode->
append_node(buildEventList(state->getOutgoingEvents()));
75 if (startStateTransition->destinationState)
77 rootNode->
append_node(buildStartState(startStateTransition));
79 rootNode->
append_node(buildTransitionList(state->getTransitions(), uuidToNodeMap));
81 document.append_node(rootNode);
89 return QString::fromStdString(
s);
95 substateNode->
append_attribute(document.allocate_attribute(
"refuuid", cloneQString(localState->getClassUUID())));
96 substateNode->
append_attribute(document.allocate_attribute(
"left", cloneQString(QString::number(localState->getTopLeft().x()))));
97 substateNode->
append_attribute(document.allocate_attribute(
"top", cloneQString(QString::number(localState->getTopLeft().y()))));
98 substateNode->
append_attribute(document.allocate_attribute(
"boundingSquareSize", cloneQString(QString::number(localState->getBoundingSquareSize()))));
104 substateNode->
append_attribute(document.allocate_attribute(
"refuuid", cloneQString(remoteState->getClassUUID())));
105 substateNode->
append_attribute(document.allocate_attribute(
"proxyName", cloneQString(remoteState->proxyName)));
106 substateNode->
append_attribute(document.allocate_attribute(
"left", cloneQString(QString::number(remoteState->getTopLeft().x()))));
107 substateNode->
append_attribute(document.allocate_attribute(
"top", cloneQString(QString::number(remoteState->getTopLeft().y()))));
108 substateNode->
append_attribute(document.allocate_attribute(
"boundingSquareSize", cloneQString(QString::number(remoteState->getBoundingSquareSize()))));
114 substateNode->
append_attribute(document.allocate_attribute(
"refuuid", cloneQString(dynamicRemoteState->getClassUUID())));
115 substateNode->
append_attribute(document.allocate_attribute(
"left", cloneQString(QString::number(dynamicRemoteState->getTopLeft().x()))));
116 substateNode->
append_attribute(document.allocate_attribute(
"top", cloneQString(QString::number(dynamicRemoteState->getTopLeft().y()))));
117 substateNode->
append_attribute(document.allocate_attribute(
"boundingSquareSize", cloneQString(QString::number(dynamicRemoteState->getBoundingSquareSize()))));
124 substateNode->
append_attribute(document.allocate_attribute(
"event", cloneQString(endState->getEventName())));
125 substateNode->
append_attribute(document.allocate_attribute(
"left", cloneQString(QString::number(endState->getTopLeft().x()))));
126 substateNode->
append_attribute(document.allocate_attribute(
"top", cloneQString(QString::number(endState->getTopLeft().y()))));
127 substateNode->
append_attribute(document.allocate_attribute(
"boundingSquareSize", cloneQString(QString::number(endState->getBoundingSquareSize()))));
139 for (EventList::const_iterator i = eventList.begin(); i != eventList.end(); ++i)
144 eventNode->
append_attribute(document.allocate_attribute(
"name", cloneQString(event->name)));
146 if (!event->description.isEmpty())
148 eventNode->
append_node(buildDescription(event->description));
161 for (armarx::statechartmodel::StateParameterMap::const_iterator i = parameterMap.begin(); i != parameterMap.end(); ++i)
163 QString parameterName = i.key();
168 parameterNode->
append_attribute(document.allocate_attribute(
"name", cloneQString(parameterName)));
169 parameterNode->
append_attribute(document.allocate_attribute(
"type", cloneQString(parameter->type)));
170 parameterNode->
append_attribute(document.allocate_attribute(
"docType", cloneQString(QString::fromStdString(variantInfo->getNestedHumanNameFromBaseName(parameter->type.toStdString())))));
171 parameterNode->
append_attribute(document.allocate_attribute(
"optional", parameter->optional ?
"yes" :
"no"));
173 if (!parameter->description.isEmpty())
175 parameterNode->
append_node(buildDescription(parameter->description));
178 for (
auto j = parameter->profileDefaultValues.constBegin(); j != parameter->profileDefaultValues.constEnd(); ++j)
181 QString profileName = j.key();
185 profileDefaultValueNode->
append_attribute(document.allocate_attribute(
"profile", cloneQString(profileName)));
191 jsonObject->serializeIceObject(j.value().first);
192 profileDefaultValueNode->
append_attribute(document.allocate_attribute(
"value", cloneQString(j.value().second)));
193 profileDefaultValueNode->
append_attribute(document.allocate_attribute(
"docValue", cloneQString(QString::fromStdString(escapeString(j.value().first->toString())))));
194 parameterNode->
append_node(profileDefaultValueNode);
196 else if (j.value().second.size() != 0)
198 profileDefaultValueNode->
append_attribute(document.allocate_attribute(
"value", cloneQString(j.value().second)));
199 parameterNode->
append_node(profileDefaultValueNode);
208 std::string XmlWriter::escapeString(std::string
str)
210 str = simox::alg::replace_all(
str,
"\\",
"\\\\");
211 str = simox::alg::replace_all(
str,
"\r",
"\\r");
212 str = simox::alg::replace_all(
str,
"\n",
"\\n");
220 document.allocate_string(mappingName.toUtf8().data()));
222 for (ParameterMappingList::const_iterator j = parameterMappingList.begin(); j != parameterMappingList.end(); ++j)
228 QString mappingSourceString;
232 parameterMappingNode->
append_attribute(document.allocate_attribute(
"sourceType", cloneQString(mappingSourceString)));
233 parameterMappingNode->
append_attribute(document.allocate_attribute(
"from", cloneQString(parameterMapping->sourceKey)));
234 parameterMappingNode->
append_attribute(document.allocate_attribute(
"to", cloneQString(parameterMapping->destinationKey)));
236 for (
auto j = parameterMapping->profileValues.constBegin(); j != parameterMapping->profileValues.constEnd(); ++j)
239 QString profileName = j.key();
243 profileDefaultValueNode->
append_attribute(document.allocate_attribute(
"profile", cloneQString(profileName)));
246 profileDefaultValueNode->
append_attribute(document.allocate_attribute(
"value", cloneQString(j.value())));
247 parameterMappingNode->
append_node(profileDefaultValueNode);
261 rootNode->
append_attribute(document.allocate_attribute(
"substateName", cloneQString(startStateTransition->destinationState->getInstanceName())));
263 rapidxml::xml_node<>* parameterMappingsNode = buildParameterMappingList(startStateTransition->mappingToNextStatesInput,
"ParameterMappings");
268 auto supportPoints = startStateTransition->supportPoints.toPointList();
269 for (QList<QPointF>::const_iterator j = supportPoints.begin(); j != supportPoints.end(); ++j)
271 QPointF supportPoint = *j;
274 supportPointNode->
append_attribute(document.allocate_attribute(
"posX", cloneQString(QString::number(supportPoint.x()))));
275 supportPointNode->
append_attribute(document.allocate_attribute(
"posY", cloneQString(QString::number(supportPoint.y()))));
289 for (StateInstanceMap::const_iterator i = substateMap.begin(); i != substateMap.end(); ++i)
291 QString substateName = i.key();
294 substate->accept(*
this);
295 substateNode->
prepend_attribute(document.allocate_attribute(
"name", cloneQString(substateName)));
306 for (CTransitionList::const_iterator i = transitionList.begin(); i != transitionList.end(); ++i)
311 transitionNode->
append_attribute(document.allocate_attribute(
"from", cloneQString(transition->sourceState->getInstanceName())));
312 if (transition->transitionUserCode && transition->destinationState)
314 transitionNode->
append_attribute(document.allocate_attribute(
"transitionCodeEnabled",
"1"));
315 if (transition->destinationState->getStateClass())
317 auto it = uuidToNodeMap.find(transition->destinationState->getStateClass()->getUUID());
319 if (it != uuidToNodeMap.end())
324 transitionNode->
append_attribute(document.allocate_attribute(
"toClass", cloneQString(node->getState()->getStateName())));
325 transitionNode->
append_attribute(document.allocate_attribute(
"toGroup", cloneQString(node->getGroup()->getName())));
326 transitionNode->
append_attribute(document.allocate_attribute(
"toPackage", cloneQString(node->getGroup()->getPackageName())));
330 if (transition->sourceState)
332 if (transition->sourceState->getStateClass())
334 it = uuidToNodeMap.find(transition->sourceState->getStateClass()->getUUID());
336 if (it != uuidToNodeMap.end())
341 transitionNode->
append_attribute(document.allocate_attribute(
"fromClass", cloneQString(node->getState()->getStateName())));
342 transitionNode->
append_attribute(document.allocate_attribute(
"fromGroup", cloneQString(node->getGroup()->getName())));
343 transitionNode->
append_attribute(document.allocate_attribute(
"fromPackage", cloneQString(node->getGroup()->getPackageName())));
349 throw LocalException() << (
"Could not find source stateclass of instance " + transition->sourceState->getInstanceName() +
"! Please open all Remote States in the Statechart Editor before saving.");
355 throw LocalException() << (
"Could not find destination stateclass of instance " + transition->destinationState->getInstanceName() +
"! Please open all Remote States in the Statechart Editor before saving.");
359 if (transition->destinationState)
361 transitionNode->
append_attribute(document.allocate_attribute(
"to", cloneQString(transition->destinationState->getInstanceName())));
364 transitionNode->
append_attribute(document.allocate_attribute(
"eventName", cloneQString(transition->eventName)));
367 rapidxml::xml_node<>* parameterMappingsNode = buildParameterMappingList(transition->mappingToNextStatesInput,
"ParameterMappings");
368 transitionNode->
append_node(parameterMappingsNode);
369 parameterMappingsNode = buildParameterMappingList(transition->mappingToParentStatesLocal,
"ParameterMappingsToParentsLocal");
370 transitionNode->
append_node(parameterMappingsNode);
371 parameterMappingsNode = buildParameterMappingList(transition->mappingToParentStatesOutput,
"ParameterMappingsToParentsOutput");
372 transitionNode->
append_node(parameterMappingsNode);
377 auto supportPoints = transition->supportPoints.toPointList();
378 for (QList<QPointF>::const_iterator j = supportPoints.begin(); j != supportPoints.end(); ++j)
380 QPointF supportPoint = *j;
383 supportPointNode->
append_attribute(document.allocate_attribute(
"posX", cloneQString(QString::number(supportPoint.x()))));
384 supportPointNode->
append_attribute(document.allocate_attribute(
"posY", cloneQString(QString::number(supportPoint.y()))));
406 char* XmlWriter::cloneQString(
const QString&
string)
409 return document.allocate_string(
string.
toUtf8());