Commit c051c1a4 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

footprint wizard UI and footprint wizard lists

parent 23bec4b8
......@@ -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....
......
......@@ -13,6 +13,32 @@ void FOOTPRINT_WIZARD::register_wizard()
std::vector<FOOTPRINT_WIZARD*> 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; i<max;i++)
{
FOOTPRINT_WIZARD *wizard = GetWizard(i);
wxString name = wizard->GetName();
if (name.Cmp(aName))
return wizard;
}
return NULL;
}
int FOOTPRINT_WIZARDS::GetSize()
{
return m_FootprintWizards.size();
}
void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard)
{
......
......@@ -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();
};
......
/**
* @file dialog_scripting.cpp
*/
#include <wx-2.8/wx/generic/grid.h>
#include <fctsys.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <pcbcommon.h>
#include <dialog_footprint_wizard_list.h>
#include <class_footprint_wizard.h>
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;i<n_wizards;i++)
{
FOOTPRINT_WIZARD *wizard = FOOTPRINT_WIZARDS::GetWizard(i);
wxString name = wizard->GetName();
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);
}
This diff is collapsed.
/////////////////////////////////////////////////////////////////////////////
// Name: dialog_footprint_wizard_list.h
/////////////////////////////////////////////////////////////////////////////
#ifndef _DIALOG_FOOTPRINT_WIZARD_LIST_H_
#define _DIALOG_FOOTPRINT_WIZARD_LIST_H_
#include <dialog_footprint_wizard_list_base.h>
#include <class_footprint_wizard.h>
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_
///////////////////////////////////////////////////////////////////////////
// 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 );
}
///////////////////////////////////////////////////////////////////////////
// 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 <wx/intl.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/font.h>
#include <wx/grid.h>
#include <wx/gdicmn.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// 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__
......@@ -17,7 +17,7 @@
#include <pcbnew_id.h>
#include "footprint_wizard_frame.h"
#include <wildcards_and_files_ext.h>
#include <dialogs/dialog_footprint_wizard_list.h>
#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;
if( g_LibraryNames.GetCount() == 0 )
return;
EDA_LIST_DIALOG dlg( this, _( "Select Current Wizard:" ),
g_LibraryNames, m_wizardName );
DIALOG_FOOTPRINT_WIZARD_LIST *selectWizard =
new DIALOG_FOOTPRINT_WIZARD_LIST(this);
if( dlg.ShowModal() != wxID_OK )
return;
selectWizard->ShowModal();
if( m_wizardName == dlg.GetTextSelection() )
return;
m_FootprintWizard = selectWizard->GetWizard();
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();
}
......
......@@ -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();
}
......@@ -322,36 +330,20 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
if( m_PageList == NULL )
return;
m_PageList->Clear();
m_PageList->Append(wxT("Pads"));
m_PageList->Append(wxT("Shield"));
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 (m_FootprintWizard == NULL)
return;
if( index != wxNOT_FOUND )
{
m_PageList->SetSelection( index, true );
}
else
m_PageList->Clear();
int max_page = m_FootprintWizard->GetNumParameterPages();
for (int i=0;i<max_page;i++)
{
/* If not found, clear current library selection because it can be
* deleted after a config change. */
m_libraryName = wxEmptyString;
m_footprintName = wxEmptyString;
wxString name = m_FootprintWizard->GetParameterPageName(i);
m_PageList->Append(name);
}
#endif
m_PageList->SetSelection( 0, true );
ReCreateParameterList();
ReCreateHToolbar();
DisplayWizardInfos();
m_canvas->Refresh();
......@@ -363,18 +355,22 @@ 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 );
}
......@@ -385,10 +381,6 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
if( ii < 0 )
return;
wxString name = m_PageList->GetString( ii );
printf("page=%d\n",ii);
ReCreateParameterList();
m_canvas->Refresh();
DisplayWizardInfos();
......
......@@ -32,7 +32,7 @@
#include <wx/gdicmn.h>
#include <class_footprint_wizard.h>
class wxSashLayoutWindow;
class wxListBox;
class wxSemaphore;
......@@ -58,6 +58,8 @@ private:
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
......@@ -89,6 +91,8 @@ private:
*/
void ReCreatePageList();
void ReCreateParameterList();
void SelectFootprintWizard();
void Process_Special_Functions( wxCommandEvent& event );
void DisplayWizardInfos();
......
......@@ -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;
}
......
......@@ -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();
......
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