9 import xml.sax.saxutils
as saxutils
15 '\x00':
"�",
'\x01':
"",
16 '\x02':
"",
'\x03':
"",
17 '\x04':
"",
'\x05':
"",
18 '\x06':
"",
'\x07':
"",
19 '\x08':
"",
'\x09':
"	",
20 '\x0a':
"
",
'\x0b':
"",
21 '\x0c':
"",
'\x0d':
"
",
22 '\x0e':
"",
'\x0f':
"",
23 '\x10':
"",
'\x11':
"",
24 '\x12':
"",
'\x13':
"",
25 '\x14':
"",
'\x15':
"",
26 '\x16':
"",
'\x17':
"",
27 '\x18':
"",
'\x19':
"",
28 '\x1a':
"",
'\x1b':
"",
29 '\x1c':
"",
'\x1d':
"",
30 '\x1e':
"",
'\x1f':
"",
31 '\"':
""",
'\'':
"'"
36 """ Write meta informations about a box
38 :param f: open file to write informations
45 f.write(
u"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + os.linesep)
48 f.write((
u"<BoxInterface uuid=\"{}\" box_version=\"{}\" name=\"{}\"")
53 f.write((
u" localization=\"{}\"")
54 .format(node.localization))
56 f.write((
u" tooltip=\"{}\"")
57 .format(saxutils.escape(node.tooltip, entities=ENTITIES)))
59 f.write((
u" plugin=\"{}\"").format(node.plugin))
60 f.write((
u" format_version=\"{}\" >{}").format(
u"4", os.linesep))
63 for bitmap
in node.bitmaps:
64 f.write((
u" <Bitmap path=\"{}\" />{}")
68 for inp
in node.inputs:
71 if inp.stm_value_name:
72 f.write((
u" <Input name=\"{}\" signature=\"{}\""
73 +
u" nature=\"{}\" stm_value_name=\"{}\" inner=\"{}\""
74 +
u" tooltip=\"{}\" id=\"{}\" />{}")
76 saxutils.escape(inp.signature, entities=ENTITIES),
80 saxutils.escape(inp.tooltip, entities=ENTITIES),
84 f.write((
u" <Input name=\"{}\" signature=\"{}\""
85 +
u" nature=\"{}\" inner=\"{}\" tooltip=\"{}\""
88 saxutils.escape(inp.signature, entities=ENTITIES),
91 saxutils.escape(inp.tooltip, entities=ENTITIES),
95 for output
in node.outputs:
96 if not output.tooltip:
98 f.write((
u" <Output name=\"{}\" signature=\"{}\""
99 +
u" nature=\"{}\" inner=\"{}\" tooltip=\"{}\""
100 +
u" id=\"{}\" />{}")
102 saxutils.escape(output.signature, entities=ENTITIES),
105 saxutils.escape(output.tooltip, entities=ENTITIES),
109 for parameter
in node.parameters:
110 if not parameter.tooltip:
111 parameter.tooltip =
""
112 f.write((
u" <Parameter name=\"{}\" inherits_from_parent=\"{}\""
113 +
u" type=\"{}\" default_value=\"{}\"")
114 .format(parameter.name,
115 parameter.inherits_from_parent,
116 saxutils.escape(parameter.type, entities=ENTITIES),
117 parameter.default_value))
119 if (parameter.type == xar_types.IOSignature.DOUBLE
120 or parameter.type == xar_types.IOSignature.INT):
121 f.write((
u" min=\"{}\" max=\"{}\"")
122 .format(parameter.min,
125 if parameter.custom_choice:
126 f.write((
u" custom_choice=\"{}\"")
127 .format(parameter.custom_choice))
129 if parameter.password:
130 f.write((
u" password=\"{}\"")
131 .format(parameter.password))
133 f.write((
u" tooltip=\"{}\" id=\"{}\"")
134 .format(saxutils.escape(parameter.tooltip,
137 if parameter.choices:
138 f.write(
u">" + os.linesep)
139 for choice
in parameter.choices:
140 f.write((
u" <Choice value=\"{}\" />{}")
141 .format(saxutils.escape(choice.value,
144 f.write(
u" </Parameter>" + os.linesep)
146 f.write(
u" />" + os.linesep)
148 for resource
in node.resources:
149 f.write((
u" <Resource name=\"{}\" lock_type=\"{}\""
150 +
u" timeout=\"{}\" />{}")
151 .format(resource.name,
157 f.write(
u" <Contents>" + os.linesep)
161 if node.script.language == xar_types.ScriptLanguage.PYTHON:
162 f.write((
u" <Content type=\"{}\" path=\"{}\""
163 +
u" checksum=\"\" />{}")
164 .format(xar_types.ContentType.PYTHON_SCRIPT,
165 node.script.node_path +
".py",
168 f.write((
u" <Content type=\"{}\" path=\"{}\""
169 +
u" checksum=\"\" />{}")
170 .format(xar_types.ContentType.QICHAT_SCRIPT,
171 node.script.node_path +
".top",
175 if node.timeline
and node.timeline.enable ==
"0":
176 f.write((
u" <Content type=\"{}\" path=\"{}\""
177 +
u" checksum=\"\" />{}")
178 .format(xar_types.ContentType.FLOW_DIAGRAM,
179 node.timeline.node_path +
".fld",
184 and node.timeline.enable ==
"1"
185 and node.timeline.behavior_layers):
186 f.write((
u" <Content type=\"{}\" path=\"{}\""
187 +
u" checksum=\"\" />{}")
188 .format(xar_types.ContentType.BEHAVIOR_SEQUENCE,
189 node.timeline.node_path +
".bhs",
193 if node.timeline
and node.timeline.actuator_list:
194 f.write((
u" <Content type=\"{}\" path=\"{}\""
195 +
u" checksum=\"\" />{}")
196 .format(xar_types.ContentType.ANIMATION,
197 node.timeline.actuator_list.node_path +
".anim",
200 f.write(
u" </Contents>" + os.linesep)
202 f.write(
u"</BoxInterface>" + os.linesep)
206 """ Write the behavior sequence file
208 :param f: open file to write information
209 :param timeline: the timeline object containing the sequence
213 f.write(
u"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + os.linesep)
216 f.write((
u"<BehaviorSequence fps=\"{}\" "
217 +
u"start_frame=\"{}\" end_frame=\"{}\" size=\"{}\"")
218 .format(timeline.fps,
219 timeline.start_frame,
223 if timeline.resources_acquisition:
224 f.write((
u" resources_acquisition=\"{}\"")
225 .format(timeline.resources_acquisition))
227 f.write((
u" format_version=\"{}\" >{}")
231 for layer
in timeline.behavior_layers:
234 f.write(
u"</BehaviorSequence>" + os.linesep)
238 f.write((
u"{}<BehaviorLayer name=\"{}\"")
242 f.write((
u" mute=\"{}\"")
244 f.write((
u" >{}").format(os.linesep))
246 for keyframe
in layer.behavior_keyframes:
249 f.write((
u"{}</BehaviorLayer>{}").format(indent,
254 f.write((
u"{}<BehaviorKeyframe name=\"{}\" index=\"{}\"")
260 f.write((
u" bitmap=\"{}\"")
261 .format(keyframe.bitmap))
263 f.write((
u" path=\"{}\" />{}")
264 .format(keyframe.node_path +
".fld",
269 """ Write flow diagram description
271 :param f: open file to write information
272 :param flow_diagram: diagram node to write
275 f.write(
u"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + os.linesep)
278 f.write(
u"<FlowDiagram")
280 if flow_diagram.scale:
281 f.write((
u" scale=\"{}\"")
282 .format(flow_diagram.scale))
284 f.write((
u" format_version=\"{}\" >{}")
289 for box
in flow_diagram.boxes:
293 for link
in flow_diagram.links:
296 f.write(
u"</FlowDiagram>" + os.linesep)
300 f.write((
u"{}<BoxInstance name=\"{}\" id=\"{}\""
301 +
u" x=\"{}\" y=\"{}\" path=\"{}\"")
307 instance.node_path +
".xml"))
310 if not instance.parameters
and not instance.plugin_content:
311 f.write(
u" />" + os.linesep)
315 f.write(
u" >" + os.linesep)
317 if instance.parameters:
318 for parameter
in instance.parameters:
321 if instance.plugin_content:
324 f.write((
u"{}</BoxInstance>{}").format(indent, os.linesep))
328 f.write((
u"{}<ParameterValue id=\"{}\" value=\"{}\" />{}")
336 """ Write XML part of the <pluginContent> beacon, inside the box
339 A recursive write is necessary because the content of the part
340 is completely unknown and can contain levels and levels of
344 f.write((
u"{}<{}>{}").format(indent,
345 pluginContent.beacon(),
347 for subnode
in pluginContent.subnodes:
349 f.write((
u"{}</{}>{}").format(indent,
350 pluginContent.beacon(),
355 f.write((
u"{}<{}").format(indent,
357 if subnode.attributes.keys():
358 for key
in subnode.attributes.keys():
359 f.write((
u" {}=\"{}\"").format(str(key),
360 str(subnode.attributes[key])))
363 f.write(
u">" + os.linesep)
364 for subsubnode
in subnode.subnodes:
366 f.write((
u"{}</{}>{}").format(indent,
370 elif subnode.content:
371 f.write((
u">{}</{}>{}").format(subnode.content,
376 f.write(
u"/>" + os.linesep)
380 f.write((
u"{}<Link inputowner=\"{}\" indexofinput=\"{}\""
381 +
u" outputowner=\"{}\" indexofoutput=\"{}\" />{}")
391 """ Write the animation file
393 :param f: open file to write information
394 :param timeline: the timeline containing the motion layer
397 f.write(
u"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + os.linesep)
400 f.write((
u"<Animation fps=\"{}\""
401 +
u" start_frame=\"{}\" end_frame=\"{}\" size=\"{}\"")
402 .format(actuator_list.parent_node.fps,
403 actuator_list.parent_node.start_frame,
404 actuator_list.parent_node.end_frame,
405 actuator_list.parent_node.size))
407 if actuator_list.parent_node.resources_acquisition:
408 f.write((
u" resources_acquisition=\"{}\"")
409 .format(actuator_list.parent_node.resources_acquisition))
411 f.write((
u" format_version=\"{}\" >{}")
415 f.write((
u" <ActuatorList model=\"{}\" >{}")
416 .format(actuator_list.model,
419 for curve
in actuator_list.curves:
422 f.write(
u" </ActuatorList>" + os.linesep)
423 f.write(
u"</Animation>" + os.linesep)
427 f.write((
u"{}<ActuatorCurve name=\"{}\" actuator=\"{}\""
428 +
u" recordable=\"{}\" mute=\"{}\" unit=\"{}\" >{}")
437 for key
in curve.keys:
440 f.write((
u"{}</ActuatorCurve>{}")
446 f.write((
u"{}<Key frame=\"{}\" value=\"{}\""
447 +
u" smooth=\"{}\" symmetrical=\"{}\"")
455 f.write(
u" >" + os.linesep)
456 for tangent
in key.tangents:
458 f.write((
u"{}</Key>{}")
462 f.write(
u" />" + os.linesep)
466 f.write((
u"{}<Tangent side=\"{}\" interpType=\"{}\""
467 +
u" abscissaParam=\"{}\" ordinateParam=\"{}\" />{}")
471 tangent.abscissaParam,
472 tangent.ordinateParam,
477 """ Write the main file of the behavior
479 :param f: open file to write information
480 :param node: the root node of the behavior
484 f.write(
u"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + os.linesep)
487 f.write((
u"<ChoregrapheProject name=\"{}\" format_version=\"{}\" >{}")
488 .format(name,
u"4", os.linesep))
492 f.write(
u"</ChoregrapheProject>" + os.linesep)