From 8eee76679173dd1b8c7b0a5ccd894eb2ff18ab20 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 23 Jul 2022 10:34:31 +0200 Subject: [PATCH] Fix Cvpcb DISPLAY_FOOTPRINTS_FRAME: some display options not working. Commit 5e4a7041 moved 4 settings used in Cvpcb to a PCBNEW_SETTINGS struct. But in Cvpcb, this config struct does not exist. So these 4 settings are now moved to a section (PCB_VIEWERS_SETTINGS_BASE) common to Cvpcb and Pcbnew config. --- cvpcb/cvpcb_settings.cpp | 14 +++- cvpcb/cvpcb_settings.h | 2 +- cvpcb/display_footprints_frame.cpp | 2 +- pcbnew/dialogs/panel_display_options.cpp | 4 +- pcbnew/pcb_painter.cpp | 83 ++++++++++++++++-------- pcbnew/pcbnew_settings.cpp | 12 ++-- pcbnew/pcbnew_settings.h | 36 ++++++++-- pcbnew/tools/pcb_editor_conditions.cpp | 8 +-- pcbnew/tools/pcb_viewer_tools.cpp | 12 ++-- 9 files changed, 123 insertions(+), 50 deletions(-) diff --git a/cvpcb/cvpcb_settings.cpp b/cvpcb/cvpcb_settings.cpp index dfbb4eacfd..25e19cddc5 100644 --- a/cvpcb/cvpcb_settings.cpp +++ b/cvpcb/cvpcb_settings.cpp @@ -30,7 +30,7 @@ const int cvpcbSchemaVersion = 0; CVPCB_SETTINGS::CVPCB_SETTINGS() : - APP_SETTINGS_BASE( "cvpcb", cvpcbSchemaVersion ), + PCB_VIEWERS_SETTINGS_BASE( "cvpcb", cvpcbSchemaVersion ), m_FootprintViewerZoom( 1.0 ), m_FootprintViewerAutoZoomOnSelect( true ), m_FilterFlags( 0 ), @@ -54,6 +54,18 @@ CVPCB_SETTINGS::CVPCB_SETTINGS() : m_params.emplace_back( new PARAM( "footprint_viewer.zoom", &m_FootprintViewerZoom, 1.0 ) ); m_params.emplace_back( new PARAM( "footprint_viewer.autozoom", &m_FootprintViewerAutoZoomOnSelect, true ) ); + + m_params.emplace_back( new PARAM( "footprint_viewer.show_pad_fill", + &m_ViewersDisplay.m_DisplayPadFill, true ) ); + + m_params.emplace_back( new PARAM( "footprint_viewer.show_pad_number", + &m_ViewersDisplay.m_DisplayPadNumbers, true ) ); + + m_params.emplace_back( new PARAM( "footprint_viewer.show_text_fill", + &m_ViewersDisplay.m_DisplayTextFill, true ) ); + + m_params.emplace_back( new PARAM( "footprint_viewer.show_graphic_fill", + &m_ViewersDisplay.m_DisplayGraphicsFill, true ) ); } diff --git a/cvpcb/cvpcb_settings.h b/cvpcb/cvpcb_settings.h index 572ec566be..71340ab070 100644 --- a/cvpcb/cvpcb_settings.h +++ b/cvpcb/cvpcb_settings.h @@ -28,7 +28,7 @@ #include #include -class CVPCB_SETTINGS : public APP_SETTINGS_BASE +class CVPCB_SETTINGS : public PCB_VIEWERS_SETTINGS_BASE { public: CVPCB_SETTINGS(); diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 78f20f7741..faa0d4c192 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -346,7 +346,7 @@ void DISPLAY_FOOTPRINTS_FRAME::UpdateToolbarControlSizes() void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { - auto cfg = dynamic_cast( aCfg ); + CVPCB_SETTINGS* cfg = dynamic_cast( aCfg ); wxCHECK( cfg, /* void */ ); // We don't allow people to change this right now, so make sure it's on diff --git a/pcbnew/dialogs/panel_display_options.cpp b/pcbnew/dialogs/panel_display_options.cpp index 96a7540e4f..ebcf0b8e21 100644 --- a/pcbnew/dialogs/panel_display_options.cpp +++ b/pcbnew/dialogs/panel_display_options.cpp @@ -53,7 +53,7 @@ void PANEL_DISPLAY_OPTIONS::loadPCBSettings( PCBNEW_SETTINGS* aCfg ) m_OptDisplayTracksClearance->SetSelection( i ); m_OptDisplayPadClearence->SetValue( aCfg->m_Display.m_PadClearance ); - m_OptDisplayPadNumber->SetValue( aCfg->m_Display.m_PadNumbers ); + m_OptDisplayPadNumber->SetValue( aCfg->m_ViewersDisplay.m_DisplayPadNumbers ); m_OptDisplayPadNoConn->SetValue( aCfg->m_Display.m_PadNoConnects ); m_ShowNetNamesOption->SetSelection( aCfg->m_Display.m_NetNames ); m_live3Drefresh->SetValue( aCfg->m_Display.m_Live3DRefresh ); @@ -96,7 +96,7 @@ bool PANEL_DISPLAY_OPTIONS::TransferDataFromWindow() cfg->m_Display.m_TrackClearance = UTIL::GetValFromConfig( clearanceModeMap, i ); cfg->m_Display.m_PadClearance = m_OptDisplayPadClearence->GetValue(); - cfg->m_Display.m_PadNumbers = m_OptDisplayPadNumber->GetValue(); + cfg->m_ViewersDisplay.m_DisplayPadNumbers = m_OptDisplayPadNumber->GetValue(); cfg->m_Display.m_PadNoConnects = m_OptDisplayPadNoConn->GetValue(); cfg->m_Display.m_NetNames = m_ShowNetNamesOption->GetSelection(); cfg->m_Display.m_Live3DRefresh = m_live3Drefresh->GetValue(); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index ad4c62a30f..05c2a01a69 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -66,6 +66,43 @@ using namespace KIGFX; + +PCBNEW_SETTINGS* pcbconfig() +{ + return dynamic_cast( Kiface().KifaceSettings() ); +} + +// Helpers for display options existing in Cvpcb and Pcbnew +// Note, when running Cvpcb, pcbconfig() returns nullptr and viewer_settings() +// returns the viewer options existing to Cvpcb and Pcbnew +static PCB_VIEWERS_SETTINGS_BASE* viewer_settings() +{ + return static_cast( Kiface().KifaceSettings() ); +} + +static bool displayPadFill() +{ + return viewer_settings()->m_ViewersDisplay.m_DisplayPadFill; +} + +static bool displayGraphicsFill() +{ + return viewer_settings()->m_ViewersDisplay.m_DisplayGraphicsFill; +} + + +static bool displayTextFill() +{ + return viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; +} + + +static bool displayPadNumbers() +{ + return viewer_settings()->m_ViewersDisplay.m_DisplayPadNumbers; +} + + PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS() { m_backgroundColor = COLOR4D( 0.0, 0.0, 0.0, 1.0 ); @@ -359,12 +396,6 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) cons } -PCBNEW_SETTINGS* pcbconfig() -{ - return dynamic_cast( Kiface().KifaceSettings() ); -} - - bool PCB_RENDER_SETTINGS::GetShowPageLimits() const { return pcbconfig() && pcbconfig()->m_ShowPageLimits; @@ -957,28 +988,28 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) if( IsNetnameLayer( aLayer ) ) { - if( !pcbconfig() ) - return; - - PCBNEW_SETTINGS::DISPLAY_OPTIONS& displayOpts = pcbconfig()->m_Display; + PCBNEW_SETTINGS::DISPLAY_OPTIONS* displayOpts = pcbconfig() ? &pcbconfig()->m_Display : nullptr; wxString netname; wxString padNumber; - if( displayOpts.m_PadNumbers ) + if( displayPadNumbers() ) padNumber = UnescapeString( aPad->GetNumber() ); - if( displayOpts.m_NetNames == 1 || displayOpts.m_NetNames == 3 ) - netname = UnescapeString( aPad->GetShortNetname() ); - - if( displayOpts.m_PadNoConnects - && aPad->GetShortNetname().StartsWith( wxT( "unconnected-(" ) ) ) + if( displayOpts ) { - wxString pinType = aPad->GetPinType(); + if( displayOpts->m_NetNames == 1 || displayOpts->m_NetNames == 3 ) + netname = UnescapeString( aPad->GetShortNetname() ); - if( pinType == wxT( "no_connect" ) || pinType.EndsWith( wxT( "+no_connect" ) ) ) - netname = wxT( "x" ); - else if( pinType == wxT( "free" ) ) - netname = wxT( "*" ); + if( displayOpts->m_PadNoConnects + && aPad->GetShortNetname().StartsWith( wxT( "unconnected-(" ) ) ) + { + wxString pinType = aPad->GetPinType(); + + if( pinType == wxT( "no_connect" ) || pinType.EndsWith( wxT( "+no_connect" ) ) ) + netname = wxT( "x" ); + else if( pinType == wxT( "free" ) ) + netname = wxT( "*" ); + } } if( netname.IsEmpty() && padNumber.IsEmpty() ) @@ -1097,7 +1128,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) return; } - bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayPadFill; + bool outline_mode = !displayPadFill(); if( m_pcbSettings.m_ForcePadSketchModeOff ) outline_mode = false; @@ -1412,7 +1443,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer ) { COLOR4D color = m_pcbSettings.GetColor( aShape, aShape->GetLayer() ); - bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayGraphicsFill; + bool outline_mode = !displayGraphicsFill(); int thickness = getLineThickness( aShape->GetWidth() ); PLOT_DASH_TYPE lineStyle = aShape->GetStroke().GetPlotStyle(); @@ -1733,7 +1764,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) TEXT_ATTRIBUTES attrs = aText->GetAttributes(); const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() ); - bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayTextFill; + bool outline_mode = !displayTextFill(); m_gal->SetStrokeColor( color ); m_gal->SetFillColor( color ); @@ -1886,7 +1917,7 @@ void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer ) return; const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); - bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayTextFill; + bool outline_mode = !displayTextFill(); TEXT_ATTRIBUTES attrs = aText->GetAttributes(); m_gal->SetStrokeColor( color ); @@ -2226,7 +2257,7 @@ void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer ) m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); - bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayGraphicsFill; + bool outline_mode = !displayGraphicsFill(); if( outline_mode ) m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index 05eb0b9c36..b11cbb75e8 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -47,7 +47,7 @@ const int pcbnewSchemaVersion = 2; PCBNEW_SETTINGS::PCBNEW_SETTINGS() - : APP_SETTINGS_BASE( "pcbnew", pcbnewSchemaVersion ), + : PCB_VIEWERS_SETTINGS_BASE( "pcbnew", pcbnewSchemaVersion ), m_AuiPanels(), m_Cleanup(), m_DrcDialog(), @@ -162,16 +162,16 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() 900 ) ); m_params.emplace_back( new PARAM( "pcb_display.graphic_items_fill", - &m_Display.m_DisplayGraphicsFill, true ) ); + &m_ViewersDisplay.m_DisplayGraphicsFill, true ) ); m_params.emplace_back( new PARAM( "pcb_display.max_links_shown", &m_Display.m_MaxLinksShowed, 3, 0, 15 ) ); m_params.emplace_back( new PARAM( "pcb_display.graphics_fill", - &m_Display.m_DisplayGraphicsFill, true ) ); + &m_ViewersDisplay.m_DisplayGraphicsFill, true ) ); m_params.emplace_back( new PARAM( "pcb_display.text_fill", - &m_Display.m_DisplayTextFill, true ) ); + &m_ViewersDisplay.m_DisplayTextFill, true ) ); m_params.emplace_back( new PARAM( "pcb_display.net_names_mode", &m_Display.m_NetNames, 3, 0, 3 ) ); @@ -183,10 +183,10 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() &m_Display.m_PadNoConnects, true ) ); m_params.emplace_back( new PARAM( "pcb_display.pad_fill", - &m_Display.m_DisplayPadFill, true ) ); + &m_ViewersDisplay.m_DisplayPadFill, true ) ); m_params.emplace_back( new PARAM( "pcb_display.pad_numbers", - &m_Display.m_PadNumbers, true ) ); + &m_ViewersDisplay.m_DisplayPadNumbers, true ) ); m_params.emplace_back( new PARAM( "pcb_display.ratsnest_global", &m_Display.m_ShowGlobalRatsnest, true ) ); diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index 728171aea7..2aa8d880f8 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -82,7 +82,34 @@ enum PCB_DISPLAY_ORIGIN typedef std::vector> ACTION_PLUGIN_SETTINGS_LIST; -class PCBNEW_SETTINGS : public APP_SETTINGS_BASE +// base class to handle Pcbnew SETTINGS also used in Cvpcb +class PCB_VIEWERS_SETTINGS_BASE : public APP_SETTINGS_BASE +{ +public: + struct VIEWERS_DISPLAY_OPTIONS + { + bool m_DisplayGraphicsFill; + bool m_DisplayTextFill; + bool m_DisplayPadNumbers; + bool m_DisplayPadFill; + }; + + VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay; + + PCB_VIEWERS_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ): + APP_SETTINGS_BASE( aFilename, aSchemaVersion ) + { + m_ViewersDisplay.m_DisplayGraphicsFill = true; + m_ViewersDisplay.m_DisplayTextFill = true; + m_ViewersDisplay.m_DisplayPadNumbers = true; + m_ViewersDisplay.m_DisplayPadFill = true; + } + + virtual ~PCB_VIEWERS_SETTINGS_BASE() {}; +}; + + +class PCBNEW_SETTINGS : public PCB_VIEWERS_SETTINGS_BASE { public: struct AUI_PANELS @@ -251,17 +278,16 @@ public: struct DISPLAY_OPTIONS { - bool m_DisplayPadFill; + // Note: Display options common to Cvpcb and Pcbnew are stored in + // VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay, because the section DISPLAY_OPTIONS + // exists only for Pcbnew bool m_DisplayViaFill; - bool m_DisplayGraphicsFill; - bool m_DisplayTextFill; bool m_DisplayPcbTrackFill; TRACK_CLEARANCE_MODE m_TrackClearance; bool m_PadClearance; int m_NetNames; - bool m_PadNumbers; bool m_PadNoConnects; RATSNEST_MODE m_RatsnestMode; diff --git a/pcbnew/tools/pcb_editor_conditions.cpp b/pcbnew/tools/pcb_editor_conditions.cpp index 57c2ddb593..180656b8f0 100644 --- a/pcbnew/tools/pcb_editor_conditions.cpp +++ b/pcbnew/tools/pcb_editor_conditions.cpp @@ -146,25 +146,25 @@ bool PCB_EDITOR_CONDITIONS::hasItemsFunc( const SELECTION& aSelection, PCB_BASE_ bool PCB_EDITOR_CONDITIONS::padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { - return aFrame->Settings().m_Display.m_PadNumbers; + return aFrame->Settings().m_ViewersDisplay.m_DisplayPadNumbers; } bool PCB_EDITOR_CONDITIONS::padFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { - return aFrame->Settings().m_Display.m_DisplayPadFill; + return aFrame->GetPcbNewSettings()->m_ViewersDisplay.m_DisplayPadFill; } bool PCB_EDITOR_CONDITIONS::textFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { - return aFrame->Settings().m_Display.m_DisplayTextFill; + return aFrame->Settings().m_ViewersDisplay.m_DisplayTextFill; } bool PCB_EDITOR_CONDITIONS::graphicsFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { - return aFrame->Settings().m_Display.m_DisplayGraphicsFill; + return aFrame->Settings().m_ViewersDisplay.m_DisplayGraphicsFill; } diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index 3068864af9..09e6d530bb 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -90,7 +90,8 @@ template void Flip( T& aValue ) int PCB_VIEWER_TOOLS::ShowPadNumbers( const TOOL_EVENT& aEvent ) { - Flip( displayOptions().m_PadNumbers ); + PCB_VIEWERS_SETTINGS_BASE& cfg = frame()->Settings(); + Flip( cfg.m_ViewersDisplay.m_DisplayPadNumbers ); for( FOOTPRINT* fp : board()->Footprints() ) { @@ -106,7 +107,8 @@ int PCB_VIEWER_TOOLS::ShowPadNumbers( const TOOL_EVENT& aEvent ) int PCB_VIEWER_TOOLS::PadDisplayMode( const TOOL_EVENT& aEvent ) { - Flip( displayOptions().m_DisplayPadFill ); + PCB_VIEWERS_SETTINGS_BASE& cfg = frame()->Settings(); + Flip( cfg.m_ViewersDisplay.m_DisplayPadFill ); for( FOOTPRINT* fp : board()->Footprints() ) { @@ -122,7 +124,8 @@ int PCB_VIEWER_TOOLS::PadDisplayMode( const TOOL_EVENT& aEvent ) int PCB_VIEWER_TOOLS::GraphicOutlines( const TOOL_EVENT& aEvent ) { - Flip( displayOptions().m_DisplayGraphicsFill ); + PCB_VIEWERS_SETTINGS_BASE& cfg = frame()->Settings(); + Flip( cfg.m_ViewersDisplay.m_DisplayGraphicsFill ); for( FOOTPRINT* fp : board()->Footprints() ) { @@ -151,7 +154,8 @@ int PCB_VIEWER_TOOLS::GraphicOutlines( const TOOL_EVENT& aEvent ) int PCB_VIEWER_TOOLS::TextOutlines( const TOOL_EVENT& aEvent ) { - Flip( displayOptions().m_DisplayTextFill ); + PCB_VIEWERS_SETTINGS_BASE& cfg = frame()->Settings(); + Flip( cfg.m_ViewersDisplay.m_DisplayTextFill ); for( FOOTPRINT* fp : board()->Footprints() ) {