Commit d0724de1 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Fix rounding issue when a double is stored in a wxConfig file (wxWidgets 2.9.4...

Fix rounding issue when a double is stored in a wxConfig file (wxWidgets 2.9.4 store only 4 digits in mantissa).
A new inline function ConfigBaseWriteDouble( config, key,  double_value )  is used instead of config->Write(  key, double_value ) which store 12 digits
parent 675f8d4a
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -508,7 +508,11 @@ void PARAM_CFG_INT_WITH_SCALE::SaveParam( wxConfigBase* aConfig ) const
    if( m_Pt_param == NULL || aConfig == NULL )
        return;

    aConfig->Write( m_Ident, *m_Pt_param * m_BIU_to_cfgunit );
    // We cannot use aConfig->Write for a double, because
    // this function uses a format with very few digits in mantissa,
    // and truncature issues are frequent.
    // We uses our function.
    ConfigBaseWriteDouble( aConfig, m_Ident, *m_Pt_param * m_BIU_to_cfgunit );
}


@@ -617,7 +621,11 @@ void PARAM_CFG_DOUBLE::SaveParam( wxConfigBase* aConfig ) const
    if( m_Pt_param == NULL || aConfig == NULL )
        return;

    aConfig->Write( m_Ident, *m_Pt_param );
    // We cannot use aConfig->Write for a double, because
    // this function uses a format with very few digits in mantissa,
    // and truncature issues are frequent.
    // We uses our function.
    ConfigBaseWriteDouble( aConfig, m_Ident, *m_Pt_param );
}


+25 −0
Original line number Diff line number Diff line
@@ -14,6 +14,31 @@



/**
 * inline ConfigBaseWriteDouble
 * This is a helper funvtion tor write doubles in config
 * We cannot use wxConfigBase->Write for a double, because
 * this function uses a format with very few digits in mantissa,
 * and truncation issues are frequent.
 * We use here a better floatting format.
 *
 * Note: prior to 2.9.1, the separator was localized, and after, uses
 * the "C" notation
 */
 void inline ConfigBaseWriteDouble( wxConfigBase* aConfig,
                                    const wxString& aKey, double aValue )
 {
    wxString tnumber;

#if wxCHECK_VERSION(2,9,1)
    tnumber = wxString::FromCDouble( aValue, 12 );
#else
    tnumber.Printf( wxT("%12f"), aValue );
#endif
    aConfig->Write( aKey, tnumber );
}


/** Type of parameter in the configuration file */
enum paramcfg_id {
    PARAM_INT,
+5 −6
Original line number Diff line number Diff line
@@ -415,21 +415,20 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab
        m_settings.m_Zone_45_Only = true;

    m_settings.m_ThermalReliefGap = ReturnValueFromTextCtrl( *m_AntipadSizeValue );

    m_settings.m_ThermalReliefCopperBridge = ReturnValueFromTextCtrl( *m_CopperWidthValue );

    if( m_Config )
    {
        m_Config->Write( ZONE_CLEARANCE_WIDTH_STRING_KEY,
        ConfigBaseWriteDouble( m_Config, ZONE_CLEARANCE_WIDTH_STRING_KEY,
                               (double) m_settings.m_ZoneClearance / IU_PER_MILS );

        m_Config->Write( ZONE_MIN_THICKNESS_WIDTH_STRING_KEY,
        ConfigBaseWriteDouble( m_Config, ZONE_MIN_THICKNESS_WIDTH_STRING_KEY,
            (double) m_settings.m_ZoneMinThickness / IU_PER_MILS );

        m_Config->Write( ZONE_THERMAL_RELIEF_GAP_STRING_KEY,
        ConfigBaseWriteDouble( m_Config, ZONE_THERMAL_RELIEF_GAP_STRING_KEY,
            (double) m_settings.m_ThermalReliefGap / IU_PER_MILS );

        m_Config->Write( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY,
        ConfigBaseWriteDouble( m_Config, ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY,
            (double) m_settings.m_ThermalReliefCopperBridge / IU_PER_MILS );
    }

+4 −3
Original line number Diff line number Diff line
@@ -627,7 +627,7 @@ void DIALOG_PLOT::applyPlotSettings()
        m_messagesBox->AppendText( msg );
    }

    m_config->Write( OPTKEY_PLOT_X_FINESCALE_ADJ, m_XScaleAdjust );
   ConfigBaseWriteDouble( m_config, OPTKEY_PLOT_X_FINESCALE_ADJ, m_XScaleAdjust );

    // Y scale
    msg = m_fineAdjustYscaleOpt->GetValue();
@@ -641,7 +641,7 @@ void DIALOG_PLOT::applyPlotSettings()
        m_messagesBox->AppendText( msg );
    }

    m_config->Write( OPTKEY_PLOT_Y_FINESCALE_ADJ, m_YScaleAdjust );
    ConfigBaseWriteDouble( m_config, OPTKEY_PLOT_Y_FINESCALE_ADJ, m_YScaleAdjust );

    // PS Width correction
    msg = m_PSFineAdjustWidthOpt->GetValue();
@@ -661,7 +661,8 @@ void DIALOG_PLOT::applyPlotSettings()
    }

    // Store m_PSWidthAdjust in mm in user config
    m_config->Write( CONFIG_PS_FINEWIDTH_ADJ, (double)m_PSWidthAdjust / IU_PER_MM );
    ConfigBaseWriteDouble( m_config, CONFIG_PS_FINEWIDTH_ADJ,
                           (double)m_PSWidthAdjust / IU_PER_MM );

    tempOptions.SetUseGerberExtensions( m_useGerberExtensions->GetValue() );

+4 −2
Original line number Diff line number Diff line
@@ -314,8 +314,10 @@ void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event )

    if( m_config )
    {
        m_config->Write( OPTKEY_PRINT_X_FINESCALE_ADJ, s_Parameters.m_XScaleAdjust );
        m_config->Write( OPTKEY_PRINT_Y_FINESCALE_ADJ, s_Parameters.m_YScaleAdjust );
        ConfigBaseWriteDouble( m_config, OPTKEY_PRINT_X_FINESCALE_ADJ,
                               s_Parameters.m_XScaleAdjust );
        ConfigBaseWriteDouble( m_config, OPTKEY_PRINT_Y_FINESCALE_ADJ,
                               s_Parameters.m_YScaleAdjust );
        m_config->Write( OPTKEY_PRINT_SCALE, m_ScaleOption->GetSelection() );
        m_config->Write( OPTKEY_PRINT_PAGE_FRAME, s_Parameters.m_Print_Sheet_Ref);
        m_config->Write( OPTKEY_PRINT_MONOCHROME_MODE, s_Parameters.m_Print_Black_and_White);
Loading