← Back to team overview

kicad-developers team mailing list archive

Any pointers to the core of this problem with DXF poly import in footprint editor?

 

On and off I have been looking into getting DXF drawings imported as filled polygons
on copper layers.

While this is working fine in pcbnew, I have been bumping into a problem doing the same the module editor. The problem is that the polygon looses the polygon coordinates on
the import and things go downhill from there (i.e. segfaults).

Still being very fresh to KiCad code and development, it's been a road of discovery as to how to get a debug session of pcbnew working, but I now managed to get a debug session
with some more info illustrating this problem.

However, I have no idea how to go from here as I am definitely not a C++ wiz of any kind.

I am hoping somebody has an Aha moment with the info below or can provide a pointer
towards the core problem.

So here are the GDB steps (on Fedora Linux):

Running the footprint editor and creating a new footprint. Then going through the DXF import dialog to select a DXF file. The import itself has DXF2BRD_CONVERTER::addPolyline
modified to create an S_POLYGON shape instead of a series of lines.

As this works Ok in pcbnew I suspect that code is at least half right.

Now from pressing Ok in the DXF import dialog, I break in dialog_dxf_import.cpp line 281:

Breakpoint 1, InvokeDXFDialogModuleImport (aCaller=0x2942870, aModule=0x952600) at /home/marco/KiCad/src/kicad/pcbnew/import_dxf/dialog_dxf_import.cpp:281
281                        aModule->Add( converted );

This are the relevant source lines showing we had the break point just after the static cast
assignment in line 280:

(gdb) list
276                {
277                    case PCB_LINE_T:
278                    {
279                        converted = new EDGE_MODULE( aModule );
280 *static_cast<DRAWSEGMENT*>( converted ) = *static_cast<DRAWSEGMENT*>( item );
281                        aModule->Add( converted );
282 static_cast<EDGE_MODULE*>( converted )->SetLocalCoord();
283                        delete item;
284                        break;
285                    }

Displaying the imported 'item' variable with m_PolyPoints vector filled with the points from the DXF:

(gdb) print *static_cast<DRAWSEGMENT*>(item)
$6 = {<BOARD_ITEM> = {<EDA_ITEM> = {<KIGFX::VIEW_ITEM> = {
        _vptr.VIEW_ITEM = 0x7fffd7faf590 <vtable for DRAWSEGMENT+16>,
        m_view = 0x0, m_flags = 1, m_requiredUpdate = 0, m_groups = 0x0,
m_groupsSize = 0, m_layers = std::bitset}, m_StructType = PCB_LINE_T, m_Status = 0, Pnext = 0x0, Pback = 0x0, m_List = 0x0, m_Parent = 0x0, m_TimeStamp = 0, m_forceVisible = false, m_Flags = 0, m_Image = 0x0},
    m_Layer = F_Cu, static ZeroOffset = {x = 0, y = 0}}, m_Width = 100,
  m_Start = {x = 0, y = 0}, m_End = {x = 0, y = 0}, m_Shape = S_POLYGON,
m_Type = 11, m_Angle = 0, m_BezierC1 = {x = 0, y = 0}, m_BezierC2 = {x = 0,
    y = 0}, m_BezierPoints = std::vector of length 0, capacity 0,
  m_PolyPoints = std::vector of length 29, capacity 29 = {{x = 188501100,
      y = 104003600}, {x = 188501100, y = 105003600}, {x = 198501100,
      y = 105003600}, {x = 198501100, y = 94003600}, {x = 194501100,
      y = 94003600}, {x = 194501100, y = 93003600}, {x = 198501100,
      y = 93003600}, {x = 198501100, y = 90003600}, {x = 194501100,
      y = 90003600}, {x = 194501100, y = 89003600}, {x = 198501100,
      y = 89003600}, {x = 198501100, y = 85003600}, {x = 193501100,
      y = 85003600}, {x = 193501100, y = 87003600}, {x = 197501100,
      y = 87003600}, {x = 197501100, y = 88003600}, {x = 193501100,
      y = 88003600}, {x = 193501100, y = 91003600}, {x = 197501100,
      y = 91003600}, {x = 197501100, y = 92003600}, {x = 193501100,
      y = 92003600}, {x = 193501100, y = 95003600}, {x = 197501100,
      y = 95003600}, {x = 197501100, y = 97003600}, {x = 188501100,
      y = 97003600}, {x = 188501100, y = 98003600}, {x = 197501100,
      y = 98003600}, {x = 197501100, y = 104003600}, {x = 188501100,
      y = 104003600}}}

And now the 'converted' variable. The m_PolyPoints is now empty!

(gdb) print *static_cast<DRAWSEGMENT*>(converted)
$7 = {<BOARD_ITEM> = {<EDA_ITEM> = {<KIGFX::VIEW_ITEM> = {
        _vptr.VIEW_ITEM = 0x7fffd7faf720 <vtable for EDGE_MODULE+16>,
        m_view = 0x0, m_flags = 1, m_requiredUpdate = 0, m_groups = 0x0,
        m_groupsSize = 0, m_layers = std::bitset},
      m_StructType = PCB_MODULE_EDGE_T, m_Status = 0, Pnext = 0x0,
      Pback = 0x0, m_List = 0x0, m_Parent = 0x952600, m_TimeStamp = 0,
      m_forceVisible = false, m_Flags = 0, m_Image = 0x0}, m_Layer = F_Cu,
    static ZeroOffset = {x = 0, y = 0}}, m_Width = 100, m_Start = {x = 0,
    y = 0}, m_End = {x = 0, y = 0}, m_Shape = S_POLYGON, m_Type = 11,
  m_Angle = 0, m_BezierC1 = {x = 0, y = 0}, m_BezierC2 = {x = 0, y = 0},
  m_BezierPoints = std::vector of length 0, capacity 0,
  m_PolyPoints = std::vector of length 0, capacity 0}

Anybody any ideas as to where the core of this problem is or even better
an Aha moment as to where and how to fix this?

Thanks,

Marco



Follow ups