#NEWLINE# def extractDocs( svg_in ) : #NEWLINE# #INDENT# "\n    Extracts the position of the documentation elements and updates\n    the board's json\n    " #NEWLINE# xpath_expr = '//svg:g[@pcbmode:sheet="documentation"]//svg:g[@pcbmode:type="module-shapes"]' #NEWLINE# docs = svg_in . findall ( xpath_expr , namespaces = { #NEWLINE# #INDENT# 'pcbmode' : config . cfg [ 'ns' ] [ 'pcbmode' ] , #NEWLINE# 'svg' : config . cfg [ 'ns' ] [ 'svg' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# for doc in docs : #NEWLINE# #INDENT# doc_key = doc . get ( ( ( '{' + config . cfg [ 'ns' ] [ 'pcbmode' ] ) + '}doc-key' ) ) #NEWLINE# translate_data = utils . parseTransform ( doc . get ( 'transform' ) ) #NEWLINE# location = translate_data [ 'location' ] #NEWLINE# location . y *= config . cfg [ 'invert-y' ] #NEWLINE# current_location = utils . toPoint ( config . brd [ 'documentation' ] [ doc_key ] [ 'location' ] ) #NEWLINE# if ( current_location != location ) : #NEWLINE# #INDENT# config . brd [ 'documentation' ] [ doc_key ] [ 'location' ] = [ location . x , location . y ] #NEWLINE# msg . subInfo ( ( "Found new location ([%s, %s]) for '%s'" % ( location . x , location . y , doc_key ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# xpath_expr = '//svg:g[@pcbmode:sheet="drills"]//svg:g[@pcbmode:type="drill-index"]' #NEWLINE# drill_index = svg_in . find ( xpath_expr , namespaces = { #NEWLINE# #INDENT# 'pcbmode' : config . cfg [ 'ns' ] [ 'pcbmode' ] , #NEWLINE# 'svg' : config . cfg [ 'ns' ] [ 'svg' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# transform_dict = utils . parseTransform ( drill_index . get ( 'transform' ) ) #NEWLINE# location = transform_dict [ 'location' ] #NEWLINE# location . y *= config . cfg [ 'invert-y' ] #NEWLINE# drill_index_dict = config . brd . get ( 'drill-index' ) #NEWLINE# if ( drill_index_dict == None ) : #NEWLINE# #INDENT# config . brd [ 'drill-index' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# config . brd [ 'drill-index' ] [ 'location' ] = [ location . x , location . y ] #NEWLINE# 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 ) )