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.

172 lines
4.9 KiB

  1. /************************************************/
  2. /** gerbview_config.cpp : Gerbview configuration*/
  3. /************************************************/
  4. /* Functions to handle Gerbview configuration */
  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 "pcbcommon.h"
  12. #include "gerbview.h"
  13. #include "pcbplot.h"
  14. #include "hotkeys.h"
  15. #include "gerbview_config.h"
  16. #include "protos.h"
  17. #define HOTKEY_FILENAME wxT( "gerbview" )
  18. const wxString GerbviewProjectFileExt( wxT( "cnf" ) );
  19. const wxString GerbviewProjectFileWildcard( _( "GerbView project files (.cnf)|*.cnf" ) );
  20. /*************************************************************/
  21. void WinEDA_GerberFrame::Process_Config( wxCommandEvent& event )
  22. /*************************************************************/
  23. {
  24. int id = event.GetId();
  25. wxPoint pos;
  26. wxString FullFileName;
  27. pos = GetPosition();
  28. pos.x += 20;
  29. pos.y += 20;
  30. switch( id )
  31. {
  32. case ID_COLORS_SETUP:
  33. DisplayColorSetupFrame( this, pos );
  34. break;
  35. case ID_CONFIG_REQ: // Creation de la fenetre de configuration
  36. {
  37. InstallConfigFrame( pos );
  38. break;
  39. }
  40. case ID_PCB_TRACK_SIZE_SETUP:
  41. case ID_PCB_DISPLAY_OPTIONS_SETUP:
  42. case ID_OPTIONS_SETUP:
  43. InstallPcbOptionsFrame( pos, id );
  44. break;
  45. case ID_CONFIG_SAVE:
  46. Update_config();
  47. break;
  48. /* Hotkey IDs */
  49. case ID_PREFERENCES_HOTKEY_CREATE_CONFIG:
  50. FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
  51. FullFileName += HOTKEY_FILENAME;
  52. FullFileName += wxT(".");
  53. FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
  54. WriteHotkeyConfigFile( FullFileName, s_Gerbview_Hokeys_Descr, true );
  55. break;
  56. case ID_PREFERENCES_HOTKEY_READ_CONFIG:
  57. Read_Hotkey_Config( this, true );
  58. break;
  59. case ID_PREFERENCES_HOTKEY_EDIT_CONFIG:
  60. {
  61. FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
  62. FullFileName += HOTKEY_FILENAME;
  63. FullFileName += wxT(".");
  64. FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
  65. AddDelimiterString( FullFileName );
  66. wxString editorname = wxGetApp().GetEditorName();
  67. if( !editorname.IsEmpty() )
  68. ExecuteFile( this, editorname, FullFileName );
  69. }
  70. break;
  71. case ID_PREFERENCES_HOTKEY_PATH_IS_HOME:
  72. case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD:
  73. HandleHotkeyConfigMenuSelection( this, id );
  74. break;
  75. case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: // Display Current hotkey list for gerbview
  76. DisplayHotkeyList( this, s_Gerbview_Hokeys_Descr );
  77. break;
  78. default:
  79. DisplayError( this,
  80. wxT( "WinEDA_GerberFrame::Process_Config internal error" ) );
  81. }
  82. }
  83. /*****************************************************/
  84. bool Read_Config()
  85. /*****************************************************/
  86. /* lit la configuration, si elle n'a pas deja etee lue
  87. * 1 - lit gerbview.cnf
  88. * 2 - si non trouve lit <chemin de gerbview.exe>/gerbview.cnf
  89. * 3 - si non trouve: init des variables aux valeurs par defaut
  90. *
  91. * Retourne un pointeur su le message d'erreur a afficher
  92. */
  93. {
  94. wxGetApp().ReadProjectConfig( wxT( "gerbview.cnf" ), GROUP, ParamCfgList,
  95. FALSE );
  96. /* Inits autres variables */
  97. if( g_PhotoFilenameExt.IsEmpty() )
  98. g_PhotoFilenameExt = wxT( "pho" );
  99. if( g_DrillFilenameExt.IsEmpty() )
  100. g_DrillFilenameExt = wxT( "drl" );
  101. if( g_PenFilenameExt.IsEmpty() )
  102. g_PenFilenameExt = wxT( "pen" );
  103. return TRUE;
  104. }
  105. /******************************************/
  106. void WinEDA_GerberFrame::Update_config()
  107. /******************************************/
  108. /*
  109. * creation du fichier de config
  110. */
  111. {
  112. wxFileName fn = wxFileName( wxEmptyString, wxT( "gerbview" ),
  113. GerbviewProjectFileExt );
  114. wxFileDialog dlg( this, _( "Save GerbView Project File" ), wxEmptyString,
  115. fn.GetFullName(), GerbviewProjectFileWildcard,
  116. wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  117. if( dlg.ShowModal() == wxID_CANCEL )
  118. return;
  119. /* ecriture de la configuration */
  120. wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP, ParamCfgList );
  121. }
  122. /***************************************************************/
  123. bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose )
  124. /***************************************************************/
  125. /*
  126. * Read the hotkey files config for pcbnew and module_edit
  127. */
  128. {
  129. wxString FullFileName = ReturnHotkeyConfigFilePath(
  130. g_ConfigFileLocationChoice );
  131. FullFileName += HOTKEY_FILENAME;
  132. FullFileName += wxT(".");
  133. FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
  134. return frame->ReadHotkeyConfigFile( FullFileName,
  135. s_Gerbview_Hokeys_Descr,
  136. verbose );
  137. }