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.

115 lines
3.8 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. PCB_GENERAL_SETTINGS::PCB_GENERAL_SETTINGS( FRAME_T aFrameType )
  26. : m_frameType( aFrameType ), m_colorsSettings( aFrameType )
  27. {
  28. switch( m_frameType )
  29. {
  30. case FRAME_PCB:
  31. Add( "LegacyAutoDeleteOldTrack", &m_legacyAutoDeleteOldTrack, true );
  32. Add( "LegacyUse45DegreeTracks",&m_legacyUse45DegreeTracks, true);
  33. Add( "LegacyUseTwoSegmentTracks", &m_legacyUseTwoSegmentTracks, true);
  34. Add( "Use45DegreeGraphicSegments", &m_use45DegreeGraphicSegments, false);
  35. Add( "MagneticPads", reinterpret_cast<int*>( &m_magneticPads ), CAPTURE_CURSOR_IN_TRACK_TOOL );
  36. Add( "MagneticTracks", reinterpret_cast<int*>( &m_magneticTracks ), CAPTURE_CURSOR_IN_TRACK_TOOL );
  37. Add( "MagneticGraphics", &m_magneticGraphics, true );
  38. Add( "EditActionChangesTrackWidth", &m_editActionChangesTrackWidth, false );
  39. Add( "DragSelects", &m_dragSelects, true );
  40. break;
  41. case FRAME_PCB_MODULE_EDITOR:
  42. Add( "Use45DegreeGraphicSegments", &m_use45DegreeGraphicSegments, false);
  43. Add( "MagneticPads", reinterpret_cast<int*>( &m_magneticPads ), CAPTURE_CURSOR_IN_TRACK_TOOL );
  44. Add( "DragSelects", &m_dragSelects, true );
  45. break;
  46. default:
  47. break;
  48. }
  49. }
  50. void PCB_GENERAL_SETTINGS::Load( wxConfigBase* aCfg )
  51. {
  52. m_colorsSettings.Load( aCfg );
  53. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  54. m_pluginSettings.clear();
  55. wxString pluginSettings = aCfg->Read( "ActionPluginButtons" );
  56. wxStringTokenizer pluginSettingsTokenizer = wxStringTokenizer( pluginSettings, ";" );
  57. while( pluginSettingsTokenizer.HasMoreTokens() )
  58. {
  59. wxString plugin = pluginSettingsTokenizer.GetNextToken();
  60. wxStringTokenizer pluginTokenizer = wxStringTokenizer( plugin, "=" );
  61. if( pluginTokenizer.CountTokens() != 2 )
  62. {
  63. // Bad config
  64. continue;
  65. }
  66. plugin = pluginTokenizer.GetNextToken();
  67. m_pluginSettings.push_back( std::make_pair( plugin, pluginTokenizer.GetNextToken() ) );
  68. }
  69. #endif
  70. SETTINGS::Load( aCfg );
  71. }
  72. void PCB_GENERAL_SETTINGS::Save( wxConfigBase* aCfg )
  73. {
  74. m_colorsSettings.Save( aCfg );
  75. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  76. wxString pluginSettings;
  77. for( auto const& entry : m_pluginSettings )
  78. {
  79. if( !pluginSettings.IsEmpty() )
  80. {
  81. pluginSettings = pluginSettings + wxT( ";" );
  82. }
  83. pluginSettings = pluginSettings + entry.first + wxT( "=" ) + entry.second;
  84. }
  85. aCfg->Write( "ActionPluginButtons" , pluginSettings );
  86. #endif
  87. SETTINGS::Save( aCfg );
  88. }
  89. bool PCB_GENERAL_SETTINGS::m_use45DegreeGraphicSegments = false;
  90. bool PCB_GENERAL_SETTINGS::m_dragSelects = true;