35#include <wx/wfstream.h>
59 wxFFileOutputStream stream( aOutFileName );
67 return xdoc.Save( stream, 2 );
114 xroot->AddChild( xchains );
131 wxString description;
133 nlohmann::ordered_map<wxString, wxString> fields;
144 wxString ref = aSymbol->
GetRef( &aSheet );
147 using SOURCE = std::pair<int, KIID>;
149 std::optional<SOURCE> valueSrc;
150 std::optional<SOURCE> footprintSrc;
151 std::optional<SOURCE> datasheetSrc;
152 std::optional<SOURCE> descriptionSrc;
155 std::map<wxString, std::pair<bool, SOURCE>> fieldSrcs;
158 [](
const SOURCE& aNew,
const std::optional<SOURCE>& aOld )
160 return !aOld || aNew < *aOld;
169 wxString ref2 = symbol2->
GetRef( &sheet );
171 if( ref2.CmpNoCase( ref ) != 0 )
181 if( !candidate.IsEmpty() && earlier( src, valueSrc ) )
190 if( !candidate.IsEmpty() && earlier( src, footprintSrc ) )
192 footprint = candidate;
200 if( !candidate.IsEmpty() && earlier( src, datasheetSrc ) )
210 if( !candidate.IsEmpty() && earlier( src, descriptionSrc ) )
212 description = candidate;
213 descriptionSrc = src;
219 if( field.IsMandatory() || field.IsPrivate() )
224 const std::pair<bool, SOURCE> rank{ candidate.IsEmpty(), src };
225 auto known = fieldSrcs.find( field.GetName() );
227 if( known == fieldSrcs.end() || rank < known->second )
229 fields[field.GetName()] = candidate;
230 fieldSrcs.insert_or_assign( field.GetName(), rank );
249 if( field.IsMandatory() || field.IsPrivate() )
264 aNode->AddChild(
node( wxT(
"value" ), wxT(
"~" ) ) );
266 if( footprint.size() )
272 if( description.size() )
276 aNode->AddChild( xfields =
node( wxT(
"fields" ) ) );
278 for(
const auto& [ fieldName, fieldValue ] : fields )
282 xfields->AddChild( xfield );
289 XNODE* xcomps =
node( wxT(
"components" ) );
297 const wxString currentVariant =
m_schematic->GetCurrentVariant();
304 if( forBOM && ( aSheet.GetExcludedFromBOM( currentVariant )
310 return forBoard && ( aSheet.GetExcludedFromBoard( currentVariant )
333 std::set<
SCH_SYMBOL*,
decltype( cmp )> ordered_symbols( cmp );
334 std::multiset<
SCH_SYMBOL*,
decltype( cmp )> extra_units( cmp );
341 if( excluded( symbol, sheet ) )
344 auto test = ordered_symbols.insert( symbol );
348 if( ( *(
test.first ) )->m_Uuid > symbol->
m_Uuid )
350 extra_units.insert( *(
test.first ) );
351 ordered_symbols.erase(
test.first );
352 ordered_symbols.insert( symbol );
356 extra_units.insert( symbol );
361 for(
EDA_ITEM* item : ordered_symbols )
373 xcomps->AddChild( xcomp =
node( wxT(
"comp" ) ) );
379 xcomp->AddChild( xlibsource =
node( wxT(
"libsource" ) ) );
407 std::vector<SCH_FIELD>& fields = symbol->
GetFields();
411 if( field.IsMandatory() || field.IsPrivate() )
414 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
415 xproperty->
AddAttribute( wxT(
"name" ), field.GetUntranslatedName() );
421 for(
const SCH_FIELD& sheetField : sheet.Last()->GetFields() )
423 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
424 xproperty->
AddAttribute( wxT(
"name" ), sheetField.GetUntranslatedName() );
436 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
437 xproperty->
AddAttribute( wxT(
"name" ), wxT(
"exclude_from_bom" ) );
443 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
444 xproperty->
AddAttribute( wxT(
"name" ), wxT(
"exclude_from_sim" ) );
450 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
451 xproperty->
AddAttribute( wxT(
"name" ), wxT(
"exclude_from_board" ) );
458 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
459 xproperty->
AddAttribute( wxT(
"name" ), wxT(
"exclude_from_pos_files" ) );
462 const bool baseDnp = symbol->
ResolveDNP( &sheet ) || sheet.GetDNP();
466 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
472 const std::set<wxString>& variantNames =
m_schematic->GetVariantNames();
477 XNODE* xvariants =
nullptr;
479 for(
const auto& variantName : variantNames )
481 XNODE* xvariant =
nullptr;
484 [
this, &xvariant, &variantName](
XNODE* child ) ->
void
491 xvariant =
node( wxT(
"variant" ) );
494 xvariant->AddChild( child );
498 [
this, &addToVariant]( wxString
const&
name,
bool base,
bool effective ) ->
void
500 if( base == effective )
503 XNODE* xvarprop =
node( wxT(
"property" ) );
505 xvarprop->
AddAttribute( wxT(
"value" ), effective ? wxT(
"1" ) : wxT(
"0" ) );
506 addToVariant( xvarprop );
509 bool effectiveDnp = symbol->
ResolveDNP( &sheet, variantName ) || sheet.GetDNP( variantName );
510 addBinaryProp( wxT(
"dnp" ), baseDnp, effectiveDnp );
513 || sheet.GetExcludedFromBOM( variantName );
514 addBinaryProp( wxT(
"exclude_from_bom" ), baseExcludedFromBOM, effectiveExcludedFromBOM );
517 || sheet.GetExcludedFromSim( variantName );
518 addBinaryProp( wxT(
"exclude_from_sim" ), baseExcludedFromSim, effectiveExcludedFromSim );
521 addBinaryProp( wxT(
"exclude_from_pos_files" ), baseExcludedFromPosFiles,
522 effectiveExcludedFromPosFiles );
528 variant = &instance.
m_Variants.at( variantName );
532 XNODE* xprop =
node( wxT(
"property" ) );
533 xprop->
AddAttribute( wxT(
"name" ), wxT(
"symbol_override" ) );
535 addToVariant( xprop );
540 XNODE* xfields =
nullptr;
542 for(
const auto& [fieldName, fieldValue] : variant->
m_Fields )
544 const wxString baseValue = symbol->
GetFieldText( fieldName, &sheet, wxEmptyString );
546 if( fieldValue == baseValue )
550 xfields =
node( wxT(
"fields" ) );
552 wxString resolvedValue = fieldValue;
555 resolvedValue = symbol->
ResolveText( fieldValue, &sheet );
559 xfields->AddChild( xfield );
569 const wxString& fieldName = baseField.GetName();
571 if( variant->
m_Fields.contains( fieldName ) )
574 const wxString baseValue = symbol->
GetFieldText( fieldName, &sheet, wxEmptyString );
575 const wxString variantValue = symbol->
GetFieldText( fieldName, &sheet, variantName );
577 if( variantValue == baseValue )
581 xfields =
node( wxT(
"fields" ) );
583 wxString resolvedValue = variantValue;
586 resolvedValue = symbol->
ResolveText( variantValue, &sheet );
590 xfields->AddChild( xfield );
597 std::vector<SCH_FIELD*> altFields;
598 altSymbol->GetFields( altFields );
600 for(
const SCH_FIELD* altField : altFields )
602 const wxString& fieldName = altField->GetName();
605 || variant->
m_Fields.contains( fieldName )
606 || altField->GetText().IsEmpty() )
612 xfields =
node( wxT(
"fields" ) );
614 wxString resolvedValue = altField->GetText();
617 resolvedValue = symbol->
ResolveText( resolvedValue, &sheet );
621 xfields->AddChild( xfield );
626 addToVariant( xfields );
632 xvariants =
node( wxT(
"variants" ) );
634 xvariants->AddChild( xvariant );
639 xcomp->AddChild( xvariants );
642 if(
const std::unique_ptr<LIB_SYMBOL>& part = symbol->
GetLibSymbolRef() )
644 if( part->GetKeyWords().size() )
646 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
647 xproperty->
AddAttribute( wxT(
"name" ), wxT(
"ki_keywords" ) );
648 xproperty->
AddAttribute( wxT(
"value" ), part->GetKeyWords() );
651 if( !part->GetFPFilters().IsEmpty() )
655 for(
const wxString&
filter : part->GetFPFilters() )
658 xcomp->AddChild( xproperty =
node( wxT(
"property" ) ) );
659 xproperty->
AddAttribute( wxT(
"name" ), wxT(
"ki_fp_filters" ) );
663 if( part->GetDuplicatePinNumbersAreJumpers() )
664 xcomp->AddChild(
node( wxT(
"duplicate_pin_numbers_are_jumpers" ), wxT(
"1" ) ) );
671 xcomp->AddChild( xproperty =
node( wxT(
"jumper_pin_groups" ) ) );
675 xproperty->AddChild( groupNode =
node( wxT(
"group" ) ) );
677 for(
const wxString& pinName :
group.GetNames() )
678 groupNode->AddChild(
node( wxT(
"pin" ), pinName ) );
684 xcomp->AddChild( xsheetpath =
node( wxT(
"sheetpath" ) ) );
686 xsheetpath->
AddAttribute( wxT(
"names" ), sheet.PathHumanReadable() );
687 xsheetpath->
AddAttribute( wxT(
"tstamps" ), sheet.PathAsString() );
692 if( compClassNames.size() > 0 )
694 XNODE* xcompclasslist;
695 xcomp->AddChild( xcompclasslist =
node( wxT(
"component_classes" ) ) );
697 for(
const wxString& compClass : compClassNames )
702 xcomp->AddChild( xunits =
node( wxT(
"tstamps" ) ) );
704 auto range = extra_units.equal_range( symbol );
708 for(
auto it = range.first; it != range.second; ++it )
710 uuid = ( *it )->m_Uuid.AsString();
717 xunits->AddChild(
new XNODE( wxXML_TEXT_NODE, wxEmptyString, uuid ) );
722 xunits->AddChild(
new XNODE( wxXML_TEXT_NODE, wxEmptyString, uuid ) );
726 xcomp->AddChild( xunitInfo =
node( wxT(
"units" ) ) );
741 const std::vector<LIB_SYMBOL::UNIT_PIN_INFO>& defaultUnitInfo = libSym->GetUnitPinInfo();
742 std::map<int, SCH_SYMBOL*> symbolByUnit;
750 int unit = aUnitSymbol->GetUnitSelection( &sheet );
753 symbolByUnit.try_emplace( unit, aUnitSymbol );
756 addUnitSymbol( symbol );
758 auto extraUnitRange = extra_units.equal_range( symbol );
762 for(
auto it = extraUnitRange.first; it != extraUnitRange.second; ++it )
763 addUnitSymbol( *it );
767 for(
size_t unitIdx = 0; unitIdx < defaultUnitInfo.size(); ++unitIdx )
770 auto symbolIt = symbolByUnit.find( unitIdx + 1 );
772 if( symbolIt != symbolByUnit.end() )
774 const std::unique_ptr<LIB_SYMBOL>& unitLibSym = symbolIt->second->GetLibSymbolRef();
778 const std::vector<LIB_SYMBOL::UNIT_PIN_INFO>& unitSpecificInfo =
779 unitLibSym->GetUnitPinInfo();
781 if( unitIdx < unitSpecificInfo.size() )
782 unitInfo = unitSpecificInfo[unitIdx];
787 xunitInfo->AddChild( xunit =
node( wxT(
"unit" ) ) );
791 xunit->AddChild( xpins =
node( wxT(
"pins" ) ) );
796 xpins->AddChild( xpin =
node( wxT(
"pin" ) ) );
820 std::map<SCH_SCREEN*, int> screenVisits;
823 screenVisits[sheet.LastScreen()]++;
831 wxString instancePrefix = sheet.PathAsString();
836 wxString groupName =
group->GetName();
838 if( screenVisits[sheet.LastScreen()] > 1 )
839 groupName = wxString::Format( wxT(
"%s (%s)" ), groupName, sheet.PathHumanReadable() );
842 xcomps->AddChild( xgroup =
node( wxT(
"group" ) ) );
845 xgroup->
AddAttribute( wxT(
"uuid" ), instancePrefix +
group->m_Uuid.AsString() );
849 xgroup->AddChild( xmembers =
node( wxT(
"members" ) ) );
856 xmembers->AddChild( xmember =
node( wxT(
"member" ) ) );
857 xmember->
AddAttribute( wxT(
"uuid" ), instancePrefix + member->m_Uuid.AsString() );
863 xmembers->AddChild( xmember =
node( wxT(
"member" ) ) );
864 xmember->
AddAttribute( wxT(
"uuid" ), instancePrefix + member->m_Uuid.AsString() );
869 std::vector<SCH_SHEET_PATH> descendantSheets;
879 xmembers->AddChild( xmember =
node( wxT(
"member" ) ) );
881 descendantSheet.PathAsString() + descendantItem->m_Uuid.AsString() );
897 XNODE* xvariants =
node( wxT(
"variants" ) );
899 std::set<wxString> variantNames =
m_schematic->GetVariantNames();
901 for(
const wxString& variantName : variantNames )
904 xvariants->AddChild( xvariant =
node( wxT(
"variant" ) ) );
907 wxString description =
m_schematic->GetVariantDescription( variantName );
909 if( !description.IsEmpty() )
910 xvariant->
AddAttribute( wxT(
"description" ), description );
920 std::vector<SCH_SHEET_PATH> symbolSheets;
921 symbolSheets.push_back( aSymbolSheet );
928 const wxString ref = aSymbol->
GetRef( &aSymbolSheet );
936 wxString ref2 = symbol2->
GetRef( &sheet );
939 if( ref2.CmpNoCase( ref ) != 0 )
942 if( otherUnit == primaryUnit )
945 symbolSheets.push_back( sheet );
949 compClassNames.insert( otherClassNames.begin(), otherClassNames.end() );
959 if( symbolSheetPath.IsContainedWithin( sheetPath ) )
960 compClassNames.insert( sheetCompClasses.begin(), sheetCompClasses.end() );
964 std::vector<wxString> sortedCompClassNames( compClassNames.begin(), compClassNames.end() );
965 std::sort( sortedCompClassNames.begin(), sortedCompClassNames.end(),
966 [](
const wxString& str1,
const wxString& str2 )
968 return str1.Cmp( str2 ) < 0;
971 return sortedCompClassNames;
978 XNODE* xdesign =
node( wxT(
"design" ) );
984 wxFileName sourceFileName;
987 xdesign->AddChild(
node( wxT(
"source" ),
m_schematic->GetFileName() ) );
994 const std::map<wxString, wxString>& properties =
m_schematic->Project().GetTextVars();
996 for(
const std::pair<const wxString, wxString>& prop : properties )
998 xdesign->AddChild( xtextvar =
node( wxT(
"textvar" ), prop.second ) );
1005 unsigned sheetIndex = 1;
1009 screen = sheet.LastScreen();
1011 xdesign->AddChild( xsheet =
node( wxT(
"sheet" ) ) );
1014 sheetTxt.Printf( wxT(
"%u" ), sheetIndex++ );
1016 xsheet->
AddAttribute( wxT(
"name" ), sheet.PathHumanReadable() );
1017 xsheet->
AddAttribute( wxT(
"tstamps" ), sheet.PathAsString() );
1022 xsheet->AddChild( xtitleBlock =
node( wxT(
"title_block" ) ) );
1030 sourceFileName = wxFileName( screen->
GetFileName() );
1031 xtitleBlock->AddChild(
node( wxT(
"source" ), sourceFileName.GetFullName() ) );
1033 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1037 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1041 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1045 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1049 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1053 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1057 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1061 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1065 xtitleBlock->AddChild( xcomment =
node( wxT(
"comment" ) ) );
1076 XNODE* xlibs =
node( wxT(
"libraries" ) );
1087 xlibs->AddChild( xlibrary =
node( wxT(
"library" ) ) );
1088 xlibrary->
AddAttribute( wxT(
"logical" ), libNickname );
1089 xlibrary->AddChild(
node( wxT(
"uri" ), *uri ) );
1099 XNODE* xlibparts =
node( wxT(
"libparts" ) );
1100 std::vector<SCH_FIELD*> fieldList;
1106 wxString libNickname = lcomp->GetLibId().GetLibNickname();;
1109 if( !libNickname.IsEmpty() )
1113 xlibparts->AddChild( xlibpart =
node( wxT(
"libpart" ) ) );
1115 xlibpart->
AddAttribute( wxT(
"part" ), lcomp->GetName() );
1118 if( !lcomp->GetDescription().IsEmpty() )
1119 xlibpart->AddChild(
node( wxT(
"description" ), lcomp->GetDescription() ) );
1121 if( !lcomp->GetDatasheetField().GetText().IsEmpty() )
1122 xlibpart->AddChild(
node( wxT(
"docs" ), lcomp->GetDatasheetField().GetText() ) );
1125 if( lcomp->GetFPFilters().GetCount() )
1128 xlibpart->AddChild( xfootprints =
node( wxT(
"footprints" ) ) );
1130 for(
unsigned i = 0; i < lcomp->GetFPFilters().GetCount(); ++i )
1132 if( !lcomp->GetFPFilters()[i].IsEmpty() )
1133 xfootprints->AddChild(
node( wxT(
"fp" ), lcomp->GetFPFilters()[i] ) );
1139 lcomp->GetFields( fieldList );
1142 xlibpart->AddChild( xfields =
node(
"fields" ) );
1144 for(
const SCH_FIELD* field : fieldList )
1147 xfields->AddChild( xfield =
node( wxT(
"field" ), field->GetText() ) );
1148 xfield->
AddAttribute( wxT(
"name" ), field->GetUntranslatedName() );
1154 std::vector<SCH_PIN*> pinList = lcomp->GetGraphicalPins( 0, 0 );
1166 for(
int ii = 0; ii < (int)pinList.size()-1; ii++ )
1168 if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
1170 pinList.erase(pinList.begin() + ii + 1);
1175 wxLogTrace(
"CVPCB_PINCOUNT",
1176 wxString::Format(
"makeLibParts: lib='%s' part='%s' pinList(size)=%zu",
1177 libNickname, lcomp->GetName(), pinList.size() ) );
1179 if( pinList.size() )
1183 xlibpart->AddChild( pins =
node( wxT(
"pins" ) ) );
1185 for(
unsigned i=0; i<pinList.size(); ++i )
1187 SCH_PIN* basePin = pinList[i];
1189 bool stackedValid =
false;
1193 if( stackedValid && !expandedNums.empty() )
1195 for(
const wxString& num : expandedNums )
1198 pins->AddChild(
pin =
node( wxT(
"pin" ) ) );
1199 pin->AddAttribute( wxT(
"num" ), num );
1203 wxLogTrace(
"CVPCB_PINCOUNT",
1204 wxString::Format(
"makeLibParts: -> pin num='%s' name='%s' (expanded)",
1211 pins->AddChild(
pin =
node( wxT(
"pin" ) ) );
1216 wxLogTrace(
"CVPCB_PINCOUNT",
1217 wxString::Format(
"makeLibParts: -> pin num='%s' name='%s'",
1233 wxString netCodeTxt;
1235 XNODE* xnet =
nullptr;
1257 NET_RECORD(
const wxString& aName ) :
1259 m_HasNoConnect(
false )
1264 bool m_HasNoConnect;
1265 std::vector<NET_NODE> m_Nodes;
1268 std::vector<NET_RECORD*> nets;
1270 std::shared_ptr<NET_SETTINGS> netSettings;
1273 netSettings =
m_schematic->Project().GetProjectFile().NetSettings();
1278 nets.emplace_back(
new NET_RECORD( netName ) );
1279 NET_RECORD* net_record = nets.back();
1280 net_record->m_HasNoConnect = net.hasNoConnect;
1284 if(
const auto netclass = netSettings->GetEffectiveNetClass( net.name ) )
1288 for(
const auto& [
pin, sheet] : net.pins )
1309 net_record->m_Nodes.emplace_back(
pin, sheet );
1314 std::sort( nets.begin(), nets.end(),
1315 [](
const NET_RECORD* a,
const NET_RECORD*b )
1317 return StrNumCmp( a->m_Name, b->m_Name ) < 0;
1320 for(
int i = 0; i < (int) nets.size(); ++i )
1322 NET_RECORD* net_record = nets[i];
1327 std::sort( net_record->m_Nodes.begin(), net_record->m_Nodes.end(),
1330 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
1331 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
1334 return a.m_Pin->GetShownNumber() < b.m_Pin->GetShownNumber();
1345 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
1346 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
1348 return refA == refB && a.m_Pin->GetShownNumber() == b.m_Pin->GetShownNumber();
1353 bool allNetPinsStacked =
true;
1355 if( net_record->m_Nodes.size() > 1 )
1357 SCH_PIN* firstPin = net_record->m_Nodes.begin()->m_Pin;
1358 allNetPinsStacked = std::all_of( net_record->m_Nodes.begin() + 1, net_record->m_Nodes.end(),
1361 return firstPin->GetParent() == node.m_Pin->GetParent()
1362 && firstPin->GetPosition() == node.m_Pin->GetPosition()
1363 && firstPin->GetName() == node.m_Pin->GetName();
1367 for(
const NET_NODE& netNode : net_record->m_Nodes )
1369 wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
1372 if( refText[0] == wxChar(
'#' ) )
1378 std::vector<wxString> nums =
resolvePadNumbers( netNode.m_Pin, netNode.m_Sheet );
1384 wxString baseName = netNode.m_Pin->GetShownName();
1385 wxString pinType = netNode.m_Pin->GetCanonicalElectricalTypeName();
1389 netCodeTxt.Printf( wxT(
"%d" ), i + 1 );
1391 xnets->AddChild( xnet =
node( wxT(
"net" ) ) );
1393 xnet->
AddAttribute( wxT(
"name" ), net_record->m_Name );
1394 xnet->
AddAttribute( wxT(
"class" ), net_record->m_Class );
1399 for(
const wxString& num : nums )
1401 xnet->AddChild( xnode =
node( wxT(
"node" ) ) );
1405 wxString fullName = baseName.IsEmpty() ? num : baseName + wxT(
"_" ) + num;
1407 if( !baseName.IsEmpty() || nums.size() > 1 )
1410 wxString typeAttr = pinType;
1412 if( net_record->m_HasNoConnect
1413 && ( net_record->m_Nodes.size() == 1 || allNetPinsStacked ) )
1415 typeAttr += wxT(
"+no_connect" );
1423 for( NET_RECORD* record : nets )
1431 const auto& committed =
m_schematic->NetChains().GetCommittedNetChains();
1433 if( committed.empty() )
1436 XNODE* xchains =
node( wxT(
"net_chains" ) );
1438 for(
const std::unique_ptr<SCH_NETCHAIN>&
chain : committed )
1444 xchains->AddChild( xchain =
node( wxT(
"net_chain" ) ) );
1447 if( !
chain->GetNetClass().IsEmpty() )
1456 const std::shared_ptr<NET_SETTINGS>& ns = pf.
NetSettings();
1460 wxString className = ns->GetNetChainClass(
chain->GetName() );
1462 if( !className.IsEmpty() )
1463 xchain->
AddAttribute( wxT(
"net_chain_class" ), className );
1471 wxString::Format( wxT(
"#%02X%02X%02X%02X" ),
1472 (
int) std::clamp(
KiROUND( c.
r * 255.0 ), 0, 255 ),
1473 (
int) std::clamp(
KiROUND( c.
g * 255.0 ), 0, 255 ),
1474 (
int) std::clamp(
KiROUND( c.
b * 255.0 ), 0, 255 ),
1475 (
int) std::clamp(
KiROUND( c.
a * 255.0 ), 0, 255 ) ) );
1479 xchain->AddChild( xmembers =
node( wxT(
"members" ) ) );
1485 for(
const wxString& net :
chain->GetNets() )
1491 xmembers->AddChild( xmember =
node( wxT(
"member" ) ) );
1495 if( !
chain->GetTerminalRefDes( 0 ).IsEmpty() || !
chain->GetTerminalRefDes( 1 ).IsEmpty() )
1498 xchain->AddChild( xterms =
node( wxT(
"terminal_pins" ) ) );
1500 for(
int i = 0; i < 2; ++i )
1502 if(
chain->GetTerminalRefDes( i ).IsEmpty() )
1506 xterms->AddChild( xterm =
node( wxT(
"terminal_pin" ) ) );
1519 XNODE* n =
new XNODE( wxXML_ELEMENT_NODE, aName );
1521 if( aTextualContent.Len() > 0 )
1522 n->AddChild(
new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
1541 auto getComponentClassFields =
1542 [&](
const std::vector<SCH_FIELD>& fields,
const SCH_SHEET_PATH* sheetPath )
1544 std::unordered_set<wxString> componentClasses;
1548 if( field.GetUntranslatedName() == wxT(
"Component Class" ) )
1555 return componentClasses;
1563 std::unordered_set<wxString> sheetComponentClasses;
1564 const std::unordered_set<SCH_RULE_AREA*>& sheetRuleAreas = sheetItem->
GetRuleAreaCache();
1570 std::unordered_set<wxString> ruleAreaComponentClasses = getComponentClassFields( label->GetFields(),
1572 sheetComponentClasses.insert( ruleAreaComponentClasses.begin(), ruleAreaComponentClasses.end() );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
wxString GetBuildVersion()
Get the full KiCad version string.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A base class for most all the KiCad significant classes used in schematics and boards.
Represents an (ordered) list of JUMPER_GROUP objects.
const std::vector< JUMPER_GROUP > & GetAll() const
Represents a group of jumper pins or pads, keyed by name.
A color representation with 4 components: red, green, blue, alpha.
wxString AsString() const
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const wxString GetUniStringLibNickname() const
Define a library symbol object.
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
std::vector< wxString > resolvePadNumbers(const SCH_PIN *aPin, const SCH_SHEET_PATH &aSheetPath) const
Resolve aPin to its effective pad number(s) for every netlist path (issue #2282).
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
SCH_SHEET_LIST m_exportSheets
std::vector< EXPORT_NET > m_exportNets
wxString m_exportVariant
The schematic we're generating a netlist for.
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath, const EXPORT_EXCLUSION &aExcluded=nullptr)
Check if the given symbol should be processed for netlisting.
void getSheetComponentClasses()
std::map< SCH_SHEET_PATH, std::unordered_set< wxString > > m_sheetComponentClasses
Map of all sheets to component classes covering the whole sheet.
XNODE * makeDesignHeader()
Fill out a project "design" header into an XML node.
XNODE * makeLibraries()
Fill out an XML node with a list of used libraries and returns it.
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
XNODE * makeListOfNets(unsigned aCtl)
Fill out an XML node with a list of nets and returns it.
void addSymbolFields(XNODE *aNode, SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheet, const SCH_SHEET_LIST &aSheetList)
Holder for multi-unit symbol fields.
RESOLUTION_CONTEXT m_resolveTextVars
bool writeNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter) override
Write generic netlist to aOutFileName.
std::vector< wxString > getComponentClassNamesForAllSymbolUnits(SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSymbolSheet, const SCH_SHEET_LIST &aSheetList)
Finds all component class names attached to any sub-unit of a given symbol.
XNODE * makeSymbols(unsigned aCtl)
XNODE * makeRoot(unsigned aCtl=GNL_ALL)
Build the entire document tree for the generic export.
std::set< wxString > m_libraries
XNODE * makeLibParts()
Fill out an XML node with the unique library parts and returns it.
virtual LIBRARY_MANAGER & GetLibraryManager() const
The backing store for a PROJECT, in JSON format.
std::shared_ptr< NET_SETTINGS > & NetSettings()
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
A set of SCH_ITEMs (i.e., without duplicates).
Base class for any item which can be embedded within the SCHEMATIC container class,...
bool ResolveExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
const std::unordered_set< SCH_RULE_AREA * > & GetRuleAreaCache() const
Get the cache of rule areas enclosing this item.
bool ResolveExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
bool ResolveExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
bool ResolveDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
bool ResolveExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
static bool IsPersistableNet(const wxString &aNet)
Synthetic keys do not survive a reload, so only named nets are written out.
std::vector< wxString > GetStackedPinNumbers(bool *aValid=nullptr) const
wxString GetCanonicalElectricalTypeName() const
const wxString & GetShownName() const
const wxString & GetShownNumber() const
const wxString & GetFileName() const
TITLE_BLOCK & GetTitleBlock()
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetSheetsWithinPath(std::vector< SCH_SHEET_PATH > &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Variant information for a schematic symbol.
std::optional< LIB_ID > m_SymbolOverride
Alternate library symbol to substitute for the base symbol in this variant, if any.
bool UseLibIdLookup() const
wxString GetSchSymbolLibraryName() const
const wxString GetFootprintFieldText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
wxString GetShownDescription(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
std::unordered_set< wxString > GetComponentClassNames(const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
Return the component classes this symbol belongs in.
const LIB_ID & GetLibId() const override
LIB_SYMBOL * GetVariantLibSymbol(const wxString &aVariantName, const SCH_SHEET_PATH &aPath) const
Resolve the alternate library symbol for a given variant.
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
const wxString GetValue(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const override
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
int GetUnitCount() const override
Return the number of units per package of the symbol.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
wxString GetFieldText(const SCH_FIELD *aField, const wxString &aFieldName, const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
const wxString & GetCompany() const
const wxString & GetRevision() const
const wxString & GetDate() const
const wxString & GetComment(int aIdx) const
const wxString & GetTitle() const
std::map< wxString, wxString > m_Fields
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
void AddAttribute(const wxString &aName, const wxString &aValue) override
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
std::function< bool(const SCH_SYMBOL *, const SCH_SHEET_PATH &)> EXPORT_EXCLUSION
An abstract class used for the netlist exporters that Eeschema supports.
static bool sortPinsByNumber(SCH_PIN *aPin1, SCH_PIN *aPin2)
PGM_BASE & Pgm()
The global program "get" accessor.
static const std::vector< std::string > filters
Class to handle a set of SCH_ITEMs.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
wxString UnescapeString(const wxString &aSource)
wxString GetISO8601CurrentDateTime()
std::vector< wxString > m_pinNumbers
One refdes -> net membership row collected from the NETDEF section.
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
const SHAPE_LINE_CHAIN chain
wxLogTrace helper definitions.