FootprintWizardBase.py: fix Arc building due to recent code changes.

Add a arc_test wizard (only to test arcs in fp).
This commit is contained in:
jean-pierre charras 2021-10-22 10:03:49 +02:00
parent 1860893d63
commit 0bdb424215
2 changed files with 67 additions and 11 deletions

View File

@ -1,3 +1,8 @@
#
# This program source code file is part of KiCad, a free EDA CAD application.
#
# Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
#
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@ -22,7 +27,7 @@ import math
class FootprintWizard(pcbnew.FootprintWizardPlugin): class FootprintWizard(pcbnew.FootprintWizardPlugin):
"""! """!
A class to simplify many aspects of footprint creation, leaving only A class to simplify many aspects of footprint creation, leaving only
the foot-print specific routines to the wizards themselves. the footprint specific routines to the wizards themselves.
Inherit this class to make a new wizard. Inherit this class to make a new wizard.
@ -528,7 +533,7 @@ class FootprintWizardDrawingAids:
return 1 return 1
return 0 return 0
def Arc(self, cx, cy, sx, sy, a): def Arc(self, cx, cy, sx, sy, angle):
"""! """!
Draw an arc based on centre, start and angle Draw an arc based on centre, start and angle
@ -541,24 +546,26 @@ class FootprintWizardDrawingAids:
@param cy: the y 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 sx: the x coordinate of the arc start point
@param sy: the y coordinate of the arc start point @param sy: the y coordinate of the arc start point
@param a: the arc's central angle (in deci-degrees) @param angle: the arc's central angle (in deci-degrees)
""" """
circle = pcbnew.FP_SHAPE(self.module) arc = pcbnew.FP_SHAPE(self.module)
circle.SetWidth(self.dc['lineThickness']) arc.SetShape(pcbnew.SHAPE_T_ARC)
arc.SetWidth(self.dc['lineThickness'])
center = self.TransformPoint(cx, cy) center = self.TransformPoint(cx, cy)
start = self.TransformPoint(sx, sy) start = self.TransformPoint(sx, sy)
circle.SetLayer(self.dc['layer']) arc.SetLayer(self.dc['layer'])
circle.SetShape(pcbnew.S_ARC)
# check if the angle needs to be reverse (a flip scaling) # check if the angle needs to be reverse (a flip scaling)
if self.MyCmp(self.dc['transform'][0], 0) != self.MyCmp(self.dc['transform'][4], 0): if self.MyCmp(self.dc['transform'][0], 0) != self.MyCmp(self.dc['transform'][4], 0):
a = -a angle = -angle
circle.SetAngle(a) arc.SetCenter(center)
circle.SetStartEnd(center, start) arc.SetStart(start)
self.module.Add(circle) arc.SetArcAngleAndEnd(angle, True)
arc.SetLocalCoord()
self.module.Add(arc)
def HLine(self, x, y, l): def HLine(self, x, y, l):
"""! """!

View File

@ -0,0 +1,49 @@
# 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.
#
# A basic fp wizard to test arcs in footprints
import pcbnew
import FootprintWizardBase
class DemoArc(FootprintWizardBase.FootprintWizard):
"""Test for arc"""
GetName = lambda self: "DemoArc"
GetDescription = lambda self: DemoArc.__doc__
GetReferencePrefix = lambda self: "demo"
GetValue = lambda self: "Arc"
def GenerateParameterList(self):
self.AddParam("demo", "radius", self.uMM, 8, min_value=0.1)
self.AddParam("demo", "centerX", self.uMM, 0)
self.AddParam("demo", "centerY", self.uMM, 0)
self.AddParam("demo", "angle", self.uDegrees, 90)
def BuildThisFootprint(self):
radius = self.parameters["demo"]["radius"]
arc_angle_deg = self.parameters["demo"]["angle"]
centerx = self.parameters["demo"]["centerX"]
centery = self.parameters["demo"]["centerY"]
startptx = centerx
startpty = centery+radius
self.draw.Arc(centerx, centery, startptx, startpty, arc_angle_deg * 10)
t_size = self.GetTextSize()
self.draw.Reference(0, -t_size, t_size)
self.draw.Value(0, t_size, t_size)
def CheckParameters(self):
pass
DemoArc().register()