KiCad PCB EDA Suite
Loading...
Searching...
No Matches
common_control.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) 2014-2016 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25// kicad_curl_easy.h must be included before wxWidgets because on Windows (msys2), there are
26// collision with wx headers and curl.h defs
28
29#include <bitmaps.h>
30#include <build_version.h>
31#include <common.h> // for SearchHelpFileFullPath
32#include <pgm_base.h>
33#include <tool/actions.h>
34#include <tool/tool_manager.h>
35#include <eda_draw_frame.h>
36#include <view/view.h>
38#include <base_screen.h>
39#include <tool/common_control.h>
40#include <id.h>
41#include <kiface_base.h>
43#include <eda_doc.h>
44#include <wx/msgdlg.h>
45#include <executable_names.h>
46#include <gestfich.h>
48#include <confirm.h>
49
50#define URL_GET_INVOLVED wxS( "https://go.kicad.org/contribute/" )
51#define URL_DONATE wxS( "https://go.kicad.org/app-donate" )
52#define URL_DOCUMENTATION wxS( "https://go.kicad.org/docs/" )
53
54
57 wxS( "https://gitlab.com/kicad/code/kicad/-/issues/new?issuable_template=bare&issue"
58 "[description]=%s" );
59
60
63 "```\n"
64 "%s\n"
65 "```" );
66
67
72
73
75{
76 m_frame->ShowPreferences( wxEmptyString, wxEmptyString );
77 return 0;
78}
79
80
82{
83 // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
84 // be edited
85 if( KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false ) )
86 {
87 try
88 {
89 pcbnew->CreateKiWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
90 }
91 catch( ... )
92 {
93 // Do nothing here.
94 // A error message is displayed after trying to load _pcbnew.kiface.
95 }
96 }
97 else
98 {
100
101 if( dlg.ShowModal() == wxID_OK )
102 m_frame->Kiway().CommonSettingsChanged( ENVVARS_CHANGED );
103 }
104
105 return 0;
106}
107
108
110{
112 {
113 try // Sch frame was not available, try to start it
114 {
115 if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ) )
116 kiface->CreateKiWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
117 }
118 catch( ... )
119 {
120 // _eeschema.kiface is not available: it contains the library table dialog.
121 // Do nothing here.
122 // A error message is displayed after trying to load _eeschema.kiface.
123 }
124 }
125 else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
126 {
127 try // Pcb frame was not available, try to start it
128 {
129 if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB ) )
130 kiface->CreateKiWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
131 }
132 catch( ... )
133 {
134 // _pcbnew.kiface is not available: it contains the library table dialog.
135 // Do nothing here.
136 // A error message is displayed after trying to load _pcbnew.kiface.
137 }
138 }
139 else if( aEvent.IsAction( &ACTIONS::showDesignBlockLibTable ) )
140 {
141 try // Kicad frame was not available, try to start it
142 {
143 if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ) )
144 kiface->CreateKiWindow( m_frame, DIALOG_DESIGN_BLOCK_LIBRARY_TABLE, &m_frame->Kiway() );
145 }
146 catch( ... )
147 {
148 // _eeschema.kiface is not available: it contains the library table dialog.
149 // Do nothing here.
150 // A error message is displayed after trying to load _eeschema.kiface.
151 }
152 }
153
154 return 0;
155}
156
157
159{
160 // Needed on Windows, other platforms do not use it, but it creates no issue
161 if( aFrame->IsIconized() )
162 aFrame->Iconize( false );
163
164 aFrame->Raise();
165
166 // Raising the window does not set the focus on Linux. This should work on
167 // any platform.
168 if( wxWindow::FindFocus() != aFrame )
169 aFrame->SetFocus();
170
171 // If the player is currently blocked, focus the user attention on the correct window
172 if( wxWindow* blocking_win = aFrame->Kiway().GetBlockingDialog() )
173 {
174 blocking_win->Raise();
175 blocking_win->SetFocus();
176 }
177}
178
179
181{
182 FRAME_T playerType = aEvent.Parameter<FRAME_T>();
183 KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
184
185 // editor can be null if Player() fails:
186 wxCHECK_MSG( editor != nullptr, 0, wxT( "Cannot open/create the editor frame" ) );
187
188 showFrame( editor );
189
190 return 0;
191}
192
193
195{
196 m_frame->CallAfter(
197 [this]()
198 {
199 m_frame->Kiway().OnKiCadExit();
200 } );
201
202 return 0;
203}
204
205
206class TERMINATE_HANDLER : public wxProcess
207{
208public:
209 TERMINATE_HANDLER( const wxString& appName )
210 { }
211
212 void OnTerminate( int pid, int status ) override
213 {
214 delete this;
215 }
216};
217
218
219int COMMON_CONTROL::Execute( const wxString& aExecutible, const wxString& aParam )
220{
221 TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( aExecutible );
222
223 bool isKicadBinary = false;
224
225 if( aExecutible == GERBVIEW_EXE || aExecutible == BITMAPCONVERTER_EXE
226 || aExecutible == PCB_CALCULATOR_EXE || aExecutible == PL_EDITOR_EXE
227 || aExecutible == EESCHEMA_EXE || aExecutible == PCBNEW_EXE )
228 {
229 isKicadBinary = true;
230 }
231
232 long pid = ExecuteFile( aExecutible, aParam, callback, isKicadBinary );
233
234 if( pid > 0 )
235 {
236#ifdef __WXMAC__
237 wxString script;
238
239 script.Printf( wxS( "tell application \"System Events\" to tell application process \"%s\"\n"
240 " set frontmost to true\n"
241 "end tell" ),
242 aExecutible );
243
244 // This non-parameterized use of wxExecute is fine because script is not derived
245 // from user input.
246 wxExecute( wxString::Format( "osascript -e '%s'", script ) );
247#endif
248 }
249 else
250 {
251 delete callback;
252 }
253
254 return 0;
255}
256
257
259{
260 wxString execFile;
261 wxString param;
262
264 execFile = PCB_CALCULATOR_EXE;
265 else
266 wxFAIL_MSG( "Execute(): unexpected request" );
267
268 if( execFile.IsEmpty() )
269 return 0;
270
271 return Execute( execFile, param );
272}
273
274
276{
277 // Note: dynamic_cast doesn't work over the Kiway() on MacOS. We have to use static_cast
278 // here.
279 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_frame->Kiway().GetTop() );
280
281 if( top && top->GetFrameType() == KICAD_MAIN_FRAME_T )
282 showFrame( top );
283 else
284 KICAD_MESSAGE_DIALOG( m_frame, _( "Can not switch to project manager in stand-alone mode." ) );
285
286 return 0;
287}
288
289
291{
292 wxString helpFile;
293 wxString msg;
294
295 // the URL of help files is "https://go.kicad.org/docs/<version>/<language>/<name>/"
296 const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + wxT( "/" )
297 + Pgm().GetLocale()->GetName().BeforeLast( '_' ) + wxT( "/" );
298
299 /* We have to get document for beginners,
300 * or the full specific doc
301 * if event id is wxID_INDEX, we want the document for beginners.
302 * else the specific doc file (its name is in Kiface().GetHelpFileName())
303 * The document for beginners is the same for all KiCad utilities
304 */
305 if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
306 {
307 // List of possible names for Getting Started in KiCad
308 const wxChar* names[2] = {
309 wxT( "getting_started_in_kicad" ),
310 wxT( "Getting_Started_in_KiCad" )
311 };
312
313 // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
314 // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
315 for( auto& name : names )
316 {
317 helpFile = SearchHelpFileFullPath( name );
318
319 if( !helpFile.IsEmpty() )
320 break;
321 }
322
323 if( !helpFile )
324 {
325 msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
326 "Do you want to access the KiCad online help?" ),
327 names[0], names[1] );
328 KICAD_MESSAGE_DIALOG dlg( nullptr, msg, _( "File Not Found" ),
329 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
330
331 if( dlg.ShowModal() != wxID_YES )
332 return -1;
333
334 helpFile = baseUrl + names[0] + wxS( "/" );
335 }
336 }
337 else
338 {
339 wxString base_name = m_frame->help_name();
340
341 helpFile = SearchHelpFileFullPath( base_name );
342
343 if( !helpFile )
344 {
345 msg = wxString::Format( _( "Help file '%s' could not be found.\n"
346 "Do you want to access the KiCad online help?" ),
347 base_name );
348 KICAD_MESSAGE_DIALOG dlg( nullptr, msg, _( "File Not Found" ),
349 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
350
351 if( dlg.ShowModal() != wxID_YES )
352 return -1;
353
354 helpFile = baseUrl + base_name + wxS( "/" );
355 }
356 }
357
358 GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
359 return 0;
360}
361
362
364{
365 void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
367 return 0;
368}
369
370
372{
374 return 0;
375}
376
377
379{
380 if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
381 {
382 wxString msg;
383 msg.Printf( _( "Could not launch the default browser.\n"
384 "For information on how to help the KiCad project, visit %s" ),
386 wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
387 }
388
389 return 0;
390}
391
392
394{
395 if( !wxLaunchDefaultBrowser( URL_DONATE ) )
396 {
397 wxString msg;
398 msg.Printf( _( "Could not launch the default browser.\n"
399 "To donate to the KiCad project, visit %s" ),
400 URL_DONATE );
401 wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
402 }
403
404 return 0;
405}
406
407
409{
411 return 0;
412
413 wxString version = GetVersionInfoData( m_frame->GetUntranslatedAboutTitle(), false, true );
414
415 wxString message;
416 message.Printf( m_bugReportTemplate, version );
417
418 KICAD_CURL_EASY kcurl;
419 wxString url_string;
420 url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
421
422 wxLaunchDefaultBrowser( url_string );
423
424 return 0;
425}
426
427
429{
430 Go( &COMMON_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
431
443
450 Go( &COMMON_CONTROL::About, ACTIONS::about.MakeEvent() );
451}
452
453
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
const char * name
BASE_SCREEN class implementation.
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
wxString GetVersionInfoData(const wxString &aTitle, bool aHtml, bool aBrief)
Create a version info string for bug reports and the about dialog.
static TOOL_ACTION showCalculatorTools
Definition actions.h:263
static TOOL_ACTION about
Definition actions.h:287
static TOOL_ACTION reportBug
Definition actions.h:291
static TOOL_ACTION showSymbolLibTable
Definition actions.h:282
static TOOL_ACTION showSymbolEditor
Definition actions.h:260
static TOOL_ACTION showSymbolBrowser
Definition actions.h:259
static TOOL_ACTION donate
Definition actions.h:289
static TOOL_ACTION listHotKeys
Definition actions.h:288
static TOOL_ACTION openPreferences
Definition actions.h:280
static TOOL_ACTION getInvolved
Definition actions.h:290
static TOOL_ACTION showFootprintLibTable
Definition actions.h:283
static TOOL_ACTION quit
Definition actions.h:66
static TOOL_ACTION showDesignBlockLibTable
Definition actions.h:284
static TOOL_ACTION showFootprintEditor
Definition actions.h:262
static TOOL_ACTION configurePaths
Definition actions.h:281
static TOOL_ACTION showProjectManager
Definition actions.h:257
static TOOL_ACTION gettingStarted
Definition actions.h:285
static TOOL_ACTION showFootprintBrowser
Definition actions.h:261
static TOOL_ACTION help
Definition actions.h:286
int ConfigurePaths(const TOOL_EVENT &aEvent)
int ShowHelp(const TOOL_EVENT &aEvent)
EDA_BASE_FRAME * m_frame
< Pointer to the currently used edit frame.
int ShowLibraryTable(const TOOL_EVENT &aEvent)
int Quit(const TOOL_EVENT &aEvent)
int About(const TOOL_EVENT &aEvent)
int ListHotKeys(const TOOL_EVENT &aEvent)
static wxString m_bugReportUrl
URL to launch a new issue with pre-populated description.
int GetInvolved(const TOOL_EVENT &aEvent)
int ShowProjectManager(const TOOL_EVENT &aEvent)
int Execute(const TOOL_EVENT &aEvent)
int ReportBug(const TOOL_EVENT &aEvent)
Sets up handlers for various events.
int ShowPlayer(const TOOL_EVENT &aEvent)
int Donate(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int OpenPreferences(const TOOL_EVENT &aEvent)
static wxString m_bugReportTemplate
Issue template to use for reporting bugs (this should not be translated)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int ShowModal() override
The base frame for deriving all KiCad main window classes.
std::string Escape(const std::string &aUrl)
Escapes a string for use as a URL.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition kiway.cpp:685
@ FACE_SCH
eeschema DSO
Definition kiway.h:301
@ FACE_PCB
pcbnew DSO
Definition kiway.h:302
virtual wxLocale * GetLocale()
Definition pgm_base.h:183
void OnTerminate(int pid, int status) override
TERMINATE_HANDLER(const wxString &appName)
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:186
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:78
Generic, UI-independent tool event.
Definition tool_event.h:171
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:473
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
Definition common.cpp:782
The common library.
#define URL_DONATE
#define URL_DOCUMENTATION
void showFrame(EDA_BASE_FRAME *aFrame)
#define URL_GET_INVOLVED
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
Definition confirm.h:52
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
Definition eda_doc.cpp:63
This file is part of the common library.
KiCad executable names.
const wxString EESCHEMA_EXE
const wxString GERBVIEW_EXE
const wxString PL_EDITOR_EXE
const wxString BITMAPCONVERTER_EXE
const wxString PCBNEW_EXE
const wxString PCB_CALCULATOR_EXE
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:33
@ DIALOG_PCB_LIBRARY_TABLE
Definition frame_type.h:126
@ DIALOG_SCH_LIBRARY_TABLE
Definition frame_type.h:125
@ DIALOG_CONFIGUREPATHS
Definition frame_type.h:123
@ DIALOG_DESIGN_BLOCK_LIBRARY_TABLE
Definition frame_type.h:124
@ KICAD_MAIN_FRAME_T
Definition frame_type.h:68
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition gestfich.cpp:146
void DisplayHotkeyList(EDA_BASE_FRAME *aParent)
Display the current hotkey list.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
wxString SearchHelpFileFullPath(const wxString &aBaseName)
Return the help file's full path.
Implement a participant in the KIWAY alchemy.
Definition kiway.h:155
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
KIBIS top(path, &reporter)
#define ENVVARS_CHANGED