2021-10-22 08:03:49 +00:00
|
|
|
#
|
|
|
|
# This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
#
|
2014-04-23 16:36:31 +00:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
from __future__ import division
|
2014-04-23 16:36:31 +00:00
|
|
|
import pcbnew
|
2014-09-14 16:29:10 +00:00
|
|
|
import math
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
|
2017-01-03 15:01:47 +00:00
|
|
|
class FootprintWizard(pcbnew.FootprintWizardPlugin):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
A class to simplify many aspects of footprint creation, leaving only
|
2021-10-22 08:03:49 +00:00
|
|
|
the footprint specific routines to the wizards themselves.
|
2017-01-03 15:01:47 +00:00
|
|
|
|
2018-06-01 12:11:03 +00:00
|
|
|
Inherit this class to make a new wizard.
|
2017-01-03 15:01:47 +00:00
|
|
|
|
2018-06-01 12:11:03 +00:00
|
|
|
Provides simplified access to helpers like drawing functions, a transform
|
|
|
|
matrix stack and simple parameter checking.
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
Generally, you need to implement:
|
|
|
|
GetValue()
|
|
|
|
GenerateParameterList()
|
|
|
|
CheckParameters()
|
|
|
|
BuildThisFootprint()
|
|
|
|
GetName()
|
|
|
|
GetDescription()
|
|
|
|
"""
|
|
|
|
|
2018-06-01 12:11:03 +00:00
|
|
|
# Copy units from pcbnew
|
|
|
|
uMM = pcbnew.uMM
|
|
|
|
uMils = pcbnew.uMils
|
|
|
|
uFloat = pcbnew.uFloat
|
|
|
|
uInteger = pcbnew.uInteger
|
|
|
|
uBool = pcbnew.uBool
|
|
|
|
uRadians = pcbnew.uRadians
|
|
|
|
uDegrees = pcbnew.uDegrees
|
|
|
|
uPercent = pcbnew.uPercent
|
|
|
|
uString = pcbnew.uString
|
|
|
|
|
2017-01-03 15:01:47 +00:00
|
|
|
def __init__(self):
|
|
|
|
pcbnew.FootprintWizardPlugin.__init__(self)
|
|
|
|
self.GenerateParameterList()
|
|
|
|
|
|
|
|
def GetName(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2018-06-01 11:19:31 +00:00
|
|
|
Return the name of the footprint wizard
|
2017-01-03 15:01:47 +00:00
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def GetDescription(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2017-01-03 15:01:47 +00:00
|
|
|
Return the footprint wizard description
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def GetValue(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2017-01-03 15:01:47 +00:00
|
|
|
Return the value (name) of the generated footprint
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def GenerateParameterList(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2017-01-03 15:01:47 +00:00
|
|
|
Footprint parameter specification is done here
|
|
|
|
"""
|
2018-06-01 11:19:31 +00:00
|
|
|
raise NotImplementedError
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
def CheckParameters(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2017-01-03 15:01:47 +00:00
|
|
|
Any custom parameter checking should be performed here
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def BuildThisFootprint(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2017-01-03 15:01:47 +00:00
|
|
|
Draw the footprint.
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
This is specific to each footprint class, you need to implement
|
2017-01-03 15:01:47 +00:00
|
|
|
this to draw what you want
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
# Do not override this method!
|
2018-06-01 11:19:31 +00:00
|
|
|
def BuildFootprint(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2018-06-01 11:19:31 +00:00
|
|
|
Actually make the footprint. We defer all but the set-up to
|
2017-01-03 15:01:47 +00:00
|
|
|
the implementing class
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.buildmessages = ""
|
2020-11-13 23:10:45 +00:00
|
|
|
self.module = pcbnew.FOOTPRINT(None) # create a new module
|
2017-01-03 15:01:47 +00:00
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
# Perform default checks on all parameters
|
2017-01-03 15:01:47 +00:00
|
|
|
for p in self.params:
|
|
|
|
p.ClearErrors()
|
2018-06-01 11:19:31 +00:00
|
|
|
p.Check() # use defaults
|
2017-01-03 15:01:47 +00:00
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
self.CheckParameters() # User error checks
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
if self.AnyErrors(): # Errors were detected!
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
self.buildmessages = ("Cannot build footprint: "
|
|
|
|
"Parameters have errors:\n")
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
for p in self.params:
|
|
|
|
if len(p.error_list) > 0:
|
2018-06-01 11:19:31 +00:00
|
|
|
self.buildmessages += "['{page}']['{name}']:\n".format(
|
|
|
|
page=p.page, name=p.name)
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
for error in p.error_list:
|
|
|
|
self.buildmessages += "\t" + error + "\n"
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
self.buildmessages = (
|
|
|
|
"Building new {name} footprint with the following parameters:\n"
|
|
|
|
.format(name=self.name))
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
self.buildmessages += self.Show()
|
|
|
|
|
|
|
|
self.draw = FootprintWizardDrawingAids(
|
|
|
|
self.module)
|
|
|
|
|
|
|
|
self.module.SetValue(self.GetValue())
|
|
|
|
self.module.SetReference("%s**" % self.GetReferencePrefix())
|
|
|
|
|
2018-07-31 16:45:56 +00:00
|
|
|
fpid = pcbnew.LIB_ID("", self.module.GetValue()) # the lib name (empty) and the name in library
|
2017-01-03 15:01:47 +00:00
|
|
|
self.module.SetFPID(fpid)
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
self.SetModule3DModel() # add a 3D module if specified
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
thick = self.GetTextThickness()
|
|
|
|
|
2020-04-19 00:36:52 +00:00
|
|
|
self.module.Reference().SetTextThickness(thick)
|
|
|
|
self.module.Value().SetTextThickness(thick)
|
2017-01-03 15:01:47 +00:00
|
|
|
|
|
|
|
self.BuildThisFootprint() # implementer's build function
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def SetModule3DModel(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
If your plug-in sets a 3D model, override this function
|
|
|
|
"""
|
2017-01-03 15:01:47 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
def GetTextSize(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
Get the default text size for the footprint. Override to change it.
|
|
|
|
|
|
|
|
Defaults to IPC nominal of 1.0mm
|
2017-01-03 15:01:47 +00:00
|
|
|
"""
|
|
|
|
return pcbnew.FromMM(1.0)
|
|
|
|
|
|
|
|
def GetTextThickness(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2017-01-03 15:01:47 +00:00
|
|
|
Thicker than IPC guidelines (10% of text height = 0.12mm)
|
|
|
|
as 5 wires/mm is a common silk screen limitation
|
|
|
|
"""
|
|
|
|
return pcbnew.FromMM(0.15)
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
|
2014-04-23 16:36:31 +00:00
|
|
|
class FootprintWizardDrawingAids:
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-04-23 16:36:31 +00:00
|
|
|
Collection of handy functions to simplify drawing shapes from within
|
|
|
|
footprint wizards
|
|
|
|
|
|
|
|
A "drawing context" is provided which can be used to set and retain
|
2018-06-01 12:11:03 +00:00
|
|
|
settings such as line thickness and layer. The DC also contains a
|
|
|
|
"transform stack", which allows easy positioning and transforming of
|
|
|
|
drawn elements without lots of geometric book-keeping.
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
# directions (in degrees, compass-like)
|
|
|
|
dirN = 0
|
|
|
|
dirNE = 45
|
|
|
|
dirE = 90
|
|
|
|
dirSE = 135
|
|
|
|
dirS = 180
|
|
|
|
dirSW = 225
|
|
|
|
dirW = 270
|
|
|
|
dirNW = 315
|
|
|
|
|
2018-06-01 12:11:03 +00:00
|
|
|
# Flip constants
|
2018-06-01 11:19:31 +00:00
|
|
|
flipNone = 0 # no flip transform
|
|
|
|
flipX = 1 # flip X values, i.e. about the Y-axis
|
|
|
|
flipY = 2 # flip Y values, i.e. about the X-axis
|
|
|
|
flipBoth = 3 # flip X and Y values, equivalent to a 180-degree rotation
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
xfrmIDENTITY = [1, 0, 0, 0, 1, 0] # no transform
|
|
|
|
|
2015-10-29 17:35:52 +00:00
|
|
|
# these values come from our KiCad Library Convention 0.11
|
|
|
|
defaultLineThickness = pcbnew.FromMM(0.15)
|
|
|
|
|
|
|
|
def DefaultGraphicLayer(self):
|
|
|
|
return pcbnew.F_SilkS
|
|
|
|
|
|
|
|
def DefaultTextValueLayer(self):
|
|
|
|
return pcbnew.F_Fab
|
|
|
|
|
2014-04-23 16:36:31 +00:00
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
2014-09-14 16:29:10 +00:00
|
|
|
# drawing context defaults
|
2014-04-23 16:36:31 +00:00
|
|
|
self.dc = {
|
2015-10-29 17:35:52 +00:00
|
|
|
'layer': self.DefaultGraphicLayer(),
|
|
|
|
'lineThickness': self.defaultLineThickness,
|
2014-09-14 16:29:10 +00:00
|
|
|
'transforms': [],
|
|
|
|
'transform': self.xfrmIDENTITY
|
2014-04-23 16:36:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
def PushTransform(self, mat):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Add a transform to the top of the stack and recompute the
|
|
|
|
overall transform
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param mat: the transform matrix to add to the stack
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
self.dc['transforms'].append(mat)
|
|
|
|
self.RecomputeTransforms()
|
|
|
|
|
|
|
|
def PopTransform(self, num=1):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Remove a transform from the top of the stack and recompute the
|
|
|
|
overall transform
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param num: the number of transforms to pop from the stack.
|
|
|
|
@return the last popped transform
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
for i in range(num):
|
|
|
|
mat = self.dc['transforms'].pop()
|
|
|
|
self.RecomputeTransforms()
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def ResetTransform(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
Reset the transform stack to the identity matrix.
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
self.dc['transforms'] = []
|
|
|
|
self.RecomputeTransforms()
|
|
|
|
|
|
|
|
def _ComposeMatricesWithIdentity(self, mats):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Compose a sequence of matrices together by sequential
|
2018-06-01 12:11:03 +00:00
|
|
|
pre-multiplication with the identity matrix.
|
|
|
|
|
|
|
|
@param mats: list of matrices to compose
|
|
|
|
@return: the composed transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
x = self.xfrmIDENTITY
|
|
|
|
|
|
|
|
for mat in mats:
|
2018-06-01 11:19:31 +00:00
|
|
|
# Pre-compose with each transform in turn
|
2014-09-14 16:29:10 +00:00
|
|
|
x = [
|
|
|
|
x[0] * mat[0] + x[1] * mat[3],
|
|
|
|
x[0] * mat[1] + x[1] * mat[4],
|
|
|
|
x[0] * mat[2] + x[1] * mat[5] + x[2],
|
|
|
|
x[3] * mat[0] + x[4] * mat[3],
|
|
|
|
x[3] * mat[1] + x[4] * mat[4],
|
|
|
|
x[3] * mat[2] + x[4] * mat[5] + x[5]]
|
|
|
|
|
|
|
|
return x
|
|
|
|
|
|
|
|
def RecomputeTransforms(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Re-compute the transform stack into a single transform and
|
|
|
|
store in the DC
|
|
|
|
"""
|
|
|
|
self.dc['transform'] = self._ComposeMatricesWithIdentity(
|
|
|
|
self.dc['transforms'])
|
|
|
|
|
|
|
|
def TransformTranslate(self, x, y, push=True):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2018-06-01 11:19:31 +00:00
|
|
|
Set up and return a transform matrix representing a translation
|
2014-09-14 16:29:10 +00:00
|
|
|
optionally pushing onto the stack
|
|
|
|
|
|
|
|
( 1 0 x )
|
|
|
|
( 0 1 y )
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param x: translation in x-direction
|
|
|
|
@param y: translation in y-direction
|
|
|
|
@param push: add this transform to the current stack
|
|
|
|
@return the generated transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
mat = [1, 0, x, 0, 1, y]
|
|
|
|
|
|
|
|
if push:
|
|
|
|
self.PushTransform(mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def TransformFlipOrigin(self, flip, push=True):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Set up and return a transform matrix representing a horizontal,
|
|
|
|
vertical or both flip about the origin
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param flip: one of flipNone, flipX, flipY, flipBoth
|
|
|
|
@param push: add this transform to the current stack
|
|
|
|
@return the generated transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
mat = None
|
|
|
|
if flip == self.flipX:
|
|
|
|
mat = [-1, 0, 0, 0, 1, 0]
|
|
|
|
elif flip == self.flipY:
|
|
|
|
mat = [1, 0, 0, 0, -1, 0]
|
|
|
|
elif flip == self.flipBoth:
|
|
|
|
mat = [-1, 0, 0, 0, -1, 0]
|
|
|
|
elif flip == self.flipNone:
|
|
|
|
mat = self.xfrmIDENTITY
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
if push:
|
|
|
|
self.PushTransform(mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def TransformFlip(self, x, y, flip=flipNone, push=True):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Set up and return a transform matrix representing a horizontal,
|
|
|
|
vertical or both flip about a point (x,y)
|
|
|
|
|
|
|
|
This is performed by a translate-to-origin, flip, translate-
|
2018-06-01 12:11:03 +00:00
|
|
|
back sequence.
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the flip point
|
|
|
|
@param y: the y coordinate of the flip point
|
2018-06-01 12:11:03 +00:00
|
|
|
@param flip: one of flipNone, flipX, flipY, flipBoth
|
|
|
|
@param push: add this transform to the current stack
|
|
|
|
@return the generated transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
mats = [self.TransformTranslate(x, y, push=False),
|
|
|
|
self.TransformFlipOrigin(flip, push=False),
|
|
|
|
self.TransformTranslate(-x, -y, push=False)]
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
# Distil into a single matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
mat = self._ComposeMatricesWithIdentity(mats)
|
|
|
|
|
|
|
|
if push:
|
|
|
|
self.PushTransform(mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def TransformRotationOrigin(self, rot, push=True):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Set up and return a transform matrix representing a rotation
|
|
|
|
about the origin, and optionally push onto the stack
|
|
|
|
|
|
|
|
( cos(t) -sin(t) 0 )
|
|
|
|
( sin(t) cos(t) 0 )
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param rot: the rotation angle in degrees
|
|
|
|
@param push: add this transform to the current stack
|
|
|
|
@return the generated transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
rads = rot * math.pi / 180
|
|
|
|
mat = [math.cos(rads), -math.sin(rads), 0,
|
|
|
|
math.sin(rads), math.cos(rads), 0]
|
|
|
|
|
|
|
|
if push:
|
|
|
|
self.PushTransform(mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def TransformRotation(self, x, y, rot, push=True):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Set up and return a transform matrix representing a rotation
|
2015-10-31 11:54:48 +00:00
|
|
|
about the point (x,y), and optionally push onto the stack
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
This is performed by a translate-to-origin, rotate, translate-
|
|
|
|
back sequence
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the rotation centre
|
|
|
|
@param y: the y coordinate of the rotation centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param rot: the rotation angle in degrees
|
|
|
|
@param push: add this transform to the current stack
|
|
|
|
@return the generated transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
mats = [self.TransformTranslate(x, y, push=False),
|
|
|
|
self.TransformRotationOrigin(rot, push=False),
|
|
|
|
self.TransformTranslate(-x, -y, push=False)]
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
# Distil into a single matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
mat = self._ComposeMatricesWithIdentity(mats)
|
|
|
|
|
|
|
|
if push:
|
|
|
|
self.PushTransform(mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def TransformScaleOrigin(self, sx, sy=None, push=True):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Set up and return a transform matrix representing a scale about
|
|
|
|
the origin, and optionally push onto the stack
|
|
|
|
|
|
|
|
( sx 0 0 )
|
|
|
|
( 0 sy 0 )
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param sx: the scale factor in the x direction
|
|
|
|
@param sy: the scale factor in the y direction
|
|
|
|
@param push: add this transform to the current stack
|
|
|
|
@return the generated transform matrix
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
if sy is None:
|
|
|
|
sy = sx
|
|
|
|
|
|
|
|
mat = [sx, 0, 0, 0, sy, 0]
|
|
|
|
|
|
|
|
if push:
|
|
|
|
self.PushTransform(mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
def TransformPoint(self, x, y, mat=None):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Return a point (x, y) transformed by the given matrix, or if
|
|
|
|
that is not given, the drawing context transform
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the point to transform
|
|
|
|
@param y: the y coordinate of the point to transform
|
2018-06-01 12:11:03 +00:00
|
|
|
@param mat: the transform matrix to use or None to use the current DC's
|
2022-01-03 10:43:15 +00:00
|
|
|
@return: the transformed point as a VECTOR2I
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
if not mat:
|
|
|
|
mat = self.dc['transform']
|
|
|
|
|
2022-01-03 10:43:15 +00:00
|
|
|
return pcbnew.VECTOR2I( (int)(x * mat[0] + y * mat[1] + mat[2]),
|
|
|
|
(int)(x * mat[3] + y * mat[4] + mat[5]) )
|
2014-09-14 16:29:10 +00:00
|
|
|
|
2016-02-11 15:02:37 +00:00
|
|
|
def SetLineThickness(self, lineThickness):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2016-02-11 15:02:37 +00:00
|
|
|
Set the current pen lineThickness used for subsequent drawing
|
|
|
|
operations
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param lineThickness: the new line thickness to set
|
2016-02-11 15:02:37 +00:00
|
|
|
"""
|
|
|
|
self.dc['lineThickness'] = lineThickness
|
|
|
|
|
2015-10-29 17:35:52 +00:00
|
|
|
def SetLineTickness(self, lineThickness):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2016-02-11 15:02:37 +00:00
|
|
|
Old version of SetLineThickness.
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
Does the same thing, but is only here for compatibility with old
|
2018-06-01 11:19:31 +00:00
|
|
|
scripts.
|
2015-10-29 17:35:52 +00:00
|
|
|
Set the current pen lineThickness used for subsequent drawing
|
2014-09-14 16:29:10 +00:00
|
|
|
operations
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param lineThickness: the new line thickness to set
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
2018-06-01 12:11:03 +00:00
|
|
|
self.SetLineThickness(lineThickness)
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2016-02-11 15:02:37 +00:00
|
|
|
def GetLineThickness(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2016-02-11 15:02:37 +00:00
|
|
|
Get the current drawing context line thickness
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
2015-10-29 17:35:52 +00:00
|
|
|
return self.dc['lineThickness']
|
2014-09-14 16:29:10 +00:00
|
|
|
|
2014-04-23 16:36:31 +00:00
|
|
|
def SetLayer(self, layer):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Set the current drawing layer, used for subsequent drawing
|
|
|
|
operations
|
|
|
|
"""
|
2014-04-23 16:36:31 +00:00
|
|
|
self.dc['layer'] = layer
|
|
|
|
|
2015-10-29 17:35:52 +00:00
|
|
|
def GetLayer(self):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
Return the current drawing layer, used for drawing operations
|
2015-10-29 17:35:52 +00:00
|
|
|
"""
|
|
|
|
return self.dc['layer']
|
|
|
|
|
2014-04-23 16:36:31 +00:00
|
|
|
def Line(self, x1, y1, x2, y2):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Draw a line from (x1, y1) to (x2, y2)
|
|
|
|
"""
|
2020-10-09 18:48:13 +00:00
|
|
|
outline = pcbnew.FP_SHAPE(self.module)
|
2016-02-11 15:02:37 +00:00
|
|
|
outline.SetWidth(self.GetLineThickness())
|
2015-10-29 17:35:52 +00:00
|
|
|
outline.SetLayer(self.GetLayer())
|
2014-04-23 16:36:31 +00:00
|
|
|
outline.SetShape(pcbnew.S_SEGMENT)
|
2014-09-14 16:29:10 +00:00
|
|
|
start = self.TransformPoint(x1, y1)
|
|
|
|
end = self.TransformPoint(x2, y2)
|
2014-04-23 16:36:31 +00:00
|
|
|
outline.SetStartEnd(start, end)
|
|
|
|
self.module.Add(outline)
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
def Circle(self, x, y, r, filled=False):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Draw a circle at (x,y) of radius r
|
2015-10-29 17:35:52 +00:00
|
|
|
If filled is true, the thickness and radius of the line will be set
|
2014-09-14 16:29:10 +00:00
|
|
|
such that the circle appears filled
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the arc centre
|
|
|
|
@param y: the y coordinate of the arc centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param r: the circle's radius
|
|
|
|
@param filled: True to draw a filled circle, False to use the current
|
|
|
|
DC line thickness
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
2017-01-03 15:01:47 +00:00
|
|
|
|
2020-10-09 18:48:13 +00:00
|
|
|
circle = pcbnew.FP_SHAPE(self.module)
|
2014-09-14 16:29:10 +00:00
|
|
|
start = self.TransformPoint(x, y)
|
|
|
|
|
|
|
|
if filled:
|
|
|
|
circle.SetWidth(r)
|
|
|
|
end = self.TransformPoint(x, y + r/2)
|
|
|
|
else:
|
2015-10-29 17:35:52 +00:00
|
|
|
circle.SetWidth(self.dc['lineThickness'])
|
2014-09-14 16:29:10 +00:00
|
|
|
end = self.TransformPoint(x, y + r)
|
|
|
|
|
|
|
|
circle.SetLayer(self.dc['layer'])
|
|
|
|
circle.SetShape(pcbnew.S_CIRCLE)
|
|
|
|
circle.SetStartEnd(start, end)
|
|
|
|
self.module.Add(circle)
|
|
|
|
|
2021-06-25 07:04:49 +00:00
|
|
|
def MyCmp(self, n1, n2):
|
|
|
|
"""
|
|
|
|
replace the cmp() of python2
|
|
|
|
"""
|
|
|
|
if n1 < n2:
|
|
|
|
return -1
|
|
|
|
if n1 > n2:
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2021-10-22 08:03:49 +00:00
|
|
|
def Arc(self, cx, cy, sx, sy, angle):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Draw an arc based on centre, start and angle
|
|
|
|
|
|
|
|
The transform matrix is applied
|
|
|
|
|
|
|
|
Note that this won't work properly if the result is not a
|
2018-06-01 11:19:31 +00:00
|
|
|
circular arc (e.g. a horizontal scale)
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param cx: the x coordinate of the arc centre
|
|
|
|
@param cy: the y coordinate of the arc centre
|
|
|
|
@param sx: the x coordinate of the arc start point
|
|
|
|
@param sy: the y coordinate of the arc start point
|
2021-10-22 08:03:49 +00:00
|
|
|
@param angle: the arc's central angle (in deci-degrees)
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
2021-10-22 08:03:49 +00:00
|
|
|
arc = pcbnew.FP_SHAPE(self.module)
|
|
|
|
arc.SetShape(pcbnew.SHAPE_T_ARC)
|
|
|
|
arc.SetWidth(self.dc['lineThickness'])
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
center = self.TransformPoint(cx, cy)
|
|
|
|
start = self.TransformPoint(sx, sy)
|
|
|
|
|
2021-10-22 08:03:49 +00:00
|
|
|
arc.SetLayer(self.dc['layer'])
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
# check if the angle needs to be reverse (a flip scaling)
|
2021-06-25 07:04:49 +00:00
|
|
|
if self.MyCmp(self.dc['transform'][0], 0) != self.MyCmp(self.dc['transform'][4], 0):
|
2021-10-22 08:03:49 +00:00
|
|
|
angle = -angle
|
2014-09-14 16:29:10 +00:00
|
|
|
|
2021-10-22 08:03:49 +00:00
|
|
|
arc.SetCenter(center)
|
|
|
|
arc.SetStart(start)
|
|
|
|
arc.SetArcAngleAndEnd(angle, True)
|
|
|
|
arc.SetLocalCoord()
|
|
|
|
self.module.Add(arc)
|
2014-09-14 16:29:10 +00:00
|
|
|
|
2014-04-23 16:36:31 +00:00
|
|
|
def HLine(self, x, y, l):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-04-23 16:36:31 +00:00
|
|
|
Draw a horizontal line from (x,y), rightwards
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: line start x coordinate
|
|
|
|
@param y: line start y coordinate
|
2018-06-01 12:11:03 +00:00
|
|
|
@param l: line length
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
|
|
|
self.Line(x, y, x + l, y)
|
|
|
|
|
|
|
|
def VLine(self, x, y, l):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-04-23 16:36:31 +00:00
|
|
|
Draw a vertical line from (x1,y1), downwards
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: line start x coordinate
|
|
|
|
@param y: line start y coordinate
|
2018-06-01 12:11:03 +00:00
|
|
|
@param l: line length
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
|
|
|
self.Line(x, y, x, y + l)
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
def Polyline(self, pts, mirrorX=None, mirrorY=None):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2018-06-01 11:19:31 +00:00
|
|
|
Draw a polyline, optionally mirroring around the given points
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param pts: list of polyline vertices (list of (x, y))
|
2021-06-09 19:32:58 +00:00
|
|
|
@param mirrorX: x coordinate of mirror point (None for no x-flip)
|
|
|
|
@param mirrorY: y coordinate of mirror point (None for no y-flip)
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def _PolyLineInternal(pts):
|
|
|
|
if len(pts) < 2:
|
|
|
|
return
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
for i in range(0, len(pts) - 1):
|
|
|
|
self.Line(pts[i][0], pts[i][1], pts[i+1][0], pts[i+1][1])
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2023-04-16 14:51:07 +00:00
|
|
|
if mirrorX is None and mirrorY is None:
|
|
|
|
_PolyLineInternal(pts) # original
|
2014-09-14 16:29:10 +00:00
|
|
|
|
2023-04-16 14:51:07 +00:00
|
|
|
elif mirrorX is not None and mirrorY is not None:
|
2017-01-03 15:01:47 +00:00
|
|
|
self.TransformFlip(mirrorX, mirrorY, self.flipBoth) # both
|
2014-09-14 16:29:10 +00:00
|
|
|
_PolyLineInternal(pts)
|
|
|
|
self.PopTransform()
|
|
|
|
|
2017-01-03 15:01:47 +00:00
|
|
|
elif mirrorX is not None:
|
|
|
|
self.TransformFlip(mirrorX, 0, self.flipX)
|
2014-09-14 16:29:10 +00:00
|
|
|
_PolyLineInternal(pts)
|
|
|
|
self.PopTransform()
|
|
|
|
|
2017-01-03 15:01:47 +00:00
|
|
|
elif mirrorY is not None:
|
|
|
|
self.TransformFlip(0, mirrorY, self.flipY)
|
2014-09-14 16:29:10 +00:00
|
|
|
_PolyLineInternal(pts)
|
|
|
|
self.PopTransform()
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
def Reference(self, x, y, size, orientation_degree=0):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-04-23 16:36:31 +00:00
|
|
|
Draw the module's reference as the given point.
|
|
|
|
|
|
|
|
The actual setting of the reference is not done in this drawing
|
|
|
|
aid - that is up to the wizard
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param x: the x position of the reference
|
|
|
|
@param y: the y position of the reference
|
|
|
|
@param size: the text size (in both directions)
|
|
|
|
@param orientation_degree: text orientation in degrees
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
|
|
|
|
2022-05-20 10:57:16 +00:00
|
|
|
text_size = pcbnew.VECTOR2I(size, size)
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
self.module.Reference().SetPos0(self.TransformPoint(x, y))
|
2017-01-26 19:19:20 +00:00
|
|
|
self.module.Reference().SetPosition(
|
2014-09-14 16:29:10 +00:00
|
|
|
self.module.Reference().GetPos0())
|
2017-01-26 19:19:20 +00:00
|
|
|
self.module.Reference().SetTextSize(text_size)
|
2022-01-28 16:02:13 +00:00
|
|
|
self.module.Reference().SetTextAngle( pcbnew.EDA_ANGLE( orientation_degree, pcbnew.DEGREES_T ) )
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
def Value(self, x, y, size, orientation_degree=0):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-04-23 16:36:31 +00:00
|
|
|
As for references, draw the module's value
|
2018-06-01 12:11:03 +00:00
|
|
|
|
|
|
|
@param x: the x position of the value
|
|
|
|
@param y: the y position of the value
|
|
|
|
@param size: the text size (in both directions)
|
|
|
|
@param orientation_degree: text orientation in degrees
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
2022-05-20 10:57:16 +00:00
|
|
|
text_size = pcbnew.VECTOR2I(size, size)
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
self.module.Value().SetPos0(self.TransformPoint(x, y))
|
2017-01-26 19:19:20 +00:00
|
|
|
self.module.Value().SetPosition(self.module.Value().GetPos0())
|
|
|
|
self.module.Value().SetTextSize(text_size)
|
2015-10-29 17:35:52 +00:00
|
|
|
self.module.Value().SetLayer(self.DefaultTextValueLayer())
|
2022-01-28 16:02:13 +00:00
|
|
|
self.module.Value().SetTextAngle( pcbnew.EDA_ANGLE( orientation_degree, pcbnew.DEGREES_T ) )
|
2014-04-23 16:36:31 +00:00
|
|
|
|
|
|
|
def Box(self, x, y, w, h):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-04-23 16:36:31 +00:00
|
|
|
Draw a rectangular box, centred at (x,y), with given width and
|
|
|
|
height
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the box's centre
|
|
|
|
@param y: the y coordinate of the box's centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param w: the width of the box
|
|
|
|
@param h: the height of the box
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
pts = [[x - w/2, y - h/2], # left
|
|
|
|
[x + w/2, y - h/2], # right
|
|
|
|
[x + w/2, y + h/2], # bottom
|
|
|
|
[x - w/2, y + h/2], # top
|
|
|
|
[x - w/2, y - h/2]] # close
|
|
|
|
|
|
|
|
self.Polyline(pts)
|
|
|
|
|
2015-10-31 11:54:48 +00:00
|
|
|
def NotchedCircle(self, x, y, r, notch_w, notch_h, rotate=0):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2018-06-01 11:19:31 +00:00
|
|
|
Circle radius r centred at (x, y) with a raised or depressed notch
|
2014-09-14 16:29:10 +00:00
|
|
|
at the top
|
|
|
|
Notch height is measured from the top of the circle radius
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the circle's centre
|
|
|
|
@param y: the y coordinate of the circle's centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param r: the radius of the circle
|
|
|
|
@param notch_w: the width of the notch
|
|
|
|
@param notch_h: the height of the notch
|
|
|
|
@param rotate: the rotation of the whole figure, in degrees
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
2015-10-31 11:54:48 +00:00
|
|
|
|
|
|
|
self.TransformRotation(x, y, rotate)
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
# find the angle where the notch vertical meets the circle
|
|
|
|
angle_intercept = math.asin(notch_w/(2 * r))
|
|
|
|
|
|
|
|
# and find the co-ords of this point
|
|
|
|
sx = math.sin(angle_intercept) * r
|
|
|
|
sy = -math.cos(angle_intercept) * r
|
|
|
|
|
|
|
|
# NOTE: this may be out by a factor of ten one day
|
|
|
|
arc_angle = (math.pi * 2 - angle_intercept * 2) * (1800/math.pi)
|
|
|
|
|
2018-06-01 11:19:31 +00:00
|
|
|
self.Arc(x, y, sx, sy, arc_angle)
|
2014-09-14 16:29:10 +00:00
|
|
|
|
|
|
|
pts = [[sx, sy],
|
|
|
|
[sx, -r - notch_h],
|
|
|
|
[-sx, -r - notch_h],
|
|
|
|
[-sx, sy]]
|
|
|
|
|
|
|
|
self.Polyline(pts)
|
2015-10-31 11:54:48 +00:00
|
|
|
self.PopTransform()
|
2014-04-23 16:36:31 +00:00
|
|
|
|
2015-10-31 11:54:48 +00:00
|
|
|
def NotchedBox(self, x, y, w, h, notchW, notchH, rotate=0):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
Draw a box with a notch in the centre of the top edge
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the circle's centre
|
|
|
|
@param y: the y coordinate of the circle's centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param w: the width of the box
|
|
|
|
@param h: the height of the box
|
|
|
|
@param notchW: the width of the notch
|
|
|
|
@param notchH: the height of the notch
|
|
|
|
@param rotate: the rotation of the whole figure, in degrees
|
2014-04-23 16:36:31 +00:00
|
|
|
"""
|
2015-10-31 11:54:48 +00:00
|
|
|
|
|
|
|
self.TransformRotation(x, y, rotate)
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
# limit to half the overall width
|
2014-04-23 16:36:31 +00:00
|
|
|
notchW = min(x + w/2, notchW)
|
|
|
|
|
|
|
|
# draw notch
|
2014-09-14 16:29:10 +00:00
|
|
|
self.Polyline([ # three sides of box
|
|
|
|
(x - w/2, y - h/2),
|
|
|
|
(x - w/2, y + h/2),
|
|
|
|
(x + w/2, y + h/2),
|
|
|
|
(x + w/2, y - h/2),
|
|
|
|
# the notch
|
|
|
|
(notchW/2, y - h/2),
|
|
|
|
(notchW/2, y - h/2 + notchH),
|
|
|
|
(-notchW/2, y - h/2 + notchH),
|
|
|
|
(-notchW/2, y - h/2),
|
|
|
|
(x - w/2, y - h/2)
|
|
|
|
])
|
|
|
|
|
2015-10-31 11:54:48 +00:00
|
|
|
self.PopTransform()
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
def BoxWithDiagonalAtCorner(self, x, y, w, h,
|
|
|
|
setback=pcbnew.FromMM(1.27), flip=flipNone):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
|
|
|
Draw a box with a diagonal at the top left corner.
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the circle's centre
|
|
|
|
@param y: the y coordinate of the circle's centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param w: the width of the box
|
|
|
|
@param h: the height of the box
|
|
|
|
@param setback: the set-back of the diagonal, in both x and y
|
|
|
|
@param flip: one of flipNone, flipX, flipY or flipBoth to change the
|
|
|
|
diagonal corner
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.TransformFlip(x, y, flip, push=True)
|
|
|
|
|
|
|
|
pts = [[x - w/2 + setback, y - h/2],
|
|
|
|
[x - w/2, y - h/2 + setback],
|
|
|
|
[x - w/2, y + h/2],
|
|
|
|
[x + w/2, y + h/2],
|
|
|
|
[x + w/2, y - h/2],
|
|
|
|
[x - w/2 + setback, y - h/2]]
|
|
|
|
|
|
|
|
self.Polyline(pts)
|
|
|
|
|
|
|
|
self.PopTransform()
|
|
|
|
|
|
|
|
def BoxWithOpenCorner(self, x, y, w, h,
|
|
|
|
setback=pcbnew.FromMM(1.27), flip=flipNone):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Draw a box with an opening at the top left corner
|
2018-06-01 12:11:03 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
@param x: the x coordinate of the circle's centre
|
|
|
|
@param y: the y coordinate of the circle's centre
|
2018-06-01 12:11:03 +00:00
|
|
|
@param w: the width of the box
|
|
|
|
@param h: the height of the box
|
|
|
|
@param setback: the set-back of the opening, in both x and y
|
|
|
|
@param flip: one of flipNone, flipX, flipY or flipBoth to change the
|
|
|
|
open corner position
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.TransformTranslate(x, y)
|
|
|
|
self.TransformFlipOrigin(flip)
|
|
|
|
|
|
|
|
pts = [[- w/2, - h/2 + setback],
|
|
|
|
[- w/2, + h/2],
|
|
|
|
[+ w/2, + h/2],
|
|
|
|
[+ w/2, - h/2],
|
|
|
|
[- w/2 + setback, - h/2]]
|
|
|
|
|
|
|
|
self.Polyline(pts)
|
|
|
|
|
|
|
|
self.PopTransform(num=2)
|
|
|
|
|
2018-06-01 11:08:26 +00:00
|
|
|
def RoundedBox(self, x, y, w, h, rad):
|
|
|
|
"""!
|
|
|
|
Draw a box with rounded corners (i.e. a 90-degree circular arc)
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
:param x: the x coordinate of the box's centre
|
|
|
|
:param y: the y coordinate of the box's centre
|
2018-06-01 11:08:26 +00:00
|
|
|
:param w: the width of the box
|
|
|
|
:param h: the height of the box
|
|
|
|
:param rad: the radius of the corner rounds
|
|
|
|
"""
|
|
|
|
|
|
|
|
x_inner = w - rad * 2
|
|
|
|
y_inner = h - rad * 2
|
|
|
|
|
|
|
|
x_left = x - w / 2
|
|
|
|
y_top = y - h / 2
|
|
|
|
|
|
|
|
# Draw straight sections
|
|
|
|
self.HLine(x_left + rad, y_top, x_inner)
|
|
|
|
self.HLine(x_left + rad, -y_top, x_inner)
|
|
|
|
|
|
|
|
self.VLine(x_left, y_top + rad, y_inner)
|
|
|
|
self.VLine(-x_left, y_top + rad, y_inner)
|
|
|
|
|
|
|
|
# corner arcs
|
|
|
|
ninety_deg = 90 * 10 # deci-degs
|
|
|
|
cx = x - w / 2 + rad
|
|
|
|
cy = y - h / 2 + rad
|
|
|
|
|
|
|
|
# top left
|
|
|
|
self.Arc(+cx, +cy, +x_left, +cy, +ninety_deg)
|
|
|
|
self.Arc(-cx, +cy, -x_left, +cy, -ninety_deg)
|
|
|
|
self.Arc(+cx, -cy, +x_left, -cy, -ninety_deg)
|
|
|
|
self.Arc(-cx, -cy, -x_left, -cy, +ninety_deg)
|
|
|
|
|
|
|
|
def ChamferedBox(self, x, y, w, h, chamfer_x, chamfer_y):
|
|
|
|
"""!
|
|
|
|
Draw a box with chamfered corners.
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
:param x: the x coordinate of the box's centre
|
|
|
|
:param y: the y coordinate of the box's centre
|
2018-06-01 11:08:26 +00:00
|
|
|
:param w: the width of the box
|
|
|
|
:param h: the height of the box
|
|
|
|
:param chamfer_x: the size of the chamfer set-back in the x direction
|
|
|
|
:param chamfer_y: the size of the chamfer set-back in the y direction
|
|
|
|
"""
|
|
|
|
# outermost dimensions
|
|
|
|
x_left = x - w / 2
|
|
|
|
y_top = y - h / 2
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
# x and y coordinates of inner edges of chamfers
|
2018-06-01 11:08:26 +00:00
|
|
|
x_inner = x_left + chamfer_x
|
|
|
|
y_inner = y_top + chamfer_y
|
|
|
|
|
|
|
|
pts = [
|
|
|
|
[+x_inner, +y_top],
|
|
|
|
[-x_inner, +y_top],
|
|
|
|
[-x_left, +y_inner],
|
|
|
|
[-x_left, -y_inner],
|
|
|
|
[-x_inner, -y_top],
|
|
|
|
[+x_inner, -y_top],
|
|
|
|
[+x_left, -y_inner],
|
|
|
|
[+x_left, +y_inner],
|
|
|
|
[+x_inner, +y_top],
|
|
|
|
]
|
|
|
|
|
|
|
|
self.draw.Polyline(pts)
|
|
|
|
|
2014-09-14 16:29:10 +00:00
|
|
|
def MarkerArrow(self, x, y, direction=dirN, width=pcbnew.FromMM(1)):
|
2018-06-01 12:11:03 +00:00
|
|
|
"""!
|
2014-09-14 16:29:10 +00:00
|
|
|
Draw a marker arrow facing in the given direction, with the
|
|
|
|
point at (x,y)
|
|
|
|
|
2018-06-01 12:11:03 +00:00
|
|
|
@param x: x position of the arrow tip
|
|
|
|
@param y: y position of the arrow tip
|
|
|
|
@param direction: arrow direction in degrees (0 is "north", can use
|
|
|
|
dir* shorthands)
|
|
|
|
@param width: arrow width
|
2014-09-14 16:29:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.TransformTranslate(x, y)
|
|
|
|
self.TransformRotationOrigin(direction)
|
|
|
|
|
|
|
|
pts = [[0, 0],
|
|
|
|
[width / 2, width / 2],
|
|
|
|
[-width / 2, width / 2],
|
|
|
|
[0, 0]]
|
|
|
|
|
|
|
|
self.Polyline(pts)
|
2018-06-01 11:08:26 +00:00
|
|
|
self.PopTransform(2)
|