Commit c89070da authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Plot poly code cleaning. Suppress erreurs for malformed polygons (< 2 corners)

parent dcccaee2
Loading
Loading
Loading
Loading
+42 −36
Original line number Diff line number Diff line
@@ -100,47 +100,53 @@ double PLOTTER::user_to_device_size( double size )
void PLOTTER::center_square( const wxPoint& position, int diametre, FILL_T fill )
{
    int radius     = wxRound( diametre / 2.8284 );
    int coord[10] =
    {
        position.x + radius, position.y + radius,
        position.x + radius, position.y - radius,
        position.x - radius, position.y - radius,
        position.x - radius, position.y + radius,
        position.x + radius, position.y + radius
    };

    if( fill )
    {
        poly( 4, coord, fill );
    }
    else
    {
        poly( 5, coord, fill );
    }
    static std::vector< wxPoint > corner_list;
    corner_list.clear();
    wxPoint corner;
    corner.x = position.x + radius;
    corner.y = position.y + radius;
    corner_list.push_back( corner );
    corner.x = position.x + radius;
    corner.y = position.y - radius;
    corner_list.push_back( corner );
    corner.x = position.x - radius;
    corner.y = position.y - radius;
    corner_list.push_back( corner );
    corner.x = position.x - radius;
    corner.y = position.y + radius;
    corner_list.push_back( corner );
    corner.x = position.x + radius;
    corner.y = position.y + radius;
    corner_list.push_back( corner );

    PlotPoly( corner_list, fill );

}


void PLOTTER::center_lozenge( const wxPoint& position, int diametre,
                              FILL_T fill )
void PLOTTER::center_lozenge( const wxPoint& position, int diametre, FILL_T fill )
{
    int radius     = diametre / 2;
    int coord[10] =
    {
        position.x,         position.y + radius,
        position.x + radius, position.y,
        position.x,         position.y - radius,
        position.x - radius, position.y,
        position.x,         position.y + radius,
    };

    if( fill )
    {
        poly( 4, coord, fill );
    }
    else
    {
        poly( 5, coord, fill );
    }
    static std::vector< wxPoint > corner_list;
    corner_list.clear();
    wxPoint corner;
    corner.x = position.x;
    corner.y = position.y + radius;
    corner_list.push_back( corner );
    corner.x = position.x + radius;
    corner.y = position.y,
    corner_list.push_back( corner );
    corner.x = position.x;
    corner.y = position.y - radius;
    corner_list.push_back( corner );
    corner.x = position.x - radius;
    corner.y = position.y;
    corner_list.push_back( corner );
    corner.x = position.x;
    corner.y = position.y + radius;
    corner_list.push_back( corner );

    PlotPoly( corner_list, fill );
}


+11 −13
Original line number Diff line number Diff line
@@ -115,27 +115,25 @@ void DXF_PLOTTER::circle( wxPoint centre, int diameter, FILL_T fill, int width )
}


/* Draw a polygon (closed if completed) in DXF format
 * coord = coord table tops
/* Draw a polygon (closed if filled) in DXF format
 * nb = number of coord (coord 1 = 2 elements: X and Y table)
 * fill: if != 0 filled polygon
 * aFill: if != 0 filled polygon
 */
void DXF_PLOTTER::poly( int nb, int* coord, FILL_T fill, int width )
void DXF_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth)
{
    wxASSERT( output_file );
    if( nb <= 1 )
    if( aCornerList.size() <= 1 )
        return;

    move_to( wxPoint( coord[0], coord[1] ) );
    for( int ii = 1; ii < nb; ii++ )
        line_to( wxPoint( coord[ii * 2], coord[(ii * 2) + 1] ) );
    move_to( aCornerList[0] );
    for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
        line_to( aCornerList[ii] );

    /* Close polygon. */
    if( fill )
    if( aFill )
    {
        int ii = (nb - 1) * 2;
        if( ( coord[ii] != coord[0] ) || ( coord[ii + 1] != coord[1] ) )
            line_to( wxPoint( coord[0], coord[1] ) );
        unsigned ii = aCornerList.size() - 1;
        if( aCornerList[ii] != aCornerList[0] )
            line_to( aCornerList[0] );
    }
    pen_finish();
}
+36 −32
Original line number Diff line number Diff line
@@ -248,16 +248,20 @@ void GERBER_PLOTTER::pen_to( wxPoint aPos, char plume )

void GERBER_PLOTTER::rect( wxPoint p1, wxPoint p2, FILL_T fill, int width )
{
    wxASSERT( output_file );
    int coord[10] =
    {
        p1.x, p1.y,
        p1.x, p2.y,
        p2.x, p2.y,
        p2.x, p1.y,
        p1.x, p1.y
    };
    poly( 5, coord, fill, width );
    static std::vector< wxPoint > cornerList;
    cornerList.clear();

    // Build corners list
    cornerList.push_back( p1 );
    wxPoint corner(p1.x, p2.y);
    cornerList.push_back( corner );
    cornerList.push_back( p2 );
    corner.x = p2.x;
    corner.y = p1.y;
    cornerList.push_back( corner );
    cornerList.push_back( p1 );

    PlotPoly( cornerList, fill, width );
}


