KiCad PCB EDA Suite
ECOORD Struct Reference

#include <eagle_parser.h>

Public Types

enum  EAGLE_UNIT { EU_NM, EU_MM, EU_INCH, EU_MIL }
 

Public Member Functions

 ECOORD ()
 
 ECOORD (int aValue, enum EAGLE_UNIT aUnit)
 
 ECOORD (const wxString &aValue, enum EAGLE_UNIT aUnit)
 
int ToMils () const
 
int To100NanoMeters () const
 
int ToNanoMeters () const
 
float ToMm () const
 
int ToSchUnits () const
 
int ToPcbUnits () const
 
ECOORD operator+ (const ECOORD &aOther) const
 
ECOORD operator- (const ECOORD &aOther) const
 
bool operator== (const ECOORD &aOther) const
 Converts a size expressed in a certain unit to nanometers. More...
 

Static Public Member Functions

static long long int ConvertToNm (int aValue, enum EAGLE_UNIT aUnit)
 

Public Attributes

long long int value
 Unit used for the value field. More...
 

Static Public Attributes

static constexpr EAGLE_UNIT ECOORD_UNIT = EU_NM
 

Detailed Description

Definition at line 383 of file eagle_parser.h.

Member Enumeration Documentation

◆ EAGLE_UNIT

Enumerator
EU_NM 

nanometers

EU_MM 

millimeters

EU_INCH 

inches

EU_MIL 

mils/thous

Definition at line 385 of file eagle_parser.h.

386  {
387  EU_NM,
388  EU_MM,
389  EU_INCH,
390  EU_MIL,
391  };
nanometers
Definition: eagle_parser.h:387
mils/thous
Definition: eagle_parser.h:390
millimeters
Definition: eagle_parser.h:388

Constructor & Destructor Documentation

◆ ECOORD() [1/3]

ECOORD::ECOORD ( )
inline

Definition at line 399 of file eagle_parser.h.

