2009-11-23 15:16:50 +00:00
|
|
|
/**************/
|
|
|
|
/* common.cpp */
|
|
|
|
/**************/
|
|
|
|
|
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 */
|
2009-06-13 17:06:07 +00:00
|
|
|
Ki_PageDescr g_Sheet_A4( wxSize( 11700, 8267 ), wxPoint( 0, 0 ), wxT( "A4" ) );
|
|
|
|
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" ) );
|
2009-11-23 15:16:50 +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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* File extension definitions. Please do not changes these. If a different
|
|
|
|
* file extension is needed, create a new definition in the application.
|
2009-11-23 15:16:50 +00:00
|
|
|
* Please note, just because they are defined as const doesn't guarantee
|
2009-04-05 20:49:15 +00:00
|
|
|
* that they cannot be changed. */
|
|
|
|
const wxString ProjectFileExtension( wxT( "pro" ) );
|
|
|
|
const wxString SchematicFileExtension( wxT( "sch" ) );
|
|
|
|
const wxString BoardFileExtension( wxT( "brd" ) );
|
|
|
|
const wxString NetlistFileExtension( wxT( "net" ) );
|
|
|
|
const wxString GerberFileExtension( wxT( "pho" ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
const wxString PdfFileExtension( wxT( "pdf" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* Proper wxFileDialog wild card definitions. */
|
|
|
|
const wxString ProjectFileWildcard( _( "Kicad project files (*.pro)|*.pro" ) );
|
2009-06-13 17:06:07 +00:00
|
|
|
const wxString BoardFileWildcard( _( "Kicad PCB files (*.brd)|*.brd" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
const wxString SchematicFileWildcard( _( "Kicad schematic files (*.sch)|*.sch" ) );
|
|
|
|
const wxString NetlistFileWildcard( _( "Kicad netlist files (*.net)|*.net" ) );
|
|
|
|
const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) );
|
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;
|
|
|
|
int g_GridColor = DARKGRAY;
|
|
|
|
wxString g_UserLibDirBuffer;
|
|
|
|
int g_DebugLevel;
|
|
|
|
int g_MouseOldButtons;
|
|
|
|
int g_KeyPressed;
|
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
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Handle the preferred editor for browsing report files:
|
2009-06-13 17:06:07 +00:00
|
|
|
int g_UnitMetric; // display units mm = 1, inches = 0, cm = 2
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* Draw color for moving objects: */
|
2009-06-13 17:06:07 +00:00
|
|
|
int g_GhostColor;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
/* predefined colors used in kicad.
|
|
|
|
* Please: if you change a value, remember these values are carefully chosen
|
|
|
|
* to have good results in pcbnew, that uses the ORed value of basic colors
|
|
|
|
* 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
|
|
|
};
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/** function SetLocaleTo_C_standard
|
2009-11-23 15:16:50 +00:00
|
|
|
* because kicad is internationalized, switch internalization to "C" standard
|
2009-06-13 17:06:07 +00:00
|
|
|
* i.e. uses the . (dot) as separator in print/read float numbers
|
2009-11-23 15:16:50 +00:00
|
|
|
* (some countries (France, Germany ..) use , (comma) as separator)
|
|
|
|
* This function must be called before read or write ascii files using float
|
|
|
|
* numbers in data the SetLocaleTo_C_standard function must be called after
|
|
|
|
* reading or writing the file
|
2009-06-13 17:06:07 +00:00
|
|
|
*
|
|
|
|
* This is wrapper to the C setlocale( LC_NUMERIC, "C" ) function,
|
|
|
|
* but could make more easier an optional use of locale in kicad
|
|
|
|
*/
|
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
|
|
|
|
2008-06-06 16:39:45 +00:00
|
|
|
/** function SetLocaleTo_Default
|
2009-11-23 15:16:50 +00:00
|
|
|
* because kicad is internationalized, switch internalization to default
|
2009-06-13 17:06:07 +00:00
|
|
|
* to use the default separator in print/read float numbers
|
2009-11-23 15:16:50 +00:00
|
|
|
* (. (dot) but some countries (France, Germany ..) use , (comma) as separator)
|
2009-06-13 17:06:07 +00:00
|
|
|
* This function must be called after a call to SetLocaleTo_C_standard
|
2008-09-09 11:32:21 +00:00
|
|
|
*
|
2009-06-13 17:06:07 +00:00
|
|
|
* This is wrapper to the C setlocale( LC_NUMERIC, "" ) function,
|
|
|
|
* but could make more easier an optional use of locale in kicad
|
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
|
|
|
{
|
|
|
|
setlocale( LC_NUMERIC, "" ); // revert to the current locale
|
|
|
|
}
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
|
2009-06-13 17:06:07 +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();
|
|
|
|
if( size.GetWidth() < width + 10 )
|
|
|
|
{
|
|
|
|
size.SetWidth( width + 10 );
|
|
|
|
aCtrl->SetSizeHints( size );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-13 17:06:07 +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)
|
2009-06-13 17:06:07 +00:00
|
|
|
m_LeftMargin = LEFTMARGIN;
|
|
|
|
m_RightMargin = RIGHTMARGIN;
|
|
|
|
m_TopMargin = TOPMARGIN;
|
2008-11-05 11:41:15 +00:00
|
|
|
m_BottomMargin = BOTTOMMARGIN;
|
|
|
|
#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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString ReturnUnitSymbol( int Units )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxString label;
|
|
|
|
|
|
|
|
switch( Units )
|
|
|
|
{
|
|
|
|
case INCHES:
|
|
|
|
label = _( " (\"):" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MILLIMETRE:
|
|
|
|
label = _( " (mm):" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
wxString GetUnitsLabel( int units )
|
|
|
|
{
|
|
|
|
wxString label;
|
|
|
|
|
|
|
|
switch( units )
|
|
|
|
{
|
|
|
|
case INCHES:
|
|
|
|
label = _( "inches" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MILLIMETRE:
|
|
|
|
label = _( "millimeters" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CENTIMETRE:
|
|
|
|
label = _( "centimeters" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
label = _( "Unknown" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*
|
2009-03-02 13:43:52 +00:00
|
|
|
* Add string " (mm):" or " ("):" to the static text Stext.
|
2007-08-22 05:11:01 +00:00
|
|
|
* Used in dialog boxes for entering values depending on selected units
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
void AddUnitSymbol( wxStaticText& Stext, int Units )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-11 10:27:21 +00:00
|
|
|
wxString msg = Stext.GetLabel();
|
|
|
|
msg += ReturnUnitSymbol( Units );
|
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
|
|
|
/*
|
2009-03-02 13:43:52 +00:00
|
|
|
* Convert the number Value in a string according to the internal units
|
2007-08-22 05:11:01 +00:00
|
|
|
* and the selected unit (g_UnitMetric) and put it in the wxTextCtrl TextCtrl
|
|
|
|
*/
|
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
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxString msg = ReturnStringFromValue( g_UnitMetric, Value, Internal_Unit );
|
|
|
|
|
|
|
|
TextCtr.SetValue( msg );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/*
|
|
|
|
* Convert the Value in the wxTextCtrl TextCtrl in an integer,
|
2007-08-22 05:11:01 +00:00
|
|
|
* according to the internal units and the selected unit (g_UnitMetric)
|
|
|
|
*/
|
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();
|
|
|
|
|
|
|
|
value = ReturnValueFromString( g_UnitMetric, msg, Internal_Unit );
|
|
|
|
|
|
|
|
return value;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
/** Function ReturnStringFromValue
|
|
|
|
* Return the string from Value, according to units (inch, mm ...) for display,
|
|
|
|
* and the initial unit for value
|
|
|
|
* @param aUnit = display units (INCHES, MILLIMETRE ..)
|
|
|
|
* @param aValue = value in Internal_Unit
|
|
|
|
* @param aInternal_Unit = units per inch for Value
|
|
|
|
* @param aAdd_unit_symbol = true to add symbol unit to the string value
|
2009-11-23 15:16:50 +00:00
|
|
|
* @return a wxString what contains value and optionally the symbol unit
|
|
|
|
* (like 2.000 mm)
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString ReturnStringFromValue( int aUnits, int aValue, int aInternal_Unit,
|
|
|
|
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;
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
if( aUnits >= CENTIMETRE )
|
|
|
|
StringValue << aValue;
|
2007-08-22 05:11:01 +00:00
|
|
|
else
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
value_to_print = To_User_Unit( (bool) aUnits, (double) aValue,
|
|
|
|
aInternal_Unit );
|
|
|
|
StringValue.Printf( ( aInternal_Unit > 1000 ) ? wxT( "%.4f" ) :
|
|
|
|
wxT( "%.3f" ),
|
|
|
|
value_to_print );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 11:32:21 +00:00
|
|
|
if( aAdd_unit_symbol )
|
|
|
|
switch( aUnits )
|
|
|
|
{
|
|
|
|
case INCHES:
|
|
|
|
StringValue += _( " \"" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MILLIMETRE:
|
|
|
|
StringValue += _( " mm" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*
|
2009-03-02 13:43:52 +00:00
|
|
|
* Return the string from Value, according to units (inch, mm ...) for display,
|
2007-08-22 05:11:01 +00:00
|
|
|
* and the initial unit for value
|
|
|
|
* Unit = display units (INCH, MM ..)
|
|
|
|
* Value = text
|
|
|
|
* Internal_Unit = units per inch for computed value
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
int ReturnValueFromString( int Units, 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;
|
|
|
|
|
|
|
|
TextValue.ToDouble( &dtmp );
|
|
|
|
if( Units >= CENTIMETRE )
|
2009-04-05 20:49:15 +00:00
|
|
|
Value = wxRound( dtmp );
|
2007-08-22 05:11:01 +00:00
|
|
|
else
|
2009-06-13 17:06:07 +00:00
|
|
|
Value = From_User_Unit( (bool) Units, 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
|
|
|
|
2009-04-28 19:34:42 +00:00
|
|
|
/**
|
|
|
|
* Function wxStringSplit
|
|
|
|
* Split a String to a String List when founding 'splitter'
|
|
|
|
* @return the list
|
|
|
|
* @param txt : wxString : a String text
|
|
|
|
* @param splitter : wxChar : the 'split' character
|
|
|
|
*/
|
2009-06-13 17:06:07 +00:00
|
|
|
wxArrayString* wxStringSplit( wxString txt, wxChar splitter )
|
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
|
|
|
{
|
2009-06-13 17:06:07 +00:00
|
|
|
int index = txt.Find( splitter );
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
break;
|
2009-05-02 07:35:04 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
wxString tmp;
|
|
|
|
tmp = txt.Mid( 0, index );
|
|
|
|
txt = txt.Mid( index + 1, txt.size() - index );
|
|
|
|
list->Add( tmp );
|
2009-04-28 19:34:42 +00:00
|
|
|
}
|
2009-05-02 07:35:04 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
if( !txt.IsEmpty() )
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2009-06-13 17:06:07 +00:00
|
|
|
list->Add( txt );
|
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
|
|
|
|
2009-03-12 15:24:52 +00:00
|
|
|
/**
|
|
|
|
* Function To_User_Unit
|
|
|
|
* Convert in inch or mm the variable "val" (double)given in internal units
|
|
|
|
* @return the converted value, in double
|
|
|
|
* @param is_metric : true if the result must be returned in mm , false if inches
|
|
|
|
* @param val : double : the given value
|
|
|
|
* @param internal_unit_value = internal units per inch
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
double To_User_Unit( bool is_metric, double val, int internal_unit_value )
|
2009-03-12 15:24:52 +00:00
|
|
|
{
|
|
|
|
double value;
|
|
|
|
|
|
|
|
if( is_metric )
|
2009-10-14 19:43:31 +00:00
|
|
|
value = val * 25.4000508001016 / internal_unit_value;
|
2009-03-12 15:24:52 +00:00
|
|
|
else
|
|
|
|
value = val / internal_unit_value;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/*
|
|
|
|
* Return in internal units the value "val" given in inch or mm
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
int From_User_Unit( bool is_metric, 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
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( is_metric )
|
2009-10-14 19:43:31 +00:00
|
|
|
value = val * internal_unit_value / 25.4000508001016;
|
2007-08-22 05:11:01 +00:00
|
|
|
else
|
|
|
|
value = val * internal_unit_value;
|
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-03-02 13:43:52 +00:00
|
|
|
/*
|
|
|
|
* Return the string date "day month year" like "23 jun 2005"
|
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-03-02 13:43:52 +00:00
|
|
|
/*
|
|
|
|
* My memory allocation
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
void* MyMalloc( size_t nb_octets )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
void* pt_mem;
|
|
|
|
|
|
|
|
if( nb_octets == 0 )
|
|
|
|
{
|
|
|
|
DisplayError( NULL, wxT( "Allocate 0 bytes !!" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pt_mem = malloc( nb_octets );
|
|
|
|
if( pt_mem == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "Out of memory: allocation %d bytes" ), nb_octets );
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
}
|
|
|
|
return pt_mem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
/**
|
|
|
|
* Function ProcessExecute
|
|
|
|
* runs a child process.
|
|
|
|
* @param aCommandLine The process and any arguments to it all in a single string.
|
|
|
|
* @param aFlags The same args as allowed for wxExecute()
|
|
|
|
* @return bool - true if success, else false
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/*
|
|
|
|
* My memory allocation, memory space is cleared
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
void* MyZMalloc( size_t nb_octets )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
void* pt_mem = MyMalloc( nb_octets );
|
|
|
|
|
|
|
|
if( pt_mem )
|
|
|
|
memset( pt_mem, 0, nb_octets );
|
|
|
|
return pt_mem;
|
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 MyFree( void* pt_mem )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
if( pt_mem )
|
|
|
|
free( pt_mem );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum textbox {
|
2007-08-22 05:11:01 +00:00
|
|
|
ID_TEXTBOX_LIST = 8010
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_TextFrame, wxDialog )
|
2009-11-23 15:16:50 +00:00
|
|
|
EVT_LISTBOX_DCLICK( ID_TEXTBOX_LIST, WinEDA_TextFrame::D_ClickOnList )
|
|
|
|
EVT_LISTBOX( ID_TEXTBOX_LIST, WinEDA_TextFrame::D_ClickOnList )
|
|
|
|
EVT_CLOSE( WinEDA_TextFrame::OnClose )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
WinEDA_TextFrame::WinEDA_TextFrame( wxWindow* parent,
|
2009-03-02 13:43:52 +00:00
|
|
|
const wxString& title ) :
|
2009-06-13 17:06:07 +00:00
|
|
|
wxDialog( parent,
|
|
|
|
-1, title,
|
|
|
|
wxPoint( -1, -1 ),
|
|
|
|
wxSize( 250, 350 ),
|
|
|
|
wxDEFAULT_DIALOG_STYLE |
|
|
|
|
wxFRAME_FLOAT_ON_PARENT |
|
|
|
|
MAYBE_RESIZE_BORDER )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxSize size;
|
|
|
|
|
|
|
|
m_Parent = parent;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
CentreOnParent();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
size = GetClientSize();
|
2009-03-02 13:43:52 +00:00
|
|
|
m_List = new wxListBox( this,
|
|
|
|
ID_TEXTBOX_LIST,
|
|
|
|
wxPoint( 0, 0 ),
|
|
|
|
size,
|
|
|
|
0, NULL,
|
|
|
|
wxLB_ALWAYS_SB | wxLB_SINGLE );
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
SetReturnCode( -1 );
|
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 WinEDA_TextFrame::Append( const wxString& text )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
m_List->Append( text );
|
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 WinEDA_TextFrame::D_ClickOnList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
int ii = m_List->GetSelection();
|
|
|
|
|
|
|
|
EndModal( ii );
|
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 WinEDA_TextFrame::OnClose( wxCloseEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
EndModal( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void Affiche_1_Parametre( WinEDA_DrawFrame* frame, int pos_X,
|
|
|
|
const wxString& texte_H, const wxString& texte_L,
|
2009-03-02 13:43:52 +00:00
|
|
|
int color )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->MsgPanel->Affiche_1_Parametre( pos_X, texte_H, texte_L, color );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +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 );
|
|
|
|
if( NewTimeStamp <= OldTimeStamp )
|
|
|
|
NewTimeStamp = OldTimeStamp + 1;
|
|
|
|
OldTimeStamp = NewTimeStamp;
|
|
|
|
return NewTimeStamp;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
/* Returns to display the value of a parameter, by type of units selected
|
|
|
|
* Input: value in mils, buffer text
|
|
|
|
* Returns to buffer: text: value expressed in inches or millimeters
|
|
|
|
* Followed by " or mm
|
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
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
if( g_UnitMetric )
|
|
|
|
{
|
2007-10-11 00:11:59 +00:00
|
|
|
buf_texte.Printf( wxT( "%3.3f mm" ), valeur * 0.00254 );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-11 00:11:59 +00:00
|
|
|
buf_texte.Printf( wxT( "%2.4f \"" ), valeur * 0.0001 );
|
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
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
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;
|
|
|
|
}
|