KiCad PCB EDA Suite
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 (C) 2021-2022 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 "https://kicad.org/contribute/"
47#define URL_DONATE "https://go.kicad.org/app-donate"
48#define URL_DOCUMENTATION "https://docs.kicad.org/"
49
50
53 "https://gitlab.com/kicad/code/kicad/issues/new?issue[description]=%s";
54
55
58 "```\n"
59 "%s\n"
60 "```";
61
62
64{
65 m_frame = getEditFrame<EDA_BASE_FRAME>();
66}
67
68
70{
71 wxCommandEvent dummy;
72
74
75 return 0;
76}
77
78
80{
81 // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
82 // be edited
84
85 if( pcbnew )
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( true, false );
103 }
104
105 return 0;
106}
107
108
110{
112 {
113 try // Sch frame was not available, try to start it
114 {
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
128 try // Pcb frame was not available, try to start it
129 {
131 kiface->CreateKiWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
132 }
133 catch( ... )
134 {
135 // _pcbnew.kiface is not available: it contains the library table dialog.
136 // Do nothing here.
137 // A error message is displayed after trying to load _pcbnew.kiface.
138 }
139 }
140
141 return 0;
142}
143
144
146{
147 FRAME_T playerType = aEvent.Parameter<FRAME_T>();
148 KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
149
150 // editor can be null if Player() fails:
151 wxCHECK_MSG( editor != nullptr, 0, wxT( "Cannot open/create the editor frame" ) );
152
153 // Needed on Windows, other platforms do not use it, but it creates no issue
154 if( editor->IsIconized() )
155 editor->Iconize( false );
156
157 editor->Raise();
158
159 // Raising the window does not set the focus on Linux. This should work on
160 // any platform.
161 if( wxWindow::FindFocus() != editor )
162 editor->SetFocus();
163
164 // If the player is currently blocked, focus the user attention on the correct window
165 if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
166 {
167 blocking_win->Raise();
168 blocking_win->SetFocus();
169 }
170
171 return 0;
172}
173
174
176{
177 wxString helpFile;
178 wxString msg;
179
180 // the URL of help files is "https://docs.kicad.org/<version>/<language>/<name>/"
181 const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + wxT( "/" )
182 + Pgm().GetLocale()->GetName().BeforeLast( '_' ) + wxT( "/" );
183
184 /* We have to get document for beginners,
185 * or the full specific doc
186 * if event id is wxID_INDEX, we want the document for beginners.
187 * else the specific doc file (its name is in Kiface().GetHelpFileName())
188 * The document for beginners is the same for all KiCad utilities
189 */
190 if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
191 {
192 // List of possible names for Getting Started in KiCad
193 const wxChar* names[2] = {
194 wxT( "getting_started_in_kicad" ),
195 wxT( "Getting_Started_in_KiCad" )
196 };
197
198 // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
199 // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
200 for( auto& name : names )
201 {
202 helpFile = SearchHelpFileFullPath( name );
203
204 if( !helpFile.IsEmpty() )
205 break;
206 }
207
208 if( !helpFile )
209 {
210 msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
211 "Do you want to access the KiCad online help?" ),
212 names[0], names[1] );
213 wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
214 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
215
216 if( dlg.ShowModal() != wxID_YES )
217 return -1;
218
219 helpFile = baseUrl + names[0] + "/";
220 }
221 }
222 else
223 {
224 wxString base_name = m_frame->help_name();
225
226 helpFile = SearchHelpFileFullPath( base_name );
227
228 if( !helpFile )
229 {
230 msg = wxString::Format( _( "Help file '%s' could not be found.\n"
231 "Do you want to access the KiCad online help?" ),
232 base_name );
233 wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
234 wxYES_NO | wxNO_DEFAULT | wxCANCEL );
235
236 if( dlg.ShowModal() != wxID_YES )
237 return -1;
238
239 helpFile = baseUrl + base_name + "/";
240 }
241 }
242
243 GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
244 return 0;
245}
246
247
249{
251 return 0;
252}
253
254
256{
257 if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
258 {
259 wxString msg;
260 msg.Printf( _( "Could not launch the default browser.\n"
261 "For information on how to help the KiCad project, visit %s" ),
263 wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
264 }
265
266 return 0;
267}
268
269
271{
272 if( !wxLaunchDefaultBrowser( URL_DONATE ) )
273 {
274 wxString msg;
275 msg.Printf( _( "Could not launch the default browser.\n"
276 "To donate to the KiCad project, visit %s" ),
277 URL_DONATE );
278 wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
279 }
280
281 return 0;
282}
283
284
286{
288 return 0;
289
290 wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
291
292 wxString message;
293 message.Printf( m_bugReportTemplate, version );
294
295 KICAD_CURL_EASY kcurl;
296 wxString url_string;
297 url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
298
299 wxLaunchDefaultBrowser( url_string );
300
301 return 0;
302}
303
304
306{
315
322}
323
324
const char * name
Definition: DXF_plotter.cpp:56
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 reportBug
Cursor control event types.
Definition: actions.h:187
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:180
static TOOL_ACTION showSymbolEditor
Definition: actions.h:164
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:163
static TOOL_ACTION donate
Definition: actions.h:185
static TOOL_ACTION listHotKeys
Definition: actions.h:184
static TOOL_ACTION openPreferences
Definition: actions.h:178
static TOOL_ACTION getInvolved
Definition: actions.h:186
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:181
static TOOL_ACTION showFootprintEditor
Definition: actions.h:166
static TOOL_ACTION configurePaths
Definition: actions.h:179
static TOOL_ACTION gettingStarted
Definition: actions.h:182
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:165
static TOOL_ACTION help
Definition: actions.h:183
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 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 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.
virtual wxString help_name()
const wxString & GetAboutTitle() const
void OnPreferences(wxCommandEvent &event)
Displays the preferences and settings of all opened editors paged dialog.
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:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:572
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:198
@ FACE_SCH
eeschema DSO
Definition: kiway.h:280
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:281
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:156
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:442
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:88
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:603
The common library.
#define URL_DONATE
#define URL_DOCUMENTATION
#define URL_GET_INVOLVED
return & kiface
Definition: cvpcb.cpp:112
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:74
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:105
@ DIALOG_SCH_LIBRARY_TABLE
Definition: frame_type.h:104
@ DIALOG_CONFIGUREPATHS
Definition: frame_type.h:103
void DisplayHotkeyList(EDA_BASE_FRAME *aParent)
Display the current hotkey list.
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
wxString SearchHelpFileFullPath(const wxString &aBaseName)
Return the help file's full path.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151