diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index 78f1bec822..577eb621db 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -434,6 +434,7 @@ COLOR4D& COLOR4D::Saturate( double aFactor ) constexpr COLOR4D COLOR4D::UNSPECIFIED( 0, 0, 0, 0 ); constexpr COLOR4D COLOR4D::WHITE( 1, 1, 1, 1 ); constexpr COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 ); +constexpr COLOR4D COLOR4D::CLEAR( 1, 0, 1, 0 ); EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB ) diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index 09e1e5dc4f..d97731f824 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -107,6 +107,95 @@ PROJECT_FILE::PROJECT_FILE( const std::string& 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() ) + { + 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() ) + { + 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.layers.set( layerNum ); + } + } + } + + m_LayerPresets.emplace_back( p ); + } + } + }, + {} ) ); } diff --git a/common/project/project_local_settings.cpp b/common/project/project_local_settings.cpp index 079d6052fd..47582838e8 100644 --- a/common/project/project_local_settings.cpp +++ b/common/project/project_local_settings.cpp @@ -140,9 +140,16 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( const std::string& aFilename ) : } ) ); m_params.emplace_back( new PARAM_ENUM( - "active_layer", &m_ActiveLayer, F_Cu, PCBNEW_LAYER_ID_START, F_Fab ) ); + "board.active_layer", &m_ActiveLayer, F_Cu, PCBNEW_LAYER_ID_START, F_Fab ) ); - m_params.emplace_back( new PARAM_LIST( "hidden_nets", &m_HiddenNets, {} ) ); + m_params.emplace_back( new PARAM( "board.active_layer_preset", + &m_ActiveLayerPreset, "" ) ); + + m_params.emplace_back( new PARAM_ENUM( "board.high_contrast_mode", + &m_ContrastModeDisplay, HIGH_CONTRAST_MODE::NORMAL, HIGH_CONTRAST_MODE::NORMAL, + HIGH_CONTRAST_MODE::HIDDEN ) ); + + m_params.emplace_back( new PARAM_LIST( "board.hidden_nets", &m_HiddenNets, {} ) ); } diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index a4779c172c..308eedc18f 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -490,6 +490,10 @@ TOOL_ACTION ACTIONS::highContrastMode( "common.Control.highContrastMode", _( "High Contrast Mode" ), _( "Use high contrast display mode" ), contrast_mode_xpm ); +TOOL_ACTION ACTIONS::highContrastModeCycle( "common.Control.highContrastModeCycle", + AS_GLOBAL, 0, "", _( "High Contrast Mode (3-state)" ), + _( "Toggle inactive layers between normal, dimmed, and hidden" ), contrast_mode_xpm ); + TOOL_ACTION ACTIONS::selectionTool( "common.InteractiveSelection.selectionTool", AS_GLOBAL, 0, "", _( "Select item(s)" ), "", diff --git a/include/gal/color4d.h b/include/gal/color4d.h index bfc17f552c..1423e7b98f 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -374,6 +374,7 @@ public: // Declare a few color shortcuts that are used for comparisons frequently static const COLOR4D WHITE; static const COLOR4D BLACK; + static const COLOR4D CLEAR; }; /// @brief Equality operator, are two colors equal diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index fbc7422064..7c5499c4a0 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -234,6 +234,44 @@ inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b ) return t; } +/// Helper for storing and iterating over GAL_LAYER_IDs +class GAL_SET : public std::bitset +{ +public: + GAL_SET() : std::bitset() + { + } + + GAL_SET( const GAL_SET& aOther ) : std::bitset( aOther ) + { + } + + GAL_SET& set() + { + std::bitset::set(); + return *this; + } + + GAL_SET& set( size_t aPos, bool aVal = true ) + { + std::bitset::set( aPos, aVal ); + return *this; + } + + std::vector Seq() const + { + std::vector ret; + + for( size_t i = 0; i < size(); ++i ) + { + if( test( i ) ) + ret.push_back( static_cast( i ) ); + } + + return ret; + } +}; + /// Eeschema drawing layers enum SCH_LAYER_ID: int { @@ -404,7 +442,6 @@ public: } }; -typedef std::bitset GAL_SET; typedef std::bitset BASE_SET; diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 63e9a72898..5717538148 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -173,7 +173,7 @@ public: * (for instance solid or sketch mode) */ const PCB_DISPLAY_OPTIONS& GetDisplayOptions() const { return m_DisplayOptions; } - void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ) { m_DisplayOptions = aOptions; } + void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ); const ZONE_SETTINGS& GetZoneSettings() const; void SetZoneSettings( const ZONE_SETTINGS& aSettings ); @@ -369,6 +369,8 @@ public: int GetSeverity( int aErrorCode ) const override; + virtual void OnDisplayOptionsChanged() {} + void LoadSettings( APP_SETTINGS_BASE* aCfg ) override; void SaveSettings( APP_SETTINGS_BASE* aCfg ) override; diff --git a/include/pcb_display_options.h b/include/pcb_display_options.h index c5f1eb58de..74e8e738f2 100644 --- a/include/pcb_display_options.h +++ b/include/pcb_display_options.h @@ -30,6 +30,8 @@ #ifndef PCB_DISPLAY_OPTIONS_H_ #define PCB_DISPLAY_OPTIONS_H_ +#include + /** * PCB_DISPLAY_OPTIONS * handles display options like enable/disable some optional drawings. @@ -79,7 +81,9 @@ public: * 3 show netnames on tracks and pads */ - bool m_ContrastModeDisplay; + /// How inactive layers are displayed. @see HIGH_CONTRAST_MODE + HIGH_CONTRAST_MODE m_ContrastModeDisplay; + int m_MaxLinksShowed; // in track creation: number of hairwires shown bool m_ShowModuleRatsnest; // When moving a footprint: allows displaying a ratsnest bool m_ShowGlobalRatsnest; // If true, show all diff --git a/include/project/board_local_settings.h b/include/project/board_project_settings.h similarity index 57% rename from include/project/board_local_settings.h rename to include/project/board_project_settings.h index e05220a8ba..7661442a66 100644 --- a/include/project/board_local_settings.h +++ b/include/project/board_project_settings.h @@ -18,8 +18,16 @@ * with this program. If not, see . */ -#ifndef KICAD_BOARD_LOCAL_SETTINGS_H -#define KICAD_BOARD_LOCAL_SETTINGS_H +#ifndef KICAD_BOARD_PROJECT_SETTINGS_H +#define KICAD_BOARD_PROJECT_SETTINGS_H + +#include + +/** + * This file contains data structures that are saved in the project file or project local settings + * file that are specific to PcbNew. This is done so that these structures are available in common. + */ + /** * Selection filtering that applies all the time (not the "filter selection" dialog that modifies @@ -67,4 +75,50 @@ struct SELECTION_FILTER_OPTIONS } }; -#endif // KICAD_BOARD_LOCAL_SETTINGS_H +/** + * Determines how inactive layers should be displayed + */ +enum class HIGH_CONTRAST_MODE +{ + NORMAL = 0, ///> Non-active layers are shown normally (no high-contrast mode) + DIMMED, ///> Non-active layers are dimmed (old high-contrast mode) + HIDDEN ///> Non-active layers are hidden +}; + +/** + * A saved set of layers that are visible + */ +struct LAYER_PRESET +{ + wxString name; ///< A name for this layer set + LSET layers; ///< Board layers that are visible + GAL_SET renderLayers; ///< Render layers (e.g. object types) that are visible + PCB_LAYER_ID activeLayer; ///< Optional layer to set active when this preset is loaded + + LAYER_PRESET( const wxString& aName ) : + name( aName ), + activeLayer( UNSELECTED_LAYER ) + { + } + + LAYER_PRESET( const wxString& aName, const LSET& aSet ) : + name( aName ), + layers( aSet ), + activeLayer( UNSELECTED_LAYER ) + { + } + + LAYER_PRESET( const wxString& aName, const LSET& aSet, PCB_LAYER_ID aActive ) : + name( aName ), + layers( aSet ), + activeLayer( aActive ) + { + } + + bool LayersMatch( const LAYER_PRESET& aOther ) + { + return aOther.layers == layers && aOther.renderLayers == renderLayers; + } +}; + +#endif // KICAD_BOARD_PROJECT_SETTINGS_H diff --git a/include/project/project_file.h b/include/project/project_file.h index f6a7be7236..5cbf7d93db 100644 --- a/include/project/project_file.h +++ b/include/project/project_file.h @@ -22,6 +22,7 @@ #define KICAD_PROJECT_FILE_H #include +#include #include #include @@ -183,6 +184,9 @@ public: * schematics, one netlist partitioned into multiple boards) */ std::shared_ptr m_NetSettings; + + /// List of stored layer presets + std::vector m_LayerPresets; }; // Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON diff --git a/include/project/project_local_settings.h b/include/project/project_local_settings.h index 278bf636a3..b16d1fc8de 100644 --- a/include/project/project_local_settings.h +++ b/include/project/project_local_settings.h @@ -22,7 +22,7 @@ #define KICAD_PROJECT_LOCAL_SETTINGS_H #include -#include +#include #include #include @@ -88,6 +88,12 @@ public: /// The current (active) board layer for editing PCB_LAYER_ID m_ActiveLayer; + /// The name of a LAYER_PRESET that is currently activated (or blank if none) + wxString m_ActiveLayerPreset; + + /// The current contrast mode + HIGH_CONTRAST_MODE m_ContrastModeDisplay; + /** * A list of netnames that have been manually hidden in the board editor. * Currently, hiding nets means hiding the ratsnest for those nets. diff --git a/include/tool/actions.h b/include/tool/actions.h index d287fc7b9d..706622416e 100644 --- a/include/tool/actions.h +++ b/include/tool/actions.h @@ -97,6 +97,7 @@ public: static TOOL_ACTION toggleCursor; static TOOL_ACTION toggleCursorStyle; static TOOL_ACTION highContrastMode; + static TOOL_ACTION highContrastModeCycle; static TOOL_ACTION refreshPreview; // Similar to a synthetic mouseMoved event, but also // used after a rotate, mirror, etc. diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 591fc3ab20..7bf95e697e 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -60,7 +60,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_TOOLBARH_PCB_SELECT_LAYER: SetActiveLayer( ToLAYER_ID( m_SelLayerBox->GetLayerSelection() ) ); - if( displ_opts.m_ContrastModeDisplay ) + if( displ_opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ) GetCanvas()->Refresh(); break; @@ -118,7 +118,7 @@ void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ) SetActiveLayer( layer ); - if( displ_opts.m_ContrastModeDisplay ) + if( displ_opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ) GetCanvas()->Refresh(); } diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 457f81e8f1..57165755fa 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -300,8 +300,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_TOOLBARH_PCB_SELECT_LAYER: SetActiveLayer( ToLAYER_ID( m_selLayerBox->GetLayerSelection() ) ); - if( GetDisplayOptions().m_ContrastModeDisplay ) + if( GetDisplayOptions().m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ) + { GetCanvas()->Refresh(); + } break; case ID_MODEDIT_CHECK: diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index 11e58cb42f..cfaace4e0f 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -168,7 +168,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() return !GetDisplayOptions().m_DisplayTextFill; }; auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) { - return !GetDisplayOptions().m_ContrastModeDisplay; + return ( GetDisplayOptions().m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ); }; auto searchTreeShownCondition = [ this ] ( const SELECTION& aSel ) { return IsSearchTreeShown(); @@ -216,8 +217,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() contrastModeSubMenu->SetIcon( contrast_mode_xpm ); contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition ); - contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaDec, SELECTION_CONDITIONS::ShowAlways ); - contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaInc, SELECTION_CONDITIONS::ShowAlways ); + contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaDec, SELECTION_CONDITIONS::ShowAlways ); + contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaInc, SELECTION_CONDITIONS::ShowAlways ); viewMenu->AddMenu( contrastModeSubMenu ); viewMenu->AddSeparator(); diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 67fb6ccab8..c6ffc13f17 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -318,7 +318,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() }; auto contrastModeCondition = [ &disp_opt ]( const SELECTION &aSel ) { - return !disp_opt.m_ContrastModeDisplay; + return disp_opt.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; }; auto sketchGraphicsCondition = [ &disp_opt ]( const SELECTION &aSel ) { @@ -386,7 +386,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() contrastModeSubMenu->SetTitle( _( "&Contrast Mode" ) ); contrastModeSubMenu->SetIcon( contrast_mode_xpm ); - contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition ); + contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition ); contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaDec, SELECTION_CONDITIONS::ShowAlways ); contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaInc, SELECTION_CONDITIONS::ShowAlways ); viewMenu->AddMenu( contrastModeSubMenu ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index b7c25418e5..a3bc27a70b 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -417,7 +417,7 @@ void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ) SetActiveLayer( layer ); - if( displ_opts.m_ContrastModeDisplay ) + if( displ_opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ) GetCanvas()->Refresh(); } @@ -742,3 +742,17 @@ void PCB_BASE_FRAME::ActivateGalCanvas() canvas->StartDrawing(); } + +void PCB_BASE_FRAME::SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ) +{ + m_DisplayOptions = aOptions; + + EDA_DRAW_PANEL_GAL* canvas = GetCanvas(); + KIGFX::PCB_VIEW* view = static_cast( canvas->GetView() ); + + view->UpdateDisplayOptions( aOptions ); + canvas->SetHighContrastLayer( GetActiveLayer() ); + OnDisplayOptionsChanged(); + + canvas->Refresh(); +} diff --git a/pcbnew/pcb_display_options.cpp b/pcbnew/pcb_display_options.cpp index 7b88e6f914..799fe3bb87 100644 --- a/pcbnew/pcb_display_options.cpp +++ b/pcbnew/pcb_display_options.cpp @@ -50,7 +50,7 @@ PCB_DISPLAY_OPTIONS::PCB_DISPLAY_OPTIONS() * 1 show netnames on pads * 2 show netnames on tracks * 3 show netnames on tracks and pads */ - m_ContrastModeDisplay = false; + m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL; m_MaxLinksShowed = 3; // in track creation: number of hairwires shown m_ShowModuleRatsnest = true; // When moving a footprint: allows displaying a ratsnest m_DisplayRatsnestLinesCurved = false; diff --git a/pcbnew/pcb_layer_widget.cpp b/pcbnew/pcb_layer_widget.cpp index c0a38c17af..e016530ff9 100644 --- a/pcbnew/pcb_layer_widget.cpp +++ b/pcbnew/pcb_layer_widget.cpp @@ -592,9 +592,12 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( int aLayer ) myframe->SetActiveLayer( layer ); + bool hcm = ( myframe->GetDisplayOptions().m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ); + if( m_alwaysShowActiveCopperLayer ) OnLayerSelected(); - else if( myframe->GetDisplayOptions().m_ContrastModeDisplay ) + else if( hcm ) myframe->GetCanvas()->Refresh(); return true; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index ebbc48de5e..7b2263c3e5 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -129,7 +129,8 @@ void PCB_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings ) void PCB_RENDER_SETTINGS::LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aShowPageLimits ) { - m_hiContrastEnabled = aOptions.m_ContrastModeDisplay; + m_hiContrastEnabled = ( aOptions.m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ); m_padNumbers = aOptions.m_DisplayPadNum; m_sketchGraphics = !aOptions.m_DisplayGraphicsFill; m_sketchText = !aOptions.m_DisplayTextFill; @@ -214,6 +215,8 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOption if( aOptions.m_DisplayPadIsol ) m_clearance |= CL_PADS; + m_contrastModeDisplay = aOptions.m_ContrastModeDisplay; + m_showPageLimits = aShowPageLimits; } @@ -247,6 +250,15 @@ const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer const EDA_ITEM* item = dynamic_cast( aItem ); const BOARD_CONNECTED_ITEM* conItem = dynamic_cast ( aItem ); + // Make items invisible in "other layers hidden" contrast mode + if( m_contrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN && m_activeLayers.count( aLayer ) == 0 ) + return COLOR4D::CLEAR; + + // Hide net names in "dimmed" contrast mode + if( m_contrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL && IsNetnameLayer( aLayer ) + && m_activeLayers.count( aLayer ) == 0 ) + return COLOR4D::CLEAR; + if( item ) { // Selection disambiguation @@ -297,8 +309,8 @@ const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer if( m_highlightEnabled && m_highlightNetcodes.count( netCode ) ) return m_layerColorsHi[aLayer]; - // Return grayish color for non-highlighted layers in the high contrast mode - if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 ) + // Return grayish color for non-highlighted layers in the dimmed high contrast mode + if( m_contrastModeDisplay == HIGH_CONTRAST_MODE::DIMMED && m_activeLayers.count( aLayer ) == 0 ) return m_hiContrastColor[aLayer]; // Catch the case when highlight and high-contraste modes are enabled diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 930e718543..221b2f50ed 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -28,6 +28,7 @@ #define __CLASS_PCB_PAINTER_H #include +#include #include @@ -88,6 +89,7 @@ public: DZ_SHOW_OUTLINED }; + ///> Determines how net color overrides should be applied enum class NET_COLOR_MODE { OFF, ///< Net (and netclass) colors are not shown @@ -250,6 +252,9 @@ protected: ///> Set of net codes that should not have their ratsnest displayed std::set m_hiddenNets; + + ///> How to display inactive layers + HIGH_CONTRAST_MODE m_contrastModeDisplay; }; diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index fbeeab8271..b74b652d63 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -117,6 +117,12 @@ bool PCB_EDIT_FRAME::LoadProjectSettings() filterOpts = localSettings.m_SelectionFilter; m_selectionFilterPanel->SetCheckboxesFromFilter( filterOpts ); + PCB_DISPLAY_OPTIONS opts = GetDisplayOptions(); + opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay; + SetDisplayOptions( opts ); + + SetActiveLayer( localSettings.m_ActiveLayer ); + return true; } @@ -142,6 +148,10 @@ void PCB_EDIT_FRAME::SaveProjectSettings() RecordDRCExclusions(); + localSettings.m_ActiveLayer = GetActiveLayer(); + + localSettings.m_ContrastModeDisplay = GetDisplayOptions().m_ContrastModeDisplay; + KIGFX::PCB_RENDER_SETTINGS* rs = static_cast( GetCanvas()->GetView()->GetPainter()->GetSettings() ); diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 60ab02561b..97dcca3911 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -198,13 +198,15 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer, b ITEM* rv = NULL; + bool highContrast = ( displayOptions().m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ); + for( int i = 0; i < candidateCount; i++ ) { ITEM* item = prioritized[i]; - if( displayOptions().m_ContrastModeDisplay ) - if( item && !item->Layers().Overlaps( tl ) ) - item = NULL; + if( highContrast && item && !item->Layers().Overlaps( tl ) ) + item = nullptr; if( item && ( aLayer < 0 || item->Layers().Overlaps( aLayer ) ) ) { diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 028bda8e3f..dc7cebe31a 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -237,6 +237,8 @@ void FOOTPRINT_EDIT_FRAME::SyncToolbars() m_mainToolBar->Toggle( PCB_ACTIONS::footprintProperties, GetBoard()->GetFirstModule() ); m_mainToolBar->Refresh(); + bool hcm = opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; + m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES ); m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == EDA_UNITS::INCHES ); @@ -244,7 +246,7 @@ void FOOTPRINT_EDIT_FRAME::SyncToolbars() m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill ); m_optionsToolBar->Toggle( PCB_ACTIONS::textOutlines, !opts.m_DisplayTextFill ); m_optionsToolBar->Toggle( PCB_ACTIONS::graphicsOutlines, !opts.m_DisplayGraphicsFill ); - m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts.m_ContrastModeDisplay ); + m_optionsToolBar->Toggle( ACTIONS::highContrastMode, hcm ); m_optionsToolBar->Toggle( PCB_ACTIONS::toggleFootprintTree, IsSearchTreeShown() ); m_optionsToolBar->Refresh(); diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 91f15a54fd..e1cb9e82b7 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -731,13 +731,15 @@ void PCB_EDIT_FRAME::SyncToolbars() m_optionsToolBar->Toggle( PCB_ACTIONS::showLayersManager, LayerManagerShown() ); m_optionsToolBar->Toggle( PCB_ACTIONS::showMicrowaveToolbar, MicrowaveToolbarShown() ); + bool hcm = opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; + m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayEnable, zoneMode == 0 ); m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayDisable, zoneMode == 1 ); m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayOutlines, zoneMode == 2 ); m_optionsToolBar->Toggle( PCB_ACTIONS::trackDisplayMode, !opts.m_DisplayPcbTrackFill ); m_optionsToolBar->Toggle( PCB_ACTIONS::viaDisplayMode, !opts.m_DisplayViaFill ); m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill ); - m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts.m_ContrastModeDisplay ); + m_optionsToolBar->Toggle( ACTIONS::highContrastMode, hcm ); m_optionsToolBar->Refresh(); TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 054b77f1ae..b3a48b2e21 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -519,10 +519,11 @@ int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent ) D_PAD* pad = static_cast( selection[0] ); PCB_LAYER_ID layer = explodePad( pad ); - m_wasHighContrast = opts.m_ContrastModeDisplay; + m_wasHighContrast = ( opts.m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ); frame()->SetActiveLayer( layer ); - if( !opts.m_ContrastModeDisplay ) + if( !m_wasHighContrast ) m_toolMgr->RunAction( ACTIONS::highContrastMode, false ); if( PCB_ACTIONS::explodePad.GetHotKey() == PCB_ACTIONS::recombinePad.GetHotKey() ) @@ -540,7 +541,10 @@ int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent ) if( m_editPad == niluuid ) { - if( m_wasHighContrast != opts.m_ContrastModeDisplay ) + bool highContrast = ( opts.m_ContrastModeDisplay != + HIGH_CONTRAST_MODE::NORMAL ); + + if( m_wasHighContrast != highContrast ) m_toolMgr->RunAction( ACTIONS::highContrastMode, false ); infoBar->Dismiss(); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index ef32325f50..a31314d37f 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -214,10 +214,40 @@ int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent ) { auto opts = displayOptions(); - Flip( opts.m_ContrastModeDisplay ); + opts.m_ContrastModeDisplay = + ( opts.m_ContrastModeDisplay == HIGH_CONTRAST_MODE::NORMAL ) ? + HIGH_CONTRAST_MODE::DIMMED : + HIGH_CONTRAST_MODE::NORMAL; + m_frame->SetDisplayOptions( opts ); - view()->UpdateDisplayOptions( opts ); - canvas()->SetHighContrastLayer( m_frame->GetActiveLayer() ); + + return 0; +} + + +int PCBNEW_CONTROL::HighContrastModeCycle( const TOOL_EVENT& aEvent ) +{ + auto opts = displayOptions(); + + switch( opts.m_ContrastModeDisplay ) + { + case HIGH_CONTRAST_MODE::NORMAL: + opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::DIMMED; + break; + + case HIGH_CONTRAST_MODE::DIMMED: + opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::HIDDEN; + break; + + case HIGH_CONTRAST_MODE::HIDDEN: + opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL; + break; + } + + m_frame->SetDisplayOptions( opts ); + + // TODO: remove once EVT_UPDATE_UI works + m_frame->SyncToolbars(); return 0; } @@ -1023,15 +1053,16 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); // Display modes - Go( &PCBNEW_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() ); - Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::showRatsnest.MakeEvent() ); - Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::ratsnestLineMode.MakeEvent() ); - Go( &PCBNEW_CONTROL::ViaDisplayMode, PCB_ACTIONS::viaDisplayMode.MakeEvent() ); - Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayEnable.MakeEvent() ); - Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayDisable.MakeEvent() ); - Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayOutlines.MakeEvent() ); - Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayToggle.MakeEvent() ); - Go( &PCBNEW_CONTROL::HighContrastMode, ACTIONS::highContrastMode.MakeEvent() ); + Go( &PCBNEW_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() ); + Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::showRatsnest.MakeEvent() ); + Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::ratsnestLineMode.MakeEvent() ); + Go( &PCBNEW_CONTROL::ViaDisplayMode, PCB_ACTIONS::viaDisplayMode.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayEnable.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayDisable.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayOutlines.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayToggle.MakeEvent() ); + Go( &PCBNEW_CONTROL::HighContrastMode, ACTIONS::highContrastMode.MakeEvent() ); + Go( &PCBNEW_CONTROL::HighContrastModeCycle, ACTIONS::highContrastModeCycle.MakeEvent() ); // Layer control Go( &PCBNEW_CONTROL::LayerSwitch, PCB_ACTIONS::layerTop.MakeEvent() ); @@ -1092,5 +1123,3 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::UpdateMessagePanel, EVENTS::ClearedEvent ); Go( &PCBNEW_CONTROL::UpdateMessagePanel, EVENTS::SelectedItemsModified ); } - - diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 998b5caeda..a46b3f9d65 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -59,8 +59,16 @@ public: int ZoneDisplayMode( const TOOL_EVENT& aEvent ); int TrackDisplayMode( const TOOL_EVENT& aEvent ); int ViaDisplayMode( const TOOL_EVENT& aEvent ); + + // Update the view with the new high-contrast mode from the display settings int HighContrastMode( const TOOL_EVENT& aEvent ); + // Rotate through the available high-contrast modes + int HighContrastModeCycle( const TOOL_EVENT& aEvent ); + + // Layer view presets + int ApplyLayerPreset( const TOOL_EVENT& aEvent ); + // Layer control int LayerSwitch( const TOOL_EVENT& aEvent ); int LayerNext( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 85f1cb34ea..9baf9ffce1 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -30,12 +30,12 @@ #include #include -#include -#include +#include #include -#include -#include #include +#include +#include +#include class PCB_BASE_FRAME; class BOARD_ITEM;