From 92174d414cc86eceefd042b9ea80fd721cea266f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 16 Aug 2020 10:17:20 -0400 Subject: [PATCH] Ensure pads and zones come up visible by default These visibility layers didn't exist until now --- common/project/project_local_settings.cpp | 51 +++++++++++++++++++++-- common/settings/settings_manager.cpp | 3 +- include/project/project_local_settings.h | 7 +++- pcbnew/pcb_parser.cpp | 4 ++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/common/project/project_local_settings.cpp b/common/project/project_local_settings.cpp index 7ad056f29b..c2e6bfa235 100644 --- a/common/project/project_local_settings.cpp +++ b/common/project/project_local_settings.cpp @@ -22,14 +22,14 @@ #include #include -const int projectLocalSettingsVersion = 1; +const int projectLocalSettingsVersion = 2; -PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( const wxString& aFilename ) : +PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxString& aFilename ) : JSON_SETTINGS( aFilename, SETTINGS_LOC::PROJECT, projectLocalSettingsVersion, /* aCreateIfMissing = */ true, /* aCreateIfDefault = */ false, /* aWriteFile = */ true ), - m_project( nullptr ), + m_project( aProject ), m_SelectionFilter() { m_params.emplace_back( new PARAM_LAMBDA( "board.visible_layers", @@ -186,3 +186,48 @@ bool PROJECT_LOCAL_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce return JSON_SETTINGS::SaveToFile( aDirectory, aForce ); } + + +bool PROJECT_LOCAL_SETTINGS::Migrate() +{ + bool ret = true; + int filever = at( PointerFromString( "meta.version" ) ).get(); + + if( filever == 1 ) + { + ret &= migrateSchema1to2(); + + if( ret ) + { + ( *this )[PointerFromString( "meta.version" )] = 1; + } + } + + return ret; +} + + +bool PROJECT_LOCAL_SETTINGS::migrateSchema1to2() +{ + /** + * Schema version 1 to 2: + * LAYER_PADS and LAYER_ZONES added to visibility controls + */ + + nlohmann::json::json_pointer ptr( "/board/visible_items"_json_pointer ); + + if( contains( ptr ) ) + { + if( ( *this )[ptr].is_array() ) + { + ( *this )[ptr].push_back( LAYER_PADS ); + ( *this )[ptr].push_back( LAYER_ZONES ); + } + else + { + at( "board" ).erase( "visible_items" ); + } + } + + return true; +} \ No newline at end of file diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index f6c85075aa..8557c817f2 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -712,10 +712,9 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive ) wxString fn( path.GetName() ); PROJECT_LOCAL_SETTINGS* settings = static_cast( - RegisterSettings( new PROJECT_LOCAL_SETTINGS( fn ) ) ); + RegisterSettings( new PROJECT_LOCAL_SETTINGS( m_projects[fullPath].get(), fn ) ) ); m_projects[fullPath]->setLocalSettings( settings ); - settings->SetProject( m_projects[fullPath].get() ); if( m_kiway ) m_kiway->ProjectChanged(); diff --git a/include/project/project_local_settings.h b/include/project/project_local_settings.h index aa15e05f04..8cfb853588 100644 --- a/include/project/project_local_settings.h +++ b/include/project/project_local_settings.h @@ -43,12 +43,14 @@ class PROJECT; class PROJECT_LOCAL_SETTINGS : public JSON_SETTINGS { public: - PROJECT_LOCAL_SETTINGS( const wxString& aFilename ); + PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxString& aFilename ); virtual ~PROJECT_LOCAL_SETTINGS() {} bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override; + bool Migrate() override; + bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override; void SetProject( PROJECT* aProject ) @@ -56,6 +58,9 @@ public: m_project = aProject; } +private: + bool migrateSchema1to2(); + protected: wxString getFileExt() const override diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 2a3019d775..55b74c5625 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1810,6 +1810,10 @@ void PCB_PARSER::parseSetup() for( size_t i = 0; i < sizeof( int ) * CHAR_BIT; i++ ) m_board->m_LegacyVisibleItems.set( i, visible & ( 1u << i ) ); + // These didn't exist in legacy files; make sure they are set + m_board->m_LegacyVisibleItems.set( LAYER_PADS ); + m_board->m_LegacyVisibleItems.set( LAYER_ZONES ); + NeedRIGHT(); } break;