KiCad PCB EDA Suite
rs274_read_XY_and_IJ_coordinates.cpp File Reference
#include <fctsys.h>
#include <common.h>
#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)
 Function scaletoIU converts a distance given in floating point to our internal units. More...
 
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...
 

Variables

static double scale_list [SCALE_LIST_SIZE]
 

Macro Definition Documentation

◆ SCALE_LIST_SIZE

#define SCALE_LIST_SIZE   9

Definition at line 41 of file rs274_read_XY_and_IJ_coordinates.cpp.

Function Documentation

◆ ReadDouble()

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

325 {
326  double ret;
327 
328  // For strtod, a string starting by 0X or 0x is a valid number in hexadecimal or octal.
329  // However, 'X' is a separator in Gerber strings with numbers.
330  // We need to detect that
331  if( strncasecmp( text, "0X", 2 ) == 0 )
332  {
333  text++;
334  ret = 0.0;
335  }
336  else
337  ret = strtod( text, &text );
338 
339  if( *text == ',' || isspace( *text ) )
340  {
341  if( aSkipSeparator )
342  ++text;
343  }
344 
345  return ret;
346 }

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

◆ ReadInt()

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

291 {
292  int ret;
293 
294  // For strtol, a string starting by 0X or 0x is a valid number in hexadecimal or octal.
295  // However, 'X' is a separator in Gerber strings with numbers.
296  // We need to detect that
297  if( strncasecmp( text, "0X", 2 ) == 0 )
298  {
299  text++;
300  ret = 0;
301  }
302  else
303  ret = (int) strtol( text, &text, 10 );
304 
305  if( *text == ',' || isspace( *text ) )
306  {
307  if( aSkipSeparator )
308  ++text;
309  }
310 
311  return ret;
312 }

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

◆ scaletoIU()

int scaletoIU ( double  aCoord,
bool  isMetric 
)

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

Definition at line 60 of file rs274_read_XY_and_IJ_coordinates.cpp.

61 {
62  int ret;
63 
64  if( isMetric ) // gerber are units in mm
65  ret = KiROUND( aCoord * IU_PER_MM );
66  else // gerber are units in inches
67  ret = KiROUND( aCoord * IU_PER_MILS * 1000.0 );
68 
69  return ret;
70 }
#define IU_PER_MILS
Definition: plotter.cpp:138
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:61

References IU_PER_MILS, 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:138

Definition at line 42 of file rs274_read_XY_and_IJ_coordinates.cpp.

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