400  : value( 0 )
401  {
402  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

Referenced by operator+(), and operator-().

◆ ECOORD() [2/3]

ECOORD::ECOORD ( int  aValue,
enum EAGLE_UNIT  aUnit 
)
inline

Definition at line 404 of file eagle_parser.h.

405  : value( ConvertToNm( aValue, aUnit ) )
406  {
407  }
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

◆ ECOORD() [3/3]

ECOORD::ECOORD ( const wxString &  aValue,
enum EAGLE_UNIT  aUnit 
)

Definition at line 61 of file eagle_parser.cpp.

62 {
63  // This array is used to adjust the fraction part value basing on the number of digits
64  // in the fraction.
65  constexpr int DIVIDERS[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
66  constexpr unsigned int DIVIDERS_MAX_IDX = sizeof( DIVIDERS ) / sizeof( DIVIDERS[0] ) - 1;
67 
68  int integer, fraction, pre_fraction, post_fraction;
69 
70  // The following check is needed to handle correctly negative fractions where the integer
71  // part == 0.
72  bool negative = ( aValue[0] == '-' );
73 
74  // %n is used to find out how many digits contains the fraction part, e.g. 0.001 contains 3
75  // digits.
76  int ret = sscanf( aValue.c_str(), "%d.%n%d%n", &integer, &pre_fraction, &fraction,
77  &post_fraction );
78 
79  if( ret == 0 )
80  throw XML_PARSER_ERROR( "Invalid coordinate" );
81 
82  // process the integer part
83  value = ConvertToNm( integer, aUnit );
84 
85  // process the fraction part
86  if( ret == 2 )
87  {
88  int digits = post_fraction - pre_fraction;
89 
90  // adjust the number of digits if necessary as we cannot handle anything smaller than
91  // nanometers (rounding).
92  if( (unsigned) digits > DIVIDERS_MAX_IDX )
93  {
94  int diff = digits - DIVIDERS_MAX_IDX;
95  digits = DIVIDERS_MAX_IDX;
96  fraction /= DIVIDERS[diff];
97  }
98 
99  int frac_value = ConvertToNm( fraction, aUnit ) / DIVIDERS[digits];
100 
101  // keep the sign in mind
102  value = negative ? value - frac_value : value + frac_value;
103  }
104 }
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
Definition: eagle_parser.h:70
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References ConvertToNm(), and value.

Member Function Documentation

◆ ConvertToNm()

long long int ECOORD::ConvertToNm ( int  aValue,
enum EAGLE_UNIT  aUnit 
)
static

Definition at line 107 of file eagle_parser.cpp.

108 {
109  long long int ret;
110 
111  switch( aUnit )
112  {
113  default:
114  case EU_NM: ret = aValue; break;
115  case EU_MM: ret = (long long) aValue * 1000000; break;
116  case EU_INCH: ret = (long long) aValue * 25400000; break;
117  case EU_MIL: ret = (long long) aValue * 25400; break;
118  }
119 
120  if( ( ret > 0 ) != ( aValue > 0 ) )
121  wxLogError( _( "Invalid size %lld: too large" ), aValue );
122 
123  return ret;
124 }
nanometers
Definition: eagle_parser.h:387
mils/thous
Definition: eagle_parser.h:390
millimeters
Definition: eagle_parser.h:388
#define _(s)
Definition: 3d_actions.cpp:33

References _, EU_INCH, EU_MIL, EU_MM, and EU_NM.

Referenced by ECOORD().

◆ operator+()

ECOORD ECOORD::operator+ ( const ECOORD aOther) const
inline

Definition at line 434 of file eagle_parser.h.

435  {
436  return ECOORD( value + aOther.value, ECOORD_UNIT );
437  }
static constexpr EAGLE_UNIT ECOORD_UNIT
Definition: eagle_parser.h:397
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References ECOORD(), ECOORD_UNIT, and value.

◆ operator-()

ECOORD ECOORD::operator- ( const ECOORD aOther) const
inline

Definition at line 439 of file eagle_parser.h.

440  {
441  return ECOORD( value - aOther.value, ECOORD_UNIT );
442  }
static constexpr EAGLE_UNIT ECOORD_UNIT
Definition: eagle_parser.h:397
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References ECOORD(), ECOORD_UNIT, and value.

◆ operator==()

bool ECOORD::operator== ( const ECOORD aOther) const
inline

Converts a size expressed in a certain unit to nanometers.

Definition at line 444 of file eagle_parser.h.

References value.

◆ To100NanoMeters()

int ECOORD::To100NanoMeters ( ) const
inline

Definition at line 416 of file eagle_parser.h.

417  {
418  return value / 100;
419  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References value.

Referenced by ToSchUnits().

◆ ToMils()

int ECOORD::ToMils ( ) const
inline

Definition at line 411 of file eagle_parser.h.

412  {
413  return value / 25400;
414  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References value.

◆ ToMm()

float ECOORD::ToMm ( ) const
inline

Definition at line 426 of file eagle_parser.h.

427  {
428  return value / 1000000.0;
429  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References value.

◆ ToNanoMeters()

int ECOORD::ToNanoMeters ( ) const
inline

Definition at line 421 of file eagle_parser.h.

422  {
423  return value;
424  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:394

References value.

Referenced by ToPcbUnits().

◆ ToPcbUnits()

◆ ToSchUnits()

Member Data Documentation

◆ ECOORD_UNIT

constexpr EAGLE_UNIT ECOORD::ECOORD_UNIT = EU_NM
static

Definition at line 397 of file eagle_parser.h.

Referenced by operator+(), and operator-().

◆ value

long long int ECOORD::value

Unit used for the value field.

Definition at line 394 of file eagle_parser.h.

Referenced by ECOORD(), operator+(), operator-(), operator==(), To100NanoMeters(), ToMils(), ToMm(), and ToNanoMeters().


The documentation for this struct was generated from the following files: