KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SETTINGS_MANAGER Class Reference

#include <settings_manager.h>

Public Member Functions

 SETTINGS_MANAGER (bool aHeadless=false)
 
 ~SETTINGS_MANAGER ()
 
bool IsOK ()
 
void SetKiway (KIWAY *aKiway)
 Associate this setting manager with the given Kiway.
 
template<typename T >
T * RegisterSettings (T *aSettings, bool aLoadNow=true)
 Takes ownership of the pointer passed in.
 
void Load ()
 
void Load (JSON_SETTINGS *aSettings)
 
void Save ()
 
void Save (JSON_SETTINGS *aSettings)
 
void FlushAndRelease (JSON_SETTINGS *aSettings, bool aSave=true)
 If the given settings object is registered, save it to disk and unregister it.
 
template<typename T >
T * GetAppSettings ()
 Returns a handle to the a given settings by type If the settings have already been loaded, returns the existing pointer.
 
template<typename T >
T * GetAppSettings (const wxString &aFilename)
 
COLOR_SETTINGSGetColorSettings (const wxString &aName="user")
 Retrieves a color settings object that applications can read colors from.
 
std::vector< COLOR_SETTINGS * > GetColorSettingsList ()
 
void SaveColorSettings (COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
 Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
 
COLOR_SETTINGSAddNewColorSettings (const wxString &aFilename)
 Registers a new color settings object with the given filename.
 
COLOR_SETTINGSGetMigratedColorSettings ()
 Returns a color theme for storing colors migrated from legacy (5.x and earlier) settings, creating the theme if necessary.
 
COMMON_SETTINGSGetCommonSettings () const
 Retrieves the common settings shared by all applications.
 
wxString GetPathForSettingsFile (JSON_SETTINGS *aSettings)
 Returns the path a given settings file should be loaded from / stored to.
 
bool MigrateIfNeeded ()
 Handles the initialization of the user settings directory and migration from previous KiCad versions as needed.
 
void SetMigrationSource (const wxString &aSource)
 Helper for DIALOG_MIGRATE_SETTINGS to specify a source for migration.
 
void SetMigrateLibraryTables (bool aMigrate=true)
 
bool GetPreviousVersionPaths (std::vector< wxString > *aName=nullptr)
 Retrieves the name of the most recent previous KiCad version that can be found in the user settings directory.
 
void ReloadColorSettings ()
 Re-scans the color themes directory, reloading any changes it finds.
 
bool LoadProject (const wxString &aFullPath, bool aSetActive=true)
 Loads a project or sets up a new project with a specified path.
 
bool UnloadProject (PROJECT *aProject, bool aSave=true)
 Saves, unloads and unregisters the given PROJECT.
 
bool IsProjectOpen () const
 Helper for checking if we have a project open TODO: This should be deprecated along with Prj() once we support multiple projects fully.
 
bool IsProjectOpenNotDummy () const
 Helper for checking if we have a project open that is not a dummy project.
 
PROJECTPrj () const
 A helper while we are not MDI-capable – return the one and only project.
 
PROJECTGetProject (const wxString &aFullPath) const
 Retrieves a loaded project by name.
 
std::vector< wxString > GetOpenProjects () const
 
bool SaveProject (const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
 Saves a loaded project.
 
void SaveProjectAs (const wxString &aFullPath, PROJECT *aProject=nullptr)
 Sets the currently loaded project path and saves it (pointers remain valid) Note that this will not modify the read-only state of the project, so it will have no effect if the project is marked as read-only!
 
void SaveProjectCopy (const wxString &aFullPath, PROJECT *aProject=nullptr)
 Saves a copy of the current project under the given path.
 
wxString GetProjectBackupsPath () const
 
bool BackupProject (REPORTER &aReporter, wxFileName &aTarget) const
 Creates a backup archive of the current project.
 
bool TriggerBackupIfNeeded (REPORTER &aReporter) const
 Calls BackupProject if a new backup is needed according to the current backup policy.
 

Static Public Member Functions

static bool IsSettingsPathValid (const wxString &aPath)
 Checks if a given path is probably a valid KiCad configuration directory.
 
static wxString GetColorSettingsPath ()
 Returns the path where color scheme files are stored; creating it if missing (normally .
 
static std::string GetSettingsVersion ()
 Parses the current KiCad build version and extracts the major and minor revision to use as the name of the settings directory for this KiCad version.
 
static wxString GetUserSettingsPath ()
 A proxy for PATHS::GetUserSettingsPath rather than fighting swig.
 

Private Member Functions

JSON_SETTINGSregisterSettings (JSON_SETTINGS *aSettings, bool aLoadNow=true)
 
COLOR_SETTINGSloadColorSettingsByName (const wxString &aName)
 Attempts to load a color theme by name (the color theme directory and .json ext are assumed)
 
COLOR_SETTINGSregisterColorSettings (const wxString &aFilename, bool aAbsolutePath=false)
 
void loadAllColorSettings ()
 
bool loadProjectFile (PROJECT &aProject)
 Registers a PROJECT_FILE and attempts to load it from disk.
 
bool unloadProjectFile (PROJECT *aProject, bool aSave)
 Optionally saves, and then unloads and unregisters the given PROJECT_FILE.
 
void registerBuiltinColorSettings ()
 

Static Private Member Functions

static int compareVersions (const std::string &aFirst, const std::string &aSecond)
 Compares two settings versions, like "5.99" and "6.0".
 
static bool extractVersion (const std::string &aVersionString, int *aMajor=nullptr, int *aMinor=nullptr)
 Extracts the numeric version from a given settings string.
 

Private Attributes

bool m_headless
 True if running outside a UI context.
 
KIWAYm_kiway
 The kiway this settings manager interacts with.
 
std::vector< std::unique_ptr< JSON_SETTINGS > > m_settings
 
std::unordered_map< wxString, COLOR_SETTINGS * > m_color_settings
 
std::unordered_map< size_t, JSON_SETTINGS * > m_app_settings_cache
 Cache for app settings.
 
COMMON_SETTINGSm_common_settings
 
wxString m_migration_source
 
bool m_migrateLibraryTables
 If true, the symbol and footprint library tables will be migrated from the previous version.
 
bool m_ok
 True if settings loaded successfully at construction.
 
std::vector< std::unique_ptr< PROJECT > > m_projects_list
 Loaded projects (ownership here)
 
std::map< wxString, PROJECT * > m_projects
 Loaded projects, mapped according to project full name.
 
std::map< wxString, PROJECT_FILE * > m_project_files
 Loaded project files, mapped according to project full name.
 
std::unique_ptr< LOCKFILEm_project_lock
 Lock for loaded project (expand to multiple once we support MDI)
 

Static Private Attributes

static wxString backupDateTimeFormat = wxT( "%Y-%m-%d_%H%M%S" )
 

Detailed Description

Definition at line 45 of file settings_manager.h.

Constructor & Destructor Documentation

◆ SETTINGS_MANAGER()

◆ ~SETTINGS_MANAGER()

SETTINGS_MANAGER::~SETTINGS_MANAGER ( )

Definition at line 84 of file settings_manager.cpp.

References m_color_settings, m_projects, m_projects_list, m_settings, and project.

Member Function Documentation

◆ AddNewColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::AddNewColorSettings ( const wxString &  aFilename)

Registers a new color settings object with the given filename.

Parameters
aFilenameis the location to store the new settings object
Returns
a pointer to the new object

Definition at line 311 of file settings_manager.cpp.

References registerColorSettings().

Referenced by FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), COLOR_SETTINGS::migrateSchema0to1(), and PANEL_COLOR_SETTINGS::OnThemeChanged().

◆ BackupProject()

bool SETTINGS_MANAGER::BackupProject ( REPORTER aReporter,
wxFileName &  aTarget 
) const

Creates a backup archive of the current project.

Parameters
aReporteris used for progress reporting
aTargetis the full path to the backup file. If empty, will generate and return the full path to the backup file.
Returns
true if everything succeeded

Definition at line 1224 of file settings_manager.cpp.

References PROJECT_ARCHIVER::Archive(), FILEEXT::ArchiveFileExtension, backupDateTimeFormat, GetProjectBackupsPath(), Prj(), and traceSettings.

Referenced by TriggerBackupIfNeeded().

◆ compareVersions()

int SETTINGS_MANAGER::compareVersions ( const std::string &  aFirst,
const std::string &  aSecond 
)
staticprivate

Compares two settings versions, like "5.99" and "6.0".

Returns
-1 if aFirst is older than aSecond, 1 if aFirst is newer than aSecond, 0 otherwise

Definition at line 823 of file settings_manager.cpp.

References extractVersion(), and traceSettings.

Referenced by GetPreviousVersionPaths().

◆ extractVersion()

bool SETTINGS_MANAGER::extractVersion ( const std::string &  aVersionString,
int *  aMajor = nullptr,
int *  aMinor = nullptr 
)
staticprivate

Extracts the numeric version from a given settings string.

Parameters
aVersionStringis the string to split at the "."
aMajorwill store the first part
aMinorwill store the second part
Returns
true if extraction succeeded

Definition at line 863 of file settings_manager.cpp.

Referenced by compareVersions(), and GetPreviousVersionPaths().

◆ FlushAndRelease()

void SETTINGS_MANAGER::FlushAndRelease ( JSON_SETTINGS aSettings,
bool  aSave = true 
)

If the given settings object is registered, save it to disk and unregister it.

Parameters
aSettingsis the object to release

Definition at line 178 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_app_settings_cache, m_settings, and traceSettings.

Referenced by BIN_MOD::End(), CV::IFACE::OnKifaceStart(), SCH::IFACE::OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and unloadProjectFile().

◆ GetAppSettings() [1/2]

template<typename T >
T * SETTINGS_MANAGER::GetAppSettings ( )
inline

Returns a handle to the a given settings by type If the settings have already been loaded, returns the existing pointer.

If the settings have not been loaded, creates a new object owned by the settings manager and returns a pointer to it.

Template Parameters
Tis a type derived from APP_SETTINGS_BASE
Parameters
aLoadNowis true to load the registered file from disk immediately
Returns
a pointer to a loaded settings object

Definition at line 100 of file settings_manager.h.

Referenced by PANEL_DESIGN_BLOCK_LIB_TABLE::browseLibrariesHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), DIALOG_FOOTPRINT_CHOOSER::build3DCanvas(), FOOTPRINT_CHOOSER_FRAME::build3DCanvas(), UPDATE_MANAGER::CheckForUpdate(), SCH_EDIT_FRAME::CommonSettingsChanged(), SYMBOL_EDIT_FRAME::CommonSettingsChanged(), SYMBOL_VIEWER_FRAME::CommonSettingsChanged(), GERBVIEW_FRAME::CommonSettingsChanged(), PL_EDITOR_FRAME::CommonSettingsChanged(), FOOTPRINT_EDIT_FRAME::CommonSettingsChanged(), FOOTPRINT_EDIT_FRAME::config(), PANEL_SYMBOL_CHOOSER::constructRightPanel(), PCB::IFACE::CreateKiWindow(), DESIGN_BLOCK_PREVIEW_WIDGET::DESIGN_BLOCK_PREVIEW_WIDGET(), DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST(), SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape(), SCH_MOVE_TOOL::doMoveSelection(), GRID_CELL_LAYER_RENDERER::Draw(), EVT_TOOL_RANGE(), PCB_EDITOR_CONDITIONS::get45degModeFunc(), PCB_EDIT_FRAME::GetActionPluginButtonVisible(), FOOTPRINT_CHOOSER_FRAME::GetColorSettings(), DISPLAY_FOOTPRINTS_FRAME::GetColorSettings(), SCH_BASE_FRAME::GetColorSettings(), SYMBOL_EDIT_FRAME::GetColorSettings(), GERBVIEW_FRAME::GetColorSettings(), FOOTPRINT_VIEWER_FRAME::GetColorSettings(), SCH_ITEM::GetDefaultFont(), PCB_BASE_FRAME::GetFootprintEditorSettings(), GetLastPinLength(), GetLastPinNameSize(), GetLastPinNumSize(), PCB_LAYER_PRESENTATION::getLayerColor(), DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings(), PCB_EDIT_FRAME::GetOrderedActionPlugins(), PCB_BASE_FRAME::GetPcbNewSettings(), FOOTPRINT_EDIT_FRAME::GetSettings(), SCH_BASE_FRAME::GetViewerSettingsBase(), PCB_BASE_FRAME::GetViewerSettingsBase(), DISPLAY_FOOTPRINTS_FRAME::GetViewerSettingsBase(), DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings(), gvconfig(), IfaceOrAddress(), DIALOG_EXPORT_2581::Init(), DIALOG_EXPORT_ODBPP::Init(), PCB_TOOL_BASE::Is45Limited(), PCBNEW_JOBS_HANDLER::JobExportRender(), DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), PANEL_PREVIEW_3D_MODEL::loadSettings(), SYMBOL_VIEWER_FRAME::LoadSettings(), FOOTPRINT_VIEWER_FRAME::LoadSettings(), PCB_VIEWER_TOOLS::MeasureTool(), EESCHEMA_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), FOOTPRINT_PREVIEW_PANEL::New(), KICAD_MANAGER_CONTROL::NewFromTemplate(), PANEL_PACKAGES_VIEW::OnDownloadVersionClicked(), PCB::IFACE::OnKifaceStart(), DIALOG_PCM::OnManageRepositoriesClicked(), PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER(), PANEL_DESIGN_BLOCK_LIB_TABLE::PANEL_DESIGN_BLOCK_LIB_TABLE(), PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(), PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS(), PANEL_GERBVIEW_DISPLAY_OPTIONS::PANEL_GERBVIEW_DISPLAY_OPTIONS(), PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER(), PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES(), PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL(), DIALOG_PLOT::Plot(), POSITION_RELATIVE_TOOL::PositionRelativeInteractively(), EDA_3D_VIEWER_FRAME::Process_Special_Functions(), PIN_LAYOUT_CACHE::recomputeCaches(), BOARD_ADAPTER::ReloadColorSettings(), EDA_3D_CANVAS::RenderEngineChanged(), SCH_EDIT_TOOL::RepeatDrawItem(), SYMBOL_EDITOR_PIN_TOOL::RepeatPin(), SaveFileAs(), EDA_3D_VIEWER_FRAME::SaveSettings(), SYMBOL_VIEWER_FRAME::SaveSettings(), SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), PCB_TEST_FRAME_BASE::SetBoard(), PANEL_SYM_LIB_TABLE::setupGrid(), PANEL_FP_LIB_TABLE::setupGrid(), PIN_TABLE_DATA_MODEL::SetValue(), KICAD_MANAGER_CONTROL::ShowPluginManager(), SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME(), SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET(), EDA_3D_VIEWER_FRAME::ToggleAppearanceManager(), DRAWING_TOOL::ToggleHV45Mode(), PANEL_3D_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow(), PANEL_3D_RAYTRACING_OPTIONS::TransferDataFromWindow(), PANEL_PACKAGES_AND_UPDATES::TransferDataFromWindow(), PANEL_EESCHEMA_ANNOTATION_OPTIONS::TransferDataFromWindow(), PANEL_EESCHEMA_COLOR_SETTINGS::TransferDataFromWindow(), PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_EESCHEMA_EDITING_OPTIONS::TransferDataFromWindow(), PANEL_SIMULATOR_PREFERENCES::TransferDataFromWindow(), PANEL_SYM_COLOR_SETTINGS::TransferDataFromWindow(), PANEL_SYM_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_SYM_EDITING_OPTIONS::TransferDataFromWindow(), PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow(), PANEL_GERBVIEW_COLOR_SETTINGS::TransferDataFromWindow(), PANEL_GERBVIEW_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_GERBVIEW_EXCELLON_SETTINGS::TransferDataFromWindow(), DIALOG_UPDATE_CHECK_PROMPT::TransferDataFromWindow(), PANEL_PL_EDITOR_COLOR_SETTINGS::TransferDataFromWindow(), DIALOG_EXPORT_2581::TransferDataFromWindow(), DIALOG_EXPORT_ODBPP::TransferDataFromWindow(), PANEL_EDIT_OPTIONS::TransferDataFromWindow(), PANEL_FP_EDITOR_COLOR_SETTINGS::TransferDataFromWindow(), PANEL_FP_EDITOR_DEFAULTS::TransferDataFromWindow(), PANEL_PCB_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_PCBNEW_COLOR_SETTINGS::TransferDataFromWindow(), PANEL_3D_DISPLAY_OPTIONS::TransferDataToWindow(), PANEL_3D_OPENGL_OPTIONS::TransferDataToWindow(), PANEL_3D_RAYTRACING_OPTIONS::TransferDataToWindow(), PANEL_PACKAGES_AND_UPDATES::TransferDataToWindow(), PANEL_EESCHEMA_ANNOTATION_OPTIONS::TransferDataToWindow(), PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataToWindow(), PANEL_EESCHEMA_EDITING_OPTIONS::TransferDataToWindow(), PANEL_SIMULATOR_PREFERENCES::TransferDataToWindow(), PANEL_SYM_COLOR_SETTINGS::TransferDataToWindow(), PANEL_SYM_DISPLAY_OPTIONS::TransferDataToWindow(), PANEL_SYM_EDITING_OPTIONS::TransferDataToWindow(), PANEL_GERBVIEW_DISPLAY_OPTIONS::TransferDataToWindow(), PANEL_GERBVIEW_EXCELLON_SETTINGS::TransferDataToWindow(), PANEL_PL_EDITOR_COLOR_SETTINGS::TransferDataToWindow(), PANEL_EDIT_OPTIONS::TransferDataToWindow(), PANEL_FP_EDITOR_DEFAULTS::TransferDataToWindow(), PANEL_PCB_DISPLAY_OPTIONS::TransferDataToWindow(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), PCB_DRAW_PANEL_GAL::UpdateColors(), DRAWING_TOOL::UpdateStatusBar(), KIGFX::PCB_PAINTER::viewer_settings(), DIALOG_FOOTPRINT_WIZARD_LIST::~DIALOG_FOOTPRINT_WIZARD_LIST(), PANEL_FOOTPRINT_CHOOSER::~PANEL_FOOTPRINT_CHOOSER(), and SYMBOL_EDIT_FRAME::~SYMBOL_EDIT_FRAME().

