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

Static Public Member Functions

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

Converts a size expressed in a certain unit to nanometers.

More...
 

Public Attributes

long long int value
 

Value expressed in nanometers

More...
 

Static Public Attributes

static constexpr EAGLE_UNIT ECOORD_UNIT = EU_NM
 

Unit used for the value field

More...
 

Detailed Description

Definition at line 395 of file eagle_parser.h.

Member Enumeration Documentation

Enumerator
EU_NM 

nanometers

EU_MM 

millimeters

EU_INCH 

inches

EU_MIL 

mils/thous

Definition at line 397 of file eagle_parser.h.

398  {
399  EU_NM,
400  EU_MM,
401  EU_INCH,
402  EU_MIL,
403  };
nanometers
Definition: eagle_parser.h:399
mils/thous
Definition: eagle_parser.h:402
millimeters
Definition: eagle_parser.h:400

Constructor & Destructor Documentation

ECOORD::ECOORD ( )
inline

Definition at line 411 of file eagle_parser.h.

412  : value( 0 )
413  {
414  }
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
ECOORD::ECOORD ( int  aValue,
enum EAGLE_UNIT  aUnit 
)
inline

Definition at line 416 of file eagle_parser.h.

417  : value( ConvertToNm( aValue, aUnit ) )
418  {
419  }
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)
Converts a size expressed in a certain unit to nanometers.
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
ECOORD::ECOORD ( const wxString &  aValue,
enum EAGLE_UNIT  aUnit 
)

Definition at line 58 of file eagle_parser.cpp.

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

Member Function Documentation

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

Converts a size expressed in a certain unit to nanometers.

Definition at line 99 of file eagle_parser.cpp.

100 {
101  long long int ret;
102 
103  switch( aUnit )
104  {
105  default:
106  case EU_NM: ret = aValue; break;
107  case EU_MM: ret = (long long) aValue * 1000000; break;
108  case EU_INCH: ret = (long long) aValue * 25400000; break;
109  case EU_MIL: ret = (long long) aValue * 25400; break;
110  }
111 
112  wxASSERT( ( ret > 0 ) == ( aValue > 0 ) ); // check for overflow
113  return ret;
114 }
nanometers
Definition: eagle_parser.h:399
mils/thous
Definition: eagle_parser.h:402
millimeters
Definition: eagle_parser.h:400
ECOORD ECOORD::operator+ ( const ECOORD aOther) const
inline

Definition at line 441 of file eagle_parser.h.

References value.

442  {
443  return ECOORD( value + aOther.value, ECOORD_UNIT );
444  }
static constexpr EAGLE_UNIT ECOORD_UNIT
Unit used for the value field
Definition: eagle_parser.h:409
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
ECOORD ECOORD::operator- ( const ECOORD aOther) const
inline

Definition at line 446 of file eagle_parser.h.

References value.

447  {
448  return ECOORD( value - aOther.value, ECOORD_UNIT );
449  }
static constexpr EAGLE_UNIT ECOORD_UNIT
Unit used for the value field
Definition: eagle_parser.h:409
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
bool ECOORD::operator== ( const ECOORD aOther) const
inline

Definition at line 451 of file eagle_parser.h.

References value.

452  {
453  return value == aOther.value;
454  }
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
int ECOORD::ToMils ( ) const
inline

Definition at line 423 of file eagle_parser.h.

424  {
425  return value / 25400;
426  }
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
float ECOORD::ToMm ( ) const
inline

Definition at line 433 of file eagle_parser.h.

434  {
435  return value / 1000000.0;
436  }
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406
int ECOORD::ToNanoMeters ( ) const
inline

Definition at line 428 of file eagle_parser.h.

429  {
430  return value;
431  }
long long int value
Value expressed in nanometers
Definition: eagle_parser.h:406

Member Data Documentation

constexpr EAGLE_UNIT ECOORD::ECOORD_UNIT = EU_NM
static

Unit used for the value field

Definition at line 409 of file eagle_parser.h.

long long int ECOORD::value

Value expressed in nanometers

Definition at line 406 of file eagle_parser.h.

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


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