2021-02-12 22:37:39 -05:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2021-02-12 22:37:39 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bitmaps.h>
|
2021-09-13 23:30:22 +01:00
|
|
|
#include <bitmap_store.h>
|
2021-02-12 22:37:39 -05:00
|
|
|
#include <kicad_manager_frame.h>
|
2022-04-12 00:11:16 -04:00
|
|
|
#include <kiplatform/policy.h>
|
|
|
|
#include <policy_keys.h>
|
2021-02-12 22:37:39 -05:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/kicad_manager_actions.h>
|
2025-07-09 16:41:51 +01:00
|
|
|
#include <tools/kicad_manager_control.h>
|
2021-02-12 22:37:39 -05:00
|
|
|
#include <widgets/bitmap_button.h>
|
2021-06-03 07:49:49 -04:00
|
|
|
#include <wx/stattext.h>
|
2021-02-12 22:37:39 -05:00
|
|
|
|
|
|
|
#include "panel_kicad_launcher.h"
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_KICAD_LAUNCHER::PANEL_KICAD_LAUNCHER( wxWindow* aParent ) :
|
2025-07-14 21:10:09 +01:00
|
|
|
PANEL_KICAD_LAUNCHER_BASE( aParent ),
|
|
|
|
m_frame( static_cast<KICAD_MANAGER_FRAME*>( aParent->GetParent() ) )
|
2021-02-12 22:37:39 -05:00
|
|
|
{
|
|
|
|
CreateLaunchers();
|
2021-09-13 23:30:22 +01:00
|
|
|
|
2025-07-14 21:10:09 +01:00
|
|
|
Bind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
|
2021-02-12 22:37:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-08-16 02:13:13 +00:00
|
|
|
PANEL_KICAD_LAUNCHER::~PANEL_KICAD_LAUNCHER()
|
|
|
|
{
|
2025-05-29 12:29:55 +03:00
|
|
|
m_frame->SetPcmButton( nullptr );
|
|
|
|
|
2024-09-05 20:49:19 -04:00
|
|
|
for( wxWindow* window : m_scrolledWindow->GetChildren() )
|
|
|
|
{
|
|
|
|
if( dynamic_cast<BITMAP_BUTTON*>( window ) != nullptr )
|
|
|
|
window->Unbind( wxEVT_BUTTON, &PANEL_KICAD_LAUNCHER::onLauncherButtonClick, this );
|
|
|
|
}
|
|
|
|
|
2025-07-14 21:10:09 +01:00
|
|
|
Unbind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
|
2024-09-05 20:49:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_KICAD_LAUNCHER::onLauncherButtonClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2025-07-09 16:41:51 +01:00
|
|
|
// Don't accept clicks processed during wxProgressReporter updating. In particular, the wxSafeYield()
|
|
|
|
// call below will puke.
|
|
|
|
if( m_frame->GetToolManager()->GetTool<KICAD_MANAGER_CONTROL>()->InShowPlayer() )
|
|
|
|
return;
|
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
// Defocus the button because leaving the large buttons focused after a click looks out of place in
|
|
|
|
// the launcher
|
2024-09-05 20:49:19 -04:00
|
|
|
m_frame->SetFocus();
|
2025-07-09 16:13:34 +01:00
|
|
|
|
|
|
|
// Gives a slice of time to update the button state (mandatory on GTK, useful on MSW to avoid some
|
|
|
|
// cosmetic issues).
|
2024-09-05 20:49:19 -04:00
|
|
|
wxSafeYield();
|
|
|
|
|
|
|
|
BITMAP_BUTTON* button = (BITMAP_BUTTON*) aEvent.GetEventObject();
|
|
|
|
const TOOL_ACTION* action = static_cast<const TOOL_ACTION*>( button->GetClientData() );
|
|
|
|
|
|
|
|
if( action == nullptr )
|
|
|
|
return;
|
|
|
|
|
|
|
|
OPT_TOOL_EVENT evt = action->MakeEvent();
|
|
|
|
evt->SetHasPosition( false );
|
|
|
|
m_frame->GetToolManager()->ProcessEvent( *evt );
|
2024-08-16 02:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-12 22:37:39 -05:00
|
|
|
void PANEL_KICAD_LAUNCHER::CreateLaunchers()
|
|
|
|
{
|
2022-08-18 20:41:43 +00:00
|
|
|
m_frame->SetPcmButton( nullptr );
|
|
|
|
|
2024-05-27 11:49:13 +03:00
|
|
|
if( m_toolsSizer->GetEffectiveRowsCount() > 0 )
|
2021-02-12 22:37:39 -05:00
|
|
|
{
|
|
|
|
m_toolsSizer->Clear( true );
|
|
|
|
m_toolsSizer->SetRows( 0 );
|
|
|
|
}
|
|
|
|
|
2021-02-14 13:13:20 +00:00
|
|
|
wxFont titleFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
2021-02-27 11:43:19 +00:00
|
|
|
#ifndef __WXGTK__
|
2021-02-14 13:13:20 +00:00
|
|
|
titleFont.SetPointSize( titleFont.GetPointSize() + 2 );
|
2021-02-27 11:43:19 +00:00
|
|
|
#endif
|
2021-02-14 13:13:20 +00:00
|
|
|
titleFont.SetWeight( wxFONTWEIGHT_BOLD );
|
|
|
|
|
|
|
|
wxFont helpFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
|
|
|
helpFont.SetStyle( wxFONTSTYLE_ITALIC );
|
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
auto addLauncher =
|
|
|
|
[&]( const TOOL_ACTION& aAction, BITMAPS aBitmaps, const wxString& aHelpText, bool enabled = true )
|
|
|
|
{
|
|
|
|
BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_scrolledWindow, wxID_ANY );
|
|
|
|
btn->SetBitmap( KiBitmapBundle( aBitmaps ) );
|
|
|
|
btn->SetDisabledBitmap( KiDisabledBitmapBundle( aBitmaps ) );
|
|
|
|
btn->SetPadding( FromDIP( 4 ) );
|
|
|
|
btn->SetToolTip( aAction.GetTooltip() );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
m_scrolledWindow->SetFont( titleFont ); // Use font inheritance to avoid extra SetFont call.
|
|
|
|
wxStaticText* label = new wxStaticText( m_scrolledWindow, wxID_ANY, aAction.GetFriendlyName() );
|
|
|
|
label->SetToolTip( aAction.GetTooltip() );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
m_scrolledWindow->SetFont( helpFont ); // Use font inheritance to avoid extra SetFont call.
|
|
|
|
wxStaticText* help = new wxStaticText( m_scrolledWindow, wxID_ANY, aHelpText );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
btn->Bind( wxEVT_BUTTON, &PANEL_KICAD_LAUNCHER::onLauncherButtonClick, this );
|
|
|
|
btn->SetClientData( (void*) &aAction );
|
2021-03-22 17:19:44 +00:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
// The bug fix below makes this handler active for the entire window width. Without any visual
|
|
|
|
// feedback that's a bit odd. Disabling for now.
|
|
|
|
// label->Bind( wxEVT_LEFT_UP, handler );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
m_toolsSizer->Add( btn, 1, wxALIGN_CENTER_VERTICAL );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
wxBoxSizer* textSizer = new wxBoxSizer( wxVERTICAL );
|
2021-02-27 11:43:19 +00:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
textSizer->Add( label );
|
|
|
|
textSizer->Add( help );
|
2021-02-27 11:43:19 +00:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
m_toolsSizer->Add( textSizer, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL );
|
2022-04-12 00:11:16 -04:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
btn->Enable( enabled );
|
2022-08-18 20:41:43 +00:00
|
|
|
|
2025-07-09 16:13:34 +01:00
|
|
|
if( !enabled )
|
|
|
|
{
|
|
|
|
help->Disable();
|
|
|
|
label->Disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
};
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::editSchematic, BITMAPS::icon_eeschema,
|
2021-02-14 13:13:20 +00:00
|
|
|
_( "Edit the project schematic" ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::editSymbols, BITMAPS::icon_libedit,
|
2021-02-14 13:13:20 +00:00
|
|
|
_( "Edit global and/or project schematic symbol libraries" ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::editPCB, BITMAPS::icon_pcbnew,
|
2021-02-14 13:13:20 +00:00
|
|
|
_( "Edit the project PCB design" ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::editFootprints, BITMAPS::icon_modedit,
|
2021-02-14 16:59:04 +00:00
|
|
|
_( "Edit global and/or project PCB footprint libraries" ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::viewGerbers, BITMAPS::icon_gerbview,
|
2021-02-14 13:13:20 +00:00
|
|
|
_( "Preview Gerber files" ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::convertImage, BITMAPS::icon_bitmap2component,
|
2021-02-14 13:13:20 +00:00
|
|
|
_( "Convert bitmap images to schematic symbols or PCB footprints" ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::showCalculator, BITMAPS::icon_pcbcalculator,
|
2021-02-14 13:13:20 +00:00
|
|
|
_( "Show tools for calculating resistance, current capacity, etc." ) );
|
2021-02-12 22:37:39 -05:00
|
|
|
|
2024-05-26 07:55:24 +03:00
|
|
|
addLauncher( KICAD_MANAGER_ACTIONS::editDrawingSheet, BITMAPS::icon_pagelayout_editor,
|
2025-07-09 16:13:34 +01:00
|
|
|
_( "Edit drawing sheet borders and title blocks for use in schematics and PCB designs" ) );
|
|
|
|
|
|
|
|
BITMAP_BUTTON* bb = addLauncher( KICAD_MANAGER_ACTIONS::showPluginManager, BITMAPS::icon_pcm,
|
|
|
|
_( "Manage downloadable packages from KiCad and 3rd party repositories" ),
|
|
|
|
KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM )
|
|
|
|
!= KIPLATFORM::POLICY::PBOOL::DISABLED );
|
2022-08-18 20:41:43 +00:00
|
|
|
|
|
|
|
m_frame->SetPcmButton( bb );
|
2020-10-26 03:54:36 -07:00
|
|
|
|
2021-02-12 22:37:39 -05:00
|
|
|
Layout();
|
|
|
|
}
|
2021-09-13 23:30:22 +01:00
|
|
|
|
|
|
|
|
2024-09-05 20:49:19 -04:00
|
|
|
void PANEL_KICAD_LAUNCHER::onThemeChanged( wxSysColourChangedEvent& aEvent )
|
2021-09-13 23:30:22 +01:00
|
|
|
{
|
|
|
|
GetBitmapStore()->ThemeChanged();
|
|
|
|
CreateLaunchers();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|