Commit 6b05cf31 authored by jean-pierre charras's avatar jean-pierre charras

Fixed bug in GRLineArray(). Cleanup Gerbview code

parent ee4aadc4
......@@ -56,7 +56,7 @@ int g_DrawBgColor = WHITE;
#define USE_CLIP_FILLED_POLYGONS
#ifdef USE_CLIP_FILLED_POLYGONS
void ClipAndDrawFilledPoly( EDA_Rect* ClipBox, wxDC * DC, wxPoint Points[], int n );
void ClipAndDrawFilledPoly( EDA_Rect * ClipBox, wxDC * DC, wxPoint Points[], int n );
#endif
/* These functions are used by corresponding functions
......@@ -82,8 +82,9 @@ static void GRSFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int StAngle
int EndAngle, int r, int width, int Color, int BgColor );
static void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int aPenSize, int Color );
static void GRSLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int lines, int width, int Color );
static void GRSLineArray( EDA_Rect * aClipBox, wxDC * aDC, std::vector<wxPoint>& aLines,
int aWidth, int aColor );
/**/
extern BASE_SCREEN* ActiveScreen;
......@@ -169,7 +170,9 @@ int GRMapY( int y )
#if defined( USE_WX_ZOOM )
// currently only used if USE_WX_ZOOM is defined.
/**
* Test if any part of a line falls within the bounds of a rectangle.
*
......@@ -254,7 +257,8 @@ static bool clipLine( EDA_Rect* aClipBox, int& x1, int& y1, int& x2, int& y2 )
/* If we're here, something has gone terribly wrong. */
#if DEBUG_DUMP_CLIP_ERROR_COORDS
wxLogDebug( wxT( "Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
wxLogDebug( wxT(
"Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY, x1, y1, x2, y2 );
#endif
return false;
......@@ -308,7 +312,8 @@ static bool clipLine( EDA_Rect* aClipBox, int& x1, int& y1, int& x2, int& y2 )
/* If we're here, something has gone terribly wrong. */
#if DEBUG_DUMP_CLIP_ERROR_COORDS
wxLogDebug( wxT( "Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
wxLogDebug( wxT(
"Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY, x1, y1, x2, y2 );
#endif
return false;
......@@ -386,7 +391,8 @@ static bool clipLine( EDA_Rect* aClipBox, int& x1, int& y1, int& x2, int& y2 )
* something has gone terribly wrong. */
#if DEBUG_DUMP_CLIP_ERROR_COORDS
if( haveFirstPoint )
wxLogDebug( wxT( "Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
wxLogDebug( wxT(
"Line (%d,%d):(%d,%d) in rectangle (%d,%d,%d,%d) clipped to (%d,%d,%d,%d)" ),
tmpX1, tmpY1, tmpX2, tmpY2, minX, minY, maxX, maxY, x1, y1, x2, y2 );
#endif
}
......@@ -400,6 +406,8 @@ static bool clipLine( EDA_Rect* aClipBox, int& x1, int& y1, int& x2, int& y2 )
return true;
}
#endif // if defined( USE_WX_ZOOM )
......@@ -528,10 +536,11 @@ static void WinClipAndDrawLine( EDA_Rect* ClipBox, wxDC* DC,
ycliphi += width;
#if defined( USE_WX_ZOOM )
if ( clipLine( ClipBox, x1, y1, x2, y2 ) )
if( clipLine( ClipBox, x1, y1, x2, y2 ) )
#else
if( clip_line( x1, y1, x2, y2 ) )
#endif
return;
}
......@@ -566,10 +575,10 @@ void GRSetColorPen( wxDC* DC, int Color, int width, wxPenStyle style )
Color = BLACK;
}
if( s_DC_lastcolor != Color ||
s_DC_lastwidth != width ||
s_DC_lastpenstyle != style ||
s_DC_lastDC != DC )
if( s_DC_lastcolor != Color
|| s_DC_lastwidth != width
|| s_DC_lastpenstyle != style
|| s_DC_lastDC != DC )
{
wxPen pen;
......@@ -585,7 +594,6 @@ void GRSetColorPen( wxDC* DC, int Color, int width, wxPenStyle style )
s_DC_lastwidth = width;
s_DC_lastpenstyle = style;
s_DC_lastDC = DC;
}
}
......@@ -595,9 +603,9 @@ void GRSetBrush( wxDC* DC, int Color, int fill )
if( s_ForceBlackPen )
Color = BLACK;
if( s_DC_lastbrushcolor != Color ||
s_DC_lastbrushfill != fill ||
s_DC_lastDC != DC )
if( s_DC_lastbrushcolor != Color
|| s_DC_lastbrushfill != fill
|| s_DC_lastDC != DC )
{
wxBrush DrawBrush;
DrawBrush.SetColour( MakeColour( Color ) );
......@@ -616,7 +624,6 @@ void GRSetBrush( wxDC* DC, int Color, int fill )
}
/** function GRForceBlackPen
* @param flagforce True to force a black pen whenever the asked color
*/
......@@ -642,30 +649,40 @@ void GRSetDrawMode( wxDC* DC, int draw_mode )
{
if( draw_mode & GR_OR )
#if defined(__WXMAC__) && (wxMAC_USE_CORE_GRAPHICS || wxCHECK_VERSION( 2, 9, 0 ) )
DC->SetLogicalFunction( wxCOPY );
#elif defined( USE_WX_GRAPHICS_CONTEXT )
DC->SetLogicalFunction( wxCOPY );
#else
DC->SetLogicalFunction( wxOR );
#endif
else if( draw_mode & GR_XOR )
#if defined( USE_WX_GRAPHICS_CONTEXT )
DC->SetLogicalFunction( wxCOPY );
#else
DC->SetLogicalFunction( wxXOR );
#endif
else if( draw_mode & GR_NXOR )
#if defined(__WXMAC__) && (wxMAC_USE_CORE_GRAPHICS || wxCHECK_VERSION( 2, 9, 0 ) )
DC->SetLogicalFunction( wxXOR );
#elif defined( USE_WX_GRAPHICS_CONTEXT )
DC->SetLogicalFunction( wxCOPY );
#else
DC->SetLogicalFunction( wxEQUIV );
#endif
else if( draw_mode & GR_INVERT )
#if defined( USE_WX_GRAPHICS_CONTEXT )
DC->SetLogicalFunction( wxCOPY );
#else
DC->SetLogicalFunction( wxINVERT );
#endif
else
......@@ -863,7 +880,6 @@ void GRSMoveTo( int x, int y )
}
/*
* Draw line to a new position, in screen (pixels) space.
*/
......@@ -881,95 +897,65 @@ void GRSLine( EDA_Rect* ClipBox,
GRLastMoveToY = y2;
}
/*
* Draw an array of lines
*/
void GRLineArray(EDA_Rect* ClipBox,
wxDC* DC,
wxPoint points[],
int lines,
int width,
int Color )
/** Function GRLineArray
* draws an array of lines (not a polygon).
* @param aClipBox = the clip box
* @param aDC = the device context into which drawing should occur.
* @param aLines = a list of pair of coordinate in user space: a pair for each line.
* @param aWidth = the width of each line.
* @param aColor = an index into our color table of RGB colors.
* @see EDA_Colors and colors.h
*/
void GRLineArray( EDA_Rect* aClipBox, wxDC* aDC,
std::vector<wxPoint>& aLines,
int aWidth, int aColor )
{
for(int i= 0 ; i < lines; i++)
for( unsigned i = 0; i < aLines.size(); i++ )
{
points[i].x = GRMapX( points[i].x );
points[i].y = GRMapY( points[i].y );
aLines[i].x = GRMapX( aLines[i].x );
aLines[i].y = GRMapY( aLines[i].y );
}
width = ZoomValue( width );
GRSLineArray(ClipBox,DC,points,lines,width,Color);
aWidth = ZoomValue( aWidth );
GRSLineArray( aClipBox, aDC, aLines, aWidth, aColor );
}
void GRSLineArray(EDA_Rect* ClipBox,
wxDC* DC,
wxPoint points[],
int lines,
int width,
int Color )
void GRSLineArray( EDA_Rect* aClipBox, wxDC* aDC,
std::vector<wxPoint>& aLines,
int aWidth, int aColor )
{
GRSetColorPen( DC, Color, width );
GRSetColorPen( aDC, aColor, aWidth );
#if defined( USE_WX_GRAPHICS_CONTEXT ) || defined(__WXMAC__)
wxGraphicsContext *gc = wxGraphicsContext::Create( DC );
wxASSERT(gc);
gc->Clip( ClipBox->GetX(), ClipBox->GetY(), ClipBox->GetRight(), ClipBox->GetHeight());
wxGraphicsContext* gc = wxGraphicsContext::Create( aDC );
wxASSERT( gc );
gc->Clip( aClipBox->GetX(), aClipBox->GetY(), aClipBox->GetRight(), aClipBox->GetHeight() );
wxGraphicsPath path = gc->CreatePath();
for(int i= 0 ; i < lines; i+=2)
for( unsigned i = 0; i < aLines.size(); )
{
path.MoveToPoint(points[i].x, points[i].y);
path.AddLineToPoint(points[i+1].x, points[i+1].y);
path.MoveToPoint( aLines[i].x, aLines[i].y );
i++;
path.AddLineToPoint( aLines[i].x, aLines[i].y );
i++;
}
gc->StrokePath(path);
gc->StrokePath( path );
gc->ResetClip();
delete gc;
#else
for(int i= 0 ; i < lines; i+=2)
for( unsigned i = 0; i < aLines.size(); )
{
WinClipAndDrawLine( ClipBox, DC, points[i].x , points[i].y, points[i+1].x , points[i+1].y, Color, width );
GRLastMoveToX = points[i+1].x;
GRLastMoveToY = points[i+1].y;
WinClipAndDrawLine( aClipBox, aDC, aLines[i].x, aLines[i].y,
aLines[i + 1].x, aLines[i + 1].y, aColor, aWidth );
i++;
GRLastMoveToX = aLines[i].x;
GRLastMoveToY = aLines[i].y;
i++;
}
#endif
}
/*
* Move to a new position relative to current one, in object space.
*/
void GRMoveRel( int x, int y )
{
GRLastMoveToX += ZoomValue( x );
GRLastMoveToY += ZoomValue( y );
}
/*
* Draw a line to a new position relative to current one, in object space.
*/
void GRLineRel( EDA_Rect* ClipBox,
wxDC* DC,
int x,
int y,
int width,
int Color )
{
int GRLineToX = GRLastMoveToX,
GRLineToY = GRLastMoveToY;
GRLineToX += ZoomValue( x );
GRLineToY += ZoomValue( y );
GRSLine( ClipBox,
DC,
GRLastMoveToX,
GRLastMoveToY,
GRLineToX,
GRLineToY,
ZoomValue( width ),
Color );
#endif
}
......@@ -983,6 +969,7 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
GRMapY( y2 ), ZoomValue( width ), ZoomValue( aPenSize ), Color );
}
void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int Color )
{
......@@ -990,6 +977,7 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
GRMapY( y2 ), ZoomValue( width ), 0, Color );
}
void GRCSegm( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
int aWidth, int aColor )
{
......@@ -998,6 +986,7 @@ void GRCSegm( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
ZoomValue( aWidth ), 0, aColor );
}
/*
* Draw segment (full) with rounded ends in object space (real coords.).
*/
......@@ -1060,6 +1049,7 @@ void GRSCSegm( EDA_Rect* ClipBox,
#else
if( clip_line( x1, y1, x2, y2 ) )
#endif
return;
}
......@@ -1187,7 +1177,7 @@ void GRSCSegm( EDA_Rect* ClipBox,
static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, wxPoint Points[] )
{
if( ! ClipBox )
if( !ClipBox )
return true;
if( n <= 0 )
......@@ -1367,6 +1357,7 @@ void GRCircle( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int r, int Color )
GRSCircle( ClipBox, DC, cx, cy, radius, 0, Color );
}
/*
* Draw a circle in object space.
*/
......@@ -1377,6 +1368,7 @@ void GRCircle( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int r, int width, int
GRSCircle( ClipBox, DC, GRMapX( x ), GRMapY( y ), r, width, Color );
}
/*
* Draw a circle in object space.
*/
......@@ -1400,6 +1392,7 @@ void GRFilledCircle( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int r,
Color, BgColor );
}
/*
* Draw a filled circle, in object space.
*/
......@@ -1410,6 +1403,7 @@ void GRFilledCircle( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, i
aColor, aColor );
}
/*
* Draw a filled circle, in drawing space.
*/
......@@ -1440,7 +1434,6 @@ void GRSFilledCircle( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int r,
}
/*
* Draw a circle in drawing space.
*/
......@@ -1498,6 +1491,7 @@ void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
Color );
}
void GRArc1( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
wxPoint aCenter, int aWidth, int aColor )
{
......@@ -1736,6 +1730,7 @@ void GRRect( EDA_Rect* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, int
GRSRect( aClipBox, aDC, x1, y1, x2, y2, 0, aColor );
}
void GRRectPs( EDA_Rect* aClipBox, wxDC* aDC, const EDA_Rect& aRect, int aColor, wxPenStyle aStyle )
{
int x1 = GRMapX( aRect.GetX() );
......@@ -1761,6 +1756,7 @@ void GRRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int wi
GRSRect( ClipBox, DC, x1, y1, x2, y2, width, Color );
}
void GRRect( EDA_Rect* aClipBox, wxDC* aDC, const EDA_Rect& aRect, int aWidth, int aColor )
{
int x1 = GRMapX( aRect.GetX() );
......@@ -1845,7 +1841,6 @@ void GRSRect( EDA_Rect* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
}
void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC,
int x1, int y1, int x2, int y2,
int width, int Color, int BgColor )
......
......@@ -116,26 +116,10 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event )
Close( TRUE );
break;
case ID_NEW_PROJECT:
case ID_LOAD_PROJECT:
Files_io( event );
break;
case ID_GERBVIEW_GLOBAL_DELETE:
Erase_Current_Layer( TRUE );
break;
case ID_GET_TOOLS:
// InstallToolsFrame(this, wxPoint(-1,-1) );
break;
case ID_FIND_ITEMS:
// InstallFindFrame(this, pos);
break;
case ID_NO_SELECT_BUTT:
SetToolID( 0, 0, wxEmptyString );
break;
......@@ -223,19 +207,5 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event )
*/
void WinEDA_GerberFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
EDA_BaseStruct* DrawStruct = GetScreen()->GetCurItem();
switch( m_ID_current_state )
{
case 0:
if( (DrawStruct == NULL) || ((DrawStruct->m_Flags & ~DRAW_ERASED) == 0) )
{
DrawStruct = GerberGeneralLocateAndDisplay();
}
break;
default:
break;
}
// Currently: no nothing
}
......@@ -169,7 +169,7 @@ WinEDA_GerberFrame::WinEDA_GerberFrame( wxWindow* father,
ReCreateMenuBar();
ReCreateHToolbar();
ReCreateVToolbar();
// ReCreateVToolbar(); // Currently: no right vertical toolbar
ReCreateOptToolbar();
m_auimgr.SetManagedWindow( this );
......
......@@ -47,13 +47,6 @@ void WinEDA_GerberFrame::ReCreateHToolbar( void )
wxBitmap( open_xpm ),
_( "Load a new Gerber file on the current layer. Previous data will be deleted" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( wxID_UNDO, wxEmptyString,
wxBitmap( undelete_xpm ),
_( "Undelete" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( wxID_PRINT, wxEmptyString,
wxBitmap( print_button ),
......
......@@ -77,8 +77,6 @@ void GRDashedLine( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
void GRDashedLineTo( EDA_Rect* ClipBox, wxDC* DC, int x2, int y2, int width, int Color );
void GRMoveTo( int x, int y );
void GRLineTo( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int width, int Color );
void GRMoveRel( int x, int y );
void GRLineRel( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int width, int Color );
void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[], bool Fill,
int width, int Color, int BgColor );
......@@ -204,7 +202,16 @@ void GRRectPs( EDA_Rect* aClipBox, wxDC* aDC,const EDA_Rect& aRect,
void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
int x2, int y2, int width, int Color, int BgColor );
void GRLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int lines, int width, int Color );
/** Function GRLineArray
* draws an array of lines (not a polygon).
* @param aClipBox = the clip box
* @param aDC = the device context into which drawing should occur.
* @param aLines = a list of pair of coordinate in user space: a pair for each line.
* @param aWidth = the width of each line.
* @param aColor = an index into our color table of RGB colors.
* @see EDA_Colors and colors.h
*/
void GRLineArray( EDA_Rect* aClipBox, wxDC* aDC,std::vector<wxPoint>& aLines,
int aWidth, int aColor );
#endif /* define GR_BASIC */
......@@ -18,7 +18,6 @@
#include "protos.h"
/************************/
/* class ZONE_CONTAINER */
/************************/
......@@ -477,7 +476,8 @@ void ZONE_CONTAINER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, con
// draw the lines
int i_start_contour = 0;
wxPoint lines[( GetNumCorners()*2)+2];
std::vector<wxPoint> lines;
lines.reserve( (GetNumCorners()*2)+2);
for( int ic = 0; ic < GetNumCorners(); ic++ )
{
seg_start = GetCornerPosition( ic ) + offset;
......@@ -490,23 +490,24 @@ void ZONE_CONTAINER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, con
seg_end = GetCornerPosition( i_start_contour ) + offset;
i_start_contour = ic + 1;
}
lines[ic*2].x = seg_start.x;
lines[ic*2].y = seg_start.y;
lines[ic*2+1].x = seg_start.x;
lines[ic*2+1].y = seg_start.y;
lines.push_back( seg_start );
lines.push_back( seg_end );
}
GRLineArray(&panel->m_ClipBox, DC, lines, GetNumCorners(), 0, color);
GRLineArray(&panel->m_ClipBox, DC, lines, 0, color);
// draw hatches
wxPoint hatches[(m_Poly->m_HatchLines.size() *2)+2];
lines.clear();
lines.reserve( (m_Poly->m_HatchLines.size() *2) +2 );
for( unsigned ic = 0; ic < m_Poly->m_HatchLines.size(); ic++ )
{
hatches[ic*2].x = m_Poly->m_HatchLines[ic].xi + offset.x;
hatches[ic*2].y = m_Poly->m_HatchLines[ic].yi + offset.y;
hatches[ic*2+1].x = m_Poly->m_HatchLines[ic].xf + offset.x;
hatches[ic*2+1].y = m_Poly->m_HatchLines[ic].yf + offset.y;
seg_start.x = m_Poly->m_HatchLines[ic].xi + offset.x;
seg_start.y = m_Poly->m_HatchLines[ic].yi + offset.y;
seg_end.x = m_Poly->m_HatchLines[ic].xf + offset.x;
seg_end.y = m_Poly->m_HatchLines[ic].yf + offset.y;
lines.push_back( seg_start );
lines.push_back( seg_end );
}
GRLineArray(&panel->m_ClipBox, DC, hatches, m_Poly->m_HatchLines.size(), 0, color );
GRLineArray(&panel->m_ClipBox, DC, lines, 0, color );
}
......
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