Add layer presets switcher.

Fixes https://gitlab.com/kicad/code/kicad/issues/5247
This commit is contained in:
Jeff Young 2020-08-19 11:31:20 +01:00
parent 01bf395cc2
commit 4b7c883095
12 changed files with 391 additions and 543 deletions

View File

@ -180,6 +180,8 @@ set( COMMON_DLG_SRCS
dialogs/dialog_text_entry.cpp
dialogs/eda_list_dialog.cpp
dialogs/eda_list_dialog_base.cpp
dialogs/eda_view_switcher.cpp
dialogs/eda_view_switcher_base.cpp
dialogs/panel_color_settings_base.cpp
dialogs/panel_color_settings.cpp
dialogs/panel_common_settings.cpp

View File

@ -1,9 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -24,194 +22,86 @@
*/
#include <fctsys.h>
#include <macros.h>
#include <eda_draw_frame.h>
#include <kicad_string.h>
#include <dialog_helpers.h>
#include <eda_view_switcher.h>
// wxWidgets spends *far* too long calcuating column widths (most of it, believe it or
// not, in repeatedly creating/destroying a wxDC to do the measurement in).
// Use default column widths instead.
static int DEFAULT_COL_WIDTHS[] = { 200, 600 };
#define LIST_BOX_H_PADDING 10
#define LIST_BOX_V_PADDING 5
EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemHeaders,
const std::vector<wxArrayString>& aItemList,
const wxString& aSelection ) :
EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
EDA_VIEW_SWITCHER::EDA_VIEW_SWITCHER( wxWindow* aParent, const wxArrayString& aItems ) :
EDA_VIEW_SWITCHER_BASE( aParent ),
m_tabState( true )
{
m_itemsList = &aItemList;
m_listBox->InsertItems( aItems, 0 );
m_listBox->SetSelection( std::min( 1, (int) m_listBox->GetCount() - 1 ) );
m_filterBox->SetHint( _( "Filter" ) );
int width = 0;
int height = 0;
initDialog( aItemHeaders, aSelection );
for( const wxString& item : aItems )
{
wxSize extents = m_listBox->GetTextExtent( item );
width = std::max( width, extents.x );
height += extents.y + LIST_BOX_V_PADDING;
}
// DIALOG_SHIM needs a unique hash_key because classname is not sufficient
// because so many dialogs share this same class, with different numbers of
// columns, different column names, and column widths.
m_hash_key = TO_UTF8( aTitle );
m_sdbSizerOK->SetDefault();
m_listBox->SetMinSize( wxSize( width + LIST_BOX_H_PADDING, height ) );
SetInitialFocus( m_listBox );
// this line fixes an issue on Linux Ubuntu using Unity (dialog not shown),
// and works fine on all systems
GetSizer()->Fit( this );
GetSizer()->Fit( this );
Centre();
}
void EDA_LIST_DIALOG::initDialog( const wxArrayString& aItemHeaders, const wxString& aSelection )
// OK, this is *really* annoying, but wxWidgets doesn't give us key-down events while the
// control key is being held down. So we can't use OnKeyDown() or OnCharHook() and instead
// must rely on watching key states in TryBefore().
//
// Just checking the state of the tab key is tempting, but then we'll think it's been hit
// several times when it's actually just a key-down followed by a redraw or idle event.
//
// So we have to keep a state machine of the tab key.
//
bool EDA_VIEW_SWITCHER::TryBefore( wxEvent& aEvent )
{
for( unsigned i = 0; i < aItemHeaders.Count(); i++ )
if( !wxGetKeyState( WXK_RAW_CONTROL ) )
{
m_listBox->InsertColumn( i, aItemHeaders.Item( i ),
wxLIST_FORMAT_LEFT, DEFAULT_COL_WIDTHS[ i ] );
EndModal( wxID_OK );
return true;
}
InsertItems( *m_itemsList, 0 );
if( !aSelection.IsEmpty() )
if( m_tabState )
{
long sel = m_listBox->FindItem( -1, aSelection );
if( !wxGetKeyState( WXK_TAB ) )
m_tabState = false;
}
else if( wxGetKeyState( WXK_TAB ) )
{
m_tabState = true;
if( sel != wxNOT_FOUND )
int idx = m_listBox->GetSelection();
if( wxGetKeyState( WXK_SHIFT ) )
{
m_listBox->SetItemState( sel, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
// Set to a small size so EnsureVisible() won't be foiled by later additions.
// ListBox will expand to fit later.
m_listBox->SetSize( m_listBox->GetSize().GetX(), 100 );
m_listBox->EnsureVisible( sel );
}
}
}
void EDA_LIST_DIALOG::SetListLabel( const wxString& aLabel )
{
m_listLabel->SetLabel( aLabel );
m_listBox->SetSingleStyle( wxLC_NO_HEADER, true );
}
void EDA_LIST_DIALOG::SetOKLabel( const wxString& aLabel )
{
m_sdbSizerOK->SetLabel( aLabel );
}
void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event )
{
wxString filter;
wxString itemName;
filter = wxT( "*" ) + m_filterBox->GetLineText( 0 ).MakeLower() + wxT( "*" );
m_listBox->DeleteAllItems();
for( const wxArrayString& row : *m_itemsList )
{
itemName = row.Item( 0 );
if( itemName.MakeLower().Matches( filter ) )
Append( row );
}
sortList();
}
wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn )
{
wxCHECK_MSG( unsigned( aColumn ) < unsigned( m_listBox->GetColumnCount() ), wxEmptyString,
wxT( "Invalid list control column." ) );
long item = m_listBox->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
if( item >= 0 ) // if something is selected.
{
wxListItem info;
info.m_mask = wxLIST_MASK_TEXT;
info.m_itemId = item;
info.m_col = aColumn;
if( m_listBox->GetItem( info ) )
return info.m_text;
}
return wxEmptyString;
}
void EDA_LIST_DIALOG::Append( const wxArrayString& itemList )
{
long itemIndex = m_listBox->InsertItem( m_listBox->GetItemCount(), itemList[0] );
m_listBox->SetItemPtrData( itemIndex, wxUIntPtr( &itemList[0] ) );
// Adding the next columns content
for( unsigned i = 1; i < itemList.size(); i++ )
m_listBox->SetItem( itemIndex, i, itemList[i] );
}
void EDA_LIST_DIALOG::InsertItems( const std::vector< wxArrayString >& itemList, int position )
{
for( unsigned row = 0; row < itemList.size(); row++ )
{
wxASSERT( (int) itemList[row].GetCount() == m_listBox->GetColumnCount() );
for( unsigned col = 0; col < itemList[row].GetCount(); col++ )
{
wxListItem info;
info.m_itemId = row + position;
info.m_col = col;
info.m_text = itemList[row].Item( col );
info.m_width = DEFAULT_COL_WIDTHS[ col ];
info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_WIDTH;
if( col == 0 )
{
info.m_data = wxUIntPtr( &itemList[row].Item( col ) );
info.m_mask |= wxLIST_MASK_DATA;
m_listBox->InsertItem( info );
}
if( --idx <= 0 )
m_listBox->SetSelection( (int) m_listBox->GetCount() - 1 );
else
{
m_listBox->SetItem( info );
}
m_listBox->SetSelection( idx );
}
else
{
if( ++idx >= (int) m_listBox->GetCount() )
m_listBox->SetSelection( 0 );
else
m_listBox->SetSelection( idx );
}
return true;
}
sortList();
}
void EDA_LIST_DIALOG::onListItemActivated( wxListEvent& event )
{
EndModal( wxID_OK );
}
/* Sort alphabetically, case insensitive.
*/
static int wxCALLBACK myCompareFunction( wxIntPtr aItem1, wxIntPtr aItem2,
wxIntPtr WXUNUSED( aSortData ) )
{
wxString* component1Name = (wxString*) aItem1;
wxString* component2Name = (wxString*) aItem2;
return StrNumCmp( *component1Name, *component2Name, true );
}
void EDA_LIST_DIALOG::sortList()
{
m_listBox->SortItems( myCompareFunction, 0 );
return DIALOG_SHIM::TryBefore( aEvent );
}

