Commit 155ea57c authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

LOCALE_IO toggle implementation for locale switches on scripting; code...

LOCALE_IO toggle implementation for locale switches on scripting; code cleanups to comply with kicad coding style policy
parent cefd3cd5
...@@ -36,12 +36,8 @@ void FOOTPRINT_WIZARD::register_wizard() ...@@ -36,12 +36,8 @@ void FOOTPRINT_WIZARD::register_wizard()
FOOTPRINT_WIZARDS::register_wizard( this ); FOOTPRINT_WIZARDS::register_wizard( this );
} }
/**
* FOOTPRINT_WIZARD system wide static list
*/
std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARDS::m_FootprintWizards; std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARDS::m_FootprintWizards;
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex ) FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex )
{ {
return m_FootprintWizards[aIndex]; return m_FootprintWizards[aIndex];
...@@ -50,17 +46,17 @@ FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex ) ...@@ -50,17 +46,17 @@ FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex )
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( wxString aName ) FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( wxString aName )
{ {
int max = GetSize(); int max = GetSize();
for( int i=0; i<max; i++ ) for( int i=0; i<max; i++ )
{ {
FOOTPRINT_WIZARD *wizard = GetWizard( i ); FOOTPRINT_WIZARD *wizard = GetWizard( i );
wxString name = wizard->GetName(); wxString name = wizard->GetName();
if ( name.Cmp( aName ) ) if ( name.Cmp( aName ) )
return wizard; return wizard;
} }
return NULL; return NULL;
} }
...@@ -71,10 +67,10 @@ int FOOTPRINT_WIZARDS::GetSize() ...@@ -71,10 +67,10 @@ int FOOTPRINT_WIZARDS::GetSize()
void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard) void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard)
{ {
wxString name = aWizard->GetName(); wxString name = aWizard->GetName();
m_FootprintWizards.push_back( aWizard ); m_FootprintWizards.push_back( aWizard );
} }
......
...@@ -134,6 +134,9 @@ public: ...@@ -134,6 +134,9 @@ public:
class FOOTPRINT_WIZARDS class FOOTPRINT_WIZARDS
{ {
private: private:
/**
* FOOTPRINT_WIZARD system wide static list
*/
static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards; static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards;
public: public:
......
...@@ -20,25 +20,28 @@ ...@@ -20,25 +20,28 @@
#include <dialogs/dialog_footprint_wizard_list.h> #include <dialogs/dialog_footprint_wizard_list.h>
#include <base_units.h> #include <base_units.h>
#define NEXT_PART 1 #define NEXT_PART 1
#define NEW_PART 0 #define NEW_PART 0
#define PREVIOUS_PART -1 #define PREVIOUS_PART -1
void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
{ {
wxString msg; wxString msg;
int page; int page;
switch( event.GetId() ) switch( event.GetId() )
{ {
case ID_FOOTPRINT_WIZARD_NEXT: case ID_FOOTPRINT_WIZARD_NEXT:
m_PageList->SetSelection( m_PageList->GetSelection()+1, true ); m_PageList->SetSelection( m_PageList->GetSelection() + 1, true );
break; break;
case ID_FOOTPRINT_WIZARD_PREVIOUS: case ID_FOOTPRINT_WIZARD_PREVIOUS:
page = m_PageList->GetSelection()-1; page = m_PageList->GetSelection() - 1;
if (page<0) page=0;
if( page<0 )
page = 0;
m_PageList->SetSelection( page, true ); m_PageList->SetSelection( page, true );
break; break;
...@@ -50,17 +53,19 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -50,17 +53,19 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
} }
} }
/* Function OnLeftClick /* Function OnLeftClick
* Captures a left click event in the dialog * Captures a left click event in the dialog
* *
*/ */
void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{ {
} }
/* Function OnRightClick /* Function OnRightClick
* Captures a right click event in the dialog * Captures a right click event in the dialog
* *
*/ */
bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{ {
...@@ -71,12 +76,12 @@ bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopM ...@@ -71,12 +76,12 @@ bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopM
/* Displays the name of the current opened library in the caption */ /* Displays the name of the current opened library in the caption */
void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos() void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
{ {
wxString msg; wxString msg;
msg = _( "Footprint Wizard" ); msg = _( "Footprint Wizard" );
msg << wxT( " [" ); msg << wxT( " [" );
if( ! m_wizardName.IsEmpty() ) if( !m_wizardName.IsEmpty() )
msg << m_wizardName; msg << m_wizardName;
else else
msg += _( "no wizard selected" ); msg += _( "no wizard selected" );
...@@ -86,6 +91,7 @@ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos() ...@@ -86,6 +91,7 @@ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
SetTitle( msg ); SetTitle( msg );
} }
void FOOTPRINT_WIZARD_FRAME::ReloadFootprint() void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
{ {
if( m_FootprintWizard == NULL ) if( m_FootprintWizard == NULL )
...@@ -94,25 +100,28 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint() ...@@ -94,25 +100,28 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
SetCurItem( NULL ); SetCurItem( NULL );
// Delete the current footprint // Delete the current footprint
GetBoard()->m_Modules.DeleteAll(); GetBoard()->m_Modules.DeleteAll();
MODULE *m = m_FootprintWizard->GetModule(); MODULE* m = m_FootprintWizard->GetModule();
if ( m )
if( m )
{ {
/* Here we should make a copy of the object before adding to board*/ /* Here we should make a copy of the object before adding to board*/
m->SetParent((EDA_ITEM*)GetBoard()); m->SetParent( (EDA_ITEM*) GetBoard() );
GetBoard()->m_Modules.Append(m); GetBoard()->m_Modules.Append( m );
wxPoint p( 0 , 0 ); wxPoint p( 0, 0 );
m->SetPosition( p ); m->SetPosition( p );
} }
else else
{ {
printf ("m_FootprintWizard->GetModule() returns NULL\n"); printf( "m_FootprintWizard->GetModule() returns NULL\n" );
} }
m_canvas->Refresh(); m_canvas->Refresh();
} }
MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint() MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
{ {
if ( m_FootprintWizard ) if( m_FootprintWizard )
{ {
return m_FootprintWizard->GetModule(); return m_FootprintWizard->GetModule();
} }
...@@ -122,16 +131,17 @@ MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint() ...@@ -122,16 +131,17 @@ MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
} }
} }
void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard() void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
{ {
DIALOG_FOOTPRINT_WIZARD_LIST *selectWizard = DIALOG_FOOTPRINT_WIZARD_LIST* selectWizard =
new DIALOG_FOOTPRINT_WIZARD_LIST( this ); new DIALOG_FOOTPRINT_WIZARD_LIST( this );
selectWizard->ShowModal(); selectWizard->ShowModal();
m_FootprintWizard = selectWizard->GetWizard(); m_FootprintWizard = selectWizard->GetWizard();
if ( m_FootprintWizard ) if( m_FootprintWizard )
{ {
m_wizardName = m_FootprintWizard->GetName(); m_wizardName = m_FootprintWizard->GetName();
m_wizardDescription = m_FootprintWizard->GetDescription(); m_wizardDescription = m_FootprintWizard->GetDescription();
...@@ -142,64 +152,63 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard() ...@@ -142,64 +152,63 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
DisplayWizardInfos(); DisplayWizardInfos();
ReCreatePageList(); ReCreatePageList();
ReCreateParameterList(); ReCreateParameterList();
} }
void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event ) void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
{ {
SelectFootprintWizard(); SelectFootprintWizard();
} }
/** /**
* Function SelectCurrentFootprint * Function SelectCurrentFootprint
* Selects the current footprint name and display it * Selects the current footprint name and display it
*/ */
void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event ) void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
{ {
int page = m_PageList->GetSelection(); int page = m_PageList->GetSelection();
if ( page<0 ) if( page<0 )
return; return;
int n=m_ParameterGrid->GetNumberRows(); int n = m_ParameterGrid->GetNumberRows();
wxArrayString arr; wxArrayString arr;
wxArrayString ptList = m_FootprintWizard->GetParameterTypes(page); wxArrayString ptList = m_FootprintWizard->GetParameterTypes( page );
for ( int i=0; i<n; i++ ) for( int i = 0; i<n; i++ )
{ {
wxString value = m_ParameterGrid->GetCellValue( i, 1 ); wxString value = m_ParameterGrid->GetCellValue( i, 1 );
// if this parameter is expected to be an internal // if this parameter is expected to be an internal
// unit convert it back from the user format // unit convert it back from the user format
if (ptList[i]==wxT("IU")) if( ptList[i]==wxT( "IU" ) )
{ {
LOCALE_IO toggle;
double dValue; double dValue;
value.ToDouble( &dValue ); value.ToDouble( &dValue );
// convert from mils to inches where it's needed // convert from mils to inches where it's needed
if (g_UserUnit==INCHES) dValue = dValue / 1000.0; if( g_UserUnit==INCHES )
dValue = From_User_Unit( g_UserUnit, dValue); dValue = dValue / 1000.0;
value.Printf( wxT("%lf"), dValue ); dValue = From_User_Unit( g_UserUnit, dValue );
value.Printf( wxT( "%lf" ), dValue );
} }
// If our locale is set to use , for decimal point, just change it // If our locale is set to use , for decimal point, just change it
// to be scripting compatible // to be scripting compatible
value.Replace( wxT( "," ), wxT( "." ) );
arr.Add( value ); arr.Add( value );
} }
wxString res = m_FootprintWizard->SetParameterValues( page, arr ); wxString res = m_FootprintWizard->SetParameterValues( page, arr );
ReloadFootprint(); ReloadFootprint();
DisplayWizardInfos(); DisplayWizardInfos();
} }
...@@ -207,8 +216,8 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event ) ...@@ -207,8 +216,8 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
* Function RedrawActiveWindow * Function RedrawActiveWindow
* Display the current selected component. * Display the current selected component.
* If the component is an alias, the ROOT component is displayed * If the component is an alias, the ROOT component is displayed
* *
*/ */
void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{ {
if( !GetBoard() ) if( !GetBoard() )
...@@ -219,7 +228,7 @@ void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) ...@@ -219,7 +228,7 @@ void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
MODULE* module = GetBoard()->m_Modules; MODULE* module = GetBoard()->m_Modules;
if ( module ) if( module )
SetMsgPanel( module ); SetMsgPanel( module );
m_canvas->DrawCrossHair( DC ); m_canvas->DrawCrossHair( DC );
......
...@@ -63,7 +63,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME ) ...@@ -63,7 +63,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
/* Toolbar events */ /* Toolbar events */
EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD,
FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
...@@ -79,7 +79,8 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME ) ...@@ -79,7 +79,8 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
/* listbox events */ /* listbox events */
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList ) EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
EVT_GRID_CMD_CELL_CHANGE( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) EVT_GRID_CMD_CELL_CHANGE( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset ) EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset )
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -92,11 +93,11 @@ END_EVENT_TABLE() ...@@ -92,11 +93,11 @@ END_EVENT_TABLE()
*/ */
static wxAcceleratorEntry accels[] = static wxAcceleratorEntry accels[] =
{ {
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_ZOOM_IN ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_ZOOM_IN ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_ZOOM_OUT ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_ZOOM_OUT ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F3, ID_ZOOM_REDRAW ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F3, ID_ZOOM_REDRAW ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_POPUP_ZOOM_CENTER ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_POPUP_ZOOM_CENTER ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_HOME, ID_ZOOM_PAGE ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_HOME, ID_ZOOM_PAGE ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_SPACE, ID_SET_RELATIVE_OFFSET ) wxAcceleratorEntry( wxACCEL_NORMAL, WXK_SPACE, ID_SET_RELATIVE_OFFSET )
}; };
...@@ -118,9 +119,9 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -118,9 +119,9 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
{ {
wxAcceleratorTable table( ACCEL_TABLE_CNT, accels ); wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
m_FrameName = FOOTPRINT_WIZARD_FRAME_NAME; m_FrameName = FOOTPRINT_WIZARD_FRAME_NAME;
m_configPath = wxT( "FootprintWizard" ); m_configPath = wxT( "FootprintWizard" );
m_showAxis = true; // true to draw axis. m_showAxis = true; // true to draw axis.
// Give an icon // Give an icon
...@@ -131,20 +132,20 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -131,20 +132,20 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr; m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr;
m_FootprintWizard = NULL; m_FootprintWizard = NULL;
m_PageList= NULL; m_PageList = NULL;
m_ParameterGrid = NULL; m_ParameterGrid = NULL;
m_PageListWindow = NULL; m_PageListWindow = NULL;
m_ParameterGridWindow = NULL; m_ParameterGridWindow = NULL;
m_Semaphore = semaphore; m_Semaphore = semaphore;
m_wizardName.Empty(); m_wizardName.Empty();
if( m_Semaphore ) if( m_Semaphore )
SetModalMode(true); SetModalMode( true );
SetBoard( new BOARD() ); SetBoard( new BOARD() );
// Ensure all layers and items are visible: // Ensure all layers and items are visible:
GetBoard()->SetVisibleAlls(); GetBoard()->SetVisibleAlls();
SetScreen( new PCB_SCREEN(GetPageSizeIU()) ); SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
GetScreen()->m_Center = true; // Center coordinate origins on screen. GetScreen()->m_Center = true; // Center coordinate origins on screen.
LoadSettings(); LoadSettings();
...@@ -154,14 +155,14 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -154,14 +155,14 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
ReCreateHToolbar(); ReCreateHToolbar();
ReCreateVToolbar(); ReCreateVToolbar();
wxSize size = GetClientSize(); wxSize size = GetClientSize();
size.y -= m_MsgFrameHeight + 2; size.y -= m_MsgFrameHeight + 2;
m_PageListSize.y = -1; m_PageListSize.y = -1;
wxPoint win_pos( 0, 0 ); wxPoint win_pos( 0, 0 );
// Creates the libraries window display // Creates the libraries window display
m_PageListWindow = m_PageListWindow =
new wxSashLayoutWindow( this, ID_FOOTPRINT_WIZARD_PAGES_WINDOW, win_pos, new wxSashLayoutWindow( this, ID_FOOTPRINT_WIZARD_PAGES_WINDOW, win_pos,
wxDefaultSize, wxCLIP_CHILDREN | wxSW_3D, wxDefaultSize, wxCLIP_CHILDREN | wxSW_3D,
...@@ -171,39 +172,38 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -171,39 +172,38 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
m_PageListWindow->SetSashVisible( wxSASH_RIGHT, true ); m_PageListWindow->SetSashVisible( wxSASH_RIGHT, true );
m_PageListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE ); m_PageListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_PageList = new wxListBox( m_PageListWindow, ID_FOOTPRINT_WIZARD_PAGE_LIST, m_PageList = new wxListBox( m_PageListWindow, ID_FOOTPRINT_WIZARD_PAGE_LIST,
wxPoint( 0, 0 ), wxDefaultSize, wxPoint( 0, 0 ), wxDefaultSize,
0, NULL, wxLB_HSCROLL ); 0, NULL, wxLB_HSCROLL );
// Creates the component window display // Creates the component window display
m_ParameterGridSize.y = size.y; m_ParameterGridSize.y = size.y;
win_pos.x = m_PageListSize.x; win_pos.x = m_PageListSize.x;
m_ParameterGridWindow = new wxSashLayoutWindow( this, m_ParameterGridWindow = new wxSashLayoutWindow( this,
ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW, ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW,
win_pos, wxDefaultSize, win_pos, wxDefaultSize,
wxCLIP_CHILDREN | wxSW_3D, wxCLIP_CHILDREN | wxSW_3D,
wxT( "ParameterList" ) ); wxT( "ParameterList" ) );
m_ParameterGridWindow->SetOrientation( wxLAYOUT_VERTICAL ); m_ParameterGridWindow->SetOrientation( wxLAYOUT_VERTICAL );
m_ParameterGridWindow->SetSashVisible( wxSASH_RIGHT, true ); m_ParameterGridWindow->SetSashVisible( wxSASH_RIGHT, true );
m_ParameterGridWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE ); m_ParameterGridWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_ParameterGrid = new wxGrid( m_ParameterGridWindow, m_ParameterGrid = new wxGrid( m_ParameterGridWindow,
ID_FOOTPRINT_WIZARD_PARAMETER_LIST, ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
wxPoint( 0 , 0 ), wxPoint( 0, 0 ),
wxDefaultSize ); wxDefaultSize );
m_ParameterGrid->CreateGrid( 1, 3 ); m_ParameterGrid->CreateGrid( 1, 3 );
// Columns // Columns
m_ParameterGrid->AutoSizeColumns(); m_ParameterGrid->AutoSizeColumns();
m_ParameterGrid->SetColLabelSize( 20 ); m_ParameterGrid->SetColLabelSize( 20 );
m_ParameterGrid->SetColLabelValue( 0, _("Parameter") ); m_ParameterGrid->SetColLabelValue( 0, _( "Parameter" ) );
m_ParameterGrid->SetColLabelValue( 1, _("Value") ); m_ParameterGrid->SetColLabelValue( 1, _( "Value" ) );
m_ParameterGrid->SetColLabelValue( 2, _("Units") ); m_ParameterGrid->SetColLabelValue( 2, _( "Units" ) );
m_ParameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE ); m_ParameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
ReCreatePageList(); ReCreatePageList();
DisplayWizardInfos(); DisplayWizardInfos();
...@@ -214,29 +214,29 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -214,29 +214,29 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
m_auimgr.SetManagedWindow( this ); m_auimgr.SetManagedWindow( this );
EDA_PANEINFO horiz; EDA_PANEINFO horiz;
horiz.HorizontalToolbarPane(); horiz.HorizontalToolbarPane();
EDA_PANEINFO vert; EDA_PANEINFO vert;
vert.VerticalToolbarPane(); vert.VerticalToolbarPane();
EDA_PANEINFO info; EDA_PANEINFO info;
info.InfoToolbarPane(); info.InfoToolbarPane();
EDA_PANEINFO mesg; EDA_PANEINFO mesg;
mesg.MessageToolbarPane(); mesg.MessageToolbarPane();
// Manage main toolbal // Manage main toolbal
m_auimgr.AddPane( m_mainToolBar, m_auimgr.AddPane( m_mainToolBar,
wxAuiPaneInfo( horiz ).Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) ); wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) );
wxSize minsize( 60, -1 ); wxSize minsize( 60, -1 );
// Manage the left window (list of pages) // Manage the left window (list of pages)
if( m_PageListWindow ) if( m_PageListWindow )
m_auimgr.AddPane( m_PageListWindow, wxAuiPaneInfo( info ).Name( wxT( "m_PageList" ) ). m_auimgr.AddPane( m_PageListWindow, wxAuiPaneInfo( info ).Name( wxT( "m_PageList" ) ).
Left().Row( 0 )); Left().Row( 0 ) );
// Manage the list of parameters) // Manage the list of parameters)
m_auimgr.AddPane( m_ParameterGridWindow, m_auimgr.AddPane( m_ParameterGridWindow,
...@@ -249,7 +249,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -249,7 +249,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
// Manage the message panel // Manage the message panel
m_auimgr.AddPane( m_messagePanel, m_auimgr.AddPane( m_messagePanel,
wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer( 10 ) );
/* Now the minimum windows are fixed, set library list /* Now the minimum windows are fixed, set library list
* and component list of the previous values from last viewlib use * and component list of the previous values from last viewlib use
...@@ -259,6 +259,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, ...@@ -259,6 +259,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_PageListWindow ); wxAuiPaneInfo& pane = m_auimgr.GetPane( m_PageListWindow );
pane.MinSize( wxSize( m_PageListSize.x, -1 ) ); pane.MinSize( wxSize( m_PageListSize.x, -1 ) );
} }
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_ParameterGridWindow ); wxAuiPaneInfo& pane = m_auimgr.GetPane( m_ParameterGridWindow );
pane.MinSize( wxSize( m_ParameterGridSize.x, -1 ) ); pane.MinSize( wxSize( m_ParameterGridSize.x, -1 ) );
...@@ -292,18 +293,19 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME() ...@@ -292,18 +293,19 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME()
void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event ) void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
wxCommandEvent fakeEvent; wxCommandEvent fakeEvent;
ExportSelectedFootprint( fakeEvent ); ExportSelectedFootprint( fakeEvent );
} }
void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent ) void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
{ {
SaveSettings(); SaveSettings();
if( m_Semaphore ) if( m_Semaphore )
{ {
m_Semaphore->Post(); m_Semaphore->Post();
SetModalMode(false); SetModalMode( false );
// This window will be destroyed by the calling function, // This window will be destroyed by the calling function,
// to avoid side effects // to avoid side effects
} }
...@@ -311,8 +313,6 @@ void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent ) ...@@ -311,8 +313,6 @@ void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
{ {
Destroy(); Destroy();
} }
} }
...@@ -330,6 +330,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event ) ...@@ -330,6 +330,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event )
switch( event.GetId() ) switch( event.GetId() )
{ {
case ID_FOOTPRINT_WIZARD_WINDOW: case ID_FOOTPRINT_WIZARD_WINDOW:
if( m_PageListWindow ) if( m_PageListWindow )
{ {
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_PageListWindow ); wxAuiPaneInfo& pane = m_auimgr.GetPane( m_PageListWindow );
...@@ -337,15 +338,16 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event ) ...@@ -337,15 +338,16 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event )
pane.MinSize( m_PageListSize ); pane.MinSize( m_PageListSize );
m_auimgr.Update(); m_auimgr.Update();
} }
break; break;
case ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW: case ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW:
{ {
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_ParameterGridWindow ); wxAuiPaneInfo& pane = m_auimgr.GetPane( m_ParameterGridWindow );
m_ParameterGridSize.x = event.GetDragRect().width; m_ParameterGridSize.x = event.GetDragRect().width;
pane.MinSize( m_ParameterGridSize ); pane.MinSize( m_ParameterGridSize );
m_auimgr.Update(); m_auimgr.Update();
} }
break; break;
} }
} }
...@@ -363,6 +365,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv ) ...@@ -363,6 +365,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
SizeEv.Skip(); SizeEv.Skip();
} }
/* Function OnSetRelativeOffset /* Function OnSetRelativeOffset
* Updates the cursor position and the status bar * Updates the cursor position and the status bar
* *
...@@ -373,6 +376,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event ) ...@@ -373,6 +376,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
UpdateStatusBar(); UpdateStatusBar();
} }
/* Function ReCreatePageList /* Function ReCreatePageList
* It recreates the list of pages for a new loaded wizard * It recreates the list of pages for a new loaded wizard
* *
...@@ -382,12 +386,13 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList() ...@@ -382,12 +386,13 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
if( m_PageList == NULL ) if( m_PageList == NULL )
return; return;
if (m_FootprintWizard == NULL) if( m_FootprintWizard == NULL )
return; return;
m_PageList->Clear(); m_PageList->Clear();
int max_page = m_FootprintWizard->GetNumParameterPages(); int max_page = m_FootprintWizard->GetNumParameterPages();
for ( int i=0; i<max_page; i++)
for( int i = 0; i<max_page; i++ )
{ {
wxString name = m_FootprintWizard->GetParameterPageName( i ); wxString name = m_FootprintWizard->GetParameterPageName( i );
m_PageList->Append( name ); m_PageList->Append( name );
...@@ -401,6 +406,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList() ...@@ -401,6 +406,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
m_canvas->Refresh(); m_canvas->Refresh();
} }
/* Function ReCreateParameterList /* Function ReCreateParameterList
* It creates the parameter grid for a certain wizard page of the current wizard * It creates the parameter grid for a certain wizard page of the current wizard
* *
...@@ -411,12 +417,12 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList() ...@@ -411,12 +417,12 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
if( m_ParameterGrid == NULL ) if( m_ParameterGrid == NULL )
return; return;
if (m_FootprintWizard == NULL ) if( m_FootprintWizard == NULL )
return; return;
int page = m_PageList->GetSelection(); int page = m_PageList->GetSelection();
if (page<0) if( page<0 )
return; return;
m_ParameterGrid->ClearGrid(); m_ParameterGrid->ClearGrid();
...@@ -429,58 +435,59 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList() ...@@ -429,58 +435,59 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
m_ParameterGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); m_ParameterGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Get the list of names, values, and types // Get the list of names, values, and types
wxArrayString fpList = m_FootprintWizard->GetParameterNames( page ); wxArrayString fpList = m_FootprintWizard->GetParameterNames( page );
wxArrayString fvList = m_FootprintWizard->GetParameterValues( page ); wxArrayString fvList = m_FootprintWizard->GetParameterValues( page );
wxArrayString ptList = m_FootprintWizard->GetParameterTypes( page ); wxArrayString ptList = m_FootprintWizard->GetParameterTypes( page );
// Dimension the wxGrid // Dimension the wxGrid
m_ParameterGrid->DeleteRows( 0, m_ParameterGrid->GetNumberRows() ); m_ParameterGrid->DeleteRows( 0, m_ParameterGrid->GetNumberRows() );
m_ParameterGrid->AppendRows( fpList.size() ); m_ParameterGrid->AppendRows( fpList.size() );
for (unsigned int i=0; i<fpList.size(); i++) for( unsigned int i = 0; i<fpList.size(); i++ )
{ {
wxString name,value,units; wxString name, value, units;
name = fpList[i]; name = fpList[i];
value = fvList[i]; value = fvList[i];
m_ParameterGrid->SetCellValue( i, 0, name ); m_ParameterGrid->SetCellValue( i, 0, name );
m_ParameterGrid->SetReadOnly( i, 0 ); m_ParameterGrid->SetReadOnly( i, 0 );
if ( ptList[i]==wxT( "IU" ) ) if( ptList[i]==wxT( "IU" ) )
{ {
LOCALE_IO toggle;
// We are handling internal units, so convert them to the current // We are handling internal units, so convert them to the current
// system selected units and store into value. // system selected units and store into value.
double dValue; double dValue;
value.ToDouble( &dValue ); value.ToDouble( &dValue );
dValue = To_User_Unit( g_UserUnit, dValue ); dValue = To_User_Unit( g_UserUnit, dValue );
if ( g_UserUnit==INCHES ) // we convert inches into mils for more detail if( g_UserUnit==INCHES ) // we convert inches into mils for more detail
{ {
dValue = dValue*1000.0; dValue = dValue * 1000.0;
units = wxT( "mils" ); units = wxT( "mils" );
} }
else if ( g_UserUnit==MILLIMETRES ) else if( g_UserUnit==MILLIMETRES )
{ {
units = wxT( "mm" ); units = wxT( "mm" );
} }
value.Printf( wxT( "%lf" ), dValue ); value.Printf( wxT( "%lf" ), dValue );
value.Replace( wxT( "," ), wxT( "." ) );
} }
else if ( ptList[i]==wxT( "UNITS" ) ) // 1,2,3,4,5 ... N else if( ptList[i]==wxT( "UNITS" ) ) // 1,2,3,4,5 ... N
{ {
units = wxT( "" ); units = wxT( "" );
} }
m_ParameterGrid->SetCellValue( i, 1 , value ); m_ParameterGrid->SetCellValue( i, 1, value );
m_ParameterGrid->SetCellValue( i, 2 , units ); m_ParameterGrid->SetCellValue( i, 2, units );
m_ParameterGrid->SetReadOnly( i, 2 ); m_ParameterGrid->SetReadOnly( i, 2 );
} }
m_ParameterGrid->AutoSizeColumns(); m_ParameterGrid->AutoSizeColumns();
} }
...@@ -497,33 +504,32 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event ) ...@@ -497,33 +504,32 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
} }
#define PARTLIST_WIDTH_KEY wxT( "Partlist_width" )
#define PARTLIST_WIDTH_KEY wxT( "Partlist_width" )
#define PARAMLIST_WIDTH_KEY wxT( "Paramlist_width" ) #define PARAMLIST_WIDTH_KEY wxT( "Paramlist_width" )
void FOOTPRINT_WIZARD_FRAME::LoadSettings( ) void FOOTPRINT_WIZARD_FRAME::LoadSettings()
{ {
wxConfig* cfg ; wxConfig* cfg;
EDA_DRAW_FRAME::LoadSettings(); EDA_DRAW_FRAME::LoadSettings();
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath ); wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
cfg = wxGetApp().GetSettings(); cfg = wxGetApp().GetSettings();
m_PageListSize.x = 150; // default width of libs list m_PageListSize.x = 150; // default width of libs list
m_ParameterGridSize.x = 350; // default width of component list m_ParameterGridSize.x = 350; // default width of component list
cfg->Read( PARTLIST_WIDTH_KEY , &m_PageListSize.x ); cfg->Read( PARTLIST_WIDTH_KEY, &m_PageListSize.x );
cfg->Read( PARAMLIST_WIDTH_KEY, &m_ParameterGridSize.x ); cfg->Read( PARAMLIST_WIDTH_KEY, &m_ParameterGridSize.x );
// Set parameters to a reasonable value. // Set parameters to a reasonable value.
if ( m_PageListSize.x > m_FrameSize.x/2 ) if( m_PageListSize.x > m_FrameSize.x / 2 )
m_PageListSize.x = m_FrameSize.x/2; m_PageListSize.x = m_FrameSize.x / 2;
if ( m_ParameterGridSize.x > m_FrameSize.x/2 )
m_ParameterGridSize.x = m_FrameSize.x/2;
if( m_ParameterGridSize.x > m_FrameSize.x / 2 )
m_ParameterGridSize.x = m_FrameSize.x / 2;
} }
...@@ -534,9 +540,10 @@ void FOOTPRINT_WIZARD_FRAME::SaveSettings() ...@@ -534,9 +540,10 @@ void FOOTPRINT_WIZARD_FRAME::SaveSettings()
EDA_DRAW_FRAME::SaveSettings(); EDA_DRAW_FRAME::SaveSettings();
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath ); wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
cfg = wxGetApp().GetSettings(); cfg = wxGetApp().GetSettings();
if ( m_PageListSize.x ) if( m_PageListSize.x )
cfg->Write( PARTLIST_WIDTH_KEY, m_PageListSize.x ); cfg->Write( PARTLIST_WIDTH_KEY, m_PageListSize.x );
cfg->Write( PARAMLIST_WIDTH_KEY, m_ParameterGridSize.x ); cfg->Write( PARAMLIST_WIDTH_KEY, m_ParameterGridSize.x );
...@@ -548,28 +555,29 @@ void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event ) ...@@ -548,28 +555,29 @@ void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
EDA_DRAW_FRAME::OnActivate( event ); EDA_DRAW_FRAME::OnActivate( event );
// Ensure we do not have old selection: // Ensure we do not have old selection:
if( ! m_FrameIsActive ) if( !m_FrameIsActive )
return; return;
bool footprintWizardsChanged=false; bool footprintWizardsChanged = false;
if ( footprintWizardsChanged )
if( footprintWizardsChanged )
{ {
// If we are here, the library list has changed, rebuild it // If we are here, the library list has changed, rebuild it
ReCreatePageList(); ReCreatePageList();
DisplayWizardInfos(); DisplayWizardInfos();
} }
} }
void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey )
{ {
wxRealPoint gridSize; wxRealPoint gridSize;
wxPoint oldpos; wxPoint oldpos;
PCB_SCREEN* screen = GetScreen(); PCB_SCREEN* screen = GetScreen();
wxPoint pos = aPosition; wxPoint pos = aPosition;
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this ); cmd.SetEventObject( this );
pos = screen->GetNearestGridPosition( pos ); pos = screen->GetNearestGridPosition( pos );
...@@ -659,7 +667,7 @@ void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event ) ...@@ -659,7 +667,7 @@ void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event )
// Raising the window does not show the window on Windows if iconized. // Raising the window does not show the window on Windows if iconized.
// This should work on any platform. // This should work on any platform.
if( m_Draw3DFrame->IsIconized() ) if( m_Draw3DFrame->IsIconized() )
m_Draw3DFrame->Iconize( false ); m_Draw3DFrame->Iconize( false );
m_Draw3DFrame->Raise(); m_Draw3DFrame->Raise();
...@@ -675,6 +683,7 @@ void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event ) ...@@ -675,6 +683,7 @@ void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event )
m_Draw3DFrame->Show( true ); m_Draw3DFrame->Show( true );
} }
/** /**
* Function Update3D_Frame * Function Update3D_Frame
* must be called after a footprint selection * must be called after a footprint selection
...@@ -692,6 +701,7 @@ void FOOTPRINT_WIZARD_FRAME::Update3D_Frame( bool aForceReloadFootprint ) ...@@ -692,6 +701,7 @@ void FOOTPRINT_WIZARD_FRAME::Update3D_Frame( bool aForceReloadFootprint )
if( aForceReloadFootprint ) if( aForceReloadFootprint )
{ {
m_Draw3DFrame->ReloadRequest(); m_Draw3DFrame->ReloadRequest();
// Force 3D screen refresh immediately // Force 3D screen refresh immediately
if( GetBoard()->m_Modules ) if( GetBoard()->m_Modules )
m_Draw3DFrame->NewDisplay(); m_Draw3DFrame->NewDisplay();
...@@ -741,12 +751,13 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar() ...@@ -741,12 +751,13 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar()
msg = AddHotkeyName( _( "Redraw view" ), g_Module_Editor_Hokeys_Descr, msg = AddHotkeyName( _( "Redraw view" ), g_Module_Editor_Hokeys_Descr,
HK_ZOOM_REDRAW, IS_COMMENT ); HK_ZOOM_REDRAW, IS_COMMENT );
m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
KiBitmap( zoom_redraw_xpm ), msg ); KiBitmap( zoom_redraw_xpm ), msg );
msg = AddHotkeyName( _( "Zoom auto" ), g_Module_Editor_Hokeys_Descr, msg = AddHotkeyName( _( "Zoom auto" ), g_Module_Editor_Hokeys_Descr,
HK_ZOOM_AUTO, IS_COMMENT ); HK_ZOOM_AUTO, IS_COMMENT );
m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
KiBitmap( zoom_fit_in_page_xpm ), msg ); KiBitmap( zoom_fit_in_page_xpm ), msg );
if( m_Semaphore ) if( m_Semaphore )
{ {
// The library browser is called from a "load component" command // The library browser is called from a "load component" command
...@@ -767,5 +778,4 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar() ...@@ -767,5 +778,4 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar()
void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar() void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar()
{ {
} }
...@@ -48,105 +48,104 @@ class FOOTPRINT_WIZARD_FRAME : public PCB_BASE_FRAME ...@@ -48,105 +48,104 @@ class FOOTPRINT_WIZARD_FRAME : public PCB_BASE_FRAME
{ {
private: private:
wxSashLayoutWindow* m_PageListWindow; //< List of libraries (for selection ) wxSashLayoutWindow* m_PageListWindow; // < List of libraries (for selection )
wxListBox* m_PageList; //< The list of pages wxListBox* m_PageList; // < The list of pages
wxSize m_PageListSize; //< size of the window wxSize m_PageListSize; // < size of the window
wxSashLayoutWindow* m_ParameterGridWindow; //< List of components in the selected library wxSashLayoutWindow* m_ParameterGridWindow; // < List of components in the selected library
wxGrid* m_ParameterGrid; //< The list of parameters wxGrid* m_ParameterGrid; // < The list of parameters
wxSize m_ParameterGridSize; //< size of the window wxSize m_ParameterGridSize; // < size of the window
// Flags // Flags
wxSemaphore* m_Semaphore; //< != NULL if the frame must emulate a modal dialog wxSemaphore* m_Semaphore; // < != NULL if the frame must emulate a modal dialog
wxString m_configPath; //< subpath for configuration wxString m_configPath; // < subpath for configuration
FOOTPRINT_WIZARD* m_FootprintWizard;
FOOTPRINT_WIZARD* m_FootprintWizard;
protected: protected:
wxString m_wizardName; //< name of the current wizard wxString m_wizardName; // < name of the current wizard
wxString m_wizardDescription; //< description of the wizard wxString m_wizardDescription; // < description of the wizard
wxString m_wizardStatus; //< current wizard status wxString m_wizardStatus; // < current wizard status
public: public:
FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
wxSemaphore* semaphore = NULL, wxSemaphore* semaphore = NULL,
long style = KICAD_DEFAULT_DRAWFRAME_STYLE ); long style = KICAD_DEFAULT_DRAWFRAME_STYLE );
~FOOTPRINT_WIZARD_FRAME(); ~FOOTPRINT_WIZARD_FRAME();
MODULE* GetBuiltFootprint( void ); MODULE* GetBuiltFootprint( void );
private: private:
void OnSize( wxSizeEvent& event ); void OnSize( wxSizeEvent& event );
/** /**
* Function ExportSelectedFootprint(); * Function ExportSelectedFootprint();
* will let the caller exit from the wait loop, and get the built footprint * will let the caller exit from the wait loop, and get the built footprint
* *
*/ */
void ExportSelectedFootprint( wxCommandEvent& aEvent ); void ExportSelectedFootprint( wxCommandEvent& aEvent );
/** /**
* Function OnSashDrag * Function OnSashDrag
* resizes the child windows when dragging a sash window border. * resizes the child windows when dragging a sash window border.
*/ */
void OnSashDrag( wxSashEvent& event ); void OnSashDrag( wxSashEvent& event );
/** /**
* Function ReCreatePageList * Function ReCreatePageList
* Creates or recreates the list of parameter pages for the current wizard. * Creates or recreates the list of parameter pages for the current wizard.
* This list is sorted * This list is sorted
*/ */
void ReCreatePageList(); void ReCreatePageList();
/** /**
* Function ReCreateParameterList * Function ReCreateParameterList
* Creates the list of parameters for the current page * Creates the list of parameters for the current page
*/ */
void ReCreateParameterList(); void ReCreateParameterList();
/** /**
* Function SelectFootprintWizard * Function SelectFootprintWizard
* Shows the list of footprint wizards available into the system * Shows the list of footprint wizards available into the system
*/ */
void SelectFootprintWizard(); void SelectFootprintWizard();
/** /**
* Function ReloadFootprint * Function ReloadFootprint
* Reloads the current footprint * Reloads the current footprint
*/ */
void ReloadFootprint(); void ReloadFootprint();
void Process_Special_Functions( wxCommandEvent& event ); void Process_Special_Functions( wxCommandEvent& event );
/** /**
* Function DisplayWizardInfos * Function DisplayWizardInfos
* Shows all the details about the current wizard * Shows all the details about the current wizard
*/ */
void DisplayWizardInfos(); void DisplayWizardInfos();
void RedrawActiveWindow( wxDC* DC, bool EraseBg ); void RedrawActiveWindow( wxDC* DC, bool EraseBg );
void OnCloseWindow( wxCloseEvent& Event ); void OnCloseWindow( wxCloseEvent& Event );
void ReCreateHToolbar(); void ReCreateHToolbar();
void ReCreateVToolbar(); void ReCreateVToolbar();
void OnLeftClick( wxDC* DC, const wxPoint& MousePos ); void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
void ClickOnPageList( wxCommandEvent& event ); void ClickOnPageList( wxCommandEvent& event );
void OnSetRelativeOffset( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event );
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/** /**
* Function LoadSettings * Function LoadSettings
* loads the library viewer frame specific configuration settings. * loads the library viewer frame specific configuration settings.
* *
* Don't forget to call this base method from any derived classes or the * Don't forget to call this base method from any derived classes or the
* settings will not get loaded. * settings will not get loaded.
*/ */
void LoadSettings(); void LoadSettings();
/** /**
* Function SaveSettings * Function SaveSettings
...@@ -155,7 +154,7 @@ private: ...@@ -155,7 +154,7 @@ private:
* Don't forget to call this base method from any derived classes or the * Don't forget to call this base method from any derived classes or the
* settings will not get saved. * settings will not get saved.
*/ */
void SaveSettings(); void SaveSettings();
/** /**
...@@ -163,21 +162,20 @@ private: ...@@ -163,21 +162,20 @@ private:
* is called when the frame frame is activate to reload the libraries and component lists * is called when the frame frame is activate to reload the libraries and component lists
* that can be changed by the schematic editor or the library editor. * that can be changed by the schematic editor or the library editor.
*/ */
virtual void OnActivate( wxActivateEvent& event ); virtual void OnActivate( wxActivateEvent& event );
void SelectCurrentWizard( wxCommandEvent& event );
void ParametersUpdated( wxGridEvent& event ); void SelectCurrentWizard( wxCommandEvent& event );
void ParametersUpdated( wxGridEvent& event );
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ); bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
/** /**
* Function Show3D_Frame (virtual) * Function Show3D_Frame (virtual)
* displays 3D view of the footprint (module) being edited. * displays 3D view of the footprint (module) being edited.
*/ */
void Show3D_Frame( wxCommandEvent& event ); void Show3D_Frame( wxCommandEvent& event );
/** /**
* Function Update3D_Frame * Function Update3D_Frame
...@@ -186,18 +184,18 @@ private: ...@@ -186,18 +184,18 @@ private:
* @param aForceReloadFootprint = true to reload data (default) * @param aForceReloadFootprint = true to reload data (default)
* = false to update title only -(aftre creating the 3D viewer) * = false to update title only -(aftre creating the 3D viewer)
*/ */
void Update3D_Frame( bool aForceReloadFootprint = true ); void Update3D_Frame( bool aForceReloadFootprint = true );
/* /*
* Virtual functions, not used here, but needed by PCB_BASE_FRAME * Virtual functions, not used here, but needed by PCB_BASE_FRAME
* (virtual pure functions ) * (virtual pure functions )
*/ */
void OnLeftDClick(wxDC*, const wxPoint&) {} void OnLeftDClick( wxDC*, const wxPoint& ) {}
void SaveCopyInUndoList(BOARD_ITEM*, UNDO_REDO_T, const wxPoint&) {} void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) {}
void SaveCopyInUndoList(PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint&) {} void SaveCopyInUndoList( PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint& ) {}
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif // FOOTPRINT_WIZARD_FRM_H_ #endif // FOOTPRINT_WIZARD_FRM_H_
...@@ -29,22 +29,21 @@ ...@@ -29,22 +29,21 @@
#include "pcbnew_footprint_wizards.h" #include "pcbnew_footprint_wizards.h"
#include <python_scripting.h> #include <python_scripting.h>
#include <stdio.h> #include <stdio.h>
PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD( PyObject* aWizard ) PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD( PyObject* aWizard )
{ {
PyLOCK lock; PyLOCK lock;
this->m_PyWizard= aWizard; this->m_PyWizard = aWizard;
Py_XINCREF( aWizard ); Py_XINCREF( aWizard );
} }
PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD() PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD()
{ {
PyLOCK lock; PyLOCK lock;
Py_XDECREF( this->m_PyWizard ); Py_XDECREF( this->m_PyWizard );
} }
...@@ -52,10 +51,10 @@ PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD() ...@@ -52,10 +51,10 @@ PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD()
PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aArglist ) PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aArglist )
{ {
PyLOCK lock; PyLOCK lock;
// pFunc is a new reference to the desired method // pFunc is a new reference to the desired method
PyObject* pFunc = PyObject_GetAttrString( this->m_PyWizard, aMethod ); PyObject* pFunc = PyObject_GetAttrString( this->m_PyWizard, aMethod );
if( pFunc && PyCallable_Check( pFunc ) ) if( pFunc && PyCallable_Check( pFunc ) )
{ {
...@@ -63,23 +62,23 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA ...@@ -63,23 +62,23 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA
if( PyErr_Occurred() ) if( PyErr_Occurred() )
{ {
wxString message; wxString message;
PyObject* t; PyObject* t;
PyObject* v; PyObject* v;
PyObject* b; PyObject* b;
PyErr_Fetch( &t, &v, &b ); PyErr_Fetch( &t, &v, &b );
message.Printf ( wxT( "calling %s()\n" message.Printf( wxT( "calling %s()\n"
"Exception: %s\n" "Exception: %s\n"
" : %s\n"), " : %s\n" ),
aMethod, aMethod,
PyString_AsString( PyObject_Str( v ) ), FROM_UTF8( PyString_AsString( PyObject_Str( v ) ) ),
PyString_AsString( PyObject_Str( b ) ) FROM_UTF8( PyString_AsString( PyObject_Str( b ) ) )
); );
wxMessageBox( message, wxMessageBox( message,
wxT( "Exception on python footprint wizard code" ), wxT( "Exception on python footprint wizard code" ),
wxICON_ERROR|wxOK); wxICON_ERROR | wxOK );
} }
if( result ) if( result )
...@@ -105,48 +104,52 @@ wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod( const char* aMethod, PyObjec ...@@ -105,48 +104,52 @@ wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod( const char* aMethod, PyObjec
wxString ret; wxString ret;
PyLOCK lock; PyLOCK lock;
PyObject* result = CallMethod( aMethod, aArglist ); PyObject* result = CallMethod( aMethod, aArglist );
if( result ) if( result )
{ {
const char* str_res = PyString_AsString( result ); const char* str_res = PyString_AsString( result );
ret = wxString::FromUTF8( str_res ); ret = FROM_UTF8( str_res );
Py_DECREF( result ); Py_DECREF( result );
} }
return ret; return ret;
} }
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod( const char* aMethod,
( const char* aMethod, PyObject* aArglist ) PyObject* aArglist )
{ {
wxArrayString ret; wxArrayString ret;
wxString str_item; wxString str_item;
PyLOCK lock; PyLOCK lock;
PyObject* result = CallMethod( aMethod, aArglist ); PyObject* result = CallMethod( aMethod, aArglist );
if( result ) if( result )
{ {
if( !PyList_Check( result ) ) if( !PyList_Check( result ) )
{ {
Py_DECREF( result ); Py_DECREF( result );
ret.Add( wxT( "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ), 1 ); ret.Add( wxT(
return ret; "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
} 1 );
return ret;
}
int list_size = PyList_Size( result ); int list_size = PyList_Size( result );
for ( int n=0; n<list_size; n++ ) for( int n = 0; n<list_size; n++ )
{ {
PyObject* element = PyList_GetItem( result, n ); PyObject* element = PyList_GetItem( result, n );
const char* str_res = PyString_AsString( element ); const char* str_res = PyString_AsString( element );
str_item = wxString::FromUTF8( str_res ); str_item = FROM_UTF8( str_res );
ret.Add( str_item, 1 ); ret.Add( str_item, 1 );
} }
Py_DECREF( result ); Py_DECREF( result );
} }
return ret; return ret;
...@@ -155,7 +158,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod ...@@ -155,7 +158,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod
wxString PYTHON_FOOTPRINT_WIZARD::GetName() wxString PYTHON_FOOTPRINT_WIZARD::GetName()
{ {
PyLOCK lock; PyLOCK lock;
return CallRetStrMethod( "GetName" ); return CallRetStrMethod( "GetName" );
} }
...@@ -163,7 +166,7 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetName() ...@@ -163,7 +166,7 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetName()
wxString PYTHON_FOOTPRINT_WIZARD::GetImage() wxString PYTHON_FOOTPRINT_WIZARD::GetImage()
{ {
PyLOCK lock; PyLOCK lock;
return CallRetStrMethod( "GetImage" ); return CallRetStrMethod( "GetImage" );
} }
...@@ -171,7 +174,7 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetImage() ...@@ -171,7 +174,7 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetImage()
wxString PYTHON_FOOTPRINT_WIZARD::GetDescription() wxString PYTHON_FOOTPRINT_WIZARD::GetDescription()
{ {
PyLOCK lock; PyLOCK lock;
return CallRetStrMethod( "GetDescription" ); return CallRetStrMethod( "GetDescription" );
} }
...@@ -183,15 +186,15 @@ int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages() ...@@ -183,15 +186,15 @@ int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages()
PyLOCK lock; PyLOCK lock;
// Time to call the callback // Time to call the callback
PyObject* result = CallMethod( "GetNumParameterPages" , NULL ); PyObject* result = CallMethod( "GetNumParameterPages", NULL );
if( result ) if( result )
{ {
if( !PyInt_Check( result ) ) if( !PyInt_Check( result ) )
return -1; return -1;
ret = PyInt_AsLong( result ); ret = PyInt_AsLong( result );
Py_DECREF( result ); Py_DECREF( result );
} }
return ret; return ret;
...@@ -204,37 +207,40 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName( int aPage ) ...@@ -204,37 +207,40 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName( int aPage )
PyLOCK lock; PyLOCK lock;
// Time to call the callback // Time to call the callback
PyObject* arglist = Py_BuildValue( "(i)", aPage ); PyObject* arglist = Py_BuildValue( "(i)", aPage );
PyObject* result = CallMethod( "GetParameterPageName", arglist ); PyObject* result = CallMethod( "GetParameterPageName", arglist );
Py_DECREF( arglist ); Py_DECREF( arglist );
if( result ) if( result )
{ {
const char* str_res = PyString_AsString( result ); const char* str_res = PyString_AsString( result );
ret = wxString::FromUTF8( str_res ); ret = FROM_UTF8( str_res );
Py_DECREF( result ); Py_DECREF( result );
} }
return ret; return ret;
} }
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames( int aPage ) wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames( int aPage )
{ {
wxArrayString ret; wxArrayString ret;
PyLOCK lock; PyLOCK lock;
PyObject* arglist = Py_BuildValue( "(i)", aPage );
PyObject* arglist = Py_BuildValue( "(i)", aPage );
ret = CallRetArrayStrMethod( "GetParameterNames", arglist ); ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
Py_DECREF( arglist ); Py_DECREF( arglist );
for ( unsigned i=0; i<ret.GetCount(); i++ ) for( unsigned i = 0; i<ret.GetCount(); i++ )
{ {
wxString rest; wxString rest;
wxString item = ret[i]; wxString item = ret[i];
if( item.StartsWith( wxT( "*" ), &rest ) ) if( item.StartsWith( wxT( "*" ), &rest ) )
{ {
ret[i]=rest; ret[i] = rest;
} }
} }
...@@ -247,14 +253,16 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes( int aPage ) ...@@ -247,14 +253,16 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes( int aPage )
wxArrayString ret; wxArrayString ret;
PyLOCK lock; PyLOCK lock;
PyObject* arglist = Py_BuildValue( "(i)", aPage ); PyObject* arglist = Py_BuildValue( "(i)", aPage );
ret = CallRetArrayStrMethod( "GetParameterNames", arglist ); ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
Py_DECREF( arglist ); Py_DECREF( arglist );
for ( unsigned i=0; i<ret.GetCount(); i++ ) for( unsigned i = 0; i<ret.GetCount(); i++ )
{ {
wxString rest; wxString rest;
wxString item = ret[i]; wxString item = ret[i];
if( item.StartsWith( wxT( "*" ), &rest ) ) if( item.StartsWith( wxT( "*" ), &rest ) )
{ {
ret[i] = wxT( "UNITS" ); // units ret[i] = wxT( "UNITS" ); // units
...@@ -271,24 +279,26 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes( int aPage ) ...@@ -271,24 +279,26 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes( int aPage )
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues( int aPage ) wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues( int aPage )
{ {
PyLOCK lock; PyLOCK lock;
PyObject* arglist = Py_BuildValue( "(i)", aPage ); PyObject* arglist = Py_BuildValue( "(i)", aPage );
wxArrayString ret = CallRetArrayStrMethod( "GetParameterValues", arglist ); wxArrayString ret = CallRetArrayStrMethod( "GetParameterValues", arglist );
Py_DECREF( arglist ); Py_DECREF( arglist );
return ret; return ret;
} }
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage ) wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage )
{ {
PyLOCK lock; PyLOCK lock;
PyObject* arglist = Py_BuildValue( "(i)", aPage );
PyObject* arglist = Py_BuildValue( "(i)", aPage ); wxArrayString ret = CallRetArrayStrMethod( "GetParameterErrors", arglist );
wxArrayString ret = CallRetArrayStrMethod( "GetParameterErrors", arglist );
Py_DECREF( arglist ); Py_DECREF( arglist );
return ret; return ret;
...@@ -297,23 +307,23 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage ) ...@@ -297,23 +307,23 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage )
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues( int aPage, wxArrayString& aValues ) wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues( int aPage, wxArrayString& aValues )
{ {
int len = aValues.size(); int len = aValues.size();
PyLOCK lock; PyLOCK lock;
PyObject* py_list = PyList_New( len ); PyObject* py_list = PyList_New( len );
for ( int i=0; i<len ; i++ ) for( int i = 0; i<len; i++ )
{ {
wxString str = aValues[i]; wxString str = aValues[i];
PyObject* py_str = PyString_FromString( ( const char* )str.mb_str() ); PyObject* py_str = PyString_FromString( (const char*) str.mb_str() );
PyList_SetItem( py_list, i, py_str ); PyList_SetItem( py_list, i, py_str );
} }
PyObject* arglist; PyObject* arglist;
arglist = Py_BuildValue( "(i,O)", aPage, py_list ); arglist = Py_BuildValue( "(i,O)", aPage, py_list );
wxString res = CallRetStrMethod( "SetParameterValues", arglist ); wxString res = CallRetStrMethod( "SetParameterValues", arglist );
Py_DECREF( arglist ); Py_DECREF( arglist );
return res; return res;
...@@ -336,16 +346,7 @@ MODULE* PYTHON_FOOTPRINT_WIZARD::GetModule() ...@@ -336,16 +346,7 @@ MODULE* PYTHON_FOOTPRINT_WIZARD::GetModule()
PyObject* obj = PyObject_GetAttrString( result, "this" ); PyObject* obj = PyObject_GetAttrString( result, "this" );
if( PyErr_Occurred() ) if( PyErr_Occurred() )
{
/*
PyObject *t, *v, *b;
PyErr_Fetch( &t, &v, &b );
printf ( "calling GetModule()\n" );
printf ( "Exception: %s\n",PyString_AsString( PyObject_Str( v ) ) );
printf ( " : %s\n",PyString_AsString( PyObject_Str( b ) ) );
*/
PyErr_Print(); PyErr_Print();
}
MODULE* mod = PyModule_to_MODULE( obj ); MODULE* mod = PyModule_to_MODULE( obj );
...@@ -357,26 +358,5 @@ void PYTHON_FOOTPRINT_WIZARDS::register_wizard( PyObject* aPyWizard ) ...@@ -357,26 +358,5 @@ void PYTHON_FOOTPRINT_WIZARDS::register_wizard( PyObject* aPyWizard )
{ {
PYTHON_FOOTPRINT_WIZARD* fw = new PYTHON_FOOTPRINT_WIZARD( aPyWizard ); PYTHON_FOOTPRINT_WIZARD* fw = new PYTHON_FOOTPRINT_WIZARD( aPyWizard );
//printf( "Registered python footprint wizard '%s'\n",
// ( const char* )fw->GetName().mb_str()
// );
// this get the wizard registered in the common
// FOOTPRINT_WIZARDS class
fw->register_wizard(); fw->register_wizard();
#if 0
// just to test if it works correctly
int pages = fw->GetNumParameterPages();
printf( " %d pages\n",pages );
for ( int n=0; n<pages; n++ )
{
printf( " page %d->'%s'\n",n,
( const char* )fw->GetParameterPageName( n ).mb_str() );
}
#endif
} }
...@@ -28,45 +28,41 @@ ...@@ -28,45 +28,41 @@
*/ */
#ifndef PCBNEW_FOOTPRINT_WIZARDS_H #ifndef PCBNEW_FOOTPRINT_WIZARDS_H
#define PCBNEW_FOOTPRINT_WIZARDS_H #define PCBNEW_FOOTPRINT_WIZARDS_H
#include <Python.h> #include <Python.h>
#include <vector> #include <vector>
#include <class_footprint_wizard.h> #include <class_footprint_wizard.h>
class PYTHON_FOOTPRINT_WIZARD : public FOOTPRINT_WIZARD
class PYTHON_FOOTPRINT_WIZARD: public FOOTPRINT_WIZARD
{ {
PyObject* m_PyWizard;
PyObject *m_PyWizard; PyObject* CallMethod( const char* aMethod, PyObject* aArglist = NULL );
PyObject *CallMethod( const char *aMethod, PyObject *aArglist=NULL ); wxString CallRetStrMethod( const char* aMethod, PyObject* aArglist = NULL );
wxString CallRetStrMethod( const char *aMethod, PyObject *aArglist=NULL ); wxArrayString CallRetArrayStrMethod( const char* aMethod,
wxArrayString CallRetArrayStrMethod( const char *aMethod, PyObject* aArglist = NULL );
PyObject *aArglist=NULL );
public: public:
PYTHON_FOOTPRINT_WIZARD( PyObject *wizard ); PYTHON_FOOTPRINT_WIZARD( PyObject* wizard );
~PYTHON_FOOTPRINT_WIZARD(); ~PYTHON_FOOTPRINT_WIZARD();
wxString GetName(); wxString GetName();
wxString GetImage(); wxString GetImage();
wxString GetDescription(); wxString GetDescription();
int GetNumParameterPages(); int GetNumParameterPages();
wxString GetParameterPageName( int aPage ); wxString GetParameterPageName( int aPage );
wxArrayString GetParameterNames( int aPage ); wxArrayString GetParameterNames( int aPage );
wxArrayString GetParameterTypes( int aPage ); wxArrayString GetParameterTypes( int aPage );
wxArrayString GetParameterValues( int aPage ); wxArrayString GetParameterValues( int aPage );
wxArrayString GetParameterErrors( int aPage ); wxArrayString GetParameterErrors( int aPage );
wxString SetParameterValues( int aPage, wxArrayString& aValues ); //< must return "OK" or error description wxString SetParameterValues( int aPage, wxArrayString& aValues ); // < must return "OK" or error description
MODULE* GetModule(); MODULE* GetModule();
}; };
class PYTHON_FOOTPRINT_WIZARDS class PYTHON_FOOTPRINT_WIZARDS
{ {
public: public:
static void register_wizard( PyObject *aPyWizard ); static void register_wizard( PyObject* aPyWizard );
}; };
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */ #endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
...@@ -39,68 +39,68 @@ ...@@ -39,68 +39,68 @@
#include <macros.h> #include <macros.h>
#include <stdlib.h> #include <stdlib.h>
static PCB_EDIT_FRAME *PcbEditFrame=NULL; static PCB_EDIT_FRAME* PcbEditFrame = NULL;
BOARD *GetBoard() BOARD* GetBoard()
{ {
if (PcbEditFrame) if( PcbEditFrame )
return PcbEditFrame->GetBoard(); return PcbEditFrame->GetBoard();
else return NULL; else
return NULL;
} }
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME *aPCBEdaFrame )
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame )
{ {
PcbEditFrame = aPCBEdaFrame; PcbEditFrame = aPCBEdaFrame;
} }
BOARD* LoadBoard( wxString& aFileName ) BOARD* LoadBoard( wxString& aFileName )
{ {
if( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
return LoadBoard( aFileName, IO_MGR::KICAD );
if ( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) ) else if( aFileName.EndsWith( wxT( ".brd" ) ) )
return LoadBoard(aFileName,IO_MGR::KICAD); return LoadBoard( aFileName, IO_MGR::LEGACY );
else if (aFileName.EndsWith(wxT(".brd")))
return LoadBoard(aFileName,IO_MGR::LEGACY);
// as fall back for any other kind use the legacy format // as fall back for any other kind use the legacy format
return LoadBoard(aFileName,IO_MGR::LEGACY); return LoadBoard( aFileName, IO_MGR::LEGACY );
} }
BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ) BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat )
{ {
return IO_MGR::Load( aFormat, aFileName ); return IO_MGR::Load( aFormat, aFileName );
} }
bool SaveBoard( wxString& aFilename, BOARD* aBoard ) bool SaveBoard( wxString& aFilename, BOARD* aBoard )
{ {
return SaveBoard( aFilename, aBoard,IO_MGR::KICAD ); return SaveBoard( aFilename, aBoard, IO_MGR::KICAD );
} }
bool SaveBoard( wxString& aFileName, BOARD* aBoard, bool SaveBoard( wxString& aFileName, BOARD* aBoard,
IO_MGR::PCB_FILE_T aFormat ) IO_MGR::PCB_FILE_T aFormat )
{ {
aBoard->m_Status_Pcb &= ~CONNEXION_OK; aBoard->m_Status_Pcb &= ~CONNEXION_OK;
aBoard->SynchronizeNetsAndNetClasses(); aBoard->SynchronizeNetsAndNetClasses();
aBoard->SetCurrentNetClass( aBoard->m_NetClasses.GetDefault()->GetName() ); aBoard->SetCurrentNetClass( aBoard->m_NetClasses.GetDefault()->GetName() );
wxString header;
PROPERTIES props;
if ( aFormat==IO_MGR::LEGACY )
{
header = wxString::Format(
wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s scripting\n\n" ),
LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(),
GetBuildVersion().GetData() );
props["header"] = header;
}
wxString header;
PROPERTIES props;
if( aFormat==IO_MGR::LEGACY )
{
header = wxString::Format(
wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s scripting\n\n" ),
LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(),
GetBuildVersion().GetData() );
props["header"] = header;
}
IO_MGR::Save( aFormat, aFileName, aBoard, &props );
return true;
IO_MGR::Save( aFormat, aFileName, aBoard, &props );
return true;
} }
...@@ -31,16 +31,17 @@ ...@@ -31,16 +31,17 @@
* we want plain pcbnew.<method_name> access from python */ * we want plain pcbnew.<method_name> access from python */
#ifndef SWIG #ifndef SWIG
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME *aPCBEdaFrame ); void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame );
#endif
BOARD *GetBoard(); #endif
BOARD* GetBoard();
BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ); BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat );
BOARD* LoadBoard( wxString& aFileName ); BOARD* LoadBoard( wxString& aFileName );
bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat ); bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat );
bool SaveBoard( wxString& aFileName, BOARD* aBoard ); bool SaveBoard( wxString& aFileName, BOARD* aBoard );
#endif #endif
...@@ -54,18 +54,18 @@ extern "C" void init_pcbnew( void ); ...@@ -54,18 +54,18 @@ extern "C" void init_pcbnew( void );
* our own ones * our own ones
*/ */
struct _inittab *SwigImportInittab; struct _inittab* SwigImportInittab;
static int SwigNumModules = 0; static int SwigNumModules = 0;
/* Add a name + initfuction to our SwigImportInittab */ /* Add a name + initfuction to our SwigImportInittab */
static void swigAddModule( const char* name, void (* initfunc)() ) static void swigAddModule( const char* name, void (* initfunc)() )
{ {
SwigImportInittab[SwigNumModules].name = (char*) name; SwigImportInittab[SwigNumModules].name = (char*) name;
SwigImportInittab[SwigNumModules].initfunc = initfunc; SwigImportInittab[SwigNumModules].initfunc = initfunc;
SwigNumModules++; SwigNumModules++;
SwigImportInittab[SwigNumModules].name = (char*) 0; SwigImportInittab[SwigNumModules].name = (char*) 0;
SwigImportInittab[SwigNumModules].initfunc = 0; SwigImportInittab[SwigNumModules].initfunc = 0;
} }
...@@ -81,11 +81,12 @@ static void swigAddBuiltin() ...@@ -81,11 +81,12 @@ static void swigAddBuiltin()
i++; i++;
/* allocate memory for the python module table */ /* allocate memory for the python module table */
SwigImportInittab = (struct _inittab*) malloc( SwigImportInittab = (struct _inittab*) malloc(
sizeof(struct _inittab)*(i+EXTRA_PYTHON_MODULES)); sizeof(struct _inittab) * (i + EXTRA_PYTHON_MODULES) );
/* copy all pre-existing python modules into our newly created table */ /* copy all pre-existing python modules into our newly created table */
i=0; i = 0;
while( PyImport_Inittab[i].name ) while( PyImport_Inittab[i].name )
{ {
swigAddModule( PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc ); swigAddModule( PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc );
...@@ -107,9 +108,10 @@ static void swigAddModules() ...@@ -107,9 +108,10 @@ static void swigAddModules()
// finally it seems better to include all in just one module // finally it seems better to include all in just one module
// but in case we needed to include any other modules, // but in case we needed to include any other modules,
// it must be done like this: // it must be done like this:
// swigAddModule("_kicad",init_kicad); // swigAddModule( "_kicad", init_kicad );
} }
/* Function swigSwitchPythonBuiltin /* Function swigSwitchPythonBuiltin
* switches python module table to our built one . * switches python module table to our built one .
* *
...@@ -120,6 +122,7 @@ static void swigSwitchPythonBuiltin() ...@@ -120,6 +122,7 @@ static void swigSwitchPythonBuiltin()
PyImport_Inittab = SwigImportInittab; PyImport_Inittab = SwigImportInittab;
} }
/* Function pcbnewInitPythonScripting /* Function pcbnewInitPythonScripting
* Initializes all the python environment and publish our interface inside it * Initializes all the python environment and publish our interface inside it
* initializes all the wxpython interface, and returns the python thread control structure * initializes all the wxpython interface, and returns the python thread control structure
...@@ -142,9 +145,9 @@ bool pcbnewInitPythonScripting() ...@@ -142,9 +145,9 @@ bool pcbnewInitPythonScripting()
// Load the wxPython core API. Imports the wx._core_ module and sets a // Load the wxPython core API. Imports the wx._core_ module and sets a
// local pointer to a function table located there. The pointer is used // local pointer to a function table located there. The pointer is used
// internally by the rest of the API functions. // internally by the rest of the API functions.
if( ! wxPyCoreAPI_IMPORT() ) if( !wxPyCoreAPI_IMPORT() )
{ {
wxLogError(wxT("***** Error importing the wxPython API! *****")); wxLogError( wxT( "***** Error importing the wxPython API! *****" ) );
PyErr_Print(); PyErr_Print();
Py_Finalize(); Py_Finalize();
return false; return false;
...@@ -160,7 +163,7 @@ bool pcbnewInitPythonScripting() ...@@ -160,7 +163,7 @@ bool pcbnewInitPythonScripting()
#endif #endif
{ {
PyLOCK lock; PyLOCK lock;
PyRun_SimpleString( "import sys\n" PyRun_SimpleString( "import sys\n"
"sys.path.append(\".\")\n" "sys.path.append(\".\")\n"
...@@ -172,10 +175,11 @@ bool pcbnewInitPythonScripting() ...@@ -172,10 +175,11 @@ bool pcbnewInitPythonScripting()
return true; return true;
} }
void pcbnewFinishPythonScripting() void pcbnewFinishPythonScripting()
{ {
#ifdef KICAD_SCRIPTING_WXPYTHON #ifdef KICAD_SCRIPTING_WXPYTHON
wxPyEndAllowThreads(g_PythonMainTState); wxPyEndAllowThreads( g_PythonMainTState );
#endif #endif
Py_Finalize(); Py_Finalize();
} }
...@@ -189,54 +193,55 @@ void RedirectStdio() ...@@ -189,54 +193,55 @@ void RedirectStdio()
// redirects Python's stdout and stderr to a window that will popup // redirects Python's stdout and stderr to a window that will popup
// only on demand when something is printed, like a traceback. // only on demand when something is printed, like a traceback.
const char* python_redirect = const char* python_redirect =
"import sys\n\ "import sys\n"
import wx\n\ "import wx\n"
output = wx.PyOnDemandOutputWindow()\n\ "output = wx.PyOnDemandOutputWindow()\n"
c sys.stderr = output\n"; "sys.stderr = output\n";
PyLOCK lock;
PyLOCK lock;
PyRun_SimpleString( python_redirect ); PyRun_SimpleString( python_redirect );
} }
wxWindow* CreatePythonShellWindow(wxWindow* parent) wxWindow* CreatePythonShellWindow( wxWindow* parent )
{ {
const char* pycrust_panel =
const char* pycrust_panel = "\ "import wx\n"
import wx\n\ "from wx.py import shell, version\n"
from wx.py import shell, version\n\ "\n"
\n\ "class PyCrustPanel(wx.Panel):\n"
class PyCrustPanel(wx.Panel):\n\ "\tdef __init__(self, parent):\n"
\tdef __init__(self, parent):\n\ "\t\twx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)\n"
\t\twx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)\n\ "\t\t\n"
\t\t\n\ "\t\t\n"
\t\t\n\ "\t\tintro = \"Welcome To PyCrust %s - KiCAD Python Shell\" % version.VERSION\n"
\t\tintro = \"Welcome To PyCrust %s - KiCAD Python Shell\" % version.VERSION\n\ "\t\tpycrust = shell.Shell(self, -1, introText=intro)\n"
\t\tpycrust = shell.Shell(self, -1, introText=intro)\n\ "\t\t\n"
\t\t\n\ "\t\tsizer = wx.BoxSizer(wx.VERTICAL)\n\n"
\t\tsizer = wx.BoxSizer(wx.VERTICAL)\n\n\ "\t\tsizer.Add(pycrust, 1, wx.EXPAND|wx.BOTTOM|wx.LEFT|wx.RIGHT, 10)\n\n"
\t\tsizer.Add(pycrust, 1, wx.EXPAND|wx.BOTTOM|wx.LEFT|wx.RIGHT, 10)\n\n\ "\t\tself.SetSizer(sizer)\n\n"
\t\tself.SetSizer(sizer)\n\n\ "\n"
\n\ "def makeWindow(parent):\n"
def makeWindow(parent):\n\ " win = PyCrustPanel(parent)\n"
win = PyCrustPanel(parent)\n\ " return win\n"
return win\n\ "\n";
";
wxWindow* window = NULL;
wxWindow* window = NULL; PyObject* result;
PyObject* result;
// As always, first grab the GIL // As always, first grab the GIL
PyLOCK lock; PyLOCK lock;
// Now make a dictionary to serve as the global namespace when the code is // Now make a dictionary to serve as the global namespace when the code is
// executed. Put a reference to the builtins module in it. // executed. Put a reference to the builtins module in it.
PyObject* globals = PyDict_New(); PyObject* globals = PyDict_New();
PyObject* builtins = PyImport_ImportModule( "__builtin__" ); PyObject* builtins = PyImport_ImportModule( "__builtin__" );
PyDict_SetItemString( globals, "__builtins__", builtins ); PyDict_SetItemString( globals, "__builtins__", builtins );
Py_DECREF(builtins); Py_DECREF( builtins );
// Execute the code to make the makeWindow function we defined above // Execute the code to make the makeWindow function we defined above
result = PyRun_String( pycrust_panel, Py_file_input, globals, globals ); result = PyRun_String( pycrust_panel, Py_file_input, globals, globals );
...@@ -247,7 +252,8 @@ def makeWindow(parent):\n\ ...@@ -247,7 +252,8 @@ def makeWindow(parent):\n\
PyErr_Print(); PyErr_Print();
return NULL; return NULL;
} }
Py_DECREF(result);
Py_DECREF( result );
// Now there should be an object named 'makeWindow' in the dictionary that // Now there should be an object named 'makeWindow' in the dictionary that
// we can grab a pointer to: // we can grab a pointer to:
...@@ -258,10 +264,10 @@ def makeWindow(parent):\n\ ...@@ -258,10 +264,10 @@ def makeWindow(parent):\n\
// use of another wxPython API to take a wxWindows object and build a // use of another wxPython API to take a wxWindows object and build a
// wxPython object that wraps it. // wxPython object that wraps it.
PyObject* arg = wxPyMake_wxObject( parent, false ); PyObject* arg = wxPyMake_wxObject( parent, false );
wxASSERT( arg != NULL ); wxASSERT( arg != NULL );
PyObject* tuple = PyTuple_New( 1 ); PyObject* tuple = PyTuple_New( 1 );
PyTuple_SET_ITEM( tuple, 0, arg ); PyTuple_SET_ITEM( tuple, 0, arg );
result = PyEval_CallObject( func, tuple ); result = PyEval_CallObject( func, tuple );
...@@ -273,11 +279,11 @@ def makeWindow(parent):\n\ ...@@ -273,11 +279,11 @@ def makeWindow(parent):\n\
{ {
// Otherwise, get the returned window out of Python-land and // Otherwise, get the returned window out of Python-land and
// into C++-ville... // into C++-ville...
bool success = wxPyConvertSwigPtr(result, (void**)&window, _T("wxWindow") ); bool success = wxPyConvertSwigPtr( result, (void**) &window, _T( "wxWindow" ) );
(void)success; (void) success;
wxASSERT_MSG(success, _T("Returned object was not a wxWindow!") ); wxASSERT_MSG( success, _T( "Returned object was not a wxWindow!" ) );
Py_DECREF(result); Py_DECREF( result );
} }
// Release the python objects we still have // Release the python objects we still have
...@@ -286,4 +292,6 @@ def makeWindow(parent):\n\ ...@@ -286,4 +292,6 @@ def makeWindow(parent):\n\
return window; return window;
} }
#endif #endif
#ifndef __PYTHON_SCRIPTING_H #ifndef __PYTHON_SCRIPTING_H
#define __PYTHON_SCRIPTING_H #define __PYTHON_SCRIPTING_H
// undefs explained here: https://bugzilla.redhat.com/show_bug.cgi?id=427617 // undefs explained here: https://bugzilla.redhat.com/show_bug.cgi?id=427617
#ifdef _POSIX_C_SOURCE #ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE #undef _POSIX_C_SOURCE
...@@ -21,19 +21,18 @@ ...@@ -21,19 +21,18 @@
* Initializes the Python engine inside pcbnew * Initializes the Python engine inside pcbnew
*/ */
bool pcbnewInitPythonScripting(); bool pcbnewInitPythonScripting();
void pcbnewFinishPythonScripting(); void pcbnewFinishPythonScripting();
#ifdef KICAD_SCRIPTING_WXPYTHON #ifdef KICAD_SCRIPTING_WXPYTHON
void RedirectStdio(); void RedirectStdio();
wxWindow* CreatePythonShellWindow( wxWindow* parent ); wxWindow* CreatePythonShellWindow( wxWindow* parent );
class PyLOCK class PyLOCK
{ {
wxPyBlock_t b; wxPyBlock_t b;
public: public:
// @todo, find out why these are wxPython specific. We need the GIL regardless. // @todo, find out why these are wxPython specific. We need the GIL regardless.
...@@ -46,13 +45,12 @@ public: ...@@ -46,13 +45,12 @@ public:
#else #else
class PyLOCK class PyLOCK
{ {
PyGILState_STATE gil_state; PyGILState_STATE gil_state;
public: public:
PyLOCK() { gil_state = PyGILState_Ensure(); } PyLOCK() { gil_state = PyGILState_Ensure(); }
~PyLOCK() { PyGILState_Release( gil_state ); } ~PyLOCK() { PyGILState_Release( gil_state ); }
}; };
#endif #endif
#endif // __PYTHON_SCRIPTING_H #endif // __PYTHON_SCRIPTING_H
...@@ -65,8 +65,8 @@ wxString* newWxStringFromPy( PyObject* src ) ...@@ -65,8 +65,8 @@ wxString* newWxStringFromPy( PyObject* src )
{ {
bool must_unref_str = false; bool must_unref_str = false;
wxString* result = NULL; wxString* result = NULL;
PyObject* obj = src; PyObject* obj = src;
#if wxUSE_UNICODE #if wxUSE_UNICODE
bool must_unref_obj = false; bool must_unref_obj = false;
...@@ -111,14 +111,14 @@ wxString* newWxStringFromPy( PyObject* src ) ...@@ -111,14 +111,14 @@ wxString* newWxStringFromPy( PyObject* src )
// normal string (or object) to normal python string // normal string (or object) to normal python string
PyObject* str = src; PyObject* str = src;
if( PyUnicode_Check( src ) ) // if it's unicode convert to normal string if( PyUnicode_Check( src ) ) // if it's unicode convert to normal string
{ {
str = PyUnicode_AsEncodedString( src, wxPythonEncoding, "strict" ); str = PyUnicode_AsEncodedString( src, wxPythonEncoding, "strict" );
if( PyErr_Occurred() ) if( PyErr_Occurred() )
return NULL; return NULL;
} }
else if( !PyString_Check( src ) ) // if it's not a string, str(obj) else if( !PyString_Check( src ) ) // if it's not a string, str(obj)
{ {
str = PyObject_Str( src ); str = PyObject_Str( src );
must_unref_str = true; must_unref_str = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment