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
This commit is contained in:
jean-pierre charras 2017-04-16 13:53:56 +02:00
parent 60310b3d32
commit 50fd7a27cf
9 changed files with 221 additions and 44 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -42,9 +42,10 @@ private:
TEXTE_MODULE* m_valueCopy;
std::vector<S3D_INFO> 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

View File

@ -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 );
}

View File

@ -268,6 +268,7 @@
<property name="minimum_size"></property>
<property name="name">PropLeftSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<event name="OnUpdateUI"></event>
<object class="sizeritem" expanded="0">
@ -1206,7 +1207,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Footprint Name in Library</property>
<property name="label">Footprint name in library</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -1348,6 +1349,180 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Library nickname</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticTextLibNickname</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength">0</property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_LibraryNicknameCtrl</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxTE_READONLY</property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnText"></event>
<event name="OnTextEnter"></event>
<event name="OnTextMaxLen"></event>
<event name="OnTextURL"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
@ -1570,6 +1745,7 @@
<property name="minimum_size"></property>
<property name="name">sbSizerAutoplace</property>
<property name="orient">wxHORIZONTAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<event name="OnUpdateUI"></event>
<object class="sizeritem" expanded="0">
@ -1988,6 +2164,7 @@
<property name="minimum_size"></property>
<property name="name">sbSizer8</property>
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<event name="OnUpdateUI"></event>
<object class="sizeritem" expanded="0">
@ -3462,6 +3639,7 @@
<property name="minimum_size"></property>
<property name="name">sbSizer4</property>
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<event name="OnUpdateUI"></event>
<object class="sizeritem" expanded="0">
@ -3972,11 +4150,11 @@
<property name="name">m_sdbSizerStdButtons</property>
<property name="permission">protected</property>
<event name="OnApplyButtonClick"></event>
<event name="OnCancelButtonClick">OnCancelClick</event>
<event name="OnCancelButtonClick"></event>
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>
<event name="OnOKButtonClick">OnOkClick</event>
<event name="OnOKButtonClick"></event>
<event name="OnSaveButtonClick"></event>
<event name="OnYesButtonClick"></event>
</object>

View File

@ -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:

View File

@ -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;

View File

@ -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<MODULE*>( aItem ) );
int ret = dialog.ShowModal();
dialog.ShowModal();
GetScreen()->GetCurItem()->ClearFlags();
m_canvas->MoveCursorToCrossHair();
if( ret > 0 )
m_canvas->Refresh();
m_canvas->Refresh();
}
break;