From 50fd7a27cf69999a1912b9dc7e5c162b23e732e1 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 16 Apr 2017 13:53:56 +0200 Subject: [PATCH] Fix a few coding issues in dialog_edit_module_for_Modedit. (Mainly, remove OnOkClick and OnCancelClick to use default handlers, and use TransferDataFromWindow to update fields) Fix also a minor issue in lib_id --- common/lib_id.cpp | 9 +- include/lib_id.h | 2 +- .../dialog_edit_module_for_Modedit.cpp | 30 +-- .../dialogs/dialog_edit_module_for_Modedit.h | 8 +- .../dialog_edit_module_for_Modedit_base.cpp | 15 +- .../dialog_edit_module_for_Modedit_base.fbp | 184 +++++++++++++++++- .../dialog_edit_module_for_Modedit_base.h | 6 +- pcbnew/modedit.cpp | 5 +- pcbnew/modedit_onclick.cpp | 6 +- 9 files changed, 221 insertions(+), 44 deletions(-) diff --git a/common/lib_id.cpp b/common/lib_id.cpp index 7eae9d02f7..049e8abcdb 100644 --- a/common/lib_id.cpp +++ b/common/lib_id.cpp @@ -296,8 +296,6 @@ UTF8 LIB_ID::GetLibItemNameAndRev() const } -#if 0 // this is broken, it does not output aLibItemName for some reason - UTF8 LIB_ID::Format( const UTF8& aLogicalLib, const UTF8& aLibItemName, const UTF8& aRevision ) throw( PARSE_ERROR ) { @@ -312,15 +310,15 @@ UTF8 LIB_ID::Format( const UTF8& aLogicalLib, const UTF8& aLibItemName, const UT { THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ), wxString::FromUTF8( aLogicalLib.c_str() ), - aLogicalLib.c_str(), - 0, - offset ); + aLogicalLib.c_str(), 0, offset ); } ret += aLogicalLib; ret += ':'; } + ret += aLibItemName; // TODO: Add validity test. + if( aRevision.size() ) { offset = okRevision( aRevision ); @@ -340,7 +338,6 @@ UTF8 LIB_ID::Format( const UTF8& aLogicalLib, const UTF8& aLibItemName, const UT return ret; } -#endif int LIB_ID::compare( const LIB_ID& aLibId ) const diff --git a/include/lib_id.h b/include/lib_id.h index 4826128198..7967d0a495 100644 --- a/include/lib_id.h +++ b/include/lib_id.h @@ -159,10 +159,10 @@ public: * aLibNickname, aLibItemName, and aRevision. * * @throw PARSE_ERROR if any of the pieces are illegal. + */ static UTF8 Format( const UTF8& aLibNickname, const UTF8& aLibItemName, const UTF8& aRevision = "" ) throw( PARSE_ERROR ); - */ /** * Function IsValid diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 51569cbd37..cfe69f2d41 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -172,7 +172,10 @@ void DIALOG_MODULE_MODULE_EDITOR::initModeditProperties() m_valueCopy->SetParent( m_currentModule ); m_ReferenceCtrl->SetValue( m_referenceCopy->GetText() ); m_ValueCtrl->SetValue( m_valueCopy->GetText() ); - m_FootprintNameCtrl->SetValue( FROM_UTF8( m_currentModule->GetFPID().Format() ) ); + + m_currentFPID = m_currentModule->GetFPID(); + m_FootprintNameCtrl->SetValue( FROM_UTF8( m_currentFPID.GetLibItemName() ) ); + m_LibraryNicknameCtrl->SetValue( FROM_UTF8( m_currentFPID.GetLibNickname() ) ); m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD components" ) ); m_AttributsCtrl->SetItemToolTip( 1, @@ -433,17 +436,9 @@ void DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DShapeFile() } -void DIALOG_MODULE_MODULE_EDITOR::OnCancelClick( wxCommandEvent& event ) +bool DIALOG_MODULE_MODULE_EDITOR::TransferDataFromWindow() { - EndModal( -1 ); -} - - -void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) -{ - BOARD_COMMIT commit( m_parent ); wxString msg; - // First, test for invalid chars in module name wxString footprintName = m_FootprintNameCtrl->GetValue(); @@ -451,22 +446,24 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) { if( ! MODULE::IsLibNameValid( footprintName ) ) { - msg.Printf( _( "Error:\none of invalid chars <%s> found\nin <%s>" ), + msg.Printf( _( "Error:\n" + "one of invalid chars <%s> found\nin <%s>" ), MODULE::StringLibNameInvalidChars( true ), GetChars( footprintName ) ); DisplayError( NULL, msg ); - return; + return false; } } if( !m_PreviewPane->ValidateWithMessage( msg ) ) { DisplayError( NULL, msg ); - return; + return false; } + BOARD_COMMIT commit( m_parent ); commit.Modify( m_currentModule ); m_currentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 ); @@ -493,7 +490,10 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) // Init footprint name in library if( ! footprintName.IsEmpty() ) - m_currentModule->SetFPID( LIB_ID( footprintName ) ); + { + m_currentFPID.SetLibItemName( footprintName, false ); + m_currentModule->SetFPID( m_currentFPID ); + } // Init Fields: TEXTE_MODULE& reference = m_currentModule->Reference(); @@ -527,7 +527,7 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) commit.Push( _( "Modify module properties" ) ); - EndModal( 1 ); + return true; } diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.h b/pcbnew/dialogs/dialog_edit_module_for_Modedit.h index 00b908e36c..5d98198098 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.h +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.h @@ -42,9 +42,10 @@ private: TEXTE_MODULE* m_valueCopy; std::vector m_shapes3D_list; int m_lastSelected3DShapeIndex; - static size_t m_page; // remember the last open page during session + static size_t m_page; // remember the last open page during session PANEL_PREV_3D* m_PreviewPane; MODULE* m_currentModuleCopy; + LIB_ID m_currentFPID; // the full initial FPID public: @@ -71,10 +72,11 @@ private: { Edit3DShapeFileName(); } - void OnCancelClick( wxCommandEvent& event ) override; - void OnOkClick( wxCommandEvent& event ) override; + void Cfg3DPath( wxCommandEvent& event ) override; + bool TransferDataFromWindow() override; + void OnInitDlg( wxInitDialogEvent& event ) override { // Call the default wxDialog handler of a wxInitDialogEvent diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.cpp index 20321e0dcb..e3f2e0e4e2 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version May 6 2016) +// C++ code generated with wxFormBuilder (version Feb 19 2017) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -72,13 +72,20 @@ DIALOG_MODULE_MODULE_EDITOR_BASE::DIALOG_MODULE_MODULE_EDITOR_BASE( wxWindow* pa PropLeftSizer->Add( 0, 20, 0, 0, 5 ); - m_staticTextFp = new wxStaticText( PropLeftSizer->GetStaticBox(), wxID_ANY, _("Footprint Name in Library"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextFp = new wxStaticText( PropLeftSizer->GetStaticBox(), wxID_ANY, _("Footprint name in library"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextFp->Wrap( -1 ); PropLeftSizer->Add( m_staticTextFp, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_FootprintNameCtrl = new wxTextCtrl( PropLeftSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); PropLeftSizer->Add( m_FootprintNameCtrl, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5 ); + m_staticTextLibNickname = new wxStaticText( PropLeftSizer->GetStaticBox(), wxID_ANY, _("Library nickname"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextLibNickname->Wrap( -1 ); + PropLeftSizer->Add( m_staticTextLibNickname, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_LibraryNicknameCtrl = new wxTextCtrl( PropLeftSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); + PropLeftSizer->Add( m_LibraryNicknameCtrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + PropLeftSizer->Add( 0, 0, 0, wxEXPAND, 5 ); @@ -308,8 +315,6 @@ DIALOG_MODULE_MODULE_EDITOR_BASE::DIALOG_MODULE_MODULE_EDITOR_BASE( wxWindow* pa m_buttonRemove->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::Remove3DShape ), NULL, this ); m_buttonEdit->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::Edit3DShapeFilename ), NULL, this ); m_button6->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::Cfg3DPath ), NULL, this ); - m_sdbSizerStdButtonsCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::OnCancelClick ), NULL, this ); - m_sdbSizerStdButtonsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::OnOkClick ), NULL, this ); } DIALOG_MODULE_MODULE_EDITOR_BASE::~DIALOG_MODULE_MODULE_EDITOR_BASE() @@ -324,7 +329,5 @@ DIALOG_MODULE_MODULE_EDITOR_BASE::~DIALOG_MODULE_MODULE_EDITOR_BASE() m_buttonRemove->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::Remove3DShape ), NULL, this ); m_buttonEdit->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::Edit3DShapeFilename ), NULL, this ); m_button6->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::Cfg3DPath ), NULL, this ); - m_sdbSizerStdButtonsCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::OnCancelClick ), NULL, this ); - m_sdbSizerStdButtonsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MODULE_MODULE_EDITOR_BASE::OnOkClick ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.fbp b/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.fbp index e71b85b2ba..7d202bf4a7 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.fbp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.fbp @@ -268,6 +268,7 @@ PropLeftSizer wxVERTICAL + 1 none @@ -1206,7 +1207,7 @@ 0 0 wxID_ANY - Footprint Name in Library + Footprint name in library 0 @@ -1348,6 +1349,180 @@ + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Library nickname + + 0 + + + 0 + + 1 + m_staticTextLibNickname + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_LibraryNicknameCtrl + 1 + + + protected + 1 + + Resizable + 1 + + wxTE_READONLY + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxEXPAND @@ -1570,6 +1745,7 @@ sbSizerAutoplace wxHORIZONTAL + 1 none @@ -1988,6 +2164,7 @@ sbSizer8 wxVERTICAL + 1 none @@ -3462,6 +3639,7 @@ sbSizer4 wxVERTICAL + 1 none @@ -3972,11 +4150,11 @@ m_sdbSizerStdButtons protected - OnCancelClick + - OnOkClick + diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.h b/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.h index c57fdd3a39..2e6082e51b 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.h +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version May 6 2016) +// C++ code generated with wxFormBuilder (version Feb 19 2017) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -65,6 +65,8 @@ class DIALOG_MODULE_MODULE_EDITOR_BASE : public DIALOG_SHIM wxButton* m_button5; wxStaticText* m_staticTextFp; wxTextCtrl* m_FootprintNameCtrl; + wxStaticText* m_staticTextLibNickname; + wxTextCtrl* m_LibraryNicknameCtrl; wxRadioBox* m_AttributsCtrl; wxRadioBox* m_AutoPlaceCtrl; wxStaticText* m_staticText11; @@ -107,8 +109,6 @@ class DIALOG_MODULE_MODULE_EDITOR_BASE : public DIALOG_SHIM virtual void Add3DShape( wxCommandEvent& event ) { event.Skip(); } virtual void Remove3DShape( wxCommandEvent& event ) { event.Skip(); } virtual void Cfg3DPath( wxCommandEvent& event ) { event.Skip(); } - virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 3651d2628f..28e0b51261 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -580,11 +580,10 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) DIALOG_MODULE_MODULE_EDITOR dialog( this, (MODULE*) GetScreen()->GetCurItem() ); - int ret = dialog.ShowModal(); + dialog.ShowModal(); GetScreen()->GetCurItem()->ClearFlags(); - if( ret > 0 ) - m_canvas->Refresh(); + m_canvas->Refresh(); } break; diff --git a/pcbnew/modedit_onclick.cpp b/pcbnew/modedit_onclick.cpp index 4bf4c4ae79..7e760583b0 100644 --- a/pcbnew/modedit_onclick.cpp +++ b/pcbnew/modedit_onclick.cpp @@ -531,12 +531,10 @@ void FOOTPRINT_EDIT_FRAME::OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem ) case PCB_MODULE_T: { DIALOG_MODULE_MODULE_EDITOR dialog( this, static_cast( aItem ) ); - int ret = dialog.ShowModal(); + dialog.ShowModal(); GetScreen()->GetCurItem()->ClearFlags(); m_canvas->MoveCursorToCrossHair(); - - if( ret > 0 ) - m_canvas->Refresh(); + m_canvas->Refresh(); } break;