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.

117 lines
3.9 KiB

8 years ago
8 years ago
  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012-2017 Kicad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <pcb_general_settings.h>
  24. #include <wx/tokenzr.h>
  25. bool PCB_GENERAL_SETTINGS::g_Use45DegreeGraphicSegments = false;
  26. bool PCB_GENERAL_SETTINGS::g_EditHotkeyChangesTrackWidth = false;
  27. bool PCB_GENERAL_SETTINGS::g_DragSelects = true;
  28. MAGNETIC_OPTIONS PCB_GENERAL_SETTINGS::g_MagneticPads = CAPTURE_CURSOR_IN_TRACK_TOOL;
  29. MAGNETIC_OPTIONS PCB_GENERAL_SETTINGS::g_MagneticTracks = CAPTURE_CURSOR_IN_TRACK_TOOL;
  30. bool PCB_GENERAL_SETTINGS::g_MagneticGraphics = true;
  31. PCB_GENERAL_SETTINGS::PCB_GENERAL_SETTINGS( FRAME_T aFrameType )
  32. : m_frameType( aFrameType ), m_colorsSettings( aFrameType )
  33. {
  34. switch( m_frameType )
  35. {
  36. case FRAME_PCB:
  37. Add( "Use45DegreeGraphicSegments", &g_Use45DegreeGraphicSegments, false);
  38. Add( "MagneticPads", reinterpret_cast<int*>( &g_MagneticPads ), CAPTURE_CURSOR_IN_TRACK_TOOL );
  39. Add( "MagneticTracks", reinterpret_cast<int*>( &g_MagneticTracks ), CAPTURE_CURSOR_IN_TRACK_TOOL );
  40. Add( "MagneticGraphics", &g_MagneticGraphics, true );
  41. Add( "EditActionChangesTrackWidth", &g_EditHotkeyChangesTrackWidth, false );
  42. Add( "DragSelects", &g_DragSelects, true );
  43. break;
  44. case FRAME_PCB_MODULE_EDITOR:
  45. Add( "Use45DegreeGraphicSegments", &g_Use45DegreeGraphicSegments, false);
  46. Add( "MagneticPads", reinterpret_cast<int*>( &g_MagneticPads ), CAPTURE_CURSOR_IN_TRACK_TOOL );
  47. Add( "DragSelects", &g_DragSelects, true );
  48. break;
  49. default:
  50. break;
  51. }
  52. }
  53. void PCB_GENERAL_SETTINGS::Load( wxConfigBase* aCfg )
  54. {
  55. m_colorsSettings.Load( aCfg );
  56. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  57. m_pluginSettings.clear();
  58. wxString pluginSettings = aCfg->Read( "ActionPluginButtons" );
  59. wxStringTokenizer pluginSettingsTokenizer = wxStringTokenizer( pluginSettings, ";" );
  60. while( pluginSettingsTokenizer.HasMoreTokens() )
  61. {
  62. wxString plugin = pluginSettingsTokenizer.GetNextToken();
  63. wxStringTokenizer pluginTokenizer = wxStringTokenizer( plugin, "=" );
  64. if( pluginTokenizer.CountTokens() != 2 )
  65. {
  66. // Bad config
  67. continue;
  68. }
  69. plugin = pluginTokenizer.GetNextToken();
  70. m_pluginSettings.push_back( std::make_pair( plugin, pluginTokenizer.GetNextToken() ) );
  71. }
  72. #endif
  73. SETTINGS::Load( aCfg );
  74. }
  75. void PCB_GENERAL_SETTINGS::Save( wxConfigBase* aCfg )
  76. {
  77. m_colorsSettings.Save( aCfg );
  78. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  79. wxString pluginSettings;
  80. for( auto const& entry : m_pluginSettings )
  81. {
  82. if( !pluginSettings.IsEmpty() )
  83. {
  84. pluginSettings = pluginSettings + wxT( ";" );
  85. }
  86. pluginSettings = pluginSettings + entry.first + wxT( "=" ) + entry.second;
  87. }
  88. aCfg->Write( "ActionPluginButtons" , pluginSettings );
  89. #endif
  90. SETTINGS::Save( aCfg );
  91. }