2019-06-09 21:57:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2016 CERN
|
2021-05-29 16:09:49 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-07-15 19:26:35 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2019-06-09 21:57:23 +00: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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2021-08-28 08:32:47 +00:00
|
|
|
// kicad_curl_easy.h must be included before wxWidgets because on Windows (msys2), there are
|
|
|
|
// collision with wx headers and curl.h defs
|
|
|
|
#include <kicad_curl/kicad_curl_easy.h>
|
2019-06-09 21:57:23 +00:00
|
|
|
|
|
|
|
#include <bitmaps.h>
|
2020-05-25 00:39:15 +00:00
|
|
|
#include <build_version.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <common.h> // for SearchHelpFileFullPath
|
2021-04-13 18:06:09 +00:00
|
|
|
#include <pgm_base.h>
|
2019-06-09 21:57:23 +00:00
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <eda_draw_frame.h>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <base_screen.h>
|
|
|
|
#include <tool/common_control.h>
|
|
|
|
#include <id.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-10-25 13:36:19 +00:00
|
|
|
#include <dialogs/dialog_configure_paths.h>
|
2019-06-09 21:57:23 +00:00
|
|
|
#include <eda_doc.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2019-06-09 21:57:23 +00:00
|
|
|
|
2022-02-05 00:24:26 +00:00
|
|
|
#define URL_GET_INVOLVED wxT( "https://kicad.org/contribute/" )
|
|
|
|
#define URL_DONATE wxT( "https://go.kicad.org/app-donate" )
|
|
|
|
#define URL_DOCUMENTATION wxT( "https://docs.kicad.org/" )
|
2019-06-09 21:57:23 +00:00
|
|
|
|
|
|
|
|
2020-05-25 00:39:15 +00:00
|
|
|
/// URL to launch a new issue with pre-populated description
|
|
|
|
wxString COMMON_CONTROL::m_bugReportUrl =
|
2022-02-05 00:24:26 +00:00
|
|
|
wxT( "https://gitlab.com/kicad/code/kicad/issues/new?issue[description]=%s" );
|
2020-05-25 00:39:15 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2020-05-25 00:39:15 +00:00
|
|
|
/// Issue template to use for reporting bugs (this should not be translated)
|
|
|
|
wxString COMMON_CONTROL::m_bugReportTemplate =
|
2022-02-05 00:24:26 +00:00
|
|
|
wxT( "<!-- Before Creating a New Issue:\n" )
|
|
|
|
wxT( "* Search the issue tracker to verify the issue has not already been reported.\n" )
|
|
|
|
wxT( "* Only report one problem per issue. -->\n" )
|
|
|
|
wxT( "\n" )
|
|
|
|
wxT( "# Description\n" )
|
|
|
|
wxT( "<!-- What is the current behavior and what is the expected behavior? -->\n" )
|
|
|
|
wxT( "<!-- Please attach screenshots if they will help explain the problem. -->\n" )
|
|
|
|
wxT( "\n" )
|
|
|
|
wxT( "# Steps to reproduce\n" )
|
|
|
|
wxT( "<!-- Please include a screen recording if it will help explain how to reproduce. -->\n" )
|
|
|
|
wxT( "<!-- If this issue is specific to a project, please attach it. -->\n" )
|
|
|
|
wxT( "1.\n" )
|
|
|
|
wxT( "2.\n" )
|
|
|
|
wxT( "# KiCad Version\n" )
|
|
|
|
wxT( "\n" )
|
|
|
|
wxT( "```\n" )
|
|
|
|
wxT( "%s\n" )
|
|
|
|
wxT( "```" );
|
2020-05-25 00:39:15 +00:00
|
|
|
|
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
void COMMON_CONTROL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
m_frame = getEditFrame<EDA_BASE_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-29 16:09:49 +00:00
|
|
|
int COMMON_CONTROL::OpenPreferences( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-07 19:45:17 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
|
|
|
|
m_frame->OnPreferences( dummy );
|
|
|
|
|
2021-05-29 16:09:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
int COMMON_CONTROL::ConfigurePaths( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-05-29 20:52:20 +00:00
|
|
|
// If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
|
|
|
|
// be edited
|
|
|
|
KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false );
|
|
|
|
|
|
|
|
if( pcbnew )
|
2020-02-06 10:41:00 +00:00
|
|
|
{
|
2020-05-29 20:52:20 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
pcbnew->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// Do nothing here.
|
|
|
|
// A error message is displayed after trying to load _pcbnew.kiface.
|
|
|
|
}
|
2020-07-13 20:21:34 +00:00
|
|
|
}
|
2020-05-29 20:52:20 +00:00
|
|
|
else
|
2020-02-06 10:41:00 +00:00
|
|
|
{
|
2020-05-29 20:52:20 +00:00
|
|
|
DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr );
|
|
|
|
|
2020-10-28 23:06:48 +00:00
|
|
|
// Use QuasiModal so that HTML help window will work
|
|
|
|
if( dlg.ShowQuasiModal() == wxID_OK )
|
2020-07-17 20:04:14 +00:00
|
|
|
m_frame->Kiway().CommonSettingsChanged( true, false );
|
2020-02-06 10:41:00 +00:00
|
|
|
}
|
2020-05-29 20:52:20 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_CONTROL::ShowLibraryTable( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
|
|
|
|
{
|
2020-02-06 10:41:00 +00:00
|
|
|
try // Sch frame was not available, try to start it
|
|
|
|
{
|
|
|
|
KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH );
|
|
|
|
kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// _eeschema.kiface is not available: it contains the library table dialog.
|
|
|
|
// Do nothing here.
|
|
|
|
// A error message is displayed after trying to load _eeschema.kiface.
|
|
|
|
}
|
2019-06-09 21:57:23 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
|
|
|
|
{
|
2020-02-06 10:41:00 +00:00
|
|
|
|
|
|
|
try // Pcb frame was not available, try to start it
|
|
|
|
{
|
|
|
|
KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB );
|
|
|
|
kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// _pcbnew.kiface is not available: it contains the library table dialog.
|
|
|
|
// Do nothing here.
|
|
|
|
// A error message is displayed after trying to load _pcbnew.kiface.
|
|
|
|
}
|
2019-06-09 21:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-17 22:02:30 +00:00
|
|
|
FRAME_T playerType = aEvent.Parameter<FRAME_T>();
|
2019-06-09 21:57:23 +00:00
|
|
|
KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
|
|
|
|
|
2021-03-19 14:01:03 +00:00
|
|
|
// editor can be null if Player() fails:
|
2022-02-05 00:24:26 +00:00
|
|
|
wxCHECK_MSG( editor != nullptr, 0, wxT( "Cannot open/create the editor frame" ) );
|
2021-03-19 14:01:03 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
// Needed on Windows, other platforms do not use it, but it creates no issue
|
|
|
|
if( editor->IsIconized() )
|
|
|
|
editor->Iconize( false );
|
|
|
|
|
|
|
|
editor->Raise();
|
|
|
|
|
|
|
|
// Raising the window does not set the focus on Linux. This should work on
|
|
|
|
// any platform.
|
|
|
|
if( wxWindow::FindFocus() != editor )
|
|
|
|
editor->SetFocus();
|
2020-02-06 10:41:00 +00:00
|
|
|
|
2022-07-12 21:44:53 +00:00
|
|
|
// If the player is currently blocked, focus the user attention on the correct window
|
|
|
|
if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
|
|
|
|
{
|
|
|
|
blocking_win->Raise();
|
|
|
|
blocking_win->SetFocus();
|
|
|
|
}
|
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_CONTROL::ShowHelp( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-04-05 17:03:36 +00:00
|
|
|
wxString helpFile;
|
|
|
|
wxString msg;
|
2019-06-09 21:57:23 +00:00
|
|
|
|
2022-02-05 00:24:26 +00:00
|
|
|
// the URL of help files is wxT( "https://docs.kicad.org/<version>/<language>/<name>/" )
|
|
|
|
const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + wxT( "/" )
|
|
|
|
+ Pgm().GetLocale()->GetName().BeforeLast( '_' ) + wxT( "/" );
|
2021-04-13 18:06:09 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
/* We have to get document for beginners,
|
|
|
|
* or the full specific doc
|
|
|
|
* if event id is wxID_INDEX, we want the document for beginners.
|
|
|
|
* else the specific doc file (its name is in Kiface().GetHelpFileName())
|
|
|
|
* The document for beginners is the same for all KiCad utilities
|
|
|
|
*/
|
|
|
|
if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
|
|
|
|
{
|
|
|
|
// List of possible names for Getting Started in KiCad
|
|
|
|
const wxChar* names[2] = {
|
|
|
|
wxT( "getting_started_in_kicad" ),
|
|
|
|
wxT( "Getting_Started_in_KiCad" )
|
|
|
|
};
|
|
|
|
|
|
|
|
// Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
|
|
|
|
// or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
|
|
|
|
for( auto& name : names )
|
|
|
|
{
|
2021-04-05 17:03:36 +00:00
|
|
|
helpFile = SearchHelpFileFullPath( name );
|
2019-06-09 21:57:23 +00:00
|
|
|
|
|
|
|
if( !helpFile.IsEmpty() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !helpFile )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
|
2021-04-13 18:06:09 +00:00
|
|
|
"Do you want to access the KiCad online help?" ),
|
2019-06-09 21:57:23 +00:00
|
|
|
names[0], names[1] );
|
2021-07-15 19:26:35 +00:00
|
|
|
wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
|
2021-04-13 18:06:09 +00:00
|
|
|
wxYES_NO | wxNO_DEFAULT | wxCANCEL );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_YES )
|
|
|
|
return -1;
|
|
|
|
|
2022-02-05 00:24:26 +00:00
|
|
|
helpFile = baseUrl + names[0] + wxT( "/" );
|
2019-06-09 21:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString base_name = m_frame->help_name();
|
2020-02-06 10:41:00 +00:00
|
|
|
|
2021-04-05 17:03:36 +00:00
|
|
|
helpFile = SearchHelpFileFullPath( base_name );
|
2020-02-06 10:41:00 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
if( !helpFile )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
msg = wxString::Format( _( "Help file '%s' could not be found.\n"
|
2021-04-13 18:06:09 +00:00
|
|
|
"Do you want to access the KiCad online help?" ),
|
|
|
|
base_name );
|
2021-07-15 19:26:35 +00:00
|
|
|
wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
|
2021-04-13 18:06:09 +00:00
|
|
|
wxYES_NO | wxNO_DEFAULT | wxCANCEL );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_YES )
|
|
|
|
return -1;
|
|
|
|
|
2022-02-05 00:24:26 +00:00
|
|
|
helpFile = baseUrl + base_name + wxT( "/" );
|
2019-06-09 21:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 21:10:42 +00:00
|
|
|
GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
|
2019-06-09 21:57:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_CONTROL::ListHotKeys( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
DisplayHotkeyList( m_frame, m_toolMgr );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_CONTROL::GetInvolved( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Could not launch the default browser.\n"
|
|
|
|
"For information on how to help the KiCad project, visit %s" ),
|
|
|
|
URL_GET_INVOLVED );
|
|
|
|
wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
|
|
|
|
}
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-08 17:21:44 +00:00
|
|
|
int COMMON_CONTROL::Donate( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( !wxLaunchDefaultBrowser( URL_DONATE ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Could not launch the default browser.\n"
|
|
|
|
"To donate to the KiCad project, visit %s" ),
|
|
|
|
URL_DONATE );
|
|
|
|
wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
|
|
|
|
}
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2021-04-08 17:21:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-25 00:39:15 +00:00
|
|
|
int COMMON_CONTROL::ReportBug( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-09 01:02:10 +00:00
|
|
|
if( WarnUserIfOperatingSystemUnsupported() )
|
|
|
|
return 0;
|
|
|
|
|
2020-05-25 00:39:15 +00:00
|
|
|
wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
|
|
|
|
|
|
|
|
wxString message;
|
|
|
|
message.Printf( m_bugReportTemplate, version );
|
|
|
|
|
|
|
|
KICAD_CURL_EASY kcurl;
|
|
|
|
wxString url_string;
|
2021-03-17 03:04:42 +00:00
|
|
|
url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
|
2020-05-25 00:39:15 +00:00
|
|
|
|
|
|
|
wxLaunchDefaultBrowser( url_string );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
void COMMON_CONTROL::setTransitions()
|
|
|
|
{
|
2021-05-29 16:09:49 +00:00
|
|
|
Go( &COMMON_CONTROL::OpenPreferences, ACTIONS::openPreferences.MakeEvent() );
|
2019-06-09 21:57:23 +00:00
|
|
|
Go( &COMMON_CONTROL::ConfigurePaths, ACTIONS::configurePaths.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showSymbolLibTable.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showFootprintLibTable.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showSymbolBrowser.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showSymbolEditor.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showFootprintBrowser.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showFootprintEditor.MakeEvent() );
|
2020-02-06 10:41:00 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
Go( &COMMON_CONTROL::ShowHelp, ACTIONS::gettingStarted.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::ListHotKeys, ACTIONS::listHotKeys.MakeEvent() );
|
|
|
|
Go( &COMMON_CONTROL::GetInvolved, ACTIONS::getInvolved.MakeEvent() );
|
2021-04-08 17:21:44 +00:00
|
|
|
Go( &COMMON_CONTROL::Donate, ACTIONS::donate.MakeEvent() );
|
2020-05-25 00:39:15 +00:00
|
|
|
Go( &COMMON_CONTROL::ReportBug, ACTIONS::reportBug.MakeEvent() );
|
2019-06-09 21:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|