25#include <SimoxUtility/algorithm/string/string_tools.h>
50 document.append_node(buildXmlDeclaration());
56 document.allocate_attribute(
"name", cloneQString(state->getStateName())));
57 rootNode->
append_attribute(document.allocate_attribute(
"uuid", cloneQString(state->getUUID())));
59 "width", cloneQString(QString::number(state->getSize().width()))));
61 "height", cloneQString(QString::number(state->getSize().height()))));
65 const QString& description = state->getDescription();
67 if (!description.isEmpty())
69 rootNode->
append_node(buildDescription(description));
72 rootNode->
append_node(buildParameterList(
"InputParameters", state->getInputParameters()));
73 rootNode->
append_node(buildParameterList(
"OutputParameters", state->getOutputParameters()));
74 rootNode->
append_node(buildParameterList(
"LocalParameters", state->getLocalParameters()));
75 rootNode->
append_node(buildSubstateList(state->getSubstates()));
76 rootNode->
append_node(buildEventList(state->getOutgoingEvents()));
80 if (startStateTransition->destinationState)
82 rootNode->
append_node(buildStartState(startStateTransition));
84 rootNode->
append_node(buildTransitionList(state->getTransitions(), uuidToNodeMap));
86 document.append_node(rootNode);
95 return QString::fromStdString(s);
102 substateNode->append_attribute(
103 document.allocate_attribute(
"refuuid", cloneQString(localState->getClassUUID())));
104 substateNode->append_attribute(document.allocate_attribute(
105 "left", cloneQString(QString::number(localState->getTopLeft().x()))));
106 substateNode->append_attribute(document.allocate_attribute(
107 "top", cloneQString(QString::number(localState->getTopLeft().y()))));
108 substateNode->append_attribute(document.allocate_attribute(
109 "boundingSquareSize", cloneQString(QString::number(localState->getBoundingSquareSize()))));
116 substateNode->append_attribute(
117 document.allocate_attribute(
"refuuid", cloneQString(remoteState->getClassUUID())));
118 substateNode->append_attribute(
119 document.allocate_attribute(
"proxyName", cloneQString(remoteState->proxyName)));
120 substateNode->append_attribute(document.allocate_attribute(
121 "left", cloneQString(QString::number(remoteState->getTopLeft().x()))));
122 substateNode->append_attribute(document.allocate_attribute(
123 "top", cloneQString(QString::number(remoteState->getTopLeft().y()))));
124 substateNode->append_attribute(document.allocate_attribute(
125 "boundingSquareSize", cloneQString(QString::number(remoteState->getBoundingSquareSize()))));
132 substateNode->append_attribute(
133 document.allocate_attribute(
"refuuid", cloneQString(dynamicRemoteState->getClassUUID())));
134 substateNode->append_attribute(document.allocate_attribute(
135 "left", cloneQString(QString::number(dynamicRemoteState->getTopLeft().x()))));
136 substateNode->append_attribute(document.allocate_attribute(
137 "top", cloneQString(QString::number(dynamicRemoteState->getTopLeft().y()))));
138 substateNode->append_attribute(document.allocate_attribute(
139 "boundingSquareSize",
140 cloneQString(QString::number(dynamicRemoteState->getBoundingSquareSize()))));
147 substateNode->append_attribute(
148 document.allocate_attribute(
"event", cloneQString(endState->getEventName())));
149 substateNode->append_attribute(document.allocate_attribute(
150 "left", cloneQString(QString::number(endState->getTopLeft().x()))));
151 substateNode->append_attribute(document.allocate_attribute(
152 "top", cloneQString(QString::number(endState->getTopLeft().y()))));
153 substateNode->append_attribute(document.allocate_attribute(
154 "boundingSquareSize", cloneQString(QString::number(endState->getBoundingSquareSize()))));
158XmlWriter::buildDescription(
const QString& description)
164XmlWriter::buildEventList(
const EventList& eventList)
168 for (EventList::const_iterator i = eventList.begin(); i != eventList.end(); ++i)
175 if (!event->description.isEmpty())
177 eventNode->
append_node(buildDescription(event->description));
187XmlWriter::buildParameterList(
const QString& tagName,
190 rapidxml::xml_node<>* rootNode =
193 for (armarx::statechartmodel::StateParameterMap::const_iterator i = parameterMap.begin();
194 i != parameterMap.end();
197 QString parameterName = i.key();
200 rapidxml::xml_node<>* parameterNode =
204 document.allocate_attribute(
"name", cloneQString(parameterName)));
206 document.allocate_attribute(
"type", cloneQString(parameter->type)));
209 cloneQString(QString::fromStdString(
210 variantInfo->getNestedHumanNameFromBaseName(parameter->type.toStdString())))));
212 document.allocate_attribute(
"optional", parameter->optional ?
"yes" :
"no"));
214 if (!parameter->description.isEmpty())
216 parameterNode->
append_node(buildDescription(parameter->description));
219 for (
auto j = parameter->profileDefaultValues.constBegin();
220 j != parameter->profileDefaultValues.constEnd();
223 rapidxml::xml_node<>* profileDefaultValueNode =
225 QString profileName = j.key();
230 document.allocate_attribute(
"profile", cloneQString(profileName)));
236 jsonObject->serializeIceObject(j.value().first);
238 document.allocate_attribute(
"value", cloneQString(j.value().second)));
240 document.allocate_attribute(
"docValue",
241 cloneQString(QString::fromStdString(
242 escapeString(j.value().first->toString())))));
243 parameterNode->
append_node(profileDefaultValueNode);
245 else if (j.value().second.size() != 0)
248 document.allocate_attribute(
"value", cloneQString(j.value().second)));
249 parameterNode->
append_node(profileDefaultValueNode);
260XmlWriter::escapeString(std::string
str)
262 str = simox::alg::replace_all(
str,
"\\",
"\\\\");
263 str = simox::alg::replace_all(
str,
"\r",
"\\r");
264 str = simox::alg::replace_all(
str,
"\n",
"\\n");
269XmlWriter::buildParameterMappingList(
271 const QString& mappingName)
274 rapidxml::xml_node<>* rootNode = document.allocate_node(
277 for (ParameterMappingList::const_iterator j = parameterMappingList.begin();
278 j != parameterMappingList.end();
283 rapidxml::xml_node<>* parameterMappingNode =
286 QString mappingSourceString;
288 mappingSourceString =
292 document.allocate_attribute(
"sourceType", cloneQString(mappingSourceString)));
294 document.allocate_attribute(
"from", cloneQString(parameterMapping->sourceKey)));
296 document.allocate_attribute(
"to", cloneQString(parameterMapping->destinationKey)));
298 for (
auto j = parameterMapping->profileValues.constBegin();
299 j != parameterMapping->profileValues.constEnd();
302 rapidxml::xml_node<>* profileDefaultValueNode =
304 QString profileName = j.key();
309 document.allocate_attribute(
"profile", cloneQString(profileName)));
313 document.allocate_attribute(
"value", cloneQString(j.value())));
314 parameterMappingNode->
append_node(profileDefaultValueNode);
330 "substateName", cloneQString(startStateTransition->destinationState->getInstanceName())));
332 rapidxml::xml_node<>* parameterMappingsNode = buildParameterMappingList(
333 startStateTransition->mappingToNextStatesInput,
"ParameterMappings");
337 rapidxml::xml_node<>* supportPointsNode =
339 auto supportPoints = startStateTransition->supportPoints.toPointList();
340 for (QList<QPointF>::const_iterator j = supportPoints.begin(); j != supportPoints.end(); ++j)
342 QPointF supportPoint = *j;
344 rapidxml::xml_node<>* supportPointNode =
347 document.allocate_attribute(
"posX", cloneQString(QString::number(supportPoint.x()))));
349 document.allocate_attribute(
"posY", cloneQString(QString::number(supportPoint.y()))));
364 for (StateInstanceMap::const_iterator i = substateMap.begin(); i != substateMap.end(); ++i)
366 QString substateName = i.key();
369 substate->accept(*
this);
370 substateNode->prepend_attribute(
371 document.allocate_attribute(
"name", cloneQString(substateName)));
380 const QMap<QString, StateTreeNodePtr>& uuidToNodeMap)
384 for (CTransitionList::const_iterator i = transitionList.begin(); i != transitionList.end(); ++i)
388 rapidxml::xml_node<>* transitionNode =
391 "from", cloneQString(transition->sourceState->getInstanceName())));
392 if (transition->transitionUserCode && transition->destinationState)
395 document.allocate_attribute(
"transitionCodeEnabled",
"1"));
396 if (transition->destinationState->getStateClass())
399 uuidToNodeMap.find(transition->destinationState->getStateClass()->getUUID());
401 if (it != uuidToNodeMap.end())
407 "toClass", cloneQString(node->getState()->getStateName())));
409 "toGroup", cloneQString(node->getGroup()->getName())));
411 "toPackage", cloneQString(node->getGroup()->getPackageName())));
414 if (transition->sourceState)
416 if (transition->sourceState->getStateClass())
419 uuidToNodeMap.find(transition->sourceState->getStateClass()->getUUID());
421 if (it != uuidToNodeMap.end())
427 "fromClass", cloneQString(node->getState()->getStateName())));
429 "fromGroup", cloneQString(node->getGroup()->getName())));
432 cloneQString(node->getGroup()->getPackageName())));
438 throw LocalException() << (
"Could not find source stateclass of instance " +
439 transition->sourceState->getInstanceName() +
440 "! Please open all Remote States in the "
441 "Statechart Editor before saving.");
447 throw LocalException()
448 << (
"Could not find destination stateclass of instance " +
449 transition->destinationState->getInstanceName() +
450 "! Please open all Remote States in the Statechart Editor before saving.");
454 if (transition->destinationState)
457 "to", cloneQString(transition->destinationState->getInstanceName())));
461 document.allocate_attribute(
"eventName", cloneQString(transition->eventName)));
464 rapidxml::xml_node<>* parameterMappingsNode =
465 buildParameterMappingList(transition->mappingToNextStatesInput,
"ParameterMappings");
466 transitionNode->
append_node(parameterMappingsNode);
467 parameterMappingsNode = buildParameterMappingList(transition->mappingToParentStatesLocal,
468 "ParameterMappingsToParentsLocal");
469 transitionNode->
append_node(parameterMappingsNode);
470 parameterMappingsNode = buildParameterMappingList(transition->mappingToParentStatesOutput,
471 "ParameterMappingsToParentsOutput");
472 transitionNode->
append_node(parameterMappingsNode);
476 rapidxml::xml_node<>* supportPointsNode =
478 auto supportPoints = transition->supportPoints.toPointList();
479 for (QList<QPointF>::const_iterator j = supportPoints.begin(); j != supportPoints.end();
482 QPointF supportPoint = *j;
484 rapidxml::xml_node<>* supportPointNode =
487 "posX", cloneQString(QString::number(supportPoint.x()))));
489 "posY", cloneQString(QString::number(supportPoint.y()))));
503XmlWriter::buildXmlDeclaration()
513XmlWriter::cloneQString(
const QString&
string)
516 return document.allocate_string(
string.
toUtf8());
static std::string MappingSourceToString(MappingSource mappingSource)
static std::string GetRootName()
void visitDynamicRemoteState(armarx::statechartmodel::DynamicRemoteStateCPtr dynamicRemoteState) override
void visitLocalState(armarx::statechartmodel::LocalStateCPtr localState) override
QString getXmlString(bool indent=true) const
Builds the XML document for the state object that has been handled by serialize() before.
void visitEndState(armarx::statechartmodel::EndStateCPtr endState) override
XmlWriter(const VariantInfoPtr &variantInfo)
void visitRemoteState(armarx::statechartmodel::RemoteStateCPtr remoteState) override
void serialize(armarx::statechartmodel::StateCPtr state, const QMap< QString, StateTreeNodePtr > &uuidToNodeMap=QMap< QString, StateTreeNodePtr >())
Builds XML data structures for serialization of the given state object.
static QString StateTypeToString(eStateType type)
xml_node< Ch > * allocate_node(node_type type, const Ch *name=nullptr, const Ch *value=nullptr, std::size_t name_size=0, std::size_t value_size=0)
Allocates a new node from the pool, and optionally assigns name and value to it.
xml_attribute< Ch > * allocate_attribute(const Ch *name=nullptr, const Ch *value=nullptr, std::size_t name_size=0, std::size_t value_size=0)
Allocates a new attribute from the pool, and optionally assigns name and value to it.
Class representing a node of XML document.
void append_node(xml_node< Ch > *child)
Appends a new child node.
void append_attribute(xml_attribute< Ch > *attribute)
Appends a new attribute to the node.
std::string toUtf8(QString const &qstring)
QMap< QString, StateParameterPtr > StateParameterMap
std::shared_ptr< StateInstance > StateInstancePtr
std::shared_ptr< const LocalState > LocalStateCPtr
std::shared_ptr< StateParameter > StateParameterPtr
QList< ParameterMappingPtr > ParameterMappingList
std::shared_ptr< const State > StateCPtr
std::shared_ptr< Event > EventPtr
std::shared_ptr< const Transition > TransitionCPtr
std::shared_ptr< const EndState > EndStateCPtr
QList< EventPtr > EventList
QList< TransitionCPtr > CTransitionList
std::shared_ptr< const DynamicRemoteState > DynamicRemoteStateCPtr
std::shared_ptr< const RemoteState > RemoteStateCPtr
std::shared_ptr< ParameterMapping > ParameterMappingPtr
QMap< QString, StateInstancePtr > StateInstanceMap
std::shared_ptr< VariantInfo > VariantInfoPtr
IceInternal::Handle< JSONObject > JSONObjectPtr
std::shared_ptr< StateTreeNode > StateTreeNodePtr
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Prints XML to given output iterator.
@ node_element
An element node. Name contains element name. Value contains text of first data node.
@ node_declaration
A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalon...
const int print_no_indenting
Printer flag instructing the printer to suppress indenting of XML. See print() function.
This file contains rapidxml printer implementation.