KiCad PCB EDA Suite
rs274_read_XY_and_IJ_coordinates.cpp File Reference
#include <fctsys.h>
#include <common.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

#define SCALE_LIST_SIZE   9

Definition at line 40 of file rs274_read_XY_and_IJ_coordinates.cpp.

Function Documentation

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

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

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

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

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

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

Definition at line 59 of file rs274_read_XY_and_IJ_coordinates.cpp.

References IU_PER_MILS, and KiROUND().

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

60 {
61  int ret;
62 
63  if( isMetric ) // gerber are units in mm
64  ret = KiROUND( aCoord * IU_PER_MM );
65  else // gerber are units in inches
66  ret = KiROUND( aCoord * IU_PER_MILS * 1000.0 );
67 
68  return ret;
69 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
#define IU_PER_MILS
Definition: plotter.cpp:134

Variable Documentation

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:134

Definition at line 41 of file rs274_read_XY_and_IJ_coordinates.cpp.

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