dialog_freeroute_exchange.cpp 6.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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
 */
/**
Wayne Stambaugh's avatar
Wayne Stambaugh committed
24
 * @file dialog_freeroute_exchange.cpp
25 26 27
 * Dialog to access to FreeRoute, the web bases free router, export/import files
 * to/from FreeRoute
 */
28

29 30 31 32 33 34 35
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <confirm.h>
#include <gestfich.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <macros.h>
36

37
#include <../common/dialogs/dialog_display_info_HTML_base.h>
38

39
#include <dialog_freeroute_exchange.h>
40

41 42 43 44
#ifdef __WINDOWS__
#include <wx/msw/registry.h>
#endif

45 46 47 48 49

#define FREEROUTE_URL_KEY wxT( "freeroute_url" )
#define FREEROUTE_RUN_KEY wxT( "freeroute_command" )


50
void PCB_EDIT_FRAME::Access_to_External_Tool( wxCommandEvent& event )
51
{
charras's avatar
charras committed
52
    DIALOG_FREEROUTE dialog( this );
53 54 55 56 57
    dialog.ShowModal();
}



58
DIALOG_FREEROUTE::DIALOG_FREEROUTE( PCB_EDIT_FRAME* parent ):
charras's avatar
charras committed
59
    DIALOG_FREEROUTE_BASE( parent )
60
{
charras's avatar
charras committed
61 62
    m_Parent = parent;
    MyInit();
charras's avatar
charras committed
63

64
    m_sdbSizer1OK->SetDefault();
charras's avatar
charras committed
65
    GetSizer()->SetSizeHints( this );
66 67 68 69 70
    Centre();
}



71
/* Specific data initialization
72 73
 */

charras's avatar
charras committed
74
void DIALOG_FREEROUTE::MyInit()
75
{
charras's avatar
charras committed
76
    SetFocus();
77 78 79
    m_FreeRouteSetupChanged = false;

    wxString msg;
80 81
    wxGetApp().GetSettings()->Read( FREEROUTE_URL_KEY, &msg );

82 83 84 85 86 87
    if( msg.IsEmpty() )
        m_FreerouteURLName->SetValue( wxT( "http://www.freerouting.net/" ) );
    else
        m_FreerouteURLName->SetValue( msg );
}

charras's avatar
charras committed
88
const char * s_FreeRouteHelpInfo =
89
#include <dialog_freeroute_exchange_help_html.h>
charras's avatar
charras committed
90 91
;
void DIALOG_FREEROUTE::OnHelpButtonClick( wxCommandEvent& event )
92
{
charras's avatar
charras committed
93 94
    DIALOG_DISPLAY_HTML_TEXT_BASE help_Dlg( this, wxID_ANY,
        _("Freeroute Help"),wxDefaultPosition, wxSize( 650,550 ) );
95

96
    wxString msg = FROM_UTF8(s_FreeRouteHelpInfo);
charras's avatar
charras committed
97 98
    help_Dlg.m_htmlWindow->AppendToPage( msg );
    help_Dlg.ShowModal();
99 100
}

101
/*  wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CREATE_EXPORT_DSN_FILE
102
 */
charras's avatar
charras committed
103
void DIALOG_FREEROUTE::OnExportButtonClick( wxCommandEvent& event )
104 105 106 107 108
{
    m_Parent->ExportToSpecctra( event );
}


109
/*  wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_IMPORT_FREEROUTE_DSN_FILE
110
 */
charras's avatar
charras committed
111
void DIALOG_FREEROUTE::OnImportButtonClick( wxCommandEvent& event )
112 113
{
    m_Parent->ImportSpecctraSession(  event );
114 115 116 117 118 119

    /* Connectivity inf 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 );
120 121 122
}


123
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RUN_FREEROUTE
124
 */
charras's avatar
charras committed
125
void DIALOG_FREEROUTE::OnLaunchButtonClick( wxCommandEvent& event )
126
{
127
    wxString url;
128
    wxString command;
129
    wxFileName fileName( FindKicadFile( wxT( "freeroute.jnlp" ) ), wxPATH_UNIX );
130

131
    if( fileName.FileExists() )
132
    {
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
        wxString javaWebStartCommand = wxT( "javaws" );

        // Find the Java web start application on Windows.
#ifdef __WINDOWS__
        // 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.
        wxRegKey key( wxRegKey::HKLM, wxT( "SOFTWARE\\JavaSoft\\Java Web Start" ),
                      wxIsPlatform64Bit() ? wxRegKey::WOW64ViewMode_64 :
                      wxRegKey::WOW64ViewMode_Default );

        // It's possible that 32 bit Java is installed on 64 bit Windows.
        if( !key.Exists() && wxIsPlatform64Bit() )
            key.SetName( wxRegKey::HKLM, wxT( "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Web Start" ) );

        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( wxT( "Home" ), value );
        javaWebStartCommand = value + wxFileName::GetPathSeparator() + javaWebStartCommand;
#endif

169 170
        // Wrap FullFileName in double quotes in case it has C:\Program Files in it.
        // The space is interpreted as an argument separator.
171 172
        command << javaWebStartCommand << wxChar( ' ' ) << wxChar( '"' )
                << fileName.GetFullPath() << wxChar( '"' );
173
        ProcessExecute( command );
174 175
        return;
    }
176

177
    url = m_FreerouteURLName->GetValue() + wxT( "/java/freeroute.jnlp" );
dickelbeck's avatar
dickelbeck committed
178

179
    wxLaunchDefaultBrowser( url );
180 181 182
}


183
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
184
 */
charras's avatar
charras committed
185
void DIALOG_FREEROUTE::OnVisitButtonClick( wxCommandEvent& event )
186 187 188 189 190 191 192
{
    wxString command = m_FreerouteURLName->GetValue();

    wxLaunchDefaultBrowser( command );
}


193
/*  wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
194
 */
charras's avatar
charras committed
195
void DIALOG_FREEROUTE::OnCancelButtonClick( wxCommandEvent& event )
196
{
197
    EndModal(wxID_CANCEL);
198 199 200
}


charras's avatar
charras committed
201
void DIALOG_FREEROUTE::OnOKButtonClick( wxCommandEvent& event )
202 203 204
{
    if( m_FreeRouteSetupChanged )  // Save new config
    {
205 206
        wxGetApp().GetSettings()->Write( FREEROUTE_URL_KEY,
                                         m_FreerouteURLName->GetValue() );
207 208
    }

209
    EndModal(wxID_OK);
210 211 212
}


213
/* wxEVT_COMMAND_TEXT_UPDATED event handler for ID_TEXT_EDIT_FR_URL
214
 */
charras's avatar
charras committed
215
void DIALOG_FREEROUTE::OnTextEditFrUrlUpdated( wxCommandEvent& event )
216 217 218
{
    m_FreeRouteSetupChanged = true;
}