2013-05-26 04:36:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN
|
2018-06-17 13:50:49 +00:00
|
|
|
* Copyright (C) 1992-2018 KiCad Developers, see change_log.txt for contributors.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* @file base_units.cpp
|
|
|
|
* @brief Code to handle objects that require both schematic and board internal units.
|
|
|
|
* @note This file is an ugly hack to solve the problem of formatting the base units
|
|
|
|
* for either schematics or boards in objects that are include in both domains.
|
|
|
|
* At some point in the future. This code should be rolled back into the
|
|
|
|
* appropriate object and build with the correct internal unit formatting
|
|
|
|
* depending on the application.
|
|
|
|
*/
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
#include <macros.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
#include <base_struct.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <title_block.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <base_units.h>
|
2017-11-23 10:36:24 +00:00
|
|
|
#include "libeval/numeric_evaluator.h"
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR )
|
2013-05-26 04:36:44 +00:00
|
|
|
#define IU_TO_MM( x ) ( x / IU_PER_MM )
|
|
|
|
#define IU_TO_IN( x ) ( x / IU_PER_MILS / 1000 )
|
2018-02-02 15:44:53 +00:00
|
|
|
#define IU_TO_MILS( x ) ( x / IU_PER_MILS )
|
2013-05-26 04:36:44 +00:00
|
|
|
#define MM_TO_IU( x ) ( x * IU_PER_MM )
|
|
|
|
#define IN_TO_IU( x ) ( x * IU_PER_MILS * 1000 )
|
2018-02-02 15:44:53 +00:00
|
|
|
#define MILS_TO_IU( x ) ( x * IU_PER_MILS )
|
2013-05-26 04:36:44 +00:00
|
|
|
#else
|
|
|
|
#error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
// Helper function to print a float number without using scientific notation
|
|
|
|
// and no trailing 0
|
|
|
|
// So we cannot always just use the %g or the %f format to print a fp number
|
|
|
|
// this helper function uses the %f format when needed, or %g when %f is
|
|
|
|
// not well working and then removes trailing 0
|
|
|
|
|
|
|
|
std::string Double2Str( double aValue )
|
|
|
|
{
|
|
|
|
char buf[50];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if( aValue != 0.0 && fabs( aValue ) <= 0.0001 )
|
|
|
|
{
|
|
|
|
// For these small values, %f works fine,
|
|
|
|
// and %g gives an exponent
|
|
|
|
len = sprintf( buf, "%.16f", aValue );
|
|
|
|
|
|
|
|
while( --len > 0 && buf[len] == '0' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
if( buf[len] == '.' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
else
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For these values, %g works fine, and sometimes %f
|
|
|
|
// gives a bad value (try aValue = 1.222222222222, with %.16f format!)
|
|
|
|
len = sprintf( buf, "%.16g", aValue );
|
|
|
|
}
|
|
|
|
|
2015-01-17 08:01:16 +00:00
|
|
|
return std::string( buf, len );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
double To_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
switch( aUnit )
|
|
|
|
{
|
|
|
|
case MILLIMETRES:
|
|
|
|
return IU_TO_MM( aValue );
|
|
|
|
|
|
|
|
case INCHES:
|
2018-02-02 15:44:53 +00:00
|
|
|
if( aUseMils )
|
|
|
|
return IU_TO_MILS( aValue );
|
|
|
|
else
|
|
|
|
return IU_TO_IN( aValue );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
case DEGREES:
|
|
|
|
return aValue / 10.0f;
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
default:
|
|
|
|
return aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert a value to a string using double notation.
|
|
|
|
* For readability, the mantissa has 0, 1, 3 or 4 digits, depending on units
|
|
|
|
* for unit = inch the mantissa has 3 digits (Eeschema) or 4 digits
|
|
|
|
* for unit = mil the mantissa has 0 digits (Eeschema) or 1 digits
|
|
|
|
* for unit = mm the mantissa has 3 digits (Eeschema) or 4 digits
|
|
|
|
* Should be used only to display info in status,
|
|
|
|
* but not in dialogs, because 4 digits only
|
|
|
|
* could truncate the actual value
|
|
|
|
*/
|
2018-03-06 12:06:46 +00:00
|
|
|
|
|
|
|
// A lower-precision (for readability) version of StringFromValue()
|
|
|
|
wxString MessageTextFromValue( EDA_UNITS_T aUnits, int aValue, bool aUseMils )
|
|
|
|
{
|
|
|
|
return MessageTextFromValue( aUnits, (double) aValue, aUseMils );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A lower-precision (for readability) version of StringFromValue()
|
|
|
|
wxString MessageTextFromValue( EDA_UNITS_T aUnits, double aValue, bool aUseMils )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
const wxChar* format;
|
2018-03-06 12:06:46 +00:00
|
|
|
double value = To_User_Unit( aUnits, aValue, aUseMils );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2018-03-06 12:06:46 +00:00
|
|
|
if( aUnits == INCHES )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2018-02-02 15:44:53 +00:00
|
|
|
if( aUseMils )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
#if defined( EESCHEMA )
|
|
|
|
format = wxT( "%.0f" );
|
|
|
|
#else
|
|
|
|
format = wxT( "%.1f" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#if defined( EESCHEMA )
|
|
|
|
format = wxT( "%.3f" );
|
|
|
|
#else
|
|
|
|
format = wxT( "%.4f" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#if defined( EESCHEMA )
|
|
|
|
format = wxT( "%.2f" );
|
|
|
|
#else
|
|
|
|
format = wxT( "%.3f" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
text.Printf( format, value );
|
2018-03-09 03:32:01 +00:00
|
|
|
text += " ";
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
text += GetAbbreviatedUnitsLabel( aUnits, aUseMils );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove trailing 0 from a string containing a converted float number.
|
|
|
|
* the trailing 0 are removed if the mantissa has more
|
|
|
|
* than aTrailingZeroAllowed digits and some trailing 0
|
|
|
|
*/
|
|
|
|
void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
|
|
|
|
{
|
|
|
|
struct lconv * lc = localeconv();
|
|
|
|
char sep = lc->decimal_point[0];
|
|
|
|
unsigned sep_pos = aStringValue.Find( sep );
|
|
|
|
|
|
|
|
if( sep_pos > 0 )
|
|
|
|
{
|
|
|
|
// We want to keep at least aTrailingZeroAllowed digits after the separator
|
|
|
|
unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
|
|
|
|
|
|
|
|
while( aStringValue.Len() > min_len )
|
|
|
|
{
|
|
|
|
if( aStringValue.Last() == '0' )
|
|
|
|
aStringValue.RemoveLast();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Convert a value to a string using double notation.
|
2013-08-03 05:15:23 +00:00
|
|
|
* For readability, the mantissa has 3 or more digits,
|
2013-05-26 04:36:44 +00:00
|
|
|
* the trailing 0 are removed if the mantissa has more than 3 digits
|
|
|
|
* and some trailing 0
|
|
|
|
* This function should be used to display values in dialogs because a value
|
|
|
|
* entered in mm (for instance 2.0 mm) could need up to 8 digits mantissa
|
|
|
|
* if displayed in inch to avoid truncation or rounding made just by the printf function.
|
|
|
|
* otherwise the actual value is rounded when read from dialog and converted
|
|
|
|
* in internal units, and therefore modified.
|
|
|
|
*/
|
2018-03-06 12:06:46 +00:00
|
|
|
wxString StringFromValue( EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2018-03-06 12:06:46 +00:00
|
|
|
double value_to_print = To_User_Unit( aUnits, aValue, aUseMils );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
#if defined( EESCHEMA )
|
2013-08-03 05:15:23 +00:00
|
|
|
wxString stringValue = wxString::Format( wxT( "%.3f" ), value_to_print );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
// Strip trailing zeros. However, keep at least 3 digits in mantissa
|
|
|
|
// For readability
|
|
|
|
StripTrailingZeros( stringValue, 3 );
|
2013-08-03 05:15:23 +00:00
|
|
|
|
|
|
|
#else
|
2013-08-03 20:20:55 +00:00
|
|
|
|
|
|
|
char buf[50];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
|
|
|
|
{
|
|
|
|
len = sprintf( buf, "%.10f", value_to_print );
|
|
|
|
|
|
|
|
while( --len > 0 && buf[len] == '0' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
if( buf[len]=='.' || buf[len]==',' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
else
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-13 11:03:41 +00:00
|
|
|
if( aUnits == INCHES && aUseMils )
|
|
|
|
len = sprintf( buf, "%.7g", value_to_print );
|
|
|
|
else
|
|
|
|
len = sprintf( buf, "%.10g", value_to_print );
|
2013-08-03 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString stringValue( buf, wxConvUTF8 );
|
2013-08-03 05:15:23 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if( aAddUnitSymbol )
|
|
|
|
{
|
2018-03-06 12:06:46 +00:00
|
|
|
switch( aUnits )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
case INCHES:
|
2018-02-02 15:44:53 +00:00
|
|
|
if( aUseMils )
|
|
|
|
stringValue += wxT( " mils" );
|
|
|
|
else
|
|
|
|
stringValue += wxT( " in" );
|
2013-05-26 04:36:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MILLIMETRES:
|
2018-02-02 15:44:53 +00:00
|
|
|
stringValue += wxT( " mm" );
|
2013-05-26 04:36:44 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
case DEGREES:
|
2018-02-02 15:44:53 +00:00
|
|
|
stringValue += wxT( " deg" );
|
2015-02-12 03:22:24 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
case UNSCALED_UNITS:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-06 12:06:46 +00:00
|
|
|
double From_User_Unit( EDA_UNITS_T aUnits, double aValue, bool aUseMils )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2018-03-06 12:06:46 +00:00
|
|
|
switch( aUnits )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
case MILLIMETRES:
|
2018-02-02 15:44:53 +00:00
|
|
|
return MM_TO_IU( aValue );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
case INCHES:
|
2018-02-02 15:44:53 +00:00
|
|
|
if( aUseMils )
|
|
|
|
return MILS_TO_IU( aValue );
|
|
|
|
else
|
|
|
|
return IN_TO_IU( aValue );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
case DEGREES:
|
|
|
|
// Convert to "decidegrees"
|
2018-02-02 15:44:53 +00:00
|
|
|
return aValue * 10;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
default:
|
|
|
|
case UNSCALED_UNITS:
|
2018-02-02 15:44:53 +00:00
|
|
|
return aValue;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
double DoubleValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bool aUseMils )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
double value;
|
|
|
|
double dtmp = 0;
|
|
|
|
|
|
|
|
// Acquire the 'right' decimal point separator
|
|
|
|
const struct lconv* lc = localeconv();
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
wxChar decimal_point = lc->decimal_point[0];
|
|
|
|
wxString buf( aTextValue.Strip( wxString::both ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
// Convert the period in decimal point
|
|
|
|
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
|
|
|
|
|
|
|
|
// Find the end of the numeric part
|
|
|
|
unsigned brk_point = 0;
|
|
|
|
|
|
|
|
while( brk_point < buf.Len() )
|
|
|
|
{
|
|
|
|
wxChar ch = buf[brk_point];
|
|
|
|
|
|
|
|
if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++brk_point;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the numeric part
|
2013-07-09 05:48:26 +00:00
|
|
|
buf.Left( brk_point );
|
|
|
|
|
|
|
|
buf.ToDouble( &dtmp );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
// Check the optional unit designator (2 ch significant)
|
|
|
|
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
if( aUnits == INCHES || aUnits == MILLIMETRES )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2015-02-12 03:22:24 +00:00
|
|
|
if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
|
|
|
|
{
|
|
|
|
aUnits = INCHES;
|
2018-02-02 15:44:53 +00:00
|
|
|
aUseMils = false;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
else if( unit == wxT( "mm" ) )
|
|
|
|
{
|
|
|
|
aUnits = MILLIMETRES;
|
|
|
|
}
|
2018-02-02 15:44:53 +00:00
|
|
|
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
aUnits = INCHES;
|
2018-02-02 15:44:53 +00:00
|
|
|
aUseMils = true;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
else if( aUnits == DEGREES )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2015-02-12 03:22:24 +00:00
|
|
|
if( unit == wxT( "ra" ) ) // Radians
|
|
|
|
{
|
|
|
|
dtmp *= 180.0f / M_PI;
|
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
value = From_User_Unit( aUnits, dtmp, aUseMils );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS_T& aUnits, bool& aUseMils )
|
|
|
|
{
|
2018-07-26 20:10:55 +00:00
|
|
|
wxString buf( aTextValue.Strip( wxString::both ) );
|
2018-07-21 12:49:19 +00:00
|
|
|
unsigned brk_point = 0;
|
|
|
|
|
|
|
|
while( brk_point < buf.Len() )
|
|
|
|
{
|
2018-07-26 20:10:55 +00:00
|
|
|
wxChar c = buf[brk_point];
|
2018-07-21 12:49:19 +00:00
|
|
|
|
2018-07-26 20:10:55 +00:00
|
|
|
if( !( (c >= '0' && c <='9') || (c == '.') || (c == ',') || (c == '-') || (c == '+') ) )
|
2018-07-21 12:49:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
++brk_point;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the unit designator (2 ch significant)
|
|
|
|
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
|
|
|
|
|
|
|
|
if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
|
|
|
|
{
|
|
|
|
aUnits = INCHES;
|
|
|
|
aUseMils = false;
|
|
|
|
}
|
|
|
|
else if( unit == wxT( "mm" ) )
|
|
|
|
{
|
|
|
|
aUnits = MILLIMETRES;
|
|
|
|
}
|
|
|
|
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
|
|
|
|
{
|
|
|
|
aUnits = INCHES;
|
|
|
|
aUseMils = true;
|
|
|
|
}
|
|
|
|
else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad"
|
|
|
|
{
|
|
|
|
aUnits = DEGREES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bool aUseMils )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2018-02-02 15:44:53 +00:00
|
|
|
double value = DoubleValueFromString( aUnits, aTextValue, aUseMils );
|
2013-05-26 04:36:44 +00:00
|
|
|
return KiROUND( value );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 20:12:36 +00:00
|
|
|
/**
|
|
|
|
* Function AngleToStringDegrees
|
|
|
|
* is a helper to convert the \a double \a aAngle (in internal unit)
|
|
|
|
* to a string in degrees
|
|
|
|
*/
|
|
|
|
wxString AngleToStringDegrees( double aAngle )
|
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
|
|
|
|
text.Printf( wxT( "%.3f" ), aAngle/10.0 );
|
|
|
|
StripTrailingZeros( text, 1 );
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2017-02-09 10:16:28 +00:00
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit, bool aUseMils )
|
2017-02-09 10:16:28 +00:00
|
|
|
{
|
|
|
|
switch( aUnit )
|
|
|
|
{
|
|
|
|
case INCHES:
|
2018-02-02 15:44:53 +00:00
|
|
|
if( aUseMils )
|
|
|
|
return _( "mils" );
|
|
|
|
else
|
|
|
|
return _( "in" );
|
2017-02-09 10:16:28 +00:00
|
|
|
|
|
|
|
case MILLIMETRES:
|
2018-02-02 15:44:53 +00:00
|
|
|
return _( "mm" );
|
2017-02-09 10:16:28 +00:00
|
|
|
|
|
|
|
case UNSCALED_UNITS:
|
2018-02-02 15:44:53 +00:00
|
|
|
return wxEmptyString;
|
2017-02-09 10:16:28 +00:00
|
|
|
|
|
|
|
case DEGREES:
|
2018-02-02 15:44:53 +00:00
|
|
|
return _( "deg" );
|
2017-02-09 10:16:28 +00:00
|
|
|
|
|
|
|
default:
|
2018-02-02 15:44:53 +00:00
|
|
|
return wxT( "??" );
|
2017-02-09 10:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
|
|
|
|
std::string FormatInternalUnits( int aValue )
|
|
|
|
{
|
|
|
|
char buf[50];
|
|
|
|
double engUnits = aValue;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
#ifndef EESCHEMA
|
|
|
|
engUnits /= IU_PER_MM;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
|
|
|
|
{
|
|
|
|
len = snprintf( buf, sizeof(buf), "%.10f", engUnits );
|
|
|
|
|
|
|
|
while( --len > 0 && buf[len] == '0' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
#ifndef EESCHEMA
|
|
|
|
if( buf[len] == '.' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = snprintf( buf, sizeof(buf), "%.10g", engUnits );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::string( buf, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string FormatAngle( double aAngle )
|
|
|
|
{
|
|
|
|
char temp[50];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf( temp, sizeof(temp), "%.10g", aAngle / 10.0 );
|
|
|
|
|
|
|
|
return std::string( temp, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string FormatInternalUnits( const wxPoint& aPoint )
|
|
|
|
{
|
|
|
|
return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string FormatInternalUnits( const VECTOR2I& aPoint )
|
|
|
|
{
|
|
|
|
return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string FormatInternalUnits( const wxSize& aSize )
|
|
|
|
{
|
|
|
|
return FormatInternalUnits( aSize.GetWidth() ) + " " + FormatInternalUnits( aSize.GetHeight() );
|
|
|
|
}
|
|
|
|
|