Python and DRAWSEGMENT confusion

Using KiCAD nightly from 2020/3/20

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:

  1. 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?
  2. 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)
  4. There is an IsPolygonFilled but no SetPolygonFilled. How do you create a filled polygon or an unfilled polygon?
  5. 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).
  6. 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?

You can get answers to your questions by looking at comments and parameter type definitions here

Have a look and if you still have questions I’ll try to answer them.

1 Like

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).

  1. 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

  1. SetType is the parallel to GetType. GetType returns exactly the same integer as the S_ attributes for segments drawn with the GUI.

  2. 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

  3. 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.

  4. 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).

  5. 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.

shape_poly_set.h comments that 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.

You got it right.

For example on how to read SHAPE_POLY_SET see here

I patched kicad to add some accessors some time ago, I think it was available since 5.0.x release.

1 Like

Thank you. That answers my question. Now I have to figure out how to expose these efficiently in KiCommand.

I really appreciate it!

1 Like

One more thing, don’t trust this comment

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.

1 Like

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