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:
parent
36bcff34f7
commit
07f0662ba9
|
@ -356,16 +356,16 @@ void NETLIST_DIALOG::InstallCustomPages()
|
|||
if( cfg )
|
||||
{
|
||||
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++ )
|
||||
{
|
||||
// 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
|
||||
|
||||
wxString command = cfg->m_NetlistPanel.custom_command_paths[i];
|
||||
wxString command = cfg->m_NetlistPanel.plugins[i].command;
|
||||
|
||||
currPage = AddOneCustomPage( title, command,
|
||||
static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
|
||||
|
@ -557,10 +557,10 @@ void NETLIST_DIALOG::WriteCurrentNetlistSetup()
|
|||
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
wxASSERT( cfg );
|
||||
|
||||
if( cfg )
|
||||
{
|
||||
cfg->m_NetlistPanel.custom_command_titles.clear();
|
||||
cfg->m_NetlistPanel.custom_command_paths.clear();
|
||||
if( !cfg )
|
||||
return;
|
||||
|
||||
cfg->m_NetlistPanel.plugins.clear();
|
||||
|
||||
// Update existing custom pages
|
||||
for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
|
||||
|
@ -571,14 +571,13 @@ void NETLIST_DIALOG::WriteCurrentNetlistSetup()
|
|||
break;
|
||||
|
||||
wxString title = currPage->m_TitleStringCtrl->GetValue();
|
||||
wxString command = currPage->m_CommandStringCtrl->GetValue();
|
||||
|
||||
if( title.IsEmpty() )
|
||||
if( title.IsEmpty() || command.IsEmpty() )
|
||||
continue;
|
||||
|
||||
cfg->m_NetlistPanel.custom_command_titles.emplace_back( title );
|
||||
cfg->m_NetlistPanel.custom_command_paths.emplace_back(
|
||||
currPage->m_CommandStringCtrl->GetValue() );
|
||||
}
|
||||
cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
|
||||
cfg->m_NetlistPanel.plugins.back().command = command;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -219,6 +219,22 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
|
|||
},
|
||||
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_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, "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
|
||||
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_paths", js_cmd );
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
// 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,
|
||||
const char* aLine, const wxString& aSource ) :
|
||||
DIALOG_BOM_CFG_LEXER( aLine, aSource )
|
||||
|
|
|
@ -70,6 +70,20 @@ public:
|
|||
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
|
||||
{
|
||||
int default_bus_thickness;
|
||||
|
@ -161,8 +175,9 @@ public:
|
|||
|
||||
struct PANEL_NETLIST
|
||||
{
|
||||
std::vector<wxString> custom_command_titles;
|
||||
std::vector<wxString> custom_command_paths;
|
||||
// std::vector<wxString> custom_command_titles;
|
||||
// std::vector<wxString> custom_command_paths;
|
||||
std::vector<NETLIST_PLUGIN_SETTINGS> plugins;
|
||||
};
|
||||
|
||||
struct PANEL_PLOT
|
||||
|
@ -216,6 +231,9 @@ private:
|
|||
|
||||
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:
|
||||
APPEARANCE m_Appearance;
|
||||
|
||||
|
|
Loading…
Reference in New Issue