41 wxT(
"KICAD7_SYMBOL_DIR" ),
42 wxT(
"KICAD7_FOOTPRINT_DIR" ),
43 wxT(
"KICAD7_TEMPLATES_DIR" ),
44 wxT(
"KICAD7_3DMODEL_DIR" )
67#if defined( __WXGTK__ ) || defined( __WXMSW__ )
78#if defined( __WXGTK__ ) || defined( __WXMSW__ )
105#if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
143 for(
const std::pair<wxString, ENV_VAR_ITEM> entry :
m_Env.
vars )
145 const ENV_VAR_ITEM& var = entry.second;
147 wxASSERT( entry.first == var.GetKey() );
150 if( var.IsDefault() )
152 wxLogTrace( traceEnvVars,
153 wxS(
"COMMON_SETTINGS: Env var %s skipping save (default)" ),
158 wxString value = var.GetValue();
162 if( var.GetDefinedExternally() )
164 if( var.GetDefinedInSettings() )
166 wxLogTrace( traceEnvVars,
167 wxS(
"COMMON_SETTINGS: Env var %s was overridden externally, " )
168 "saving previously-loaded value %s",
169 var.GetKey(), var.GetSettingsValue() );
170 value = var.GetSettingsValue();
174 wxLogTrace( traceEnvVars,
175 wxS(
"COMMON_SETTINGS: Env var %s skipping save (external)" ),
182 wxS(
"COMMON_SETTINGS: Saving env var %s = %s" ),
183 var.GetKey(), value);
185 std::string key( var.GetKey().ToUTF8() );
193 if( !aJson.is_object() )
196 for(
const auto& entry : aJson.items() )
198 wxString key = wxString( entry.key().c_str(), wxConvUTF8 );
199 wxString val = entry.value().get<wxString>();
201 if( m_Env.vars.count( key ) )
203 if( m_Env.vars[key].GetDefinedExternally() )
205 wxLogTrace(
traceEnvVars, wxS(
"COMMON_SETTINGS: %s is defined externally" ),
207 m_Env.vars[key].SetDefinedInSettings();
208 m_Env.vars[key].SetSettingsValue( val );
213 wxLogTrace(
traceEnvVars, wxS(
"COMMON_SETTINGS: Updating %s: %s -> %s"),
214 key, m_Env.vars[key].GetValue(), val );
215 m_Env.vars[key].SetValue( val );
220 wxLogTrace(
traceEnvVars, wxS(
"COMMON_SETTINGS: Loaded new var: %s = %s" ),
225 m_Env.vars[key].SetDefinedInSettings();
226 m_Env.vars[key].SetSettingsValue( val );
231 m_params.emplace_back(
new PARAM<bool>(
"input.focus_follow_sch_pcb",
232 &m_Input.focus_follow_sch_pcb,
false ) );
234 m_params.emplace_back(
new PARAM<bool>(
"input.auto_pan", &m_Input.auto_pan,
false ) );
236 m_params.emplace_back(
new PARAM<int>(
"input.auto_pan_acceleration",
237 &m_Input.auto_pan_acceleration, 5 ) );
239 m_params.emplace_back(
new PARAM<bool>(
"input.center_on_zoom",
240 &m_Input.center_on_zoom,
true ) );
242 m_params.emplace_back(
new PARAM<bool>(
"input.immediate_actions",
243 &m_Input.immediate_actions,
true ) );
245 m_params.emplace_back(
new PARAM<bool>(
"input.warp_mouse_on_move",
246 &m_Input.warp_mouse_on_move,
true ) );
248 m_params.emplace_back(
new PARAM<bool>(
"input.horizontal_pan",
249 &m_Input.horizontal_pan,
false ) );
251 m_params.emplace_back(
new PARAM<bool>(
"input.zoom_acceleration",
252 &m_Input.zoom_acceleration,
false ) );
255 int default_zoom_speed = 5;
257 int default_zoom_speed = 1;
260 m_params.emplace_back(
new PARAM<int>(
"input.zoom_speed",
261 &m_Input.zoom_speed, default_zoom_speed ) );
263 m_params.emplace_back(
new PARAM<bool>(
"input.zoom_speed_auto",
264 &m_Input.zoom_speed_auto,
true ) );
266 m_params.emplace_back(
new PARAM<int>(
"input.scroll_modifier_zoom",
267 &m_Input.scroll_modifier_zoom, 0 ) );
269 m_params.emplace_back(
new PARAM<int>(
"input.scroll_modifier_pan_h",
270 &m_Input.scroll_modifier_pan_h, WXK_CONTROL ) );
272 m_params.emplace_back(
new PARAM<int>(
"input.scroll_modifier_pan_v",
273 &m_Input.scroll_modifier_pan_v, WXK_SHIFT ) );
287 m_params.emplace_back(
new PARAM<int>(
"graphics.opengl_antialiasing_mode",
288 &m_Graphics.opengl_aa_mode, 1, 0, 2 ) );
290 m_params.emplace_back(
new PARAM<int>(
"graphics.cairo_antialiasing_mode",
291 &m_Graphics.cairo_aa_mode, 0, 0, 2 ) );
293 m_params.emplace_back(
new PARAM<int>(
"system.autosave_interval",
294 &m_System.autosave_interval, 600 ) );
298 &m_System.text_editor, wxS(
"/usr/bin/open -e" ) ) );
301 &m_System.text_editor, wxS(
"" ) ) );
304 m_params.emplace_back(
new PARAM<int>(
"system.file_history_size",
305 &m_System.file_history_size, 9 ) );
308 &m_System.language, wxS(
"Default" ) ) );
311 &m_System.pdf_viewer_name, wxS(
"" ) ) );
313 m_params.emplace_back(
new PARAM<bool>(
"system.use_system_pdf_viewer",
314 &m_System.use_system_pdf_viewer,
true ) );
317 &m_System.working_dir, wxS(
"" ) ) );
319 m_params.emplace_back(
new PARAM<int>(
"system.clear_3d_cache_interval",
320 &m_System.clear_3d_cache_interval, 30 ) );
322 m_params.emplace_back(
new PARAM<bool>(
"do_not_show_again.zone_fill_warning",
323 &m_DoNotShowAgain.zone_fill_warning,
false ) );
325 m_params.emplace_back(
new PARAM<bool>(
"do_not_show_again.env_var_overwrite_warning",
326 &m_DoNotShowAgain.env_var_overwrite_warning,
false ) );
328 m_params.emplace_back(
new PARAM<bool>(
"do_not_show_again.scaled_3d_models_warning",
329 &m_DoNotShowAgain.scaled_3d_models_warning,
false ) );
331 m_params.emplace_back(
new PARAM<bool>(
"do_not_show_again.data_collection_prompt",
332 &m_DoNotShowAgain.data_collection_prompt,
false ) );
334 m_params.emplace_back(
new PARAM<bool>(
"session.remember_open_files",
335 &m_Session.remember_open_files,
false ) );
338 &m_Session.pinned_symbol_libs, {} ) );
341 &m_Session.pinned_fp_libs, {} ) );
343 m_params.emplace_back(
new PARAM<int>(
"netclass_panel.sash_pos",
344 &m_NetclassPanel.sash_pos, 160 ) );
346 m_params.emplace_back(
new PARAM<int>(
"package_manager.sash_pos",
347 &m_PackageManager.sash_pos, 380 ) );
363 nlohmann::json::json_pointer mwp_pointer(
"/input/mousewheel_pan"_json_pointer );
370 m_internals->At(
"input" ).erase(
"mousewheel_pan" );
374 wxLogTrace(
traceSettings, wxT(
"COMMON_SETTINGS::Migrate 0->1: mousewheel_pan not found" ) );
379 ( *m_internals )[nlohmann::json::json_pointer(
"/input/horizontal_pan" )] =
true;
381 ( *m_internals )[nlohmann::json::json_pointer(
"/input/scroll_modifier_pan_h" )] = WXK_SHIFT;
382 ( *m_internals )[nlohmann::json::json_pointer(
"/input/scroll_modifier_pan_v" )] = 0;
383 ( *m_internals )[nlohmann::json::json_pointer(
"/input/scroll_modifier_zoom" )] = WXK_CONTROL;
387 ( *m_internals )[nlohmann::json::json_pointer(
"/input/horizontal_pan" )] =
false;
389 ( *m_internals )[nlohmann::json::json_pointer(
"/input/scroll_modifier_pan_h" )] = WXK_CONTROL;
390 ( *m_internals )[nlohmann::json::json_pointer(
"/input/scroll_modifier_pan_v" )] = WXK_SHIFT;
391 ( *m_internals )[nlohmann::json::json_pointer(
"/input/scroll_modifier_zoom" )] = 0;
400 nlohmann::json::json_pointer v1_pointer(
"/input/prefer_select_to_drag"_json_pointer );
402 bool prefer_selection =
false;
407 m_internals->at( nlohmann::json::json_pointer(
"/input"_json_pointer ) ).erase(
"prefer_select_to_drag" );
411 wxLogTrace(
traceSettings, wxT(
"COMMON_SETTINGS::Migrate 1->2: prefer_select_to_drag not found" ) );
414 if( prefer_selection )
427 cfgpath.AppendDir( wxT(
"3d" ) );
428 cfgpath.SetFullName( wxS(
"3Dresolver.cfg" ) );
429 cfgpath.MakeAbsolute();
431 std::vector<LEGACY_3D_SEARCH_PATH> legacyPaths;
435 wxRegEx nonValidCharsRegex( wxS(
"[^A-Z0-9_]+" ), wxRE_ADVANCED );
439 wxString key =
path.m_Alias;
440 const wxString& val =
path.m_Pathvar;
448 key.Replace( wxS(
"-" ), wxS(
"_" ) );
451 nonValidCharsRegex.Replace( &key, wxEmptyString );
455 wxLogTrace(
traceEnvVars, wxS(
"COMMON_SETTINGS: Loaded new var: %s = %s" ), key, val );
460 if( cfgpath.FileExists() )
462 wxRemoveFile( cfgpath.GetFullPath() );
473 ret &= fromLegacy<double>( aCfg,
"CanvasScale",
"appearance.canvas_scale" );
474 ret &= fromLegacy<int>( aCfg,
"IconScale",
"appearance.icon_scale" );
475 ret &= fromLegacy<bool>( aCfg,
"UseIconsInMenus",
"appearance.use_icons_in_menus" );
476 ret &= fromLegacy<bool>( aCfg,
"ShowEnvVarWarningDialog",
"environment.show_warning_dialog" );
483 nlohmann::json::json_pointer ptr =
m_internals->PointerFromString(
"environment.vars" );
485 aCfg->SetPath(
"EnvironmentVariables" );
488 while( aCfg->GetNextEntry( key, index ) )
492 wxLogTrace(
traceSettings, wxT(
"Migrate Env: %s is blacklisted; skipping." ), key );
496 value = aCfg->Read( key, wxEmptyString );
498 if( !value.IsEmpty() )
500 ptr.push_back( key.ToStdString() );
502 wxLogTrace(
traceSettings, wxT(
"Migrate Env: %s=%s" ), ptr.to_string(), value );
503 ( *m_internals )[ptr] = value.ToUTF8();
509 aCfg->SetPath(
".." );
514 bool mousewheel_pan =
false;
516 if( aCfg->Read(
"MousewheelPAN", &mousewheel_pan ) && mousewheel_pan )
518 Set(
"input.horizontal_pan",
true );
519 Set(
"input.scroll_modifier_pan_h",
static_cast<int>( WXK_SHIFT ) );
520 Set(
"input.scroll_modifier_pan_v", 0 );
521 Set(
"input.scroll_modifier_zoom",
static_cast<int>( WXK_CONTROL ) );
524 ret &= fromLegacy<bool>( aCfg,
"AutoPAN",
"input.auto_pan" );
525 ret &= fromLegacy<bool>( aCfg,
"ImmediateActions",
"input.immediate_actions" );
526 ret &= fromLegacy<bool>( aCfg,
"PreferSelectionToDragging",
"input.prefer_select_to_drag" );
527 ret &= fromLegacy<bool>( aCfg,
"MoveWarpsCursor",
"input.warp_mouse_on_move" );
528 ret &= fromLegacy<bool>( aCfg,
"ZoomNoCenter",
"input.center_on_zoom" );
531 if( std::optional<bool> value = Get<bool>(
"input.center_on_zoom" ) )
532 Set(
"input.center_on_zoom", !( *value ) );
534 ret &= fromLegacy<int>( aCfg,
"OpenGLAntialiasingMode",
"graphics.opengl_antialiasing_mode" );
535 ret &= fromLegacy<int>( aCfg,
"CairoAntialiasingMode",
"graphics.cairo_antialiasing_mode" );
537 ret &= fromLegacy<int>( aCfg,
"AutoSaveInterval",
"system.autosave_interval" );
539 ret &= fromLegacy<int>( aCfg,
"FileHistorySize",
"system.file_history_size" );
541 ret &=
fromLegacyString( aCfg,
"PdfBrowserName",
"system.pdf_viewer_name" );
542 ret &= fromLegacy<bool>( aCfg,
"UseSystemBrowser",
"system.use_system_pdf_viewer" );
552 [&](
const wxString& aKey,
const wxString& aDefault )
558 if( wxGetEnv( aKey, &envValue ) ==
true && !envValue.IsEmpty() )
563 wxS(
"InitializeEnvironment: Entry %s defined externally as %s" ), aKey,
568 wxLogTrace(
traceEnvVars, wxS(
"InitializeEnvironment: Setting entry %s to default %s" ),
575 wxFileName
path( basePath );
576 path.AppendDir( wxT(
"footprints" ) );
577 addVar( wxT(
"KICAD7_FOOTPRINT_DIR" ),
path.GetFullPath() );
580 path.AppendDir( wxT(
"3dmodels" ) );
581 addVar( wxT(
"KICAD7_3DMODEL_DIR" ),
path.GetFullPath() );
590 path.AppendDir( wxT(
"symbols" ) );
591 addVar( wxT(
"KICAD7_SYMBOL_DIR" ),
path.GetFullPath() );
596 std::vector<LEGACY_3D_SEARCH_PATH>& aSearchPaths )
598 wxFileName cfgpath(
path );
604 wxString cfgname = cfgpath.GetFullPath();
606 std::ifstream cfgFile;
609 if( !wxFileName::Exists( cfgname ) )
611 std::ostringstream ostr;
612 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
613 wxString errmsg =
"no 3D configuration file";
614 ostr <<
" * " << errmsg.ToUTF8() <<
" '";
615 ostr << cfgname.ToUTF8() <<
"'";
620 cfgFile.open( cfgname.ToUTF8() );
622 if( !cfgFile.is_open() )
624 std::ostringstream ostr;
625 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
626 wxString errmsg = wxS(
"Could not open configuration file" );
627 ostr <<
" * " << errmsg.ToUTF8() <<
" '" << cfgname.ToUTF8() <<
"'";
628 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
637 while( cfgFile.good() )
640 std::getline( cfgFile, cfgLine );
643 if( cfgLine.empty() )
651 if( 1 == lineno && cfgLine.compare( 0, 2,
"#V" ) == 0 )
654 if( cfgLine.size() > 2 )
656 std::istringstream istr;
657 istr.str( cfgLine.substr( 2 ) );
671 if( al.
m_Alias == wxS(
"${KICAD7_3DMODEL_DIR}" ) || al.
m_Alias == wxS(
"${KIPRJMOD}" )
672 || al.
m_Alias == wxS(
"$(KIPRJMOD)" ) || al.
m_Alias == wxS(
"${KISYS3DMOD}" )
673 || al.
m_Alias == wxS(
"$(KISYS3DMOD)" ) )
684 aSearchPaths.push_back( al );
698 if( aIndex >= aString.size() )
700 std::ostringstream ostr;
701 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
702 wxString errmsg = wxS(
"bad Hollerith string on line" );
703 ostr <<
" * " << errmsg.ToUTF8() <<
"\n'" << aString <<
"'";
704 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
709 size_t i2 = aString.find(
'"', aIndex );
711 if( std::string::npos == i2 )
713 std::ostringstream ostr;
714 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
715 wxString errmsg = wxS(
"missing opening quote mark in config file" );
716 ostr <<
" * " << errmsg.ToUTF8() <<
"\n'" << aString <<
"'";
717 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
724 if( i2 >= aString.size() )
726 std::ostringstream ostr;
727 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
728 wxString errmsg = wxS(
"invalid entry (unexpected end of line)" );
729 ostr <<
" * " << errmsg.ToUTF8() <<
"\n'" << aString <<
"'";
730 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
737 while( aString[i2] >=
'0' && aString[i2] <=
'9' )
738 tnum.append( 1, aString[i2++] );
740 if( tnum.empty() || aString[i2++] !=
':' )
742 std::ostringstream ostr;
743 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
744 wxString errmsg = wxS(
"bad Hollerith string on line" );
745 ostr <<
" * " << errmsg.ToUTF8() <<
"\n'" << aString <<
"'";
746 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
751 std::istringstream istr;
756 if( ( i2 + nchars ) >= aString.size() )
758 std::ostringstream ostr;
759 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
760 wxString errmsg = wxS(
"invalid entry (unexpected end of line)" );
761 ostr <<
" * " << errmsg.ToUTF8() <<
"\n'" << aString <<
"'";
762 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
769 aResult = wxString::FromUTF8( aString.substr( i2, nchars ).c_str() );
773 if( i2 >= aString.size() || aString[i2] !=
'"' )
775 std::ostringstream ostr;
776 ostr << __FILE__ <<
": " << __FUNCTION__ <<
": " << __LINE__ <<
"\n";
777 wxString errmsg = wxS(
"missing closing quote mark in config file" );
778 ostr <<
" * " << errmsg.ToUTF8() <<
"\n'" << aString <<
"'";
779 wxLogTrace(
traceSettings, wxS(
"%s\n" ), ostr.str().c_str() );
static bool getLegacy3DHollerith(const std::string &aString, size_t &aIndex, wxString &aResult)
bool readLegacy3DResolverCfg(const wxString &aPath, std::vector< LEGACY_3D_SEARCH_PATH > &aSearchPaths)
void InitializeEnvironment()
Creates the built-in environment variables and sets their default values.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
KiCad uses environment variables internally for determining the base paths for libraries,...
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)
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
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...
Stores an enum as an integer.
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
static wxString GetStockEDALibraryPath()
Gets the stock (install) EDA library data path, which is the base path for templates,...
static wxString GetDefault3rdPartyPath()
Gets the default path for PCM packages.
static wxString GetStockTemplatesPath()
Gets the stock (install) templates path.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
const std::set< wxString > envVarBlacklist
! The following environment variables will never be migrated from a previous version
const int commonSchemaVersion
! Update the schema version whenever a migration is required
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.
@ USER
The main config directory (e.g. ~/.config/kicad/)
bool apply_icon_scale_to_fonts
double hicontrast_dimming_factor
int min_interval
Minimum time, in seconds, between subsequent backups.
bool backup_on_autosave
Trigger a backup on autosave.
unsigned long long limit_total_size
Maximum total size of backups (bytes), 0 for unlimited.
int limit_total_files
Maximum number of backup archives to retain.
int limit_daily_files
Maximum files to keep per day, 0 for unlimited.
bool enabled
Automatically back up the project when files are saved.
System directories search utilities.
wxLogTrace helper definitions.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().