2011-11-10 15:55:05 +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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file common.cpp
|
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +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"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "confirm.h"
|
2008-04-24 16:55:35 +00:00
|
|
|
|
#include <wx/process.h>
|
2008-01-05 17:20:46 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Global variables definitions.
|
|
|
|
|
*
|
|
|
|
|
* TODO: All if these variables should be moved into the class were they
|
|
|
|
|
* are defined and used. Most of them probably belong in the
|
|
|
|
|
* application class.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Standard page sizes in 1/1000 inch */
|
2010-03-11 13:48:39 +00:00
|
|
|
|
#if defined(KICAD_GOST)
|
|
|
|
|
Ki_PageDescr g_Sheet_A4( wxSize( 8283, 11700 ), wxPoint( 0, 0 ), wxT( "A4" ) );
|
|
|
|
|
#else
|
2009-06-13 17:06:07 +00:00
|
|
|
|
Ki_PageDescr g_Sheet_A4( wxSize( 11700, 8267 ), wxPoint( 0, 0 ), wxT( "A4" ) );
|
2010-03-11 13:48:39 +00:00
|
|
|
|
#endif
|
2009-06-13 17:06:07 +00:00
|
|
|
|
Ki_PageDescr g_Sheet_A3( wxSize( 16535, 11700 ), wxPoint( 0, 0 ), wxT( "A3" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_A2( wxSize( 23400, 16535 ), wxPoint( 0, 0 ), wxT( "A2" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_A1( wxSize( 33070, 23400 ), wxPoint( 0, 0 ), wxT( "A1" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_A0( wxSize( 46800, 33070 ), wxPoint( 0, 0 ), wxT( "A0" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_A( wxSize( 11000, 8500 ), wxPoint( 0, 0 ), wxT( "A" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_B( wxSize( 17000, 11000 ), wxPoint( 0, 0 ), wxT( "B" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_C( wxSize( 22000, 17000 ), wxPoint( 0, 0 ), wxT( "C" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_D( wxSize( 34000, 22000 ), wxPoint( 0, 0 ), wxT( "D" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_E( wxSize( 44000, 34000 ), wxPoint( 0, 0 ), wxT( "E" ) );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
Ki_PageDescr g_Sheet_GERBER( wxSize( 32000, 32000 ), wxPoint( 0, 0 ), wxT( "GERBER" ) );
|
|
|
|
|
Ki_PageDescr g_Sheet_user( wxSize( 17000, 11000 ), wxPoint( 0, 0 ), wxT( "User" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
|
Ki_PageDescr* g_SheetSizeList[NB_ITEMS + 1] =
|
|
|
|
|
{
|
2009-06-13 17:06:07 +00:00
|
|
|
|
&g_Sheet_A4, &g_Sheet_A3, &g_Sheet_A2, &g_Sheet_A1, &g_Sheet_A0,
|
|
|
|
|
&g_Sheet_A, &g_Sheet_B, &g_Sheet_C, &g_Sheet_D, &g_Sheet_E,
|
2009-04-05 20:49:15 +00:00
|
|
|
|
&g_Sheet_user, NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const wxString ProjectFileExtension( wxT( "pro" ) );
|
|
|
|
|
const wxString SchematicFileExtension( wxT( "sch" ) );
|
|
|
|
|
const wxString NetlistFileExtension( wxT( "net" ) );
|
|
|
|
|
const wxString GerberFileExtension( wxT( "pho" ) );
|
2010-05-17 20:35:46 +00:00
|
|
|
|
const wxString PcbFileExtension( wxT( "brd" ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
const wxString PdfFileExtension( wxT( "pdf" ) );
|
2011-09-07 09:27:02 +00:00
|
|
|
|
const wxString MacrosFileExtension( wxT( "mcr" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
|
const wxString ProjectFileWildcard( _( "KiCad project files (*.pro)|*.pro" ) );
|
|
|
|
|
const wxString SchematicFileWildcard( _( "KiCad schematic files (*.sch)|*.sch" ) );
|
|
|
|
|
const wxString NetlistFileWildcard( _( "KiCad netlist files (*.net)|*.net" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) );
|
2011-09-30 18:15:37 +00:00
|
|
|
|
const wxString PcbFileWildcard( _( "KiCad printed circuit board files (*.brd)|*.brd" ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) );
|
2011-09-30 18:15:37 +00:00
|
|
|
|
const wxString MacrosFileWildcard( _( "KiCad recorded macros (*.mcr)|*.mcr" ) );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
const wxString AllFilesWildcard( _( "All files (*)|*" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
wxString g_ProductName = wxT( "KiCad E.D.A. " );
|
|
|
|
|
bool g_ShowPageLimits = true;
|
|
|
|
|
wxString g_UserLibDirBuffer;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
wxString g_Prj_Default_Config_FullFilename;
|
|
|
|
|
wxString g_Prj_Config_LocalFilename;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
|
EDA_UNITS_T g_UserUnit;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
int g_GhostColor;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* The predefined colors used in KiCad.
|
2009-04-14 16:45:22 +00:00
|
|
|
|
* Please: if you change a value, remember these values are carefully chosen
|
2011-09-30 18:15:37 +00:00
|
|
|
|
* to have good results in Pcbnew, that uses the ORed value of basic colors
|
2009-04-14 16:45:22 +00:00
|
|
|
|
* when displaying superimposed objects
|
2009-07-09 04:55:55 +00:00
|
|
|
|
* This list must have exactly NBCOLOR items
|
2009-04-14 16:45:22 +00:00
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
|
StructColors ColorRefs[NBCOLOR] =
|
|
|
|
|
{
|
2009-06-13 17:06:07 +00:00
|
|
|
|
{ 0, 0, 0, BLACK, wxT( "BLACK" ), DARKDARKGRAY },
|
|
|
|
|
{ 192, 0, 0, BLUE, wxT( "BLUE" ), LIGHTBLUE },
|
|
|
|
|
{ 0, 160, 0, GREEN, wxT( "GREEN" ), LIGHTGREEN },
|
|
|
|
|
{ 160, 160, 0, CYAN, wxT( "CYAN" ), LIGHTCYAN },
|
|
|
|
|
{ 0, 0, 160, RED, wxT( "RED" ), LIGHTRED },
|
|
|
|
|
{ 160, 0, 160, MAGENTA, wxT( "MAGENTA" ), LIGHTMAGENTA },
|
|
|
|
|
{ 0, 128, 128, BROWN, wxT( "BROWN" ), YELLOW },
|
|
|
|
|
{ 192, 192, 192, LIGHTGRAY, wxT( "GRAY" ), WHITE },
|
|
|
|
|
{ 128, 128, 128, DARKGRAY, wxT( "DARKGRAY" ), LIGHTGRAY },
|
|
|
|
|
{ 255, 0, 0, LIGHTBLUE, wxT( "LIGHTBLUE" ), LIGHTBLUE },
|
|
|
|
|
{ 0, 255, 0, LIGHTGREEN, wxT( "LIGHTGREEN" ), LIGHTGREEN },
|
|
|
|
|
{ 255, 255, 0, LIGHTCYAN, wxT( "LIGHTCYAN" ), LIGHTCYAN },
|
|
|
|
|
{ 0, 0, 255, LIGHTRED, wxT( "LIGHTRED" ), LIGHTRED },
|
|
|
|
|
{ 255, 0, 255, LIGHTMAGENTA, wxT( "LIGHTMAGENTA" ), LIGHTMAGENTA },
|
|
|
|
|
{ 0, 255, 255, YELLOW, wxT( "YELLOW" ), YELLOW },
|
|
|
|
|
{ 255, 255, 255, WHITE, wxT( "WHITE" ), WHITE },
|
|
|
|
|
{ 64, 64, 64, DARKDARKGRAY, wxT( "DARKDARKGRAY" ), DARKGRAY },
|
|
|
|
|
{ 64, 0, 0, DARKBLUE, wxT( "DARKBLUE" ), BLUE },
|
|
|
|
|
{ 0, 64, 0, DARKGREEN, wxT( "DARKGREEN" ), GREEN },
|
|
|
|
|
{ 64, 64, 0, DARKCYAN, wxT( "DARKCYAN" ), CYAN },
|
|
|
|
|
{ 0, 0, 80, DARKRED, wxT( "DARKRED" ), RED },
|
|
|
|
|
{ 64, 0, 64, DARKMAGENTA, wxT( "DARKMAGENTA" ), MAGENTA },
|
|
|
|
|
{ 0, 64, 64, DARKBROWN, wxT( "DARKBROWN" ), BROWN },
|
|
|
|
|
{ 128, 255, 255, LIGHTYELLOW, wxT( "LIGHTYELLOW" ), LIGHTYELLOW }
|
2009-04-05 20:49:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-11-10 15:55: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
|
|
|
|
|
* Very annoying and we detect this and use a stupid but necessary workarount
|
|
|
|
|
*/
|
|
|
|
|
bool g_DisableFloatingPointLocalNotation = false;
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
void SetLocaleTo_C_standard( void )
|
2008-06-06 16:39:45 +00:00
|
|
|
|
{
|
|
|
|
|
setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
|
void SetLocaleTo_Default( void )
|
2008-06-06 16:39:45 +00:00
|
|
|
|
{
|
2010-01-29 20:36:12 +00:00
|
|
|
|
if( ! g_DisableFloatingPointLocalNotation )
|
|
|
|
|
setlocale( LC_NUMERIC, "" ); // revert to the current locale
|
2008-06-06 16:39:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
wxCoord width;
|
|
|
|
|
wxCoord height;
|
2009-01-29 17:30:38 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
wxClientDC dc( window );
|
|
|
|
|
dc.SetFont( aCtrl->GetFont() );
|
|
|
|
|
dc.GetTextExtent( *aString, &width, &height );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxSize size = aCtrl->GetSize();
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2009-01-29 17:30:38 +00:00
|
|
|
|
if( size.GetWidth() < width + 10 )
|
|
|
|
|
{
|
|
|
|
|
size.SetWidth( width + 10 );
|
|
|
|
|
aCtrl->SetSizeHints( size );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2009-01-29 17:30:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
Ki_PageDescr::Ki_PageDescr( const wxSize& size, const wxPoint& offset, const wxString& name )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
// All sizes are in 1/1000 inch
|
2008-09-09 11:32:21 +00:00
|
|
|
|
m_Size = size;
|
2008-04-24 16:55:35 +00:00
|
|
|
|
m_Offset = offset;
|
2008-09-09 11:32:21 +00:00
|
|
|
|
m_Name = name;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
|
|
// Adjust the default value for margins to 400 mils (0,4 inch or 10 mm)
|
2008-11-05 11:41:15 +00:00
|
|
|
|
#if defined(KICAD_GOST)
|
2010-07-13 13:18:13 +00:00
|
|
|
|
m_LeftMargin = GOST_LEFTMARGIN;
|
|
|
|
|
m_RightMargin = GOST_RIGHTMARGIN;
|
|
|
|
|
m_TopMargin = GOST_TOPMARGIN;
|
|
|
|
|
m_BottomMargin = GOST_BOTTOMMARGIN;
|
2008-11-05 11:41:15 +00:00
|
|
|
|
#else
|
2009-06-13 17:06:07 +00:00
|
|
|
|
m_LeftMargin = m_RightMargin = m_TopMargin = m_BottomMargin = 400;
|
2008-11-05 11:41:15 +00:00
|
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
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 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
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int Internal_Unit )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
|
wxString msg = ReturnStringFromValue( g_UserUnit, Value, Internal_Unit );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
|
|
TextCtr.SetValue( msg );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
int value;
|
|
|
|
|
wxString msg = TextCtr.GetValue();
|
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
value = ReturnValueFromString( g_UserUnit, msg, Internal_Unit );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
|
|
return value;
|
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 ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Unit,
|
2009-04-05 20:49:15 +00:00
|
|
|
|
bool aAdd_unit_symbol )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
wxString StringValue;
|
|
|
|
|
double value_to_print;
|
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
value_to_print = To_User_Unit( aUnit, aValue, aInternal_Unit );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
|
/* Yet another 'if Pcbnew' :( */
|
2011-11-10 15:55:05 +00:00
|
|
|
|
StringValue.Printf( ( aInternal_Unit > 1000 ) ? wxT( "%.4f" ) : wxT( "%.3f" ),
|
2010-07-12 14:07:09 +00:00
|
|
|
|
value_to_print );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
if( aAdd_unit_symbol )
|
2010-07-12 14:07:09 +00:00
|
|
|
|
switch( aUnit )
|
2008-09-09 11:32:21 +00:00
|
|
|
|
{
|
|
|
|
|
case INCHES:
|
|
|
|
|
StringValue += _( " \"" );
|
|
|
|
|
break;
|
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
case MILLIMETRES:
|
2008-09-09 11:32:21 +00:00
|
|
|
|
StringValue += _( " mm" );
|
|
|
|
|
break;
|
2010-07-12 19:28:38 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
case UNSCALED_UNITS:
|
2008-09-09 11:32:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
return StringValue;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Internal_Unit )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
int Value;
|
|
|
|
|
double dtmp = 0;
|
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
/* Acquire the 'right' decimal point separator */
|
|
|
|
|
const struct lconv* lc = localeconv();
|
|
|
|
|
wxChar decimal_point = lc->decimal_point[0];
|
|
|
|
|
wxString buf( TextValue.Strip( wxString::both ) );
|
|
|
|
|
|
|
|
|
|
/* Convert the period in decimal point */
|
|
|
|
|
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
|
// An ugly fix needed by WxWidgets 2.9.1 that sometimes
|
|
|
|
|
// back to a point as separator, although the separator is the comma
|
|
|
|
|
// TODO: remove this line if WxWidgets 2.9.2 fixes this issue
|
|
|
|
|
buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
|
2010-07-12 14:07:09 +00:00
|
|
|
|
|
|
|
|
|
/* Find the end of the numeric part */
|
|
|
|
|
unsigned brk_point = 0;
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
while( brk_point < buf.Len() )
|
|
|
|
|
{
|
|
|
|
|
wxChar ch = buf[brk_point];
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) )
|
2010-07-12 14:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
++brk_point;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Extract the numeric part */
|
|
|
|
|
buf.Left( brk_point ).ToDouble( &dtmp );
|
|
|
|
|
|
|
|
|
|
/* Check the optional unit designator (2 ch significant) */
|
|
|
|
|
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
|
|
|
|
|
{
|
|
|
|
|
aUnit = INCHES;
|
|
|
|
|
}
|
|
|
|
|
else if( unit == wxT( "mm" ) )
|
|
|
|
|
{
|
|
|
|
|
aUnit = MILLIMETRES;
|
|
|
|
|
}
|
|
|
|
|
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) /* Mils or thous */
|
|
|
|
|
{
|
|
|
|
|
aUnit = INCHES;
|
|
|
|
|
dtmp /= 1000;
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
Value = From_User_Unit( aUnit, dtmp, Internal_Unit );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
|
|
return Value;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
#ifdef KICAD_NANOMETRE
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*New common length functions
|
|
|
|
|
*/
|
|
|
|
|
|
2011-11-14 16:56:05 +00:00
|
|
|
|
const LENGTH_UNIT_DESC MillimetreDesc =
|
2011-11-09 13:25:49 +00:00
|
|
|
|
{
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_UNITS<LENGTH_PCB>::millimetre(),
|
2011-11-09 17:35:16 +00:00
|
|
|
|
wxT( "mm" ),
|
2011-11-09 13:25:49 +00:00
|
|
|
|
6
|
|
|
|
|
};
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
2011-11-14 16:56:05 +00:00
|
|
|
|
const LENGTH_UNIT_DESC InchDesc =
|
2011-11-09 13:25:49 +00:00
|
|
|
|
{
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_UNITS<LENGTH_PCB>::inch(),
|
2011-11-09 17:35:16 +00:00
|
|
|
|
wxT( "\"" ),
|
2011-11-09 13:25:49 +00:00
|
|
|
|
7
|
|
|
|
|
};
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
2011-11-14 16:56:05 +00:00
|
|
|
|
const LENGTH_UNIT_DESC MilDesc =
|
2011-11-09 13:25:49 +00:00
|
|
|
|
{
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_UNITS<LENGTH_PCB>::mil(),
|
2011-11-09 17:35:16 +00:00
|
|
|
|
wxT( "mil" ),
|
2011-11-09 13:25:49 +00:00
|
|
|
|
5
|
|
|
|
|
};
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
2011-11-14 16:56:05 +00:00
|
|
|
|
const LENGTH_UNIT_DESC UnscaledDesc = /* stub */
|
2011-11-09 13:25:49 +00:00
|
|
|
|
{
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_PCB::quantum(),
|
2011-11-09 17:35:16 +00:00
|
|
|
|
wxT( "" ),
|
2011-11-09 13:25:49 +00:00
|
|
|
|
4
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit ) {
|
|
|
|
|
switch(aUnit) {
|
|
|
|
|
case INCHES:
|
2011-11-14 16:56:05 +00:00
|
|
|
|
return &InchDesc;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
case MILLIMETRES:
|
2011-11-14 16:56:05 +00:00
|
|
|
|
return &MillimetreDesc;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
default:
|
2011-11-14 16:56:05 +00:00
|
|
|
|
return &UnscaledDesc; /* should not be reached */
|
2011-11-09 13:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 17:35:16 +00:00
|
|
|
|
/* TODO: localisation */
|
2011-11-15 18:26:06 +00:00
|
|
|
|
wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_PCB aValue,
|
2011-11-09 13:25:49 +00:00
|
|
|
|
bool aAdd_unit_symbol ) {
|
|
|
|
|
wxString StringValue;
|
|
|
|
|
double value_to_print;
|
|
|
|
|
value_to_print = LENGTH<double>(aValue) / LENGTH<double>(aUnit->m_Value);
|
|
|
|
|
StringValue.Printf( wxT( "%.*f" ), aUnit->m_Precision, value_to_print);
|
2011-11-09 17:35:16 +00:00
|
|
|
|
size_t zero_tail = StringValue.find_last_not_of( wxT( "0" ) );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
if( zero_tail != std::string::npos )
|
|
|
|
|
{
|
2011-11-09 17:35:16 +00:00
|
|
|
|
//fprintf( stderr, "pos : %d", (int) zero_tail );
|
|
|
|
|
size_t delim_pos = StringValue.Length() - aUnit->m_Precision;
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
if( zero_tail < delim_pos)
|
|
|
|
|
zero_tail = delim_pos;
|
|
|
|
|
|
2011-11-09 17:35:16 +00:00
|
|
|
|
StringValue.Truncate( zero_tail + 1 );
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
if( aAdd_unit_symbol && aUnit->m_Symbol != wxT( "" ) )
|
|
|
|
|
{
|
2011-11-09 17:35:16 +00:00
|
|
|
|
StringValue += wxT( " " );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
StringValue += wxGetTranslation( aUnit->m_Symbol );
|
2011-11-09 13:25:49 +00:00
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
return StringValue;
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_PCB StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextValue )
|
2011-11-09 13:25:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_PCB Value;
|
|
|
|
|
double dtmp = 0;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
|
|
|
|
|
/* Acquire the 'right' decimal point separator */
|
|
|
|
|
const struct lconv* lc = localeconv();
|
|
|
|
|
wxChar decimal_point = lc->decimal_point[0];
|
|
|
|
|
wxString buf( TextValue.Strip( wxString::both ) );
|
|
|
|
|
|
|
|
|
|
/* Convert the period in decimal point */
|
|
|
|
|
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
// An ugly fix needed by WxWidgets 2.9.1 that sometimes
|
|
|
|
|
// back to a point as separator, although the separator is the comma
|
|
|
|
|
// TODO: remove this line if WxWidgets 2.9.2 fixes this issue
|
|
|
|
|
buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
|
|
|
|
|
|
|
|
|
|
/* Find the end of the numeric part */
|
|
|
|
|
unsigned brk_point = 0;
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
while( brk_point < buf.Len() )
|
|
|
|
|
{
|
|
|
|
|
wxChar ch = buf[brk_point];
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
if( !( (ch >= '0' && ch <='9') || (ch == decimal_point)
|
|
|
|
|
|| (ch == '-') || (ch == '+') ) )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
++brk_point;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Extract the numeric part */
|
|
|
|
|
buf.Left( brk_point ).ToDouble( &dtmp );
|
|
|
|
|
|
|
|
|
|
/* Check the optional unit designator (2 ch significant) */
|
|
|
|
|
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-09 13:25:49 +00:00
|
|
|
|
if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
|
|
|
|
|
{
|
2011-11-14 16:56:05 +00:00
|
|
|
|
aUnit = &InchDesc;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
else if( unit == wxT( "mm" ) )
|
|
|
|
|
{
|
2011-11-14 16:56:05 +00:00
|
|
|
|
aUnit = &MillimetreDesc;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) /* Mils or thous */
|
|
|
|
|
{
|
2011-11-14 16:56:05 +00:00
|
|
|
|
aUnit = &MilDesc;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-15 18:26:06 +00:00
|
|
|
|
Value = LENGTH_PCB( dtmp * LENGTH< double, 1 >( aUnit->m_Value ) );
|
2011-11-09 13:25:49 +00:00
|
|
|
|
|
|
|
|
|
return Value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 18:26:06 +00:00
|
|
|
|
void LengthToTextCtrl( wxTextCtrl& TextCtr, LENGTH_PCB Value )
|
2011-11-10 15:55:05 +00:00
|
|
|
|
{
|
2011-11-09 13:25:49 +00:00
|
|
|
|
wxString msg = LengthToString( UnitDescription( g_UserUnit ), Value );
|
|
|
|
|
|
|
|
|
|
TextCtr.SetValue( msg );
|
|
|
|
|
}
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_PCB LengthFromTextCtrl( const wxTextCtrl& TextCtr )
|
2011-11-09 13:25:49 +00:00
|
|
|
|
{
|
2011-11-15 18:26:06 +00:00
|
|
|
|
LENGTH_PCB value;
|
2011-11-09 13:25:49 +00:00
|
|
|
|
wxString msg = TextCtr.GetValue();
|
|
|
|
|
|
|
|
|
|
value = StringToLength( UnitDescription( g_UserUnit ), msg );
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
wxArrayString* wxStringSplit( wxString aString, wxChar aSplitter )
|
2009-04-28 19:34:42 +00:00
|
|
|
|
{
|
|
|
|
|
wxArrayString* list = new wxArrayString();
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
|
|
while( 1 )
|
2009-04-28 19:34:42 +00:00
|
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
|
int index = aString.Find( aSplitter );
|
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
|
break;
|
2009-05-02 07:35:04 +00:00
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
wxString tmp;
|
2011-11-10 15:55:05 +00:00
|
|
|
|
tmp = aString.Mid( 0, index );
|
|
|
|
|
aString = aString.Mid( index + 1, aString.size() - index );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
list->Add( tmp );
|
2009-04-28 19:34:42 +00:00
|
|
|
|
}
|
2009-05-02 07:35:04 +00:00
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
if( !aString.IsEmpty() )
|
2009-04-28 19:34:42 +00:00
|
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
|
list->Add( aString );
|
2009-04-28 19:34:42 +00:00
|
|
|
|
}
|
2009-05-02 07:35:04 +00:00
|
|
|
|
|
2009-04-28 19:34:42 +00:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
|
double To_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value )
|
2009-03-12 15:24:52 +00:00
|
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
|
switch( aUnit )
|
|
|
|
|
{
|
|
|
|
|
case MILLIMETRES:
|
|
|
|
|
return val * 25.4 / internal_unit_value;
|
2009-03-12 15:24:52 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
case INCHES:
|
|
|
|
|
return val / internal_unit_value;
|
2009-03-12 15:24:52 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
default:
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2009-03-12 15:24:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
|
int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
double value;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
|
switch( aUnit )
|
|
|
|
|
{
|
|
|
|
|
case MILLIMETRES:
|
2010-03-26 19:34:47 +00:00
|
|
|
|
value = val * internal_unit_value / 25.4;
|
2010-07-12 14:07:09 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case INCHES:
|
2007-08-22 05:11:01 +00:00
|
|
|
|
value = val * internal_unit_value;
|
2010-07-12 14:07:09 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2010-07-12 19:28:38 +00:00
|
|
|
|
default:
|
2010-07-12 14:07:09 +00:00
|
|
|
|
case UNSCALED_UNITS:
|
|
|
|
|
value = val;
|
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
return wxRound( value );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxString GenDate()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
static const wxString mois[12] =
|
|
|
|
|
{
|
|
|
|
|
wxT( "jan" ), wxT( "feb" ), wxT( "mar" ), wxT( "apr" ), wxT( "may" ), wxT( "jun" ),
|
|
|
|
|
wxT( "jul" ), wxT( "aug" ), wxT( "sep" ), wxT( "oct" ), wxT( "nov" ), wxT( "dec" )
|
|
|
|
|
};
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
time_t buftime;
|
|
|
|
|
struct tm* Date;
|
|
|
|
|
wxString string_date;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
|
|
time( &buftime );
|
|
|
|
|
Date = gmtime( &buftime );
|
|
|
|
|
string_date.Printf( wxT( "%d %s %d" ), Date->tm_mday,
|
2009-10-13 09:00:46 +00:00
|
|
|
|
GetChars( mois[Date->tm_mon] ),
|
2009-06-13 17:06:07 +00:00
|
|
|
|
Date->tm_year + 1900 );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
return string_date;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
bool ProcessExecute( const wxString& aCommandLine, int aFlags )
|
2008-04-24 16:55:35 +00:00
|
|
|
|
{
|
2008-04-25 07:33:45 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2008-09-09 11:32:21 +00:00
|
|
|
|
int pid = wxExecute( aCommandLine );
|
2008-06-29 18:51:38 +00:00
|
|
|
|
return pid ? true : false;
|
2008-04-25 07:33:45 +00:00
|
|
|
|
#else
|
2008-09-09 11:32:21 +00:00
|
|
|
|
wxProcess* process = wxProcess::Open( aCommandLine, aFlags );
|
2008-06-29 18:51:38 +00:00
|
|
|
|
return (process != NULL) ? true : false;
|
2008-04-25 07:33:45 +00:00
|
|
|
|
#endif
|
2008-04-24 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
|
int GetTimeStamp()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
|
static int OldTimeStamp, NewTimeStamp;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
NewTimeStamp = time( NULL );
|
2011-04-19 14:28:34 +00:00
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
if( NewTimeStamp <= OldTimeStamp )
|
|
|
|
|
NewTimeStamp = OldTimeStamp + 1;
|
2011-04-19 14:28:34 +00:00
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
OldTimeStamp = NewTimeStamp;
|
2011-04-19 14:28:34 +00:00
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
return NewTimeStamp;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
const wxString& valeur_param( int valeur, wxString& buf_texte )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
|
switch( g_UserUnit )
|
2007-08-22 05:11:01 +00:00
|
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
|
case MILLIMETRES:
|
2011-06-30 06:02:07 +00:00
|
|
|
|
buf_texte.Printf( _( "%3.3f mm" ), valeur * 0.00254 );
|
2010-07-12 14:07:09 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case INCHES:
|
2007-10-11 00:11:59 +00:00
|
|
|
|
buf_texte.Printf( wxT( "%2.4f \"" ), valeur * 0.0001 );
|
2010-07-12 14:07:09 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case UNSCALED_UNITS:
|
|
|
|
|
buf_texte.Printf( wxT( "%d" ), valeur );
|
|
|
|
|
break;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
}
|
2008-02-19 00:35:45 +00:00
|
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
|
return buf_texte;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
2008-05-05 19:43:56 +00:00
|
|
|
|
|
2008-09-05 19:02:39 +00:00
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
wxString CoordinateToString( int aValue, int aInternalUnits, bool aConvertToMils )
|
|
|
|
|
{
|
|
|
|
|
wxCHECK_MSG( (aInternalUnits == EESCHEMA_INTERNAL_UNIT)
|
|
|
|
|
|| (aInternalUnits == PCB_INTERNAL_UNIT),
|
|
|
|
|
wxString( _( "*** Bad Internal Units ***" ) ),
|
|
|
|
|
wxT( "Invalid interanl units value." ) );
|
|
|
|
|
|
|
|
|
|
wxString text;
|
|
|
|
|
const wxChar* format;
|
|
|
|
|
double value = To_User_Unit( g_UserUnit, aValue, aInternalUnits );
|
|
|
|
|
|
|
|
|
|
if( g_UserUnit == INCHES )
|
|
|
|
|
{
|
|
|
|
|
if( aConvertToMils )
|
|
|
|
|
{
|
|
|
|
|
format = ( aInternalUnits == EESCHEMA_INTERNAL_UNIT ) ? wxT( "%.0f" ) : wxT( "%.1f" );
|
|
|
|
|
value *= 1000;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
format = ( aInternalUnits == EESCHEMA_INTERNAL_UNIT ) ? wxT( "%.3f" ) : wxT( "%.4f" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
format = ( aInternalUnits == EESCHEMA_INTERNAL_UNIT ) ? wxT( "%.2f" ) : wxT( "%.3f" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text.Printf( format, value );
|
|
|
|
|
|
|
|
|
|
if( g_UserUnit == INCHES )
|
|
|
|
|
text += ( aConvertToMils ) ? _( " mils" ) : _( " in" );
|
|
|
|
|
else
|
|
|
|
|
text += _( " mm" );
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxString& operator <<( wxString& aString, const wxPoint& aPos )
|
2008-05-05 19:43:56 +00:00
|
|
|
|
{
|
|
|
|
|
wxString temp;
|
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
aString << wxT( "@ (" ) << valeur_param( aPos.x, temp );
|
|
|
|
|
aString << wxT( "," ) << valeur_param( aPos.y, temp );
|
|
|
|
|
aString << wxT( ")" );
|
2008-05-05 19:43:56 +00:00
|
|
|
|
|
|
|
|
|
return aString;
|
|
|
|
|
}
|