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 <tool/actions.h>
27 #include <tool/tool_manager.h>
28 #include <eda_draw_frame.h>
29 #include <class_draw_panel_gal.h>
30 #include <view/view.h>
31 #include <view/view_controls.h>
33 #include <base_screen.h>
34 #include <tool/common_control.h>
35 #include <id.h>
36 #include <project.h>
37 #include <kiface_i.h>
38 #include <dialog_configure_paths.h>
39 #include <eda_doc.h>
40 
41 #define URL_GET_INVOLVED "http://kicad-pcb.org/contribute/"
42 
43 
45 {
46  m_frame = getEditFrame<EDA_BASE_FRAME>();
47 }
48 
49 
51 {
52  try // _pcbnew.kiface must be available: it contains the configure path dialog.
53  {
55  kiface->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
56  }
57  catch( ... )
58  {
59  // Do nothing here.
60  // A error message is displayed after trying to load _pcbnew.kiface.
61  }
62  return 0;
63 }
64 
65 
67 {
68  if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
69  {
70  try // Sch frame was not available, try to start it
71  {
73  kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
74  }
75  catch( ... )
76  {
77  // _eeschema.kiface is not available: it contains the library table dialog.
78  // Do nothing here.
79  // A error message is displayed after trying to load _eeschema.kiface.
80  }
81  }
82  else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
83  {
84 
85  try // Pcb frame was not available, try to start it
86  {
88  kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
89  }
90  catch( ... )
91  {
92  // _pcbnew.kiface is not available: it contains the library table dialog.
93  // Do nothing here.
94  // A error message is displayed after trying to load _pcbnew.kiface.
95  }
96  }
97 
98  return 0;
99 }
100 
101 
103 {
104  FRAME_T playerType = aEvent.Parameter<FRAME_T>();
105  KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
106 
107  // Needed on Windows, other platforms do not use it, but it creates no issue
108  if( editor->IsIconized() )
109  editor->Iconize( false );
110 
111  editor->Raise();
112 
113  // Raising the window does not set the focus on Linux. This should work on
114  // any platform.
115  if( wxWindow::FindFocus() != editor )
116  editor->SetFocus();
117 
118  return 0;
119 }
120 
121 
123 {
124  const SEARCH_STACK& search = m_frame->sys_search();
125  wxString helpFile;
126  wxString msg;
127 
128  /* We have to get document for beginners,
129  * or the full specific doc
130  * if event id is wxID_INDEX, we want the document for beginners.
131  * else the specific doc file (its name is in Kiface().GetHelpFileName())
132  * The document for beginners is the same for all KiCad utilities
133  */
134  if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
135  {
136  // List of possible names for Getting Started in KiCad
137  const wxChar* names[2] = {
138  wxT( "getting_started_in_kicad" ),
139  wxT( "Getting_Started_in_KiCad" )
140  };
141 
142  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
143  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
144  for( auto& name : names )
145  {
146  helpFile = SearchHelpFileFullPath( search, name );
147 
148  if( !helpFile.IsEmpty() )
149  break;
150  }
151 
152  if( !helpFile )
153  {
154  msg = wxString::Format( _( "Html or pdf help file \n%s\nor\n%s could not be found." ),
155  names[0], names[1] );
156  wxMessageBox( msg );
157  return -1;
158  }
159  }
160  else
161  {
162  wxString base_name = m_frame->help_name();
163 
164  helpFile = SearchHelpFileFullPath( search, base_name );
165 
166  if( !helpFile )
167  {
168  msg = wxString::Format( _( "Help file \"%s\" could not be found." ), base_name );
169  wxMessageBox( msg );
170  return -1;
171  }
172  }
173 
174  GetAssociatedDocument( m_frame, helpFile );
175  return 0;
176 }
177 
178 
180 {
182  return 0;
183 }
184 
185 
187 {
188  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
189  {
190  wxString msg;
191  msg.Printf( _( "Could not launch the default browser.\n"
192  "For information on how to help the KiCad project, visit %s" ),
194  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
195  }
196  return 0;
197 }
198 
199 
201 {
209 
211  Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
214 }
215 
216 
static TOOL_ACTION listHotKeys
Definition: actions.h:171
BITMAP2CMP_SETTINGS kiface
#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.
int ShowLibraryTable(const TOOL_EVENT &aEvent)
VIEW_CONTROLS class definition.
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:218
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 showSymbolLibTable
Definition: actions.h:167
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:80
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
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:341
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.
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:154
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
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:177
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
int ShowPlayer(const TOOL_EVENT &aEvent)
KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
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:78
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