From 8660b4c1440cc21df4273263e66eae9eab6afc8a Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 3 Feb 2020 17:46:58 +0100 Subject: [PATCH] ADDED: New color theme editor and multi-theme support --- common/CMakeLists.txt | 3 + common/dialogs/panel_color_settings.cpp | 39 + common/dialogs/panel_color_settings.h | 39 + common/dialogs/panel_color_settings_base.cpp | 163 +++ common/dialogs/panel_color_settings_base.fbp | 1043 +++++++++++++++++ common/dialogs/panel_color_settings_base.h | 77 ++ common/eda_draw_frame.cpp | 8 +- common/layer_id.cpp | 124 ++ common/settings/app_settings.cpp | 2 + common/settings/color_settings.cpp | 1 - common/settings/settings_manager.cpp | 110 +- eeschema/CMakeLists.txt | 2 +- eeschema/class_libentry.cpp | 5 +- eeschema/dialogs/dialog_edit_line_style.cpp | 19 +- .../dialogs/panel_eeschema_color_settings.cpp | 674 +++++++++++ .../dialogs/panel_eeschema_color_settings.h | 130 ++ eeschema/eeschema.cpp | 22 - eeschema/eeschema_config.cpp | 13 +- eeschema/general.h | 14 +- eeschema/lib_bezier.cpp | 5 +- eeschema/plot_schematic_DXF.cpp | 3 + eeschema/plot_schematic_HPGL.cpp | 3 + eeschema/plot_schematic_PDF.cpp | 3 + eeschema/plot_schematic_PS.cpp | 3 + eeschema/plot_schematic_SVG.cpp | 2 + eeschema/sch_base_frame.cpp | 19 + eeschema/sch_base_frame.h | 7 + eeschema/sch_draw_panel.cpp | 11 +- eeschema/sch_legacy_plugin.cpp | 2 +- eeschema/sch_line.cpp | 17 +- eeschema/sch_line.h | 3 +- eeschema/sch_painter.cpp | 7 +- .../widgets/widget_eeschema_color_config.cpp | 310 ----- .../widgets/widget_eeschema_color_config.h | 77 -- include/eda_draw_frame.h | 9 +- include/layers_id_colors_and_visibility.h | 4 + include/settings/app_settings.h | 3 + include/settings/color_settings.h | 10 + include/settings/settings_manager.h | 38 +- qa/eeschema/mocks_eeschema.cpp | 19 - 40 files changed, 2552 insertions(+), 491 deletions(-) create mode 100644 common/dialogs/panel_color_settings.cpp create mode 100644 common/dialogs/panel_color_settings.h create mode 100644 common/dialogs/panel_color_settings_base.cpp create mode 100644 common/dialogs/panel_color_settings_base.fbp create mode 100644 common/dialogs/panel_color_settings_base.h create mode 100644 common/layer_id.cpp create mode 100644 eeschema/dialogs/panel_eeschema_color_settings.cpp create mode 100644 eeschema/dialogs/panel_eeschema_color_settings.h delete mode 100644 eeschema/widgets/widget_eeschema_color_config.cpp delete mode 100644 eeschema/widgets/widget_eeschema_color_config.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 48fbb74487..93a05ac8ef 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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 diff --git a/common/dialogs/panel_color_settings.cpp b/common/dialogs/panel_color_settings.cpp new file mode 100644 index 0000000000..fcd1d84f00 --- /dev/null +++ b/common/dialogs/panel_color_settings.cpp @@ -0,0 +1,39 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jon Evans + * 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 . + */ + +#include +#include +#include +#include +#include + + +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 ); +} diff --git a/common/dialogs/panel_color_settings.h b/common/dialogs/panel_color_settings.h new file mode 100644 index 0000000000..18631e37e4 --- /dev/null +++ b/common/dialogs/panel_color_settings.h @@ -0,0 +1,39 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jon Evans + * 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 . + */ + +#ifndef PANEL_COLOR_SETTINGS_H +#define PANEL_COLOR_SETTINGS_H + +#include + + +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 diff --git a/common/dialogs/panel_color_settings_base.cpp b/common/dialogs/panel_color_settings_base.cpp new file mode 100644 index 0000000000..c98f7fa869 --- /dev/null +++ b/common/dialogs/panel_color_settings_base.cpp @@ -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 ); + +} diff --git a/common/dialogs/panel_color_settings_base.fbp b/common/dialogs/panel_color_settings_base.fbp new file mode 100644 index 0000000000..06f0f75522 --- /dev/null +++ b/common/dialogs/panel_color_settings_base.fbp @@ -0,0 +1,1043 @@ + + + + + ; + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + panel_color_settings_base + 1000 + none + + 1 + PanelColorSettings + + . + + 1 + 1 + 1 + 1 + UI + 1 + 0 + + 0 + wxAUI_MGR_DEFAULT + + + 1 + 1 + impl_virtual + + + 0 + wxID_ANY + + + PANEL_COLOR_SETTINGS_BASE + + 826,300 + ; ; forward_declare + + + + wxTAB_TRAVERSAL + OnSize + + + m_mainSizer + wxVERTICAL + protected + + 5 + wxEXPAND + 0 + + + bControlSizer + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Theme: + 0 + + 0 + + + 0 + + 1 + m_staticText9 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "User" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + 150,-1 + 1 + m_cbTheme + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnThemeChanged + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 0 + + 1 + + + 0 + 0 + wxID_ANY + &Save + + 0 + + 0 + + + 0 + + 1 + m_btnSave + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + Save the active color theme + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnSaveClicked + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + &New + + 0 + + 0 + + + 0 + + 1 + m_btnNew + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + Create a new color theme based on the current one + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnNewClicked + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 0 + + 1 + + + 0 + 0 + wxID_ANY + Rename + + 0 + + 0 + + + 0 + + 1 + m_btnRename + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + The "User" theme cannot be renamed + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnRenameClicked + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + &Reset colors to default + + 0 + + 0 + + + 0 + + 1 + m_btnReset + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + Reset all colors in this theme to the KiCad defaults + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnResetClicked + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Open theme folder + + 0 + + 0 + + + 0 + + 1 + m_btnOpenFolder + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + Open the folder containing color themes + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnOpenThemeFolderClicked + + + + + + 0 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 1 + wxID_ANY + + 0 + + + 0 + + 1 + m_panelThemeProperties + 1 + + + protected + 1 + + Resizable + 1 + + ; ; forward_declare + 0 + + + + wxTAB_TRAVERSAL + + + m_sizerThemeProperties + wxHORIZONTAL + protected + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Theme name: + 0 + + 0 + + + 0 + + 1 + m_staticText6 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 48 + + 0 + 200,-1 + 1 + m_txtThemeName + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Name of the theme + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnThemeNameChanged + + + + 5 + wxEXPAND + 0 + + 0 + protected + 24 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Filename: + 0 + + 0 + + + 0 + + 1 + m_staticText7 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + 200,-1 + 1 + m_txtFilename + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Filename to save the theme to (must end in .json) + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnFilenameChar + OnFilenameChanged + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + 255,0,0 + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + + 0 + + 1 + m_lblThemePropertiesError + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + + + + 5 + wxEXPAND + 1 + + + m_colorsMainSizer + wxHORIZONTAL + protected + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + 240,-1 + 1 + m_colorsListWindow + 1 + + + protected + 1 + + Resizable + 5 + 5 + 1 + + ; ; forward_declare + 0 + + + + wxVSCROLL + + 2 + wxHORIZONTAL + 0 + + 5 + + m_colorsGridSizer + wxFLEX_GROWMODE_NONE + protected + 0 + 5 + + + + + + + + + diff --git a/common/dialogs/panel_color_settings_base.h b/common/dialogs/panel_color_settings_base.h new file mode 100644 index 0000000000..6814d6abb0 --- /dev/null +++ b/common/dialogs/panel_color_settings_base.h @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// 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(); + +}; + diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index b0c6250502..70f4066ae7 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -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; } diff --git a/common/layer_id.cpp b/common/layer_id.cpp new file mode 100644 index 0000000000..44f777d8b7 --- /dev/null +++ b/common/layer_id.cpp @@ -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 . + */ + +#include +#include + + +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; + } +} \ No newline at end of file diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index c6782b0416..601d820b09 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -82,6 +82,8 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( std::string aFilename, int aSchemaVersion m_params.emplace_back( new PARAM( "system.units", &m_System.units, static_cast( EDA_UNITS::MILLIMETRES ) ) ); + m_params.emplace_back( new PARAM( "appearance.color_theme", &m_ColorTheme, "user" ) ); + addParamsForWindow( &m_Window, "window" ); } diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index 21ab37d8ed..b71e47b5e4 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -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 ) ); diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index c1699eb62b..2dca095094 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -58,9 +58,7 @@ SETTINGS_MANAGER::SETTINGS_MANAGER() : m_common_settings = static_cast( RegisterSettings( new COMMON_SETTINGS, false ) ); - // create the default color settings - m_color_settings["default"] = - static_cast( 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( + 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 m_action; + +public: + explicit COLOR_SETTINGS_LOADER( std::function 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( + 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(); diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 7b4f028cad..af777411b0 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -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 ) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 13d4dd6e9b..34f9a95fd9 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -39,6 +39,7 @@ #include #include #include +#include // 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 ) diff --git a/eeschema/dialogs/dialog_edit_line_style.cpp b/eeschema/dialogs/dialog_edit_line_style.cpp index 9d736064e3..b5fcd6108e 100644 --- a/eeschema/dialogs/dialog_edit_line_style.cpp +++ b/eeschema/dialogs/dialog_edit_line_style.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include 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,7 +190,15 @@ void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event ) void DIALOG_EDIT_LINE_STYLE::setColor( const COLOR4D& aColor ) { m_selectedColor = aColor; - updateColorButton( m_selectedColor ); + + 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 ); - } + line->SetLineColor( m_selectedColor ); m_frame->RefreshItem( line ); } diff --git a/eeschema/dialogs/panel_eeschema_color_settings.cpp b/eeschema/dialogs/panel_eeschema_color_settings.cpp new file mode 100644 index 0000000000..1480b08073 --- /dev/null +++ b/eeschema/dialogs/panel_eeschema_color_settings.cpp @@ -0,0 +1,674 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jon Evans + * 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 . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// 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(); + + 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( 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( 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( 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( 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(); + + 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 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( 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>> 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( event.GetEventObject() ); + auto layer = + static_cast( 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( 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( 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( 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 ); +} diff --git a/eeschema/dialogs/panel_eeschema_color_settings.h b/eeschema/dialogs/panel_eeschema_color_settings.h new file mode 100644 index 0000000000..6169705150 --- /dev/null +++ b/eeschema/dialogs/panel_eeschema_color_settings.h @@ -0,0 +1,130 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jon Evans + * 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 . + */ + +#ifndef PANEL_EESCHEMA_COLOR_SETTINGS_H_ +#define PANEL_EESCHEMA_COLOR_SETTINGS_H_ + +#include +#include +#include + +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 m_previewItems; + + std::map 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 diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 7ba44632b7..8611ec6f38 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -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() ) diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index bfd69e2351..4fec0f71eb 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -42,10 +43,11 @@ #include #include #include +#include #include #include #include -#include +//#include #include #include @@ -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" ) ); diff --git a/eeschema/general.h b/eeschema/general.h index 5ef462acc6..ce5c34f70d 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -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_ diff --git a/eeschema/lib_bezier.cpp b/eeschema/lib_bezier.cpp index 8e9e81d22b..eac900386b 100644 --- a/eeschema/lib_bezier.cpp +++ b/eeschema/lib_bezier.cpp @@ -34,6 +34,7 @@ #include #include #include +#include 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 ); } } diff --git a/eeschema/plot_schematic_DXF.cpp b/eeschema/plot_schematic_DXF.cpp index e28c8251f9..1f76a90d25 100644 --- a/eeschema/plot_schematic_DXF.cpp +++ b/eeschema/plot_schematic_DXF.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -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 ); diff --git a/eeschema/plot_schematic_HPGL.cpp b/eeschema/plot_schematic_HPGL.cpp index 79ee686c7f..dd4cae5cfb 100644 --- a/eeschema/plot_schematic_HPGL.cpp +++ b/eeschema/plot_schematic_HPGL.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include @@ -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() ) diff --git a/eeschema/plot_schematic_PDF.cpp b/eeschema/plot_schematic_PDF.cpp index 1020de7b9b..1291867127 100644 --- a/eeschema/plot_schematic_PDF.cpp +++ b/eeschema/plot_schematic_PDF.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include @@ -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() ); diff --git a/eeschema/plot_schematic_PS.cpp b/eeschema/plot_schematic_PS.cpp index 8be731ecd3..519b1cb0e7 100644 --- a/eeschema/plot_schematic_PS.cpp +++ b/eeschema/plot_schematic_PS.cpp @@ -29,8 +29,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -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" ) ); diff --git a/eeschema/plot_schematic_SVG.cpp b/eeschema/plot_schematic_SVG.cpp index 9e9cac7240..fe318627c3 100644 --- a/eeschema/plot_schematic_SVG.cpp +++ b/eeschema/plot_schematic_SVG.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index f9a2cc81a8..8e08aba676 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -24,9 +24,12 @@ #include #include +#include +#include #include #include #include +#include #include #include #include @@ -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(); + m_colorSettings = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme ); + } + + return m_colorSettings; +} \ No newline at end of file diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 4d8c9d7ca8..e3ea9cdf99 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -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. diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index f38464dbe0..e1a7484702 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -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( 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 diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index c1d32ad6f6..40c60406c9 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -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 ) ) ); } diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index d628bde484..ef3b7a2cea 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -222,18 +222,9 @@ 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; + 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() ) diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index d611dcfb18..5afdaee902 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -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 ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 151573ea90..3621d780d9 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -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( aItem )->GetLineColor(); + { + COLOR4D lineColor = static_cast( aItem )->GetLineColor(); + + if( lineColor != COLOR4D::UNSPECIFIED ) + color = lineColor; + } if( aItem->IsBrightened() && !aDrawingShadows ) // Selection disambiguation, etc. { diff --git a/eeschema/widgets/widget_eeschema_color_config.cpp b/eeschema/widgets/widget_eeschema_color_config.cpp deleted file mode 100644 index 0358c728c5..0000000000 --- a/eeschema/widgets/widget_eeschema_color_config.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include - -#include "widget_eeschema_color_config.h" -#include - -// 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(); -} diff --git a/eeschema/widgets/widget_eeschema_color_config.h b/eeschema/widgets/widget_eeschema_color_config.h deleted file mode 100644 index 996a9523c1..0000000000 --- a/eeschema/widgets/widget_eeschema_color_config.h +++ /dev/null @@ -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 -#include -#include -#include - -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_ diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index c0dc23fee0..fd50930b8d 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -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; } diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index 7b724ee1cc..b40b521242 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -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 diff --git a/include/settings/app_settings.h b/include/settings/app_settings.h index db4d7a390e..cffc58a3bd 100644 --- a/include/settings/app_settings.h +++ b/include/settings/app_settings.h @@ -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; diff --git a/include/settings/color_settings.h b/include/settings/color_settings.h index 854e718da6..62e1930e21 100644 --- a/include/settings/color_settings.h +++ b/include/settings/color_settings.h @@ -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; diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index f5fe53a7fa..4ab86d599c 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -21,8 +21,8 @@ #ifndef _SETTINGS_MANAGER_H #define _SETTINGS_MANAGER_H +#include // for wxString hash #include -#include 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 GetColorSettingsList() + { + std::vector 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> m_settings; - std::unordered_map m_color_settings; + std::unordered_map m_color_settings; // Convenience shortcut COMMON_SETTINGS* m_common_settings; diff --git a/qa/eeschema/mocks_eeschema.cpp b/qa/eeschema/mocks_eeschema.cpp index d07273d194..cd50c44b50 100644 --- a/qa/eeschema/mocks_eeschema.cpp +++ b/qa/eeschema/mocks_eeschema.cpp @@ -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 ); -}