Eeschema: boom generator: ugly fix on Windows to allow xsltproc.exe working from the command line created from bom dialog.

(On windows, xsltproc.exe does not accept '\' in output filename, only '/' like on Unix, so this separator is converted when possible)
Minor code cleanup
This commit is contained in:
jean-pierre charras 2017-10-09 20:57:41 +02:00
parent 835c19f1e2
commit e626136e29
6 changed files with 54 additions and 41 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras@wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2017 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
@ -233,8 +233,8 @@ DIALOG_BOM::DIALOG_BOM( SCH_EDIT_FRAME* parent ) :
m_config = Kiface().KifaceSettings();
installPluginsList();
#ifdef __WINDOWS__
m_checkBoxShowConsole->Show( true );
#ifndef __WINDOWS__
m_checkBoxShowConsole->Show( false );
#endif
// Now all widgets have the size fixed, call FinishDialogSettings
@ -545,20 +545,20 @@ wxString DIALOG_BOM::choosePlugin()
wxFileName fn( fullFileName );
wxString ext = fn.GetExt();
if( ext == wxT("xsl" ) )
cmdLine.Printf(wxT("xsltproc -o \"%%O\" \"%s\" \"%%I\""), GetChars( fullFileName ) );
else if( ext == wxT("exe" ) || ext.IsEmpty() )
cmdLine.Printf(wxT("\"%s\" < \"%%I\" > \"%%O\""), GetChars( fullFileName ) );
if( ext == "xsl" )
cmdLine.Printf( "xsltproc -o \"%%O\" \"%s\" \"%%I\"", GetChars( fullFileName ) );
else if( ext == "exe" || ext.IsEmpty() )
cmdLine.Printf( "\"%s\" < \"%%I\" > \"%%O\"", GetChars( fullFileName ) );
else if( ext == wxT("py" ) || ext.IsEmpty() )
cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) );
else if( ext == wxT("pyw" ) || ext.IsEmpty() )
cmdLine.Printf( "python \"%s\" \"%%I\" \"%%O\"", GetChars( fullFileName ) );
else if( ext == "pyw" || ext.IsEmpty() )
#ifdef __WINDOWS__
cmdLine.Printf(wxT("pythonw \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) );
#else
cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) );
cmdLine.Printf( "python \"%s\" \"%%I\" \"%%O\"", GetChars( fullFileName ) );
#endif
else
cmdLine.Printf(wxT("\"%s\""), GetChars( fullFileName ) );
cmdLine.Printf( "\"%s\"", GetChars( fullFileName ) );
return cmdLine;
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 22 2016)
// C++ code generated with wxFormBuilder (version Jul 2 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -24,7 +24,7 @@ END_EVENT_TABLE()
DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
this->SetSizeHints( wxSize( 500,-1 ), wxDefaultSize );
wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxVERTICAL );
@ -96,20 +96,20 @@ DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxStrin
bbottomSizer->Add( m_textCtrlCommand, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_checkBoxShowConsole = new wxCheckBox( this, wxID_ANY, _("Show console window"), wxDefaultPosition, wxDefaultSize, 0 );
m_checkBoxShowConsole->Hide();
m_checkBoxShowConsole->SetToolTip( _("By default, command line runs with hidden console window and output is redirected to \"Plugin info\" field. Set this option to show the window of the running command.") );
m_checkBoxShowConsole->SetValue(true);
m_checkBoxShowConsole->SetToolTip( _("By default, command line runs with hidden console window and output is redirected to \"Plugin info\" field.\nSet this option to show the window of the running command.") );
bbottomSizer->Add( m_checkBoxShowConsole, 0, wxBOTTOM|wxLEFT, 5 );
bbottomSizer->Add( m_checkBoxShowConsole, 0, wxALL, 5 );
bMainSizer->Add( bbottomSizer, 0, wxEXPAND, 5 );
m_staticTextInfo = new wxStaticText( this, wxID_ANY, _("Plugin Info:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextInfo->Wrap( -1 );
bMainSizer->Add( m_staticTextInfo, 0, wxRIGHT|wxLEFT, 5 );
bMainSizer->Add( m_staticTextInfo, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_Messages = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
bMainSizer->Add( m_Messages, 1, wxALL|wxEXPAND, 5 );
bMainSizer->Add( m_Messages, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
this->SetSizer( bMainSizer );

View File

@ -41,10 +41,10 @@
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="minimum_size">500,-1</property>
<property name="name">DIALOG_BOM_BASE</property>
<property name="pos"></property>
<property name="size">409,393</property>
<property name="size">500,397</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Bill of Material</property>
@ -1265,7 +1265,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxLEFT</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
@ -1281,7 +1281,7 @@
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="checked">1</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
@ -1294,7 +1294,7 @@
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">1</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Show console window</property>
<property name="max_size"></property>
@ -1317,7 +1317,7 @@
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">By default, command line runs with hidden console window and output is redirected to &quot;Plugin info&quot; field. Set this option to show the window of the running command.</property>
<property name="tooltip">By default, command line runs with hidden console window and output is redirected to &quot;Plugin info&quot; field.&#x0A;Set this option to show the window of the running command.</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
@ -1355,7 +1355,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxRIGHT|wxLEFT</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
@ -1438,7 +1438,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 22 2016)
// C++ code generated with wxFormBuilder (version Jul 2 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -94,7 +94,7 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM
public:
DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Bill of Material"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 409,393 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Bill of Material"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,397 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_BOM_BASE();
};

View File

@ -48,7 +48,7 @@
wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
const wxString& aTempfile, const wxString& aFinalFile, const wxString& aProjectPath )
const wxString& aNetlistFile, const wxString& aFinalFile, const wxString& aProjectPath )
{
// Expand format symbols in the command line:
// %B => base filename of selected output file, minus path and extension.
@ -56,14 +56,27 @@ wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
// %I => full filename of the input file (the intermediate net file).
// %O => complete filename and path (but without extension) of the user chosen output file.
wxString ret = aFormatString;
wxFileName in = aTempfile;
wxFileName out = aFinalFile;
wxString ret = aFormatString;
wxFileName in = aNetlistFile;
wxFileName out = aFinalFile;
ret.Replace( wxT( "%P" ), aProjectPath.GetData(), true );
ret.Replace( wxT( "%B" ), out.GetName().GetData(), true );
ret.Replace( wxT( "%I" ), in.GetFullPath().GetData(), true );
ret.Replace( wxT( "%O" ), out.GetFullPath().GetData(), true );
ret.Replace( "%P", aProjectPath, true );
ret.Replace( "%B", out.GetName(), true );
ret.Replace( "%I", in.GetFullPath(), true );
#ifdef __WINDOWS__
// A ugly hack to run xsltproc that has a serious bug on Window since along time:
// the filename given after -o option (output filename) cannot use '\' in filename
// so replace if by '/' if possible (I mean if the filename does not start by "\\"
// that is a filename on a Windows server)
wxString str_out = out.GetFullPath();
if( !str_out.StartsWith( "\\\\" ) )
str_out.Replace( "\\", "/" );
#endif
ret.Replace( "%O", str_out, true );
return ret;
}
@ -84,7 +97,7 @@ void NETLIST_EXPORTER::sprintPinNetName( wxString& aResult,
{
if( aUseNetcodeAsNetName )
{
aResult.Printf( wxT("%d"), netcode );
aResult.Printf( "%d", netcode );
}
else
{

View File

@ -209,9 +209,9 @@ public:
* <li>formatting sequences, see below.
* </ul>
*
* @param aTempfile is the name of an input file to the
* external program.
* @param aFinalFile is the name of an output file that
* @param aNetlistFile is the name of the input file for the
* external program, that is a intermediate netlist file in xml format.
* @param aFinalFile is the name of the output file that
* the user expects.
* @param aProjectDirectory is used for %P replacement, it should omit
* the trailing '/'.
@ -228,7 +228,7 @@ public:
* </ul>
*/
static wxString MakeCommandLine( const wxString& aFormatString,
const wxString& aTempfile, const wxString& aFinalFile,
const wxString& aNetlistFile, const wxString& aFinalFile,
const wxString& aProjectDirectory
);
};