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 <pcb_edit_frame.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  init();
62 
63  m_sdbSizerCancel->SetDefault();
64 
65  // Rename "Cancel" button label to "Close", because:
66  // wxFormBuilder has no option to create/rename a Close button in the wxStdDialogButtonSizer
67  // and a Cancel button (id = wxID_CANCEL) is mandatory to allow dismiss dialog by ESC key
68  wxButton* button = dynamic_cast<wxButton*>( wxWindow::FindWindowById( wxID_CANCEL, this ) );
69 
70  if( button )
71  button->SetLabel( _( "Close" ) );
72 
73  GetSizer()->SetSizeHints( this );
74  Centre();
75 }
76 
77 
78 
79 // Specific data initialization
81 {
82  SetFocus();
83  m_freeRouterFound = false;
84 
85  wxFileName fileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
86 
87  if( fileName.FileExists() )
88  m_freeRouterFound = true;
89 
91 
92 }
93 
94 const char * s_FreeRouteHelpInfo =
95 #include <dialog_freeroute_exchange_help_html.h>
96 ;
97 
98 void DIALOG_FREEROUTE::OnHelpButtonClick( wxCommandEvent& event )
99 {
100  DIALOG_DISPLAY_HTML_TEXT_BASE help_Dlg( this, wxID_ANY,
101  _("Freeroute Help"),wxDefaultPosition, wxSize( 650,550 ) );
102 
103  wxString msg = FROM_UTF8(s_FreeRouteHelpInfo);
104  help_Dlg.m_htmlWindow->AppendToPage( msg );
105  help_Dlg.ShowModal();
106 }
107 
108 
109 void DIALOG_FREEROUTE::OnExportButtonClick( wxCommandEvent& event )
110 {
111  m_Parent->ExportToSpecctra( event );
112 }
113 
114 
115 void DIALOG_FREEROUTE::OnImportButtonClick( wxCommandEvent& event )
116 {
118 }
119 
120 
121 // Run freeroute, if it is available (freeroute.jar found in kicad binaries)
122 void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event )
123 {
124  wxString dsnFile;
125 
126  if( m_freeRouterFound )
127  {
128  dsnFile = createDSN_File();
129 
130  if( dsnFile.IsEmpty() ) // Something is wrong or command cancelled
131  return;
132  }
133 
134  wxFileName jarfileName( FindKicadFile( wxT( "freeroute.jar" ) ), wxPATH_UNIX );
135  wxString command;
136 
137  // Find the Java application on Windows.
138  // Colud be no more needed since we now have to run only java, not java web start
139 #ifdef __WINDOWS__
140 
141  // If you thought the registry was brain dead before, now you have to deal with
142  // accessing it in either 64 or 32 bit mode depending on the build version of
143  // Windows and the build version of KiCad.
144 
145  // This key works for 32 bit Java on 32 bit Windows and 64 bit Java on 64 bit Windows.
146  wxString keyName = wxT( "SOFTWARE\\JavaSoft\\Java Runtime Environment" );
147  wxRegKey key( wxRegKey::HKLM, keyName,
148  wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 :
149  wxRegKey::WOW64ViewMode_Default );
150 
151  // It's possible that 32 bit Java is installed on 64 bit Windows.
152  if( !key.Exists() && wxIsPlatform64Bit() )
153  {
154  keyName = wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment" );
155  key.SetName( wxRegKey::HKLM, keyName );
156  }
157 
158  if( !key.Exists() )
159  {
160  ::wxMessageBox( _( "It appears that the Java run time environment is not "
161  "installed on this computer. Java is required to use "
162  "FreeRoute." ),
163  _( "Pcbnew Error" ), wxOK | wxICON_ERROR );
164  return;
165  }
166 
167  key.Open( wxRegKey::Read );
168 
169  // Get the current version of java installed to determine the executable path.
170  wxString value;
171  key.QueryValue( wxT( "CurrentVersion" ), value );
172  key.SetName( key.GetName() + wxT( "\\" ) + value );
173 
174  key.QueryValue( wxT( "JavaHome" ), value );
175  command = value + wxFileName::GetPathSeparator();
176  command << wxT("bin\\java");
177 #else // __WINDOWS__
178  command = wxT( "java" );
179 #endif
180 
181  command << wxT(" -jar ");
182  // add "freeroute.jar" to command line:
183  command << wxChar( '"' ) << jarfileName.GetFullPath() << wxChar( '"' );
184  // add option to load the .dsn file
185  command << wxT( " -de " );
186  // add *.dsn full filename (quoted):
187  command << wxChar( '"' ) << dsnFile << wxChar( '"' );
188 
189  ProcessExecute( command );
190 }
191 
193 {
194  wxFileName fn( m_Parent->GetBoard()->GetFileName() );
195  wxString dsn_ext = SpecctraDsnFileExtension;
196  fn.SetExt( dsn_ext );
197  wxString mask = SpecctraDsnFileWildcard();
198 
199  wxString fullFileName = EDA_FILE_SELECTOR( _( "Specctra DSN File" ),
200  fn.GetPath(), fn.GetFullName(),
201  dsn_ext, mask,
202  this, wxFD_SAVE, false );
203 
204  if( !fullFileName.IsEmpty() )
205  {
206  if( ! m_Parent->ExportSpecctraFile( fullFileName ) ) // the file was not created
207  return wxEmptyString;
208  }
209 
210  return fullFileName;
211 }
212 
213 
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)
Run a command in a child process.
Definition: common.cpp:154
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
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void OnHelpButtonClick(wxCommandEvent &event) override
wxString SpecctraDsnFileWildcard()
bool ExportSpecctraFile(const wxString &aFullFilename)
Function ExportSpecctraFile will export the current BOARD to a specctra dsn file. ...