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_FlipLeftRight( false ),
31  m_MagneticPads( CAPTURE_CURSOR_IN_TRACK_TOOL ),
32  m_MagneticTracks( CAPTURE_CURSOR_IN_TRACK_TOOL ),
33  m_MagneticGraphics( true ),
34  m_frameType( aFrameType ),
35  m_colorsSettings( aFrameType )
36 {
37  try
38  {
39  switch( m_frameType )
40  {
41  case FRAME_PCB_EDITOR:
42  Add( "Use45DegreeGraphicSegments", &m_Use45DegreeGraphicSegments, false);
43  Add( "MagneticPads", reinterpret_cast<int*>( &m_MagneticPads ), CAPTURE_CURSOR_IN_TRACK_TOOL );
44  Add( "MagneticTracks", reinterpret_cast<int*>( &m_MagneticTracks ), CAPTURE_CURSOR_IN_TRACK_TOOL );
45  Add( "MagneticGraphics", &m_MagneticGraphics, true );
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  catch( boost::bad_pointer& )
66  {
67  // Out of memory? Ship's going down anyway....
68  }
69 }
70 
71 
72 void PCB_GENERAL_SETTINGS::Load( wxConfigBase* aCfg )
73 {
74  m_colorsSettings.Load( aCfg );
75 
76 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
77 
78  m_pluginSettings.clear();
79 
80  wxString pluginSettings = aCfg->Read( "ActionPluginButtons" );
81 
82  wxStringTokenizer pluginSettingsTokenizer = wxStringTokenizer( pluginSettings, ";" );
83 
84  while( pluginSettingsTokenizer.HasMoreTokens() )
85  {
86  wxString plugin = pluginSettingsTokenizer.GetNextToken();
87  wxStringTokenizer pluginTokenizer = wxStringTokenizer( plugin, "=" );
88 
89  if( pluginTokenizer.CountTokens() != 2 )
90  {
91  // Bad config
92  continue;
93  }
94 
95  plugin = pluginTokenizer.GetNextToken();
96  m_pluginSettings.emplace_back( plugin, pluginTokenizer.GetNextToken() );
97  }
98 
99 #endif
100 
101  SETTINGS::Load( aCfg );
102 }
103 
104 
105 void PCB_GENERAL_SETTINGS::Save( wxConfigBase* aCfg )
106 {
107  m_colorsSettings.Save( aCfg );
108 
109 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
110 
111  wxString pluginSettings;
112 
113  for( auto const& entry : m_pluginSettings )
114  {
115  if( !pluginSettings.IsEmpty() )
116  {
117  pluginSettings = pluginSettings + wxT( ";" );
118  }
119  pluginSettings = pluginSettings + entry.first + wxT( "=" ) + entry.second;
120  }
121 
122  aCfg->Write( "ActionPluginButtons" , pluginSettings );
123 
124 #endif
125 
126  SETTINGS::Save( aCfg );
127 }
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
virtual void Save(wxConfigBase *aConfig) override
void Add(const wxString &name, int *aPtr, int aDefaultValue)
Definition: settings.h:93
std::vector< PARAM_CFG * > m_params
Definition: settings.h:122
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