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 381 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 383 of file eagle_parser.h.

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

Constructor & Destructor Documentation

◆ ECOORD() [1/3]

ECOORD::ECOORD ( )
inline

Definition at line 397 of file eagle_parser.h.

398  : value( 0 )
399  {
400  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

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

◆ ECOORD() [2/3]

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

Definition at line 402 of file eagle_parser.h.

403  : value( ConvertToNm( aValue, aUnit ) )
404  {
405  }
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:392

◆ ECOORD() [3/3]

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

Definition at line 60 of file eagle_parser.cpp.

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

References ConvertToNm(), and value.

Member Function Documentation

◆ ConvertToNm()

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

Definition at line 106 of file eagle_parser.cpp.

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

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 432 of file eagle_parser.h.

433  {
434  return ECOORD( value + aOther.value, ECOORD_UNIT );
435  }
static constexpr EAGLE_UNIT ECOORD_UNIT
Definition: eagle_parser.h:395
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

References ECOORD(), ECOORD_UNIT, and value.

◆ operator-()

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

Definition at line 437 of file eagle_parser.h.

438  {
439  return ECOORD( value - aOther.value, ECOORD_UNIT );
440  }
static constexpr EAGLE_UNIT ECOORD_UNIT
Definition: eagle_parser.h:395
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

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 442 of file eagle_parser.h.

References value.

◆ To100NanoMeters()

int ECOORD::To100NanoMeters ( ) const
inline

Definition at line 414 of file eagle_parser.h.

415  {
416  return value / 100;
417  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

References value.

Referenced by ToSchUnits().

◆ ToMils()

int ECOORD::ToMils ( ) const
inline

Definition at line 409 of file eagle_parser.h.

410  {
411  return value / 25400;
412  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

References value.

◆ ToMm()

float ECOORD::ToMm ( ) const
inline

Definition at line 424 of file eagle_parser.h.

425  {
426  return value / 1000000.0;
427  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

References value.

◆ ToNanoMeters()

int ECOORD::ToNanoMeters ( ) const
inline

Definition at line 419 of file eagle_parser.h.

420  {
421  return value;
422  }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:392

References value.

Referenced by ToPcbUnits().

◆ ToPcbUnits()

◆ ToSchUnits()

Member Data Documentation

◆ ECOORD_UNIT

constexpr EAGLE_UNIT ECOORD::ECOORD_UNIT = EU_NM
static

Definition at line 395 of file eagle_parser.h.

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

◆ value

long long int ECOORD::value

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