68#include <wx/numformatter.h>
73#include <wx/xml/xml.h>
95 static_cast<int>( aDrill.end ), aDrill.size.x, aDrill.size.y,
96 static_cast<int>( aDrill.shape ), aDrill.is_capped.has_value(),
97 aDrill.is_capped.value_or(
false ), aDrill.is_filled.has_value(),
98 aDrill.is_filled.value_or(
false ) );
101 auto mixPostMachining =
107 aPost.size, aPost.depth, aPost.angle );
220 std::vector<FOOTPRINT*> retval;
223 retval.push_back(
static_cast<FOOTPRINT*
>( fp->Clone() ) );
233 if( aParent->GetChildren() )
234 aNode->SetNext( aParent->GetChildren() );
236 aNode->SetNext(
nullptr );
238 aParent->SetChildren( aNode );
239 aNode->SetParent( aParent );
250 aNode->SetNext( aPrev->GetNext() );
251 aPrev->SetNext( aNode );
252 aNode->SetParent( aPrev->GetParent() );
273 check = check->GetParent();
277 if( aNode->GetParent() )
278 aNode->GetParent()->RemoveChild( aNode );
289 wxXmlNode* node =
new wxXmlNode( wxXML_ELEMENT_NODE, aName );
304 aNode->SetParent( aParent );
309 aParent->AddChild( aNode );
321 wxXmlNode* node =
new wxXmlNode( wxXML_ELEMENT_NODE, aName );
335 str.Replace( wxT(
":" ), wxT(
"_" ) );
339 for( wxString::const_iterator iter = aStr.begin(); iter != aStr.end(); ++iter )
356 wxString key = aPrefix ? wxString( aPrefix ) + wxT(
":" ) + aStr : aStr;
366 wxString
name = base;
369 wxString prefix = aPrefix ? wxString( aPrefix ) : wxString();
370 bool ownSet = prefix == wxS(
"CMP" ) || prefix == wxS(
"REF" );
371 std::set<wxString>& names =
m_element_names[ownSet ? prefix : wxString()];
373 while( names.count(
name ) )
374 name = wxString::Format(
"%s_%d", base, suffix++ );
376 names.insert(
name );
405 if( aSublayerId > 0 )
406 name += wxString::Format(
"_%d", aSublayerId );
414 return genString( wxString::Format( wxS(
"%s_%s" ),
416 m_board->GetLayerName( aBottom ) ), aPrefix );
445 [&](
const wxString& aName )
480 wxString baseName =
genString( ref,
"CMP" );
481 wxString
name = baseName;
484 while( !tryInsert(
name ) )
485 name = wxString::Format(
"%s_%d", baseName, suffix++ );
516 aNode->AddAttribute( aName, aValue );
522 wxXmlNode* xmlHeaderNode =
new wxXmlNode(wxXML_ELEMENT_NODE,
"IPC-2581");
524 addAttribute( xmlHeaderNode,
"xmlns",
"http://webstds.ipc.org/2581");
525 addAttribute( xmlHeaderNode,
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
526 addAttribute( xmlHeaderNode,
"xmlns:xsd",
"http://www.w3.org/2001/XMLSchema");
531 "http://webstds.ipc.org/2581 http://webstds.ipc.org/2581/IPC-2581B1.xsd" );
536 "http://webstds.ipc.org/2581 http://webstds.ipc.org/2581/IPC-2581C.xsd" );
541 return xmlHeaderNode;
553 wxXmlNode* node =
appendNode( contentNode,
"FunctionMode" );
567 wxFileName fn(
m_board->GetFileName() );
571 wxXmlNode* color_node =
included( IPC2581::SECTION::STACKUP )
573 :
new wxXmlNode( wxXML_ELEMENT_NODE,
"DictionaryColor" );
577 contentNode->AddChild( color_node );
581 wxXmlNode* fillNode =
appendNode( contentNode,
"DictionaryFillDesc" );
601 contentNode->AddChild( color_node );
610 wxXmlNode* location_node =
appendNode( aNode,
"Location" );
626 if( offset.
x != 0 || offset.
y != 0 )
678 wxXmlNode* color_node =
new wxXmlNode( wxXML_ELEMENT_NODE,
"DictionaryColor" );
682 for(
int sub_idx = 0; sub_idx < item->GetSublayersCount(); sub_idx++ )
692 wxXmlNode* entry_color =
appendNode( color_node,
"EntryColor" );
694 wxXmlNode* color =
appendNode( entry_color,
"Color" );
696 wxString colorName = item->GetColor( sub_idx );
698 if( colorName.StartsWith( wxT(
"#" ) ) )
700 COLOR4D layer_color( colorName );
709 if( fab_color.GetName() == colorName )
711 KIGFX::COLOR4D fab_color_for_type = fab_color.GetColor( item->GetType() );
733 return it->second + aSuffix;
735 return wxS(
"NET_0" ) + aSuffix;
739 return genString( aNetname + aSuffix,
"NET" );
760 if( !aMessage.IsEmpty() )
784 return section &&
included( *section );
795 std::function<void( wxXmlNode* )> visit =
796 [&]( wxXmlNode* aNode )
798 for( wxXmlNode* child = aNode->GetChildren(); child; child = child->GetNext() )
800 const wxString&
name = child->GetName();
802 if(
name ==
"Layer" )
805 child->GetAttribute(
"layerFunction" ),
806 child->GetAttribute(
"side" ) );
809 sections.
Set( *section );
811 else if(
name ==
"Bom" )
812 sections.
Set( IPC2581::SECTION::BOM_AVL );
813 else if(
name ==
"PadStackDef" )
814 sections.
Set( IPC2581::SECTION::PADSTACKS );
815 else if(
name ==
"Package" )
816 sections.
Set( IPC2581::SECTION::PACKAGES );
817 else if(
name ==
"Component" )
818 sections.
Set( IPC2581::SECTION::COMPONENTS );
819 else if(
name ==
"Stackup" )
820 sections.
Set( IPC2581::SECTION::STACKUP );
821 else if(
name ==
"Profile" )
822 sections.
Set( IPC2581::SECTION::PROFILE );
823 else if(
name ==
"LogicalNet" )
824 sections.
Set( IPC2581::SECTION::LOGICAL_NET );
825 else if(
name ==
"PhyNetGroup" )
826 sections.
Set( IPC2581::SECTION::PHYSICAL_NET );
827 else if(
name ==
"Dfx" )
828 sections.
Set( IPC2581::SECTION::DFX );
849 wxXmlNode*
next = child->GetNext();
851 if( child->GetName() ==
"StepRef" )
864 wxXmlNode* insertBefore =
nullptr;
866 for( wxXmlNode* child =
m_contentNode->GetChildren(); child; child = child->GetNext() )
868 if( child->GetName().StartsWith(
"Dictionary" ) )
870 insertBefore = child;
875 for( wxXmlNode* layer = aCadDataNode->GetChildren(); layer; layer = layer->GetNext() )
877 if( layer->GetName() !=
"Layer" )
880 wxXmlNode* ref =
new wxXmlNode( wxXML_ELEMENT_NODE,
"LayerRef" );
881 addAttribute( ref,
"name", layer->GetAttribute(
"name" ) );
899 wxXmlNode* fillDesc_node =
appendNode( aNode,
"FillDesc" );
905 wxXmlNode* fillDesc_node =
appendNode( aNode,
"FillDesc" );
906 addAttribute( fillDesc_node,
"fillProperty",
"HOLLOW" );
913 wxCHECK_RET( aNode,
"aNode is null" );
918 wxXmlNode* entry_node =
nullptr;
922 size_t hash =
lineHash( aWidth, aDashType );
923 wxString
name = wxString::Format(
"LINE_%zu",
m_line_dict.size() + 1 );
927 wxXmlNode* lineDesc_node =
appendNode( aNode,
"LineDescRef" );
942 wxXmlNode* line_node =
appendNode( entry_node,
"LineDesc" );
966 if( outlineCount == 0 )
973 if( outlineCount == 1 )
979 wxXmlNode* special_node =
appendNode( aContentNode,
"UserSpecial" );
981 for(
int ii = 0; ii < outlineCount; ++ii )
996 wxXmlNode* text_node =
appendNode( aContentNode,
"UserSpecial" );
998 std::list<VECTOR2I> pts;
1003 if( pts.size() < 2 )
1006 wxXmlNode* line_node =
nullptr;
1010 if( pts.size() < 3 )
1013 addXY( line_node, pts.front(),
"startX",
"startY" );
1014 addXY( line_node, pts.back(),
"endX",
"endY" );
1018 line_node =
appendNode( text_node,
"Polyline" );
1019 wxXmlNode* point_node =
appendNode( line_node,
"PolyBegin" );
1020 addXY( point_node, pts.front() );
1022 auto iter = pts.begin();
1024 for( ++iter; iter != pts.end(); ++iter )
1026 wxXmlNode* step_node =
appendNode( line_node,
"PolyStepSegment" );
1027 addXY( step_node, *iter );
1041 if( aPt1 == pts.back() )
1042 pts.push_back( aPt2 );
1043 else if( aPt2 == pts.front() )
1044 pts.push_front( aPt1 );
1045 else if( aPt1 == pts.front() )
1046 pts.push_front( aPt2 );
1047 else if( aPt2 == pts.back() )
1048 pts.push_back( aPt1 );
1052 pts.push_back( aPt1 );
1053 pts.push_back( aPt2 );
1058 pts.push_back( aPt1 );
1059 pts.push_back( aPt2 );
1065 if( aPoly.PointCount() < 3 )
1068 wxXmlNode* outline_node =
appendNode( text_node,
"Outline" );
1069 wxXmlNode* poly_node =
appendNode( outline_node,
"Polygon" );
1072 const std::vector<VECTOR2I>& polyPts = aPoly.CPoints();
1073 wxXmlNode* point_node =
appendNode( poly_node,
"PolyBegin" );
1074 addXY( point_node, polyPts.front() );
1076 for(
size_t ii = 1; ii < polyPts.size(); ++ii )
1078 wxXmlNode* poly_step_node =
appendNode( poly_node,
"PolyStepSegment" );
1079 addXY( poly_step_node, polyPts[ii] );
1082 point_node =
appendNode( poly_node,
"PolyStepSegment" );
1083 addXY( point_node, polyPts.front() );
1093 if( text_node->GetChildren() ==
nullptr )
1095 aContentNode->RemoveChild( text_node );
1103 int maxError =
m_board->GetDesignSettings().m_MaxError;
1119 wxXmlNode* shape_node =
appendNode( aContentNode,
"StandardPrimitiveRef" );
1125 const PAD& resolved = geometry.
Pad();
1137 int diameter = resolved.
GetSize( aLayer ).
x;
1139 wxXmlNode* circle_node =
appendNode( entry_node,
"Circle" );
1159 wxXmlNode* rect_node =
appendNode( entry_node,
"RectRound" );
1170 wxXmlNode* rect_node =
appendNode( entry_node,
"RectCenter" );
1188 wxXmlNode* oval_node =
appendNode( entry_node,
"Oval" );
1206 wxXmlNode* roundrect_node =
appendNode( entry_node,
"RectRound" );
1226 if( margin.
x <= 0 || margin.
x != margin.
y )
1233 wxXmlNode* chamfered_node =
appendNode( entry_node,
"RectCham" );
1237 int shorterSide = std::min( pad_size.
x, pad_size.
y );
1294 wxXmlNode* shape_node =
appendNode( aContentNode,
"StandardPrimitiveRef" );
1309 wxXmlNode* shape_node =
appendNode( aContentNode,
"UserPrimitiveRef" );
1326 wxXmlNode* polyline_node =
appendNode( aContentNode,
"Polyline" );
1334 wxXmlNode* begin_node =
appendNode( polyline_node,
"PolyBegin" );
1335 addXY( begin_node, start );
1338 wxXmlNode* arc1_node =
appendNode( polyline_node,
"PolyStepCurve" );
1339 addXY( arc1_node, mid );
1344 wxXmlNode* arc2_node =
appendNode( polyline_node,
"PolyStepCurve" );
1345 addXY( arc2_node, start );
1364 wxXmlNode* special_node =
appendNode( entry_node,
"UserSpecial" );
1366 wxXmlNode* circle_node =
appendNode( special_node,
"Circle" );
1392 wxXmlNode* polyline_node =
appendNode( aContentNode,
"Polyline" );
1397 wxXmlNode* begin_node =
appendNode( polyline_node,
"PolyBegin" );
1398 addXY( begin_node, corners[0] );
1400 for(
size_t i = 1; i < corners.size(); ++i )
1402 wxXmlNode* step_node =
appendNode( polyline_node,
"PolyStepSegment" );
1403 addXY( step_node, corners[i] );
1407 wxXmlNode* close_node =
appendNode( polyline_node,
"PolyStepSegment" );
1408 addXY( close_node, corners[0] );
1410 addLineDesc( polyline_node, stroke_width, dash,
true );
1420 wxXmlNode* special_node =
appendNode( entry_node,
"UserSpecial" );
1431 width += stroke_width;
1432 height += stroke_width;
1433 radius += stroke_width / 2;
1438 wxXmlNode* rect_node =
appendNode( special_node,
radius > 0 ?
"RectRound" :
"RectCenter" );
1476 wxXmlNode* polyline_node =
appendNode( aContentNode,
"Polyline" );
1477 const std::vector<VECTOR2I>& pts = outline.
CPoints();
1479 wxXmlNode* begin_node =
appendNode( polyline_node,
"PolyBegin" );
1480 addXY( begin_node, pts[0] );
1482 for(
size_t jj = 1; jj < pts.size(); ++jj )
1484 wxXmlNode* step_node =
appendNode( polyline_node,
"PolyStepSegment" );
1485 addXY( step_node, pts[jj] );
1489 if( pts.size() > 2 && pts.front() != pts.back() )
1491 wxXmlNode* close_node =
appendNode( polyline_node,
"PolyStepSegment" );
1492 addXY( close_node, pts[0] );
1495 addLineDesc( polyline_node, stroke_width, dash,
true );
1509 wxXmlNode* special_node =
appendNode( entry_node,
"UserSpecial" );
1530 wxXmlNode* arc_node =
appendNode( aContentNode,
"Arc" );
1532 addXY( arc_node, aShape.
GetEnd(),
"endX",
"endY" );
1545 wxXmlNode* polyline_node =
appendNode( aContentNode,
"Polyline" );
1549 std::vector<VECTOR2I> points;
1553 wxXmlNode* point_node =
appendNode( polyline_node,
"PolyBegin" );
1554 addXY( point_node, points[0] );
1556 for(
size_t i = 1; i < points.size(); i++ )
1558 wxXmlNode* seg_node =
appendNode( polyline_node,
"PolyStepSegment" );
1559 addXY( seg_node, points[i] );
1569 wxXmlNode* line_node =
appendNode( aContentNode,
"Line" );
1571 addXY( line_node, aShape.
GetEnd(),
"endX",
"endY" );
1597 if(
chain.PointCount() < 2 )
1600 wxXmlNode* polyline_node =
appendNode( aContentNode,
"Polyline" );
1601 const std::vector<VECTOR2I>& pts =
chain.CPoints();
1603 wxXmlNode* begin_node =
appendNode( polyline_node,
"PolyBegin" );
1604 addXY( begin_node, pts[0] );
1606 for(
size_t jj = 1; jj < pts.size(); ++jj )
1608 wxXmlNode* step_node =
appendNode( polyline_node,
"PolyStepSegment" );
1609 addXY( step_node, pts[jj] );
1613 if( !isArc && pts.size() > 2 && pts.front() != pts.back() )
1615 wxXmlNode* close_node =
appendNode( polyline_node,
"PolyStepSegment" );
1616 addXY( close_node, pts[0] );
1619 addLineDesc( polyline_node, stroke_width, dash,
true );
1629 wxXmlNode* special_node =
appendNode( entry_node,
"UserSpecial" );
1654 if( !aInline && !
name.empty() )
1656 wxXmlNode* shape_node =
appendNode( aContentNode,
"UserPrimitiveRef" );
1665 wxXmlNode* slotNode =
appendNode( aNode,
"SlotCavity" );
1683 if( drill_size.
y > drill_size.
x )
1685 std::swap( drill_size.
x, drill_size.
y );
1686 rotation = ( rotation +
ANGLE_90 ).Normalize();
1692 wxXmlNode* xformNode =
appendNode( slotNode,
"Xform" );
1697 wxXmlNode* ovalNode =
appendNode( slotNode,
"Oval" );
1705 int maxError =
m_board->GetDesignSettings().m_MaxError;
1717 wxXmlNode* roleNode =
appendNode( logisticNode,
"Role" );
1725 wxXmlNode* personNode =
appendNode( logisticNode,
"Person" );
1727 addAttribute( personNode,
"enterpriseRef",
"UNKNOWN" );
1730 return logisticNode;
1740 addAttribute( historyNode,
"origination", wxDateTime::Now().FormatISOCombined() );
1742 addAttribute( historyNode,
"lastChange", wxDateTime::Now().FormatISOCombined() );
1744 wxXmlNode* fileRevisionNode =
appendNode( historyNode,
"FileRevision" );
1745 addAttribute( fileRevisionNode,
"fileRevisionId",
"1" );
1746 addAttribute( fileRevisionNode,
"comment",
"NO COMMENT" );
1749 wxXmlNode* softwarePackageNode =
appendNode( fileRevisionNode,
"SoftwarePackage" );
1752 addAttribute( softwarePackageNode,
"vendor",
"KiCad EDA" );
1754 wxXmlNode* certificationNode =
appendNode( softwarePackageNode,
"Certification" );
1755 addAttribute( certificationNode,
"certificationStatus",
"SELFTEST" );
1763 if( !
included( IPC2581::SECTION::BOM_AVL ) )
1780 m_refdes =
new std::vector<REFDES>();
1781 m_props =
new std::map<wxString, wxString>();
1792 wxString m_OEMDesignRef;
1796 wxString m_description;
1798 std::vector<REFDES>* m_refdes;
1799 std::map<wxString, wxString>*
m_props;
1802 std::set<std::unique_ptr<BOM_ENTRY>,
1803 std::function<bool(
const std::unique_ptr<BOM_ENTRY>&,
const std::unique_ptr<BOM_ENTRY>& )>> bom_entries(
1804 [](
const std::unique_ptr<BOM_ENTRY>& a,
const std::unique_ptr<BOM_ENTRY>& b )
1806 return a->m_OEMDesignRef < b->m_OEMDesignRef;
1812 std::unique_ptr<FOOTPRINT> fp(
static_cast<FOOTPRINT*
>( fp_it->Clone() ) );
1813 fp->SetParentGroup(
nullptr );
1814 fp->SetPosition( {0, 0} );
1815 fp->SetOrientation(
ANGLE_0 );
1818 if( fp->IsFlipped() )
1826 Report( wxString::Format(
_(
"Footprint %s not found in dictionary; BOM data may be incomplete." ),
1827 fp->GetFPID().GetLibItemName().wx_str() ),
1832 auto entry = std::make_unique<struct BOM_ENTRY>();
1838 entry->m_OEMDesignRef = it->second;
1842 Report( wxString::Format(
_(
"Component \"%s\" missing OEM reference; BOM entry will be skipped." ),
1843 fp->GetFPID().GetLibItemName().wx_str() ),
1847 entry->m_OEMDesignRef =
genString( entry->m_OEMDesignRef,
"REF" );
1849 entry->m_pads = fp->GetPadCount();
1854 entry->m_type =
"DOCUMENT";
1856 entry->m_type =
"ELECTRICAL";
1864 auto[ bom_iter, inserted ] = bom_entries.insert( std::move( entry ) );
1867 ( *bom_iter )->m_count++;
1871 refdes.m_pkg = iter->second;
1875 ( *bom_iter )->m_refdes->push_back( refdes );
1879 for(
PCB_FIELD* prop : fp_it->GetFields() )
1884 if( prop->IsMandatory() && !prop->IsValue() )
1887 ( *bom_iter )->m_props->emplace( prop->GetName(), row.
Field( prop->GetName() ) );
1891 if( bom_entries.empty() )
1894 wxFileName fn(
m_board->GetFileName() );
1896 wxXmlNode* bomNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"Bom" );
1897 m_xml_root->InsertChild( bomNode, aEcadNode );
1900 wxXmlNode* bomHeaderNode =
appendNode( bomNode,
"BomHeader" );
1903 if( bomRevision.IsEmpty() )
1904 bomRevision =
m_board->GetTitleBlock().GetRevision();
1906 if( bomRevision.IsEmpty() )
1907 bomRevision = wxS(
"1.0" );
1909 addAttribute( bomHeaderNode,
"revision", bomRevision );
1914 wxXmlNode* stepRefNode =
appendNode( bomHeaderNode,
"StepRef" );
1918 for(
const std::unique_ptr<BOM_ENTRY>& entry : bom_entries )
1920 wxXmlNode* bomEntryNode =
appendNode( bomNode,
"BomItem" );
1921 addAttribute( bomEntryNode,
"OEMDesignNumberRef", entry->m_OEMDesignRef );
1922 addAttribute( bomEntryNode,
"quantity", wxString::Format(
"%d", entry->m_count ) );
1923 addAttribute( bomEntryNode,
"pinCount", wxString::Format(
"%d", entry->m_pads ) );
1924 addAttribute( bomEntryNode,
"category", entry->m_type );
1926 if( !entry->m_description.IsEmpty() )
1927 addAttribute( bomEntryNode,
"description", entry->m_description );
1929 for(
const REFDES& refdes : *( entry->m_refdes ) )
1934 wxXmlNode* refdesNode =
appendNode( bomEntryNode,
"RefDes" );
1938 addAttribute( refdesNode,
"packageRef", refdes.m_pkg );
1940 addAttribute( refdesNode,
"populate", refdes.m_populate ?
"true" :
"false" );
1943 addAttribute( refdesNode,
"layerRef", refdes.m_layer );
1946 wxXmlNode* characteristicsNode =
appendNode( bomEntryNode,
"Characteristics" );
1947 addAttribute( characteristicsNode,
"category", entry->m_type );
1949 for(
const auto& [propName, propValue] : *( entry->m_props ) )
1951 wxXmlNode* textualDefNode =
appendNode( characteristicsNode,
"Textual" );
1952 addAttribute( textualDefNode,
"definitionSource",
"KICAD" );
1953 addAttribute( textualDefNode,
"textualCharacteristicName", propName );
1954 addAttribute( textualDefNode,
"textualCharacteristicValue", propValue );
1971 wxXmlNode* cadDataNode =
appendNode( ecadNode,
"CadData" );
1974 if(
included( IPC2581::SECTION::DRILL_ROUT ) )
1977 if(
included( IPC2581::SECTION::MISC_FAB ) )
1980 if(
included( IPC2581::SECTION::STACKUP ) )
1989 bool haveLayer =
false;
1991 for( wxXmlNode* child = cadDataNode->GetChildren(); child; child = child->GetNext() )
1993 if( child->GetName() ==
"Layer" )
2019 std::vector<BOARD_STACKUP_ITEM*> layers = stackup.
GetList();
2020 std::set<PCB_LAYER_ID> added_layers;
2022 for(
int i = 0; i < stackup.
GetCount(); i++ )
2026 for(
int sublayer_id = 0; sublayer_id < stackup_item->
GetSublayersCount(); sublayer_id++ )
2028 wxString ly_name =
stackupLayerName( stackup_item, sublayer_id,
"SPEC_LAYER" );
2030 wxXmlNode* specNode =
appendNode( aCadLayerNode,
"Spec" );
2032 wxXmlNode* generalNode =
appendNode( specNode,
"General" );
2034 wxXmlNode* propertyNode =
appendNode( generalNode,
"Property" );
2036 switch ( stackup_item->
GetType() )
2041 wxXmlNode* conductorNode =
appendNode( specNode,
"Conductor" );
2043 propertyNode =
appendNode( conductorNode,
"Property" );
2044 addAttribute( propertyNode,
"unit", wxT(
"SIEMENS/M" ) );
2045 addAttribute( propertyNode,
"value", wxT(
"5.959E7" ) );
2052 propertyNode =
appendNode( generalNode,
"Property" );
2053 addAttribute( propertyNode,
"text", wxString::Format(
"Type : %s",
2055 wxXmlNode* dielectricNode =
appendNode( specNode,
"Dielectric" );
2056 addAttribute( dielectricNode,
"type",
"DIELECTRIC_CONSTANT" );
2057 propertyNode =
appendNode( dielectricNode,
"Property" );
2059 dielectricNode =
appendNode( specNode,
"Dielectric" );
2060 addAttribute( dielectricNode,
"type",
"LOSS_TANGENT" );
2061 propertyNode =
appendNode( dielectricNode,
"Property" );
2068 propertyNode =
appendNode( generalNode,
"Property" );
2069 addAttribute( propertyNode,
"text", wxString::Format(
"Color : %s", stackup_item->
GetColor() ) );
2070 propertyNode =
appendNode( generalNode,
"Property" );
2077 propertyNode =
appendNode( generalNode,
"Property" );
2078 addAttribute( propertyNode,
"text", wxString::Format(
"Color : %s", stackup_item->
GetColor() ) );
2079 propertyNode =
appendNode( generalNode,
"Property" );
2083 if( stackup_item->
GetEpsilonR( sublayer_id ) > 1.0 )
2085 wxXmlNode* dielectricNode =
appendNode( specNode,
"Dielectric" );
2086 addAttribute( dielectricNode,
"type",
"DIELECTRIC_CONSTANT" );
2087 propertyNode =
appendNode( dielectricNode,
"Property" );
2094 wxXmlNode* dielectricNode =
appendNode( specNode,
"Dielectric" );
2095 addAttribute( dielectricNode,
"type",
"LOSS_TANGENT" );
2096 propertyNode =
appendNode( dielectricNode,
"Property" );
2116 wxXmlNode* specNode =
appendNode( aCadLayerNode,
"Spec" );
2119 wxXmlNode* surfaceFinishNode =
appendNode( specNode,
"SurfaceFinish" );
2131 wxXmlNode* cadHeaderNode =
appendNode( aEcadNode,
"CadHeader" );
2136 if(
included( IPC2581::SECTION::STACKUP ) ||
included( IPC2581::SECTION::DIELECTRIC ) )
2174 addAttribute( aNode,
"layerFunction",
"BOARD_OUTLINE" );
2209 : aLayer ==
B_Cu ?
"BOTTOM"
2232 &&
included( IPC2581::SECTION::MISC_FAB ) );
2234 wxXmlNode* stackupNode =
appendNode( aCadLayerNode,
"Stackup" );
2235 addAttribute( stackupNode,
"name",
"Primary_Stackup" );
2242 addAttribute( stackupNode,
"stackupStatus",
"PROPOSED" );
2244 wxXmlNode* stackupGroup =
appendNode( stackupNode,
"StackupGroup" );
2245 addAttribute( stackupGroup,
"name",
"Primary_Stackup_Group" );
2250 std::vector<BOARD_STACKUP_ITEM*> layers = stackup.
GetList();
2251 std::set<PCB_LAYER_ID> added_layers;
2254 for(
int i = 0; i < stackup.
GetCount(); i++ )
2258 for(
int sublayer_id = 0; sublayer_id < stackup_item->
GetSublayersCount(); sublayer_id++ )
2263 if( hasCoating && layer_id ==
F_Cu && sublayer_id == 0 )
2265 wxXmlNode* coatingLayer =
appendNode( stackupGroup,
"StackupLayer" );
2266 addAttribute( coatingLayer,
"layerOrGroupRef",
"COATING_TOP" );
2270 addAttribute( coatingLayer,
"sequence", wxString::Format(
"%d", sequence++ ) );
2272 wxXmlNode* specRefNode =
appendNode( coatingLayer,
"SpecRef" );
2280 wxXmlNode* stackupLayer =
appendNode( stackupGroup,
"StackupLayer" );
2281 wxString spec_name =
stackupLayerName( stackup_item, sublayer_id,
"SPEC_LAYER" );
2284 addAttribute( stackupLayer,
"layerOrGroupRef", ly_name );
2288 addAttribute( stackupLayer,
"sequence", wxString::Format(
"%d", sequence++ ) );
2290 wxXmlNode* specLayerNode =
appendNode( stackupLayer,
"SpecRef" );
2296 wxXmlNode* coatingLayer =
appendNode( stackupGroup,
"StackupLayer" );
2297 addAttribute( coatingLayer,
"layerOrGroupRef",
"COATING_BOTTOM" );
2301 addAttribute( coatingLayer,
"sequence", wxString::Format(
"%d", sequence++ ) );
2303 wxXmlNode* specRefNode =
appendNode( coatingLayer,
"SpecRef" );
2315 std::vector<BOARD_STACKUP_ITEM*> layers = stackup.
GetList();
2316 std::set<PCB_LAYER_ID> added_layers;
2318 for(
int i = 0; i < stackup.
GetCount(); i++ )
2322 for(
int sublayer_id = 0; sublayer_id < stackup_item->
GetSublayersCount(); sublayer_id++ )
2335 wxXmlNode* cadLayerNode =
appendNode( aCadLayerNode,
"Layer" );
2342 addAttribute( cadLayerNode,
"layerFunction",
"DIELCORE" );
2344 addAttribute( cadLayerNode,
"layerFunction",
"DIELPREG" );
2359 LSEQ layer_seq =
m_board->GetEnabledLayers().Seq();
2363 if( added_layers.find( layer ) != added_layers.end() || !
layerIncluded( layer ) )
2368 added_layers.insert( layer );
2369 wxXmlNode* cadLayerNode =
appendNode( aCadLayerNode,
"Layer" );
2382 wxXmlNode* topCoatingNode =
appendNode( aCadLayerNode,
"Layer" );
2384 addAttribute( topCoatingNode,
"layerFunction",
"COATINGCOND" );
2386 addAttribute( topCoatingNode,
"polarity",
"POSITIVE" );
2388 wxXmlNode* botCoatingNode =
appendNode( aCadLayerNode,
"Layer" );
2389 addAttribute( botCoatingNode,
"name",
"COATING_BOTTOM" );
2390 addAttribute( botCoatingNode,
"layerFunction",
"COATINGCOND" );
2392 addAttribute( botCoatingNode,
"polarity",
"POSITIVE" );
2402 if( layer.m_Span.m_IsBackdrill )
2417 wxXmlNode* drillNode =
appendNode( aCadLayerNode,
"Layer" );
2418 drillNode->AddAttribute(
"name",
genLayersString( span.TopLayer(), span.BottomLayer(),
"DRILL" ) );
2423 wxXmlNode* spanNode =
appendNode( drillNode,
"Span" );
2430 wxXmlNode* drillNode =
appendNode( aCadLayerNode,
"Layer" );
2431 drillNode->AddAttribute(
"name",
genLayersString( layers.first, layers.second,
"SLOT" ) );
2437 wxXmlNode* spanNode =
appendNode( drillNode,
"Span" );
2458 std::vector<std::tuple<auxLayerType, PCB_LAYER_ID, PCB_LAYER_ID>> new_layers;
2480 for( std::tuple<auxLayerType, PCB_LAYER_ID, PCB_LAYER_ID>& tuple : new_layers )
2486 bool add_node =
true;
2489 wxString layerFunction;
2492 switch( std::get<0>(layers) )
2496 layerFunction =
"COATINGNONCOND";
2500 layerFunction =
"HOLEFILL";
2504 layerFunction =
"COATINGNONCOND";
2508 layerFunction =
"HOLEFILL";
2512 layerFunction =
"COATINGCOND";
2520 if( add_node && !vec.empty() )
2522 wxXmlNode* node =
appendNode( aCadLayerNode,
"Layer" );
2536 const bool first_external = std::get<1>( layers ) ==
F_Cu || std::get<1>( layers ) ==
B_Cu;
2537 const bool second_external = std::get<2>( layers ) ==
F_Cu || std::get<2>( layers ) ==
B_Cu;
2539 if( first_external )
2541 if( second_external )
2548 if( second_external )
2554 wxXmlNode* spanNode =
appendNode( node,
"Span" );
2565 wxXmlNode* stepNode =
appendNode( aCadNode,
"Step" );
2567 wxFileName fn(
m_board->GetFileName() );
2573 wxXmlNode* datumNode =
appendNode( stepNode,
"Datum" );
2577 if(
included( IPC2581::SECTION::PROFILE ) )
2591 if(
included( IPC2581::SECTION::LOGICAL_NET ) )
2594 if(
included( IPC2581::SECTION::PHYSICAL_NET ) )
2605 wxXmlNode* padNode =
appendNode( aContentNode,
"Pad" );
2612 wxXmlNode* xformNode =
appendNode( padNode,
"Xform" );
2619 addShape( padNode, *aPad, aLayer );
2623 wxXmlNode* pinRefNode =
appendNode( padNode,
"PinRef" );
2638 wxXmlNode* padNode =
appendNode( aContentNode,
"Pad" );
2660 addAttribute( aPadNode,
"padstackDefRef", th_pair->second );
2664 if( !success || !
included( IPC2581::SECTION::PADSTACKS ) )
2667 wxXmlNode* padStackDefNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"PadStackDef" );
2692 wxXmlNode* padStackHoleNode =
appendNode( padStackDefNode,
"PadstackHoleDef" );
2693 padStackHoleNode->AddAttribute(
"name", wxString::Format(
"%s%d_%d",
2718 wxXmlNode* padStackPadDefNode =
appendNode( padStackDefNode,
"PadstackPadDef" );
2720 addAttribute( padStackPadDefNode,
"padUse",
"REGULAR" );
2728 addShape( padStackPadDefNode, shape );
2732 addShape( padStackPadDefNode, *aPad, layer );
2747 addAttribute( aContentNode,
"padstackDefRef", via_pair->second );
2751 if( !success || !
included( IPC2581::SECTION::PADSTACKS ) )
2754 wxXmlNode* padStackDefNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"PadStackDef" );
2765 wxXmlNode* padStackHoleNode =
appendNode( padStackDefNode,
"PadstackHoleDef" );
2768 addAttribute( padStackHoleNode,
"platingStatus",
"VIA" );
2777 [&](
PCB_LAYER_ID aLayer,
const PCB_VIA* aViaShape,
const wxString& aLayerRef,
bool aDrill ) ->
void
2782 shape.
SetEnd( {
KiROUND( aViaShape->GetDrillValue() / 2.0 ), 0 } );
2784 shape.
SetEnd( {
KiROUND( aViaShape->GetWidth( aLayer ) / 2.0 ), 0 } );
2786 wxXmlNode* padStackPadDefNode =
appendNode( padStackDefNode,
"PadstackPadDef" );
2787 addAttribute( padStackPadDefNode,
"layerRef", aLayerRef );
2788 addAttribute( padStackPadDefNode,
"padUse",
"REGULAR" );
2791 addShape( padStackPadDefNode, shape );
2802 if( !op || !
included( IPC2581::SECTION::MISC_FAB ) )
2822 addPadShape( layer, aVia,
genLayerString( layer,
"PLUGGING" ),
true );
2825 addPadShape( layer, aVia,
genLayerString( layer,
"COVERING" ),
false );
2828 addPadShape( layer, aVia,
genLayerString( layer,
"TENTING" ),
false );
2837 if( aCadUnits == wxT(
"MILLIMETER" ) )
2840 if( aCadUnits == wxT(
"MICRON" ) )
2841 return wxT(
"MICRON" );
2843 if( aCadUnits == wxT(
"INCH" ) )
2844 return wxT(
"INCH" );
2862 && ( aDrill.size.x > 0 || aDrill.size.y > 0 );
2878 && ( !layerHasRef( secondary.
start ) || !layerHasRef( secondary.
end ) ) )
2884 && ( !layerHasRef( tertiary.
start ) || !layerHasRef( tertiary.
end ) ) )
2891 LSEQ cuStack =
m_board->GetEnabledLayers().CuStack();
2912 wxXmlNode* bd =
appendNode( specNode,
"Backdrill" );
2916 addAttribute( p,
"layerOrGroupRef", startLayer->second );
2922 wxXmlNode* bd =
appendNode( specNode,
"Backdrill" );
2923 addAttribute( bd,
"type", wxT(
"MUST_NOT_CUT_LAYER" ) );
2926 addAttribute( p,
"layerOrGroupRef", mustNotCutEntry->second );
2939 if( dielectric > 0 )
2940 stubLength = dielectric / 2;
2944 wxXmlNode* bd =
appendNode( specNode,
"Backdrill" );
2959 wxString secondarySpec = createSpec( secondary, wxString::Format( wxT(
"BD_%dA" ), specIndex ) );
2960 wxString tertiarySpec = createSpec( tertiary, wxString::Format( wxT(
"BD_%dB" ), specIndex ) );
2962 if( secondarySpec.IsEmpty() && tertiarySpec.IsEmpty() )
2978 [&](
const wxString& aSpecName )
2980 if( aSpecName.IsEmpty() )
2983 wxXmlNode* specRefNode =
appendNode( aHoleNode,
"SpecRef" );
2988 for(
const wxString& specName : it->second )
3004 if( aMachining.
m_Size <= 0 || ( !countersink && !counterbore ) )
3007 auto key = std::make_tuple( aFront,
3008 static_cast<int>( aMachining.
m_Mode ),
3010 counterbore ? aMachining.
m_Depth : 0,
3011 countersink ? aMachining.
m_Angle : 0 );
3016 it->second = wxString::Format( countersink ? wxT(
"CSK_%zu" ) : wxT(
"CBORE_%zu" ),
3022 [&](
const wxString& aType,
const wxString& aValue,
const wxString& aUnit )
3024 wxXmlNode* drill =
appendNode( spec,
"SecondaryDrill" );
3026 wxXmlNode*
property =
appendNode( drill,
"Property" );
3034 if( counterbore && aMachining.
m_Depth > 0 )
3037 if( countersink && aMachining.
m_Angle > 0 )
3038 addValue( wxT(
"ANGLE" ),
floatVal( aMachining.
m_Angle / 10.0 ), wxT(
"DEGREES" ) );
3040 wxXmlNode* side =
appendNode( spec,
"SecondaryDrill" );
3042 wxXmlNode*
property =
appendNode( side,
"Property" );
3043 addAttribute( property,
"text", aFront ? wxT(
"TOP" ) : wxT(
"BOTTOM" ) );
3045 if( ( counterbore && aMachining.
m_Depth <= 0 ) || ( countersink && aMachining.
m_Angle <= 0 ) )
3047 wxXmlNode* other =
appendNode( spec,
"SecondaryDrill" );
3049 addAttribute( other,
"comment", counterbore ? wxT(
"COUNTERBORE" ) : wxT(
"COUNTERSINK" ) );
3053 wxXmlNode* ref =
appendNode( aHoleNode,
"SpecRef" );
3073 wxXmlNode* specNode = it->second;
3094 wxXmlNode* polygonNode =
nullptr;
3102 polygonNode =
appendNode( aParentNode,
"Polygon" );
3103 wxXmlNode* polybeginNode =
appendNode( polygonNode,
"PolyBegin" );
3105 const std::vector<VECTOR2I>& pts = aPolygon.
CPoints();
3106 addXY( polybeginNode, pts[0] );
3108 for(
size_t ii = 1; ii < pts.size(); ++ii )
3110 wxXmlNode* polyNode =
appendNode( polygonNode,
"PolyStepSegment" );
3111 addXY( polyNode, pts[ii] );
3114 wxXmlNode* polyendNode =
appendNode( polygonNode,
"PolyStepSegment" );
3115 addXY( polyendNode, pts[0] );
3126 addLineDesc( polygonNode, aWidth, aDashType,
true );
3130 wxCHECK( aWidth == 0,
false );
3142 for(
size_t ii = 1; ii < aPolygon.size(); ++ii )
3144 wxCHECK2( aPolygon[ii].PointCount() >= 3,
continue );
3146 wxXmlNode* cutoutNode =
appendNode( aParentNode,
"Cutout" );
3147 wxXmlNode* polybeginNode =
appendNode( cutoutNode,
"PolyBegin" );
3149 const std::vector<VECTOR2I>& hole = aPolygon[ii].CPoints();
3150 addXY( polybeginNode, hole[0] );
3152 for(
size_t jj = 1; jj < hole.size(); ++jj )
3154 wxXmlNode* polyNode =
appendNode( cutoutNode,
"PolyStepSegment" );
3155 addXY( polyNode, hole[jj] );
3158 wxXmlNode* polyendNode =
appendNode( cutoutNode,
"PolyStepSegment" );
3159 addXY( polyendNode, hole[0] );
3172 wxXmlNode* outlineNode =
appendNode( aParentNode,
"Outline" );
3186 for(
int ii = 0; ii <
source->OutlineCount(); ++ii )
3189 wxLogTrace(
traceIpc2581, wxS(
"Failed to add polygon to outline" ) );
3192 if( !outlineNode->GetChildren() )
3194 aParentNode->RemoveChild( outlineNode );
3211 wxXmlNode* contourNode =
appendNode( aParentNode,
"Contour" );
3221 aParentNode->RemoveChild( contourNode );
3234 if( !
m_board->GetBoardPolygonOutlines( board_outline,
false ) || board_outline.
OutlineCount() == 0 )
3240 wxXmlNode* profileNode =
appendNode( aStepNode,
"Profile" );
3244 wxLogTrace(
traceIpc2581, wxS(
"Failed to add polygon to profile" ) );
3245 aStepNode->RemoveChild( profileNode );
3271 std::unique_ptr<FOOTPRINT> fp(
static_cast<FOOTPRINT*
>( aFp->
Clone() ) );
3272 fp->SetParentGroup(
nullptr );
3273 fp->SetPosition( { 0, 0 } );
3274 fp->SetOrientation(
ANGLE_0 );
3279 bool wasFlipped = fp->IsFlipped();
3282 if( fp->IsFlipped() )
3287 fp->GetFPID().GetLibItemName().wx_str(),
3293 addAttribute( aContentNode,
"packageRef", iter->second );
3297 if( !success || !
included( IPC2581::SECTION::PACKAGES ) )
3302 wxXmlNode* packageNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"Package" );
3303 wxXmlNode* otherSideViewNode =
nullptr;
3309 if( fp->FindPadByNumber(
"1" ) )
3311 else if ( fp->FindPadByNumber(
"A1" ) )
3313 else if ( fp->FindPadByNumber(
"A" ) )
3315 else if ( fp->FindPadByNumber(
"a" ) )
3317 else if ( fp->FindPadByNumber(
"a1" ) )
3319 else if ( fp->FindPadByNumber(
"Anode" ) )
3321 else if ( fp->FindPadByNumber(
"ANODE" ) )
3328 PAD* pinOnePad = fp->FindPadByNumber(
"1" );
3331 pinOnePad = fp->FindPadByNumber(
"A1" );
3333 if( pinOnePad && fp->Pads().size() >= 2 )
3336 BOX2I fpBBox = fp->GetBoundingBox();
3348 if( onCenterX && onCenterY )
3350 else if( onCenterX && pinPos.
y <
center.y )
3352 else if( onCenterX && pinPos.
y >
center.y )
3354 else if( onCenterY && pinPos.
x <
center.x )
3356 else if( onCenterY && pinPos.
x >
center.x )
3371 addAttribute( packageNode,
"pinOneOrientation",
"OTHER" );
3372 addAttribute( packageNode,
"comment",
"Pin 1 orientation could not be determined" );
3378 : fp->GetCourtyard(
F_CrtYd );
3380 : fp->GetCourtyard(
B_CrtYd );
3396 otherSideViewNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"OtherSideView" );
3402 wxXmlNode* pickupPointNode =
appendNode( packageNode,
"PickupPoint" );
3406 std::map<PCB_LAYER_ID, std::map<bool, std::vector<BOARD_ITEM*>>> elements;
3408 for(
BOARD_ITEM* item : fp->GraphicalItems() )
3433 elements[item->GetLayer()][is_abs].push_back( item );
3436 auto add_base_node =
3439 wxXmlNode* parent = packageNode;
3448 bool is_other_side = wasFlipped ? ( aLayer ==
F_SilkS || aLayer ==
F_Fab )
3453 if( !otherSideViewNode )
3454 otherSideViewNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"OtherSideView" );
3456 parent = otherSideViewNode;
3463 else if( aLayer ==
F_Fab || aLayer ==
B_Fab )
3472 auto add_marking_node =
3473 [&]( wxXmlNode* aNode ) -> wxXmlNode*
3475 wxXmlNode* marking_node =
appendNode( aNode,
"Marking" );
3477 return marking_node;
3480 std::map<PCB_LAYER_ID, wxXmlNode*> layer_nodes;
3481 std::map<PCB_LAYER_ID, BOX2I> layer_bbox;
3485 if( elements.find( layer ) != elements.end() )
3487 if( elements[layer][
true].size() > 0 )
3488 layer_bbox[layer] = elements[layer][
true][0]->GetBoundingBox();
3489 else if( elements[layer][
false].size() > 0 )
3490 layer_bbox[layer] = elements[layer][
false][0]->GetBoundingBox();
3494 for(
auto& [layer, map] : elements )
3496 wxXmlNode* layer_node = add_base_node( layer );
3497 wxXmlNode* marking_node = add_marking_node( layer_node );
3498 wxXmlNode* group_node =
appendNode( marking_node,
"UserSpecial" );
3499 bool update_bbox =
false;
3503 layer_nodes[layer] = layer_node;
3507 for(
auto& [is_abs, vec] : map )
3511 wxXmlNode* output_node =
nullptr;
3514 layer_bbox[layer].Merge( item->GetBoundingBox() );
3517 output_node = add_marking_node( layer_node );
3519 output_node = group_node;
3521 switch( item->Type() )
3527 if(
text->IsKnockout() )
3541 if(
text->IsBorderEnabled() )
3544 text->GetEffectiveShape()->TransformToPolygon( poly_set, 0,
ERROR_INSIDE );
3568 if( group_node->GetChildren() ==
nullptr )
3570 marking_node->RemoveChild( group_node );
3571 layer_node->RemoveChild( marking_node );
3573 delete marking_node;
3577 for(
auto& [layer, bbox] : layer_bbox )
3579 if( bbox.GetWidth() > 0 )
3581 wxXmlNode* outlineNode =
insertNode( layer_nodes[layer],
"Outline" );
3584 std::vector<VECTOR2I> points( 4 );
3585 points[0] = bbox.GetPosition();
3586 points[2] = bbox.GetEnd();
3587 points[1].x = points[0].x;
3588 points[1].y = points[2].y;
3589 points[3].x = points[2].x;
3590 points[3].y = points[0].y;
3592 outline.
Append( points );
3598 std::map<wxString, wxXmlNode*> pin_nodes;
3600 for(
size_t ii = 0; ii < fp->Pads().size(); ++ii )
3602 PAD*
pad = fp->Pads()[ii];
3605 wxXmlNode* pinNode =
nullptr;
3607 auto [ it, inserted ] = pin_nodes.emplace( pin_name,
nullptr );
3612 it->second = pinNode;
3623 if(
pad->HasHole() )
3628 if(
pad->GetFPRelativeOrientation() !=
ANGLE_0 )
3630 wxXmlNode* xformNode =
appendNode( pinNode,
"Xform" );
3631 EDA_ANGLE pad_angle =
pad->GetFPRelativeOrientation().Normalize();
3633 if( fp->IsFlipped() )
3650 if( otherSideViewNode )
3651 packageNode->AddChild( otherSideViewNode );
3659 std::vector<wxXmlNode*> componentNodes;
3660 std::vector<wxXmlNode*> packageNodes;
3661 std::set<wxString> packageNames;
3663 bool generate_unique =
m_OEMRef.empty();
3675 wxXmlNode* componentNode =
new wxXmlNode( wxXML_ELEMENT_NODE,
"Component" );
3682 for(
PAD*
pad : fp->Pads() )
3684 if(
pad->GetNetCode() > 0 )
3688 wxXmlNode* pkg =
addPackage( componentNode, fp );
3691 packageNodes.push_back( pkg );
3695 if(
name.IsEmpty() )
3697 name = wxString::Format(
"%s_%s_%s",
3698 fp->GetFPID().GetFullLibraryName(),
3699 fp->GetFPID().GetLibItemName().wx_str(),
3705 Report(
_(
"Duplicate footprint pointers encountered; IPC-2581 output may be incorrect." ),
3719 if( fp->GetOrientation() !=
ANGLE_0 || fp->IsFlipped() )
3721 wxXmlNode* xformNode =
appendNode( componentNode,
"Xform" );
3725 if( fp->IsFlipped() )
3731 if( fp->IsFlipped() )
3735 addLocationNode( componentNode, fp->GetPosition().x, fp->GetPosition().y );
3737 componentNodes.push_back( componentNode );
3743 [&]( std::vector<wxXmlNode*>& aNodes,
IPC2581::SECTION aSection,
bool aInsert )
3747 for( wxXmlNode*& node : aNodes )
3760 aStepNode->AddChild( node );
3768 attachOrDrop(
m_padstacks, IPC2581::SECTION::PADSTACKS,
true );
3769 attachOrDrop( packageNodes, IPC2581::SECTION::PACKAGES,
false );
3770 attachOrDrop( componentNodes, IPC2581::SECTION::COMPONENTS,
false );
3780 wxXmlNode* netNode =
appendNode( aStepNode,
"LogicalNet" );
3783 for(
auto& [cmp,
pin] : pin_pair )
3785 wxXmlNode* netPinNode =
appendNode( netNode,
"PinRef" );
3804 wxString m_exposure;
3812 std::map<int, std::vector<NET_POINT>> byNet;
3825 bool frontOpen = !aPoint.m_front || aPoint.m_frontMask;
3826 bool backOpen = !aPoint.m_back || aPoint.m_backMask;
3828 if( frontOpen && backOpen )
3829 return wxT(
"EXPOSED" );
3832 return wxT(
"COVERED_PRIMARY" );
3835 return wxT(
"COVERED_SECONDARY" );
3837 return wxT(
"COVERED" );
3841 for(
bool wantPad : {
true,
false } )
3846 if( ( testPoint.m_pad !=
nullptr ) != wantPad
3847 || testPoint.m_netCode <= 0
3848 || ( !testPoint.m_front && !testPoint.m_back ) )
3854 point.m_pos = testPoint.m_position;
3855 point.m_layer = testPoint.m_front ?
F_Cu :
B_Cu;
3857 point.m_exposure = exposure( testPoint );
3858 point.m_end = testPoint.m_netEnd;
3859 point.m_via = testPoint.m_via !=
nullptr;
3860 point.m_width = testPoint.m_pad ? testPoint.m_pad->GetSize( point.m_layer ).x
3861 : testPoint.m_via->GetWidth( point.m_layer );
3862 point.m_drill = testPoint.m_drill;
3863 point.m_pad = testPoint.m_pad;
3864 byNet[testPoint.m_netCode].push_back( point );
3872 wxXmlNode* groupNode =
appendNode( aStepNode,
"PhyNetGroup" );
3875 for(
const auto& [netcode, points] : byNet )
3884 wxXmlNode* netNode =
appendNode( groupNode,
"PhyNet" );
3887 for(
const NET_POINT& point : points )
3889 wxXmlNode* pointNode =
appendNode( netNode,
"PhyNetPoint" );
3890 addXY( pointNode, point.m_pos );
3896 addAttribute( pointNode,
"netNode", point.m_end ?
"END" :
"MIDDLE" );
3897 addAttribute( pointNode,
"exposure", point.m_exposure );
3904 addShape( pointNode, *point.m_pad, point.m_layer );
3909 dummy.SetPosition( point.m_pos );
3910 dummy.SetSize( point.m_layer,
VECTOR2I( point.m_width, point.m_width ) );
3912 if( point.m_drill > 0 )
3913 dummy.SetDrillSize(
VECTOR2I( point.m_drill, point.m_drill ) );
3937 wxXmlNode* layerNode =
appendNode( aStepNode,
"LayerFeature" );
3945 auto netItems = netsOnLayer.find( net );
3947 if( netItems == netsOnLayer.end() || netItems->second.empty() )
3955 tickProgress( wxString::Format(
_(
"Exporting layer %s, net %s" ),
3956 m_board->GetLayerName( layer ),
3957 net->GetNetname() ) );
3959 process_net( net->GetNetCode() );
3962 if( layerNode->GetChildren() ==
nullptr )
3964 aStepNode->RemoveChild( layerNode );
3973 if( !
included( IPC2581::SECTION::DRILL_ROUT ) )
3980 wxXmlNode* layerNode =
appendNode( aLayerNode,
"LayerFeature" );
3981 layerNode->AddAttribute(
"layerRef",
genLayersString( span.TopLayer(), span.BottomLayer(),
"DRILL" ) );
4001 wxXmlNode* padNode =
appendNode( layerNode,
"Set" );
4004 if(
via->GetNetCode() > 0 )
4007 wxXmlNode* holeNode =
appendNode( padNode,
"Hole" );
4008 addAttribute( holeNode,
"name", wxString::Format(
"H%d", hole_count++ ) );
4013 addXY( holeNode,
via->GetPosition() );
4029 Report(
_(
"Pad uses unsupported padstack; hole was omitted from drill data." ),
4034 wxXmlNode* padNode =
appendNode( layerNode,
"Set" );
4037 if(
pad->GetNetCode() > 0 )
4040 wxXmlNode* holeNode =
appendNode( padNode,
"Hole" );
4041 addAttribute( holeNode,
"name", wxString::Format(
"H%d", hole_count++ ) );
4047 addXY( holeNode,
pad->GetPosition() );
4058 wxXmlNode* layerNode =
appendNode( aLayerNode,
"LayerFeature" );
4059 layerNode->AddAttribute(
"layerRef",
genLayersString( layers.first, layers.second,
"SLOT" ) );
4063 wxXmlNode* padNode =
appendNode( layerNode,
"Set" );
4065 if(
pad->GetNetCode() > 0 )
4068 addSlotCavity( padNode, *
pad, wxString::Format(
"SLOT%d", hole_count++ ) );
4071 DRILL_SPAN span( layers.first, layers.second,
false,
false );
4081 const std::vector<BOARD_ITEM*>& aItems )
4083 auto it = aItems.begin();
4084 wxXmlNode* layerSetNode =
appendNode( aLayerNode,
"Set" );
4085 wxXmlNode* featureSetNode =
appendNode( layerSetNode,
"Features" );
4086 wxXmlNode* specialNode =
appendNode( featureSetNode,
"UserSpecial" );
4088 bool has_via =
false;
4089 bool has_pad =
false;
4091 wxXmlNode* padSetNode =
nullptr;
4093 wxXmlNode* viaSetNode =
nullptr;
4095 wxXmlNode* teardropLayerSetNode =
nullptr;
4096 wxXmlNode* teardropFeatureSetNode =
nullptr;
4098 bool teardrop_warning =
false;
4103 if( item->GetNetCode() > 0 )
4113 shape.
SetStart( track->GetStart() );
4114 shape.
SetEnd( track->GetEnd() );
4135 shape.
SetStart( track->GetStart() );
4136 shape.
SetEnd( track->GetEnd() );
4147 viaSetNode = layerSetNode;
4152 viaSetNode =
appendNode( layerSetNode,
"Set" );
4154 if( track->GetNetCode() > 0 )
4161 addVia( viaSetNode,
static_cast<PCB_VIA*
>( track ), aLayer );
4168 wxXmlNode* zoneFeatureNode = specialNode;
4170 if( zone->IsTeardropArea() )
4174 if( !teardropFeatureSetNode )
4176 teardropLayerSetNode =
appendNode( aLayerNode,
"Set" );
4177 addAttribute( teardropLayerSetNode,
"geometryUsage",
"TEARDROP" );
4179 if( zone->GetNetCode() > 0 )
4182 wxXmlNode* new_teardrops =
appendNode( teardropLayerSetNode,
"Features" );
4184 teardropFeatureSetNode =
appendNode( new_teardrops,
"UserSpecial" );
4187 zoneFeatureNode = teardropFeatureSetNode;
4189 else if( !teardrop_warning )
4191 Report(
_(
"Teardrops are not supported in IPC-2581 revision B; they were exported as zones." ),
4193 teardrop_warning =
true;
4200 wxXmlNode* tempSetNode =
appendNode( aLayerNode,
"Set" );
4206 wxXmlNode* newFeatures =
appendNode( tempSetNode,
"Features" );
4208 zoneFeatureNode =
appendNode( newFeatures,
"UserSpecial" );
4212 SHAPE_POLY_SET& zone_shape = *zone->GetFilledPolysList( aLayer );
4214 for(
int ii = 0; ii < zone_shape.
OutlineCount(); ++ii )
4230 wxXmlNode* tempSetNode =
appendNode( aLayerNode,
"Set" );
4233 addAttribute( tempSetNode,
"geometryUsage",
"GRAPHIC" );
4235 bool link_to_component =
true;
4238 link_to_component =
false;
4240 if( link_to_component )
4246 wxXmlNode* tempFeature =
appendNode( tempSetNode,
"Features" );
4255 wxXmlNode* tempSetNode =
appendNode( aLayerNode,
"Set" );
4262 wxXmlNode* tempFeature =
appendNode( tempSetNode,
"Features" );
4279 text_item =
static_cast<EDA_TEXT*
>( pcb_text );
4281 text_item =
static_cast<EDA_TEXT*
>( pcb_textbox );
4283 if( !text_item || !text_item->
IsVisible() )
4288 if( content.empty() )
4291 bool isWhitespace = content.Strip( wxString::both ).empty();
4295 if( isWhitespace && !isKnockout && !hasBorder )
4298 wxXmlNode* tempSetNode =
appendNode( aLayerNode,
"Set" );
4303 bool link_to_component = fp !=
nullptr;
4306 link_to_component =
false;
4308 if( link_to_component )
4314 wxXmlNode* nonStandardAttributeNode =
appendNode( tempSetNode,
"NonstandardAttribute" );
4315 addAttribute( nonStandardAttributeNode,
"name",
"TEXT" );
4316 addAttribute( nonStandardAttributeNode,
"value", content );
4317 addAttribute( nonStandardAttributeNode,
"type",
"STRING" );
4319 if( !isWhitespace || isKnockout )
4321 wxXmlNode* glyphFeature =
appendNode( tempSetNode,
"Features" );
4327 addText( glyphFeature, text_item,
text->GetFontMetrics() );
4333 wxXmlNode* borderFeature =
appendNode( tempSetNode,
"Features" );
4336 addShape( borderFeature, *border );
4347 padSetNode = layerSetNode;
4352 padSetNode =
appendNode( aLayerNode,
"Set" );
4354 if(
pad->GetNetCode() > 0 )
4364 switch( item->Type() )
4369 add_track(
static_cast<PCB_TRACK*
>( item ) );
4377 add_pad(
static_cast<PAD*
>( item ) );
4381 add_shape(
static_cast<PCB_SHAPE*
>( item ) );
4406 if( specialNode->GetChildren() ==
nullptr )
4408 featureSetNode->RemoveChild( specialNode );
4412 if( featureSetNode->GetChildren() ==
nullptr )
4414 layerSetNode->RemoveChild( featureSetNode );
4418 if( layerSetNode->GetChildren() ==
nullptr )
4420 aLayerNode->RemoveChild( layerSetNode );
4427 if( !
included( IPC2581::SECTION::MISC_FAB ) )
4432 bool add_node =
true;
4438 switch( std::get<0>(layers) )
4467 wxXmlNode* layerNode =
appendNode( aStepNode,
"LayerFeature" );
4475 layerNode->AddAttribute(
"layerRef",
genLayersString( std::get<1>( layers ),
4479 wxXmlNode* setNode =
appendNode( layerNode,
"Set" );
4493 shape.
SetEnd( {
KiROUND(
via->GetWidth( std::get<1>( layers ) ) / 2.0 ), 0 } );
4495 wxXmlNode* padNode =
appendNode( setNode,
"Pad" );
4507 if( !
included( IPC2581::SECTION::BOM_AVL ) )
4520 wxXmlNode* header =
appendNode( avl,
"AvlHeader" );
4524 addAttribute( header,
"datetime", wxDateTime::Now().FormatISOCombined() );
4527 std::set<wxString> unique_parts;
4528 std::map<wxString,wxString> unique_vendors;
4529 std::vector<FOOTPRINT*> footprints;
4530 std::vector<AVL_ROW>
rows;
4539 footprints.push_back( fp );
4540 rows.push_back( { it->second, fp->GetReference() } );
4547 auto [ it, success ] = unique_parts.insert(
name );
4552 wxXmlNode* part =
appendNode( avl,
"AvlItem" );
4559 for (
int ii = 0; ii < 2; ++ii )
4565 if( mpn_name.empty() )
4568 wxXmlNode* vmpn =
appendNode( part,
"AvlVmpn" );
4572 wxXmlNode* mpn =
appendNode( vmpn,
"AvlMpn" );
4575 wxXmlNode* vendor =
appendNode( vmpn,
"AvlVendor" );
4577 wxString vendor_name = wxT(
"UNKNOWN" );
4580 if( !ii && company[ii] )
4588 else if( !ii && !company_name[ii].
empty() )
4590 vendor_name = company_name[ii];
4592 else if( ii && !
m_dist.empty() )
4597 auto [vendor_id, inserted] = unique_vendors.emplace( vendor_name,
4598 wxString::Format(
"VENDOR_%zu",
4599 unique_vendors.size() ) );
4601 addAttribute( vendor,
"enterpriseRef", vendor_id->second );
4605 wxXmlNode* new_vendor =
new wxXmlNode( wxXML_ELEMENT_NODE,
"Enterprise" );
4621 const std::map<std::string, UTF8>* aProperties )
4683 const std::map<std::string, UTF8> emptyProperties;
4686 aProperties = &emptyProperties;
4688 if(
auto it = aProperties->find(
"variant" ); it != aProperties->end() )
4691 if(
auto it = aProperties->find(
"units" ); it != aProperties->end() )
4693 if( it->second ==
"inch" )
4700 if(
auto it = aProperties->find(
"sigfig" ); it != aProperties->end() )
4701 m_sigfig = std::stoi( it->second );
4703 if(
auto it = aProperties->find(
"version" ); it != aProperties->end() )
4706 if(
auto it = aProperties->find(
"OEMRef" ); it != aProperties->end() )
4709 if(
auto it = aProperties->find(
"mpn" ); it != aProperties->end() )
4710 m_mpn = it->second.wx_str();
4712 if(
auto it = aProperties->find(
"mfg" ); it != aProperties->end() )
4713 m_mfg = it->second.wx_str();
4715 if(
auto it = aProperties->find(
"dist" ); it != aProperties->end() )
4716 m_dist = it->second.wx_str();
4718 if(
auto it = aProperties->find(
"distpn" ); it != aProperties->end() )
4721 if(
auto it = aProperties->find(
"bomrev" ); it != aProperties->end() )
4724 m_mode = IPC2581::MODE::USERDEF;
4727 if(
auto it = aProperties->find(
"mode" ); it != aProperties->end() )
4732 THROW_IO_ERROR( wxString::Format(
_(
"Unknown IPC-2581 data set '%s'." ), it->second.wx_str() ) );
4738 if(
auto it = aProperties->find(
"sections" ); it != aProperties->end() )
4741 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IPC-2581 section key '%s'." ), it->second.wx_str() ) );
4744 if(
auto it = aProperties->find(
"netnames" ); it != aProperties->end() )
4756 if(
auto it = aProperties->find(
"refdes" ); it != aProperties->end() )
4766 for(
char c =
'a'; c <=
'z'; ++c )
4769 for(
char c =
'A'; c <=
'Z'; ++c )
4772 for(
char c =
'0'; c <=
'9'; ++c )
4776 std::string specialChars =
"_\\-.+><";
4778 for(
char c : specialChars )
4789 if( !
included( IPC2581::SECTION::LOGICAL_NET ) )
4792 if( !
included( IPC2581::SECTION::PHYSICAL_NET ) )
4795 if( !
included( IPC2581::SECTION::BOM_AVL ) )
4816 wxXmlNode* insertBefore =
nullptr;
4818 for( wxXmlNode* child =
m_contentNode->GetChildren(); child; child = child->GetNext() )
4820 if( child->GetName().StartsWith(
"Dictionary" ) )
4822 insertBefore = child;
4828 [&](
const wxString& aNodeName, wxXmlNode* aSection )
4833 wxXmlNode* ref =
new wxXmlNode( wxXML_ELEMENT_NODE, aNodeName );
4834 ref->AddAttribute(
"name", aSection->GetAttribute(
"name" ) );
4842 insertRef(
"BomRef", bom_node );
4843 insertRef(
"AvlRef", avl_node );
4854 double written_bytes = 0.0;
4855 double last_yield = 0.0;
4862 auto update_progress =
4863 [&](
size_t aBytes )
4865 written_bytes += aBytes;
4866 double percent = written_bytes /
static_cast<double>(
m_total_bytes );
4871 if( last_yield + 0.01 < percent )
4873 last_yield = percent;
4885 wxBufferedOutputStream buffered_stream( out_stream, 1 << 20 );
4887 if( !
m_xml_doc->Save( buffered_stream ) )
4890 buffered_stream.Sync();
constexpr int ARC_HIGH_DEF
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
static bool hasBackdrill(const PADSTACK &aPadstack)
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_ITEM_TYPE_SILKSCREEN
@ BS_ITEM_TYPE_DIELECTRIC
@ BS_ITEM_TYPE_SOLDERMASK
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
wxString GetMajorMinorPatchVersion()
Get the major, minor and patch version in a string major.minor.patch This is extracted by CMake from ...
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
FOOTPRINT * GetParentFootprint() const
VECTOR2I GetFPRelativePosition() const
Manage one layer needed to make a physical board.
wxString GetTypeName() const
int GetSublayersCount() const
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetColor(int aDielectricSubLayer=0) const
wxString GetLayerName() const
PCB_LAYER_ID GetBrdLayerId() const
int GetThickness(int aDielectricSubLayer=0) const
BOARD_STACKUP_ITEM_TYPE GetType() const
wxString GetMaterial(int aDielectricSubLayer=0) const
int GetDielectricLayerId() const
double GetLossTangent(int aDielectricSubLayer=0) const
Manage layers needed to make a physical board.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
int BuildBoardThicknessFromStackup() const
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.
wxString m_FinishType
The name of external copper finish.
Information pertinent to a Pcbnew printed circuit board.
wxString GetCurrentVariant() const
constexpr size_type GetWidth() const
constexpr const Vec GetCenter() const
constexpr size_type GetHeight() const
KICAD_T Type() const
Returns the type of object.
int GetEllipseMinorRadius() const
const VECTOR2I & GetBezierC2() const
const VECTOR2I & GetEllipseCenter() const
EDA_ANGLE GetEllipseEndAngle() const
FILL_T GetFillMode() const
int GetEllipseMajorRadius() const
int GetRectangleWidth() const
SHAPE_POLY_SET & GetPolyShape()
EDA_ANGLE GetEllipseRotation() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
std::vector< VECTOR2I > GetRectCorners() const
EDA_ANGLE GetEllipseStartAngle() const
const VECTOR2I & GetBezierC1() const
int GetRectangleHeight() const
bool IsClockwiseArc() const
int GetCornerRadius() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual bool IsVisible() const
virtual EDA_ANGLE GetDrawRotation() const
virtual VECTOR2I GetDrawPos() const
virtual wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
Return the string actually shown after processing of the base text.
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
const TEXT_ATTRIBUTES & GetAttributes() const
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
static ENUM_MAP< T > & Instance()
SECTION_SET & Set(SECTION aSection, bool aOn=true)
Board items grouped by authored layer and net, sorted by FabItemLess.
std::map< int, std::vector< BOARD_ITEM * > > NET_ITEMS
Board stackup snapshot synchronized without changing the source board.
wxString m_name
Name of the IO loader.
virtual void Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) const
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
FONT is an abstract base class for both outline and stroke fonts.
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Draw a string.
A color representation with 4 components: red, green, blue, alpha.
wxString AsString() const
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Handle the data for a net.
const wxString & GetNetname() const
Container for NETINFO_ITEM elements, which are the nets.
unsigned GetNetCount() const
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
PCB_LAYER_ID EffectiveLayerFor(PCB_LAYER_ID aLayer) const
Determines which geometry layer should be used for the given input layer.
POST_MACHINING_PROPS & FrontPostMachining()
DRILL_PROPS & TertiaryDrill()
DRILL_PROPS & SecondaryDrill()
POST_MACHINING_PROPS & BackPostMachining()
A pad's resolved artwork on one fabrication layer.
const SHAPE_POLY_SET & Contour() const
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
bool FlashLayer(int aLayer, bool aOnlyCheckIfPermitted=false) const
Check to see whether the pad should be flashed on the specific layer.
PAD_ATTRIB GetAttribute() const
const wxString & GetNumber() const
VECTOR2I GetPosition() const override
VECTOR2I GetOffset(PCB_LAYER_ID aLayer) const
VECTOR2I GetDrillSize() const
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
int GetSolderMaskExpansion(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
const PADSTACK & Padstack() const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
PAD_DRILL_SHAPE GetDrillShape() const
int GetChamferPositions(PCB_LAYER_ID aLayer) const
double GetChamferRectRatio(PCB_LAYER_ID aLayer) const
VECTOR2I GetSolderPasteMargin(PCB_LAYER_ID aLayer) const
Usually < 0 (mask shape smaller than pad)because the margin can be dependent on the pad size,...
bool HasHole() const override
bool TransformHoleToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Build the corner list of the polygonal drill shape in the board coordinate system.
bool IsDegenerated(int aThreshold=5) const
const VECTOR2I & GetMid() const
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void addText(wxXmlNode *aContentNode, EDA_TEXT *aShape, const KIFONT::METRICS &aFontMetrics)
wxString floatVal(double aVal, int aSigFig=-1) const
void generateLayerSetDrill(wxXmlNode *aStepNode)
wxString genLayerString(PCB_LAYER_ID aLayer, const char *aPrefix) const
wxXmlNode * generateContentSection()
Creates the Content section of the XML file.
wxXmlNode * appendNode(wxXmlNode *aParent, const wxString &aName)
void addBackdrillSpecRefs(wxXmlNode *aHoleNode, const wxString &aPadstackName)
void generateDrillLayers(wxXmlNode *aCadLayerNode)
wxString sanitizeId(const wxString &aStr) const
wxXmlNode * addPackage(wxXmlNode *aStepNode, FOOTPRINT *aFootprint)
void generateComponents(wxXmlNode *aStepNode)
IPC2581::SECTION_SET emittedSections() const
Schema sections that the finished document holds.
bool addContourNode(wxXmlNode *aParentNode, const SHAPE_POLY_SET &aPolySet, int aOutline=0, FILL_T aFillType=FILL_T::FILLED_SHAPE, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
bool refDesEmitted() const
True if a Component keeps a designator that a reference can name.
wxString componentName(FOOTPRINT *aFootprint)
void addShape(wxXmlNode *aContentNode, const PCB_SHAPE &aShape, bool aInline=false)
IPC2581::RESOLVE_RESULT m_resolved
std::map< FOOTPRINT *, wxString > m_anon_refdes_dict
bool componentRefEmitted() const
True if a component reference can name a Component that the export wrote.
bool addOutlineNode(wxXmlNode *aParentNode, const SHAPE_POLY_SET &aPolySet, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
void generateStackup(wxXmlNode *aCadLayerNode)
std::map< std::tuple< auxLayerType, PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< BOARD_ITEM * > > m_auxilliary_Layers
bool addPolygonNode(wxXmlNode *aParentNode, const SHAPE_LINE_CHAIN &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
void insertNodeAfter(wxXmlNode *aPrev, wxXmlNode *aNode)
void generateCadLayers(wxXmlNode *aCadLayerNode)
std::vector< wxXmlNode * > m_padstacks
wxString pinName(const PAD *aPad) const
bool stackupRowIncluded(bool aDielectric, PCB_LAYER_ID aLayer) const
True if a stackup row is in a schema section that this export holds.
void generateCadSpecs(wxXmlNode *aCadLayerNode)
void addVia(wxXmlNode *aContentNode, const PCB_VIA *aVia, PCB_LAYER_ID aLayer)
IPC2581::SECTION_SET m_requestedSections
void addSlotCavity(wxXmlNode *aContentNode, const PAD &aPad, const wxString &aName)
void deleteNode(wxXmlNode *&aNode)
wxXmlNode * m_last_padstack
size_t lineHash(int aWidth, LINE_STYLE aDashType)
void SaveBoard(const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
std::map< size_t, wxString > m_std_shape_dict
wxString netName(const wxString &aNetname, const wxString &aSuffix=wxEmptyString)
Name to write for aNetname with the net name policy.
void addAttribute(wxXmlNode *aNode, const wxString &aName, const wxString &aValue)
wxXmlNode * m_shape_user_node
wxXmlNode * generateAvlSection()
Creates the Approved Vendor List section.
wxXmlNode * generateHistorySection()
Creates the history section.
wxString stackupLayerName(const BOARD_STACKUP_ITEM *aItem, int aSublayerId, const char *aPrefix) const
wxXmlNode * m_contentNode
void addXY(wxXmlNode *aNode, const VECTOR2I &aVec, const char *aXName=nullptr, const char *aYName=nullptr)
void reportPhase(const wxString &aMessage)
Go to the next progress phase and repaint.
wxXmlNode * m_shape_std_node
void addPadStack(wxXmlNode *aContentNode, const PAD *aPad)
std::map< FOOTPRINT *, wxString > m_OEMRef_dict
void clearLoadedFootprints()
Frees the memory allocated for the loaded footprints in m_loaded_footprints.
std::map< wxString, wxXmlNode * > m_backdrill_spec_nodes
std::map< std::pair< PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< PAD * > > m_slot_holes
std::map< size_t, wxString > m_footprint_dict
wxXmlNode * m_functionModeNode
wxXmlNode * generateLogisticSection()
Creates the logistical data header.
std::map< std::tuple< bool, int, int, int, int >, wxString > m_post_machining_specs
std::map< wxString, wxString > m_net_name_dict
std::map< size_t, wxString > m_line_dict
void addLineDesc(wxXmlNode *aNode, int aWidth, LINE_STYLE aDashType, bool aForce=false)
void addKnockoutText(wxXmlNode *aContentNode, PCB_TEXT *aText)
std::map< size_t, wxString > m_padstack_dict
void addPostMachiningSpecRefs(wxXmlNode *aHoleNode, const DRILL_OPERATION &aOperation)
std::map< DRILL_SPAN, std::vector< BOARD_ITEM * > > m_drill_layers
std::map< wxString, FOOTPRINT * > m_footprint_refdes_dict
void generateProfile(wxXmlNode *aStepNode)
void generateLayerFeatures(wxXmlNode *aStepNode)
void generateLayerSetNet(wxXmlNode *aLayerNode, PCB_LAYER_ID aLayer, const std::vector< BOARD_ITEM * > &aItems)
bool suppressed(IPC2581::SUPPRESS aWhat) const
wxXmlNode * generateBOMSection(wxXmlNode *aEcadNode)
Creates the BOM section.
wxXmlNode * generateContentStackup(wxXmlNode *aContentNode)
const FAB_DRILL_MODEL * m_fabDrillModel
void generateAuxilliaryLayers(wxXmlNode *aCadLayerNode)
wxXmlNode * m_cad_header_node
void addCadHeader(wxXmlNode *aEcadNode)
void generateLayerSetAuxilliary(wxXmlNode *aStepNode)
bool layerIncluded(PCB_LAYER_ID aLayer) const
True if aLayer is in a schema section that this export holds.
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
const std::map< std::string, UTF8 > * m_props
wxString genLayersString(PCB_LAYER_ID aTop, PCB_LAYER_ID aBottom, const char *aPrefix) const
void generateLogicalNets(wxXmlNode *aStepNode)
void addFillDesc(wxXmlNode *aNode, FILL_T aFillType, bool aForce=false)
std::map< size_t, wxString > m_user_shape_dict
void generatePhyNetGroup(wxXmlNode *aStepNode)
std::map< wxString, std::set< wxString > > m_element_names
~PCB_IO_IPC2581() override
wxString genString(const wxString &aStr, const char *aPrefix=nullptr) const
static constexpr int EXPORT_PHASES
Content logistic history CAD data components the two netlists BOM vendor list references the write an...
std::vector< FOOTPRINT * > m_loaded_footprints
bool addPolygonCutouts(wxXmlNode *aParentNode, const SHAPE_POLY_SET::POLYGON &aPolygon)
void pruneUnusedBackdrillSpecs()
IPC2581::REVISION m_revision
std::set< wxUniChar > m_acceptable_chars
void addLayerAttributes(wxXmlNode *aNode, PCB_LAYER_ID aLayer)
wxXmlNode * generateXmlHeader()
Creates the XML header for IPC-2581.
void ensureBackdrillSpecs(const wxString &aPadstackName, const PADSTACK &aPadstack)
wxXmlNode * generateEcadSection()
Creates the ECAD section.
const FAB_STACKUP * m_fabStackup
wxXmlDocument * m_xml_doc
bool included(IPC2581::SECTION aSection) const
wxXmlNode * insertNode(wxXmlNode *aParent, const wxString &aName)
void addPad(wxXmlNode *aContentNode, const PAD *aPad, PCB_LAYER_ID aLayer)
void generateContentLayerRefs(wxXmlNode *aCadDataNode)
void generateStepSection(wxXmlNode *aCadNode)
std::map< PCB_LAYER_ID, wxString > m_layer_name_map
void dropContentStepRefs()
Remove Content/StepRef when the export writes no Step.
std::map< wxString, wxString > m_generated_names
std::set< wxString > m_backdrill_spec_used
void addLocationNode(wxXmlNode *aContentNode, double aX, double aY)
std::map< wxString, std::array< wxString, 2 > > m_padstack_backdrill_specs
std::map< int, std::vector< std::pair< wxString, wxString > > > m_net_pin_dict
int m_backdrill_spec_index
void tickProgress(const wxString &aMessage=wxEmptyString)
Count one unit of work in this phase and repaint at intervals.
std::map< FOOTPRINT *, wxString > m_footprint_refdes_reverse_dict
wxXmlNode * m_lastAppendedNode
Optimization for appendNode to avoid O(n) child traversal.
wxXmlNode * m_enterpriseNode
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
void SetWidth(int aWidth) override
void SetEnd(const VECTOR2I &aEnd) override
STROKE_PARAMS GetStroke() const override
void SetStart(const VECTOR2I &aStart) override
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) override
Set the three controlling points for an arc.
VECTOR2I GetPosition() 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).
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
PCB_LAYER_ID BottomLayer() const
VECTOR2I GetPosition() const override
bool FlashLayer(int aLayer) const
Check to see whether the via should have a pad on the specific layer.
const PADSTACK & Padstack() const
int GetWidth() const override
PCB_LAYER_ID TopLayer() const
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
RAII class that sets an value at construction and resets it to the original value at destruction.
SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError) const
Build a polyline approximation of the ellipse or arc.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int Width() const
Get the current width of the segments in the chain.
int PointCount() const
Return the number of points (vertices) in this line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
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)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
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.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
LINE_STYLE GetLineStyle() const
Handle a list of polygons defining a copper zone.
void SetProgressCallback(std::function< void(size_t)> aCallback)
@ RECT_CHAMFER_BOTTOM_RIGHT
@ RECT_CHAMFER_BOTTOM_LEFT
static bool empty(const wxTextEntryBase *aCtrl)
bool IsDrillSlot(const PAD &aPad)
Whether a pad's hole is a slot rather than a round drill.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_180
@ FILLED_SHAPE
Fill with object color.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
FAB_COMPONENT_ROW MakeFabComponentRow(const FOOTPRINT &aFootprint, const wxString &aVariant)
PCB_LAYER_ID FabBackdrillMustNotCut(const LSEQ &aCopperStack, PCB_LAYER_ID aStart, PCB_LAYER_ID aMustCut)
aMustCut is DRILL_PROPS.end; returns the next enabled copper past it away from aStart,...
int FabTrackWidth(const PCB_TRACK &aTrack, PCB_LAYER_ID aLayer)
Use only for traces and arcs; vias require a layer-specific width.
bool FabMaskShape(const PCB_SHAPE &aShape, PCB_LAYER_ID aLayer, PCB_SHAPE &aResult)
Build an expanded mask copy of an exposed copper shape when needed.
std::map< int, wxString > FabAnonymousNetNames(const BOARD &aBoard)
Anonymous names NET_1 through NET_n keyed and numbered by net code.
PAD_LAYER_GEOMETRY ResolvePadLayer(const PAD &aPad, PCB_LAYER_ID aLayer, int aMaxError)
Artwork on one layer as plotted by PlotStandardLayer; keep the plotter independent as the parity orac...
VECTOR2I ResolvePadMargin(const PAD &aPad, PCB_LAYER_ID aLayer)
Per-side mask or paste margin as PlotStandardLayer applies it.
FAB_PIN MakeFabPin(const PAD &aPad, size_t aIndexInFootprint)
aIndexInFootprint is the pad's position in its footprint, used to name NPTH and unnumbered pads
std::vector< FAB_TEST_POINT > FabTestPoints(const BOARD &aBoard)
The caller must build board connectivity before enumerating net endpoints.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_CANCELLED()
static const wxChar traceIpc2581[]
This program source code file is part of KiCad, a free EDA CAD application.
static constexpr void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
static constexpr std::size_t hash_val(const Types &... args)
size_t hash_fp_item(const EDA_ITEM *aItem, int aFlags)
Calculate hash of an EDA_ITEM.
Hashing functions for EDA_ITEMs.
@ RELATIVE_TO_PARENT_COORDS
std::vector< size_t > OrderAvlRows(const std::vector< AVL_ROW > &aRows)
Return row indices sorted by OEM name, reference, then input order.
surfaceFinishType
IPC-6012 surface finish types from Table 3-3 "Final Finish and Coating Requirements".
@ OTHER
Non-standard finish.
@ DIG
Direct Immersion Gold.
@ HT_OSP
High Temperature OSP.
@ ENEPIG_N
ENEPIG for soldering (normal gold thickness)
@ NONE
No surface finish / not specified - skip coating layer generation.
@ OSP
Organic Solderability Preservative.
@ ENIG_N
ENIG for soldering (normal gold thickness)
bool IsUserLayer(PCB_LAYER_ID aLayerId)
Test whether a layer is a non copper and a non tech layer.
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
wxString SectionKeyString(const SECTION_SET &aSet)
Give aSet as a sectionKey attribute value.
SECTION
Schema sections of the IPC-2581C function mode table, Table 4 p 80.
bool SectionSetFromKeyString(const wxString &aKey, SECTION_SET &aResult)
Read a sectionKey attribute value Return false for an unknown character.
SECTION_SET RecommendedOptionalSections(MODE aMode)
Optional schema sections that aMode selects by default.
std::optional< MODE > ModeFromToken(const wxString &aToken)
Read a Table 4 function mode token in upper case or in lower case.
wxString ModeToken(MODE aMode)
Table 4 function mode token such as FABRICATION.
bool NeedsCadData(const SECTION_SET &aSet)
True if an included schema section needs an Ecad/CadData element.
RESOLVE_RESULT ResolveSections(REVISION aRevision, MODE aMode, const SECTION_SET &aRequested)
Compare aRequested with Table 4 and give the attributes to remove and the conflicts.
std::optional< SECTION > SectionForLayerFunction(const wxString &aLayerFunction, const wxString &aSide)
Schema section that holds the layers with aLayerFunction.
@ PINREF_COMPONENTREF
Pad/PinRef@componentRef and LogicalNet/PinRef@componentRef.
@ PAD_PADSTACKDEFREF
Pad@padstackDefRef, and the PadStackDef elements themselves.
@ COMPONENT_PACKAGEREF
Component@packageRef.
@ BOM_REFDES_PACKAGEREF
Bom/BomItem/RefDes@packageRef.
@ BOM_REFDES
Bom/BomItem/RefDes and all its attributes.
@ BOM_REFDES_LAYERREF
Bom/BomItem/RefDes@layerRef.
std::optional< SECTION > SectionForBoardLayer(PCB_LAYER_ID aLayer)
Schema section that holds the artwork of aLayer.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ PTH
Plated through hole pad.
static const std::map< surfaceFinishType, wxString > surfaceFinishTypeToString
Map surfaceFinishType enum to IPC-2581 XML string values.
static bool isOppositeSideSilk(const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer)
static void mixBackdrillIntoPadstackHash(size_t &aHash, const PADSTACK &aPadstack)
static size_t ipcPadstackHash(const PCB_VIA *aVia, const DRILL_OPERATION *aOperation)
static const std::map< wxString, surfaceFinishType > surfaceFinishMap
Map KiCad surface finish strings to IPC-6012 surfaceFinishType enum.
static wxString propertyUnitForCadUnits(const wxString &aCadUnits)
static surfaceFinishType getSurfaceFinishType(const wxString &aFinish)
static wxString nodeName(const wxString &aSymbolPin)
std::vector< FAB_LAYER_COLOR > dummy
const std::vector< FAB_LAYER_COLOR > & GetStandardColors(BOARD_STACKUP_ITEM_TYPE aType)
wxString FormatTrimmedDecimal(double aValue, int aPrecision)
Format a value to aPrecision decimal digits and strip trailing zeros, keeping one digit after the dec...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
LINE_STYLE
Dashed line types.
One machining action, which is also one NC hit and one tool assignment.
DRILL_POST_MACHINING m_BackPostMachining
BOARD_ITEM * m_SourceItem
non-owning, valid only for this enumeration
DRILL_POST_MACHINING m_FrontPostMachining
PAD_DRILL_POST_MACHINING_MODE m_Mode
Footprint facts resolved for one assembly variant.
wxString Field(const wxString &aName) const
Variant-resolved shown text, empty when the field is missing.
FAB_ELECTRICAL m_electrical
The properties of a padstack drill.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
std::vector< DATABASE_CONNECTION::ROW > rows
static EDA_ORIENTATION orientation(double d)
KIBIS top(path, &reporter)
const SHAPE_LINE_CHAIN chain
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D