Clean up (yes, yet again) the default pen width handling.

Fixes https://gitlab.com/kicad/code/kicad/issues/8980
This commit is contained in:
Jeff Young 2021-08-17 11:59:04 +01:00
parent a133853a4f
commit dd24502255
11 changed files with 37 additions and 63 deletions

View File

@ -272,12 +272,10 @@ void LIB_ARC::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_fill == FILL_TYPE::FILLED_WITH_BG_BODYCOLOR;
int pen_size = GetPenWidth();
int pen_size = GetEffectivePenWidth( aPlotter->RenderSettings() );
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetMinPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->Arc( pos, -t2, -t1, m_Radius, already_filled ? FILL_TYPE::NO_FILL : m_fill,
pen_size );
@ -287,11 +285,7 @@ void LIB_ARC::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_ARC::GetPenWidth() const
{
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != FILL_TYPE::NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
return m_Width;
}
@ -299,14 +293,14 @@ void LIB_ARC::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, v
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
int penWidth = GetEffectivePenWidth( aSettings );
if( forceNoFill && m_fill != FILL_TYPE::NO_FILL && penWidth == 0 )
return;
wxDC* DC = aSettings->GetPrintDC();
wxPoint pos1, pos2, posc;
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
pos1 = aTransform.TransformCoordinate( m_ArcEnd ) + aOffset;
pos2 = aTransform.TransformCoordinate( m_ArcStart ) + aOffset;
@ -323,8 +317,6 @@ void LIB_ARC::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, v
if( forceNoFill || m_fill == FILL_TYPE::NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRArc1( nullptr, DC, pos1.x, pos1.y, pos2.x, pos2.y, posc.x, posc.y, penWidth, color );
}
else

View File

@ -184,12 +184,10 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_fill == FILL_TYPE::FILLED_WITH_BG_BODYCOLOR;
int pen_size = GetPenWidth();
int pen_size = GetEffectivePenWidth( aPlotter->RenderSettings() );
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetMinPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->PlotPoly( cornerList, already_filled ? FILL_TYPE::NO_FILL : m_fill, pen_size );
}
@ -198,11 +196,7 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_BEZIER::GetPenWidth() const
{
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != FILL_TYPE::NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
return m_Width;
}
@ -210,7 +204,7 @@ void LIB_BEZIER::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
int penWidth = GetEffectivePenWidth( aSettings );
if( forceNoFill && m_fill != FILL_TYPE::NO_FILL && penWidth == 0 )
return;
@ -229,8 +223,6 @@ void LIB_BEZIER::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset
if( forceNoFill || m_fill == FILL_TYPE::NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRPoly( nullptr, DC, m_PolyPoints.size(), &PolyPointsTraslated[0], false, penWidth,
color, color );
}

View File

@ -174,12 +174,10 @@ void LIB_CIRCLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_fill == FILL_TYPE::FILLED_WITH_BG_BODYCOLOR;
int pen_size = GetPenWidth();
int pen_size = GetEffectivePenWidth( aPlotter->RenderSettings() );
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetMinPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->Circle( pos, GetRadius() * 2, already_filled ? FILL_TYPE::NO_FILL : m_fill,
pen_size );
@ -189,11 +187,7 @@ void LIB_CIRCLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_CIRCLE::GetPenWidth() const
{
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != FILL_TYPE::NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
return m_Width;
}
@ -201,7 +195,7 @@ void LIB_CIRCLE::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset
void* aData, const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
int penWidth = GetEffectivePenWidth( aSettings );
if( forceNoFill && m_fill != FILL_TYPE::NO_FILL && penWidth == 0 )
return;
@ -212,8 +206,6 @@ void LIB_CIRCLE::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset
if( forceNoFill || m_fill == FILL_TYPE::NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRCircle( nullptr, DC, pos1.x, pos1.y, GetRadius(), penWidth, color );
}
else

View File

@ -108,7 +108,7 @@ void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
{
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( IsVisible() ? GetDefaultLayer() : LAYER_HIDDEN );
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
int penWidth = GetEffectivePenWidth( aSettings );
wxPoint text_pos = aTransform.TransformCoordinate( GetTextPos() ) + aOffset;
wxString text = aData ? *static_cast<wxString*>( aData ) : GetText();
@ -285,7 +285,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
else
color = COLOR4D::BLACK;
int penWidth = std::max( GetPenWidth(),aPlotter->RenderSettings()->GetMinPenWidth() );
int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() );
aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify,
penWidth, IsItalic(), IsBold() );

