Gerbview: accept any structured comment as X2 attribute.

A structured comment is a comment line starting by "G04 #@! " and in fact containing
a X2 attribute. It is used to create Gerber files contianing X2 metadata, but compatible
with X1 file format
This commit is contained in:
jean-pierre charras 2018-05-13 18:22:09 +02:00
parent 1a6e8d4713
commit 8da242c593
4 changed files with 40 additions and 26 deletions

View File

@ -298,11 +298,20 @@ public:
/**
* Function ExecuteRS274XCommand
* executes 1 command
* executes a RS274X command
*/
bool ExecuteRS274XCommand( int aCommand, char* aBuff,
unsigned int aBuffSize, char*& aText );
/**
* reads two bytes of data and assembles them into an int with the first
* byte in the sequence put into the most significant part of a 16 bit value
* to build a RS274X command identifier.
* @param text A reference to a pointer to read bytes from and to advance as
* they are read.
* @return a RS274X command identifier.
*/
int ReadXCommandID( char*& text );
/**
* Function ReadApertureMacro

View File

@ -83,6 +83,7 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
}
auto canvas = GetGalCanvas();
if( canvas )
{
auto view = canvas->GetView();

View File

@ -42,7 +42,7 @@
* G01 linear interpolation (right trace)
* G02, G20, G21 Circular interpolation, meaning trig <0 (clockwise)
* G03, G30, G31 Circular interpolation, meaning trigo> 0 (counterclockwise)
* G04 = comment. Since Sept 2014, file attributes can be found here
* G04 = comment. Since Sept 2014, file attributes and other X2 attributes can be found here
* if the line starts by G04 #@!
* G06 parabolic interpolation
* G07 Cubic Interpolation
@ -478,22 +478,32 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command )
break;
case GC_COMMENT:
// Skip comment, but only if the line does not start by "G04 #@! TF"
// which is a metadata
if( strncmp( text, " #@! TF", 7 ) == 0 )
// Skip comment, but only if the line does not start by "G04 #@! "
// which is a metadata, i.e. a X2 command inside the comment.
// this comment is called a "structured comment"
if( strncmp( text, " #@! ", 5 ) == 0 )
{
text += 7;
X2_ATTRIBUTE dummy;
dummy.ParseAttribCmd( m_Current_File, NULL, 0, text, m_LineNum );
if( dummy.IsFileFunction() )
text += 5;
// The string starting at text is the same as the X2 attribute,
// but a X2 attribute ends by '%'. So we build the X2 attribute string
std::string x2buf;
while( *text && (*text != '*') )
{
delete m_FileFunction;
m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy );
x2buf += *text;
text++;
}
// add the end of X2 attribute string
x2buf += "*%";
x2buf += '\0';
char* cptr = (char*)x2buf.data();
int code_command = ReadXCommandID( cptr );
ExecuteRS274XCommand( code_command, NULL, 0, cptr );
}
while ( *text && (*text != '*') )
text++;
while( *text && (*text != '*') )
text++;
break;
case GC_LINEAR_INTERPOL_10X:

View File

@ -111,17 +111,11 @@ enum RS274X_PARAMETERS {
};
/**
* Function ReadXCommand
* reads in two bytes of data and assembles them into an int with the first
* byte in the sequence put into the most significant part of a 16 bit value
* and the second byte put into the least significant part of the 16 bit value.
* @param text A reference to a pointer to read bytes from and to advance as
* they are read.
* @return int - with 16 bits of data in the ls bits, upper bits zeroed.
*/
static int ReadXCommand( char*& text )
int GERBER_FILE_IMAGE::ReadXCommandID( char*& text )
{
/* reads two bytes of data and assembles them into an int with the first
* byte in the sequence put into the most significant part of a 16 bit value
*/
int result;
int currbyte;
@ -218,7 +212,7 @@ bool GERBER_FILE_IMAGE::ReadRS274XCommand( char *aBuff, unsigned int aBuffSize,
break;
default:
code_command = ReadXCommand( aText );
code_command = ReadXCommandID( aText );
ok = ExecuteRS274XCommand( code_command, aBuff, aBuffSize, aText );
if( !ok )
goto exit;
@ -403,7 +397,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
break;
case MODE_OF_UNITS:
code = ReadXCommand( aText );
code = ReadXCommandID( aText );
if( code == INCH )
m_GerbMetric = false;
else if( code == MILLIMETER )
@ -433,7 +427,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
}
break;
case APERTURE_ATTRIBUTE: // Command %TA ... Not yet supported
case APERTURE_ATTRIBUTE: // Command %TA
{
X2_ATTRIBUTE dummy;
dummy.ParseAttribCmd( m_Current_File, aBuff, aBuffSize, aText, m_LineNum );