Pcbnew 7: How to add arc segment of polyline with Python API?

I’m trying to create a polyline that is a combination of straight line and arc segments in pcbnew with the Python API. I am able to generate polylines that consist only of line segments and add them to the board layout. I have not been able to do this with an arc segment, though I can add the arc directly to the layout by itself.

It appears that I should be able to create the SHAPE_ARC and pass it to the Append() method on my SHAPE_LINE_CHAIN, however this isn’t working for me. I’m perhaps missing a way to cast the Arc?

This is what I have now:

import pcbnew
board = pcbnew.GetBoard()

a = pcbnew.PCB_SHAPE(board, pcbnew.SHAPE_T_ARC)
a.SetCenter(pcbnew.VECTOR2I(0, 0))
a.SetStart(pcbnew.VECTOR2I(pcbnew.FromMM(-100), -pcbnew.FromMM(0)))
a.SetEnd(pcbnew.VECTOR2I(pcbnew.FromMM(100), -pcbnew.FromMM(0)))
a.SetWidth(0)

slc = pcbnew.SHAPE_LINE_CHAIN()
slc.Append(0, 0)
slc.Append(pcbnew.FromMM(-100), 0)

# The arc works if I add it directly
board.Add(a)
pcbnew.Refresh()

# The chain works if I add it through a polyline set
sps = pcbnew.SHAPE_POLY_SET()
sps.AddOutline(slc)
ps = pcbnew.PCB_SHAPE(board, pcbnew.SHAPE_T_POLY)
ps.SetPolyShape(sps)
ps.SetWidth(0)
board.Add(ps)
pcbnew.Refresh()

# But I can't add the arc to the polyline...
slc.Append(a)
# .... which is odd because the type I'm passing is listed as a suitable one:

#TypeError: in method 'SHAPE_LINE_CHAIN_Append', argument 2 of type 'SHAPE_ARC const &'                                                                              
#Additional information:
#Wrong number or type of arguments for overloaded function 'SHAPE_LINE_CHAIN_Append'.
#  Possible C/C++ prototypes are:
#    SHAPE_LINE_CHAIN::Append(int,int,bool)
#    SHAPE_LINE_CHAIN::Append(int,int)
#    SHAPE_LINE_CHAIN::Append(VECTOR2I const &,bool)
#    SHAPE_LINE_CHAIN::Append(VECTOR2I const &)
#    SHAPE_LINE_CHAIN::Append(SHAPE_LINE_CHAIN const &)
#    SHAPE_LINE_CHAIN::Append(SHAPE_ARC const &)    <<<<<<<<<<<< Isn't this what I'm doing??
#    SHAPE_LINE_CHAIN::Append(SHAPE_ARC const &,double)

The error message is particularly baffling to me since it seems to be saying that I can’t call Append() with a SHAPE_ARC const &, but then lists that as an option below.

What am I missing?

I’m facing the same problem. According to SWIG and Python, a missing “typecheck typemap for overloading” might be the cause.

@mjpelmear, did you ever solve this?

Can somebody confirm that a missing typecheck typemap is the cause?

That is creating a PCB_SHAPE, not SHAPE_ARC, which is it’s own class.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.