You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
8.9 KiB

  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. #include <bitmaps.h>
  25. #include <build_version.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>
  32. #include <gal/graphics_abstraction_layer.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 <kicad_curl/kicad_curl_easy.h>
  39. #include <dialog_configure_paths.h>
  40. #include <eda_doc.h>
  41. #define URL_GET_INVOLVED "http://kicad-pcb.org/contribute/"
  42. /// URL to launch a new issue with pre-populated description
  43. wxString COMMON_CONTROL::m_bugReportUrl =
  44. "https://gitlab.com/kicad/code/kicad/issues/new?issue[description]=%s";
  45. /// Issue template to use for reporting bugs (this should not be translated)
  46. wxString COMMON_CONTROL::m_bugReportTemplate =
  47. "<!-- Before Creating a New Issue:\n"
  48. "* Search the issue tracker to verify the issue has not already been reported.\n"
  49. "* Only report one problem per issue. -->\n"
  50. "\n"
  51. "# Description\n"
  52. "<!-- What is the current behavior and what is the expected behavior? -->\n"
  53. "<!-- Please attach screenshots if they will help explain the problem. -->\n"
  54. "\n"
  55. "# Steps to reproduce\n"
  56. "<!-- Please include a screen recording if it will help explain how to reproduce. -->\n"
  57. "<!-- If this issue is specific to a project, please attach it. -->\n"
  58. "1.\n"
  59. "2.\n"
  60. "# KiCad Version\n"
  61. "\n"
  62. "```\n"
  63. "%s\n"
  64. "```";
  65. void COMMON_CONTROL::Reset( RESET_REASON aReason )
  66. {
  67. m_frame = getEditFrame<EDA_BASE_FRAME>();
  68. }
  69. int COMMON_CONTROL::ConfigurePaths( const TOOL_EVENT& aEvent )
  70. {
  71. // If _pcbnew.kiface is running have it put up the dialog so the 3D paths can also
  72. // be edited
  73. KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false );
  74. if( pcbnew )
  75. {
  76. try
  77. {
  78. pcbnew->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
  79. }
  80. catch( ... )
  81. {
  82. // Do nothing here.
  83. // A error message is displayed after trying to load _pcbnew.kiface.
  84. }
  85. }
  86. else
  87. {
  88. DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr );
  89. if( dlg.ShowModal() == wxID_OK )
  90. m_frame->Kiway().CommonSettingsChanged( true, false );
  91. }
  92. return 0;
  93. }
  94. int COMMON_CONTROL::ShowLibraryTable( const TOOL_EVENT& aEvent )
  95. {
  96. if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
  97. {
  98. try // Sch frame was not available, try to start it
  99. {
  100. KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH );
  101. kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
  102. }
  103. catch( ... )
  104. {
  105. // _eeschema.kiface is not available: it contains the library table dialog.
  106. // Do nothing here.
  107. // A error message is displayed after trying to load _eeschema.kiface.
  108. }
  109. }
  110. else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
  111. {
  112. try // Pcb frame was not available, try to start it
  113. {
  114. KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB );
  115. kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
  116. }
  117. catch( ... )
  118. {
  119. // _pcbnew.kiface is not available: it contains the library table dialog.
  120. // Do nothing here.
  121. // A error message is displayed after trying to load _pcbnew.kiface.
  122. }
  123. }
  124. return 0;
  125. }
  126. int COMMON_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
  127. {
  128. FRAME_T playerType = aEvent.Parameter<FRAME_T>();
  129. KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true );
  130. // Needed on Windows, other platforms do not use it, but it creates no issue
  131. if( editor->IsIconized() )
  132. editor->Iconize( false );
  133. editor->Raise();
  134. // Raising the window does not set the focus on Linux. This should work on
  135. // any platform.
  136. if( wxWindow::FindFocus() != editor )
  137. editor->SetFocus();
  138. return 0;
  139. }
  140. int COMMON_CONTROL::ShowHelp( const TOOL_EVENT& aEvent )
  141. {
  142. const SEARCH_STACK& search = m_frame->sys_search();
  143. wxString helpFile;
  144. wxString msg;
  145. /* We have to get document for beginners,
  146. * or the full specific doc
  147. * if event id is wxID_INDEX, we want the document for beginners.
  148. * else the specific doc file (its name is in Kiface().GetHelpFileName())
  149. * The document for beginners is the same for all KiCad utilities
  150. */
  151. if( aEvent.IsAction( &ACTIONS::gettingStarted ) )
  152. {
  153. // List of possible names for Getting Started in KiCad
  154. const wxChar* names[2] = {
  155. wxT( "getting_started_in_kicad" ),
  156. wxT( "Getting_Started_in_KiCad" )
  157. };
  158. // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
  159. // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
  160. for( auto& name : names )
  161. {
  162. helpFile = SearchHelpFileFullPath( search, name );
  163. if( !helpFile.IsEmpty() )
  164. break;
  165. }
  166. if( !helpFile )
  167. {
  168. msg = wxString::Format( _( "Html or pdf help file \n%s\nor\n%s could not be found." ),
  169. names[0], names[1] );
  170. wxMessageBox( msg );
  171. return -1;
  172. }
  173. }
  174. else
  175. {
  176. wxString base_name = m_frame->help_name();
  177. helpFile = SearchHelpFileFullPath( search, base_name );
  178. if( !helpFile )
  179. {
  180. msg = wxString::Format( _( "Help file \"%s\" could not be found." ), base_name );
  181. wxMessageBox( msg );
  182. return -1;
  183. }
  184. }
  185. GetAssociatedDocument( m_frame, helpFile, &m_frame->Prj() );
  186. return 0;
  187. }
  188. int COMMON_CONTROL::ListHotKeys( const TOOL_EVENT& aEvent )
  189. {
  190. DisplayHotkeyList( m_frame, m_toolMgr );
  191. return 0;
  192. }
  193. int COMMON_CONTROL::GetInvolved( const TOOL_EVENT& aEvent )
  194. {
  195. if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
  196. {
  197. wxString msg;
  198. msg.Printf( _( "Could not launch the default browser.\n"
  199. "For information on how to help the KiCad project, visit %s" ),
  200. URL_GET_INVOLVED );
  201. wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, m_frame );
  202. }
  203. return 0;
  204. }
  205. int COMMON_CONTROL::ReportBug( const TOOL_EVENT& aEvent )
  206. {
  207. wxString version = GetVersionInfoData( m_frame->GetAboutTitle(), false, true );
  208. wxString message;
  209. message.Printf( m_bugReportTemplate, version );
  210. KICAD_CURL_EASY kcurl;
  211. wxString url_string;
  212. url_string.Printf( m_bugReportUrl, kcurl.Escape( message.ToStdString() ) );
  213. wxLaunchDefaultBrowser( url_string );
  214. return 0;
  215. }
  216. void COMMON_CONTROL::setTransitions()
  217. {
  218. Go( &COMMON_CONTROL::ConfigurePaths, ACTIONS::configurePaths.MakeEvent() );
  219. Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showSymbolLibTable.MakeEvent() );
  220. Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showFootprintLibTable.MakeEvent() );
  221. Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showSymbolBrowser.MakeEvent() );
  222. Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showSymbolEditor.MakeEvent() );
  223. Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showFootprintBrowser.MakeEvent() );
  224. Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showFootprintEditor.MakeEvent() );
  225. Go( &COMMON_CONTROL::ShowHelp, ACTIONS::gettingStarted.MakeEvent() );
  226. Go( &COMMON_CONTROL::ShowHelp, ACTIONS::help.MakeEvent() );
  227. Go( &COMMON_CONTROL::ListHotKeys, ACTIONS::listHotKeys.MakeEvent() );
  228. Go( &COMMON_CONTROL::GetInvolved, ACTIONS::getInvolved.MakeEvent() );
  229. Go( &COMMON_CONTROL::ReportBug, ACTIONS::reportBug.MakeEvent() );
  230. }