18 """ Format a name and erase not printable chars
20 :param name: name to format
21 :returns: formatted name
24 return "unnamed_object"
28 if char
in string.printable:
32 pattern = re.compile(
r'[\W_]+')
33 return pattern.sub(
'_', name)
37 """ Find the name of the io designed by id in a box
39 :param box: box with ports
40 :param io_id: id of the io
41 :returns: name of the io as a string
43 for io
in box.inputs + box.outputs + box.parameters:
50 """ Find the nature of the input designed by id in a box
52 :param box: box with inputs
53 :param io_id: id of the io
54 :returns: nature of the io as a string
63 """ Do a traversal of xar objects and rename each objects
64 according to the new format convention
73 name = node.name + str(node.id)
75 name = node.parent_path +
"_" + name
83 prefix = node.parent_path
85 if isinstance(node, node_box.Box):
89 if node.id != str(-1):
90 prefix += str(node.id)
91 elif isinstance(node, node_behavior_layer.BehaviorLayer):
94 prefix += str(node.id)
95 elif isinstance(node, node_behavior_keyframe.BehaviorKeyframe):
98 prefix += str(node.id)
104 raise Exception(
"Conflict found on name: " + name)
110 """ Returns a map with names and associated objects
117 """ Visit a node, and choose the good method to apply
121 methname =
"_visit_%s" % node.node_type.lower()
122 method = getattr(self, methname, self.
visit)
129 node.node_path = node.parent_node.node_path
130 for childNode
in node.children_node:
131 self.
visit(childNode)
139 timeline = node.parent_node.parent_node.parent_node
140 if timeline.enable ==
"0":
141 node.node_path = timeline.node_path
143 node.node_path = node.parent_node.node_path
145 for childNode
in node.children_node:
146 self.
visit(childNode)
149 for child
in node.boxes:
150 id_map[child.id] = child.node_path
155 sys.stderr.write(
"ERROR: No parent for " + node.name
156 +
" abort..." + os.linesep)
158 id_map[str(0)] = parent_name
164 for link
in node.links:
165 link.emitterName = id_map[link.emitterID]
166 link.receiverName = id_map[link.receiverID]
176 self.
_boxes[node.node_path] = node
179 for childNode
in node.children_node:
180 self.
visit(childNode)
186 for childNode
in node.children_node:
187 self.
visit(childNode)
192 for childNode
in node.children_node:
193 self.
visit(childNode)
197 node.node_path = node.parent_path +
"_Bitmap"
198 for childNode
in node.children_node:
199 self.
visit(childNode)
206 node.node_path = node.parent_node.node_path
207 for childNode
in node.children_node:
208 self.
visit(childNode)
212 node.node_path = node.parent_path +
"_Parameter"
216 node.node_path = node.parent_path +
"_PluginContent"
221 node.node_path = node.parent_node.node_path
222 for childNode
in node.children_node:
223 self.
visit(childNode)
227 node.node_path = node.parent_path +
"_ActuatorCurve"
228 for childNode
in node.children_node:
229 self.
visit(childNode)
233 node.node_path = node.parent_path +
"_ActuatorKey"
234 for childNode
in node.children_node:
235 self.
visit(childNode)