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

390 {
391 EU_NM,
392 EU_MM,
393 EU_INCH,
394 EU_MIL,
395 };
@ EU_NM
nanometers
Definition: eagle_parser.h:391
@ EU_MM
millimeters
Definition: eagle_parser.h:392
@ EU_MIL
mils/thous
Definition: eagle_parser.h:394
@ EU_INCH
inches
Definition: eagle_parser.h:393

Constructor & Destructor Documentation

◆ ECOORD() [1/3]

ECOORD::ECOORD ( )
inline

Definition at line 403 of file eagle_parser.h.

404 : value( 0 )
405 {
406 }
long long int value
Unit used for the value field.
Definition: eagle_parser.h:398

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

◆ ECOORD() [2/3]

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

Definition at line 408 of file eagle_parser.h.

409 : value( ConvertToNm( aValue, aUnit ) )
410 {
411 }
static long long int ConvertToNm(int aValue, enum EAGLE_UNIT aUnit)

◆ ECOORD() [3/3]

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

Definition at line 151 of file eagle_parser.cpp.

152{
153 // This array is used to adjust the fraction part value basing on the number of digits
154 // in the fraction.
155 constexpr int DIVIDERS[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
156 constexpr unsigned int DIVIDERS_MAX_IDX = sizeof( DIVIDERS ) / sizeof( DIVIDERS[0] ) - 1;
157
158 int integer, fraction, pre_fraction, post_fraction;
159
160 // The following check is needed to handle correctly negative fractions where the integer
161 // part == 0.
162 bool negative = ( aValue[0] == '-' );
163
164 // %n is used to find out how many digits contains the fraction part, e.g. 0.001 contains 3
165 // digits.
166 int ret = sscanf( aValue.c_str(), "%d.%n%d%n", &integer, &pre_fraction, &fraction,
167 &post_fraction );
168
169 if( ret == 0 )
170 throw XML_PARSER_ERROR( "Invalid coordinate" );
171
172 // process the integer part
173 value = ConvertToNm( integer, aUnit );
174
175 // process the fraction part
176 if( ret == 2 )
177 {
178 int digits = post_fraction - pre_fraction;
179
180 // adjust the number of digits if necessary as we cannot handle anything smaller than
181 // nanometers (rounding).
182 if( (unsigned) digits > DIVIDERS_MAX_IDX )
183 {
184 int diff = digits - DIVIDERS_MAX_IDX;
185 digits = DIVIDERS_MAX_IDX;
186 fraction /= DIVIDERS[diff];
187 }
188
189 int frac_value = ConvertToNm( fraction, aUnit ) / DIVIDERS[digits];
190
191 // keep the sign in mind
192 value = negative ? value - frac_value : value + frac_value;
193 }
194}
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
Definition: eagle_parser.h:75

References ConvertToNm(), and value.

Member Function Documentation

◆ ConvertToNm()

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

Definition at line 197 of file eagle_parser.cpp.

198{
199 long long int ret;
200
201 switch( aUnit )
202 {
203 default:
204 case EU_NM: ret = aValue; break;
205 case EU_MM: ret = (long long) aValue * 1000000; break;
206 case EU_INCH: ret = (long long) aValue * 25400000; break;
207 case EU_MIL: ret = (long long) aValue * 25400; break;
208 }
209
210 if( ( ret > 0 ) != ( aValue > 0 ) )
211 wxLogError( _( "Invalid size %lld: too large" ), aValue );
212
213 return ret;
214}
#define _(s)

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

439 {
440 return ECOORD( value + aOther.value, ECOORD_UNIT );
441 }
static constexpr EAGLE_UNIT ECOORD_UNIT
Definition: eagle_parser.h:401

References ECOORD(), ECOORD_UNIT, and value.

◆ operator-()

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

Definition at line 443 of file eagle_parser.h.

444 {
445 return ECOORD( value - aOther.value, ECOORD_UNIT );
446 }

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

References value.

◆ To100NanoMeters()

int ECOORD::To100NanoMeters ( ) const
inline

Definition at line 420 of file eagle_parser.h.

421 {
422 return value / 100;
423 }

References value.

Referenced by ToSchUnits().

◆ ToMils()

int ECOORD::ToMils ( ) const
inline

Definition at line 415 of file eagle_parser.h.

416 {
417 return value / 25400;
418 }

References value.

◆ ToMm()

float ECOORD::ToMm ( ) const
inline

Definition at line 430 of file eagle_parser.h.

431 {
432 return value / 1000000.0;
433 }

References value.

◆ ToNanoMeters()

int ECOORD::ToNanoMeters ( ) const
inline

Definition at line 425 of file eagle_parser.h.

426 {
427 return value;
428 }

References value.

Referenced by ToPcbUnits().

◆ ToPcbUnits()

◆ ToSchUnits()

Member Data Documentation

◆ ECOORD_UNIT

constexpr EAGLE_UNIT ECOORD::ECOORD_UNIT = EU_NM
staticconstexpr

Definition at line 401 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: