From 2209f5e93b72d9668e563235c7b33a0419fa915a Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Thu, 24 Aug 2023 21:00:19 -0400 Subject: [PATCH] Fix accidental plotting of disabled textbox borders Fixes https://gitlab.com/kicad/code/kicad/-/issues/15252 --- pcbnew/dialogs/dialog_textbox_properties.cpp | 70 ++++++++++++-------- pcbnew/fp_textbox.cpp | 12 ++++ pcbnew/fp_textbox.h | 6 ++ pcbnew/pcb_textbox.cpp | 12 ++++ pcbnew/pcb_textbox.h | 6 ++ pcbnew/plot_brditems_plotter.cpp | 6 +- 6 files changed, 82 insertions(+), 30 deletions(-) diff --git a/pcbnew/dialogs/dialog_textbox_properties.cpp b/pcbnew/dialogs/dialog_textbox_properties.cpp index fa4f1b9336..c27988be6a 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.cpp +++ b/pcbnew/dialogs/dialog_textbox_properties.cpp @@ -270,14 +270,29 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataToWindow() STROKE_PARAMS stroke; if( m_fpTextBox ) + { stroke = m_fpTextBox->GetStroke(); + m_borderCheckbox->SetValue( m_fpTextBox->IsBorderEnabled() ); + + if( m_fpTextBox->IsBorderEnabled() ) + m_borderWidth.SetValue( stroke.GetWidth() ); + + m_borderWidth.Enable( m_fpTextBox->IsBorderEnabled() ); + m_borderStyleLabel->Enable( m_fpTextBox->IsBorderEnabled() ); + m_borderStyleCombo->Enable( m_fpTextBox->IsBorderEnabled() ); + } else if( m_pcbTextBox ) + { stroke = m_pcbTextBox->GetStroke(); + m_borderCheckbox->SetValue( m_pcbTextBox->IsBorderEnabled() ); - m_borderCheckbox->SetValue( stroke.GetWidth() >= 0 ); + if( m_pcbTextBox->IsBorderEnabled() ) + m_borderWidth.SetValue( stroke.GetWidth() ); - if( stroke.GetWidth() >= 0 ) - m_borderWidth.SetValue( stroke.GetWidth() ); + m_borderWidth.Enable( m_pcbTextBox->IsBorderEnabled() ); + m_borderStyleLabel->Enable( m_pcbTextBox->IsBorderEnabled() ); + m_borderStyleCombo->Enable( m_pcbTextBox->IsBorderEnabled() ); + } PLOT_DASH_TYPE style = stroke.GetPlotStyle(); @@ -287,10 +302,6 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataToWindow() if( (int) style < (int) lineTypeNames.size() ) m_borderStyleCombo->SetSelection( (int) style ); - m_borderWidth.Enable( stroke.GetWidth() >= 0 ); - m_borderStyleLabel->Enable( stroke.GetWidth() >= 0 ); - m_borderStyleCombo->Enable( stroke.GetWidth() >= 0 ); - return DIALOG_TEXTBOX_PROPERTIES_BASE::TransferDataToWindow(); } @@ -448,36 +459,39 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() m_edaText->SetMirrored( m_mirrored->IsChecked() ); - STROKE_PARAMS stroke; - - if( m_fpTextBox ) - stroke = m_fpTextBox->GetStroke(); - else if( m_pcbTextBox ) - stroke = m_pcbTextBox->GetStroke(); - if( m_borderCheckbox->GetValue() ) { + STROKE_PARAMS stroke; + + if( m_fpTextBox ) + stroke = m_fpTextBox->GetStroke(); + else if( m_pcbTextBox ) + stroke = m_pcbTextBox->GetStroke(); + if( !m_borderWidth.IsIndeterminate() ) stroke.SetWidth( m_borderWidth.GetValue() ); + + auto it = lineTypeNames.begin(); + std::advance( it, m_borderStyleCombo->GetSelection() ); + + if( it == lineTypeNames.end() ) + stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT ); + else + stroke.SetPlotStyle( it->first ); + + if( m_fpTextBox ) + m_fpTextBox->SetStroke( stroke ); + else if( m_pcbTextBox ) + m_pcbTextBox->SetStroke( stroke ); } else { - stroke.SetWidth( -1 ); + if( m_fpTextBox ) + m_fpTextBox->DisableBorder(); + else if( m_pcbTextBox ) + m_pcbTextBox->DisableBorder(); } - auto it = lineTypeNames.begin(); - std::advance( it, m_borderStyleCombo->GetSelection() ); - - if( it == lineTypeNames.end() ) - stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT ); - else - stroke.SetPlotStyle( it->first ); - - if( m_fpTextBox ) - m_fpTextBox->SetStroke( stroke ); - else if( m_pcbTextBox ) - m_pcbTextBox->SetStroke( stroke ); - m_edaText->ClearBoundingBoxCache(); m_edaText->ClearRenderCache(); diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index 8f7e9b0983..e436d7583a 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -575,6 +575,18 @@ wxString FP_TEXTBOX::GetParentAsString() const } +bool FP_TEXTBOX::IsBorderEnabled() const +{ + return m_stroke.GetWidth() != -1; +} + + +void FP_TEXTBOX::DisableBorder() +{ + m_stroke.SetWidth( -1 ); +} + + static struct FP_TEXTBOX_DESC { FP_TEXTBOX_DESC() diff --git a/pcbnew/fp_textbox.h b/pcbnew/fp_textbox.h index e8f3134c70..e174e4e3fa 100644 --- a/pcbnew/fp_textbox.h +++ b/pcbnew/fp_textbox.h @@ -131,6 +131,12 @@ public: double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + ///< Tests whether the border is disabled, as configured by the stroke + bool IsBorderEnabled() const; + + ///< Disables the border, this is done by changing the stroke internally + void DisableBorder(); + #if defined(DEBUG) virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index 7a1b29182b..1f0e04c529 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -505,6 +505,18 @@ void PCB_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID } +bool PCB_TEXTBOX::IsBorderEnabled() const +{ + return m_stroke.GetWidth() != -1; +} + + +void PCB_TEXTBOX::DisableBorder() +{ + m_stroke.SetWidth( -1 ); +} + + static struct PCB_TEXTBOX_DESC { PCB_TEXTBOX_DESC() diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index 964557498d..15c5695105 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -132,6 +132,12 @@ public: EDA_ITEM* Clone() const override; + ///< Tests whether the border is disabled, as configured by the stroke + bool IsBorderEnabled() const; + + ///< Disables the border, this is done by changing the stroke internally + void DisableBorder(); + protected: virtual void swapData( BOARD_ITEM* aImage ) override; }; diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index c18c3a87e9..ba49a938de 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -363,7 +363,8 @@ void BRDITEMS_PLOTTER::PlotPcbGraphicItem( const BOARD_ITEM* item ) { const PCB_TEXTBOX* textbox = static_cast( item ); PlotPcbText( textbox, textbox, textbox->GetLayer(), textbox->IsKnockout() ); - PlotPcbShape( textbox ); + if( textbox->IsBorderEnabled() ) + PlotPcbShape( textbox ); break; } @@ -527,7 +528,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) if( m_layerMask[ textbox->GetLayer() ] ) { PlotPcbText( textbox, textbox, textbox->GetLayer(), textbox->IsKnockout() ); - PlotFootprintShape( textbox ); + if( textbox->IsBorderEnabled() ) + PlotFootprintShape( textbox ); } break;