Python fp wizards: fix a few issues in qrcode_footprint_wizard.py
Fixes: lp:1828744 https://bugs.launchpad.net/kicad/+bug/1828744
This commit is contained in:
parent
7a715904ad
commit
92ccb766ab
|
@ -29,8 +29,8 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
GetValue = lambda self: self.module.Value().GetText()
|
GetValue = lambda self: self.module.Value().GetText()
|
||||||
|
|
||||||
def GenerateParameterList(self):
|
def GenerateParameterList(self):
|
||||||
self.AddParam("Barcode", "Pixel Width", self.uMM, 0.5, min_value=0.4)
|
self.AddParam("Barcode", "Qr Pixel Width", self.uMM, 0.5, min_value=0.4)
|
||||||
self.AddParam("Barcode", "Border", self.uInteger, 0)
|
self.AddParam("Barcode", "Border Margin (Px)", self.uInteger, 0)
|
||||||
self.AddParam("Barcode", "Contents", self.uString, 'Example')
|
self.AddParam("Barcode", "Contents", self.uString, 'Example')
|
||||||
self.AddParam("Barcode", "Negative", self.uBool, False)
|
self.AddParam("Barcode", "Negative", self.uBool, False)
|
||||||
self.AddParam("Barcode", "Use SilkS layer", self.uBool, False)
|
self.AddParam("Barcode", "Use SilkS layer", self.uBool, False)
|
||||||
|
@ -43,16 +43,19 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
|
|
||||||
def CheckParameters(self):
|
def CheckParameters(self):
|
||||||
self.Barcode = str(self.parameters['Barcode']['Contents'])
|
self.Barcode = str(self.parameters['Barcode']['Contents'])
|
||||||
self.X = self.parameters['Barcode']['Pixel Width']
|
self.X = self.parameters['Barcode']['Qr Pixel Width']
|
||||||
self.negative = self.parameters['Barcode']['Negative']
|
self.negative = self.parameters['Barcode']['Negative']
|
||||||
self.UseSilkS = self.parameters['Barcode']['Use SilkS layer']
|
self.UseSilkS = self.parameters['Barcode']['Use SilkS layer']
|
||||||
self.UseCu = self.parameters['Barcode']['Use Cu layer']
|
self.UseCu = self.parameters['Barcode']['Use Cu layer']
|
||||||
self.border = int(self.parameters['Barcode']['Border'])
|
self.border = int(self.parameters['Barcode']['Border Margin (Px)'])
|
||||||
self.textHeight = int(self.parameters['Caption']['Height'])
|
self.textHeight = int(self.parameters['Caption']['Height'])
|
||||||
self.textThickness = int(self.parameters['Caption']['Thickness'])
|
self.textThickness = int(self.parameters['Caption']['Thickness'])
|
||||||
self.textWidth = int(self.parameters['Caption']['Width'])
|
self.textWidth = int(self.parameters['Caption']['Width'])
|
||||||
self.module.Value().SetText(str(self.Barcode))
|
self.module.Value().SetText(str(self.Barcode))
|
||||||
|
|
||||||
|
if self.border < 0:
|
||||||
|
self.border = 0
|
||||||
|
|
||||||
# Build Qrcode
|
# Build Qrcode
|
||||||
self.qr = qrcode.QRCode()
|
self.qr = qrcode.QRCode()
|
||||||
self.qr.setTypeNumber(4)
|
self.qr.setTypeNumber(4)
|
||||||
|
@ -61,7 +64,7 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
self.qr.addData(str(self.Barcode))
|
self.qr.addData(str(self.Barcode))
|
||||||
self.qr.make()
|
self.qr.make()
|
||||||
|
|
||||||
def drawSquareArea( self, layer, size, xposition, yposition):
|
def drawPixelSquareArea( self, layer, size, xposition, yposition):
|
||||||
# creates a EDGE_MODULE of polygon type. The polygon is a square
|
# creates a EDGE_MODULE of polygon type. The polygon is a square
|
||||||
polygon = pcbnew.EDGE_MODULE(self.module)
|
polygon = pcbnew.EDGE_MODULE(self.module)
|
||||||
polygon.SetShape(pcbnew.S_POLYGON)
|
polygon.SetShape(pcbnew.S_POLYGON)
|
||||||
|
@ -76,23 +79,24 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
return polygon
|
return polygon
|
||||||
|
|
||||||
|
|
||||||
def _drawPixel(self, xposition, yposition):
|
def _drawQrPixel(self, xposition, yposition):
|
||||||
# build a rectangular pad as a dot on copper layer,
|
# build a rectangular pad as a dot on copper layer,
|
||||||
# and a polygon (a square) on silkscreen
|
# and a polygon (a square) on silkscreen
|
||||||
if self.UseCu:
|
if self.UseCu:
|
||||||
pad = pcbnew.D_PAD(self.module)
|
pad = pcbnew.D_PAD(self.module)
|
||||||
pad.SetSize(pcbnew.wxSize(self.X, self.X))
|
pad.SetSize(pcbnew.wxSize(self.X, self.X))
|
||||||
pad.SetPosition(pcbnew.wxPoint(xposition,yposition))
|
pad_pos = pcbnew.wxPoint(xposition,yposition)
|
||||||
|
pad.SetPosition(pad_pos)
|
||||||
|
pad.SetPos0(pad_pos)
|
||||||
pad.SetShape(pcbnew.PAD_SHAPE_RECT)
|
pad.SetShape(pcbnew.PAD_SHAPE_RECT)
|
||||||
pad.SetAttribute(pcbnew.PAD_ATTRIB_SMD)
|
pad.SetAttribute(pcbnew.PAD_ATTRIB_SMD)
|
||||||
pad.SetName("")
|
pad.SetName("")
|
||||||
layerset = pcbnew.LSET()
|
layerset = pcbnew.LSET()
|
||||||
layerset.AddLayer(pcbnew.F_Cu)
|
layerset.AddLayer(pcbnew.F_Cu)
|
||||||
layerset.AddLayer(pcbnew.F_Mask)
|
|
||||||
pad.SetLayerSet( layerset )
|
pad.SetLayerSet( layerset )
|
||||||
self.module.Add(pad)
|
self.module.Add(pad)
|
||||||
if self.UseSilkS:
|
if self.UseSilkS:
|
||||||
polygon=self.drawSquareArea(pcbnew.F_SilkS, self.X, xposition, yposition)
|
polygon=self.drawPixelSquareArea(pcbnew.F_SilkS, self.X, xposition, yposition)
|
||||||
self.module.Add(polygon)
|
self.module.Add(polygon)
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,6 +106,7 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
sz = self.qr.modules.__len__() + (self.border * 2)
|
sz = self.qr.modules.__len__() + (self.border * 2)
|
||||||
arrayToDraw = [ [ 0 for a in range(sz) ] for b in range(sz) ]
|
arrayToDraw = [ [ 0 for a in range(sz) ] for b in range(sz) ]
|
||||||
lineposition = self.border
|
lineposition = self.border
|
||||||
|
|
||||||
for i in self.qr.modules:
|
for i in self.qr.modules:
|
||||||
columnposition = self.border
|
columnposition = self.border
|
||||||
for j in i:
|
for j in i:
|
||||||
|
@ -114,9 +119,12 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
|
|
||||||
# used many times...
|
# used many times...
|
||||||
half_number_of_elements = arrayToDraw.__len__() / 2
|
half_number_of_elements = arrayToDraw.__len__() / 2
|
||||||
|
area_width = arrayToDraw.__len__()*self.X + self.border*2
|
||||||
|
|
||||||
# Center position of QrCode
|
# Center position of QrCode
|
||||||
yposition = - int(half_number_of_elements * self.X)
|
yposition = - int(half_number_of_elements * self.X)
|
||||||
|
area_height = arrayToDraw.__len__()*self.X + self.border*2
|
||||||
|
|
||||||
for line in arrayToDraw:
|
for line in arrayToDraw:
|
||||||
xposition = - int(half_number_of_elements * self.X)
|
xposition = - int(half_number_of_elements * self.X)
|
||||||
for pixel in line:
|
for pixel in line:
|
||||||
|
@ -130,19 +138,40 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
|
||||||
# 1 | 1 | 0
|
# 1 | 1 | 0
|
||||||
# => Draw as Xor
|
# => Draw as Xor
|
||||||
if self.negative != pixel: # Xor...
|
if self.negative != pixel: # Xor...
|
||||||
self._drawPixel(xposition, yposition)
|
self._drawQrPixel(xposition, yposition)
|
||||||
xposition += self.X
|
xposition += self.X
|
||||||
yposition += self.X
|
yposition += self.X
|
||||||
#int((5 + half_number_of_elements) * self.X))
|
|
||||||
|
# Add value field
|
||||||
textPosition = int((self.textHeight) + ((1 + half_number_of_elements) * self.X))
|
textPosition = int((self.textHeight) + ((1 + half_number_of_elements) * self.X))
|
||||||
self.module.Value().SetPosition(pcbnew.wxPoint(0, - textPosition))
|
pos = pcbnew.wxPoint(0, - textPosition)
|
||||||
|
self.module.Value().SetPosition(pos)
|
||||||
|
self.module.Value().SetPos0(pos)
|
||||||
self.module.Value().SetTextHeight(self.textHeight)
|
self.module.Value().SetTextHeight(self.textHeight)
|
||||||
self.module.Value().SetTextWidth(self.textWidth)
|
self.module.Value().SetTextWidth(self.textWidth)
|
||||||
self.module.Value().SetThickness(self.textThickness)
|
self.module.Value().SetThickness(self.textThickness)
|
||||||
self.module.Reference().SetPosition(pcbnew.wxPoint(0, textPosition))
|
|
||||||
|
# Add Reference field
|
||||||
|
pos = pcbnew.wxPoint(0, textPosition)
|
||||||
|
self.module.Reference().SetPosition(pos)
|
||||||
|
self.module.Reference().SetPos0(pos)
|
||||||
self.module.Reference().SetTextHeight(self.textHeight)
|
self.module.Reference().SetTextHeight(self.textHeight)
|
||||||
self.module.Reference().SetTextWidth(self.textWidth)
|
self.module.Reference().SetTextWidth(self.textWidth)
|
||||||
self.module.Reference().SetThickness(self.textThickness)
|
self.module.Reference().SetThickness(self.textThickness)
|
||||||
self.module.Value().SetLayer(pcbnew.F_SilkS)
|
self.module.Value().SetLayer(pcbnew.F_SilkS)
|
||||||
|
|
||||||
|
#build the footprint courtyard
|
||||||
|
self.draw.SetLayer( pcbnew.F_CrtYd )
|
||||||
|
self.draw.SetLineThickness( pcbnew.FromMM( 0.05 ) ) #Default per KLC F5.1 as of 12/2018
|
||||||
|
cr_margin = pcbnew.FromMM( 0.1 )
|
||||||
|
self.draw.Box(0, 0, area_width + cr_margin*2, area_height + cr_margin*2)
|
||||||
|
|
||||||
|
#build the footprint solder mask: the solder mask covers all copper pads
|
||||||
|
if self.UseCu:
|
||||||
|
self.draw.SetLineThickness( 0 )
|
||||||
|
sm_margin = pcbnew.FromMM( 0.05 )
|
||||||
|
polygon=self.drawPixelSquareArea(pcbnew.F_Mask, area_width + sm_margin*2, 0, 0)
|
||||||
|
self.module.Add(polygon)
|
||||||
|
|
||||||
|
|
||||||
QRCodeWizard().register()
|
QRCodeWizard().register()
|
||||||
|
|
Loading…
Reference in New Issue