Fix accidental plotting of disabled textbox borders

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15252
This commit is contained in:
Marek Roszko 2023-08-24 21:00:19 -04:00
parent a17cd9d054
commit 2209f5e93b
6 changed files with 82 additions and 30 deletions

View File

@ -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();

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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;
};

View File

@ -363,7 +363,8 @@ void BRDITEMS_PLOTTER::PlotPcbGraphicItem( const BOARD_ITEM* item )
{
const PCB_TEXTBOX* textbox = static_cast<const PCB_TEXTBOX*>( 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;