1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014-2016 CERN
* Copyright The 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
* 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
*/
// 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>
#include <bitmaps.h>
#include <build_version.h>
#include <common.h> // for SearchHelpFileFullPath
#include <pgm_base.h>
#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>
#include <kiface_base.h>
#include <dialogs/dialog_configure_paths.h>
#include <eda_doc.h>
#include <wx/msgdlg.h>
#define URL_GET_INVOLVED wxS( "https://go.kicad.org/contribute/" )
#define URL_DONATE wxS( "https://go.kicad.org/app-donate" )
#define URL_DOCUMENTATION wxS( "https://go.kicad.org/docs/" )
/// URL to launch a new issue with pre-populated description
wxString COMMON_CONTROL::m_bugReportUrl =
wxS( "https://gitlab.com/kicad/code/kicad/-/issues/new?issuable_template=bare&issue"
"[description]=%s" );
/// Issue template to use for reporting bugs (this should not be translated)
wxString COMMON_CONTROL::m_bugReportTemplate = wxS(
"```\n"
"%s\n"
"```" );
void COMMON_CONTROL::Reset( RESET_REASON aReason )
{
m_frame = getEditFrame<EDA_BASE_FRAME>();
}
int COMMON_CONTROL::OpenPreferences( const TOOL_EVENT& aEvent )
{
m_frame->ShowPreferences( wxEmptyString, wxEmptyString );
return 0;
}
int COMMON_CONTROL::ConfigurePaths( const TOOL_EVENT& aEvent )
{
// If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
// be edited
if( KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false ) )
{
try
{
pcbnew->CreateKiWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
}
catch( ... )
{
// Do nothing here.
// A error message is displayed after trying to load _pcbnew.kiface.
}
}
else
{
DIALOG_CONFIGURE_PATHS dlg( m_frame );
if( dlg.ShowModal() == wxID_OK )
m_frame->Kiway().CommonSettingsChanged( ENVVARS_CHANGED );
}
return 0;
}
int COMMON_CONTROL::ShowLibraryTable( const TOOL_EVENT& aEvent )
{
if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
{
try // Sch frame was not available, try to start it
{
if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ) )
kiface->CreateKiWindow( 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.
}
}
else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
{
try // Pcb frame was not available, try to start it
{
if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB ) )
kiface->CreateKiWindow( 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.
}
}
else if( aEvent.IsAction( &ACTIONS::showDesignBlockLibTable ) )
{
try // Kicad frame was not available, try to start it
{
if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ) )
kiface->CreateKiWindow( m_frame, DIALOG_DESIGN_BLOCK_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.
}
}
return 0;
}
void showFrame( EDA_BASE_FRAME* aFrame )
{
// Needed on Windows, other platforms do not use it, but it creates no issue
if( aFrame->IsIconized() )
aFrame->Iconize( false );
aFrame->Raise();
// Raising the window does not set the focus on Linux. This should work on
// any platform.
if( wxWindow::FindFocus() != aFrame )
aFrame->SetFocus();
// If the player is currently blocked, focus the user attention on the correct window
if( wxWindow* blocking_win = aFrame->Kiway().GetBlockingDialog() )
{
blocking_win->Raise();
blocking_win->SetFocus();
}
}
int COMMON_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
{
FRAME_T playerType = aEvent.Parameter<FRAME_T>();
KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
// editor can be null if Player() fails:
wxCHECK_MSG( editor != nullptr, 0, wxT( "Cannot open/create the editor frame" ) );
showFrame( editor );
return 0;
}
int COMMON_CONTROL::ShowProjectManager( const TOOL_EVENT& aEvent )
{
// Note: dynamic_cast doesn't work over the Kiway() on MacOS. We have to use static_cast
// here.
EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_frame->Kiway().GetTop() );
if( top && top->GetFrameType() == KICAD_MAIN_FRAME_T )
{
showFrame( top );
}
else
{
wxMessageDialog( m_frame, _( "Can not switch to project manager in stand-alone mode." ) );
}
return 0;
}
int COMMON_CONTROL::ShowHelp( const TOOL_EVENT& aEvent )
{
wxString helpFile;
wxString msg;
// the URL of help files is "https://go.kicad.org/docs/<version>/<language>/<name>/"
const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + wxT( "/" )
+ Pgm().GetLocale()->GetName().BeforeLast( '_' ) + wxT( "/" );
/* 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 )
{
helpFile = SearchHelpFileFullPath( name );
if( !helpFile.IsEmpty() )
break;
}
if( !helpFile )
{
msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
"Do you want to access the KiCad online help?" ),
names[0], names[1] );
wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
wxYES_NO | wxNO_DEFAULT | wxCANCEL );
if( dlg.ShowModal() != wxID_YES )
return -1;
helpFile = baseUrl + names[0] + wxS( "/" );
}
}
else
{
wxString base_name = m_frame->help_name();
helpFile = SearchHelpFileFullPath( base_name );
if( !helpFile )
{
msg = wxString::Format( _( "Help file '%s' could not be found.\n"
"Do you want to access the KiCad online help?" ),
base_name );
wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
wxYES_NO | wxNO_DEFAULT | wxCANCEL );
if( dlg.ShowModal() != wxID_YES )
return -1;
helpFile = baseUrl + base_name + wxS( "/" );
}
}
GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
return 0;
}
int COMMON_CONTROL::About( const TOOL_EVENT& aEvent )
{
void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
ShowAboutDialog( m_frame );
return 0;
}
int COMMON_CONTROL::ListHotKeys( const TOOL_EVENT& aEvent )
{
DisplayHotkeyList( m_frame );
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 );
}
return 0;
}
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 );
}
return 0;
}
int COMMON_CONTROL::ReportBug( const TOOL_EVENT& aEvent )
{
if( WarnUserIfOperatingSystemUnsupported() )
return 0;
wxString version = GetVersionInfoData( m_frame->GetUntranslatedAboutTitle(), false, true );
wxString message;
message.Printf( m_bugReportTemplate, version );
KICAD_CURL_EASY kcurl;
wxString url_string;
url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
wxLaunchDefaultBrowser( url_string );
return 0;
}
void COMMON_CONTROL::setTransitions()
{
Go( &COMMON_CONTROL::OpenPreferences, ACTIONS::openPreferences.MakeEvent() );
Go( &COMMON_CONTROL::ConfigurePaths, ACTIONS::configurePaths.MakeEvent() );
Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showSymbolLibTable.MakeEvent() );
Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showFootprintLibTable.MakeEvent() );
Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showDesignBlockLibTable.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() );
Go( &COMMON_CONTROL::ShowProjectManager, ACTIONS::showProjectManager.MakeEvent() );
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() );
Go( &COMMON_CONTROL::Donate, ACTIONS::donate.MakeEvent() );
Go( &COMMON_CONTROL::ReportBug, ACTIONS::reportBug.MakeEvent() );
Go( &COMMON_CONTROL::About, ACTIONS::about.MakeEvent() );
}
|