KiCad PCB EDA Suite
dialog_freeroute_exchange.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
29 #include <fctsys.h>
30 #include <kiface_i.h>
31 #include <confirm.h>
32 #include <gestfich.h>
33 #include <pcbnew.h>
34 #include <wxPcbStruct.h>
35 #include <macros.h>
36 #include <class_board.h>
37 
38 #include <../common/dialogs/dialog_display_info_HTML_base.h>
39 
41 
42 #ifdef __WINDOWS__
43 #include <wx/msw/registry.h>
44 #endif
45 
46 
47 void PCB_EDIT_FRAME::Access_to_External_Tool( wxCommandEvent& event )
48 {
49  DIALOG_FREEROUTE dialog( this );
50  dialog.ShowModal();
51 }
52 
53 
54 
56  DIALOG_FREEROUTE_BASE( parent )
57 {
58  m_Parent = parent;
59  MyInit();
60 
61  m_sdbSizerOK->SetDefault();
62  GetSizer()->SetSizeHints( this );
63  Centre();
64 }
65 
66 
67 
68 // Specific data initialization
70 {
71  SetFocus();
72  m_freeRouterFound = false;
73 
74  wxFileName fileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
75 
76  if( fileName.FileExists() )
77  m_freeRouterFound = true;
78 
80 
81 }
82 
83 const char * s_FreeRouteHelpInfo =
85 ;
86 
87 void DIALOG_FREEROUTE::OnHelpButtonClick( wxCommandEvent& event )
88 {
89  DIALOG_DISPLAY_HTML_TEXT_BASE help_Dlg( this, wxID_ANY,
90  _("Freeroute Help"),wxDefaultPosition, wxSize( 650,550 ) );
91 
92  wxString msg = FROM_UTF8(s_FreeRouteHelpInfo);
93  help_Dlg.m_htmlWindow->AppendToPage( msg );
94  help_Dlg.ShowModal();
95 }
96 
97 
98 void DIALOG_FREEROUTE::OnExportButtonClick( wxCommandEvent& event )
99 {
100  m_Parent->ExportToSpecctra( event );
101 }
102 
103 
104 void DIALOG_FREEROUTE::OnImportButtonClick( wxCommandEvent& event )
105 {
107 }
108 
109 
110 // Run freeroute, if it is available (freeroute.jar found in kicad binaries)
111 void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event )
112 {
113  wxString dsnFile;
114 
115  if( m_freeRouterFound )
116  {
117  dsnFile = createDSN_File();
118 
119  if( dsnFile.IsEmpty() ) // Something is wrong or command cancelled
120  return;
121  }
122 
123  wxFileName jarfileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
124  wxString command;
125 
126  // Find the Java application on Windows.
127  // Colud be no more needed since we now have to run only java, not java web start
128 #ifdef __WINDOWS__
129 
130  // If you thought the registry was brain dead before, now you have to deal with
131  // accessing it in either 64 or 32 bit mode depending on the build version of
132  // Windows and the build version of KiCad.
133 
134  // This key works for 32 bit Java on 32 bit Windows and 64 bit Java on 64 bit Windows.
135  wxString keyName = wxT( "SOFTWARE\\JavaSoft\\Java Runtime Environment" );
136  wxRegKey key( wxRegKey::HKLM, keyName,
137  wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 :
138  wxRegKey::WOW64ViewMode_Default );
139 
140  // It's possible that 32 bit Java is installed on 64 bit Windows.
141  if( !key.Exists() && wxIsPlatform64Bit() )
142  {
143  keyName = wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment" );
144  key.SetName( wxRegKey::HKLM, keyName );
145  }
146 
147  if( !key.Exists() )
148  {
149  ::wxMessageBox( _( "It appears that the Java run time environment is not "
150  "installed on this computer. Java is required to use "
151  "FreeRoute." ),
152  _( "Pcbnew Error" ), wxOK | wxICON_ERROR );
153  return;
154  }
155 
156  key.Open( wxRegKey::Read );
157 
158  // Get the current version of java installed to determine the executable path.
159  wxString value;
160  key.QueryValue( wxT( "CurrentVersion" ), value );
161  key.SetName( key.GetName() + wxT( "\\" ) + value );
162 
163  key.QueryValue( wxT( "JavaHome" ), value );
164  command = value + wxFileName::GetPathSeparator();
165  command << wxT("bin\\java");
166 #else // __WINDOWS__
167  command = wxT( "java" );
168 #endif
169 
170  command << wxT(" -jar ");
171  // add "freeroute.jar" to command line:
172  command << wxChar( '"' ) << jarfileName.GetFullPath() << wxChar( '"' );
173  // add option to load the .dsn file
174  command << wxT( " -de " );
175  // add *.dsn full filename (quoted):
176  command << wxChar( '"' ) << dsnFile << wxChar( '"' );
177 
178  ProcessExecute( command );
179 }
180 
182 {
183  wxFileName fn( m_Parent->GetBoard()->GetFileName() );
184  wxString dsn_ext = wxT( "dsn" );
185  fn.SetExt( dsn_ext );
186  wxString mask = wxT( "*." ) + dsn_ext;
187 
188  wxString fullFileName = EDA_FILE_SELECTOR( _( "Specctra DSN file:" ),
189  fn.GetPath(), fn.GetFullName(),
190  dsn_ext, mask,
191  this, wxFD_SAVE, false );
192 
193  if( !fullFileName.IsEmpty() )
194  {
195  if( ! m_Parent->ExportSpecctraFile( fullFileName ) ) // the file was not created
196  return wxEmptyString;
197  }
198 
199  return fullFileName;
200 }
201 
202 
void ExportToSpecctra(wxCommandEvent &event)
Function ExporttoSPECCTRA Ask for a filename and call ExportSpecctraFile to export the current BOARD ...
Class DIALOG_FREEROUTE_BASE.
int ProcessExecute(const wxString &aCommandLine, int aFlags, wxProcess *callback)
Function ProcessExecute runs a child process.
Definition: common.cpp:160
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
This file is part of the common library TODO brief description.
This file is part of the common library.
void OnLaunchButtonClick(wxCommandEvent &event) override
Class BOARD to handle a board.
BOARD * GetBoard() const
DIALOG_FREEROUTE(PCB_EDIT_FRAME *parent)
This file contains miscellaneous commonly used macros and functions.
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
const wxString & GetFileName() const
Definition: class_board.h:237
const char * s_FreeRouteHelpInfo
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
void OnExportButtonClick(wxCommandEvent &event) override
wxString FindKicadFile(const wxString &shortname)
Function FindKicadFile searches the executable file shortname in KiCad binary path and return full fi...
Definition: gestfich.cpp:146
void OnImportButtonClick(wxCommandEvent &event) override
void ImportSpecctraSession(wxCommandEvent &event)
Function ImportSpecctraSession will import a specctra *.ses file and use it to relocate MODULEs and t...
void OnHelpButtonClick(wxCommandEvent &event) override
void Access_to_External_Tool(wxCommandEvent &event)
Function Access_to_External_Tool Run an external tool (like freeroute )
bool ExportSpecctraFile(const wxString &aFullFilename)
Function ExportSpecctraFile will export the current BOARD to a specctra dsn file. ...