#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#

from __future__ import division
import pcbnew

import HelpfulFootprintWizardPlugin
import PadArray as PA


class SOLDERWizard(HelpfulFootprintWizardPlugin.HelpfulFootprintWizardPlugin):

    def GetName(self):
        return "SOLDER"

    def GetDescription(self):
        return "Solder Pad Footprint Wizard v1.0"

    def GenerateParameterList(self):
        self.AddParam("Pads", "n", self.uNatural, 3)
        self.AddParam("Pads", "pad pitch", self.uMM, 2.54)
        self.AddParam("Pads", "pad width", self.uMM, 1.5)
        self.AddParam("Pads", "pad length", self.uMM, 2)
        self.AddParam("Pads", "drill", self.uMM, 0.9)
        self.AddParam("Pads", "drill relief", self.uMM, 1.5)
        self.AddParam("Pads", "relief offset", self.uMM, 5)        

    def CheckParameters(self):
        self.CheckParamInt("Pads", "*n")

    def GetValue(self):
        return "SDR %d" % self.parameters["Pads"]["*n"]

    def BuildThisFootprint(self):
        pads = self.parameters["Pads"]        
        pad_pitch = pads["pad pitch"]
        pad_length = pads["pad length"]
        pad_width = pads["pad width"]
        drill = pads["drill"]
        relief_drill = pads["drill relief"]
        relief_offset = pads["relief offset"]
        pad_num = pads["*n"]
        first_pad = PA.PadMaker(self.module).THPad(pad_length, pad_width, drill, pcbnew.PAD_RECT)
        normal_pad = PA.PadMaker(self.module).THPad(pad_length, pad_width, drill, pcbnew.PAD_OVAL) 
        relief_pad = PA.PadMaker(self.module).NPTHRoundPad(relief_drill)
        pin1Pos = pcbnew.wxPoint(0, 0)
        array = PA.PadLineArray(normal_pad, pad_num, pad_pitch, False, pin1Pos)
        array.SetFirstPadInArray(1)
        array.SetFirstPadType(first_pad)
        array.AddPadsToModule(self.draw)  
        pin1Pos = pcbnew.wxPoint(0, relief_offset)
        array_relief = PA.PadLineArray(relief_pad, pad_num, pad_pitch, False, pin1Pos)
        array_relief.SetFirstPadInArray(1)
        array_relief.AddPadsToModule(self.draw)          
        text_size = pcbnew.FromMM(1.2) 
        text_offset = text_size + pad_length / 2
        self.draw.Value(0, -text_offset, text_size)
        self.draw.Reference(0, relief_drill / 2 + relief_offset + text_size, text_size)

SOLDERWizard().register()
