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

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
...@@ -508,7 +508,11 @@ void PARAM_CFG_INT_WITH_SCALE::SaveParam( wxConfigBase* aConfig ) const ...@@ -508,7 +508,11 @@ void PARAM_CFG_INT_WITH_SCALE::SaveParam( wxConfigBase* aConfig ) const
if( m_Pt_param == NULL || aConfig == NULL ) if( m_Pt_param == NULL || aConfig == NULL )
return; 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 ...@@ -617,7 +621,11 @@ void PARAM_CFG_DOUBLE::SaveParam( wxConfigBase* aConfig ) const
if( m_Pt_param == NULL || aConfig == NULL ) if( m_Pt_param == NULL || aConfig == NULL )
return; 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 );
} }
......
...@@ -14,6 +14,31 @@ ...@@ -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 */ /** Type of parameter in the configuration file */
enum paramcfg_id { enum paramcfg_id {
PARAM_INT, PARAM_INT,
......
...@@ -415,21 +415,20 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab ...@@ -415,21 +415,20 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab
m_settings.m_Zone_45_Only = true; m_settings.m_Zone_45_Only = true;
m_settings.m_ThermalReliefGap = ReturnValueFromTextCtrl( *m_AntipadSizeValue ); m_settings.m_ThermalReliefGap = ReturnValueFromTextCtrl( *m_AntipadSizeValue );
m_settings.m_ThermalReliefCopperBridge = ReturnValueFromTextCtrl( *m_CopperWidthValue ); m_settings.m_ThermalReliefCopperBridge = ReturnValueFromTextCtrl( *m_CopperWidthValue );
if( m_Config ) 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 ); (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 ); (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 ); (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 ); (double) m_settings.m_ThermalReliefCopperBridge / IU_PER_MILS );
} }
......
...@@ -627,7 +627,7 @@ void DIALOG_PLOT::applyPlotSettings() ...@@ -627,7 +627,7 @@ void DIALOG_PLOT::applyPlotSettings()
m_messagesBox->AppendText( msg ); 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 // Y scale
msg = m_fineAdjustYscaleOpt->GetValue(); msg = m_fineAdjustYscaleOpt->GetValue();
...@@ -641,7 +641,7 @@ void DIALOG_PLOT::applyPlotSettings() ...@@ -641,7 +641,7 @@ void DIALOG_PLOT::applyPlotSettings()
m_messagesBox->AppendText( msg ); 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 // PS Width correction
msg = m_PSFineAdjustWidthOpt->GetValue(); msg = m_PSFineAdjustWidthOpt->GetValue();
...@@ -661,7 +661,8 @@ void DIALOG_PLOT::applyPlotSettings() ...@@ -661,7 +661,8 @@ void DIALOG_PLOT::applyPlotSettings()
} }
// Store m_PSWidthAdjust in mm in user config // 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() ); tempOptions.SetUseGerberExtensions( m_useGerberExtensions->GetValue() );
......
...@@ -314,8 +314,10 @@ void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event ) ...@@ -314,8 +314,10 @@ void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event )
if( m_config ) if( m_config )
{ {
m_config->Write( OPTKEY_PRINT_X_FINESCALE_ADJ, s_Parameters.m_XScaleAdjust ); ConfigBaseWriteDouble( m_config, OPTKEY_PRINT_X_FINESCALE_ADJ,
m_config->Write( OPTKEY_PRINT_Y_FINESCALE_ADJ, s_Parameters.m_YScaleAdjust ); 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_SCALE, m_ScaleOption->GetSelection() );
m_config->Write( OPTKEY_PRINT_PAGE_FRAME, s_Parameters.m_Print_Sheet_Ref); 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); m_config->Write( OPTKEY_PRINT_MONOCHROME_MODE, s_Parameters.m_Print_Black_and_White);
......
...@@ -61,11 +61,11 @@ ...@@ -61,11 +61,11 @@
// Keys used in read/write config // Keys used in read/write config
#define OPTKEY_DEFAULT_LINEWIDTH_VALUE wxT( "PlotLineWidth_mm" ) #define OPTKEY_DEFAULT_LINEWIDTH_VALUE wxT( "PlotLineWidth_mm" )
#define PCB_SHOW_FULL_RATSNET_OPT wxT( "PcbFulRatsnest" ) #define PCB_SHOW_FULL_RATSNET_OPT wxT( "PcbFullRatsnest" )
#define PCB_MAGNETIC_PADS_OPT wxT( "PcbMagPadOpt" ) #define PCB_MAGNETIC_PADS_OPT wxT( "PcbMagPadOpt" )
#define PCB_MAGNETIC_TRACKS_OPT wxT( "PcbMagTrackOpt" ) #define PCB_MAGNETIC_TRACKS_OPT wxT( "PcbMagTrackOpt" )
#define SHOW_MICROWAVE_TOOLS wxT( "ShowMicrowaveTools" ) #define SHOW_MICROWAVE_TOOLS wxT( "ShowMicrowaveTools" )
#define SHOW_LAYER_MANAGER_TOOLS wxT( "ShowLayerManagerTools" ) #define SHOW_LAYER_MANAGER_TOOLS wxT( "ShowLayerManagerTools" )
BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
...@@ -313,14 +313,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, ...@@ -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_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; wxIcon icon;
icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) ); icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) );
SetIcon( icon ); SetIcon( icon );
...@@ -333,6 +325,16 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, ...@@ -333,6 +325,16 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
// LoadSettings() *after* creating m_LayersManager, because LoadSettings() // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
// initialize parameters in m_LayersManager // initialize parameters in m_LayersManager
LoadSettings(); 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 ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER ); GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
...@@ -592,6 +594,7 @@ void PCB_EDIT_FRAME::LoadSettings() ...@@ -592,6 +594,7 @@ void PCB_EDIT_FRAME::LoadSettings()
long tmp; long tmp;
config->Read( PCB_SHOW_FULL_RATSNET_OPT, &tmp ); config->Read( PCB_SHOW_FULL_RATSNET_OPT, &tmp );
GetBoard()->SetElementVisibility(RATSNEST_VISIBLE, tmp); GetBoard()->SetElementVisibility(RATSNEST_VISIBLE, tmp);
config->Read( PCB_MAGNETIC_PADS_OPT, &g_MagneticPadOption ); config->Read( PCB_MAGNETIC_PADS_OPT, &g_MagneticPadOption );
config->Read( PCB_MAGNETIC_TRACKS_OPT, &g_MagneticTrackOption ); config->Read( PCB_MAGNETIC_TRACKS_OPT, &g_MagneticTrackOption );
config->Read( SHOW_MICROWAVE_TOOLS, &m_show_microwave_tools ); config->Read( SHOW_MICROWAVE_TOOLS, &m_show_microwave_tools );
......
...@@ -348,6 +348,8 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings() ...@@ -348,6 +348,8 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings()
&DisplayOpt.DisplayModText, FILLED, 0, 2 ) ); &DisplayOpt.DisplayModText, FILLED, 0, 2 ) );
m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbAffT" ), m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbAffT" ),
&DisplayOpt.DisplayDrawItems, FILLED, 0, 2 ) ); &DisplayOpt.DisplayDrawItems, FILLED, 0, 2 ) );
m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ),
&DisplayOpt.DisplayZonesMode, 0, 0, 2 ) );
// Colors: // Colors:
m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay0" ), LOC_COLOR( 0 ), m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay0" ), LOC_COLOR( 0 ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment