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 )
102  }
103 
104 
105  return 0;
106 }
107 
108 
110 {
111  if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
112  {
113  try // Sch frame was not available, try to start it
114  {
116  kiface->CreateWindow( 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->CreateWindow( 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  // Needed on Windows, other platforms do not use it, but it creates no issue
151  if( editor->IsIconized() )
152  editor->Iconize( false );
153 
154  editor->Raise();
155 
156  // Raising the window does not set the focus on Linux. This should work on
157  // any platform.
158  if( wxWindow::FindFocus() != editor )
159  editor->SetFocus();
160 
161  return 0;
162 }
163 
164 
166 {
167  const SEARCH_STACK& search = m_frame->sys_search();
168  wxString helpFile;
169  wxString msg;
170 
171  /* We have to get document for beginners,
172  * or the full specific doc
173  * if event id is wxID_INDEX, we want the document for beginners.
174  * else the specific doc file (its name is in Kiface().GetHelpFileName())
175  * The document for beginners is the same for all KiCad utilities
176  */
177  if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
178  {
179  // List of possible names for Getting Started in KiCad
180  const wxChar* names[2] = {
181  wxT( "getting_started_in_kicad" ),
182  wxT( "Getting_Started_in_KiCad" )
183  };
184 
185  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
186  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
187  for( auto& name : names )
188  {
189  helpFile = SearchHelpFileFullPath( search, name );
190 
191  if( !helpFile.IsEmpty() )
192  break;
193  }
194 
195  if( !helpFile )
196  {
197  msg = wxString::Format( _( "Html or pdf help file \n%s\nor\n%s could not be found." ),
198  names[0], names[1] );
199  wxMessageBox( msg );
200  return -1;
201  }
202  }
203  else
204  {
205  wxString base_name = m_frame->help_name();
206 
207  helpFile = SearchHelpFileFullPath( search, base_name );
208 
209  if( !helpFile )
210  {
211  msg = wxString::Format( _( "Help file \"%s\" could not be found." ), base_name );
212  wxMessageBox( msg );
213  return -1;
214  }
215  }
216 
217  GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
218  return 0;
219 }
220 
221 
223 {
225  return 0;
226 }
227 
228 
230 {
231  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
232  {
233  wxString msg;
234  msg.Printf( _( "Could not launch the default browser.\n"
235  "For information on how to help the KiCad project, visit %s" ),
237  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
238  }
239  return 0;
240 }
241 
242 
244 {
245  wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
246 
247  wxString message;
248  message.Printf( m_bugReportTemplate, version );
249 
250  KICAD_CURL_EASY kcurl;
251  wxString url_string;
252  url_string.Printf( m_bugReportUrl, kcurl.Escape( message.ToStdString() ) );
253 
254  wxLaunchDefaultBrowser( url_string );
255 
256  return 0;
257 }
258 
259 
261 {
269 
271  Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
275 }
276 
277 
static TOOL_ACTION listHotKeys
Definition: actions.h:171
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
wxString SearchHelpFileFullPath(const SEARCH_STACK &aSearchStack, const wxString &aBaseName)
Return the help file's full path.
VTBL_ENTRY void CommonSettingsChanged(bool aEnvVarsChanged)
Function CommonSettingsChanged Calls CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:472
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:173
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:167
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:168
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:342
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:154
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
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:178
eeschema DSO
Definition: kiway.h:281
static TOOL_ACTION showSymbolEditor
Definition: actions.h:153
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:205
#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:170
virtual wxString help_name()
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:152
BASE_SCREEN class implementation.
static TOOL_ACTION getInvolved
Definition: actions.h:172
static TOOL_ACTION configurePaths
Definition: actions.h:166
static TOOL_ACTION gettingStarted
Definition: actions.h:169
static TOOL_ACTION showFootprintEditor
Definition: actions.h:155