ADDED: New color theme editor and multi-theme support

This commit is contained in:
Jon Evans 2020-02-03 17:46:58 +01:00
parent 1e104d5bd4
commit 8660b4c144
40 changed files with 2552 additions and 491 deletions

View File

@ -179,6 +179,8 @@ set( COMMON_DLG_SRCS
dialogs/dialog_print_generic.cpp
dialogs/dialog_print_generic_base.cpp
dialogs/dialog_text_entry.cpp
dialogs/panel_color_settings_base.cpp
dialogs/panel_color_settings.cpp
dialogs/panel_common_settings.cpp
dialogs/panel_common_settings_base.cpp
dialogs/panel_hotkeys_editor.cpp
@ -310,6 +312,7 @@ set( COMMON_SRCS
kiway_player.cpp
languages_menu.cpp
launch_ext.cpp
layer_id.cpp
lib_id.cpp
lib_table_base.cpp
lib_tree_model.cpp

View File

@ -0,0 +1,39 @@
/*
* 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/>.
*/
#include <confirm.h>
#include <launch_ext.h>
#include <panel_color_settings.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
PANEL_COLOR_SETTINGS::PANEL_COLOR_SETTINGS( wxWindow* aParent ) :
PANEL_COLOR_SETTINGS_BASE( aParent )
{
}
void PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked( wxCommandEvent& event )
{
wxString cmd;
wxString dir( Pgm().GetSettingsManager().GetColorSettingsPath() );
LaunchExternal( dir );
}

View File

@ -0,0 +1,39 @@
/*
* 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 PANEL_COLOR_SETTINGS_H
#define PANEL_COLOR_SETTINGS_H
#include <panel_color_settings_base.h>
class PANEL_COLOR_SETTINGS : public PANEL_COLOR_SETTINGS_BASE
{
public:
PANEL_COLOR_SETTINGS( wxWindow* aParent );
~PANEL_COLOR_SETTINGS() = default;
protected:
void OnBtnOpenThemeFolderClicked( wxCommandEvent& event ) override;
};
#endif

View File

@ -0,0 +1,163 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "panel_color_settings_base.h"
///////////////////////////////////////////////////////////////////////////
PANEL_COLOR_SETTINGS_BASE::PANEL_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
m_mainSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bControlSizer;
bControlSizer = new wxBoxSizer( wxHORIZONTAL );
m_staticText9 = new wxStaticText( this, wxID_ANY, _("Theme:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText9->Wrap( -1 );
bControlSizer->Add( m_staticText9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxString m_cbThemeChoices[] = { _("User") };
int m_cbThemeNChoices = sizeof( m_cbThemeChoices ) / sizeof( wxString );
m_cbTheme = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_cbThemeNChoices, m_cbThemeChoices, 0 );
m_cbTheme->SetSelection( 0 );
m_cbTheme->SetMinSize( wxSize( 150,-1 ) );
bControlSizer->Add( m_cbTheme, 0, wxALL, 5 );
m_btnSave = new wxButton( this, wxID_ANY, _("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
m_btnSave->Enable( false );
m_btnSave->SetToolTip( _("Save the active color theme") );
bControlSizer->Add( m_btnSave, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_btnNew = new wxButton( this, wxID_ANY, _("&New"), wxDefaultPosition, wxDefaultSize, 0 );
m_btnNew->SetToolTip( _("Create a new color theme based on the current one") );
bControlSizer->Add( m_btnNew, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_btnRename = new wxButton( this, wxID_ANY, _("Rename"), wxDefaultPosition, wxDefaultSize, 0 );
m_btnRename->Enable( false );
m_btnRename->SetToolTip( _("The \"User\" theme cannot be renamed") );
bControlSizer->Add( m_btnRename, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
bControlSizer->Add( 0, 0, 1, wxEXPAND, 5 );
m_btnReset = new wxButton( this, wxID_ANY, _("&Reset colors to default"), wxDefaultPosition, wxDefaultSize, 0 );
m_btnReset->SetToolTip( _("Reset all colors in this theme to the KiCad defaults") );
bControlSizer->Add( m_btnReset, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_btnOpenFolder = new wxButton( this, wxID_ANY, _("Open theme folder"), wxDefaultPosition, wxDefaultSize, 0 );
m_btnOpenFolder->SetToolTip( _("Open the folder containing color themes") );
bControlSizer->Add( m_btnOpenFolder, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_mainSizer->Add( bControlSizer, 0, wxEXPAND, 5 );
m_panelThemeProperties = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_panelThemeProperties->Hide();
m_sizerThemeProperties = new wxBoxSizer( wxHORIZONTAL );
m_staticText6 = new wxStaticText( m_panelThemeProperties, wxID_ANY, _("Theme name:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText6->Wrap( -1 );
m_sizerThemeProperties->Add( m_staticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_txtThemeName = new wxTextCtrl( m_panelThemeProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
#ifdef __WXGTK__
if ( !m_txtThemeName->HasFlag( wxTE_MULTILINE ) )
{
m_txtThemeName->SetMaxLength( 48 );
}
#else
m_txtThemeName->SetMaxLength( 48 );
#endif
m_txtThemeName->SetToolTip( _("Name of the theme") );
m_txtThemeName->SetMinSize( wxSize( 200,-1 ) );
m_sizerThemeProperties->Add( m_txtThemeName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_sizerThemeProperties->Add( 24, 0, 0, wxEXPAND, 5 );
m_staticText7 = new wxStaticText( m_panelThemeProperties, wxID_ANY, _("Filename:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText7->Wrap( -1 );
m_sizerThemeProperties->Add( m_staticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_txtFilename = new wxTextCtrl( m_panelThemeProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_txtFilename->SetToolTip( _("Filename to save the theme to (must end in .json)") );
m_txtFilename->SetMinSize( wxSize( 200,-1 ) );
m_sizerThemeProperties->Add( m_txtFilename, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_lblThemePropertiesError = new wxStaticText( m_panelThemeProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_lblThemePropertiesError->Wrap( -1 );
m_lblThemePropertiesError->SetForegroundColour( wxColour( 255, 0, 0 ) );
m_sizerThemeProperties->Add( m_lblThemePropertiesError, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_panelThemeProperties->SetSizer( m_sizerThemeProperties );
m_panelThemeProperties->Layout();
m_sizerThemeProperties->Fit( m_panelThemeProperties );
m_mainSizer->Add( m_panelThemeProperties, 0, wxEXPAND | wxALL, 0 );
m_colorsMainSizer = new wxBoxSizer( wxHORIZONTAL );
m_colorsListWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
m_colorsListWindow->SetScrollRate( 5, 5 );
m_colorsListWindow->SetMinSize( wxSize( 240,-1 ) );
m_colorsGridSizer = new wxFlexGridSizer( 0, 2, 5, 5 );
m_colorsGridSizer->AddGrowableCol( 0 );
m_colorsGridSizer->SetFlexibleDirection( wxHORIZONTAL );
m_colorsGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
m_colorsListWindow->SetSizer( m_colorsGridSizer );
m_colorsListWindow->Layout();
m_colorsGridSizer->Fit( m_colorsListWindow );
m_colorsMainSizer->Add( m_colorsListWindow, 0, wxEXPAND | wxALL, 5 );
m_mainSizer->Add( m_colorsMainSizer, 1, wxEXPAND, 5 );
this->SetSizer( m_mainSizer );
this->Layout();
// Connect Events
this->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_COLOR_SETTINGS_BASE::OnSize ) );
m_cbTheme->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnThemeChanged ), NULL, this );
m_btnSave->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnSaveClicked ), NULL, this );
m_btnNew->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnNewClicked ), NULL, this );
m_btnRename->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnRenameClicked ), NULL, this );
m_btnReset->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnResetClicked ), NULL, this );
m_btnOpenFolder->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnOpenThemeFolderClicked ), NULL, this );
m_txtThemeName->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnThemeNameChanged ), NULL, this );
m_txtFilename->Connect( wxEVT_CHAR, wxKeyEventHandler( PANEL_COLOR_SETTINGS_BASE::OnFilenameChar ), NULL, this );
m_txtFilename->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnFilenameChanged ), NULL, this );
}
PANEL_COLOR_SETTINGS_BASE::~PANEL_COLOR_SETTINGS_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_COLOR_SETTINGS_BASE::OnSize ) );
m_cbTheme->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnThemeChanged ), NULL, this );
m_btnSave->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnSaveClicked ), NULL, this );
m_btnNew->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnNewClicked ), NULL, this );
m_btnRename->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnRenameClicked ), NULL, this );
m_btnReset->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnResetClicked ), NULL, this );
m_btnOpenFolder->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnOpenThemeFolderClicked ), NULL, this );
m_txtThemeName->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnThemeNameChanged ), NULL, this );
m_txtFilename->Disconnect( wxEVT_CHAR, wxKeyEventHandler( PANEL_COLOR_SETTINGS_BASE::OnFilenameChar ), NULL, this );
m_txtFilename->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnFilenameChanged ), NULL, this );
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/choice.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#include <wx/scrolwin.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class PANEL_COLOR_SETTINGS_BASE
///////////////////////////////////////////////////////////////////////////////
class PANEL_COLOR_SETTINGS_BASE : public wxPanel
{
private:
protected:
wxBoxSizer* m_mainSizer;
wxStaticText* m_staticText9;
wxChoice* m_cbTheme;
wxButton* m_btnSave;
wxButton* m_btnNew;
wxButton* m_btnRename;
wxButton* m_btnReset;
wxButton* m_btnOpenFolder;
wxPanel* m_panelThemeProperties;
wxBoxSizer* m_sizerThemeProperties;
wxStaticText* m_staticText6;
wxTextCtrl* m_txtThemeName;
wxStaticText* m_staticText7;
wxTextCtrl* m_txtFilename;
wxStaticText* m_lblThemePropertiesError;
wxBoxSizer* m_colorsMainSizer;
wxScrolledWindow* m_colorsListWindow;
wxFlexGridSizer* m_colorsGridSizer;
// Virtual event handlers, overide them in your derived class
virtual void OnSize( wxSizeEvent& event ) { event.Skip(); }
virtual void OnThemeChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnBtnSaveClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnBtnNewClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnBtnRenameClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnBtnResetClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnBtnOpenThemeFolderClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnThemeNameChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnFilenameChar( wxKeyEvent& event ) { event.Skip(); }
virtual void OnFilenameChanged( wxCommandEvent& event ) { event.Skip(); }
public:
PANEL_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 826,300 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~PANEL_COLOR_SETTINGS_BASE();
};

View File

@ -88,6 +88,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
m_showPageLimits = false;
m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
// BLACK for Pcbnew, BLACK or WHITE for eeschema
m_colorSettings = nullptr;
m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
m_zoomLevelCoeff = 1.0;
m_userUnits = EDA_UNITS::MILLIMETRES;
@ -839,7 +840,10 @@ void EDA_DRAW_FRAME::RecreateToolbars()
}
COLOR4D EDA_DRAW_FRAME::GetLayerColor( SCH_LAYER_ID aLayer )
COLOR_SETTINGS* EDA_DRAW_FRAME::GetColorSettings()
{
return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
if( !m_colorSettings )
m_colorSettings = Pgm().GetSettingsManager().GetColorSettings();
return m_colorSettings;
}

124
common/layer_id.cpp Normal file
View File

@ -0,0 +1,124 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* 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/>.
*/
#include <layers_id_colors_and_visibility.h>
#include <wx/wx.h>
wxString LayerName( SCH_LAYER_ID aLayer )
{
switch( aLayer )
{
case LAYER_WIRE:
return _( "Wire" );
case LAYER_BUS:
return _( "Bus" );
case LAYER_JUNCTION:
return _( "Junction" );
case LAYER_LOCLABEL:
return _( "Label" );
case LAYER_GLOBLABEL:
return _( "Global label" );
case LAYER_HIERLABEL:
return _( "Hierarchical label" );
case LAYER_PINNUM:
return _( "Pin number" );
case LAYER_PINNAM:
return _( "Pin name" );
case LAYER_REFERENCEPART:
return _( "Reference" );
case LAYER_VALUEPART:
return _( "Value" );
case LAYER_FIELDS:
return _( "Fields" );
case LAYER_DEVICE:
return _( "Body outline" );
case LAYER_NOTES:
return _( "Notes" );
case LAYER_NETNAM:
return _( "Net name" );
case LAYER_PIN:
return _( "Pin" );
case LAYER_SHEET:
return _( "Sheet" );
case LAYER_SHEETNAME:
return _( "Sheet name" );
case LAYER_SHEETFILENAME:
return _( "Sheet file name" );
case LAYER_SHEETLABEL:
return _( "Sheet label" );
case LAYER_NOCONNECT:
return _( "No connect symbol" );
case LAYER_ERC_WARN:
return _( "ERC warning" );
case LAYER_ERC_ERR:
return _( "ERC error" );
case LAYER_DEVICE_BACKGROUND:
return _( "Body background" );
case LAYER_SHEET_BACKGROUND:
return _( "Sheet background" );
case LAYER_SCHEMATIC_GRID:
return _( "Grid" );
case LAYER_SCHEMATIC_BACKGROUND:
return _( "Background" );
case LAYER_SCHEMATIC_CURSOR:
return _( "Cursor" );
case LAYER_BRIGHTENED:
return _( "Highlighted items" );
case LAYER_HIDDEN:
return _( "Hidden item" );
case LAYER_SELECTION_SHADOWS:
return _( "Selection highlight" );
case LAYER_SCHEMATIC_WORKSHEET:
return _( "Worksheet" );
default:
return wxEmptyString;
}
}

View File

@ -82,6 +82,8 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( std::string aFilename, int aSchemaVersion
m_params.emplace_back( new PARAM<int>( "system.units", &m_System.units,
static_cast<int>( EDA_UNITS::MILLIMETRES ) ) );
m_params.emplace_back( new PARAM<wxString>( "appearance.color_theme", &m_ColorTheme, "user" ) );
addParamsForWindow( &m_Window, "window" );
}

View File

@ -120,7 +120,6 @@ COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) :
CLR( "board.footprint_text_invisible", LAYER_MOD_TEXT_INVISIBLE, COLOR4D( LIGHTGRAY ) );
CLR( "board.grid", LAYER_GRID, COLOR4D( DARKGRAY ) );
CLR( "board.grid_axes", LAYER_GRID_AXES, COLOR4D( LIGHTGRAY ) );
CLR( "board.microvia", LAYER_VIA_MICROVIA, COLOR4D( LIGHTGRAY ) );
CLR( "board.no_connect", LAYER_NO_CONNECTS, COLOR4D( BLUE ) );
CLR( "board.pad_back", LAYER_PAD_BK, COLOR4D( GREEN ) );
CLR( "board.pad_front", LAYER_PAD_FR, COLOR4D( RED ) );

View File

@ -58,9 +58,7 @@ SETTINGS_MANAGER::SETTINGS_MANAGER() :
m_common_settings =
static_cast<COMMON_SETTINGS*>( RegisterSettings( new COMMON_SETTINGS, false ) );
// create the default color settings
m_color_settings["default"] =
static_cast<COLOR_SETTINGS*>( RegisterSettings( new COLOR_SETTINGS ) );
loadAllColorSettings();
}
SETTINGS_MANAGER::~SETTINGS_MANAGER()
@ -150,7 +148,7 @@ void SETTINGS_MANAGER::FlushAndRelease( JSON_SETTINGS* aSettings )
}
COLOR_SETTINGS* SETTINGS_MANAGER::GetColorSettings( std::string aName )
COLOR_SETTINGS* SETTINGS_MANAGER::GetColorSettings( const wxString& aName )
{
COLOR_SETTINGS* ret = nullptr;
@ -160,14 +158,112 @@ COLOR_SETTINGS* SETTINGS_MANAGER::GetColorSettings( std::string aName )
}
catch( std::out_of_range& )
{
if( !aName.empty() )
ret = loadColorSettingsByName( aName );
// This had better work
ret = m_color_settings.at( "default" );
if( !ret )
ret = m_color_settings.at( "user" );
}
return ret;
}
COLOR_SETTINGS* SETTINGS_MANAGER::loadColorSettingsByName( const wxString& aName )
{
wxLogTrace( traceSettings, "Attempting to load color theme %s", aName );
wxFileName fn( GetColorSettingsPath(), aName, "json" );
if( !fn.IsOk() || !fn.Exists() )
{
wxLogTrace( traceSettings, "Theme file %s.json not found, falling back to user", aName );
return nullptr;
}
auto cs = static_cast<COLOR_SETTINGS*>(
RegisterSettings( new COLOR_SETTINGS( aName.ToStdString() ) ) );
if( cs->GetFilename() != aName.ToStdString() )
{
wxLogTrace( traceSettings, "Warning: stored filename is actually %s, ", cs->GetFilename() );
}
m_color_settings[aName] = cs;
return cs;
}
class COLOR_SETTINGS_LOADER : public wxDirTraverser
{
private:
std::function<void( const wxString& )> m_action;
public:
explicit COLOR_SETTINGS_LOADER( std::function<void( const wxString& )> aAction )
: m_action( std::move( aAction ) )
{
}
wxDirTraverseResult OnFile( const wxString& aFilePath ) override
{
wxFileName file( aFilePath );
if( file.GetExt() != "json" )
return wxDIR_CONTINUE;
if( file.GetName() == "user" )
return wxDIR_CONTINUE;
m_action( file.GetName() );
return wxDIR_CONTINUE;
}
wxDirTraverseResult OnDir( const wxString& dirPath ) override
{
return wxDIR_IGNORE;
}
};
void SETTINGS_MANAGER::registerColorSettings( const wxString& aFilename )
{
m_color_settings[aFilename] = static_cast<COLOR_SETTINGS*>(
RegisterSettings( new COLOR_SETTINGS( aFilename.ToStdString() ) ) );
}
COLOR_SETTINGS* SETTINGS_MANAGER::AddNewColorSettings( const wxString& aFilename )
{
wxString filename = aFilename;
if( filename.EndsWith( wxT( ".json" ) ) )
filename = filename.BeforeLast( '.' );
registerColorSettings( filename );
return m_color_settings[filename];
}
void SETTINGS_MANAGER::loadAllColorSettings()
{
// Create the default color settings
registerColorSettings( "user" );
// Search for and load any other settings
COLOR_SETTINGS_LOADER loader(
[&]( const wxString& aFilename ) { registerColorSettings( aFilename ); } );
wxDir colors_dir( GetColorSettingsPath() );
if( colors_dir.IsOpened() )
colors_dir.Traverse( loader );
}
void SETTINGS_MANAGER::SaveColorSettings( COLOR_SETTINGS* aSettings, const std::string& aNamespace )
{
// The passed settings should already be managed
@ -182,8 +278,8 @@ void SETTINGS_MANAGER::SaveColorSettings( COLOR_SETTINGS* aSettings, const std::
wxASSERT( aSettings->contains( ptr ) );
wxLogTrace( traceSettings, "Saving color scheme %s, preserving &s",
aSettings->GetFilename(), aNamespace );
wxLogTrace( traceSettings, "Saving color scheme %s, preserving %s", aSettings->GetFilename(),
aNamespace );
nlohmann::json backup = aSettings->at( ptr );
std::string path = GetColorSettingsPath();

View File

@ -94,6 +94,7 @@ set( EESCHEMA_DLGS
dialogs/dialog_update_fields_base.cpp
dialogs/dialog_update_from_pcb.cpp
dialogs/dialog_update_from_pcb_base.cpp
dialogs/panel_eeschema_color_settings.cpp
dialogs/panel_eeschema_template_fieldnames.cpp
dialogs/panel_eeschema_template_fieldnames_base.cpp
dialogs/panel_eeschema_display_options.cpp
@ -111,7 +112,6 @@ set( EESCHEMA_WIDGETS
widgets/pin_type_combobox.cpp
widgets/symbol_preview_widget.cpp
widgets/symbol_tree_pane.cpp
widgets/widget_eeschema_color_config.cpp
)

View File

@ -39,6 +39,7 @@
#include <class_libentry.h>
#include <lib_pin.h>
#include <lib_arc.h>
#include <settings/color_settings.h>
// the separator char between the subpart id and the reference
@ -494,7 +495,7 @@ void LIB_PART::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
{
wxASSERT( aPlotter != NULL );
aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
aPlotter->SetColor( aPlotter->ColorSettings()->GetColor( LAYER_DEVICE ) );
bool fill = aPlotter->GetColorMode();
// draw background for filled items using background option
@ -540,7 +541,7 @@ void LIB_PART::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
{
wxASSERT( aPlotter != NULL );
aPlotter->SetColor( GetLayerColor( LAYER_FIELDS ) );
aPlotter->SetColor( aPlotter->ColorSettings()->GetColor( LAYER_FIELDS ) );
bool fill = aPlotter->GetColorMode();
for( LIB_ITEM& item : m_drawings )

View File

@ -26,6 +26,8 @@
#include <sch_line.h>
#include <dialog_edit_line_style.h>
#include <dialogs/dialog_color_picker.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <sch_edit_frame.h>
const int BUTT_COLOR_MINSIZE_X = 32;
@ -174,7 +176,7 @@ void DIALOG_EDIT_LINE_STYLE::updateColorButton( COLOR4D& aColor )
void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event )
{
m_width.SetValue( m_lines.front()->GetDefaultWidth() );
setColor( m_lines.front()->GetDefaultColor() );
setColor( COLOR4D::UNSPECIFIED );
auto typeIt = lineTypeNames.find( m_lines.front()->GetDefaultStyle() );
wxCHECK_RET( typeIt != lineTypeNames.end(),
@ -188,6 +190,14 @@ void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event )
void DIALOG_EDIT_LINE_STYLE::setColor( const COLOR4D& aColor )
{
m_selectedColor = aColor;
if( aColor == COLOR4D::UNSPECIFIED )
{
COLOR4D defaultColor = Pgm().GetSettingsManager().GetColorSettings()->GetColor(
m_lines.front()->GetLayer() );
updateColorButton( defaultColor );
}
else
updateColorButton( m_selectedColor );
}
@ -215,10 +225,7 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow()
line->SetLineStyle( it->first );
}
if( m_selectedColor != COLOR4D::UNSPECIFIED )
{
line->SetLineColor( m_selectedColor );
}
m_frame->RefreshItem( line );
}

View File

@ -0,0 +1,674 @@
/*
* 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/>.
*/
#include <regex>
#include <bitmaps.h>
#include <dialogs/dialog_color_picker.h>
#include <eeschema_settings.h>
#include <gal/gal_display_options.h>
#include <layers_id_colors_and_visibility.h>
#include <class_libentry.h>
#include <lib_pin.h>
#include <lib_polyline.h>
#include <menus_helpers.h>
#include <page_info.h>
#include <panel_eeschema_color_settings.h>
#include <pgm_base.h>
#include <sch_bus_entry.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_painter.h>
#include <sch_preview_panel.h>
#include <sch_text.h>
#include <settings/color_settings.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <title_block.h>
#include <view/view.h>
#include <ws_proxy_view_item.h>
// Width and height of every (color-displaying / bitmap) button in dialog units
const wxSize BUTTON_SIZE( 24, 12 );
const wxSize BUTTON_BORDER( 4, 4 );
// Button ID starting point
constexpr int FIRST_BUTTON_ID = 1800;
PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS( EDA_DRAW_FRAME* aFrame,
wxWindow* aParent ) :
PANEL_COLOR_SETTINGS( aParent ),
m_frame( aFrame ),
m_preview( nullptr ),
m_currentSettings( nullptr ),
m_page( nullptr ),
m_titleBlock( nullptr ),
m_previewItems(),
m_buttons(),
m_filenameEdited( false ),
m_isNewTheme( false ),
m_dirty( false ),
m_copied( COLOR4D::UNSPECIFIED )
{
m_buttonSizePx = ConvertDialogToPixels( BUTTON_SIZE );
auto common_settings = Pgm().GetCommonSettings();
auto app_settings = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
COLOR_SETTINGS* current =
Pgm().GetSettingsManager().GetColorSettings( app_settings->m_ColorTheme );
m_cbTheme->Clear();
for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
{
int pos = m_cbTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
if( settings == current )
m_cbTheme->SetSelection( pos );
}
m_currentSettings = new COLOR_SETTINGS( *current );
KIGFX::GAL_DISPLAY_OPTIONS options;
options.ReadConfig( *common_settings, app_settings->m_Window, this );
auto type = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( app_settings->m_Graphics.canvas_type );
m_preview = new SCH_PREVIEW_PANEL( this, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ),
options, type );
m_preview->SetStealsFocus( false );
m_preview->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
createButtons();
Connect( FIRST_BUTTON_ID, FIRST_BUTTON_ID + ( SCH_LAYER_ID_END - SCH_LAYER_ID_START ),
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( PANEL_EESCHEMA_COLOR_SETTINGS::SetColor ) );
m_colorsMainSizer->Add( m_preview, 1, wxALL | wxEXPAND, 5 );
createPreviewItems();
updatePreview();
zoomFitPreview();
}
PANEL_EESCHEMA_COLOR_SETTINGS::~PANEL_EESCHEMA_COLOR_SETTINGS()
{
delete m_page;
delete m_titleBlock;
for( auto item : m_previewItems )
delete item;
}
bool PANEL_EESCHEMA_COLOR_SETTINGS::TransferDataFromWindow()
{
return saveCurrentTheme();
}
bool PANEL_EESCHEMA_COLOR_SETTINGS::TransferDataToWindow()
{
zoomFitPreview();
return true;
}
bool PANEL_EESCHEMA_COLOR_SETTINGS::saveCurrentTheme()
{
COLOR4D bgcolor = m_currentSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
{
if( bgcolor == m_currentSettings->GetColor( clyr ) && clyr != LAYER_SCHEMATIC_BACKGROUND )
{
wxString msg =
_( "Some items have the same color as the background\n"
"and they will not be seen on the screen. Are you\n"
"sure you want to use these colors?" );
if( wxMessageBox( msg, _( "Warning" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
return false;
break;
}
}
bool dirty = m_dirty;
COLOR_SETTINGS* selected;
if( !m_isNewTheme )
{
int idx = m_cbTheme->GetSelection();
selected = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
}
else
{
if( !validateFilename() )
return false;
selected = Pgm().GetSettingsManager().AddNewColorSettings(
m_txtFilename->GetValue().ToStdString() );
selected->SetName( m_txtThemeName->GetValue() );
Pgm().GetSettingsManager().Save( selected );
dirty = true;
m_cbTheme->SetSelection(
m_cbTheme->Append( m_txtThemeName->GetValue(), static_cast<void*>( selected ) ) );
}
for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
{
COLOR4D color = m_currentSettings->GetColor( clyr );
// Do not allow non-background layers to be completely white.
// This ensures the BW printing recognizes that the colors should be printed black.
if( color == COLOR4D::WHITE && clyr != LAYER_SCHEMATIC_BACKGROUND )
color.Darken( 0.01 );
if( !dirty && selected->GetColor( clyr ) != color )
dirty = true;
selected->SetColor( clyr, color );
}
auto settings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
settings->LoadColors( selected );
if( dirty )
{
Pgm().GetSettingsManager().SaveColorSettings( selected, "schematic" );
m_dirty = false;
}
auto app_settings = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
app_settings->m_ColorTheme = selected->GetFilename();
return true;
}
void PANEL_EESCHEMA_COLOR_SETTINGS::createButtons()
{
const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT;
wxSize border = ConvertDialogToPixels( BUTTON_BORDER );
std::vector<SCH_LAYER_ID> layers;
for( SCH_LAYER_ID i = SCH_LAYER_ID_START; i < SCH_LAYER_ID_END; ++i )
layers.push_back( i );
std::sort( layers.begin(), layers.end(), []( SCH_LAYER_ID a, SCH_LAYER_ID b ) {
return LayerName( a ) < LayerName( b );
} );
for( SCH_LAYER_ID layer : layers )
{
// LAYER_SHEET_BACKGROUND doesn't currently allow changing settings
if( layer == LAYER_SHEET_BACKGROUND )
continue;
wxString name = LayerName( layer );
auto label = new wxStaticText( m_colorsListWindow, wxID_ANY, name );
COLOR4D color = m_currentSettings->GetColor( layer );
wxMemoryDC iconDC;
wxBitmap bitmap( m_buttonSizePx );
iconDC.SelectObject( bitmap );
iconDC.SetPen( *wxBLACK_PEN );
wxBrush brush;
brush.SetColour( color.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, m_buttonSizePx.x, m_buttonSizePx.y );
int id = FIRST_BUTTON_ID + ( layer - SCH_LAYER_ID_START );
auto button = new wxBitmapButton( m_colorsListWindow, id, bitmap, wxDefaultPosition,
m_buttonSizePx + border + wxSize( 1, 1 ) );
button->SetToolTip( _( "Edit color (right click for options)" ) );
m_colorsGridSizer->Add( label, 1, flags, 5 );
m_colorsGridSizer->Add( button, 1, flags, 5 );
m_buttons[layer] = button;
button->Bind( wxEVT_RIGHT_DOWN, [&, layer]( wxMouseEvent& aEvent ) {
ShowColorContextMenu( aEvent, layer );
} );
}
}
void PANEL_EESCHEMA_COLOR_SETTINGS::drawButton( wxBitmapButton* aButton, const COLOR4D& aColor )
{
wxMemoryDC iconDC;
wxBitmap bitmap = aButton->GetBitmapLabel();
iconDC.SelectObject( bitmap );
iconDC.SetPen( *wxBLACK_PEN );
wxBrush brush;
brush.SetColour( aColor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, m_buttonSizePx.x, m_buttonSizePx.y );
aButton->SetBitmapLabel( bitmap );
aButton->Refresh();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems()
{
auto view = m_preview->GetView();
m_page = new PAGE_INFO( PAGE_INFO::Custom );
m_titleBlock = new TITLE_BLOCK;
m_page->SetHeightMils( 5000 );
m_page->SetWidthMils( 5500 );
m_ws = new KIGFX::WS_PROXY_VIEW_ITEM( static_cast<int>( IU_PER_MILS ), m_page, m_titleBlock );
m_ws->SetColorLayer( LAYER_SCHEMATIC_WORKSHEET );
view->Add( m_ws );
// NOTE: It would be nice to parse a schematic file here.
// This is created from the color_settings.sch file in demos folder
auto addItem = [&]( EDA_ITEM* aItem ) {
view->Add( aItem );
m_previewItems.push_back( aItem );
};
std::vector<std::pair<SCH_LAYER_ID, std::pair<wxPoint, wxPoint>>> lines = {
{ LAYER_WIRE, { { 1950, 1500 }, { 2325, 1500 } } },
{ LAYER_WIRE, { { 1950, 2600 }, { 2350, 2600 } } },
{ LAYER_WIRE, { { 2150, 1700 }, { 2325, 1700 } } },
{ LAYER_WIRE, { { 2150, 2000 }, { 2150, 1700 } } },
{ LAYER_WIRE, { { 2925, 1600 }, { 3075, 1600 } } },
{ LAYER_WIRE, { { 3075, 1600 }, { 3075, 2000 } } },
{ LAYER_WIRE, { { 3075, 1600 }, { 3250, 1600 } } },
{ LAYER_WIRE, { { 3075, 2000 }, { 2150, 2000 } } },
{ LAYER_BUS, { { 1750, 1400 }, { 1850, 1400 } } },
{ LAYER_BUS, { { 1850, 2500 }, { 1850, 1400 } } },
{ LAYER_NOTES, { { 2350, 2125 }, { 2350, 2300 } } },
{ LAYER_NOTES, { { 2350, 2125 }, { 2950, 2125 } } },
{ LAYER_NOTES, { { 2950, 2125 }, { 2950, 2300 } } },
{ LAYER_NOTES, { { 2950, 2300 }, { 2350, 2300 } } }
};
for( const auto& line : lines )
{
auto wire = new SCH_LINE;
wire->SetLayer( line.first );
wire->SetStartPoint(
wxPoint( Mils2iu( line.second.first.x ), Mils2iu( line.second.first.y ) ) );
wire->SetEndPoint(
wxPoint( Mils2iu( line.second.second.x ), Mils2iu( line.second.second.y ) ) );
addItem( wire );
}
auto nc = new SCH_NO_CONNECT;
nc->SetPosition( wxPoint( Mils2iu( 2525 ), Mils2iu( 1300 ) ) );
addItem( nc );
auto e1 = new SCH_BUS_WIRE_ENTRY;
e1->SetPosition( wxPoint( Mils2iu( 1850 ), Mils2iu( 1400 ) ) );
addItem( e1 );
auto e2 = new SCH_BUS_WIRE_ENTRY;
e2->SetPosition( wxPoint( Mils2iu( 1850 ), Mils2iu( 2500 ) ) );
addItem( e2 );
auto t1 = new SCH_TEXT( wxPoint( Mils2iu( 2850 ), Mils2iu( 2250 ) ), wxT( "PLAIN TEXT" ) );
t1->SetLabelSpinStyle( 0 );
addItem( t1 );
auto t2 = new SCH_LABEL( wxPoint( Mils2iu( 1975 ), Mils2iu( 1500 ) ), wxT( "GLOBAL0" ) );
t2->SetLabelSpinStyle( 2 );
t2->SetIsDangling( false );
addItem( t2 );
auto t3 = new SCH_LABEL( wxPoint( Mils2iu( 1975 ), Mils2iu( 2600 ) ), wxT( "GLOBAL1" ) );
t3->SetLabelSpinStyle( 2 );
t3->SetIsDangling( false );
addItem( t3 );
auto t4 = new SCH_GLOBALLABEL(
wxPoint( Mils2iu( 1750 ), Mils2iu( 1400 ) ), wxT( "GLOBAL[3..0]" ) );
t4->SetLabelSpinStyle( 0 );
t4->SetIsDangling( false );
addItem( t4 );
auto t5 = new SCH_HIERLABEL( wxPoint( Mils2iu( 3250 ), Mils2iu( 1600 ) ), wxT( "HIER_LABEL" ) );
t5->SetLabelSpinStyle( 2 );
t5->SetIsDangling( false );
addItem( t5 );
auto j = new SCH_JUNCTION( wxPoint( Mils2iu( 3075 ), Mils2iu( 1600 ) ) );
addItem( j );
e2->SetBrightened();
t2->SetSelected();
{
auto part = new LIB_PART( wxEmptyString );
wxPoint p( 2625, -1600 );
part->SetShowPinNames( true );
part->SetShowPinNumbers( true );
addItem( part );
auto comp_body = new LIB_POLYLINE( part );
comp_body->SetUnit( 0 );
comp_body->SetConvert( 0 );
comp_body->SetWidth( Mils2iu( 10 ) );
comp_body->SetFillMode( FILLED_WITH_BG_BODYCOLOR );
comp_body->AddPoint( wxPoint( Mils2iu( p.x - 200 ), Mils2iu( p.y + 200 ) ) );
comp_body->AddPoint( wxPoint( Mils2iu( p.x + 200 ), Mils2iu( p.y ) ) );
comp_body->AddPoint( wxPoint( Mils2iu( p.x - 200 ), Mils2iu( p.y - 200 ) ) );
comp_body->AddPoint( wxPoint( Mils2iu( p.x - 200 ), Mils2iu( p.y + 200 ) ) );
addItem( comp_body );
}
zoomFitPreview();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::SetColor( wxCommandEvent& event )
{
auto button = static_cast<wxBitmapButton*>( event.GetEventObject() );
auto layer =
static_cast<SCH_LAYER_ID>( button->GetId() - FIRST_BUTTON_ID + SCH_LAYER_ID_START );
COLOR4D oldColor = m_currentSettings->GetColor( layer );
COLOR4D newColor = COLOR4D::UNSPECIFIED;
DIALOG_COLOR_PICKER dialog( this, oldColor, false );
if( dialog.ShowModal() == wxID_OK )
newColor = dialog.GetColor();
if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
return;
updateColor( layer, newColor );
}
void PANEL_EESCHEMA_COLOR_SETTINGS::updateColor( SCH_LAYER_ID aLayer, const KIGFX::COLOR4D& aColor )
{
m_currentSettings->SetColor( aLayer, aColor );
m_dirty = true;
m_btnSave->Enable();
drawButton( m_buttons[aLayer], aColor );
updatePreview();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnBtnResetClicked( wxCommandEvent& event )
{
for( const auto& pair : m_buttons )
{
SCH_LAYER_ID layer = pair.first;
wxBitmapButton* button = pair.second;
COLOR4D defaultColor = m_currentSettings->GetDefaultColor( layer );
m_currentSettings->SetColor( layer, defaultColor );
drawButton( button, defaultColor );
}
m_dirty = true;
m_btnSave->Enable();
updatePreview();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::updatePreview()
{
KIGFX::VIEW* view = m_preview->GetView();
auto settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
settings->LoadColors( m_currentSettings );
m_preview->GetGAL()->SetClearColor( settings->GetBackgroundColor() );
view->UpdateAllItems( KIGFX::COLOR );
auto rect = m_preview->GetScreenRect();
m_preview->Refresh( true, &rect );
}
void PANEL_EESCHEMA_COLOR_SETTINGS::zoomFitPreview()
{
auto view = m_preview->GetView();
view->SetScale( 1.0 );
VECTOR2D screenSize = view->ToWorld( m_preview->GetClientSize(), false );
VECTOR2I psize( m_page->GetWidthIU(), m_page->GetHeightIU() );
double scale = view->GetScale() / std::max( fabs( psize.x / screenSize.x ),
fabs( psize.y / screenSize.y ) );
view->SetScale( scale / 1.02 );
view->SetCenter( m_ws->ViewBBox().Centre() );
m_preview->ForceRefresh();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnSize( wxSizeEvent& aEvent )
{
zoomFitPreview();
aEvent.Skip();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::showThemeNamePanel( bool aShow )
{
m_panelThemeProperties->Show( aShow );
Layout();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnBtnNewClicked( wxCommandEvent& event )
{
m_txtFilename->Enable();
m_txtThemeName->SetValue( "" );
m_txtFilename->SetValue( "" );
showThemeNamePanel();
m_btnSave->Enable();
m_txtThemeName->SetFocus();
m_filenameEdited = false;
m_isNewTheme = true;
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnBtnRenameClicked( wxCommandEvent& event )
{
// "User" theme can't be renamed, it is the default if no other themes exist
if( m_currentSettings->GetFilename() == "user" )
return;
m_isNewTheme = false;
m_txtFilename->Disable();
showThemeNamePanel();
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnBtnSaveClicked( wxCommandEvent& event )
{
if( ( !m_isNewTheme || validateFilename() ) && saveCurrentTheme() )
{
m_isNewTheme = false;
showThemeNamePanel( false );
m_btnSave->Disable();
}
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnThemeChanged( wxCommandEvent& event )
{
// TODO(JE) If dirty here, we should prompt to save the previous theme first
int idx = m_cbTheme->GetSelection();
auto selected = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
if( selected->GetFilename() != m_currentSettings->GetFilename() )
{
*m_currentSettings = *selected;
updatePreview();
for( auto pair : m_buttons )
drawButton( pair.second, m_currentSettings->GetColor( pair.first ) );
}
m_isNewTheme = false;
m_filenameEdited = false;
showThemeNamePanel( false );
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnThemeNameChanged( wxCommandEvent& event )
{
if( !m_filenameEdited )
m_txtFilename->SetValue( suggestFilename( m_txtThemeName->GetValue() ) );
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnFilenameChanged( wxCommandEvent& event )
{
}
void PANEL_EESCHEMA_COLOR_SETTINGS::OnFilenameChar( wxKeyEvent& event )
{
// Once the user has typed something in the filename box, stop suggesting things
m_filenameEdited = true;
if( !m_lblThemePropertiesError->GetLabel().empty() )
validateFilename();
event.Skip();
}
bool PANEL_EESCHEMA_COLOR_SETTINGS::validateFilename()
{
wxFileName fn( m_txtFilename->GetValue() );
fn.SetPath( Pgm().GetSettingsManager().GetColorSettingsPath() );
if( !fn.IsOk() )
{
m_lblThemePropertiesError->SetLabel( _( "Invalid filename" ) );
return false;
}
if( fn.Exists() && m_isNewTheme )
{
m_lblThemePropertiesError->SetLabel( _( "File already exists!" ) );
return false;
}
if( fn.GetExt() != "json" )
{
m_lblThemePropertiesError->SetLabel( _( "File must end in .json" ) );
return false;
}
return true;
}
wxString PANEL_EESCHEMA_COLOR_SETTINGS::suggestFilename( const wxString& aThemeName )
{
static const std::regex invalidChars( "[^-\\w_ ]+" );
static const std::regex whitespace( "\\s+" );
std::string themeName( aThemeName.ToUTF8() );
themeName = std::regex_replace( themeName, invalidChars, "" );
themeName = std::regex_replace( themeName, whitespace, "_" );
wxString filename( themeName.c_str(), wxConvUTF8 );
filename.MakeLower();
filename.Append( ".json" );
return filename;
}
void PANEL_EESCHEMA_COLOR_SETTINGS::ShowColorContextMenu( wxMouseEvent& aEvent,
SCH_LAYER_ID aLayer )
{
auto selected =
static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) );
COLOR4D current = m_currentSettings->GetColor( aLayer );
COLOR4D saved = selected->GetColor( aLayer );
wxMenu menu;
AddMenuItem( &menu, ID_COPY, _( "Copy color" ), KiBitmap( copy_xpm ) );
if( m_copied != COLOR4D::UNSPECIFIED )
AddMenuItem( &menu, ID_PASTE, _( "Paste color" ), KiBitmap( paste_xpm ) );
if( current != saved )
AddMenuItem( &menu, ID_REVERT, _( "Revert to saved color" ), KiBitmap( undo_xpm ) );
menu.Bind( wxEVT_COMMAND_MENU_SELECTED, [&]( wxCommandEvent& aCmd ) {
switch( aCmd.GetId() )
{
case ID_COPY:
m_copied = current;
break;
case ID_PASTE:
updateColor( aLayer, m_copied );
break;
case ID_REVERT:
updateColor( aLayer, saved );
break;
default:
aCmd.Skip();
}
} );
PopupMenu( &menu );
}

View File

@ -0,0 +1,130 @@
/*
* 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 PANEL_EESCHEMA_COLOR_SETTINGS_H_
#define PANEL_EESCHEMA_COLOR_SETTINGS_H_
#include <gal/color4d.h>
#include <layers_id_colors_and_visibility.h>
#include <panel_color_settings.h>
class COLOR_SETTINGS;
class EDA_DRAW_FRAME;
class PAGE_INFO;
class SCH_ITEM;
class SCH_PREVIEW_PANEL;
class TITLE_BLOCK;
namespace KIGFX
{
class WS_PROXY_VIEW_ITEM;
}
class PANEL_EESCHEMA_COLOR_SETTINGS : public PANEL_COLOR_SETTINGS
{
public:
PANEL_EESCHEMA_COLOR_SETTINGS( EDA_DRAW_FRAME* aFrame, wxWindow* aParent );
~PANEL_EESCHEMA_COLOR_SETTINGS() override;
protected:
bool TransferDataFromWindow() override;
bool TransferDataToWindow() override;
void SetColor( wxCommandEvent& aEvent );
void OnBtnResetClicked( wxCommandEvent& aEvent ) override;
void OnBtnRenameClicked( wxCommandEvent& aEvent ) override;
void OnThemeChanged( wxCommandEvent& aEvent ) override;
void OnBtnSaveClicked( wxCommandEvent& aEvent ) override;
void OnBtnNewClicked( wxCommandEvent& aEvent ) override;
void OnThemeNameChanged( wxCommandEvent& aEvent ) override;
void OnFilenameChanged( wxCommandEvent& aEvent ) override;
void OnFilenameChar( wxKeyEvent& aEvent ) override;
void OnSize( wxSizeEvent& aEvent ) override;
void ShowColorContextMenu( wxMouseEvent& aEvent, SCH_LAYER_ID aLayer );
enum COLOR_CONTEXT_ID
{
ID_COPY = wxID_HIGHEST + 1,
ID_PASTE,
ID_REVERT
};
private:
EDA_DRAW_FRAME* m_frame;
SCH_PREVIEW_PANEL* m_preview;
COLOR_SETTINGS* m_currentSettings;
wxSize m_buttonSizePx;
PAGE_INFO* m_page;
TITLE_BLOCK* m_titleBlock;
KIGFX::WS_PROXY_VIEW_ITEM* m_ws;
std::vector<EDA_ITEM*> m_previewItems;
std::map<SCH_LAYER_ID, wxBitmapButton*> m_buttons;
bool m_filenameEdited;
bool m_isNewTheme;
bool m_dirty;
KIGFX::COLOR4D m_copied;
bool saveCurrentTheme();
void createPreviewItems();
void createButtons();
void updateColor( SCH_LAYER_ID aLayer, const KIGFX::COLOR4D& aColor );
void drawButton( wxBitmapButton* aButton, const KIGFX::COLOR4D& aColor );
void updatePreview();
void zoomFitPreview();
bool validateFilename();
void showThemeNamePanel( bool aShow = true );
static wxString suggestFilename( const wxString& aThemeName );
};
#endif

View File

@ -164,26 +164,6 @@ PGM_BASE& Pgm()
}
// TODO(JE) Get rid of this on a second pass through eeschema
static COLOR4D s_layerColor[LAYER_ID_COUNT];
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
{
unsigned layer = ( aLayer );
wxASSERT( layer < arrayDim( s_layerColor ) );
return s_layerColor[layer];
}
void OnColorsChanged()
{
COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetColorSettings();
for( SCH_LAYER_ID layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; ++layer )
s_layerColor[layer] = cs->GetColor( layer );
}
bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
{
// This is process-level-initialization, not project-level-initialization of the DSO.
@ -193,8 +173,6 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
start_common( aCtlBits );
OnColorsChanged();
wxFileName fn = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
if( !fn.FileExists() )

View File

@ -23,6 +23,7 @@
#include <class_library.h>
#include <confirm.h>
#include <dialogs/panel_eeschema_color_settings.h>
#include <dialogs/panel_eeschema_display_options.h>
#include <dialogs/panel_eeschema_settings.h>
#include <dialogs/panel_eeschema_template_fieldnames.h>
@ -42,10 +43,11 @@
#include <sch_painter.h>
#include <sch_sheet.h>
#include <settings/app_settings.h>
#include <settings/settings_manager.h>
#include <symbol_lib_table.h>
#include <widgets/paged_dialog.h>
#include <widgets/symbol_tree_pane.h>
#include <widgets/widget_eeschema_color_config.h>
//#include <widgets/widget_eeschema_color_config.h>
#include <wildcards_and_files_ext.h>
#include <ws_data_model.h>
@ -153,10 +155,11 @@ void SetSelectionThickness( int aThickness )
s_selectThickness = aThickness;
}
// Color to draw selected items
COLOR4D GetItemSelectedColor()
/// Helper for all the old plotting/printing code while it still exists
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
{
return COLOR4D( BROWN );
return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
}
@ -175,7 +178,7 @@ void SCH_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent,
book->AddPage( new wxPanel( book ), _( "Eeschema" ) );
book->AddSubPage( new PANEL_EESCHEMA_DISPLAY_OPTIONS( this, book ), _( "Display Options" ) );
book->AddSubPage( new PANEL_EESCHEMA_SETTINGS( this, book ), _( "Editing Options" ) );
book->AddSubPage( new PANEL_EESCHEMA_COLOR_CONFIG( this, book ), _( "Colors" ) );
book->AddSubPage( new PANEL_EESCHEMA_COLOR_SETTINGS( this, book ), _( "Colors" ) );
book->AddSubPage( new PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( this, book ),
_( "Field Name Templates" ) );

View File

@ -147,18 +147,10 @@ void SetSelectionFillShapes( bool aBool );
int GetSelectionThickness();
void SetSelectionThickness( int aThickness );
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer );
/**
* Update the static layer color cache used by GetLayerColor()
* TODO(JE) Remove this once eeschema is refactored to not need s_layerColor[]
*/
void OnColorsChanged();
// Color to draw selected items
COLOR4D GetItemSelectedColor();
// Color to draw items flagged invisible, in libedit (they are invisible in Eeschema
COLOR4D GetInvisibleItemColor();
// TODO(JE) Remove this once wxDC printing is gone
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer );
#endif // _GENERAL_H_

View File

@ -34,6 +34,7 @@
#include <general.h>
#include <lib_bezier.h>
#include <transform.h>
#include <settings/color_settings.h>
LIB_BEZIER::LIB_BEZIER( LIB_PART* aParent ) :
@ -188,7 +189,7 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
aPlotter->SetColor( GetLayerColor( LAYER_DEVICE_BACKGROUND ) );
aPlotter->SetColor( aPlotter->ColorSettings()->GetColor( LAYER_DEVICE_BACKGROUND ) );
aPlotter->PlotPoly( cornerList, FILLED_WITH_BG_BODYCOLOR, 0 );
}
@ -198,7 +199,7 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( 0, pen_size );
aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
aPlotter->SetColor( aPlotter->ColorSettings()->GetColor( LAYER_DEVICE ) );
aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, pen_size );
}
}

View File

@ -30,6 +30,8 @@
#include <sch_edit_frame.h>
#include <sch_sheet_path.h>
#include <project.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <dialog_plot_schematic.h>
#include <wx_html_report_panel.h>
@ -113,6 +115,7 @@ bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
plotter->SetPageSettings( pageInfo );
plotter->SetColorMode( getModeColor() );
plotter->SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
// Currently, plot units are in decimil
plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );

View File

@ -31,6 +31,8 @@
#include <base_units.h>
#include <sch_sheet_path.h>
#include <project.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <dialog_plot_schematic.h>
#include <wx_html_report_panel.h>
@ -200,6 +202,7 @@ bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
plotter->SetPenDiameter( m_HPGLPenSize );
plotter->StartPlot();
plotter->SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
plotter->SetColor( BLACK );
if( getPlotFrameRef() )

View File

@ -30,8 +30,10 @@
#include <sch_edit_frame.h>
#include <base_units.h>
#include <sch_sheet_path.h>
#include <pgm_base.h>
#include <project.h>
#include <general.h>
#include <settings/settings_manager.h>
#include <reporter.h>
@ -61,6 +63,7 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
PDF_PLOTTER* plotter = new PDF_PLOTTER();
plotter->SetDefaultLineWidth( GetDefaultLineThickness() );
plotter->SetColorMode( getModeColor() );
plotter->SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
plotter->SetCreator( wxT( "Eeschema-PDF" ) );
plotter->SetTitle( m_parent->GetTitleBlock().GetTitle() );

View File

@ -29,8 +29,10 @@
#include <sch_edit_frame.h>
#include <base_units.h>
#include <sch_sheet_path.h>
#include <pgm_base.h>
#include <project.h>
#include <reporter.h>
#include <settings/settings_manager.h>
#include <dialog_plot_schematic.h>
#include <wx_html_report_panel.h>
@ -140,6 +142,7 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
plotter->SetColorMode( getModeColor() );
// Currently, plot units are in decimil
plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
plotter->SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
// Init :
plotter->SetCreator( wxT( "Eeschema-PS" ) );

View File

@ -36,6 +36,7 @@
#include <sch_sheet_path.h>
#include <project.h>
#include <reporter.h>
#include <settings/settings_manager.h>
#include <dialog_plot_schematic.h>
#include <wx_html_report_panel.h>
@ -109,6 +110,7 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( EDA_DRAW_FRAME* aFrame,
plotter->SetPageSettings( pageInfo );
plotter->SetDefaultLineWidth( GetDefaultLineThickness() );
plotter->SetColorMode( aPlotBlackAndWhite ? false : true );
plotter->SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
wxPoint plot_offset;
double scale = 1.0;
// Currently, plot units are in decimil

View File

@ -24,9 +24,12 @@
#include <base_units.h>
#include <kiway.h>
#include <pgm_base.h>
#include <eeschema_settings.h>
#include <sch_draw_panel.h>
#include <sch_view.h>
#include <sch_painter.h>
#include <settings/settings_manager.h>
#include <gal/graphics_abstraction_layer.h>
#include <confirm.h>
#include <preview_items/selection_area.h>
@ -446,3 +449,19 @@ void SCH_BASE_FRAME::SyncView()
}
COLOR4D SCH_BASE_FRAME::GetLayerColor( SCH_LAYER_ID aLayer )
{
return GetColorSettings()->GetColor( aLayer );
}
COLOR_SETTINGS* SCH_BASE_FRAME::GetColorSettings()
{
if( !m_colorSettings )
{
auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
m_colorSettings = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme );
}
return m_colorSettings;
}

View File

@ -339,6 +339,13 @@ public:
*/
virtual void OnModify() {}
/**
* Helper to retrieve a layer color from the global color settings
*/
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer );
COLOR_SETTINGS* GetColorSettings() override;
protected:
/**
* Saves Symbol Library Tables to disk.

View File

@ -63,7 +63,16 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
m_painter->GetSettings()->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
COLOR_SETTINGS* cs = nullptr;
if( auto frame = dynamic_cast<SCH_BASE_FRAME*>( aParentWindow ) )
cs = frame->GetColorSettings();
else
cs = Pgm().GetSettingsManager().GetColorSettings();
wxASSERT( cs );
m_painter->GetSettings()->LoadColors( cs );
m_view->SetPainter( m_painter.get() );
m_view->SetScaleLimits( 1000.0, 0.0001 ); // This fixes the zoom in and zoom out limits

View File

@ -2290,7 +2290,7 @@ void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine )
m_out->Print( 0, " %s %s", T_STYLE,
SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
if( aLine->GetLineColor() != aLine->GetDefaultColor() )
if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
m_out->Print( 0, " %s",
TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
}

View File

@ -222,17 +222,8 @@ double SCH_LINE::GetLength() const
}
COLOR4D SCH_LINE::GetDefaultColor() const
{
return GetLayerColor( m_Layer );
}
void SCH_LINE::SetLineColor( const COLOR4D aColor )
{
if( aColor == GetDefaultColor() )
m_color = COLOR4D::UNSPECIFIED;
else
m_color = aColor;
}
@ -241,7 +232,7 @@ void SCH_LINE::SetLineColor( const double r, const double g, const double b, con
{
COLOR4D newColor(r, g, b, a);
if( newColor == GetDefaultColor() || newColor == COLOR4D::UNSPECIFIED )
if( newColor == COLOR4D::UNSPECIFIED )
m_color = COLOR4D::UNSPECIFIED;
else
{
@ -254,12 +245,10 @@ void SCH_LINE::SetLineColor( const double r, const double g, const double b, con
COLOR4D SCH_LINE::GetLineColor() const
{
if( m_color == COLOR4D::UNSPECIFIED )
return GetLayerColor( m_Layer );
return m_color;
}
PLOT_DASH_TYPE SCH_LINE::GetDefaultStyle() const
{
if( IsGraphicLine() )

View File

@ -118,10 +118,9 @@ public:
void SetLineColor( const double r, const double g, const double b, const double a );
/// Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line
COLOR4D GetLineColor() const;
COLOR4D GetDefaultColor() const;
int GetDefaultWidth() const;
void SetLineWidth( const int aSize );

View File

@ -240,7 +240,12 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr
COLOR4D color = m_schSettings.GetLayerColor( aLayer );
if( aItem->Type() == SCH_LINE_T )
color = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
{
COLOR4D lineColor = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
if( lineColor != COLOR4D::UNSPECIFIED )
color = lineColor;
}
if( aItem->IsBrightened() && !aDrawingShadows ) // Selection disambiguation, etc.
{

View File

@ -1,310 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2016-2018 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 2
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Set up colors to draw items in Eeschema
*/
#include <fctsys.h>
#include <eda_draw_frame.h>
#include <sch_draw_panel.h>
#include <sch_view.h>
#include <general.h>
#include <painter.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include "widget_eeschema_color_config.h"
#include <dialogs/dialog_color_picker.h>
// Width and height of every (color-displaying / bitmap) button in dialog units
const wxSize BUTT_SIZE( 10, 6 );
const wxSize BUTT_BORDER( 4, 4 );
/********************/
/* Layer menu list. */
/********************/
struct COLORBUTTON
{
wxString m_Name;
int m_Layer;
};
struct BUTTONINDEX
{
wxString m_Name;
COLORBUTTON* m_Buttons;
};
static COLORBUTTON generalColorButtons[] = {
{ _( "Wire" ), LAYER_WIRE },
{ _( "Bus" ), LAYER_BUS },
{ _( "Junction" ), LAYER_JUNCTION },
{ _( "Label" ), LAYER_LOCLABEL },
{ _( "Global label" ), LAYER_GLOBLABEL },
{ _( "Net name" ), LAYER_NETNAM },
{ _( "Notes" ), LAYER_NOTES },
{ _( "No connect symbol" ), LAYER_NOCONNECT },
{ wxT( "" ), -1 } // Sentinel marking end of list.
};
static COLORBUTTON componentColorButtons[] = {
{ _( "Body outline" ), LAYER_DEVICE },
{ _( "Body background" ), LAYER_DEVICE_BACKGROUND },
{ _( "Pin" ), LAYER_PIN },
{ _( "Pin number" ), LAYER_PINNUM },
{ _( "Pin name" ), LAYER_PINNAM },
{ _( "Reference" ), LAYER_REFERENCEPART },
{ _( "Value" ), LAYER_VALUEPART },
{ _( "Fields" ), LAYER_FIELDS },
{ wxT( "" ), -1 } // Sentinel marking end of list.
};
static COLORBUTTON sheetColorButtons[] = {
{ _( "Sheet" ), LAYER_SHEET },
{ _( "Sheet file name" ), LAYER_SHEETFILENAME },
{ _( "Sheet name" ), LAYER_SHEETNAME },
{ _( "Sheet label" ), LAYER_SHEETLABEL },
{ _( "Hierarchical label" ),LAYER_HIERLABEL },
{ wxT( "" ), -1 } // Sentinel marking end of list.
};
static COLORBUTTON miscColorButtons[] = {
{ _( "ERC warning" ), LAYER_ERC_WARN },
{ _( "ERC error" ), LAYER_ERC_ERR },
{ _( "Brightened" ), LAYER_BRIGHTENED },
{ _( "Hidden item" ), LAYER_HIDDEN },
{ _( "Worksheet" ), LAYER_SCHEMATIC_WORKSHEET },
{ _( "Cursor" ), LAYER_SCHEMATIC_CURSOR },
{ _( "Grid" ), LAYER_SCHEMATIC_GRID },
{ _( "Background" ), LAYER_SCHEMATIC_BACKGROUND },
{ _( "Selection highlight" ), LAYER_SELECTION_SHADOWS },
{ wxT( "" ), -1 } // Sentinel marking end of list.
};
static BUTTONINDEX buttonGroups[] = {
{ _( "General" ), generalColorButtons },
{ _( "Component" ), componentColorButtons },
{ _( "Sheet" ), sheetColorButtons },
{ _( "Miscellaneous" ), miscColorButtons },
{ wxT( "" ), NULL }
};
static COLORBUTTON bgColorButton = { "", LAYER_SCHEMATIC_BACKGROUND };
static COLOR4D currentColors[ LAYER_ID_COUNT ];
WIDGET_EESCHEMA_COLOR_CONFIG::WIDGET_EESCHEMA_COLOR_CONFIG( wxWindow* aParent, EDA_DRAW_FRAME* aDrawFrame ) :
wxPanel( aParent ), m_drawFrame( aDrawFrame )
{
m_butt_size_pix = ConvertDialogToPixels( BUTT_SIZE );
m_butt_border_pix = ConvertDialogToPixels( BUTT_BORDER );
CreateControls();
}
void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
{
wxStaticText* label;
int buttonId = 1800;
m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( m_mainBoxSizer );
BUTTONINDEX* groups = buttonGroups;
wxBoxSizer* columnBoxSizer = NULL;
while( groups->m_Buttons != NULL )
{
COLORBUTTON* buttons = groups->m_Buttons;
columnBoxSizer = new wxBoxSizer( wxVERTICAL );
m_mainBoxSizer->Add( columnBoxSizer, 1, wxALIGN_TOP | wxLEFT, 5 );
wxBoxSizer* rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
// Add a text string to identify the column of color select buttons.
label = new wxStaticText( this, wxID_ANY, groups->m_Name );
// Make the column label font bold.
wxFont font( label->GetFont() );
font.SetWeight( wxFONTWEIGHT_BOLD );
label->SetFont( font );
rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
while( buttons->m_Layer >= 0 )
{
rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 );
COLOR4D color = m_drawFrame->GetLayerColor( SCH_LAYER_ID( buttons->m_Layer ) );
currentColors[ buttons->m_Layer ] = color;
wxMemoryDC iconDC;
wxBitmap bitmap( m_butt_size_pix );
iconDC.SelectObject( bitmap );
iconDC.SetPen( *wxBLACK_PEN );
wxBrush brush;
brush.SetColour( color.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
wxBitmapButton* bitmapButton = new wxBitmapButton(
this, buttonId, bitmap, wxDefaultPosition,
m_butt_size_pix + m_butt_border_pix + wxSize( 1, 1 ) );
bitmapButton->SetClientData( (void*) buttons );
rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) );
rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
buttonId += 1;
buttons++;
}
groups++;
}
Connect( 1800, buttonId, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
// Dialog now needs to be resized, but the associated command is found elsewhere.
}
void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor( wxCommandEvent& event )
{
wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
COLOR4D oldColor = currentColors[ colorButton->m_Layer ];
COLOR4D newColor = COLOR4D::UNSPECIFIED;
DIALOG_COLOR_PICKER dialog( this, oldColor, false );
if( dialog.ShowModal() == wxID_OK )
{
newColor = dialog.GetColor();
}
if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
return;
currentColors[ colorButton->m_Layer ] = newColor;
wxMemoryDC iconDC;
wxBitmap bitmap = button->GetBitmapLabel();
iconDC.SelectObject( bitmap );
iconDC.SetPen( *wxBLACK_PEN );
wxBrush brush;
brush.SetColour( newColor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
button->SetBitmapLabel( bitmap );
button->Refresh();
Refresh( false );
}
bool WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl()
{
// Check for color conflicts with background color to give user a chance to bail
// out before making changes.
COLOR4D bgcolor = currentColors[ LAYER_SCHEMATIC_BACKGROUND ];
for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
{
if( bgcolor == currentColors[ clyr ] && clyr != LAYER_SCHEMATIC_BACKGROUND )
{
wxString msg = _( "Some items have the same color as the background\n"
"and they will not be seen on the screen. Are you\n"
"sure you want to use these colors?" );
if( wxMessageBox( msg, _( "Warning" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
return false;
break;
}
}
COLOR_SETTINGS* color_settings = Pgm().GetSettingsManager().GetColorSettings();
for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
{
// Do not allow non-background layers to be completely white.
// This ensures the BW printing recognizes that the colors should be printed black.
if( currentColors[ clyr ] == COLOR4D::WHITE && clyr != LAYER_SCHEMATIC_BACKGROUND )
currentColors[ clyr ].Darken( 0.01 );
color_settings->SetColor( clyr, currentColors[ clyr ] );
}
auto settings = m_drawFrame->GetCanvas()->GetView()->GetPainter()->GetSettings();
settings->LoadColors( color_settings );
Pgm().GetSettingsManager().SaveColorSettings( color_settings, "schematic" );
OnColorsChanged();
return true;
}
PANEL_EESCHEMA_COLOR_CONFIG::PANEL_EESCHEMA_COLOR_CONFIG( EDA_DRAW_FRAME* aFrame,
wxWindow* aParent ) :
wxPanel( aParent )
{
auto sizer = new wxBoxSizer( wxVERTICAL );
SetSizer( sizer );
m_colorConfig = new WIDGET_EESCHEMA_COLOR_CONFIG( this, aFrame );
sizer->Add( m_colorConfig, 1, wxEXPAND | wxLEFT | wxRIGHT, 5 );
}
bool PANEL_EESCHEMA_COLOR_CONFIG::TransferDataToWindow()
{
return true;
}
bool PANEL_EESCHEMA_COLOR_CONFIG::TransferDataFromWindow()
{
return m_colorConfig->TransferDataFromControl();
}

View File

@ -1,77 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 G. Harland
* Copyright (C) 1992-2018 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 2
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef WIDGET_EESCHEMA_COLOR_CONFIG_H_
#define WIDGET_EESCHEMA_COLOR_CONFIG_H_
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/colordlg.h>
#include <wx/clrpicker.h>
class wxBoxSizer;
class wxStaticLine;
class wxStdDialogButtonSizer;
/***********************************************/
/* Derived class for the frame color settings. */
/***********************************************/
class WIDGET_EESCHEMA_COLOR_CONFIG : public wxPanel
{
private:
EDA_DRAW_FRAME* m_drawFrame;
wxBoxSizer* m_mainBoxSizer;
wxSize m_butt_size_pix;
wxSize m_butt_border_pix;
// Creates the controls and sizers
void CreateControls();
void SetColor( wxCommandEvent& aEvent );
virtual EDA_DRAW_FRAME* GetDrawFrame() { return m_drawFrame; }
public:
// Constructors and destructor
WIDGET_EESCHEMA_COLOR_CONFIG( wxWindow* aParent, EDA_DRAW_FRAME* aDrawFrame );
bool TransferDataFromControl();
};
class PANEL_EESCHEMA_COLOR_CONFIG : public wxPanel
{
public:
PANEL_EESCHEMA_COLOR_CONFIG( EDA_DRAW_FRAME* aFrame, wxWindow* aParent );
protected:
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
WIDGET_EESCHEMA_COLOR_CONFIG* m_colorConfig;
};
#endif // WIDGET_EESCHEMA_COLOR_CONFIG_H_

View File

@ -37,6 +37,7 @@
class wxSingleInstanceChecker;
class ACTION_TOOLBAR;
class COLOR_SETTINGS;
class TOOL_MENU;
class APP_SETTINGS_BASE;
@ -112,6 +113,8 @@ protected:
EDA_MSG_PANEL* m_messagePanel;
int m_MsgFrameHeight;
COLOR_SETTINGS* m_colorSettings;
/// The current canvas type
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType;
@ -227,10 +230,8 @@ public:
*/
virtual void SetDrawBgColor( COLOR4D aColor) { m_drawBgColor= aColor ; }
/**
* Helper to retrieve a layer color from the global color settings
*/
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer );
/// Returns a pointer to the active color theme settings
virtual COLOR_SETTINGS* GetColorSettings();
bool ShowPageLimits() const { return m_showPageLimits; }
void SetShowPageLimits( bool aShow ) { m_showPageLimits = aShow; }

View File

@ -345,6 +345,10 @@ enum LAYER_3D_ID : int
#define LAYER_ID_COUNT FPEDIT_LAYER_ID_END
/// Returns the string equivalent of a given layer
wxString LayerName( SCH_LAYER_ID aLayer );
// Some elements do not have yet a visibility control
// from a dialog, but have a visibility control flag.
// Here is a mask to set them visible, to be sure they are displayed

View File

@ -131,6 +131,9 @@ public:
WINDOW_SETTINGS m_Window;
/// Active color theme name
wxString m_ColorTheme;
///! Local schema version for common app settings
int m_appSettingsSchemaVersion;

View File

@ -87,6 +87,16 @@ public:
m_color_context = aContext;
}
const wxString& GetName()
{
return m_displayName;
}
void SetName( const wxString& aName )
{
m_displayName = aName;
}
private:
wxString m_displayName;

View File

@ -21,8 +21,8 @@
#ifndef _SETTINGS_MANAGER_H
#define _SETTINGS_MANAGER_H
#include <common.h> // for wxString hash
#include <settings/color_settings.h>
#include <wx/wx.h>
class COLOR_SETTINGS;
class COMMON_SETTINGS;
@ -96,7 +96,21 @@ public:
* @param aName is the name of the color scheme to load
* @return a loaded COLOR_SETTINGS object
*/
COLOR_SETTINGS* GetColorSettings( std::string aName = "default" );
COLOR_SETTINGS* GetColorSettings( const wxString& aName = "user" );
std::vector<COLOR_SETTINGS*> GetColorSettingsList()
{
std::vector<COLOR_SETTINGS*> ret;
for( const auto& el : m_color_settings )
ret.push_back( el.second );
std::sort( ret.begin(), ret.end(), []( COLOR_SETTINGS* a, COLOR_SETTINGS* b ) {
return a->GetName() < b->GetName();
} );
return ret;
}
/**
* Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
@ -109,6 +123,13 @@ public:
*/
void SaveColorSettings( COLOR_SETTINGS* aSettings, const std::string& aNamespace = "" );
/**
* Registers a new color settings object with the given filename
* @param aFilename is the location to store the new settings object
* @return a pointer to the new object
*/
COLOR_SETTINGS* AddNewColorSettings( const wxString& aFilename );
/**
* Retrieves the common settings shared by all applications
* @return a pointer to a loaded COMMON_SETTINGS
@ -221,9 +242,20 @@ private:
*/
static bool extractVersion( const std::string& aVersionString, int* aMajor, int* aMinor );
/**
* Attempts to load a color theme by name (the color theme directory and .json ext are assumed)
* @param aName is the filename of the color theme (without the extension or path)
* @return the loaded settings, or nullptr if load failed
*/
COLOR_SETTINGS* loadColorSettingsByName( const wxString& aName );
void registerColorSettings( const wxString& aFilename );
void loadAllColorSettings();
std::vector<std::unique_ptr<JSON_SETTINGS>> m_settings;
std::unordered_map<std::string, COLOR_SETTINGS*> m_color_settings;
std::unordered_map<wxString, COLOR_SETTINGS*> m_color_settings;
// Convenience shortcut
COMMON_SETTINGS* m_common_settings;

View File

@ -118,22 +118,3 @@ KIFACE_I& Kiface()
{
return kiface;
}
static COLOR4D s_layerColor[LAYER_ID_COUNT];
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
{
unsigned layer = ( aLayer );
wxASSERT( layer < arrayDim( s_layerColor ) );
return s_layerColor[layer];
}
void OnColorsChanged()
{
COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetColorSettings();
for( SCH_LAYER_ID layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; ++layer )
s_layerColor[layer] = cs->GetColor( layer );
}