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>
34 
35 #include <pcbnew.h>
36 #include <wxPcbStruct.h>
37 #include <macros.h>
38 #include <class_board.h>
39 
40 #include <../common/dialogs/dialog_display_info_HTML_base.h>
41 
43 
44 #ifdef __WINDOWS__
45 #include <wx/msw/registry.h>
46 #endif
47 
48 
49 void PCB_EDIT_FRAME::Access_to_External_Tool( wxCommandEvent& event )
50 {
51  DIALOG_FREEROUTE dialog( this );
52  dialog.ShowModal();
53 }
54 
55 
56 
58  DIALOG_FREEROUTE_BASE( parent )
59 {
60  m_Parent = parent;
61  MyInit();
62 
63  m_sdbSizerOK->SetDefault();
64  GetSizer()->SetSizeHints( this );
65  Centre();
66 }
67 
68 
69 
70 // Specific data initialization
72 {
73  SetFocus();
74  m_freeRouterFound = false;
75 
76  wxFileName fileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
77 
78  if( fileName.FileExists() )
79  m_freeRouterFound = true;
80 
82 
83 }
84 
85 const char * s_FreeRouteHelpInfo =
87 ;
88 
89 void DIALOG_FREEROUTE::OnHelpButtonClick( wxCommandEvent& event )
90 {
91  DIALOG_DISPLAY_HTML_TEXT_BASE help_Dlg( this, wxID_ANY,
92  _("Freeroute Help"),wxDefaultPosition, wxSize( 650,550 ) );
93 
94  wxString msg = FROM_UTF8(s_FreeRouteHelpInfo);
95  help_Dlg.m_htmlWindow->AppendToPage( msg );
96  help_Dlg.ShowModal();
97 }
98 
99 
100 void DIALOG_FREEROUTE::OnExportButtonClick( wxCommandEvent& event )
101 {
102  m_Parent->ExportToSpecctra( event );
103 }
104 
105 
106 void DIALOG_FREEROUTE::OnImportButtonClick( wxCommandEvent& event )
107 {
109 }
110 
111 
112 // Run freeroute, if it is available (freeroute.jar found in kicad binaries)
113 void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event )
114 {
115  wxString dsnFile;
116 
117  if( m_freeRouterFound )
118  {
119  dsnFile = createDSN_File();
120 
121  if( dsnFile.IsEmpty() ) // Something is wrong or command cancelled
122  return;
123  }
124 
125  wxFileName jarfileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
126  wxString command;
127 
128  // Find the Java application on Windows.
129  // Colud be no more needed since we now have to run only java, not java web start
130 #ifdef __WINDOWS__
131 
132  // If you thought the registry was brain dead before, now you have to deal with
133  // accessing it in either 64 or 32 bit mode depending on the build version of
134  // Windows and the build version of KiCad.
135 
136  // This key works for 32 bit Java on 32 bit Windows and 64 bit Java on 64 bit Windows.
137  wxString keyName = wxT( "SOFTWARE\\JavaSoft\\Java Runtime Environment" );
138  wxRegKey key( wxRegKey::HKLM, keyName,
139  wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 :
140  wxRegKey::WOW64ViewMode_Default );
141 
142  // It's possible that 32 bit Java is installed on 64 bit Windows.
143  if( !key.Exists() && wxIsPlatform64Bit() )
144  {
145  keyName = wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment" );
146  key.SetName( wxRegKey::HKLM, keyName );
147  }
148 
149  if( !key.Exists() )
150  {
151  ::wxMessageBox( _( "It appears that the Java run time environment is not "
152  "installed on this computer. Java is required to use "
153  "FreeRoute." ),
154  _( "Pcbnew Error" ), wxOK | wxICON_ERROR );
155  return;
156  }
157 
158  key.Open( wxRegKey::Read );
159 
160  // Get the current version of java installed to determine the executable path.
161  wxString value;
162  key.QueryValue( wxT( "CurrentVersion" ), value );
163  key.SetName( key.GetName() + wxT( "\\" ) + value );
164 
165  key.QueryValue( wxT( "JavaHome" ), value );
166  command = value + wxFileName::GetPathSeparator();
167  command << wxT("bin\\java");
168 #else // __WINDOWS__
169  command = wxT( "java" );
170 #endif
171 
172  command << wxT(" -jar ");
173  // add "freeroute.jar" to command line:
174  command << wxChar( '"' ) << jarfileName.GetFullPath() << wxChar( '"' );
175  // add option to load the .dsn file
176  command << wxT( " -de " );
177  // add *.dsn full filename (quoted):
178  command << wxChar( '"' ) << dsnFile << wxChar( '"' );
179 
180  ProcessExecute( command );
181 }
182 
184 {
185  wxFileName fn( m_Parent->GetBoard()->GetFileName() );
186  wxString dsn_ext = SpecctraDsnFileExtension;
187  fn.SetExt( dsn_ext );
188  wxString mask = SpecctraDsnFileWildcard();
189 
190  wxString fullFileName = EDA_FILE_SELECTOR( _( "Specctra DSN File" ),
191  fn.GetPath(), fn.GetFullName(),
192  dsn_ext, mask,
193  this, wxFD_SAVE, false );
194 
195  if( !fullFileName.IsEmpty() )
196  {
197  if( ! m_Parent->ExportSpecctraFile( fullFileName ) ) // the file was not created
198  return wxEmptyString;
199  }
200 
201  return fullFileName;
202 }
203 
204 
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:234
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
The common library.
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...
const wxString SpecctraDsnFileExtension
void OnHelpButtonClick(wxCommandEvent &event) override
wxString SpecctraDsnFileWildcard()
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. ...