@@ -110,6 +110,9 @@ def __init__(self, rot_string):
110110 self .angle = float ('' .join (d for d in rot_string
111111 if d in string .digits + '.' ))
112112
113+ def __repr__ (self ):
114+ return self .__str__ ()
115+
113116 def __str__ (self ):
114117 return "Mirrored: {0}, Spin: {1}, Angle: {2}" .format (self .mirrored ,
115118 self .spin ,
@@ -585,61 +588,83 @@ def _process_footprint(self, package, x, y, angle, mirrored, populate):
585588 elif (mirrored and top ) or (not mirrored and bot ):
586589 dwg_layer ['B' ].append (dwg )
587590
588- def _element_refdes_to_silk (self , el ):
591+ def _name_to_silk (self , name , x , y , elr , tr , align , size , ratio ):
592+ angle = tr .angle
593+ mirrored = tr .mirrored
594+ spin = elr .spin ^ tr .spin
595+ if mirrored :
596+ angle = - angle
597+
598+ if align is None :
599+ justify = [- 1 , 1 ]
600+ elif align == 'center' :
601+ justify = [0 , 0 ]
602+ else :
603+ j = align .split ('-' )
604+ alignments = {
605+ 'bottom' : 1 ,
606+ 'center' : 0 ,
607+ 'top' : - 1 ,
608+ 'left' : - 1 ,
609+ 'right' : 1
610+ }
611+ justify = [alignments [ss ] for ss in j [::- 1 ]]
612+ if (90 < angle <= 270 and not spin ) or \
613+ (- 90 >= angle >= - 270 and not spin ):
614+ angle += 180
615+ justify = [- j for j in justify ]
616+
617+ dwg = {
618+ 'type' : 'text' ,
619+ 'text' : name ,
620+ 'pos' : [x , y ],
621+ 'height' : size ,
622+ 'width' : size ,
623+ 'justify' : justify ,
624+ 'thickness' : size * ratio ,
625+ 'attr' : [] if not mirrored else ['mirrored' ],
626+ 'angle' : angle
627+ }
628+
629+ self .font_parser .parse_font_for_string (name )
630+ if mirrored :
631+ self .pcbdata ['drawings' ]['silkscreen' ]['B' ].append (dwg )
632+ else :
633+ self .pcbdata ['drawings' ]['silkscreen' ]['F' ].append (dwg )
634+
635+ def _element_refdes_to_silk (self , el , package ):
636+ if 'smashed' not in el .attrib :
637+ elx = float (el .attrib ['x' ])
638+ ely = - float (el .attrib ['y' ])
639+ for p_el in package .iter ('text' ):
640+ if p_el .text == '>NAME' :
641+ dx = float (p_el .attrib ['x' ])
642+ dy = float (p_el .attrib ['y' ])
643+ elr = self .Rot (el .get ('rot' ))
644+ dx , dy = self ._rotate (dx , dy , elr .angle , elr .mirrored )
645+ tr = self .Rot (p_el .get ('rot' ))
646+ tr .angle += elr .angle
647+ tr .mirrored ^= elr .mirrored
648+ self ._name_to_silk (name = el .attrib ['name' ],
649+ x = elx + dx ,
650+ y = ely - dy ,
651+ elr = elr ,
652+ tr = tr ,
653+ align = p_el .get ('align' ),
654+ size = float (p_el .attrib ['size' ]),
655+ ratio = float (p_el .get ('ratio' , '8' ))/ 100 )
656+
657+
589658 for attr in el .iter ('attribute' ):
590659 if attr .attrib ['name' ] == 'NAME' :
591- attrx = float (attr .attrib ['x' ])
592- attry = - float (attr .attrib ['y' ])
593- xpos = attrx
594- ypos = attry
595- elr = self .Rot (el .get ('rot' ))
596- tr = self .Rot (attr .get ('rot' ))
597- text = el .attrib ['name' ]
598-
599- angle = tr .angle
600- mirrored = tr .mirrored
601- spin = elr .spin ^ tr .spin
602- if mirrored :
603- angle = - angle
604-
605- if 'align' not in attr .attrib :
606- justify = [- 1 , 1 ]
607- elif attr .attrib ['align' ] == 'center' :
608- justify = [0 , 0 ]
609- else :
610- j = attr .attrib ['align' ].split ('-' )
611- alignments = {
612- 'bottom' : 1 ,
613- 'center' : 0 ,
614- 'top' : - 1 ,
615- 'left' : - 1 ,
616- 'right' : 1
617- }
618- justify = [alignments [ss ] for ss in j [::- 1 ]]
619- if (90 < angle < 270 and not spin ) or \
620- (- 90 >= angle >= - 270 and not spin ):
621- angle += 180
622- justify = [- j for j in justify ]
623-
624- size = float (attr .attrib ['size' ])
625- ratio = float (attr .get ('ratio' , '8' )) / 100
626- dwg = {
627- 'type' : 'text' ,
628- 'text' : text ,
629- 'pos' : [xpos , ypos ],
630- 'height' : size ,
631- 'width' : size ,
632- 'justify' : justify ,
633- 'thickness' : size * ratio ,
634- 'attr' : [] if not mirrored else ['mirrored' ],
635- 'angle' : angle
636- }
637-
638- self .font_parser .parse_font_for_string (text )
639- if mirrored :
640- self .pcbdata ['drawings' ]['silkscreen' ]['B' ].append (dwg )
641- else :
642- self .pcbdata ['drawings' ]['silkscreen' ]['F' ].append (dwg )
660+ self ._name_to_silk (name = el .attrib ['name' ],
661+ x = float (attr .attrib ['x' ]),
662+ y = - float (attr .attrib ['y' ]),
663+ elr = self .Rot (el .get ('rot' )),
664+ tr = self .Rot (attr .get ('rot' )),
665+ align = attr .attrib .get ('align' ),
666+ size = float (attr .attrib ['size' ]),
667+ ratio = float (attr .get ('ratio' , '8' )) / 100 )
643668
644669 @staticmethod
645670 def _segments_to_polygon (segs , angle = 0 , mirrored = False ):
@@ -822,7 +847,7 @@ def _parse(self, brdfile):
822847 # Add silkscreen, edges for component footprint & refdes
823848 self ._process_footprint (package , elx , ely , elr .angle , elr .mirrored ,
824849 populate )
825- self ._element_refdes_to_silk (el )
850+ self ._element_refdes_to_silk (el , package )
826851
827852 if populate :
828853 self .components .append (comp )
0 commit comments