Fix some issues in eeschema, dialog BOM: now displays info and error messages when running the BOM script

This commit is contained in:
jean-pierre charras 2015-06-12 09:02:06 +02:00
parent f97191b050
commit e952302e43
4 changed files with 62 additions and 24 deletions

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras@wanadoo.fr
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras@wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -36,11 +36,13 @@
#include <schframe.h>
#include <netlist.h>
#include <netlist_exporter_generic.h>
#include <sch_sheet.h>
#include <invoke_sch_dialog.h>
#include <dialog_helpers.h>
#include <dialog_bom_base.h>
#include <html_messagebox.h>
#include <reporter.h>
#define BOM_PLUGINS_KEY wxT("bom_plugins")
#define BOM_PLUGIN_SELECTED_KEY wxT("bom_plugin_selected")
@ -363,7 +365,7 @@ void DIALOG_BOM::displayPluginInfo( FILE * aFile, const wxString& aFilename )
if( strend == wxNOT_FOUND)
return;
// Remove emty line if any
// Remove empty line if any
while( data[strstart] < ' ' )
strstart++;
@ -377,8 +379,6 @@ void DIALOG_BOM::displayPluginInfo( FILE * aFile, const wxString& aFilename )
void DIALOG_BOM::OnRunPlugin( wxCommandEvent& event )
{
wxFileName fn;
wxString fileWildcard;
wxString title = _( "Save Netlist File" );
// Calculate the xml netlist filename
fn = g_RootSheet->GetScreen()->GetFileName();
@ -389,8 +389,13 @@ void DIALOG_BOM::OnRunPlugin( wxCommandEvent& event )
wxString fullfilename = fn.GetFullPath();
m_parent->ClearMsgPanel();
wxString reportmsg;
WX_STRING_REPORTER reporter( &reportmsg );
reporter.SetReportAll( true );
m_parent->SetNetListerCommand( m_textCtrlCommand->GetValue() );
m_parent->CreateNetlist( -1, fullfilename, 0 );
m_parent->CreateNetlist( -1, fullfilename, 0, &reporter );
m_Messages->SetValue( reportmsg );
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
*
@ -33,6 +33,7 @@
#include <gestfich.h>
#include <pgm_base.h>
#include <schframe.h>
#include <reporter.h>
#include <netlist.h>
#include <netlist_exporter.h>
@ -44,7 +45,7 @@
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions )
unsigned aNetlistOptions, REPORTER* aReporter )
{
bool res = true;
bool executeCommandLine = false;
@ -84,16 +85,11 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
}
res = helper->WriteNetlist( fileName, aNetlistOptions );
delete helper;
if( executeCommandLine )
// If user provided a plugin command line, execute it.
if( executeCommandLine && res && !m_netListerCommand.IsEmpty() )
{
if( !res )
return res;
// If user provided no plugin command line, return now.
if( m_netListerCommand.IsEmpty() )
return res;
wxString prj_dir = Prj().GetProjectPath();
// build full command line from user's format string, e.g.:
@ -105,9 +101,40 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
prj_dir.SubString( 0, prj_dir.Len() - 2 ) // strip trailing '/'
);
ProcessExecute( commandLine, wxEXEC_SYNC );
if( aReporter )
{
wxArrayString output, errors;
int diag = wxExecute (commandLine, output, errors, wxEXEC_SYNC );
aReporter->Report( _("Run command:") );
*aReporter << wxT("\n") << commandLine << wxT("\n\n");
if( diag != 0 )
aReporter->Report( wxString::Format( _("Command error. Return code %d"), diag ) );
else
aReporter->Report( _("Success") );
*aReporter << wxT("\n");
if( output.GetCount() && aReporter->ReportWarnings() )
{
*aReporter << wxT("\n") << _("Info messages:") << wxT("\n");
for( unsigned ii = 0; ii < output.GetCount(); ii++ )
*aReporter << output[ii] << wxT("\n");
}
if( errors.GetCount() && aReporter->ReportErrors() )
{
*aReporter << wxT("\n") << _("Error messages:") << wxT("\n");
for( unsigned ii = 0; ii < errors.GetCount(); ii++ )
*aReporter << errors[ii] << wxT("\n");
}
}
else
ProcessExecute( commandLine, wxEXEC_SYNC );
}
delete helper;
return res;
}

View File

@ -1,9 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -111,7 +111,7 @@ void SCH_EDIT_FRAME::sendNetlist()
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions )
unsigned aNetlistOptions, REPORTER* aReporter )
{
if( !prepareForNetlist() )
return false;
@ -119,7 +119,7 @@ bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
std::auto_ptr<NETLIST_OBJECT_LIST> connectedItemsList( BuildNetListBase() );
bool success = WriteNetListFile( connectedItemsList.release(), aFormat,
aFullFileName, aNetlistOptions );
aFullFileName, aNetlistOptions, aReporter );
return success;
}

View File

@ -510,11 +510,14 @@ public:
* else use net numbers (net codes)
* if NET_USE_X_PREFIX is set : change "U" and "IC" refernce prefix to "X"
* </p>
* @param aReporter = a REPORTER to report error messages,
* mainly if a command line must be run (can be NULL
* @return true if success.
*/
bool CreateNetlist( int aFormat,
const wxString& aFullFileName,
unsigned aNetlistOptions );
unsigned aNetlistOptions,
REPORTER* aReporter = NULL );
/**
* Function WriteNetListFile
@ -530,12 +533,15 @@ public:
* else use net numbers (net codes)
* if NET_USE_X_PREFIX is set : change "U" and "IC" refernce prefix to "X"
* </p>
* @param aReporter = a REPORTER to report error messages,
* mainly if a command line must be run (can be NULL
* @return true if success.
*/
bool WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
int aFormat,
const wxString& aFullFileName,
unsigned aNetlistOptions );
unsigned aNetlistOptions,
REPORTER* aReporter = NULL );
/**
* Function DeleteAnnotation