Fix a few (minor) issues:

- Make DIALOG_SHIM::SetPosition working)
- rename PCB_BASE_FRAME::SelectLayer() to PCB_BASE_FRAME::SelectOneLayer()
- PCB_BASE_FRAME::SelectOneLayer(): make dismiss dialog by escape key working.
Fixes #7578
https://gitlab.com/kicad/code/kicad/issues/7578
This commit is contained in:
jean-pierre charras 2021-02-17 20:47:28 +01:00
parent 34c2028e7b
commit 5d2dc0b50e
6 changed files with 63 additions and 10 deletions

View File

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

View File

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

View File

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

View File

@ -753,9 +753,7 @@ 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<PCB_LAYER_ID>( currentLayer ),
targetLayer = frame()->SelectOneLayer( static_cast<PCB_LAYER_ID>( currentLayer ),
LSET::AllNonCuMask(), endPoint );
// Reset the cursor to the end of the track

View File

@ -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,7 +222,8 @@ void PCB_ONE_LAYER_SELECTOR::OnRightGridCellClick( wxGridEvent& event )
}
PCB_LAYER_ID PCB_BASE_FRAME::SelectLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask,
PCB_LAYER_ID PCB_BASE_FRAME::SelectOneLayer( PCB_LAYER_ID aDefaultLayer,
LSET aNotAllowedLayersMask,
wxPoint aDlgPosition )
{
PCB_ONE_LAYER_SELECTOR dlg( this, GetBoard(), aDefaultLayer, aNotAllowedLayersMask );

View File

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