2020-01-13 01:44:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COLOR_SETTINGS_H
|
|
|
|
#define _COLOR_SETTINGS_H
|
|
|
|
|
|
|
|
#include <gal/color4d.h>
|
|
|
|
#include <settings/json_settings.h>
|
|
|
|
|
|
|
|
using KIGFX::COLOR4D;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Color settings are a bit different than most of the settings objects in that there
|
|
|
|
* can be more than one of them loaded at once.
|
|
|
|
*
|
|
|
|
* Each COLOR_SETTINGS object corresponds to a single color scheme file on disk.
|
|
|
|
* The default color scheme is called "default" and will be created on first run.
|
|
|
|
*
|
|
|
|
* When users change color settings, they have the option of modifying the default scheme
|
|
|
|
* or saving their changes to a new color scheme file.
|
|
|
|
*
|
|
|
|
* Each COLOR_SETTINGS defines all the settings used across all parts of KiCad, but it's not
|
|
|
|
* necessary for the underlying theme file to contain all of them. The color settings cascade,
|
|
|
|
* so if a user chooses a non-default scheme for a certain application, and that non-default
|
|
|
|
* scheme file is missing some color definitions, those will fall back to those from the "default"
|
|
|
|
* scheme (which is either loaded from disk or created if missing)
|
|
|
|
*
|
|
|
|
* Each application (eeschema, gerbview, pcbnew) can have a different active color scheme selected.
|
|
|
|
* The "child applications" (library editors) inherit from either eeschema or pcbnew.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <settings/json_settings.h>
|
|
|
|
#include <settings/parameters.h>
|
|
|
|
|
|
|
|
|
|
|
|
class COLOR_SETTINGS : public JSON_SETTINGS
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2020-04-09 16:15:57 +00:00
|
|
|
* m_Pallete stores a list of colors that are used, in order, when a list of colors needs to
|
|
|
|
* be generated for an application. For example, layer colors in GerbView, or default layer
|
|
|
|
* colors in PcbNew.
|
2020-01-13 01:44:19 +00:00
|
|
|
*/
|
|
|
|
std::vector<COLOR4D> m_Palette;
|
|
|
|
|
2020-08-02 09:23:21 +00:00
|
|
|
explicit COLOR_SETTINGS( wxString aFilename = "user" );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
virtual ~COLOR_SETTINGS() {}
|
|
|
|
|
2020-07-04 02:34:16 +00:00
|
|
|
/**
|
|
|
|
* Copy ctor provided for temporary manipulation of themes in the theme editor.
|
|
|
|
* This will not copy the JSON_SETTINGS underlying data.
|
|
|
|
*/
|
|
|
|
COLOR_SETTINGS( const COLOR_SETTINGS& aOther );
|
|
|
|
|
|
|
|
COLOR_SETTINGS& operator=( const COLOR_SETTINGS &aOther );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
bool MigrateFromLegacy( wxConfigBase* aCfg ) override;
|
|
|
|
|
2020-05-06 01:45:48 +00:00
|
|
|
bool Migrate() override;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
COLOR4D GetColor( int aLayer ) const;
|
|
|
|
|
|
|
|
COLOR4D GetDefaultColor( int aLayer );
|
|
|
|
|
|
|
|
void SetColor( int aLayer, COLOR4D aColor );
|
|
|
|
|
2020-04-09 16:15:57 +00:00
|
|
|
const wxString& GetName() const { return m_displayName; }
|
|
|
|
void SetName( const wxString& aName ) { m_displayName = aName; }
|
2020-02-03 16:46:58 +00:00
|
|
|
|
2020-04-09 16:15:57 +00:00
|
|
|
bool GetOverrideSchItemColors() const { return m_overrideSchItemColors; }
|
|
|
|
void SetOverrideSchItemColors( bool aFlag ) { m_overrideSchItemColors = aFlag; }
|
2020-02-03 16:46:58 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
private:
|
2020-05-06 01:45:48 +00:00
|
|
|
bool migrateSchema0to1();
|
2020-10-03 01:07:35 +00:00
|
|
|
bool migrateSchema1to2();
|
2020-05-06 01:45:48 +00:00
|
|
|
|
2020-07-08 16:19:10 +00:00
|
|
|
void initFromOther( const COLOR_SETTINGS& aOther );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
wxString m_displayName;
|
2020-05-06 01:45:48 +00:00
|
|
|
|
2020-04-09 16:15:57 +00:00
|
|
|
bool m_overrideSchItemColors;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map of all layer colors.
|
|
|
|
* The key needs to be a valid layer ID, see layers_id_colors_and_visibility.h
|
|
|
|
*/
|
|
|
|
std::unordered_map<int, COLOR4D> m_colors;
|
|
|
|
|
|
|
|
std::unordered_map<int, COLOR4D> m_defaultColors;
|
|
|
|
};
|
|
|
|
|
|
|
|
class COLOR_MAP_PARAM : public PARAM_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
COLOR_MAP_PARAM( const std::string& aJsonPath, int aMapKey, COLOR4D aDefault,
|
|
|
|
std::unordered_map<int, COLOR4D>* aMap, bool aReadOnly = false ) :
|
|
|
|
PARAM_BASE( aJsonPath, aReadOnly ), m_key( aMapKey ), m_default( aDefault ),
|
|
|
|
m_map( aMap )
|
|
|
|
{}
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
|
|
|
if( m_readOnly )
|
|
|
|
return;
|
|
|
|
|
2020-03-07 21:06:33 +00:00
|
|
|
if( OPT<COLOR4D> optval = aSettings->Get<COLOR4D>( m_path ) )
|
2020-05-31 21:42:04 +00:00
|
|
|
( *m_map )[ m_key ] = *optval;
|
|
|
|
else if( aResetIfMissing )
|
|
|
|
( *m_map )[ m_key ] = m_default;
|
2020-01-13 01:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Store( JSON_SETTINGS* aSettings) const override
|
|
|
|
{
|
|
|
|
aSettings->Set<COLOR4D>( m_path, ( *m_map )[ m_key ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetKey() const
|
|
|
|
{
|
|
|
|
return m_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
COLOR4D GetDefault() const
|
|
|
|
{
|
|
|
|
return m_default;
|
|
|
|
}
|
|
|
|
|
2020-05-30 16:56:16 +00:00
|
|
|
void SetDefault() override
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
|
|
|
( *m_map )[ m_key ] = m_default;
|
|
|
|
}
|
|
|
|
|
2020-05-30 16:56:16 +00:00
|
|
|
bool IsDefault() const override
|
|
|
|
{
|
|
|
|
return ( *m_map )[ m_key ] == m_default;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
|
|
|
{
|
|
|
|
if( OPT<COLOR4D> optval = aSettings->Get<COLOR4D>( m_path ) )
|
|
|
|
return m_map->count( m_key ) && ( *optval == m_map->at( m_key ) );
|
|
|
|
|
|
|
|
// If the JSON doesn't exist, the map shouldn't exist either
|
|
|
|
return !m_map->count( m_key );
|
|
|
|
}
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
private:
|
|
|
|
int m_key;
|
2020-05-30 16:56:16 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
COLOR4D m_default;
|
2020-05-30 16:56:16 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
std::unordered_map<int, COLOR4D>* m_map;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|