def from_sexpr(cls, sexpr, unit, demorgan): sexpr_orig = sexpr.copy() pts = [] if (sexpr.pop(0) != 'text'): return None text = sexpr.pop(0) (posx, posy, rotation) = _parse_at(sexpr) effects = TextEffect.from_sexpr(_get_array(sexpr, 'effects')[0]) return Text(text, posx, posy, rotation, effects, unit = unit, demorgan = demorgan)
def from_sexpr(cls, sexpr, unit: int = 0) -> Optional["Property"]: if sexpr.pop(0) != "property": return None name = sexpr.pop(0) value = sexpr.pop(0) idd = _get_value_of(sexpr, "id") (posx, posy, rotation) = _parse_at(sexpr) effects = TextEffect.from_sexpr(_get_array(sexpr, "effects")[0]) return Property(name, value, idd, posx, posy, rotation, effects)
def from_sexpr(cls, sexpr, unit=0): sexpr_orig = sexpr.copy() if (sexpr.pop(0) != 'property'): return None name = sexpr.pop(0) value = sexpr.pop(0) idd = _get_value_of(sexpr, 'id') (posx, posy, rotation) = _parse_at(sexpr) effects = TextEffect.from_sexpr(_get_array(sexpr, 'effects')[0]) return Property(name, value, idd, posx, posy, rotation, effects)
def from_sexpr(cls, sexpr, unit: int, demorgan: int) -> "Pin": is_global = False # The first 3 items are pin, type and shape if sexpr.pop(0) != "pin": return None etype = sexpr.pop(0) shape = sexpr.pop(0) # the 4th item (global) is optional if sexpr[0] == "global": sexpr.pop(0) is_global = True # fetch more properties is_hidden = "hide" in sexpr length = _get_value_of(sexpr, "length") (posx, posy, rotation) = _parse_at(sexpr) (name, name_effect) = cls._parse_name_or_number(sexpr) (number, number_effect) = cls._parse_name_or_number(sexpr, typ="number") if rotation not in VALID_ROTATIONS: raise ValueError( f"Invalid 'rotation' attribute value for pin: {rotation}" f" (must be one of {set(VALID_ROTATIONS)})") altfuncs = [] alt_n = _get_array(sexpr, "alternate") for alt_sexpr in alt_n: altfuncs.append(AltFunction.from_sexpr(alt_sexpr)) # we also need the pin-number as integer, try to convert it. # Some pins won't work since they are called 'MP' or similar number_int = None try: number_int = int(number) except ValueError: pass # create and return a pin with the extracted values return Pin( name, number, etype, posx, posy, rotation, shape, length, is_global, is_hidden, number_int, name_effect, number_effect, altfuncs=altfuncs, unit=unit, demorgan=demorgan, )
def from_sexpr(cls, sexpr, unit: int, demorgan: int) -> Optional["Text"]: if sexpr.pop(0) != "text": return None text = sexpr.pop(0) (posx, posy, rotation) = _parse_at(sexpr) effects = TextEffect.from_sexpr(_get_array(sexpr, "effects")[0]) return Text(text, posx, posy, rotation, effects, unit=unit, demorgan=demorgan)
def from_sexpr(cls, sexpr): if sexpr.pop(0) != "effects": return None font = _get_array(sexpr, "font")[0] (sizex, sizey) = _get_xy(font, "size") is_italic = "italic" in font is_bold = "bold" in font is_hidden = "hide" in sexpr is_mirrored = "mirror" in sexpr justify = _get_array2(sexpr, "justify") h_justify = "center" v_justify = "center" if justify: if "top" in justify[0]: v_justify = "top" if "bottom" in justify[0]: v_justify = "bottom" if "left" in justify[0]: h_justify = "left" if "right" in justify[0]: h_justify = "right" return cls( sizex, sizey, is_italic, is_bold, is_hidden, is_mirrored, h_justify, v_justify, )
def from_sexpr(cls, sexpr, unit, demorgan): sexpr_orig = sexpr.copy() if (sexpr.pop(0) != 'arc'): return None # the 1st element (startx, starty) = _get_xy(sexpr, 'start') (endx, endy) = _get_xy(sexpr, 'end') rad = _get_array(sexpr, 'radius')[0] (centerx, centery) = _get_xy(rad, 'at') length = _get_value_of(rad, 'length') (angle_start, angle_stop) = _get_xy(rad, 'angles') (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Arc(startx, starty, endx, endy, centerx, centery, length, angle_start, angle_stop, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan)
def from_sexpr(cls, sexpr, unit, demorgan): sexpr_orig = sexpr.copy() if (sexpr.pop(0) != 'rectangle'): return None # the 1st element (startx, starty) = _get_xy(sexpr, 'start') (endx, endy) = _get_xy(sexpr, 'end') (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Rectangle(startx, starty, endx, endy, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan)
def from_sexpr(cls, sexpr, unit, demorgan): sexpr_orig = sexpr.copy() is_global = False # The first 3 items are pin, type and shape if (sexpr.pop(0) != 'pin'): return None etype = sexpr.pop(0) shape = sexpr.pop(0) # the 4th item (global) is optional if sexpr[0] == 'global': sexpr.pop(0) is_global = True # fetch more properties is_hidden = 'hide' in sexpr length = _get_value_of(sexpr, 'length') (posx, posy, rotation) = _parse_at(sexpr) (name, name_effect) = cls._parse_name_or_number(sexpr) (number, number_effect) = cls._parse_name_or_number(sexpr, typ='number') # we also need the pin-number as integer, try to convert it. # Some pins won't work since they are called 'MP' or similar number_int = None try: number_int = int(number) except ValueError: pass # create and return a pin with the just extraced values return Pin(name, number, etype, posx, posy, rotation, shape, length, is_global, is_hidden, number_int, name_effect, number_effect, unit=unit, demorgan=demorgan)
def from_sexpr(cls, sexpr, unit, demorgan): sexpr_orig = sexpr.copy() # The first 3 items are pin, type and shape if (sexpr.pop(0) != 'circle'): return None # the 1st element (centerx, centery) = _get_xy(sexpr, 'center') radius = _get_value_of(sexpr, 'radius') (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Circle(centerx, centery, radius, stroke, scolor, fill, fcolor, unit = unit, demorgan = demorgan)
def from_sexpr(cls, sexpr, unit, demorgan): sexpr_orig = sexpr.copy() pts = [] if (sexpr.pop(0) != 'polyline'): return None for p in _get_array(sexpr, 'pts')[0]: if 'xy' in p: pts.append(Point(p[1], p[2])) (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Polyline(pts, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan)
def from_sexpr(cls, sexpr, unit: int, demorgan: int) -> Optional["Polyline"]: pts = [] if sexpr.pop(0) != "polyline": return None for p in _get_array(sexpr, "pts")[0]: if "xy" in p: pts.append(Point(p[1], p[2])) (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Polyline(pts, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan)
def from_sexpr(cls, sexpr): sexpr_orig = sexpr.copy() if (sexpr.pop(0) != 'effects'): return None font = _get_array(sexpr, 'font')[0] (sizex, sizey) = _get_xy(font, 'size') is_italic = 'italic' in font is_bold = 'bold' in font is_hidden = 'hide' in sexpr is_mirrored = 'mirror' in sexpr justify = _get_array2(sexpr, 'justify') h_justify = "center" v_justify = "center" if justify: if 'top' in justify[0]: v_justify = 'top' if 'bottom' in justify[0]: v_justify = 'bottom' if 'left' in justify[0]: h_justify = 'left' if 'right' in justify[0]: h_justify = 'right' return cls(sizex, sizey, is_italic, is_bold, is_hidden, is_mirrored, h_justify, v_justify)
def from_sexpr(cls, sexpr, unit: int, demorgan: int): # The first 3 items are pin, type and shape if sexpr.pop(0) != "circle": return None # the 1st element (centerx, centery) = _get_xy(sexpr, "center") radius = _get_value_of(sexpr, "radius") (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Circle( centerx, centery, radius, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan, )
def from_sexpr(cls, sexpr, unit: int, demorgan: int) -> Optional["Rectangle"]: if sexpr.pop(0) != "rectangle": return None # the 1st element (startx, starty) = _get_xy(sexpr, "start") (endx, endy) = _get_xy(sexpr, "end") (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Rectangle( startx, starty, endx, endy, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan, )
def from_sexpr(cls, sexpr, unit: int, demorgan: int) -> Optional["Arc"]: if sexpr.pop(0) != "arc": return None (startx, starty) = _get_xy(sexpr, "start") (endx, endy) = _get_xy(sexpr, "end") (midx, midy) = _get_xy(sexpr, "mid") (stroke, scolor) = _get_stroke(sexpr) (fill, fcolor) = _get_fill(sexpr) return Arc( startx, starty, endx, endy, midx, midy, stroke, scolor, fill, fcolor, unit=unit, demorgan=demorgan, )