JamesBremner / DXF_Viewer

A simple DXF File viewer
MIT License
22 stars 4 forks source link

Draw closed polyline #3

Closed asmwarrior closed 5 years ago

asmwarrior commented 5 years ago

Hi, I see currently, the code does not draw closed polyline. For a reference, POLYLINE (DXF) | Search | Autodesk Knowledge Network, which says that for a default polyline, the group code 70 = 0, while for group code 70 = 1, we can simply connect the first point and last point, thus make a closed polyline.

    for( dxfv::CPolyLine& polyline : dxf->m_PolyLine )
    {
        dxf->Init( draw );
        while( polyline.getDraw( draw ) )
        {
            dc.DrawLine( draw.x1, draw.y1, draw.x2, draw.y2 );
        }
    }

This code may be updated with some if condition for the m_PolyLineFlag field check.

Thanks.

asmwarrior commented 5 years ago

This is a bug in the latest git head which cause endless loop when drawing closed polyline:

bool CPolyLine::getDraw( s_dxf_draw& draw )
{
    if( 0 > draw.index || draw.index == (int)m_VertexCount )
        return false;
    if( draw.index == (int)m_VertexCount  )
        return false;
    if( draw.index == (int)m_VertexCount-1  )
    {
        if( ! myfClosed )
        {
            return false;
        }
        else
        {
            draw.x1 = x[draw.index];
            draw.y1 = y[draw.index];
            draw.x2 = x[0];
            draw.y2 = y[0];
        }
    }
    else
    {
        draw.x1 = x[draw.index];
        draw.y1 = y[draw.index];
        draw.index++;
        draw.x2 = x[draw.index];
        draw.y2 = y[draw.index];
    }
    draw.rect->ApplyScale( draw.x1, draw.y1 );
    draw.rect->ApplyScale( draw.x2, draw.y2 );

    return true;
}

I think the index should be increased in this brace:

        {
            draw.x1 = x[draw.index];
            draw.y1 = y[draw.index];
            draw.x2 = x[0];
            draw.y2 = y[0];
        }
JamesBremner commented 5 years ago

Fixed. ( I would assign the issue back to you for testing, but you forgot to assign it to me. )

asmwarrior commented 5 years ago

It works OK now, so I think this issue can be closed, thanks!