2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-01-07 15:04:57 +00:00
|
|
|
* Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file common.cpp
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <build_version.h>
|
|
|
|
#include <confirm.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2014-10-26 13:59:01 +00:00
|
|
|
#include <reporter.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
#include <wx/process.h>
|
2014-09-05 21:12:38 +00:00
|
|
|
#include <wx/config.h>
|
|
|
|
#include <wx/utils.h>
|
|
|
|
#include <wx/stdpaths.h>
|
2008-01-05 17:20:46 +00:00
|
|
|
|
2013-06-28 16:29:39 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Global variables definitions.
|
|
|
|
*
|
2013-03-19 01:25:19 +00:00
|
|
|
* TODO: All of these variables should be moved into the class were they
|
2009-04-05 20:49:15 +00:00
|
|
|
* are defined and used. Most of them probably belong in the
|
|
|
|
* application class.
|
|
|
|
*/
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
bool g_ShowPageLimits = true;
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_UNITS_T g_UserUnit;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T g_GhostColor;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function to use local notation or C standard notation for floating point numbers
|
2010-01-29 20:36:12 +00:00
|
|
|
* some countries use 1,5 and others (and C) 1.5
|
|
|
|
* so we switch from local to C and C to local when reading or writing files
|
|
|
|
* And other problem is a bug when cross compiling under linux:
|
|
|
|
* a printf print 1,5 and the read functions expects 1.5
|
|
|
|
* (depending on version print = 1.5 and read = 1,5
|
2013-03-19 01:25:19 +00:00
|
|
|
* Very annoying and we detect this and use a stupid but necessary workaround
|
2010-01-29 20:36:12 +00:00
|
|
|
*/
|
|
|
|
bool g_DisableFloatingPointLocalNotation = false;
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
int LOCALE_IO::C_count;
|
|
|
|
|
|
|
|
|
|
|
|
void SetLocaleTo_C_standard()
|
2008-06-06 16:39:45 +00:00
|
|
|
{
|
|
|
|
setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C
|
|
|
|
}
|
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
void SetLocaleTo_Default()
|
2008-06-06 16:39:45 +00:00
|
|
|
{
|
2012-04-17 06:13:22 +00:00
|
|
|
if( !g_DisableFloatingPointLocalNotation )
|
2010-01-29 20:36:12 +00:00
|
|
|
setlocale( LC_NUMERIC, "" ); // revert to the current locale
|
2008-06-06 16:39:45 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
2012-05-06 23:32:01 +00:00
|
|
|
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
wxCoord width;
|
|
|
|
wxCoord height;
|
|
|
|
|
|
|
|
{
|
|
|
|
wxClientDC dc( aWindow );
|
|
|
|
dc.SetFont( aWindow->GetFont() );
|
|
|
|
dc.GetTextExtent( aSingleLine, &width, &height );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxSize( width, height );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
|
2009-01-29 17:30:38 +00:00
|
|
|
{
|
2009-06-13 17:06:07 +00:00
|
|
|
wxWindow* window = aCtrl->GetParent();
|
|
|
|
|
2009-01-29 17:30:38 +00:00
|
|
|
if( !window )
|
|
|
|
window = aCtrl;
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
wxString ctrlText;
|
2009-01-29 17:30:38 +00:00
|
|
|
|
|
|
|
if( !aString )
|
|
|
|
{
|
|
|
|
ctrlText = aCtrl->GetValue();
|
2009-06-13 17:06:07 +00:00
|
|
|
aString = &ctrlText;
|
2009-01-29 17:30:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 23:32:01 +00:00
|
|
|
wxSize textz = GetTextSize( *aString, window );
|
|
|
|
wxSize ctrlz = aCtrl->GetSize();
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2012-05-06 23:32:01 +00:00
|
|
|
if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
|
2009-01-29 17:30:38 +00:00
|
|
|
{
|
2012-05-06 23:32:01 +00:00
|
|
|
ctrlz.SetWidth( textz.GetWidth() + 10 );
|
|
|
|
aCtrl->SetSizeHints( ctrlz );
|
2009-01-29 17:30:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2009-01-29 17:30:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
wxString tmp;
|
2007-08-22 05:11:01 +00:00
|
|
|
wxString label;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( aUnit )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
|
|
|
case INCHES:
|
2010-03-16 18:22:59 +00:00
|
|
|
tmp = _( "\"" );
|
2007-08-22 05:11:01 +00:00
|
|
|
break;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case MILLIMETRES:
|
2010-03-16 18:22:59 +00:00
|
|
|
tmp = _( "mm" );
|
2007-08-22 05:11:01 +00:00
|
|
|
break;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case UNSCALED_UNITS:
|
2007-08-22 05:11:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( formatString.IsEmpty() )
|
|
|
|
return tmp;
|
|
|
|
|
|
|
|
label.Printf( formatString, GetChars( tmp ) );
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
return label;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
wxString GetUnitsLabel( EDA_UNITS_T aUnit )
|
2009-10-30 19:26:25 +00:00
|
|
|
{
|
|
|
|
wxString label;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( aUnit )
|
2009-10-30 19:26:25 +00:00
|
|
|
{
|
|
|
|
case INCHES:
|
|
|
|
label = _( "inches" );
|
|
|
|
break;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case MILLIMETRES:
|
2009-10-30 19:26:25 +00:00
|
|
|
label = _( "millimeters" );
|
|
|
|
break;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case UNSCALED_UNITS:
|
|
|
|
label = _( "units" );
|
2009-10-30 19:26:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
|
|
|
wxString label;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( aUnit )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
|
|
|
case INCHES:
|
|
|
|
label = _( "in" );
|
|
|
|
break;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case MILLIMETRES:
|
2010-03-16 18:22:59 +00:00
|
|
|
label = _( "mm" );
|
|
|
|
break;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case UNSCALED_UNITS:
|
2010-03-16 18:22:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-11 10:27:21 +00:00
|
|
|
wxString msg = Stext.GetLabel();
|
2010-07-12 14:07:09 +00:00
|
|
|
|
|
|
|
msg += ReturnUnitSymbol( aUnit );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
Stext.SetLabel( msg );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter )
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString tmp;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < aText.Length(); ii++ )
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
if( aText[ii] == aSplitter )
|
|
|
|
{
|
|
|
|
aStrings.Add( tmp );
|
|
|
|
tmp.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
tmp << aText[ii];
|
2009-04-28 19:34:42 +00:00
|
|
|
}
|
2009-05-02 07:35:04 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
if( !tmp.IsEmpty() )
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
aStrings.Add( tmp );
|
2009-04-28 19:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2013-01-18 10:42:23 +00:00
|
|
|
int ProcessExecute( const wxString& aCommandLine, int aFlags, wxProcess *callback )
|
2008-04-24 16:55:35 +00:00
|
|
|
{
|
2013-01-18 10:42:23 +00:00
|
|
|
return wxExecute( aCommandLine, aFlags, callback );
|
2008-04-24 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t GetNewTimeStamp()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-05-25 01:52:04 +00:00
|
|
|
static time_t oldTimeStamp;
|
|
|
|
time_t newTimeStamp;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-07 15:49:32 +00:00
|
|
|
newTimeStamp = time( NULL );
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2011-12-07 15:49:32 +00:00
|
|
|
if( newTimeStamp <= oldTimeStamp )
|
|
|
|
newTimeStamp = oldTimeStamp + 1;
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2011-12-07 15:49:32 +00:00
|
|
|
oldTimeStamp = newTimeStamp;
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2011-12-07 15:49:32 +00:00
|
|
|
return newTimeStamp;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
double RoundTo0( double x, double precision )
|
|
|
|
{
|
|
|
|
assert( precision != 0 );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
long long ix = KiROUND( x * precision );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
if ( x < 0.0 )
|
|
|
|
NEGATE( ix );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
int remainder = ix % 10; // remainder is in precision mm
|
2008-05-05 19:43:56 +00:00
|
|
|
|
2015-01-07 15:04:57 +00:00
|
|
|
if( remainder <= 2 )
|
2012-04-13 18:51:24 +00:00
|
|
|
ix -= remainder; // truncate to the near number
|
2015-01-07 15:04:57 +00:00
|
|
|
else if( remainder >= 8 )
|
2012-04-13 18:51:24 +00:00
|
|
|
ix += 10 - remainder; // round to near number
|
2008-05-05 19:43:56 +00:00
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
if ( x < 0 )
|
|
|
|
NEGATE( ix );
|
|
|
|
|
|
|
|
return (double) ix / precision;
|
2008-05-05 19:43:56 +00:00
|
|
|
}
|
2013-05-23 18:45:23 +00:00
|
|
|
|
|
|
|
wxString FormatDateLong( const wxDateTime &aDate )
|
|
|
|
{
|
2014-09-05 21:12:38 +00:00
|
|
|
// GetInfo was introduced only on wx 2.9; for portability reason an
|
|
|
|
// hardcoded format is used on wx 2.8
|
2013-05-23 18:45:23 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
|
|
|
return aDate.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
|
|
|
|
#else
|
|
|
|
return aDate.Format( wxT("%d %b %Y") );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-05 21:12:38 +00:00
|
|
|
|
|
|
|
wxConfigBase* GetNewConfig( const wxString& aProgName )
|
|
|
|
{
|
|
|
|
wxConfigBase* cfg = 0;
|
|
|
|
wxFileName configname;
|
|
|
|
configname.AssignDir( GetKicadConfigPath() );
|
|
|
|
configname.SetFullName( aProgName );
|
|
|
|
|
|
|
|
cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
2015-01-07 15:04:57 +00:00
|
|
|
wxString GetKicadLockFilePath()
|
|
|
|
{
|
|
|
|
wxFileName lockpath;
|
|
|
|
lockpath.AssignDir( wxGetHomeDir() ); // Default wx behavior
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ )
|
|
|
|
// In OSX use the standard per user cache directory
|
|
|
|
lockpath.AppendDir( wxT( "Library" ) );
|
|
|
|
lockpath.AppendDir( wxT( "Caches" ) );
|
|
|
|
lockpath.AppendDir( wxT( "kicad" ) );
|
|
|
|
#elif defined( __UNIX__ )
|
|
|
|
wxString envstr;
|
|
|
|
// Try first the standard XDG_RUNTIME_DIR, falling back to XDG_CACHE_HOME
|
|
|
|
if( wxGetEnv( wxT( "XDG_RUNTIME_DIR" ), &envstr ) && !envstr.IsEmpty() )
|
|
|
|
{
|
|
|
|
lockpath.AssignDir( envstr );
|
|
|
|
}
|
|
|
|
else if( wxGetEnv( wxT( "XDG_CACHE_HOME" ), &envstr ) && !envstr.IsEmpty() )
|
|
|
|
{
|
|
|
|
lockpath.AssignDir( envstr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If all fails, just use ~/.cache
|
|
|
|
lockpath.AppendDir( wxT( ".cache" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
lockpath.AppendDir( wxT( "kicad" ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ ) || defined( __UNIX__ )
|
|
|
|
if( !lockpath.DirExists() )
|
|
|
|
{
|
|
|
|
// Lockfiles should be only readable by the user
|
|
|
|
lockpath.Mkdir( 0700, wxPATH_MKDIR_FULL );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return lockpath.GetPath();
|
|
|
|
}
|
|
|
|
|
2014-09-05 21:12:38 +00:00
|
|
|
|
|
|
|
wxString GetKicadConfigPath()
|
|
|
|
{
|
|
|
|
wxFileName cfgpath;
|
|
|
|
|
|
|
|
// From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
|
|
|
|
// Unix: ~ (the home directory)
|
|
|
|
// Windows: "C:\Documents and Settings\username\Application Data"
|
|
|
|
// Mac: ~/Library/Preferences
|
|
|
|
cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
|
|
|
|
|
|
|
|
#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
|
|
|
|
wxString envstr;
|
|
|
|
|
|
|
|
if( !wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) || envstr.IsEmpty() )
|
|
|
|
{
|
|
|
|
// XDG_CONFIG_HOME is not set, so use the fallback
|
|
|
|
cfgpath.AppendDir( wxT( ".config" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Override the assignment above with XDG_CONFIG_HOME
|
|
|
|
cfgpath.AssignDir( envstr );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cfgpath.AppendDir( wxT( "kicad" ) );
|
|
|
|
|
|
|
|
#if !wxCHECK_VERSION( 2, 9, 0 )
|
|
|
|
#define wxS_DIR_DEFAULT 0777
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( !cfgpath.DirExists() )
|
|
|
|
{
|
|
|
|
cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfgpath.GetPath();
|
|
|
|
}
|
2014-10-16 22:13:01 +00:00
|
|
|
|
2014-10-26 13:59:01 +00:00
|
|
|
|
2014-12-23 13:01:59 +00:00
|
|
|
#include <ki_mutex.h>
|
|
|
|
const wxString ExpandEnvVarSubstitutions( const wxString& aString )
|
|
|
|
{
|
|
|
|
// wxGetenv( wchar_t* ) is not re-entrant on linux.
|
|
|
|
// Put a lock on multithreaded use of wxGetenv( wchar_t* ), called from wxEpandEnvVars(),
|
|
|
|
static MUTEX getenv_mutex;
|
|
|
|
|
|
|
|
MUTLOCK lock( getenv_mutex );
|
|
|
|
|
|
|
|
// We reserve the right to do this another way, by providing our own member
|
|
|
|
// function.
|
|
|
|
return wxExpandEnvVars( aString );
|
|
|
|
}
|
2014-10-26 13:59:01 +00:00
|
|
|
|
|
|
|
bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName,
|
|
|
|
const wxString& aBaseFilename,
|
|
|
|
REPORTER* aReporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
wxString baseFilePath = wxFileName( aBaseFilename ).GetPath();
|
|
|
|
|
|
|
|
// make aTargetFullFileName path, which is relative to aBaseFilename path (if it is not
|
|
|
|
// already an absolute path) absolute:
|
|
|
|
if( !aTargetFullFileName->MakeAbsolute( baseFilePath ) )
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "*** Error: cannot make path '%s' absolute with respect to '%s'! ***" ),
|
|
|
|
GetChars( aTargetFullFileName->GetPath() ),
|
|
|
|
GetChars( baseFilePath ) );
|
|
|
|
aReporter->Report( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure the path of aTargetFullFileName exists, and create it if needed:
|
|
|
|
wxString outputPath( aTargetFullFileName->GetPath() );
|
|
|
|
|
|
|
|
if( !wxFileName::DirExists( outputPath ) )
|
|
|
|
{
|
|
|
|
if( wxMkdir( outputPath ) )
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Output directory '%s' created.\n" ), GetChars( outputPath ) );
|
|
|
|
aReporter->Report( msg );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "*** Error: cannot create output directory '%s'! ***\n" ),
|
|
|
|
GetChars( outputPath ) );
|
|
|
|
aReporter->Report( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 22:13:01 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxString GetOSXKicadUserDataDir()
|
|
|
|
{
|
|
|
|
// According to wxWidgets documentation for GetUserDataDir:
|
|
|
|
// Mac: ~/Library/Application Support/appname
|
|
|
|
wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
|
|
|
|
|
|
|
|
// Since appname is different if started via launcher or standalone binary
|
|
|
|
// map all to "kicad" here
|
|
|
|
udir.RemoveLastDir();
|
|
|
|
udir.AppendDir( wxT( "kicad" ) );
|
|
|
|
|
|
|
|
return udir.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString GetOSXKicadMachineDataDir()
|
|
|
|
{
|
|
|
|
return wxT( "/Library/Application Support/kicad" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString GetOSXKicadDataDir()
|
|
|
|
{
|
|
|
|
// According to wxWidgets documentation for GetDataDir:
|
|
|
|
// Mac: appname.app/Contents/SharedSupport bundle subdirectory
|
|
|
|
wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
|
|
|
|
|
|
|
|
// This must be mapped to main bundle for everything but kicad.app
|
|
|
|
const wxArrayString dirs = ddir.GetDirs();
|
|
|
|
if( dirs[dirs.GetCount() - 3] != wxT( "kicad.app" ) )
|
|
|
|
{
|
|
|
|
// Bundle structure resp. current path is
|
|
|
|
// kicad.app/Contents/Applications/<standalone>.app/Contents/SharedSupport
|
|
|
|
// and will be mapped to
|
|
|
|
// kicad.app/Contents/SharedSupprt
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.AppendDir( wxT( "SharedSupport" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ddir.GetPath();
|
|
|
|
}
|
|
|
|
#endif
|