KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_kicad_launcher.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <bitmaps.h>
21#include <bitmap_store.h>
22#include <kicad_manager_frame.h>
23#include <kiplatform/policy.h>
24#include <policy_keys.h>
25#include <tool/tool_manager.h>
29#include <wx/stattext.h>
30
32
33
36 m_frame( static_cast<KICAD_MANAGER_FRAME*>( aParent->GetParent() ) )
37{
39
40 Bind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
41}
42
43
45{
46 m_frame->SetPcmButton( nullptr );
47
48 for( wxWindow* window : m_scrolledWindow->GetChildren() )
49 {
50 if( dynamic_cast<BITMAP_BUTTON*>( window ) != nullptr )
51 window->Unbind( wxEVT_BUTTON, &PANEL_KICAD_LAUNCHER::onLauncherButtonClick, this );
52 }
53
54 Unbind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
55}
56
57
58void PANEL_KICAD_LAUNCHER::onLauncherButtonClick( wxCommandEvent& aEvent )
59{
60 // BITMAP_BUTTON::OnLeftButtonUp() defers this click via CallAfter(), so CreateLaunchers()
61 // can destroy and rebuild the sender before this event is delivered. aEvent.GetEventObject()
62 // may therefore be dangling; aEvent.GetId() is a plain copy made while the button was alive.
63 auto it = m_actionForId.find( aEvent.GetId() );
64
65 if( it == m_actionForId.end() )
66 return;
67
68 const TOOL_ACTION* action = it->second;
69
70 // Don't accept clicks processed during wxProgressReporter updating. In particular, the wxSafeYield()
71 // call below will puke.
72 if( m_frame->GetToolManager()->GetTool<KICAD_MANAGER_CONTROL>()->InShowPlayer() )
73 return;
74
75 // Defocus the button because leaving the large buttons focused after a click looks out of place in
76 // the launcher
77 m_frame->SetFocus();
78
79 // Gives a slice of time to update the button state (mandatory on GTK, useful on MSW to avoid some
80 // cosmetic issues).
81 wxSafeYield();
82
83 OPT_TOOL_EVENT evt = action->MakeEvent();
84 evt->SetHasPosition( false );
85 m_frame->GetToolManager()->ProcessEvent( *evt );
86}
87
88
90{
91 m_frame->SetPcmButton( nullptr );
92
93 // Old buttons are about to be destroyed; drop the id lookup with them so a stale
94 // asynchronous click event can never be mapped to an action again.
95 m_actionForId.clear();
96
97 if( m_toolsSizer->GetEffectiveRowsCount() > 0 )
98 {
99 m_toolsSizer->Clear( true );
100 m_toolsSizer->SetRows( 0 );
101 }
102
103 wxFont titleFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
104#ifndef __WXGTK__
105 titleFont.SetPointSize( titleFont.GetPointSize() + 2 );
106#endif
107 titleFont.SetWeight( wxFONTWEIGHT_BOLD );
108
109 wxFont helpFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
110 helpFont.SetStyle( wxFONTSTYLE_ITALIC );
111
112 auto addLauncher =
113 [&]( const TOOL_ACTION& aAction, BITMAPS aBitmaps, const wxString& aHelpText, bool enabled = true )
114 {
115 // Assign a monotonic id that is never reused across rebuilds. A wxID_ANY id can be
116 // recycled after CreateLaunchers() destroys the old buttons, which would let a stale
117 // deferred click resolve to a different action; a fresh id makes it miss the map instead.
118 int id = m_nextLauncherId++;
120 btn->SetBitmap( KiBitmapBundle( aBitmaps ) );
121 btn->SetDisabledBitmap( KiDisabledBitmapBundle( aBitmaps ) );
122 btn->SetPadding( 4 );
123 btn->SetToolTip( aAction.GetTooltip() );
124
125 m_scrolledWindow->SetFont( titleFont ); // Use font inheritance to avoid extra SetFont call.
126 wxStaticText* label = new wxStaticText( m_scrolledWindow, wxID_ANY, aAction.GetFriendlyName() );
127 label->SetToolTip( aAction.GetTooltip() );
128
129 m_scrolledWindow->SetFont( helpFont ); // Use font inheritance to avoid extra SetFont call.
130 wxStaticText* help = new wxStaticText( m_scrolledWindow, wxID_ANY, aHelpText );
131
132 btn->Bind( wxEVT_BUTTON, &PANEL_KICAD_LAUNCHER::onLauncherButtonClick, this );
133 m_actionForId[id] = &aAction;
134
135 // The bug fix below makes this handler active for the entire window width. Without any visual
136 // feedback that's a bit odd. Disabling for now.
137 // label->Bind( wxEVT_LEFT_UP, handler );
138
139 m_toolsSizer->Add( btn, 1, wxALIGN_CENTER_VERTICAL );
140
141 wxBoxSizer* textSizer = new wxBoxSizer( wxVERTICAL );
142
143 textSizer->Add( label );
144 textSizer->Add( help );
145
146 m_toolsSizer->Add( textSizer, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL );
147
148 btn->Enable( enabled );
149
150 if( !enabled )
151 {
152 help->Disable();
153 label->Disable();
154 }
155
156 return btn;
157 };
158
160 _( "Edit the project schematic" ) );
161
163 _( "Edit global and/or project schematic symbol libraries" ) );
164
166 _( "Edit the project PCB design" ) );
167
169 _( "Edit global and/or project PCB footprint libraries" ) );
170
172 _( "Preview Gerber files" ) );
173
175 _( "Show tools for calculating resistance, current capacity, etc." ) );
176
178 _( "Edit drawing sheet borders and title blocks for use in schematics and PCB designs" ) );
179
181 _( "Manage downloadable packages from KiCad and 3rd party repositories" ),
184
185 m_frame->SetPcmButton( bb );
186
187 Layout();
188}
189
190
191void PANEL_KICAD_LAUNCHER::onThemeChanged( wxSysColourChangedEvent& aEvent )
192{
194
195 aEvent.Skip();
196}
wxBitmapBundle KiDisabledBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:118
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
BITMAPS
A list of all bitmap identifiers.
@ icon_pagelayout_editor
@ icon_pcbcalculator
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
bool Enable(bool aEnable=true) override
Enable the button.
void SetDisabledBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is disabled.
void SetPadding(int aPaddingDIP)
Set the amount of padding present on each side of the bitmap.
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
static TOOL_ACTION editSchematic
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION editFootprints
static TOOL_ACTION showPluginManager
static TOOL_ACTION showCalculator
static TOOL_ACTION viewGerbers
static TOOL_ACTION editSymbols
Handle actions in the kicad manager frame.
The main KiCad project manager frame.
PANEL_KICAD_LAUNCHER_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void onThemeChanged(wxSysColourChangedEvent &aEvent)
void onLauncherButtonClick(wxCommandEvent &aEvent)
std::unordered_map< int, const TOOL_ACTION * > m_actionForId
PANEL_KICAD_LAUNCHER(wxWindow *aParent)
KICAD_MANAGER_FRAME * m_frame
Represent a single user action.
wxString GetTooltip(bool aIncludeHotkey=true) const
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
wxString GetFriendlyName() const
Return the translated user-friendly name of the action.
void SetHasPosition(bool aHasPosition)
Definition tool_event.h:257
#define _(s)
PBOOL GetPolicyBool(const wxString &aKey)
#define POLICY_KEY_PCM
Definition policy_keys.h:27
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition tool_event.h:652