KiCad PCB EDA Suite
rs274x.cpp File Reference
#include <fctsys.h>
#include <common.h>
#include <macros.h>
#include <base_units.h>
#include <gerbview.h>
#include <class_gerber_file_image.h>
#include <class_X2_gerber_attributes.h>

Go to the source code of this file.

Macros

#define CODE(x, y)   ( ( (x) << 8 ) + (y) )
 

Enumerations

enum  RS274X_PARAMETERS {
  AXIS_SELECT = CODE( 'A', 'S' ), FORMAT_STATEMENT = CODE( 'F', 'S' ), MIRROR_IMAGE = CODE( 'M', 'I' ), MODE_OF_UNITS = CODE( 'M', 'O' ),
  INCH = CODE( 'I', 'N' ), MILLIMETER = CODE( 'M', 'M' ), OFFSET = CODE( 'O', 'F' ), SCALE_FACTOR = CODE( 'S', 'F' ),
  IMAGE_JUSTIFY = CODE( 'I', 'J' ), IMAGE_NAME = CODE( 'I', 'N' ), IMAGE_OFFSET = CODE( 'I', 'O' ), IMAGE_POLARITY = CODE( 'I', 'P' ),
  IMAGE_ROTATION = CODE( 'I', 'R' ), PLOTTER_FILM = CODE( 'P', 'M' ), AP_DEFINITION = CODE( 'A', 'D' ), AP_MACRO = CODE( 'A', 'M' ),
  FILE_ATTRIBUTE = CODE( 'T', 'F' ), NET_ATTRIBUTE = CODE( 'T', 'O' ), APERTURE_ATTRIBUTE = CODE( 'T', 'A' ), REMOVE_APERTURE_ATTRIBUTE = CODE( 'T', 'D' ),
  LAYER_NAME = CODE( 'L', 'N' ), LAYER_POLARITY = CODE( 'L', 'P' ), KNOCKOUT = CODE( 'K', 'O' ), STEP_AND_REPEAT = CODE( 'S', 'R' ),
  ROTATE = CODE( 'R', 'O' ), INCLUDE_FILE = CODE( 'I', 'F' )
}
 

Functions

int ReadInt (char *&text, bool aSkipSeparator=true)
 Function ReadInt reads an int from an ASCII character buffer. More...
 
double ReadDouble (char *&text, bool aSkipSeparator=true)
 Function ReadDouble reads a double from an ASCII character buffer. More...
 
bool GetEndOfBlock (char *buff, char *&text, FILE *gerber_file)
 
static int ReadXCommand (char *&text)
 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. More...
 
static const wxString fromGerberString (const wxString &aGbrString)
 convert a string read from a gerber file to an unicode string usual chars are just copied. More...
 
static char * GetNextLine (char *aBuff, char *aText, FILE *aFile)
 Function GetNextLine test for an end of line if an end of line is found: read a new line. More...
 

Macro Definition Documentation

#define CODE (   x,
 
)    ( ( (x) << 8 ) + (y) )

Definition at line 43 of file rs274x.cpp.

Enumeration Type Documentation

Enumerator
AXIS_SELECT 
FORMAT_STATEMENT 
MIRROR_IMAGE 
MODE_OF_UNITS 
INCH 
MILLIMETER 
OFFSET 
SCALE_FACTOR 
IMAGE_JUSTIFY 
IMAGE_NAME 
IMAGE_OFFSET 
IMAGE_POLARITY 
IMAGE_ROTATION 
PLOTTER_FILM 
AP_DEFINITION 
AP_MACRO 
FILE_ATTRIBUTE 
NET_ATTRIBUTE 
APERTURE_ATTRIBUTE 
REMOVE_APERTURE_ATTRIBUTE 
LAYER_NAME 
LAYER_POLARITY 
KNOCKOUT 
STEP_AND_REPEAT 
ROTATE 
INCLUDE_FILE 

Definition at line 56 of file rs274x.cpp.

