From 86273e86b98a19cc5043e63fedcab255be0c1751 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 12 Nov 2018 23:08:47 +0000 Subject: [PATCH] Added user and grid origins to Position Relative dialog. Also fixed a refresh bug when doing Position Relative. Fixes: lp:1792699 * https://bugs.launchpad.net/kicad/+bug/1792699 --- pcbnew/dialogs/dialog_position_relative.cpp | 18 + pcbnew/dialogs/dialog_position_relative.h | 2 + .../dialogs/dialog_position_relative_base.cpp | 55 +- .../dialogs/dialog_position_relative_base.fbp | 715 ++++++++++++------ .../dialogs/dialog_position_relative_base.h | 4 + pcbnew/tools/position_relative_tool.cpp | 2 + 6 files changed, 536 insertions(+), 260 deletions(-) diff --git a/pcbnew/dialogs/dialog_position_relative.cpp b/pcbnew/dialogs/dialog_position_relative.cpp index fe58ff1b49..c76f7e8805 100644 --- a/pcbnew/dialogs/dialog_position_relative.cpp +++ b/pcbnew/dialogs/dialog_position_relative.cpp @@ -162,6 +162,24 @@ void DIALOG_POSITION_RELATIVE::OnSelectItemClick( wxCommandEvent& event ) } +void DIALOG_POSITION_RELATIVE::OnUseGridOriginClick( wxCommandEvent& event ) +{ + BOARD* board = (BOARD*) m_toolMgr->GetModel(); + + m_anchor_position = board->GetGridOrigin(); + m_referenceInfo->SetLabel( _( "Reference location: grid origin" ) ); +} + + +void DIALOG_POSITION_RELATIVE::OnUseUserOriginClick( wxCommandEvent& event ) +{ + PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame(); + + m_anchor_position = frame->GetScreen()->m_O_Curseur; + m_referenceInfo->SetLabel( _( "Reference location: local coordinates origin" ) ); +} + + void DIALOG_POSITION_RELATIVE::UpdateAnchor( EDA_ITEM* aItem ) { wxString reference = _( "" ); diff --git a/pcbnew/dialogs/dialog_position_relative.h b/pcbnew/dialogs/dialog_position_relative.h index aee4754bfb..fa142aa6e4 100644 --- a/pcbnew/dialogs/dialog_position_relative.h +++ b/pcbnew/dialogs/dialog_position_relative.h @@ -61,6 +61,8 @@ private: void OnClear( wxCommandEvent& event ) override; void OnSelectItemClick( wxCommandEvent& event ) override; + void OnUseGridOriginClick( wxCommandEvent& event ) override; + void OnUseUserOriginClick( wxCommandEvent& event ) override; void OnOkClick( wxCommandEvent& event ) override; /** diff --git a/pcbnew/dialogs/dialog_position_relative_base.cpp b/pcbnew/dialogs/dialog_position_relative_base.cpp index 3c2a635b89..132beaa765 100644 --- a/pcbnew/dialogs/dialog_position_relative_base.cpp +++ b/pcbnew/dialogs/dialog_position_relative_base.cpp @@ -17,28 +17,46 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, bMainSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer* bUpperSizer; - bUpperSizer = new wxBoxSizer( wxHORIZONTAL ); + bUpperSizer = new wxBoxSizer( wxVERTICAL ); m_referenceInfo = new wxStaticText( this, wxID_ANY, _("Reference item: "), wxDefaultPosition, wxDefaultSize, 0 ); m_referenceInfo->Wrap( -1 ); m_referenceInfo->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); m_referenceInfo->SetMinSize( wxSize( 340,-1 ) ); - bUpperSizer->Add( m_referenceInfo, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); + bUpperSizer->Add( m_referenceInfo, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - bUpperSizer->Add( 0, 0, 1, wxEXPAND, 5 ); + bUpperSizer->Add( 0, 0, 0, wxEXPAND, 5 ); - m_select_anchor_button = new wxButton( this, wxID_ANY, _("Select"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); + wxBoxSizer* bSizer4; + bSizer4 = new wxBoxSizer( wxHORIZONTAL ); + + m_user_origin_button = new wxButton( this, wxID_ANY, _("Use Local Origin"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer4->Add( m_user_origin_button, 1, wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_grid_origin_button = new wxButton( this, wxID_ANY, _("Use Grid Origin"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer4->Add( m_grid_origin_button, 1, wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_select_anchor_button = new wxButton( this, wxID_ANY, _("Select Item..."), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); m_select_anchor_button->SetToolTip( _("Click and select a board item.\nThe anchor position will be the position of the selected item.") ); - bUpperSizer->Add( m_select_anchor_button, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); + bSizer4->Add( m_select_anchor_button, 1, wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - bMainSizer->Add( bUpperSizer, 0, wxEXPAND|wxALL, 10 ); + bUpperSizer->Add( bSizer4, 1, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 ); + + wxBoxSizer* bSizer6; + bSizer6 = new wxBoxSizer( wxVERTICAL ); m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bMainSizer->Add( m_staticline2, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 ); + bSizer6->Add( m_staticline2, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); + + + bUpperSizer->Add( bSizer6, 0, wxEXPAND|wxTOP, 3 ); + + + bMainSizer->Add( bUpperSizer, 0, wxEXPAND|wxALL, 5 ); wxFlexGridSizer* fgSizer2; fgSizer2 = new wxFlexGridSizer( 0, 5, 5, 0 ); @@ -58,7 +76,7 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, fgSizer2->Add( m_xUnit, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxTOP|wxRIGHT, 5 ); - fgSizer2->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); + fgSizer2->Add( 10, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); m_clearX = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); fgSizer2->Add( m_clearX, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 ); @@ -75,7 +93,7 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, fgSizer2->Add( m_yUnit, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 ); + fgSizer2->Add( 10, 0, 1, wxEXPAND, 5 ); m_clearY = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); fgSizer2->Add( m_clearY, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); @@ -83,15 +101,24 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, bMainSizer->Add( fgSizer2, 1, wxEXPAND|wxALL, 10 ); + wxBoxSizer* bSizer5; + bSizer5 = new wxBoxSizer( wxVERTICAL ); + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bMainSizer->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 ); + bSizer5->Add( m_staticline1, 0, wxEXPAND|wxALL, 5 ); + + + bMainSizer->Add( bSizer5, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* bSizerBottom; bSizerBottom = new wxBoxSizer( wxHORIZONTAL ); m_polarCoords = new wxCheckBox( this, wxID_ANY, _("Use polar coordinates"), wxDefaultPosition, wxDefaultSize, 0 ); m_polarCoords->SetValue(true); - bSizerBottom->Add( m_polarCoords, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + bSizerBottom->Add( m_polarCoords, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, 5 ); + + + bSizerBottom->Add( 40, 0, 1, wxEXPAND, 5 ); m_stdButtons = new wxStdDialogButtonSizer(); m_stdButtonsOK = new wxButton( this, wxID_OK ); @@ -100,7 +127,7 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, m_stdButtons->AddButton( m_stdButtonsCancel ); m_stdButtons->Realize(); - bSizerBottom->Add( m_stdButtons, 1, wxALL|wxEXPAND, 5 ); + bSizerBottom->Add( m_stdButtons, 0, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); bMainSizer->Add( bSizerBottom, 0, wxEXPAND|wxLEFT, 5 ); @@ -112,6 +139,8 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, // Connect Events this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClose ) ); + m_user_origin_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnUseUserOriginClick ), NULL, this ); + m_grid_origin_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnUseGridOriginClick ), NULL, this ); m_select_anchor_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnSelectItemClick ), NULL, this ); m_xEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_clearX->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this ); @@ -125,6 +154,8 @@ DIALOG_POSITION_RELATIVE_BASE::~DIALOG_POSITION_RELATIVE_BASE() { // Disconnect Events this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClose ) ); + m_user_origin_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnUseUserOriginClick ), NULL, this ); + m_grid_origin_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnUseGridOriginClick ), NULL, this ); m_select_anchor_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnSelectItemClick ), NULL, this ); m_xEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_clearX->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_position_relative_base.fbp b/pcbnew/dialogs/dialog_position_relative_base.fbp index a454d01110..75ba3e2ec9 100644 --- a/pcbnew/dialogs/dialog_position_relative_base.fbp +++ b/pcbnew/dialogs/dialog_position_relative_base.fbp @@ -94,17 +94,17 @@ wxVERTICAL none - 10 + 5 wxEXPAND|wxALL 0 bUpperSizer - wxHORIZONTAL + wxVERTICAL none 5 - wxALIGN_CENTER_HORIZONTAL|wxTOP|wxBOTTOM|wxRIGHT + wxALIGN_CENTER_VERTICAL|wxALL 0 1 @@ -188,7 +188,7 @@ 5 wxEXPAND - 1 + 0 0 protected @@ -197,173 +197,371 @@ 5 - wxALIGN_CENTER_VERTICAL|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Select - - 0 - - - 0 + wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT + 1 + - 1 - m_select_anchor_button - 1 - - - protected - 1 - - Resizable - 1 - - wxBU_EXACTFIT - - 0 - Click and select a board item. The anchor position will be the position of the selected item. - - wxFILTER_NONE - wxDefaultValidator - - - - - OnSelectItemClick - - - - - - - - - - - - - - - - - - - - - - - + bSizer4 + wxHORIZONTAL + none + + 5 + wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Use Local Origin + + 0 + + + 0 + + 1 + m_user_origin_button + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnUseUserOriginClick + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Use Grid Origin + + 0 + + + 0 + + 1 + m_grid_origin_button + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnUseGridOriginClick + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Select Item... + + 0 + + + 0 + + 1 + m_select_anchor_button + 1 + + + protected + 1 + + Resizable + 1 + + wxBU_EXACTFIT + + 0 + Click and select a board item. The anchor position will be the position of the selected item. + + wxFILTER_NONE + wxDefaultValidator + + + + + OnSelectItemClick + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + wxEXPAND|wxTOP + 0 + + + bSizer6 + wxVERTICAL + none + + 5 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline2 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - 10 - wxEXPAND|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_staticline2 - 1 - - - protected - 1 - - Resizable - 1 - - wxLI_HORIZONTAL - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -646,7 +844,7 @@ 0 protected - 0 + 10 @@ -1001,7 +1199,7 @@ 0 protected - 0 + 10 @@ -1095,84 +1293,95 @@ - 10 + 5 wxEXPAND|wxRIGHT|wxLEFT 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 + - 1 - m_staticline1 - 1 - - - protected - 1 - - Resizable - 1 - - wxLI_HORIZONTAL - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - + bSizer5 + wxVERTICAL + none + + 5 + wxEXPAND|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1186,7 +1395,7 @@ none 5 - wxALIGN_CENTER_VERTICAL|wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL 0 1 @@ -1272,10 +1481,20 @@ + + 5 + wxEXPAND + 1 + + 0 + protected + 40 + + 5 - wxALL|wxEXPAND - 1 + wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL + 0 0 1 diff --git a/pcbnew/dialogs/dialog_position_relative_base.h b/pcbnew/dialogs/dialog_position_relative_base.h index 389bedaac7..7966d767e5 100644 --- a/pcbnew/dialogs/dialog_position_relative_base.h +++ b/pcbnew/dialogs/dialog_position_relative_base.h @@ -37,6 +37,8 @@ class DIALOG_POSITION_RELATIVE_BASE : public DIALOG_SHIM protected: wxStaticText* m_referenceInfo; + wxButton* m_user_origin_button; + wxButton* m_grid_origin_button; wxButton* m_select_anchor_button; wxStaticLine* m_staticline2; wxStaticText* m_xLabel; @@ -55,6 +57,8 @@ class DIALOG_POSITION_RELATIVE_BASE : public DIALOG_SHIM // Virtual event handlers, overide them in your derived class virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } + virtual void OnUseUserOriginClick( wxCommandEvent& event ) { event.Skip(); } + virtual void OnUseGridOriginClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnSelectItemClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnTextFocusLost( wxFocusEvent& event ) { event.Skip(); } virtual void OnClear( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index e70fd850d3..4cbca3e6a4 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -130,6 +130,8 @@ int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint aPosAnchor, wxPoi m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true ); + + getEditFrame()->Refresh(); return 0; }