From e89db97dd4717d018bade4e22ec8fc242d5354a8 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 5 Aug 2013 15:43:15 +0200 Subject: [PATCH] Pcbnew: footprint wizard dialogs: minor fixes, and fixes a not working parmeters dialog under Windows, due to an incorrect Printf format. --- .../dialogs/dialog_footprint_wizard_list.cpp | 7 +- .../dialogs/dialog_footprint_wizard_list.fbp | 100 ++++-------------- pcbnew/dialogs/dialog_footprint_wizard_list.h | 4 +- .../dialog_footprint_wizard_list_base.cpp | 17 ++- .../dialog_footprint_wizard_list_base.h | 7 +- pcbnew/dialogs/dialog_set_grid_base.cpp | 6 +- pcbnew/dialogs/dialog_set_grid_base.fbp | 4 +- pcbnew/dialogs/dialog_set_grid_base.h | 2 +- pcbnew/footprint_wizard.cpp | 35 +++--- pcbnew/footprint_wizard_frame.cpp | 37 +++---- pcbnew/footprint_wizard_frame.h | 6 +- pcbnew/modedit.cpp | 17 ++- 12 files changed, 98 insertions(+), 144 deletions(-) diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp index d6ccf56ba8..e1e31d67e0 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp @@ -68,5 +68,10 @@ FOOTPRINT_WIZARD* DIALOG_FOOTPRINT_WIZARD_LIST::GetWizard() void DIALOG_FOOTPRINT_WIZARD_LIST::OnOpenButtonClick( wxCommandEvent& event ) { - Close(true); + EndModal( wxID_OK ); +} + +void DIALOG_FOOTPRINT_WIZARD_LIST::OnCancelClick( wxCommandEvent& event ) +{ + EndModal( wxID_CANCEL ); } diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.fbp b/pcbnew/dialogs/dialog_footprint_wizard_list.fbp index 2b0e8f9996..a90927a424 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.fbp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.fbp @@ -236,90 +236,28 @@ 5 - wxALIGN_CENTER|wxALL + wxEXPAND 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Open - - 0 - - - 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 - 1 - m_btOpen - 1 - - + m_sdbSizer protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnOpenButtonClick - - - - - - - - - - - - - - - - - - - - - - - + + OnCancelClick + + + + OnOpenButtonClick + + diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.h b/pcbnew/dialogs/dialog_footprint_wizard_list.h index 956df0c9d6..181bafd819 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.h +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.h @@ -16,13 +16,13 @@ private: public: DIALOG_FOOTPRINT_WIZARD_LIST(wxWindow * parent ); - + FOOTPRINT_WIZARD* GetWizard(); private: - void OnCellWizardClick( wxGridEvent& event ); void OnOpenButtonClick( wxCommandEvent& event ); + void OnCancelClick( 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 index f0144b1e17..a669fab58b 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp @@ -51,9 +51,14 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* bSizerMain->Add( m_footprintWizardsGrid, 1, wxALL|wxEXPAND, 5 ); - m_btOpen = new wxButton( this, wxID_ANY, _("Open"), wxDefaultPosition, wxDefaultSize, 0 ); - m_btOpen->SetDefault(); - bSizerMain->Add( m_btOpen, 0, wxALIGN_CENTER|wxALL, 5 ); + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizer->Realize(); + + bSizerMain->Add( m_sdbSizer, 0, wxEXPAND, 5 ); this->SetSizer( bSizerMain ); @@ -63,13 +68,15 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* // 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 ); + m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCancelClick ), NULL, this ); + m_sdbSizerOK->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 ); + m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCancelClick ), NULL, this ); + m_sdbSizerOK->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 index 63990720a6..ed7a8564dd 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list_base.h +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.h @@ -20,8 +20,8 @@ class DIALOG_SHIM; #include #include #include -#include #include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -36,10 +36,13 @@ class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public DIALOG_SHIM protected: wxGrid* m_footprintWizardsGrid; - wxButton* m_btOpen; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerCancel; // Virtual event handlers, overide them in your derived class virtual void OnCellWizardClick( wxGridEvent& event ) { event.Skip(); } + virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOpenButtonClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcbnew/dialogs/dialog_set_grid_base.cpp b/pcbnew/dialogs/dialog_set_grid_base.cpp index d28f7b7d8c..3530f39de9 100644 --- a/pcbnew/dialogs/dialog_set_grid_base.cpp +++ b/pcbnew/dialogs/dialog_set_grid_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 30 2013) +// C++ code generated with wxFormBuilder (version Oct 8 2012) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -114,14 +114,14 @@ DIALOG_SET_GRID_BASE::DIALOG_SET_GRID_BASE( wxWindow* parent, wxWindowID id, con m_staticTextGrid1->Wrap( -1 ); fgSizer3->Add( m_staticTextGrid1, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxLEFT|wxTOP, 5 ); - m_comboBoxGrid1 = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + m_comboBoxGrid1 = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); fgSizer3->Add( m_comboBoxGrid1, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 ); m_staticTextGrid2 = new wxStaticText( this, wxID_ANY, _("Grid 2:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextGrid2->Wrap( -1 ); fgSizer3->Add( m_staticTextGrid2, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxBOTTOM|wxLEFT|wxTOP, 5 ); - m_comboBoxGrid2 = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + m_comboBoxGrid2 = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); fgSizer3->Add( m_comboBoxGrid2, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/dialog_set_grid_base.fbp b/pcbnew/dialogs/dialog_set_grid_base.fbp index e03ad55b27..ac115f7829 100644 --- a/pcbnew/dialogs/dialog_set_grid_base.fbp +++ b/pcbnew/dialogs/dialog_set_grid_base.fbp @@ -1375,7 +1375,7 @@ -1 1 - + wxCB_READONLY 0 @@ -1549,7 +1549,7 @@ -1 1 - + wxCB_READONLY 0 diff --git a/pcbnew/dialogs/dialog_set_grid_base.h b/pcbnew/dialogs/dialog_set_grid_base.h index 3f8fbd7aaa..9bb3e86b55 100644 --- a/pcbnew/dialogs/dialog_set_grid_base.h +++ b/pcbnew/dialogs/dialog_set_grid_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 30 2013) +// C++ code generated with wxFormBuilder (version Oct 8 2012) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! diff --git a/pcbnew/footprint_wizard.cpp b/pcbnew/footprint_wizard.cpp index 75560423a0..28377da033 100644 --- a/pcbnew/footprint_wizard.cpp +++ b/pcbnew/footprint_wizard.cpp @@ -34,6 +34,7 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) { case ID_FOOTPRINT_WIZARD_NEXT: m_PageList->SetSelection( m_PageList->GetSelection() + 1, true ); + ClickOnPageList( event ); break; case ID_FOOTPRINT_WIZARD_PREVIOUS: @@ -43,6 +44,7 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) page = 0; m_PageList->SetSelection( page, true ); + ClickOnPageList( event ); break; default: @@ -102,19 +104,20 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint() SetCurItem( NULL ); // Delete the current footprint GetBoard()->m_Modules.DeleteAll(); - MODULE* m = footprintWizard->GetModule(); - if( m ) + // Creates the module + MODULE* module = footprintWizard->GetModule(); + + if( module ) { - /* 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->SetPosition( p ); + // Add the object to board + module->SetParent( (EDA_ITEM*) GetBoard() ); + GetBoard()->m_Modules.Append( module ); + module->SetPosition( wxPoint( 0, 0 ) ); } else { - printf( "footprintWizard->GetModule() returns NULL\n" ); + D(printf( "footprintWizard->GetModule() returns NULL\n" );) } m_canvas->Refresh(); @@ -142,14 +145,12 @@ MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint() { FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName ); - if( footprintWizard ) + if( footprintWizard && m_exportRequest ) { return footprintWizard->GetModule(); } - else - { - return NULL; - } + + return NULL; } @@ -158,7 +159,8 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard() DIALOG_FOOTPRINT_WIZARD_LIST* selectWizard = new DIALOG_FOOTPRINT_WIZARD_LIST( this ); - selectWizard->ShowModal(); + if( selectWizard->ShowModal() != wxID_OK ) + return; FOOTPRINT_WIZARD* footprintWizard = selectWizard->GetWizard(); @@ -225,14 +227,11 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event ) dValue = dValue / 1000.0; dValue = From_User_Unit( g_UserUnit, dValue ); - - value.Printf( wxT( "%lf" ), dValue ); + value.Printf( wxT( "%f" ), dValue ); } // If our locale is set to use , for decimal point, just change it // to be scripting compatible - - arr.Add( value ); } diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index f5e10d9b50..1804286618 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -127,11 +127,12 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, m_showAxis = true; // true to draw axis. // Give an icon - +#if 1 // Disabled for now, it raises an assert error in wxwidgets - // wxIcon icon; - // icon.CopyFromBitmap( KiBitmap( module_wizard_xpm) ); - // SetIcon( icon ); + wxIcon icon; + icon.CopyFromBitmap( KiBitmap( module_wizard_xpm) ); + SetIcon( icon ); +#endif m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr; m_PageList = NULL; @@ -140,6 +141,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent, m_ParameterGridWindow = NULL; m_Semaphore = semaphore; m_wizardName.Empty(); + m_exportRequest = false; if( m_Semaphore ) SetModalMode( true ); @@ -199,11 +201,11 @@ 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->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE ); + m_ParameterGrid->AutoSizeColumns(); ReCreatePageList(); @@ -293,14 +295,6 @@ 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(); @@ -318,6 +312,13 @@ void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent ) } +void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent ) +{ + m_exportRequest = true; + Close(); +} + + /* Function OnSashDrag * handles the horizontal separator (sash) drag, updating the pagelist or parameter list */ @@ -450,10 +451,9 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList() m_ParameterGrid->DeleteRows( 0, m_ParameterGrid->GetNumberRows() ); m_ParameterGrid->AppendRows( fpList.size() ); + wxString name, value, units; for( unsigned int i = 0; iAddSeparator(); m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_PREVIOUS, wxEmptyString, KiBitmap( lib_previous_xpm ), - _( "Display previous page" ) ); + _( "Select previous editable item" ) ); m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_NEXT, wxEmptyString, KiBitmap( lib_next_xpm ), - _( "Display next page" ) ); + _( "Select next editable item" ) ); m_mainToolBar->AddSeparator(); m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW, wxEmptyString, diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index d52c07311e..f65ee1d62d 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -47,7 +47,6 @@ class FOOTPRINT_EDIT_FRAME; 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 @@ -55,15 +54,18 @@ private: wxSashLayoutWindow* m_ParameterGridWindow; // < List of components in the selected library wxGrid* m_ParameterGrid; // < The list of parameters - wxSize m_ParameterGridSize; // < size of the window + 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 + bool m_exportRequest; // < true if the current footprint should be exported + protected: 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, diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index c140224549..ca026f9f11 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -311,11 +311,6 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_MODEDIT_NEW_MODULE_FROM_WIZARD: { - Clear_Pcb( true ); - GetScreen()->ClearUndoRedoList(); - SetCurItem( NULL ); - SetCrossHairPosition( wxPoint( 0, 0 ) ); - wxSemaphore semaphore( 0, 1 ); FOOTPRINT_WIZARD_FRAME *wizard = new FOOTPRINT_WIZARD_FRAME( this, &semaphore, KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT ); @@ -328,11 +323,17 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) wxMilliSleep( 50 ); } + // Creates the new footprint from python script wizard MODULE* module = wizard->GetBuiltFootprint(); if( module ) // i.e. if create module command not aborted { - // Here we should make a copy of the object before adding to board + Clear_Pcb( true ); + GetScreen()->ClearUndoRedoList(); + SetCurItem( NULL ); + SetCrossHairPosition( wxPoint( 0, 0 ) ); + + // Add the new object to board module->SetParent( (EDA_ITEM*)GetBoard() ); GetBoard()->m_Modules.Append( module ); @@ -342,9 +343,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) GetBoard()->BuildListOfNets(); redraw = true; module->SetPosition( wxPoint( 0, 0 ) ); - - if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); + module->ClearFlags(); } wizard->Destroy();