56  {
57  // Directive parameters: single usage recommended
58  // Must be at the beginning of the file
59  AXIS_SELECT = CODE( 'A', 'S' ), // Default: A=X, B=Y
60  FORMAT_STATEMENT = CODE( 'F', 'S' ), // no default: this command must exists
61  MIRROR_IMAGE = CODE( 'M', 'I' ), // Default: mo mirror
62  MODE_OF_UNITS = CODE( 'M', 'O' ), // Default: inch
63  INCH = CODE( 'I', 'N' ),
64  MILLIMETER = CODE( 'M', 'M' ),
65  OFFSET = CODE( 'O', 'F' ), // Default: A = 0, B = 0
66  SCALE_FACTOR = CODE( 'S', 'F' ), // Default: A = 1.0, B = 1.0
67 
68  // Image parameters:
69  // commands used only once at the beginning of the file
70  IMAGE_JUSTIFY = CODE( 'I', 'J' ), // Default: no justification
71  IMAGE_NAME = CODE( 'I', 'N' ), // Default: void
72  IMAGE_OFFSET = CODE( 'I', 'O' ), // Default: A = 0, B = 0
73  IMAGE_POLARITY = CODE( 'I', 'P' ), // Default: Positive
74  IMAGE_ROTATION = CODE( 'I', 'R' ), // Default: 0
75  PLOTTER_FILM = CODE( 'P', 'M' ),
76 
77  // Aperture parameters:
78  // Usually for the whole file
79  AP_DEFINITION = CODE( 'A', 'D' ),
80  AP_MACRO = CODE( 'A', 'M' ),
81 
82  // X2 extention attribute commands
83  // Mainly are found standard attributes and user attributes
84  // standard attributes commands are:
85  // TF (file attribute) TO (net attribute)
86  // TA (aperture attribute) and TD (delete aperture attribute)
87  FILE_ATTRIBUTE = CODE( 'T', 'F' ),
88 
89  // X2 extention Net attribute info
90  // Net attribute options are:
91  // TO (net attribute data): TO.CN or TO.P TO.N or TO.C
92  NET_ATTRIBUTE = CODE( 'T', 'O' ),
93 
94  // X2 extention Aperture attribute TA
95  APERTURE_ATTRIBUTE = CODE( 'T', 'A' ),
96 
97  // TD (delete aperture/object attribute):
98  // Delete aperture attribute added by %TA or Oblect attribute added b %TO
99  // TD (delete all) or %TD<attr name> to delete <attr name>.
100  // eg: TD.P or TD.N or TD.C ...
101  REMOVE_APERTURE_ATTRIBUTE = CODE( 'T', 'D' ),
102 
103  // Layer specific parameters
104  // May be used singly or may be layer specfic
105  // theses parameters are at the beginning of the file or layer
106  // and reset some layer parameters (like interpolation)
107  LAYER_NAME = CODE( 'L', 'N' ), // Default: Positive
108  LAYER_POLARITY = CODE( 'L', 'P' ),
109  KNOCKOUT = CODE( 'K', 'O' ), // Default: off
110  STEP_AND_REPEAT = CODE( 'S', 'R' ), // Default: A = 1, B = 1
111  ROTATE = CODE( 'R', 'O' ), // Default: 0
112 
113  // Miscellaneous parameters:
114  INCLUDE_FILE = CODE( 'I', 'F' )
115 };
#define CODE(x, y)
Definition: rs274x.cpp:43
Definition: rs274x.cpp:63

Function Documentation

static const wxString fromGerberString ( const wxString &  aGbrString)
static

convert a string read from a gerber file to an unicode string usual chars are just copied.

values are converted to the unicoade char value

Definition at line 156 of file rs274x.cpp.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand().

157 {
158  wxString text;
159 
160  for( unsigned ii = 0; ii < aGbrString.size(); ++ii )
161  {
162  if( aGbrString[ii] == '\\' )
163  {
164  unsigned value = 0;
165 
166  for( int jj = 0; jj < 4; jj++ )
167  { // Convert 4 hexa digits to binary value:
168  ii++;
169  value <<= 4;
170  int digit = aGbrString[ii];
171 
172  if( digit >= '0' && digit <= '9' )
173  digit -= '0';
174  else if( digit >= 'A' && digit <= 'F' )
175  digit -= 'A' - 10;
176  else if( digit >= 'a' && digit <= 'f' )
177  digit -= 'a' - 10;
178  else digit = 0;
179 
180  value += digit & 0xF;
181  }
182 
183  text.Append( wxUniChar( value ) );
184  }
185  else
186  text.Append( aGbrString[ii] );
187  }
188 
189  return text;
190 }
bool GetEndOfBlock ( char *  buff,
char *&  text,
FILE *  gerber_file 
)

