From 295b5b5deae0ee06e98d560b5000c1b366c8bacc Mon Sep 17 00:00:00 2001 From: Jacobo Aragunde Perez Date: Fri, 18 Jan 2013 11:42:23 +0100 Subject: [PATCH] Add patch from Jacobo Aragunde Perez --- common/common.cpp | 10 ++---- common/gestfich.cpp | 17 ++++++---- include/common.h | 8 +++-- include/gestfich.h | 3 +- kicad/class_treeproject_item.cpp | 13 ++++--- kicad/kicad.h | 56 ++++++++++++++++++++++++++++-- kicad/mainframe.cpp | 58 ++++++++++++++++++++++++++------ 7 files changed, 128 insertions(+), 37 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 2b4183744c..c8ac359ce3 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -313,15 +313,9 @@ wxString GenDate() } -bool ProcessExecute( const wxString& aCommandLine, int aFlags ) +int ProcessExecute( const wxString& aCommandLine, int aFlags, wxProcess *callback ) { -#ifdef __WINDOWS__ - int pid = wxExecute( aCommandLine ); - return pid ? true : false; -#else - wxProcess* process = wxProcess::Open( aCommandLine, aFlags ); - return (process != NULL) ? true : false; -#endif + return wxExecute( aCommandLine, aFlags, callback ); } diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 3b0ceb13cc..0fb679615b 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -415,7 +415,8 @@ wxString FindKicadFile( const wxString& shortname ) } -int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param ) +int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param, + wxProcess *callback ) { wxString FullFileName; @@ -425,19 +426,21 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para #ifdef __WXMAC__ if( wxFileExists( FullFileName ) || wxDir::Exists( FullFileName ) ) { - ProcessExecute( wxGetApp().GetExecutablePath() + wxT("/") + ExecFile + wxT(" ") + param ); - } else { - ProcessExecute( wxT("/usr/bin/open ") + param ); + return ProcessExecute( wxGetApp().GetExecutablePath() + wxT( "/" ) + + ExecFile + wxT( " " ) + + param, wxEXEC_ASYNC, callback ); + } + else + { + return ProcessExecute( wxT( "/usr/bin/open " ) + param, wxEXEC_ASYNC, callback ); } - return 0; #else if( wxFileExists( FullFileName ) ) { if( !param.IsEmpty() ) FullFileName += wxT( " " ) + param; - ProcessExecute( FullFileName ); - return 0; + return ProcessExecute( FullFileName, wxEXEC_ASYNC, callback ); } #endif wxString msg; diff --git a/include/common.h b/include/common.h index af30065d12..fa44caa440 100644 --- a/include/common.h +++ b/include/common.h @@ -555,9 +555,13 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL ); * @param aCommandLine The process and any arguments to it all in a single * string. * @param aFlags The same args as allowed for wxExecute() - * @return bool - true if success, else false + * @param callback wxProcess implementing OnTerminate to be run when the + child process finishes + * @return int - pid of process, 0 in case of error (like return values of + * wxExecute()) */ -bool ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC ); +int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC, + wxProcess *callback = NULL ); /*******************/ diff --git a/include/gestfich.h b/include/gestfich.h index db81f8a5e6..4d6403e29d 100644 --- a/include/gestfich.h +++ b/include/gestfich.h @@ -10,6 +10,7 @@ #define __INCLUDE__GESTFICH_H__ 1 #include +#include /* Forward class declarations. */ @@ -79,7 +80,7 @@ EDA_LIST_DIALOG* GetFileNames( char* Directory, char* Mask ); * calls the executable file \a ExecFile with the command line parameters \a param. */ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, - const wxString& param = wxEmptyString ); + const wxString& param = wxEmptyString, wxProcess *callback = NULL ); /** * Function AddDelimiterString diff --git a/kicad/class_treeproject_item.cpp b/kicad/class_treeproject_item.cpp index e4a62caa5f..1c2102f21f 100644 --- a/kicad/class_treeproject_item.cpp +++ b/kicad/class_treeproject_item.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -188,6 +189,7 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) wxString sep = wxFileName().GetPathSeparator(); wxString FullFileName = GetFileName(); wxTreeItemId id = GetId(); + KICAD_MANAGER_FRAME* mainFrame = (KICAD_MANAGER_FRAME*) wxGetApp().GetTopWindow(); AddDelimiterString( FullFileName ); @@ -201,16 +203,16 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) break; case TREE_SCHEMA: - ExecuteFile( m_parent, EESCHEMA_EXE, FullFileName ); + mainFrame->Execute( m_parent, EESCHEMA_EXE, FullFileName ); break; case TREE_LEGACY_PCB: case TREE_SEXP_PCB: - ExecuteFile( m_parent, PCBNEW_EXE, FullFileName ); + mainFrame->Execute( m_parent, PCBNEW_EXE, FullFileName ); break; case TREE_GERBER: - ExecuteFile( m_parent, GERBVIEW_EXE, FullFileName ); + mainFrame->Execute( m_parent, GERBVIEW_EXE, FullFileName ); break; case TREE_PDF: @@ -218,7 +220,7 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) break; case TREE_NET: - ExecuteFile( m_parent, CVPCB_EXE, FullFileName ); + mainFrame->Execute( m_parent, CVPCB_EXE, FullFileName ); break; case TREE_TXT: @@ -226,7 +228,7 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) wxString editorname = wxGetApp().GetEditorName(); if( !editorname.IsEmpty() ) - ExecuteFile( m_parent, editorname, FullFileName ); + mainFrame->Execute( m_parent, editorname, FullFileName ); break; } @@ -235,4 +237,5 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) OpenFile( FullFileName ); break; } + } diff --git a/kicad/kicad.h b/kicad/kicad.h index 1d8cab43bc..a6cdb3578d 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -1,6 +1,31 @@ -/***********/ -/* kicad.h */ -/***********/ +/** + * @file kicad/kicad.h + * @brief KICAD_MANAGER_FRAME is the KiCad main frame. + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN (www.cern.ch) + * Copyright (C) 2013 KiCad Developers, see CHANGELOG.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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #ifndef KICAD_H #define KICAD_H @@ -10,6 +35,7 @@ #include #include #include +#include #include #include @@ -182,6 +208,30 @@ public: KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title, */ void SaveSettings(); + /** + * Function Execute + * opens another KiCad application and logs a message. + * @param frame = owner frame. + * @param execFile = name of the executable file. + * @param param = parameters to be passed to the executable. + */ + void Execute( wxWindow* frame, const wxString& execFile, + const wxString& param = wxEmptyString ); + + class PROCESS_TERMINATE_EVENT_HANDLER : public wxProcess + { + private: + wxString appName; + + public: + PROCESS_TERMINATE_EVENT_HANDLER( const wxString& appName ) : + appName(appName) + { + } + + void OnTerminate( int pid, int status ); + }; + #ifdef KICAD_USE_FILES_WATCHER /** * Called by sending a event with id = ID_INIT_WATCHED_PATHS diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index bbf53744d2..a4934e7dc9 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -7,6 +7,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2013 CERN (www.cern.ch) * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -186,15 +187,51 @@ void KICAD_MANAGER_FRAME::OnExit( wxCommandEvent& event ) } +void KICAD_MANAGER_FRAME::PROCESS_TERMINATE_EVENT_HANDLER:: + OnTerminate( int pid, int status ) +{ + + wxString msg; + + msg.Printf( appName + _( " closed [pid=%d]\n" ), pid ); + ( (KICAD_MANAGER_FRAME*) wxGetApp().GetTopWindow() )->PrintMsg( msg ); + + delete this; +} + + +void KICAD_MANAGER_FRAME::Execute( wxWindow* frame, const wxString& execFile, + const wxString& param ) +{ + + PROCESS_TERMINATE_EVENT_HANDLER* callback; + long pid; + wxString msg; + + callback = new PROCESS_TERMINATE_EVENT_HANDLER( execFile ); + pid = ExecuteFile( frame, execFile, param, callback ); + + if( pid > 0 ) + { + msg.Printf( execFile + _( " opened [pid=%ld]\n" ), pid ); + PrintMsg( msg ); + } + else + { + delete callback; + } +} + + void KICAD_MANAGER_FRAME::OnRunBitmapConverter( wxCommandEvent& event ) { - ExecuteFile( this, BITMAPCONVERTER_EXE, wxEmptyString ); + Execute( this, BITMAPCONVERTER_EXE ); } void KICAD_MANAGER_FRAME::OnRunPcbCalculator( wxCommandEvent& event ) { - ExecuteFile( this, PCB_CALCULATOR_EXE, wxEmptyString ); + Execute( this, PCB_CALCULATOR_EXE ); } @@ -207,9 +244,9 @@ void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event ) kicad_board.SetExt( KiCadPcbFileExtension ); if( !legacy_board.FileExists() || kicad_board.FileExists() ) - ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( kicad_board ) ); + Execute( this, PCBNEW_EXE, QuoteFullPath( kicad_board ) ); else - ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( legacy_board ) ); + Execute( this, PCBNEW_EXE, QuoteFullPath( legacy_board ) ); } @@ -218,18 +255,17 @@ void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) wxFileName fn( m_ProjectFileName ); fn.SetExt( NetlistFileExtension ); - ExecuteFile( this, CVPCB_EXE, QuoteFullPath( fn ) ); + Execute( this, CVPCB_EXE, QuoteFullPath( fn ) ); } - void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event ) { wxFileName fn( m_ProjectFileName ); fn.SetExt( SchematicFileExtension ); - ExecuteFile( this, EESCHEMA_EXE, QuoteFullPath( fn ) ); -} + Execute( this, EESCHEMA_EXE, QuoteFullPath( fn ) ); +} void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event ) { @@ -237,7 +273,7 @@ void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event ) wxString path = wxT( "\"" ); path += fn.GetPath( wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME ) + wxT( "\"" ); - ExecuteFile( this, GERBVIEW_EXE, path ); + Execute( this, GERBVIEW_EXE, path ); } @@ -246,7 +282,7 @@ void KICAD_MANAGER_FRAME::OnOpenTextEditor( wxCommandEvent& event ) wxString editorname = wxGetApp().GetEditorName(); if( !editorname.IsEmpty() ) - ExecuteFile( this, editorname, wxEmptyString ); + Execute( this, editorname, wxEmptyString ); } @@ -271,7 +307,7 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event ) filename += dlg.GetPath() + wxT( "\"" ); if( !dlg.GetPath().IsEmpty() && !wxGetApp().GetEditorName().IsEmpty() ) - ExecuteFile( this, wxGetApp().GetEditorName(), filename ); + Execute( this, wxGetApp().GetEditorName(), filename ); }