8 import xml.sax.saxutils
as saxutils
14 '\x00':
"�",
'\x01':
"",
15 '\x02':
"",
'\x03':
"",
16 '\x04':
"",
'\x05':
"",
17 '\x06':
"",
'\x07':
"",
18 '\x08':
"",
'\x09':
"	",
19 '\x0a':
"
",
'\x0b':
"",
20 '\x0c':
"",
'\x0d':
"
",
21 '\x0e':
"",
'\x0f':
"",
22 '\x10':
"",
'\x11':
"",
23 '\x12':
"",
'\x13':
"",
24 '\x14':
"",
'\x15':
"",
25 '\x16':
"",
'\x17':
"",
26 '\x18':
"",
'\x19':
"",
27 '\x1a':
"",
'\x1b':
"",
28 '\x1c':
"",
'\x1d':
"",
29 '\x1e':
"",
'\x1f':
"",
30 '\"':
""",
'\'':
"'"
36 f.write(
u"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + os.linesep)
39 f.write(
u"<ChoregrapheProject "
40 +
u"xmlns=\"http://www.aldebaran-robotics.com/schema/choregraphe/project.xsd\""
41 +
u" xar_version=\"3\">"
46 f.write(
u"</ChoregrapheProject>" + os.linesep)
51 f.write((
u"{}<Box name=\"{}\" id=\"{}\"")
53 saxutils.escape(instance.name, entities=ENTITIES),
56 if instance.interface.localization:
57 f.write((
u" localization=\"{}\"")
58 .format(instance.interface.localization))
60 f.write((
u" tooltip=\"{}\"")
61 .format(saxutils.escape(instance.interface.tooltip,
64 if instance.interface.plugin:
65 f.write((
u" plugin=\"{}\"").format(instance.interface.plugin))
67 f.write((
u" x=\"{}\" y=\"{}\">{}")
72 for bitmap
in instance.interface.bitmaps:
77 if instance.plugin_content
and instance.interface.plugin:
80 for input
in instance.interface.inputs:
83 for output
in instance.interface.outputs:
86 for parameter
in instance.interface.parameters:
87 value = instance.get_parameter_value(parameter.id)
92 for resource
in instance.interface.resources:
95 f.write((
u"{}</Box>{}").format(indent, os.linesep))
99 f.write((
u"{}<bitmap>{}</bitmap>{}")
106 script_content =
None
107 for content
in instance.interface.contents:
108 if (content.content_type == xar_types.ContentType.PYTHON_SCRIPT
109 or content.content_type == xar_types.ContentType.QICHAT_SCRIPT):
110 script_content = content
113 if script_content.content_type == xar_types.ContentType.PYTHON_SCRIPT:
114 f.write((
u"{}<script language=\"{}\">{}")
116 xar_types.ScriptLanguage.PYTHON,
118 elif script_content.content_type == xar_types.ContentType.QICHAT_SCRIPT:
119 f.write((
u"{}<script language=\"{}\">{}")
121 xar_types.ScriptLanguage.QICHAT,
124 raise Exception(
"Bad script language "
125 + script_content.content_type)
127 f.write((
u"{}<content>{}"
128 +
u"{}<![CDATA[{}]]>{}"
131 .format(indent +
' ', os.linesep,
132 indent +
' ', script_content.impl, os.linesep,
136 f.write((
u"{}<script/>{}").format(indent, os.linesep))
140 """ Write XML part of the <pluginContent> beacon, inside the box
143 A recursive write is necessary because the content of the part
144 is completely unknown and can contain levels and levels of
148 f.write((
u"{}<pluginContent>{}").format(indent,
150 for subnode
in plugin_content.subnodes:
152 f.write((
u"{}</pluginContent>{}").format(indent,
157 f.write((
u"{}<{}").format(indent,
159 if subnode.attributes.keys():
160 for key
in subnode.attributes.keys():
161 f.write((
u" {}=\"{}\"").format(str(key),
162 str(subnode.attributes[key])))
165 f.write(
u">" + os.linesep)
166 for subsubnode
in subnode.subnodes:
168 f.write((
u"{}</{}>{}").format(indent,
171 elif subnode.content:
172 f.write((
u">{}</{}>{}").format(saxutils.escape(subnode.content,
177 f.write(
u"/>" + os.linesep)
181 f.write((
u"{}<Input name=\"{}\" {} nature=\"{}\"")
187 if input.stm_value_name:
188 f.write((
u" stm_value_name=\"{}\"")
189 .format(input.stm_value_name))
191 f.write((
u" inner=\"{}\" tooltip=\"{}\" id=\"{}\" />{}")
193 saxutils.escape(input.tooltip, entities=ENTITIES),
199 f.write((
u"{}<Output name=\"{}\" {}"
200 +
u" nature=\"{}\" inner=\"{}\" tooltip=\"{}\" id=\"{}\" />{}")
206 saxutils.escape(output.tooltip, entities=ENTITIES),
212 f.write((
u"{}<Parameter name=\"{}\" inherits_from_parent=\"{}\""
213 +
u" content_type=\"{}\" value=\"{}\" default_value=\"{}\"")
216 parameter.inherits_from_parent,
219 parameter.default_value))
221 if (parameter.type == xar_types.IOSignature.DOUBLE
222 or parameter.type == xar_types.IOSignature.INT):
223 f.write((
u" min=\"{}\" max=\"{}\"")
224 .format(parameter.min,
227 if parameter.custom_choice:
228 f.write((
u" custom_choice=\"{}\"").format(parameter.custom_choice))
230 if parameter.password ==
"1":
231 f.write((
u" password=\"{}\"").format(parameter.password))
233 if parameter.choices:
234 f.write((
u" tooltip=\"{}\" id=\"{}\">{}")
235 .format(saxutils.escape(parameter.tooltip, entities=ENTITIES),
238 for choice
in parameter.choices:
239 f.write((
u"{}<Choice value=\"{}\" />{}")
240 .format(indent +
' ',
241 saxutils.escape(choice.value, entities=ENTITIES),
243 f.write((
u"{}</Parameter>{}")
247 f.write((
u" tooltip=\"{}\" id=\"{}\" />{}")
248 .format(saxutils.escape(parameter.tooltip, entities=ENTITIES),
258 signature = io.signature.strip(
"()")
259 if signature == xar_types.IOSignature.BANG:
260 ioType = xar_types.IOType.BANG
261 elif signature == xar_types.IOSignature.BITMAP:
262 ioType = xar_types.IOType.BITMAP
263 elif signature == xar_types.IOSignature.SOUND:
264 ioType = xar_types.IOType.SOUND
265 elif signature[0] == xar_types.IOSignature.DYNAMIC:
266 ioType = xar_types.IOType.DYNAMIC
267 elif signature[0] == xar_types.IOSignature.DOUBLE:
268 ioType = xar_types.IOType.NUMBER
269 ioSize = str(signature.count(xar_types.IOSignature.DOUBLE))
270 elif signature[0] == xar_types.IOSignature.STRING:
271 ioType = xar_types.IOType.STRING
272 ioSize = str(signature.count(xar_types.IOSignature.STRING))
274 raise Exception(
"Unknown signature: %s" % io.type)
276 return u"type=\"{}\" type_size=\"{}\"".format(ioType, ioSize)
282 if parameter.type == xar_types.IOSignature.BOOL:
283 paramType = xar_types.ParameterType.BOOL
284 elif parameter.type == xar_types.IOSignature.DOUBLE:
285 paramType = xar_types.ParameterType.DOUBLE
286 elif parameter.type == xar_types.IOSignature.INT:
287 paramType = xar_types.ParameterType.INT
288 elif parameter.type == xar_types.IOSignature.RESOURCE:
289 paramType = xar_types.ParameterType.RESOURCE
290 elif parameter.type == xar_types.IOSignature.STRING:
291 paramType = xar_types.ParameterType.STRING
293 raise Exception(
"Unknown signature: %s" % parameter.type)
304 for content
in interface.contents:
305 if content.content_type == xar_types.ContentType.FLOW_DIAGRAM:
306 flow_diagram = content.impl
307 elif content.content_type == xar_types.ContentType.BEHAVIOR_SEQUENCE:
308 sequence = content.impl
309 elif content.content_type == xar_types.ContentType.ANIMATION:
310 animation = content.impl
311 elif content.content_type == xar_types.ContentType.PYTHON_SCRIPT:
313 elif content.content_type == xar_types.ContentType.QICHAT_SCRIPT:
316 raise Exception(
"unknown content type "
317 + str(content.content_type))
319 if not (flow_diagram
or sequence
or animation):
323 f.write((
u"{}<Timeline enable=\"0\">{}")
327 f.write((
u"{}<Timeline enable=\"1\" fps=\"{}\" start_frame=\"{}\""
328 +
u" end_frame=\"{}\" size=\"{}\"")
331 animation.start_frame,
334 if animation.resources_acquisition:
335 f.write((
u" resources_acquisition=\"{}\">{}")
336 .format(animation.resources_acquisition,
339 f.write((
u">{}").format(os.linesep))
341 f.write((
u"{}<Timeline enable=\"1\" fps=\"{}\" start_frame=\"{}\""
342 +
u" end_frame=\"{}\" size=\"{}\"")
345 sequence.start_frame,
348 if sequence.resources_acquisition:
349 f.write((
u" resources_acquisition=\"{}\">{}")
350 .format(sequence.resources_acquisition,
353 f.write((
u">{}").format(os.linesep))
364 f.write((
u"{}</Timeline>{}")
370 f.write((
u"{}<BehaviorLayer name=\"behavior_layer1\">{}"
371 +
u"{}<BehaviorKeyframe name=\"keyframe1\" index=\"1\">{}")
377 f.write((
u"{}</BehaviorKeyframe>{}"
378 +
u"{}</BehaviorLayer>{}")
379 .format(indent +
' ',
391 f.write((
u"{}<ActuatorList model=\"{}\">{}")
396 for curve
in actuator_list.curves:
399 f.write((
u"{}</ActuatorList>{}")
405 f.write((
u"{}<ActuatorCurve name=\"{}\" actuator=\"{}\" recordable=\"{}\""
406 +
u" mute=\"{}\" unit=\"{}\"")
415 f.write(
u">" + os.linesep)
416 for key
in curve.keys:
419 f.write((
u"{}</ActuatorCurve>{}")
423 f.write(
u" />" + os.linesep)
427 f.write((
u"{}<Key frame=\"{}\" value=\"{}\"")
432 if key.smooth ==
"1":
433 f.write(
u" smooth=\"1\"")
434 if key.symmetrical ==
"1":
435 f.write(
u" symmetrical=\"1\"")
438 f.write(
u">" + os.linesep)
439 for tangent
in key.tangents:
441 f.write(indent +
u"</Key>" + os.linesep)
443 f.write(
u" />" + os.linesep)
447 f.write((
u"{}<Tangent side=\"{}\" interpType=\"{}\""
448 +
u" abscissaParam=\"{}\" ordinateParam=\"{}\" />{}")
452 tangent.abscissaParam,
453 tangent.ordinateParam,
458 for layer
in sequence.behavior_layers:
463 f.write((
u"{}<BehaviorLayer name=\"{}\"")
467 f.write((
u" mute=\"{}\">{}")
471 f.write(
u">" + os.linesep)
473 for keyframe
in layer.behavior_keyframes:
476 f.write((
u"{}</BehaviorLayer>{}")
482 f.write((
u"{}<BehaviorKeyframe name=\"{}\" index=\"{}\"")
487 f.write((
u" bitmap=\"{}\">{}")
488 .format(keyframe.bitmap,
491 f.write(
u">" + os.linesep)
495 f.write((
u"{}</BehaviorKeyframe>{}")
502 if (
not diagram.box_instances)
and (
not diagram.links):
503 f.write(indent +
u"<Diagram />" + os.linesep)
507 f.write(indent +
u"<Diagram")
510 f.write((
u" scale=\"{}\">{}")
511 .format(diagram.scale,
514 f.write(
u">" + os.linesep)
516 for box_instance
in diagram.box_instances:
519 for link
in diagram.links:
522 f.write(indent +
u"</Diagram>" + os.linesep)
526 f.write((
u"{}<Link inputowner=\"{}\" indexofinput=\"{}\""
527 +
u" outputowner=\"{}\" indexofoutput=\"{}\" />{}")
537 f.write((
u"{}<Resource name=\"{}\" type=\"{}\" timeout=\"{}\" />{}")