33bool SegmentsShareEndpoint(
const SEG& aSegA,
const SEG& aSegB )
35 return ( aSegA.
A == aSegB.
A || aSegA.
A == aSegB.
B || aSegA.
B == aSegB.
A || aSegA.
B == aSegB.
B );
43 wxASSERT_MSG( aLine.
GetShape() == SHAPE_T::SEGMENT,
"Can only modify segments" );
45 const bool removed = aSeg.
Length() == 0;
66 return _(
"Fillet Lines" );
74 return _(
"Unable to fillet the selected lines." );
78 return _(
"Some of the lines could not be filleted." );
94 if( seg_a.
A == seg_b.
A )
99 else if( seg_a.
A == seg_b.
B )
104 else if( seg_a.
B == seg_b.
A )
109 else if( seg_a.
B == seg_b.
B )
126 VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
131 aPointToSet.
x = aVecToTest.x;
132 aPointToSet.
y = aVecToTest.y;
140 if( !setIfPointOnSeg( t1newPoint, seg_a, sArc.
GetP0() )
141 && !setIfPointOnSeg( t2newPoint, seg_b, sArc.
GetP0() ) )
147 if( !setIfPointOnSeg( t1newPoint, seg_a, sArc.
GetP1() )
148 && !setIfPointOnSeg( t2newPoint, seg_b, sArc.
GetP1() ) )
154 auto tArc = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::ARC );
159 tArc->SetWidth( aLineA.
GetWidth() );
160 tArc->SetLayer( aLineA.
GetLayer() );
161 tArc->SetLocked( aLineA.
IsLocked() );
178 return _(
"Chamfer Lines" );
186 return _(
"Unable to chamfer the selected lines." );
190 return _(
"Some of the lines could not be chamfered." );
207 if( !SegmentsShareEndpoint( seg_a, seg_b ) )
213 std::optional<CHAMFER_RESULT> chamfer_result =
216 if( !chamfer_result )
222 auto tSegment = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::SEGMENT );
224 tSegment->SetStart( chamfer_result->m_chamfer.A );
225 tSegment->SetEnd( chamfer_result->m_chamfer.B );
228 tSegment->SetWidth( aLineA.
GetWidth() );
229 tSegment->SetLayer( aLineA.
GetLayer() );
230 tSegment->SetLocked( aLineA.
IsLocked() );
245 return _(
"Extend Lines to Meet" );
253 return _(
"Unable to extend the selected lines to meet." );
257 return _(
"Some of the lines could not be extended to meet." );
288 const auto line_extender = [&](
const SEG& aSeg,
PCB_SHAPE& aLine )
291 if( !aSeg.
Contains( *intersection ) )
293 const int dist_start = ( *intersection - aSeg.
A ).EuclideanNorm();
294 const int dist_end = ( *intersection - aSeg.
B ).EuclideanNorm();
296 const VECTOR2I& furthest_pt = ( dist_start < dist_end ) ? aSeg.
B : aSeg.
A;
299 unsigned int edge_padding =
static_cast<unsigned>(
pcbIUScale.
mmToIU( 200 ) );
303 aLine.SetStart( furthest_pt );
304 aLine.SetEnd( new_end );
308 line_extender( seg_a, aLineA );
309 line_extender( seg_b, aLineB );
317 std::unique_ptr<SHAPE_POLY_SET> poly;
323 poly = std::make_unique<SHAPE_POLY_SET>( aPcbShape.
GetPolyShape() );
326 case SHAPE_T::RECTANGLE:
330 const std::vector<VECTOR2I> rect_pts = aPcbShape.
GetRectCorners();
334 for(
const VECTOR2I& pt : rect_pts )
339 poly = std::make_unique<SHAPE_POLY_SET>( std::move( rect_poly ) );
356 auto initial = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::POLY );
357 initial->SetPolyShape( *poly );
360 initial->SetLayer( aPcbShape.
GetLayer() );
361 initial->SetWidth( aPcbShape.
GetWidth() );
389 return _(
"Merge polygons." );
397 return _(
"Unable to merge the selected polygons." );
401 return _(
"Some of the polygons could not be merged." );
412 working_copy.
BooleanAdd( aPolygon, poly_mode );
427 return _(
"Subtract polygons." );
435 return _(
"Unable to subtract the selected polygons." );
439 return _(
"Some of the polygons could not be subtracted." );
468 return _(
"Intersect polygons." );
476 return _(
"Unable to intersect the selected polygons." );
480 return _(
"Some of the polygons could not be intersected." );
constexpr EDA_IU_SCALE pcbIUScale
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
bool IsHorizontal() 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
EDA_ANGLE Angle(const SEG &aOther) const
Determine the smallest angle between two segments.
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).
a few functions useful in geometry calculations.
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamps a vector to values that can be negated, respecting numeric limits of coordinates data type wit...
std::optional< VECTOR2I > OPT_VECTOR2I
constexpr int mmToIU(double mm) const