1. boldport
  2. Untitled project
  3. PCBmodE

Source

PCBmodE / 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. 'n' and 'm' are the starting positions for the first pin on each
    edge.
    
    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
        m = (width_pin_c2c/2)

        # if number of pins is even, subtract pitch/2 
        if (pins_on_edge % 2 == 0):
            n -= pitch / 2
        
        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

        # apply unique pad for pin 1, if defined
        if pad_for_pin_1 is not None:
            pins['1']['layout']['pad'] = pad_for_pin_1

    else:
        print "ERROR: unsupported package type"


    return pins