#NEWLINE# def extractComponents( svg_in ) : #NEWLINE# #INDENT# '\n    ' #NEWLINE# xpath_expr_place = '//svg:g[@pcbmode:pcb-layer="%s"]//svg:g[@pcbmode:sheet="placement"]//svg:g[@pcbmode:type="%s"]' #NEWLINE# for pcb_layer in config . stk [ 'surface-layer-names' ] : #NEWLINE# #INDENT# markers = svg_in . findall ( ( xpath_expr_place % ( pcb_layer , 'component' ) ) , namespaces = { #NEWLINE# #INDENT# 'pcbmode' : config . cfg [ 'ns' ] [ 'pcbmode' ] , #NEWLINE# 'svg' : config . cfg [ 'ns' ] [ 'svg' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# markers += svg_in . findall ( ( xpath_expr_place % ( pcb_layer , 'shape' ) ) , namespaces = { #NEWLINE# #INDENT# 'pcbmode' : config . cfg [ 'ns' ] [ 'pcbmode' ] , #NEWLINE# 'svg' : config . cfg [ 'ns' ] [ 'svg' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# for marker in markers : #NEWLINE# #INDENT# transform_data = utils . parseTransform ( marker . get ( 'transform' ) ) #NEWLINE# refdef = marker . get ( ( ( '{' + config . cfg [ 'ns' ] [ 'pcbmode' ] ) + '}refdef' ) ) #NEWLINE# marker_type = marker . get ( ( ( '{' + config . cfg [ 'ns' ] [ 'pcbmode' ] ) + '}type' ) ) #NEWLINE# if ( marker_type == 'component' ) : #NEWLINE# #INDENT# comp_dict = config . brd [ 'components' ] [ refdef ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( marker_type == 'shape' ) : #NEWLINE# #INDENT# comp_dict = config . brd [ 'shapes' ] [ refdef ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# new_location = transform_data [ 'location' ] #NEWLINE# old_location = utils . toPoint ( ( comp_dict . get ( 'location' ) or [ 0 , 0 ] ) ) #NEWLINE# new_location . y *= config . cfg [ 'invert-y' ] #NEWLINE# if ( new_location != old_location ) : #NEWLINE# #INDENT# x1 = utils . niceFloat ( old_location . x ) #NEWLINE# y1 = utils . niceFloat ( old_location . y ) #NEWLINE# x2 = utils . niceFloat ( new_location . x ) #NEWLINE# y2 = utils . niceFloat ( filename . y ) #NEWLINE# msg . subInfo ( ( '%s has moved from [%s,%s] to [%s,%s]' % ( refdef , x1 , y2 , x2 , y2 ) ) ) #NEWLINE# comp_dict [ 'location' ] = [ x2 , y2 ] #NEWLINE# #UNINDENT# if ( transform_data [ 'type' ] == 'matrix' ) : #NEWLINE# #INDENT# old_rotate = ( comp_dict . get ( 'rotate' ) or 0 ) #NEWLINE# new_rotate = transform_data [ 'rotate' ] #NEWLINE# comp_dict [ 'rotate' ] = utils . niceFloat ( ( ( old_rotate + new_rotate ) % 360 ) ) #NEWLINE# msg . subInfo ( ( 'Component %s rotated from %s to %s' % ( refdef , old_rotate , comp_dict [ 'rotate' ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# filename = os . path . join ( config . cfg [ 'locations' ] [ 'boards' ] , config . cfg [ 'name' ] , ( config . cfg [ 'name' ] + '.json' ) ) #NEWLINE# try : #NEWLINE# #INDENT# with open ( filename , 'wb' ) as f : #NEWLINE# #INDENT# f . write ( json . dumps ( config . brd , sort_keys = True , indent = 2 ) ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# msg . error ( ( 'Cannot save file %s' % filename ) ) #NEWLINE# #UNINDENT# return