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.

239 lines
7.3 KiB

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
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
  1. /***********************************/
  2. /** pcbcfg() : configuration **/
  3. /***********************************/
  4. /* lit ou met a jour la configuration de PCBNEW */
  5. #include "fctsys.h"
  6. #include "appl_wxstruct.h"
  7. #include "common.h"
  8. #include "class_drawpanel.h"
  9. #include "confirm.h"
  10. #include "gestfich.h"
  11. #include "pcbnew.h"
  12. #include "pcbplot.h"
  13. #include "pcbcfg.h"
  14. #include "worksheet.h"
  15. #include "id.h"
  16. #include "hotkeys.h"
  17. #include "protos.h"
  18. /* Routines Locales */
  19. /* Variables locales */
  20. #define HOTKEY_FILENAME wxT( "pcbnew" )
  21. /***********************************************************/
  22. void WinEDA_PcbFrame::Process_Config( wxCommandEvent& event )
  23. /***********************************************************/
  24. {
  25. int id = event.GetId();
  26. wxPoint pos;
  27. wxClientDC dc( DrawPanel );
  28. wxFileName fn;
  29. DrawPanel->PrepareGraphicContext( &dc );
  30. pos = GetPosition();
  31. pos.x += 20;
  32. pos.y += 20;
  33. switch( id )
  34. {
  35. case ID_COLORS_SETUP:
  36. DisplayColorSetupFrame( this, pos );
  37. break;
  38. case ID_CONFIG_REQ: // Creation de la fenetre de configuration
  39. InstallConfigFrame( pos );
  40. break;
  41. case ID_PCB_TRACK_SIZE_SETUP:
  42. case ID_PCB_LOOK_SETUP:
  43. case ID_OPTIONS_SETUP:
  44. case ID_PCB_DRAWINGS_WIDTHS_SETUP:
  45. InstallPcbOptionsFrame( pos, &dc, id );
  46. break;
  47. case ID_PCB_PAD_SETUP:
  48. InstallPadOptionsFrame( NULL, NULL, pos );
  49. break;
  50. case ID_CONFIG_SAVE:
  51. Update_config( this );
  52. break;
  53. case ID_CONFIG_READ:
  54. {
  55. fn = GetScreen()->m_FileName;
  56. fn.SetExt( ProjectFileExtension );
  57. wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(),
  58. fn.GetFullName(), ProjectFileWildcard,
  59. wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
  60. if( dlg.ShowModal() == wxID_CANCEL )
  61. break;
  62. if( !wxFileExists( dlg.GetPath() ) )
  63. {
  64. wxString msg;
  65. msg.Printf( _( "File %s not found" ), dlg.GetPath().c_str() );
  66. DisplayError( this, msg );
  67. break;
  68. }
  69. Read_Config( dlg.GetPath() );
  70. break;
  71. }
  72. case ID_PREFERENCES_CREATE_CONFIG_HOTKEYS:
  73. fn.SetPath( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ) );
  74. fn.SetName( HOTKEY_FILENAME );
  75. fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
  76. WriteHotkeyConfigFile( fn.GetFullPath(), s_Pcbnew_Editor_Hokeys_Descr,
  77. true );
  78. break;
  79. case ID_PREFERENCES_READ_CONFIG_HOTKEYS:
  80. Read_Hotkey_Config( this, true );
  81. break;
  82. case ID_PREFERENCES_EDIT_CONFIG_HOTKEYS:
  83. {
  84. fn.SetPath( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ) );
  85. fn.SetName( HOTKEY_FILENAME );
  86. fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
  87. wxString editorname = wxGetApp().GetEditorName();
  88. if( !editorname.IsEmpty() )
  89. ExecuteFile( this, editorname, QuoteFullPath( fn ) );
  90. break;
  91. }
  92. case ID_PREFERENCES_HOTKEY_PATH_IS_HOME:
  93. case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD:
  94. HandleHotkeyConfigMenuSelection( this, id );
  95. break;
  96. case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
  97. DisplayHotkeyList( this, s_Board_Editor_Hokeys_Descr );
  98. break;
  99. default:
  100. DisplayError( this,
  101. wxT( "WinEDA_PcbFrame::Process_Config internal error" ) );
  102. }
  103. }
  104. /***************************************************************/
  105. bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose )
  106. /***************************************************************/
  107. /*
  108. * Read the hotkey files config for pcbnew and module_edit
  109. */
  110. {
  111. wxString FullFileName = ReturnHotkeyConfigFilePath(
  112. g_ConfigFileLocationChoice );
  113. FullFileName += HOTKEY_FILENAME;
  114. FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
  115. return frame->ReadHotkeyConfigFile( FullFileName,
  116. s_Pcbnew_Editor_Hokeys_Descr,
  117. verbose );
  118. }
  119. /**************************************************************************/
  120. bool Read_Config( const wxString& projectFileName )
  121. /*************************************************************************/
  122. /* lit la configuration, si elle n'a pas deja ete lue
  123. * 1 - lit <nom fichier brd>.pro
  124. * 2 - si non trouve lit <chemin de *.exe>/kicad.pro
  125. * 3 - si non trouve: init des variables aux valeurs par defaut
  126. *
  127. * Retourne TRUE si lu, FALSE si config non lue ou non modifie
  128. */
  129. {
  130. wxFileName fn = projectFileName;
  131. int ii;
  132. if( fn.GetExt() != ProjectFileExtension )
  133. {
  134. wxLogDebug( wxT( "Attempting to open project file <%s>. Changing \
  135. file extension to a Kicad project file extension (.pro)." ),
  136. fn.GetFullPath().c_str() );
  137. fn.SetExt( ProjectFileExtension );
  138. }
  139. wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer );
  140. /* Init des valeurs par defaut */
  141. g_LibName_List.Clear();
  142. wxGetApp().ReadProjectConfig( fn.GetFullPath(),
  143. GROUP, ParamCfgList, FALSE );
  144. /* User library path takes precedent over default library search paths. */
  145. wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 );
  146. /* Some parameters must be reinitialize after loading a new board or config: */
  147. g_DesignSettings.m_TrackWidthHistory[0] = g_DesignSettings.m_CurrentTrackWidth;
  148. g_DesignSettings.m_ViaSizeHistory[0] = g_DesignSettings.m_CurrentViaSize;
  149. for( ii = 1; ii < HISTORY_NUMBER; ii++ )
  150. {
  151. g_DesignSettings.m_TrackWidthHistory[ii] = 0;
  152. g_DesignSettings.m_ViaSizeHistory[ii] = 0;
  153. }
  154. /* Reset the ITEM_NOT_SHOW flag when loading a new config
  155. * Because it could creates SERIOUS mistakes for the user,
  156. * if some items are not visible after loading a board...
  157. */
  158. for( ii = 0; ii < LAYER_COUNT; ii++ )
  159. g_DesignSettings.m_LayerColor[ii] &= ~ ITEM_NOT_SHOW;
  160. DisplayOpt.Show_Modules_Cmp = true;
  161. DisplayOpt.Show_Modules_Cu = true;
  162. g_ModuleTextNOVColor &= ~ ITEM_NOT_SHOW;
  163. g_ModuleTextCMPColor &= ~ ITEM_NOT_SHOW;
  164. g_ModuleTextCUColor &= ~ ITEM_NOT_SHOW;
  165. g_PadCMPColor &= ~ ITEM_NOT_SHOW;
  166. g_PadCUColor &= ~ ITEM_NOT_SHOW;
  167. g_DesignSettings.m_ViaColor[VIA_THROUGH] &= ~ ITEM_NOT_SHOW;
  168. g_DesignSettings.m_ViaColor[VIA_BLIND_BURIED] &= ~ ITEM_NOT_SHOW;
  169. g_DesignSettings.m_ViaColor[VIA_MICROVIA] &= ~ ITEM_NOT_SHOW;
  170. // These parameters could be left in their previous state, or resetted
  171. // Comment or uncomment to keep or reset this option after loading a board
  172. g_AnchorColor &= ~ ITEM_NOT_SHOW;
  173. DisplayOpt.DisplayPadNoConn = true;
  174. return TRUE;
  175. }
  176. /**********************************************************/
  177. void WinEDA_PcbFrame::Update_config( wxWindow* displayframe )
  178. /***********************************************************/
  179. /* enregistrement de la config */
  180. {
  181. wxFileName fn;
  182. fn = GetScreen()->m_FileName;
  183. fn.SetExt( ProjectFileExtension );
  184. wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(),
  185. fn.GetFullName(), ProjectFileWildcard,
  186. wxFD_SAVE | wxFD_CHANGE_DIR );
  187. if( dlg.ShowModal() == wxID_CANCEL )
  188. return;
  189. /* ecriture de la configuration */
  190. wxGetApp().WriteProjectConfig( fn.GetFullPath(), wxT( "/pcbnew" ),
  191. ParamCfgList );
  192. }