◆ GetAppSettings() [2/2]

template<typename T >
T * SETTINGS_MANAGER::GetAppSettings ( const wxString &  aFilename)
inline

Definition at line 132 of file settings_manager.h.

◆ GetColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::GetColorSettings ( const wxString &  aName = "user")

Retrieves a color settings object that applications can read colors from.

If the given settings file cannot be found, returns the default settings.

Parameters
aNameis the name of the color scheme to load
Returns
a loaded COLOR_SETTINGS object

Definition at line 204 of file settings_manager.cpp.

References COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT, loadColorSettingsByName(), m_color_settings, registerColorSettings(), JSON_SETTINGS::SetFilename(), and JSON_SETTINGS::SetReadOnly().

Referenced by PL_EDITOR_FRAME::CommonSettingsChanged(), DESIGN_BLOCK_PREVIEW_WIDGET::DESIGN_BLOCK_PREVIEW_WIDGET(), GRID_CELL_LAYER_RENDERER::Draw(), GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL(), BOARD_ADAPTER::GetBoardEditorCopperLayerColors(), SCH_MARKER::getColor(), PCB_MARKER::getColor(), DIALOG_PLOT_SCHEMATIC::getColorSettings(), FOOTPRINT_CHOOSER_FRAME::GetColorSettings(), EDA_DRAW_FRAME::GetColorSettings(), DISPLAY_FOOTPRINTS_FRAME::GetColorSettings(), SCH_BASE_FRAME::GetColorSettings(), SYMBOL_EDIT_FRAME::GetColorSettings(), GERBVIEW_FRAME::GetColorSettings(), FOOTPRINT_EDIT_FRAME::GetColorSettings(), FOOTPRINT_VIEWER_FRAME::GetColorSettings(), FOOTPRINT_WIZARD_FRAME::GetColorSettings(), PCB_BASE_EDIT_FRAME::GetColorSettings(), PCB_LAYER_PRESENTATION::getLayerColor(), GetLayerColor(), BOARD_ADAPTER::GetLayerColors(), EESCHEMA_JOBS_HANDLER::InitRenderSettings(), PCBNEW_JOBS_HANDLER::JobExportPdf(), EESCHEMA_JOBS_HANDLER::JobSymExportSvg(), PANEL_EESCHEMA_EDITING_OPTIONS::loadEEschemaSettings(), PCB_TEST_FRAME_BASE::LoadSettings(), PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS(), PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS(), PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL(), EXPORT_SVG::Plot(), SCH_PLOTTER::Plot(), SCH_SHEET::Plot(), DIALOG_PLOT::Plot(), SCH_SYMBOL::PlotDNP(), SCH_PRINTOUT::PrintPage(), BOARD_ADAPTER::ReloadColorSettings(), PANEL_COLOR_SETTINGS::saveCurrentTheme(), GERBVIEW_FRAME::SaveSettings(), SCH_DRAW_PANEL::SCH_DRAW_PANEL(), BOARD_ADAPTER::SetLayerColors(), SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET(), PANEL_SYM_COLOR_SETTINGS::TransferDataToWindow(), PANEL_PL_EDITOR_COLOR_SETTINGS::TransferDataToWindow(), and PCB_DRAW_PANEL_GAL::UpdateColors().

