Commit 0d790e57 authored by dickelbeck's avatar dickelbeck

polygon work, EDGE_MODULE::m_PolyPoints is now std::vector

parent fadacffc
......@@ -5,6 +5,17 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2008-Dec-29 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all
* gr_basic.h DOXYGEN comments. made a couple functions static and removed
those from gr_basic.h since they are private to gr_basic.c. changed the
polygon code to use wxPoints since that is what the underlying wxWidgets
API uses.
++gerbview
More work on drawing polygons, erasure still work in progress. Will
probably switch to ZONEs from SEG_ZONEs for polygons.
2008-Dec-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
......
......@@ -269,7 +269,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, wxDC* DC,
*(coordptr + 2), *(coordptr + 3), aWidth, aColor );
}
else
GRPoly( &aPanel->m_ClipBox, DC, ii / 2, coord, 0,
GRPoly( &aPanel->m_ClipBox, DC, ii / 2, (wxPoint*)coord, 0,
aWidth, aColor, aColor );
}
plume = f_cod; ii = 0;
......
......@@ -828,21 +828,19 @@ void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int
}
static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, int* Points )
static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, wxPoint Points[] )
{
int ii;
int Xmin, Xmax, Ymin, Ymax;
Xmin = Xmax = Points[0];
Ymin = Ymax = Points[1];
Xmin = Xmax = Points[0].x;
Ymin = Ymax = Points[0].y;
for( ii = 1; ii < n; ii++ ) // calcul du rectangle d'encadrement
for( int ii = 1; ii < n; ii++ ) // calcul du rectangle d'encadrement
{
int jj = ii * 2;
Xmin = MIN( Xmin, Points[jj] );
Xmax = MAX( Xmax, Points[jj] );
Ymin = MIN( Ymin, Points[jj + 1] );
Ymax = MAX( Ymax, Points[jj + 1] );
Xmin = MIN( Xmin, Points[ii].x );
Xmax = MAX( Xmax, Points[ii].x );
Ymin = MIN( Ymin, Points[ii].y );
Ymax = MAX( Ymax, Points[ii].y );
}
xcliplo = ClipBox->GetX();
......@@ -866,7 +864,7 @@ static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, int* Points )
/************************************************************************/
/* Routine to draw a new polyline and fill it if Fill, in screen space. */
/************************************************************************/
void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, bool Fill,
static void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[], bool Fill,
int width, int Color, int BgColor )
{
if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
......@@ -877,19 +875,19 @@ void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, bool Fill,
if( Fill && ( n > 2 ) )
{
GRSetBrush( DC, BgColor, FILLED );
DC->DrawPolygon( n, (wxPoint*) Points );
DC->DrawPolygon( n, Points );
}
else
{
int endx = Points[n * 2 - 2];
int endy = Points[n * 2 - 1];
wxPoint endPt = Points[n-1];
GRSetBrush( DC, Color );
DC->DrawLines( n, (wxPoint*) Points );
DC->DrawLines( n, Points );
// The last point is not drawn by DrawLine and DrawLines
// Add it if the polygon is not closed
if ( endx != Points[0] || endy != Points[1] )
DC->DrawPoint(endx, endy);
if( endPt != Points[0] )
DC->DrawPoint(endPt.x, endPt.y);
}
}
......@@ -897,61 +895,56 @@ void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, bool Fill,
/******************************************************************************/
/* Routine to draw a new closed polyline and fill it if Fill, in screen space */
/******************************************************************************/
void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
bool Fill, int Color, int BgColor )
{
GRSClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
}
void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
static void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int aPointCount, wxPoint aPoints[],
bool Fill, int width, int Color, int BgColor )
{
int startx, starty;
if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
if( !IsGRSPolyDrawable( ClipBox, aPointCount, aPoints ) )
return;
GRSetColorPen( DC, Color, width );
if( Fill && ( n > 2 ) )
if( Fill && ( aPointCount > 2 ) )
{
GRSMoveTo( Points[n * 2 - 2], Points[n * 2 - 1] );
GRSMoveTo( aPoints[aPointCount-1].x, aPoints[aPointCount-1].y );
GRSetBrush( DC, BgColor, FILLED );
DC->DrawPolygon( n, (wxPoint*) Points, 0, 0, wxODDEVEN_RULE );
DC->DrawPolygon( aPointCount, aPoints, 0, 0, wxODDEVEN_RULE );
}
else
{
startx = Points[n * 2 - 2]; starty = Points[n * 2 - 1];
GRSetBrush( DC, BgColor );
DC->DrawLines( n, (wxPoint*) Points );
DC->DrawLines( aPointCount, aPoints );
/* Fermeture du polygone */
if( (startx != Points[0]) || (starty != Points[1]) )
if( aPoints[aPointCount-1] != aPoints[0] )
{
GRSLine( ClipBox, DC, Points[0], Points[1], startx, starty, width, Color );
GRSLine( ClipBox, DC, aPoints[0].x, aPoints[0].y,
aPoints[aPointCount-1].x, aPoints[aPointCount-1].y, width, Color );
}
}
}
/* not used
static void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
bool Fill, int Color, int BgColor )
{
GRSClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
}
*/
/************************************************************************/
/* Routine to draw a new polyline and fill it if Fill, in drawing space. */
/************************************************************************/
void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
bool Fill, int width, int Color, int BgColor )
{
int ii, jj;
width = ZoomValue( width );
for( ii = 0; ii < n; ii++ )
for( int i=0; i<n; ++i )
{
jj = ii << 1;
Points[jj] = GRMapX( Points[jj] );
jj++;
Points[jj] = GRMapY( Points[jj] );
Points[i].x = GRMapX( Points[i].x );
Points[i].y = GRMapY( Points[i].y );
}
width = ZoomValue( width );
GRSPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
}
......@@ -959,27 +952,23 @@ void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
/**************************************************************************/
/* Routine to draw a closed polyline and fill it if Fill, in object space */
/**************************************************************************/
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
bool Fill, int Color, int BgColor )
{
GRClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
}
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
bool Fill, int width, int Color, int BgColor )
{
int ii, jj;
width = ZoomValue( width );
for( ii = 0; ii < n; ii++ )
for( int i=0; i<n; ++i )
{
jj = ii << 1;
Points[jj] = GRMapX( Points[jj] );
jj++;
Points[jj] = GRMapY( Points[jj] );
Points[i].x = GRMapX( Points[i].x );
Points[i].y = GRMapY( Points[i].y );
}
width = ZoomValue( width );
GRSClosedPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
}
......
......@@ -35,7 +35,8 @@
/*******************************************************************/
Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent,
const wxPoint& pos, const wxString& text ) :
const wxPoint& pos,
const wxString& text ) :
SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ),
EDA_TextStruct( text )
/*******************************************************************/
......@@ -76,16 +77,23 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
EDA_Colors txtcolor;
int posx, tposx, posy, size2;
wxSize size;
int NbSegm, coord[20];
int NbSegm;
// @todo use wxPoints here
int coord[20];
int LineWidth = g_DrawMinimunLineWidth;
if( Color >= 0 )
txtcolor = (EDA_Colors)Color;
txtcolor = (EDA_Colors) Color;
else
txtcolor = ReturnLayerColor( m_Layer );
GRSetDrawMode( DC, DrawMode );
posx = m_Pos.x + offset.x; posy = m_Pos.y + offset.y; size = m_Size;
posx = m_Pos.x + offset.x;
posy = m_Pos.y + offset.y;
size = m_Size;
if( !m_Text.IsEmpty() )
{
if( m_Edge )
......@@ -110,7 +118,10 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
size.y = -size.y;
}
coord[0] = posx; coord[1] = posy; size2 = size.x / 2;
coord[0] = posx;
coord[1] = posy;
size2 = size.x / 2;
NbSegm = 0;
switch( m_Shape )
......@@ -154,7 +165,8 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
}
int FillShape = FALSE;
GRPoly( &panel->m_ClipBox, DC, NbSegm, coord, FillShape, LineWidth, txtcolor, txtcolor ); /* Poly Non rempli */
GRPoly( &panel->m_ClipBox, DC, NbSegm, (wxPoint*) coord,
FillShape, LineWidth, txtcolor, txtcolor ); /* Poly Non rempli */
}
......@@ -202,6 +214,7 @@ bool Hierarchical_PIN_Sheet_Struct::Save( FILE* aFile ) const
return true;
}
#if defined(DEBUG)
void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
{
......@@ -214,7 +227,7 @@ void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
<< std::flush;
// NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
}
#endif
......@@ -393,15 +393,16 @@ void SCH_HIERLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offs
}
CreateGraphicShape( Poly, AnchorPos );
GRPoly( &panel->m_ClipBox, DC, Poly[0], Poly + 1, 0, width, color, color );
GRPoly( &panel->m_ClipBox, DC, Poly[0], (wxPoint*)(Poly + 1), 0, width, color, color );
if( m_IsDangling )
DrawDanglingSymbol( panel, DC, m_Pos + offset, color );
}
/** function CreateGraphicShape
* Calculates the graphic shape (a polygon) associated to the text
/**
* Function CreateGraphicShape
* calculates the graphic shape (a polygon) associated to the text
* @param corner_list = coordinates list fill with polygon corners ooordinates (size > 20)
* @param Pos = Postion of the shape
* format list is
......@@ -414,13 +415,14 @@ void SCH_HIERLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos )
int imax = *Template; Template++;
*corner_list = imax; corner_list++;
*corner_list++ = imax;
for( int ii = 0; ii < imax; ii++ )
{
*corner_list = ( HalfSize * (*Template) ) + Pos.x;
corner_list++; Template++;
*corner_list = ( HalfSize * (*Template) ) + Pos.y;
corner_list++; Template++;
*corner_list++ = ( HalfSize * (*Template) ) + Pos.x;
Template++;
*corner_list++ = ( HalfSize * (*Template) ) + Pos.y;
Template++;
}
}
......@@ -546,7 +548,7 @@ void SCH_GLOBALLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& dr
}
CreateGraphicShape( Poly, AnchorPos );
GRPoly( &panel->m_ClipBox, DC, Poly[0], Poly + 1, 0, width, color, color );
GRPoly( &panel->m_ClipBox, DC, Poly[0], (wxPoint*) (Poly + 1), 0, width, color, color );
if( m_IsDangling )
DrawDanglingSymbol( panel, DC, AnchorPos, color );
......
......@@ -281,14 +281,14 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
Buf_Poly_Drawings, 1, linewidth, color,
(wxPoint*) Buf_Poly_Drawings, 1, linewidth, color,
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE )
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
Buf_Poly_Drawings, 1, linewidth, color, color );
(wxPoint*) Buf_Poly_Drawings, 1, linewidth, color, color );
else
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
Buf_Poly_Drawings, 0, linewidth, color, color );
(wxPoint*) Buf_Poly_Drawings, 0, linewidth, color, color );
}
......
This diff is collapsed.
......@@ -113,12 +113,13 @@ void WinEDA_GerberFrame::Trace_Gerber( wxDC* DC, int draw_mode, int printmasklay
if( !m_Pcb )
return;
bool erase;
// Draw filled polygons
#define NBMAX 20000
int nbpoints = 0;
int nbpointsmax = NBMAX;
int* coord = (int*) malloc( nbpointsmax * sizeof(int) * 2 );
int* ptcoord = coord;
std::vector<wxPoint> coords;
// minimize reallocations of the vector's internal array by starting with a good sized one.
coords.reserve(20000);
for( TRACK* track = m_Pcb->m_Zone; track; track = track->Next() )
{
......@@ -127,36 +128,37 @@ void WinEDA_GerberFrame::Trace_Gerber( wxDC* DC, int draw_mode, int printmasklay
if( track->GetNet() == 0 ) // StartPoint
{
if( nbpoints ) // we have found a new polygon: Draw the old polygon
if( coords.size() ) // we have found a new polygon: Draw the old polygon
{
int Color = g_DesignSettings.m_LayerColor[track->GetLayer()];
int filled = (g_DisplayPolygonsModeSketch == 0) ? 1 : 0;
int Color;
int filled;
GRClosedPoly( &DrawPanel->m_ClipBox, DC, nbpoints, coord,
filled, Color, Color );
if( erase )
{
D(printf("erase\n");)
Color = g_DrawBgColor;
filled = true;
}
else
{
D(printf("NO erase\n");)
Color = g_DesignSettings.m_LayerColor[track->GetLayer()];
filled = (g_DisplayPolygonsModeSketch == 0) ? 1 : 0;
}
nbpoints = 2;
ptcoord = coord;
GRClosedPoly( &DrawPanel->m_ClipBox, DC, coords.size(), &coords[0],
filled, Color, Color );
}
*ptcoord++ = track->m_Start.x;
*ptcoord++ = track->m_Start.y;
erase = ( track->m_Flags & DRAW_ERASED ) ? true : false;
*ptcoord++ = track->m_End.x;
*ptcoord++ = track->m_End.y;
coords.clear();
coords.push_back( track->m_Start );
coords.push_back( track->m_End );
}
else
{
if( nbpoints >= nbpointsmax )
{
nbpointsmax *= 2;
coord = (int*) realloc( coord, nbpointsmax * sizeof(int) * 2 );
ptcoord = coord + nbpointsmax;
}
nbpoints++;
*ptcoord++ = track->m_End.x;
*ptcoord++ = track->m_End.y;
coords.push_back( track->m_End );
}
if( track->Next() == NULL ) // Last point
......@@ -164,13 +166,11 @@ void WinEDA_GerberFrame::Trace_Gerber( wxDC* DC, int draw_mode, int printmasklay
int Color = g_DesignSettings.m_LayerColor[track->GetLayer()];
int filled = (g_DisplayPolygonsModeSketch == 0) ? 1 : 0;
GRClosedPoly( &DrawPanel->m_ClipBox, DC, nbpoints, coord,
GRClosedPoly( &DrawPanel->m_ClipBox, DC, coords.size(), &coords[0],
filled, Color, Color );
}
}
free( coord );
// Draw tracks and flashes down here. This will probably not be a final solution to drawing order issues
Draw_Track_Buffer( DrawPanel, DC, m_Pcb, draw_mode, printmasklayer );
......
......@@ -64,7 +64,6 @@ void Trace_Segment( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* track, int draw_mo
int l_piste;
int color;
int zoom;
int rayon;
int fillopt;
static bool show_err;
......@@ -93,32 +92,35 @@ void Trace_Segment( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* track, int draw_mo
zoom = panel->GetZoom();
rayon = l_piste = track->m_Width >> 1;
fillopt = DisplayOpt.DisplayPcbTrackFill ? FILLED : SKETCH;
switch( track->m_Shape )
{
case S_CIRCLE:
rayon = (int) hypot( (double) (track->m_End.x - track->m_Start.x),
{
int radius = (int) hypot( (double) (track->m_End.x - track->m_Start.x),
(double) (track->m_End.y - track->m_Start.y) );
if( (l_piste / zoom) < L_MIN_DESSIN )
int halfPenWidth = track->m_Width >> 1;
if( (halfPenWidth / zoom) < L_MIN_DESSIN )
{
GRCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon, 0, color );
radius, 0, color );
}
if( fillopt == SKETCH )
{
// draw the border of the pen's path using two circles, each as narrow as possible
GRCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon - l_piste, 0, color );
radius - halfPenWidth, 0, color );
GRCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon + l_piste, 0, color );
radius + halfPenWidth, 0, color );
}
else
{
GRCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon, track->m_Width, color );
radius, track->m_Width, color );
}
}
break;
......@@ -139,26 +141,33 @@ void Trace_Segment( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* track, int draw_mo
break;
case S_SPOT_CIRCLE:
{
int radius = track->m_Width >> 1;
fillopt = DisplayOpt.DisplayPadFill ? FILLED : SKETCH;
if( (rayon / zoom) < L_MIN_DESSIN )
if( (radius / zoom) < L_MIN_DESSIN )
{
GRCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon, 0, color );
radius, 0, color );
}
else if( fillopt == SKETCH )
{
GRCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon, 0, color );
radius, 0, color );
}
else
{
GRFilledCircle( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
rayon, 0, color, color );
radius, 0, color, color );
}
}
break;
case S_SPOT_RECT:
case S_RECT:
l_piste = track->m_Width >> 1;
fillopt = DisplayOpt.DisplayPadFill ? FILLED : SKETCH;
if( (l_piste / zoom) < L_MIN_DESSIN )
{
......@@ -189,6 +198,8 @@ void Trace_Segment( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* track, int draw_mo
fillopt = DisplayOpt.DisplayPadFill ? FILLED : SKETCH;
case S_SEGMENT:
l_piste = track->m_Width >> 1;
if( (l_piste / zoom) < L_MIN_DESSIN )
{
GRLine( &panel->m_ClipBox, DC, track->m_Start.x, track->m_Start.y,
......
......@@ -95,13 +95,57 @@ void GRMoveRel(int x, int y);
void GRSMoveRel(int x, int y);
void GRLineRel(EDA_Rect * ClipBox, wxDC * DC, int x, int y, int width, int Color);
void GRSLineRel(EDA_Rect * ClipBox, wxDC * DC, int x, int y, int width, int Color);
void GRPoly(EDA_Rect * ClipBox, wxDC * DC, int n, int *Points,
bool Fill, int width, int Color, int BgColor);
void GRClosedPoly(EDA_Rect * ClipBox, wxDC * DC, int n, int *Points, bool Fill, int Color, int BgColor);
void GRClosedPoly(EDA_Rect * ClipBox, wxDC * DC, int n, int *Points, bool Fill, int width, int Color, int BgColor);
void GRSPoly(EDA_Rect * ClipBox, wxDC * DC, int n, int *Points, bool Fill, int width, int Color, int BgColor);
void GRSClosedPoly(EDA_Rect * ClipBox, wxDC * DC, int n, int *Points, bool Fill, int width, int Color, int BgColor);
void GRCircle(EDA_Rect * ClipBox, wxDC * DC, int x, int y, int r, int Color);
void GRPoly(EDA_Rect * ClipBox, wxDC * DC, int n, wxPoint Points[], bool Fill, int width, int Color, int BgColor);
/**
* Function GRClosedPoly
* draws a closed polygon onto the drawing context \a aDC and optionally fills and/or
* draws a border around it.
* @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
* @param aDC the device context into which drawing should occur.
* @param aPointCount the number of points in the array \a aPointArray.
* @param aPointArray an array holding the wxPoints in the polygon.
* @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
* @param aPenColor the color index of the border.
* @param aFillColor the fill color of the polygon's interior.
*/
void GRClosedPoly(EDA_Rect* ClipBox, wxDC* aDC, int aPointCount, wxPoint aPoints[], bool doFill, int aPenColor, int aFillColor);
// @todo could make these 2 closed polygons calls a single function and default the aPenWidth argument
/**
* Function GRClosedPoly
* draws a closed polygon onto the drawing context \a aDC and optionally fills and/or
* draws a border around it.
* @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
* @param aDC the device context into which drawing should occur.
* @param aPointCount the number of points in the array \a aPointArray.
* @param aPointArray an array holding the wxPoints in the polygon.
* @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
* @param aPenWidth is the width of the pen to use on the perimeter, can be zero.
* @param aPenColor the color index of the border.
* @param aFillColor the fill color of the polygon's interior.
*/
void GRClosedPoly(EDA_Rect * ClipBox, wxDC* aDC, int aPointCount, wxPoint aPoints[], bool doFill, int aPenWidth, int aPenColor, int aFillColor);
/**
* Function GRCircle
* draws a circle onto the drawing context \a aDC centered at the user coordinates (x,y)
*
* @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
* @param aDC the device context into which drawing should occur.
* @param x The x coordinate in user space of the center of the circle.
* @param x The y coordinate in user space of the center of the circle.
* @param aRadius is the radis of the circle.
* @param aColor is an index into our color table of RGB colors.
* @see EDA_Colors and colors.h
*/
void GRCircle(EDA_Rect * ClipBox, wxDC * aDC, int x, int y, int aRadius, int aColor);
void GRCircle(EDA_Rect * ClipBox, wxDC * DC, int x, int y, int r, int width, int Color);
void GRFilledCircle(EDA_Rect * ClipBox, wxDC * DC, int x, int y, int r,
int width, int Color, int BgColor);
......
......@@ -35,17 +35,11 @@ EDGE_MODULE::EDGE_MODULE( MODULE* parent ) :
m_Shape = S_SEGMENT;
m_Angle = 0;
m_Width = 120;
m_PolyCount = 0; // For polygons : number of points (> 2)
m_PolyList = NULL; // For polygons: coord list (1 point = 2 coord)
}
EDGE_MODULE::~EDGE_MODULE()
{
if( m_PolyList )
free( m_PolyList );
m_PolyList = NULL;
m_PolyCount = 0;
}
......@@ -56,6 +50,7 @@ void EDGE_MODULE:: Copy( EDGE_MODULE* source ) // copy structure
if( source == NULL )
return;
// @todo why not just use "*this = source;" ?
m_Start = source->m_Start;
m_End = source->m_End;
m_Shape = source->m_Shape;
......@@ -64,18 +59,8 @@ void EDGE_MODULE:: Copy( EDGE_MODULE* source ) // copy structure
m_Angle = source->m_Angle; // pour les arcs de cercle: longueur de l'arc en 0,1 degres
m_Layer = source->m_Layer;
m_Width = source->m_Width;
if( m_PolyList )
free( m_PolyList );
m_PolyCount = 0;
m_PolyList = NULL;
if( source->m_PolyCount && source->m_PolyList )
{
int size;
m_PolyCount = source->m_PolyCount; // For polygons : number of points
size = m_PolyCount * 2 * sizeof(int); // For polygons: 1 point = 2 coord
m_PolyList = (int*) MyMalloc( size );
memcpy( m_PolyList, source->m_PolyList, size );
}
m_PolyPoints = source->m_PolyPoints;
}
/***********************************/
......@@ -211,31 +196,30 @@ void EDGE_MODULE::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
case S_POLYGON:
{
// We must compute true coordinates from m_PolyList
// We must compute true coordinates from m_PolyPoints
// which are relative to module position, orientation 0
int ii, * source, * ptr, * ptr_base;
ptr = ptr_base = (int*) MyMalloc( 2 * m_PolyCount * sizeof(int) );
source = m_PolyList;
for( ii = 0; ii < m_PolyCount; ii++ )
std::vector<wxPoint> points = m_PolyPoints;
for( unsigned ii = 0; ii < points.size(); ii++ )
{
int x, y;
x = *source; source++; y = *source; source++;
wxPoint& pt = points[ii];
if( Module )
{
RotatePoint( &x, &y, Module->m_Orient );
x += Module->m_Pos.x;
y += Module->m_Pos.y;
RotatePoint( &pt.x, &pt.y, Module->m_Orient );
pt.x += Module->m_Pos.x;
pt.y += Module->m_Pos.y;
}
x += m_Start0.x - offset.x;
y += m_Start0.y - offset.y;
*ptr = x; ptr++; *ptr = y; ptr++;
pt.x += m_Start0.x - offset.x;
pt.y += m_Start0.y - offset.y;
}
GRPoly( &panel->m_ClipBox, DC, m_PolyCount, ptr_base,
GRPoly( &panel->m_ClipBox, DC, points.size(), &points[0],
TRUE, m_Width, color, color );
free( ptr_base );
break;
}
break;
}
}
......@@ -306,13 +290,11 @@ bool EDGE_MODULE::Save( FILE* aFile ) const
ret = fprintf( aFile, "DP %d %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_PolyCount,
m_PolyPoints.size(),
m_Width, m_Layer );
int* pInt;
pInt = m_PolyList;
for( int i=0; i<m_PolyCount; ++i, pInt+=2 )
fprintf( aFile, "Dl %d %d\n", pInt[0], pInt[1] );
for( unsigned i=0; i<m_PolyPoints.size(); ++i )
fprintf( aFile, "Dl %d %d\n", m_PolyPoints[i].x, m_PolyPoints[i].y );
break;
default:
......@@ -345,11 +327,10 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File,
*
*/
{
int ii, * ptr;
int ii;
int error = 0;
char Buf[1024];
switch( Line[1] )
{
case 'S':
......@@ -394,26 +375,37 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File,
break;
case S_POLYGON:
int pointCount;
sscanf( Line + 3, "%d %d %d %d %d %d %d",
&m_Start0.x, &m_Start0.y,
&m_End0.x, &m_End0.y,
&m_PolyCount, &m_Width, &m_Layer );
&pointCount, &m_Width, &m_Layer );
(*LineNum)++;
m_PolyList = (int*) MyZMalloc( 2 * m_PolyCount * sizeof(int) );
for( ii = 0, ptr = m_PolyList; ii < m_PolyCount; ii++ )
m_PolyPoints.clear();
m_PolyPoints.reserve( pointCount );
for( ii = 0; ii<pointCount; ii++ )
{
if( GetLine( File, Buf, LineNum, sizeof(Buf) - 1 ) != NULL )
{
if( strncmp( Buf, "Dl", 2 ) != 0 )
{
error = 1; break;
error = 1;
break;
}
sscanf( Buf + 3, "%d %d\n", ptr, ptr + 1 );
(*LineNum)++; ptr += 2;
int x;
int y;
sscanf( Buf + 3, "%d %d\n", &x, &y );
m_PolyPoints.push_back( wxPoint(x,y) );
(*LineNum)++;
}
else
{
error = 1; break;
error = 1;
break;
}
}
......
......@@ -20,8 +20,7 @@ public:
int m_Angle; // pour les arcs de cercle: longueur de l'arc en 0,1 degres
int m_PolyCount; // For polygons: number of points (> 2)
int* m_PolyList; // For polygons: coord list (1 point = 2 coord)
std::vector<wxPoint> m_PolyPoints; // For polygons: number of points (> 2)
// Coord are relative to Origin, orient 0
public:
......
......@@ -280,7 +280,7 @@ void D_PAD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoin
coord[ii].y = coord[ii].y + uy0;
}
GRClosedPoly( &panel->m_ClipBox, DC, 4, (int*) coord, fillpad, color, color );
GRClosedPoly( &panel->m_ClipBox, DC, 4, coord, fillpad, color, color );
if( DisplayIsol )
{
......@@ -306,7 +306,7 @@ void D_PAD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoin
coord[ii].y = coord[ii].y + uy0;
}
GRClosedPoly( &panel->m_ClipBox, DC, 4, (int*) coord, 0, color, color );
GRClosedPoly( &panel->m_ClipBox, DC, 4, coord, 0, color, color );
}
}
break;
......
......@@ -455,19 +455,6 @@ void ZONE_CONTAINER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, con
}
}
/* this is local class to handle 2 integers that are a corner coordinate
* One could use wxPoint insteed.
* However, this class has only 2 integers
* if changes happen in wxPoint ( like virtual functions) they will be not suitable
* So i prefer use this simple class to handle a coordinate.
*/
class corner_coord
{
public:
int x;
int y;
};
/************************************************************************************/
void ZONE_CONTAINER::DrawFilledArea( WinEDA_DrawPanel* panel,
......@@ -483,8 +470,8 @@ void ZONE_CONTAINER::DrawFilledArea( WinEDA_DrawPanel* panel,
* @param aDrawMode = GR_OR, GR_XOR, GR_COPY ..
*/
{
static vector < char > CornersTypeBuffer;
static vector < corner_coord > CornersBuffer;
static vector <char> CornersTypeBuffer;
static vector <wxPoint> CornersBuffer;
// outline_mode is false to show filled polys,
// and true to show polygons outlines only (test and debug purposes)
bool outline_mode = DisplayOpt.DisplayZonesMode == 2 ? true : false;
......@@ -535,13 +522,15 @@ void ZONE_CONTAINER::DrawFilledArea( WinEDA_DrawPanel* panel,
for( int ic = 0; ic <= imax; ic++ )
{
CPolyPt* corner = &m_FilledPolysList[ic];
corner_coord coord;
wxPoint coord;
coord.x = corner->x + offset.x;
coord.y = corner->y + offset.y;
CornersBuffer.push_back(coord);
CornersTypeBuffer.push_back((char) corner->utility);
if( (corner->end_contour) || (ic == imax) ) // the last corner of a filled area is found: draw it
{ /* Draw the current filled area: draw segments ouline first
{
/* Draw the current filled area: draw segments ouline first
* Curiously, draw segments ouline first and after draw filled polygons
* with oulines thickness = 0 is a faster than
* just draw filled polygons but with oulines thickness = m_ZoneMinThickness
......@@ -559,6 +548,7 @@ void ZONE_CONTAINER::DrawFilledArea( WinEDA_DrawPanel* panel,
int y0 = CornersBuffer[is].y;
int x1 = CornersBuffer[ie].x;
int y1 = CornersBuffer[ie].y;
if ( CornersTypeBuffer[ie] == 0 ) // Draw only basic outlines, not extra segments
{
if( (!DisplayOpt.DisplayPcbTrackFill) || GetState( FORCE_SKETCH ) )
......@@ -574,7 +564,7 @@ void ZONE_CONTAINER::DrawFilledArea( WinEDA_DrawPanel* panel,
}
// Draw areas:
if( (m_FillMode == 0 ) && ! outline_mode )
GRPoly( &panel->m_ClipBox, DC, CornersBuffer.size(), (int*)&CornersBuffer[0].x,
GRPoly( &panel->m_ClipBox, DC, CornersBuffer.size(), &CornersBuffer[0],
true, 0, color, color );
}
CornersTypeBuffer.clear();
......
......@@ -116,7 +116,7 @@ MODULE* WinEDA_PcbFrame::Create_MuWaveComponent( int shape_type )
* the "gap" is isolation created between this 2 pads
*/
{
int gap_size, oX, ii;
int oX;
float fcoeff;
D_PAD* pad;
MODULE* Module;
......@@ -126,7 +126,7 @@ MODULE* WinEDA_PcbFrame::Create_MuWaveComponent( int shape_type )
bool abort;
/* Enter the size of the gap or stub*/
gap_size = g_DesignSettings.m_CurrentTrackWidth; // Valeur raisonnable
int gap_size = g_DesignSettings.m_CurrentTrackWidth; // Valeur raisonnable
switch( shape_type )
{
......@@ -219,40 +219,39 @@ MODULE* WinEDA_PcbFrame::Create_MuWaveComponent( int shape_type )
pad->m_Pos.y += pad->m_Pos0.y;
break;
case 2: //Arc Stub created by a polygonal approach:
case 2: // Arc Stub created by a polygonal approach:
{
EDGE_MODULE* edge; int* ptr, theta;
ii = angle / 50; // Note : angles are in 0.1 degrees
edge = new EDGE_MODULE( Module );
EDGE_MODULE* edge = new EDGE_MODULE( Module );
Module->m_Drawings.PushFront( edge );
edge->m_Shape = S_POLYGON;
edge->SetLayer( LAYER_CMP_N );
edge->m_PolyCount = ii + 3;
edge->m_PolyList = (int*) MyMalloc( edge->m_PolyCount * 2 * sizeof(int) );
ptr = edge->m_PolyList;
int numPoints = angle / 50 + 3; // Note : angles are in 0.1 degrees
edge->m_PolyPoints.reserve( numPoints );
edge->m_Start0.y = -pad->m_Size.y / 2;
*ptr = 0; ptr++;
*ptr = 0; ptr++;
theta = -angle / 2;
for( ii = 1; ii < edge->m_PolyCount - 1; ii++ )
edge->m_PolyPoints.push_back( wxPoint(0,0) );
int theta = -angle / 2;
for( int ii=1; ii<numPoints-1; ii++ )
{
int x, y;
x = 0; y = -gap_size;
RotatePoint( &x, &y, theta );
*ptr = x; ptr++; *ptr = y; ptr++;
wxPoint pt(0, -gap_size);
RotatePoint( &pt.x, &pt.y, theta );
edge->m_PolyPoints.push_back( pt );
theta += 50;
if( theta > angle / 2 )
theta = angle / 2;
}
// Close the polygon:
*ptr = edge->m_PolyList[0]; ptr++;
*ptr = edge->m_PolyList[1];
break;
edge->m_PolyPoints.push_back( edge->m_PolyPoints[0] );
}
break;
default:
break;
......@@ -505,11 +504,13 @@ MODULE* WinEDA_PcbFrame::Create_MuWavePolygonShape( )
MODULE* Module;
wxString cmp_name;
int pad_count = 2;
EDGE_MODULE* edge; int* ptr;
EDGE_MODULE* edge;
int ii, npoints;
WinEDA_SetParamShapeFrame* frame = new WinEDA_SetParamShapeFrame( this, wxPoint( -1, -1 ) );
int ok = frame->ShowModal(); frame->Destroy();
int ok = frame->ShowModal();
frame->Destroy();
DrawPanel->MouseToCursorSchema();
......@@ -524,6 +525,7 @@ MODULE* WinEDA_PcbFrame::Create_MuWavePolygonShape( )
if( PolyShapeType == 2 ) // mirrored
ShapeScaleY = -ShapeScaleY;
ShapeSize.x = (int) round( ShapeScaleX );
ShapeSize.y = (int) round( ShapeScaleY );
......@@ -558,69 +560,50 @@ MODULE* WinEDA_PcbFrame::Create_MuWavePolygonShape( )
edge->SetLayer( LAYER_CMP_N );
npoints = PolyEdgesCount;
switch( PolyShapeType )
{
case 0: // Single
case 2: // Single, mirrored
edge->m_PolyCount = PolyEdgesCount + 2;
break;
case 1: // Symetric
edge->m_PolyCount = (2 * PolyEdgesCount) + 2;
break;
}
edge->m_PolyList = (int*) MyMalloc( edge->m_PolyCount * 2 * sizeof(int) );
ptr = edge->m_PolyList;
edge->m_PolyPoints.reserve(2 * PolyEdgesCount + 2);
// Init start point coord:
*ptr = pad1->m_Pos0.x; ptr++;
*ptr = 0; ptr++;
edge->m_PolyPoints.push_back( wxPoint( pad1->m_Pos0.x, 0) );
double* dptr = PolyEdges;
wxPoint first_cordinate, last_cordinate;
wxPoint first_coordinate, last_coordinate;
for( ii = 0; ii < npoints; ii++ ) // Copy points
{
last_cordinate.x = *ptr = (int) round( *dptr * ShapeScaleX ) + pad1->m_Pos0.x;
dptr++; ptr++;
last_cordinate.y = *ptr = -(int) round( *dptr * ShapeScaleY );
dptr++; ptr++;
last_coordinate.x = (int) round( *dptr++ * ShapeScaleX ) + pad1->m_Pos0.x;
last_coordinate.y = -(int) round( *dptr++ * ShapeScaleY );
edge->m_PolyPoints.push_back( last_coordinate );
}
first_cordinate.y = edge->m_PolyList[3];
first_coordinate.y = edge->m_PolyPoints[1].y;
switch( PolyShapeType )
{
int* ptr1;
case 0: // Single
case 2: // Single mirrored
// Init end point coord:
*ptr = pad2->m_Pos0.x = last_cordinate.x; ptr++;
*ptr = 0;
pad1->m_Size.x = pad1->m_Size.y = ABS( first_cordinate.y );
pad2->m_Size.x = pad2->m_Size.y = ABS( last_cordinate.y );
pad1->m_Pos0.y = first_cordinate.y / 2;
pad2->m_Pos0.y = last_cordinate.y / 2;
pad2->m_Pos0.x = last_coordinate.x;
edge->m_PolyPoints.push_back( wxPoint( last_coordinate.x, 0 ) );
pad1->m_Size.x = pad1->m_Size.y = ABS( first_coordinate.y );
pad2->m_Size.x = pad2->m_Size.y = ABS( last_coordinate.y );
pad1->m_Pos0.y = first_coordinate.y / 2;
pad2->m_Pos0.y = last_coordinate.y / 2;
pad1->m_Pos.y = pad1->m_Pos0.y + Module->m_Pos.y;
pad2->m_Pos.y = pad2->m_Pos0.y + Module->m_Pos.y;
break;
case 1: // Symetric
ptr1 = ptr - 2;
for( ii = 0; ii <= npoints; ii++ )
for( int ndx = edge->m_PolyPoints.size()-1; ndx>=0; --ndx )
{
*ptr = *ptr1; // Copy X coord
ptr++;
*ptr = -*(ptr1 + 1); // Copy Y coord, mirror X axis
ptr1 -= 2; ptr++;
}
wxPoint pt = edge->m_PolyPoints[ndx];
pad1->m_Size.x = pad1->m_Size.y = 2* ABS( first_cordinate.y );
pt.y = -pt.y; // mirror about X axis
pad2->m_Size.x = pad2->m_Size.y = 2* ABS( last_cordinate.y );
edge->m_PolyPoints.push_back( pt );
}
pad1->m_Size.x = pad1->m_Size.y = 2 * ABS( first_coordinate.y );
pad2->m_Size.x = pad2->m_Size.y = 2 * ABS( last_coordinate.y );
break;
}
......
......@@ -472,6 +472,7 @@ void Plot_1_EdgeModule( int format_plot, EDGE_MODULE* PtEdge )
if( PtEdge->Type() != TYPE_EDGE_MODULE )
return;
type_trace = PtEdge->m_Shape;
thickness = PtEdge->m_Width;
if( Plot_Mode == FILAIRE )
......@@ -520,13 +521,16 @@ void Plot_1_EdgeModule( int format_plot, EDGE_MODULE* PtEdge )
{
// We must compute true coordinates from m_PolyList
// which are relative to module position, orientation 0
int ii, * source, * ptr, * ptr_base;
MODULE* Module = NULL;
if( PtEdge->GetParent() && (PtEdge->GetParent()->Type() == TYPE_MODULE) )
Module = (MODULE*) PtEdge->GetParent();
ptr = ptr_base = (int*) MyMalloc( 2 * PtEdge->m_PolyCount * sizeof(int) );
source = PtEdge->m_PolyList;
for( ii = 0; ii < PtEdge->m_PolyCount; ii++ )
int* ptr_base = (int*) MyMalloc( 2 * PtEdge->m_PolyPoints.size() * sizeof(int) );
int* ptr = ptr_base;
int* source = (int*) &PtEdge->m_PolyPoints[0];
for( unsigned ii = 0; ii < PtEdge->m_PolyPoints.size(); ii++ )
{
int x = *source++;
int y = *source++;
......@@ -545,10 +549,10 @@ void Plot_1_EdgeModule( int format_plot, EDGE_MODULE* PtEdge )
*ptr++ = y;
}
PlotFilledPolygon( format_plot, PtEdge->m_PolyCount, ptr_base );
PlotFilledPolygon( format_plot, PtEdge->m_PolyPoints.size(), ptr_base );
free( ptr_base );
break;
}
break;
}
}
......
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