KiCad PCB EDA Suite
gerbview_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) 2020 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 <gerbview_settings.h>
26 #include <pgm_base.h>
28 #include <settings/parameters.h>
30 #include <wx/config.h>
31 
32 
34 const int gerbviewSchemaVersion = 0;
35 
36 
38 {
39  // Make Coverity happy
41 
42  // Init settings:
43  m_params.emplace_back( new PARAM<bool>( "appearance.show_border_and_titleblock",
45 
46  m_params.emplace_back( new PARAM<bool>( "appearance.show_dcodes",
47  &m_Appearance.show_dcodes, false ) );
48 
49  m_params.emplace_back( new PARAM<bool>( "appearance.show_negative_objects",
51 
52  m_params.emplace_back( new PARAM<wxString>( "appearance.page_type",
53  &m_Appearance.page_type, "GERBER" ) );
54 
55  m_params.emplace_back( new PARAM_LIST<wxString>( "system.drill_file_history",
56  &m_DrillFileHistory, {} ) );
57 
58  m_params.emplace_back( new PARAM_LIST<wxString>( "system.zip_file_history",
59  &m_ZipFileHistory, {} ) );
60 
61  m_params.emplace_back( new PARAM_LIST<wxString>( "system.job_file_history",
62  &m_JobFileHistory, {} ) );
63 
64  m_params.emplace_back( new PARAM_LIST<int>( "gerber_to_pcb_layers",
66 
67  m_params.emplace_back( new PARAM<int>( "gerber_to_pcb_copperlayers_count",
68  &m_BoardLayersCount, 2 ) );
69 }
70 
71 
72 bool GERBVIEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
73 {
74  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
75 
76  ret &= fromLegacy<bool>( aCfg,
77  "ShowBorderAndTitleBlock", "appearance.show_border_and_titleblock" );
78 
79  ret &= fromLegacy<bool>( aCfg, "ShowDCodesOpt", "appearance.show_dcodes" );
80  ret &= fromLegacy<bool>( aCfg, "ShowNegativeObjectsOpt", "appearance.show_negative_objects" );
81  ret &= fromLegacyString( aCfg, "PageSizeOpt", "appearance.page_type" );
82 
83  auto migrate_files = [&] ( const std::string& aPath, const std::string& aDest )
84  {
85  int max_history_size = Pgm().GetCommonSettings()->m_System.file_history_size;
86  wxString file, key;
87  nlohmann::json js = nlohmann::json::array();
88 
89  aCfg->SetPath( aPath );
90 
91  for( int i = 0; i < max_history_size; i++ )
92  {
93  key.Printf( "file%d", i );
94  file = aCfg->Read( key, wxEmptyString );
95 
96  if( !file.IsEmpty() )
97  js.emplace_back( file.ToStdString() );
98  }
99 
100  aCfg->SetPath( ".." );
101 
102  ( *this )[PointerFromString( aDest )] = js;
103  };
104 
105  migrate_files( "drl_files", "system.drill_file_history" );
106  migrate_files( "zip_files", "system.zip_file_history" );
107  migrate_files( "job_files", "system.job_file_history" );
108 
109  {
110  wxString key;
111  int value = 0;
112  nlohmann::json::json_pointer ptr = PointerFromString( "gerber_to_pcb_layers" );
113 
114  ( *this )[ptr] = nlohmann::json::array();
115 
116  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
117  {
118  key.Printf( "GbrLyr%dToPcb", i );
119  aCfg->Read( key, &value, UNSELECTED_LAYER );
120  ( *this )[ptr].emplace_back( value );
121  }
122  }
123 
124  COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
125 
126  auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
127  wxString str;
128 
129  if( aCfg->Read( aKey, &str ) )
130  cs->SetColor( aLayerId, COLOR4D( str ) );
131  };
132 
133  migrateLegacyColor( "BackgroundColorEx", LAYER_GERBVIEW_BACKGROUND );
134  migrateLegacyColor( "DCodeColorEx", LAYER_DCODES );
135  migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_GRID );
136  migrateLegacyColor( "NegativeObjectsColorEx", LAYER_NEGATIVE_OBJECTS );
137  migrateLegacyColor( "WorksheetColorEx", LAYER_GERBVIEW_WORKSHEET );
138 
139  wxString key;
140 
141  for( int i = 0, id = GERBVIEW_LAYER_ID_START;
143  {
144  key.Printf( "ColorLayer%dEx", i );
145  migrateLegacyColor( key.ToStdString(), id );
146  }
147 
148  Pgm().GetSettingsManager().SaveColorSettings( cs, "gerbview" );
149 
150  ( *this )[PointerFromString( "appearance.color_theme" )] = cs->GetFilename();
151 
152  return ret;
153 }
std::vector< wxString > m_JobFileHistory
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
wxString GetFilename() const
Definition: json_settings.h:64
const int gerbviewSchemaVersion
! Update the schema version whenever a migration is required
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
nlohmann::json json
Definition: gerbview.cpp:39
std::vector< wxString > m_DrillFileHistory
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
#define GERBER_DRAWLAYERS_COUNT
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
see class PGM_BASE
std::vector< wxString > m_ZipFileHistory
Board layer functions and definitions.
std::vector< int > m_GerberToPcbLayerMapping
A list of GERBER_DRAWLAYERS_COUNT length containing a mapping of gerber layers to PCB layers,...
Color settings are a bit different than most of the settings objects in that there can be more than o...
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
void SetColor(int aLayer, COLOR4D aColor)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100