◆ GetColorSettingsList()

◆ GetColorSettingsPath()

wxString SETTINGS_MANAGER::GetColorSettingsPath ( )
static

Returns the path where color scheme files are stored; creating it if missing (normally .

/colors/ under the user settings path)

Definition at line 795 of file settings_manager.cpp.

References PATHS::GetUserSettingsPath(), path, and traceSettings.

Referenced by GetPathForSettingsFile(), loadAllColorSettings(), loadColorSettingsByName(), PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked(), PANEL_COLOR_SETTINGS::OnThemeChanged(), and SaveColorSettings().

◆ GetCommonSettings()

COMMON_SETTINGS * SETTINGS_MANAGER::GetCommonSettings ( ) const
inline

Retrieves the common settings shared by all applications.

Returns
a pointer to a loaded COMMON_SETTINGS

Definition at line 220 of file settings_manager.h.

Referenced by GetLanguage(), PANEL_PLUGIN_SETTINGS::TransferDataFromWindow(), PANEL_PLUGIN_SETTINGS::TransferDataToWindow(), and TriggerBackupIfNeeded().

◆ GetMigratedColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::GetMigratedColorSettings ( )

Returns a color theme for storing colors migrated from legacy (5.x and earlier) settings, creating the theme if necessary.

This theme will be called "user.json" / "User".

