43#include <wx/tokenzr.h>
67constexpr double OCTAGON_CHAMFER_RATIO = 0.25;
89std::vector<VECTOR2I> parsePolyPad(
const std::string& aValue )
91 std::vector<VECTOR2I> pts;
92 wxStringTokenizer tokens( wxString( aValue ), wxS(
";" ), wxTOKEN_STRTOK );
94 while( tokens.HasMoreTokens() )
96 wxString pair = tokens.GetNextToken();
100 if( !pair.BeforeFirst(
',' ).ToLong( &x ) || !pair.AfterFirst(
',' ).ToLong( &y ) )
103 pts.emplace_back(
int( x ),
int( y ) );
111int mostCommon(
const std::map<int, int>& aCounts )
113 auto it = std::max_element( aCounts.begin(), aCounts.end(),
114 [](
const auto& a,
const auto& b )
116 return a.second < b.second;
144 if( !aFill.
Collide( &probe, aReach, &gap ) || gap <= 0 )
147 best = best ? std::min( best, gap ) : gap;
181 m_board->GetDesignSettings().m_CopperEdgeClearance = 0;
184 m_board->m_LegacyDesignSettingsLoaded =
true;
190 bbox =
m_board->ComputeBoundingBox(
false );
200 return LAYER_FUNCTION::OTHER;
210 return f == LAYER_FUNCTION::COPPER_BOTTOM || f == LAYER_FUNCTION::COPPER_INSIDE
211 || f == LAYER_FUNCTION::COPPER_TOP;
224 wxString
text = aValue;
225 text.Replace( wxS(
"\\" ), wxS(
"\\\\" ) );
226 text.Replace( wxS(
"'" ), wxS(
"\\\\'" ) );
227 text.Replace( wxS(
"\"" ), wxS(
"\\\"" ) );
228 return wxS(
"'" ) +
text + wxS(
"'" );
237 std::map<int, int> boardCounts;
238 std::map<int, std::vector<wxString>> netsByClearance;
244 if( !item || item->
GetNetCode() <= 0 || counts.empty() )
247 netsByClearance[mostCommon( counts )].push_back( item->
GetNetname() );
249 for(
const auto& [
clearance, count] : counts )
253 if( boardCounts.empty() )
256 auto addRule = [&](
const wxString& aName,
int aClearance,
const wxString& aCondition )
258 m_designRules += wxString::Format( wxS(
"\n(rule \"%s\"\n (constraint clearance (min %s))\n"
259 " (condition \"%s\"))\n" ),
260 aName,
ruleMm( aClearance ), aCondition );
264 int base = mostCommon( boardCounts );
266 addRule( wxS(
"TARGET 3001! copper areas" ), base, wxS(
"A.Type == 'Zone'" ) );
268 for(
const auto& [
clearance, nets] : netsByClearance )
275 for(
const wxString&
name : nets )
277 if( !condition.IsEmpty() )
278 condition += wxS(
" || " );
284 wxS(
"A.Type == 'Zone' && (" ) + condition + wxS(
")" ) );
298 m_designRules += wxS(
"\n(rule \"TARGET 3001! areas join own pads and vias\"\n"
299 " (condition \"A.hasCustomProperty('TARGET3001_AURA') "
300 "&& B.hasCustomProperty('TARGET3001_AREA')\")\n"
301 " (constraint zone_connection solid))\n" );
304 m_designRules += wxS(
"\n(rule \"TARGET 3001! area spokes\"\n"
305 " (condition \"B.hasCustomProperty('TARGET3001_AREA')\")\n"
306 " (constraint min_resolved_spokes 1))\n" );
310 m_designRules += wxString::Format( wxS(
"\n(rule \"TARGET 3001! aura %s\"\n"
311 " (condition \"A.customProperty('TARGET3001_AURA') == '%d' "
312 "&& B.hasCustomProperty('TARGET3001_AREA')\")\n"
313 " (constraint zone_connection none)\n"
314 " (constraint physical_clearance (min %s)))\n" ),
322 m_designRules += wxString::Format( wxS(
"\n(rule \"TARGET 3001! no aura on %s\"\n"
324 " (condition \"A.customProperty('TARGET3001_NO_AURA') == '*,%s,*' "
325 "&& B.hasCustomProperty('TARGET3001_AREA')\")\n"
326 " (constraint zone_connection solid)\n"
327 " (constraint physical_clearance (min 0mm)))\n" ),
335 aItem.
SetCustomProperty( wxS(
"TARGET3001_AURA" ), wxString::Format( wxS(
"%d" ), aAura ) );
345 if(
const std::string* list = aBase.
FindProp(
"NO_AURA" ) )
347 wxStringTokenizer tokens( wxString::FromUTF8( *list ), wxS(
"," ) );
349 while( tokens.HasMoreTokens() )
353 if( !tokens.GetNextToken().Trim().Trim(
false ).ToLong( &layer ) || !
isCopper(
int( layer ) ) )
356 if( std::optional<PCB_LAYER_ID> cu =
mapLayer(
int( layer ) ) )
358 layers += ( layers.IsEmpty() ? wxS(
"," ) : wxS(
"" ) ) +
LSET::Name( *cu ) + wxS(
"," );
364 if( !layers.IsEmpty() )
371 std::vector<int>
top;
372 std::vector<int> inner;
373 std::vector<int> bottom;
379 case LAYER_FUNCTION::COPPER_TOP:
top.push_back( layer );
break;
380 case LAYER_FUNCTION::COPPER_INSIDE: inner.push_back( layer );
break;
381 case LAYER_FUNCTION::COPPER_BOTTOM: bottom.push_back( layer );
break;
394 THROW_IO_ERROR( wxString::Format(
_(
"TARGET 3001! board has %zu copper layers; at most %d are supported." ),
400 if( copperCount % 2 )
403 m_board->SetCopperLayerCount( copperCount );
433 std::optional<PCB_LAYER_ID> id;
437 case LAYER_FUNCTION::POSITION_BOTTOM:
id =
B_SilkS;
break;
438 case LAYER_FUNCTION::POSITION_TOP:
id =
F_SilkS;
break;
439 case LAYER_FUNCTION::NAMES_BOTTOM:
id =
B_SilkS;
break;
440 case LAYER_FUNCTION::NAMES_TOP:
id =
F_SilkS;
break;
441 case LAYER_FUNCTION::VALUES_BOTTOM:
id =
B_Fab;
break;
442 case LAYER_FUNCTION::VALUES_TOP:
id =
F_Fab;
break;
443 case LAYER_FUNCTION::MASK_BOTTOM:
id =
B_Mask;
break;
444 case LAYER_FUNCTION::MASK_TOP:
id =
F_Mask;
break;
445 case LAYER_FUNCTION::PASTE_BOTTOM:
id =
B_Paste;
break;
446 case LAYER_FUNCTION::PASTE_TOP:
id =
F_Paste;
break;
447 case LAYER_FUNCTION::GLUE_BOTTOM:
id =
B_Adhes;
break;
448 case LAYER_FUNCTION::GLUE_TOP:
id =
F_Adhes;
break;
450 case LAYER_FUNCTION::OUTLINE:
id =
Edge_Cuts;
break;
451 case LAYER_FUNCTION::DIMENSIONING:
id =
Dwgs_User;
break;
452 case LAYER_FUNCTION::DRILL_PLAN:
id =
Cmts_User;
break;
455 case LAYER_FUNCTION::AREA_BOTTOM:
456 case LAYER_FUNCTION::AREA_INSIDE:
457 case LAYER_FUNCTION::AREA_TOP:
458 case LAYER_FUNCTION::DELETION_BOTTOM:
459 case LAYER_FUNCTION::DELETION_INSIDE:
460 case LAYER_FUNCTION::DELETION_TOP:
461 case LAYER_FUNCTION::AIR_WIRES:
482 m_board->SetEnabledLayers( enabled );
483 m_board->SetVisibleLayers( enabled );
488 m_board->SetLayerName(
id, wxString::Format( wxS(
"Target layer %d" ), target ) );
510 case LAYER_FUNCTION::AREA_BOTTOM:
511 case LAYER_FUNCTION::AREA_INSIDE:
512 case LAYER_FUNCTION::AREA_TOP:
513 defaultCopper = aLayer + 2;
516 case LAYER_FUNCTION::DELETION_BOTTOM:
517 case LAYER_FUNCTION::DELETION_INSIDE:
518 case LAYER_FUNCTION::DELETION_TOP:
519 defaultCopper = aLayer + 1;
526 int copper =
m_project.layerAssociations[aLayer];
530 copper = defaultCopper;
552 for(
size_t i = 0; i <
m_project.signals.size(); i++ )
556 if( e.
type != ELEMENT_TYPE::SIGNAL || !e.
signal )
562 name = wxString::Format( wxS(
"Net-%zu" ), i + 1 );
566 name = wxString::Format( wxS(
"%s_%zu" ),
name, i + 1 );
575 auto it =
m_nets.find( aSignal );
576 return it ==
m_nets.end() ? nullptr : it->second;
596 if(
comp.packageItems.empty() )
599 const ELEMENT* placement = &
comp.packageItems.front();
601 if( placement->
type != ELEMENT_TYPE::PACKAGE || !placement->
package )
606 if( placementLayer != LAYER_FUNCTION::POSITION_TOP && placementLayer != LAYER_FUNCTION::POSITION_BOTTOM )
622 wxString reference =
ToWx(
comp.prefix ).Trim().Trim(
false );
623 uint16_t number =
comp.referenceExtension.value_or(
comp.referenceNumber );
635 if( &item != placement )
636 addItem( item, fp, fp,
false );
643 std::vector<const ELEMENT*> spokes;
647 if( e.
type != ELEMENT_TYPE::SIGNAL || !e.
signal )
650 std::set<int64_t> polygons;
655 polygons.insert( poly.
id );
665 if( std::optional<int64_t>
id = t.
base.
PolygonId();
id && polygons.count( *
id ) )
678 spokes.push_back( &t );
692 for(
int i = 0; i < polys.OutlineCount(); i++ )
699 shape->
SetNet(
net( uint16_t( key.first ) ) );
708 std::set<std::pair<uint16_t, PCB_LAYER_ID>> areas;
709 std::map<int, std::vector<PAD*>> padsByNet;
710 std::map<int, std::vector<PCB_VIA*>> viasByNet;
713 areas.emplace( area.signal, area.layer );
717 for(
PAD*
pad : fp->Pads() )
718 padsByNet[
pad->GetNetCode()].push_back(
pad );
724 viasByNet[track->GetNetCode()].push_back(
static_cast<PCB_VIA*
>( track ) );
727 std::map<PAD*, const ELEMENT*> padSpokes;
728 std::set<PCB_VIA*> spokedVias;
730 for(
const ELEMENT* spoke : aSpokes )
738 if( layer &&
IsCopperLayer( *layer ) && item && areas.count( { b.signal, *layer } ) )
742 if(
pad->IsOnLayer( *layer ) &&
pad->GetEffectiveShape( *layer )->Collide( start ) )
756 if( !relief &&
via->IsOnLayer( *layer ) &&
via->GetEffectiveShape( *layer )->Collide( start ) )
758 spokedVias.insert(
via );
768 for(
const auto& [
pad, spoke] : padSpokes )
770 VECTOR2I dir =
toKi( spoke->line.x2, spoke->line.y2 ) -
toKi( spoke->base.x, spoke->base.y );
774 double degrees = std::fmod(
EDA_ANGLE(
VECTOR2D( dir ) ).AsDegrees() + 360.0, 90.0 );
777 pad->SetCustomProperty( wxS(
"TARGET3001_AURA" ), wxS(
"0" ) );
779 pad->SetLocalThermalSpokeWidthOverride( spoke->line.width );
782 if( std::optional<int> aura =
pad->GetLocalClearance(); aura && *aura > 0 )
783 pad->SetLocalThermalGapOverride( aura );
788 via->SetCustomProperty( wxS(
"TARGET3001_AURA" ), wxS(
"0" ) );
801 std::map<std::pair<uint16_t, PCB_LAYER_ID>,
SHAPE_POLY_SET> pours;
804 pours[{ area.signal, area.layer }].Append( area.outline );
806 for(
auto& [key, outline] : pours )
810 for(
int i = 0; i < outline.OutlineCount(); i++ )
835 for(
int i = 0; i < keepout.OutlineCount(); i++ )
856 if( e.
type != ELEMENT_TYPE::SIGNAL || !e.
signal )
861 std::optional<PCB_LAYER_ID> layer =
polygonLayer( poly );
872 size_t count = poly.
outline.size();
877 for(
size_t i = 0; i < count; i++ )
899 zone->
SetCustomProperty( wxS(
"TARGET3001_POLYGON_AURA" ), wxString::Format( wxS(
"%d" ), poly.
aura ) );
936 std::map<PAD*, std::map<ZONE*, int>> padGaps;
937 std::map<ZONE*, std::map<int, int>> zoneCounts;
938 std::map<int, int> boardCounts;
948 for(
PAD*
pad : fp->Pads() )
950 if(
pad->GetNetCode() != zone->GetNetCode() || !
pad->FlashLayer( layer )
951 || !zone->Outline()->Contains(
pad->GetPosition() ) )
957 if( !spokes.
Collide(
pad->GetEffectiveShape( layer ).get() ) )
960 int gap =
KiROUND(
double( padFillGap( *
pad, layer, body, reach ) ) / step ) * step;
965 padGaps[
pad][zone] = gap;
966 zoneCounts[zone][gap]++;
972 if( boardCounts.empty() )
978 auto it = zoneCounts.find( zone );
979 zone->SetThermalReliefGap( mostCommon( it != zoneCounts.end() ? it->second : boardCounts ) );
982 std::map<wxString, int> references;
985 references[fp->GetReference()]++;
987 std::map<int, std::vector<wxString>> footprintsByGap;
991 std::map<PAD*, int> overrides;
994 for(
PAD*
pad : fp->Pads() )
996 auto it = padGaps.find(
pad );
998 if( it == padGaps.end() )
1001 std::map<int, int> counts;
1002 bool differs =
false;
1004 for(
const auto& [zone, gap] : it->second )
1008 differs |= gap != zone->GetThermalReliefGap();
1012 overrides[
pad] = mostCommon( counts );
1015 if( overrides.empty() )
1019 const wxString& ref = fp->GetReference();
1021 if( gaps.size() == 1 && !ref.IsEmpty() && references[ref] == 1 )
1023 footprintsByGap[*gaps.begin()].push_back( ref );
1027 for(
const auto& [
pad, gap] : overrides )
1028 pad->SetLocalThermalGapOverride( gap );
1031 if( footprintsByGap.empty() )
1038 for(
const auto& [gap, refs] : footprintsByGap )
1042 for(
const wxString& ref : refs )
1044 if( !condition.IsEmpty() )
1045 condition += wxS(
" || " );
1047 condition += wxS(
"A.Reference == " ) +
ruleLiteral( ref );
1050 m_designRules += wxString::Format( wxS(
"\n(rule \"TARGET 3001! thermal gap %s\"\n"
1051 " (condition \"A.Type == 'Footprint' && (%s)\")\n"
1052 " (constraint thermal_relief_gap (min %s)))\n" ),
1068 m_designRules += wxString::Format( wxS(
"\n(rule \"TARGET 3001! polygon contour distance %s\"\n"
1069 " (condition \"A.customProperty('TARGET3001_EDGE_CLEARANCE') "
1071 " (constraint edge_clearance (min %s)))\n" ),
1078 m_designRules += wxString::Format( wxS(
"\n(rule \"TARGET 3001! polygon aura %s\"\n"
1079 " (condition \"A.customProperty('TARGET3001_POLYGON_AURA') "
1080 "== '%d' && B.Type == 'Zone'\")\n"
1081 " (constraint clearance (min %s)))\n" ),
1092 switch( aElem.
type )
1094 case ELEMENT_TYPE::TRIANGLE:
1104 case ELEMENT_TYPE::RECTANGLE:
1108 VECTOR2D corners[4] = { { 0.0, 0.0 }, { double( r.
width ), 0.0 },
1123 case ELEMENT_TYPE::DISC:
1127 case ELEMENT_TYPE::LINE:
1132 case ELEMENT_TYPE::FIDUCIAL:
1138 case ELEMENT_TYPE::ARC:
1140 const ARC& a = aElem.
arc;
1142 int width = std::max( 1, a.
width );
1145 if(
sweep >= 360.0 - 1e-6 )
1151 auto onArc = [&](
double aDeg )
1188 if( ( b.
flags & 1 ) && aElem.
type != ELEMENT_TYPE::TEXT )
1191 if( aElem.
type == ELEMENT_TYPE::PAD )
1194 addPad( aElem, aFootprint );
1198 addPad( aElem,
nullptr );
1208 if( aElem.
type == ELEMENT_TYPE::TEXT )
1225 bool isArea = f == LAYER_FUNCTION::AREA_BOTTOM || f == LAYER_FUNCTION::AREA_INSIDE
1226 || f == LAYER_FUNCTION::AREA_TOP;
1237 std::vector<PCB_LAYER_ID> layers;
1243 layers.push_back( cu );
1245 else if( std::optional<PCB_LAYER_ID> layer =
mapLayer( b.
layer ) )
1247 layers.push_back( *layer );
1252 if( aElem.
type == ELEMENT_TYPE::TEXT )
1253 addText( aElem, aParent, aFootprint, layer );
1255 addShape( aElem, aParent, aFootprint, aIsTrack, layer );
1270 if( aElem.
type == ELEMENT_TYPE::LINE )
1272 else if( aElem.
type == ELEMENT_TYPE::ARC )
1274 else if( aElem.
type == ELEMENT_TYPE::SPLINE )
1282 switch( aElem.
type )
1284 case ELEMENT_TYPE::LINE:
1288 if( copper && aIsTrack && !aFootprint )
1313 case ELEMENT_TYPE::ARC:
1315 const ARC& a = aElem.
arc;
1319 bool full =
sweep >= 360.0 - 1e-6;
1344 if( copper && aIsTrack && !aFootprint )
1369 case ELEMENT_TYPE::SPLINE:
1393 case ELEMENT_TYPE::TRIANGLE:
1394 case ELEMENT_TYPE::RECTANGLE:
1395 case ELEMENT_TYPE::DISC:
1401 if( copper && aIsTrack && !aFootprint && aElem.
type == ELEMENT_TYPE::TRIANGLE )
1409 if( aElem.
type == ELEMENT_TYPE::DISC )
1432 case ELEMENT_TYPE::FIDUCIAL:
1433 for( std::unique_ptr<PCB_SHAPE>& shape :
fiducialShapes( aElem, aParent ) )
1435 shape->SetLayer( aLayer );
1456 std::vector<std::unique_ptr<PCB_SHAPE>> shapes;
1458 auto circle = [&](
int aRadius,
int aWidth,
bool aFilled )
1460 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aParent,
SHAPE_T::CIRCLE );
1461 shape->SetCenter(
toKi( b.
x, b.
y ) );
1462 shape->SetRadius( aRadius );
1464 shape->SetFilled( aFilled );
1465 shapes.push_back( std::move( shape ) );
1484 for(
double axis : { 0.0, 90.0 } )
1487 int32_t dx =
KiROUND( ring * cos( rad ) );
1488 int32_t dy =
KiROUND( ring * sin( rad ) );
1490 std::unique_ptr<PCB_SHAPE> arm = std::make_unique<PCB_SHAPE>( aParent,
SHAPE_T::SEGMENT );
1491 arm->SetStart(
toKi( b.
x + dx, b.
y + dy ) );
1492 arm->SetEnd(
toKi( b.
x - dx, b.
y - dy ) );
1494 shapes.push_back( std::move( arm ) );
1532 if( size.
x == size.
y )
1539 bool wide = size.
x > size.
y;
1543 int anchor = std::min( size.
x, size.
y );
1555 const std::string* prop = b.
FindProp(
"POLY_PAD" );
1556 std::vector<VECTOR2I> pts = prop ? parsePolyPad( *prop ) : std::vector<VECTOR2I>();
1558 if( pts.size() >= 3 )
1560 std::vector<VECTOR2I> local;
1563 local.emplace_back( pt.x, -pt.y );
1595 if(
const std::string* prop = b.
FindProp(
"RECT_ROUNDED" ) )
1596 wxString( *prop ).ToLong( &rounded );
1614 bool hasHole = src.
drill > 0;
1620 if(
const std::string* slot = b.
FindProp(
"SLOT_HOLE" ) )
1624 if( wxString( *slot ).ToLong( &length ) && length > src.
drill )
1639 pad->SetLayerSet( *padstack );
1647 pad->DeletePrimitivesList();
1655 pad->SetLayerSet( *padstack );
1661 LSET layers( { side } );
1665 else if( side ==
B_Cu )
1669 pad->SetLayerSet( layers );
1697 || ( f != LAYER_FUNCTION::DELETION_BOTTOM && f != LAYER_FUNCTION::DELETION_INSIDE
1698 && f != LAYER_FUNCTION::DELETION_TOP ) )
1714 const std::vector<TARGET3001::PADSTACK_DEF>& padstacks =
m_project.settings.padstacks;
1717 if( aLayer < TARGET3001::FIRST_PADSTACK_LAYER || index >= padstacks.size() )
1718 return std::nullopt;
1724 if( !padstacks[
index].onLayer[layer] )
1727 std::optional<PCB_LAYER_ID> mapped =
mapLayer( layer );
1732 layers.
set( *mapped );
1746 bool slotted = b.
FindProp(
"SLOT_HOLE" ) !=
nullptr;
1754 || ( padstack && ( *padstack & allCopper ) != allCopper ) )
1756 addPad( aElem,
nullptr );
1787 m_fonts.Apply( aText, aElem, 1 );
1795 if( std::optional<std::pair<int32_t, int32_t>>
end = b.
TextRightEnd() )
1812 if( aFootprint && t.
function == uint8_t( TEXT_FUNCTION::REFERENCE ) )
1819 if( aFootprint && t.
function == uint8_t( TEXT_FUNCTION::VALUE ) )
constexpr int ARC_HIGH_DEF
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
BASE_SET & set(size_t pos)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
constexpr coord_type GetY() const
constexpr size_type GetWidth() const
constexpr coord_type GetX() const
constexpr size_type GetHeight() const
void SetCustomProperty(const wxString &aKey, const wxString &aValue)
virtual void SetFilled(bool aFlag)
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
virtual void SetTextPos(const VECTOR2I &aPoint)
void SetMirrored(bool isMirrored)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Handle the data for a net.
const wxString & GetNetname() const
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
static LSET PTHMask()
layer set for a through hole pad
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
void SetMid(const VECTOR2I &aMid)
void SetCenter(const VECTOR2I &aCenter) override
void SetBezierC1(const VECTOR2I &aPt) override
void SetEnd(const VECTOR2I &aEnd) override
void SetPolyShape(const SHAPE_POLY_SET &aShape) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetBezierC2(const VECTOR2I &aPt) override
void SetStroke(const STROKE_PARAMS &aStroke) override
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) override
Set the three controlling points for an arc.
VECTOR2I GetTextPos() const override
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
void SetTextAngle(const EDA_ANGLE &aAngle) override
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
virtual void SetWidth(int aWidth)
A pure virtual class used to derive REPORTER objects from.
SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError) const
Build a polyline approximation of the ellipse or arc.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
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)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
Simple container to manage line stroke parameters.
static VECTOR2I BaselineShift(const EDA_TEXT &aText)
Offset in text units that moves aText so the baseline-left point of its first glyph lies on its posit...
TARGET3001::LAYER_FUNCTION LayerFunction(int aLayer) const
Function of a TARGET 3001! board layer in this project.
const TARGET3001::PROJECT & m_project
std::map< uint16_t, NETINFO_ITEM * > m_nets
by signal ID
std::vector< POUR_AREA > m_pourAreas
void addShape(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent, FOOTPRINT *aFootprint, bool aIsTrack, PCB_LAYER_ID aLayer)
Add the graphic or track form of aElem on one KiCad layer.
void addVia(const TARGET3001::ELEMENT &aElem)
std::map< int, SHAPE_POLY_SET > m_pourKeepouts
KiCad layer -> pour keepout.
void addFootprint(const TARGET3001::ELEMENT &aComponent)
std::vector< int > m_copperStack
TARGET layers, top to bottom.
void addItem(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent, FOOTPRINT *aFootprint, bool aIsTrack)
Add one board element to aParent; footprint items are passed with their footprint.
void buildAreaSpokes(const std::vector< const TARGET3001::ELEMENT * > &aSpokes)
Turn the spokes an old style area stores into thermal reliefs on the pads they start in.
std::vector< std::unique_ptr< PCB_SHAPE > > fiducialShapes(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent) const
Strokes and discs that draw a fiducial mark, not yet assigned a layer.
std::vector< std::pair< ZONE *, int64_t > > m_polygonZones
thermal polygon zones and their POLYGONID
std::optional< PCB_LAYER_ID > pourCopperLayer(int aLayer) const
Copper layer that an area or deletion layer applies to.
void buildAreaClearanceRules()
Clearance rules between copper areas and each signal's tracks and vias.
bool isCopper(int aLayer) const
NETINFO_ITEM * net(uint16_t aSignal) const
void addPad(const TARGET3001::ELEMENT &aElem, FOOTPRINT *aFootprint)
bool elementOutline(const TARGET3001::ELEMENT &aElem, SHAPE_POLY_SET &aOut) const
Outline of a filled element (rectangle, triangle, disc, stroked line or arc) in KiCad coordinates.
void buildAuraRules()
Rules that keep areas the aura distance from pads and vias, except on their NO_AURA layers.
std::set< std::pair< uint16_t, PCB_LAYER_ID > > m_pourLayers
(signal, KiCad layer) holding an area
std::map< int64_t, SHAPE_POLY_SET > m_polygonSpokes
POLYGONID -> stored thermal spokes.
std::map< std::pair< int, int >, SHAPE_POLY_SET > m_copperFills
(net, KiCad layer) -> filled copper
std::map< uint16_t, std::map< int, int > > m_signalClearances
Track and via clearances counted per signal, then per clearance value.
TARGET3001_PCB_BUILDER(BOARD *aBoard, const TARGET3001::PROJECT &aProject, REPORTER *aReporter)
void addPadstackCuts(const BOARD_ITEM &aItem, int aPadstack)
Cut aItem, grown per layer, from the pours of the deletion layers padstack aPadstack lists.
std::optional< PCB_LAYER_ID > polygonLayer(const TARGET3001::POLYGON_POUR &aPoly) const
Copper layer of a signal polygon that can become a zone.
std::optional< LSET > padstackLayers(int aLayer) const
Copper, mask and paste layers of the padstack a pad layer >= 101 selects.
void buildThermalGaps()
Thermal gaps the stored fill leaves around spoked pads, as zone defaults and pad or footprint overrid...
void addText(const TARGET3001::ELEMENT &aElem, BOARD_ITEM_CONTAINER *aParent, FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer)
void tagAura(BOARD_CONNECTED_ITEM &aItem, const TARGET3001::ELEMENT_BASE &aBase, int aAura)
Tag a pad or via with its aura so the aura rules can match it.
void buildPolygonRules()
Rules for the board contour and foreign polygon distances each signal polygon keeps.
std::set< int > m_auraValues
distinct aura distances above zero
std::map< int64_t, SHAPE_POLY_SET > m_polygonFills
POLYGONID -> stored fill without spokes.
TARGET3001::FONTS m_fonts
std::set< int > m_polygonEdgeClearances
void noteContour(const TARGET3001::ELEMENT &aElem)
Record whether a board contour stroke carries a clearance.
void configureText(PCB_TEXT *aText, const TARGET3001::ELEMENT &aElem, PCB_LAYER_ID aLayer)
VECTOR2I toKi(int32_t aX, int32_t aY) const
std::set< PCB_LAYER_ID > m_noAuraLayers
copper layers some NO_AURA list names
std::optional< int > m_contourLayer
first TARGET layer holding the contour
std::optional< PCB_LAYER_ID > mapLayer(int aLayer) const
Copper or graphic layer for a board element, if KiCad has a place for it.
std::map< int, PCB_LAYER_ID > m_layerMap
bool m_contourCarvesNothing
a contour stroke has no clearance
std::set< int > m_polygonAuras
Handle a list of polygons defining a copper zone.
void SetNeedRefill(bool aNeedRefill)
void SetDoNotAllowPads(bool aEnable)
void SetLocalClearance(std::optional< int > aClearance)
void SetMinThickness(int aMinThickness)
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
SHAPE_POLY_SET * Outline()
void SetIsRuleArea(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
void SetIsFilled(bool isFilled)
void SetDoNotAllowVias(bool aEnable)
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowZoneFills(bool aEnable)
void SetAssignedPriority(unsigned aPriority)
void SetPadConnection(ZONE_CONNECTION aPadConnection)
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
void TransformRingToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
PCB_LAYER_ID BoardLayerFromLegacyId(int aLegacyId)
Retrieve a layer ID from an integer converted from a legacy (pre-V9) enum value.
bool IsSolderMaskLayer(int aLayer)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
LAYER_FUNCTION
Board layer function codes stored per layer in the project header.
constexpr int FIRST_PADSTACK_LAYER
A pad on board layer FIRST_PADSTACK_LAYER + n takes its layers from project padstack n.
wxString PadNumber(const ELEMENT &aPad)
Number of a pad element in KiCad, its PADNAME when present, else its stored number.
constexpr int ALL_COPPER_LAYER
Board elements on this layer exist on every copper layer.
@ POLYGON
vertices in the POLY_PAD property
@ CROSSHAIR_RINGS
cross and rings at 1, 2/3 and 1/3 of the outer centreline radius
@ FILLED_CIRCLE
solid disc of the outer radius
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
ELEMENT_TYPE
Element class tags as stored in the file.
constexpr int BOARD_LAYER_COUNT
Board layers 0..99 carry a per-project function; 100 and above have fixed meanings.
constexpr uint8_t NO_ASSOCIATION
Layer association value for a layer that belongs to no copper layer.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
LINE_STYLE
Dashed line types.
Stroked arc or circle. The base position is the start point.
double Sweep() const
Counter-clockwise sweep in (0, 360]; equal angles give a full circle.
float startAngle
degrees, counter-clockwise from +X
Fields shared by every drawable element.
std::optional< int64_t > PolygonId() const
ID of the signal polygon whose stored fill this element is part of, if any.
bool FlagProp(const std::string &aKey) const
True when property aKey holds one of the format's boolean true words.
uint16_t signal
ID of the owning signal (a signal stores its own), 0 for none.
std::optional< std::pair< int32_t, int32_t > > TextRightEnd() const
Right end of right-aligned text from its ARXY property, in file coordinates.
const std::string * FindProp(const std::string &aKey) const
Return the value of the first property named aKey, if any.
One element of any class.
std::shared_ptr< COMPONENT > component
std::shared_ptr< SIGNAL > signal
std::shared_ptr< PACKAGE > package
uint8_t kind
FIDUCIAL_KIND.
uint8_t dashStyle
0 solid, 1 long dash, 2 dash-dot, 3 other, 4 short dash
Footprint placement. Pads and graphics of the footprint are stored in board coordinates.
Project padstack; the board layers a pad exists on and how far it grows on each.
std::array< bool, BOARD_LAYER_COUNT > onLayer
std::array< int32_t, BOARD_LAYER_COUNT > oversize
growth per side, nm
int32_t width
along the pad's own X axis before rotation
int32_t drill
0 for no hole
Copper polygon of a signal, stored in a "$%&POLY" signal property.
int32_t rank
a polygon is cut out of every one of lower rank on its layer
std::vector< std::pair< int32_t, int32_t > > outline
closed, first vertex repeated last
int32_t aura
distance kept from other signals' polygons, 0 for the default
int32_t edgeClearance
distance kept from the board contour, 0 for none
int32_t width
fill stroke width, 0 for the board default
bool thermals
own pads join by spokes rather than solidly
Filled rectangle anchored at a corner (the base position); sizes are signed.
Quadratic Bezier from the base position to the end point.
Filled triangle given by three absolute corners (the first is the base position).
constexpr int ALL_COPPER_LAYER
Board elements on this layer exist on every copper layer.
constexpr int BOARD_LAYER_COUNT
Board layers 0..99 carry a per-project function; 100 and above have fixed meanings.
static wxString ruleLiteral(const wxString &aValue)
An expression string literal, whose only escape is \', inside a quoted rules file string.
constexpr uint8_t NO_ASSOCIATION
Layer association value for a layer that belongs to no copper layer.
static wxString ruleMm(int aValue)
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
KIBIS top(path, &reporter)
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
static double sweep(float aStart, float aEnd)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
double DEG2RAD(double deg)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
@ THERMAL
Use thermal relief for pads.
@ FULL
pads are covered by copper