Migrate dimension precision
This commit is contained in:
parent
b11e315d10
commit
ae7877c6cb
|
@ -64,11 +64,45 @@ bool NESTED_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
|||
catch( ... )
|
||||
{
|
||||
wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not load from %s at %s",
|
||||
m_filename, m_parent->GetFilename(), m_path );
|
||||
m_filename, m_parent->GetFilename(), m_path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( success )
|
||||
{
|
||||
int filever = -1;
|
||||
|
||||
try
|
||||
{
|
||||
filever = at( PointerFromString( "meta.version" ) ).get<int>();
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
wxLogTrace( traceSettings, "%s: nested settings version could not be read!",
|
||||
m_filename );
|
||||
success = false;
|
||||
}
|
||||
|
||||
if( filever >= 0 && filever < m_schemaVersion )
|
||||
{
|
||||
wxLogTrace( traceSettings, "%s: attempting migration from version %d to %d",
|
||||
m_filename, filever, m_schemaVersion );
|
||||
|
||||
if( !Migrate() )
|
||||
{
|
||||
wxLogTrace( traceSettings, "%s: migration failed!", GetFullFilename() );
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
else if( filever > m_schemaVersion )
|
||||
{
|
||||
wxLogTrace( traceSettings,
|
||||
"%s: warning: nested settings version %d is newer than latest (%d)",
|
||||
m_filename, filever, m_schemaVersion );
|
||||
}
|
||||
}
|
||||
|
||||
Load();
|
||||
|
||||
return success;
|
||||
|
|
|
@ -327,6 +327,8 @@ private:
|
|||
|
||||
void initFromOther( const BOARD_DESIGN_SETTINGS& aOther );
|
||||
|
||||
bool migrateSchema0to1();
|
||||
|
||||
public:
|
||||
BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath );
|
||||
|
||||
|
@ -338,6 +340,8 @@ public:
|
|||
|
||||
bool LoadFromFile( const wxString& aDirectory = "" ) override;
|
||||
|
||||
bool Migrate() override;
|
||||
|
||||
BOARD_STACKUP& GetStackupDescriptor() { return m_stackup; }
|
||||
|
||||
int GetSeverity( int aDRCErrorCode );
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <project/project_file.h>
|
||||
#include <advanced_config.h>
|
||||
|
||||
const int bdsSchemaVersion = 0;
|
||||
const int bdsSchemaVersion = 1;
|
||||
|
||||
|
||||
BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
|
||||
|
@ -393,7 +393,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std:
|
|||
if( !aObj.is_array() )
|
||||
return;
|
||||
|
||||
m_DiffPairDimensionsList.clear();
|
||||
m_DiffPairDimensionsList.clear();
|
||||
|
||||
for( const nlohmann::json& entry : aObj )
|
||||
{
|
||||
|
@ -514,7 +514,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std:
|
|||
&m_DimensionUnits, 0, 0, 2 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "defaults.dimension_precision",
|
||||
&m_DimensionPrecision, 1, 0, 2 ) );
|
||||
&m_DimensionPrecision, 4, 0, 5 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<bool>( "defaults.zones.45_degree_only",
|
||||
&m_defaultZoneSettings.m_Zone_45_Only, false ) );
|
||||
|
@ -665,6 +665,76 @@ void BOARD_DESIGN_SETTINGS::initFromOther( const BOARD_DESIGN_SETTINGS& aOther )
|
|||
}
|
||||
|
||||
|
||||
bool BOARD_DESIGN_SETTINGS::Migrate()
|
||||
{
|
||||
bool ret = true;
|
||||
int filever = at( PointerFromString( "meta.version" ) ).get<int>();
|
||||
|
||||
if( filever == 0 )
|
||||
{
|
||||
ret &= migrateSchema0to1();
|
||||
|
||||
if( ret )
|
||||
{
|
||||
( *this )[PointerFromString( "meta.version" )] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool BOARD_DESIGN_SETTINGS::migrateSchema0to1()
|
||||
{
|
||||
/**
|
||||
* Schema 0 to 1: default dimension precision changed in meaning.
|
||||
* Previously it was an enum with the following meaning:
|
||||
*
|
||||
* 0: 0.01mm / 1 mil / 0.001 in
|
||||
* 1: 0.001mm / 0.1 mil / 0.0001 in
|
||||
* 2: 0.0001mm / 0.01 mil / 0.00001 in
|
||||
*
|
||||
* Now it is indepenent of display units and is an integer meaning the number of digits
|
||||
* displayed after the decimal point, so we have to migrate based on the default units.
|
||||
*
|
||||
* The units is an integer with the following mapping:
|
||||
*
|
||||
* 0: Inches
|
||||
* 1: Mils
|
||||
* 2: Millimetres
|
||||
*/
|
||||
nlohmann::json::json_pointer units_ptr( "/defaults/dimension_units" );
|
||||
nlohmann::json::json_pointer precision_ptr( "/defaults/dimension_precision" );
|
||||
|
||||
if( !( contains( units_ptr ) && contains( precision_ptr ) &&
|
||||
at( units_ptr ).is_number_integer() &&
|
||||
at( precision_ptr ).is_number_integer() ) )
|
||||
{
|
||||
// if either is missing or invalid, migration doesn't make sense
|
||||
return true;
|
||||
}
|
||||
|
||||
int units = at( units_ptr ).get<int>();
|
||||
int precision = at( precision_ptr ).get<int>();
|
||||
|
||||
// The enum maps directly to precision if the units is mils
|
||||
int extraDigits = 0;
|
||||
|
||||
switch( units )
|
||||
{
|
||||
case 0: extraDigits = 3; break;
|
||||
case 2: extraDigits = 2; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
precision += extraDigits;
|
||||
|
||||
( *this )[precision_ptr] = precision;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool BOARD_DESIGN_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
||||
{
|
||||
bool ret = NESTED_SETTINGS::LoadFromFile( aDirectory );
|
||||
|
|
|
@ -102,7 +102,7 @@ DIALOG_DIMENSION_PROPERTIES_BASE::DIALOG_DIMENSION_PROPERTIES_BASE( wxWindow* pa
|
|||
|
||||
gbSizerFormat->Add( m_lblPrecision, wxGBPosition( 2, 4 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
wxString m_cbPrecisionChoices[] = { _("0.0000"), _("0.000"), _("0.00"), _("0.0"), _("0") };
|
||||
wxString m_cbPrecisionChoices[] = { _("0"), _("0.0"), _("0.00"), _("0.000"), _("0.0000"), _("0.00000") };
|
||||
int m_cbPrecisionNChoices = sizeof( m_cbPrecisionChoices ) / sizeof( wxString );
|
||||
m_cbPrecision = new wxChoice( sbSizerFormat->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_cbPrecisionNChoices, m_cbPrecisionChoices, 0 );
|
||||
m_cbPrecision->SetSelection( 0 );
|
||||
|
|
|
@ -908,7 +908,7 @@
|
|||
<property name="caption"></property>
|
||||
<property name="caption_visible">1</property>
|
||||
<property name="center_pane">0</property>
|
||||
<property name="choices">"0.0000" "0.000" "0.00" "0.0" "0"</property>
|
||||
<property name="choices">"0" "0.0" "0.00" "0.000" "0.0000" "0.00000"</property>
|
||||
<property name="close_button">1</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
|
|
Loading…
Reference in New Issue