def test_bounds_all_elts(self): '''bounds() with all the elements competing''' net = Net('foo') mkbounds(net, 3, 3, -1, -2) self.des.add_net(net) annot = Annotation('foo', 3, 3, 0, True) mkbounds(annot, 3, 3, 3, 5) self.des.design_attributes.add_annotation(annot) libcomp = Component('bar') libcomp.add_symbol(Symbol()) libcomp.symbols[0].add_body(Body()) mkbounds(libcomp.symbols[0].bodies[0], 0, 0, 3, 3) self.des.add_component('foo', libcomp) compinst = ComponentInstance('bar', 'foo', 0) compinst.add_symbol_attribute(SymbolAttribute(3, 0, 0, False)) self.des.add_component_instance(compinst) top_left, btm_right = self.des.bounds() self.assertEqual(top_left.x, -1) self.assertEqual(top_left.y, -2) self.assertEqual(btm_right.x, 6) self.assertEqual(btm_right.y, 5)
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 = Body() 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 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 parse_body(self, body): """ Extract a body of a symbol. """ bdy = Body() for pin in body.get('pins'): parsed_pin = self.parse_pin(pin) bdy.add_pin(parsed_pin) for shape in body.get('shapes'): parsed_shape = self.parse_shape(shape) bdy.add_shape(parsed_shape) return bdy
def parse(self): """ Parses a component from the library, returns a Compenent. """ part = Component(self.filename) part.add_symbol(Symbol()) part.symbols[0].add_body(Body()) tree = ViewDrawBase.parse(self) for k, v in tree['attr']: part.add_attribute(k, v) for shape in tree['shape'] + sum(tree['lines'], []): part.symbols[0].bodies[0].add_shape(shape) for pin in tree['pin']: part.symbols[0].bodies[0].add_pin(pin) return part
def make_body_from_symbol(self, lib, symbol_name): """ Contruct an openjson Body from an eagle symbol in a library. """ body = Body() symbol = [ s for s in get_subattr(lib, 'symbols.symbol') if s.name == symbol_name ][0] for wire in symbol.wire: body.add_shape( Line((self.make_length(wire.x1), self.make_length(wire.y1)), (self.make_length(wire.x2), self.make_length(wire.y2)))) return body
def make_body_from_symbol(self, lib, symbol_name): """ Construct an openjson Body from an eagle symbol in a library. """ body = Body() symbol = [ s for s in get_subattr(lib, 'symbols.symbol') if s.name == symbol_name ][0] for wire in symbol.wire: body.add_shape( Line((self.make_length(wire.x1), self.make_length(wire.y1)), (self.make_length(wire.x2), self.make_length(wire.y2)))) for rect in symbol.rectangle: x = self.make_length(rect.x1) y = self.make_length(rect.y1) width = self.make_length(rect.x2) - x height = self.make_length(rect.y2) - y body.add_shape(Rectangle(x, y + height, width, height)) pin_map = {} for pin in symbol.pin: connect_point = (self.make_length(pin.x), self.make_length(pin.y)) null_point = self.get_pin_null_point(connect_point, pin.length, pin.rot) label = self.get_pin_label(pin, null_point) pin_map[pin.name] = Pin(pin.name, null_point, connect_point, label) body.add_pin(pin_map[pin.name]) ann_map = {} for text in symbol.text: x = self.make_length(text.x) y = self.make_length(text.y) content = '' if text.valueOf_ is None else text.valueOf_ rotation = self.make_angle('0' if text.rot is None else text.rot) if content == '>NAME': ann_map['name'] = Annotation(content, x, y, rotation, 'true') elif content == '>VALUE': ann_map['value'] = Annotation(content, x, y, rotation, 'true') else: body.add_shape(Label(x, y, content, 'left', rotation)) return body, pin_map, ann_map
def test_bounds_parts(self): '''test bounds() with just components in the design''' libcomp = Component('bar') libcomp.add_symbol(Symbol()) libcomp.symbols[0].add_body(Body()) mkbounds(libcomp.symbols[0].bodies[0], 0, 0, 10, 10) self.des.add_component('foo', libcomp) for (x, y) in ((1, 3), (3, 2), (5, 3), (3, 7)): compinst = ComponentInstance(str((x, y)), 'foo', 0) compinst.add_symbol_attribute(SymbolAttribute(x, y, 0, False)) self.des.add_component_instance(compinst) top_left, btm_right = self.des.bounds() self.assertEqual(top_left.x, 1) self.assertEqual(top_left.y, 2) self.assertEqual(btm_right.x, 15) self.assertEqual(btm_right.y, 17)
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 tearDown(self): """ Teardown the test case. """ self.bod = Body()
def setUp(self): """ Setup the test case. """ self.bod = Body()