From 49e1b5785f0ef7b6461f0e4be0aeaf72ecfbf070 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 22 Jul 2021 10:36:57 +0200 Subject: [PATCH] PCB_SHAPE::GetFocusPosition(): returns a point on the outline instead of center. This function is used in DRC to locate a graphic shape. For not filled shapes, this point must be on the shape outline, not on the center of the shape (the center shows nothing) Fixes #8832 https://gitlab.com/kicad/code/kicad/issues/8832 --- pcbnew/pcb_shape.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ pcbnew/pcb_shape.h | 10 ++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index 0a28791eb4..f9461cd942 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -76,6 +76,47 @@ wxPoint PCB_SHAPE::GetPosition() const } +const wxPoint PCB_SHAPE::GetFocusPosition() const +{ + // For some shapes return the visual center, but for not filled polygonal shapes, + // the center is usually far from the shape: a point on the outline is better + + switch( m_shape ) + { + case SHAPE_T::CIRCLE: + if( !IsFilled() ) + return wxPoint( GetCenter().x + GetRadius(), GetCenter().y ); + break; + + case SHAPE_T::RECT: + if( !IsFilled() ) + return GetStart(); + break; + + case SHAPE_T::POLY: + if( !IsFilled() ) + { + VECTOR2I pos = GetPolyShape().Outline(0).CPoint(0); + return wxPoint( pos.x, pos.y ); + } + break; + + case SHAPE_T::ARC: + return GetArcMid(); + break; + + case SHAPE_T::BEZIER: + return GetStart(); + break; + + default: + break; + } + + return GetCenter(); +} + + double PCB_SHAPE::GetLength() const { double length = 0.0; diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index 059d124b47..a10288eaab 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -205,10 +205,12 @@ public: */ void SetArcGeometry( const wxPoint& aStart, const wxPoint& aMid, const wxPoint& aEnd ); - const wxPoint GetFocusPosition() const override - { - return GetCenter(); - } + /** + * Allows items to return their visual center rather than their anchor. + * For some shapes this is similar to GetPosition, but for polygonal shapes, + * the anchor is not suitable (shows nothing): a point on the outline is better + */ + const wxPoint GetFocusPosition() const override; /** * Return the parent footprint or NULL if PCB_SHAPE does not belong to a footprint.