View File

@ -143,6 +143,19 @@ public:
virtual int GetPenWidth() const = 0;
virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const
{
// For historical reasons, a stored value of 0 means "default width" and negative
// numbers meant "don't stroke".
if( GetPenWidth() < 0 && GetFillMode() != FILL_TYPE::NO_FILL )
return 0;
else if( GetPenWidth() == 0 )
return aSettings->GetDefaultPenWidth();
else
return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
}
LIB_SYMBOL* GetParent() const
{
return (LIB_SYMBOL*) m_parent;

View File

@ -164,7 +164,7 @@ bool LIB_PIN::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) c
int LIB_PIN::GetPenWidth() const
{
return 1;
return 0;
}
@ -217,7 +217,7 @@ void LIB_PIN::printPinSymbol( const RENDER_SETTINGS* aSettings, const wxPoint& a
{
wxDC* DC = aSettings->GetPrintDC();
int MapX1, MapY1, x1, y1;
int width = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
int width = GetEffectivePenWidth( aSettings );
int posX = aPos.x, posY = aPos.y, len = m_length;
COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN );
@ -537,7 +537,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
{
int MapX1, MapY1, x1, y1;
COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_PIN );
int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() );
aPlotter->SetColor( color );
aPlotter->SetCurrentLineWidth( penWidth );

View File

@ -139,12 +139,10 @@ void LIB_POLYLINE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_fill == FILL_TYPE::FILLED_WITH_BG_BODYCOLOR;
int pen_size = GetPenWidth();
int pen_size = GetEffectivePenWidth( aPlotter->RenderSettings() );
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->PlotPoly( cornerList, already_filled ? FILL_TYPE::NO_FILL : m_fill, pen_size );
}
@ -185,11 +183,7 @@ void LIB_POLYLINE::RemoveCorner( int aIdx )
int LIB_POLYLINE::GetPenWidth() const
{
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != FILL_TYPE::NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
return m_Width;
}
@ -197,7 +191,7 @@ void LIB_POLYLINE::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffs
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
int penWidth = GetEffectivePenWidth( aSettings );
if( forceNoFill && m_fill != FILL_TYPE::NO_FILL && penWidth == 0 )
return;
@ -211,8 +205,6 @@ void LIB_POLYLINE::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffs
if( forceNoFill || m_fill == FILL_TYPE::NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRPoly( nullptr, DC, m_PolyPoints.size(), buffer, false, penWidth, color, color );
}
else

View File

@ -136,12 +136,10 @@ void LIB_RECTANGLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_fill == FILL_TYPE::FILLED_WITH_BG_BODYCOLOR;
int pen_size = GetPenWidth();
int pen_size = GetEffectivePenWidth( aPlotter->RenderSettings() );
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetMinPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->Rect( pos, end, already_filled ? FILL_TYPE::NO_FILL : m_fill, pen_size );
}
@ -150,11 +148,7 @@ void LIB_RECTANGLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_RECTANGLE::GetPenWidth() const
{
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != FILL_TYPE::NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
return m_Width;
}
@ -162,7 +156,7 @@ void LIB_RECTANGLE::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOff
void* aData, const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
int penWidth = GetEffectivePenWidth( aSettings );
if( forceNoFill && m_fill != FILL_TYPE::NO_FILL && penWidth == 0 )
return;
@ -174,7 +168,6 @@ void LIB_RECTANGLE::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOff
if( forceNoFill || m_fill == FILL_TYPE::NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, penWidth, color );
}
else

View File

@ -176,7 +176,7 @@ void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter ) const
int delta = GetSize() / 2;
int pX = m_pos.x;
int pY = m_pos.y;
int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );
int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetCurrentLineWidth( penWidth );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );

View File

@ -341,7 +341,7 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr
float SCH_PAINTER::getLineWidth( const LIB_ITEM* aItem, bool aDrawingShadows ) const
{
float width = (float) std::max( aItem->GetPenWidth(), m_schSettings.GetDefaultPenWidth() );
float width = (float) aItem->GetEffectivePenWidth( &m_schSettings );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();

View File

@ -97,7 +97,7 @@ bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
int SCH_SHEET_PIN::GetPenWidth() const
{
return 1;
return 0;
}