49 m_selectionTool(
NULL ),
68 m_frame = getEditFrame<PCB_BASE_FRAME>();
84 auto anyLines = graphicLines || trackLines;
92 auto showConvert = anyPolys || anyLines || lineToArc;
120 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
124 switch( item->
Type() )
128 switch( static_cast<PCB_SHAPE*>( item )->GetShape() )
137 aCollector.
Remove( item );
147 aCollector.
Remove( item );
152 if( selection.Empty() )
171 if(
FP_SHAPE* graphic = dynamic_cast<FP_SHAPE*>( selection.Front() ) )
172 parentFootprint = graphic->GetParentFootprint();
177 std::vector<SHAPE_POLY_SET> polys;
193 commit.
Add( graphic );
196 commit.
Push(
_(
"Convert shapes to polygon" ) );
212 if( ret == wxID_CANCEL )
227 commit.
Push(
_(
"Convert shapes to zone" ) );
238 std::map<VECTOR2I, std::vector<EDA_ITEM*>> connections;
239 std::set<EDA_ITEM*> used;
240 std::deque<EDA_ITEM*> toCheck;
246 toCheck.push_back( item );
247 connections[seg->A].emplace_back( item );
248 connections[seg->B].emplace_back( item );
252 while( !toCheck.empty() )
254 EDA_ITEM* candidate = toCheck.front();
257 if( used.count( candidate ) )
264 std::deque<VECTOR2I> points;
269 [&](
EDA_ITEM* aItem,
bool aDirection )
271 if( used.count( aItem ) )
274 used.insert( aItem );
280 VECTOR2I& ref = aDirection ? points.back() : points.front();
283 VECTOR2I&
next = ( ref == nextSeg->A ) ? nextSeg->B : nextSeg->A;
286 points.push_back(
next );
288 points.push_front(
next );
291 process( neighbor, aDirection );
295 points.push_back( seg->A );
301 for(
EDA_ITEM* possibleLeft : connections[seg->A] )
303 if( possibleLeft != candidate )
313 if( points.size() < 3 )
316 for(
const VECTOR2I& point : points )
337 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( item );
368 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( item );
391 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
395 switch( item->
Type() )
399 switch( static_cast<PCB_SHAPE*>( item )->GetShape() )
408 aCollector.
Remove( item );
418 aCollector.
Remove( item );
423 if( selection.Empty() )
431 switch( aItem->Type() )
435 set = *static_cast<ZONE*>( aItem )->
Outline();
441 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
463 wxFAIL_MSG(
"Unhandled graphic shape type in PolyToLines - getPolySet" );
469 wxFAIL_MSG(
"Unhandled type in PolyToLines - getPolySet" );
479 std::vector<SEG> segs;
482 wxASSERT( aPoly.VertexCount() >= 2 );
484 for(
int i = 1; i < aPoly.VertexCount(); i++ )
485 segs.emplace_back(
SEG( aPoly.CVertex( i - 1 ), aPoly.CVertex( i ) ) );
487 segs.emplace_back(
SEG( aPoly.CVertex( aPoly.VertexCount() - 1 ),
488 aPoly.CVertex( 0 ) ) );
505 std::vector<SEG> segs = getSegList( polySet );
509 for(
SEG& seg : segs )
516 graphic->
SetStart( wxPoint( seg.A ) );
518 graphic->
SetEnd( wxPoint( seg.B ) );
519 graphic->
SetEnd0( wxPoint( seg.B ) );
520 commit.
Add( graphic );
528 graphic->
SetStart( wxPoint( seg.A ) );
529 graphic->
SetEnd( wxPoint( seg.B ) );
530 commit.
Add( graphic );
547 for(
SEG& seg : segs )
551 graphic->
SetStart( wxPoint( seg.A ) );
553 graphic->
SetEnd( wxPoint( seg.B ) );
554 graphic->
SetEnd0( wxPoint( seg.B ) );
555 commit.
Add( graphic );
561 for(
SEG& seg : segs )
566 track->
SetStart( wxPoint( seg.A ) );
567 track->
SetEnd( wxPoint( seg.B ) );
574 commit.
Push(
_(
"Convert polygons to lines" ) );
585 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
593 aCollector.
Remove( item );
598 EDA_ITEM* source = selection.Front();
602 const double offsetRatio = 0.1;
609 VECTOR2I normal = ( seg->B - seg->A ).Perpendicular().
Resize( offsetRatio * seg->Length() );
610 mid = seg->Center() + normal;
618 BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( source );
630 PCB_SHAPE* line = static_cast<PCB_SHAPE*>( source );
650 TRACK* line = static_cast<TRACK*>( source );
651 ARC* arc =
new ARC( parent );
656 arc->
SetMid( wxPoint( mid ) );
657 arc->
SetEnd( wxPoint( end ) );
662 commit.
Push(
_(
"Create arc from line segment" ) );
670 switch( aItem->
Type() )
675 PCB_SHAPE* line = static_cast<PCB_SHAPE*>( aItem );
682 TRACK* line = static_cast<TRACK*>( aItem );
689 ARC* arc = static_cast<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)
double GetArcAngle(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Returns the subtended angle for a given arc.
static TOOL_ACTION convertToTracks
SHAPE_POLY_SET & GetPolyShape()
static TOOL_ACTION convertToLines
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
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...
void SetEnd(const wxPoint &aEnd)
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...
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
const wxPoint & GetStart() const
const BITMAP_OPAQUE convert_xpm[1]
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
void SetFilled(bool aFlag)
SHAPE_POLY_SET * Outline()
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
static SELECTION_CONDITION OnlyGraphicShapeTypes(const std::set< PCB_SHAPE_TYPE_T > aTypes)
Create a functor that tests if the selection contains PCB_SHAPE* items of certain shapes.
polygon (not yet used for tracks, but could be in microwave apps)
class ARC, an arc track segment on a copper layer
Class that groups generic conditions for selected items.
usual segment : line with rounded ends
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
class FP_SHAPE, a footprint edge
segment with non rounded ends
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.
static SELECTION_CONDITION SameLayer()
Creates a functor that tests if selection contains items that belong exclusively to the same layer.
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 TRACK, a track segment (segment on a copper layer)
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetWidth(int aWidth)
int GetCount() const
Return the number of objects in the list.
void SetClosed(bool aClosed)
Function SetClosed()
PCB_LAYER_ID
A quick note on layer IDs:
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
void SetShape(PCB_SHAPE_TYPE_T aShape)
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
void HatchBorder()
Function HatchBorder computes the hatch lines depending on the hatch parameters and stores it in the ...
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
const ZONE_SETTINGS & GetZoneSettings() const
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
static TOOL_ACTION convertToZone
static TOOL_ACTION convertToKeepout
ZONE handles a list of polygons defining a copper zone.
class ZONE, a copper pour area
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
void SetMid(const wxPoint &aMid)
void SetStart0(const wxPoint &aPoint)
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
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
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
static TOOL_ACTION convertToArc
bool IsType(FRAME_T aType) const
Common, abstract interface for edit frames.
void SetStart(const wxPoint &aStart)
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
void process(const BOARD_CONNECTED_ITEM *item, int net)
void SetWidth(int aWidth)
A base class for most all the KiCad significant classes used in schematics and boards.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aCornerBuffer, wxPoint aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc)
Function TransformCircleToPolygon convert a circle to a polygon, using multiple straight lines.
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.
const wxPoint & GetEnd() const
void SetArcEnd(const wxPoint &aArcEndPoint)
Initialize the end arc point.
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
void SetStart(const wxPoint &aStart)
static TOOL_ACTION convertToPoly
void SetPolyShape(const SHAPE_POLY_SET &aShape)
PCB_SHAPE_TYPE_T GetShape() const
Abstract interface for BOARD_ITEMs capable of storing other items inside.
const VECTOR2I GetArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
virtual void SetAngle(double aAngle, bool aUpdateEnd=true)
Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
class PCB_SHAPE, a segment not on copper layers
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
FP_ZONE is a specialization of ZONE for use in footprints.
void SetEnd(const wxPoint &aEnd)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
KICAD_T Type() const
Returns the type of object.
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...