Returns
the color settings to be used for migrating legacy settings

Definition at line 320 of file settings_manager.cpp.

References m_color_settings, registerColorSettings(), Save(), and COLOR_SETTINGS::SetName().

Referenced by EESCHEMA_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), and PCBNEW_SETTINGS::MigrateFromLegacy().

◆ GetOpenProjects()

std::vector< wxString > SETTINGS_MANAGER::GetOpenProjects ( ) const
Returns
a list of open projects

Definition at line 1054 of file settings_manager.cpp.

References m_projects.

Referenced by KICAD_MANAGER_FRAME::canCloseWindow(), and KICAD_MANAGER_FRAME::SaveSettings().

◆ GetPathForSettingsFile()

wxString SETTINGS_MANAGER::GetPathForSettingsFile ( JSON_SETTINGS aSettings)

Returns the path a given settings file should be loaded from / stored to.

Parameters
aSettingsis the settings object
Returns
a path based on aSettings->m_location

Definition at line 436 of file settings_manager.cpp.

References GetColorSettingsPath(), JSON_SETTINGS::GetLocation(), PROJECT::GetProjectPath(), PATHS::GetUserSettingsPath(), and Prj().

Referenced by FlushAndRelease(), Load(), MigrateIfNeeded(), PANEL_COLOR_SETTINGS::OnThemeChanged(), registerSettings(), Save(), SETTINGS_MANAGER(), and unloadProjectFile().

