From 7c003f98d5249505465d58b41f1e6516a873af65 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 29 Sep 2020 23:29:58 -0400 Subject: [PATCH] ADDED: Appearance panel for footprint editor Fixes https://gitlab.com/kicad/code/kicad/-/issues/5643 --- common/CMakeLists.txt | 1 + common/project/board_project_settings.cpp | 130 +++++++++++++ common/project/project_file.cpp | 93 +--------- include/footprint_editor_settings.h | 4 + include/project/board_project_settings.h | 15 ++ pcbnew/footprint_edit_frame.cpp | 95 +++------- pcbnew/footprint_edit_frame.h | 20 -- pcbnew/footprint_editor_settings.cpp | 5 + pcbnew/footprint_editor_utils.cpp | 5 +- pcbnew/pcb_base_edit_frame.cpp | 1 - pcbnew/pcb_base_edit_frame.h | 3 - pcbnew/pcb_edit_frame.cpp | 1 - pcbnew/widgets/appearance_controls.cpp | 215 +++++++++++++++------- pcbnew/widgets/appearance_controls.h | 10 + 14 files changed, 341 insertions(+), 257 deletions(-) create mode 100644 common/project/board_project_settings.cpp diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 568624dc5b..97a40e04c1 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -437,6 +437,7 @@ set( COMMON_SRCS settings/nested_settings.cpp settings/settings_manager.cpp + project/board_project_settings.cpp project/net_settings.cpp project/project_archiver.cpp project/project_file.cpp diff --git a/common/project/board_project_settings.cpp b/common/project/board_project_settings.cpp new file mode 100644 index 0000000000..e32e3270cd --- /dev/null +++ b/common/project/board_project_settings.cpp @@ -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 . + */ + +#include +#include + +using namespace std::placeholders; + + +PARAM_LAYER_PRESET::PARAM_LAYER_PRESET( const std::string& aPath, + std::vector* aPresetList ) : + PARAM_LAMBDA( aPath, + std::bind( &PARAM_LAYER_PRESET::presetsToJson, this ), + std::bind( &PARAM_LAYER_PRESET::jsonToPresets, this, _1 ), + {} ), + m_presets( aPresetList ) +{ + wxASSERT( aPresetList ); +} + + +nlohmann::json PARAM_LAYER_PRESET::presetsToJson() +{ + nlohmann::json ret = nlohmann::json::array(); + + for( const LAYER_PRESET& preset : *m_presets ) + { + nlohmann::json js = { + { "name", preset.name }, + { "activeLayer", preset.activeLayer } + }; + + nlohmann::json layers = nlohmann::json::array(); + + for( PCB_LAYER_ID layer : preset.layers.Seq() ) + layers.push_back( static_cast( layer ) ); + + js["layers"] = layers; + + nlohmann::json renderLayers = nlohmann::json::array(); + + for( GAL_LAYER_ID layer : preset.renderLayers.Seq() ) + renderLayers.push_back( static_cast( layer ) ); + + js["renderLayers"] = renderLayers; + + ret.push_back( js ); + } + + return ret; +} + + +void PARAM_LAYER_PRESET::jsonToPresets( const nlohmann::json& aJson ) +{ + if( aJson.empty() || !aJson.is_array() ) + return; + + m_presets->clear(); + + for( const nlohmann::json& preset : aJson ) + { + if( preset.contains( "name" ) ) + { + LAYER_PRESET p( preset.at( "name" ).get() ); + + if( preset.contains( "activeLayer" ) && + preset.at( "activeLayer" ).is_number_integer() ) + { + int active = preset.at( "activeLayer" ).get(); + + if( active >= 0 && active < PCB_LAYER_ID_COUNT ) + p.activeLayer = static_cast( active ); + } + + if( preset.contains( "layers" ) && preset.at( "layers" ).is_array() ) + { + p.layers.reset(); + + for( const nlohmann::json& layer : preset.at( "layers" ) ) + { + if( layer.is_number_integer() ) + { + int layerNum = layer.get(); + + if( layerNum >= 0 && layerNum < PCB_LAYER_ID_COUNT ) + p.layers.set( layerNum ); + } + } + } + + if( preset.contains( "renderLayers" ) + && preset.at( "renderLayers" ).is_array() ) + { + p.renderLayers.reset(); + + for( const nlohmann::json& layer : preset.at( "renderLayers" ) ) + { + if( layer.is_number_integer() ) + { + int layerNum = layer.get(); + + if( layerNum >= GAL_LAYER_ID_START + && layerNum < GAL_LAYER_ID_END ) + p.renderLayers.set( static_cast( layerNum ) ); + } + } + } + + m_presets->emplace_back( p ); + } + } +} diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index 509782abc4..9a70817fd9 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -106,98 +106,7 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) : m_NetSettings = std::make_shared( this, "net_settings" ); - m_params.emplace_back( new PARAM_LAMBDA( "board.layer_presets", - [&]() -> nlohmann::json - { - nlohmann::json ret = nlohmann::json::array(); - - for( const LAYER_PRESET& preset : m_LayerPresets ) - { - nlohmann::json js = { - { "name", preset.name }, - { "activeLayer", preset.activeLayer } - }; - - nlohmann::json layers = nlohmann::json::array(); - - for( PCB_LAYER_ID layer : preset.layers.Seq() ) - layers.push_back( static_cast( layer ) ); - - js["layers"] = layers; - - nlohmann::json renderLayers = nlohmann::json::array(); - - for( GAL_LAYER_ID layer : preset.renderLayers.Seq() ) - renderLayers.push_back( static_cast( layer ) ); - - js["renderLayers"] = renderLayers; - - ret.push_back( js ); - } - - return ret; - }, - [&]( const nlohmann::json& aVal ) - { - if( aVal.empty() || !aVal.is_array() ) - return; - - m_LayerPresets.clear(); - - for( const nlohmann::json& preset : aVal ) - { - if( preset.contains( "name" ) ) - { - LAYER_PRESET p( preset.at( "name" ).get() ); - - if( preset.contains( "activeLayer" ) && - preset.at( "activeLayer" ).is_number_integer() ) - { - int active = preset.at( "activeLayer" ).get(); - - if( active >= 0 && active < PCB_LAYER_ID_COUNT ) - p.activeLayer = static_cast( active ); - } - - if( preset.contains( "layers" ) && preset.at( "layers" ).is_array() ) - { - p.layers.reset(); - - for( const nlohmann::json& layer : preset.at( "layers" ) ) - { - if( layer.is_number_integer() ) - { - int layerNum = layer.get(); - - if( layerNum >= 0 && layerNum < PCB_LAYER_ID_COUNT ) - p.layers.set( layerNum ); - } - } - } - - if( preset.contains( "renderLayers" ) - && preset.at( "renderLayers" ).is_array() ) - { - p.renderLayers.reset(); - - for( const nlohmann::json& layer : preset.at( "renderLayers" ) ) - { - if( layer.is_number_integer() ) - { - int layerNum = layer.get(); - - if( layerNum >= GAL_LAYER_ID_START - && layerNum < GAL_LAYER_ID_END ) - p.renderLayers.set( static_cast( layerNum ) ); - } - } - } - - m_LayerPresets.emplace_back( p ); - } - } - }, - {} ) ); + m_params.emplace_back( new PARAM_LAYER_PRESET( "board.layer_presets", &m_LayerPresets ) ); } diff --git a/include/footprint_editor_settings.h b/include/footprint_editor_settings.h index 1b608827f9..6de2586fef 100644 --- a/include/footprint_editor_settings.h +++ b/include/footprint_editor_settings.h @@ -69,6 +69,10 @@ public: SELECTION_FILTER_OPTIONS m_SelectionFilter; + std::vector m_LayerPresets; + + wxString m_ActiveLayerPreset; + protected: virtual std::string getLegacyFrameName() const override { return "ModEditFrame"; } diff --git a/include/project/board_project_settings.h b/include/project/board_project_settings.h index 71d85949d7..566d19a5b2 100644 --- a/include/project/board_project_settings.h +++ b/include/project/board_project_settings.h @@ -22,6 +22,7 @@ #define KICAD_BOARD_PROJECT_SETTINGS_H #include +#include /** * This file contains data structures that are saved in the project file or project local settings @@ -159,4 +160,18 @@ struct LAYER_PRESET } }; + +class PARAM_LAYER_PRESET : public PARAM_LAMBDA +{ +public: + PARAM_LAYER_PRESET( const std::string& aPath, std::vector* aPresetList ); + +private: + nlohmann::json presetsToJson(); + + void jsonToPresets( const nlohmann::json& aJson ); + + std::vector* m_presets; +}; + #endif // KICAD_BOARD_PROJECT_SETTINGS_H diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index de850aae37..cdd3b5a6fd 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -69,6 +68,7 @@ #include #include #include +#include #include #include #include @@ -135,7 +135,6 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, SetCanvas( drawPanel ); SetBoard( new BOARD() ); - m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), true ); // In modedit, the default net clearance is not known (it depends on the actual board). // So we do not show the default clearance, by setting it to 0. @@ -177,6 +176,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, ReCreateOptToolbar(); m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this ); + m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas(), true ); // LoadSettings() *after* creating m_LayersManager, because LoadSettings() initialize // parameters in m_LayersManager @@ -192,12 +192,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, GetBoard()->SetVisibleLayers( GetBoard()->GetEnabledLayers() ); GetBoard()->SetLayerName( In1_Cu, _( "Inner layers" ) ); - m_Layers->ReFill(); - m_Layers->ReFillRender(); - - GetScreen()->m_Active_Layer = F_SilkS; - m_Layers->SelectLayer( F_SilkS ); - m_Layers->OnLayerSelected(); + SetActiveLayer( F_SilkS ); // Create the infobar m_infoBar = new WX_INFOBAR( this, &m_auimgr ); @@ -218,10 +213,11 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, .BestSize( m_defaultLibWidth, -1 ) ); m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(2) ); - m_auimgr.AddPane( m_Layers, EDA_PANE().Palette().Name( "LayersManager" ).Right().Layer(3) - .Caption( _( "Layers Manager" ) ).PaneBorder( false ) - .MinSize( 80, -1 ).BestSize( m_Layers->GetBestSize() ) ); + m_auimgr.AddPane( m_appearancePanel, + EDA_PANE().Name( "LayersManager" ).Right().Layer( 3 ) + .Caption( _( "Appearance" ) ).PaneBorder( false ) + .MinSize( 180, -1 ).BestSize( 180, -1 ) ); m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Palette().Name( "SelectionFilter" ).Right().Layer( 3 ) .Caption( _( "Selection Filter" ) ).PaneBorder( false ).Position( 2 ) @@ -242,6 +238,11 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, m_auimgr.GetPane( "InfoBar" ).Hide(); m_auimgr.Update(); + // Apply saved visibility stuff at the end + FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings(); + m_appearancePanel->SetUserLayerPresets( cfg->m_LayerPresets ); + m_appearancePanel->ApplyLayerPreset( cfg->m_ActiveLayerPreset ); + GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false ); updateTitle(); InitExitKey(); @@ -265,7 +266,7 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME() retainLastFootprint(); delete m_selectionFilterPanel; - delete m_Layers; + delete m_appearancePanel; } @@ -477,10 +478,12 @@ void FOOTPRINT_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) PCB_BASE_FRAME::SaveSettings( cfg ); - cfg->m_DesignSettings = GetDesignSettings(); - cfg->m_Display = m_DisplayOptions; - cfg->m_LibWidth = m_treePane->GetSize().x; - cfg->m_SelectionFilter = GetToolManager()->GetTool()->GetFilter(); + cfg->m_DesignSettings = GetDesignSettings(); + cfg->m_Display = m_DisplayOptions; + cfg->m_LibWidth = m_treePane->GetSize().x; + cfg->m_SelectionFilter = GetToolManager()->GetTool()->GetFilter(); + cfg->m_LayerPresets = m_appearancePanel->GetUserLayerPresets(); + cfg->m_ActiveLayerPreset = m_appearancePanel->GetActiveLayerPreset(); GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" ); } @@ -639,28 +642,6 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent } -void FOOTPRINT_EDIT_FRAME::ReFillLayerWidget() -{ - - m_Layers->Freeze(); - m_Layers->ReFill(); - m_Layers->Thaw(); - - wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_Layers ); - - wxSize bestz = m_Layers->GetBestSize(); - - lyrs.MinSize( bestz ); - lyrs.BestSize( bestz ); - lyrs.FloatingSize( bestz ); - - if( lyrs.IsDocked() ) - m_auimgr.Update(); - else - m_Layers->SetSize( bestz ); -} - - void FOOTPRINT_EDIT_FRAME::ShowChangedLanguage() { // call my base class @@ -673,12 +654,12 @@ void FOOTPRINT_EDIT_FRAME::ShowChangedLanguage() bool tree_shown = tree_pane_info.IsShown(); tree_pane_info.Caption( _( "Libraries" ) ); - wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_Layers ); + wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_appearancePanel ); bool lm_shown = lm_pane_info.IsShown(); - lm_pane_info.Caption( _( "Layers Manager" ) ); + lm_pane_info.Caption( _( "Appearance" ) ); // update the layer manager - m_Layers->SetLayersManagerTabsText(); + m_appearancePanel->OnBoardChanged(); UpdateUserInterface(); // Now restore the visibility: @@ -740,21 +721,7 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() void FOOTPRINT_EDIT_FRAME::UpdateUserInterface() { - // Update the layer manager and other widgets from the board setup - // (layer and items visibility, colors ...) - - // Update the layer manager - m_Layers->Freeze(); - ReFillLayerWidget(); - m_Layers->ReFillRender(); - - // update the layer widget to match board visibility states. - m_Layers->SyncLayerVisibilities(); - GetCanvas()->SyncLayersVisibility( m_Pcb ); - m_Layers->SelectLayer( GetActiveLayer() ); - m_Layers->OnLayerSelected(); - - m_Layers->Thaw(); + m_appearancePanel->OnBoardChanged(); } @@ -847,23 +814,9 @@ void FOOTPRINT_EDIT_FRAME::FocusOnLibID( const LIB_ID& aLibID ) } -bool FOOTPRINT_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const -{ - return GetBoard()->IsElementVisible( aElement ); -} - - -void FOOTPRINT_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState ) -{ - GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState ); - GetBoard()->SetElementVisibility( aElement, aNewState ); - m_Layers->SetRenderState( aElement, aNewState ); -} - - void FOOTPRINT_EDIT_FRAME::OnUpdateLayerAlpha( wxUpdateUIEvent & ) { - m_Layers->SyncLayerAlphaIndicators(); + m_appearancePanel->OnLayerAlphaChanged(); } diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 6c2f0715b2..fda95618af 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -260,24 +260,6 @@ public: */ bool DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm ); - /** - * Test whether a given element category is visible. - * - * @param aElement is from the enum by the same name - * @return bool - true if the element is visible. - * @see enum PCB_LAYER_ID - */ - bool IsElementVisible( GAL_LAYER_ID aElement ) const; - - /** - * Function SetElementVisibility - * changes the visibility of an element category - * @param aElement is from the enum by the same name - * @param aNewState = The new visibility state of the element category - * @see enum PCB_LAYER_ID - */ - void SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState ); - /** * @return the color of the grid */ @@ -314,8 +296,6 @@ public: */ void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override; - void ReFillLayerWidget(); - /** * Update visible items after a language change. */ diff --git a/pcbnew/footprint_editor_settings.cpp b/pcbnew/footprint_editor_settings.cpp index ba2607e1ad..c84f80d30c 100644 --- a/pcbnew/footprint_editor_settings.cpp +++ b/pcbnew/footprint_editor_settings.cpp @@ -77,6 +77,11 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_params.emplace_back( new PARAM( "pcb_display.pad_fill", &m_Display.m_DisplayPadFill, true ) ); + m_params.emplace_back( new PARAM_LAYER_PRESET( "pcb_display.layer_presets", &m_LayerPresets ) ); + + m_params.emplace_back( new PARAM( "pcb_display.active_layer_preset", + &m_ActiveLayerPreset, "" ) ); + m_params.emplace_back( new PARAM_LAMBDA( "design_settings.default_footprint_text_items", [&] () -> nlohmann::json diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 72887f162b..19d4904308 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,7 @@ #include #include #include +#include #include using namespace std::placeholders; @@ -427,8 +427,7 @@ void FOOTPRINT_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer ) { PCB_BASE_FRAME::SetActiveLayer( aLayer ); - m_Layers->SelectLayer( aLayer ); - m_Layers->OnLayerSelected(); + m_appearancePanel->OnLayerChanged(); m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools GetCanvas()->SetFocus(); // allow capture of hotkeys diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index eea2d7a607..77b63711a4 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -48,7 +48,6 @@ PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, const wxString& aFrameName ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ), m_rotationAngle( 900 ), m_undoRedoBlocked( false ), - m_Layers( nullptr ), m_selectionFilterPanel( nullptr ), m_appearancePanel( nullptr ) { diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 1e17a94c32..3505285b35 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -228,9 +228,6 @@ protected: void unitsChangeRefresh() override; - /// Layer manager. It is the responsibility of the child frames to instantiate this - PCB_LAYER_WIDGET* m_Layers; - /// AUI panel for changing the selection tool filter controls PANEL_SELECTION_FILTER* m_selectionFilterPanel; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index a6ebb83d9e..dc38577fb3 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -185,7 +185,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_show_layer_manager_tools = true; m_hasAutoSave = true; m_microWaveToolBar = NULL; - m_Layers = nullptr; // We don't know what state board was in when it was lasat saved, so we have to // assume dirty diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index d495d5c603..7cd95a9a96 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -35,11 +36,11 @@ #include #include #include -#include #include #include #include #include +#include #include @@ -351,6 +352,20 @@ const APPEARANCE_CONTROLS::APPEARANCE_SETTING APPEARANCE_CONTROLS::s_objectSetti RR( _( "Grid" ), LAYER_GRID, _( "Show the (x,y) grid dots" ) ) }; +/// These GAL layers are shown in the Objects tab in the footprint editor +static std::set s_allowedInFpEditor = + { + LAYER_TRACKS, + LAYER_VIAS, + LAYER_PADS, + LAYER_ZONES, + LAYER_PADS_TH, + LAYER_MOD_VALUES, + LAYER_MOD_REFERENCES, + LAYER_MOD_TEXT_INVISIBLE, + LAYER_GRID + }; + // These are the built-in layer presets that cannot be deleted LAYER_PRESET APPEARANCE_CONTROLS::presetNoLayers( _( "No Layers" ), LSET() ); @@ -382,6 +397,7 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo m_frame( aParent ), m_focusOwner( aFocusOwner ), m_board( nullptr ), + m_isFpEditor( aFpEditorMode ), m_currentPreset( nullptr ), m_lastSelectedUserPreset( nullptr ), m_layerContextMenu( nullptr ) @@ -524,6 +540,9 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo m_netsGrid->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT ); m_netclassScrolledWindow->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT ); + if( m_isFpEditor ) + m_notebook->RemovePage( 2 ); + loadDefaultLayerPresets(); rebuildObjects(); OnBoardChanged(); @@ -1005,15 +1024,14 @@ void APPEARANCE_CONTROLS::OnLayerChanged() void APPEARANCE_CONTROLS::SetLayerVisible( LAYER_NUM aLayer, bool isVisible ) { - BOARD* board = m_frame->GetBoard(); - LSET visible = board->GetVisibleLayers(); + LSET visible = getVisibleLayers(); PCB_LAYER_ID layer = ToLAYER_ID( aLayer ); if( visible.test( layer ) == isVisible ) return; visible.set( layer, isVisible ); - board->SetVisibleLayers( visible ); + setVisibleLayers( visible ); m_frame->GetCanvas()->GetView()->SetLayerVisible( layer, isVisible ); @@ -1032,6 +1050,77 @@ void APPEARANCE_CONTROLS::SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible } +void APPEARANCE_CONTROLS::setVisibleLayers( LSET aLayers ) +{ + if( m_isFpEditor ) + { + KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); + + for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() ) + view->SetLayerVisible( layer, aLayers.Contains( layer ) ); + } + else + { + m_frame->GetBoard()->SetVisibleLayers( aLayers ); + } +} + + +void APPEARANCE_CONTROLS::setVisibleObjects( GAL_SET aLayers ) +{ + if( m_isFpEditor ) + { + KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); + + for( size_t i = 0; i < aLayers.size(); i++ ) + view->SetLayerVisible( GAL_LAYER_ID_START + GAL_LAYER_ID( i ), aLayers.test( i ) ); + } + else + { + m_frame->GetBoard()->SetVisibleElements( aLayers ); + } +} + + +LSET APPEARANCE_CONTROLS::getVisibleLayers() +{ + if( m_isFpEditor ) + { + KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); + LSET set; + + for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() ) + set.set( layer, view->IsLayerVisible( layer ) ); + + return set; + } + else + { + return m_frame->GetBoard()->GetVisibleLayers(); + } +} + + +GAL_SET APPEARANCE_CONTROLS::getVisibleObjects() +{ + if( m_isFpEditor ) + { + KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); + GAL_SET set; + set.reset(); + + for( size_t i = 0; i < set.size(); i++ ) + set.set( i, view->IsLayerVisible( GAL_LAYER_ID_START + GAL_LAYER_ID( i ) ) ); + + return set; + } + else + { + return m_frame->GetBoard()->GetVisibleElements(); + } +} + + void APPEARANCE_CONTROLS::OnLayerAlphaChanged() { // TODO(JE) Is this even needed if the layer alphas are getting directly updated? @@ -1090,16 +1179,19 @@ void APPEARANCE_CONTROLS::UpdateDisplayOptions() case NET_COLOR_MODE::OFF: m_rbNetColorOff->SetValue( true ); break; } - if( options.m_RatsnestMode == RATSNEST_MODE::ALL ) - m_rbRatsnestAllLayers->SetValue( true ); - else - m_rbRatsnestVisibleLayers->SetValue( true ); - - wxASSERT( m_objectSettingsMap.count( LAYER_RATSNEST ) ); - APPEARANCE_SETTING* ratsnest = m_objectSettingsMap.at( LAYER_RATSNEST ); - ratsnest->ctl_visibility->SetValue( options.m_ShowGlobalRatsnest ); - m_cbFlipBoard->SetValue( m_frame->GetCanvas()->GetView()->IsMirroredX() ); + + if( !m_isFpEditor ) + { + if( options.m_RatsnestMode == RATSNEST_MODE::ALL ) + m_rbRatsnestAllLayers->SetValue( true ); + else + m_rbRatsnestVisibleLayers->SetValue( true ); + + wxASSERT( m_objectSettingsMap.count( LAYER_RATSNEST ) ); + APPEARANCE_SETTING* ratsnest = m_objectSettingsMap.at( LAYER_RATSNEST ); + ratsnest->ctl_visibility->SetValue( options.m_ShowGlobalRatsnest ); + } } @@ -1180,7 +1272,7 @@ void APPEARANCE_CONTROLS::rebuildLayers() { BOARD* board = m_frame->GetBoard(); LSET enabled = board->GetEnabledLayers(); - LSET visible = board->GetVisibleLayers(); + LSET visible = getVisibleLayers(); COLOR_SETTINGS* theme = m_frame->GetColorSettings(); COLOR4D bgColor = theme->GetColor( LAYER_PCB_BACKGROUND ); @@ -1256,11 +1348,18 @@ void APPEARANCE_CONTROLS::rebuildLayers() btn_visible->Bind( TOGGLE_CHANGED, [&]( wxCommandEvent& aEvent ) { - int layId = static_cast( aEvent.GetEventObject() )->GetId(); + wxObject* btn = aEvent.GetEventObject(); + int layId = static_cast( btn )->GetId(); bool isVisible = aEvent.GetInt(); wxASSERT( layId >= 0 && layId < PCB_LAYER_ID_COUNT ); + if( LSET::ForbiddenFootprintLayers().test( layId ) ) + { + static_cast( btn )->SetValue( !isVisible ); + return; + } + onLayerVisibilityChanged( static_cast( layId ), isVisible, true ); } ); @@ -1306,14 +1405,11 @@ void APPEARANCE_CONTROLS::rebuildLayers() appendLayer( setting ); - // TODO(JE) -#ifdef NOTYET - if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) ) + if( m_isFpEditor && LSET::ForbiddenFootprintLayers().test( layer ) ) { - getLayerComp( GetLayerRowCount()-1, COLUMN_COLOR_LYRNAME )->Enable( false ); - getLayerComp( GetLayerRowCount()-1, COLUMN_COLORBM )->SetToolTip( wxEmptyString ); + setting->ctl_text->Disable(); + setting->ctl_color->SetToolTip( wxEmptyString ); } -#endif } // technical layers are shown in this order: @@ -1368,14 +1464,11 @@ void APPEARANCE_CONTROLS::rebuildLayers() appendLayer( setting ); - // TODO(JE) -#ifdef NOTYET - if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) ) + if( m_isFpEditor && LSET::ForbiddenFootprintLayers().test( layer ) ) { - getLayerComp( GetLayerRowCount()-1, COLUMN_COLOR_LYRNAME )->Enable( false ); - getLayerComp( GetLayerRowCount()-1, COLUMN_COLORBM )->SetToolTip( wxEmptyString ); + setting->ctl_text->Disable(); + setting->ctl_color->SetToolTip( wxEmptyString ); } -#endif } m_layersOuterSizer->AddSpacer( 10 ); @@ -1444,7 +1537,7 @@ void APPEARANCE_CONTROLS::rebuildLayerContextMenu() void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent ) { BOARD* board = m_frame->GetBoard(); - LSET visible = board->GetVisibleLayers(); + LSET visible = getVisibleLayers(); PCB_LAYER_ID current = m_frame->GetActiveLayer(); @@ -1461,7 +1554,7 @@ void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent ) case ID_SHOW_ALL_COPPER_LAYERS: { visible |= presetAllCopper.layers; - board->SetVisibleLayers( visible ); + setVisibleLayers( visible ); break; } @@ -1477,7 +1570,7 @@ void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent ) if( !visible.test( current ) ) m_frame->SetActiveLayer( *visible.Seq().begin() ); - board->SetVisibleLayers( visible ); + setVisibleLayers( visible ); break; } @@ -1488,7 +1581,7 @@ void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent ) if( !visible.test( current ) ) m_frame->SetActiveLayer( *visible.Seq().begin() ); - board->SetVisibleLayers( visible ); + setVisibleLayers( visible ); break; } @@ -1496,7 +1589,7 @@ void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent ) { visible |= ~presetAllCopper.layers; - board->SetVisibleLayers( visible ); + setVisibleLayers( visible ); break; } @@ -1523,7 +1616,10 @@ void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent ) syncLayerPresetSelection(); syncColorsAndVisibility(); - m_frame->GetCanvas()->SyncLayersVisibility( board ); + + if( !m_isFpEditor ) + m_frame->GetCanvas()->SyncLayersVisibility( board ); + m_frame->GetCanvas()->Refresh(); } @@ -1545,9 +1641,8 @@ void APPEARANCE_CONTROLS::SetTabIndex( int aTab ) void APPEARANCE_CONTROLS::syncColorsAndVisibility() { - BOARD* board = m_frame->GetBoard(); - LSET visible = board->GetVisibleLayers(); - GAL_SET objects = board->GetVisibleElements(); + LSET visible = getVisibleLayers(); + GAL_SET objects = getVisibleObjects(); Freeze(); @@ -1594,11 +1689,8 @@ void APPEARANCE_CONTROLS::onLayerClick( wxMouseEvent& aEvent ) PCB_LAYER_ID layer = ToLAYER_ID( eventSource->GetId() ); - // TODO(JE) -#ifdef NOTYET - if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) ) - return false; -#endif + if( m_isFpEditor && LSET::ForbiddenFootprintLayers().test( layer ) ) + return; m_frame->SetActiveLayer( layer ); passOnFocus(); @@ -1608,15 +1700,13 @@ void APPEARANCE_CONTROLS::onLayerClick( wxMouseEvent& aEvent ) void APPEARANCE_CONTROLS::onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool isVisible, bool isFinal ) { - BOARD* board = m_frame->GetBoard(); - - LSET visibleLayers = board->GetVisibleLayers(); + LSET visibleLayers = getVisibleLayers(); if( visibleLayers.test( aLayer ) != isVisible ) { visibleLayers.set( aLayer, isVisible ); - board->SetVisibleLayers( visibleLayers ); + setVisibleLayers( visibleLayers ); m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible ); } @@ -1631,8 +1721,7 @@ void APPEARANCE_CONTROLS::onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool is void APPEARANCE_CONTROLS::onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal ) { - BOARD* board = m_frame->GetBoard(); - GAL_SET visible = board->GetVisibleElements(); + GAL_SET visible = getVisibleObjects(); // Special-case controls switch( aLayer ) @@ -1667,7 +1756,7 @@ void APPEARANCE_CONTROLS::onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool i if( visible.Contains( aLayer ) != isVisible ) { visible.set( aLayer, isVisible ); - board->SetVisibleElements( visible ); + setVisibleObjects( visible ); m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible ); syncLayerPresetSelection(); } @@ -1682,10 +1771,9 @@ void APPEARANCE_CONTROLS::onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool i void APPEARANCE_CONTROLS::rebuildObjects() { - BOARD* board = m_frame->GetBoard(); COLOR_SETTINGS* theme = m_frame->GetColorSettings(); COLOR4D bgColor = theme->GetColor( LAYER_PCB_BACKGROUND ); - GAL_SET visible = board->GetVisibleElements(); + GAL_SET visible = getVisibleObjects(); int swatchWidth = m_windowObjects->ConvertDialogToPixels( wxSize( 8, 0 ) ).x; int labelWidth = 0; @@ -1800,11 +1888,8 @@ void APPEARANCE_CONTROLS::rebuildObjects() for( const APPEARANCE_SETTING& s_setting : s_objectSettings ) { - // TODO(JE) -#ifdef NOTYET - if( m_fp_editor_mode && !isAllowedInFpMode( setting.id ) ) + if( m_isFpEditor && !s_allowedInFpEditor.count( s_setting.id ) ) continue; -#endif if( !s_setting.spacer ) { @@ -1842,8 +1927,7 @@ void APPEARANCE_CONTROLS::rebuildObjects() void APPEARANCE_CONTROLS::syncObjectSettings() { - BOARD* board = m_frame->GetBoard(); - GAL_SET visible = board->GetVisibleElements(); + GAL_SET visible = getVisibleObjects(); const PCB_DISPLAY_OPTIONS& opts = m_frame->GetDisplayOptions(); @@ -2047,9 +2131,8 @@ void APPEARANCE_CONTROLS::rebuildLayerPresetsWidget() void APPEARANCE_CONTROLS::syncLayerPresetSelection() { - BOARD* board = m_frame->GetBoard(); - LSET visibleLayers = board->GetVisibleLayers(); - GAL_SET visibleObjects = board->GetVisibleElements(); + LSET visibleLayers = getVisibleLayers(); + GAL_SET visibleObjects = getVisibleObjects(); auto it = std::find_if( m_layerPresets.begin(), m_layerPresets.end(), [&]( const std::pair& aPair ) @@ -2086,8 +2169,6 @@ void APPEARANCE_CONTROLS::updateLayerPresetSelection( const wxString& aName ) void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent ) { - BOARD* board = m_frame->GetBoard(); - int count = m_cbLayerPresets->GetCount(); int index = m_cbLayerPresets->GetSelection(); @@ -2126,8 +2207,8 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent ) bool exists = m_layerPresets.count( name ); if( !exists ) - m_layerPresets[name] = LAYER_PRESET( name, board->GetVisibleLayers(), - board->GetVisibleElements(), UNSELECTED_LAYER ); + m_layerPresets[name] = LAYER_PRESET( name, getVisibleLayers(), + getVisibleObjects(), UNSELECTED_LAYER ); LAYER_PRESET* preset = &m_layerPresets[name]; m_currentPreset = preset; @@ -2203,8 +2284,8 @@ void APPEARANCE_CONTROLS::doApplyLayerPreset( const LAYER_PRESET& aPreset ) { BOARD* board = m_frame->GetBoard(); - board->SetVisibleLayers( aPreset.layers ); - board->SetVisibleElements( aPreset.renderLayers ); + setVisibleLayers( aPreset.layers ); + setVisibleObjects( aPreset.renderLayers ); // If the preset doesn't have an explicit active layer to restore, we can at least // force the active layer to be something in the preset's layer set @@ -2220,7 +2301,9 @@ void APPEARANCE_CONTROLS::doApplyLayerPreset( const LAYER_PRESET& aPreset ) if( activeLayer != UNSELECTED_LAYER && boardLayers.Contains( activeLayer ) ) m_frame->SetActiveLayer( activeLayer ); - m_frame->GetCanvas()->SyncLayersVisibility( board ); + if( !m_isFpEditor ) + m_frame->GetCanvas()->SyncLayersVisibility( board ); + m_frame->GetCanvas()->Refresh(); syncColorsAndVisibility(); diff --git a/pcbnew/widgets/appearance_controls.h b/pcbnew/widgets/appearance_controls.h index 5ac752b361..c1d4513996 100644 --- a/pcbnew/widgets/appearance_controls.h +++ b/pcbnew/widgets/appearance_controls.h @@ -286,6 +286,8 @@ private: BOARD* m_board; + bool m_isFpEditor; + // Nets grid view NET_GRID_TABLE* m_netsTable; @@ -416,6 +418,14 @@ private: void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal ); + void setVisibleLayers( LSET aLayers ); + + void setVisibleObjects( GAL_SET aObjects ); + + LSET getVisibleLayers(); + + GAL_SET getVisibleObjects(); + void onObjectOpacitySlider( int aLayer, float aOpacity ); void updateLayerPresetSelection( const wxString& aName );