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 The 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 <layer_ids.h>
27#include <pgm_base.h>
30#include <settings/parameters.h>
32#include <wx/config.h>
33
34
37
38
43{
44 // Init settings:
45 m_params.emplace_back( new PARAM<bool>( "appearance.show_border_and_titleblock",
46 &m_Appearance.show_border_and_titleblock, false ) );
47
48 m_params.emplace_back( new PARAM<bool>( "appearance.show_dcodes",
49 &m_Appearance.show_dcodes, false ) );
50
51 m_params.emplace_back( new PARAM<bool>( "appearance.show_negative_objects",
52 &m_Appearance.show_negative_objects, false ) );
53
54 m_params.emplace_back( new PARAM<wxString>( "appearance.page_type",
55 &m_Appearance.page_type, "GERBER" ) );
56
57 m_params.emplace_back( new PARAM<bool>( "appearance.show_page_limit",
58 &m_Display.m_DisplayPageLimits, false ) );
59
60 m_params.emplace_back( new PARAM<double>( "appearance.mode_opacity_value",
61 &m_Display.m_OpacityModeAlphaValue, 0.6 ) );
62
63 // WARNING: any change to this key MUST be reflected in GetFileHistories()
64 m_params.emplace_back( new PARAM_LIST<wxString>( "system.drill_file_history",
65 &m_DrillFileHistory, {} ) );
66
67 // WARNING: any change to this key MUST be reflected in GetFileHistories()
68 m_params.emplace_back( new PARAM_LIST<wxString>( "system.zip_file_history",
69 &m_ZipFileHistory, {} ) );
70
71 // WARNING: any change to this key MUST be reflected in GetFileHistories()
72 m_params.emplace_back( new PARAM_LIST<wxString>( "system.job_file_history",
73 &m_JobFileHistory, {} ) );
74
75 m_params.emplace_back( new PARAM_LIST<int>( "gerber_to_pcb_layers",
77
78 m_params.emplace_back( new PARAM<int>( "gerber_to_pcb_copperlayers_count",
79 &m_BoardLayersCount, 2 ) );
80
81 m_params.emplace_back( new PARAM<bool>( "excellon_defaults.unit_mm",
82 &m_ExcellonDefaults.m_UnitsMM, false ) );
83
84 m_params.emplace_back( new PARAM<bool>( "excellon_defaults.lz_format",
85 &m_ExcellonDefaults.m_LeadingZero, true ) );
86
87 m_params.emplace_back( new PARAM<int>( "excellon_defaults.mm_integer_len",
88 &m_ExcellonDefaults.m_MmIntegerLen, FMT_INTEGER_MM, 2 , 6 ) );
89
90 m_params.emplace_back( new PARAM<int>( "excellon_defaults.mm_mantissa_len",
91 &m_ExcellonDefaults.m_MmMantissaLen, FMT_MANTISSA_MM, 2 , 6 ) );
92
93 m_params.emplace_back( new PARAM<int>( "excellon_defaults.inch_integer_len",
94 &m_ExcellonDefaults.m_InchIntegerLen, FMT_INTEGER_INCH, 2 , 6 ) );
95
96 m_params.emplace_back( new PARAM<int>( "excellon_defaults.inch_mantissa_len",
97 &m_ExcellonDefaults.m_InchMantissaLen, FMT_MANTISSA_INCH, 2 , 6 ) );
98}
99
100
101bool GERBVIEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
102{
103 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
104
105 ret &= fromLegacy<bool>( aCfg,
106 "ShowBorderAndTitleBlock", "appearance.show_border_and_titleblock" );
107
108 ret &= fromLegacy<bool>( aCfg, "ShowDCodesOpt", "appearance.show_dcodes" );
109 ret &= fromLegacy<bool>( aCfg, "ShowNegativeObjectsOpt", "appearance.show_negative_objects" );
110 ret &= fromLegacyString( aCfg, "PageSizeOpt", "appearance.page_type" );
111
112 auto migrate_files = [&] ( const std::string& aPath, const std::string& aDest )
113 {
114 int max_history_size = Pgm().GetCommonSettings()->m_System.file_history_size;
115 wxString file, key;
116 nlohmann::json js = nlohmann::json::array();
117
118 aCfg->SetPath( aPath );
119
120 for( int i = 0; i < max_history_size; i++ )
121 {
122 key.Printf( wxT( "file%d" ), i );
123 file = aCfg->Read( key, wxEmptyString );
124
125 if( !file.IsEmpty() )
126 js.emplace_back( file.ToStdString() );
127 }
128
129 aCfg->SetPath( wxT( ".." ) );
130
131 Set( aDest, js );
132 };
133
134 migrate_files( "drl_files", "system.drill_file_history" );
135 migrate_files( "zip_files", "system.zip_file_history" );
136 migrate_files( "job_files", "system.job_file_history" );
137
138 {
139 wxString key;
140 int value = 0;
141
142 Set( "gerber_to_pcb_layers", nlohmann::json::array() );
143
144 for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
145 {
146 key.Printf( wxT( "GbrLyr%dToPcb" ), i );
147 aCfg->Read( key, &value, UNSELECTED_LAYER );
148 At( "gerber_to_pcb_layers" ).emplace_back( value );
149 }
150 }
151
153
154 auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
155 wxString str;
156
157 if( aCfg->Read( aKey, &str ) )
158 cs->SetColor( aLayerId, COLOR4D( str ) );
159 };
160
161 migrateLegacyColor( "BackgroundColorEx", LAYER_GERBVIEW_BACKGROUND );
162 migrateLegacyColor( "DCodeColorEx", LAYER_DCODES );
163 migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_GRID );
164 migrateLegacyColor( "NegativeObjectsColorEx", LAYER_NEGATIVE_OBJECTS );
165 migrateLegacyColor( "WorksheetColorEx", LAYER_GERBVIEW_DRAWINGSHEET );
166 migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_PAGE_LIMITS );
167
168 wxString key;
169
170 for( int i = 0, id = GERBVIEW_LAYER_ID_START;
172 {
173 key.Printf( wxT( "ColorLayer%dEx" ), i );
174 migrateLegacyColor( key.ToStdString(), id );
175 }
176
177 Pgm().GetSettingsManager().SaveColorSettings( cs, "gerbview" );
178
179 Set( "appearance.color_theme", cs->GetFilename() );
180
181 return ret;
182}
183
184
185std::map<std::string, nlohmann::json> GERBVIEW_SETTINGS::GetFileHistories()
186{
187 std::map<std::string, nlohmann::json> histories = JSON_SETTINGS::GetFileHistories();
188
189 for( const std::string& candidate : { std::string("system.drill_file_history"),
190 std::string("system.zip_file_history"),
191 std::string("system.job_file_history") } )
192 {
193 if( Contains( candidate ) )
194 histories[candidate] = GetJson( candidate ).value();
195 }
196
197 return histories;
198}
199
APP_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
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
bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
std::map< std::string, nlohmann::json > GetFileHistories() override
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
bool fromLegacy(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig value to a given JSON pointer value.
virtual std::map< std::string, nlohmann::json > GetFileHistories()
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...
std::optional< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
bool Contains(const std::string &aPath) const
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...
wxString GetFilename() const
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:541
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:131
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely save a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
COLOR_SETTINGS * GetMigratedColorSettings()
Return a color theme for storing colors migrated from legacy (5.x and earlier) settings,...
#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:534
@ GERBVIEW_LAYER_ID_START
Definition layer_ids.h:524
@ LAYER_GERBVIEW_BACKGROUND
Definition layer_ids.h:533
@ LAYER_DCODES
Definition layer_ids.h:529
@ LAYER_NEGATIVE_OBJECTS
Definition layer_ids.h:530
@ LAYER_GERBVIEW_PAGE_LIMITS
Definition layer_ids.h:535
@ LAYER_GERBVIEW_GRID
Definition layer_ids.h:531
@ UNSELECTED_LAYER
Definition layer_ids.h:62
#define GERBER_DRAWLAYERS_COUNT
Number of draw layers in Gerbview.
Definition layer_ids.h:519
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE