Fix some issues in dialog_netlist.cpp , round 2 (work in progress)

The netlist plugins added in dialog_netlist are now stored in eeschema config.
This commit is contained in:
jean-pierre charras 2021-09-05 16:13:52 +02:00
parent 36bcff34f7
commit 07f0662ba9
3 changed files with 105 additions and 23 deletions

View File

@ -356,16 +356,16 @@ void NETLIST_DIALOG::InstallCustomPages()
if( cfg ) if( cfg )
{ {
for( size_t i = 0; for( size_t i = 0;
i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.custom_command_titles.size(); i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.plugins.size();
i++ ) i++ )
{ {
// pairs of (title, command) are stored // pairs of (title, command) are stored
wxString title = cfg->m_NetlistPanel.custom_command_titles[i]; wxString title = cfg->m_NetlistPanel.plugins[i].name;
if( i >= cfg->m_NetlistPanel.custom_command_paths.size() ) if( i >= cfg->m_NetlistPanel.plugins.size() )
break; // No more panel to install break; // No more panel to install
wxString command = cfg->m_NetlistPanel.custom_command_paths[i]; wxString command = cfg->m_NetlistPanel.plugins[i].command;
currPage = AddOneCustomPage( title, command, currPage = AddOneCustomPage( title, command,
static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) ); static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
@ -557,28 +557,27 @@ void NETLIST_DIALOG::WriteCurrentNetlistSetup()
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ); EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxASSERT( cfg ); wxASSERT( cfg );
if( cfg ) if( !cfg )
return;
cfg->m_NetlistPanel.plugins.clear();
// Update existing custom pages
for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
{ {
cfg->m_NetlistPanel.custom_command_titles.clear(); NETLIST_PAGE_DIALOG* currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
cfg->m_NetlistPanel.custom_command_paths.clear();
// Update existing custom pages if( currPage == nullptr )
for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ ) break;
{
NETLIST_PAGE_DIALOG* currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
if( currPage == nullptr ) wxString title = currPage->m_TitleStringCtrl->GetValue();
break; wxString command = currPage->m_CommandStringCtrl->GetValue();
wxString title = currPage->m_TitleStringCtrl->GetValue(); if( title.IsEmpty() || command.IsEmpty() )
continue;
if( title.IsEmpty() ) cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
continue; cfg->m_NetlistPanel.plugins.back().command = command;
cfg->m_NetlistPanel.custom_command_titles.emplace_back( title );
cfg->m_NetlistPanel.custom_command_paths.emplace_back(
currPage->m_CommandStringCtrl->GetValue() );
}
} }
} }

View File

@ -219,6 +219,22 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
}, },
defaultBomPlugins ) ); defaultBomPlugins ) );
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "netlist.plugins",
std::bind( &EESCHEMA_SETTINGS::netlistSettingsToJson, this ),
[&]( const nlohmann::json& aObj )
{
if( !aObj.is_array() )
return;
if( aObj.empty() )
return;
const nlohmann::json& list = aObj;
m_NetlistPanel.plugins = netlistSettingsFromJson( list );
},
nullptr ) );
m_params.emplace_back( new PARAM<bool>( "page_settings.export_paper", m_params.emplace_back( new PARAM<bool>( "page_settings.export_paper",
&m_PageSettings.export_paper, false ) ); &m_PageSettings.export_paper, false ) );
@ -475,6 +491,7 @@ bool EESCHEMA_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment8", "page_settings.export_comment8" ); ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment8", "page_settings.export_comment8" );
ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment9", "page_settings.export_comment9" ); ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment9", "page_settings.export_comment9" );
#if 0 // To do: move this code to the new netlist plugin management in settings
{ {
constexpr int max_custom_commands = 8; // from DIALOG_NETLIST constexpr int max_custom_commands = 8; // from DIALOG_NETLIST
nlohmann::json js_cmd = nlohmann::json::array(); nlohmann::json js_cmd = nlohmann::json::array();
@ -498,6 +515,7 @@ bool EESCHEMA_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
Set( "netlist.custom_command_titles", js_title ); Set( "netlist.custom_command_titles", js_title );
Set( "netlist.custom_command_paths", js_cmd ); Set( "netlist.custom_command_paths", js_cmd );
} }
#endif
{ {
// NOTE(JE) These parameters should move to project-local storage before V6, but we are // NOTE(JE) These parameters should move to project-local storage before V6, but we are
@ -739,6 +757,53 @@ std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::bomSettin
} }
nlohmann::json EESCHEMA_SETTINGS::netlistSettingsToJson() const
{
nlohmann::json js = nlohmann::json::array();
for( const NETLIST_PLUGIN_SETTINGS& plugin : m_NetlistPanel.plugins )
{
nlohmann::json pluginJson;
pluginJson["name"] = plugin.name.ToUTF8();
pluginJson["path"] = plugin.path.ToUTF8();
pluginJson["command"] = plugin.command.ToUTF8();
js.push_back( pluginJson );
}
return js;
}
std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::netlistSettingsFromJson(
const nlohmann::json& aObj )
{
std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> ret;
wxASSERT( aObj.is_array() );
for( const nlohmann::json& entry : aObj )
{
if( entry.empty() || !entry.is_object() )
continue;
if( !entry.contains( "name" ) || !entry.contains( "path" ) )
continue;
NETLIST_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
entry.at( "path" ).get<wxString>() );
if( entry.contains( "command" ) )
plugin.command = entry.at( "command" ).get<wxString>();
ret.emplace_back( plugin );
}
return ret;
}
BOM_CFG_PARSER::BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList, BOM_CFG_PARSER::BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
const char* aLine, const wxString& aSource ) : const char* aLine, const wxString& aSource ) :
DIALOG_BOM_CFG_LEXER( aLine, aSource ) DIALOG_BOM_CFG_LEXER( aLine, aSource )

View File

@ -70,6 +70,20 @@ public:
wxString command; wxString command;
}; };
struct NETLIST_PLUGIN_SETTINGS
{
NETLIST_PLUGIN_SETTINGS() = default;
NETLIST_PLUGIN_SETTINGS( const wxString& aName, const wxString& aPath ) :
name( aName ),
path( aPath )
{}
wxString name;
wxString path;
wxString command;
};
struct DRAWING struct DRAWING
{ {
int default_bus_thickness; int default_bus_thickness;
@ -161,8 +175,9 @@ public:
struct PANEL_NETLIST struct PANEL_NETLIST
{ {
std::vector<wxString> custom_command_titles; // std::vector<wxString> custom_command_titles;
std::vector<wxString> custom_command_paths; // std::vector<wxString> custom_command_paths;
std::vector<NETLIST_PLUGIN_SETTINGS> plugins;
}; };
struct PANEL_PLOT struct PANEL_PLOT
@ -216,6 +231,9 @@ private:
static std::vector<BOM_PLUGIN_SETTINGS> bomSettingsFromJson( const nlohmann::json& aObj ); static std::vector<BOM_PLUGIN_SETTINGS> bomSettingsFromJson( const nlohmann::json& aObj );
nlohmann::json netlistSettingsToJson() const;
static std::vector<NETLIST_PLUGIN_SETTINGS> netlistSettingsFromJson( const nlohmann::json& aObj );
public: public:
APPEARANCE m_Appearance; APPEARANCE m_Appearance;