Commit 443534e7 authored by jean-pierre charras's avatar jean-pierre charras

Gerbview: fixed a serious bug when reading GERBER files with no trailing zeros

parents 562f26dd 69b3bfd4
...@@ -555,7 +555,7 @@ void GRResetPenAndBrush( wxDC* DC ) ...@@ -555,7 +555,7 @@ void GRResetPenAndBrush( wxDC* DC )
* Function GRSetColorPen * Function GRSetColorPen
* sets a pen style, width, color, and alpha into the given device context. * sets a pen style, width, color, and alpha into the given device context.
*/ */
void GRSetColorPen( wxDC* DC, int Color, int width, int style ) void GRSetColorPen( wxDC* DC, int Color, int width, wxPenStyle style )
{ {
if( width < 0 ) if( width < 0 )
width = 0; width = 0;
...@@ -733,7 +733,7 @@ void GRSDashedLine( EDA_Rect* ClipBox, ...@@ -733,7 +733,7 @@ void GRSDashedLine( EDA_Rect* ClipBox,
GRLastMoveToX = x2; GRLastMoveToX = x2;
GRLastMoveToY = y2; GRLastMoveToY = y2;
s_DC_lastcolor = -1; s_DC_lastcolor = -1;
GRSetColorPen( DC, Color, width, wxSHORT_DASH ); GRSetColorPen( DC, Color, width, wxPENSTYLE_SHORT_DASH );
GRSLine( ClipBox, DC, x1, y1, x2, y2, width, Color ); GRSLine( ClipBox, DC, x1, y1, x2, y2, width, Color );
s_DC_lastcolor = -1; s_DC_lastcolor = -1;
GRSetColorPen( DC, Color, width ); GRSetColorPen( DC, Color, width );
...@@ -748,7 +748,7 @@ void GRSDashedLineTo( EDA_Rect* ClipBox, ...@@ -748,7 +748,7 @@ void GRSDashedLineTo( EDA_Rect* ClipBox,
int Color ) int Color )
{ {
s_DC_lastcolor = -1; s_DC_lastcolor = -1;
GRSetColorPen( DC, Color, width, wxSHORT_DASH ); GRSetColorPen( DC, Color, width, wxPENSTYLE_SHORT_DASH );
GRSLine( ClipBox, DC, GRLastMoveToX, GRLastMoveToY, x2, y2, width, Color ); GRSLine( ClipBox, DC, GRLastMoveToX, GRLastMoveToY, x2, y2, width, Color );
s_DC_lastcolor = -1; s_DC_lastcolor = -1;
GRSetColorPen( DC, Color, width ); GRSetColorPen( DC, Color, width );
...@@ -846,7 +846,7 @@ void GRSMixedLine( EDA_Rect* ClipBox, ...@@ -846,7 +846,7 @@ void GRSMixedLine( EDA_Rect* ClipBox,
int width, int width,
int Color ) int Color )
{ {
GRSetColorPen( DC, Color, width, wxDOT_DASH ); GRSetColorPen( DC, Color, width, wxPENSTYLE_DOT_DASH );
GRSLine( ClipBox, DC, x1, y1, x2, y2, width, Color ); GRSLine( ClipBox, DC, x1, y1, x2, y2, width, Color );
GRSetColorPen( DC, Color, width ); GRSetColorPen( DC, Color, width );
} }
......
...@@ -21,7 +21,7 @@ X0Y00100D03* ...@@ -21,7 +21,7 @@ X0Y00100D03*
G04 Two, with round holes, slightly overlapping, centered at 0.1,0.1 * G04 Two, with round holes, slightly overlapping, centered at 0.1,0.1 *
G54D11* G54D11*
X00100Y00090D03* X100Y90D03*
X00100Y00110D03* X00100Y00110D03*
M02* M02*
...@@ -481,9 +481,11 @@ void WinEDA_GerberFrame::Liste_D_Codes( ) ...@@ -481,9 +481,11 @@ void WinEDA_GerberFrame::Liste_D_Codes( )
/** function UpdateTitleAndInfo /** function UpdateTitleAndInfo
* displays the short filename (if exists) of the selected layer * displays the short filename (if exists) of the selected layer
* on the caption of the main gerbview window * on the caption of the main gerbview window
* and the name of the layer (found in the gerber file: LN <name> command) * displays image name and the last layer name (found in the gerber file: LN <name> command)
* in the status bar * in the status bar
* Note layer name can change when reading a gerber file, and the layer name is the last found.
* So, show the layer name is not very useful, and can be seen as a debug feature.
*/ */
void WinEDA_GerberFrame::UpdateTitleAndInfo() void WinEDA_GerberFrame::UpdateTitleAndInfo()
{ {
...@@ -493,24 +495,28 @@ void WinEDA_GerberFrame::UpdateTitleAndInfo() ...@@ -493,24 +495,28 @@ void WinEDA_GerberFrame::UpdateTitleAndInfo()
if( gerber == NULL ) if( gerber == NULL )
{ {
text = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion(); text = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
SetTitle( text );
SetStatusText( wxEmptyString, 0 ); SetStatusText( wxEmptyString, 0 );
m_TextInfo->Clear(); m_TextInfo->Clear();
SetTitle( text );
return; return;
} }
text = _( "File:" ); text = _( "File:" );
text << wxT( " " ) << gerber->m_FileName; text << wxT( " " ) << gerber->m_FileName;
SetTitle( text );
// Display Image Name and Layer Name (from the current gerber data): // Display Image Name and Layer Name (from the current gerber data):
text.Printf( _("Image name: \"%s\" Layer name \"%s\""), text.Printf( _("Image name: \"%s\" Layer name \"%s\""),
GetChars(gerber->m_ImageName), GetChars(gerber->m_LayerName) ); GetChars(gerber->m_ImageName), GetChars(gerber->m_LayerName) );
SetStatusText( text, 0 ); SetStatusText( text, 0 );
// Display data format like fmt in X3.4Y3.4 or fmt mm X2.3 Y3.5 // Display data format like fmt in X3.4Y3.4 no LZ or fmt mm X2.3 Y3.5 no TZ in main toolbar
text.Printf(wxT("fmt %s X%d.%d Y%d.%d"), text.Printf(wxT("fmt: %s X%d.%d Y%d.%d no %cZ"),
gerber->m_GerbMetric ? wxT("mm") : wxT("in"), gerber->m_GerbMetric ? wxT("mm") : wxT("in"),
gerber->m_FmtLen.x - gerber->m_FmtScale.x, gerber->m_FmtScale.x, gerber->m_FmtLen.x - gerber->m_FmtScale.x, gerber->m_FmtScale.x,
gerber->m_FmtLen.y - gerber->m_FmtScale.y, gerber->m_FmtScale.y ); gerber->m_FmtLen.y - gerber->m_FmtScale.y, gerber->m_FmtScale.y,
gerber->m_NoTrailingZeros ? 'T' : 'L');
m_TextInfo->SetValue( text ); m_TextInfo->SetValue( text );
} }
......
...@@ -453,7 +453,7 @@ static void fillArcPOLY( BOARD* aPcb, GERBER_DRAW_ITEM* aGbrItem, ...@@ -453,7 +453,7 @@ static void fillArcPOLY( BOARD* aPcb, GERBER_DRAW_ITEM* aGbrItem,
wxPoint GERBER::ReadXYCoord( char*& Text ) wxPoint GERBER::ReadXYCoord( char*& Text )
{ {
wxPoint pos = m_CurrentPos; wxPoint pos = m_CurrentPos;
int type_coord = 0, current_coord, nbchar; int type_coord = 0, current_coord, nbdigits;
bool is_float = false; bool is_float = false;
char* text; char* text;
char line[256]; char line[256];
...@@ -475,15 +475,16 @@ wxPoint GERBER::ReadXYCoord( char*& Text ) ...@@ -475,15 +475,16 @@ wxPoint GERBER::ReadXYCoord( char*& Text )
type_coord = *Text; type_coord = *Text;
Text++; Text++;
text = line; text = line;
nbchar = 0; nbdigits = 0;
while( IsNumber( *Text ) ) while( IsNumber( *Text ) )
{ {
if( *Text == '.' ) if( *Text == '.' )
is_float = true; is_float = true;
*(text++) = *(Text++); // count digits only (sign and decimal point are not counted)
if( (*Text >= '0') && (*Text <='9') ) if( (*Text >= '0') && (*Text <='9') )
nbchar++; nbdigits++;
} *(text++) = *(Text++);
}
*text = 0; *text = 0;
if( is_float ) if( is_float )
...@@ -495,24 +496,21 @@ wxPoint GERBER::ReadXYCoord( char*& Text ) ...@@ -495,24 +496,21 @@ wxPoint GERBER::ReadXYCoord( char*& Text )
} }
else else
{ {
int fmt_scale = int fmt_scale = (type_coord == 'X') ? m_FmtScale.x : m_FmtScale.y;
(type_coord == 'X') ? m_FmtScale.x : m_FmtScale.y;
if( m_NoTrailingZeros ) if( m_NoTrailingZeros )
{ {
int min_digit = int min_digit =
(type_coord == 'X') ? m_FmtLen.x : m_FmtLen.y; (type_coord == 'X') ? m_FmtLen.x : m_FmtLen.y;
while( nbchar < min_digit ) while( nbdigits < min_digit )
{ {
*(text++) = '0'; *(text++) = '0';
nbchar++; nbdigits++;
} }
*text = 0; *text = 0;
} }
current_coord = atoi( line ); current_coord = atoi( line );
double real_scale = 1.0; double real_scale = 1.0;
if( fmt_scale < 0 || fmt_scale > 9 )
fmt_scale = 4;
double scale_list[10] = double scale_list[10] =
{ {
10000.0, 1000.0, 100.0, 10.0, 10000.0, 1000.0, 100.0, 10.0,
...@@ -557,7 +555,7 @@ wxPoint GERBER::ReadIJCoord( char*& Text ) ...@@ -557,7 +555,7 @@ wxPoint GERBER::ReadIJCoord( char*& Text )
{ {
wxPoint pos( 0, 0 ); wxPoint pos( 0, 0 );
int type_coord = 0, current_coord, nbchar; int type_coord = 0, current_coord, nbdigits;
bool is_float = false; bool is_float = false;
char* text; char* text;
char line[256]; char line[256];
...@@ -573,14 +571,15 @@ wxPoint GERBER::ReadIJCoord( char*& Text ) ...@@ -573,14 +571,15 @@ wxPoint GERBER::ReadIJCoord( char*& Text )
type_coord = *Text; type_coord = *Text;
Text++; Text++;
text = line; text = line;
nbchar = 0; nbdigits = 0;
while( IsNumber( *Text ) ) while( IsNumber( *Text ) )
{ {
if( *Text == '.' ) if( *Text == '.' )
is_float = true; is_float = true;
*(text++) = *(Text++); // count digits only (sign and decimal point are not counted)
if( (*Text >= '0') && (*Text <='9') ) if( (*Text >= '0') && (*Text <='9') )
nbchar++; nbdigits++;
*(text++) = *(Text++);
} }
*text = 0; *text = 0;
...@@ -599,10 +598,10 @@ wxPoint GERBER::ReadIJCoord( char*& Text ) ...@@ -599,10 +598,10 @@ wxPoint GERBER::ReadIJCoord( char*& Text )
{ {
int min_digit = int min_digit =
(type_coord == 'I') ? m_FmtLen.x : m_FmtLen.y; (type_coord == 'I') ? m_FmtLen.x : m_FmtLen.y;
while( nbchar < min_digit ) while( nbdigits < min_digit )
{ {
*(text++) = '0'; *(text++) = '0';
nbchar++; nbdigits++;
} }
*text = 0; *text = 0;
......
...@@ -225,11 +225,20 @@ bool GERBER::ExecuteRS274XCommand( int command, ...@@ -225,11 +225,20 @@ bool GERBER::ExecuteRS274XCommand( int command,
// number of digits after the decimal point // number of digits after the decimal point
m_FmtScale.x = *text - '0'; m_FmtScale.x = *text - '0';
m_FmtLen.x = ctmp + m_FmtScale.x; m_FmtLen.x = ctmp + m_FmtScale.x;
// m_FmtScale is 0 to 9
if( m_FmtScale.x < 0 )
m_FmtScale.x = 0;
if( m_FmtScale.x > 9 )
m_FmtScale.x = 9;
} }
else else
{ {
m_FmtScale.y = *text - '0'; m_FmtScale.y = *text - '0';
m_FmtLen.y = ctmp + m_FmtScale.y; m_FmtLen.y = ctmp + m_FmtScale.y;
if( m_FmtScale.y < 0 )
m_FmtScale.y = 0;
if( m_FmtScale.y > 9 )
m_FmtScale.y = 9;
} }
text++; text++;
} }
...@@ -285,6 +294,29 @@ bool GERBER::ExecuteRS274XCommand( int command, ...@@ -285,6 +294,29 @@ bool GERBER::ExecuteRS274XCommand( int command,
break; break;
case SCALE_FACTOR: case SCALE_FACTOR:
m_LayerScale.x = m_LayerScale.y = 1.0;
while( *text != '*' )
{
switch( *text )
{
case 'A': // A axis scale
text++;
m_LayerScale.x = ReadDouble( text );
break;
case 'B': // B axis scale
text++;
m_LayerScale.y = ReadDouble( text );
break;
}
}
if( m_LayerScale.x != 1.0 || m_LayerScale.y != 1.0 )
{
msg.Printf( _( "RS274X: FS command: Gerbview uses 1.0 only scale factor") );
ReportMessage( msg );
}
break;
case IMAGE_JUSTIFY: case IMAGE_JUSTIFY:
case IMAGE_ROTATION: case IMAGE_ROTATION:
case IMAGE_OFFSET: case IMAGE_OFFSET:
...@@ -292,11 +324,9 @@ bool GERBER::ExecuteRS274XCommand( int command, ...@@ -292,11 +324,9 @@ bool GERBER::ExecuteRS274XCommand( int command,
case KNOCKOUT: case KNOCKOUT:
case STEP_AND_REPEAT: case STEP_AND_REPEAT:
case ROTATE: case ROTATE:
{
msg.Printf( _( "RS274X: Command \"%c%c\" ignored by Gerbview" ), msg.Printf( _( "RS274X: Command \"%c%c\" ignored by Gerbview" ),
(command >> 8) & 0xFF, command & 0xFF ); (command >> 8) & 0xFF, command & 0xFF );
ReportMessage( msg ); ReportMessage( msg );
}
break; break;
case IMAGE_NAME: case IMAGE_NAME:
......
...@@ -27,6 +27,8 @@ class EDA_Rect; ...@@ -27,6 +27,8 @@ class EDA_Rect;
//wxWidgets 2.8 compatibility //wxWidgets 2.8 compatibility
#if !wxCHECK_VERSION(2,9,0) #if !wxCHECK_VERSION(2,9,0)
#define wxPENSTYLE_SOLID wxSOLID #define wxPENSTYLE_SOLID wxSOLID
#define wxPENSTYLE_SHORT_DASH wxSHORT_DASH
#define wxPENSTYLE_DOT_DASH wxDOT_DASH
typedef int wxPenStyle; typedef int wxPenStyle;
#endif #endif
...@@ -51,7 +53,7 @@ class WinEDA_DrawPanel; ...@@ -51,7 +53,7 @@ class WinEDA_DrawPanel;
void GRSetDrawMode( wxDC* DC, int mode ); void GRSetDrawMode( wxDC* DC, int mode );
int GRGetDrawMode( wxDC* DC ); int GRGetDrawMode( wxDC* DC );
void GRResetPenAndBrush( wxDC* DC ); void GRResetPenAndBrush( wxDC* DC );
void GRSetColorPen( wxDC* DC, int Color, int width = 1, int stype = wxSOLID ); void GRSetColorPen( wxDC* DC, int Color, int width = 1, wxPenStyle stype = wxPENSTYLE_SOLID );
void GRSetBrush( wxDC* DC, int Color, int fill = 0 ); void GRSetBrush( wxDC* DC, int Color, int fill = 0 );
/** function GRForceBlackPen /** function GRForceBlackPen
...@@ -191,7 +193,7 @@ void GRRect( EDA_Rect* ClipBox, wxDC* DC,const EDA_Rect& aRect, int Color ); ...@@ -191,7 +193,7 @@ void GRRect( EDA_Rect* ClipBox, wxDC* DC,const EDA_Rect& aRect, int Color );
void GRRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, void GRRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
int x2, int y2, int width, int Color ); int x2, int y2, int width, int Color );
void GRRectPs( EDA_Rect* aClipBox, wxDC* aDC,const EDA_Rect& aRect, void GRRectPs( EDA_Rect* aClipBox, wxDC* aDC,const EDA_Rect& aRect,
int aWidth, int aColor, int aStyle = wxSOLID ); int aWidth, int aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
int x2, int y2, int width, int Color, int BgColor ); int x2, int y2, int width, int Color, int BgColor );
......
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