Definition at line 940 of file rs274x.cpp.

References GERBER_BUFZ.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand().

941 {
942  for( ; ; )
943  {
944  while( (text < buff + GERBER_BUFZ) && *text )
945  {
946  if( *text == '*' )
947  return true;
948 
949  if( *text == '%' )
950  return true;
951 
952  text++;
953  }
954 
955  if( fgets( buff, GERBER_BUFZ, gerber_file ) == NULL )
956  break;
957 
958  text = buff;
959  }
960 
961  return false;
962 }
#define GERBER_BUFZ
size of single line of a text from a gerber file.
Definition: gerbview.h:39
static char* GetNextLine ( char *  aBuff,
char *  aText,
FILE *  aFile 
)
static

Function GetNextLine test for an end of line if an end of line is found: read a new line.

Parameters
aBuff= buffer (size = GERBER_BUFZ) to fill with a new line
aText= pointer to the last useful char in aBuff on return: points the beginning of the next line.
aFile= the opened GERBER file to read
Returns
a pointer to the beginning of the next line or NULL if end of file

Definition at line 976 of file rs274x.cpp.

References GERBER_BUFZ.

Referenced by GERBER_FILE_IMAGE::ReadApertureMacro().

977 {
978  for( ; ; )
979  {
980  switch (*aText )
981  {
982  case ' ': // skip blanks
983  case '\n':
984  case '\r': // Skip line terminators
985  ++aText;
986  break;
987 
988  case 0: // End of text found in aBuff: Read a new string
989  if( fgets( aBuff, GERBER_BUFZ, aFile ) == NULL )
990  return NULL;
991  aText = aBuff;
992  return aText;
993 
994  default:
995  return aText;
996  }
997  }
998  return aText;
999 }
#define GERBER_BUFZ
size of single line of a text from a gerber file.
Definition: gerbview.h:39
double ReadDouble ( char *&  text,
bool  aSkipSeparator = true 
)

Function ReadDouble reads a double from an ASCII character buffer.

If there is a comma after the double, then skip over that.

Parameters
textA reference to a character pointer from which the ASCII double is read from and the pointer advanced for each character read.
aSkipSeparator= true (default) to skip comma
Returns
double

Definition at line 291 of file rs274_read_XY_and_IJ_coordinates.cpp.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand().

292 {
293  double ret = strtod( text, &text );
294 
295  if( *text == ',' || isspace( *text ) )
296  {
297  if( aSkipSeparator )
298  ++text;
299  }
300 
301  return ret;
302 }
int ReadInt ( char *&  text,
bool  aSkipSeparator = true 
)

Function ReadInt reads an int from an ASCII character buffer.

If there is a comma after the int, then skip over that.

Parameters
textA reference to a character pointer from which bytes are read and the pointer is advanced for each byte read.
aSkipSeparator= true (default) to skip comma
Returns
int - The int read in.

Definition at line 268 of file rs274_read_XY_and_IJ_coordinates.cpp.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand(), and GERBER_FILE_IMAGE::ReadApertureMacro().

269 {
270  int ret = (int) strtol( text, &text, 10 );
271 
272  if( *text == ',' || isspace( *text ) )
273  {
274  if( aSkipSeparator )
275  ++text;
276  }
277 
278  return ret;
279 }
static int ReadXCommand ( char *&  text)
static

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.

Parameters
textA reference to a pointer to read bytes from and to advance as they are read.
Returns
int - with 16 bits of data in the ls bits, upper bits zeroed.

Definition at line 127 of file rs274x.cpp.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand(), and GERBER_FILE_IMAGE::ReadRS274XCommand().

128 {
129  int result;
130  int currbyte;
131 
132  if( text && *text )
133  {
134  currbyte = *text++;
135  result = ( currbyte & 0xFF ) << 8;
136  }
137  else
138  return -1;
139 
140  if( text && *text )
141  {
142  currbyte = *text++;
143  result += currbyte & 0xFF;
144  }
145  else
146  return -1;
147 
148  return result;
149 }