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.

346 lines
9.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2015 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. #include <fctsys.h>
  30. #include <pgm_base.h>
  31. #include <kiface_i.h>
  32. #include <confirm.h>
  33. #include <macros.h>
  34. #include <class_drawpanel.h>
  35. #include <wxPcbStruct.h>
  36. #include <eda_dde.h>
  37. #include <wx/stdpaths.h>
  38. #include <wx/file.h>
  39. #include <wx/snglinst.h>
  40. #include <wx/dir.h>
  41. #include <gestfich.h>
  42. #include <pcbnew.h>
  43. #include <hotkeys.h>
  44. #include <wildcards_and_files_ext.h>
  45. #include <class_board.h>
  46. #include <fp_lib_table.h>
  47. #include <module_editor_frame.h>
  48. #include <modview_frame.h>
  49. #include <footprint_wizard_frame.h>
  50. #include <wxPcbStruct.h>
  51. #include <class_board.h>
  52. #include <class_track.h>
  53. #include <class_drawsegment.h>
  54. #include <class_pcb_text.h>
  55. #include <class_pcb_target.h>
  56. #include <class_module.h>
  57. #include <class_dimension.h>
  58. #include <class_zone.h>
  59. #include <class_edge_mod.h>
  60. #include <tools/pcb_actions.h>
  61. #include "pcb_tool.h"
  62. #include <dialog_find.h>
  63. #include <dialog_block_options.h>
  64. bool g_Drc_On = true;
  65. bool g_AutoDeleteOldTrack = true;
  66. bool g_Raccord_45_Auto = true;
  67. bool g_Alternate_Track_Posture = false;
  68. bool g_Track_45_Only_Allowed = true; // True to allow horiz, vert. and 45deg only tracks
  69. bool g_Segments_45_Only; // True to allow horiz, vert. and 45deg only graphic segments
  70. bool g_TwoSegmentTrackBuild = true;
  71. PCB_LAYER_ID g_Route_Layer_TOP;
  72. PCB_LAYER_ID g_Route_Layer_BOTTOM;
  73. int g_MagneticPadOption;
  74. int g_MagneticTrackOption;
  75. wxPoint g_Offset_Module; // module offset used when moving a footprint
  76. /* Name of the document footprint list
  77. * usually located in share/modules/footprints_doc
  78. * this is of the responsibility to users to create this file
  79. * if they want to have a list of footprints
  80. */
  81. wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" );
  82. /*
  83. * Used in track creation, a list of track segments currently being created,
  84. * with the newest track at the end of the list, sorted by new-ness. e.g. use
  85. * TRACK->Back() to get the next older track, TRACK->Next() to get the next
  86. * newer track.
  87. */
  88. DLIST<TRACK> g_CurrentTrackList;
  89. bool g_DumpZonesWhenFilling = false;
  90. static struct IFACE : public KIFACE_I
  91. {
  92. // Of course all are overloads, implementations of the KIFACE.
  93. IFACE( const char* aName, KIWAY::FACE_T aType ) :
  94. KIFACE_I( aName, aType )
  95. {}
  96. bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
  97. {
  98. return true;
  99. }
  100. void OnKifaceEnd() override {}
  101. wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
  102. {
  103. assert( false );
  104. return nullptr;
  105. }
  106. /**
  107. * Function IfaceOrAddress
  108. * return a pointer to the requested object. The safest way to use this
  109. * is to retrieve a pointer to a static instance of an interface, similar to
  110. * how the KIFACE interface is exported. But if you know what you are doing
  111. * use it to retrieve anything you want.
  112. *
  113. * @param aDataId identifies which object you want the address of.
  114. *
  115. * @return void* - and must be cast into the know type.
  116. */
  117. void* IfaceOrAddress( int aDataId ) override
  118. {
  119. return NULL;
  120. }
  121. }
  122. kiface( "pcb_test_frame", KIWAY::FACE_PCB );
  123. static struct PGM_TEST_FRAME : public PGM_BASE
  124. {
  125. bool OnPgmInit();
  126. void OnPgmExit()
  127. {
  128. Kiway.OnKiwayEnd();
  129. // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
  130. // earlier than wxApp and earlier than static destruction would.
  131. PGM_BASE::Destroy();
  132. }
  133. void MacOpenFile( const wxString& aFileName ) override
  134. {
  135. wxFileName filename( aFileName );
  136. if( filename.FileExists() )
  137. {
  138. #if 0
  139. // this pulls in EDA_DRAW_FRAME type info, which we don't want in
  140. // the single_top link image.
  141. KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
  142. #else
  143. KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
  144. #endif
  145. if( frame )
  146. frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
  147. }
  148. }
  149. }
  150. program;
  151. PGM_BASE& Pgm()
  152. {
  153. return program;
  154. }
  155. KIFACE_I& Kiface()
  156. {
  157. return kiface;
  158. }
  159. FP_LIB_TABLE GFootprintTable;
  160. void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
  161. {
  162. }
  163. // Initialize static member variables
  164. wxString DIALOG_FIND::prevSearchString;
  165. bool DIALOG_FIND::warpMouse = true;
  166. DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent )
  167. {
  168. // these members are initialized to avoid warnings about non initialized vars
  169. parent = aParent;
  170. itemCount = markerCount = 0;
  171. foundItem = nullptr;
  172. }
  173. void DIALOG_FIND::OnInitDialog( wxInitDialogEvent& event )
  174. {
  175. }
  176. void DIALOG_FIND::EnableWarp( bool aEnabled )
  177. {
  178. }
  179. void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
  180. {
  181. }
  182. void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
  183. {
  184. }
  185. void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
  186. {
  187. }
  188. void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
  189. {
  190. }
  191. DIALOG_FIND_BASE::DIALOG_FIND_BASE( wxWindow* parent,
  192. wxWindowID id,
  193. const wxString& title,
  194. const wxPoint& pos,
  195. const wxSize& size,
  196. long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
  197. {
  198. // these members are initialized only to avoid warnings about non initialized vars
  199. m_staticText1 = nullptr;
  200. m_SearchTextCtrl = nullptr;
  201. m_NoMouseWarpCheckBox = nullptr;
  202. m_button1 = nullptr;
  203. m_button2 = nullptr;
  204. m_button3 = nullptr;
  205. }
  206. DIALOG_FIND_BASE::~DIALOG_FIND_BASE()
  207. {
  208. }
  209. MODULE* PCB_BASE_FRAME::GetFootprintFromBoardByReference()
  210. {
  211. return nullptr;
  212. }
  213. TOOL_ACTION PCB_ACTIONS::selectionModified( "pcbnew.InteractiveEdit.ModifiedSelection",
  214. AS_GLOBAL, 0,
  215. "", "", nullptr, AF_NOTIFY );
  216. TOOL_ACTION PCB_ACTIONS::flip( "pcbnew.InteractiveEdit.flip",
  217. AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_FLIP_ITEM ),
  218. _( "Flip" ), _( "Flips selected item(s)" ), nullptr );
  219. TOOL_ACTION PCB_ACTIONS::properties( "pcbnew.InteractiveEdit.properties",
  220. AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_ITEM ),
  221. _( "Properties" ), _( "Displays item properties dialog" ), nullptr );
  222. TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet",
  223. AS_GLOBAL, 0,
  224. "", "" );
  225. DIALOG_BLOCK_OPTIONS_BASE::DIALOG_BLOCK_OPTIONS_BASE( wxWindow* parent,
  226. wxWindowID id,
  227. const wxString& title,
  228. const wxPoint& pos,
  229. const wxSize& size,
  230. long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
  231. {
  232. // these members are initialized only to avoid warnings about non initialized vars
  233. m_Include_Modules = nullptr;
  234. m_Include_PcbTextes = nullptr;
  235. m_IncludeLockedModules = nullptr;
  236. m_Include_Draw_Items = nullptr;
  237. m_Include_Tracks = nullptr;
  238. m_Include_Edges_Items = nullptr;
  239. m_Include_Zones = nullptr;
  240. m_DrawBlockItems = nullptr;
  241. m_staticline1 = nullptr;
  242. m_checkBoxIncludeInvisible = nullptr;
  243. m_sdbSizer1 = nullptr;
  244. m_sdbSizer1OK = nullptr;
  245. m_sdbSizer1Cancel = nullptr;
  246. }
  247. DIALOG_BLOCK_OPTIONS_BASE::~DIALOG_BLOCK_OPTIONS_BASE()
  248. {
  249. }
  250. TOOL_ACTION PCB_ACTIONS::rotateCw( "pcbnew.InteractiveEdit.rotateCw",
  251. AS_GLOBAL, MD_SHIFT + 'R',
  252. _( "Rotate Clockwise" ), _( "Rotates selected item(s) clockwise" ),
  253. nullptr, AF_NONE, (void*) -1 );
  254. TOOL_ACTION PCB_ACTIONS::rotateCcw( "pcbnew.InteractiveEdit.rotateCcw",
  255. AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ROTATE_ITEM ),
  256. _( "Rotate Counterclockwise" ), _( "Rotates selected item(s) counterclockwise" ),
  257. nullptr, AF_NONE, (void*) 1 );
  258. DIALOG_BLOCK_OPTIONS::DIALOG_BLOCK_OPTIONS( PCB_BASE_FRAME* aParent,
  259. OPTIONS& aOptions, bool aShowLegacyOptions,
  260. const wxString& aTitle ) :
  261. DIALOG_BLOCK_OPTIONS_BASE( aParent, -1, aTitle ),
  262. m_options( aOptions )
  263. {
  264. }
  265. void DIALOG_BLOCK_OPTIONS::checkBoxClicked( wxCommandEvent& aEvent )
  266. {
  267. }
  268. void DIALOG_BLOCK_OPTIONS::ExecuteCommand( wxCommandEvent& event )
  269. {
  270. }
  271. void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
  272. {
  273. }