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.

236 lines
7.4 KiB

19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file pcbnew.cpp
  27. * @brief Pcbnew main program.
  28. */
  29. #ifdef KICAD_SCRIPTING
  30. #include <python_scripting.h>
  31. #include <pcbnew_scripting_helpers.h>
  32. #endif
  33. #include <fctsys.h>
  34. #include <appl_wxstruct.h>
  35. #include <confirm.h>
  36. #include <macros.h>
  37. #include <class_drawpanel.h>
  38. #include <wxPcbStruct.h>
  39. #include <eda_dde.h>
  40. #include <pcbcommon.h>
  41. #include <colors_selection.h>
  42. #include <gr_basic.h>
  43. #include <wx/file.h>
  44. #include <wx/snglinst.h>
  45. #include <pcbnew.h>
  46. #include <protos.h>
  47. #include <hotkeys.h>
  48. #include <wildcards_and_files_ext.h>
  49. #include <class_board.h>
  50. // Colors for layers and items
  51. COLORS_DESIGN_SETTINGS g_ColorsSettings;
  52. bool Drc_On = true;
  53. bool g_AutoDeleteOldTrack = true;
  54. bool g_Show_Module_Ratsnest;
  55. bool g_Raccord_45_Auto = true;
  56. bool g_Alternate_Track_Posture = false;
  57. bool g_Track_45_Only_Allowed = true; // True to allow horiz, vert. and 45deg only tracks
  58. bool Segments_45_Only; // True to allow horiz, vert. and 45deg only graphic segments
  59. bool g_TwoSegmentTrackBuild = true;
  60. int Route_Layer_TOP;
  61. int Route_Layer_BOTTOM;
  62. int g_MaxLinksShowed;
  63. int g_MagneticPadOption = capture_cursor_in_track_tool;
  64. int g_MagneticTrackOption = capture_cursor_in_track_tool;
  65. wxPoint g_Offset_Module; /* Distance to offset module trace when moving. */
  66. /* Name of the document footprint list
  67. * usually located in share/modules/footprints_doc
  68. * this is of the responsibility to users to create this file
  69. * if they want to have a list of footprints
  70. */
  71. wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" );
  72. wxArrayString g_LibraryNames;
  73. // wxWindow* DoPythonStuff(wxWindow* parent); // declaration
  74. IMPLEMENT_APP( EDA_APP )
  75. /* MacOSX: Needed for file association
  76. * http://wiki.wxwidgets.org/WxMac-specific_topics
  77. */
  78. void EDA_APP::MacOpenFile( const wxString& fileName )
  79. {
  80. wxFileName filename = fileName;
  81. PCB_EDIT_FRAME* frame = ( (PCB_EDIT_FRAME*) GetTopWindow() );
  82. if( !filename.FileExists() )
  83. return;
  84. frame->LoadOnePcbFile( fileName, false );
  85. }
  86. bool EDA_APP::OnInit()
  87. {
  88. wxFileName fn;
  89. PCB_EDIT_FRAME* frame = NULL;
  90. #ifdef KICAD_SCRIPTING
  91. if ( !pcbnewInitPythonScripting() )
  92. {
  93. return false;
  94. }
  95. #endif
  96. InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T );
  97. if( m_Checker && m_Checker->IsAnotherRunning() )
  98. {
  99. if( !IsOK( NULL, _( "Pcbnew is already running, Continue?" ) ) )
  100. return false;
  101. }
  102. // read current setup and reopen last directory if no filename to open in command line
  103. bool reopenLastUsedDirectory = argc == 1;
  104. GetSettings( reopenLastUsedDirectory );
  105. if( argc > 1 )
  106. {
  107. fn = argv[1];
  108. if( fn.GetExt() != PcbFileExtension )
  109. {
  110. wxLogDebug( wxT( "Pcbnew file <%s> has the wrong extension. \
  111. Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
  112. fn.SetExt( PcbFileExtension );
  113. }
  114. if( fn.IsOk() && fn.DirExists() )
  115. wxSetWorkingDirectory( fn.GetPath() );
  116. }
  117. g_DrawBgColor = BLACK;
  118. /* Must be called before creating the main frame in order to
  119. * display the real hotkeys in menus or tool tips */
  120. ReadHotkeyConfig( wxT( "PcbFrame" ), g_Board_Editor_Hokeys_Descr );
  121. frame = new PCB_EDIT_FRAME( NULL, wxT( "Pcbnew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
  122. #ifdef KICAD_SCRIPTING
  123. ScriptingSetPcbEditFrame(frame); /* give the scripting helpers access to our frame */
  124. #endif
  125. frame->UpdateTitle();
  126. SetTopWindow( frame );
  127. frame->Show( true );
  128. if( CreateServer( frame, KICAD_PCB_PORT_SERVICE_NUMBER ) )
  129. {
  130. SetupServerFunction( RemoteCommand );
  131. }
  132. frame->Zoom_Automatique( true );
  133. // Load config and default values before loading a board file
  134. // Some will be overwritten after loading the board file
  135. frame->LoadProjectSettings( fn.GetFullPath() );
  136. /* Load file specified in the command line. */
  137. if( fn.IsOk() )
  138. {
  139. /* Note the first time Pcbnew is called after creating a new project
  140. * the board file may not exist so we load settings only.
  141. */
  142. if( fn.FileExists() )
  143. {
  144. frame->LoadOnePcbFile( fn.GetFullPath() );
  145. }
  146. else
  147. { // File does not exists: prepare an empty board
  148. wxSetWorkingDirectory( fn.GetPath() );
  149. frame->GetBoard()->SetFileName( fn.GetFullPath( wxPATH_UNIX ) );
  150. frame->UpdateTitle();
  151. frame->UpdateFileHistory( frame->GetBoard()->GetFileName() );
  152. frame->OnModify(); // Ready to save the new empty board
  153. wxString msg;
  154. msg.Printf( _( "File <%s> does not exist.\nThis is normal for a new project" ),
  155. GetChars( frame->GetBoard()->GetFileName() ) );
  156. wxMessageBox( msg );
  157. }
  158. }
  159. else
  160. // No file to open: initialize a new empty board
  161. // using default values for design settings:
  162. frame->Clear_Pcb( false );
  163. // update the layer names in the listbox
  164. frame->ReCreateLayerBox( NULL );
  165. /* For an obscure reason the focus is lost after loading a board file
  166. * when starting (i.e. only at this point)
  167. * (seems due to the recreation of the layer manager after loading the file)
  168. * give focus to main window and Drawpanel
  169. * must be done for these 2 windows (for an obscure reason ...)
  170. * Linux specific
  171. * This is more a workaround than a fix.
  172. */
  173. frame->SetFocus();
  174. frame->GetCanvas()->SetFocus();
  175. return true;
  176. }
  177. #if 0
  178. // for some reason KiCad classes do not implement OnExit
  179. // if I add it in the declaration, I need to fix it in every application
  180. // so for now make a note TODO TODO
  181. // we need to clean up python when the application exits
  182. int EDA_APP::OnExit() {
  183. // Restore the thread state and tell Python to cleanup after itself.
  184. // wxPython will do its own cleanup as part of that process. This is done
  185. // in OnExit instead of ~MyApp because OnExit is only called if OnInit is
  186. // successful.
  187. #if KICAD_SCRIPTING_WXPYTHON
  188. pcbnewFinishPythonScripting();
  189. #endif
  190. return 0;
  191. }
  192. #endif