32bool SegmentsShareEndpoint(
const SEG& aSegA,
const SEG& aSegB )
34 return ( aSegA.
A == aSegB.
A || aSegA.
A == aSegB.
B || aSegA.
B == aSegB.
A || aSegA.
B == aSegB.
B );
42 wxASSERT_MSG( aLine.
GetShape() == SHAPE_T::SEGMENT,
"Can only modify segments" );
44 const bool removed = aSeg.
Length() == 0;
63 return _(
"Fillet Lines" );
71 return _(
"Unable to fillet the selected lines." );
75 return _(
"Some of the lines could not be filleted." );
91 if( seg_a.
A == seg_b.
A )
96 else if( seg_a.
A == seg_b.
B )
101 else if( seg_a.
B == seg_b.
A )
106 else if( seg_a.
B == seg_b.
B )
121 VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
126 aPointToSet.
x = aVecToTest.x;
127 aPointToSet.
y = aVecToTest.y;
135 if( !setIfPointOnSeg( t1newPoint, seg_a, sArc.
GetP0() )
136 && !setIfPointOnSeg( t2newPoint, seg_b, sArc.
GetP0() ) )
142 if( !setIfPointOnSeg( t1newPoint, seg_a, sArc.
GetP1() )
143 && !setIfPointOnSeg( t2newPoint, seg_b, sArc.
GetP1() ) )
149 auto tArc = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::ARC );
154 tArc->SetWidth( aLineA.
GetWidth() );
155 tArc->SetLayer( aLineA.
GetLayer() );
156 tArc->SetLocked( aLineA.
IsLocked() );
173 return _(
"Chamfer Lines" );
181 return _(
"Unable to chamfer the selected lines." );
185 return _(
"Some of the lines could not be chamfered." );
202 if( !SegmentsShareEndpoint( seg_a, seg_b ) )
208 std::optional<CHAMFER_RESULT> chamfer_result =
211 if( !chamfer_result )
217 auto tSegment = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::SEGMENT );
219 tSegment->SetStart( chamfer_result->m_chamfer.A );
220 tSegment->SetEnd( chamfer_result->m_chamfer.B );
223 tSegment->SetWidth( aLineA.
GetWidth() );
224 tSegment->SetLayer( aLineA.
GetLayer() );
225 tSegment->SetLocked( aLineA.
IsLocked() );
240 return _(
"Extend Lines to Meet" );
248 return _(
"Unable to extend the selected lines to meet." );
252 return _(
"Some of the lines could not be extended to meet." );
283 const auto line_extender = [&](
const SEG& aSeg,
PCB_SHAPE& aLine )
286 if( !aSeg.
Contains( *intersection ) )
288 const int dist_start = ( *intersection - aSeg.
A ).
EuclideanNorm();
291 const VECTOR2I& furthest_pt = ( dist_start < dist_end ) ? aSeg.
B : aSeg.
A;
294 aLine.SetStart( furthest_pt );
295 aLine.SetEnd( *intersection );
299 line_extender( seg_a, aLineA );
300 line_extender( seg_b, aLineB );
308 std::unique_ptr<SHAPE_POLY_SET> poly;
314 poly = std::make_unique<SHAPE_POLY_SET>( aPcbShape.
GetPolyShape() );
317 case SHAPE_T::RECTANGLE:
321 const std::vector<VECTOR2I> rect_pts = aPcbShape.
GetRectCorners();
325 for(
const VECTOR2I& pt : rect_pts )
330 poly = std::make_unique<SHAPE_POLY_SET>( std::move( rect_poly ) );
347 auto initial = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::POLY );
348 initial->SetPolyShape( *poly );
351 initial->SetLayer( aPcbShape.
GetLayer() );
352 initial->SetWidth( aPcbShape.
GetWidth() );
380 return _(
"Merge polygons." );
388 return _(
"Unable to merge the selected polygons." );
392 return _(
"Some of the polygons could not be merged." );
403 working_copy.
BooleanAdd( aPolygon, poly_mode );
418 return _(
"Subtract polygons." );
426 return _(
"Unable to subtract the selected polygons." );
430 return _(
"Some of the polygons could not be subtracted." );
459 return _(
"Intersect polygons." );
467 return _(
"Unable to intersect the selected polygons." );
471 return _(
"Some of the polygons could not be intersected." );
std::optional< CHAMFER_RESULT > ComputeChamferPoints(const SEG &aSegA, const SEG &aSegB, const CHAMFER_PARAMS &aChamferParams)
Compute the chamfer points for a given line pair and chamfer parameters.
virtual bool IsLocked() const
SHAPE_POLY_SET & GetPolyShape()
void SetPolyShape(const SHAPE_POLY_SET &aShape)
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
std::vector< VECTOR2I > GetRectCorners() const
void SetEnd(const VECTOR2I &aEnd)
virtual void DeleteItem(PCB_SHAPE &aItem)=0
Report that the tool has deleted an item on the board.
virtual void MarkItemModified(PCB_SHAPE &aItem)=0
Report that the tool has modified an item on the board.
virtual void AddNewItem(std::unique_ptr< PCB_SHAPE > aItem)=0
Report that the tools wants to add a new item to the board.
unsigned GetFailures() const
void AddFailure()
Mark that one of the actions failed.
unsigned GetSuccesses() const
void AddSuccess()
Mark that one of the actions succeeded.
bool ModifyLineOrDeleteIfZeroLength(PCB_SHAPE &aItem, const SEG &aSeg)
Helper function useful for multiple tools: modify a line or delete it if it has zero length.
BOARD_ITEM * GetBoard() const
The BOARD used when creating new shapes.
CHANGE_HANDLER & GetHandler()
Access the handler for making changes to the board.
wxString GetCommitDescription() const override
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
const CHAMFER_PARAMS m_chamferParams
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
wxString GetCommitDescription() const override
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
wxString GetCommitDescription() const override
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
int GetWidth() const override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
PCB_SHAPE * m_workingPolygon
PCB_SHAPE * GetWorkingPolygon() const
void ProcessShape(PCB_SHAPE &aPcbShape)
virtual bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon)=0
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
wxString GetCommitDescription() const override
bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon) override
bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon) override
wxString GetCommitDescription() const override
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
wxString GetCommitDescription() const override
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon) override
bool Intersects(const SEG &aSeg) const
int Length() const
Return the length (this).
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
bool Contains(const SEG &aSeg) const
const VECTOR2I & GetArcMid() const
const VECTOR2I & GetP1() const
const VECTOR2I & GetP0() const
Represent a set of closed polygons.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
POLYGON_MODE
Operations on polygons use a aFastMode param if aFastMode is PM_FAST (true) the result can be a weak ...
int VertexCount(int aOutline=-1, int aHole=-1) const
Return the number of vertices in a given outline/hole.
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union For aFastMode meaning, see function booleanOp.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
int OutlineCount() const
Return the number of outlines in the set.
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in a shape.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
std::optional< VECTOR2I > OPT_VECTOR2I
double EuclideanNorm(const VECTOR2I &vector)