@@ -33,12 +33,11 @@ class Circle(object):
3333 def __init__ (self ):
3434 self .center = []
3535 self .end = []
36- self .width = 0
37- self .angle = 0
36+ self .width = '0'
3837 self .layer = ''
3938 self .fill = ''
4039 self .tstamp = ''
41- self .status = 0
40+ self .status = ''
4241
4342
4443 def From_PCB (self , input ):
@@ -59,9 +58,9 @@ def From_PCB(self, input):
5958 self .end .append (float (item [1 ]))
6059 self .end .append (float (item [2 ]))
6160
62- if item [0 ] == 'angle' :
63- self .angle = item [1 ]
64- assert False ,"Gr_circle: Please report this! Never seen before."
61+ # if item[0] == 'angle':
62+ # self.angle = item[1]
63+ # assert False,"Gr_circle: Please report this! Never seen before."
6564
6665 if item [0 ] == 'layer' :
6766 self .layer = item [1 ]
@@ -88,15 +87,20 @@ def To_PCB(self, fp = False):
8887 pcb .append (['center' ] + self .center )
8988 pcb .append (['end' ] + self .end )
9089 pcb .append (['width' , self .width ])
91- pcb .append (['angle' , self .angle ])
90+ # pcb.append(['angle', self.angle])
9291 pcb .append (['layer' , self .layer ])
93- pcb .append (['fill' , self .fill ])
92+ if self .fill != '' :
93+ pcb .append (['fill' , self .fill ])
9494 pcb .append (['tstamp' , self .tstamp ])
9595 pcb .append (['status' , self .status ])
9696
9797 return pcb
9898
99- def To_SVG (self ):
99+ def To_SVG (self , fp = False ):
100+ if fp :
101+ circletype = 'fp_circle'
102+ else :
103+ circletype = 'gr_circle'
100104 tstamp = ''
101105 status = ''
102106 fill = ''
@@ -118,11 +122,44 @@ def To_SVG(self):
118122 parameters += 'cy="' + str (self .center [1 ] * pxToMM ) + '" '
119123 parameters += 'r="' + str (r * pxToMM ) + '" '
120124 parameters += 'layer="' + self .layer + '" '
121- parameters += 'type="gr_circle " '
125+ parameters += 'type="' + circletype + ' " '
122126 parameters += fill
123127 parameters += tstamp
124128 parameters += status
125129 parameters += '/>'
126130
127131 return parameters
128132
133+
134+
135+ def From_SVG (self , tag ):
136+ style = tag ['style' ]
137+
138+ width = style [style .find ('stroke-width:' ) + 13 :]
139+ self .width = width [0 :width .find ('mm' )]
140+
141+ if tag .has_attr ('layer' ):
142+ self .layer = tag ['layer' ]
143+ elif tag .parent .has_attr ('inkscape:label' ):
144+ #XML metadata trashed, try to recover from parent tag
145+ self .layer = tag .parent ['inkscape:label' ]
146+ else :
147+ assert False , "Circle not in layer"
148+
149+
150+ r = str ((float (tag ['r' ]) + float (tag ['cx' ] )) / pxToMM )
151+ x = str (float (tag ['cx' ]) / pxToMM )
152+ y = str (float (tag ['cy' ]) / pxToMM )
153+ self .center = [x , y ]
154+ self .end = [r , y ]
155+
156+ if tag .has_attr ('fill' ) == True :
157+ self .fill = tag ['fill' ]
158+
159+ if tag .has_attr ('status' ) == True :
160+ self .status = tag ['status' ]
161+
162+ if tag .has_attr ('tstamp' ) == True :
163+ self .tstamp = tag ['tstamp' ]
164+
165+
0 commit comments