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.