44 #if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR ) 45 #define IU_TO_MM( x ) ( x / IU_PER_MM ) 46 #define IU_TO_IN( x ) ( x / IU_PER_MILS / 1000 ) 47 #define IU_TO_MILS( x ) ( x / IU_PER_MILS ) 48 #define MM_TO_IU( x ) ( x * IU_PER_MM ) 49 #define IN_TO_IU( x ) ( x * IU_PER_MILS * 1000 ) 50 #define MILS_TO_IU( x ) ( x * IU_PER_MILS ) 52 #error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW." 58 return KiROUND( x * 1000. / 25.4 );
64 return KiROUND( x * 25.4 / 1000. );
73 return IU_TO_MM( aValue );
76 return IU_TO_MILS( aValue );
79 return IU_TO_IN( aValue );
82 return aValue / 10.0f;
124 const wxChar* format;
125 double value = aValue;
147 #if defined( EESCHEMA ) 148 format = wxT(
"%.2f" );
150 format = wxT(
"%.4f" );
155 #if defined( EESCHEMA ) 156 format = wxT(
"%.0f" );
158 format = wxT(
"%.2f" );
163 #if defined( EESCHEMA ) 164 format = wxT(
"%.3f" );
166 format = wxT(
"%.4f" );
172 format = wxT(
"%.3f" );
176 format = wxT(
"%.0f" );
180 text.Printf( format, value );
207 double value_to_print = aValue;
212 value_to_print =
To_User_Unit( aUnits, value_to_print );
216 value_to_print =
To_User_Unit( aUnits, value_to_print );
220 value_to_print =
To_User_Unit( aUnits, value_to_print );
227 if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
229 len = sprintf( buf,
"%.10f", value_to_print );
231 while( --len > 0 && buf[len] ==
'0' )
234 if( buf[len]==
'.' || buf[len]==
',' )
242 len = sprintf( buf,
"%.7g", value_to_print );
244 len = sprintf( buf,
"%.10g", value_to_print );
247 wxString stringValue( buf, wxConvUTF8 );
254 stringValue += wxT(
" mm" );
258 stringValue += wxT(
" deg" );
262 stringValue += wxT(
" mils" );
266 stringValue += wxT(
" in" );
270 stringValue += wxT(
"%" );
287 return MM_TO_IU( aValue );
290 return MILS_TO_IU( aValue );
293 return IN_TO_IU( aValue );
312 const struct lconv* lc = localeconv();
314 wxChar decimal_point = lc->decimal_point[0];
315 wxString buf( aTextValue.Strip( wxString::both ) );
318 buf.Replace( wxT(
"." ), wxString( decimal_point, 1 ) );
319 buf.Replace( wxT(
"," ), wxString( decimal_point, 1 ) );
322 unsigned brk_point = 0;
324 while( brk_point < buf.Len() )
326 wxChar ch = buf[brk_point];
328 if( !( (ch >=
'0' && ch <=
'9') || (ch == decimal_point) || (ch ==
'-') || (ch ==
'+') ) )
335 buf.Left( brk_point ).ToDouble( &dtmp );
338 wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
343 if( unit == wxT(
"mm" ) )
347 else if( unit == wxT(
"mi" ) || unit == wxT(
"th" ) )
351 else if( unit == wxT(
"in" ) || unit == wxT(
"\"" ) )
355 else if( unit == wxT(
"oz" ) )
363 if( unit == wxT(
"ra" ) )
365 dtmp *= 180.0f / M_PI;
389 wxString buf( aTextValue.Strip( wxString::both ) );
390 unsigned brk_point = 0;
392 while( brk_point < buf.Len() )
394 wxChar c = buf[brk_point];
396 if( !( (c >=
'0' && c <=
'9') || (c ==
'.') || (c ==
',') || (c ==
'-') || (c ==
'+') ) )
403 wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
405 if( unit == wxT(
"mm" ) )
407 else if( unit == wxT(
"mi" ) || unit == wxT(
"th" ) )
409 else if( unit == wxT(
"in" ) || unit == wxT(
"\"" ) )
411 else if( unit == wxT(
"de" ) || unit == wxT(
"ra" ) )
420 return KiROUND<double, long long int>( value );
437 return _(
"sq. mm" );
439 return _(
"cu. mm" );
451 return _(
"sq. mils" );
453 return _(
"cu. mils" );
465 return _(
"sq. in" );
467 return _(
"cu. in" );
474 return wxEmptyString;
488 double engUnits = aValue;
493 if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
495 len = snprintf( buf,
sizeof(buf),
"%.10f", engUnits );
498 wxCHECK( len >= 0 && len < 50 && strchr( buf,
',' ) ==
nullptr, std::string(
"" ) );
500 while( --len > 0 && buf[len] ==
'0' )
503 if( buf[len] ==
'.' )
510 len = snprintf( buf,
sizeof(buf),
"%.10g", engUnits );
513 wxCHECK( len >= 0 && len < 50 && strchr( buf,
',' ) ==
nullptr , std::string(
"" ) );
516 return std::string( buf, len );
525 len = snprintf( temp,
sizeof(temp),
"%.10g", aAngle / 10.0 );
527 return std::string( temp, len );
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Implementation of conversion functions that require both schematic and board internal units.
static constexpr double IU_PER_MM
Mock up a conversion function.
EDA_DATA_TYPE
The type of unit.
Define a general 2D-vector/point.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
This file contains miscellaneous commonly used macros and functions.
int Mm2mils(double x)
Convert mm to mils.
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
void FetchUnitsFromString(const wxString &aTextValue, EDA_UNITS &aUnits)
Function FetchUnitsFromString writes any unit info found in the string to aUnits.
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
double To_User_Unit(EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
int Mils2mm(double x)
Convert mils to mm.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function DoubleValueFromString converts aTextValue to a double.
double From_User_Unit(EDA_UNITS aUnits, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...