#!/usr/bin/perl

# Copyright (C) 2005 John C. Luciani Jr.

# This program may be distributed or modified under the terms of
# version 0.2 of the No-Fee Software License published by
# John C. Luciani Jr.

# Creates the PCB elements specified in the DATA section.  The
# footprints are for the SMD packages 0402, 0603, 0805, 1206, 1210,
# 2010, 2512, 0402, 0504, 0603, 0805, 1206, 1210, 1812, 1825

use strict;
use warnings;

use Pcb_9;

my $Pcb = Pcb_9 -> new(debug => 1);

my @Fields = qw(land_pattern_length  land_row_distance 
		land_width   	     land_length 
		land_row_centers     grid);

while (<DATA>) {
    s/\#.*//; # Remove comments
    s/^\s*//; # Remove leading spaces
    s/\s*$//; # Revove trailing spaces
    next unless length; # Skip empty lines
    my ($type, @values) = split /\s*\|\s*/;

    # hash for each footprint

    my %f = map { $_ => shift(@values) } @Fields;

    $Pcb -> element_begin(description => 'SMD',
			  output_file => "tmp/$type",
			  dim   => 'mm');

    my $x = -$f{land_row_centers} / 2;
    foreach my $pin_num (1..2) {
	$Pcb -> element_add_pad_rectangle(width => $f{land_width},
					  length=> $f{land_length},
					  x => $x,
					  y => 0,
					  name => 'input',
					  mask => 0.254,
					  clearance => 0.254,
					  pin_number => $pin_num);
	$x += $f{land_row_centers};
    }

    # Draw a silkscreen rectangle around the component.  A silkscreen
    # specification that all PCB vendors should be able to meet is
    # 10mil line width and 10mil spacing. The silkscreen line width
    # defaults to 10mils. To achieve the proper spacing we add 
    # 30mils (0.762mm) to the maximum extents of the copper pads 
    # (10mils on either side of the copper and 2*5 mils for the 
    # silkscreen line).

    my $length = $f{land_pattern_length} + 0.762;
    my $width  = $f{land_width} + 0.762;

    $Pcb -> element_add_rectangle(width => $width,
				  length=> $length,
				  x => 0,
				  y => 0);

    # Place the refdes slightly (0.5mm) above the upper left corner of
    # the outline rectangle.

    $Pcb -> element_set_text_xy(x => -$length/2,
				y => -$width/2 - 0.5);

    $Pcb -> element_output();

}


__DATA__

# type   package name
#  Z     overall length of land pattern
#  G     distance between land rows 
#  X     land width 
#  Y     land length
#  C     center-to-center spacing between land rows
#  Grid  number of 0.5mm by 0.5mm elements 

# type     Z        G       X         Y        C     Grid

 0402 |   2.20 |   0.40 |   0.70 |   0.90 |   1.30 | 2x6
 0504 |   2.40 |   0.40 |   1.30 |   1.00 |   1.40 | 4x6
 0603 |   2.80 |   0.60 |   1.00 |   1.10 |   1.70 | 4x6
 0805 |   3.20 |   0.60 |   1.50 |   1.30 |   1.90 | 4x8
 1206 |   4.40 |   1.20 |   1.80 |   1.60 |   2.80 | 4x10
 1210 |   4.40 |   1.20 |   2.70 |   1.60 |   2.80 | 6x10
 1812 |   5.80 |   2.00 |   3.40 |   1.90 |   3.90 | 8x12
 1825 |   5.80 |   2.00 |   6.80 |   1.90 |   3.90 | 14x12
 2010 |   6.20 |   2.60 |   2.70 |   1.80 |   4.40 | 6x14
 2512 |   7.40 |   3.80 |   3.20 |   1.80 |   5.60 | 8x16
