Howto python fillet a track

so probably is related

new_shape = PCB_SHAPE() 
new_arc = PCB_ARC(new_shape)
new_arc.SetStart(p1)
new_arc.SetEnd(p2)
new_arc.SetMid(mp)

probably this one should work:

new_trk = PCB_TRACK()
new_arc = PCB_ARC(new_trk)
new_arc.SetStart(p1)
new_arc.SetEnd(p2)
new_arc.SetMid(mp)

I just tested on 5.99

board = pcbnew.GetBoard()
new_arc = pcbnew.PCB_ARC(board)
new_arc.SetStart(p1)
new_arc.SetEnd(p2)
new_arc.SetMid(mp)
new_arc.SetWidth(w)
board.Add(new_arc)

Works fine and is draggable. Didn’t show up until I reloaded the board though, not even with Refresh().

Thanks I confirm it!

that’s a known issue … it works only with action scripts, python console doesn’t allow ATM to show added items.

Still it would be nice to have a way to call the python Fillet function… this will automatic create an arc tangent to tracks.
‘Fillet’ function will allow the track to be dragged more than the dimension of the created arc.

I’m not sure I understand what you want to achieve that can’t be done natively in KiCad

Arc track interactive resizing is here:

That function has nothing to do with tracks, it’s for rounding edges of polygon shapes. You can’t use it for tracks because it won’t give you coordinates for arc which you ultimately have to create.

Yes, I know it. But I need to manipulate it to add some functionalities available ATM only with the plugins (i.e. Solder Mask Expander for tracks)

So what is the corresponding python function used by the GUI to fillet tracks?

You can lookup EDIT_TOOL::FilletTracks. It’s not usable in scripting, none of the tools are.

There is a SHAPE_ARC constructor that does fillet calculation that you want

/**
     * Build a SHAPE_ARC which is tangent to two segments and a given radius.
     *
     * @param aSegmentA is the first segment
     * @param aSegmentB is the second segment
     * @param aRadius is the arc radius
     * @param aWidth is the arc line thickness
     */
    SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth = 0 );

Then the code passes that shape to PCB_ARC. Unfortunately neither SHAPE_ARC nor SEG needed to create it that way are exposed in API.

thanks a lot, I will have a look at those to see if I can port the code to python.

This is the meat of it and has a cute diagram too

Be mindful of the license when porting GPL code directly.

1 Like

I will, but in this case I just adapted what I did for kicad 5 to calculate segments and simply got the middle point instead of all the discretized.
Thanks again for support :smiley:

2 Likes

Ah right sorry now I understand. I must say I’m not sure what the rules are but I wrote the fillet tracks tool (and corresponding constructor inSHAPE_ARC) so I’m happy if you’d like to use a derivative of that in your plugin.

To make sure you can “drag-resize” the arc tracks you create, you need to ensure thar start point of the arc track matches the end point of the previous track. Similarly, the end point of the arc track must match the start point of the next one.

Glad someone appreciates it :laughing: It took me a good while to make it look sensible in ascii art.

3 Likes

Is there a way to create an arc using python for a i.e. Mask layer (like a drawing on Mask Layer) to free the area over a track?

This is the way I use my Solder Mask Expander plugin.
In kv5 I use a discretization of the arc, but in 5.99 I would like to use a real arc.

It seems to me ATM there is no way to create an Arc in a different layer than Cu through python code.
(There is instead a way using the Gui)

1 Like

I havent tested it but I think you want PCB_SHAPE, and use the functions SetShape (to define the PCB shape as an arc with SHAPE_T::ARC) and SetArcGeometry to set the actual geometry.

I’m not sure if SHAPE_T is exposed in python but basically SHAPE_T::ARC is equal to 2 as defined in the C++ code

import pcbnew
from pcbnew import *
b=pcbnew.GetBoard()
new_arc=PCB_SHAPE()
new_arc.SetShape(SHAPE_T)
p1= wxPoint(203200000, 127000000)
md= wxPoint(221160512, 134439488)
p2= wxPoint(228600000, 152400000)
# new_arc.SetArcGeometry(aStart: 'wxPoint', aMid: 'wxPoint', aEnd: 'wxPoint')
new_arc.SetArcGeometry(p1,md,p2)
# new_arc.SetStart(p1)
# new_arc.SetMid(md)
# new_arc.SetEnd(p2)
new_arc.SetWidth(250000)
new_arc.SetLayer(pcbnew.F_SilkS)
b.Add(new_arc)
# pcbnew.SaveBoard("./test.kicad_pcb",b)

Here a sample code that should work…
But the result is a line instead of an arc.
The format inside the file is ‘gr_line’ instead of ‘gr_arc

Moreover, executing the Save code (last commented line), pcbnew just crashes.

I also found a nasty error… designing a simple 90 deg Arc with the Gui and pressing Edit and simply confirm the Arc will rotate… probably because Start point is mangled with Center point in the pcbnew code…

Application: KiCad PCB Editor (64-bit)

Version: (5.99.0-11630-gc5e195bdff), release build

Libraries:
wxWidgets 3.1.5
libcurl/7.74.0-DEV Schannel zlib/1.2.11

Platform: Windows 10 (build 18363), 64-bit edition, 64 bit, Little endian, wxMSW

Build Info:
Date: Aug 3 2021 21:00:05
wxWidgets: 3.1.5 (wchar_t,STL containers)
Boost: 1.75.0
OCC: 7.5.0
Curl: 7.74.0-DEV
ngspice: 34
Compiler: Visual C++ 1928 without C++ ABI

Build settings:
KICAD_USE_OCC=ON
KICAD_SPICE=ON

test.kicad_pcb (2.1 KB)
arc-dwg.kicad_pcb (2.1 KB)

Should be SHAPE_T_ARC

thanks, this solves the arc
… still I get a wrong Arc
test2.kicad_pcb (2.1 KB)
it seems that editing an arc with a negative angle can give a wrong design
arc1.kicad_pcb (2.5 KB) (both arcs have been placed by hand)

here the Arc Editing with wrong behavior…
simply clicking on ‘E’ and confirming the values the Arc gets flipped:


(note: this seems to be an issue in win only)

I cant reproduce on latest nightly. Might be some state leftover after your script. What did you do to generate?

Application: KiCad PCB Editor (64-bit)

Version: (5.99.0-11640-gb6664eecf2), release build

Libraries:
	wxWidgets 3.1.5
	libcurl/7.74.0-DEV Schannel zlib/1.2.11

Platform: Windows 10 (build 19041), 64-bit edition, 64 bit, Little endian, wxMSW

Build Info:
	Date: Aug  5 2021 20:59:33
	wxWidgets: 3.1.5 (wchar_t,STL containers)
	Boost: 1.75.0
	OCC: 7.5.0
	Curl: 7.74.0-DEV
	ngspice: 34
	Compiler: Visual C++ 1928 without C++ ABI

Build settings:
	KICAD_USE_OCC=ON
	KICAD_SPICE=ON

I simply draw the arc manually… have you tried with the attached above board? (arc1.kicad_pcb)