diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index 8de4f18c34..2f3d76f2cc 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -183,6 +183,36 @@ int DIALOG_SHIM::vertPixelsFromDU( int y ) const static RECT_MAP class_map; + +void DIALOG_SHIM::SetPosition( const wxPoint& aNewPosition ) +{ + wxDialog::SetPosition( aNewPosition ); + + // Now update the stored position: + const char* hash_key; + + if( m_hash_key.size() ) + { + // a special case like EDA_LIST_DIALOG, which has multiple uses. + hash_key = m_hash_key.c_str(); + } + else + { + hash_key = typeid(*this).name(); + } + + RECT_MAP::iterator it = class_map.find( hash_key ); + + if( it == class_map.end() ) + return; + + EDA_RECT rect = it->second; + rect.SetOrigin( aNewPosition ); + + class_map[ hash_key ] = rect; +} + + bool DIALOG_SHIM::Show( bool show ) { bool ret; diff --git a/include/dialog_shim.h b/include/dialog_shim.h index 420474892f..a0f2038271 100644 --- a/include/dialog_shim.h +++ b/include/dialog_shim.h @@ -112,6 +112,11 @@ public: void OnPaint( wxPaintEvent &event ); + /** Force the position of the dialog to a new position + * @param aNewPosition is the new forced position + */ + void SetPosition( const wxPoint& aNewPosition ); + EDA_UNITS GetUserUnits() const { return m_units; diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 61ead52f00..8665f2f8e6 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -328,16 +328,16 @@ public: /** - * Show the dialog box for layer selection. + * Show the dialog box for a layer selection. * - * @param aDefaultLayer is the default layer to select. Use #NB_PCB_LAYERS if no selection + * @param aDefaultLayer is the default layer to select. Use UNDEFINED_LAYER if no selection * is desired. * @param aNotAllowedLayersMask is a layer mask for not allowed layers. Use 0 to show all * layers in use. * @param aDlgPosition is the position of dialog (default is centered). * @return the selected layer id. */ - PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(), + PCB_LAYER_ID SelectOneLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(), wxPoint aDlgPosition = wxDefaultPosition ); virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 90313a2cdd..a704f0d812 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -753,10 +753,8 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia ) wxPoint endPoint = (wxPoint) view()->ToScreen( m_endSnapPoint ); endPoint = frame()->GetCanvas()->ClientToScreen( endPoint ); - controls()->WarpCursor( endPoint ); - - targetLayer = frame()->SelectLayer( static_cast( currentLayer ), - LSET::AllNonCuMask(), endPoint ); + targetLayer = frame()->SelectOneLayer( static_cast( currentLayer ), + LSET::AllNonCuMask(), endPoint ); // Reset the cursor to the end of the track controls()->SetCursorPosition( m_endSnapPoint ); diff --git a/pcbnew/sel_layer.cpp b/pcbnew/sel_layer.cpp index 0fc2730f88..6e8153abc0 100644 --- a/pcbnew/sel_layer.cpp +++ b/pcbnew/sel_layer.cpp @@ -89,6 +89,7 @@ class PCB_ONE_LAYER_SELECTOR : public PCB_LAYER_SELECTOR, public: PCB_ONE_LAYER_SELECTOR( PCB_BASE_FRAME* aParent, BOARD * aBrd, PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask ); + ~PCB_ONE_LAYER_SELECTOR(); LAYER_NUM GetLayerSelection() { return m_layerSelected; } @@ -97,6 +98,9 @@ private: void OnLeftGridCellClick( wxGridEvent& event ) override; void OnRightGridCellClick( wxGridEvent& event ) override; + // Will close the dialog on ESC key + void onCharHook( wxKeyEvent& event ); + void buildList(); }; @@ -119,12 +123,27 @@ PCB_ONE_LAYER_SELECTOR::PCB_ONE_LAYER_SELECTOR( PCB_BASE_FRAME* aParent, BOARD* m_rightGridLayers->SetColFormatBool( SELECT_COLNUM ); buildList(); + Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( PCB_ONE_LAYER_SELECTOR::onCharHook ) ); + Layout(); GetSizer()->SetSizeHints( this ); SetFocus(); } +PCB_ONE_LAYER_SELECTOR::~PCB_ONE_LAYER_SELECTOR() +{ + Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( PCB_ONE_LAYER_SELECTOR::onCharHook ) ); +} + + +void PCB_ONE_LAYER_SELECTOR::onCharHook( wxKeyEvent& event ) +{ + if( event.GetKeyCode() == WXK_ESCAPE ) + Close(); +} + + void PCB_ONE_LAYER_SELECTOR::buildList() { wxColour bg = getLayerColor( LAYER_PCB_BACKGROUND ).ToColour(); @@ -203,8 +222,9 @@ void PCB_ONE_LAYER_SELECTOR::OnRightGridCellClick( wxGridEvent& event ) } -PCB_LAYER_ID PCB_BASE_FRAME::SelectLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask, - wxPoint aDlgPosition ) +PCB_LAYER_ID PCB_BASE_FRAME::SelectOneLayer( PCB_LAYER_ID aDefaultLayer, + LSET aNotAllowedLayersMask, + wxPoint aDlgPosition ) { PCB_ONE_LAYER_SELECTOR dlg( this, GetBoard(), aDefaultLayer, aNotAllowedLayersMask ); diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index 7cab902c28..9be421dd46 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -537,7 +537,7 @@ int CONVERT_TOOL::PolyToLines( const TOOL_EVENT& aEvent ) BOARD_ITEM_CONTAINER* parent = frame->GetModel(); if( !IsCopperLayer( layer ) ) - layer = frame->SelectLayer( F_Cu, LSET::AllNonCuMask() ); + layer = frame->SelectOneLayer( F_Cu, LSET::AllNonCuMask() ); // I am really unsure converting a polygon to "tracks" (i.e. segments on // copper layers) make sense for footprints, but anyway this code exists