KiCad PCB EDA Suite
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 (C) 2021 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 along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <bitmaps.h>
21 #include <kicad_manager_frame.h>
22 #include <tool/tool_manager.h>
24 #include <widgets/bitmap_button.h>
25 
26 #include "panel_kicad_launcher.h"
27 
28 
30  PANEL_KICAD_LAUNCHER_BASE( aParent )
31 {
32  m_toolManager = static_cast<KICAD_MANAGER_FRAME*>( aParent )->GetToolManager();
34 }
35 
36 
38 {
39  if( m_toolsSizer->GetRows() > 0 )
40  {
41  m_toolsSizer->Clear( true );
42  m_toolsSizer->SetRows( 0 );
43  }
44 
45  wxFont titleFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
46 #ifndef __WXGTK__
47  titleFont.SetPointSize( titleFont.GetPointSize() + 2 );
48 #endif
49  titleFont.SetWeight( wxFONTWEIGHT_BOLD );
50 
51  wxFont helpFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
52  helpFont.SetStyle( wxFONTSTYLE_ITALIC );
53 
54  auto addLauncher =
55  [&]( const TOOL_ACTION& aAction, const wxBitmap& aBitmap, const wxString& aHelpText )
56  {
57  BITMAP_BUTTON* btn = new BITMAP_BUTTON( this, wxID_ANY );
58  btn->SetBitmap( aBitmap );
59  btn->SetPadding( 5 );
60  btn->SetToolTip( aAction.GetDescription() );
61 
62  auto handler =
63  [&]( wxEvent& aEvent )
64  {
65  OPT_TOOL_EVENT evt = aAction.MakeEvent();
66  evt->SetHasPosition( false );
67  m_toolManager->ProcessEvent( *evt );
68  };
69 
70  wxStaticText* label = new wxStaticText( this, wxID_ANY, aAction.GetLabel() );
71  wxStaticText* help;
72 
73  label->SetToolTip( aAction.GetDescription() );
74  label->SetFont( titleFont );
75 
76  help = new wxStaticText( this, wxID_ANY, aHelpText );
77  help->SetFont( helpFont );
78 
79  btn->Bind( wxEVT_BUTTON, handler );
80 
81  // The bug fix below makes this handler active for the entire window width. Without
82  // any visual feedback that's a bit odd. Disabling for now.
83  // label->Bind( wxEVT_LEFT_UP, handler );
84 
85  int row = m_toolsSizer->GetRows();
86 
87  m_toolsSizer->Add( btn, wxGBPosition( row, 0 ), wxGBSpan( 2, 1 ), wxBOTTOM, 12 );
88 
89  // Due to https://trac.wxwidgets.org/ticket/16088?cversion=0&cnum_hist=7 GTK fails to
90  // correctly set the BestSize of non-default-size or styled text so we need to make
91  // sure that the BestSize isn't needed by setting wxEXPAND. Unfortunately this makes
92  // wxALIGN_BOTTOM non-functional, so we have to jump through a bunch more hoops to
93  // try and align the title and help text in the middle of the icon.
94  m_toolsSizer->Add( label, wxGBPosition( row, 1 ), wxGBSpan( 1, 1 ), wxTOP|wxEXPAND, 10 );
95 
96  m_toolsSizer->Add( help, wxGBPosition( row + 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_TOP|wxTOP, 1 );
97  };
98 
101  _( "Edit the project schematic" ) );
102 
105  _( "Edit global and/or project schematic symbol libraries" ) );
106 
107  addLauncher( KICAD_MANAGER_ACTIONS::editPCB,
109  _( "Edit the project PCB design" ) );
110 
113  _( "Edit global and/or project PCB footprint libraries" ) );
114 
117  _( "Preview Gerber files" ) );
118 
121  _( "Convert bitmap images to schematic symbols or PCB footprints" ) );
122 
125  _( "Show tools for calculating resistance, current capacity, etc." ) );
126 
129  _( "Edit drawing sheet borders and title blocks for use in schematics and PCB "
130  "designs" ) );
131 
132  if( m_toolsSizer->IsColGrowable( 1 ) )
133  m_toolsSizer->RemoveGrowableCol( 1 );
134 
135  m_toolsSizer->AddGrowableCol( 1 );
136  Layout();
137 }
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:39
Class PANEL_KICAD_LAUNCHER_BASE.
TOOL_MANAGER * m_toolManager
static TOOL_ACTION showCalculator
static TOOL_ACTION viewGerbers
static TOOL_ACTION convertImage
PANEL_KICAD_LAUNCHER(wxWindow *aParent)
static TOOL_ACTION editSchematic
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
static TOOL_ACTION editFootprints
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:84
wxString GetLabel() const
Definition: tool_action.cpp:70
static TOOL_ACTION editPCB
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
#define _(s)
Definition: 3d_actions.cpp:33
Represent a single user action.
Definition: tool_action.h:49
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.h:123
static TOOL_ACTION editSymbols
void SetHasPosition(bool aHasPosition)
Returns if the action associated with this event should be treated as immediate regardless of the cur...
Definition: tool_event.h:262
static TOOL_ACTION editDrawingSheet
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:569