I’m working out exactly how to create each type of DRAWSEGMENT and will use this thread to work through all the details.
Current questions:
Where did DRAWSEGMENT.SetRadius() go? This is used to set the radius of a circle. It is in neither the documentation nor the nightly from 2020/3/20. Edit: actually, this may not have existed. I’ve identified code that apparently uses it, but if it ever executed it should have caused an error (using S_CIRCLE instead of pcbnew.S_CIRCLE). The gist of the question remains: how do I create a drawsegment of type S_CIRCLE?
What is SetType? Can anyone verify it’s within the set of S_ values (S_ARC, S_CIRCLE, S_CURVE, S_LAST, S_POLYGON, S_RECT, S_SEGMENT)
What is initialization argument idtype=PCB_LINE_T. The other PCB_ values are (PCB_DIMENSION_T, PCB_IO, PCB_ITEM_LIST_T, PCB_LAYER_ID_COUNT, PCB_LINE_T, PCB_MARKER_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_NETINFO_T, PCB_PAD_T, PCB_PLOT_PARAMS, PCB_PLOT_PARAMS_GetGerberDefaultPrecision, PCB_SEGZONE_T, PCB_T, PCB_TARGET, PCB_TARGET_ClassOf, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T)
There is an IsPolygonFilled but no SetPolygonFilled. How do you create a filled polygon or an unfilled polygon?
What is SetPolyShape? It seems to use argument of type SHAPE_POLY_SET. The only other place this type is used is in TransformShapeWithClearanceToPolygon() for an argument called aCornerBuffer. It appears to be a fully fledged class (and not an integer like the S_ attributes are).
There is a SetPolyPoints() but not GetPolyPoints() function. However, there is a BuildPolyPointsList() (which returns a wxPoint_Vector). Are these equivalent to the Set/Get pair of functions?
Thank you so much for pointing me there. To answer my own questions (somewhat), I have discovered the following. (please comment if anything below is egregiously wrong).
Radius is calculated as distance from Start to End
For Circule and Arc:
Center is equivalent to Start
ArcStart is equivalent to End
Additionally, for Arc, Angle is used
SetType is the parallel to GetType. GetType returns exactly the same integer as the S_ attributes for segments drawn with the GUI.
PCB_LINE_T seems to be part of the KICAD_T enumeration defined in type.h. All DRAWSEGMENTS are defined as PCB_LINE_T, commented there as
///< class DRAWSEGMENT, a segment not on copper layers
IsPolygonFilled is currently defined as m_Layer != Edge_Cuts with the comment Polygonal shape is not always filled. For now it is filled on all layers but Edge_Cut layer.
SHAPE_POLY_SET appears to be a collection of polygons, for use in 2d and 3d imaging. It appears to be the core collection of objects defining the polygon (and holes within that initial outline).
BuildPolyPointsList has the following comment:
Build and return the list of corners in a std::vector
It must be used only to convert the SHAPE_POLY_SET internal corner buffer to a list of wxPoints, and nothing else, because it duplicates the buffer, that is inefficient to know for instance the corner count
Based on this, the proper method to set points is the SetPoints and the method to get points is GetPolyShape, which returns a SHAPE_POLY_SET.
///> represents a single polygon outline with holes. The first entry is the outline,
///> the remaining (if any), are the holes
///> N.B. SWIG only supports typedef, so avoid c++ 'using' keyword
It’s not clear to me, yet, how to decipher what is in the SHAPE_POLY_SET object. I’ve tried various attributes and class methods, and can’t find a function to retrieve points of the polygon. Presumably the initial (single) outline is accessible, then subsequent outlines/contours are holes within the first outline. Disturbingly, many objects indicated as an “Iterator” do not appear to be a Python iterator Still investigating.
In practice semantics depend on where the class is used. For example zones return a poly set that has no holes (polygons are pre-cut so that any holes become part of outline) and multiple polygons are separate parts of zone outline.
Notice the horizontal slits in zone that connect the outer edge with holes.