28 def __init__(self, raw_file, w, use_hybridnum, omit_symbols, omit_pixmaps):
46 self.w.write_attribute(
'linewidth', self.
fmt(line.width))
48 self.w.write_attribute(
'capstyle', ENUM_CAPSTYLE[line.cap_style])
50 self.w.write_attribute(
'dashstyle', ENUM_DASHSTYLE[line.dash_style])
51 if line.dash_style != 0
and line.dash_style != 1:
52 self.w.write_attribute(
'dashlength', self.
fmt(line.dash_length))
53 if line.dash_style != 0:
54 self.w.write_attribute(
'dashspace', self.
fmt(line.dash_space))
58 self.w.write_attribute(
'filltype', ENUM_FILLTYPE[fill.type])
59 if fill.type == 2
or fill.type == 3:
60 self.w.write_attribute(
'fillwidth', self.
fmt(fill.width))
61 self.w.write_attribute(
'angle0', str(fill.angle0))
62 self.w.write_attribute(
'pitch0', self.
fmt(fill.pitch0))
64 self.w.write_attribute(
'angle1', str(fill.angle1))
65 self.w.write_attribute(
'pitch1', self.
fmt(fill.pitch1))
70 self.w.start_element(
'arc')
71 self.w.write_attribute(
'x', self.
fmt(data.x))
72 self.w.write_attribute(
'y', self.
fmt(data.y))
73 self.w.write_attribute(
'radius', self.
fmt(data.radius))
74 self.w.write_attribute(
'startangle', str(data.startangle))
75 self.w.write_attribute(
'sweepangle', str(data.sweepangle))
77 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
82 self.w.start_element(
'box')
83 self.w.write_attribute(
'x', self.
fmt(data.x))
84 self.w.write_attribute(
'y', self.
fmt(data.y))
85 self.w.write_attribute(
'width', self.
fmt(data.width))
86 self.w.write_attribute(
'height', self.
fmt(data.height))
88 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
94 self.w.start_element(
'circle')
95 self.w.write_attribute(
'x', self.
fmt(data.x))
96 self.w.write_attribute(
'y', self.
fmt(data.y))
97 self.w.write_attribute(
'radius', self.
fmt(data.radius))
99 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
105 self.w.start_element(
'component')
106 self.w.write_attribute(
'x', self.
fmt(data.x))
107 self.w.write_attribute(
'y', self.
fmt(data.y))
108 if not data.selectable:
109 self.w.write_attribute(
'selectable',
110 ENUM_BOOLEAN[data.selectable])
112 self.w.write_attribute(
'angle', str(data.angle))
114 self.w.write_attribute(
'mirror', ENUM_BOOLEAN[data.mirror])
115 self.w.write_attribute(
'symbol', self.
symbol_ids[data.symbol])
116 for ob
in ob.attached_objects():
121 self.w.start_element(
'line')
122 self.w.write_attribute(
'x0', self.
fmt(data.x))
123 self.w.write_attribute(
'y0', self.
fmt(data.y))
124 self.w.write_attribute(
'x1', self.
fmt(data.x + data.width))
125 self.w.write_attribute(
'y1', self.
fmt(data.y + data.height))
127 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
133 self.w.start_element(
'pin')
136 self.w.start_element(
'net')
141 self.w.write_attribute(
'x0', self.
fmt(data.x))
142 self.w.write_attribute(
'y0', self.
fmt(data.y))
143 self.w.write_attribute(
'x1', self.
fmt(data.x + data.width))
144 self.w.write_attribute(
'y1', self.
fmt(data.y + data.height))
145 if data.color != default_color:
146 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
148 self.w.write_attribute(
'type', ENUM_NETTYPE[data.is_bus])
149 if data.is_pin
and data.is_inverted:
150 self.w.write_attribute(
'inverted',
151 ENUM_BOOLEAN[data.is_inverted])
152 for ob
in ob.attached_objects():
157 self.w.start_element(
'path', preserve_whitespace =
True)
159 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
162 for i, line
in enumerate(data.pathdata.split(
'\n')):
164 self.w.start_element(
'br')
166 self.w.write_character_data(line)
170 self.w.start_element(
'picture')
171 self.w.write_attribute(
'x', self.
fmt(data.x))
172 self.w.write_attribute(
'y', self.
fmt(data.y))
173 self.w.write_attribute(
'width', self.
fmt(data.width))
174 self.w.write_attribute(
'height', self.
fmt(data.height))
176 self.w.write_attribute(
'angle', str(data.angle))
178 self.w.write_attribute(
'mirrored', ENUM_BOOLEAN[data.mirror])
179 self.w.write_attribute(
'pixmap', self.
pixmap_ids[data.pixmap])
188 self.w.start_element(
'text',
True)
192 self.w.start_element(
'attribute',
True)
193 self.w.write_attribute(
'name', name)
197 self.w.write_attribute(
'x', self.
fmt(data.x))
198 self.w.write_attribute(
'y', self.
fmt(data.y))
199 if data.color != (5
if is_attribute
else 9):
200 self.w.write_attribute(
'color', ENUM_COLOR[data.color])
201 self.w.write_attribute(
'size', str(data.text_size))
202 if is_attribute
or not data.visibility:
203 self.w.write_attribute(
204 'visible', ENUM_BOOLEAN[data.visibility])
205 if is_attribute
or data.show_name_value:
206 self.w.write_attribute(
207 'show', ENUM_SHOW_NAME_VALUE[data.show_name_value])
209 self.w.write_attribute(
'angle', str(data.angle))
211 self.w.write_attribute(
'alignment',
212 ENUM_ALIGNMENT[data.alignment])
215 for i, part
in enumerate(text.split(
'\\_')):
217 self.w.start_element(
'overbar')
219 part =
'\\'.join(s.replace(
'\\',
'')
220 for s
in part.split(
'\\\\'))
222 for j, line
in enumerate(part.split(
'\n')):
224 self.w.start_element(
'br')
226 self.w.write_character_data(line.decode(
'utf-8'))
236 raise ValueError,
'symbol contents missing'
237 self.w.start_element(
'symbol')
238 self.w.write_attribute(
'id', self.
symbol_ids[symbol])
239 self.w.write_attribute(
'name', symbol.basename)
241 self.w.write_attribute(
'mode',
'embedded')
244 self.w.write_attribute(
'mode',
'referenced')
247 self.w.write_attribute(
'mode',
'omitted')
252 raise ValueError,
'pixmap contents missing'
253 self.w.start_element(
'pixmap', preserve_whitespace =
True)
254 self.w.write_attribute(
'id', self.
pixmap_ids[pixmap])
255 self.w.write_attribute(
'name', pixmap.filename)
258 self.w.write_attribute(
'mode',
'embedded')
260 self.w.write_attribute(
'mode',
'referenced')
261 self.w.write_character_data(
'')
262 self.raw_file.write(
'\n')
264 self.raw_file.write(
' ' * (len(self.w.stack) - 1))
266 self.w.write_attribute(
'mode',
'omitted')
271 def get_unique_id(name):
275 id =
"%s.%d" % (name, i)
279 for ob
in rev.all_objects():
283 tmp = data.symbol.basename
284 if tmp.lower().endswith(
'.sym'):
286 if tmp.lower().endswith(
'.sym.xml'):
288 self.
symbol_ids[data.symbol] = get_unique_id(tmp)
291 tmp = data.pixmap.filename.split(
'/')[-1]
294 if tmp.lower().endswith(
'.jpg')
or \
295 tmp.lower().endswith(
'.png')
or \
296 tmp.lower().endswith(
'.gif')
or \
297 tmp.lower().endswith(
'.svg'):
299 self.
pixmap_ids[data.pixmap] = get_unique_id(tmp)
301 self.w.start_element(
'content')
302 for ob
in rev.toplevel_objects():
306 written_symbols = set()
307 written_pixmaps = set()
308 for ob
in rev.all_objects():
311 if data.symbol
not in written_symbols:
313 written_symbols.add(data.symbol)
315 if data.pixmap
not in written_pixmaps:
317 written_pixmaps.add(data.pixmap)
319 def write_file(f, rev, is_symbol, use_hybridnum = False,
320 omit_symbols =
False,
321 omit_pixmaps =
False):
324 w.start_element(
'symbol')
326 w.start_element(
'schematic')
327 w.write_attribute(
'xmlns', NAMESPACE)
328 fff = [
'experimental']
330 fff.append(
'hybridnum')
332 w.write_attribute(
'file-format-features',
' '.join(fff))
333 Writer(f, w, use_hybridnum, omit_symbols, omit_pixmaps).write_rev(rev)
Attribute parsing and lookup.
Schematic net segment, bus segment, or pin.
def encode
Write a binary string to a file in base64 representation.
High-level revision proxy class.
def format
Convert a floating-point number to its hybrid string representation.
Schematic text or attribute.
Hybrid fixed-/floating-point numbers.
def format
Convert an integer to its fixed-point string representation.
def parse_string
Parse an attribute string of the form name=value into its name and value parts.