Source

PCBmodE / utils / footlight.py

Full commit
#!/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"