Eagle import: minor ECOORD refactor
- changed EAGLE_UNIT enum names from EAGLE_* to EU_* - renamed ToNanoMeters() to ConvertToNm() and added a comment - added ToMils() and ToNanoMeters() method
This commit is contained in:
parent
133b681006
commit
4c9be316dd
|
@ -73,7 +73,7 @@ ECOORD::ECOORD( const wxString& aValue, enum ECOORD::EAGLE_UNIT aUnit )
|
|||
throw XML_PARSER_ERROR( "Invalid coordinate" );
|
||||
|
||||
// process the integer part
|
||||
value = ToNanoMeters( integer, aUnit );
|
||||
value = ConvertToNm( integer, aUnit );
|
||||
|
||||
// process the fraction part
|
||||
if( ret == 2 )
|
||||
|
@ -88,7 +88,7 @@ ECOORD::ECOORD( const wxString& aValue, enum ECOORD::EAGLE_UNIT aUnit )
|
|||
fraction /= DIVIDERS[diff];
|
||||
}
|
||||
|
||||
int frac_value = ToNanoMeters( fraction, aUnit ) / DIVIDERS[digits];
|
||||
int frac_value = ConvertToNm( fraction, aUnit ) / DIVIDERS[digits];
|
||||
|
||||
// keep the sign in mind
|
||||
value = negative ? value - frac_value : value + frac_value;
|
||||
|
@ -96,17 +96,17 @@ ECOORD::ECOORD( const wxString& aValue, enum ECOORD::EAGLE_UNIT aUnit )
|
|||
}
|
||||
|
||||
|
||||
long long int ECOORD::ToNanoMeters( int aValue, enum EAGLE_UNIT aUnit )
|
||||
long long int ECOORD::ConvertToNm( int aValue, enum EAGLE_UNIT aUnit )
|
||||
{
|
||||
long long int ret;
|
||||
|
||||
switch( aUnit )
|
||||
{
|
||||
default:
|
||||
case EAGLE_NM: ret = aValue; break;
|
||||
case EAGLE_MM: ret = (long long) aValue * 1000000; break;
|
||||
case EAGLE_INCH: ret = (long long) aValue * 25400000; break;
|
||||
case EAGLE_MIL: ret = (long long) aValue * 25400; break;
|
||||
case EU_NM: ret = aValue; break;
|
||||
case EU_MM: ret = (long long) aValue * 1000000; break;
|
||||
case EU_INCH: ret = (long long) aValue * 25400000; break;
|
||||
case EU_MIL: ret = (long long) aValue * 25400; break;
|
||||
}
|
||||
|
||||
wxASSERT( ( ret > 0 ) == ( aValue > 0 ) ); // check for overflow
|
||||
|
@ -195,7 +195,7 @@ template<>
|
|||
ECOORD Convert<ECOORD>( const wxString& aCoord )
|
||||
{
|
||||
// Eagle uses millimeters as the default unit
|
||||
return ECOORD( aCoord, ECOORD::EAGLE_UNIT::EAGLE_MM );
|
||||
return ECOORD( aCoord, ECOORD::EAGLE_UNIT::EU_MM );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -395,17 +395,17 @@ struct ECOORD
|
|||
{
|
||||
enum EAGLE_UNIT
|
||||
{
|
||||
EAGLE_NM, ///< nanometers
|
||||
EAGLE_MM, ///< millimeters
|
||||
EAGLE_INCH, ///< inches
|
||||
EAGLE_MIL, ///< mils/thous
|
||||
EU_NM, ///< nanometers
|
||||
EU_MM, ///< millimeters
|
||||
EU_INCH, ///< inches
|
||||
EU_MIL, ///< mils/thous
|
||||
};
|
||||
|
||||
///> Value expressed in nanometers
|
||||
long long int value;
|
||||
|
||||
///> Unit used for the value field
|
||||
static constexpr EAGLE_UNIT ECOORD_UNIT = EAGLE_NM;
|
||||
static constexpr EAGLE_UNIT ECOORD_UNIT = EU_NM;
|
||||
|
||||
ECOORD()
|
||||
: value( 0 )
|
||||
|
@ -413,21 +413,19 @@ struct ECOORD
|
|||
}
|
||||
|
||||
ECOORD( int aValue, enum EAGLE_UNIT aUnit )
|
||||
: value( ToNanoMeters( aValue, aUnit ) )
|
||||
: value( ConvertToNm( aValue, aUnit ) )
|
||||
{
|
||||
}
|
||||
|
||||
ECOORD( const wxString& aValue, enum EAGLE_UNIT aUnit );
|
||||
|
||||
int ToSchUnits() const
|
||||
int ToMils() const
|
||||
{
|
||||
// mils
|
||||
return value / 25400;
|
||||
}
|
||||
|
||||
int ToPcbUnits() const
|
||||
int ToNanoMeters() const
|
||||
{
|
||||
// nanometers
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -436,6 +434,9 @@ struct ECOORD
|
|||
return value / 1000000.0;
|
||||
}
|
||||
|
||||
int ToSchUnits() const { return ToMils(); }
|
||||
int ToPcbUnits() const { return ToNanoMeters(); }
|
||||
|
||||
ECOORD operator+( const ECOORD& aOther ) const
|
||||
{
|
||||
return ECOORD( value + aOther.value, ECOORD_UNIT );
|
||||
|
@ -451,7 +452,8 @@ struct ECOORD
|
|||
return value == aOther.value;
|
||||
}
|
||||
|
||||
static long long int ToNanoMeters( int aValue, enum EAGLE_UNIT aUnit );
|
||||
///> Converts a size expressed in a certain unit to nanometers.
|
||||
static long long int ConvertToNm( int aValue, enum EAGLE_UNIT aUnit );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ typedef MODULE_MAP::const_iterator MODULE_CITER;
|
|||
static int parseEagle( const wxString& aDistance )
|
||||
{
|
||||
ECOORD::EAGLE_UNIT unit = ( aDistance.npos != aDistance.find( "mil" ) )
|
||||
? ECOORD::EAGLE_UNIT::EAGLE_MIL : ECOORD::EAGLE_UNIT::EAGLE_MM;
|
||||
? ECOORD::EAGLE_UNIT::EU_MIL : ECOORD::EAGLE_UNIT::EU_MM;
|
||||
|
||||
ECOORD coord( aDistance, unit );
|
||||
|
||||
|
@ -703,14 +703,14 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
|
|||
if( *d.dimensionType == "horizontal" )
|
||||
{
|
||||
int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
|
||||
d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EAGLE_NM );
|
||||
d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EAGLE_NM );
|
||||
d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
|
||||
d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
|
||||
}
|
||||
else if( *d.dimensionType == "vertical" )
|
||||
{
|
||||
int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2;
|
||||
d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EAGLE_NM );
|
||||
d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EAGLE_NM );
|
||||
d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
|
||||
d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue