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 )
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 );
}
......
......@@ -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();
}
......
......@@ -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];
/* Draw the polygon and fill the interior as required. */
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 );
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 )
......
......@@ -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();
}
......
......@@ -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++ )
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( &coord[ii * 2], &coord[ii * 2 + 1], pos.x, pos.y, orient );
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 );
}
......@@ -204,31 +204,25 @@ void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
{
wxASSERT( aPlotter != NULL );
size_t i;
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
static std::vector< wxPoint > cornerList;
cornerList.clear();
if( Poly == NULL )
return;
for( i = 0; i < m_PolyPoints.size(); i++ )
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
{
wxPoint pos = m_PolyPoints[i];
wxPoint pos = m_PolyPoints[ii];
pos = aTransform.TransformCoordinate( pos ) + aOffset;
Poly[i * 2] = pos.x;
Poly[i * 2 + 1] = pos.y;
cornerList.push_back( pos );
}
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
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;
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
aPlotter->poly( i, Poly, already_filled ? NO_FILL : m_Fill, GetPenSize() );
MyFree( Poly );
aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, GetPenSize() );
}
......
......@@ -194,32 +194,26 @@ void LIB_POLYLINE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill
{
wxASSERT( aPlotter != NULL );
size_t i;
static std::vector< wxPoint > cornerList;
cornerList.clear();
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
if( Poly == NULL )
return;
for( i = 0; i < m_PolyPoints.size(); i++ )
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
{
wxPoint pos = m_PolyPoints[i];
wxPoint pos = m_PolyPoints[ii];
pos = aTransform.TransformCoordinate( pos ) + aOffset;
Poly[i * 2] = pos.x;
Poly[i * 2 + 1] = pos.y;
cornerList.push_back( pos );
}
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
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.
}
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
aPlotter->poly( i, Poly, already_filled ? NO_FILL : m_Fill, GetPenSize() );
MyFree( Poly );
aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, GetPenSize() );
}
......
......@@ -298,7 +298,7 @@ static void PlotTextStruct( PLOTTER* plotter, SCH_TEXT* aSchText )
/* Draw graphic symbol for global or hierarchical labels */
aSchText->CreateGraphicShape( Poly, aSchText->m_Pos );
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 );
int width = -1 ) = 0;
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
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,
GRTraceMode tracemode );
virtual void thick_arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
......@@ -261,7 +269,15 @@ public: HPGL_PLOTTER() : PLOTTER( PLOT_FORMAT_HPGL )
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 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,
GRTraceMode tracemode );
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
......@@ -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 arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
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 flash_pad_circle( wxPoint pos, int diametre,
GRTraceMode trace_mode );
......@@ -376,7 +400,15 @@ public: GERBER_PLOTTER() : PLOTTER( PLOT_FORMAT_GERBER )
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 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 flash_pad_circle( wxPoint pos, int diametre,
GRTraceMode trace_mode );
......@@ -436,7 +468,15 @@ public: DXF_PLOTTER() : PLOTTER( PLOT_FORMAT_DXF )
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 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,
GRTraceMode tracemode );
virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
......
......@@ -430,40 +430,34 @@ void Plot_1_EdgeModule( PLOTTER* plotter, EDGE_MODULE* PtEdge,
case S_POLYGON:
{
if( PtEdge->m_PolyPoints.size() <= 1 ) // Malformed polygon
break;
// We must compute true coordinates from m_PolyList
// which are relative to module position, orientation 0
MODULE* Module = NULL;
if( PtEdge->GetParent() && (PtEdge->GetParent()->Type() == TYPE_MODULE) )
Module = (MODULE*) PtEdge->GetParent();
int* ptr_base =
(int*) MyMalloc( 2 * PtEdge->m_PolyPoints.size() * sizeof(int) );
int* ptr = ptr_base;
int* source = (int*) &PtEdge->m_PolyPoints[0];
static std::vector< wxPoint > cornerList;
cornerList.clear();
for( unsigned ii = 0; ii < PtEdge->m_PolyPoints.size(); ii++ )
{
int x = *source++;
int y = *source++;
wxPoint corner = PtEdge->m_PolyPoints[0];
if( Module )
{
RotatePoint( &x, &y, Module->m_Orient );
x += Module->m_Pos.x;
y += Module->m_Pos.y;
RotatePoint( &corner, Module->m_Orient );
corner += Module->m_Pos;
}
x += PtEdge->m_Start0.x;
y += PtEdge->m_Start0.y;
corner += PtEdge->m_Start0;
*ptr++ = x;
*ptr++ = y;
cornerList.push_back( corner );
}
plotter->poly( PtEdge->m_PolyPoints.size(), ptr_base, FILLED_SHAPE,
thickness );
free( ptr_base );
plotter->PlotPoly( cornerList, FILLED_SHAPE, thickness );
}
break;
}
......@@ -532,30 +526,13 @@ void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer,
void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
GRTraceMode trace_mode )
{
static int* CornersBuffer = NULL;
static unsigned CornersBufferSize = 0;
unsigned imax = aZone->m_FilledPolysList.size();
if( imax == 0 ) // Nothing to draw
return;
// We need a buffer to store corners coordinates:
imax++; // provide room to sore an extra coordinate to close the polygon
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--;
static std::vector< wxPoint > cornerList;
cornerList.clear();
/* 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
......@@ -563,22 +540,16 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
*
* in non filled mode the outline is plotted, but not the filling items
*/
int corners_count = 0;
for( unsigned ic = 0, ii = 0; ic < imax; ic++ )
for( unsigned ic = 0; ic < imax; ic++ )
{
CPolyPt* corner = &aZone->m_FilledPolysList[ic];
CornersBuffer[ii++] = corner->x;
CornersBuffer[ii++] = corner->y;
corners_count++;
cornerList.push_back( wxPoint( corner->x, corner->y) );
if( corner->end_contour ) // Plot the current filled area outline
{
// First, close the outline
if( CornersBuffer[0] != CornersBuffer[ii - 2]
|| CornersBuffer[1] != CornersBuffer[ii - 1] )
if( cornerList[0] != cornerList[cornerList.size() - 1] )
{
CornersBuffer[ii++] = CornersBuffer[0];
CornersBuffer[ii] = CornersBuffer[1];
corners_count++;
cornerList.push_back( cornerList[0] );
}
// Plot the current filled area and its outline
......@@ -587,9 +558,9 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
// Plot the current filled area polygon
if( aZone->m_FillMode == 0 ) // We are using solid polygons
// (if != 0: using segments )
plotter->poly( corners_count, CornersBuffer, FILLED_SHAPE );
plotter->PlotPoly( cornerList, FILLED_SHAPE );
else // We are using areas filled by
// segments: plot hem )
// segments: plot them )
{
for( unsigned iseg = 0;
iseg < aZone->m_FillSegmList.size();
......@@ -606,26 +577,20 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone,
// Plot the current filled area outline
if( aZone->m_ZoneMinThickness > 0 )
plotter->poly( corners_count, CornersBuffer, NO_FILL,
aZone->m_ZoneMinThickness );
plotter->PlotPoly( cornerList, NO_FILL, aZone->m_ZoneMinThickness );
}
else
{
if( aZone->m_ZoneMinThickness > 0 )
{
for( int ii = 1; ii<corners_count; ii++ )
plotter->thick_segment(
wxPoint( CornersBuffer[ii * 2 - 2],
CornersBuffer[ii * 2 - 1] ),
wxPoint( CornersBuffer[ii * 2],
CornersBuffer[ii * 2 + 1] ),
for( unsigned jj = 1; jj<cornerList.size(); jj++ )
plotter->thick_segment(cornerList[jj -1], cornerList[jj],
( trace_mode == FILAIRE ) ? -1 : aZone->m_ZoneMinThickness,
trace_mode );
}
plotter->set_current_line_width( -1 );
}
corners_count = 0;
ii = 0;
cornerList.clear();
}
}
}
......
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