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.

219 lines
6.2 KiB

16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2011 KiCad Developers, see change_log.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 eeschema.cpp
  27. * @brief the main file
  28. */
  29. #include <fctsys.h>
  30. #include <appl_wxstruct.h>
  31. #include <class_drawpanel.h>
  32. #include <confirm.h>
  33. #include <gestfich.h>
  34. #include <eda_dde.h>
  35. #include <wxEeschemaStruct.h>
  36. #include <eda_text.h>
  37. #include <general.h>
  38. #include <class_libentry.h>
  39. //#include <sch_junction.h>
  40. #include <hotkeys.h>
  41. #include <dialogs/dialog_color_config.h>
  42. #include <transform.h>
  43. #include <wildcards_and_files_ext.h>
  44. #include <wx/snglinst.h>
  45. #if defined( USE_KIWAY_DLLS )
  46. #include <kiway.h>
  47. #include <import_export.h>
  48. static struct SCH_FACE : public KIFACE
  49. {
  50. wxWindow* CreateWindow( int aClassId, KIWAY* aKIWAY, int aCtlBits = 0 )
  51. {
  52. switch( aClassId )
  53. {
  54. default:
  55. return new SCH_EDIT_FRAME( NULL, wxT( "Eeschema" ),
  56. wxPoint( 0, 0 ), wxSize( 600, 400 ) );
  57. }
  58. }
  59. /**
  60. * Function IfaceOrAddress
  61. * return a pointer to the requested object. The safest way to use this
  62. * is to retrieve a pointer to a static instance of an interface, similar to
  63. * how the KIFACE interface is exported. But if you know what you are doing
  64. * use it to retrieve anything you want.
  65. *
  66. * @param aDataId identifies which object you want the address of.
  67. *
  68. * @return void* - and must be cast into the know type.
  69. */
  70. void* IfaceOrAddress( int aDataId )
  71. {
  72. return NULL;
  73. }
  74. } kiface;
  75. static EDA_APP* process;
  76. // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
  77. // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
  78. MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, wxApp* aProcess )
  79. {
  80. process = (EDA_APP*) aProcess;
  81. return &kiface;
  82. }
  83. EDA_APP& wxGetApp()
  84. {
  85. wxASSERT( process ); // KIFACE_GETTER has already been called.
  86. return *process;
  87. }
  88. #else
  89. // Create a new application object: this macro will allow wxWindows to create
  90. // the application object during program execution (it's better than using a
  91. // static object for many reasons) and also declares the accessor function
  92. // wxGetApp() which will return the reference of the right type (i.e. MyApp and
  93. // not wxApp)
  94. IMPLEMENT_APP( EDA_APP )
  95. #endif
  96. // Global variables
  97. wxSize g_RepeatStep;
  98. int g_RepeatDeltaLabel;
  99. int g_DefaultBusWidth;
  100. SCH_SHEET* g_RootSheet = NULL;
  101. TRANSFORM DefaultTransform = TRANSFORM( 1, 0, 0, -1 );
  102. /************************************/
  103. /* Called to initialize the program */
  104. /************************************/
  105. /* MacOSX: Needed for file association
  106. * http://wiki.wxwidgets.org/WxMac-specific_topics
  107. */
  108. void EDA_APP::MacOpenFile( const wxString& aFileName )
  109. {
  110. wxFileName filename = aFileName;
  111. SCH_EDIT_FRAME* frame = ((SCH_EDIT_FRAME*) GetTopWindow());
  112. if( !frame )
  113. return;
  114. if( !filename.FileExists() )
  115. return;
  116. frame->LoadOneEEProject( aFileName, false );
  117. }
  118. bool EDA_APP::OnInit()
  119. {
  120. wxFileName filename;
  121. SCH_EDIT_FRAME* frame = NULL;
  122. bool fileReady = false;
  123. InitEDA_Appl( wxT( "Eeschema" ), APP_EESCHEMA_T );
  124. if( argc > 1 )
  125. filename = argv[1];
  126. if( filename.IsOk() )
  127. {
  128. if( filename.GetExt() != SchematicFileExtension )
  129. filename.SetExt( SchematicFileExtension );
  130. if( !wxGetApp().LockFile( filename.GetFullPath() ) )
  131. {
  132. DisplayError( NULL, _( "This file is already open." ) );
  133. return false;
  134. }
  135. fileReady = true;
  136. }
  137. if( m_Checker && m_Checker->IsAnotherRunning() )
  138. {
  139. if( !IsOK( NULL, _( "Eeschema is already running, Continue?" ) ) )
  140. return false;
  141. }
  142. // Give a default colour for all layers
  143. // (actual color will be initialized by config)
  144. for( int ii = 0; ii < NB_SCH_LAYERS; ii++ )
  145. SetLayerColor( DARKGRAY, ii );
  146. // read current setup and reopen last directory if no filename to open in
  147. // command line
  148. bool reopenLastUsedDirectory = argc == 1;
  149. GetSettings( reopenLastUsedDirectory );
  150. /* Must be called before creating the main frame in order to
  151. * display the real hotkeys in menus or tool tips */
  152. ReadHotkeyConfig( wxT("SchematicFrame"), s_Eeschema_Hokeys_Descr );
  153. // Create main frame (schematic frame) :
  154. frame = new SCH_EDIT_FRAME( NULL, wxT( "Eeschema" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
  155. SetTopWindow( frame );
  156. frame->Show( true );
  157. CreateServer( frame, KICAD_SCH_PORT_SERVICE_NUMBER );
  158. frame->Zoom_Automatique( true );
  159. // Load file specified in the command line:
  160. if( fileReady )
  161. {
  162. if( !filename.GetPath().IsEmpty() )
  163. // wxSetWorkingDirectory does not like empty paths
  164. wxSetWorkingDirectory( filename.GetPath() );
  165. if( frame->LoadOneEEProject( filename.GetFullPath(), false ) )
  166. frame->GetCanvas()->Refresh( true );
  167. }
  168. else
  169. {
  170. // Read a default config file if no file to load.
  171. frame->LoadProjectFile( wxEmptyString, true );
  172. frame->GetCanvas()->Refresh( true );
  173. }
  174. return true;
  175. }