← Back to team overview

kicad-developers team mailing list archive

[PATCH] Show zero thickness lines in GAL

 

Hi,

Here is a patch to show zero-thickness lines in GAL using the "outline width".

This addressess https://bugs.launchpad.net/kicad/+bug/1501749

Cheers,

John
From 60dfc34c70493bf05f77ecd4dca7594b46798c8e Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Tue, 7 Feb 2017 18:21:26 +0800
Subject: [PATCH] Show lines of zero thickness in GAL

If a line has zero thickness, use the outline thickness to draw it.

This avoids having invisible items on the PCB that could still end up in
outputs, or "losing" an item by setting thickness to 0.

This only affects GAL drawing routines, the PCB data structures are not
affected, so any outputs will be the same.

Fixes: lp:1501749
* https://bugs.launchpad.net/kicad/+bug/1501749
---
 pcbnew/pcb_painter.cpp | 22 +++++++++++++++++-----
 pcbnew/pcb_painter.h   |  9 +++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp
index f46bf85fd..20f84a0fc 100644
--- a/pcbnew/pcb_painter.cpp
+++ b/pcbnew/pcb_painter.cpp
@@ -247,6 +247,18 @@ PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
 }
 
 
+int PCB_PAINTER::getLineThickness( int aActualThickness ) const
+{
+    // if items have 0 thickness, draw them with the outline
+    // width, otherwise respect the set value (which, no matter
+    // how small will produce something)
+    if( aActualThickness == 0 )
+        return m_pcbSettings.m_outlineWidth;
+
+    return aActualThickness;
+}
+
+
 bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
 {
     const EDA_ITEM* item = static_cast<const EDA_ITEM*>( aItem );
@@ -784,7 +796,7 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
     if( m_pcbSettings.m_sketchMode[aLayer] )
         m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );    // Outline mode
     else
-        m_gal->SetLineWidth( aSegment->GetWidth() );            // Filled mode
+        m_gal->SetLineWidth( getLineThickness( aSegment->GetWidth() ) );     // Filled mode
 
     switch( aSegment->GetShape() )
     {
@@ -871,7 +883,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
     else
     {
         // Filled mode
-        m_gal->SetLineWidth( aText->GetThickness() );
+        m_gal->SetLineWidth( getLineThickness( aText->GetThickness() ) );
     }
 
     m_gal->SetStrokeColor( color );
@@ -899,7 +911,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
     else
     {
         // Filled mode
-        m_gal->SetLineWidth( aText->GetThickness() );
+        m_gal->SetLineWidth( getLineThickness( aText->GetThickness() ) );
     }
 
     m_gal->SetStrokeColor( color );
@@ -1021,7 +1033,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
     m_gal->SetStrokeColor( strokeColor );
     m_gal->SetIsFill( false );
     m_gal->SetIsStroke( true );
-    m_gal->SetLineWidth( aDimension->GetWidth() );
+    m_gal->SetLineWidth( getLineThickness( aDimension->GetWidth() ) );
 
     // Draw an arrow
     m_gal->DrawLine( VECTOR2D( aDimension->m_crossBarO ), VECTOR2D( aDimension->m_crossBarF ) );
@@ -1050,7 +1062,7 @@ void PCB_PAINTER::draw( const PCB_TARGET* aTarget )
     VECTOR2D position( aTarget->GetPosition() );
     double   size, radius;
 
-    m_gal->SetLineWidth( aTarget->GetWidth() );
+    m_gal->SetLineWidth( getLineThickness( aTarget->GetWidth() ) );
     m_gal->SetStrokeColor( strokeColor );
     m_gal->SetIsFill( false );
     m_gal->SetIsStroke( true );
diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h
index c86991862..718f619a1 100644
--- a/pcbnew/pcb_painter.h
+++ b/pcbnew/pcb_painter.h
@@ -228,6 +228,15 @@ protected:
     void draw( const DIMENSION* aDimension, int aLayer );
     void draw( const PCB_TARGET* aTarget );
     void draw( const MARKER_PCB* aMarker );
+
+    /**
+     * Function getLineThickness()
+     * Get the thickness to draw for a line (e.g. 0 thickness lines
+     * get a minimum value).
+     * @param aActualThickness line own thickness
+     * @return the thickness to draw
+     */
+    int getLineThickness( int aActualThickness ) const;
 };
 } // namespace KIGFX
 
-- 
2.11.0


Follow ups