52 m_selectionTool( nullptr ),
72 m_frame = getEditFrame<PCB_BASE_FRAME>();
93 auto anyLines = graphicLines || trackLines;
101 auto showConvert = anyPolys || anyLines || lineToArc;
102 auto canCreatePolyType = anyLines || anyPolys;
103 auto canCreateTracks = anyPolys || graphicToTrack;
131 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
135 switch( item->
Type() )
140 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
149 aCollector.
Remove( item );
157 aCollector.
Remove( item );
171 aCollector.
Remove( item );
176 if( selection.Empty() )
195 if(
FP_SHAPE* graphic = dynamic_cast<FP_SHAPE*>( selection.Front() ) )
197 else if(
FP_ZONE* zone = dynamic_cast<FP_ZONE*>( selection.Front() ) )
198 parentFootprint = static_cast<FOOTPRINT*>( zone->GetParent() );
200 wxFAIL_MSG( wxT(
"Unimplemented footprint parent in CONVERT_TOOL::CreatePolys" ) );
206 std::vector<SHAPE_POLY_SET> polys;
219 graphic->
SetWidth( poly.Outline( 0 ).Width() );
223 commit.
Add( graphic );
226 commit.
Push(
_(
"Convert shapes to polygon" ) );
236 zoneInfo.
m_Layers.reset().set( destLayer );
257 if( ret == wxID_CANCEL )
272 commit.
Push(
_(
"Convert shapes to zone" ) );
286 const int chainingEpsilonSquared =
SEG::Square( 100 );
291 std::map<VECTOR2I, std::vector<std::pair<int, EDA_ITEM*>>> connections;
292 std::set<EDA_ITEM*> used;
293 std::deque<EDA_ITEM*> toCheck;
298 return ( aLeft - aRight ).SquaredEuclideanNorm() <= aLimit;
301 auto findInsertionPoint =
304 if( connections.count( aPoint ) )
307 for(
const auto& candidatePair : connections )
309 if( closeEnough( aPoint, candidatePair.first, chainingEpsilonSquared ) )
310 return candidatePair.first;
320 toCheck.push_back( item );
321 connections[findInsertionPoint( seg->A )].emplace_back( std::make_pair( 0, item ) );
322 connections[findInsertionPoint( seg->B )].emplace_back( std::make_pair( 1, item ) );
326 while( !toCheck.empty() )
328 EDA_ITEM* candidate = toCheck.front();
331 if( used.count( candidate ) )
342 && static_cast<PCB_SHAPE*>( aItem )->GetShape() ==
SHAPE_T::ARC ) )
348 std::shared_ptr<SHAPE> es =
349 static_cast<PCB_ARC*>( aItem )->GetEffectiveShape();
350 arc = *static_cast<SHAPE_ARC*>( es.get() );
354 PCB_SHAPE* ps = static_cast<PCB_SHAPE*>( aItem );
369 VECTOR2I& point = ( aAnchor == nextSeg->A ) ? nextSeg->B : nextSeg->A;
374 outline.
Insert( 0, point );
383 if( used.count( aItem ) )
386 used.insert( aItem );
388 insert( aItem, aAnchor, aDirection );
393 VECTOR2I nextAnchor = ( aAnchor == anchors->A ) ? anchors->B : anchors->A;
395 for( std::pair<int, EDA_ITEM*> pair : connections[nextAnchor] )
397 if( pair.second == aItem )
400 process( pair.second, nextAnchor, aDirection );
412 && static_cast<PCB_SHAPE*>( candidate )->GetShape() ==
SHAPE_T::ARC ) ) )
414 insert( candidate, anchors->A,
true );
417 process( candidate, anchors->B,
true );
422 for( std::pair<int, EDA_ITEM*> possibleLeft : connections[anchors->A] )
424 if( possibleLeft.second != candidate )
426 left = possibleLeft.second;
459 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( item );
492 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( item );
516 switch( item->Type() )
520 switch( static_cast<PCB_SHAPE*>( item )->GetShape() )
523 poly.
Append( static_cast<PCB_SHAPE*>( item )->GetPolyShape() );
534 poly.
Append( *static_cast<ZONE*>( item )->Outline() );
551 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
555 switch( item->
Type() )
559 switch( static_cast<PCB_SHAPE*>( item )->GetShape() )
568 aCollector.
Remove( item );
578 aCollector.
Remove( item );
583 if( selection.Empty() )
591 switch( aItem->Type() )
595 set = *static_cast<ZONE*>( aItem )->
Outline();
601 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
623 wxFAIL_MSG( wxT(
"Unhandled graphic shape type in PolyToLines - getPolySet" ) );
629 wxFAIL_MSG( wxT(
"Unhandled type in PolyToLines - getPolySet" ) );
639 std::vector<SEG> segs;
642 wxASSERT( aPoly.VertexCount() >= 2 );
644 for(
int i = 1; i < aPoly.VertexCount(); i++ )
645 segs.emplace_back(
SEG( aPoly.CVertex( i - 1 ), aPoly.CVertex( i ) ) );
647 segs.emplace_back(
SEG( aPoly.CVertex( aPoly.VertexCount() - 1 ),
648 aPoly.CVertex( 0 ) ) );
664 auto handleGraphicSeg =
670 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
708 targetLayer = copperLayer;
714 if( handleGraphicSeg( item ) )
718 std::vector<SEG> segs = getSegList( polySet );
722 for(
SEG& seg : segs )
729 graphic->
SetStart( wxPoint( seg.A ) );
731 graphic->
SetEnd( wxPoint( seg.B ) );
732 graphic->
SetEnd0( wxPoint( seg.B ) );
733 commit.
Add( graphic );
740 graphic->
SetStart( wxPoint( seg.A ) );
741 graphic->
SetEnd( wxPoint( seg.B ) );
742 commit.
Add( graphic );
753 for(
SEG& seg : segs )
757 graphic->
SetStart( wxPoint( seg.A ) );
759 graphic->
SetEnd( wxPoint( seg.B ) );
760 graphic->
SetEnd0( wxPoint( seg.B ) );
761 commit.
Add( graphic );
767 for(
SEG& seg : segs )
772 track->
SetStart( wxPoint( seg.A ) );
773 track->
SetEnd( wxPoint( seg.B ) );
780 commit.
Push(
_(
"Convert polygons to lines" ) );
791 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
799 aCollector.
Remove( item );
804 EDA_ITEM* source = selection.Front();
808 const double offsetRatio = 0.1;
815 VECTOR2I normal = ( seg->B - seg->A ).Perpendicular().Resize( offsetRatio * seg->Length() );
816 mid = seg->Center() +
normal;
826 BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( source );
838 PCB_SHAPE* line = static_cast<PCB_SHAPE*>( source );
849 arc->
SetEnd( wxPoint( end ) );
856 PCB_TRACK* line = static_cast<PCB_TRACK*>( source );
862 arc->
SetMid( wxPoint( mid ) );
863 arc->
SetEnd( wxPoint( end ) );
868 commit.
Push(
_(
"Create arc from line segment" ) );
876 switch( aItem->
Type() )
881 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
892 PCB_TRACK* line = static_cast<PCB_TRACK*>( aItem );
903 PCB_ARC* arc = static_cast<PCB_ARC*>( aItem );
PCB_LAYER_ID SelectOneLayer(PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask=LSET(), wxPoint aDlgPosition=wxDefaultPosition)
Show the dialog box for a layer selection.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void SetEnd0(const wxPoint &aPoint)
static TOOL_ACTION convertToTracks
void SetFilled(bool aFlag)
void SetEnd(const wxPoint &aEnd)
const wxPoint & GetEnd() const
static TOOL_ACTION convertToLines
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const wxPoint & GetStart() const
Return the starting point of the graphic.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
void SetEnd(const wxPoint &aEnd)
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
SHAPE_LINE_CHAIN & Simplify(bool aRemoveColinear=true)
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
void SetPolyShape(const SHAPE_POLY_SET &aShape)
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
SHAPE_POLY_SET * Outline()
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
class PCB_ARC, an arc track segment on a copper layer
Class that groups generic conditions for selected items.
class FP_SHAPE, a footprint edge
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
int PointCount() const
Return the number of points (vertices) in this line chain.
static SEG::ecoord Square(int a)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
static SELECTION_CONDITION SameLayer()
Creates a functor that tests if selection contains items that belong exclusively to the same layer.
static SELECTION_CONDITION OnlyGraphicShapeTypes(const std::set< SHAPE_T > aTypes)
Create a functor that tests if the selection contains PCB_SHAPE* items of certain shapes.
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
search types array terminator (End Of Types)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
class PCB_TRACK, a track segment (segment on a copper layer)
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
void Insert(size_t aVertex, const VECTOR2I &aP)
void SetStart(const wxPoint &aStart)
virtual PCB_LAYER_ID GetActiveLayer() const
int GetCount() const
Return the number of objects in the list.
void SetWidth(int aWidth)
Set the width of all segments in the chain.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
const wxPoint & GetEnd() const
Return the ending point of the graphic.
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
void SetMid(const wxPoint &aMid)
const VECTOR2I & GetP0() const
const ZONE_SETTINGS & GetZoneSettings() const
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aCornerBuffer, const wxPoint &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Test whether a layer is a non copper layer.
static TOOL_ACTION convertToZone
void SetStart(const wxPoint &aStart)
static TOOL_ACTION convertToKeepout
void SetWidth(int aWidth)
Handle a list of polygons defining a copper zone.
class ZONE, a copper pour area
void SetCenter(const wxPoint &aCenter)
void SetIsRuleArea(bool aEnable)
void SetStart0(const wxPoint &aPoint)
SHAPE_POLY_SET & GetPolyShape()
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
ZONE_SETTINGS handles zones parameters.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
wxPoint GetPosition() const override
void SetWidth(int aWidth)
static TOOL_ACTION convertToArc
bool IsType(FRAME_T aType) const
Common, abstract interface for edit frames.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
PCB_LAYER_ID
A quick note on layer IDs:
Used when the right click button is pressed, or when the select tool is in effect.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Create a functor that tests if the selected items are only of given type.
class ZONE, managed by a footprint
wxPoint GetArcMid() const
void process(const BOARD_CONNECTED_ITEM *item, int net)
void SetShape(SHAPE_T aShape)
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
static TOOL_ACTION convertToPoly
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
SHAPE_ARC Reversed() const
Abstract interface for BOARD_ITEMs capable of storing other items inside.
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
class PCB_SHAPE, a segment not on copper layers
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
A specialization of ZONE for use in footprints.
const wxPoint & GetStart() const
KICAD_T Type() const
Returns the type of object.
BOARD_ITEM_CONTAINER * GetParentFootprint() const
Container for design settings for a BOARD object.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...