Cleanup formatting

This commit is contained in:
Ian McInerney 2020-09-21 12:15:03 +01:00
parent 9e6a1225db
commit 7dfbb3cb18
1 changed files with 55 additions and 16 deletions

View File

@ -262,16 +262,20 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
// Obscure option // Obscure option
aText++; aText++;
seq_char = *aText++; seq_char = *aText++;
if( (seq_char >= '0') && (seq_char <= '9') ) if( (seq_char >= '0') && (seq_char <= '9') )
seq_len = seq_char - '0'; seq_len = seq_char - '0';
break; break;
case 'M': // Sequence code (followed by one digit: the sequence len) case 'M': // Sequence code (followed by one digit: the sequence len)
// (sometimes found after the X,Y sequence) // (sometimes found after the X,Y sequence)
// Obscure option // Obscure option
code = *aText++; code = *aText++;
if( ( *aText >= '0' ) && ( *aText<= '9' ) ) if( ( *aText >= '0' ) && ( *aText<= '9' ) )
aText++; // skip the digit aText++; // skip the digit
break; break;
case 'X': case 'X':
@ -279,6 +283,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
{ {
code = *(aText++); code = *(aText++);
char ctmp = *(aText++) - '0'; char ctmp = *(aText++) - '0';
if( code == 'X' ) if( code == 'X' )
{ {
x_fmt_known = true; x_fmt_known = true;
@ -290,6 +295,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
// (Old Gerber specification was 0 to 6) // (Old Gerber specification was 0 to 6)
if( m_FmtScale.x < 0 ) if( m_FmtScale.x < 0 )
m_FmtScale.x = 0; m_FmtScale.x = 0;
if( m_FmtScale.x > 7 ) if( m_FmtScale.x > 7 )
m_FmtScale.x = 7; m_FmtScale.x = 7;
} }
@ -298,11 +304,14 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
y_fmt_known = true; y_fmt_known = true;
m_FmtScale.y = *aText - '0'; m_FmtScale.y = *aText - '0';
m_FmtLen.y = ctmp + m_FmtScale.y; m_FmtLen.y = ctmp + m_FmtScale.y;
if( m_FmtScale.y < 0 ) if( m_FmtScale.y < 0 )
m_FmtScale.y = 0; m_FmtScale.y = 0;
if( m_FmtScale.y > 7 ) if( m_FmtScale.y > 7 )
m_FmtScale.y = 7; m_FmtScale.y = 7;
} }
aText++; aText++;
} }
break; break;
@ -319,6 +328,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
break; break;
} }
} }
if( !x_fmt_known || !y_fmt_known ) if( !x_fmt_known || !y_fmt_known )
AddMessageToList( wxT( "RS274X: Format Statement (FS) without X or Y format" ) ); AddMessageToList( wxT( "RS274X: Format Statement (FS) without X or Y format" ) );
@ -326,26 +336,33 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
case AXIS_SELECT: // command ASAXBY*% or %ASAYBX*% case AXIS_SELECT: // command ASAXBY*% or %ASAYBX*%
m_SwapAxis = false; m_SwapAxis = false;
if( strncasecmp( aText, "AYBX", 4 ) == 0 ) if( strncasecmp( aText, "AYBX", 4 ) == 0 )
m_SwapAxis = true; m_SwapAxis = true;
break; break;
case MIRROR_IMAGE: // command %MIA0B0*%, %MIA0B1*%, %MIA1B0*%, %MIA1B1*% case MIRROR_IMAGE: // command %MIA0B0*%, %MIA0B1*%, %MIA1B0*%, %MIA1B1*%
m_MirrorA = m_MirrorB = 0; m_MirrorA = m_MirrorB = 0;
while( *aText && *aText != '*' ) while( *aText && *aText != '*' )
{ {
switch( *aText ) switch( *aText )
{ {
case 'A': // Mirror A axis ? case 'A': // Mirror A axis ?
aText++; aText++;
if( *aText == '1' ) if( *aText == '1' )
m_MirrorA = true; m_MirrorA = true;
break; break;
case 'B': // Mirror B axis ? case 'B': // Mirror B axis ?
aText++; aText++;
if( *aText == '1' ) if( *aText == '1' )
m_MirrorB = true; m_MirrorB = true;
break; break;
default: default:
@ -357,16 +374,18 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
case MODE_OF_UNITS: case MODE_OF_UNITS:
code = ReadXCommandID( aText ); code = ReadXCommandID( aText );
if( code == INCH ) if( code == INCH )
m_GerbMetric = false; m_GerbMetric = false;
else if( code == MILLIMETER ) else if( code == MILLIMETER )
m_GerbMetric = true; m_GerbMetric = true;
conv_scale = m_GerbMetric ? IU_PER_MILS / 25.4 : IU_PER_MILS; conv_scale = m_GerbMetric ? IU_PER_MILS / 25.4 : IU_PER_MILS;
break; break;
case FILE_ATTRIBUTE: // Command %TF ... case FILE_ATTRIBUTE: // Command %TF ...
m_IsX2_file = true; m_IsX2_file = true;
{ {
X2_ATTRIBUTE dummy; X2_ATTRIBUTE dummy;
dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum ); dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum );
@ -383,11 +402,11 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
{ {
m_PartString = dummy.GetPrm( 1 ); m_PartString = dummy.GetPrm( 1 );
} }
} }
break; break;
case APERTURE_ATTRIBUTE: // Command %TA case APERTURE_ATTRIBUTE: // Command %TA
{ {
X2_ATTRIBUTE dummy; X2_ATTRIBUTE dummy;
dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum ); dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum );
@ -399,11 +418,11 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
for( int ii = 2; ii < dummy.GetPrmCount(); ii++ ) for( int ii = 2; ii < dummy.GetPrmCount(); ii++ )
m_AperFunction << "," << dummy.GetPrm( ii ); m_AperFunction << "," << dummy.GetPrm( ii );
} }
} }
break; break;
case NET_ATTRIBUTE: // Command %TO currently %TO.P %TO.N and %TO.C case NET_ATTRIBUTE: // Command %TO currently %TO.P %TO.N and %TO.C
{ {
X2_ATTRIBUTE dummy; X2_ATTRIBUTE dummy;
dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum ); dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum );
@ -425,20 +444,24 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
m_NetAttributeDict.m_Padname.SetField( FormatStringFromGerber( dummy.GetPrm( 2 ) ), true, true ); m_NetAttributeDict.m_Padname.SetField( FormatStringFromGerber( dummy.GetPrm( 2 ) ), true, true );
if( dummy.GetPrmCount() > 3 ) if( dummy.GetPrmCount() > 3 )
{
m_NetAttributeDict.m_PadPinFunction.SetField( m_NetAttributeDict.m_PadPinFunction.SetField(
FormatStringFromGerber( dummy.GetPrm( 3 ) ), true, true ); FormatStringFromGerber( dummy.GetPrm( 3 ) ), true, true );
}
else else
{
m_NetAttributeDict.m_PadPinFunction.Clear(); m_NetAttributeDict.m_PadPinFunction.Clear();
}
} }
} }
break; break;
case REMOVE_APERTURE_ATTRIBUTE: // Command %TD ... case REMOVE_APERTURE_ATTRIBUTE: // Command %TD ...
{ {
X2_ATTRIBUTE dummy; X2_ATTRIBUTE dummy;
dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum ); dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum );
RemoveAttribute( dummy ); RemoveAttribute( dummy );
} }
break; break;
case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset
@ -513,6 +536,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
m_ImageRotation = 270; m_ImageRotation = 270;
else else
AddMessageToList( _( "RS274X: Command \"IR\" rotation value not allowed" ) ); AddMessageToList( _( "RS274X: Command \"IR\" rotation value not allowed" ) );
break; break;
case STEP_AND_REPEAT: // command SR, like %SRX3Y2I5.0J2*% case STEP_AND_REPEAT: // command SR, like %SRX3Y2I5.0J2*%
@ -522,6 +546,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
GetLayerParams().m_XRepeatCount = 1; GetLayerParams().m_XRepeatCount = 1;
GetLayerParams().m_YRepeatCount = 1; // The repeat count GetLayerParams().m_YRepeatCount = 1; // The repeat count
GetLayerParams().m_StepForRepeatMetric = m_GerbMetric; // the step units GetLayerParams().m_StepForRepeatMetric = m_GerbMetric; // the step units
while( *aText && *aText != '*' ) while( *aText && *aText != '*' )
{ {
switch( *aText ) switch( *aText )
@ -545,6 +570,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
aText++; aText++;
GetLayerParams().m_YRepeatCount = ReadInt( aText ); GetLayerParams().m_YRepeatCount = ReadInt( aText );
break; break;
default: default:
aText++; aText++;
break; break;
@ -563,6 +589,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
{ {
case 'A': // A axis justify case 'A': // A axis justify
aText++; aText++;
if( *aText == 'C' ) if( *aText == 'C' )
{ {
m_ImageJustifyXCenter = true; m_ImageJustifyXCenter = true;
@ -573,11 +600,16 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
m_ImageJustifyXCenter = true; m_ImageJustifyXCenter = true;
aText++; aText++;
} }
else m_ImageJustifyOffset.x = KiROUND( ReadDouble( aText ) * conv_scale); else
{
m_ImageJustifyOffset.x = KiROUND( ReadDouble( aText ) * conv_scale);
}
break; break;
case 'B': // B axis justify case 'B': // B axis justify
aText++; aText++;
if( *aText == 'C' ) if( *aText == 'C' )
{ {
m_ImageJustifyYCenter = true; m_ImageJustifyYCenter = true;
@ -588,17 +620,25 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
m_ImageJustifyYCenter = true; m_ImageJustifyYCenter = true;
aText++; aText++;
} }
else m_ImageJustifyOffset.y = KiROUND( ReadDouble( aText ) * conv_scale); else
{
m_ImageJustifyOffset.y = KiROUND( ReadDouble( aText ) * conv_scale);
}
break; break;
default: default:
aText++; aText++;
break; break;
} }
} }
if( m_ImageJustifyXCenter ) if( m_ImageJustifyXCenter )
m_ImageJustifyOffset.x = 0; m_ImageJustifyOffset.x = 0;
if( m_ImageJustifyYCenter ) if( m_ImageJustifyYCenter )
m_ImageJustifyOffset.y = 0; m_ImageJustifyOffset.y = 0;
break; break;
case KNOCKOUT: case KNOCKOUT:
@ -608,25 +648,22 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
break; break;
case ROTATE: // Layer rotation: command like %RO45*% case ROTATE: // Layer rotation: command like %RO45*%
m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
m_LocalRotation =ReadDouble( aText ); // Store layer rotation in degrees m_LocalRotation = ReadDouble( aText ); // Store layer rotation in degrees
break; break;
case IMAGE_NAME: case IMAGE_NAME:
m_ImageName.Empty(); m_ImageName.Empty();
while( *aText != '*' ) while( *aText != '*' )
{
m_ImageName.Append( *aText++ ); m_ImageName.Append( *aText++ );
}
break; break;
case LOAD_NAME: case LOAD_NAME:
// %LN is a (deprecated) equivalentto G04: a comment // %LN is a (deprecated) equivalentto G04: a comment
while( *aText && *aText != '*' ) while( *aText && *aText != '*' )
{
aText++; // Skip text aText++; // Skip text
}
break; break;
@ -993,9 +1030,11 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
case AMP_COMMENT: // lines starting by 0 are a comment case AMP_COMMENT: // lines starting by 0 are a comment
paramCount = 0; paramCount = 0;
is_comment = true; is_comment = true;
// Skip comment // Skip comment
while( *aText && ( *aText != '*' ) ) while( *aText && ( *aText != '*' ) )
aText++; aText++;
break; break;
case AMP_CIRCLE: case AMP_CIRCLE: