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 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(), 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 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(), 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 * IU_PER_MM );
64  else // gerber are units in inches
65  ret = KiROUND( aCoord * IU_PER_MILS * 1000.0 );
66 
67  return ret;
68 }
static constexpr double IU_PER_MM
Mock up a conversion function.
#define IU_PER_MILS
Definition: plotter.cpp:136
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:73

References IU_PER_MILS, IU_PER_MM, and KiROUND().

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

Variable Documentation

◆ scale_list

double scale_list[SCALE_LIST_SIZE]
static
Initial value:
=
{
1000.0 * IU_PER_MILS,
100.0 * IU_PER_MILS,
10.0 * IU_PER_MILS,
1.0 * IU_PER_MILS,
0.1 * IU_PER_MILS,
0.01 * IU_PER_MILS,
0.001 * IU_PER_MILS,
0.0001 * IU_PER_MILS,
0.00001 * IU_PER_MILS,
}
#define IU_PER_MILS
Definition: plotter.cpp:136

Definition at line 40 of file rs274_read_XY_and_IJ_coordinates.cpp.

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