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 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
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  "<!-- Before Creating a New Issue:\n"
59  "* Search the issue tracker to verify the issue has not already been reported.\n"
60  "* Only report one problem per issue. -->\n"
61  "\n"
62  "# Description\n"
63  "<!-- What is the current behavior and what is the expected behavior? -->\n"
64  "<!-- Please attach screenshots if they will help explain the problem. -->\n"
65  "\n"
66  "# Steps to reproduce\n"
67  "<!-- Please include a screen recording if it will help explain how to reproduce. -->\n"
68  "<!-- If this issue is specific to a project, please attach it. -->\n"
69  "1.\n"
70  "2.\n"
71  "# KiCad Version\n"
72  "\n"
73  "```\n"
74  "%s\n"
75  "```";
76 
77 
79 {
80  m_frame = getEditFrame<EDA_BASE_FRAME>();
81 }
82 
83 
85 {
86  wxCommandEvent dummy;
87 
89 
90  return 0;
91 }
92 
93 
95 {
96  // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
97  // be edited
99 
100  if( pcbnew )
101  {
102  try
103  {
104  pcbnew->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
105  }
106  catch( ... )
107  {
108  // Do nothing here.
109  // A error message is displayed after trying to load _pcbnew.kiface.
110  }
111  }
112  else
113  {
114  DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr );
115 
116  // Use QuasiModal so that HTML help window will work
117  if( dlg.ShowQuasiModal() == wxID_OK )
118  m_frame->Kiway().CommonSettingsChanged( true, false );
119  }
120 
121  return 0;
122 }
123 
124 
126 {
127  if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
128  {
129  try // Sch frame was not available, try to start it
130  {
132  kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
133  }
134  catch( ... )
135  {
136  // _eeschema.kiface is not available: it contains the library table dialog.
137  // Do nothing here.
138  // A error message is displayed after trying to load _eeschema.kiface.
139  }
140  }
141  else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
142  {
143 
144  try // Pcb frame was not available, try to start it
145  {
147  kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
148  }
149  catch( ... )
150  {
151  // _pcbnew.kiface is not available: it contains the library table dialog.
152  // Do nothing here.
153  // A error message is displayed after trying to load _pcbnew.kiface.
154  }
155  }
156 
157  return 0;
158 }
159 
160 
162 {
163  FRAME_T playerType = aEvent.Parameter<FRAME_T>();
164  KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
165 
166  // editor can be null if Player() fails:
167  wxCHECK_MSG( editor != nullptr, 0, "Cannot open/create the editor frame" );
168 
169  // Needed on Windows, other platforms do not use it, but it creates no issue
170  if( editor->IsIconized() )
171  editor->Iconize( false );
172 
173  editor->Raise();
174 
175  // Raising the window does not set the focus on Linux. This should work on
176  // any platform.
177  if( wxWindow::FindFocus() != editor )
178  editor->SetFocus();
179 
180  return 0;
181 }
182 
183 
185 {
186  wxString helpFile;
187  wxString msg;
188 
189  // the URL of help files is "https://docs.kicad.org/<version>/<language>/<name>/"
190  const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + "/"
191  + Pgm().GetLocale()->GetName().BeforeLast( '_' ) + "/";
192 
193  /* We have to get document for beginners,
194  * or the full specific doc
195  * if event id is wxID_INDEX, we want the document for beginners.
196  * else the specific doc file (its name is in Kiface().GetHelpFileName())
197  * The document for beginners is the same for all KiCad utilities
198  */
199  if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
200  {
201  // List of possible names for Getting Started in KiCad
202  const wxChar* names[2] = {
203  wxT( "getting_started_in_kicad" ),
204  wxT( "Getting_Started_in_KiCad" )
205  };
206 
207  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
208  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
209  for( auto& name : names )
210  {
211  helpFile = SearchHelpFileFullPath( name );
212 
213  if( !helpFile.IsEmpty() )
214  break;
215  }
216 
217  if( !helpFile )
218  {
219  msg = wxString::Format( _( "Help file '%s' or\n'%s' could not be found.\n"
220  "Do you want to access the KiCad online help?" ),
221  names[0], names[1] );
222  wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
223  wxYES_NO | wxNO_DEFAULT | wxCANCEL );
224 
225  if( dlg.ShowModal() != wxID_YES )
226  return -1;
227 
228  helpFile = baseUrl + names[0] + "/";
229  }
230  }
231  else
232  {
233  wxString base_name = m_frame->help_name();
234 
235  helpFile = SearchHelpFileFullPath( base_name );
236 
237  if( !helpFile )
238  {
239  msg = wxString::Format( _( "Help file '%s' could not be found.\n"
240  "Do you want to access the KiCad online help?" ),
241  base_name );
242  wxMessageDialog dlg( nullptr, msg, _( "File Not Found" ),
243  wxYES_NO | wxNO_DEFAULT | wxCANCEL );
244 
245  if( dlg.ShowModal() != wxID_YES )
246  return -1;
247 
248  helpFile = baseUrl + base_name + "/";
249  }
250  }
251 
252  GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
253  return 0;
254 }
255 
256 
258 {
260  return 0;
261 }
262 
263 
265 {
266  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
267  {
268  wxString msg;
269  msg.Printf( _( "Could not launch the default browser.\n"
270  "For information on how to help the KiCad project, visit %s" ),
272  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
273  }
274 
275  return 0;
276 }
277 
278 
279 int COMMON_CONTROL::Donate( const TOOL_EVENT& aEvent )
280 {
281  if( !wxLaunchDefaultBrowser( URL_DONATE ) )
282  {
283  wxString msg;
284  msg.Printf( _( "Could not launch the default browser.\n"
285  "To donate to the KiCad project, visit %s" ),
286  URL_DONATE );
287  wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
288  }
289 
290  return 0;
291 }
292 
293 
295 {
297  return 0;
298 
299  wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
300 
301  wxString message;
302  message.Printf( m_bugReportTemplate, version );
303 
304  KICAD_CURL_EASY kcurl;
305  wxString url_string;
306  url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
307 
308  wxLaunchDefaultBrowser( url_string );
309 
310  return 0;
311 }
312 
313 
315 {
324 
326  Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
329  Go( &COMMON_CONTROL::Donate, ACTIONS::donate.MakeEvent() );
331 }
332 
333 
int Donate(const TOOL_EVENT &aEvent)
static TOOL_ACTION listHotKeys
Definition: actions.h:178
BITMAP2CMP_SETTINGS kiface
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:79
#define URL_GET_INVOLVED
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
int ShowLibraryTable(const TOOL_EVENT &aEvent)
wxString GetVersionInfoData(const wxString &aTitle, bool aHtml, bool aBrief)
Create a version info string for bug reports and the about dialog.
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:32
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
int ShowHelp(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
static TOOL_ACTION reportBug
Cursor control event types.
Definition: actions.h:181
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:174
int ReportBug(const TOOL_EVENT &aEvent)
Sets up handlers for various events.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:382
static TOOL_ACTION donate
Definition: actions.h:179
EDA_BASE_FRAME * m_frame
< Pointer to the currently used edit frame.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
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).
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
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
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:175
#define URL_DONATE
void DisplayHotkeyList(EDA_BASE_FRAME *aParent, TOOL_MANAGER *aToolManager)
Display the current hotkey list.
int ShowQuasiModal()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:161
static wxString m_bugReportTemplate
Issue template to use for reporting bugs (this should not be translated)
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
std::string Escape(const std::string &aUrl)
Escapes a string for use as a URL.
int ConfigurePaths(const TOOL_EVENT &aEvent)
int GetInvolved(const TOOL_EVENT &aEvent)
Generic, UI-independent tool event.
Definition: tool_event.h:152
wxString SearchHelpFileFullPath(const wxString &aBaseName)
Return the help file's full path.
int ListHotKeys(const TOOL_EVENT &aEvent)
#define _(s)
pcbnew DSO
Definition: kiway.h:269
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:195
eeschema DSO
Definition: kiway.h:268
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
see class PGM_BASE
static TOOL_ACTION showSymbolEditor
Definition: actions.h:160
const char * name
Definition: DXF_plotter.cpp:56
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
Definition: common.cpp:615
const wxString & GetAboutTitle() const
int ShowPlayer(const TOOL_EVENT &aEvent)
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:148
static wxString m_bugReportUrl
URL to launch a new issue with pre-populated description.
static TOOL_ACTION help
Definition: actions.h:177
The common library.
virtual wxString help_name()
#define URL_DOCUMENTATION
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
int OpenPreferences(const TOOL_EVENT &aEvent)
void OnPreferences(wxCommandEvent &event)
Displays the preferences and settings of all opened editors paged dialog.
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:553
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:159
static TOOL_ACTION openPreferences
Definition: actions.h:172
BASE_SCREEN class implementation.
static TOOL_ACTION getInvolved
Definition: actions.h:180
static TOOL_ACTION configurePaths
Definition: actions.h:173
static TOOL_ACTION gettingStarted
Definition: actions.h:176
static TOOL_ACTION showFootprintEditor
Definition: actions.h:162