You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.5 KiB

10 years ago
  1. # This program is free software; you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation; either version 2 of the License, or
  4. # (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  14. # MA 02110-1301, USA.
  15. #
  16. from __future__ import division
  17. import pcbnew
  18. import FootprintWizardBase
  19. class FPC_FootprintWizard(FootprintWizardBase.FootprintWizard):
  20. def GetName(self):
  21. return "FPC (SMT connector)"
  22. def GetDescription(self):
  23. return "FPC (SMT connector) Footprint Wizard"
  24. def GetValue(self):
  25. pins = self.parameters["Pads"]["n"]
  26. return "FPC_%d" % pins
  27. def GenerateParameterList(self):
  28. self.AddParam( "Pads", "n", self.uInteger, 40 )
  29. self.AddParam( "Pads", "pitch", self.uMM, 0.5 )
  30. self.AddParam( "Pads", "width", self.uMM, 0.25 )
  31. self.AddParam( "Pads", "height", self.uMM, 1.6)
  32. self.AddParam( "Shield", "shield_to_pad", self.uMM, 1.6 )
  33. self.AddParam( "Shield", "from_top", self.uMM, 1.3 )
  34. self.AddParam( "Shield", "width", self.uMM, 1.5 )
  35. self.AddParam( "Shield", "height", self.uMM, 2 )
  36. # build a rectangular pad
  37. def smdRectPad(self,module,size,pos,name):
  38. pad = pcbnew.D_PAD(module)
  39. pad.SetSize(size)
  40. pad.SetShape(pcbnew.PAD_SHAPE_RECT)
  41. pad.SetAttribute(pcbnew.PAD_ATTRIB_SMD)
  42. pad.SetLayerSet( pad.SMDMask() )
  43. pad.SetPos0(pos)
  44. pad.SetPosition(pos)
  45. pad.SetName(name)
  46. return pad
  47. def CheckParameters(self):
  48. #TODO implement custom parameter checking
  49. pass
  50. def BuildThisFootprint(self):
  51. p = self.parameters
  52. pad_count = int(p["Pads"]["n"])
  53. pad_width = p["Pads"]["width"]
  54. pad_height = p["Pads"]["height"]
  55. pad_pitch = p["Pads"]["pitch"]
  56. shl_width = p["Shield"]["width"]
  57. shl_height = p["Shield"]["height"]
  58. shl_to_pad = p["Shield"]["shield_to_pad"]
  59. shl_from_top = p["Shield"]["from_top"]
  60. offsetX = pad_pitch * ( pad_count-1 ) / 2
  61. size_pad = pcbnew.wxSize( pad_width, pad_height )
  62. size_shld = pcbnew.wxSize(shl_width, shl_height)
  63. size_text = self.GetTextSize() # IPC nominal
  64. # Gives a position and size to ref and value texts:
  65. textposy = pad_height/2 + pcbnew.FromMM(1) + self.GetTextThickness()
  66. angle_degree = 0.0
  67. self.draw.Reference( 0, textposy, size_text, angle_degree )
  68. textposy = textposy + size_text + self.GetTextThickness()
  69. self.draw.Value( 0, textposy, size_text )
  70. # create a pad array and add it to the module
  71. for n in range ( 0, pad_count ):
  72. xpos = pad_pitch*n - offsetX
  73. pad = self.smdRectPad(self.module,size_pad, pcbnew.wxPoint(xpos,0),str(n+1))
  74. self.module.Add(pad)
  75. # Mechanical shield pads: left pad and right pad
  76. xpos = -shl_to_pad-offsetX
  77. pad_s0_pos = pcbnew.wxPoint(xpos,shl_from_top)
  78. pad_s0 = self.smdRectPad(self.module, size_shld, pad_s0_pos, "0")
  79. xpos = (pad_count-1) * pad_pitch+shl_to_pad - offsetX
  80. pad_s1_pos = pcbnew.wxPoint(xpos,shl_from_top)
  81. pad_s1 = self.smdRectPad(self.module, size_shld, pad_s1_pos, "0")
  82. self.module.Add(pad_s0)
  83. self.module.Add(pad_s1)
  84. # add footprint outline
  85. linewidth = self.draw.GetLineThickness()
  86. margin = linewidth
  87. # upper line
  88. posy = -pad_height/2 - linewidth/2 - margin
  89. xstart = - pad_pitch*0.5-offsetX
  90. xend = pad_pitch * pad_count + xstart;
  91. self.draw.Line( xstart, posy, xend, posy )
  92. # lower line
  93. posy = pad_height/2 + linewidth/2 + margin
  94. self.draw.Line(xstart, posy, xend, posy)
  95. # around left mechanical pad (the outline around right pad is mirrored/y axix)
  96. yend = pad_s0_pos.y + shl_height/2 + margin
  97. self.draw.Line(xstart, posy, xstart, yend)
  98. self.draw.Line(-xstart, posy, -xstart, yend)
  99. posy = yend
  100. xend = pad_s0_pos.x - (shl_width/2 + linewidth + margin*2)
  101. self.draw.Line(xstart, posy, xend, posy)
  102. # right pad side
  103. self.draw.Line(-xstart, posy, -xend, yend)
  104. # set SMD attribute
  105. self.module.SetAttributes(pcbnew.MOD_CMS)
  106. # vertical segment at left of the pad
  107. xstart = xend
  108. yend = posy - (shl_height + linewidth + margin*2)
  109. self.draw.Line(xstart, posy, xend, yend)
  110. # right pad side
  111. self.draw.Line(-xstart, posy, -xend, yend)
  112. # horizontal segment above the pad
  113. xstart = xend
  114. xend = - pad_pitch*0.5-offsetX
  115. posy = yend
  116. self.draw.Line(xstart, posy, xend, yend)
  117. # right pad side
  118. self.draw.Line(-xstart, posy,-xend, yend)
  119. # vertical segment above the pad
  120. xstart = xend
  121. yend = -pad_height/2 - linewidth/2 - margin
  122. self.draw.Line(xstart, posy, xend, yend)
  123. # right pad side
  124. self.draw.Line(-xstart, posy, -xend, yend)
  125. FPC_FootprintWizard().register()