Fix management of nested settings for PNS
This commit is contained in:
parent
d5ceb8252e
commit
9cc5b4b3f9
|
@ -642,8 +642,6 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas
|
||||||
if( cfg )
|
if( cfg )
|
||||||
cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
|
cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
|
||||||
|
|
||||||
Pgm().GetSettingsManager().Save( cfg );
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -381,10 +381,27 @@ bool JSON_SETTINGS::fromLegacyColor( wxConfigBase* aConfig, const std::string& a
|
||||||
|
|
||||||
void JSON_SETTINGS::AddNestedSettings( NESTED_SETTINGS* aSettings )
|
void JSON_SETTINGS::AddNestedSettings( NESTED_SETTINGS* aSettings )
|
||||||
{
|
{
|
||||||
|
wxLogTrace( traceSettings, "AddNestedSettings %s", aSettings->GetFilename() );
|
||||||
m_nested_settings.push_back( aSettings );
|
m_nested_settings.push_back( aSettings );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JSON_SETTINGS::ReleaseNestedSettings( NESTED_SETTINGS* aSettings )
|
||||||
|
{
|
||||||
|
auto it = std::find_if( m_nested_settings.begin(), m_nested_settings.end(),
|
||||||
|
[&aSettings]( const JSON_SETTINGS* aPtr ) {
|
||||||
|
return aPtr == aSettings;
|
||||||
|
} );
|
||||||
|
|
||||||
|
if( it != m_nested_settings.end() )
|
||||||
|
{
|
||||||
|
wxLogTrace( traceSettings, "Flush and release %s", ( *it )->GetFilename() );
|
||||||
|
( *it )->SaveToFile();
|
||||||
|
m_nested_settings.erase( it );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Specializations to allow conversion between wxString and std::string via JSON_SETTINGS API
|
// Specializations to allow conversion between wxString and std::string via JSON_SETTINGS API
|
||||||
|
|
||||||
template<> wxString JSON_SETTINGS::Get( std::string aPath ) const
|
template<> wxString JSON_SETTINGS::Get( std::string aPath ) const
|
||||||
|
|
|
@ -38,6 +38,12 @@ NESTED_SETTINGS::NESTED_SETTINGS( const std::string& aName, int aVersion, JSON_S
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NESTED_SETTINGS::~NESTED_SETTINGS()
|
||||||
|
{
|
||||||
|
m_parent->ReleaseNestedSettings( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NESTED_SETTINGS::LoadFromFile( const std::string& aDirectory )
|
void NESTED_SETTINGS::LoadFromFile( const std::string& aDirectory )
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -147,6 +147,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void AddNestedSettings( NESTED_SETTINGS* aSettings );
|
void AddNestedSettings( NESTED_SETTINGS* aSettings );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves and frees a nested settings object, if it exists within this one
|
||||||
|
* @param aSettings is a pointer to a NESTED_SETTINGS that has already been added to this one
|
||||||
|
*/
|
||||||
|
void ReleaseNestedSettings( NESTED_SETTINGS* aSettings );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a JSON pointer based on a given string
|
* Builds a JSON pointer based on a given string
|
||||||
* @param aPath is the path in the form "key1.key2.key3"
|
* @param aPath is the path in the form "key1.key2.key3"
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent,
|
NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent,
|
||||||
const std::string& aPath, nlohmann::json aDefault = nlohmann::json( {} ) );
|
const std::string& aPath, nlohmann::json aDefault = nlohmann::json( {} ) );
|
||||||
|
|
||||||
virtual ~NESTED_SETTINGS() {}
|
virtual ~NESTED_SETTINGS();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the JSON document from the parent and then calls Load()
|
* Loads the JSON document from the parent and then calls Load()
|
||||||
|
|
|
@ -77,7 +77,6 @@ void DIALOG_PNS_SETTINGS::OnOkClick( wxCommandEvent& aEvent )
|
||||||
m_settings.SetFreeAngleMode( m_freeAngleMode->GetValue() );
|
m_settings.SetFreeAngleMode( m_freeAngleMode->GetValue() );
|
||||||
m_settings.SetInlineDragEnabled( m_dragToolMode->GetSelection () ? true : false );
|
m_settings.SetInlineDragEnabled( m_dragToolMode->GetSelection () ? true : false );
|
||||||
m_settings.SetOptimizeDraggedTrack( m_optimizeDraggedTrack->GetValue() );
|
m_settings.SetOptimizeDraggedTrack( m_optimizeDraggedTrack->GetValue() );
|
||||||
m_settings.SaveToFile();
|
|
||||||
|
|
||||||
aEvent.Skip(); // ends returning wxID_OK (default behavior)
|
aEvent.Skip(); // ends returning wxID_OK (default behavior)
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,6 +387,9 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() : APP_SETTINGS_BASE( "pcbnew", pcbnewSchemaVe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PCBNEW_SETTINGS::~PCBNEW_SETTINGS() = default;
|
||||||
|
|
||||||
|
|
||||||
bool PCBNEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
|
bool PCBNEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
|
||||||
{
|
{
|
||||||
bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
|
bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
|
||||||
|
|
|
@ -191,7 +191,7 @@ public:
|
||||||
|
|
||||||
PCBNEW_SETTINGS();
|
PCBNEW_SETTINGS();
|
||||||
|
|
||||||
virtual ~PCBNEW_SETTINGS() {}
|
virtual ~PCBNEW_SETTINGS();
|
||||||
|
|
||||||
virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override;
|
virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override;
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ public:
|
||||||
|
|
||||||
bool m_MagneticGraphics;
|
bool m_MagneticGraphics;
|
||||||
|
|
||||||
PNS::ROUTING_SETTINGS* m_PnsSettings;
|
std::unique_ptr<PNS::ROUTING_SETTINGS> m_PnsSettings;
|
||||||
|
|
||||||
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
|
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
|
||||||
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins;
|
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins;
|
||||||
|
|
|
@ -89,7 +89,6 @@ TOOL_BASE::~TOOL_BASE()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void TOOL_BASE::Reset( RESET_REASON aReason )
|
void TOOL_BASE::Reset( RESET_REASON aReason )
|
||||||
{
|
{
|
||||||
delete m_gridHelper;
|
delete m_gridHelper;
|
||||||
|
@ -109,9 +108,12 @@ void TOOL_BASE::Reset( RESET_REASON aReason )
|
||||||
|
|
||||||
m_router->UpdateSizes( m_savedSizes );
|
m_router->UpdateSizes( m_savedSizes );
|
||||||
|
|
||||||
auto settings = new PNS::ROUTING_SETTINGS( frame()->GetSettings(), "tools.pns" );
|
PCBNEW_SETTINGS* settings = frame()->GetSettings();
|
||||||
frame()->GetSettings()->m_PnsSettings = settings;
|
|
||||||
m_router->LoadSettings( frame()->GetSettings()->m_PnsSettings );
|
if( !settings->m_PnsSettings )
|
||||||
|
settings->m_PnsSettings = std::make_unique<ROUTING_SETTINGS>( settings, "tools.pns" );
|
||||||
|
|
||||||
|
m_router->LoadSettings( settings->m_PnsSettings.get() );
|
||||||
|
|
||||||
m_gridHelper = new GRID_HELPER( frame() );
|
m_gridHelper = new GRID_HELPER( frame() );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue