def parse(self): '''Returns a Design built up from a schematic file that represents one sheet of the original schematic''' tree = ViewDrawBase.parse(self) # tree['lines'] is a [list of [list of lines]] tree['shape'].extend(sum(tree['lines'], [])) ckt = Design() # TODO little weak here, a copy instead? ckt.components = self.lib for net in tree['net']: ckt.add_net(net) for inst in tree['inst']: ckt.add_component_instance(inst) # hold on tight, this is ugly for (netid, netpt, pinid) in inst.conns: net = [n for n in ckt.nets if n.net_id == netid][0] comp = ConnectedComponent(inst.instance_id, pinid) net.ibpts[netpt - 1].add_connected_component(comp) del inst.conns for net in ckt.nets: del net.ibpts for shape in tree['shape']: ckt.add_shape(shape) if isinstance(shape, Label): ann = Annotation(shape.text, shape.x, shape.y, shape._rotation, True) ckt.design_attributes.add_annotation(ann) for k, v, annot in tree['attr']: ckt.design_attributes.add_attribute(k, v) ckt.design_attributes.add_annotation(annot) return ckt
def _convert_nets(self, struct): """ Convert nets """ # FIXME polyline_path is not documented and no success with reverse engineering yet self._convert_wires(struct) if struct.network: for net in struct.network.net: if net.pins is None: continue prev_point = None for pin_ref in net.pins.pin_reference: # pin_ref like A1-"-" is valid (parsed to A1--) component_id, pin_id = pin_ref[:pin_ref.index('-')], pin_ref[pin_ref.index('-') + 1:] point = self.get_component_pin(component_id, pin_id) if point is None: print 'Could not find net %s pin ref %s' % (net.net_id, pin_ref) continue cc = ConnectedComponent(component_id, pin_id) np = self._get_point(net.net_id, pin_ref, point[0], point[1]) np.add_connected_component(cc) if prev_point is not None: # XXX if point is already connected assume wiring had routed network, don't do it here if len(prev_point.connected_points) == 0: prev_point.add_connected_point(np.point_id) if len(np.connected_points) == 0: np.add_connected_point(prev_point.point_id) prev_point = np
def connect_pinref(self, pinref, point): """ Add a connected component to a NetPoint given an eagle pinref. """ inst = self.part2inst[pinref.part] cpt = self.design.components.components[inst.library_id] pin = self.cptgate2pin_map[cpt, pinref.gate][pinref.pin] point.add_connected_component( ConnectedComponent(inst.instance_id, pin.pin_number))
def connect_point(self, cid, inst, point): """ Given a connector id, instance id, and a NetPoint, add the appropriate ConnectedComponent to the point """ termid = self.cid2termid.get(cid) pin = self.termid2pin.get(termid) if pin is not None: ccpt = ConnectedComponent(inst.instance_id, pin.pin_number) point.add_connected_component(ccpt)
def make_pin_points(self, design, point_factory): """ Construct a set of NetPoints connected to pins. """ for inst in design.component_instances: if inst.library_id in design.components.components: cpt = design.components.components[inst.library_id] for symba, body in zip(inst.symbol_attributes, cpt.symbols[inst.symbol_index].bodies): for pin in body.pins: point = point_factory(self.get_pin_coord(pin, symba)) point.add_connected_component( ConnectedComponent(inst.instance_id, pin.pin_number))
def calc_connected_components(self, design): """ Add all the connected components to the nets """ pins = defaultdict(set) # (x, y) -> set([(instance_id, pin_number)]) for inst in design.component_instances: if inst.library_id in design.components.components: cpt = design.components.components[inst.library_id] for symba, body in zip(inst.symbol_attributes, cpt.symbols[inst.symbol_index].bodies): for pin in body.pins: pins[symba.x + pin.p2.x, symba.y - pin.p2.y].add( (inst.instance_id, pin.pin_number)) for net in design.nets: for point in net.points.values(): for instance_id, pin_number in pins.get((point.x, point.y), ()): conncpt = ConnectedComponent(instance_id, pin_number) point.add_connected_component(conncpt)
def test_create_new_component(self): """ Test the creation of a new empty connected component. """ comp = ConnectedComponent('001', '002') assert comp.instance_id == '001'
def parse_connected_component(self, connectedcomponent): """ Extract a connected component. """ instance_id = connectedcomponent.get('instance_id') pin_number = connectedcomponent.get('pin_number') return ConnectedComponent(instance_id, pin_number)