@@ -296,34 +300,31 @@ void GERBER_PLOTTER::circle( wxPoint aCentre, int aDiameter, FILL_T aFill,


/**
 * Function PlotFilledPolygon_GERBER
 * writes a filled polyline to output file
 * @param aCornersCount = number of corners
 * Function PlotPoly
 * writes a filled or not filled polyline to output file
 * @param aCoord = buffer of corners coordinates
 * @param aFill = plot option (NO_FILL, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR)
 * @param aWidth = Width of the line to plot.
 */
void GERBER_PLOTTER::poly( int aCornersCount, int* aCoord, FILL_T aFill, int aWidth )
void GERBER_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth )
{
    wxASSERT( output_file );
    wxPoint pos, startpos;
    if( aCornerList.size() <= 1 )
        return;

    set_current_line_width( aWidth );

    if( aFill )
        fputs( "G36*\n", output_file );
    startpos.x = *aCoord++;
    startpos.y = *aCoord++;
    move_to( startpos );
    for( int ii = 1; ii < aCornersCount; ii++ )

    move_to( aCornerList[0] );
    for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
    {
        pos.x = *aCoord++;
        pos.y = *aCoord++;
        line_to( pos );
        line_to( aCornerList[ii] );
    }

    if( aFill )
    {
        finish_to( startpos );
        finish_to( aCornerList[0] );
        fputs( "G37*\n", output_file );
    }
    else
@@ -488,22 +489,25 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
                                   int aPadOrient, GRTraceMode aTrace_Mode )

{
    wxPoint polygon[5];    // polygon corners list
    // polygon corners list
    static std::vector< wxPoint > cornerList;
    cornerList.clear();


    for( int ii = 0; ii < 4; ii++ )
        polygon[ii] = aCorners[ii];
        cornerList.push_back( aCorners[ii] );

   /* Draw the polygon and fill the interior as required. */
    for( int ii = 0; ii < 4; ii++ )
    for( unsigned ii = 0; ii < 4; ii++ )
    {
        RotatePoint( &polygon[ii], aPadOrient );
        polygon[ii] += aPadPos;
        RotatePoint( &cornerList[ii], aPadOrient );
        cornerList[ii] += aPadPos;
    }
    // Close the polygon
    polygon[4] = polygon[0];
    cornerList.push_back( cornerList[0] );

    set_current_line_width( -1 );
    poly( 5, &polygon[0].x, aTrace_Mode==FILLED ? FILLED_SHAPE : NO_FILL );
    PlotPoly( cornerList, aTrace_Mode==FILLED ? FILLED_SHAPE : NO_FILL );
}

void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )
+11 −13
Original line number Diff line number Diff line
@@ -75,26 +75,24 @@ void HPGL_PLOTTER::circle( wxPoint centre,


/* Plot a polygon (closed if completed) in HPGL
 * Coord = coord table tops
 * Nb = number of coord (coord 1 = 2 elements: X and Y table)
 * Fill: if! = 0 filled polygon
 * aCornerList = a wxPoint list of corner
 * aFill: if != 0 filled polygon
 */
void HPGL_PLOTTER::poly( int nb, int* coord, FILL_T fill, int width )
void HPGL_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth)
{
    wxASSERT( output_file );
    if( nb <= 1 )
    if( aCornerList.size() <= 1 )
        return;

    move_to( wxPoint( coord[0], coord[1] ) );
    for( int ii = 1; ii < nb; ii++ )
        line_to( wxPoint( coord[ii * 2], coord[(ii * 2) + 1] ) );
    move_to( aCornerList[0] );
    for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
        line_to( aCornerList[ii] );

    /* Close polygon if filled. */
    if( fill )
    if( aFill )
    {
        int ii = (nb - 1) * 2;
        if( (coord[ii] != coord[0] ) || (coord[ii + 1] != coord[1]) )
            line_to( wxPoint( coord[0], coord[1] ) );
        int ii = aCornerList.size() - 1;
        if( aCornerList[ii] != aCornerList[0] )
            line_to( aCornerList[0] );
    }
    pen_finish();
}
+49 −50
Original line number Diff line number Diff line
@@ -168,40 +168,33 @@ void PS_PLOTTER::arc( wxPoint centre, int StAngle, int EndAngle, int radius,
}


