KiCad PCB EDA Suite
pcb_general_settings.cpp
Go to the documentation of this file.
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 
24 #include <pcb_general_settings.h>
25 #include <wx/tokenzr.h>
26 
27 
29  m_Use45DegreeGraphicSegments( false ),
30  m_EditHotkeyChangesTrackWidth( false ),
31  m_FlipLeftRight( false ),
32  m_MagneticPads( CAPTURE_CURSOR_IN_TRACK_TOOL ),
33  m_MagneticTracks( CAPTURE_CURSOR_IN_TRACK_TOOL ),
34  m_MagneticGraphics( true ),
35  m_frameType( aFrameType ),
36  m_colorsSettings( aFrameType )
37 {
38  switch( m_frameType )
39  {
40  case FRAME_PCB_EDITOR:
41  Add( "Use45DegreeGraphicSegments", &m_Use45DegreeGraphicSegments, false);
42  Add( "MagneticPads", reinterpret_cast<int*>( &m_MagneticPads ), CAPTURE_CURSOR_IN_TRACK_TOOL );
43  Add( "MagneticTracks", reinterpret_cast<int*>( &m_MagneticTracks ), CAPTURE_CURSOR_IN_TRACK_TOOL );
44  Add( "MagneticGraphics", &m_MagneticGraphics, true );
45  Add( "EditActionChangesTrackWidth", &m_EditHotkeyChangesTrackWidth, false );
46  Add( "FlipLeftRight", &m_FlipLeftRight, false );
47  break;
48 
50  m_params.push_back( new PARAM_CFG_BOOL( "FpEditorUse45DegreeGraphicSegments",
52  nullptr, "Use45DegreeGraphicSegments" ) ); // legacy location
53  m_params.push_back( new PARAM_CFG_INT( "FpEditorMagneticPads",
54  reinterpret_cast<int*>( &m_MagneticPads ),
56  NO_EFFECT, // min
57  CAPTURE_ALWAYS, // max
58  nullptr, "MagneticPads" ) ); // legacy location
59  break;
60 
61  default:
62  break;
63  }
64 }
65 
66 
67 void PCB_GENERAL_SETTINGS::Load( wxConfigBase* aCfg )
68 {
69  m_colorsSettings.Load( aCfg );
70 
71 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
72 
73  m_pluginSettings.clear();
74 
75  wxString pluginSettings = aCfg->Read( "ActionPluginButtons" );
76 
77  wxStringTokenizer pluginSettingsTokenizer = wxStringTokenizer( pluginSettings, ";" );
78 
79  while( pluginSettingsTokenizer.HasMoreTokens() )
80  {
81  wxString plugin = pluginSettingsTokenizer.GetNextToken();
82  wxStringTokenizer pluginTokenizer = wxStringTokenizer( plugin, "=" );
83 
84  if( pluginTokenizer.CountTokens() != 2 )
85  {
86  // Bad config
87  continue;
88  }
89 
90  plugin = pluginTokenizer.GetNextToken();
91  m_pluginSettings.push_back( std::make_pair( plugin, pluginTokenizer.GetNextToken() ) );
92  }
93 
94 #endif
95 
96  SETTINGS::Load( aCfg );
97 }
98 
99 
100 void PCB_GENERAL_SETTINGS::Save( wxConfigBase* aCfg )
101 {
102  m_colorsSettings.Save( aCfg );
103 
104 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
105 
106  wxString pluginSettings;
107 
108  for( auto const& entry : m_pluginSettings )
109  {
110  if( !pluginSettings.IsEmpty() )
111  {
112  pluginSettings = pluginSettings + wxT( ";" );
113  }
114  pluginSettings = pluginSettings + entry.first + wxT( "=" ) + entry.second;
115  }
116 
117  aCfg->Write( "ActionPluginButtons" , pluginSettings );
118 
119 #endif
120 
121  SETTINGS::Save( aCfg );
122 }
void Load(wxConfigBase *aCfg) override
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
virtual void Save(wxConfigBase *aConfig)
Definition: settings.cpp:39
MAGNETIC_OPTIONS m_MagneticTracks
virtual void Load(wxConfigBase *aConfig)
Definition: settings.cpp:26
PARAM_CFG_ARRAY m_params
Definition: settings.h:122
virtual void Save(wxConfigBase *aConfig) override
void Add(const wxString &name, int *aPtr, int aDefaultValue)
Definition: settings.h:93
PCB_GENERAL_SETTINGS(FRAME_T aFrameType)
MAGNETIC_OPTIONS m_MagneticPads
Configuration parameter - Integer Class.
Configuration parameter - Boolean Class.
COLORS_DESIGN_SETTINGS m_colorsSettings
virtual void Load(wxConfigBase *aConfig) override
void Save(wxConfigBase *aCfg) override