40 changed files with 2552 additions and 491 deletions
-
3common/CMakeLists.txt
-
39common/dialogs/panel_color_settings.cpp
-
39common/dialogs/panel_color_settings.h
-
163common/dialogs/panel_color_settings_base.cpp
-
1043common/dialogs/panel_color_settings_base.fbp
-
77common/dialogs/panel_color_settings_base.h
-
8common/eda_draw_frame.cpp
-
124common/layer_id.cpp
-
2common/settings/app_settings.cpp
-
1common/settings/color_settings.cpp
-
110common/settings/settings_manager.cpp
-
2eeschema/CMakeLists.txt
-
5eeschema/class_libentry.cpp
-
19eeschema/dialogs/dialog_edit_line_style.cpp
-
674eeschema/dialogs/panel_eeschema_color_settings.cpp
-
130eeschema/dialogs/panel_eeschema_color_settings.h
-
22eeschema/eeschema.cpp
-
13eeschema/eeschema_config.cpp
-
14eeschema/general.h
-
5eeschema/lib_bezier.cpp
-
3eeschema/plot_schematic_DXF.cpp
-
3eeschema/plot_schematic_HPGL.cpp
-
3eeschema/plot_schematic_PDF.cpp
-
3eeschema/plot_schematic_PS.cpp
-
2eeschema/plot_schematic_SVG.cpp
-
19eeschema/sch_base_frame.cpp
-
7eeschema/sch_base_frame.h
-
11eeschema/sch_draw_panel.cpp
-
2eeschema/sch_legacy_plugin.cpp
-
17eeschema/sch_line.cpp
-
3eeschema/sch_line.h
-
7eeschema/sch_painter.cpp
-
310eeschema/widgets/widget_eeschema_color_config.cpp
-
77eeschema/widgets/widget_eeschema_color_config.h
-
9include/eda_draw_frame.h
-
4include/layers_id_colors_and_visibility.h
-
3include/settings/app_settings.h
-
10include/settings/color_settings.h
-
38include/settings/settings_manager.h
-
19qa/eeschema/mocks_eeschema.cpp
@ -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 ); |
|||
} |
@ -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 |
@ -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 ); |
|||
|
|||
} |
1043
common/dialogs/panel_color_settings_base.fbp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
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(); |
|||
|
|||
}; |
|||
|
@ -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; |
|||
} |
|||
} |
@ -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 ); |
|||
} |
@ -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 |
@ -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(); |
|||
} |
@ -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_ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue