<s> """<STR_LIT>""" <EOL> from . utils import ( parse_gerber_value , write_gerber_value , decimal_string , <EOL> inch , metric ) <EOL> from . am_statements import * <EOL> from . am_read import read_macro <EOL> from . am_eval import eval_macro <EOL> class Statement ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stype , units = '<STR_LIT>' ) : <EOL> self . type = stype <EOL> self . units = units <EOL> def __str__ ( self ) : <EOL> s = "<STR_LIT>" . format ( self . __class__ . __name__ ) <EOL> for key , value in self . __dict__ . items ( ) : <EOL> s += "<STR_LIT>" . format ( key , value ) <EOL> s = s . rstrip ( ) + "<STR_LIT:>>" <EOL> return s <EOL> def to_inch ( self ) : <EOL> self . units = '<STR_LIT>' <EOL> def to_metric ( self ) : <EOL> self . units = '<STR_LIT>' <EOL> def offset ( self , x_offset = <NUM_LIT:0> , y_offset = <NUM_LIT:0> ) : <EOL> pass <EOL> def __eq__ ( self , other ) : <EOL> return self . __dict__ == other . __dict__ <EOL> class ParamStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , param ) : <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> self . param = param <EOL> class FSParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> """<STR_LIT:U+0020>""" <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> if stmt_dict . get ( '<STR_LIT>' ) == '<STR_LIT:L>' : <EOL> zeros = '<STR_LIT>' <EOL> elif stmt_dict . get ( '<STR_LIT>' ) == '<STR_LIT:T>' : <EOL> zeros = '<STR_LIT>' <EOL> else : <EOL> zeros = '<STR_LIT:none>' <EOL> notation = '<STR_LIT>' if stmt_dict . get ( '<STR_LIT>' ) == '<STR_LIT:A>' else '<STR_LIT>' <EOL> fmt = tuple ( map ( int , stmt_dict . get ( '<STR_LIT:x>' ) ) ) <EOL> return cls ( param , zeros , notation , fmt ) <EOL> def __init__ ( self , param , zero_suppression = '<STR_LIT>' , <EOL> notation = '<STR_LIT>' , format = ( <NUM_LIT:2> , <NUM_LIT:4> ) ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . zero_suppression = zero_suppression <EOL> self . notation = notation <EOL> self . format = format <EOL> def to_gerber ( self , settings = None ) : <EOL> if settings : <EOL> zero_suppression = '<STR_LIT:L>' if settings . zero_suppression == '<STR_LIT>' else '<STR_LIT:T>' <EOL> notation = '<STR_LIT:A>' if settings . notation == '<STR_LIT>' else '<STR_LIT:I>' <EOL> fmt = '<STR_LIT>' . join ( map ( str , settings . format ) ) <EOL> else : <EOL> zero_suppression = '<STR_LIT:L>' if self . zero_suppression == '<STR_LIT>' else '<STR_LIT:T>' <EOL> notation = '<STR_LIT:A>' if self . notation == '<STR_LIT>' else '<STR_LIT:I>' <EOL> fmt = '<STR_LIT>' . join ( map ( str , self . format ) ) <EOL> return '<STR_LIT>' . format ( zero_suppression , notation , fmt , fmt ) <EOL> def __str__ ( self ) : <EOL> return ( '<STR_LIT>' % <EOL> ( self . format [ <NUM_LIT:0> ] , self . format [ <NUM_LIT:1> ] , self . zero_suppression , self . notation ) ) <EOL> class MOParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> if stmt_dict . get ( '<STR_LIT>' ) is None : <EOL> mo = None <EOL> elif stmt_dict . get ( '<STR_LIT>' ) . lower ( ) not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> elif stmt_dict . get ( '<STR_LIT>' ) . lower ( ) == '<STR_LIT>' : <EOL> mo = '<STR_LIT>' <EOL> else : <EOL> mo = '<STR_LIT>' <EOL> return cls ( param , mo ) <EOL> def __init__ ( self , param , mo ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . mode = mo <EOL> def to_gerber ( self , settings = None ) : <EOL> mode = '<STR_LIT>' if self . mode == '<STR_LIT>' else '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( mode ) <EOL> def to_inch ( self ) : <EOL> self . mode = '<STR_LIT>' <EOL> def to_metric ( self ) : <EOL> self . mode = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> mode_str = '<STR_LIT>' if self . mode == '<STR_LIT>' else '<STR_LIT>' <EOL> return ( '<STR_LIT>' % mode_str ) <EOL> class LPParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict [ '<STR_LIT>' ] <EOL> lp = '<STR_LIT>' if stmt_dict . get ( '<STR_LIT>' ) == '<STR_LIT:C>' else '<STR_LIT>' <EOL> return cls ( param , lp ) <EOL> def __init__ ( self , param , lp ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . lp = lp <EOL> def to_gerber ( self , settings = None ) : <EOL> lp = '<STR_LIT:C>' if self . lp == '<STR_LIT>' else '<STR_LIT:D>' <EOL> return '<STR_LIT>' . format ( lp ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . lp <EOL> class ADParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> d = int ( stmt_dict . get ( '<STR_LIT:d>' ) ) <EOL> shape = stmt_dict . get ( '<STR_LIT>' ) <EOL> modifiers = stmt_dict . get ( '<STR_LIT>' ) <EOL> return cls ( param , d , shape , modifiers ) <EOL> def __init__ ( self , param , d , shape , modifiers ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . d = d <EOL> self . shape = shape <EOL> if modifiers : <EOL> self . modifiers = [ tuple ( [ float ( x ) for x in m . split ( "<STR_LIT:X>" ) if len ( x ) ] ) <EOL> for m in modifiers . split ( "<STR_LIT:U+002C>" ) if len ( m ) ] <EOL> else : <EOL> self . modifiers = [ tuple ( ) ] <EOL> def to_inch ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> self . modifiers = [ tuple ( [ inch ( x ) for x in modifier ] ) <EOL> for modifier in self . modifiers ] <EOL> def to_metric ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> self . modifiers = [ tuple ( [ metric ( x ) for x in modifier ] ) <EOL> for modifier in self . modifiers ] <EOL> def to_gerber ( self , settings = None ) : <EOL> if any ( self . modifiers ) : <EOL> return '<STR_LIT>' . format ( self . d , self . shape , '<STR_LIT:U+002C>' . join ( [ '<STR_LIT:X>' . join ( [ "<STR_LIT>" % x for x in modifier ] ) for modifier in self . modifiers ] ) ) <EOL> else : <EOL> return '<STR_LIT>' . format ( self . d , self . shape ) <EOL> def __str__ ( self ) : <EOL> if self . shape == '<STR_LIT:C>' : <EOL> shape = '<STR_LIT>' <EOL> elif self . shape == '<STR_LIT:R>' : <EOL> shape = '<STR_LIT>' <EOL> elif self . shape == '<STR_LIT:O>' : <EOL> shape = '<STR_LIT>' <EOL> else : <EOL> shape = self . shape <EOL> return '<STR_LIT>' % ( self . d , shape ) <EOL> class AMParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> return cls ( ** stmt_dict ) <EOL> def __init__ ( self , param , name , macro ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . name = name <EOL> self . macro = macro <EOL> self . instructions = self . read ( macro ) <EOL> self . primitives = [ ] <EOL> def read ( self , macro ) : <EOL> return read_macro ( macro ) <EOL> def build ( self , modifiers = [ [ ] ] ) : <EOL> self . primitives = [ ] <EOL> for primitive in eval_macro ( self . instructions , modifiers [ <NUM_LIT:0> ] ) : <EOL> if primitive [ <NUM_LIT:0> ] == '<STR_LIT:0>' : <EOL> self . primitives . append ( AMCommentPrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> ] == '<STR_LIT:1>' : <EOL> self . primitives . append ( AMCirclePrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> : <NUM_LIT:2> ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . primitives . append ( AMVectorLinePrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> : <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> self . primitives . append ( AMCenterLinePrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> : <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> self . primitives . append ( AMLowerLeftLinePrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> ] == '<STR_LIT:4>' : <EOL> self . primitives . append ( AMOutlinePrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> ] == '<STR_LIT:5>' : <EOL> self . primitives . append ( AMPolygonPrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . primitives . append ( AMMoirePrimitive . from_gerber ( primitive ) ) <EOL> elif primitive [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . primitives . append ( <EOL> AMThermalPrimitive . from_gerber ( primitive ) ) <EOL> else : <EOL> self . primitives . append ( <EOL> AMUnsupportPrimitive . from_gerber ( primitive ) ) <EOL> return self <EOL> def to_inch ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> for primitive in self . primitives : <EOL> primitive . to_inch ( ) <EOL> def to_metric ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> for primitive in self . primitives : <EOL> primitive . to_metric ( ) <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' . format ( self . name , "<STR_LIT>" . join ( [ primitive . to_gerber ( ) for primitive in self . primitives ] ) ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . name , self . macro ) <EOL> class ASParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> mode = stmt_dict . get ( '<STR_LIT>' ) <EOL> return cls ( param , mode ) <EOL> def __init__ ( self , param , mode ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . mode = mode <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' . format ( self . mode ) <EOL> def __str__ ( self ) : <EOL> return ( '<STR_LIT>' % self . mode ) <EOL> class INParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> return cls ( ** stmt_dict ) <EOL> def __init__ ( self , param , name ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . name = name <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' . format ( self . name ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> class IPParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> ip = '<STR_LIT>' if stmt_dict . get ( '<STR_LIT>' ) == '<STR_LIT>' else '<STR_LIT>' <EOL> return cls ( param , ip ) <EOL> def __init__ ( self , param , ip ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . ip = ip <EOL> def to_gerber ( self , settings = None ) : <EOL> ip = '<STR_LIT>' if self . ip == '<STR_LIT>' else '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( ip ) <EOL> def __str__ ( self ) : <EOL> return ( '<STR_LIT>' % self . ip ) <EOL> class IRParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> angle = int ( stmt_dict [ '<STR_LIT>' ] ) <EOL> return cls ( stmt_dict [ '<STR_LIT>' ] , angle ) <EOL> def __init__ ( self , param , angle ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . angle = angle <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' . format ( self . angle ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . angle <EOL> class MIParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> a = int ( stmt_dict . get ( '<STR_LIT:a>' , <NUM_LIT:0> ) ) <EOL> b = int ( stmt_dict . get ( '<STR_LIT:b>' , <NUM_LIT:0> ) ) <EOL> return cls ( param , a , b ) <EOL> def __init__ ( self , param , a , b ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . a = a <EOL> self . b = b <EOL> def to_gerber ( self , settings = None ) : <EOL> ret = "<STR_LIT>" <EOL> if self . a is not None : <EOL> ret += "<STR_LIT>" . format ( self . a ) <EOL> if self . b is not None : <EOL> ret += "<STR_LIT>" . format ( self . b ) <EOL> ret += "<STR_LIT>" <EOL> return ret <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . a , self . b ) <EOL> class OFParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> a = float ( stmt_dict . get ( '<STR_LIT:a>' , <NUM_LIT:0> ) ) <EOL> b = float ( stmt_dict . get ( '<STR_LIT:b>' , <NUM_LIT:0> ) ) <EOL> return cls ( param , a , b ) <EOL> def __init__ ( self , param , a , b ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . a = a <EOL> self . b = b <EOL> def to_gerber ( self , settings = None ) : <EOL> ret = '<STR_LIT>' <EOL> if self . a is not None : <EOL> ret += '<STR_LIT:A>' + decimal_string ( self . a , precision = <NUM_LIT:5> ) <EOL> if self . b is not None : <EOL> ret += '<STR_LIT:B>' + decimal_string ( self . b , precision = <NUM_LIT:5> ) <EOL> return ret + '<STR_LIT>' <EOL> def to_inch ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> if self . a is not None : <EOL> self . a = inch ( self . a ) <EOL> if self . b is not None : <EOL> self . b = inch ( self . b ) <EOL> def to_metric ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> if self . a is not None : <EOL> self . a = metric ( self . a ) <EOL> if self . b is not None : <EOL> self . b = metric ( self . b ) <EOL> def offset ( self , x_offset = <NUM_LIT:0> , y_offset = <NUM_LIT:0> ) : <EOL> if self . a is not None : <EOL> self . a += x_offset <EOL> if self . b is not None : <EOL> self . b += y_offset <EOL> def __str__ ( self ) : <EOL> offset_str = '<STR_LIT>' <EOL> if self . a is not None : <EOL> offset_str += ( '<STR_LIT>' % self . a ) <EOL> if self . b is not None : <EOL> offset_str += ( '<STR_LIT>' % self . b ) <EOL> return ( '<STR_LIT>' % offset_str ) <EOL> class SFParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> param = stmt_dict . get ( '<STR_LIT>' ) <EOL> a = float ( stmt_dict . get ( '<STR_LIT:a>' , <NUM_LIT:1> ) ) <EOL> b = float ( stmt_dict . get ( '<STR_LIT:b>' , <NUM_LIT:1> ) ) <EOL> return cls ( param , a , b ) <EOL> def __init__ ( self , param , a , b ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . a = a <EOL> self . b = b <EOL> def to_gerber ( self , settings = None ) : <EOL> ret = '<STR_LIT>' <EOL> if self . a is not None : <EOL> ret += '<STR_LIT:A>' + decimal_string ( self . a , precision = <NUM_LIT:5> ) <EOL> if self . b is not None : <EOL> ret += '<STR_LIT:B>' + decimal_string ( self . b , precision = <NUM_LIT:5> ) <EOL> return ret + '<STR_LIT>' <EOL> def to_inch ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> if self . a is not None : <EOL> self . a = inch ( self . a ) <EOL> if self . b is not None : <EOL> self . b = inch ( self . b ) <EOL> def to_metric ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> if self . a is not None : <EOL> self . a = metric ( self . a ) <EOL> if self . b is not None : <EOL> self . b = metric ( self . b ) <EOL> def offset ( self , x_offset = <NUM_LIT:0> , y_offset = <NUM_LIT:0> ) : <EOL> if self . a is not None : <EOL> self . a += x_offset <EOL> if self . b is not None : <EOL> self . b += y_offset <EOL> def __str__ ( self ) : <EOL> scale_factor = '<STR_LIT>' <EOL> if self . a is not None : <EOL> scale_factor += ( '<STR_LIT>' % self . a ) <EOL> if self . b is not None : <EOL> scale_factor += ( '<STR_LIT>' % self . b ) <EOL> return ( '<STR_LIT>' % scale_factor ) <EOL> class LNParamStmt ( ParamStmt ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict ) : <EOL> return cls ( ** stmt_dict ) <EOL> def __init__ ( self , param , name ) : <EOL> """<STR_LIT>""" <EOL> ParamStmt . __init__ ( self , param ) <EOL> self . name = name <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' . format ( self . name ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> class DeprecatedStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_gerber ( cls , line ) : <EOL> return cls ( line ) <EOL> def __init__ ( self , line ) : <EOL> """<STR_LIT>""" <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> self . line = line <EOL> def to_gerber ( self , settings = None ) : <EOL> return self . line <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . line <EOL> class CoordStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def from_dict ( cls , stmt_dict , settings ) : <EOL> function = stmt_dict [ '<STR_LIT>' ] <EOL> x = stmt_dict . get ( '<STR_LIT:x>' ) <EOL> y = stmt_dict . get ( '<STR_LIT:y>' ) <EOL> i = stmt_dict . get ( '<STR_LIT:i>' ) <EOL> j = stmt_dict . get ( '<STR_LIT>' ) <EOL> op = stmt_dict . get ( '<STR_LIT>' ) <EOL> if x is not None : <EOL> x = parse_gerber_value ( stmt_dict . get ( '<STR_LIT:x>' ) , settings . format , <EOL> settings . zero_suppression ) <EOL> if y is not None : <EOL> y = parse_gerber_value ( stmt_dict . get ( '<STR_LIT:y>' ) , settings . format , <EOL> settings . zero_suppression ) <EOL> if i is not None : <EOL> i = parse_gerber_value ( stmt_dict . get ( '<STR_LIT:i>' ) , settings . format , <EOL> settings . zero_suppression ) <EOL> if j is not None : <EOL> j = parse_gerber_value ( stmt_dict . get ( '<STR_LIT>' ) , settings . format , <EOL> settings . zero_suppression ) <EOL> return cls ( function , x , y , i , j , op , settings ) <EOL> def __init__ ( self , function , x , y , i , j , op , settings ) : <EOL> """<STR_LIT>""" <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> self . function = function <EOL> self . x = x <EOL> self . y = y <EOL> self . i = i <EOL> self . j = j <EOL> self . op = op <EOL> def to_gerber ( self , settings = None ) : <EOL> ret = '<STR_LIT>' <EOL> if self . function : <EOL> ret += self . function <EOL> if self . x is not None : <EOL> ret += '<STR_LIT>' . format ( write_gerber_value ( self . x , settings . format , <EOL> settings . zero_suppression ) ) <EOL> if self . y is not None : <EOL> ret += '<STR_LIT>' . format ( write_gerber_value ( self . y , settings . format , <EOL> settings . zero_suppression ) ) <EOL> if self . i is not None : <EOL> ret += '<STR_LIT>' . format ( write_gerber_value ( self . i , settings . format , <EOL> settings . zero_suppression ) ) <EOL> if self . j is not None : <EOL> ret += '<STR_LIT>' . format ( write_gerber_value ( self . j , settings . format , <EOL> settings . zero_suppression ) ) <EOL> if self . op : <EOL> ret += self . op <EOL> return ret + '<STR_LIT:*>' <EOL> def to_inch ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> if self . x is not None : <EOL> self . x = inch ( self . x ) <EOL> if self . y is not None : <EOL> self . y = inch ( self . y ) <EOL> if self . i is not None : <EOL> self . i = inch ( self . i ) <EOL> if self . j is not None : <EOL> self . j = inch ( self . j ) <EOL> if self . function == "<STR_LIT>" : <EOL> self . function = "<STR_LIT>" <EOL> def to_metric ( self ) : <EOL> if self . units == '<STR_LIT>' : <EOL> self . units = '<STR_LIT>' <EOL> if self . x is not None : <EOL> self . x = metric ( self . x ) <EOL> if self . y is not None : <EOL> self . y = metric ( self . y ) <EOL> if self . i is not None : <EOL> self . i = metric ( self . i ) <EOL> if self . j is not None : <EOL> self . j = metric ( self . j ) <EOL> if self . function == "<STR_LIT>" : <EOL> self . function = "<STR_LIT>" <EOL> def offset ( self , x_offset = <NUM_LIT:0> , y_offset = <NUM_LIT:0> ) : <EOL> if self . x is not None : <EOL> self . x += x_offset <EOL> if self . y is not None : <EOL> self . y += y_offset <EOL> if self . i is not None : <EOL> self . i += x_offset <EOL> if self . j is not None : <EOL> self . j += y_offset <EOL> def __str__ ( self ) : <EOL> coord_str = '<STR_LIT>' <EOL> if self . function : <EOL> coord_str += '<STR_LIT>' % self . function <EOL> if self . x is not None : <EOL> coord_str += '<STR_LIT>' % self . x <EOL> if self . y is not None : <EOL> coord_str += '<STR_LIT>' % self . y <EOL> if self . i is not None : <EOL> coord_str += '<STR_LIT>' % self . i <EOL> if self . j is not None : <EOL> coord_str += '<STR_LIT>' % self . j <EOL> if self . op : <EOL> if self . op == '<STR_LIT>' : <EOL> op = '<STR_LIT>' <EOL> elif self . op == '<STR_LIT>' : <EOL> op = '<STR_LIT>' <EOL> elif self . op == '<STR_LIT>' : <EOL> op = '<STR_LIT>' <EOL> else : <EOL> op = self . op <EOL> coord_str += '<STR_LIT>' % op <EOL> return '<STR_LIT>' % coord_str <EOL> class ApertureStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , d , deprecated = None ) : <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> self . d = int ( d ) <EOL> self . deprecated = True if deprecated is not None and deprecated is not False else False <EOL> def to_gerber ( self , settings = None ) : <EOL> if self . deprecated : <EOL> return '<STR_LIT>' . format ( self . d ) <EOL> else : <EOL> return '<STR_LIT>' . format ( self . d ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . d <EOL> class CommentStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , comment ) : <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> self . comment = comment if comment is not None else "<STR_LIT>" <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' . format ( self . comment ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . comment <EOL> class EofStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' <EOL> class QuadrantModeStmt ( Statement ) : <EOL> @ classmethod <EOL> def from_gerber ( cls , line ) : <EOL> if '<STR_LIT>' not in line and '<STR_LIT>' not in line : <EOL> raise ValueError ( '<STR_LIT>' <EOL> % line ) <EOL> return ( cls ( '<STR_LIT>' ) if line [ : <NUM_LIT:3> ] == '<STR_LIT>' <EOL> else cls ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , mode ) : <EOL> super ( QuadrantModeStmt , self ) . __init__ ( '<STR_LIT>' ) <EOL> mode = mode . lower ( ) <EOL> if mode not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . mode = mode <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' if self . mode == '<STR_LIT>' else '<STR_LIT>' <EOL> class RegionModeStmt ( Statement ) : <EOL> @ classmethod <EOL> def from_gerber ( cls , line ) : <EOL> if '<STR_LIT>' not in line and '<STR_LIT>' not in line : <EOL> raise ValueError ( '<STR_LIT>' % line ) <EOL> return ( cls ( '<STR_LIT>' ) if line [ : <NUM_LIT:3> ] == '<STR_LIT>' else cls ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , mode ) : <EOL> super ( RegionModeStmt , self ) . __init__ ( '<STR_LIT>' ) <EOL> mode = mode . lower ( ) <EOL> if mode not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . mode = mode <EOL> def to_gerber ( self , settings = None ) : <EOL> return '<STR_LIT>' if self . mode == '<STR_LIT>' else '<STR_LIT>' <EOL> class UnknownStmt ( Statement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , line ) : <EOL> Statement . __init__ ( self , "<STR_LIT>" ) <EOL> self . line = line <EOL> def to_gerber ( self , settings = None ) : <EOL> return self . line <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . line </s>
