コード例 #1
0
/**
 * 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;
}
コード例 #2
0
/* Convert a value to a string using double notation.
 * For readability, the mantissa has 3 or more digits,
 * 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.
 */
wxString StringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol )
{
    double  value_to_print = To_User_Unit( aUnit, aValue );

#if defined( EESCHEMA )
    wxString    stringValue = wxString::Format( wxT( "%.3f" ), value_to_print );

    // Strip trailing zeros. However, keep at least 3 digits in mantissa
    // For readability
    StripTrailingZeros( stringValue, 3 );

#else

    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
    {
        len = sprintf( buf, "%.10g", value_to_print );
    }

    wxString    stringValue( buf, wxConvUTF8 );

#endif

    if( aAddUnitSymbol )
    {
        switch( aUnit )
        {
        case INCHES:
            stringValue += _( " \"" );
            break;

        case MILLIMETRES:
            stringValue += _( " mm" );
            break;

        case UNSCALED_UNITS:
            break;
        }
    }

    return stringValue;
}
コード例 #3
0
ファイル: basepcbframe.cpp プロジェクト: jerkey/kicad
void PCB_BASE_FRAME::updateGridSelectBox()
{
    UpdateStatusBar();
    DisplayUnitsMsg();

    if( m_gridSelectBox == NULL )
        return;

    // Update grid values with the current units setting.
    m_gridSelectBox->Clear();

    wxString msg;
    wxString format = _( "Grid:");

    switch( g_UserUnit )
    {
    case INCHES:    // the grid size is displayed in mils
    case MILLIMETRES:
        format += wxT( " %.6f" );
        break;

    case UNSCALED_UNITS:
        format += wxT( " %f" );
        break;
    }

    for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
    {
        GRID_TYPE& grid = GetScreen()->GetGrid( i );
        double value = To_User_Unit( g_UserUnit, grid.m_Size.x );
        if( g_UserUnit == INCHES )
            value *= 1000;

        if( grid.m_Id != ID_POPUP_GRID_USER )
        {
            msg.Printf( format.GetData(), value );
            StripTrailingZeros( msg );
        }
        else
            msg = _( "User Grid" );

        m_gridSelectBox->Append( msg, (void*) &grid.m_Id );

        if( ( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ) == GetScreen()->GetGrid( i ).m_Id )
            m_gridSelectBox->SetSelection( i );
    }
}