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

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

parent dcccaee2
...@@ -100,47 +100,53 @@ double PLOTTER::user_to_device_size( double size ) ...@@ -100,47 +100,53 @@ double PLOTTER::user_to_device_size( double size )
void PLOTTER::center_square( const wxPoint& position, int diametre, FILL_T fill ) void PLOTTER::center_square( const wxPoint& position, int diametre, FILL_T fill )
{ {
int radius = wxRound( diametre / 2.8284 ); int radius = wxRound( diametre / 2.8284 );
int coord[10] = static std::vector< wxPoint > corner_list;
{ corner_list.clear();
position.x + radius, position.y + radius, wxPoint corner;
position.x + radius, position.y - radius, corner.x = position.x + radius;
position.x - radius, position.y - radius, corner.y = position.y + radius;
position.x - radius, position.y + radius, corner_list.push_back( corner );
position.x + radius, position.y + radius corner.x = position.x + radius;
}; corner.y = position.y - radius;
corner_list.push_back( corner );
if( fill ) corner.x = position.x - radius;
{ corner.y = position.y - radius;
poly( 4, coord, fill ); corner_list.push_back( corner );
} corner.x = position.x - radius;
else corner.y = position.y + radius;
{ corner_list.push_back( corner );
poly( 5, coord, fill ); 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, void PLOTTER::center_lozenge( const wxPoint& position, int diametre, FILL_T fill )
FILL_T fill )
{ {
int radius = diametre / 2; int radius = diametre / 2;
int coord[10] = static std::vector< wxPoint > corner_list;
{ corner_list.clear();
position.x, position.y + radius, wxPoint corner;
position.x + radius, position.y, corner.x = position.x;
position.x, position.y - radius, corner.y = position.y + radius;
position.x - radius, position.y, corner_list.push_back( corner );
position.x, position.y + radius, corner.x = position.x + radius;
}; corner.y = position.y,
corner_list.push_back( corner );
if( fill ) corner.x = position.x;
{ corner.y = position.y - radius;
poly( 4, coord, fill ); corner_list.push_back( corner );
} corner.x = position.x - radius;
else corner.y = position.y;
{ corner_list.push_back( corner );
poly( 5, coord, fill ); corner.x = position.x;
} corner.y = position.y + radius;
corner_list.push_back( corner );
PlotPoly( corner_list, fill );
} }
......
...@@ -115,27 +115,25 @@ void DXF_PLOTTER::circle( wxPoint centre, int diameter, FILL_T fill, int width ) ...@@ -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 /* Draw a polygon (closed if filled) in DXF format
* coord = coord table tops
* nb = number of coord (coord 1 = 2 elements: X and Y table) * 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( aCornerList.size() <= 1 )
if( nb <= 1 )
return; return;
move_to( wxPoint( coord[0], coord[1] ) ); move_to( aCornerList[0] );
for( int ii = 1; ii < nb; ii++ ) for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
line_to( wxPoint( coord[ii * 2], coord[(ii * 2) + 1] ) ); line_to( aCornerList[ii] );
/* Close polygon. */ /* Close polygon. */
if( fill ) if( aFill )
{ {
int ii = (nb - 1) * 2; unsigned ii = aCornerList.size() - 1;
if( ( coord[ii] != coord[0] ) || ( coord[ii + 1] != coord[1] ) ) if( aCornerList[ii] != aCornerList[0] )
line_to( wxPoint( coord[0], coord[1] ) ); line_to( aCornerList[0] );
} }
pen_finish(); pen_finish();
} }
......
...@@ -248,16 +248,20 @@ void GERBER_PLOTTER::pen_to( wxPoint aPos, char plume ) ...@@ -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 ) void GERBER_PLOTTER::rect( wxPoint p1, wxPoint p2, FILL_T fill, int width )
{ {
wxASSERT( output_file ); static std::vector< wxPoint > cornerList;
int coord[10] = cornerList.clear();
{
p1.x, p1.y, // Build corners list
p1.x, p2.y, cornerList.push_back( p1 );
p2.x, p2.y, wxPoint corner(p1.x, p2.y);
p2.x, p1.y, cornerList.push_back( corner );
p1.x, p1.y cornerList.push_back( p2 );
}; corner.x = p2.x;
poly( 5, coord, fill, width ); 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, ...@@ -296,34 +300,31 @@ void GERBER_PLOTTER::circle( wxPoint aCentre, int aDiameter, FILL_T aFill,
/** /**
* Function PlotFilledPolygon_GERBER * Function PlotPoly
* writes a filled polyline to output file * writes a filled or not filled polyline to output file
* @param aCornersCount = number of corners
* @param aCoord = buffer of corners coordinates * @param aCoord = buffer of corners coordinates
* @param aFill = plot option (NO_FILL, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR) * @param aFill = plot option (NO_FILL, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR)
* @param aWidth = Width of the line to plot. * @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 ); if( aCornerList.size() <= 1 )
wxPoint pos, startpos; return;
set_current_line_width( aWidth ); set_current_line_width( aWidth );
if( aFill ) if( aFill )
fputs( "G36*\n", output_file ); fputs( "G36*\n", output_file );
startpos.x = *aCoord++;
startpos.y = *aCoord++; move_to( aCornerList[0] );
move_to( startpos ); for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
for( int ii = 1; ii < aCornersCount; ii++ )
{ {
pos.x = *aCoord++; line_to( aCornerList[ii] );
pos.y = *aCoord++;
line_to( pos );
} }
if( aFill ) if( aFill )
{ {
finish_to( startpos ); finish_to( aCornerList[0] );
fputs( "G37*\n", output_file ); fputs( "G37*\n", output_file );
} }
else else
...@@ -488,22 +489,25 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size, ...@@ -488,22 +489,25 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
int aPadOrient, GRTraceMode aTrace_Mode ) 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];
/* Draw the polygon and fill the interior as required. */
for( int ii = 0; ii < 4; ii++ ) for( int ii = 0; ii < 4; ii++ )
cornerList.push_back( aCorners[ii] );
/* Draw the polygon and fill the interior as required. */
for( unsigned ii = 0; ii < 4; ii++ )
{ {
RotatePoint( &polygon[ii], aPadOrient ); RotatePoint( &cornerList[ii], aPadOrient );
polygon[ii] += aPadPos; cornerList[ii] += aPadPos;
} }
// Close the polygon // Close the polygon
polygon[4] = polygon[0]; cornerList.push_back( cornerList[0] );
set_current_line_width( -1 ); 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 ) void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )
......
...@@ -75,26 +75,24 @@ void HPGL_PLOTTER::circle( wxPoint centre, ...@@ -75,26 +75,24 @@ void HPGL_PLOTTER::circle( wxPoint centre,
/* Plot a polygon (closed if completed) in HPGL /* Plot a polygon (closed if completed) in HPGL
* Coord = coord table tops * aCornerList = a wxPoint list of corner
* Nb = number of coord (coord 1 = 2 elements: X and Y table) * aFill: if != 0 filled polygon
* Fill: 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( aCornerList.size() <= 1 )
if( nb <= 1 )
return; return;
move_to( wxPoint( coord[0], coord[1] ) ); move_to( aCornerList[0] );
for( int ii = 1; ii < nb; ii++ ) for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
line_to( wxPoint( coord[ii * 2], coord[(ii * 2) + 1] ) ); line_to( aCornerList[ii] );
/* Close polygon if filled. */ /* Close polygon if filled. */
if( fill ) if( aFill )
{ {
int ii = (nb - 1) * 2; int ii = aCornerList.size() - 1;
if( (coord[ii] != coord[0] ) || (coord[ii + 1] != coord[1]) ) if( aCornerList[ii] != aCornerList[0] )
line_to( wxPoint( coord[0], coord[1] ) ); line_to( aCornerList[0] );
} }
pen_finish(); pen_finish();
} }
......
...@@ -168,40 +168,33 @@ void PS_PLOTTER::arc( wxPoint centre, int StAngle, int EndAngle, int radius, ...@@ -168,40 +168,33 @@ void PS_PLOTTER::arc( wxPoint centre, int StAngle, int EndAngle, int radius,
} }
/** /*
* Function poly * Function PlotPoly
* @brief Draw a polygon ( a filled polygon if fill == 1 ) in POSTSCRIPT format * Draw a polygon (filled or not) in POSTSCRIPT format
* @param nb_segm = corner count * param aCornerList = corners list
* @param coord = corner list (a corner uses 2 int = X coordinate followed by Y * param aFill :if true : filled polygon
* coordinate * param aWidth = line width
* @param fill :if true : filled polygon
* @param width = 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 ); if( aCornerList.size() <= 1 )
wxPoint pos;
if( nb_segm <= 1 )
return; return;
set_current_line_width( width ); set_current_line_width( aWidth );
pos.x = coord[0]; wxPoint pos = aCornerList[0];
pos.y = coord[1];
user_to_device_coordinates( pos ); user_to_device_coordinates( pos );
fprintf( output_file, "newpath\n%d %d moveto\n", pos.x, pos.y ); 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 = aCornerList[ii];
pos.y = coord[2 * ii + 1];
user_to_device_coordinates( pos ); user_to_device_coordinates( pos );
fprintf( output_file, "%d %d lineto\n", pos.x, pos.y ); fprintf( output_file, "%d %d lineto\n", pos.x, pos.y );
} }
// Close path // 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, ...@@ -445,7 +438,8 @@ void PS_PLOTTER::flash_pad_circle( wxPoint pos, int diametre,
void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size, void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
int orient, GRTraceMode trace_mode ) int orient, GRTraceMode trace_mode )
{ {
wxASSERT( output_file ); static std::vector< wxPoint > cornerList;
cornerList.clear();
set_current_line_width( -1 ); set_current_line_width( -1 );
int w = current_pen_width; int w = current_pen_width;
...@@ -459,23 +453,28 @@ void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size, ...@@ -459,23 +453,28 @@ void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
int dx = size.x / 2; int dx = size.x / 2;
int dy = size.y / 2; int dy = size.y / 2;
int coord[10] = wxPoint corner;
{ corner.x = pos.x - dx;
pos.x - dx, pos.y + dy, corner.y = pos.y + dy;
pos.x - dx, pos.y - dy, cornerList.push_back( corner );
pos.x + dx, pos.y - dy, corner.x = pos.x - dx;
pos.x + dx, pos.y + dy, corner.y = pos.y - dy;
0, 0 cornerList.push_back( corner );
}; corner.x = pos.x + dx;
corner.y = pos.y - dy;
for( int ii = 0; ii < 4; ii++ ) 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( &coord[ii * 2], &coord[ii * 2 + 1], pos.x, pos.y, orient ); RotatePoint( &cornerList[ii], pos, orient );
} }
coord[8] = coord[0]; cornerList.push_back( cornerList[0] );
coord[9] = coord[1];
poly( 5, coord, ( trace_mode == FILLED ) ? FILLED_SHAPE : NO_FILL ); PlotPoly( cornerList, ( trace_mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
} }
...@@ -487,11 +486,11 @@ void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size, ...@@ -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], void PS_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4],
int aPadOrient, GRTraceMode aTrace_Mode ) int aPadOrient, GRTraceMode aTrace_Mode )
{ {
wxASSERT( output_file ); static std::vector< wxPoint > cornerList;
wxPoint coord[5]; cornerList.clear();
for( int ii = 0; ii < 4; ii++ ) for( int ii = 0; ii < 4; ii++ )
coord[ii] = aCorners[ii]; cornerList.push_back( aCorners[ii] );
if( aTrace_Mode == FILLED ) if( aTrace_Mode == FILLED )
{ {
...@@ -508,22 +507,22 @@ void PS_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4], ...@@ -508,22 +507,22 @@ void PS_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4],
// coord[3] is assumed the lower right // coord[3] is assumed the lower right
/* Trace the outline. */ /* Trace the outline. */
coord[0].x += w; cornerList[0].x += w;
coord[0].y -= w; cornerList[0].y -= w;
coord[1].x += w; cornerList[1].x += w;
coord[1].y += w; cornerList[1].y += w;
coord[2].x -= w; cornerList[2].x -= w;
coord[2].y += w; cornerList[2].y += w;
coord[3].x -= w; cornerList[3].x -= w;
coord[3].y -= w; cornerList[3].y -= w;
} }
for( int ii = 0; ii < 4; ii++ ) for( int ii = 0; ii < 4; ii++ )
{ {
RotatePoint( &coord[ii], aPadOrient ); RotatePoint( &cornerList[ii], aPadOrient );
coord[ii] += aPadPos; cornerList[ii] += aPadPos;
} }
coord[4] = coord[0]; cornerList.push_back( cornerList[0] );
poly( 5, &coord[0].x, ( aTrace_Mode == FILLED ) ? FILLED_SHAPE : NO_FILL ); PlotPoly( cornerList, ( aTrace_Mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
} }
...@@ -204,31 +204,25 @@ void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, ...@@ -204,31 +204,25 @@ void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
{ {
wxASSERT( aPlotter != NULL ); wxASSERT( aPlotter != NULL );
size_t i; static std::vector< wxPoint > cornerList;
cornerList.clear();
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
if( Poly == NULL ) for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
return;
for( i = 0; i < m_PolyPoints.size(); i++ )
{ {
wxPoint pos = m_PolyPoints[i]; wxPoint pos = m_PolyPoints[ii];
pos = aTransform.TransformCoordinate( pos ) + aOffset; pos = aTransform.TransformCoordinate( pos ) + aOffset;
Poly[i * 2] = pos.x; cornerList.push_back( pos );
Poly[i * 2 + 1] = pos.y;
} }
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR ) if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{ {
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
aPlotter->poly( i, Poly, FILLED_WITH_BG_BODYCOLOR, 0 ); aPlotter->PlotPoly( cornerList, FILLED_WITH_BG_BODYCOLOR, 0 );
} }
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR; bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) ); aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
aPlotter->poly( i, Poly, already_filled ? NO_FILL : m_Fill, GetPenSize() ); aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, GetPenSize() );
MyFree( Poly );
} }
......
...@@ -194,32 +194,26 @@ void LIB_POLYLINE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill ...@@ -194,32 +194,26 @@ void LIB_POLYLINE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill
{ {
wxASSERT( aPlotter != NULL ); wxASSERT( aPlotter != NULL );
size_t i; static std::vector< wxPoint > cornerList;
cornerList.clear();
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() ); for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
if( Poly == NULL )
return;
for( i = 0; i < m_PolyPoints.size(); i++ )
{ {
wxPoint pos = m_PolyPoints[i]; wxPoint pos = m_PolyPoints[ii];
pos = aTransform.TransformCoordinate( pos ) + aOffset; pos = aTransform.TransformCoordinate( pos ) + aOffset;
Poly[i * 2] = pos.x; cornerList.push_back( pos );
Poly[i * 2 + 1] = pos.y;
} }
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR ) if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{ {
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
aPlotter->poly( i, Poly, FILLED_WITH_BG_BODYCOLOR, 0 ); aPlotter->PlotPoly( cornerList, FILLED_WITH_BG_BODYCOLOR, 0 );
aFill = false; // body is now filled, do not fill it later. aFill = false; // body is now filled, do not fill it later.
} }
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR; bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) ); aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
aPlotter->poly( i, Poly, already_filled ? NO_FILL : m_Fill, GetPenSize() ); aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, GetPenSize() );
MyFree( Poly );
} }
......
...@@ -298,7 +298,7 @@ static void PlotTextStruct( PLOTTER* plotter, SCH_TEXT* aSchText ) ...@@ -298,7 +298,7 @@ static void PlotTextStruct( PLOTTER* plotter, SCH_TEXT* aSchText )
/* Draw graphic symbol for global or hierarchical labels */ /* Draw graphic symbol for global or hierarchical labels */
aSchText->CreateGraphicShape( Poly, aSchText->m_Pos ); aSchText->CreateGraphicShape( Poly, aSchText->m_Pos );
if( Poly.size() ) if( Poly.size() )
plotter->poly( Poly.size(), &Poly[0].x, NO_FILL ); plotter->PlotPoly( Poly, NO_FILL );
} }
......
...@@ -98,8 +98,16 @@ public: PLOTTER( PlotFormat aPlotType ); ...@@ -98,8 +98,16 @@ public: PLOTTER( PlotFormat aPlotType );
int width = -1 ) = 0; int width = -1 ) = 0;
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon, virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
FILL_T fill, int width = -1 ); FILL_T fill, int width = -1 );
virtual void poly( int nb_segm, int* coord, FILL_T fill,
int width = -1 ) = 0; /**
* Function PlotPoly
* @brief Draw a polygon ( filled or not )
* @param aCornerList = corners list
* @param aFill :if true : filled polygon
* @param aWidth = line width
*/
virtual void PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth = -1 ) = 0;
virtual void thick_segment( wxPoint start, wxPoint end, int width, virtual void thick_segment( wxPoint start, wxPoint end, int width,
GRTraceMode tracemode ); GRTraceMode tracemode );
virtual void thick_arc( wxPoint centre, int StAngle, int EndAngle, int rayon, virtual void thick_arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
...@@ -261,7 +269,15 @@ public: HPGL_PLOTTER() : PLOTTER( PLOT_FORMAT_HPGL ) ...@@ -261,7 +269,15 @@ public: HPGL_PLOTTER() : PLOTTER( PLOT_FORMAT_HPGL )
virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror ); virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 ); virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 ); virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
virtual void poly( int nb_segm, int* coord, FILL_T fill, int width = -1 ); /*
* Function PlotPoly
* Draw a polygon (filled or not) in HPGL format
* param aCornerList = corners list
* param aFill :if true : filled polygon
* param aWidth = line width
*/
virtual void PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth = -1);
virtual void thick_segment( wxPoint start, wxPoint end, int width, virtual void thick_segment( wxPoint start, wxPoint end, int width,
GRTraceMode tracemode ); GRTraceMode tracemode );
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon, virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
...@@ -317,7 +333,15 @@ public: PS_PLOTTER() : PLOTTER( PLOT_FORMAT_POST ) ...@@ -317,7 +333,15 @@ public: PS_PLOTTER() : PLOTTER( PLOT_FORMAT_POST )
virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 ); virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon, virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
FILL_T fill, int width = -1 ); FILL_T fill, int width = -1 );
virtual void poly( int nb_segm, int* coord, FILL_T fill, int width = -1 ); /*
* 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
*/
virtual void PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth = -1);
virtual void pen_to( wxPoint pos, char plume ); virtual void pen_to( wxPoint pos, char plume );
virtual void flash_pad_circle( wxPoint pos, int diametre, virtual void flash_pad_circle( wxPoint pos, int diametre,
GRTraceMode trace_mode ); GRTraceMode trace_mode );
...@@ -376,7 +400,15 @@ public: GERBER_PLOTTER() : PLOTTER( PLOT_FORMAT_GERBER ) ...@@ -376,7 +400,15 @@ public: GERBER_PLOTTER() : PLOTTER( PLOT_FORMAT_GERBER )
virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror ); virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 ); virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 ); virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
virtual void poly( int nb_segm, int* coord, FILL_T fill, int width = -1 ); /*
* Function PlotPoly
* Draw a polygon (filled or not) in GERBER format
* param aCornerList = corners list
* param aFill :if true : filled polygon
* param aWidth = line width
*/
virtual void PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth = -1);
virtual void pen_to( wxPoint pos, char plume ); virtual void pen_to( wxPoint pos, char plume );
virtual void flash_pad_circle( wxPoint pos, int diametre, virtual void flash_pad_circle( wxPoint pos, int diametre,
GRTraceMode trace_mode ); GRTraceMode trace_mode );
...@@ -436,7 +468,15 @@ public: DXF_PLOTTER() : PLOTTER( PLOT_FORMAT_DXF ) ...@@ -436,7 +468,15 @@ public: DXF_PLOTTER() : PLOTTER( PLOT_FORMAT_DXF )
virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror ); virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 ); virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 ); virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
virtual void poly( int nb_segm, int* coord, FILL_T fill, int width = -1 ); /*
* Function PlotPoly
* Draw a polygon (filled or not) in DXF format
* param aCornerList = corners list
* param aFill :if true : filled polygon
* param aWidth = line width
*/
virtual void PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth = -1 );
virtual void thick_segment( wxPoint start, wxPoint end, int width, virtual void thick_segment( wxPoint start, wxPoint end, int width,
GRTraceMode tracemode ); GRTraceMode tracemode );
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon, virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
......
...@@ -430,40 +430,34 @@ void Plot_1_EdgeModule( PLOTTER* plotter, EDGE_MODULE* PtEdge, ...@@ -430,40 +430,34 @@ void Plot_1_EdgeModule( PLOTTER* plotter, EDGE_MODULE* PtEdge,
case S_POLYGON: case S_POLYGON:
{ {
if( PtEdge->m_PolyPoints.size() <= 1 ) // Malformed polygon
break;
// We must compute true coordinates from m_PolyList // We must compute true coordinates from m_PolyList
// which are relative to module position, orientation 0 // which are relative to module position, orientation 0
MODULE* Module = NULL; MODULE* Module = NULL;
if( PtEdge->GetParent() && (PtEdge->GetParent()->Type() == TYPE_MODULE) ) if( PtEdge->GetParent() && (PtEdge->GetParent()->Type() == TYPE_MODULE) )
Module = (MODULE*) PtEdge->GetParent(); Module = (MODULE*) PtEdge->GetParent();
int* ptr_base = static std::vector< wxPoint > cornerList;
(int*) MyMalloc( 2 * PtEdge->m_PolyPoints.size() * sizeof(int) ); cornerList.clear();
int* ptr = ptr_base;
int* source = (int*) &PtEdge->m_PolyPoints[0];
for( unsigned ii = 0; ii < PtEdge->m_PolyPoints.size(); ii++ ) for( unsigned ii = 0; ii < PtEdge->m_PolyPoints.size(); ii++ )
{ {
int x = *source++; wxPoint corner = PtEdge->m_PolyPoints[0];
int y = *source++;
if( Module ) if( Module )
{ {
RotatePoint( &x, &y, Module->m_Orient ); RotatePoint( &corner, Module->m_Orient );
x += Module->m_Pos.x; corner += Module->m_Pos;
y += Module->m_Pos.y;
} }
x += PtEdge->m_Start0.x; corner += PtEdge->m_Start0;
y += PtEdge->m_Start0.y;
*ptr++ = x; cornerList.push_back( corner );
*ptr++ = y;
} }
plotter->poly( PtEdge->m_PolyPoints.size(), ptr_base, FILLED_SHAPE, plotter->PlotPoly( cornerList, FILLED_SHAPE, thickness );
thickness );
free( ptr_base );
} }
break; break;
} }
...@@ -532,30 +526,13 @@ void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer, ...@@ -532,30 +526,13 @@ void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer,
void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
GRTraceMode trace_mode ) GRTraceMode trace_mode )
{ {
static int* CornersBuffer = NULL;
static unsigned CornersBufferSize = 0;
unsigned imax = aZone->m_FilledPolysList.size(); unsigned imax = aZone->m_FilledPolysList.size();
if( imax == 0 ) // Nothing to draw if( imax == 0 ) // Nothing to draw
return; return;
// We need a buffer to store corners coordinates: // We need a buffer to store corners coordinates:
static std::vector< wxPoint > cornerList;
imax++; // provide room to sore an extra coordinate to close the polygon cornerList.clear();
if( CornersBuffer == NULL )
{
CornersBufferSize = imax * 2;
CornersBuffer = (int*) MyMalloc( CornersBufferSize * sizeof(int) );
}
if( (imax * 4) > CornersBufferSize )
{
CornersBufferSize = imax * 2;
CornersBuffer = (int*) realloc( CornersBuffer,
CornersBufferSize * sizeof(int) );
}
imax--;
/* Plot all filled areas: filled areas have a filled area and a thick /* Plot all filled areas: filled areas have a filled area and a thick
* outline we must plot the filled area itself ( as a filled polygon * outline we must plot the filled area itself ( as a filled polygon
...@@ -563,22 +540,16 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, ...@@ -563,22 +540,16 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
* *
* in non filled mode the outline is plotted, but not the filling items * in non filled mode the outline is plotted, but not the filling items
*/ */
int corners_count = 0; for( unsigned ic = 0; ic < imax; ic++ )
for( unsigned ic = 0, ii = 0; ic < imax; ic++ )
{ {
CPolyPt* corner = &aZone->m_FilledPolysList[ic]; CPolyPt* corner = &aZone->m_FilledPolysList[ic];
CornersBuffer[ii++] = corner->x; cornerList.push_back( wxPoint( corner->x, corner->y) );
CornersBuffer[ii++] = corner->y;
corners_count++;
if( corner->end_contour ) // Plot the current filled area outline if( corner->end_contour ) // Plot the current filled area outline
{ {
// First, close the outline // First, close the outline
if( CornersBuffer[0] != CornersBuffer[ii - 2] if( cornerList[0] != cornerList[cornerList.size() - 1] )
|| CornersBuffer[1] != CornersBuffer[ii - 1] )
{ {
CornersBuffer[ii++] = CornersBuffer[0]; cornerList.push_back( cornerList[0] );
CornersBuffer[ii] = CornersBuffer[1];
corners_count++;
} }
// Plot the current filled area and its outline // Plot the current filled area and its outline
...@@ -587,9 +558,9 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, ...@@ -587,9 +558,9 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
// Plot the current filled area polygon // Plot the current filled area polygon
if( aZone->m_FillMode == 0 ) // We are using solid polygons if( aZone->m_FillMode == 0 ) // We are using solid polygons
// (if != 0: using segments ) // (if != 0: using segments )
plotter->poly( corners_count, CornersBuffer, FILLED_SHAPE ); plotter->PlotPoly( cornerList, FILLED_SHAPE );
else // We are using areas filled by else // We are using areas filled by
// segments: plot hem ) // segments: plot them )
{ {
for( unsigned iseg = 0; for( unsigned iseg = 0;
iseg < aZone->m_FillSegmList.size(); iseg < aZone->m_FillSegmList.size();
...@@ -606,26 +577,20 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, ...@@ -606,26 +577,20 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
// Plot the current filled area outline // Plot the current filled area outline
if( aZone->m_ZoneMinThickness > 0 ) if( aZone->m_ZoneMinThickness > 0 )
plotter->poly( corners_count, CornersBuffer, NO_FILL, plotter->PlotPoly( cornerList, NO_FILL, aZone->m_ZoneMinThickness );
aZone->m_ZoneMinThickness );
} }
else else
{ {
if( aZone->m_ZoneMinThickness > 0 ) if( aZone->m_ZoneMinThickness > 0 )
{ {
for( int ii = 1; ii<corners_count; ii++ ) for( unsigned jj = 1; jj<cornerList.size(); jj++ )
plotter->thick_segment( plotter->thick_segment(cornerList[jj -1], cornerList[jj],
wxPoint( CornersBuffer[ii * 2 - 2],
CornersBuffer[ii * 2 - 1] ),
wxPoint( CornersBuffer[ii * 2],
CornersBuffer[ii * 2 + 1] ),
( trace_mode == FILAIRE ) ? -1 : aZone->m_ZoneMinThickness, ( trace_mode == FILAIRE ) ? -1 : aZone->m_ZoneMinThickness,
trace_mode ); trace_mode );
} }
plotter->set_current_line_width( -1 ); plotter->set_current_line_width( -1 );
} }
corners_count = 0; cornerList.clear();
ii = 0;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment