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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
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 
26 #include <bitmaps.h>
27 #include <build_version.h>
28 #include <common.h> // for SearchHelpFileFullPath
29 #include <pgm_base.h>
30 #include <tool/actions.h>
31 #include <tool/tool_manager.h>
32 #include <eda_draw_frame.h>
33 #include <view/view.h>
35 #include <base_screen.h>
36 #include <tool/common_control.h>
37 #include <id.h>
38 #include <kiface_i.h>
41 #include <eda_doc.h>
42 #include <wx/msgdlg.h>
43 
44 #define URL_GET_INVOLVED "https://kicad.org/contribute/"
45 #define URL_DONATE "https://go.kicad.org/app-donate"
46 #define URL_DOCUMENTATION "https://docs.kicad.org/"
47 
48 
51  "https://gitlab.com/kicad/code/kicad/issues/new?issue[description]=%s";
52 
55  "<!-- Before Creating a New Issue:\n"
56  "* Search the issue tracker to verify the issue has not already been reported.\n"
57  "* Only report one problem per issue. -->\n"
58  "\n"
59  "# Description\n"
60  "<!-- What is the current behavior and what is the expected behavior? -->\n"
61  "<!-- Please attach screenshots if they will help explain the problem. -->\n"
62  "\n"
63  "# Steps to reproduce\n"
64  "<!-- Please include a screen recording if it will help explain how to reproduce. -->\n"
65  "<!-- If this issue is specific to a project, please attach it. -->\n"
66  "1.\n"
67  "2.\n"
68  "# KiCad Version\n"
69  "\n"
70  "```\n"
71  "%s\n"
72  "```";
73 
74 
76 {
77  m_frame = getEditFrame<EDA_BASE_FRAME>();
78 }
79 
80 
82 {
83  wxCommandEvent dummy;
84 
86 
87  return 0;
88 }
89 
90 
92 {
93  // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
94  // be edited
96 
97  if( pcbnew )
98  {
99  try
100  {
101  pcbnew->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
102  }
103  catch( ... )
104  {
105  // Do nothing here.
106  // A error message is displayed after trying to load _pcbnew.kiface.
107  }
108  }
109  else
110  {
111  DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr );
112 
113  // Use QuasiModal so that HTML help window will work
114  if( dlg.ShowQuasiModal() == wxID_OK )
115  m_frame->Kiway().CommonSettingsChanged( true, false );
116  }
117 
118  return 0;
119 }
120 
121 
123 {
124  if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
125  {
126  try // Sch frame was not available, try to start it
127  {
129  kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
130  }
131  catch( ... )
132  {
133  // _eeschema.kiface is not available: it contains the library table dialog.
134  // Do nothing here.
135  // A error message is displayed after trying to load _eeschema.kiface.
136  }
137  }
138  else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
139  {
140 
141  try // Pcb frame was not available, try to start it
142  {
144  kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
145  }
146  catch( ... )
147  {
148  // _pcbnew.kiface is not available: it contains the library table dialog.
149  // Do nothing here.
150  // A error message is displayed after trying to load _pcbnew.kiface.
151  }
152  }
153 
154  return 0;
155 }
156 
157 
159 {
160  FRAME_T playerType = aEvent.Parameter<FRAME_T>();
161  KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
162 
163  // editor can be null if Player() fails:
164  wxCHECK_MSG( editor != nullptr, 0, "Cannot open/create the editor frame" );
165 
166  // Needed on Windows, other platforms do not use it, but it creates no issue
167  if( editor->IsIconized() )
168  editor->Iconize( false );
169 
170  editor->Raise();
171 
172  // Raising the window does not set the focus on Linux. This should work on
173  // any platform.
174  if( wxWindow::FindFocus() != editor )
175  editor->SetFocus();
176 
177  return 0;
178 }
179 
180 
182 {
183  wxString helpFile;
184  wxString msg;
185 
186  // the URL of help files is "https://docs.kicad.org/<version>/<language>/<name>/"
187  const wxString baseUrl = URL_DOCUMENTATION + GetMajorMinorVersion() + "/"
188  + Pgm().GetLocale()->GetName().BeforeLast( '_' ) + "/";
189 
190  /* We have to get document for beginners,
191  * or the full specific doc
192  * if event id is wxID_INDEX, we want the document for beginners.
193  * else the specific doc file (its name is in Kiface().GetHelpFileName())
194  * The document for beginners is the same for all KiCad utilities
195  */
196  if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
197  {
198  // List of possible names for Getting Started in KiCad
199  const wxChar* names[2] = {
200  wxT( "getting_started_in_kicad" ),
201  wxT( "Getting_Started_in_KiCad" )
202  };
203 
204  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
205  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
206  for( auto& name : names )
207  {
208  helpFile = SearchHelpFileFullPath( name );
209 
210  if( !helpFile.IsEmpty() )
211  break;
212  }
213 
214  if( !helpFile )
215  {
216  msg = wxString::Format( _( "Help file \"%s\" or\n\"%s\" could not be found.\n"
217  "Do you want to access the KiCad online help?" ),
218  names[0], names[1] );
219  wxMessageDialog dlg( NULL, msg, _( "File Not Found" ),
220  wxYES_NO | wxNO_DEFAULT | wxCANCEL );
221 
222  if( dlg.ShowModal() != wxID_YES )
223  return -1;
224 
225  helpFile = baseUrl + names[0] + "/";
226  }
227  }
228  else
229  {
230  wxString base_name = m_frame->help_name();
231 
232  helpFile = SearchHelpFileFullPath( base_name );
233 
234  if( !helpFile )
235  {
236  msg = wxString::Format( _( "Help file \"%s\" could not be found.\n"
237  "Do you want to access the KiCad online help?" ),
238  base_name );
239  wxMessageDialog dlg( NULL, msg, _( "File Not Found" ),
240  wxYES_NO | wxNO_DEFAULT | wxCANCEL );
241 
242  if( dlg.ShowModal() != wxID_YES )
243  return -1;
244 
245  helpFile = baseUrl + base_name + "/";
246  }
247  }
248 
249  GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
250  return 0;
251 }
252 
253 
255 {
257  return 0;
258 }
259 
260 
262 {
263  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
264  {
265  wxString msg;
266  msg.Printf( _( "Could not launch the default browser.\n"
267  "For information on how to help the KiCad project, visit %s" ),
269  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
270  }
271  return 0;
272 }
273 
274 
275 int COMMON_CONTROL::Donate( const TOOL_EVENT& aEvent )
276 {
277  if( !wxLaunchDefaultBrowser( URL_DONATE ) )
278  {
279  wxString msg;
280  msg.Printf( _( "Could not launch the default browser.\n"
281  "To donate to the KiCad project, visit %s" ),
282  URL_DONATE );
283  wxMessageBox( msg, _( "Donate to KiCad" ), wxOK, m_frame );
284  }
285  return 0;
286 }
287 
288 
290 {
292  return 0;
293 
294  wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
295 
296  wxString message;
297  message.Printf( m_bugReportTemplate, version );
298 
299  KICAD_CURL_EASY kcurl;
300  wxString url_string;
301  url_string.Printf( m_bugReportUrl, kcurl.Escape( std::string( message.utf8_str() ) ) );
302 
303  wxLaunchDefaultBrowser( url_string );
304 
305  return 0;
306 }
307 
308 
310 {
319 
321  Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
324  Go( &COMMON_CONTROL::Donate, ACTIONS::donate.MakeEvent() );
326 }
327 
328 
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:373
KICAD_CURL_EASY wrapper interface around the curl_easy API.
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:70
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:175
#define URL_DONATE
#define NULL
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:427
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:267
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:192
eeschema DSO
Definition: kiway.h:266
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:59
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
Definition: common.cpp:610
const wxString & GetAboutTitle() const
int ShowPlayer(const TOOL_EVENT &aEvent)
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:146
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:543
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