From 58c006bc45b5a750aabc9beaf92776c1598d2e53 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 23 Oct 2020 13:42:48 +0100 Subject: [PATCH] Register properties for ARC elements so we can get their netclass. Also improves GAL arc drawing and polygonization. Fixes https://gitlab.com/kicad/code/kicad/issues/6039 --- common/gal/opengl/opengl_gal.cpp | 7 ++++++- libs/kimath/src/geometry/shape_arc.cpp | 3 ++- pcbnew/class_track.cpp | 17 +++++++++++++++++ pcbnew/pcb_painter.cpp | 4 +++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index f706ac9b38..07cb3ee0fc 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -841,7 +841,12 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d // Swap the angles, if start angle is greater than end angle SWAP( aStartAngle, >, aEndAngle ); - const double alphaIncrement = calcAngleStep( aRadius ); + // Bigger arcs need smaller alpha increment to make them look smooth + const double alphaIncrement = std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS ); + + // Draw entirely within the real arc boundary (ie: put all polygonization error inside) + double correctionFactor = cos( M_PI / (double) CIRCLE_POINTS ); + aRadius *= correctionFactor; Save(); currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 ); diff --git a/libs/kimath/src/geometry/shape_arc.cpp b/libs/kimath/src/geometry/shape_arc.cpp index f3b7337fe1..7000fbfc1d 100644 --- a/libs/kimath/src/geometry/shape_arc.cpp +++ b/libs/kimath/src/geometry/shape_arc.cpp @@ -375,13 +375,14 @@ const SHAPE_LINE_CHAIN SHAPE_ARC::ConvertToPolyline( double aAccuracy ) const int n; - if( r == 0.0 ) + if( r < aAccuracy ) { n = 0; } else { n = GetArcToSegmentCount( r, aAccuracy, ca ); + r -= aAccuracy / 2; // Split the error on either side of arc } for( int i = 0; i <= n ; i++ ) diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 6836d71f31..673bf7d2bb 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -1074,6 +1074,23 @@ static struct TRACK_VIA_DESC propMgr.AddProperty( new PROPERTY( _HKI( "End Y" ), &TRACK::SetEndY, &TRACK::GetEndY, PROPERTY_DISPLAY::DISTANCE ) ); + // Arc + REGISTER_TYPE( ARC ); + propMgr.InheritsAfter( TYPE_HASH( ARC ), TYPE_HASH( BOARD_CONNECTED_ITEM ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Width" ), + &ARC::SetWidth, &ARC::GetWidth, PROPERTY_DISPLAY::DISTANCE ) ); + propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ), + new PROPERTY( _HKI( "Origin X" ), + &TRACK::SetX, &ARC::GetX, PROPERTY_DISPLAY::DISTANCE ) ); + propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ), + new PROPERTY( _HKI( "Origin Y" ), + &TRACK::SetY, &ARC::GetY, PROPERTY_DISPLAY::DISTANCE ) ); + propMgr.AddProperty( new PROPERTY( _HKI( "End X" ), + &TRACK::SetEndX, &ARC::GetEndX, PROPERTY_DISPLAY::DISTANCE ) ); + propMgr.AddProperty( new PROPERTY( _HKI( "End Y" ), + &TRACK::SetEndY, &ARC::GetEndY, PROPERTY_DISPLAY::DISTANCE ) ); + // Via REGISTER_TYPE( VIA ); propMgr.InheritsAfter( TYPE_HASH( VIA ), TYPE_HASH( BOARD_CONNECTED_ITEM ) ); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 1dc72cf8d1..b58b858d37 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -587,13 +587,15 @@ void PCB_PAINTER::draw( const ARC* aArc, int aLayer ) if( ( m_pcbSettings.m_clearance & clearanceFlags ) == clearanceFlags ) { + int clearance = aArc->GetOwnClearance( m_pcbSettings.GetActiveLayer() ); + m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); m_gal->SetStrokeColor( color ); m_gal->DrawArcSegment( center, radius, start_angle, start_angle + angle, - width + aArc->GetOwnClearance( ToLAYER_ID( aLayer ) ) * 2 ); + width + clearance * 2 ); } } }