View File

@ -24,107 +24,20 @@
#ifndef EDA_VIEW_SWITCHER_H
#define EDA_VIEW_SWITCHER_H
#include <eda_view_switcher_base.h>
class EDA_DRAW_FRAME;
/**
* EDA_LIST_DIALOG
*
* A dialog which shows:
* a list of elements for selection,
* a text control to display help or info about the selected item.
* 2 buttons (OK and Cancel)
*
*/
class EDA_VIEW_SWITCHER : public EDA_VIEW_SWITCHER_BASE
{
public:
EDA_VIEW_SWITCHER( wxWindow* aParent, const wxArrayString& aItems );
/**
* Constructor:
* @param aParent Pointer to the parent window.
* @param aTitle = The title shown on top.
* @param aItemHeaders an optional array containing the column header names for the dialog.
* @param aItemList = A wxArrayString of the list of elements.
* @param aRefText = An item name if an item must be preselected.
*/
EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemHeaders,
const std::vector<wxArrayString>& aItemList,
const wxString& aRefText );
int GetSelection() const { return m_listBox->GetSelection(); }
// ~EDA_LIST_DIALOG() {}
protected:
bool TryBefore( wxEvent& aEvent ) override;
void SetListLabel( const wxString& aLabel );
void SetOKLabel( const wxString& aLabel );
void Append( const wxArrayString& aItemStr );
void InsertItems( const std::vector<wxArrayString>& aItemList, int aPosition = 0 );
/**
* Function GetTextSelection
* return the selected text from \a aColumn in the wxListCtrl in the dialog.
*
* @param aColumn is the column to return the text from.
* @return a wxString object containing the selected text from \a aColumn.
*/
wxString GetTextSelection( int aColumn = 0 );
private:
void onListItemActivated( wxListEvent& event ) override;
void textChangeInFilterBox(wxCommandEvent& event) override;
void initDialog( const wxArrayString& aItemHeaders, const wxString& aSelection);
void sortList();
private:
const std::vector<wxArrayString>* m_itemsList;
protected:
bool m_tabState;
};
/**************************************************************************/
/* Class to edit/enter a coordinate (pair of values) ( INCHES or MM ) in */
/* dialog boxes, */
/**************************************************************************/
class EDA_POSITION_CTRL
{
public:
EDA_UNITS m_UserUnit;
wxTextCtrl* m_FramePosX;
wxTextCtrl* m_FramePosY;
private:
wxStaticText* m_TextX, * m_TextY;
public:
EDA_POSITION_CTRL( wxWindow* parent, const wxString& title, const wxPoint& pos_to_edit,
EDA_UNITS user_unit, wxBoxSizer* BoxSizer );
~EDA_POSITION_CTRL();
void Enable( bool x_win_on, bool y_win_on );
void SetValue( int x_value, int y_value );
wxPoint GetValue();
};
/*************************************************************
* Class to edit/enter a size (pair of values for X and Y size)
* ( INCHES or MM ) in dialog boxes
***************************************************************/
class EDA_SIZE_CTRL : public EDA_POSITION_CTRL
{
public:
EDA_SIZE_CTRL( wxWindow* parent, const wxString& title, const wxSize& size_to_edit,
EDA_UNITS user_unit, wxBoxSizer* BoxSizer );
~EDA_SIZE_CTRL() { }
wxSize GetValue();
};
#endif // EDA_VIEW_SWITCHER_H

