Commits

saar drimer  committed cc98092

it is not possible to move components in Inkscape and have them extracted using the -e option

  • Participants
  • Parent commits 5cab225

Comments (0)

Files changed (2)

     if board_cfg is not None:
         cfg['board'] = board_cfg
 
+    cfg['board']['config_filename'] = board_config_filename
+
     # look for layout style file in the following places, in order
     style_files_to_look_for = [os.path.join(cfg['base_dir'],
                                             cfg['pcbmode']['locations']['styles'],

File utils/extract.py

     """
 
     # open SVG file
-    input_file = os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'],
+    input_svg_file = os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'],
                               cfg['board']['files'].get('routing_svg') or cfg['board_name'] + '.svg')    
     try:
-        input_file = open(os.path.join(input_file), 'rb')
+        input_svg_file = open(os.path.join(input_svg_file), 'rb')
     except IOError as e:
-        print "ERROR: can't open %s; has the board been created yet?" % input_file
+        print "ERROR: can't open %s; has the board been created yet?" % input_svg_file
         print "I/O error({0}): {1}".format(e.errno, e.strerror)
         raise
 
-    svg_in = et.ElementTree(file=input_file) 
-    input_file.close()
-
-    layers = {}
+    svg_in = et.ElementTree(file=input_svg_file) 
+    input_svg_file.close()
 
     ns =  {'inkscape':cfg['namespace']['inkscape'], 'svg':cfg['namespace']['svg']}
+    regex = r".*?translate\s?\(\s?(?P<x>-?[0-9]*\.?[0-9]+)\s?[\s,]\s?(?P<y>-?[0-9]*\.?[0-9]+\s?)\s?\).*"
+
+    # for each component (by 'refdef') look to see if the placement
+    # coordinate is the same as the original configuration structure; 
+    # if it isn't, change it in the *config file* (rather than dump
+    # the config structure, which will not preserve order)
+    for layer in cfg['board']['components']:
+        for refdef in cfg['board']['components'][layer]:
+            coord = utils.to_Point(cfg['board']['components'][layer][refdef]['location'])
+            tmp = svg_in.find("//svg:g[@id='%s_%s_%s']" % (layer, 'pads', refdef), namespaces=ns)
+            new_coord = re.match(regex, tmp.get('transform'))
+            new_coord = Point(new_coord.group('x'), new_coord.group('y'))
+            new_coord.y = -new_coord.y # flip the 'y' as usual
+            if coord != new_coord:
+                print "  * updating location of %s" % refdef
+                tmp = [new_coord.x, new_coord.y]
+                cfg['board']['components'][layer][refdef]['location'] = tmp
+
+    try:
+        f = open(cfg['board']['config_filename'], 'wb')
+    except IOError as e:
+        print "I/O error({0}): {1}".format(e.errno, e.strerror)
 
-    # get layers
-    for pcb_layer in utils.get_surface_layers(cfg):
-        layers[pcb_layer] = svg_in.find("//svg:g[@inkscape:label='%s']" % pcb_layer, 
-                                         namespaces=ns)
-
-        # get pad placement
-        pads = layers[pcb_layer].findall(".//svg:g[@refdef]", 
-                                       namespaces=ns)
-       
-        for pad in pads:
-            refdef = pad.get('refdef')
-            transform = pad.get('transform')
-            print refdef, transform
-
-        print
+    f.write(json.dumps(cfg['board'], sort_keys=True, indent=2))
+    f.close() 
+
+
+#    layers = {}
+# 
+#    ns =  {'inkscape':cfg['namespace']['inkscape'], 'svg':cfg['namespace']['svg']}
+# 
+#    # get layers
+#    for pcb_layer in utils.get_surface_layers(cfg):
+#        layers[pcb_layer] = svg_in.find("//svg:g[@inkscape:label='%s']" % pcb_layer, 
+#                                         namespaces=ns)
+# 
+#        # get pad placement
+#        pads = layers[pcb_layer].findall(".//svg:g[@refdef]",
+#                                       namespaces=ns)
+#       
+#        for pad in pads:
+#            refdef = pad.get('refdef')
+#            transform = pad.get('transform')
+#            print refdef, transform
+# 
+#        print
 
     return