KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2021-2024 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>
25#include <layer_ids.h>
26#include <pgm_base.h>
29#include <settings/parameters.h>
31#include <wx/config.h>
32
33
36
37
40 m_Appearance(),
41 m_BoardLayersCount( 2 )
42{
43 // Init settings:
44 m_params.emplace_back( new PARAM<bool>( "appearance.show_border_and_titleblock",
46
47 m_params.emplace_back( new PARAM<bool>( "appearance.show_dcodes",
48 &m_Appearance.show_dcodes, false ) );
49
50 m_params.emplace_back( new PARAM<bool>( "appearance.show_negative_objects",
52
53 m_params.emplace_back( new PARAM<wxString>( "appearance.page_type",
54 &m_Appearance.page_type, "GERBER" ) );
55
56 m_params.emplace_back( new PARAM<bool>( "appearance.show_page_limit",
58
59 m_params.emplace_back( new PARAM_LIST<wxString>( "system.drill_file_history",
60 &m_DrillFileHistory, {} ) );
61
62 m_params.emplace_back( new PARAM_LIST<wxString>( "system.zip_file_history",
63 &m_ZipFileHistory, {} ) );
64
65 m_params.emplace_back( new PARAM_LIST<wxString>( "system.job_file_history",
66 &m_JobFileHistory, {} ) );
67
68 m_params.emplace_back( new PARAM_LIST<int>( "gerber_to_pcb_layers",
70
71 m_params.emplace_back( new PARAM<int>( "gerber_to_pcb_copperlayers_count",
72 &m_BoardLayersCount, 2 ) );
73
74 m_params.emplace_back( new PARAM<bool>( "excellon_defaults.unit_mm",
75 &m_ExcellonDefaults.m_UnitsMM, false ) );
76
77 m_params.emplace_back( new PARAM<bool>( "excellon_defaults.lz_format",
79
80 m_params.emplace_back( new PARAM<int>( "excellon_defaults.mm_integer_len",
82
83 m_params.emplace_back( new PARAM<int>( "excellon_defaults.mm_mantissa_len",
85
86 m_params.emplace_back( new PARAM<int>( "excellon_defaults.inch_integer_len",
88
89 m_params.emplace_back( new PARAM<int>( "excellon_defaults.inch_mantissa_len",
91}
92
93
94bool GERBVIEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
95{
96 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
97
98 ret &= fromLegacy<bool>( aCfg,
99 "ShowBorderAndTitleBlock", "appearance.show_border_and_titleblock" );
100
101 ret &= fromLegacy<bool>( aCfg, "ShowDCodesOpt", "appearance.show_dcodes" );
102 ret &= fromLegacy<bool>( aCfg, "ShowNegativeObjectsOpt", "appearance.show_negative_objects" );
103 ret &= fromLegacyString( aCfg, "PageSizeOpt", "appearance.page_type" );
104
105 auto migrate_files = [&] ( const std::string& aPath, const std::string& aDest )
106 {
107 int max_history_size = Pgm().GetCommonSettings()->m_System.file_history_size;
108 wxString file, key;
109 nlohmann::json js = nlohmann::json::array();
110
111 aCfg->SetPath( aPath );
112
113 for( int i = 0; i < max_history_size; i++ )
114 {
115 key.Printf( wxT( "file%d" ), i );
116 file = aCfg->Read( key, wxEmptyString );
117
118 if( !file.IsEmpty() )
119 js.emplace_back( file.ToStdString() );
120 }
121
122 aCfg->SetPath( wxT( ".." ) );
123
124 Set( aDest, js );
125 };
126
127 migrate_files( "drl_files", "system.drill_file_history" );
128 migrate_files( "zip_files", "system.zip_file_history" );
129 migrate_files( "job_files", "system.job_file_history" );
130
131 {
132 wxString key;
133 int value = 0;
134
135 Set( "gerber_to_pcb_layers", nlohmann::json::array() );
136
137 for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
138 {
139 key.Printf( wxT( "GbrLyr%dToPcb" ), i );
140 aCfg->Read( key, &value, UNSELECTED_LAYER );
141 At( "gerber_to_pcb_layers" ).emplace_back( value );
142 }
143 }
144
145 COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
146
147 auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
148 wxString str;
149
150 if( aCfg->Read( aKey, &str ) )
151 cs->SetColor( aLayerId, COLOR4D( str ) );
152 };
153
154 migrateLegacyColor( "BackgroundColorEx", LAYER_GERBVIEW_BACKGROUND );
155 migrateLegacyColor( "DCodeColorEx", LAYER_DCODES );
156 migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_GRID );
157 migrateLegacyColor( "NegativeObjectsColorEx", LAYER_NEGATIVE_OBJECTS );
158 migrateLegacyColor( "WorksheetColorEx", LAYER_GERBVIEW_DRAWINGSHEET );
159 migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_PAGE_LIMITS );
160
161 wxString key;
162
163 for( int i = 0, id = GERBVIEW_LAYER_ID_START;
165 {
166 key.Printf( wxT( "ColorLayer%dEx" ), i );
167 migrateLegacyColor( key.ToStdString(), id );
168 }
169
170 Pgm().GetSettingsManager().SaveColorSettings( cs, "gerbview" );
171
172 Set( "appearance.color_theme", cs->GetFilename() );
173
174 return ret;
175}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetColor(int aLayer, const COLOR4D &aColor)
std::vector< wxString > m_JobFileHistory
std::vector< wxString > m_DrillFileHistory
GBR_DISPLAY_OPTIONS m_Display
EXCELLON_DEFAULTS m_ExcellonDefaults
std::vector< int > m_GerberToPcbLayerMapping
A list of GERBER_DRAWLAYERS_COUNT length containing a mapping of gerber layers to PCB layers,...
std::vector< wxString > m_ZipFileHistory
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.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
nlohmann::json & At(const std::string &aPath)
Wrappers for the underlying JSON API so that most consumers don't need json.hpp All of these function...
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
wxString GetFilename() const
Definition: json_settings.h:73
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
#define FMT_MANTISSA_INCH
#define FMT_INTEGER_MM
#define FMT_MANTISSA_MM
#define FMT_INTEGER_INCH
const int gerbviewSchemaVersion
! Update the schema version whenever a migration is required
@ LAYER_GERBVIEW_DRAWINGSHEET
Definition: layer_ids.h:431
@ GERBVIEW_LAYER_ID_START
Definition: layer_ids.h:421
@ LAYER_GERBVIEW_BACKGROUND
Definition: layer_ids.h:430
@ LAYER_DCODES
Definition: layer_ids.h:426
@ LAYER_NEGATIVE_OBJECTS
Definition: layer_ids.h:427
@ LAYER_GERBVIEW_PAGE_LIMITS
Definition: layer_ids.h:432
@ LAYER_GERBVIEW_GRID
Definition: layer_ids.h:428
@ UNSELECTED_LAYER
Definition: layer_ids.h:62
#define GERBER_DRAWLAYERS_COUNT
Definition: layer_ids.h:416
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119