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 {
53  kiface->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
54  return 0;
55 }
56 
57 
59 {
60  if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
61  {
63  kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
64  }
65  else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
66  {
68  kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
69  }
70 
71  return 0;
72 }
73 
74 
76 {
77  FRAME_T playerType = aEvent.Parameter<FRAME_T>();
78  KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
79 
80  // Needed on Windows, other platforms do not use it, but it creates no issue
81  if( editor->IsIconized() )
82  editor->Iconize( false );
83 
84  editor->Raise();
85 
86  // Raising the window does not set the focus on Linux. This should work on
87  // any platform.
88  if( wxWindow::FindFocus() != editor )
89  editor->SetFocus();
90 
91  return 0;
92 }
93 
94 
96 {
97  const SEARCH_STACK& search = m_frame->sys_search();
98  wxString helpFile;
99  wxString msg;
100 
101  /* We have to get document for beginners,
102  * or the full specific doc
103  * if event id is wxID_INDEX, we want the document for beginners.
104  * else the specific doc file (its name is in Kiface().GetHelpFileName())
105  * The document for beginners is the same for all KiCad utilities
106  */
107  if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
108  {
109  // List of possible names for Getting Started in KiCad
110  const wxChar* names[2] = {
111  wxT( "getting_started_in_kicad" ),
112  wxT( "Getting_Started_in_KiCad" )
113  };
114 
115  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
116  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
117  for( auto& name : names )
118  {
119  helpFile = SearchHelpFileFullPath( search, name );
120 
121  if( !helpFile.IsEmpty() )
122  break;
123  }
124 
125  if( !helpFile )
126  {
127  msg = wxString::Format( _( "Html or pdf help file \n%s\nor\n%s could not be found." ),
128  names[0], names[1] );
129  wxMessageBox( msg );
130  return -1;
131  }
132  }
133  else
134  {
135  wxString base_name = m_frame->help_name();
136 
137  helpFile = SearchHelpFileFullPath( search, base_name );
138 
139  if( !helpFile )
140  {
141  msg = wxString::Format( _( "Help file \"%s\" could not be found." ), base_name );
142  wxMessageBox( msg );
143  return -1;
144  }
145  }
146 
147  GetAssociatedDocument( m_frame, helpFile );
148  return 0;
149 }
150 
151 
153 {
155  return 0;
156 }
157 
158 
160 {
161  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
162  {
163  wxString msg;
164  msg.Printf( _( "Could not launch the default browser.\n"
165  "For information on how to help the KiCad project, visit %s" ),
167  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
168  }
169  return 0;
170 }
171 
172 
174 {
182 
184  Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
187 }
188 
189 
static TOOL_ACTION listHotKeys
Definition: actions.h:166
#define URL_GET_INVOLVED
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
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: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 showSymbolLibTable
Definition: actions.h:162
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:87
Class 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:63
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:163
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:321
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:150
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427
int ConfigurePaths(const TOOL_EVENT &aEvent)
int GetInvolved(const TOOL_EVENT &aEvent)
Class TOOL_EVENT.
Definition: tool_event.h:168
int ListHotKeys(const TOOL_EVENT &aEvent)
pcbnew DSO
Definition: kiway.h:267
VTBL_ENTRY KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
Definition: kiway.cpp:169
#define _(s)
eeschema DSO
Definition: kiway.h:266
static TOOL_ACTION showSymbolEditor
Definition: actions.h:149
const char * name
Definition: DXF_plotter.cpp:61
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
int ShowPlayer(const TOOL_EVENT &aEvent)
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
static TOOL_ACTION help
Definition: actions.h:165
virtual wxString help_name()
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
return & kiface
Definition: pcbnew.cpp:186
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:148
BASE_SCREEN class implementation.
static TOOL_ACTION getInvolved
Definition: actions.h:167
static TOOL_ACTION configurePaths
Definition: actions.h:161
static TOOL_ACTION gettingStarted
Definition: actions.h:164
static TOOL_ACTION showFootprintEditor
Definition: actions.h:151