◆ GetPreviousVersionPaths()

bool SETTINGS_MANAGER::GetPreviousVersionPaths ( std::vector< wxString > *  aName = nullptr)

Retrieves the name of the most recent previous KiCad version that can be found in the user settings directory.

For legacy versions (5.x, and 5.99 builds before this code was written), this will return "5.x"

Parameters
aNameis filled with the name of the previous version, if one exists
Returns
true if a previous version to migrate from exists

Definition at line 642 of file settings_manager.cpp.

References PATHS::CalculateUserSettingsPath(), compareVersions(), alg::delete_if(), extractVersion(), GetSettingsVersion(), IsSettingsPathValid(), and traceSettings.

Referenced by DIALOG_MIGRATE_SETTINGS::TransferDataToWindow().

◆ GetProject()

PROJECT * SETTINGS_MANAGER::GetProject ( const wxString &  aFullPath) const

Retrieves a loaded project by name.

Parameters
aFullPathis the full path including name and extension to the project file
Returns
a pointer to the project if loaded, or nullptr

Definition at line 1045 of file settings_manager.cpp.

References m_projects.

Referenced by GetDefaultProject(), EESCHEMA_HELPERS::GetDefaultProject(), LoadBoard(), EESCHEMA_HELPERS::LoadSchematic(), NewBoard(), DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction(), and DIALOG_BOARD_SETUP::onAuxiliaryAction().

