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
46#define URL_GET_INVOLVED wxS( "https://go.kicad.org/contribute/" )
47#define URL_DONATE wxS( "https://go.kicad.org/app-donate" )
48#define URL_DOCUMENTATION wxS( "https://go.kicad.org/docs/" )
49
50
53 wxS( "https://gitlab.com/kicad/code/kicad/-/issues/new?issuable_template=bare&issue"
54 "[description]=%s" );
55
56
59 "```\n"
60 "%s\n"
61 "```" );
62
63
65{
66 m_frame = getEditFrame<EDA_BASE_FRAME>();
67}
68
69
71{
72 m_frame->ShowPreferences( wxEmptyString, wxEmptyString );
73 return 0;
74}
75
76
78{
79 // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
80 // be edited
81 if( KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false ) )
82 {
83 try
84 {
85 pcbnew->CreateKiWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
86 }
87 catch( ... )
88 {
89 // Do nothing here.
90 // A error message is displayed after trying to load _pcbnew.kiface.
91 }
92 }
93 else
94 {
96
97 if( dlg.ShowModal() == wxID_OK )
98 m_frame->Kiway().CommonSettingsChanged( true, false );
99 }
100
101 return 0;
102}
103
104
106{
108 {
109 try // Sch frame was not available, try to start it
110 {
113 }
114 catch( ... )
115 {
116 // _eeschema.kiface is not available: it contains the library table dialog.
117 // Do nothing here.
118 // A error message is displayed after trying to load _eeschema.kiface.
119 }
120 }
121 else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
122 {
123 try // Pcb frame was not available, try to start it
124 {
127 }
128 catch( ... )
129 {
130 // _pcbnew.kiface is not available: it contains the library table dialog.
131 // Do nothing here.
132 // A error message is displayed after trying to load _pcbnew.kiface.
133 }
134 }
135 else if( aEvent.IsAction( &ACTIONS::showDesignBlockLibTable ) )
136 {
137 try // Kicad frame was not available, try to start it
138 {
141 &m_frame->Kiway() );
142 }
143 catch( ... )
144 {
145 // _eeschema.kiface is not available: it contains the library table dialog.
146 // Do nothing here.
147 // A error message is displayed after trying to load _eeschema.kiface.
148 }
149 }
150
151 return 0;
152}
153
154
156{
157 // Needed on Windows, other platforms do not use it, but it creates no issue
158 if( aFrame->IsIconized() )
159 aFrame->Iconize( false );
160
161 aFrame->Raise();
162
163 // Raising the window does not set the focus on Linux. This should work on
164 // any platform.
165 if( wxWindow::FindFocus() != aFrame )
166 aFrame->SetFocus();
167
168 // If the player is currently blocked, focus the user attention on the correct window
169 if( wxWindow* blocking_win = aFrame->Kiway().GetBlockingDialog() )
170 {
171 blocking_win->Raise();
172 blocking_win->SetFocus();
173 }
174}
175
176
178{
179 FRAME_T playerType = aEvent.Parameter<FRAME_T>();
180 KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
181
182 // editor can be null if Player() fails:
183 wxCHECK_MSG( editor != nullptr, 0, wxT( "Cannot open/create the editor frame" ) );
184
185 showFrame( editor );
186
187 return 0;
188}
189
190
192{
193 // Note: dynamic_cast doesn't work over the Kiway() on MacOS. We have to use static_cast
194 // here.
195 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_frame->Kiway().GetTop() );
196
197 if( top && top->GetFrameType() == KICAD_MAIN_FRAME_T )
198 {
199 showFrame( top );
200 }
201 else
202 {
203 wxMessageDialog( m_frame, _( "Can not switch to project manager in stand-alone mode." ) );
204 }
205
206 return 0;
207}
208
209
211{
212 wxString helpFile;
213 wxString msg;
214
215 // the URL of help files is "https://go.kicad.org/docs/<version>/<language>/<name>/"
216 const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + wxT( "/" )
217 + Pgm().GetLocale()->GetName().BeforeLast( '_' ) + wxT( "/" );
218
219 /* We have to get document for beginners,
220 * or the full specific doc
221 * if event id is wxID_INDEX, we want the document for beginners.
222 * else the specific doc file (its name is in Kiface().GetHelpFileName())
223 * The document for beginners is the same for all KiCad utilities
224 */
225 if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
226 {
227 // List of possible names for Getting Started in KiCad
228 const wxChar* names[2] = {
229 wxT( "getting_started_in_kicad" ),
230 wxT( "Getting_Started_in_KiCad" )
231 };
232
233 // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
234 // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
235 for( auto& name : names )
236 {
237 helpFile = SearchHelpFileFullPath( name );
238
239 if( !helpFile.IsEmpty() )
240 break;
241 }
242
243 if( !helpFile )
244 {
245 msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
246 "Do you want to access the KiCad online help?" ),
247 names[0], names[1] );
248 wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
249 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
250
251 if( dlg.ShowModal() != wxID_YES )
252 return -1;
253
254 helpFile = baseUrl + names[0] + wxS( "/" );
255 }
256 }
257 else
258 {
259 wxString base_name = m_frame->help_name();
260
261 helpFile = SearchHelpFileFullPath( base_name );
262
263 if( !helpFile )
264 {
265 msg = wxString::Format( _( "Help file '%s' could not be found.\n"
266 "Do you want to access the KiCad online help?" ),
267 base_name );
268 wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
269 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
270
271 if( dlg.ShowModal() != wxID_YES )
272 return -1;
273
274 helpFile = baseUrl + base_name + wxS( "/" );
275 }
276 }
277
278 GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
279 return 0;
280}
281
282
284{
285 void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
287 return 0;
288}
289
290
292{
294 return 0;
295}
296
297
299{
300 if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
301 {
302 wxString msg;
303 msg.Printf( _( "Could not launch the default browser.\n"
304 "For information on how to help the KiCad project, visit %s" ),
306 wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
307 }
308
309 return 0;
310}
311
312
314{
315 if( !wxLaunchDefaultBrowser( URL_DONATE ) )
316 {
317 wxString msg;
318 msg.Printf( _( "Could not launch the default browser.\n"
319 "To donate to the KiCad project, visit %s" ),
320 URL_DONATE );
321 wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
322 }
323
324 return 0;
325}
326
327
329{
331 return 0;
332
333 wxString version = GetVersionInfoData( m_frame->GetUntranslatedAboutTitle(), false, true );
334
335 wxString message;
336 message.Printf( m_bugReportTemplate, version );
337
338 KICAD_CURL_EASY kcurl;
339 wxString url_string;
340 url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
341
342 wxLaunchDefaultBrowser( url_string );
343
344 return 0;
345}
346
347
349{
360
367 Go( &COMMON_CONTROL::About, ACTIONS::about.MakeEvent() );
368}
369
370
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
const char * name
Definition: DXF_plotter.cpp:59
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 about
Definition: actions.h:234
static TOOL_ACTION reportBug
Definition: actions.h:238
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:229
static TOOL_ACTION showSymbolEditor
Definition: actions.h:211
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:210
static TOOL_ACTION donate
Definition: actions.h:236
static TOOL_ACTION listHotKeys
Definition: actions.h:235
static TOOL_ACTION openPreferences
Definition: actions.h:227
static TOOL_ACTION getInvolved
Definition: actions.h:237
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:230
static TOOL_ACTION showDesignBlockLibTable
Definition: actions.h:231
static TOOL_ACTION showFootprintEditor
Definition: actions.h:213
static TOOL_ACTION configurePaths
Definition: actions.h:228
static TOOL_ACTION showProjectManager
Definition: actions.h:208
static TOOL_ACTION gettingStarted
Definition: actions.h:232
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:212
static TOOL_ACTION help
Definition: actions.h:233
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 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 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.
virtual wxString help_name()
FRAME_T GetFrameType() const
const wxString & GetUntranslatedAboutTitle() const
void ShowPreferences(wxString aStartPage, wxString aStartParentPage)
Display the preferences and settings of all opened editors paged dialog, starting with a particular p...
std::string Escape(const std::string &aUrl)
Escapes a string for use as a URL.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:617
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:670
wxFrame * GetTop()
Definition: kiway.h:427
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:201
@ FACE_SCH
eeschema DSO
Definition: kiway.h:292
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:293
virtual wxLocale * GetLocale()
Definition: pgm_base.h:174
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:465
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:699
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, EMBEDDED_FILES *aFiles)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:62
This file is part of the common library.
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:118
@ DIALOG_SCH_LIBRARY_TABLE
Definition: frame_type.h:117
@ DIALOG_CONFIGUREPATHS
Definition: frame_type.h:115
@ DIALOG_DESIGN_BLOCK_LIBRARY_TABLE
Definition: frame_type.h:116
@ KICAD_MAIN_FRAME_T
Definition: frame_type.h:68
void DisplayHotkeyList(EDA_BASE_FRAME *aParent)
Display the current hotkey list.
Common command IDs shared by more than one of the KiCad applications.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
wxString SearchHelpFileFullPath(const wxString &aBaseName)
Return the help file's full path.
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:152
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)