def parse_fzp(self, fzp_file): """ Parse the Fritzing component file """ tree = ElementTree(file=fzp_file) try: prefix = tree.find('label').text except AttributeError: pass else: self.component.add_attribute('_prefix', prefix) symbol = Symbol() self.component.add_symbol(symbol) self.body = SBody() symbol.add_body(self.body) self.cid2termid.update(self.parse_terminals(tree)) self.terminals.update(self.cid2termid.values()) layers = tree.find('views/schematicView/layers') if layers is None: self.image = None else: self.image = layers.get('image') if self.image == 'schematic/dcpower.svg' : self.image='schematic/dc_powersupply.svg'
def parse_fzp(self, fzp_file): """ Parse the Fritzing component file """ tree = ElementTree(file=fzp_file) try: prefix = tree.find('label').text except AttributeError: pass else: self.component.add_attribute('_prefix', prefix) symbol = Symbol() self.component.add_symbol(symbol) self.body = SBody() symbol.add_body(self.body) self.cid2termid.update(self.parse_terminals(tree)) self.terminals.update(self.cid2termid.values()) layers = tree.find('views/schematicView/layers') if layers is None: self.image = None else: self.image = layers.get('image')
def make_device_component(self, lib, deviceset, device): """ Construct an openjson component for a device in a deviceset. """ cpt = Component(lib.name + ':' + deviceset.name + ':' + device.name) cpt.add_attribute('eaglexml_library', lib.name) cpt.add_attribute('eaglexml_deviceset', deviceset.name) cpt.add_attribute('eaglexml_device', device.name) symbol = Symbol() cpt.add_symbol(symbol) assignment = PinNumberAssignment(device) for i, gate in enumerate(get_subattr(deviceset, 'gates.gate')): body, pin_map, ann_map = self.make_body_from_symbol( lib, gate.symbol, assignment.get_pin_number_lookup(gate.name)) symbol.add_body(body) cpt.add_attribute('eaglexml_symbol_%d' % i, gate.symbol) cpt.add_attribute('eaglexml_gate_%d' % i, gate.name) self.cptgate2body_index[cpt, gate.name] = len(symbol.bodies) - 1 self.cptgate2pin_map[cpt, gate.name] = pin_map self.cptgate2ann_map[cpt, gate.name] = ann_map return cpt
def parse_symbol(self, symbol_json): """ Extract a symbol. """ symb = Symbol() for body in symbol_json.get('bodies'): bdy = self.parse_symbol_body(body) symb.add_body(bdy) return symb
def parse_symbol(self, symbol_json): """ Extract a symbol. """ symb = Symbol() for body in symbol_json.get("bodies"): bdy = self.parse_symbol_body(body) symb.add_body(bdy) return symb
def parse_symbol(self, symbol): """ Extract a symbol. """ symb = Symbol() for body in symbol.get('bodies'): bdy = self.parse_body(body) symb.add_body(bdy) return symb
def build_symbols(self, has_convert): """ Build all Symbols and Bodies for this component. The has_convert argument should be True if there are DeMorgan convert bodies. """ for _ in range(2 if has_convert else 1): symbol = Symbol() for _ in range(self.num_units): symbol.add_body(Body()) self.component.add_symbol(symbol)
def build_symbols(self, has_convert): """ Build all Symbols and Bodies for this component. The has_convert argument should be True if there are DeMorgan convert bodies. """ for _ in range(2 if has_convert else 1): symbol = Symbol() for _ in range(self.num_units): symbol.add_body(SBody()) self.component.add_symbol(symbol)
def make_component(self, lib, deviceset): """ Construct an openjson component for a deviceset in a library. """ cpt = Component(lib.name + ':' + deviceset.name) for gate in get_subattr(deviceset, 'gates.gate'): symbol = Symbol() cpt.add_symbol(symbol) self.cpt2gate2symbol_index[cpt][gate.name] = len(cpt.symbols) - 1 symbol.add_body(self.make_body_from_symbol(lib, gate.symbol)) return cpt
def _convert_library(self, struct): for image in struct.library.image: component = Component(image.image_id) self.design.add_component(image.image_id, component) sym = Symbol() body = Body() component.add_symbol(sym) sym.add_body(body) for pin in image.pin: body.add_pin(Pin(pin.pin_id, self.to_pixels(pin.vertex), self.to_pixels(pin.vertex))) for padstack in struct.library.padstack: if padstack.padstack_id == pin.padstack_id: shapes = [shape.shape for shape in padstack.shape] for shape in self._convert_shapes(shapes, self.to_pixels(pin.vertex)): body.add_shape(shape) break for outline in image.outline: for shape in self._convert_shapes([outline.shape]): body.add_shape(shape)
def make_deviceset_component(self, lib, deviceset): """ Construct an openjson component for an eaglexml deviceset in a library.""" cpt = Component(lib.name + ':' + deviceset.name + ':logical') cpt.add_attribute('eaglexml_type', 'logical') cpt.add_attribute('eaglexml_library', lib.name) cpt.add_attribute('eaglexml_deviceset', deviceset.name) symbol = Symbol() cpt.add_symbol(symbol) for i, gate in enumerate(get_subattr(deviceset, 'gates.gate')): body, pin_map, ann_map = self.make_body_from_symbol(lib, gate.symbol) symbol.add_body(body) cpt.add_attribute('eaglexml_symbol_%d' % i, gate.symbol) cpt.add_attribute('eaglexml_gate_%d' % i, gate.name) self.cptgate2body_index[cpt, gate.name] = len(symbol.bodies) - 1 self.cptgate2pin_map[cpt, gate.name] = pin_map self.cptgate2ann_map[cpt, gate.name] = ann_map return cpt
def _convert_library(self, struct): for image in struct.library.image: component = Component(image.image_id) self.design.add_component(image.image_id, component) sym = Symbol() body = Body() component.add_symbol(sym) sym.add_body(body) for pin in image.pin: body.add_pin( Pin(pin.pin_id, self.to_pixels(pin.vertex), self.to_pixels(pin.vertex))) for padstack in struct.library.padstack: if padstack.padstack_id == pin.padstack_id: shapes = [shape.shape for shape in padstack.shape] for shape in self._convert_shapes( shapes, self.to_pixels(pin.vertex)): body.add_shape(shape) break for outline in image.outline: for shape in self._convert_shapes([outline.shape]): body.add_shape(shape)
def make_deviceset_component(self, lib, deviceset): """ Construct an openjson component for an eaglexml deviceset in a library.""" cpt = Component(lib.name + ':' + deviceset.name + ':logical') cpt.add_attribute('eaglexml_type', 'logical') cpt.add_attribute('eaglexml_library', lib.name) cpt.add_attribute('eaglexml_deviceset', deviceset.name) symbol = Symbol() cpt.add_symbol(symbol) for i, gate in enumerate(get_subattr(deviceset, 'gates.gate')): body, pin_map, ann_map = self.make_body_from_symbol( lib, gate.symbol) symbol.add_body(body) cpt.add_attribute('eaglexml_symbol_%d' % i, gate.symbol) cpt.add_attribute('eaglexml_gate_%d' % i, gate.name) self.cptgate2body_index[cpt, gate.name] = len(symbol.bodies) - 1 self.cptgate2pin_map[cpt, gate.name] = pin_map self.cptgate2ann_map[cpt, gate.name] = ann_map return cpt