◆ GetProjectBackupsPath()

wxString SETTINGS_MANAGER::GetProjectBackupsPath ( ) const
Returns
the full path to where project backups should be stored

Definition at line 1215 of file settings_manager.cpp.

References PROJECT::GetProjectName(), PROJECT::GetProjectPath(), Prj(), and PROJECT_BACKUPS_DIR_SUFFIX.

Referenced by BackupProject(), and TriggerBackupIfNeeded().

◆ GetSettingsVersion()

std::string SETTINGS_MANAGER::GetSettingsVersion ( )
static

Parses the current KiCad build version and extracts the major and minor revision to use as the name of the settings directory for this KiCad version.

Returns
a string such as "5.1"

Definition at line 816 of file settings_manager.cpp.

References GetMajorMinorVersion().

Referenced by GetPreviousVersionPaths(), and DIALOG_MIGRATE_SETTINGS::TransferDataToWindow().

◆ GetUserSettingsPath()

wxString SETTINGS_MANAGER::GetUserSettingsPath ( )
static

A proxy for PATHS::GetUserSettingsPath rather than fighting swig.

Definition at line 1449 of file settings_manager.cpp.

References PATHS::GetUserSettingsPath().

◆ IsOK()

bool SETTINGS_MANAGER::IsOK ( )
inline
Returns
true if settings load was successful

Definition at line 55 of file settings_manager.h.

◆ IsProjectOpen()

bool SETTINGS_MANAGER::IsProjectOpen ( ) const

Helper for checking if we have a project open TODO: This should be deprecated along with Prj() once we support multiple projects fully.

Returns
true if a call to Prj() will succeed

Definition at line 1033 of file settings_manager.cpp.

References m_projects.

Referenced by FOOTPRINT_EDIT_FRAME::doCloseWindow(), PCB_BASE_EDIT_FRAME::doCloseWindow(), and KICAD_MANAGER_FRAME::GetProjectFileName().

◆ IsProjectOpenNotDummy()

bool SETTINGS_MANAGER::IsProjectOpenNotDummy ( ) const

Helper for checking if we have a project open that is not a dummy project.

Returns
true if a call to Prj() will succeed and the project is not a dummy project

Definition at line 1039 of file settings_manager.cpp.

References m_projects.

◆ IsSettingsPathValid()

bool SETTINGS_MANAGER::IsSettingsPathValid ( const wxString &  aPath)
static

Checks if a given path is probably a valid KiCad configuration directory.

Actually it just checks if a file called "kicad_common" exists, because that's probably good enough for now.

Parameters
aPathis the path to check
Returns
true if the path contains KiCad settings

Definition at line 782 of file settings_manager.cpp.

Referenced by GetPreviousVersionPaths(), and DIALOG_MIGRATE_SETTINGS::validatePath().

◆ Load() [1/2]

void SETTINGS_MANAGER::Load ( )

Definition at line 117 of file settings_manager.cpp.

References GetPathForSettingsFile(), and m_settings.

Referenced by init_unit_test(), and PGM_BASE::InitPgm().

◆ Load() [2/2]

void SETTINGS_MANAGER::Load ( JSON_SETTINGS aSettings)

Definition at line 136 of file settings_manager.cpp.

References GetPathForSettingsFile(), and m_settings.

◆ loadAllColorSettings()

◆ loadColorSettingsByName()

COLOR_SETTINGS * SETTINGS_MANAGER::loadColorSettingsByName ( const wxString &  aName)
private

Attempts to load a color theme by name (the color theme directory and .json ext are assumed)

Parameters
aNameis the filename of the color theme (without the extension or path)
Returns
the loaded settings, or nullptr if load failed

Definition at line 243 of file settings_manager.cpp.

References GetColorSettingsPath(), JSON_SETTINGS::GetFilename(), m_color_settings, RegisterSettings(), and traceSettings.

Referenced by GetColorSettings().

◆ LoadProject()

◆ loadProjectFile()

bool SETTINGS_MANAGER::loadProjectFile ( PROJECT aProject)
private

Registers a PROJECT_FILE and attempts to load it from disk.

Parameters
aProjectis the project object to load the file for
Returns
true if the PROJECT_FILE was successfully loaded

Definition at line 1161 of file settings_manager.cpp.

