From 30e51f7d1ad1e5bfc13a9a8518263ea9c48a2ae4 Mon Sep 17 00:00:00 2001 From: John Beard <john.j.beard@gmail.com> Date: Wed, 25 Sep 2024 20:19:52 +0100 Subject: [PATCH] Pcbnew: Show some helper lines in point editor Some shapes, like arcs and beziers have "lines" that can be useful to see when editing, but aren't directly editable and may not overlap the object's own lines. So make it possible to, indepedently: - Turn off the centre-point drag handle affordance - Show the actual line segment on screen. --- common/tool/edit_points.cpp | 14 ++++++++++- eeschema/tools/ee_point_editor.cpp | 8 ++++++ include/tool/edit_points.h | 39 ++++++++++++++++++++++++++++++ pcbnew/tools/pcb_point_editor.cpp | 8 ++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/common/tool/edit_points.cpp b/common/tool/edit_points.cpp index e62f670a52..5f45057904 100644 --- a/common/tool/edit_points.cpp +++ b/common/tool/edit_points.cpp @@ -315,7 +315,19 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const drawPoint( point ); for( const EDIT_LINE& line : m_lines ) - drawPoint( line, true ); + { + if( line.HasCenterPoint() ) + { + drawPoint( line.GetPosition(), true ); + } + + if( line.DrawLine() ) + { + gal->SetLineWidth( borderSize ); + gal->SetStrokeColor( borderColor ); + gal->DrawLine( line.GetOrigin().GetPosition(), line.GetEnd().GetPosition() ); + } + } gal->PopDepth(); } diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index 66ee6eb359..8a391cc94f 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -118,6 +118,9 @@ public: points->AddPoint( shape->GetStart() ); points->AddPoint( shape->GetEnd() ); points->AddPoint( shape->GetPosition() ); + + points->AddIndicatorLine( points->Point( ARC_CENTER ), points->Point( ARC_START ) ); + points->AddIndicatorLine( points->Point( ARC_CENTER ), points->Point( ARC_END ) ); break; case SHAPE_T::CIRCLE: @@ -160,6 +163,11 @@ public: points->AddPoint( shape->GetBezierC1() ); points->AddPoint( shape->GetBezierC2() ); points->AddPoint( shape->GetEnd() ); + + points->AddIndicatorLine( points->Point( BEZIER_START ), + points->Point( BEZIER_CTRL_PT1 ) ); + points->AddIndicatorLine( points->Point( BEZIER_END ), + points->Point( BEZIER_CTRL_PT2 ) ); break; default: diff --git a/include/tool/edit_points.h b/include/tool/edit_points.h index b36c4dd5bc..66929b80e2 100644 --- a/include/tool/edit_points.h +++ b/include/tool/edit_points.h @@ -304,6 +304,26 @@ public: return m_end; } + /** + * Is the center-point of the line useful to be shown? + */ + bool HasCenterPoint() const { return m_hasCenterPoint; } + + /** + * Set if the center-point of the line should be shown. + */ + void SetHasCenterPoint( bool aHasCenterPoint ) { m_hasCenterPoint = aHasCenterPoint; } + + /** + * Should the line itself be drawn, or just the end and/or center points? + */ + bool DrawLine() const { return m_showLine; } + + /** + * Set if the line itself should be drawn. + */ + void SetDrawLine( bool aShowLine ) { m_showLine = aShowLine; } + bool operator==( const EDIT_POINT& aOther ) const { return GetPosition() == aOther.GetPosition(); @@ -318,6 +338,9 @@ private: EDIT_POINT& m_origin; ///< Origin point for a line EDIT_POINT& m_end; ///< End point for a line + bool m_hasCenterPoint = true; ///< True if the line has a (useful) center point + bool m_showLine = false; ///< True if the line itself should be drawn + ///< Constraint for the point, NULL if none std::shared_ptr<EDIT_CONSTRAINT<EDIT_LINE> > m_constraint; }; @@ -390,6 +413,22 @@ public: m_lines.emplace_back( aOrigin, aEnd ); } + /** + * Adds an EDIT_LINE that is shown as an indicator, + * rather than an editable line (no center point drag, + * show the line itself). + * + * @param aOrigin is the origin for a new line. + * @param aEnd is the end for a new line. + */ + void AddIndicatorLine( EDIT_POINT& aOrigin, EDIT_POINT& aEnd ) + { + EDIT_LINE& line = m_lines.emplace_back( aOrigin, aEnd ); + line.SetHasCenterPoint( false ); + line.SetDrawLine( true ); + } + + /** * Adds a break, indicating the end of a contour. */ diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 66cde3ba4a..55f7e42077 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -267,6 +267,9 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) points->AddPoint( shape->GetArcMid() ); points->AddPoint( shape->GetEnd() ); points->AddPoint( shape->GetCenter() ); + + points->AddIndicatorLine( points->Point( ARC_CENTER ), points->Point( ARC_START ) ); + points->AddIndicatorLine( points->Point( ARC_CENTER ), points->Point( ARC_END ) ); break; case SHAPE_T::CIRCLE: @@ -283,6 +286,11 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) points->AddPoint( shape->GetBezierC1() ); points->AddPoint( shape->GetBezierC2() ); points->AddPoint( shape->GetEnd() ); + + points->AddIndicatorLine( points->Point( BEZIER_START ), + points->Point( BEZIER_CTRL_PT1 ) ); + points->AddIndicatorLine( points->Point( BEZIER_CTRL_PT2 ), + points->Point( BEZIER_END ) ); break; default: // suppress warnings