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. * 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) 2015 Jean-Pierre Charras, jp.charras@wanadoo.fr
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -36,11 +36,13 @@
#include <schframe.h> #include <schframe.h>
#include <netlist.h> #include <netlist.h>
#include <netlist_exporter_generic.h>
#include <sch_sheet.h> #include <sch_sheet.h>
#include <invoke_sch_dialog.h> #include <invoke_sch_dialog.h>
#include <dialog_helpers.h> #include <dialog_helpers.h>
#include <dialog_bom_base.h> #include <dialog_bom_base.h>
#include <html_messagebox.h> #include <html_messagebox.h>
#include <reporter.h>
#define BOM_PLUGINS_KEY wxT("bom_plugins") #define BOM_PLUGINS_KEY wxT("bom_plugins")
#define BOM_PLUGIN_SELECTED_KEY wxT("bom_plugin_selected") #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) if( strend == wxNOT_FOUND)
return; return;
// Remove emty line if any // Remove empty line if any
while( data[strstart] < ' ' ) while( data[strstart] < ' ' )
strstart++; strstart++;
@ -377,8 +379,6 @@ void DIALOG_BOM::displayPluginInfo( FILE * aFile, const wxString& aFilename )
void DIALOG_BOM::OnRunPlugin( wxCommandEvent& event ) void DIALOG_BOM::OnRunPlugin( wxCommandEvent& event )
{ {
wxFileName fn; wxFileName fn;
wxString fileWildcard;
wxString title = _( "Save Netlist File" );
// Calculate the xml netlist filename // Calculate the xml netlist filename
fn = g_RootSheet->GetScreen()->GetFileName(); fn = g_RootSheet->GetScreen()->GetFileName();
@ -389,8 +389,13 @@ void DIALOG_BOM::OnRunPlugin( wxCommandEvent& event )
wxString fullfilename = fn.GetFullPath(); wxString fullfilename = fn.GetFullPath();
m_parent->ClearMsgPanel(); m_parent->ClearMsgPanel();
wxString reportmsg;
WX_STRING_REPORTER reporter( &reportmsg );
reporter.SetReportAll( true );
m_parent->SetNetListerCommand( m_textCtrlCommand->GetValue() ); 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. * 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) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
* *
@ -33,6 +33,7 @@
#include <gestfich.h> #include <gestfich.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <schframe.h> #include <schframe.h>
#include <reporter.h>
#include <netlist.h> #include <netlist.h>
#include <netlist_exporter.h> #include <netlist_exporter.h>
@ -44,7 +45,7 @@
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
int aFormat, const wxString& aFullFileName, int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions ) unsigned aNetlistOptions, REPORTER* aReporter )
{ {
bool res = true; bool res = true;
bool executeCommandLine = false; bool executeCommandLine = false;
@ -84,16 +85,11 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
} }
res = helper->WriteNetlist( fileName, aNetlistOptions ); 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(); wxString prj_dir = Prj().GetProjectPath();
// build full command line from user's format string, e.g.: // 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 '/' 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; return res;
} }

View File

@ -1,9 +1,9 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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, bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions ) unsigned aNetlistOptions, REPORTER* aReporter )
{ {
if( !prepareForNetlist() ) if( !prepareForNetlist() )
return false; return false;
@ -119,7 +119,7 @@ bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
std::auto_ptr<NETLIST_OBJECT_LIST> connectedItemsList( BuildNetListBase() ); std::auto_ptr<NETLIST_OBJECT_LIST> connectedItemsList( BuildNetListBase() );
bool success = WriteNetListFile( connectedItemsList.release(), aFormat, bool success = WriteNetListFile( connectedItemsList.release(), aFormat,
aFullFileName, aNetlistOptions ); aFullFileName, aNetlistOptions, aReporter );
return success; return success;
} }

View File

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