References PROJECT::GetProjectFullName(), JSON_SETTINGS::LoadFromFile(), m_project_files, path, RegisterSettings(), PROJECT_FILE::SetProject(), and PROJECT::setProjectFile().

Referenced by LoadProject().

◆ MigrateIfNeeded()

bool SETTINGS_MANAGER::MigrateIfNeeded ( )

Handles the initialization of the user settings directory and migration from previous KiCad versions as needed.

This method will check for the existence of the user settings path for this KiCad version. If it exists, settings load will proceed normally using that path.

If that directory is empty or does not exist, the migration wizard will be launched, which will give users the option to migrate settings from a previous KiCad version (if one is found), manually specify a directory to migrate fromm, or start with default settings.

Returns
true if migration was successful or not necessary, false otherwise

Definition at line 539 of file settings_manager.cpp.

References DisplayErrorMessage(), MIGRATION_TRAVERSER::GetErrors(), GetPathForSettingsFile(), PATHS::GetUserSettingsPath(), JSON_SETTINGS::LoadFromFile(), COMMON_SETTINGS::m_Env, m_headless, m_migrateLibraryTables, m_migration_source, path, JSON_SETTINGS::SaveToFile(), DIALOG_SHIM::ShowModal(), traceSettings, and COMMON_SETTINGS::ENVIRONMENT::vars.

Referenced by SETTINGS_MANAGER().

◆ Prj()

◆ registerBuiltinColorSettings()

void SETTINGS_MANAGER::registerBuiltinColorSettings ( )
private

◆ registerColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::registerColorSettings ( const wxString &  aFilename,
bool  aAbsolutePath = false 
)
private

◆ registerSettings()

JSON_SETTINGS * SETTINGS_MANAGER::registerSettings ( JSON_SETTINGS aSettings,
bool  aLoadNow = true 
)
private

Definition at line 100 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_settings, and traceSettings.

◆ RegisterSettings()

template<typename T >
T * SETTINGS_MANAGER::RegisterSettings ( T *  aSettings,
bool  aLoadNow = true 
)
inline

◆ ReloadColorSettings()

void SETTINGS_MANAGER::ReloadColorSettings ( )

Re-scans the color themes directory, reloading any changes it finds.

Definition at line 389 of file settings_manager.cpp.

References loadAllColorSettings(), and m_color_settings.

Referenced by PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), and KICAD_MANAGER_CONTROL::ShowPluginManager().

◆ Save() [1/2]

◆ Save() [2/2]

void SETTINGS_MANAGER::Save ( JSON_SETTINGS aSettings)

Definition at line 162 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_settings, and traceSettings.

◆ SaveColorSettings()

void SETTINGS_MANAGER::SaveColorSettings ( COLOR_SETTINGS aSettings,
const std::string &  aNamespace = "" 
)

◆ SaveProject()

bool SETTINGS_MANAGER::SaveProject ( const wxString &  aFullPath = wxEmptyString,
PROJECT aProject = nullptr 
)

◆ SaveProjectAs()

void SETTINGS_MANAGER::SaveProjectAs ( const wxString &  aFullPath,
PROJECT aProject = nullptr 
)

Sets the currently loaded project path and saves it (pointers remain valid) Note that this will not modify the read-only state of the project, so it will have no effect if the project is marked as read-only!

Parameters
aFullPathis the full filename to set for the project
aProjectis the project to save, or nullptr to save the active project (Prj() return)

Definition at line 1096 of file settings_manager.cpp.

References PROJECT::GetLocalSettings(), PROJECT::GetProjectFullName(), PROJECT::IsReadOnly(), m_project_files, m_projects, Prj(), project, SaveProject(), PROJECT_LOCAL_SETTINGS::SaveToFile(), JSON_SETTINGS::SetFilename(), PROJECT::setProjectFullName(), and JSON_SETTINGS::SetReadOnly().

Referenced by SaveBoard(), PCB_EDIT_FRAME::SavePcbFile(), and SCH_EDIT_FRAME::SaveProject().

◆ SaveProjectCopy()

void SETTINGS_MANAGER::SaveProjectCopy ( const wxString &  aFullPath,
PROJECT aProject = nullptr 
)

Saves a copy of the current project under the given path.

Will save the copy even if the current project is marked as read-only.

Parameters
aFullPathis the full filename to set for the project
aProjectis the project to save, or nullptr to save the active project (Prj() return)

Definition at line 1135 of file settings_manager.cpp.

References PROJECT::GetLocalSettings(), PROJECT::GetProjectFullName(), m_project_files, Prj(), project, PROJECT_LOCAL_SETTINGS::SaveToFile(), and JSON_SETTINGS::SetFilename().

Referenced by PCB_EDIT_FRAME::OnExportSTEP(), PCB_EDIT_FRAME::SavePcbCopy(), and SCH_EDIT_FRAME::SaveProject().

◆ SetKiway()

void SETTINGS_MANAGER::SetKiway ( KIWAY aKiway)
inline

Associate this setting manager with the given Kiway.

Parameters
aKiwayis the kiway this settings manager should use

