~cern-kicad/kicad/kicad-pns-tom

« back to all changes in this revision

Viewing changes to pcbnew/scripting/plugins/FPC_(SMD_type)_footprintwizard.py

  • Committer: Maciej Suminski
  • Date: 2013-08-02 13:57:24 UTC
  • mfrom: (4024.1.238 kicad)
  • mto: This revision was merged to the branch mainline in revision 4221.
  • Revision ID: maciej.suminski@cern.ch-20130802135724-gix6orezshkukodv
Upstream merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This python script wizard creates a FPC connector
 
2
# for Surface Mounted Technology
 
3
 
 
4
 
 
5
from pcbnew import *
 
6
 
 
7
class FPCFootprintWizard(FootprintWizardPlugin):
 
8
    def __init__(self):
 
9
        FootprintWizardPlugin.__init__(self)
 
10
        self.name = "FPC"
 
11
        self.description = "FPC (SMTechnology) Footprint Wizard"
 
12
        self.parameters = {
 
13
             "Pads":
 
14
                {"*n":40,           # not internal units preceded by "*"
 
15
                 "pitch":           FromMM(0.5),
 
16
                 "width":           FromMM(0.25),
 
17
                 "height":          FromMM(1.6)},
 
18
             "Shield":
 
19
                {"shield_to_pad":   FromMM(1.6),
 
20
                 "from_top":        FromMM(1.3),
 
21
                 "width":           FromMM(1.5),
 
22
                 "height":          FromMM(2)}
 
23
        }
 
24
 
 
25
        self.ClearErrors()
 
26
 
 
27
    # build a rectangular pad
 
28
    def smdRectPad(self,module,size,pos,name):
 
29
            pad = D_PAD(module)
 
30
            pad.SetSize(size)
 
31
            pad.SetShape(PAD_RECT)
 
32
            pad.SetAttribute(PAD_SMD)
 
33
            pad.SetLayerMask(PAD_SMD_DEFAULT_LAYERS)
 
34
            pad.SetPos0(pos)
 
35
            pad.SetPosition(pos)
 
36
            pad.SetPadName(name)
 
37
            return pad
 
38
 
 
39
    # This method checks the parameters provided to wizard and set errors
 
40
    def CheckParameters(self):
 
41
        p = self.parameters
 
42
        pads            = p["Pads"]["*n"]
 
43
        errors = ""
 
44
        if (pads<1):
 
45
            self.parameter_errors["Pads"]["n"]="Must be positive"
 
46
            errors +="Pads/n has wrong value, "
 
47
        p["Pads"]["n"] = int(pads)  # make sure it stays as int (default is float)
 
48
 
 
49
        pad_width       = p["Pads"]["width"]
 
50
        pad_height      = p["Pads"]["height"]
 
51
        pad_pitch       = p["Pads"]["pitch"]
 
52
        shl_width       = p["Shield"]["width"]
 
53
        shl_height      = p["Shield"]["height"]
 
54
        shl_to_pad      = p["Shield"]["shield_to_pad"]
 
55
        shl_from_top    = p["Shield"]["from_top"]
 
56
 
 
57
        return errors
 
58
 
 
59
 
 
60
    # build the footprint from parameters
 
61
    def BuildFootprint(self):
 
62
 
 
63
        print "parameters:",self.parameters
 
64
        #self.ClearErrors()
 
65
        #print "errors:",self.parameter_errors
 
66
 
 
67
        module = MODULE(None) # create a new module
 
68
        self.module = module
 
69
 
 
70
        p = self.parameters
 
71
        pads            = int(p["Pads"]["*n"])
 
72
        pad_width       = p["Pads"]["width"]
 
73
        pad_height      = p["Pads"]["height"]
 
74
        pad_pitch       = p["Pads"]["pitch"]
 
75
        shl_width       = p["Shield"]["width"]
 
76
        shl_height      = p["Shield"]["height"]
 
77
        shl_to_pad      = p["Shield"]["shield_to_pad"]
 
78
        shl_from_top    = p["Shield"]["from_top"]
 
79
 
 
80
        offsetX         = pad_pitch*(pads-1)/2
 
81
        size_pad = wxSize(pad_width,pad_height)
 
82
        size_shld = wxSize(shl_width,shl_height)
 
83
        size_text = wxSize( FromMM( 0.8), FromMM( 0.7) )
 
84
        textposy = pad_height/2 + FromMM(1)
 
85
 
 
86
        module.SetReference("FPC"+str(pads))   # give it a reference name
 
87
        module.Reference().SetPos0(wxPoint(0, textposy))
 
88
        module.Reference().SetTextPosition(module.Reference().GetPos0())
 
89
        module.Reference().SetSize( size_text )
 
90
 
 
91
        textposy = textposy + FromMM(1)
 
92
        module.SetValue("Val***")           # give it a default value
 
93
        module.Value().SetPos0( wxPoint(0, textposy) )
 
94
        module.Value().SetTextPosition(module.Value().GetPos0())
 
95
        module.Value().SetSize( size_text )
 
96
 
 
97
        module.SetLibRef("FPC"+str(pads))   #the name in library
 
98
 
 
99
        # create a pad array and add it to the module
 
100
        for n in range (0,pads):
 
101
            xpos = pad_pitch*n - offsetX
 
102
            pad = self.smdRectPad(module,size_pad,wxPoint(xpos,0),str(n+1))
 
103
            module.Add(pad)
 
104
 
 
105
 
 
106
        xpos = -shl_to_pad-offsetX
 
107
        pad_s0 = self.smdRectPad(module, size_shld, wxPoint(xpos,shl_from_top), "0")
 
108
        xpos = (pads-1)*pad_pitch+shl_to_pad-offsetX
 
109
        pad_s1 = self.smdRectPad(module, size_shld, wxPoint(xpos,shl_from_top), "0")
 
110
 
 
111
        module.Add(pad_s0)
 
112
        module.Add(pad_s1)
 
113
 
 
114
        #add outline
 
115
        outline = EDGE_MODULE(module)
 
116
        width = FromMM(0.2)
 
117
        posy = -pad_height/2 - width/2 -FromMM(0.2)
 
118
        outline.SetStartEnd(wxPoint(pad_pitch * pads - pad_pitch*0.5-offsetX, posy),
 
119
                            wxPoint( - pad_pitch*0.5-offsetX, posy))
 
120
        outline.SetWidth(width)
 
121
        outline.SetLayer(SILKSCREEN_N_FRONT)    #default: not needed
 
122
        outline.SetShape(S_SEGMENT)
 
123
        module.Add(outline)
 
124
 
 
125
        outline1 = EDGE_MODULE(module)
 
126
        outline1.Copy(outline)                  #copy all settings from outline
 
127
        posy = pad_height/2 + width/2 +FromMM(0.2)
 
128
        outline1.SetStartEnd(wxPoint(pad_pitch * pads - pad_pitch*0.5-offsetX, posy),
 
129
                            wxPoint( - pad_pitch*0.5-offsetX, posy))
 
130
        module.Add(outline1)
 
131
 
 
132
 
 
133
# create our footprint wizard
 
134
fpc_wizard = FPCFootprintWizard()
 
135
 
 
136
# register it into pcbnew
 
137
fpc_wizard.register()