Commits

saar drimer  committed 094601d

initial commit of footprint wizard

  • Participants
  • Parent commits 0b95efe

Comments (0)

Files changed (3)

File utils/board.py

         silkscreen_outline_place = True
         silkscreen_refdef_place = True
         assembly_place = True
+        use_prototype = False
 
         # check for silkscreen refdef location override 
         silkscreen_refdef_location = component.get('silkscreen_refdef_location')
         if component.get('place_assembly') in ['no']:
             assembly_place = False
 
+        if component.get('use_prototype') in ['yes', 'true', 'True']:
+            use_prototype = True
+
         
         # get the name of the footprint
         footprint_name = component.get('footprint')
                                                               silkscreen_refdef_place,
                                                               assembly_place,
                                                               silkscreen_refdef_location,
-                                                              silkscreen_refdef_rotate
+                                                              silkscreen_refdef_rotate,
+                                                              use_prototype
                                                               )
 
 

File utils/footlight.py

+#!/usr/bin/python
+
+#   Copyright 2013 Boldport Limited
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+import os
+import re
+import json
+from lxml import etree as et
+
+# pcbmode modules
+import svg 
+import utils
+import place
+from Point import Point
+
+
+
+def process_footprint_prototype(cfg, part):
+    """
+    Process the footprints prototype and return the "pins" part of the footprint
+    definition.
+    
+    Package type options:
+      square_with_edge_pins
+
+    Pin 1 position options:
+      left_edge_top
+
+    Pin direction options:
+      counter_clockwise
+    """
+
+    proto = part['prototype']
+
+    # get prototype parameters 
+    package_type = proto.get('type')
+    pitch = float(proto.get('pitch'))
+    pad = proto.get('pad')
+    pad_for_pin_1 = proto.get('pad_for_pin_1') or pad 
+    width_pin_c2c = float(proto.get('width_pin_c2c'))
+    pin_1_position = proto.get('pin_1_position') or "left_edge_top"
+    number_of_pins = proto.get('number_of_pins')
+    direction = proto.get('direction') or "counter_clockwise"
+
+    pins = {}
+
+    # process different package types
+    if package_type == 'square_with_edge_pins':
+        pins_on_edge = number_of_pins / 4
+        n = (pins_on_edge / 2) * pitch
+        if (pins_on_edge % 2 == 0):
+            start_coord_y -= pitch / 2
+        m = (width_pin_c2c/2)
+
+        #m = start_coord_x
+        #n = start_coord_y
+        start_coords = [Point(-m, n), 
+                        Point(-n, -m), 
+                        Point(m, -n), 
+                        Point(n, m)]
+        
+        angle = 0
+        for i in range (0, 4):
+            for j in range(i*pins_on_edge, (i+1)*pins_on_edge):
+                index = "%s" % str(j+1)
+                pins[index] = {}
+                pins[index]['layout'] = {}
+                layout = pins[index]['layout']
+
+                # TODO: clean up this ugly hack ;)
+                if i == 0:
+                    layout['location'] = [-m, n-j*pitch%pins_on_edge]
+                elif i == 1:
+                    layout['location'] = [-n+j%pins_on_edge*pitch, -m]
+                elif i == 2:
+                    layout['location'] = [m, -n+j%pins_on_edge*pitch]
+                elif i == 3:
+                    layout['location'] = [n-j%pins_on_edge*pitch, m]
+                layout['rotate'] = angle
+                layout['pad'] = pad
+            angle += 90
+
+        if pad_for_pin_1 is not None:
+            pins['1']['layout']['pad'] = pad_for_pin_1
+
+        print pins
+        return pins
+
+
+    else:
+        print "ERROR: unsupported package type"
+
+

File utils/footprint.py

 import svg 
 import utils
 import place
+import footlight
 from Point import Point
 
 
                      silkscreen_refdef_place=True,
                      assembly_place=True, 
                      silkscreen_refdef_location=None,
-                     silkscreen_refdef_rotate=0):
+                     silkscreen_refdef_rotate=0,
+                     use_prototype=False):
 
 
 
                                   cfg['pcbmode']['locations']['build'], 
                                   'footprints')
 
-
+    # open footprint file
     filename_in = os.path.join(cfg['base_dir'], 
                                cfg['pcbmode']['locations']['parts'], 
                                footprint_name + '.json')
     filename_out = os.path.join(footprint_path, "%s_%s.svg" % (footprint_name, refdef))
 
-
     part = utils.get_json_data_from_file(filename_in)
 
+    # First, process prototype information if asked and prototype exists
+    prototype = part.get('prototype')
+    if (use_prototype is True) and (prototype is not None):
+        part['pins'] = footlight.process_footprint_prototype(cfg, part)
+
+    # TODO: better to automatically measure this dimension, although
+    #       at the moment these figures aren't used anywhere 
     fp_width = float(part['meta']['svg_width'])
     fp_height = float(part['meta']['svg_height'])
 
-    # create an SVG XML element 
+    # create an SVG XML element
     footprint = et.Element('svg', 
                            width=str(fp_width),
                            height=str(fp_height),