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  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <bitmaps.h>
26 #include <build_version.h>
27 #include <tool/actions.h>
28 #include <tool/tool_manager.h>
29 #include <eda_draw_frame.h>
30 #include <class_draw_panel_gal.h>
31 #include <view/view.h>
32 #include <view/view_controls.h>
34 #include <base_screen.h>
35 #include <tool/common_control.h>
36 #include <id.h>
37 #include <project.h>
38 #include <kiface_i.h>
40 #include <dialog_configure_paths.h>
41 #include <eda_doc.h>
42 
43 #define URL_GET_INVOLVED "http://kicad-pcb.org/contribute/"
44 
45 
48  "https://gitlab.com/kicad/code/kicad/issues/new?issue[description]=%s";
49 
52  "<!-- Before Creating a New Issue:\n"
53  "* Search the issue tracker to verify the issue has not already been reported.\n"
54  "* Only report one problem per issue. -->\n"
55  "\n"
56  "# Description\n"
57  "<!-- What is the current behavior and what is the expected behavior? -->\n"
58  "<!-- Please attach screenshots if they will help explain the problem. -->\n"
59  "\n"
60  "# Steps to reproduce\n"
61  "<!-- Please include a screen recording if it will help explain how to reproduce. -->\n"
62  "<!-- If this issue is specific to a project, please attach it. -->\n"
63  "1.\n"
64  "2.\n"
65  "# KiCad Version\n"
66  "\n"
67  "```\n"
68  "%s\n"
69  "```";
70 
71 
73 {
74  m_frame = getEditFrame<EDA_BASE_FRAME>();
75 }
76 
77 
79 {
80  // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
81  // be edited
82  KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false );
83 
84  if( pcbnew )
85  {
86  try
87  {
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  {
98  DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr );
99 
100  if( dlg.ShowModal() == wxID_OK )
101  m_frame->Kiway().CommonSettingsChanged( true, false );
102  }
103 
104  return 0;
105 }
106 
107 
109 {
110  if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
111  {
112  try // Sch frame was not available, try to start it
113  {
115  kiface->CreateWindow( 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 
127  try // Pcb frame was not available, try to start it
128  {
130  kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
131  }
132  catch( ... )
133  {
134  // _pcbnew.kiface is not available: it contains the library table dialog.
135  // Do nothing here.
136  // A error message is displayed after trying to load _pcbnew.kiface.
137  }
138  }
139 
140  return 0;
141 }
142 
143 
145 {
146  FRAME_T playerType = aEvent.Parameter<FRAME_T>();
147  KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
148 
149  // Needed on Windows, other platforms do not use it, but it creates no issue
150  if( editor->IsIconized() )
151  editor->Iconize( false );
152 
153  editor->Raise();
154 
155  // Raising the window does not set the focus on Linux. This should work on
156  // any platform.
157  if( wxWindow::FindFocus() != editor )
158  editor->SetFocus();
159 
160  return 0;
161 }
162 
163 
165 {
166  const SEARCH_STACK& search = m_frame->sys_search();
167  wxString helpFile;
168  wxString msg;
169 
170  /* We have to get document for beginners,
171  * or the full specific doc
172  * if event id is wxID_INDEX, we want the document for beginners.
173  * else the specific doc file (its name is in Kiface().GetHelpFileName())
174  * The document for beginners is the same for all KiCad utilities
175  */
176  if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
177  {
178  // List of possible names for Getting Started in KiCad
179  const wxChar* names[2] = {
180  wxT( "getting_started_in_kicad" ),
181  wxT( "Getting_Started_in_KiCad" )
182  };
183 
184  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
185  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
186  for( auto& name : names )
187  {
188  helpFile = SearchHelpFileFullPath( search, name );
189 
190  if( !helpFile.IsEmpty() )
191  break;
192  }
193 
194  if( !helpFile )
195  {
196  msg = wxString::Format( _( "Html or pdf help file \n%s\nor\n%s could not be found." ),
197  names[0], names[1] );
198  wxMessageBox( msg );
199  return -1;
200  }
201  }
202  else
203  {
204  wxString base_name = m_frame->help_name();
205 
206  helpFile = SearchHelpFileFullPath( search, base_name );
207 
208  if( !helpFile )
209  {
210  msg = wxString::Format( _( "Help file \"%s\" could not be found." ), base_name );
211  wxMessageBox( msg );
212  return -1;
213  }
214  }
215 
216  GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
217  return 0;
218 }
219 
220 
222 {
224  return 0;
225 }
226 
227 
229 {
230  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
231  {
232  wxString msg;
233  msg.Printf( _( "Could not launch the default browser.\n"
234  "For information on how to help the KiCad project, visit %s" ),
236  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
237  }
238  return 0;
239 }
240 
241 
243 {
244  wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
245 
246  wxString message;
247  message.Printf( m_bugReportTemplate, version );
248 
249  KICAD_CURL_EASY kcurl;
250  wxString url_string;
251  url_string.Printf( m_bugReportUrl, kcurl.Escape( message.ToStdString() ) );
252 
253  wxLaunchDefaultBrowser( url_string );
254 
255  return 0;
256 }
257 
258 
260 {
268 
270  Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
274 }
275 
276 
static TOOL_ACTION listHotKeys
Definition: actions.h:175
BITMAP2CMP_SETTINGS kiface
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:80
#define URL_GET_INVOLVED
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
int ShowLibraryTable(const TOOL_EVENT &aEvent)
VIEW_CONTROLS class definition.
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
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
void setTransitions() override
Sets up handlers for various events.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
int ShowHelp(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
static TOOL_ACTION reportBug
Definition: actions.h:177
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:171
int ReportBug(const TOOL_EVENT &aEvent)
KICAD_CURL_EASY wrapper interface around the curl_easy API.
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
EDA_BASE_FRAME * m_frame
Pointer to the currently used edit frame.
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:67
VTBL_ENTRY wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKIWAY, int aCtlBits=0)=0
Function CreateWindow creates a wxWindow for the current project.
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:172
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:343
virtual const SEARCH_STACK & sys_search()
Return a SEARCH_STACK pertaining to entire program.
void DisplayHotkeyList(EDA_BASE_FRAME *aParent, TOOL_MANAGER *aToolManager)
Function DisplayHotkeyList Displays the current hotkey list.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:157
static wxString m_bugReportTemplate
Issue template to use for reporting bugs (this should not be translated)
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
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)
TOOL_EVENT.
Definition: tool_event.h:171
wxString SearchHelpFileFullPath(const SEARCH_STACK &aSStack, const wxString &aBaseName)
Return the help file's full path.
int ListHotKeys(const TOOL_EVENT &aEvent)
pcbnew DSO
Definition: kiway.h:282
VTBL_ENTRY KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
Definition: kiway.cpp:179
eeschema DSO
Definition: kiway.h:281
static TOOL_ACTION showSymbolEditor
Definition: actions.h:156
const char * name
Definition: DXF_plotter.cpp:60
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
const wxString & GetAboutTitle() const
int ShowPlayer(const TOOL_EVENT &aEvent)
KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
static wxString m_bugReportUrl
URL to launch a new issue with pre-populated description.
static TOOL_ACTION help
Definition: actions.h:174
virtual wxString help_name()
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
VTBL_ENTRY void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Function CommonSettingsChanged Calls CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:513
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:155
BASE_SCREEN class implementation.
static TOOL_ACTION getInvolved
Definition: actions.h:176
static TOOL_ACTION configurePaths
Definition: actions.h:170
static TOOL_ACTION gettingStarted
Definition: actions.h:173
static TOOL_ACTION showFootprintEditor
Definition: actions.h:158