58 return KiROUND( aVal * 1000. / 25.4 );
64 return KiROUND( aVal * 25.4 / 1000. );
70 wxString buf( aTextValue.Strip( wxString::both ) );
71 unsigned brk_point = 0;
73 while( brk_point < buf.Len() )
75 wxChar c = buf[brk_point];
77 if( !( ( c >=
'0' && c <=
'9' ) || ( c ==
'.' ) || ( c ==
',' ) || ( c ==
'-' )
85 wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
87 if( unit == wxT(
"mm" ) )
89 else if( unit == wxT(
"mi" ) || unit == wxT(
"th" ) )
91 else if( unit == wxT(
"in" ) || unit == wxT(
"\"" ) )
93 else if( unit == wxT(
"de" ) || unit == wxT(
"ra" ) )
130 return GetText( aUnits, aType ).Trim(
false );
136 std::string temp = fmt::format(
"{:.10g}", aAngle.
AsDegrees() );
145 double engUnits = aValue;
149 if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
151 buf = fmt::format(
"{:.10f}", engUnits );
154 while( !buf.empty() && buf[buf.size() - 1] ==
'0' )
161 if( buf[buf.size() - 1] ==
'.' )
168 buf = fmt::format(
"{:.10g}", engUnits );
183#define IU_TO_MM( x, scale ) ( x / scale.IU_PER_MM )
184#define IU_TO_IN( x, scale ) ( x / scale.IU_PER_MILS / 1000 )
185#define IU_TO_MILS( x, scale ) ( x / scale.IU_PER_MILS )
186#define MM_TO_IU( x, scale ) ( x * scale.IU_PER_MM )
187#define IN_TO_IU( x, scale ) ( x * scale.IU_PER_MILS * 1000 )
188#define MILS_TO_IU( x, scale ) ( x * scale.IU_PER_MILS )
196 return IU_TO_MM( aValue, aIuScale );
202 return IU_TO_IN( aValue, aIuScale );
226 double aValue,
bool aAddUnitsText,
229 double value_to_print = aValue;
234 value_to_print =
ToUserUnit( aIuScale, aUnits, value_to_print );
238 value_to_print =
ToUserUnit( aIuScale, aUnits, value_to_print );
242 value_to_print =
ToUserUnit( aIuScale, aUnits, value_to_print );
247 if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
249 int len = snprintf( buf,
sizeof( buf ) - 1,
"%.10f", value_to_print );
251 while( --len > 0 && buf[len] ==
'0' )
254 if( len >= 0 && ( buf[len] ==
'.' || buf[len] ==
',' ) )
259 snprintf( buf,
sizeof( buf ) - 1,
"%.10g", value_to_print );
262 wxString stringValue( buf, wxConvUTF8 );
297 long long int aValue,
316 double aValue,
bool aAddUnitsText,
320 const wxChar* format;
321 double value = aValue;
326 value =
ToUserUnit( aIuScale, aUnits, value );
331 value =
ToUserUnit( aIuScale, aUnits, value );
336 value =
ToUserUnit( aIuScale, aUnits, value );
343#if defined( EESCHEMA )
344 format = wxT(
"%.2f" );
346 format = wxT(
"%.4f" );
351#if defined( EESCHEMA )
352 format = wxT(
"%.0f" );
354 format = wxT(
"%.2f" );
359#if defined( EESCHEMA )
360 format = wxT(
"%.3f" );
362 format = wxT(
"%.4f" );
368 format = wxT(
"%.3f" );
372 format = wxT(
"%.0f" );
376 text.Printf( format, value );
391 return MM_TO_IU( aValue, aIuScale );
397 return IN_TO_IU( aValue, aIuScale );
413 const struct lconv* lc = localeconv();
415 wxChar decimal_point = lc->decimal_point[0];
416 wxString buf( aTextValue.Strip( wxString::both ) );
419 buf.Replace( wxT(
"." ), wxString( decimal_point, 1 ) );
420 buf.Replace( wxT(
"," ), wxString( decimal_point, 1 ) );
423 unsigned brk_point = 0;
425 while( brk_point < buf.Len() )
427 wxChar ch = buf[brk_point];
429 if( !( ( ch >=
'0' && ch <=
'9' ) || ( ch == decimal_point ) || ( ch ==
'-' )
439 buf.Left( brk_point ).ToDouble( &dtmp );
451 const struct lconv* lc = localeconv();
453 wxChar decimal_point = lc->decimal_point[0];
454 wxString buf( aTextValue.Strip( wxString::both ) );
457 buf.Replace( wxT(
"." ), wxString( decimal_point, 1 ) );
458 buf.Replace( wxT(
"," ), wxString( decimal_point, 1 ) );
461 unsigned brk_point = 0;
463 while( brk_point < buf.Len() )
465 wxChar ch = buf[brk_point];
467 if( !( (ch >=
'0' && ch <=
'9') || (ch == decimal_point) || (ch ==
'-') || (ch ==
'+') ) )
474 buf.Left( brk_point ).ToDouble( &dtmp );
477 wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
483 if( unit == wxT(
"mm" ) )
487 else if( unit == wxT(
"mi" ) || unit == wxT(
"th" ) )
491 else if( unit == wxT(
"in" ) || unit == wxT(
"\"" ) )
495 else if( unit == wxT(
"oz" ) )
503 if( unit == wxT(
"ra" ) )
504 dtmp *= 180.0f / M_PI;
530 return KiROUND<double, long long int>( value );
538 return KiROUND<double, long long int>( value );
#define IU_TO_IN(x, scale)
#define IN_TO_IU(x, scale)
#define IU_TO_MILS(x, scale)
#define MM_TO_IU(x, scale)
#define IU_TO_MM(x, scale)
#define MILS_TO_IU(x, scale)
EDA_DATA_TYPE
The type of unit.
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
#define UNIMPLEMENTED_FOR(type)
wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
double FromUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Returns the string from aValue according to aUnits (inch, mm ...) for display.
double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
wxString GetText(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
bool FetchUnitsFromString(const wxString &aTextValue, EDA_UNITS &aUnits)
Writes any unit info found in the string to aUnits.
bool IsImperialUnit(EDA_UNITS aUnit)
bool IsMetricUnit(EDA_UNITS aUnit)
wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
int Mm2mils(double aVal)
Convert mm to mils.
std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
int Mils2mm(double aVal)
Convert mils to mm.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".