KiCad PCB EDA Suite
rs274x.cpp File Reference
#include <base_units.h>
#include <math/util.h>
#include <gerbview.h>
#include <gerber_file_image.h>
#include <ignore.h>
#include <macros.h>
#include <X2_gerber_attributes.h>
#include <gbr_metadata.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' ), 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' ), KNOCKOUT = CODE( 'K', 'O' ),
  STEP_AND_REPEAT = CODE( 'S', 'R' ), ROTATE = CODE( 'R', 'O' ), LOAD_POLARITY = CODE( 'L', 'P' ), LOAD_NAME = CODE( 'L', 'N' )
}
 

Functions

int ReadInt (char *&text, bool aSkipSeparator=true)
 Read an integer from an ASCII character buffer. More...
 
double ReadDouble (char *&text, bool aSkipSeparator=true)
 Read a double precision floating point number from an ASCII character buffer. More...
 

Macro Definition Documentation

◆ CODE

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

Definition at line 43 of file rs274x.cpp.

Enumeration Type Documentation

◆ RS274X_PARAMETERS

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 
AP_DEFINITION 
AP_MACRO 
FILE_ATTRIBUTE 
NET_ATTRIBUTE 
APERTURE_ATTRIBUTE 
REMOVE_APERTURE_ATTRIBUTE 
KNOCKOUT 
STEP_AND_REPEAT 
ROTATE 
LOAD_POLARITY 
LOAD_NAME 

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, and are deprecated
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 
76  // Aperture parameters:
77  // Usually for the whole file
78  AP_DEFINITION = CODE( 'A', 'D' ),
79  AP_MACRO = CODE( 'A', 'M' ),
80 
81  // X2 extension attribute commands
82  // Mainly are found standard attributes and user attributes
83  // standard attributes commands are:
84  // TF (file attribute) TO (net attribute)
85  // TA (aperture attribute) and TD (delete aperture attribute)
86  FILE_ATTRIBUTE = CODE( 'T', 'F' ),
87 
88  // X2 extension Net attribute info
89  // Net attribute options are:
90  // TO (net attribute data): TO.CN or TO.P TO.N or TO.C
91  NET_ATTRIBUTE = CODE( 'T', 'O' ),
92 
93  // X2 extension Aperture attribute TA
94  APERTURE_ATTRIBUTE = CODE( 'T', 'A' ),
95 
96  // TD (delete aperture/object attribute):
97  // Delete aperture attribute added by %TA or Oblect attribute added b %TO
98  // TD (delete all) or %TD<attr name> to delete <attr name>.
99  // eg: TD.P or TD.N or TD.C ...
100  REMOVE_APERTURE_ATTRIBUTE = CODE( 'T', 'D' ),
101 
102  // Layer specific parameters
103  // May be used singly or may be layer specific
104  // These parameters are at the beginning of the file or layer
105  // and reset some layer parameters (like interpolation)
106  KNOCKOUT = CODE( 'K', 'O' ), // Default: off
107  STEP_AND_REPEAT = CODE( 'S', 'R' ), // Default: A = 1, B = 1
108  ROTATE = CODE( 'R', 'O' ), // Default: 0
109 
110  LOAD_POLARITY = CODE( 'L', 'P' ), //LPC or LPD. Default: Dark (LPD)
111  LOAD_NAME = CODE( 'L', 'N' ), // Deprecated: equivalent to G04
112 };
#define CODE(x, y)
Definition: rs274x.cpp:43
Definition: rs274x.cpp:63

Function Documentation

◆ ReadDouble()

double ReadDouble ( char *&  text,
bool  aSkipSeparator = true 
)

Read a double precision floating point number from an ASCII character buffer.

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

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

Definition at line 335 of file rs274_read_XY_and_IJ_coordinates.cpp.

336 {
337  double ret;
338 
339  // For strtod, a string starting by 0X or 0x is a valid number in hexadecimal or octal.
340  // However, 'X' is a separator in Gerber strings with numbers.
341  // We need to detect that
342  if( strncasecmp( text, "0X", 2 ) == 0 )
343  {
344  text++;
345  ret = 0.0;
346  }
347  else
348  {
349  ret = strtod( text, &text );
350  }
351 
352  if( *text == ',' || isspace( *text ) )
353  {
354  if( aSkipSeparator )
355  ++text;
356  }
357 
358  return ret;
359 }

References text.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand().

◆ ReadInt()

int ReadInt ( char *&  text,
bool  aSkipSeparator = true 
)

Read an integer from an ASCII character buffer.

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

Parameters
textis a reference to a character pointer from which bytes are read and the pointer is advanced for each byte read.
aSkipSeparatorset to true (default) to skip comma.
Returns
The integer read in.

Definition at line 298 of file rs274_read_XY_and_IJ_coordinates.cpp.

299 {
300  int ret;
301 
302  // For strtol, a string starting by 0X or 0x is a valid number in hexadecimal or octal.
303  // However, 'X' is a separator in Gerber strings with numbers.
304  // We need to detect that
305  if( strncasecmp( text, "0X", 2 ) == 0 )
306  {
307  text++;
308  ret = 0;
309  }
310  else
311  {
312  ret = (int) strtol( text, &text, 10 );
313  }
314 
315  if( *text == ',' || isspace( *text ) )
316  {
317  if( aSkipSeparator )
318  ++text;
319  }
320 
321  return ret;
322 }

References text.

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