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>
#include <wx/log.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 44 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 57 of file rs274x.cpp.

57 {
58 // Directive parameters: single usage recommended
59 // Must be at the beginning of the file
60 AXIS_SELECT = CODE( 'A', 'S' ), // Default: A=X, B=Y
61 FORMAT_STATEMENT = CODE( 'F', 'S' ), // no default: this command must exists
62 MIRROR_IMAGE = CODE( 'M', 'I' ), // Default: mo mirror
63 MODE_OF_UNITS = CODE( 'M', 'O' ), // Default: inch
64 INCH = CODE( 'I', 'N' ),
65 MILLIMETER = CODE( 'M', 'M' ),
66 OFFSET = CODE( 'O', 'F' ), // Default: A = 0, B = 0
67 SCALE_FACTOR = CODE( 'S', 'F' ), // Default: A = 1.0, B = 1.0
68
69 // Image parameters:
70 // commands used only once at the beginning of the file, and are deprecated
71 IMAGE_JUSTIFY = CODE( 'I', 'J' ), // Default: no justification
72 IMAGE_NAME = CODE( 'I', 'N' ), // Default: void
73 IMAGE_OFFSET = CODE( 'I', 'O' ), // Default: A = 0, B = 0
74 IMAGE_POLARITY = CODE( 'I', 'P' ), // Default: Positive
75 IMAGE_ROTATION = CODE( 'I', 'R' ), // Default: 0
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 extension 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 extension 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 extension 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 specific
105 // These parameters are at the beginning of the file or layer
106 // and reset some layer parameters (like interpolation)
107 KNOCKOUT = CODE( 'K', 'O' ), // Default: off
108 STEP_AND_REPEAT = CODE( 'S', 'R' ), // Default: A = 1, B = 1
109 ROTATE = CODE( 'R', 'O' ), // Default: 0
110
111 LOAD_POLARITY = CODE( 'L', 'P' ), //LPC or LPD. Default: Dark (LPD)
112 LOAD_NAME = CODE( 'L', 'N' ), // Deprecated: equivalent to G04
113};
@ FILE_ATTRIBUTE
Definition: rs274x.cpp:87
@ IMAGE_JUSTIFY
Definition: rs274x.cpp:71
@ APERTURE_ATTRIBUTE
Definition: rs274x.cpp:95
@ FORMAT_STATEMENT
Definition: rs274x.cpp:61
@ NET_ATTRIBUTE
Definition: rs274x.cpp:92
@ IMAGE_OFFSET
Definition: rs274x.cpp:73
@ ROTATE
Definition: rs274x.cpp:109
@ STEP_AND_REPEAT
Definition: rs274x.cpp:108
@ LOAD_NAME
Definition: rs274x.cpp:112
@ REMOVE_APERTURE_ATTRIBUTE
Definition: rs274x.cpp:101
@ KNOCKOUT
Definition: rs274x.cpp:107
@ AP_MACRO
Definition: rs274x.cpp:80
@ MIRROR_IMAGE
Definition: rs274x.cpp:62
@ MODE_OF_UNITS
Definition: rs274x.cpp:63
@ INCH
Definition: rs274x.cpp:64
@ IMAGE_NAME
Definition: rs274x.cpp:72
@ OFFSET
Definition: rs274x.cpp:66
@ MILLIMETER
Definition: rs274x.cpp:65
@ AXIS_SELECT
Definition: rs274x.cpp:60
@ SCALE_FACTOR
Definition: rs274x.cpp:67
@ IMAGE_ROTATION
Definition: rs274x.cpp:75
@ LOAD_POLARITY
Definition: rs274x.cpp:111
@ IMAGE_POLARITY
Definition: rs274x.cpp:74
@ AP_DEFINITION
Definition: rs274x.cpp:79
#define CODE(x, y)
Definition: rs274x.cpp:44

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 303 of file rs274_read_XY_and_IJ_coordinates.cpp.

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

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 266 of file rs274_read_XY_and_IJ_coordinates.cpp.

267{
268 int ret;
269
270 // For strtol, a string starting by 0X or 0x is a valid number in hexadecimal or octal.
271 // However, 'X' is a separator in Gerber strings with numbers.
272 // We need to detect that
273 if( strncasecmp( text, "0X", 2 ) == 0 )
274 {
275 text++;
276 ret = 0;
277 }
278 else
279 {
280 ret = (int) strtol( text, &text, 10 );
281 }
282
283 if( *text == ',' || isspace( *text ) )
284 {
285 if( aSkipSeparator )
286 ++text;
287 }
288
289 return ret;
290}

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