diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index bcf99737a6..8ed2faa588 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -99,6 +99,8 @@ set(PCBNEW_DIALOGS dialogs/dialog_scripting.cpp footprint_wizard.cpp footprint_wizard_frame.cpp + dialogs/dialog_footprint_wizard_list_base.cpp + dialogs/dialog_footprint_wizard_list.cpp ) # some of the files here may be going to the dialog srcs in fact.... diff --git a/pcbnew/class_footprint_wizard.cpp b/pcbnew/class_footprint_wizard.cpp index 6e85ac4b55..cabc5a2268 100644 --- a/pcbnew/class_footprint_wizard.cpp +++ b/pcbnew/class_footprint_wizard.cpp @@ -13,6 +13,32 @@ void FOOTPRINT_WIZARD::register_wizard() std::vector FOOTPRINT_WIZARDS::m_FootprintWizards; + +FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard(int aIndex) +{ + return m_FootprintWizards[aIndex]; +} + +FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard(wxString aName) +{ + int max = GetSize(); + + for(int i=0; iGetName(); + if (name.Cmp(aName)) + return wizard; + } + + return NULL; +} + +int FOOTPRINT_WIZARDS::GetSize() +{ + return m_FootprintWizards.size(); +} + void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard) { diff --git a/pcbnew/class_footprint_wizard.h b/pcbnew/class_footprint_wizard.h index 36442a6218..2972aa55c9 100644 --- a/pcbnew/class_footprint_wizard.h +++ b/pcbnew/class_footprint_wizard.h @@ -37,6 +37,9 @@ private: public: static void register_wizard(FOOTPRINT_WIZARD *wizard); + static FOOTPRINT_WIZARD* GetWizard(wxString aName); + static FOOTPRINT_WIZARD* GetWizard(int aIndex); + static int GetSize(); }; diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp new file mode 100644 index 0000000000..d93711f0f2 --- /dev/null +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp @@ -0,0 +1,70 @@ +/** + * @file dialog_scripting.cpp + */ + +#include + + + +#include +#include +#include +#include +#include +#include + + + +DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent ) + : DIALOG_FOOTPRINT_WIZARD_LIST_BASE( aParent ) +{ + SetFocus(); + int n_wizards = FOOTPRINT_WIZARDS::GetSize(); + + // Current wizard selection, empty or first + m_FootprintWizard = NULL; + + if (n_wizards) + m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(0); + + // Choose selection mode and insert the needed rows + m_footprintWizardsGrid->SetSelectionMode(wxGrid::wxGridSelectRows); + m_footprintWizardsGrid->InsertRows(0,n_wizards,true); + + // Put all wizards in the list + for (int i=0;iGetName(); + wxString description = wizard->GetDescription(); + wxString image = wizard->GetImage(); + + m_footprintWizardsGrid->SetCellValue(i,1,name); + m_footprintWizardsGrid->SetCellValue(i,2,description); + + } + + // Select the first row + m_footprintWizardsGrid->ClearSelection(); + m_footprintWizardsGrid->SelectRow(0,false); + +} + + +void DIALOG_FOOTPRINT_WIZARD_LIST::OnCellWizardClick( wxGridEvent& event ) +{ + int click_row = event.GetRow(); + m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(click_row); + +} + +FOOTPRINT_WIZARD* DIALOG_FOOTPRINT_WIZARD_LIST::GetWizard() +{ + return m_FootprintWizard; +} + +void DIALOG_FOOTPRINT_WIZARD_LIST::OnOpenButtonClick( wxCommandEvent& event ) +{ + this->MakeModal(false); + this->Close(true); +} diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.fbp b/pcbnew/dialogs/dialog_footprint_wizard_list.fbp new file mode 100644 index 0000000000..3c31fb3a71 --- /dev/null +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.fbp @@ -0,0 +1,263 @@ + + + + + + C++ + 1 + source_name + 0 + UTF-8 + connect + dialog_footprint_wizard_list_base + 1000 + none + 1 + DIALOG_FOOTPRINT_WIZARD_LIST_BASE + + . + + 1 + 1 + 0 + 0 + + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_FOOTPRINT_WIZARD_LIST_BASE + + + wxDEFAULT_DIALOG_STYLE + + Footprint Wizards + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizer4 + wxVERTICAL + none + + 5 + wxALL + 1 + + 0 + 1 + + + + wxALIGN_LEFT + + wxALIGN_TOP + wxALIGN_LEFT + 20 + "Preview" "Name" "Description" + wxALIGN_CENTRE + 3 + 80,80,325 + + 1 + 0 + 1 + 0 + 1 + 0 + 1 + + + + 1 + 0 + wxID_ANY + + + + 0 + 0 + + -1,120 + m_footprintWizardsGrid + protected + + wxALIGN_CENTRE + 1 + + wxALIGN_CENTRE + + 0 + + + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + OnCellWizardClick + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER|wxALL + 0 + + + + 1 + 0 + 1 + + + 0 + wxID_ANY + Open + + + m_btOpen + protected + + + + + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnOpenButtonClick + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.h b/pcbnew/dialogs/dialog_footprint_wizard_list.h new file mode 100644 index 0000000000..956df0c9d6 --- /dev/null +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.h @@ -0,0 +1,28 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: dialog_footprint_wizard_list.h +///////////////////////////////////////////////////////////////////////////// + +#ifndef _DIALOG_FOOTPRINT_WIZARD_LIST_H_ +#define _DIALOG_FOOTPRINT_WIZARD_LIST_H_ + +#include +#include + +class DIALOG_FOOTPRINT_WIZARD_LIST: public DIALOG_FOOTPRINT_WIZARD_LIST_BASE +{ +private: + wxDialog * m_Parent; + FOOTPRINT_WIZARD *m_FootprintWizard; + +public: + DIALOG_FOOTPRINT_WIZARD_LIST(wxWindow * parent ); + + FOOTPRINT_WIZARD* GetWizard(); + +private: + + void OnCellWizardClick( wxGridEvent& event ); + void OnOpenButtonClick( wxCommandEvent& event ); +}; + +#endif // _DIALOG_FOOTPRINT_WIZARD_LIST_H_ diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp new file mode 100644 index 0000000000..c273fad1fb --- /dev/null +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp @@ -0,0 +1,74 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Sep 8 2010) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_footprint_wizard_list_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizer4; + bSizer4 = new wxBoxSizer( wxVERTICAL ); + + m_footprintWizardsGrid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + // Grid + m_footprintWizardsGrid->CreateGrid( 0, 3 ); + m_footprintWizardsGrid->EnableEditing( false ); + m_footprintWizardsGrid->EnableGridLines( true ); + m_footprintWizardsGrid->EnableDragGridSize( false ); + m_footprintWizardsGrid->SetMargins( 0, 0 ); + + // Columns + m_footprintWizardsGrid->SetColSize( 0, 80 ); + m_footprintWizardsGrid->SetColSize( 1, 80 ); + m_footprintWizardsGrid->SetColSize( 2, 325 ); + m_footprintWizardsGrid->EnableDragColMove( false ); + m_footprintWizardsGrid->EnableDragColSize( true ); + m_footprintWizardsGrid->SetColLabelSize( 20 ); + m_footprintWizardsGrid->SetColLabelValue( 0, _("Preview") ); + m_footprintWizardsGrid->SetColLabelValue( 1, _("Name") ); + m_footprintWizardsGrid->SetColLabelValue( 2, _("Description") ); + m_footprintWizardsGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE ); + + // Rows + m_footprintWizardsGrid->AutoSizeRows(); + m_footprintWizardsGrid->EnableDragRowSize( true ); + m_footprintWizardsGrid->SetRowLabelSize( 1 ); + m_footprintWizardsGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Label Appearance + + // Cell Defaults + m_footprintWizardsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + m_footprintWizardsGrid->SetMinSize( wxSize( -1,120 ) ); + + bSizer4->Add( m_footprintWizardsGrid, 1, wxALL, 5 ); + + m_btOpen = new wxButton( this, wxID_ANY, _("Open"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer4->Add( m_btOpen, 0, wxALIGN_CENTER|wxALL, 5 ); + + this->SetSizer( bSizer4 ); + this->Layout(); + bSizer4->Fit( this ); + + this->Centre( wxBOTH ); + + // Connect Events + m_footprintWizardsGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellWizardClick ), NULL, this ); + m_btOpen->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnOpenButtonClick ), NULL, this ); +} + +DIALOG_FOOTPRINT_WIZARD_LIST_BASE::~DIALOG_FOOTPRINT_WIZARD_LIST_BASE() +{ + // Disconnect Events + m_footprintWizardsGrid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellWizardClick ), NULL, this ); + m_btOpen->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnOpenButtonClick ), NULL, this ); + +} diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list_base.h b/pcbnew/dialogs/dialog_footprint_wizard_list_base.h new file mode 100644 index 0000000000..2d35c9e058 --- /dev/null +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.h @@ -0,0 +1,49 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Sep 8 2010) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __dialog_footprint_wizard_list_base__ +#define __dialog_footprint_wizard_list_base__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_FOOTPRINT_WIZARD_LIST_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public wxDialog +{ + private: + + protected: + wxGrid* m_footprintWizardsGrid; + wxButton* m_btOpen; + + // Virtual event handlers, overide them in your derived class + virtual void OnCellWizardClick( wxGridEvent& event ) { event.Skip(); } + virtual void OnOpenButtonClick( wxCommandEvent& event ) { event.Skip(); } + + + public: + + DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Wizards"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); + ~DIALOG_FOOTPRINT_WIZARD_LIST_BASE(); + +}; + +#endif //__dialog_footprint_wizard_list_base__ diff --git a/pcbnew/footprint_wizard.cpp b/pcbnew/footprint_wizard.cpp index a3abdac2fc..151f7fd363 100644 --- a/pcbnew/footprint_wizard.cpp +++ b/pcbnew/footprint_wizard.cpp @@ -17,7 +17,7 @@ #include #include "footprint_wizard_frame.h" #include - +#include #define NEXT_PART 1 #define NEW_PART 0 @@ -77,28 +77,31 @@ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos() } -void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event ) +void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard() { - wxString msg; + DIALOG_FOOTPRINT_WIZARD_LIST *selectWizard = + new DIALOG_FOOTPRINT_WIZARD_LIST(this); + + selectWizard->ShowModal(); + + m_FootprintWizard = selectWizard->GetWizard(); - if( g_LibraryNames.GetCount() == 0 ) - return; - - EDA_LIST_DIALOG dlg( this, _( "Select Current Wizard:" ), - g_LibraryNames, m_wizardName ); - - if( dlg.ShowModal() != wxID_OK ) - return; - - if( m_wizardName == dlg.GetTextSelection() ) - return; - - m_wizardName = dlg.GetTextSelection(); + if (m_FootprintWizard) + { + m_wizardName = m_FootprintWizard->GetName(); + m_wizardDescription = m_FootprintWizard->GetDescription(); + } DisplayWizardInfos(); ReCreatePageList(); ReCreateParameterList(); +} + +void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event ) +{ + + SelectFootprintWizard(); } diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index ae534d96f9..0446804350 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -58,8 +58,12 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME ) EVT_SASH_DRAGGED( ID_FOOTPRINT_WIZARD_PARAMETERS, FOOTPRINT_WIZARD_FRAME::OnSashDrag ) /* Toolbar events */ + EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, + FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) + EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) + EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) /* EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE, @@ -111,6 +115,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* s SetIcon( icon ); m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr; + m_FootprintWizard = NULL; m_PageList= NULL; m_ParameterList = NULL; m_PageListWindow = NULL; @@ -238,7 +243,10 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* s Zoom_Automatique( false ); #endif + Show( true ); + + this->SelectFootprintWizard(); } @@ -321,37 +329,21 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList() { if( m_PageList == NULL ) return; + + if (m_FootprintWizard == NULL) + return; m_PageList->Clear(); - - m_PageList->Append(wxT("Pads")); - m_PageList->Append(wxT("Shield")); - + int max_page = m_FootprintWizard->GetNumParameterPages(); + for (int i=0;iGetParameterPageName(i); + m_PageList->Append(name); + } + m_PageList->SetSelection( 0, true ); - /*for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ ) - { - m_PageList->Append( g_LibraryNames[ii] ); - }*/ - -#if 0 - // Search for a previous selection: - - int index = m_PageList->FindString( m_libraryName ); - - if( index != wxNOT_FOUND ) - { - m_PageList->SetSelection( index, true ); - } - else - { - /* If not found, clear current library selection because it can be - * deleted after a config change. */ - m_libraryName = wxEmptyString; - m_footprintName = wxEmptyString; - } -#endif - + ReCreateParameterList(); ReCreateHToolbar(); DisplayWizardInfos(); m_canvas->Refresh(); @@ -362,19 +354,23 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList() { if( m_ParameterList == NULL ) return; + + if (m_FootprintWizard == NULL ) + return; + + int page = m_PageList->GetSelection(); + + if (page<0) + return; m_ParameterList->Clear(); - wxArrayString fpList; + wxArrayString fpList = m_FootprintWizard->GetParameterNames(page); m_ParameterList->Append( fpList ); - m_ParameterList->Append(wxT("N")); - m_ParameterList->Append(wxT("pitch")); - m_ParameterList->Append(wxT("width")); - m_ParameterList->Append(wxT("height")); m_ParameterList->SetSelection( 0, true ); - //m_ParameterList->SetSelection( index, true ); + } @@ -383,11 +379,7 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event ) int ii = m_PageList->GetSelection(); if( ii < 0 ) - return; - - wxString name = m_PageList->GetString( ii ); - - printf("page=%d\n",ii); + return; ReCreateParameterList(); m_canvas->Refresh(); diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 82777f246a..b4cead97d4 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -32,7 +32,7 @@ #include - +#include class wxSashLayoutWindow; class wxListBox; class wxSemaphore; @@ -57,6 +57,8 @@ private: // Flags 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 @@ -89,6 +91,8 @@ private: */ void ReCreatePageList(); void ReCreateParameterList(); + void SelectFootprintWizard(); + void Process_Special_Functions( wxCommandEvent& event ); void DisplayWizardInfos(); diff --git a/pcbnew/scripting/pcbnew_footprint_wizards.cpp b/pcbnew/scripting/pcbnew_footprint_wizards.cpp index 83bcb90b1a..7313326a0e 100644 --- a/pcbnew/scripting/pcbnew_footprint_wizards.cpp +++ b/pcbnew/scripting/pcbnew_footprint_wizards.cpp @@ -73,6 +73,13 @@ wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(const char* aMethod, PyObject return ret; } + +wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod + (const char *aMethod, PyObject *aArglist) +{ + +} + wxString PYTHON_FOOTPRINT_WIZARD::GetName() { return CallRetStrMethod("GetName"); @@ -128,6 +135,23 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName(int aPage) wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage) { wxArrayString a; + wxString ret; + PyObject *arglist; + PyObject *result; + + /* Time to call the callback */ + arglist = Py_BuildValue("(i)", aPage); + result = CallMethod("GetParameterPageNames",arglist); + Py_DECREF(arglist); + + if (result) + { + + // TODO GET ITEMS IN LIST + const char *str_res = PyString_AsString(result); + ret = wxString::FromUTF8(str_res); + Py_DECREF(result); + } return a; } diff --git a/pcbnew/scripting/pcbnew_footprint_wizards.h b/pcbnew/scripting/pcbnew_footprint_wizards.h index 0e03b44a41..5faca66e31 100644 --- a/pcbnew/scripting/pcbnew_footprint_wizards.h +++ b/pcbnew/scripting/pcbnew_footprint_wizards.h @@ -15,6 +15,9 @@ 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); + public: PYTHON_FOOTPRINT_WIZARD(PyObject *wizard); ~PYTHON_FOOTPRINT_WIZARD();