kicad/pcbnew/dialogs/dialog_freeroute_exchange.cpp

307 lines
9.3 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2012 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
* 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
*/
/**
2012-12-18 13:54:44 +00:00
* @file dialog_freeroute_exchange.cpp
* Dialog to access to FreeRoute, the web bases free router, export/import files
* to/from FreeRoute
*/
2008-03-14 18:17:51 +00:00
#include <fctsys.h>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
//#include <pgm_base.h>
#include <kiface_i.h>
#include <confirm.h>
#include <gestfich.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <macros.h>
#include <class_board.h>
#include <../common/dialogs/dialog_display_info_HTML_base.h>
2008-03-14 18:17:51 +00:00
#include <dialog_freeroute_exchange.h>
2008-03-14 18:17:51 +00:00
#ifdef __WINDOWS__
#include <wx/msw/registry.h>
#endif
2008-03-14 18:17:51 +00:00
#define FREEROUTE_URL_KEY wxT( "freeroute_url" )
#define FREEROUTE_RUN_KEY wxT( "freeroute_command" )
void PCB_EDIT_FRAME::Access_to_External_Tool( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
2009-11-21 15:39:50 +00:00
DIALOG_FREEROUTE dialog( this );
2008-03-14 18:17:51 +00:00
dialog.ShowModal();
}
DIALOG_FREEROUTE::DIALOG_FREEROUTE( PCB_EDIT_FRAME* parent ):
2009-11-21 15:39:50 +00:00
DIALOG_FREEROUTE_BASE( parent )
2008-03-14 18:17:51 +00:00
{
2009-11-21 15:39:50 +00:00
m_Parent = parent;
MyInit();
2009-11-23 17:24:33 +00:00
m_sdbSizer1OK->SetDefault();
2009-11-23 17:24:33 +00:00
GetSizer()->SetSizeHints( this );
2008-03-14 18:17:51 +00:00
Centre();
}
/* Specific data initialization
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::MyInit()
2008-03-14 18:17:51 +00:00
{
2009-11-21 15:39:50 +00:00
SetFocus();
2008-03-14 18:17:51 +00:00
m_FreeRouteSetupChanged = false;
m_freeRouterIsLocal = false;
2008-03-14 18:17:51 +00:00
wxString msg;
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
wxConfigBase* cfg = Kiface().KifaceSettings();
cfg->Read( FREEROUTE_URL_KEY, &msg );
2011-12-16 20:12:49 +00:00
2008-03-14 18:17:51 +00:00
if( msg.IsEmpty() )
m_FreerouteURLName->SetValue( wxT( "http://www.freerouting.net/" ) );
else
m_FreerouteURLName->SetValue( msg );
wxFileName fileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
if( fileName.FileExists() )
{
m_freeRouterIsLocal = true;
m_buttonLaunchFreeroute->SetLabel( _("Create .dsn File and Launch FreeRouter") );
}
2008-03-14 18:17:51 +00:00
}
2009-11-21 15:39:50 +00:00
const char * s_FreeRouteHelpInfo =
#include <dialog_freeroute_exchange_help_html.h>
2009-11-21 15:39:50 +00:00
;
void DIALOG_FREEROUTE::OnHelpButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
2009-11-21 15:39:50 +00:00
DIALOG_DISPLAY_HTML_TEXT_BASE help_Dlg( this, wxID_ANY,
_("Freeroute Help"),wxDefaultPosition, wxSize( 650,550 ) );
2008-03-14 18:17:51 +00:00
wxString msg = FROM_UTF8(s_FreeRouteHelpInfo);
2009-11-21 15:39:50 +00:00
help_Dlg.m_htmlWindow->AppendToPage( msg );
help_Dlg.ShowModal();
2008-03-14 18:17:51 +00:00
}
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CREATE_EXPORT_DSN_FILE
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnExportButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
m_Parent->ExportToSpecctra( event );
}
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_IMPORT_FREEROUTE_DSN_FILE
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnImportButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
m_Parent->ImportSpecctraSession( event );
/* Connectivity must be rebuild.
* because for large board it can take some time, this is made only on demand
*/
if( IsOK( this, _("Do you want to rebuild connectivity data ?" ) ) )
m_Parent->Compile_Ratsnest( NULL, true );
2008-03-14 18:17:51 +00:00
}
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RUN_FREEROUTE
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
wxString javaCommand;
wxString command;
if( m_freeRouterIsLocal )
{
javaCommand = CmdRunFreeRouterLocal();
if( javaCommand.IsEmpty() ) // Something is wrong
return;
}
else
javaCommand = wxT( "javaws" );
wxString url;
wxFileName fileName( FindKicadFile( wxT( "freeroute.jnlp" ) ), wxPATH_UNIX );
if( m_freeRouterIsLocal || fileName.FileExists() )
{
// Find the Java web start application on Windows.
#ifdef __WINDOWS__
#if wxCHECK_VERSION( 2, 9, 0 )
// If you thought the registry was brain dead before, now you have to deal with
// accessing it in either 64 or 32 bit mode depending on the build version of
// Windows and the build version of KiCad.
// This key works for 32 bit Java on 32 bit Windows and 64 bit Java on 64 bit Windows.
wxString keyName = m_freeRouterIsLocal ? wxT( "SOFTWARE\\JavaSoft\\Java Runtime Environment" )
: wxT( "SOFTWARE\\JavaSoft\\Java Web Start" );
wxRegKey key( wxRegKey::HKLM, keyName,
wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 :
wxRegKey::WOW64ViewMode_Default );
// It's possible that 32 bit Java is installed on 64 bit Windows.
if( !key.Exists() && wxIsPlatform64Bit() )
{
keyName = m_freeRouterIsLocal ?
wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment" )
: wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Web Start" );
key.SetName( wxRegKey::HKLM, keyName );
}
if( !key.Exists() )
{
::wxMessageBox( _( "It appears that the Java run time environment is not "
"installed on this computer. Java is required to use "
"FreeRoute." ),
_( "Pcbnew Error" ), wxOK | wxICON_ERROR );
return;
}
key.Open( wxRegKey::Read );
// Get the current version of java installed to determine the executable path.
wxString value;
key.QueryValue( wxT( "CurrentVersion" ), value );
key.SetName( key.GetName() + wxT( "\\" ) + value );
key.QueryValue( m_freeRouterIsLocal ? wxT( "JavaHome" ) : wxT( "Home" ), value );
wxString javaCommandPath = value + wxFileName::GetPathSeparator();
command = javaCommandPath;
#else
#warning Kicad needs wxWidgets >= 2.9.4. version 2.8 is only supported for testing purposes
#endif // wxCHECK_VERSION( 2, 9, 0 )
if( m_freeRouterIsLocal )
command << wxT("bin\\") << javaCommand;
#else // __WINDOWS__
if( m_freeRouterIsLocal )
command << javaCommand;
#endif
else
// Wrap FullFileName in double quotes in case it has C:\Program Files in it.
// The space is interpreted as an argument separator.
command << javaCommand << wxChar( ' ' ) << wxChar( '"' )
<< fileName.GetFullPath() << wxChar( '"' );
2008-04-24 16:55:35 +00:00
ProcessExecute( command );
return;
}
2008-03-14 18:17:51 +00:00
url = m_FreerouteURLName->GetValue() + wxT( "/java/freeroute.jnlp" );
2008-03-18 21:18:04 +00:00
wxLaunchDefaultBrowser( url );
2008-03-14 18:17:51 +00:00
}
wxString DIALOG_FREEROUTE::CmdRunFreeRouterLocal()
{
wxString fullFileName = m_Parent->GetBoard()->GetFileName();
wxString path;
wxString name;
wxString ext;
wxString dsn_ext = wxT( ".dsn" );
wxString mask = wxT( "*" ) + dsn_ext;
wxFileName::SplitPath( fullFileName, &path, &name, &ext );
name += dsn_ext;
fullFileName = EDA_FileSelector( _( "Specctra DSN file:" ),
path,
name, // name.ext without path!
dsn_ext,
mask,
this,
wxFD_SAVE,
false
);
if( fullFileName == wxEmptyString )
return fullFileName;
if( ! m_Parent->ExportSpecctraFile( fullFileName ) ) // the file was not created
return fullFileName;
wxFileName jarfileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
wxString command = wxT("java -jar ");
// add "freeroute.jar" to command line:
command << wxChar( '"' ) << jarfileName.GetFullPath() << wxChar( '"' );
// add option to load the .dsn file
command << wxT( " -de " );
// add *.dsn full filename (quoted):
command << wxChar( '"' ) << fullFileName << wxChar( '"' );
return command;
}
2008-03-14 18:17:51 +00:00
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnVisitButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
wxString command = m_FreerouteURLName->GetValue();
wxLaunchDefaultBrowser( command );
}
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnCancelButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
EndModal(wxID_CANCEL);
2008-03-14 18:17:51 +00:00
}
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnOKButtonClick( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
if( m_FreeRouteSetupChanged ) // Save new config
{
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
Kiface().KifaceSettings()->Write(
FREEROUTE_URL_KEY, m_FreerouteURLName->GetValue() );
2008-03-14 18:17:51 +00:00
}
EndModal(wxID_OK);
2008-03-14 18:17:51 +00:00
}
/* wxEVT_COMMAND_TEXT_UPDATED event handler for ID_TEXT_EDIT_FR_URL
2008-03-14 18:17:51 +00:00
*/
2009-11-21 15:39:50 +00:00
void DIALOG_FREEROUTE::OnTextEditFrUrlUpdated( wxCommandEvent& event )
2008-03-14 18:17:51 +00:00
{
m_FreeRouteSetupChanged = true;
}