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;
64 return _(
"Fillet Lines" );
72 return _(
"Unable to fillet the selected lines." );
76 return _(
"Some of the lines could not be filleted." );
92 if( seg_a.
A == seg_b.
A )
97 else if( seg_a.
A == seg_b.
B )
102 else if( seg_a.
B == seg_b.
A )
107 else if( seg_a.
B == seg_b.
B )
124 VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
129 aPointToSet.
x = aVecToTest.x;
130 aPointToSet.
y = aVecToTest.y;
138 if( !setIfPointOnSeg( t1newPoint, seg_a, sArc.
GetP0() )
139 && !setIfPointOnSeg( t2newPoint, seg_b, sArc.
GetP0() ) )
145 if( !setIfPointOnSeg( t1newPoint, seg_a, sArc.
GetP1() )
146 && !setIfPointOnSeg( t2newPoint, seg_b, sArc.
GetP1() ) )
152 auto tArc = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::ARC );
157 tArc->SetWidth( aLineA.
GetWidth() );
158 tArc->SetLayer( aLineA.
GetLayer() );
159 tArc->SetLocked( aLineA.
IsLocked() );
176 return _(
"Chamfer Lines" );
184 return _(
"Unable to chamfer the selected lines." );
188 return _(
"Some of the lines could not be chamfered." );
205 if( !SegmentsShareEndpoint( seg_a, seg_b ) )
211 std::optional<CHAMFER_RESULT> chamfer_result =
214 if( !chamfer_result )
220 auto tSegment = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::SEGMENT );
222 tSegment->SetStart( chamfer_result->m_chamfer.A );
223 tSegment->SetEnd( chamfer_result->m_chamfer.B );
226 tSegment->SetWidth( aLineA.
GetWidth() );
227 tSegment->SetLayer( aLineA.
GetLayer() );
228 tSegment->SetLocked( aLineA.
IsLocked() );
243 return _(
"Extend Lines to Meet" );
251 return _(
"Unable to extend the selected lines to meet." );
255 return _(
"Some of the lines could not be extended to meet." );
286 const auto line_extender = [&](
const SEG& aSeg,
PCB_SHAPE& aLine )
289 if( !aSeg.
Contains( *intersection ) )
291 const int dist_start = ( *intersection - aSeg.
A ).
EuclideanNorm();
294 const VECTOR2I& furthest_pt = ( dist_start < dist_end ) ? aSeg.
B : aSeg.
A;
297 unsigned int edge_padding =
static_cast<unsigned>(
pcbIUScale.
mmToIU( 200 ) );
301 aLine.SetStart( furthest_pt );
302 aLine.SetEnd( new_end );
306 line_extender( seg_a, aLineA );
307 line_extender( seg_b, aLineB );
315 std::unique_ptr<SHAPE_POLY_SET> poly;
321 poly = std::make_unique<SHAPE_POLY_SET>( aPcbShape.
GetPolyShape() );
324 case SHAPE_T::RECTANGLE:
328 const std::vector<VECTOR2I> rect_pts = aPcbShape.
GetRectCorners();
332 for(
const VECTOR2I& pt : rect_pts )
337 poly = std::make_unique<SHAPE_POLY_SET>( std::move( rect_poly ) );
354 auto initial = std::make_unique<PCB_SHAPE>(
GetBoard(), SHAPE_T::POLY );
355 initial->SetPolyShape( *poly );
358 initial->SetLayer( aPcbShape.
GetLayer() );
359 initial->SetWidth( aPcbShape.
GetWidth() );
387 return _(
"Merge polygons." );
395 return _(
"Unable to merge the selected polygons." );
399 return _(
"Some of the polygons could not be merged." );
410 working_copy.
BooleanAdd( aPolygon, poly_mode );
425 return _(
"Subtract polygons." );
433 return _(
"Unable to subtract the selected polygons." );
437 return _(
"Some of the polygons could not be subtracted." );
466 return _(
"Intersect polygons." );
474 return _(
"Unable to intersect the selected polygons." );
478 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
double EuclideanNorm(const VECTOR2I &vector)