Ensure pads and zones come up visible by default

These visibility layers didn't exist until now
This commit is contained in:
Jon Evans 2020-08-16 10:17:20 -04:00
parent 6bfb32245b
commit 92174d414c
4 changed files with 59 additions and 6 deletions

View File

@ -22,14 +22,14 @@
#include <project/project_local_settings.h>
#include <settings/parameters.h>
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<std::string>( "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<int>();
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;
}

View File

@ -712,10 +712,9 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
wxString fn( path.GetName() );
PROJECT_LOCAL_SETTINGS* settings = static_cast<PROJECT_LOCAL_SETTINGS*>(
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();

View File

@ -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

View File

@ -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;