/**
 * Function poly
 * @brief Draw a polygon ( a filled polygon if fill == 1 ) in POSTSCRIPT format
 * @param nb_segm = corner count
 * @param coord = corner list (a corner uses 2 int = X coordinate followed by Y
 *  coordinate
 * @param fill :if true : filled polygon
 * @param  width = line width
/*
 * Function PlotPoly
 * Draw a polygon (filled or not) in POSTSCRIPT format
 * param aCornerList = corners list
 * param aFill :if true : filled polygon
 * param aWidth = line width
 */
void PS_PLOTTER::poly( int nb_segm, int* coord, FILL_T fill, int width )
void PS_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth )
{
    wxASSERT( output_file );
    wxPoint pos;

    if( nb_segm <= 1 )
    if( aCornerList.size() <= 1 )
        return;

    set_current_line_width( width );
    set_current_line_width( aWidth );

    pos.x = coord[0];
    pos.y = coord[1];
    wxPoint pos = aCornerList[0];
    user_to_device_coordinates( pos );
    fprintf( output_file, "newpath\n%d %d moveto\n", pos.x, pos.y );

    for( int ii = 1; ii < nb_segm; ii++ )
    for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
    {
        pos.x = coord[2 * ii];
        pos.y = coord[2 * ii + 1];
        pos = aCornerList[ii];
        user_to_device_coordinates( pos );
        fprintf( output_file, "%d %d lineto\n", pos.x, pos.y );
    }

    // Close path
    fprintf( output_file, "poly%d\n", fill );
    fprintf( output_file, "poly%d\n", aFill );
}


@@ -445,7 +438,8 @@ void PS_PLOTTER::flash_pad_circle( wxPoint pos, int diametre,
void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
                                 int orient, GRTraceMode trace_mode )
{
    wxASSERT( output_file );
    static std::vector< wxPoint > cornerList;
    cornerList.clear();

    set_current_line_width( -1 );
    int w = current_pen_width;
@@ -459,23 +453,28 @@ void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
    int dx = size.x / 2;
    int dy = size.y / 2;

    int coord[10] =
    {
        pos.x - dx, pos.y + dy,
        pos.x - dx, pos.y - dy,
        pos.x + dx, pos.y - dy,
        pos.x + dx, pos.y + dy,
        0,          0
    };

    for( int ii = 0; ii < 4; ii++ )
    {
        RotatePoint( &coord[ii * 2], &coord[ii * 2 + 1], pos.x, pos.y, orient );
    wxPoint corner;
    corner.x = pos.x - dx;
    corner.y = pos.y + dy;
    cornerList.push_back( corner );
    corner.x = pos.x - dx;
    corner.y = pos.y - dy;
    cornerList.push_back( corner );
    corner.x = pos.x + dx;
    corner.y = pos.y - dy;
    cornerList.push_back( corner );
    corner.x = pos.x + dx;
    corner.y = pos.y + dy,
    cornerList.push_back( corner );

    for( unsigned ii = 0; ii < cornerList.size(); ii++ )
    {
        RotatePoint( &cornerList[ii], pos, orient );
    }

    coord[8] = coord[0];
    coord[9] = coord[1];
    poly( 5, coord, ( trace_mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
    cornerList.push_back( cornerList[0] );

    PlotPoly( cornerList, ( trace_mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
}


@@ -487,11 +486,11 @@ void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
void PS_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4],
                                     int aPadOrient, GRTraceMode aTrace_Mode )
{
    wxASSERT( output_file );
    wxPoint coord[5];
    static std::vector< wxPoint > cornerList;
    cornerList.clear();

    for( int ii = 0; ii < 4; ii++ )
        coord[ii] = aCorners[ii];
        cornerList.push_back( aCorners[ii] );

    if( aTrace_Mode == FILLED )
    {
@@ -508,22 +507,22 @@ void PS_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4],
        // coord[3] is assumed the lower right

        /* Trace the outline. */
        coord[0].x += w;
        coord[0].y -= w;
        coord[1].x += w;
        coord[1].y += w;
        coord[2].x -= w;
        coord[2].y += w;
        coord[3].x -= w;
        coord[3].y -= w;
        cornerList[0].x += w;
        cornerList[0].y -= w;
        cornerList[1].x += w;
        cornerList[1].y += w;
        cornerList[2].x -= w;
        cornerList[2].y += w;
        cornerList[3].x -= w;
        cornerList[3].y -= w;
    }

    for( int ii = 0; ii < 4; ii++ )
    {
        RotatePoint( &coord[ii], aPadOrient );
        coord[ii] += aPadPos;
        RotatePoint( &cornerList[ii], aPadOrient );
        cornerList[ii] += aPadPos;
    }

    coord[4] = coord[0];
    poly( 5, &coord[0].x, ( aTrace_Mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
    cornerList.push_back( cornerList[0] );
    PlotPoly( cornerList, ( aTrace_Mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
}
Loading