From d0724de1de98583f7e0f6a5a1d25980b95b5ff51 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 29 Mar 2013 11:14:32 +0100 Subject: [PATCH] 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 --- common/projet_config.cpp | 12 ++++++-- include/param_config.h | 25 ++++++++++++++++ pcbnew/dialogs/dialog_copper_zones.cpp | 11 ++++--- pcbnew/dialogs/dialog_plot.cpp | 7 +++-- pcbnew/dialogs/dialog_print_using_printer.cpp | 6 ++-- pcbnew/pcbframe.cpp | 29 ++++++++++--------- pcbnew/pcbnew_config.cpp | 2 ++ 7 files changed, 66 insertions(+), 26 deletions(-) diff --git a/common/projet_config.cpp b/common/projet_config.cpp index dba92bb4e5..8e77bc7961 100644 --- a/common/projet_config.cpp +++ b/common/projet_config.cpp @@ -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 ); } diff --git a/include/param_config.h b/include/param_config.h index 1868cf9afb..65f8759779 100644 --- a/include/param_config.h +++ b/include/param_config.h @@ -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, diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index 6daacdb21b..92167854f5 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -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, - (double) m_settings.m_ZoneClearance / IU_PER_MILS ); + 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 ); } diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index 636f7eae8a..fff9f9bbf7 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -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() ); diff --git a/pcbnew/dialogs/dialog_print_using_printer.cpp b/pcbnew/dialogs/dialog_print_using_printer.cpp index 379bd073f6..111d107391 100644 --- a/pcbnew/dialogs/dialog_print_using_printer.cpp +++ b/pcbnew/dialogs/dialog_print_using_printer.cpp @@ -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); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 3378c576e3..5ee7f1a2f1 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -61,11 +61,11 @@ // Keys used in read/write config #define OPTKEY_DEFAULT_LINEWIDTH_VALUE wxT( "PlotLineWidth_mm" ) -#define PCB_SHOW_FULL_RATSNET_OPT wxT( "PcbFulRatsnest" ) -#define PCB_MAGNETIC_PADS_OPT wxT( "PcbMagPadOpt" ) -#define PCB_MAGNETIC_TRACKS_OPT wxT( "PcbMagTrackOpt" ) -#define SHOW_MICROWAVE_TOOLS wxT( "ShowMicrowaveTools" ) -#define SHOW_LAYER_MANAGER_TOOLS wxT( "ShowLayerManagerTools" ) +#define PCB_SHOW_FULL_RATSNET_OPT wxT( "PcbFullRatsnest" ) +#define PCB_MAGNETIC_PADS_OPT wxT( "PcbMagPadOpt" ) +#define PCB_MAGNETIC_TRACKS_OPT wxT( "PcbMagTrackOpt" ) +#define SHOW_MICROWAVE_TOOLS wxT( "ShowMicrowaveTools" ) +#define SHOW_LAYER_MANAGER_TOOLS wxT( "ShowLayerManagerTools" ) BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) @@ -313,14 +313,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, m_drc = new DRC( this ); // these 2 objects point to each other - m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill; - m_DisplayPadFill = DisplayOpt.DisplayPadFill; - m_DisplayViaFill = DisplayOpt.DisplayViaFill; - m_DisplayPadNum = DisplayOpt.DisplayPadNum; - - m_DisplayModEdge = DisplayOpt.DisplayModEdge; - m_DisplayModText = DisplayOpt.DisplayModText; - wxIcon icon; icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) ); SetIcon( icon ); @@ -333,6 +325,16 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, // LoadSettings() *after* creating m_LayersManager, because LoadSettings() // initialize parameters in m_LayersManager LoadSettings(); + + // Be sure options are updated + m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill; + m_DisplayPadFill = DisplayOpt.DisplayPadFill; + m_DisplayViaFill = DisplayOpt.DisplayViaFill; + m_DisplayPadNum = DisplayOpt.DisplayPadNum; + + m_DisplayModEdge = DisplayOpt.DisplayModEdge; + m_DisplayModText = DisplayOpt.DisplayModText; + SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER ); @@ -592,6 +594,7 @@ void PCB_EDIT_FRAME::LoadSettings() long tmp; config->Read( PCB_SHOW_FULL_RATSNET_OPT, &tmp ); GetBoard()->SetElementVisibility(RATSNEST_VISIBLE, tmp); + config->Read( PCB_MAGNETIC_PADS_OPT, &g_MagneticPadOption ); config->Read( PCB_MAGNETIC_TRACKS_OPT, &g_MagneticTrackOption ); config->Read( SHOW_MICROWAVE_TOOLS, &m_show_microwave_tools ); diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index b6d1d76224..895d9c1e63 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -348,6 +348,8 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings() &DisplayOpt.DisplayModText, FILLED, 0, 2 ) ); m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbAffT" ), &DisplayOpt.DisplayDrawItems, FILLED, 0, 2 ) ); + m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ), + &DisplayOpt.DisplayZonesMode, 0, 0, 2 ) ); // Colors: m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay0" ), LOC_COLOR( 0 ),