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
49#define URL_GET_INVOLVED wxS( "https://go.kicad.org/contribute/" )
50#define URL_DONATE wxS( "https://go.kicad.org/app-donate" )
51#define URL_DOCUMENTATION wxS( "https://go.kicad.org/docs/" )
52
53
56 wxS( "https://gitlab.com/kicad/code/kicad/-/issues/new?issuable_template=bare&issue"
57 "[description]=%s" );
58
59
62 "```\n"
63 "%s\n"
64 "```" );
65
66
71
72
74{
75 m_frame->ShowPreferences( wxEmptyString, wxEmptyString );
76 return 0;
77}
78
79
81{
82 // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
83 // be edited
84 if( KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false ) )
85 {
86 try
87 {
88 pcbnew->CreateKiWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
89 }
90 catch( ... )
91 {
92 // Do nothing here.
93 // A error message is displayed after trying to load _pcbnew.kiface.
94 }
95 }
96 else
97 {
99
100 if( dlg.ShowModal() == wxID_OK )
101 m_frame->Kiway().CommonSettingsChanged( ENVVARS_CHANGED );
102 }
103
104 return 0;
105}
106
107
109{
111 {
112 try // Sch frame was not available, try to start it
113 {
114 if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ) )
115 kiface->CreateKiWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
116 }
117 catch( ... )
118 {
119 // _eeschema.kiface is not available: it contains the library table dialog.
120 // Do nothing here.
121 // A error message is displayed after trying to load _eeschema.kiface.
122 }
123 }
124 else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
125 {
126 try // Pcb frame was not available, try to start it
127 {
128 if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB ) )
129 kiface->CreateKiWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
130 }
131 catch( ... )
132 {
133 // _pcbnew.kiface is not available: it contains the library table dialog.
134 // Do nothing here.
135 // A error message is displayed after trying to load _pcbnew.kiface.
136 }
137 }
138 else if( aEvent.IsAction( &ACTIONS::showDesignBlockLibTable ) )
139 {
140 try // Kicad frame was not available, try to start it
141 {
142 if( KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ) )
143 kiface->CreateKiWindow( m_frame, DIALOG_DESIGN_BLOCK_LIBRARY_TABLE, &m_frame->Kiway() );
144 }
145 catch( ... )
146 {
147 // _eeschema.kiface is not available: it contains the library table dialog.
148 // Do nothing here.
149 // A error message is displayed after trying to load _eeschema.kiface.
150 }
151 }
152
153 return 0;
154}
155
156
158{
159 // Needed on Windows, other platforms do not use it, but it creates no issue
160 if( aFrame->IsIconized() )
161 aFrame->Iconize( false );
162
163 aFrame->Raise();
164
165 // Raising the window does not set the focus on Linux. This should work on
166 // any platform.
167 if( wxWindow::FindFocus() != aFrame )
168 aFrame->SetFocus();
169
170 // If the player is currently blocked, focus the user attention on the correct window
171 if( wxWindow* blocking_win = aFrame->Kiway().GetBlockingDialog() )
172 {
173 blocking_win->Raise();
174 blocking_win->SetFocus();
175 }
176}
177
178
180{
181 FRAME_T playerType = aEvent.Parameter<FRAME_T>();
182 KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
183
184 // editor can be null if Player() fails:
185 wxCHECK_MSG( editor != nullptr, 0, wxT( "Cannot open/create the editor frame" ) );
186
187 showFrame( editor );
188
189 return 0;
190}
191
192
194{
195 m_frame->CallAfter(
196 [this]()
197 {
198 m_frame->Kiway().OnKiCadExit();
199 } );
200
201 return 0;
202}
203
204
205class TERMINATE_HANDLER : public wxProcess
206{
207public:
208 TERMINATE_HANDLER( const wxString& appName )
209 { }
210
211 void OnTerminate( int pid, int status ) override
212 {
213 delete this;
214 }
215};
216
217
218int COMMON_CONTROL::Execute( const wxString& aExecutible, const wxString& aParam )
219{
220 TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( aExecutible );
221
222 bool isKicadBinary = false;
223
224 if( aExecutible == GERBVIEW_EXE || aExecutible == BITMAPCONVERTER_EXE
225 || aExecutible == PCB_CALCULATOR_EXE || aExecutible == PL_EDITOR_EXE
226 || aExecutible == EESCHEMA_EXE || aExecutible == PCBNEW_EXE )
227 {
228 isKicadBinary = true;
229 }
230
231 long pid = ExecuteFile( aExecutible, aParam, callback, isKicadBinary );
232
233 if( pid > 0 )
234 {
235#ifdef __WXMAC__
236 wxString script;
237
238 script.Printf( wxS( "tell application \"System Events\" to tell application process \"%s\"\n"
239 " set frontmost to true\n"
240 "end tell" ),
241 aExecutible );
242
243 // This non-parameterized use of wxExecute is fine because script is not derived
244 // from user input.
245 wxExecute( wxString::Format( "osascript -e '%s'", script ) );
246#endif
247 }
248 else
249 {
250 delete callback;
251 }
252
253 return 0;
254}
255
256
258{
259 wxString execFile;
260 wxString param;
261
263 execFile = PCB_CALCULATOR_EXE;
264 else
265 wxFAIL_MSG( "Execute(): unexpected request" );
266
267 if( execFile.IsEmpty() )
268 return 0;
269
270 return Execute( execFile, param );
271}
272
273
275{
276 // Note: dynamic_cast doesn't work over the Kiway() on MacOS. We have to use static_cast
277 // here.
278 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_frame->Kiway().GetTop() );
279
280 if( top && top->GetFrameType() == KICAD_MAIN_FRAME_T )
281 showFrame( top );
282 else
283 wxMessageDialog( m_frame, _( "Can not switch to project manager in stand-alone mode." ) );
284
285 return 0;
286}
287
288
290{
291 wxString helpFile;
292 wxString msg;
293
294 // the URL of help files is "https://go.kicad.org/docs/<version>/<language>/<name>/"
295 const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + wxT( "/" )
296 + Pgm().GetLocale()->GetName().BeforeLast( '_' ) + wxT( "/" );
297
298 /* We have to get document for beginners,
299 * or the full specific doc
300 * if event id is wxID_INDEX, we want the document for beginners.
301 * else the specific doc file (its name is in Kiface().GetHelpFileName())
302 * The document for beginners is the same for all KiCad utilities
303 */
304 if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
305 {
306 // List of possible names for Getting Started in KiCad
307 const wxChar* names[2] = {
308 wxT( "getting_started_in_kicad" ),
309 wxT( "Getting_Started_in_KiCad" )
310 };
311
312 // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
313 // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
314 for( auto& name : names )
315 {
316 helpFile = SearchHelpFileFullPath( name );
317
318 if( !helpFile.IsEmpty() )
319 break;
320 }
321
322 if( !helpFile )
323 {
324 msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
325 "Do you want to access the KiCad online help?" ),
326 names[0], names[1] );
327 wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
328 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
329
330 if( dlg.ShowModal() != wxID_YES )
331 return -1;
332
333 helpFile = baseUrl + names[0] + wxS( "/" );
334 }
335 }
336 else
337 {
338 wxString base_name = m_frame->help_name();
339
340 helpFile = SearchHelpFileFullPath( base_name );
341
342 if( !helpFile )
343 {
344 msg = wxString::Format( _( "Help file '%s' could not be found.\n"
345 "Do you want to access the KiCad online help?" ),
346 base_name );
347 wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
348 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
349
350 if( dlg.ShowModal() != wxID_YES )
351 return -1;
352
353 helpFile = baseUrl + base_name + wxS( "/" );
354 }
355 }
356
357 GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
358 return 0;
359}
360
361
363{
364 void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
366 return 0;
367}
368
369
371{
373 return 0;
374}
375
376
378{
379 if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
380 {
381 wxString msg;
382 msg.Printf( _( "Could not launch the default browser.\n"
383 "For information on how to help the KiCad project, visit %s" ),
385 wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
386 }
387
388 return 0;
389}
390
391
393{
394 if( !wxLaunchDefaultBrowser( URL_DONATE ) )
395 {
396 wxString msg;
397 msg.Printf( _( "Could not launch the default browser.\n"
398 "To donate to the KiCad project, visit %s" ),
399 URL_DONATE );
400 wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
401 }
402
403 return 0;
404}
405
406
408{
410 return 0;
411
412 wxString version = GetVersionInfoData( m_frame->GetUntranslatedAboutTitle(), false, true );
413
414 wxString message;
415 message.Printf( m_bugReportTemplate, version );
416
417 KICAD_CURL_EASY kcurl;
418 wxString url_string;
419 url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
420
421 wxLaunchDefaultBrowser( url_string );
422
423 return 0;
424}
425
426
428{
429 Go( &COMMON_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
430
442
449 Go( &COMMON_CONTROL::About, ACTIONS::about.MakeEvent() );
450}
451
452
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:912
The common library.
#define URL_DONATE
#define URL_DOCUMENTATION
void showFrame(EDA_BASE_FRAME *aFrame)
#define URL_GET_INVOLVED
#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:125
@ DIALOG_SCH_LIBRARY_TABLE
Definition frame_type.h:124
@ DIALOG_CONFIGUREPATHS
Definition frame_type.h:122
@ DIALOG_DESIGN_BLOCK_LIBRARY_TABLE
Definition frame_type.h:123
@ 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:145
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