mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
LOCALE_IO toggle implementation for locale switches on scripting; code cleanups to comply with kicad coding style policy
This commit is contained in:
parent
cefd3cd5e2
commit
155ea57c36
@ -36,12 +36,8 @@ void FOOTPRINT_WIZARD::register_wizard()
|
||||
FOOTPRINT_WIZARDS::register_wizard( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* FOOTPRINT_WIZARD system wide static list
|
||||
*/
|
||||
std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARDS::m_FootprintWizards;
|
||||
|
||||
|
||||
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex )
|
||||
{
|
||||
return m_FootprintWizards[aIndex];
|
||||
|
@ -134,6 +134,9 @@ public:
|
||||
class FOOTPRINT_WIZARDS
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* FOOTPRINT_WIZARD system wide static list
|
||||
*/
|
||||
static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards;
|
||||
|
||||
public:
|
||||
|
@ -33,12 +33,15 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
||||
switch( event.GetId() )
|
||||
{
|
||||
case ID_FOOTPRINT_WIZARD_NEXT:
|
||||
m_PageList->SetSelection( m_PageList->GetSelection()+1, true );
|
||||
m_PageList->SetSelection( m_PageList->GetSelection() + 1, true );
|
||||
break;
|
||||
|
||||
case ID_FOOTPRINT_WIZARD_PREVIOUS:
|
||||
page = m_PageList->GetSelection()-1;
|
||||
if (page<0) page=0;
|
||||
page = m_PageList->GetSelection() - 1;
|
||||
|
||||
if( page<0 )
|
||||
page = 0;
|
||||
|
||||
m_PageList->SetSelection( page, true );
|
||||
break;
|
||||
|
||||
@ -50,6 +53,7 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Function OnLeftClick
|
||||
* Captures a left click event in the dialog
|
||||
*
|
||||
@ -58,6 +62,7 @@ void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* Function OnRightClick
|
||||
* Captures a right click event in the dialog
|
||||
*
|
||||
@ -76,7 +81,7 @@ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
|
||||
msg = _( "Footprint Wizard" );
|
||||
msg << wxT( " [" );
|
||||
|
||||
if( ! m_wizardName.IsEmpty() )
|
||||
if( !m_wizardName.IsEmpty() )
|
||||
msg << m_wizardName;
|
||||
else
|
||||
msg += _( "no wizard selected" );
|
||||
@ -86,6 +91,7 @@ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
|
||||
SetTitle( msg );
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
|
||||
{
|
||||
if( m_FootprintWizard == NULL )
|
||||
@ -94,25 +100,28 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
|
||||
SetCurItem( NULL );
|
||||
// Delete the current footprint
|
||||
GetBoard()->m_Modules.DeleteAll();
|
||||
MODULE *m = m_FootprintWizard->GetModule();
|
||||
if ( m )
|
||||
MODULE* m = m_FootprintWizard->GetModule();
|
||||
|
||||
if( m )
|
||||
{
|
||||
/* Here we should make a copy of the object before adding to board*/
|
||||
m->SetParent((EDA_ITEM*)GetBoard());
|
||||
GetBoard()->m_Modules.Append(m);
|
||||
wxPoint p( 0 , 0 );
|
||||
m->SetParent( (EDA_ITEM*) GetBoard() );
|
||||
GetBoard()->m_Modules.Append( m );
|
||||
wxPoint p( 0, 0 );
|
||||
m->SetPosition( p );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("m_FootprintWizard->GetModule() returns NULL\n");
|
||||
printf( "m_FootprintWizard->GetModule() returns NULL\n" );
|
||||
}
|
||||
|
||||
m_canvas->Refresh();
|
||||
}
|
||||
|
||||
|
||||
MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
|
||||
{
|
||||
if ( m_FootprintWizard )
|
||||
if( m_FootprintWizard )
|
||||
{
|
||||
return m_FootprintWizard->GetModule();
|
||||
}
|
||||
@ -122,16 +131,17 @@ MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
|
||||
{
|
||||
DIALOG_FOOTPRINT_WIZARD_LIST *selectWizard =
|
||||
DIALOG_FOOTPRINT_WIZARD_LIST* selectWizard =
|
||||
new DIALOG_FOOTPRINT_WIZARD_LIST( this );
|
||||
|
||||
selectWizard->ShowModal();
|
||||
|
||||
m_FootprintWizard = selectWizard->GetWizard();
|
||||
|
||||
if ( m_FootprintWizard )
|
||||
if( m_FootprintWizard )
|
||||
{
|
||||
m_wizardName = m_FootprintWizard->GetName();
|
||||
m_wizardDescription = m_FootprintWizard->GetDescription();
|
||||
@ -142,55 +152,55 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
|
||||
DisplayWizardInfos();
|
||||
ReCreatePageList();
|
||||
ReCreateParameterList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
|
||||
{
|
||||
|
||||
SelectFootprintWizard();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function SelectCurrentFootprint
|
||||
* Selects the current footprint name and display it
|
||||
*/
|
||||
void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
|
||||
{
|
||||
|
||||
int page = m_PageList->GetSelection();
|
||||
|
||||
if ( page<0 )
|
||||
if( page<0 )
|
||||
return;
|
||||
|
||||
int n=m_ParameterGrid->GetNumberRows();
|
||||
int n = m_ParameterGrid->GetNumberRows();
|
||||
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 );
|
||||
|
||||
// if this parameter is expected to be an internal
|
||||
// unit convert it back from the user format
|
||||
if (ptList[i]==wxT("IU"))
|
||||
if( ptList[i]==wxT( "IU" ) )
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
double dValue;
|
||||
|
||||
value.ToDouble( &dValue );
|
||||
|
||||
// convert from mils to inches where it's needed
|
||||
if (g_UserUnit==INCHES) dValue = dValue / 1000.0;
|
||||
dValue = From_User_Unit( g_UserUnit, dValue);
|
||||
if( g_UserUnit==INCHES )
|
||||
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
|
||||
// to be scripting compatible
|
||||
|
||||
value.Replace( wxT( "," ), wxT( "." ) );
|
||||
|
||||
arr.Add( value );
|
||||
}
|
||||
@ -199,7 +209,6 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
|
||||
|
||||
ReloadFootprint();
|
||||
DisplayWizardInfos();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -208,7 +217,7 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
|
||||
* Display the current selected component.
|
||||
* If the component is an alias, the ROOT component is displayed
|
||||
*
|
||||
*/
|
||||
*/
|
||||
void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
||||
{
|
||||
if( !GetBoard() )
|
||||
@ -219,7 +228,7 @@ void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
||||
|
||||
MODULE* module = GetBoard()->m_Modules;
|
||||
|
||||
if ( module )
|
||||
if( module )
|
||||
SetMsgPanel( module );
|
||||
|
||||
m_canvas->DrawCrossHair( DC );
|
||||
|
@ -63,7 +63,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
|
||||
|
||||
/* Toolbar events */
|
||||
EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD,
|
||||
FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard)
|
||||
FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
|
||||
|
||||
EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT,
|
||||
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
|
||||
@ -79,7 +79,8 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
|
||||
|
||||
/* listbox events */
|
||||
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 )
|
||||
END_EVENT_TABLE()
|
||||
@ -131,7 +132,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
|
||||
m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr;
|
||||
m_FootprintWizard = NULL;
|
||||
m_PageList= NULL;
|
||||
m_PageList = NULL;
|
||||
m_ParameterGrid = NULL;
|
||||
m_PageListWindow = NULL;
|
||||
m_ParameterGridWindow = NULL;
|
||||
@ -139,12 +140,12 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
m_wizardName.Empty();
|
||||
|
||||
if( m_Semaphore )
|
||||
SetModalMode(true);
|
||||
SetModalMode( true );
|
||||
|
||||
SetBoard( new BOARD() );
|
||||
// Ensure all layers and items are visible:
|
||||
GetBoard()->SetVisibleAlls();
|
||||
SetScreen( new PCB_SCREEN(GetPageSizeIU()) );
|
||||
SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
|
||||
GetScreen()->m_Center = true; // Center coordinate origins on screen.
|
||||
LoadSettings();
|
||||
|
||||
@ -189,7 +190,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
m_ParameterGridWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
|
||||
m_ParameterGrid = new wxGrid( m_ParameterGridWindow,
|
||||
ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
|
||||
wxPoint( 0 , 0 ),
|
||||
wxPoint( 0, 0 ),
|
||||
wxDefaultSize );
|
||||
|
||||
m_ParameterGrid->CreateGrid( 1, 3 );
|
||||
@ -197,13 +198,12 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
// Columns
|
||||
m_ParameterGrid->AutoSizeColumns();
|
||||
m_ParameterGrid->SetColLabelSize( 20 );
|
||||
m_ParameterGrid->SetColLabelValue( 0, _("Parameter") );
|
||||
m_ParameterGrid->SetColLabelValue( 1, _("Value") );
|
||||
m_ParameterGrid->SetColLabelValue( 2, _("Units") );
|
||||
m_ParameterGrid->SetColLabelValue( 0, _( "Parameter" ) );
|
||||
m_ParameterGrid->SetColLabelValue( 1, _( "Value" ) );
|
||||
m_ParameterGrid->SetColLabelValue( 2, _( "Units" ) );
|
||||
m_ParameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
|
||||
|
||||
|
||||
|
||||
ReCreatePageList();
|
||||
|
||||
DisplayWizardInfos();
|
||||
@ -229,14 +229,14 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
|
||||
// Manage main toolbal
|
||||
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 );
|
||||
|
||||
// Manage the left window (list of pages)
|
||||
if( m_PageListWindow )
|
||||
m_auimgr.AddPane( m_PageListWindow, wxAuiPaneInfo( info ).Name( wxT( "m_PageList" ) ).
|
||||
Left().Row( 0 ));
|
||||
Left().Row( 0 ) );
|
||||
|
||||
// Manage the list of parameters)
|
||||
m_auimgr.AddPane( m_ParameterGridWindow,
|
||||
@ -249,7 +249,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
|
||||
// Manage the message panel
|
||||
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
|
||||
* 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,
|
||||
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_PageListWindow );
|
||||
pane.MinSize( wxSize( m_PageListSize.x, -1 ) );
|
||||
}
|
||||
|
||||
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_ParameterGridWindow );
|
||||
pane.MinSize( wxSize( m_ParameterGridSize.x, -1 ) );
|
||||
|
||||
@ -292,18 +293,19 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME()
|
||||
void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event )
|
||||
{
|
||||
wxCommandEvent fakeEvent;
|
||||
|
||||
ExportSelectedFootprint( fakeEvent );
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
|
||||
{
|
||||
|
||||
SaveSettings();
|
||||
|
||||
if( m_Semaphore )
|
||||
{
|
||||
m_Semaphore->Post();
|
||||
SetModalMode(false);
|
||||
SetModalMode( false );
|
||||
// This window will be destroyed by the calling function,
|
||||
// to avoid side effects
|
||||
}
|
||||
@ -311,8 +313,6 @@ void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -330,6 +330,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event )
|
||||
switch( event.GetId() )
|
||||
{
|
||||
case ID_FOOTPRINT_WIZARD_WINDOW:
|
||||
|
||||
if( m_PageListWindow )
|
||||
{
|
||||
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_PageListWindow );
|
||||
@ -337,6 +338,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event )
|
||||
pane.MinSize( m_PageListSize );
|
||||
m_auimgr.Update();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW:
|
||||
@ -363,6 +365,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
|
||||
SizeEv.Skip();
|
||||
}
|
||||
|
||||
|
||||
/* Function OnSetRelativeOffset
|
||||
* Updates the cursor position and the status bar
|
||||
*
|
||||
@ -373,6 +376,7 @@ void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
|
||||
/* Function ReCreatePageList
|
||||
* It recreates the list of pages for a new loaded wizard
|
||||
*
|
||||
@ -382,12 +386,13 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
|
||||
if( m_PageList == NULL )
|
||||
return;
|
||||
|
||||
if (m_FootprintWizard == NULL)
|
||||
if( m_FootprintWizard == NULL )
|
||||
return;
|
||||
|
||||
m_PageList->Clear();
|
||||
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 );
|
||||
m_PageList->Append( name );
|
||||
@ -401,6 +406,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
|
||||
m_canvas->Refresh();
|
||||
}
|
||||
|
||||
|
||||
/* Function ReCreateParameterList
|
||||
* It creates the parameter grid for a certain wizard page of the current wizard
|
||||
*
|
||||
@ -411,12 +417,12 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
|
||||
if( m_ParameterGrid == NULL )
|
||||
return;
|
||||
|
||||
if (m_FootprintWizard == NULL )
|
||||
if( m_FootprintWizard == NULL )
|
||||
return;
|
||||
|
||||
int page = m_PageList->GetSelection();
|
||||
|
||||
if (page<0)
|
||||
if( page<0 )
|
||||
return;
|
||||
|
||||
m_ParameterGrid->ClearGrid();
|
||||
@ -437,9 +443,9 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
|
||||
m_ParameterGrid->DeleteRows( 0, m_ParameterGrid->GetNumberRows() );
|
||||
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];
|
||||
value = fvList[i];
|
||||
@ -447,40 +453,41 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
|
||||
m_ParameterGrid->SetCellValue( i, 0, name );
|
||||
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
|
||||
// system selected units and store into value.
|
||||
double dValue;
|
||||
|
||||
value.ToDouble( &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" );
|
||||
}
|
||||
else if ( g_UserUnit==MILLIMETRES )
|
||||
else if( g_UserUnit==MILLIMETRES )
|
||||
{
|
||||
units = wxT( "mm" );
|
||||
}
|
||||
|
||||
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( "" );
|
||||
}
|
||||
|
||||
m_ParameterGrid->SetCellValue( i, 1 , value );
|
||||
m_ParameterGrid->SetCellValue( i, 2 , units );
|
||||
m_ParameterGrid->SetCellValue( i, 1, value );
|
||||
m_ParameterGrid->SetCellValue( i, 2, units );
|
||||
m_ParameterGrid->SetReadOnly( i, 2 );
|
||||
}
|
||||
|
||||
m_ParameterGrid->AutoSizeColumns();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -497,33 +504,32 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define PARTLIST_WIDTH_KEY wxT( "Partlist_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();
|
||||
|
||||
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
|
||||
|
||||
cfg = wxGetApp().GetSettings();
|
||||
|
||||
m_PageListSize.x = 150; // default width of libs 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 );
|
||||
|
||||
// Set parameters to a reasonable value.
|
||||
if ( 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_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;
|
||||
}
|
||||
|
||||
|
||||
@ -534,9 +540,10 @@ void FOOTPRINT_WIZARD_FRAME::SaveSettings()
|
||||
EDA_DRAW_FRAME::SaveSettings();
|
||||
|
||||
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
|
||||
|
||||
cfg = wxGetApp().GetSettings();
|
||||
|
||||
if ( m_PageListSize.x )
|
||||
if( m_PageListSize.x )
|
||||
cfg->Write( PARTLIST_WIDTH_KEY, m_PageListSize.x );
|
||||
|
||||
cfg->Write( PARAMLIST_WIDTH_KEY, m_ParameterGridSize.x );
|
||||
@ -548,16 +555,16 @@ void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
|
||||
EDA_DRAW_FRAME::OnActivate( event );
|
||||
|
||||
// Ensure we do not have old selection:
|
||||
if( ! m_FrameIsActive )
|
||||
if( !m_FrameIsActive )
|
||||
return;
|
||||
|
||||
bool footprintWizardsChanged=false;
|
||||
if ( footprintWizardsChanged )
|
||||
bool footprintWizardsChanged = false;
|
||||
|
||||
if( footprintWizardsChanged )
|
||||
{
|
||||
// If we are here, the library list has changed, rebuild it
|
||||
ReCreatePageList();
|
||||
DisplayWizardInfos();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -570,6 +577,7 @@ void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition
|
||||
wxPoint pos = aPosition;
|
||||
|
||||
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
||||
|
||||
cmd.SetEventObject( this );
|
||||
|
||||
pos = screen->GetNearestGridPosition( pos );
|
||||
@ -675,6 +683,7 @@ void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event )
|
||||
m_Draw3DFrame->Show( true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function Update3D_Frame
|
||||
* must be called after a footprint selection
|
||||
@ -692,6 +701,7 @@ void FOOTPRINT_WIZARD_FRAME::Update3D_Frame( bool aForceReloadFootprint )
|
||||
if( aForceReloadFootprint )
|
||||
{
|
||||
m_Draw3DFrame->ReloadRequest();
|
||||
|
||||
// Force 3D screen refresh immediately
|
||||
if( GetBoard()->m_Modules )
|
||||
m_Draw3DFrame->NewDisplay();
|
||||
@ -747,6 +757,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar()
|
||||
HK_ZOOM_AUTO, IS_COMMENT );
|
||||
m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
|
||||
KiBitmap( zoom_fit_in_page_xpm ), msg );
|
||||
|
||||
if( m_Semaphore )
|
||||
{
|
||||
// The library browser is called from a "load component" command
|
||||
@ -767,5 +778,4 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar()
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -48,26 +48,24 @@ class FOOTPRINT_WIZARD_FRAME : public PCB_BASE_FRAME
|
||||
{
|
||||
private:
|
||||
|
||||
wxSashLayoutWindow* m_PageListWindow; //< List of libraries (for selection )
|
||||
wxListBox* m_PageList; //< The list of pages
|
||||
wxSize m_PageListSize; //< size of the window
|
||||
wxSashLayoutWindow* m_PageListWindow; // < List of libraries (for selection )
|
||||
wxListBox* m_PageList; // < The list of pages
|
||||
wxSize m_PageListSize; // < size of the window
|
||||
|
||||
|
||||
wxSashLayoutWindow* m_ParameterGridWindow; //< List of components in the selected library
|
||||
wxGrid* m_ParameterGrid; //< The list of parameters
|
||||
wxSize m_ParameterGridSize; //< size of the window
|
||||
wxSashLayoutWindow* m_ParameterGridWindow; // < List of components in the selected library
|
||||
wxGrid* m_ParameterGrid; // < The list of parameters
|
||||
wxSize m_ParameterGridSize; // < size of the window
|
||||
|
||||
// Flags
|
||||
wxSemaphore* m_Semaphore; //< != NULL if the frame must emulate a modal dialog
|
||||
wxString m_configPath; //< subpath for configuration
|
||||
wxSemaphore* m_Semaphore; // < != NULL if the frame must emulate a modal dialog
|
||||
wxString m_configPath; // < subpath for configuration
|
||||
|
||||
FOOTPRINT_WIZARD* m_FootprintWizard;
|
||||
|
||||
protected:
|
||||
wxString m_wizardName; //< name of the current wizard
|
||||
wxString m_wizardDescription; //< description of the wizard
|
||||
wxString m_wizardStatus; //< current wizard status
|
||||
|
||||
wxString m_wizardName; // < name of the current wizard
|
||||
wxString m_wizardDescription; // < description of the wizard
|
||||
wxString m_wizardStatus; // < current wizard status
|
||||
public:
|
||||
FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
|
||||
wxSemaphore* semaphore = NULL,
|
||||
@ -80,6 +78,7 @@ public:
|
||||
private:
|
||||
|
||||
void OnSize( wxSizeEvent& event );
|
||||
|
||||
/**
|
||||
* Function ExportSelectedFootprint();
|
||||
* will let the caller exit from the wait loop, and get the built footprint
|
||||
@ -170,7 +169,6 @@ private:
|
||||
void ParametersUpdated( wxGridEvent& event );
|
||||
|
||||
|
||||
|
||||
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
|
||||
|
||||
/**
|
||||
@ -192,9 +190,9 @@ private:
|
||||
* Virtual functions, not used here, but needed by PCB_BASE_FRAME
|
||||
* (virtual pure functions )
|
||||
*/
|
||||
void OnLeftDClick(wxDC*, const wxPoint&) {}
|
||||
void SaveCopyInUndoList(BOARD_ITEM*, UNDO_REDO_T, const wxPoint&) {}
|
||||
void SaveCopyInUndoList(PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint&) {}
|
||||
void OnLeftDClick( wxDC*, const wxPoint& ) {}
|
||||
void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) {}
|
||||
void SaveCopyInUndoList( PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint& ) {}
|
||||
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
#include "pcbnew_footprint_wizards.h"
|
||||
#include <python_scripting.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@ -37,7 +36,7 @@ PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD( PyObject* aWizard )
|
||||
{
|
||||
PyLOCK lock;
|
||||
|
||||
this->m_PyWizard= aWizard;
|
||||
this->m_PyWizard = aWizard;
|
||||
Py_XINCREF( aWizard );
|
||||
}
|
||||
|
||||
@ -69,17 +68,17 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA
|
||||
PyObject* b;
|
||||
|
||||
PyErr_Fetch( &t, &v, &b );
|
||||
message.Printf ( wxT( "calling %s()\n"
|
||||
message.Printf( wxT( "calling %s()\n"
|
||||
"Exception: %s\n"
|
||||
" : %s\n"),
|
||||
" : %s\n" ),
|
||||
aMethod,
|
||||
PyString_AsString( PyObject_Str( v ) ),
|
||||
PyString_AsString( PyObject_Str( b ) )
|
||||
FROM_UTF8( PyString_AsString( PyObject_Str( v ) ) ),
|
||||
FROM_UTF8( PyString_AsString( PyObject_Str( b ) ) )
|
||||
);
|
||||
|
||||
wxMessageBox( message,
|
||||
wxT( "Exception on python footprint wizard code" ),
|
||||
wxICON_ERROR|wxOK);
|
||||
wxICON_ERROR | wxOK );
|
||||
}
|
||||
|
||||
if( result )
|
||||
@ -106,18 +105,20 @@ wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod( const char* aMethod, PyObjec
|
||||
PyLOCK lock;
|
||||
|
||||
PyObject* result = CallMethod( aMethod, aArglist );
|
||||
|
||||
if( result )
|
||||
{
|
||||
const char* str_res = PyString_AsString( result );
|
||||
ret = wxString::FromUTF8( str_res );
|
||||
ret = FROM_UTF8( str_res );
|
||||
Py_DECREF( result );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod
|
||||
( const char* aMethod, PyObject* aArglist )
|
||||
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod( const char* aMethod,
|
||||
PyObject* aArglist )
|
||||
{
|
||||
wxArrayString ret;
|
||||
wxString str_item;
|
||||
@ -130,19 +131,21 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod
|
||||
if( !PyList_Check( result ) )
|
||||
{
|
||||
Py_DECREF( result );
|
||||
ret.Add( wxT( "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ), 1 );
|
||||
ret.Add( wxT(
|
||||
"PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
|
||||
1 );
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
const char* str_res = PyString_AsString( element );
|
||||
|
||||
str_item = wxString::FromUTF8( str_res );
|
||||
str_item = FROM_UTF8( str_res );
|
||||
ret.Add( str_item, 1 );
|
||||
}
|
||||
|
||||
@ -183,7 +186,7 @@ int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages()
|
||||
PyLOCK lock;
|
||||
|
||||
// Time to call the callback
|
||||
PyObject* result = CallMethod( "GetNumParameterPages" , NULL );
|
||||
PyObject* result = CallMethod( "GetNumParameterPages", NULL );
|
||||
|
||||
if( result )
|
||||
{
|
||||
@ -212,9 +215,10 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName( int aPage )
|
||||
if( result )
|
||||
{
|
||||
const char* str_res = PyString_AsString( result );
|
||||
ret = wxString::FromUTF8( str_res );
|
||||
ret = FROM_UTF8( str_res );
|
||||
Py_DECREF( result );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -225,16 +229,18 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames( int aPage )
|
||||
PyLOCK lock;
|
||||
|
||||
PyObject* arglist = Py_BuildValue( "(i)", aPage );
|
||||
|
||||
ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
|
||||
Py_DECREF( arglist );
|
||||
|
||||
for ( unsigned i=0; i<ret.GetCount(); i++ )
|
||||
for( unsigned i = 0; i<ret.GetCount(); i++ )
|
||||
{
|
||||
wxString rest;
|
||||
wxString item = ret[i];
|
||||
|
||||
if( item.StartsWith( wxT( "*" ), &rest ) )
|
||||
{
|
||||
ret[i]=rest;
|
||||
ret[i] = rest;
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,13 +254,15 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes( int aPage )
|
||||
PyLOCK lock;
|
||||
|
||||
PyObject* arglist = Py_BuildValue( "(i)", aPage );
|
||||
|
||||
ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
|
||||
Py_DECREF( arglist );
|
||||
|
||||
for ( unsigned i=0; i<ret.GetCount(); i++ )
|
||||
for( unsigned i = 0; i<ret.GetCount(); i++ )
|
||||
{
|
||||
wxString rest;
|
||||
wxString item = ret[i];
|
||||
|
||||
if( item.StartsWith( wxT( "*" ), &rest ) )
|
||||
{
|
||||
ret[i] = wxT( "UNITS" ); // units
|
||||
@ -282,6 +290,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues( int aPage )
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage )
|
||||
{
|
||||
PyLOCK lock;
|
||||
@ -289,6 +298,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage )
|
||||
PyObject* arglist = Py_BuildValue( "(i)", aPage );
|
||||
|
||||
wxArrayString ret = CallRetArrayStrMethod( "GetParameterErrors", arglist );
|
||||
|
||||
Py_DECREF( arglist );
|
||||
|
||||
return ret;
|
||||
@ -303,10 +313,10 @@ wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues( int aPage, wxArrayString&
|
||||
|
||||
PyObject* py_list = PyList_New( len );
|
||||
|
||||
for ( int i=0; i<len ; i++ )
|
||||
for( int i = 0; i<len; 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 );
|
||||
}
|
||||
|
||||
@ -336,16 +346,7 @@ MODULE* PYTHON_FOOTPRINT_WIZARD::GetModule()
|
||||
PyObject* obj = PyObject_GetAttrString( result, "this" );
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
MODULE* mod = PyModule_to_MODULE( obj );
|
||||
|
||||
@ -357,26 +358,5 @@ void PYTHON_FOOTPRINT_WIZARDS::register_wizard( PyObject* 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();
|
||||
|
||||
#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
|
||||
|
||||
}
|
||||
|
@ -34,18 +34,16 @@
|
||||
#include <class_footprint_wizard.h>
|
||||
|
||||
|
||||
|
||||
class PYTHON_FOOTPRINT_WIZARD: public FOOTPRINT_WIZARD
|
||||
class PYTHON_FOOTPRINT_WIZARD : public FOOTPRINT_WIZARD
|
||||
{
|
||||
|
||||
PyObject *m_PyWizard;
|
||||
PyObject *CallMethod( const char *aMethod, PyObject *aArglist=NULL );
|
||||
wxString CallRetStrMethod( const char *aMethod, PyObject *aArglist=NULL );
|
||||
wxArrayString CallRetArrayStrMethod( const char *aMethod,
|
||||
PyObject *aArglist=NULL );
|
||||
PyObject* m_PyWizard;
|
||||
PyObject* CallMethod( const char* aMethod, PyObject* aArglist = NULL );
|
||||
wxString CallRetStrMethod( const char* aMethod, PyObject* aArglist = NULL );
|
||||
wxArrayString CallRetArrayStrMethod( const char* aMethod,
|
||||
PyObject* aArglist = NULL );
|
||||
|
||||
public:
|
||||
PYTHON_FOOTPRINT_WIZARD( PyObject *wizard );
|
||||
PYTHON_FOOTPRINT_WIZARD( PyObject* wizard );
|
||||
~PYTHON_FOOTPRINT_WIZARD();
|
||||
wxString GetName();
|
||||
wxString GetImage();
|
||||
@ -56,7 +54,7 @@ public:
|
||||
wxArrayString GetParameterTypes( int aPage );
|
||||
wxArrayString GetParameterValues( 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();
|
||||
};
|
||||
|
||||
@ -64,9 +62,7 @@ public:
|
||||
class PYTHON_FOOTPRINT_WIZARDS
|
||||
{
|
||||
public:
|
||||
static void register_wizard( PyObject *aPyWizard );
|
||||
|
||||
static void register_wizard( PyObject* aPyWizard );
|
||||
};
|
||||
|
||||
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
|
||||
|
||||
|
@ -39,44 +39,48 @@
|
||||
#include <macros.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();
|
||||
else return NULL;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME *aPCBEdaFrame )
|
||||
|
||||
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame )
|
||||
{
|
||||
PcbEditFrame = aPCBEdaFrame;
|
||||
}
|
||||
|
||||
|
||||
BOARD* LoadBoard( wxString& aFileName )
|
||||
{
|
||||
if( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
|
||||
return LoadBoard( aFileName, IO_MGR::KICAD );
|
||||
|
||||
if ( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
|
||||
return LoadBoard(aFileName,IO_MGR::KICAD);
|
||||
|
||||
else if (aFileName.EndsWith(wxT(".brd")))
|
||||
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
|
||||
return LoadBoard(aFileName,IO_MGR::LEGACY);
|
||||
|
||||
return LoadBoard( aFileName, IO_MGR::LEGACY );
|
||||
}
|
||||
|
||||
|
||||
BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat )
|
||||
{
|
||||
return IO_MGR::Load( aFormat, aFileName );
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
IO_MGR::PCB_FILE_T aFormat )
|
||||
{
|
||||
@ -87,7 +91,7 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard,
|
||||
wxString header;
|
||||
PROPERTIES props;
|
||||
|
||||
if ( aFormat==IO_MGR::LEGACY )
|
||||
if( aFormat==IO_MGR::LEGACY )
|
||||
{
|
||||
header = wxString::Format(
|
||||
wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s scripting\n\n" ),
|
||||
@ -97,10 +101,6 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard,
|
||||
}
|
||||
|
||||
|
||||
|
||||
IO_MGR::Save( aFormat, aFileName, aBoard, &props );
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,10 +31,11 @@
|
||||
* we want plain pcbnew.<method_name> access from python */
|
||||
|
||||
#ifndef SWIG
|
||||
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME *aPCBEdaFrame );
|
||||
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame );
|
||||
|
||||
#endif
|
||||
|
||||
BOARD *GetBoard();
|
||||
BOARD* GetBoard();
|
||||
|
||||
BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat );
|
||||
BOARD* LoadBoard( wxString& aFileName );
|
||||
|
@ -54,7 +54,7 @@ extern "C" void init_pcbnew( void );
|
||||
* our own ones
|
||||
*/
|
||||
|
||||
struct _inittab *SwigImportInittab;
|
||||
struct _inittab* SwigImportInittab;
|
||||
static int SwigNumModules = 0;
|
||||
|
||||
|
||||
@ -82,10 +82,11 @@ static void swigAddBuiltin()
|
||||
|
||||
/* allocate memory for the python module table */
|
||||
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 */
|
||||
i=0;
|
||||
i = 0;
|
||||
|
||||
while( PyImport_Inittab[i].name )
|
||||
{
|
||||
swigAddModule( PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc );
|
||||
@ -107,9 +108,10 @@ static void swigAddModules()
|
||||
// finally it seems better to include all in just one module
|
||||
// but in case we needed to include any other modules,
|
||||
// it must be done like this:
|
||||
// swigAddModule("_kicad",init_kicad);
|
||||
// swigAddModule( "_kicad", init_kicad );
|
||||
}
|
||||
|
||||
|
||||
/* Function swigSwitchPythonBuiltin
|
||||
* switches python module table to our built one .
|
||||
*
|
||||
@ -120,6 +122,7 @@ static void swigSwitchPythonBuiltin()
|
||||
PyImport_Inittab = SwigImportInittab;
|
||||
}
|
||||
|
||||
|
||||
/* Function pcbnewInitPythonScripting
|
||||
* Initializes all the python environment and publish our interface inside it
|
||||
* initializes all the wxpython interface, and returns the python thread control structure
|
||||
@ -142,9 +145,9 @@ bool pcbnewInitPythonScripting()
|
||||
// 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
|
||||
// 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();
|
||||
Py_Finalize();
|
||||
return false;
|
||||
@ -172,10 +175,11 @@ bool pcbnewInitPythonScripting()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void pcbnewFinishPythonScripting()
|
||||
{
|
||||
#ifdef KICAD_SCRIPTING_WXPYTHON
|
||||
wxPyEndAllowThreads(g_PythonMainTState);
|
||||
wxPyEndAllowThreads( g_PythonMainTState );
|
||||
#endif
|
||||
Py_Finalize();
|
||||
}
|
||||
@ -189,39 +193,39 @@ void RedirectStdio()
|
||||
// redirects Python's stdout and stderr to a window that will popup
|
||||
// only on demand when something is printed, like a traceback.
|
||||
const char* python_redirect =
|
||||
"import sys\n\
|
||||
import wx\n\
|
||||
output = wx.PyOnDemandOutputWindow()\n\
|
||||
c sys.stderr = output\n";
|
||||
"import sys\n"
|
||||
"import wx\n"
|
||||
"output = wx.PyOnDemandOutputWindow()\n"
|
||||
"sys.stderr = output\n";
|
||||
|
||||
PyLOCK lock;
|
||||
|
||||
PyRun_SimpleString( python_redirect );
|
||||
}
|
||||
|
||||
|
||||
wxWindow* CreatePythonShellWindow(wxWindow* parent)
|
||||
wxWindow* CreatePythonShellWindow( wxWindow* parent )
|
||||
{
|
||||
|
||||
const char* pycrust_panel = "\
|
||||
import wx\n\
|
||||
from wx.py import shell, version\n\
|
||||
\n\
|
||||
class PyCrustPanel(wx.Panel):\n\
|
||||
\tdef __init__(self, parent):\n\
|
||||
\t\twx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)\n\
|
||||
\t\t\n\
|
||||
\t\t\n\
|
||||
\t\tintro = \"Welcome To PyCrust %s - KiCAD Python Shell\" % version.VERSION\n\
|
||||
\t\tpycrust = shell.Shell(self, -1, introText=intro)\n\
|
||||
\t\t\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\tself.SetSizer(sizer)\n\n\
|
||||
\n\
|
||||
def makeWindow(parent):\n\
|
||||
win = PyCrustPanel(parent)\n\
|
||||
return win\n\
|
||||
";
|
||||
const char* pycrust_panel =
|
||||
"import wx\n"
|
||||
"from wx.py import shell, version\n"
|
||||
"\n"
|
||||
"class PyCrustPanel(wx.Panel):\n"
|
||||
"\tdef __init__(self, parent):\n"
|
||||
"\t\twx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)\n"
|
||||
"\t\t\n"
|
||||
"\t\t\n"
|
||||
"\t\tintro = \"Welcome To PyCrust %s - KiCAD Python Shell\" % version.VERSION\n"
|
||||
"\t\tpycrust = shell.Shell(self, -1, introText=intro)\n"
|
||||
"\t\t\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\tself.SetSizer(sizer)\n\n"
|
||||
"\n"
|
||||
"def makeWindow(parent):\n"
|
||||
" win = PyCrustPanel(parent)\n"
|
||||
" return win\n"
|
||||
"\n";
|
||||
|
||||
|
||||
wxWindow* window = NULL;
|
||||
@ -235,8 +239,9 @@ def makeWindow(parent):\n\
|
||||
|
||||
PyObject* globals = PyDict_New();
|
||||
PyObject* builtins = PyImport_ImportModule( "__builtin__" );
|
||||
|
||||
PyDict_SetItemString( globals, "__builtins__", builtins );
|
||||
Py_DECREF(builtins);
|
||||
Py_DECREF( builtins );
|
||||
|
||||
// Execute the code to make the makeWindow function we defined above
|
||||
result = PyRun_String( pycrust_panel, Py_file_input, globals, globals );
|
||||
@ -247,7 +252,8 @@ def makeWindow(parent):\n\
|
||||
PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(result);
|
||||
|
||||
Py_DECREF( result );
|
||||
|
||||
// Now there should be an object named 'makeWindow' in the dictionary that
|
||||
// we can grab a pointer to:
|
||||
@ -273,11 +279,11 @@ def makeWindow(parent):\n\
|
||||
{
|
||||
// Otherwise, get the returned window out of Python-land and
|
||||
// into C++-ville...
|
||||
bool success = wxPyConvertSwigPtr(result, (void**)&window, _T("wxWindow") );
|
||||
(void)success;
|
||||
bool success = wxPyConvertSwigPtr( result, (void**) &window, _T( "wxWindow" ) );
|
||||
(void) success;
|
||||
|
||||
wxASSERT_MSG(success, _T("Returned object was not a wxWindow!") );
|
||||
Py_DECREF(result);
|
||||
wxASSERT_MSG( success, _T( "Returned object was not a wxWindow!" ) );
|
||||
Py_DECREF( result );
|
||||
}
|
||||
|
||||
// Release the python objects we still have
|
||||
@ -286,4 +292,6 @@ def makeWindow(parent):\n\
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef __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
|
||||
#undef _POSIX_C_SOURCE
|
||||
@ -33,7 +33,6 @@ wxWindow* CreatePythonShellWindow( wxWindow* parent );
|
||||
class PyLOCK
|
||||
{
|
||||
wxPyBlock_t b;
|
||||
|
||||
public:
|
||||
|
||||
// @todo, find out why these are wxPython specific. We need the GIL regardless.
|
||||
@ -47,7 +46,6 @@ public:
|
||||
class PyLOCK
|
||||
{
|
||||
PyGILState_STATE gil_state;
|
||||
|
||||
public:
|
||||
PyLOCK() { gil_state = PyGILState_Ensure(); }
|
||||
~PyLOCK() { PyGILState_Release( gil_state ); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user