View File

@ -18,9 +18,9 @@ EDA_VIEW_SWITCHER_BASE::EDA_VIEW_SWITCHER_BASE( wxWindow* parent, wxWindowID id,
m_staticText2 = new wxStaticText( this, wxID_ANY, _("View Preset Switcher"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText2->Wrap( -1 );
bSizerMain->Add( m_staticText2, 0, wxALL, 5 );
bSizerMain->Add( m_staticText2, 0, wxALL|wxEXPAND, 5 );
m_listBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
m_listBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0|wxBORDER_NONE );
bSizerMain->Add( m_listBox, 1, wxEXPAND, 5 );

View File

@ -11,12 +11,12 @@
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">eda_list_dialog_base</property>
<property name="file">eda_view_switcher_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">eda_list_dialog_base</property>
<property name="name">eda_view_switcher_base</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
@ -43,12 +43,12 @@
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">EDA_LIST_DIALOG_BASE</property>
<property name="name">EDA_VIEW_SWITCHER_BASE</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="style">wxSTAY_ON_TOP</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title"></property>
<property name="title">View Preset Switcher</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
@ -60,220 +60,126 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="flag">wxALL|wxEXPAND</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">View Preset Switcher</property>
<property name="markup">0</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="name">bMargins</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</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">Items:</property>
<property name="markup">0</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_listLabel</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>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</property>
<property name="proportion">3</property>
<object class="wxListCtrl" 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="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,200</property>
<property name="moveable">1</property>
<property name="name">m_listBox</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">wxLC_HRULES|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VRULES</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="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxALWAYS_SHOW_SB|wxBORDER_SIMPLE|wxVSCROLL</property>
<event name="OnListItemActivated">onListItemActivated</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</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"></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_filterBox</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="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="OnText">textChangeInFilterBox</event>
</object>
</object>
<property name="moveable">1</property>
<property name="name">m_staticText2</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">; ; forward_declare</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>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxListBox" 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="choices"></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="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer</property>
<property name="moveable">1</property>
<property name="name">m_listBox</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">; ; forward_declare</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="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxBORDER_NONE</property>
</object>
</object>
</object>

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -35,6 +36,8 @@
#include <tools/pcb_actions.h>
#include <dialogs/dialog_grid_settings.h>
#include <widgets/appearance_controls.h>
#include <dialogs/eda_view_switcher.h>
#include <layer_widget.h>
PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
FRAME_T aFrameType, const wxString& aTitle,
@ -75,6 +78,32 @@ void PCB_BASE_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
}
bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
{
static bool s_switcherShown = false;
if( !s_switcherShown && wxGetKeyState( WXK_RAW_CONTROL ) && wxGetKeyState( WXK_TAB ) )
{
const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
EDA_VIEW_SWITCHER switcher( this, mru );
s_switcherShown = true;
switcher.ShowModal();
s_switcherShown = false;
int idx = switcher.GetSelection();
if( idx >= 0 && idx < (int) mru.size() )
m_appearancePanel->ApplyLayerPreset( mru[idx] );
return true;
}
return PCB_BASE_FRAME::TryBefore( aEvent );
}
void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
{
wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -44,6 +45,8 @@ public:
virtual ~PCB_BASE_EDIT_FRAME();
bool TryBefore( wxEvent& aEvent ) override;
void OnCloseWindow( wxCloseEvent& aEvent ) override;
/**

View File

@ -482,6 +482,8 @@ void APPEARANCE_CONTROLS::SetUserLayerPresets( std::vector<LAYER_PRESET>& aPrese
continue;
m_layerPresets[preset.name] = preset;
m_presetMRU.Add( preset.name );
}
rebuildLayerPresetsWidget();
@ -499,6 +501,8 @@ void APPEARANCE_CONTROLS::loadDefaultLayerPresets()
{
m_layerPresets[preset.name] = preset;
m_layerPresets[preset.name].readOnly = true;
m_presetMRU.Add( preset.name );
}
}
@ -1582,6 +1586,8 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
index = m_cbLayerPresets->Insert( name, index - 1, static_cast<void*>( preset ) );
m_cbLayerPresets->SetSelection( index );
m_presetMRU.Insert( name, 0 );
return;
}
else if( index == count - 1 )
@ -1614,6 +1620,8 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
m_cbLayerPresets->Delete( m_cbLayerPresets->FindString( presetName ) );
m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 );
m_currentPreset = nullptr;
m_presetMRU.Remove( presetName );
}
resetSelection();
@ -1624,6 +1632,13 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
m_currentPreset = preset;
doApplyLayerPreset( *preset );
if( !m_currentPreset->name.IsEmpty() )
{
m_presetMRU.Remove( m_currentPreset->name );
m_presetMRU.Insert( m_currentPreset->name, 0 );
}
passOnFocus();
}

View File

@ -139,6 +139,11 @@ public:
return wxEmptyString;
}
const wxArrayString& GetLayerPresetsMRU()
{
return m_presetMRU;
}
void OnColorSwatchChanged( wxCommandEvent& aEvent );
void OnLayerContextMenu( wxCommandEvent& aEvent );
@ -195,6 +200,8 @@ private:
LAYER_PRESET* m_currentPreset;
wxArrayString m_presetMRU;
wxMenu* m_layerContextMenu;
/// Stores wxIDs for each netclass for control event mapping

View File

@ -220,15 +220,25 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID
m_sizerOuter->Add( m_notebook, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer18;
bSizer18 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bBottomMargin;
bBottomMargin = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer171;
bSizer171 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bPresets;
bPresets = new wxBoxSizer( wxVERTICAL );
m_staticText5 = new wxStaticText( this, wxID_ANY, wxT("Presets:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
bSizer171->Add( m_staticText5, 0, wxTOP|wxRIGHT|wxLEFT, 2 );
wxBoxSizer* bPresetsLabels;
bPresetsLabels = new wxBoxSizer( wxHORIZONTAL );
presetsLabel = new wxStaticText( this, wxID_ANY, wxT("Presets:"), wxDefaultPosition, wxDefaultSize, 0 );
presetsLabel->Wrap( -1 );
bPresetsLabels->Add( presetsLabel, 1, wxTOP|wxRIGHT|wxLEFT, 2 );
presetsHotkey = new wxStaticText( this, wxID_ANY, wxT("(Crtl+Tab)"), wxDefaultPosition, wxDefaultSize, 0 );
presetsHotkey->Wrap( -1 );
bPresetsLabels->Add( presetsHotkey, 0, wxTOP|wxRIGHT|wxLEFT, 2 );
bPresets->Add( bPresetsLabels, 1, wxEXPAND, 5 );
wxString m_cbLayerPresetsChoices[] = { wxT("All Layers"), wxT("(unsaved)") };
int m_cbLayerPresetsNChoices = sizeof( m_cbLayerPresetsChoices ) / sizeof( wxString );
@ -236,13 +246,13 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID
m_cbLayerPresets->SetSelection( 1 );
m_cbLayerPresets->SetToolTip( wxT("Layer presets") );
bSizer171->Add( m_cbLayerPresets, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 2 );
bPresets->Add( m_cbLayerPresets, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 2 );
bSizer18->Add( bSizer171, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bBottomMargin->Add( bPresets, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_sizerOuter->Add( bSizer18, 0, wxEXPAND|wxBOTTOM, 2 );
m_sizerOuter->Add( bBottomMargin, 0, wxEXPAND|wxBOTTOM, 2 );
this->SetSizer( m_sizerOuter );

View File

@ -1902,7 +1902,7 @@
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer18</property>
<property name="name">bBottomMargin</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
@ -1911,68 +1911,140 @@
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer171</property>
<property name="name">bPresets</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">2</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">Presets:</property>
<property name="markup">0</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="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText5</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">; ; forward_declare</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>
<property name="name">bPresetsLabels</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">2</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">1</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">Presets:</property>
<property name="markup">0</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">presetsLabel</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">; ; forward_declare</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>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">2</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">(Crtl+Tab)</property>
<property name="markup">0</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">presetsHotkey</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">; ; forward_declare</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>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -76,7 +76,8 @@ class APPEARANCE_CONTROLS_BASE : public wxPanel
wxRadioButton* m_rbNetColorAll;
wxRadioButton* m_rbNetColorRatsnest;
wxRadioButton* m_rbNetColorOff;
wxStaticText* m_staticText5;
wxStaticText* presetsLabel;
wxStaticText* presetsHotkey;
wxChoice* m_cbLayerPresets;
// Virtual event handlers, overide them in your derived class