Commits

saar drimer  committed 5cab225

layers will now have unique ids, so Inkscape wouldn't need to replace them with random ones

  • Participants
  • Parent commits dd06dad

Comments (0)

Files changed (4)

File utils/board.py

         """
         Adds a footprint to the board
         """
- 
+
         svg_layers = ['drills']
         for svg_layer in svg_layers:
             footprint_pcb_layer = footprint.find(".//g[@inkscape:label='%s']" % svg_layer, namespaces=cfg['namespace'])
 
         # import layer content
         for pcb_layer in utils.get_surface_layers(cfg):
+
+            # get the footprint's layer
             footprint_pcb_layer = footprint.find(".//g[@inkscape:label='%s']" % pcb_layer, namespaces=cfg['namespace'])
+
+            # get the board's layer
             board_pcb_layer = board.find(".//g[@inkscape:label='%s']" % pcb_layer, namespaces=cfg['namespace'])
  
             svg_layers = [['copper','pads'], ['copper', 'routing'], 
                     board_layer = board_layer.find(".//g[@inkscape:label='%s']" % layer, namespaces=cfg['namespace'])
                 et.strip_attributes(footprint_layer, '{'+cfg['namespace']['inkscape']+'}label')
                 et.strip_attributes(footprint_layer, '{'+cfg['namespace']['inkscape']+'}groupmode')
-                if refdef is not None:
-                    footprint_layer.set('refdef', refdef)
-                    footprint_layer.set('type', 'pad_placement')
 
                 # set transform
                 footprint_layer.set('transform', transform)

File utils/extract.py

 from Point import Point
 
 
+
+
+
+def extract_from_svg(cfg):
+    """
+    Extract routing and footpring placement from generated SVG
+    """
+    
+    extract_routing(cfg)
+    extract_placement(cfg)
+
+    return
+
+
+
+
+def extract_placement(cfg):
+    """
+    Extract placement of fooprints. This will look at the placement of
+    the footprints' pads (only pads!), compare it to the placement of
+    the board's JSON file, and update the JSON file if there's a different
+    placement.
+    """
+
+    # open SVG file
+    input_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')
+    except IOError as e:
+        print "ERROR: can't open %s; has the board been created yet?" % input_file
+        print "I/O error({0}): {1}".format(e.errno, e.strerror)
+        raise
+
+    svg_in = et.ElementTree(file=input_file) 
+    input_file.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
+ 
+
+
+
 def extract_routing(cfg):
     """
     Extracts routing paths and vias from an input SVG file, and saves the data

File utils/footprint.py

                                                             refdef=refdef)
             pad_group[pcb_layer] = et.SubElement(footprint_svg_layers[pcb_layer]['copper']['pads']['layer'], 
                                                  'g', id='pads',
-                                                 style=utils.dict_to_style(cfg['layout_style']['copper']['pads']),
+                                                 style=utils.dict_to_style(cfg['layout_style']['copper']['pads'][pcb_layer]),
                                                  refdef=refdef)
 
         # the size of soldermask is the pad size multiplied by this scale factor
     # create SVG layer structure for foorprint
     footprint_svg_layers = svg.create_svg_layers(cfg, 
                                                  footprint,
-                                                 transform)
+                                                 transform,
+                                                 refdef)
 
 
     # place the footprint's pads    

File utils/svg.py

 
 
 
-#def create_svg_layers(top_layer, board_stackup, surface_layers, transform=None):
-def create_svg_layers(cfg, top_layer, transform=None):
+
+def create_svg_layers(cfg, top_layer, transform=None, refdef=None):
     """
     Creates a dictionary holding the SVG layers
     """
     for pcb_layer_name in reversed(utils.get_surface_layers(cfg)):
 
         # create SVG layer for PCB layer
+        layer_id = pcb_layer_name
         board_svg_layers[pcb_layer_name] = {}
         board_svg_layers[pcb_layer_name]['layer'] = create_svg_layer(cfg, top_layer, 
-                                                     pcb_layer_name,
-                                                     transform,
-                                                     None)
+                                                                     pcb_layer_name,
+                                                                     layer_id,
+                                                                     transform,
+                                                                     None,
+                                                                     refdef)
 
-        # create PCB sheets for that layer
+        # create the following PCB sheets for the PCB layer
         pcb_sheets = ['copper', 'silkscreen', 'soldermask', 'assembly']
-        for pcb_sheet in pcb_sheets:        
+        for pcb_sheet in pcb_sheets:
+
+            # define a layer id
+            layer_id = "%s_%s" % (pcb_layer_name, pcb_sheet)
+            if refdef is not None:
+                layer_id += "_%s" % refdef 
+
             style = utils.dict_to_style(cfg['layout_style'][pcb_sheet]['default'].get(pcb_layer_name))
             tmp = board_svg_layers[pcb_layer_name] 
             tmp[pcb_sheet] = {}
             tmp[pcb_sheet]['layer'] = create_svg_layer(cfg, tmp['layer'], 
                                                        pcb_sheet,
+                                                       layer_id,
                                                        None, 
-                                                       style)
+                                                       style,
+                                                       refdef)
+
+
 
         # instantiate sub-layers for 'copper' PCB layer
         tmp = board_svg_layers[pcb_layer_name]['copper']
 
-        # pads
-        style = utils.dict_to_style(cfg['layout_style']['copper'].get('pads'))
-        tmp['pads'] = {}
-        tmp['pads']['layer'] = create_svg_layer(cfg, tmp['layer'], 
-                                                'pads', 
-                                                None, 
-                                                style)
-        # routing
-        style = utils.dict_to_style(cfg['layout_style']['copper']['routing'].get(pcb_layer_name))
-        tmp['routing'] = {}
-        tmp['routing']['layer'] = create_svg_layer(cfg, tmp['layer'], 
-                                                   'routing', 
-                                                   None, 
-                                                   style)
-        # pours
-        style = utils.dict_to_style(cfg['layout_style']['copper']['pours'].get(pcb_layer_name))
-        tmp['pours'] = {}
-        tmp['pours']['layer'] = create_svg_layer(cfg, tmp['layer'], 
-                                                 'pours', 
-                                                 None, 
-                                                 style)
+
+        layer_names = ['pads', 'routing', 'pours']
+
+        for layer_name in layer_names:
+            # define a layer id
+            layer_id = "%s_%s" % (pcb_layer_name, layer_name)
+            if refdef is not None:
+                layer_id += "_%s" % refdef 
+            style = utils.dict_to_style(cfg['layout_style']['copper'][layer_name].get(pcb_layer_name))
+            tmp[layer_name] = {}
+            tmp[layer_name]['layer'] = create_svg_layer(cfg, 
+                                                        tmp['layer'], 
+                                                        layer_name,
+                                                        layer_id,
+                                                        None, 
+                                                        style,
+                                                        refdef)
+
 
 
     # create dimentions layer
-    svg_layer_name = 'dimensions'
-    style = utils.dict_to_style(cfg['layout_style']['dimensions'].get('default'))
-    board_svg_layers[svg_layer_name] = {}
-    board_svg_layers[svg_layer_name]['layer'] = create_svg_layer(cfg, top_layer, 
-                                                 svg_layer_name, 
-                                                 transform, 
-                                                 style)
+    layer_name = 'dimensions'
+    # define a layer id
+    layer_id = "%s" % (layer_name)
+    if refdef is not None:
+        layer_id += "_%s" % refdef 
+    style = utils.dict_to_style(cfg['layout_style'][layer_name].get('default'))
+    board_svg_layers[layer_name] = {}
+    board_svg_layers[layer_name]['layer'] = create_svg_layer(cfg, 
+                                                             top_layer, 
+                                                             layer_name,
+                                                             layer_id,
+                                                             transform, 
+                                                             style,
+                                                             refdef)
 
     # create sub layers for dimension layer
     parent_layer = 'dimensions'
-    svg_layers = ['outline', 'origin', 'measurements']
-    for svg_layer in svg_layers:
-        style = utils.dict_to_style(cfg['layout_style'][svg_layer_name].get('default'))
-        board_svg_layers[parent_layer][svg_layer] = {}
-        board_svg_layers[parent_layer][svg_layer]['layer'] = create_svg_layer(cfg, board_svg_layers[parent_layer]['layer'], 
-                                                     svg_layer, 
-                                                     None,
-                                                     style)    
+    layer_names = ['outline', 'origin', 'measurements']
+    style = utils.dict_to_style(cfg['layout_style'][parent_layer].get('default'))
+    for layer_name in layer_names:
+        # define a layer id
+        layer_id = "%s" % (layer_name)
+        if refdef is not None:
+            layer_id += "_%s" % refdef 
+        board_svg_layers[parent_layer][layer_name] = {}
+        board_svg_layers[parent_layer][layer_name]['layer'] = create_svg_layer(cfg,
+                                                                               board_svg_layers[parent_layer]['layer'], 
+                                                                               layer_name,
+                                                                               layer_id,
+                                                                               None,
+                                                                               style,
+                                                                               refdef)    
 
 
     # create drills layer
-    svg_layer_name = 'drills'
-    style = utils.dict_to_style(cfg['layout_style'][svg_layer_name].get('default'))
-    board_svg_layers[svg_layer_name] = {}
-    board_svg_layers[svg_layer_name]['layer'] = create_svg_layer(cfg, top_layer, svg_layer_name, transform, style)
+    layer_name = 'drills'
+    # define a layer id
+    layer_id = "%s" % (layer_name)
+    if refdef is not None:
+        layer_id += "_%s" % refdef 
+    style = utils.dict_to_style(cfg['layout_style'][layer_name].get('default'))
+    board_svg_layers[layer_name] = {}
+    board_svg_layers[layer_name]['layer'] = create_svg_layer(cfg, 
+                                                             top_layer, 
+                                                             layer_name,
+                                                             layer_id,
+                                                             transform, 
+                                                             style,
+                                                             refdef)
 
     # create drills layer
-    svg_layer_name = 'documentation'
-    style = utils.dict_to_style(cfg['layout_style'][svg_layer_name].get('default'))
-    board_svg_layers[svg_layer_name] = {}
-    board_svg_layers[svg_layer_name]['layer'] = create_svg_layer(cfg, top_layer, svg_layer_name, transform, style)
+    layer_name = 'documentation'
+    # define a layer id
+    layer_id = "%s" % (layer_name)
+    if refdef is not None:
+        layer_id += "_%s" % refdef 
+    style = utils.dict_to_style(cfg['layout_style'][layer_name].get('default'))
+    board_svg_layers[layer_name] = {}
+    board_svg_layers[layer_name]['layer'] = create_svg_layer(cfg, 
+                                                             top_layer, 
+                                                             layer_name,
+                                                             layer_id,
+                                                             transform, 
+                                                             style,
+                                                             refdef)
 
     return board_svg_layers
 
 
 
 
-def create_svg_layer(cfg, parent_layer, layer_name, transform=None, style=None):
+
+
+def create_svg_layer(cfg, parent_layer, layer_name, layer_id, transform=None, style=None, refdef=None):
     """
     Create and return a new layer 
     """
 
     new_layer = et.SubElement(parent_layer, 'g',
-                              id="%s_layer" % layer_name)
+                              id="%s" % layer_id)
     new_layer.set('{'+cfg['namespace']['inkscape']+'}groupmode', 'layer')
     new_layer.set('{'+cfg['namespace']['inkscape']+'}label', layer_name)
     if transform is not None:
         new_layer.set('transform', transform) 
     if style is not None:
         new_layer.set('style', style)
+    if refdef is not None:
+        new_layer.set('refdef', refdef)
    
     return new_layer