KiCad PCB EDA Suite
rs274_read_XY_and_IJ_coordinates.cpp File Reference
#include <math/util.h>
#include <gerber_file_image.h>
#include <base_units.h>

Go to the source code of this file.

Macros

#define SCALE_LIST_SIZE   9
 

Functions

int scaletoIU (double aCoord, bool isMetric)
 Convert a coordinate given in floating point to GerbView's internal units (currently = 10 nanometers). More...
 
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...
 

Variables

static double scale_list [SCALE_LIST_SIZE]
 

Macro Definition Documentation

◆ SCALE_LIST_SIZE

#define SCALE_LIST_SIZE   9

Definition at line 39 of file rs274_read_XY_and_IJ_coordinates.cpp.

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

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

References text.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand(), AM_PARAM::ReadParam(), and EXCELLON_IMAGE::readToolInformation().

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

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

References text.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand(), GERBER_FILE_IMAGE::ReadApertureMacro(), AM_PARAM::ReadParam(), and EXCELLON_IMAGE::readToolInformation().

◆ scaletoIU()

int scaletoIU ( double  aCoord,
bool  isMetric 
)

Convert a coordinate given in floating point to GerbView's internal units (currently = 10 nanometers).

Function scaletoIU converts a distance given in floating point to our internal units.

Convert a distance given in floating point to our internal units.

Definition at line 58 of file rs274_read_XY_and_IJ_coordinates.cpp.

59{
60 int ret;
61
62 if( isMetric ) // gerber are units in mm
63 ret = KiROUND( aCoord * GERB_IU_PER_MM );
64 else // gerber are units in inches
65 ret = KiROUND( aCoord * GERB_IU_PER_MM * 25.4 );
66
67 return ret;
68}
constexpr double GERB_IU_PER_MM
some define and functions to convert a value in mils, decimils or mm to the internal unit used in pcb...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80

References GERB_IU_PER_MM, and KiROUND().

Referenced by AM_PRIMITIVE::ConvertShapeToPolygon(), AM_PRIMITIVE::DrawBasicShape(), AM_PRIMITIVE::GetShapeDim(), mapPt(), GERBER_FILE_IMAGE::ReadIJCoord(), GERBER_FILE_IMAGE::ReadXYCoord(), and GERBER_FILE_IMAGE::StepAndRepeatItem().

Variable Documentation

◆ scale_list

double scale_list[SCALE_LIST_SIZE]
static
Initial value:
=
{
1000.0 * GERB_IU_PER_MM * 0.0254,
100.0 * GERB_IU_PER_MM * 0.0254,
10.0 * GERB_IU_PER_MM * 0.0254,
1.0 * GERB_IU_PER_MM * 0.0254,
0.1 * GERB_IU_PER_MM * 0.0254,
0.01 * GERB_IU_PER_MM * 0.0254,
0.001 * GERB_IU_PER_MM * 0.0254,
0.0001 * GERB_IU_PER_MM * 0.0254,
0.00001 * GERB_IU_PER_MM * 0.0254,
}

Definition at line 40 of file rs274_read_XY_and_IJ_coordinates.cpp.

Referenced by GERBER_FILE_IMAGE::ReadIJCoord(), and GERBER_FILE_IMAGE::ReadXYCoord().