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.

399 lines
20 KiB

17 years ago
18 years ago
18 years ago
18 years ago
15 years ago
18 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. /****************************************/
  2. /** pcbnew_config.cpp : configuration **/
  3. /****************************************/
  4. #include "fctsys.h"
  5. #include "appl_wxstruct.h"
  6. #include "common.h"
  7. #include "class_drawpanel.h"
  8. #include "confirm.h"
  9. #include "gestfich.h"
  10. #include "pcbnew.h"
  11. #include "wxPcbStruct.h"
  12. #include "class_board_design_settings.h"
  13. #include "pcbplot.h"
  14. #include "plot_common.h"
  15. #include "worksheet.h"
  16. #include "pcbnew_id.h"
  17. #include "hotkeys.h"
  18. #include "protos.h"
  19. #include "dialog_mask_clearance.h"
  20. #include "dialog_general_options.h"
  21. #include "pcbnew_config.h"
  22. #include "dialog_hotkeys_editor.h"
  23. #define HOTKEY_FILENAME wxT( "pcbnew" )
  24. void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
  25. {
  26. int id = event.GetId();
  27. wxFileName fn;
  28. switch( id )
  29. {
  30. case ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG:
  31. m_show_layer_manager_tools = ! m_show_layer_manager_tools;
  32. m_auimgr.GetPane( wxT( "m_LayersManagerToolBar" ) ).Show( m_show_layer_manager_tools );
  33. m_auimgr.Update();
  34. GetMenuBar()->SetLabel( ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
  35. m_show_layer_manager_tools ?
  36. _("Hide &Layers Manager" ) : _("Show &Layers Manager" ));
  37. break;
  38. case ID_PCB_LAYERS_SETUP:
  39. InstallDialogLayerSetup();
  40. break;
  41. case ID_CONFIG_REQ:
  42. InstallConfigFrame();
  43. break;
  44. case ID_PCB_MASK_CLEARANCE:
  45. {
  46. DIALOG_PADS_MASK_CLEARANCE dlg( this );
  47. dlg.ShowModal();
  48. }
  49. break;
  50. case ID_OPTIONS_SETUP:
  51. {
  52. Dialog_GeneralOptions dlg( this );
  53. dlg.ShowModal();
  54. }
  55. break;
  56. case ID_PCB_PAD_SETUP:
  57. InstallPadOptionsFrame( NULL );
  58. break;
  59. case ID_CONFIG_SAVE:
  60. SaveProjectSettings();
  61. break;
  62. case ID_CONFIG_READ:
  63. {
  64. fn = GetScreen()->GetFileName();
  65. fn.SetExt( ProjectFileExtension );
  66. wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(),
  67. fn.GetFullName(), ProjectFileWildcard,
  68. wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
  69. if( dlg.ShowModal() == wxID_CANCEL )
  70. break;
  71. if( !wxFileExists( dlg.GetPath() ) )
  72. {
  73. wxString msg;
  74. msg.Printf( _( "File %s not found" ), GetChars( dlg.GetPath() ) );
  75. DisplayError( this, msg );
  76. break;
  77. }
  78. LoadProjectSettings( dlg.GetPath() );
  79. break;
  80. }
  81. /* Hotkey IDs */
  82. case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG:
  83. ExportHotkeyConfigToFile( g_Board_Editor_Hokeys_Descr );
  84. break;
  85. case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG:
  86. ImportHotkeyConfigFromFile( g_Board_Editor_Hokeys_Descr );
  87. break;
  88. case ID_PREFERENCES_HOTKEY_SHOW_EDITOR:
  89. InstallHotkeyFrame( this, g_Board_Editor_Hokeys_Descr );
  90. break;
  91. case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
  92. // Display current hotkey list for eeschema.
  93. DisplayHotkeyList( this, g_Board_Editor_Hokeys_Descr );
  94. break;
  95. default:
  96. DisplayError( this, wxT( "PCB_EDIT_FRAME::Process_Config error" ) );
  97. }
  98. }
  99. /**
  100. * Read the project configuration file settings.
  101. *
  102. * @param aProjectFileName = The project file name to load. If aProjectFileName
  103. * is not found load the default project file kicad.pro
  104. * and initialize setting to their default value.
  105. * @return Always returns true.
  106. */
  107. bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName )
  108. {
  109. wxFileName fn = aProjectFileName;
  110. if( fn.GetExt() != ProjectFileExtension )
  111. fn.SetExt( ProjectFileExtension );
  112. wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer );
  113. /* Initialize default values. */
  114. g_LibName_List.Clear();
  115. wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters(), false );
  116. /* User library path takes precedent over default library search paths. */
  117. wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 );
  118. /* Reset the items visibility flag when loading a new config
  119. * Because it could creates SERIOUS mistakes for the user,
  120. * if board items are not visible after loading a board...
  121. * Grid and ratsnest can be left to their previous state
  122. */
  123. bool showGrid = IsElementVisible( GRID_VISIBLE );
  124. bool showRats = IsElementVisible( RATSNEST_VISIBLE );
  125. SetVisibleAlls();
  126. SetElementVisibility( GRID_VISIBLE, showGrid );
  127. SetElementVisibility( RATSNEST_VISIBLE, showRats );
  128. return true;
  129. }
  130. void PCB_EDIT_FRAME::SaveProjectSettings()
  131. {
  132. wxFileName fn;
  133. fn = GetScreen()->GetFileName();
  134. fn.SetExt( ProjectFileExtension );
  135. wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(), fn.GetFullName(),
  136. ProjectFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR );
  137. if( dlg.ShowModal() == wxID_CANCEL )
  138. return;
  139. wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP, GetProjectFileParameters() );
  140. }
  141. /**
  142. * Return project file parameter list for PCBNew.
  143. *
  144. * Populate the project file parameter array specific to PCBNew if it hasn't
  145. * already been populated and return a reference to the array to the caller.
  146. * Creating the parameter list at run time has the advantage of being able
  147. * to define local variables. The old method of statically building the array
  148. * at compile time requiring global variable definitions by design.
  149. */
  150. PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetProjectFileParameters()
  151. {
  152. if( !m_projectFileParams.empty() )
  153. return m_projectFileParams;
  154. m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ),&g_UserLibDirBuffer,
  155. GROUPLIB ) );
  156. m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ), &g_LibName_List,
  157. GROUPLIB ) );
  158. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "PadDrlX" ), &g_Pad_Master.m_Drill.x,
  159. 320, 0, 0x7FFF ) );
  160. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "PadDimH" ), &g_Pad_Master.m_Size.x,
  161. 550, 0, 0x7FFF ) );
  162. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "PadDimV" ), &g_Pad_Master.m_Size.y,
  163. 550, 0, 0x7FFF ) );
  164. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "BoardThickness" ),
  165. &boardDesignSettings.m_BoardThickness,
  166. 630, 0, 0xFFFF ) );
  167. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "TxtPcbV" ),
  168. &boardDesignSettings.m_PcbTextSize.y,
  169. 600, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE ) );
  170. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "TxtPcbH" ),
  171. &boardDesignSettings.m_PcbTextSize.x,
  172. 600, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE ) );
  173. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "TxtModV" ), &g_ModuleTextSize.y,
  174. 500, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE ) );
  175. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "TxtModH" ), &g_ModuleTextSize.x,
  176. 500, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE ) );
  177. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "TxtModW" ), &g_ModuleTextWidth,
  178. 100, 1, TEXTS_MAX_WIDTH ) );
  179. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "VEgarde" ),
  180. &boardDesignSettings.m_SolderMaskMargin,
  181. 100, 0, 10000 ) );
  182. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "DrawLar" ),
  183. &boardDesignSettings.m_DrawSegmentWidth,
  184. 120, 0, 0xFFFF ) );
  185. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "EdgeLar" ),
  186. &boardDesignSettings.m_EdgeSegmentWidth,
  187. 120, 0, 0xFFFF ) );
  188. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "TxtLar" ),
  189. &boardDesignSettings.m_PcbTextWidth,
  190. 120, 0, 0xFFFF ) );
  191. m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "MSegLar" ), &g_ModuleSegmentWidth,
  192. 120, 0, 0xFFFF ) );
  193. m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LastNetListRead" ),
  194. &m_lastNetListRead ) );
  195. return m_projectFileParams;
  196. }
  197. /*
  198. * Return the PCBNew applications settings list.
  199. *
  200. * This replaces the old statically define list that had the project
  201. * file settings and the application settings mixed together. This
  202. * was confusing and caused some settings to get saved and loaded
  203. * incorrectly. Currently, only the settings that are needed at start
  204. * up by the main window are defined here. There are other locally used
  205. * settings are scattered throughout the PCBNew source code. If you need
  206. * to define a configuration setting that need to be loaded at run time,
  207. * this is the place to define it.
  208. *
  209. * @todo: Define the configuration variables as member variables instead of
  210. * global variables or move them to the object class where they are
  211. * used.
  212. */
  213. PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings()
  214. {
  215. if( !m_configSettings.empty() )
  216. return m_configSettings;
  217. // Units used in dialogs and toolbars
  218. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "Units" ), (int*)&g_UserUnit, MILLIMETRES ) );
  219. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayPolarCoords" ),
  220. &DisplayOpt.DisplayPolarCood, false ) );
  221. // Display options and modes:
  222. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ViaHoleDisplayMode" ),
  223. &DisplayOpt.m_DisplayViaMode,
  224. VIA_SPECIAL_HOLE_SHOW, VIA_HOLE_NOT_SHOW,
  225. OPT_VIA_HOLE_END - 1 ) );
  226. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ShowNetNamesMode" ),
  227. &DisplayOpt.DisplayNetNamesMode, 3, 0, 3 ) );
  228. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayTrackFilled" ),
  229. &DisplayOpt.DisplayPcbTrackFill, true ) );
  230. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "TrackDisplayClearance" ),
  231. &DisplayOpt.ShowTrackClearanceMode,
  232. SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS ) );
  233. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PadFill" ),
  234. &DisplayOpt.DisplayPadFill, true ) );
  235. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "ViaFill" ),
  236. &DisplayOpt.DisplayViaFill, true ) );
  237. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PadAffG" ),
  238. &DisplayOpt.DisplayPadIsol, true ) );
  239. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PadSNum" ),
  240. &DisplayOpt.DisplayPadNum, true ) );
  241. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ModAffC" ),
  242. &DisplayOpt.DisplayModEdge, FILLED, 0, 2 ) );
  243. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ModAffT" ),
  244. &DisplayOpt.DisplayModText, FILLED, 0, 2 ) );
  245. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbAffT" ),
  246. &DisplayOpt.DisplayDrawItems, FILLED, 0, 2 ) );
  247. // Colors:
  248. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay0" ), LOC_COLOR( 0 ),
  249. GREEN ) );
  250. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay1" ), LOC_COLOR( 1 ),
  251. BLUE ) );
  252. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay2" ), LOC_COLOR( 2 ),
  253. LIGHTGRAY ) );
  254. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay3" ), LOC_COLOR( 3 ),
  255. 5 ) );
  256. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay4" ), LOC_COLOR( 4 ),
  257. 4 ) );
  258. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay5" ), LOC_COLOR( 5 ),
  259. 5 ) );
  260. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay6" ), LOC_COLOR( 6 ),
  261. 6 ) );
  262. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay7" ), LOC_COLOR( 7 ),
  263. 5 ) );
  264. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay8" ), LOC_COLOR( 8 ),
  265. 7 ) );
  266. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLay9" ), LOC_COLOR( 9 ),
  267. 1 ) );
  268. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayA" ), LOC_COLOR( 10 ),
  269. 2 ) );
  270. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayB" ), LOC_COLOR( 11 ),
  271. 3 ) );
  272. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayC" ), LOC_COLOR( 12 ),
  273. 12 ) );
  274. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayD" ), LOC_COLOR( 13 ),
  275. 13 ) );
  276. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayE" ), LOC_COLOR( 14 ),
  277. 14 ) );
  278. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayF" ), LOC_COLOR( 15 ),
  279. RED ) );
  280. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayG" ), LOC_COLOR( 16 ),
  281. 1 ) );
  282. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayH" ), LOC_COLOR( 17 ),
  283. 5 ) );
  284. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayI" ), LOC_COLOR( 18 ),
  285. 11 ) );
  286. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayJ" ), LOC_COLOR( 19 ),
  287. 4 ) );
  288. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayK" ), LOC_COLOR( 20 ),
  289. 5 ) );
  290. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayL" ), LOC_COLOR( 21 ),
  291. 3 ) );
  292. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayM" ), LOC_COLOR( 22 ),
  293. 6 ) );
  294. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayN" ), LOC_COLOR( 23 ),
  295. 5 ) );
  296. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayO" ), LOC_COLOR( 24 ),
  297. LIGHTGRAY ) );
  298. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayP" ), LOC_COLOR( 25 ),
  299. 1 ) );
  300. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayQ" ), LOC_COLOR( 26 ),
  301. 2 ) );
  302. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayR" ), LOC_COLOR( 27 ),
  303. 14 ) );
  304. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayS" ), LOC_COLOR( 28 ),
  305. YELLOW ) );
  306. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayT" ), LOC_COLOR( 29 ),
  307. 13 ) );
  308. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayU" ), LOC_COLOR( 30 ),
  309. 14 ) );
  310. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColLayV" ), LOC_COLOR( 31 ),
  311. 7 ) );
  312. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CTxtMoC" ),
  313. ITEM_COLOR( MOD_TEXT_FR_VISIBLE ),
  314. LIGHTGRAY ) );
  315. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CTxtMoS" ),
  316. ITEM_COLOR( MOD_TEXT_BK_VISIBLE ),
  317. BLUE ) );
  318. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CTxtVis" ),
  319. ITEM_COLOR( MOD_TEXT_INVISIBLE ),
  320. DARKGRAY ) );
  321. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CAncreM" ),
  322. ITEM_COLOR( ANCHOR_VISIBLE ), BLUE ) );
  323. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CoPadCu" ),
  324. ITEM_COLOR( PAD_BK_VISIBLE ), GREEN ) );
  325. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CoPadCm" ),
  326. ITEM_COLOR( PAD_FR_VISIBLE ), RED ) );
  327. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CoViaTh" ),
  328. ITEM_COLOR( VIA_THROUGH_VISIBLE ),
  329. LIGHTGRAY ) );
  330. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CoViaBu" ),
  331. ITEM_COLOR( VIA_BBLIND_VISIBLE ),
  332. BROWN ) );
  333. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CoViaMi" ),
  334. ITEM_COLOR( VIA_MICROVIA_VISIBLE ),
  335. CYAN ) );
  336. m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "CoRatsN" ),
  337. ITEM_COLOR( RATSNEST_VISIBLE ),
  338. WHITE ) );
  339. // Miscellaneous:
  340. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "TimeOut" ), &g_TimeOut,
  341. 600, 0, 60000 ) );
  342. m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ), &g_MaxLinksShowed,
  343. 3, 0, 15 ) );
  344. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "ShowMRa" ),
  345. &g_Show_Module_Ratsnest, true ) );
  346. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ),
  347. &g_TwoSegmentTrackBuild, true ) );
  348. m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" ), &Segments_45_Only,
  349. true ) );
  350. return m_configSettings;
  351. }