Definition at line 62 of file settings_manager.h.

Referenced by PGM_SINGLE_TOP::OnPgmInit(), and PGM_KICAD::OnPgmInit().

◆ SetMigrateLibraryTables()

void SETTINGS_MANAGER::SetMigrateLibraryTables ( bool  aMigrate = true)
inline

Definition at line 250 of file settings_manager.h.

Referenced by DIALOG_MIGRATE_SETTINGS::TransferDataFromWindow().

◆ SetMigrationSource()

void SETTINGS_MANAGER::SetMigrationSource ( const wxString &  aSource)
inline

Helper for DIALOG_MIGRATE_SETTINGS to specify a source for migration.

Parameters
aSourceis a directory containing settings files to migrate from (can be empty)

Definition at line 248 of file settings_manager.h.

Referenced by DIALOG_MIGRATE_SETTINGS::TransferDataFromWindow().

◆ TriggerBackupIfNeeded()

◆ UnloadProject()

◆ unloadProjectFile()

bool SETTINGS_MANAGER::unloadProjectFile ( PROJECT aProject,
bool  aSave 
)
private

Optionally saves, and then unloads and unregisters the given PROJECT_FILE.

Parameters
aProjectis the project object to unload the file for
aSaveif true will save the project file before unloading
Returns
true if the PROJECT file was successfully saved

Definition at line 1179 of file settings_manager.cpp.

References FlushAndRelease(), PROJECT::GetLocalSettings(), GetPathForSettingsFile(), PROJECT::GetProjectFullName(), m_project_files, m_settings, and name.

Referenced by LoadProject(), and UnloadProject().

Member Data Documentation

◆ backupDateTimeFormat

wxString SETTINGS_MANAGER::backupDateTimeFormat = wxT( "%Y-%m-%d_%H%M%S" )
staticprivate

Definition at line 474 of file settings_manager.h.

Referenced by BackupProject(), and TriggerBackupIfNeeded().

◆ m_app_settings_cache

std::unordered_map<size_t, JSON_SETTINGS*> SETTINGS_MANAGER::m_app_settings_cache
private

Cache for app settings.

Definition at line 449 of file settings_manager.h.

Referenced by FlushAndRelease().

◆ m_color_settings

◆ m_common_settings

COMMON_SETTINGS* SETTINGS_MANAGER::m_common_settings
private

Definition at line 452 of file settings_manager.h.

Referenced by SETTINGS_MANAGER().

◆ m_headless

bool SETTINGS_MANAGER::m_headless
private

True if running outside a UI context.

Definition at line 439 of file settings_manager.h.

Referenced by MigrateIfNeeded().

◆ m_kiway

KIWAY* SETTINGS_MANAGER::m_kiway
private

The kiway this settings manager interacts with.

Definition at line 442 of file settings_manager.h.

Referenced by LoadProject(), and UnloadProject().

◆ m_migrateLibraryTables

bool SETTINGS_MANAGER::m_migrateLibraryTables
private

If true, the symbol and footprint library tables will be migrated from the previous version.

Definition at line 457 of file settings_manager.h.

Referenced by MigrateIfNeeded().

◆ m_migration_source

wxString SETTINGS_MANAGER::m_migration_source
private

Definition at line 454 of file settings_manager.h.

Referenced by MigrateIfNeeded().

◆ m_ok

bool SETTINGS_MANAGER::m_ok
private

True if settings loaded successfully at construction.

Definition at line 460 of file settings_manager.h.

Referenced by SETTINGS_MANAGER().

◆ m_project_files

std::map<wxString, PROJECT_FILE*> SETTINGS_MANAGER::m_project_files
private

Loaded project files, mapped according to project full name.

Definition at line 469 of file settings_manager.h.

Referenced by loadProjectFile(), SaveProject(), SaveProjectAs(), SaveProjectCopy(), and unloadProjectFile().

◆ m_project_lock

std::unique_ptr<LOCKFILE> SETTINGS_MANAGER::m_project_lock
private

Lock for loaded project (expand to multiple once we support MDI)

Definition at line 472 of file settings_manager.h.

Referenced by LoadProject(), and UnloadProject().

◆ m_projects

std::map<wxString, PROJECT*> SETTINGS_MANAGER::m_projects
private

Loaded projects, mapped according to project full name.

Definition at line 466 of file settings_manager.h.

Referenced by GetOpenProjects(), GetProject(), IsProjectOpen(), IsProjectOpenNotDummy(), LoadProject(), SaveProjectAs(), UnloadProject(), and ~SETTINGS_MANAGER().

◆ m_projects_list

std::vector<std::unique_ptr<PROJECT> > SETTINGS_MANAGER::m_projects_list
private

Loaded projects (ownership here)

Definition at line 463 of file settings_manager.h.

Referenced by LoadProject(), Prj(), UnloadProject(), and ~SETTINGS_MANAGER().

◆ m_settings

std::vector<std::unique_ptr<JSON_SETTINGS> > SETTINGS_MANAGER::m_settings
private

The documentation for this class was generated from the following files: