2011-12-16 20:12:49 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-12-29 20:11:42 +00:00
|
|
|
* @file edaappl.cpp
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2011-12-16 20:12:49 +00:00
|
|
|
* @brief For the main application: init functions, and language selection
|
|
|
|
* (locale handling)
|
|
|
|
*/
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <wx/html/htmlwin.h>
|
|
|
|
#include <wx/fs_zip.h>
|
2009-01-17 20:31:19 +00:00
|
|
|
#include <wx/dir.h>
|
2009-01-07 15:59:49 +00:00
|
|
|
#include <wx/filename.h>
|
2009-01-17 20:31:19 +00:00
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
#include <wx/apptrait.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
#include <wx/snglinst.h>
|
2009-04-18 14:14:40 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <param_config.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <build_version.h>
|
|
|
|
#include <hotkeys_basic.h>
|
|
|
|
#include <online_help.h>
|
|
|
|
#include <gestfich.h>
|
2012-04-09 09:16:47 +00:00
|
|
|
#include <menus_helpers.h>
|
2013-11-15 14:36:11 +00:00
|
|
|
#include <fp_lib_table.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
static const wxChar* CommonConfigPath = wxT( "kicad_common" );
|
|
|
|
|
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
// some key strings used to store parameters in config
|
2013-12-31 06:25:53 +00:00
|
|
|
static const wxChar backgroundColorKey[] = wxT( "BackgroundColor" );
|
|
|
|
static const wxChar showPageLimitsKey[] = wxT( "ShowPageLimits" );
|
|
|
|
static const wxChar workingDirKey[] = wxT( "WorkingDir" );
|
|
|
|
static const wxChar languageCfgKey[] = wxT( "LanguageID" );
|
|
|
|
static const wxChar kicadFpLibPath[] = wxT( "KicadFootprintLibraryPath" );
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
2013-12-31 06:25:53 +00:00
|
|
|
* A small class to handle the list of existing translations.
|
|
|
|
* The locale translation is automatic.
|
|
|
|
* The selection of languages is mainly for maintainer's convenience
|
2009-04-05 20:49:15 +00:00
|
|
|
* To add a support to a new translation:
|
|
|
|
* create a new icon (flag of the country) (see Lang_Fr.xpm as an example)
|
2013-12-31 06:25:53 +00:00
|
|
|
* add a new item to s_Languages[].
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
struct LANGUAGE_DESCR
|
2008-04-18 13:28:56 +00:00
|
|
|
{
|
2011-08-29 21:42:11 +00:00
|
|
|
/// wxWidgets locale identifier (See wxWidgets doc)
|
2013-12-31 06:25:53 +00:00
|
|
|
int m_WX_Lang_Identifier;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-08-29 21:42:11 +00:00
|
|
|
/// KiCad identifier used in menu selection (See id.h)
|
2013-12-31 06:25:53 +00:00
|
|
|
int m_KI_Lang_Identifier;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-08-29 21:42:11 +00:00
|
|
|
/// The menu language icons
|
2013-12-31 06:25:53 +00:00
|
|
|
BITMAP_DEF m_Lang_Icon;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-08-29 21:42:11 +00:00
|
|
|
/// Labels used in menus
|
2014-01-18 09:07:05 +00:00
|
|
|
wxString m_Lang_Label;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-08-29 21:42:11 +00:00
|
|
|
/// Set to true if the m_Lang_Label must not be translated
|
2013-12-31 06:25:53 +00:00
|
|
|
bool m_DoNotTranslate;
|
2008-04-18 13:28:56 +00:00
|
|
|
};
|
|
|
|
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
2013-12-31 06:25:53 +00:00
|
|
|
* Variable s_Languages
|
2011-04-01 17:10:16 +00:00
|
|
|
* Note: because this list is not created on the fly, wxTranslation
|
|
|
|
* must be called when a language name must be displayed after translation.
|
2013-12-31 06:25:53 +00:00
|
|
|
* Do not change this behavior, because m_Lang_Label is also used as key in config
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2013-12-31 06:25:53 +00:00
|
|
|
static LANGUAGE_DESCR s_Languages[] =
|
2008-04-18 13:28:56 +00:00
|
|
|
{
|
2012-11-09 06:58:00 +00:00
|
|
|
// Default language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_DEFAULT,
|
|
|
|
ID_LANGUAGE_DEFAULT,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_def_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Default" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// English language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_ENGLISH,
|
|
|
|
ID_LANGUAGE_ENGLISH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_en_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
wxT( "English" ),
|
|
|
|
true
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// French language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_FRENCH,
|
|
|
|
ID_LANGUAGE_FRENCH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_fr_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "French" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Finnish language
|
2010-02-07 16:32:51 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_FINNISH,
|
|
|
|
ID_LANGUAGE_FINNISH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_fi_xpm,
|
2010-02-07 16:32:51 +00:00
|
|
|
_( "Finnish" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Spanish language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_SPANISH,
|
|
|
|
ID_LANGUAGE_SPANISH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_es_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Spanish" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Portuguese language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_PORTUGUESE,
|
|
|
|
ID_LANGUAGE_PORTUGUESE,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_pt_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Portuguese" )
|
2008-04-18 13:28:56 +00:00
|
|
|
},
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Italian language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_ITALIAN,
|
|
|
|
ID_LANGUAGE_ITALIAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_it_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Italian" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// German language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_GERMAN,
|
|
|
|
ID_LANGUAGE_GERMAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_de_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "German" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Greek language
|
2011-02-05 16:15:48 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_GREEK,
|
|
|
|
ID_LANGUAGE_GREEK,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_gr_xpm,
|
2011-02-05 16:15:48 +00:00
|
|
|
_( "Greek" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Slovenian language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_SLOVENIAN,
|
|
|
|
ID_LANGUAGE_SLOVENIAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_sl_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Slovenian" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Hungarian language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_HUNGARIAN,
|
|
|
|
ID_LANGUAGE_HUNGARIAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_hu_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Hungarian" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Polish language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_POLISH,
|
|
|
|
ID_LANGUAGE_POLISH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_pl_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Polish" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Czech language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_CZECH,
|
|
|
|
ID_LANGUAGE_CZECH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_cs_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Czech" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Russian language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_RUSSIAN,
|
|
|
|
ID_LANGUAGE_RUSSIAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_ru_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Russian" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Korean language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_KOREAN,
|
|
|
|
ID_LANGUAGE_KOREAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_ko_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Korean" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Chinese simplified
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_CHINESE_SIMPLIFIED,
|
|
|
|
ID_LANGUAGE_CHINESE_SIMPLIFIED,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_chinese_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Chinese simplified" )
|
|
|
|
},
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Catalan language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_CATALAN,
|
|
|
|
ID_LANGUAGE_CATALAN,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_catalan_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Catalan" )
|
|
|
|
},
|
|
|
|
|
2011-01-16 17:11:26 +00:00
|
|
|
// Dutch language
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_DUTCH,
|
|
|
|
ID_LANGUAGE_DUTCH,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_nl_xpm,
|
2009-01-07 15:59:49 +00:00
|
|
|
_( "Dutch" )
|
2011-01-16 17:11:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Japanese language
|
|
|
|
{
|
|
|
|
wxLANGUAGE_JAPANESE,
|
|
|
|
ID_LANGUAGE_JAPANESE,
|
2011-08-29 21:42:11 +00:00
|
|
|
lang_jp_xpm,
|
2011-01-16 17:11:26 +00:00
|
|
|
_( "Japanese" )
|
2011-11-30 11:45:49 +00:00
|
|
|
},
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2011-11-30 11:45:49 +00:00
|
|
|
// Bulgarian language
|
|
|
|
{
|
|
|
|
wxLANGUAGE_BULGARIAN,
|
|
|
|
ID_LANGUAGE_BULGARIAN,
|
|
|
|
lang_bg_xpm,
|
|
|
|
_( "Bulgarian" )
|
|
|
|
}
|
2008-12-29 11:26:15 +00:00
|
|
|
};
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
EDA_APP::EDA_APP()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-16 20:12:49 +00:00
|
|
|
m_Checker = NULL;
|
2013-01-04 12:06:50 +00:00
|
|
|
m_oneInstancePerFileChecker = NULL;
|
2011-12-16 20:12:49 +00:00
|
|
|
m_HtmlCtrl = NULL;
|
|
|
|
m_settings = NULL;
|
2014-01-20 09:33:17 +00:00
|
|
|
setLanguageId( wxLANGUAGE_DEFAULT );
|
2009-01-29 14:26:20 +00:00
|
|
|
m_Locale = NULL;
|
2011-12-16 20:12:49 +00:00
|
|
|
m_projectSettings = NULL;
|
|
|
|
m_commonSettings = NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
EDA_APP::~EDA_APP()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
SaveSettings();
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// delete user datas
|
2013-12-31 06:25:53 +00:00
|
|
|
delete m_projectSettings;
|
|
|
|
delete m_commonSettings;
|
2011-12-16 20:12:49 +00:00
|
|
|
delete m_settings;
|
2013-12-31 06:25:53 +00:00
|
|
|
delete m_Checker;
|
|
|
|
delete m_oneInstancePerFileChecker;
|
2009-01-07 15:59:49 +00:00
|
|
|
delete m_Locale;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::InitEDA_Appl( const wxString& aName, EDA_APP_T aId )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-12 14:39:54 +00:00
|
|
|
m_Id = aId;
|
2011-08-29 19:50:05 +00:00
|
|
|
m_Checker = new wxSingleInstanceChecker( aName.Lower() + wxT( "-" ) + wxGetUserId() );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Init KiCad environment
|
|
|
|
// the environment variable KICAD (if exists) gives the kicad path:
|
|
|
|
// something like set KICAD=d:\kicad
|
2011-12-16 20:12:49 +00:00
|
|
|
bool isDefined = wxGetEnv( wxT( "KICAD" ), &m_KicadEnv );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
if( isDefined ) // ensure m_KicadEnv ends by "/"
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
m_KicadEnv.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !m_KicadEnv.IsEmpty() && m_KicadEnv.Last() != '/' )
|
2009-01-07 15:59:49 +00:00
|
|
|
m_KicadEnv += UNIX_STRING_DIR_SEP;
|
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Prepare On Line Help. Use only lower case for help file names, in order to
|
|
|
|
// avoid problems with upper/lower case file names under windows and unix.
|
2008-06-11 10:33:13 +00:00
|
|
|
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
|
2009-04-12 14:39:54 +00:00
|
|
|
m_HelpFileName = aName.Lower() + wxT( ".html" );
|
2008-06-11 10:33:13 +00:00
|
|
|
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
|
2009-04-12 14:39:54 +00:00
|
|
|
m_HelpFileName = aName.Lower() + wxT( ".pdf" );
|
2008-06-11 10:33:13 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
#error Help files format not defined
|
2008-06-11 10:33:13 +00:00
|
|
|
#endif
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Init parameters for configuration
|
2011-09-30 18:15:37 +00:00
|
|
|
SetVendorName( wxT( "KiCad" ) );
|
2012-05-10 06:25:27 +00:00
|
|
|
SetAppName( aName.Lower() );
|
2009-04-12 14:39:54 +00:00
|
|
|
SetTitle( aName );
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
m_settings = new wxConfig();
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
wxASSERT( m_settings != NULL );
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
m_commonSettings = new wxConfig( CommonConfigPath );
|
|
|
|
wxASSERT( m_commonSettings != NULL );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Install some image handlers, mainly for help
|
2009-01-07 15:59:49 +00:00
|
|
|
wxImage::AddHandler( new wxPNGHandler );
|
|
|
|
wxImage::AddHandler( new wxGIFHandler );
|
|
|
|
wxImage::AddHandler( new wxJPEGHandler );
|
|
|
|
wxFileSystem::AddHandler( new wxZipFSHandler );
|
|
|
|
|
2013-09-06 12:17:33 +00:00
|
|
|
// Analyze the command line & init binary path
|
2009-01-07 15:59:49 +00:00
|
|
|
SetBinDir();
|
2009-01-17 20:31:19 +00:00
|
|
|
SetDefaultSearchPaths();
|
2009-01-29 14:26:20 +00:00
|
|
|
SetLanguagePath();
|
2009-01-07 15:59:49 +00:00
|
|
|
ReadPdfBrowserInfos();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Internationalization: loading the kicad suitable Dictionary
|
2011-04-01 17:10:16 +00:00
|
|
|
wxString languageSel;
|
2011-12-16 20:12:49 +00:00
|
|
|
m_commonSettings->Read( languageCfgKey, &languageSel);
|
2014-01-20 09:33:17 +00:00
|
|
|
|
|
|
|
setLanguageId( wxLANGUAGE_DEFAULT );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
// Search for the current selection
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
|
2011-04-01 17:10:16 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
if( s_Languages[ii].m_Lang_Label == languageSel )
|
2011-04-01 17:10:16 +00:00
|
|
|
{
|
2014-01-20 09:33:17 +00:00
|
|
|
setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
|
2011-04-01 17:10:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
bool succes = SetLanguage( true );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
if( !succes )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Set locale option for separator used in float numbers
|
2009-01-07 15:59:49 +00:00
|
|
|
SetLocaleTo_Default();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
void EDA_APP::SetHtmlHelpController( wxHtmlHelpController* aController )
|
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
delete m_HtmlCtrl;
|
2011-12-16 20:12:49 +00:00
|
|
|
|
|
|
|
m_HtmlCtrl = aController;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::InitOnLineHelp()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
wxString fullfilename = FindKicadHelpPath();
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2008-06-11 10:33:13 +00:00
|
|
|
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
|
2009-01-07 15:59:49 +00:00
|
|
|
m_HelpFileName = fullfilename + wxT( ".html" );
|
|
|
|
fullfilename += wxT( "kicad.hhp" );
|
|
|
|
|
|
|
|
if( wxFileExists( fullfilename ) )
|
|
|
|
{
|
|
|
|
m_HtmlCtrl = new wxHtmlHelpController( wxHF_TOOLBAR | wxHF_CONTENTS |
|
|
|
|
wxHF_PRINT | wxHF_OPEN_FILES
|
|
|
|
/*| wxHF_SEARCH */ );
|
2011-12-16 20:12:49 +00:00
|
|
|
m_HtmlCtrl->UseConfig( m_commonSettings );
|
2011-09-30 18:15:37 +00:00
|
|
|
m_HtmlCtrl->SetTitleFormat( wxT( "KiCad Help" ) );
|
2009-01-07 15:59:49 +00:00
|
|
|
m_HtmlCtrl->AddBook( fullfilename );
|
|
|
|
}
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2008-06-11 10:33:13 +00:00
|
|
|
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
|
2009-01-07 15:59:49 +00:00
|
|
|
m_HtmlCtrl = NULL;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2008-06-11 10:33:13 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
#error Help files format not defined
|
2008-06-11 10:33:13 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
bool EDA_APP::SetBinDir()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-11-09 06:58:00 +00:00
|
|
|
// Apple MacOSx
|
2007-10-28 17:45:36 +00:00
|
|
|
#ifdef __APPLE__
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Derive path from location of the app bundle
|
2009-01-07 15:59:49 +00:00
|
|
|
CFBundleRef mainBundle = CFBundleGetMainBundle();
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
if( mainBundle == NULL )
|
|
|
|
return false;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
CFURLRef urlref = CFBundleCopyBundleURL( mainBundle );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
if( urlref == NULL )
|
|
|
|
return false;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
CFStringRef str = CFURLCopyFileSystemPath( urlref, kCFURLPOSIXPathStyle );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
if( str == NULL )
|
|
|
|
return false;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
char* native_str = NULL;
|
|
|
|
int len = CFStringGetMaximumSizeForEncoding( CFStringGetLength( str ),
|
|
|
|
kCFStringEncodingUTF8 ) + 1;
|
|
|
|
native_str = new char[len];
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
CFStringGetCString( str, native_str, len, kCFStringEncodingUTF8 );
|
2011-02-28 18:36:19 +00:00
|
|
|
m_BinDir = FROM_UTF8( native_str );
|
2009-01-07 15:59:49 +00:00
|
|
|
delete[] native_str;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2013-07-09 05:20:07 +00:00
|
|
|
#elif defined(__UNIX__) // Linux and non-Apple Unix
|
|
|
|
m_BinDir = wxStandardPaths::Get().GetExecutablePath();
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
m_BinDir = argv[0];
|
2013-07-09 05:20:07 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-07-09 05:20:07 +00:00
|
|
|
// Use unix notation for paths. I am not sure this is a good idea,
|
2013-12-31 06:25:53 +00:00
|
|
|
// but it simplifies compatibility between Windows and Unices.
|
|
|
|
// However it is a potential problem in path handling under Windows.
|
2009-02-09 20:17:06 +00:00
|
|
|
m_BinDir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
// Remove file name form command line:
|
2009-02-10 13:46:10 +00:00
|
|
|
while( m_BinDir.Last() != '/' && !m_BinDir.IsEmpty() )
|
2009-02-10 12:37:12 +00:00
|
|
|
m_BinDir.RemoveLast();
|
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
void EDA_APP::SetDefaultSearchPaths()
|
2009-01-17 20:31:19 +00:00
|
|
|
{
|
2009-02-09 20:17:06 +00:00
|
|
|
wxString path = m_BinDir;
|
2009-04-15 19:53:41 +00:00
|
|
|
wxPathList tmp;
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
m_searchPaths.Clear();
|
|
|
|
|
2009-02-09 20:17:06 +00:00
|
|
|
#ifdef __WINDOWS__
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* m_BinDir path is in unix notation.
|
2009-02-09 20:17:06 +00:00
|
|
|
* But wxFileName expect (to work fine) native notation
|
2009-04-05 20:49:15 +00:00
|
|
|
* specifically when using a path including a server, like
|
|
|
|
* \\myserver\local_path .
|
|
|
|
*/
|
2009-02-09 20:17:06 +00:00
|
|
|
path.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
wxFileName fn( path, wxEmptyString );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* User environment variable path is the first search path. Chances are
|
2009-01-29 14:26:20 +00:00
|
|
|
* if the user is savvy enough to set an environment variable they know
|
|
|
|
* what they are doing. */
|
|
|
|
if( ::wxGetEnv( wxT( "KICAD" ), NULL ) )
|
2013-09-06 12:17:33 +00:00
|
|
|
tmp.AddEnvList( wxT( "KICAD" ) );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add the user's home path.
|
2013-09-06 12:17:33 +00:00
|
|
|
tmp.Add( GetTraits()->GetStandardPaths().GetUserDataDir() );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Standard application data path if it is different from the binary path.
|
2009-01-17 20:31:19 +00:00
|
|
|
if( fn.GetPath() != GetTraits()->GetStandardPaths().GetDataDir() )
|
2009-02-09 20:17:06 +00:00
|
|
|
{
|
2013-09-06 12:17:33 +00:00
|
|
|
tmp.Add( GetTraits()->GetStandardPaths().GetDataDir() );
|
2009-02-09 20:17:06 +00:00
|
|
|
}
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Up one level relative to binary path with "share" appended for Windows.
|
2009-01-17 20:31:19 +00:00
|
|
|
fn.RemoveLastDir();
|
2013-09-06 12:17:33 +00:00
|
|
|
tmp.Add( fn.GetPath() );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
/* The normal OS program file install paths allow for binary to be
|
2012-11-09 06:58:00 +00:00
|
|
|
* installed in a different path from the library files. This is
|
|
|
|
* useful for development purposes so the library and documentation
|
|
|
|
* files do not need to be installed separately. If someone can
|
|
|
|
* figure out a way to implement this without #ifdef, please do.
|
|
|
|
*/
|
2009-04-15 19:53:41 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
tmp.AddEnvList( wxT( "PROGRAMFILES" ) );
|
2010-01-16 11:16:09 +00:00
|
|
|
#elif __WXMAC__
|
2013-09-06 12:17:33 +00:00
|
|
|
tmp.Add( wxString( wxGetenv( wxT( "HOME" ) ) ) + wxT( "/Library/Application Support" ) );
|
2013-12-31 14:28:34 +00:00
|
|
|
tmp.Add( wxT( "/Library/Application Support" ) );
|
2009-04-15 19:53:41 +00:00
|
|
|
#else
|
|
|
|
tmp.AddEnvList( wxT( "PATH" ) );
|
|
|
|
#endif
|
|
|
|
|
2013-09-06 12:17:33 +00:00
|
|
|
// This is the equivalent of CMAKE_INSTALL_PREFIX. Useful when installed by `make install`.
|
|
|
|
tmp.Add( wxT( DEFAULT_INSTALL_PATH ) );
|
|
|
|
|
|
|
|
// Add kicad, kicad/share, share, and share/kicad to each possible base path.
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned i = 0; i < tmp.GetCount(); i++ )
|
2009-04-15 19:53:41 +00:00
|
|
|
{
|
|
|
|
fn = wxFileName( tmp[i], wxEmptyString );
|
|
|
|
|
|
|
|
if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) )
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "share" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.AppendDir( wxT( "share" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Remove all non-existent paths from the list.
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned i = 0; i < m_searchPaths.GetCount(); i++ )
|
2009-01-17 20:31:19 +00:00
|
|
|
{
|
|
|
|
if( !wxFileName::IsDirReadable( m_searchPaths[i] ) )
|
|
|
|
{
|
|
|
|
m_searchPaths.RemoveAt( i );
|
|
|
|
i -= 1;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fn.Clear();
|
|
|
|
fn.SetPath( m_searchPaths[i] );
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
/* Add schematic library file path to search path list.
|
2009-04-18 14:14:40 +00:00
|
|
|
* we must add <kicad path>/library and <kicad path>/library/doc
|
|
|
|
*/
|
2011-09-06 14:09:40 +00:00
|
|
|
if( m_Id == APP_EESCHEMA_T )
|
2009-04-06 18:54:57 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.AppendDir( wxT( "library" ) );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
2009-04-12 14:39:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add schematic doc file path (library/doc)to search path list.
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.AppendDir( wxT( "doc" ) );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir(); // point to <kicad path>
|
2009-04-07 15:54:40 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add PCB library file path to search path list.
|
2013-12-31 06:25:53 +00:00
|
|
|
if( m_Id == APP_PCBNEW_T || m_Id == APP_CVPCB_T )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-04-12 14:39:54 +00:00
|
|
|
fn.AppendDir( wxT( "modules" ) );
|
|
|
|
|
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
2009-04-12 14:39:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add 3D module library file path to search path list.
|
2009-04-12 14:39:54 +00:00
|
|
|
fn.AppendDir( wxT( "packages3d" ) );
|
|
|
|
|
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-19 15:03:48 +00:00
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir(); // point to <kicad path>
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add KiCad template file path to search path list.
|
2009-04-19 15:03:48 +00:00
|
|
|
fn.AppendDir( wxT( "template" ) );
|
|
|
|
|
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
2009-04-19 15:03:48 +00:00
|
|
|
}
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-19 15:03:48 +00:00
|
|
|
fn.RemoveLastDir();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-01-17 20:31:19 +00:00
|
|
|
}
|
2013-09-06 12:17:33 +00:00
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
#if 0 && defined( DEBUG )
|
2013-09-06 12:17:33 +00:00
|
|
|
wxLogDebug( wxT( "Library search paths:" ) );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_libSearchPaths.GetCount(); i++ )
|
|
|
|
wxLogDebug( wxT( " %s" ), GetChars( m_libSearchPaths[i] ) );
|
|
|
|
#endif
|
2009-01-17 20:31:19 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::GetSettings( bool aReopenLastUsedDirectory )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-16 20:12:49 +00:00
|
|
|
wxASSERT( m_settings != NULL && m_commonSettings != NULL );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
m_HelpSize.x = 500;
|
|
|
|
m_HelpSize.y = 400;
|
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
wxString languageSel;
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
m_commonSettings->Read( languageCfgKey, &languageSel );
|
2014-01-20 09:33:17 +00:00
|
|
|
setLanguageId( wxLANGUAGE_DEFAULT );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
// Search for the current selection
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
|
2011-04-01 17:10:16 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
if( s_Languages[ii].m_Lang_Label == languageSel )
|
2011-04-01 17:10:16 +00:00
|
|
|
{
|
2014-01-20 09:33:17 +00:00
|
|
|
setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
|
2011-04-01 17:10:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
m_EditorName = m_commonSettings->Read( wxT( "Editor" ) );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
m_fileHistory.Load( *m_settings );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
m_settings->Read( showPageLimitsKey, &g_ShowPageLimits );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-07-03 07:32:48 +00:00
|
|
|
if( aReopenLastUsedDirectory )
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
wxString dir;
|
|
|
|
|
|
|
|
if( m_settings->Read( workingDirKey, &dir ) && wxDirExists( dir ) )
|
2009-07-03 07:32:48 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
wxSetWorkingDirectory( dir );
|
2009-07-03 07:32:48 +00:00
|
|
|
}
|
2009-01-07 15:59:49 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-10-13 18:23:03 +00:00
|
|
|
// FIXME OSX Mountain Lion (10.8)
|
2013-09-06 12:17:33 +00:00
|
|
|
// Seems that Read doesn't found anything and ColorFromInt Asserts - I'm unable to reproduce
|
|
|
|
// on 10.7
|
|
|
|
// In general terms I think is better have a failsafe default than an uninit variable
|
2013-05-07 18:32:06 +00:00
|
|
|
int draw_bg_color = (int)BLACK; // Default for all apps but Eeschema
|
2013-09-06 12:17:33 +00:00
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
if( m_Id == APP_EESCHEMA_T )
|
|
|
|
draw_bg_color = (int)WHITE; // Default for Eeschema
|
2013-09-06 12:17:33 +00:00
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
m_settings->Read( backgroundColorKey, &draw_bg_color );
|
2012-09-02 12:06:47 +00:00
|
|
|
g_DrawBgColor = ColorFromInt( draw_bg_color );
|
2010-10-30 02:30:21 +00:00
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
// Load per-user search paths from settings file
|
2010-11-12 16:36:43 +00:00
|
|
|
|
2010-10-30 02:30:21 +00:00
|
|
|
wxString upath;
|
|
|
|
int i = 1;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
while( 1 )
|
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
upath = m_commonSettings->Read(
|
|
|
|
wxString::Format( wxT( "LibraryPath%d" ), i ), wxT( "" ) );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
|
|
|
if( upath.IsSameAs( wxT( "" ) ) )
|
|
|
|
break;
|
|
|
|
|
2010-10-30 02:30:21 +00:00
|
|
|
m_libSearchPaths.Add( upath );
|
2013-12-31 06:25:53 +00:00
|
|
|
i++;
|
2010-10-30 02:30:21 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::SaveSettings()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-16 20:12:49 +00:00
|
|
|
wxASSERT( m_settings != NULL );
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
m_settings->Write( showPageLimitsKey, g_ShowPageLimits );
|
|
|
|
m_settings->Write( workingDirKey, wxGetCwd() );
|
|
|
|
m_settings->Write( backgroundColorKey, (long) g_DrawBgColor );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Save the file history list
|
2011-12-16 20:12:49 +00:00
|
|
|
m_fileHistory.Save( *m_settings );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
bool EDA_APP::SetLanguage( bool first_time )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
bool retv = true;
|
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
// dictionary file name without extend (full name is kicad.mo)
|
|
|
|
wxString DictionaryName( wxT( "kicad" ) );
|
|
|
|
|
2014-01-20 09:33:17 +00:00
|
|
|
delete m_Locale;
|
2009-01-29 14:26:20 +00:00
|
|
|
m_Locale = new wxLocale;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-01-02 18:56:44 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
|
|
|
if( !m_Locale->Init( m_LanguageId ) )
|
|
|
|
#else
|
2011-01-01 17:28:21 +00:00
|
|
|
if( !m_Locale->Init( m_LanguageId, wxLOCALE_CONV_ENCODING ) )
|
2011-01-02 18:56:44 +00:00
|
|
|
#endif
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
2011-08-29 19:50:05 +00:00
|
|
|
wxLogDebug( wxT( "This language is not supported by the system." ) );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2014-01-20 09:33:17 +00:00
|
|
|
setLanguageId( wxLANGUAGE_DEFAULT );
|
2009-01-29 14:26:20 +00:00
|
|
|
delete m_Locale;
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
m_Locale = new wxLocale;
|
2009-01-07 15:59:49 +00:00
|
|
|
m_Locale->Init();
|
|
|
|
retv = false;
|
|
|
|
}
|
2011-02-05 18:00:05 +00:00
|
|
|
else if( !first_time )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Search for dictionary %s.mo in %s" ),
|
2011-08-29 19:50:05 +00:00
|
|
|
GetChars( DictionaryName ), GetChars( m_Locale->GetName() ) );
|
2011-02-05 18:00:05 +00:00
|
|
|
}
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !first_time )
|
|
|
|
{
|
2011-04-01 17:10:16 +00:00
|
|
|
wxString languageSel;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
// Search for the current selection
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
|
2011-04-01 17:10:16 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
if( s_Languages[ii].m_WX_Lang_Identifier == m_LanguageId )
|
2011-04-01 17:10:16 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
languageSel = s_Languages[ii].m_Lang_Label;
|
2011-04-01 17:10:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
m_commonSettings->Write( languageCfgKey, languageSel );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2011-02-24 12:35:14 +00:00
|
|
|
// Test if floating point notation is working (bug in cross compilation, using wine)
|
2010-01-29 20:36:12 +00:00
|
|
|
// Make a conversion double <=> string
|
|
|
|
double dtst = 0.5;
|
|
|
|
wxString msg;
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2010-01-29 20:36:12 +00:00
|
|
|
extern bool g_DisableFloatingPointLocalNotation; // See common.cpp
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2010-01-29 20:36:12 +00:00
|
|
|
g_DisableFloatingPointLocalNotation = false;
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2010-01-29 20:36:12 +00:00
|
|
|
msg << dtst;
|
|
|
|
double result;
|
2013-12-31 06:25:53 +00:00
|
|
|
msg.ToDouble( &result );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2010-01-29 20:36:12 +00:00
|
|
|
if( result != dtst ) // string to double encode/decode does not work! Bug detected
|
|
|
|
{
|
2011-08-29 19:50:05 +00:00
|
|
|
// Disable floating point localization:
|
2010-01-29 20:36:12 +00:00
|
|
|
g_DisableFloatingPointLocalNotation = true;
|
|
|
|
SetLocaleTo_C_standard( );
|
|
|
|
}
|
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
if( !m_Locale->IsLoaded( DictionaryName ) )
|
|
|
|
m_Locale->AddCatalog( DictionaryName );
|
|
|
|
|
|
|
|
if( !retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
return m_Locale->IsOk();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::SetLanguageIdentifier( int menu_id )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-11-09 06:58:00 +00:00
|
|
|
wxLogDebug( wxT( "Select language ID %d from %zd possible languages." ),
|
2013-12-31 06:25:53 +00:00
|
|
|
menu_id, DIM( s_Languages ) );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
if( menu_id == s_Languages[ii].m_KI_Lang_Identifier )
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
2014-01-20 09:33:17 +00:00
|
|
|
setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
void EDA_APP::SetLanguagePath()
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add defined search paths to locale paths
|
2009-01-29 14:26:20 +00:00
|
|
|
if( !m_searchPaths.IsEmpty() )
|
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned i = 0; i < m_searchPaths.GetCount(); i++ )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
wxFileName fn( m_searchPaths[i], wxEmptyString );
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Append path for Windows and unix KiCad pack install
|
2009-01-29 14:26:20 +00:00
|
|
|
fn.AppendDir( wxT( "share" ) );
|
2009-02-07 20:11:09 +00:00
|
|
|
fn.AppendDir( wxT( "internat" ) );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
if( fn.DirExists() )
|
|
|
|
{
|
2011-08-29 19:50:05 +00:00
|
|
|
wxLogDebug( wxT( "Adding locale lookup path: " ) + fn.GetPath() );
|
2009-02-07 20:11:09 +00:00
|
|
|
wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
|
|
|
|
}
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
// Append path for unix standard install
|
2009-02-09 20:17:06 +00:00
|
|
|
fn.RemoveLastDir();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
// Append path for unix standard install
|
2009-01-29 14:26:20 +00:00
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
fn.AppendDir( wxT( "internat" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( fn.DirExists() )
|
|
|
|
{
|
2011-08-29 19:50:05 +00:00
|
|
|
wxLogDebug( wxT( "Adding locale lookup path: " ) + fn.GetPath() );
|
2009-01-29 14:26:20 +00:00
|
|
|
wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::AddMenuLanguageList( wxMenu* MasterMenu )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-18 10:15:10 +00:00
|
|
|
wxMenu* menu = NULL;
|
2009-01-07 15:59:49 +00:00
|
|
|
wxMenuItem* item;
|
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
item = MasterMenu->FindItem( ID_LANGUAGE_CHOICE );
|
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
if( item ) // This menu exists, do nothing
|
|
|
|
return;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
menu = new wxMenu;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
|
2009-01-18 10:15:10 +00:00
|
|
|
{
|
2009-04-13 05:58:11 +00:00
|
|
|
wxString label;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
if( s_Languages[ii].m_DoNotTranslate )
|
|
|
|
label = s_Languages[ii].m_Lang_Label;
|
2009-04-13 05:58:11 +00:00
|
|
|
else
|
2013-12-31 06:25:53 +00:00
|
|
|
label = wxGetTranslation( s_Languages[ii].m_Lang_Label );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
AddMenuItem( menu, s_Languages[ii].m_KI_Lang_Identifier,
|
|
|
|
label, KiBitmap(s_Languages[ii].m_Lang_Icon ),
|
2012-04-09 09:16:47 +00:00
|
|
|
wxITEM_CHECK );
|
2009-01-07 15:59:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, menu,
|
|
|
|
ID_LANGUAGE_CHOICE,
|
|
|
|
_( "Language" ),
|
|
|
|
_( "Select application language (only for testing!)" ),
|
|
|
|
KiBitmap( language_xpm ) );
|
2009-01-18 10:15:10 +00:00
|
|
|
|
|
|
|
// Set Check mark on current selected language
|
2013-12-31 06:25:53 +00:00
|
|
|
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
2013-12-31 06:25:53 +00:00
|
|
|
if( m_LanguageId == s_Languages[ii].m_WX_Lang_Identifier )
|
|
|
|
menu->Check( s_Languages[ii].m_KI_Lang_Identifier, true );
|
2009-01-07 15:59:49 +00:00
|
|
|
else
|
2013-12-31 06:25:53 +00:00
|
|
|
menu->Check( s_Languages[ii].m_KI_Lang_Identifier, false );
|
2009-01-07 15:59:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
wxString EDA_APP::FindFileInSearchPaths(
|
|
|
|
const wxString& filename, const wxArrayString* subdirs )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
size_t i, j;
|
|
|
|
wxFileName fn;
|
|
|
|
wxPathList paths;
|
|
|
|
|
|
|
|
for( i = 0; i < m_searchPaths.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
fn = wxFileName( m_searchPaths[i], wxEmptyString );
|
|
|
|
if( subdirs )
|
|
|
|
{
|
|
|
|
for( j = 0; j < subdirs->GetCount(); j++ )
|
|
|
|
fn.AppendDir( subdirs->Item( j ) );
|
|
|
|
}
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( fn.DirExists() )
|
|
|
|
{
|
|
|
|
paths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths.FindValidPath( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-31 06:25:53 +00:00
|
|
|
wxString EDA_APP::GetHelpFile()
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
wxString fn;
|
2009-02-07 20:11:09 +00:00
|
|
|
wxArrayString subdirs, altsubdirs;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* FIXME: This is not the ideal way to handle this. Unfortunately, the
|
2009-01-29 14:26:20 +00:00
|
|
|
* CMake install paths seem to be a moving target so this crude
|
|
|
|
* hack solve the problem of install path differences between
|
|
|
|
* Windows and non-Windows platforms. */
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
// Partially fixed, but must be enhanced
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Create subdir tree for "standard" linux distributions, when KiCad comes
|
2009-04-05 20:49:15 +00:00
|
|
|
// from a distribution files are in /usr/share/doc/kicad/help and binaries
|
|
|
|
// in /usr/bin or /usr/local/bin
|
2009-01-29 14:26:20 +00:00
|
|
|
subdirs.Add( wxT( "share" ) );
|
|
|
|
subdirs.Add( _T( "doc" ) );
|
|
|
|
subdirs.Add( wxT( "kicad" ) );
|
|
|
|
subdirs.Add( _T( "help" ) );
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Create subdir tree for linux and Windows KiCad pack.
|
2009-04-05 20:49:15 +00:00
|
|
|
// Note the pack form under linux is also useful if a user wants to
|
2011-09-30 18:15:37 +00:00
|
|
|
// install KiCad to a server because there is only one path to mount
|
2009-04-05 20:49:15 +00:00
|
|
|
// or export (something like /usr/local/kicad).
|
2009-02-07 20:11:09 +00:00
|
|
|
// files are in <install dir>/kicad/doc/help
|
|
|
|
// (often /usr/local/kicad/kicad/doc/help)
|
2009-04-05 20:49:15 +00:00
|
|
|
// <install dir>/kicad/ is retrieved from m_BinDir
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.Add( _T( "doc" ) );
|
|
|
|
altsubdirs.Add( _T( "help" ) );
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
/* Search for a help file.
|
|
|
|
* we *must* find a help file.
|
|
|
|
* so help is searched in directories in this order:
|
|
|
|
* help/<canonical name> like help/en_GB
|
|
|
|
* help/<short name> like help/en
|
|
|
|
* help/en
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Step 1 : Try to find help file in help/<canonical name>
|
2009-01-29 14:26:20 +00:00
|
|
|
subdirs.Add( m_Locale->GetCanonicalName() );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.Add( m_Locale->GetCanonicalName() );
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
if( !fn )
|
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &subdirs );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
// Step 2 : if not found Try to find help file in help/<short name>
|
|
|
|
if( !fn )
|
|
|
|
{
|
|
|
|
subdirs.RemoveAt( subdirs.GetCount() - 1 );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 );
|
2009-04-18 14:14:40 +00:00
|
|
|
|
|
|
|
// wxLocale::GetName() does not return always the short name
|
2009-04-05 20:49:15 +00:00
|
|
|
subdirs.Add( m_Locale->GetName().BeforeLast( '_' ) );
|
|
|
|
altsubdirs.Add( m_Locale->GetName().BeforeLast( '_' ) );
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !fn )
|
2009-02-07 20:11:09 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &subdirs );
|
2009-02-03 20:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Step 3 : if not found Try to find help file in help/en
|
|
|
|
if( !fn )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
subdirs.RemoveAt( subdirs.GetCount() - 1 );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 );
|
2009-01-29 14:26:20 +00:00
|
|
|
subdirs.Add( _T( "en" ) );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.Add( _T( "en" ) );
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs );
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !fn )
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &subdirs );
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
wxString EDA_APP::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !m_LastVisitedLibPath.IsEmpty() )
|
2009-04-15 19:53:41 +00:00
|
|
|
return m_LastVisitedLibPath;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
wxString path;
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
/* Initialize default path to the main default lib path
|
|
|
|
* this is the second path in list (the first is the project path)
|
|
|
|
*/
|
2009-04-15 19:53:41 +00:00
|
|
|
unsigned pcount = m_libSearchPaths.GetCount();
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( pcount )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
|
|
|
unsigned ipath = 0;
|
2013-12-31 06:25:53 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( m_libSearchPaths[0] == wxGetCwd() )
|
2009-04-14 16:45:22 +00:00
|
|
|
ipath = 1;
|
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
// First choice of path:
|
2009-04-18 14:14:40 +00:00
|
|
|
if( ipath < pcount )
|
2009-04-15 19:53:41 +00:00
|
|
|
path = m_libSearchPaths[ipath];
|
2009-04-14 16:45:22 +00:00
|
|
|
|
|
|
|
// Search a sub path matching aSubPathToSearch
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !aSubPathToSearch.IsEmpty() )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
for( ; ipath < pcount; ipath++ )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( m_libSearchPaths[ipath].Contains( aSubPathToSearch ) )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
path = m_libSearchPaths[ipath];
|
2009-04-14 16:45:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( path.IsEmpty() )
|
2009-04-14 16:45:22 +00:00
|
|
|
path = wxGetCwd();
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::SaveLastVisitedLibraryPath( const wxString& aPath )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
m_LastVisitedLibPath = aPath;
|
2009-04-14 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
wxString EDA_APP::ReturnFilenameWithRelativePathInLibPath( const wxString& aFullFilename )
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
/* If the library path is already in the library search paths
|
2009-04-15 15:53:21 +00:00
|
|
|
* list, just add the library name to the list. Otherwise, add
|
|
|
|
* the library name with the full or relative path.
|
|
|
|
* the relative path, when possible is preferable,
|
2011-08-29 19:50:05 +00:00
|
|
|
* because it preserve use of default libraries paths, when the path is a sub path of
|
|
|
|
* these default paths
|
2009-08-13 18:50:47 +00:00
|
|
|
* Note we accept only sub paths,
|
|
|
|
* not relative paths starting by ../ that are not subpaths and are outside kicad libs paths
|
2009-04-15 15:53:21 +00:00
|
|
|
*/
|
|
|
|
wxFileName fn = aFullFilename;
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString filename = aFullFilename;
|
2011-08-29 19:50:05 +00:00
|
|
|
unsigned pathlen = fn.GetPath().Len(); /* path len, used to find the better (shortest)
|
|
|
|
* subpath within defaults paths */
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-08-18 07:54:03 +00:00
|
|
|
for( unsigned kk = 0; kk < m_libSearchPaths.GetCount(); kk++ )
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
2009-08-18 07:54:03 +00:00
|
|
|
fn = aFullFilename;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-08-18 07:54:03 +00:00
|
|
|
// Search for the shortest subpath within m_libSearchPaths:
|
|
|
|
if( fn.MakeRelativeTo( m_libSearchPaths[kk] ) )
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
2009-08-18 07:54:03 +00:00
|
|
|
if( fn.GetPathWithSep().StartsWith( wxT("..") ) ) // Path outside kicad libs paths
|
|
|
|
continue;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-08-18 07:54:03 +00:00
|
|
|
if( pathlen > fn.GetPath().Len() ) // A better (shortest) subpath is found
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
2009-08-18 07:54:03 +00:00
|
|
|
filename = fn.GetPathWithSep() + fn.GetFullName();
|
|
|
|
pathlen = fn.GetPath().Len();
|
2009-04-15 15:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
wxString EDA_APP::FindLibraryPath( const wxString& aFileName )
|
2009-04-08 18:06:22 +00:00
|
|
|
{
|
2009-04-14 16:45:22 +00:00
|
|
|
if( wxFileName::FileExists( aFileName ) )
|
|
|
|
return aFileName;
|
2009-04-08 18:06:22 +00:00
|
|
|
else
|
2009-04-14 16:45:22 +00:00
|
|
|
return m_libSearchPaths.FindValidPath( aFileName );
|
2009-04-09 18:39:39 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::RemoveLibraryPath( const wxString& aPaths )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxStringTokenizer Token( aPaths, wxT( ";\n\r" ) );
|
|
|
|
|
|
|
|
while( Token.HasMoreTokens() )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString path = Token.GetNextToken();
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Remove( path );
|
|
|
|
}
|
2009-04-09 18:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
void EDA_APP::InsertLibraryPath( const wxString& aPaths, size_t aIndex )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxStringTokenizer Token( aPaths, wxT( ";\n\r" ) );
|
|
|
|
|
|
|
|
while( Token.HasMoreTokens() )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString path = Token.GetNextToken();
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( wxFileName::DirExists( path )
|
|
|
|
&& m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) == wxNOT_FOUND )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( aIndex >= m_libSearchPaths.GetCount() )
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Add( path );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Insert( path, aIndex );
|
|
|
|
}
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
aIndex++;
|
2009-04-09 18:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-08 18:06:22 +00:00
|
|
|
}
|
2013-01-04 12:06:50 +00:00
|
|
|
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
bool EDA_APP::LockFile( const wxString& fileName )
|
|
|
|
{
|
2013-01-30 16:15:45 +00:00
|
|
|
// first make absolute and normalize, to avoid that different lock files
|
|
|
|
// for the same file can be created
|
|
|
|
wxFileName fn = fileName;
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-30 16:15:45 +00:00
|
|
|
fn.MakeAbsolute();
|
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
// semaphore to protect the edition of the file by more than one instance
|
|
|
|
if( m_oneInstancePerFileChecker != NULL )
|
|
|
|
{
|
|
|
|
// it means that we had an open file and we are opening a different one
|
|
|
|
delete m_oneInstancePerFileChecker;
|
|
|
|
}
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-30 16:15:45 +00:00
|
|
|
wxString lockFileName = fn.GetFullPath() + wxT( ".lock" );
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
lockFileName.Replace( wxT( "/" ), wxT( "_" ) );
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
// We can have filenames coming from Windows, so also convert Windows separator
|
|
|
|
lockFileName.Replace( wxT( "\\" ), wxT( "_" ) );
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
m_oneInstancePerFileChecker = new wxSingleInstanceChecker( lockFileName );
|
2013-07-09 05:20:07 +00:00
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
if( m_oneInstancePerFileChecker &&
|
|
|
|
m_oneInstancePerFileChecker->IsAnotherRunning() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-06 12:17:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool EDA_APP::SetFootprintLibTablePath()
|
|
|
|
{
|
2013-11-15 14:36:11 +00:00
|
|
|
wxString path;
|
2013-11-15 15:12:07 +00:00
|
|
|
wxString kisysmod( wxT( KISYSMOD ) );
|
2013-09-06 12:17:33 +00:00
|
|
|
|
|
|
|
// Set the KISYSMOD environment variable for the current process if it is not already
|
|
|
|
// defined in the user's environment. This is required to expand the global footprint
|
|
|
|
// library table paths.
|
2013-11-15 14:36:11 +00:00
|
|
|
if( wxGetEnv( kisysmod, &path ) && wxFileName::DirExists( path ) )
|
2013-09-06 12:17:33 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Set the KISYSMOD environment variable to the path defined in the user's configuration
|
|
|
|
// if it is defined and the path exists.
|
|
|
|
if( m_commonSettings->Read( kicadFpLibPath, &path ) && wxFileName::DirExists( path ) )
|
|
|
|
{
|
2013-11-15 14:36:11 +00:00
|
|
|
wxSetEnv( kisysmod, path );
|
2013-09-06 12:17:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to determine where the footprint libraries were installed using the legacy
|
|
|
|
// library search paths.
|
|
|
|
if( !GetLibraryPathList().IsEmpty() )
|
|
|
|
{
|
|
|
|
unsigned modFileCount = 0;
|
|
|
|
wxString bestPath;
|
|
|
|
wxArrayString tmp;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < GetLibraryPathList().GetCount(); i++ )
|
|
|
|
{
|
|
|
|
unsigned cnt = wxDir::GetAllFiles( GetLibraryPathList()[i], &tmp, wxT( "*.mod" ),
|
2013-09-08 18:31:21 +00:00
|
|
|
wxDIR_FILES );
|
2013-09-06 12:17:33 +00:00
|
|
|
|
|
|
|
if( cnt > modFileCount )
|
|
|
|
{
|
|
|
|
modFileCount = cnt;
|
|
|
|
bestPath = GetLibraryPathList()[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( modFileCount != 0 )
|
|
|
|
{
|
2013-11-15 14:36:11 +00:00
|
|
|
wxSetEnv( kisysmod, bestPath );
|
2013-09-06 12:17:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-31 06:25:53 +00:00
|
|
|
|