KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netlist_exporter_xml.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2013 jp.charras at wanadoo.fr
5 * Copyright (C) 2013-2017 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
23
24#include <algorithm>
25#include <build_version.h>
26#include <gal/color4d.h>
27#include <common.h> // for ExpandTextVars
28#include <sch_base_frame.h>
29#include <sch_group.h>
30#include <sch_sheet.h>
31#include <string_utils.h>
32#include <connection_graph.h>
33#include <pgm_base.h>
34#include <core/kicad_algo.h>
35#include <wx/wfstream.h>
36#include <xnode.h> // also nests: <wx/xml/xml.h>
37#include <json_common.h>
38#include <project_sch.h>
41#include <sch_rule_area.h>
42#include <trace_helpers.h>
43
44#include <map>
45#include <optional>
46#include <set>
48#include <sch_sheet_path.h>
49
50static bool sortPinsByNumber( SCH_PIN* aPin1, SCH_PIN* aPin2 );
51
52bool NETLIST_EXPORTER_XML::writeNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
53 REPORTER& aReporter )
54{
55 // output the XML format netlist.
56
57 // declare the stream ourselves to use the buffered FILE api
58 // instead of letting wx use the syscall variant
59 wxFFileOutputStream stream( aOutFileName );
60
61 if( !stream.IsOk() )
62 return false;
63
64 wxXmlDocument xdoc;
65 xdoc.SetRoot( makeRoot( GNL_ALL | aNetlistOptions ) );
66
67 return xdoc.Save( stream, 2 /* indent bug, today was ignored by wxXml lib */ );
68}
69
70
72{
73 XNODE* xroot = node( wxT( "export" ) );
74
75 xroot->AddAttribute( wxT( "version" ), wxT( "E" ) );
76
77 if( aCtl & GNL_HEADER )
78 {
79 // add the "design" header
80 xroot->AddChild( makeDesignHeader() );
81 }
82
83 if( aCtl & GNL_SYMBOLS )
84 {
85 xroot->AddChild( makeSymbols( aCtl ) );
86
87 if( aCtl & GNL_OPT_KICAD )
88 {
89 xroot->AddChild( makeGroups() );
90 xroot->AddChild( makeVariants() );
91 }
92 }
93
94 if( aCtl & GNL_PARTS )
95 xroot->AddChild( makeLibParts() );
96
97 if( aCtl & GNL_LIBRARIES )
98 {
99 // must follow makeGenericLibParts()
100 xroot->AddChild( makeLibraries() );
101 }
102
103 if( aCtl & GNL_NETS )
104 {
105 xroot->AddChild( makeListOfNets( aCtl ) );
106
107 // Net chains are a KiCad-internal extension that is not part of the public XML
108 // netlist schema (version "E"). Emit them only for the KiCad-internal consumer
109 // (eeschema -> pcbnew via NETLIST_EXPORTER_KICAD) so that generic XML, KiCost and
110 // other schema-validating tools do not see an unexpected element.
111 if( aCtl & GNL_OPT_KICAD )
112 {
113 if( XNODE* xchains = makeNetChains() )
114 xroot->AddChild( xchains );
115 }
116 }
117
118 return xroot;
119}
120
121
123
124
126 const SCH_SHEET_LIST& aSheetList )
127{
128 wxString value;
129 wxString footprint;
130 wxString datasheet;
131 wxString description;
132 wxString candidate;
133 nlohmann::ordered_map<wxString, wxString> fields;
134
135 if( aSymbol->GetUnitCount() > 1 )
136 {
137 // Sadly, each unit of a symbol can have its own unique fields. This
138 // block finds the unit with the lowest number having a non blank field
139 // value and records it. Therefore user is best off setting fields
140 // into only the first unit. But this scavenger algorithm will find
141 // any non blank fields in all units and use the first non-blank field
142 // for each unique field name.
143
144 wxString ref = aSymbol->GetRef( &aSheet );
145
146 // ranked by unit then UUID so the pick does not depend on visiting order
147 using SOURCE = std::pair<int, KIID>;
148
149 std::optional<SOURCE> valueSrc;
150 std::optional<SOURCE> footprintSrc;
151 std::optional<SOURCE> datasheetSrc;
152 std::optional<SOURCE> descriptionSrc;
153
154 // a blank field ranks after any text so it never hides a higher unit's value
155 std::map<wxString, std::pair<bool, SOURCE>> fieldSrcs;
156
157 auto earlier =
158 []( const SOURCE& aNew, const std::optional<SOURCE>& aOld )
159 {
160 return !aOld || aNew < *aOld;
161 };
162
163 for( const SCH_SHEET_PATH& sheet : aSheetList )
164 {
165 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
166 {
167 SCH_SYMBOL* symbol2 = static_cast<SCH_SYMBOL*>( item );
168
169 wxString ref2 = symbol2->GetRef( &sheet );
170
171 if( ref2.CmpNoCase( ref ) != 0 )
172 continue;
173
174 const SOURCE src{ symbol2->GetUnitSelection( &sheet ), symbol2->m_Uuid };
175
176 // The lowest unit number wins. User should only set fields in any one unit.
177
178 // Value
179 candidate = symbol2->GetValue( &sheet, m_resolveTextVars, m_exportVariant );
180
181 if( !candidate.IsEmpty() && earlier( src, valueSrc ) )
182 {
183 value = candidate;
184 valueSrc = src;
185 }
186
187 // Footprint
188 candidate = symbol2->GetFootprintFieldText( &sheet, m_resolveTextVars, m_exportVariant );
189
190 if( !candidate.IsEmpty() && earlier( src, footprintSrc ) )
191 {
192 footprint = candidate;
193 footprintSrc = src;
194 }
195
196 // Datasheet
197 candidate = symbol2->GetField( FIELD_T::DATASHEET )->GetShownText( &sheet, m_resolveTextVars,
199
200 if( !candidate.IsEmpty() && earlier( src, datasheetSrc ) )
201 {
202 datasheet = candidate;
203 datasheetSrc = src;
204 }
205
206 // Description
207 candidate = symbol2->GetField( FIELD_T::DESCRIPTION )->GetShownText( &sheet, m_resolveTextVars,
209
210 if( !candidate.IsEmpty() && earlier( src, descriptionSrc ) )
211 {
212 description = candidate;
213 descriptionSrc = src;
214 }
215
216 // All non-mandatory fields
217 for( SCH_FIELD& field : symbol2->GetFields() )
218 {
219 if( field.IsMandatory() || field.IsPrivate() )
220 continue;
221
222 candidate = field.GetShownText( &sheet, m_resolveTextVars, m_exportVariant );
223
224 const std::pair<bool, SOURCE> rank{ candidate.IsEmpty(), src };
225 auto known = fieldSrcs.find( field.GetName() );
226
227 if( known == fieldSrcs.end() || rank < known->second )
228 {
229 fields[field.GetName()] = candidate;
230 fieldSrcs.insert_or_assign( field.GetName(), rank );
231 }
232 }
233 }
234 }
235 }
236 else
237 {
238 value = aSymbol->GetValue( &aSheet, m_resolveTextVars, m_exportVariant );
239 footprint = aSymbol->GetFootprintFieldText( &aSheet, m_resolveTextVars, m_exportVariant );
240
241 SCH_FIELD* datasheetField = aSymbol->GetField( FIELD_T::DATASHEET );
242 SCH_FIELD* descriptionField = aSymbol->GetField( FIELD_T::DESCRIPTION );
243
244 datasheet = datasheetField->GetShownText( &aSheet, m_resolveTextVars, m_exportVariant );
245 description = descriptionField->GetShownText( &aSheet, m_resolveTextVars, m_exportVariant );
246
247 for( SCH_FIELD& field : aSymbol->GetFields() )
248 {
249 if( field.IsMandatory() || field.IsPrivate() )
250 continue;
251
252 fields[field.GetName()] = field.GetShownText( &aSheet, m_resolveTextVars, m_exportVariant );
253 }
254 }
255
258 fields[GetDefaultFieldName( FIELD_T::DESCRIPTION, UNTRANSLATED )] = description;
259
260 // Do not output field values blank in netlist:
261 if( value.size() )
262 aNode->AddChild( node( wxT( "value" ), UnescapeString( value ) ) );
263 else // value field always written in netlist
264 aNode->AddChild( node( wxT( "value" ), wxT( "~" ) ) );
265
266 if( footprint.size() )
267 aNode->AddChild( node( wxT( "footprint" ), UnescapeString( footprint ) ) );
268
269 if( datasheet.size() )
270 aNode->AddChild( node( wxT( "datasheet" ), UnescapeString( datasheet ) ) );
271
272 if( description.size() )
273 aNode->AddChild( node( wxT( "description" ), UnescapeString( description ) ) );
274
275 XNODE* xfields;
276 aNode->AddChild( xfields = node( wxT( "fields" ) ) );
277
278 for( const auto& [ fieldName, fieldValue ] : fields )
279 {
280 XNODE* xfield = node( wxT( "field" ), UnescapeString( fieldValue ) );
281 xfield->AddAttribute( wxT( "name" ), UnescapeString( fieldName ) );
282 xfields->AddChild( xfield );
283 }
284}
285
286
288{
289 XNODE* xcomps = node( wxT( "components" ) );
290
292 m_libParts.clear();
294
295 const bool forBOM = aCtl & GNL_OPT_BOM;
296 const bool forBoard = aCtl & GNL_OPT_KICAD;
297 const wxString currentVariant = m_schematic->GetCurrentVariant();
298
299 // Do not use exportVariant for determininig whether or not to output a symbol. It
300 // will be blank when exporting to PCBNew.
301 const EXPORT_EXCLUSION excluded =
302 [&]( const SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSheet )
303 {
304 if( forBOM && ( aSheet.GetExcludedFromBOM( currentVariant )
305 || aSymbol->ResolveExcludedFromBOM( &aSheet, currentVariant ) ) )
306 {
307 return true;
308 }
309
310 return forBoard && ( aSheet.GetExcludedFromBoard( currentVariant )
311 || aSymbol->ResolveExcludedFromBoard( &aSheet, currentVariant ) );
312 };
313
314 SCH_SHEET_PATH currentSheet = m_schematic->CurrentSheet();
315 SCH_SHEET_LIST sheetList = m_exportSheets;
316
317 // Output is xml, so there is no reason to remove spaces from the field values.
318 // And XML element names need not be translated to various languages.
319
320 for( const SCH_SHEET_PATH& sheet : sheetList )
321 {
322 // Change schematic CurrentSheet in each iteration to allow hierarchical
323 // resolution of text variables in sheet fields.
324 m_schematic->SetCurrentSheet( sheet );
325
326 auto cmp =
327 [&sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b )
328 {
329 return ( StrNumCmp( a->GetRef( &sheet, false ),
330 b->GetRef( &sheet, false ), CMP_T::IGNORE_CASE ) < 0 );
331 };
332
333 std::set<SCH_SYMBOL*, decltype( cmp )> ordered_symbols( cmp );
334 std::multiset<SCH_SYMBOL*, decltype( cmp )> extra_units( cmp );
335
336 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
337 {
338 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
339
340 // An excluded unit must not stand for its package, or the included units go with it
341 if( excluded( symbol, sheet ) )
342 continue;
343
344 auto test = ordered_symbols.insert( symbol );
345
346 if( !test.second )
347 {
348 if( ( *( test.first ) )->m_Uuid > symbol->m_Uuid )
349 {
350 extra_units.insert( *( test.first ) );
351 ordered_symbols.erase( test.first );
352 ordered_symbols.insert( symbol );
353 }
354 else
355 {
356 extra_units.insert( symbol );
357 }
358 }
359 }
360
361 for( EDA_ITEM* item : ordered_symbols )
362 {
363 SCH_SYMBOL* symbol = findNextSymbol( item, sheet, excluded );
364
365 if( !symbol )
366 continue;
367
368 // Output the symbol's elements in order of expected access frequency. This may
369 // not always look best, but it will allow faster execution under XSL processing
370 // systems which do sequential searching within an element.
371
372 XNODE* xcomp; // current symbol being constructed
373 xcomps->AddChild( xcomp = node( wxT( "comp" ) ) );
374
375 xcomp->AddAttribute( wxT( "ref" ), symbol->GetRef( &sheet ) );
376 addSymbolFields( xcomp, symbol, sheet, sheetList );
377
378 XNODE* xlibsource;
379 xcomp->AddChild( xlibsource = node( wxT( "libsource" ) ) );
380
381 // "logical" library name, which is in anticipation of a better search algorithm
382 // for parts based on "logical_lib.part" and where logical_lib is merely the library
383 // name minus path and extension.
384 wxString libName;
385 wxString partName;
386
387 if( symbol->UseLibIdLookup() )
388 {
389 libName = symbol->GetLibId().GetUniStringLibNickname();
390 partName = symbol->GetLibId().GetUniStringLibItemName();
391 }
392 else
393 {
394 partName = symbol->GetSchSymbolLibraryName();
395 }
396
397 xlibsource->AddAttribute( wxT( "lib" ), libName );
398
399 // We only want the symbol name, not the full LIB_ID.
400 xlibsource->AddAttribute( wxT( "part" ), partName );
401
402 xlibsource->AddAttribute( wxT( "description" ), symbol->GetShownDescription( m_resolveTextVars ) );
403
404 /* Add the symbol properties. */
405 XNODE* xproperty;
406
407 std::vector<SCH_FIELD>& fields = symbol->GetFields();
408
409 for( SCH_FIELD& field : fields )
410 {
411 if( field.IsMandatory() || field.IsPrivate() )
412 continue;
413
414 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
415 xproperty->AddAttribute( wxT( "name" ), field.GetUntranslatedName() );
416
417 xproperty->AddAttribute( wxT( "value" ), field.GetShownText( &sheet, m_resolveTextVars,
418 m_exportVariant ) );
419 }
420
421 for( const SCH_FIELD& sheetField : sheet.Last()->GetFields() )
422 {
423 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
424 xproperty->AddAttribute( wxT( "name" ), sheetField.GetUntranslatedName() );
425
426 xproperty->AddAttribute( wxT( "value" ), sheetField.GetShownText( &sheet, m_resolveTextVars,
427 m_exportVariant ) );
428 }
429
430 const bool baseExcludedFromBOM = symbol->ResolveExcludedFromBOM( &sheet ) || sheet.GetExcludedFromBOM();
431 const bool baseExcludedFromSim = symbol->ResolveExcludedFromSim( &sheet ) || sheet.GetExcludedFromSim();
432
433 if( symbol->ResolveExcludedFromBOM( &sheet, m_exportVariant )
434 || sheet.GetExcludedFromBOM( m_exportVariant ) )
435 {
436 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
437 xproperty->AddAttribute( wxT( "name" ), wxT( "exclude_from_bom" ) );
438 }
439
440 if( symbol->ResolveExcludedFromSim( &sheet, m_exportVariant )
441 || sheet.GetExcludedFromSim( m_exportVariant ) )
442 {
443 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
444 xproperty->AddAttribute( wxT( "name" ), wxT( "exclude_from_sim" ) );
445 }
446
447 if( symbol->ResolveExcludedFromBoard( &sheet, m_exportVariant )
448 || sheet.GetExcludedFromBoard( m_exportVariant ) )
449 {
450 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
451 xproperty->AddAttribute( wxT( "name" ), wxT( "exclude_from_board" ) );
452 }
453
454 const bool baseExcludedFromPosFiles = symbol->ResolveExcludedFromPosFiles( &sheet );
455
456 if( symbol->ResolveExcludedFromPosFiles( &sheet, m_exportVariant ) )
457 {
458 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
459 xproperty->AddAttribute( wxT( "name" ), wxT( "exclude_from_pos_files" ) );
460 }
461
462 const bool baseDnp = symbol->ResolveDNP( &sheet ) || sheet.GetDNP();
463
464 if( symbol->ResolveDNP( &sheet, m_exportVariant ) || sheet.GetDNP( m_exportVariant ) )
465 {
466 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
467 xproperty->AddAttribute( wxT( "name" ), wxT( "dnp" ) );
468 }
469
470 // Iterate all variants in the schematic, not just those in the symbol instance,
471 // because a sheet can have variant-specific attributes even if the symbol does not.
472 const std::set<wxString>& variantNames = m_schematic->GetVariantNames();
473
474 // Differences against the base design, which only the board netlist still reports.
475 if( ( aCtl & GNL_OPT_KICAD ) && !variantNames.empty() )
476 {
477 XNODE* xvariants = nullptr;
478
479 for( const auto& variantName : variantNames )
480 {
481 XNODE* xvariant = nullptr;
482
483 auto addToVariant =
484 [this, &xvariant, &variantName]( XNODE* child ) -> void
485 {
486 if( !child )
487 return;
488
489 if( !xvariant )
490 {
491 xvariant = node( wxT( "variant" ) );
492 xvariant->AddAttribute( wxT( "name" ), variantName );
493 }
494 xvariant->AddChild( child );
495 };
496
497 auto addBinaryProp =
498 [this, &addToVariant]( wxString const& name, bool base, bool effective ) -> void
499 {
500 if( base == effective )
501 return;
502
503 XNODE* xvarprop = node( wxT( "property" ) );
504 xvarprop->AddAttribute( wxT( "name" ), name );
505 xvarprop->AddAttribute( wxT( "value" ), effective ? wxT( "1" ) : wxT( "0" ) );
506 addToVariant( xvarprop );
507 };
508
509 bool effectiveDnp = symbol->ResolveDNP( &sheet, variantName ) || sheet.GetDNP( variantName );
510 addBinaryProp( wxT( "dnp" ), baseDnp, effectiveDnp );
511
512 bool effectiveExcludedFromBOM = symbol->ResolveExcludedFromBOM( &sheet, variantName )
513 || sheet.GetExcludedFromBOM( variantName );
514 addBinaryProp( wxT( "exclude_from_bom" ), baseExcludedFromBOM, effectiveExcludedFromBOM );
515
516 bool effectiveExcludedFromSim = symbol->ResolveExcludedFromSim( &sheet, variantName )
517 || sheet.GetExcludedFromSim( variantName );
518 addBinaryProp( wxT( "exclude_from_sim" ), baseExcludedFromSim, effectiveExcludedFromSim );
519
520 bool effectiveExcludedFromPosFiles = symbol->ResolveExcludedFromPosFiles( &sheet, variantName );
521 addBinaryProp( wxT( "exclude_from_pos_files" ), baseExcludedFromPosFiles,
522 effectiveExcludedFromPosFiles );
523
524 SCH_SYMBOL_INSTANCE instance;
525 const SCH_SYMBOL_VARIANT* variant = nullptr;
526
527 if( symbol->GetInstance( instance, sheet.Path() ) && instance.m_Variants.contains( variantName ) )
528 variant = &instance.m_Variants.at( variantName );
529
530 if( variant && variant->m_SymbolOverride )
531 {
532 XNODE* xprop = node( wxT( "property" ) );
533 xprop->AddAttribute( wxT( "name" ), wxT( "symbol_override" ) );
534 xprop->AddAttribute( wxT( "value" ), variant->m_SymbolOverride->Format() );
535 addToVariant( xprop );
536 }
537
538 if( variant && ( !variant->m_Fields.empty() || variant->m_SymbolOverride ) )
539 {
540 XNODE* xfields = nullptr;
541
542 for( const auto& [fieldName, fieldValue] : variant->m_Fields )
543 {
544 const wxString baseValue = symbol->GetFieldText( fieldName, &sheet, wxEmptyString );
545
546 if( fieldValue == baseValue )
547 continue;
548
549 if( !xfields )
550 xfields = node( wxT( "fields" ) );
551
552 wxString resolvedValue = fieldValue;
553
555 resolvedValue = symbol->ResolveText( fieldValue, &sheet );
556
557 XNODE* xfield = node( wxT( "field" ), UnescapeString( resolvedValue ) );
558 xfield->AddAttribute( wxT( "name" ), UnescapeString( fieldName ) );
559 xfields->AddChild( xfield );
560 }
561
562 // Emit fields resolved from the alternate library symbol where the
563 // value differs from the base symbol. Explicit overrides in
564 // variant->m_Fields were already handled above.
565 if( variant->m_SymbolOverride )
566 {
567 for( const SCH_FIELD& baseField : symbol->GetFields() )
568 {
569 const wxString& fieldName = baseField.GetName();
570
571 if( variant->m_Fields.contains( fieldName ) )
572 continue;
573
574 const wxString baseValue = symbol->GetFieldText( fieldName, &sheet, wxEmptyString );
575 const wxString variantValue = symbol->GetFieldText( fieldName, &sheet, variantName );
576
577 if( variantValue == baseValue )
578 continue;
579
580 if( !xfields )
581 xfields = node( wxT( "fields" ) );
582
583 wxString resolvedValue = variantValue;
584
586 resolvedValue = symbol->ResolveText( variantValue, &sheet );
587
588 XNODE* xfield = node( wxT( "field" ), UnescapeString( resolvedValue ) );
589 xfield->AddAttribute( wxT( "name" ), UnescapeString( baseField.GetUntranslatedName() ) );
590 xfields->AddChild( xfield );
591 }
592
593 // Emit fields that exist only on the alternate library symbol so the
594 // netlist reflects the full atomic part, not just the base field set.
595 if( LIB_SYMBOL* altSymbol = symbol->GetVariantLibSymbol( variantName, sheet ) )
596 {
597 std::vector<SCH_FIELD*> altFields;
598 altSymbol->GetFields( altFields );
599
600 for( const SCH_FIELD* altField : altFields )
601 {
602 const wxString& fieldName = altField->GetName();
603
604 if( symbol->GetField( fieldName )
605 || variant->m_Fields.contains( fieldName )
606 || altField->GetText().IsEmpty() )
607 {
608 continue;
609 }
610
611 if( !xfields )
612 xfields = node( wxT( "fields" ) );
613
614 wxString resolvedValue = altField->GetText();
615
617 resolvedValue = symbol->ResolveText( resolvedValue, &sheet );
618
619 XNODE* xfield = node( wxT( "field" ), UnescapeString( resolvedValue ) );
620 xfield->AddAttribute( wxT( "name" ), UnescapeString( fieldName ) );
621 xfields->AddChild( xfield );
622 }
623 }
624 }
625
626 addToVariant( xfields );
627 }
628
629 if( xvariant )
630 {
631 if( !xvariants )
632 xvariants = node( wxT( "variants" ) );
633
634 xvariants->AddChild( xvariant );
635 }
636 }
637
638 if( xvariants )
639 xcomp->AddChild( xvariants );
640 }
641
642 if( const std::unique_ptr<LIB_SYMBOL>& part = symbol->GetLibSymbolRef() )
643 {
644 if( part->GetKeyWords().size() )
645 {
646 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
647 xproperty->AddAttribute( wxT( "name" ), wxT( "ki_keywords" ) );
648 xproperty->AddAttribute( wxT( "value" ), part->GetKeyWords() );
649 }
650
651 if( !part->GetFPFilters().IsEmpty() )
652 {
653 wxString filters;
654
655 for( const wxString& filter : part->GetFPFilters() )
656 filters += ' ' + filter;
657
658 xcomp->AddChild( xproperty = node( wxT( "property" ) ) );
659 xproperty->AddAttribute( wxT( "name" ), wxT( "ki_fp_filters" ) );
660 xproperty->AddAttribute( wxT( "value" ), filters.Trim( false ) );
661 }
662
663 if( part->GetDuplicatePinNumbersAreJumpers() )
664 xcomp->AddChild( node( wxT( "duplicate_pin_numbers_are_jumpers" ), wxT( "1" ) ) );
665
666 const JUMPER_GROUP_SET& jumperGroups = part->JumperPinGroups();
667
668 if( !jumperGroups.IsEmpty() )
669 {
670 XNODE* groupNode;
671 xcomp->AddChild( xproperty = node( wxT( "jumper_pin_groups" ) ) );
672
673 for( const JUMPER_GROUP& group : jumperGroups.GetAll() )
674 {
675 xproperty->AddChild( groupNode = node( wxT( "group" ) ) );
676
677 for( const wxString& pinName : group.GetNames() )
678 groupNode->AddChild( node( wxT( "pin" ), pinName ) );
679 }
680 }
681 }
682
683 XNODE* xsheetpath;
684 xcomp->AddChild( xsheetpath = node( wxT( "sheetpath" ) ) );
685
686 xsheetpath->AddAttribute( wxT( "names" ), sheet.PathHumanReadable() );
687 xsheetpath->AddAttribute( wxT( "tstamps" ), sheet.PathAsString() );
688
689 // Node for component class
690 std::vector<wxString> compClassNames = getComponentClassNamesForAllSymbolUnits( symbol, sheet, sheetList );
691
692 if( compClassNames.size() > 0 )
693 {
694 XNODE* xcompclasslist;
695 xcomp->AddChild( xcompclasslist = node( wxT( "component_classes" ) ) );
696
697 for( const wxString& compClass : compClassNames )
698 xcompclasslist->AddChild( node( wxT( "class" ), UnescapeString( compClass ) ) );
699 }
700
701 XNODE* xunits; // Node for extra units
702 xcomp->AddChild( xunits = node( wxT( "tstamps" ) ) );
703
704 auto range = extra_units.equal_range( symbol );
705 wxString uuid;
706
707 // Output a series of children with all UUIDs associated with the REFDES
708 for( auto it = range.first; it != range.second; ++it )
709 {
710 uuid = ( *it )->m_Uuid.AsString();
711
712 // Add a space between UUIDs, if not in KICAD mode (i.e.
713 // using wxXmlDocument::Save()). KICAD MODE has its own XNODE::Format function.
714 if( !( aCtl & GNL_OPT_KICAD ) ) // i.e. for .xml format
715 uuid += ' ';
716
717 xunits->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, uuid ) );
718 }
719
720 // Output the primary UUID
721 uuid = symbol->m_Uuid.AsString();
722 xunits->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, uuid ) );
723
724 // Emit unit information (per-unit name and pins) after tstamps
725 XNODE* xunitInfo;
726 xcomp->AddChild( xunitInfo = node( wxT( "units" ) ) );
727
728 const std::unique_ptr<LIB_SYMBOL>& libSym = symbol->GetLibSymbolRef();
729
730 if( libSym )
731 {
732 // A multi-unit symbol can resolve to a different lib symbol per placed unit
733 // after unit-specific edits. For instane, if you have units A B C in a multi-unit
734 // symbol, and you edit only unit B, unit B will point to new, modified lib symbol
735 // but A and C will point to the original lib symbol.
736 //
737 // Export the unit metadata from the actual unit instances's lib symbols so the PCB
738 // footprint metadata matches during backannotation, which always works per unit.
739 //
740 // However, the user isn't required to place all units, so keep a fallback default unit info.
741 const std::vector<LIB_SYMBOL::UNIT_PIN_INFO>& defaultUnitInfo = libSym->GetUnitPinInfo();
742 std::map<int, SCH_SYMBOL*> symbolByUnit;
743
744 auto addUnitSymbol =
745 [&]( SCH_SYMBOL* aUnitSymbol )
746 {
747 if( !aUnitSymbol )
748 return;
749
750 int unit = aUnitSymbol->GetUnitSelection( &sheet );
751
752 if( unit > 0 )
753 symbolByUnit.try_emplace( unit, aUnitSymbol );
754 };
755
756 addUnitSymbol( symbol );
757
758 auto extraUnitRange = extra_units.equal_range( symbol );
759
760 // Collect the other placed units that share this reference so each unit number
761 // can be resolved back to the specific SCH_SYMBOL instance on the sheet.
762 for( auto it = extraUnitRange.first; it != extraUnitRange.second; ++it )
763 addUnitSymbol( *it );
764
765 // Emit every unit slot from the default library symbol, but override that slot's
766 // metadata with the placed unit's resolved library symbol when one exists.
767 for( size_t unitIdx = 0; unitIdx < defaultUnitInfo.size(); ++unitIdx )
768 {
769 LIB_SYMBOL::UNIT_PIN_INFO unitInfo = defaultUnitInfo[unitIdx];
770 auto symbolIt = symbolByUnit.find( unitIdx + 1 );
771
772 if( symbolIt != symbolByUnit.end() )
773 {
774 const std::unique_ptr<LIB_SYMBOL>& unitLibSym = symbolIt->second->GetLibSymbolRef();
775
776 if( unitLibSym )
777 {
778 const std::vector<LIB_SYMBOL::UNIT_PIN_INFO>& unitSpecificInfo =
779 unitLibSym->GetUnitPinInfo();
780
781 if( unitIdx < unitSpecificInfo.size() )
782 unitInfo = unitSpecificInfo[unitIdx];
783 }
784 }
785
786 XNODE* xunit;
787 xunitInfo->AddChild( xunit = node( wxT( "unit" ) ) );
788 xunit->AddAttribute( wxT( "name" ), unitInfo.m_unitName );
789
790 XNODE* xpins;
791 xunit->AddChild( xpins = node( wxT( "pins" ) ) );
792
793 for( const wxString& number : unitInfo.m_pinNumbers )
794 {
795 XNODE* xpin;
796 xpins->AddChild( xpin = node( wxT( "pin" ) ) );
797 xpin->AddAttribute( wxT( "num" ), number );
798 }
799 }
800 }
801 }
802 }
803
804 m_schematic->SetCurrentSheet( currentSheet );
805
806 return xcomps;
807}
808
809
811{
812 XNODE* xcomps = node( wxT( "groups" ) );
813
815 // Do not clear m_libParts here: it is populated in makeSymbols() and used later by
816 // makeLibParts() to emit the libparts section for CvPcb and other consumers.
817
818 SCH_SHEET_PATH currentSheet = m_schematic->CurrentSheet();
819 SCH_SHEET_LIST sheetList = m_exportSheets;
820 std::map<SCH_SCREEN*, int> screenVisits;
821
822 for( const SCH_SHEET_PATH& sheet : sheetList )
823 screenVisits[sheet.LastScreen()]++;
824
825 for( const SCH_SHEET_PATH& sheet : sheetList )
826 {
827 // Change schematic CurrentSheet in each iteration to allow hierarchical
828 // resolution of text variables in sheet fields.
829 m_schematic->SetCurrentSheet( sheet );
830
831 wxString instancePrefix = sheet.PathAsString();
832
833 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_GROUP_T ) )
834 {
835 SCH_GROUP* group = static_cast<SCH_GROUP*>( item );
836 wxString groupName = group->GetName();
837
838 if( screenVisits[sheet.LastScreen()] > 1 )
839 groupName = wxString::Format( wxT( "%s (%s)" ), groupName, sheet.PathHumanReadable() );
840
841 XNODE* xgroup; // current symbol being constructed
842 xcomps->AddChild( xgroup = node( wxT( "group" ) ) );
843
844 xgroup->AddAttribute( wxT( "name" ), groupName );
845 xgroup->AddAttribute( wxT( "uuid" ), instancePrefix + group->m_Uuid.AsString() );
846 xgroup->AddAttribute( wxT( "lib_id" ), group->GetDesignBlockLibId().Format() );
847
848 XNODE* xmembers;
849 xgroup->AddChild( xmembers = node( wxT( "members" ) ) );
850
851 for( EDA_ITEM* member : group->GetItems() )
852 {
853 if( member->Type() == SCH_SYMBOL_T )
854 {
855 XNODE* xmember;
856 xmembers->AddChild( xmember = node( wxT( "member" ) ) );
857 xmember->AddAttribute( wxT( "uuid" ), instancePrefix + member->m_Uuid.AsString() );
858 }
859 else if( member->Type() == SCH_GROUP_T )
860 {
861 // Emit nested groups so the board side can rebuild the nesting.
862 XNODE* xmember;
863 xmembers->AddChild( xmember = node( wxT( "member" ) ) );
864 xmember->AddAttribute( wxT( "uuid" ), instancePrefix + member->m_Uuid.AsString() );
865 }
866 else if( member->Type() == SCH_SHEET_T )
867 {
868 SCH_SHEET_PATH subSheetPath = sheet;
869 std::vector<SCH_SHEET_PATH> descendantSheets;
870
871 subSheetPath.push_back( static_cast<SCH_SHEET*>( member ) );
872 sheetList.GetSheetsWithinPath( descendantSheets, subSheetPath );
873
874 for( const SCH_SHEET_PATH& descendantSheet : descendantSheets )
875 {
876 for( SCH_ITEM* descendantItem : descendantSheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
877 {
878 XNODE* xmember;
879 xmembers->AddChild( xmember = node( wxT( "member" ) ) );
880 xmember->AddAttribute( wxT( "uuid" ),
881 descendantSheet.PathAsString() + descendantItem->m_Uuid.AsString() );
882 }
883 }
884 }
885 }
886 }
887 }
888
889 m_schematic->SetCurrentSheet( currentSheet );
890
891 return xcomps;
892}
893
894
896{
897 XNODE* xvariants = node( wxT( "variants" ) );
898
899 std::set<wxString> variantNames = m_schematic->GetVariantNames();
900
901 for( const wxString& variantName : variantNames )
902 {
903 XNODE* xvariant;
904 xvariants->AddChild( xvariant = node( wxT( "variant" ) ) );
905 xvariant->AddAttribute( wxT( "name" ), variantName );
906
907 wxString description = m_schematic->GetVariantDescription( variantName );
908
909 if( !description.IsEmpty() )
910 xvariant->AddAttribute( wxT( "description" ), description );
911 }
912
913 return xvariants;
914}
915
916
918 SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSymbolSheet, const SCH_SHEET_LIST& aSheetList )
919{
920 std::vector<SCH_SHEET_PATH> symbolSheets;
921 symbolSheets.push_back( aSymbolSheet );
922
923 std::unordered_set<wxString> compClassNames = aSymbol->GetComponentClassNames( &aSymbolSheet, m_exportVariant );
924 int primaryUnit = aSymbol->GetUnitSelection( &aSymbolSheet );
925
926 if( aSymbol->GetUnitCount() > 1 )
927 {
928 const wxString ref = aSymbol->GetRef( &aSymbolSheet );
929
930 for( const SCH_SHEET_PATH& sheet : aSheetList )
931 {
932 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
933 {
934 const SCH_SYMBOL* symbol2 = static_cast<SCH_SYMBOL*>( item );
935
936 wxString ref2 = symbol2->GetRef( &sheet );
937 const int otherUnit = symbol2->GetUnitSelection( &sheet );
938
939 if( ref2.CmpNoCase( ref ) != 0 )
940 continue;
941
942 if( otherUnit == primaryUnit )
943 continue;
944
945 symbolSheets.push_back( sheet );
946
947 std::unordered_set<wxString> otherClassNames = symbol2->GetComponentClassNames( &sheet,
949 compClassNames.insert( otherClassNames.begin(), otherClassNames.end() );
950 }
951 }
952 }
953
954 // Add sheet-level component classes
955 for( auto& [sheetPath, sheetCompClasses] : m_sheetComponentClasses )
956 {
957 for( SCH_SHEET_PATH& symbolSheetPath : symbolSheets )
958 {
959 if( symbolSheetPath.IsContainedWithin( sheetPath ) )
960 compClassNames.insert( sheetCompClasses.begin(), sheetCompClasses.end() );
961 }
962 }
963
964 std::vector<wxString> sortedCompClassNames( compClassNames.begin(), compClassNames.end() );
965 std::sort( sortedCompClassNames.begin(), sortedCompClassNames.end(),
966 []( const wxString& str1, const wxString& str2 )
967 {
968 return str1.Cmp( str2 ) < 0;
969 } );
970
971 return sortedCompClassNames;
972}
973
974
976{
977 SCH_SCREEN* screen;
978 XNODE* xdesign = node( wxT( "design" ) );
979 XNODE* xtitleBlock;
980 XNODE* xsheet;
981 XNODE* xcomment;
982 XNODE* xtextvar;
983 wxString sheetTxt;
984 wxFileName sourceFileName;
985
986 // the root sheet is a special sheet, call it source
987 xdesign->AddChild( node( wxT( "source" ), m_schematic->GetFileName() ) );
988
989 xdesign->AddChild( node( wxT( "date" ), GetISO8601CurrentDateTime() ) );
990
991 // which Eeschema tool
992 xdesign->AddChild( node( wxT( "tool" ), wxT( "Eeschema " ) + GetBuildVersion() ) );
993
994 const std::map<wxString, wxString>& properties = m_schematic->Project().GetTextVars();
995
996 for( const std::pair<const wxString, wxString>& prop : properties )
997 {
998 xdesign->AddChild( xtextvar = node( wxT( "textvar" ), prop.second ) );
999 xtextvar->AddAttribute( wxT( "name" ), prop.first );
1000 }
1001
1002 /*
1003 * Export the sheets information
1004 */
1005 unsigned sheetIndex = 1; // Human readable index
1006
1007 for( const SCH_SHEET_PATH& sheet : m_exportSheets )
1008 {
1009 screen = sheet.LastScreen();
1010
1011 xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) );
1012
1013 // get the string representation of the sheet index number.
1014 sheetTxt.Printf( wxT( "%u" ), sheetIndex++ );
1015 xsheet->AddAttribute( wxT( "number" ), sheetTxt );
1016 xsheet->AddAttribute( wxT( "name" ), sheet.PathHumanReadable() );
1017 xsheet->AddAttribute( wxT( "tstamps" ), sheet.PathAsString() );
1018
1019 TITLE_BLOCK tb = screen->GetTitleBlock();
1020 PROJECT* prj = &m_schematic->Project();
1021
1022 xsheet->AddChild( xtitleBlock = node( wxT( "title_block" ) ) );
1023
1024 xtitleBlock->AddChild( node( wxT( "title" ), ExpandTextVars( tb.GetTitle(), prj, m_resolveTextVars ) ) );
1025 xtitleBlock->AddChild( node( wxT( "company" ), ExpandTextVars( tb.GetCompany(), prj, m_resolveTextVars ) ) );
1026 xtitleBlock->AddChild( node( wxT( "rev" ), ExpandTextVars( tb.GetRevision(), prj, m_resolveTextVars ) ) );
1027 xtitleBlock->AddChild( node( wxT( "date" ), ExpandTextVars( tb.GetDate(), prj, m_resolveTextVars ) ) );
1028
1029 // We are going to remove the fileName directories.
1030 sourceFileName = wxFileName( screen->GetFileName() );
1031 xtitleBlock->AddChild( node( wxT( "source" ), sourceFileName.GetFullName() ) );
1032
1033 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1034 xcomment->AddAttribute( wxT( "number" ), wxT( "1" ) );
1035 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 0 ), prj, m_resolveTextVars ) );
1036
1037 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1038 xcomment->AddAttribute( wxT( "number" ), wxT( "2" ) );
1039 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 1 ), prj, m_resolveTextVars ) );
1040
1041 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1042 xcomment->AddAttribute( wxT( "number" ), wxT( "3" ) );
1043 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 2 ), prj, m_resolveTextVars ) );
1044
1045 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1046 xcomment->AddAttribute( wxT( "number" ), wxT( "4" ) );
1047 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 3 ), prj, m_resolveTextVars ) );
1048
1049 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1050 xcomment->AddAttribute( wxT( "number" ), wxT( "5" ) );
1051 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 4 ), prj, m_resolveTextVars ) );
1052
1053 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1054 xcomment->AddAttribute( wxT( "number" ), wxT( "6" ) );
1055 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 5 ), prj, m_resolveTextVars ) );
1056
1057 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1058 xcomment->AddAttribute( wxT( "number" ), wxT( "7" ) );
1059 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 6 ), prj, m_resolveTextVars ) );
1060
1061 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1062 xcomment->AddAttribute( wxT( "number" ), wxT( "8" ) );
1063 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 7 ), prj, m_resolveTextVars ) );
1064
1065 xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
1066 xcomment->AddAttribute( wxT( "number" ), wxT( "9" ) );
1067 xcomment->AddAttribute( wxT( "value" ), ExpandTextVars( tb.GetComment( 8 ), prj, m_resolveTextVars ) );
1068 }
1069
1070 return xdesign;
1071}
1072
1073
1075{
1076 XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr
1077 LIBRARY_MANAGER& manager = Pgm().GetLibraryManager();
1078
1079 for( const wxString& libNickname : m_libraries )
1080 {
1081 XNODE* xlibrary;
1082
1083 std::optional<wxString> uri = manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libNickname );
1084
1085 if( uri )
1086 {
1087 xlibs->AddChild( xlibrary = node( wxT( "library" ) ) );
1088 xlibrary->AddAttribute( wxT( "logical" ), libNickname );
1089 xlibrary->AddChild( node( wxT( "uri" ), *uri ) );
1090 }
1091 }
1092
1093 return xlibs;
1094}
1095
1096
1098{
1099 XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr
1100 std::vector<SCH_FIELD*> fieldList;
1101
1102 m_libraries.clear();
1103
1104 for( LIB_SYMBOL* lcomp : m_libParts )
1105 {
1106 wxString libNickname = lcomp->GetLibId().GetLibNickname();;
1107
1108 // The library nickname will be empty if the cache library is used.
1109 if( !libNickname.IsEmpty() )
1110 m_libraries.insert( libNickname ); // inserts symbol's library if unique
1111
1112 XNODE* xlibpart;
1113 xlibparts->AddChild( xlibpart = node( wxT( "libpart" ) ) );
1114 xlibpart->AddAttribute( wxT( "lib" ), libNickname );
1115 xlibpart->AddAttribute( wxT( "part" ), lcomp->GetName() );
1116
1117 //----- show the important properties -------------------------
1118 if( !lcomp->GetDescription().IsEmpty() )
1119 xlibpart->AddChild( node( wxT( "description" ), lcomp->GetDescription() ) );
1120
1121 if( !lcomp->GetDatasheetField().GetText().IsEmpty() )
1122 xlibpart->AddChild( node( wxT( "docs" ), lcomp->GetDatasheetField().GetText() ) );
1123
1124 // Write the footprint list
1125 if( lcomp->GetFPFilters().GetCount() )
1126 {
1127 XNODE* xfootprints;
1128 xlibpart->AddChild( xfootprints = node( wxT( "footprints" ) ) );
1129
1130 for( unsigned i = 0; i < lcomp->GetFPFilters().GetCount(); ++i )
1131 {
1132 if( !lcomp->GetFPFilters()[i].IsEmpty() )
1133 xfootprints->AddChild( node( wxT( "fp" ), lcomp->GetFPFilters()[i] ) );
1134 }
1135 }
1136
1137 //----- show the fields here ----------------------------------
1138 fieldList.clear();
1139 lcomp->GetFields( fieldList );
1140
1141 XNODE* xfields;
1142 xlibpart->AddChild( xfields = node( "fields" ) );
1143
1144 for( const SCH_FIELD* field : fieldList )
1145 {
1146 XNODE* xfield;
1147 xfields->AddChild( xfield = node( wxT( "field" ), field->GetText() ) );
1148 xfield->AddAttribute( wxT( "name" ), field->GetUntranslatedName() );
1149 }
1150
1151 //----- show the pins here ------------------------------------
1152 // NOTE: Expand stacked-pin notation into individual pins so downstream
1153 // tools (e.g. CvPcb) see the actual number of footprint pins.
1154 std::vector<SCH_PIN*> pinList = lcomp->GetGraphicalPins( 0, 0 );
1155
1156 /*
1157 * We must erase redundant Pins references in pinList
1158 * These redundant pins exist because some pins are found more than one time when a
1159 * symbol has multiple parts per package or has 2 representations (DeMorgan conversion).
1160 * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes, and
1161 * therefore each pin appears 2 times in the list. Common pins (VCC, GND) can also be
1162 * found more than once.
1163 */
1164 sort( pinList.begin(), pinList.end(), sortPinsByNumber );
1165
1166 for( int ii = 0; ii < (int)pinList.size()-1; ii++ )
1167 {
1168 if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
1169 { // 2 pins have the same number, remove the redundant pin at index i+1
1170 pinList.erase(pinList.begin() + ii + 1);
1171 ii--;
1172 }
1173 }
1174
1175 wxLogTrace( "CVPCB_PINCOUNT",
1176 wxString::Format( "makeLibParts: lib='%s' part='%s' pinList(size)=%zu",
1177 libNickname, lcomp->GetName(), pinList.size() ) );
1178
1179 if( pinList.size() )
1180 {
1181 XNODE* pins;
1182
1183 xlibpart->AddChild( pins = node( wxT( "pins" ) ) );
1184
1185 for( unsigned i=0; i<pinList.size(); ++i )
1186 {
1187 SCH_PIN* basePin = pinList[i];
1188
1189 bool stackedValid = false;
1190 std::vector<wxString> expandedNums = basePin->GetStackedPinNumbers( &stackedValid );
1191
1192 // If stacked notation detected and valid, emit one libparts pin per expanded number.
1193 if( stackedValid && !expandedNums.empty() )
1194 {
1195 for( const wxString& num : expandedNums )
1196 {
1197 XNODE* pin;
1198 pins->AddChild( pin = node( wxT( "pin" ) ) );
1199 pin->AddAttribute( wxT( "num" ), num );
1200 pin->AddAttribute( wxT( "name" ), basePin->GetShownName() );
1201 pin->AddAttribute( wxT( "type" ), basePin->GetCanonicalElectricalTypeName() );
1202
1203 wxLogTrace( "CVPCB_PINCOUNT",
1204 wxString::Format( "makeLibParts: -> pin num='%s' name='%s' (expanded)",
1205 num, basePin->GetShownName() ) );
1206 }
1207 }
1208 else
1209 {
1210 XNODE* pin;
1211 pins->AddChild( pin = node( wxT( "pin" ) ) );
1212 pin->AddAttribute( wxT( "num" ), basePin->GetShownNumber() );
1213 pin->AddAttribute( wxT( "name" ), basePin->GetShownName() );
1214 pin->AddAttribute( wxT( "type" ), basePin->GetCanonicalElectricalTypeName() );
1215
1216 wxLogTrace( "CVPCB_PINCOUNT",
1217 wxString::Format( "makeLibParts: -> pin num='%s' name='%s'",
1218 basePin->GetShownNumber(),
1219 basePin->GetShownName() ) );
1220 }
1221
1222 // caution: construction work site here, drive slowly
1223 }
1224 }
1225 }
1226
1227 return xlibparts;
1228}
1229
1230
1232{
1233 wxString netCodeTxt;
1234 XNODE* xnets = node( wxT( "nets" ) ); // auto_ptr if exceptions ever get used.
1235 XNODE* xnet = nullptr;
1236
1237 /* output:
1238 <net code="123" name="/cfcard.sch/WAIT#" class="signal">
1239 <node ref="R23" pin="1"/>
1240 <node ref="U18" pin="12"/>
1241 </net>
1242 */
1243
1244 struct NET_NODE
1245 {
1246 NET_NODE( SCH_PIN* aPin, const SCH_SHEET_PATH& aSheet ) :
1247 m_Pin( aPin ),
1248 m_Sheet( aSheet )
1249 {}
1250
1251 SCH_PIN* m_Pin;
1252 SCH_SHEET_PATH m_Sheet;
1253 };
1254
1255 struct NET_RECORD
1256 {
1257 NET_RECORD( const wxString& aName ) :
1258 m_Name( aName ),
1259 m_HasNoConnect( false )
1260 {};
1261
1262 wxString m_Name;
1263 wxString m_Class;
1264 bool m_HasNoConnect;
1265 std::vector<NET_NODE> m_Nodes;
1266 };
1267
1268 std::vector<NET_RECORD*> nets;
1269
1270 std::shared_ptr<NET_SETTINGS> netSettings;
1271
1272 if( m_schematic )
1273 netSettings = m_schematic->Project().GetProjectFile().NetSettings();
1274
1275 for( const EXPORT_NET& net : m_exportNets )
1276 {
1277 wxString netName = ( aCtl & GNL_OPT_KICAD ) ? net.name : UnescapeString( net.name );
1278 nets.emplace_back( new NET_RECORD( netName ) );
1279 NET_RECORD* net_record = nets.back();
1280 net_record->m_HasNoConnect = net.hasNoConnect;
1281
1282 if( netSettings )
1283 {
1284 if( const auto netclass = netSettings->GetEffectiveNetClass( net.name ) )
1285 net_record->m_Class = UnescapeString( netclass->GetName() );
1286 }
1287
1288 for( const auto& [pin, sheet] : net.pins )
1289 {
1290 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1291 bool forBOM = aCtl & GNL_OPT_BOM;
1292 bool forBoard = aCtl & GNL_OPT_KICAD;
1293
1294 if( !symbol )
1295 continue;
1296
1297 if( forBOM && ( sheet.GetExcludedFromBOM( m_exportVariant )
1298 || symbol->ResolveExcludedFromBOM( &sheet, m_exportVariant ) ) )
1299 {
1300 continue;
1301 }
1302
1303 if( forBoard && ( sheet.GetExcludedFromBoard( m_exportVariant )
1304 || symbol->ResolveExcludedFromBoard( &sheet, m_exportVariant ) ) )
1305 {
1306 continue;
1307 }
1308
1309 net_record->m_Nodes.emplace_back( pin, sheet );
1310 }
1311 }
1312
1313 // Netlist ordering: Net name, then ref des, then pin name
1314 std::sort( nets.begin(), nets.end(),
1315 []( const NET_RECORD* a, const NET_RECORD*b )
1316 {
1317 return StrNumCmp( a->m_Name, b->m_Name ) < 0;
1318 } );
1319
1320 for( int i = 0; i < (int) nets.size(); ++i )
1321 {
1322 NET_RECORD* net_record = nets[i];
1323 bool added = false;
1324 XNODE* xnode;
1325
1326 // Netlist ordering: Net name, then ref des, then pin name
1327 std::sort( net_record->m_Nodes.begin(), net_record->m_Nodes.end(),
1328 []( const NET_NODE& a, const NET_NODE& b )
1329 {
1330 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
1331 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
1332
1333 if( refA == refB )
1334 return a.m_Pin->GetShownNumber() < b.m_Pin->GetShownNumber();
1335
1336 return refA < refB;
1337 } );
1338
1339 // Some duplicates can exist, for example on multi-unit parts with duplicated pins across
1340 // units. If the user connects the pins on each unit, they will appear on separate
1341 // subgraphs. Remove those here:
1342 alg::remove_duplicates( net_record->m_Nodes,
1343 []( const NET_NODE& a, const NET_NODE& b )
1344 {
1345 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
1346 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
1347
1348 return refA == refB && a.m_Pin->GetShownNumber() == b.m_Pin->GetShownNumber();
1349 } );
1350
1351 // Determine if all pins in the net are stacked (nets with only one pin are implicitly
1352 // taken to be stacked)
1353 bool allNetPinsStacked = true;
1354
1355 if( net_record->m_Nodes.size() > 1 )
1356 {
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(),
1359 [=]( NET_NODE& node )
1360 {
1361 return firstPin->GetParent() == node.m_Pin->GetParent()
1362 && firstPin->GetPosition() == node.m_Pin->GetPosition()
1363 && firstPin->GetName() == node.m_Pin->GetName();
1364 } );
1365 }
1366
1367 for( const NET_NODE& netNode : net_record->m_Nodes )
1368 {
1369 wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
1370
1371 // Skip power symbols and virtual symbols
1372 if( refText[0] == wxChar( '#' ) )
1373 continue;
1374
1375 // Emit the resolved footprint pad number(s), not the raw symbol pin number, so a
1376 // remapped pin's net lands on the right pad when the board reads this netlist
1377 // (issue #2282). Shared with the PIN_INFO path via resolvePadNumbers.
1378 std::vector<wxString> nums = resolvePadNumbers( netNode.m_Pin, netNode.m_Sheet );
1379
1380 // An unmapped pin contributes no pad, so skip it and do not open an empty net for it.
1381 if( nums.empty() )
1382 continue;
1383
1384 wxString baseName = netNode.m_Pin->GetShownName();
1385 wxString pinType = netNode.m_Pin->GetCanonicalElectricalTypeName();
1386
1387 if( !added )
1388 {
1389 netCodeTxt.Printf( wxT( "%d" ), i + 1 );
1390
1391 xnets->AddChild( xnet = node( wxT( "net" ) ) );
1392 xnet->AddAttribute( wxT( "code" ), netCodeTxt );
1393 xnet->AddAttribute( wxT( "name" ), net_record->m_Name );
1394 xnet->AddAttribute( wxT( "class" ), net_record->m_Class );
1395
1396 added = true;
1397 }
1398
1399 for( const wxString& num : nums )
1400 {
1401 xnet->AddChild( xnode = node( wxT( "node" ) ) );
1402 xnode->AddAttribute( wxT( "ref" ), refText );
1403 xnode->AddAttribute( wxT( "pin" ), num );
1404
1405 wxString fullName = baseName.IsEmpty() ? num : baseName + wxT( "_" ) + num;
1406
1407 if( !baseName.IsEmpty() || nums.size() > 1 )
1408 xnode->AddAttribute( wxT( "pinfunction" ), fullName );
1409
1410 wxString typeAttr = pinType;
1411
1412 if( net_record->m_HasNoConnect
1413 && ( net_record->m_Nodes.size() == 1 || allNetPinsStacked ) )
1414 {
1415 typeAttr += wxT( "+no_connect" );
1416 }
1417
1418 xnode->AddAttribute( wxT( "pintype" ), typeAttr );
1419 }
1420 }
1421 }
1422
1423 for( NET_RECORD* record : nets )
1424 delete record;
1425
1426 return xnets;
1427}
1428
1430{
1431 const auto& committed = m_schematic->NetChains().GetCommittedNetChains();
1432
1433 if( committed.empty() )
1434 return nullptr;
1435
1436 XNODE* xchains = node( wxT( "net_chains" ) );
1437
1438 for( const std::unique_ptr<SCH_NETCHAIN>& chain : committed )
1439 {
1440 if( !chain )
1441 continue;
1442
1443 XNODE* xchain;
1444 xchains->AddChild( xchain = node( wxT( "net_chain" ) ) );
1445 xchain->AddAttribute( wxT( "name" ), chain->GetName() );
1446
1447 if( !chain->GetNetClass().IsEmpty() )
1448 xchain->AddAttribute( wxT( "net_class" ), chain->GetNetClass() );
1449
1450 // Carry the chain's class assignment (from project's NET_SETTINGS) so
1451 // that downstream consumers of the netlist can see chain hierarchy
1452 // without having to also parse the .kicad_pro file.
1453 if( m_schematic )
1454 {
1455 PROJECT_FILE& pf = m_schematic->Project().GetProjectFile();
1456 const std::shared_ptr<NET_SETTINGS>& ns = pf.NetSettings();
1457
1458 if( ns )
1459 {
1460 wxString className = ns->GetNetChainClass( chain->GetName() );
1461
1462 if( !className.IsEmpty() )
1463 xchain->AddAttribute( wxT( "net_chain_class" ), className );
1464 }
1465 }
1466
1467 if( chain->GetColor() != COLOR4D::UNSPECIFIED )
1468 {
1469 const COLOR4D& c = chain->GetColor();
1470 xchain->AddAttribute( wxT( "color" ),
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 ) ) );
1476 }
1477
1478 XNODE* xmembers;
1479 xchain->AddChild( xmembers = node( wxT( "members" ) ) );
1480
1481 // Synthetic per-run subgraph names (__SG_*) embed run-specific subgraph codes
1482 // that do not survive a reload, and downstream consumers cannot resolve them
1483 // back to a real net. Mirror the sexpr writer's filter so the XML output is
1484 // limited to nets that have stable, user-visible names.
1485 for( const wxString& net : chain->GetNets() )
1486 {
1487 if( !SCH_NETCHAIN::IsPersistableNet( net ) )
1488 continue;
1489
1490 XNODE* xmember;
1491 xmembers->AddChild( xmember = node( wxT( "member" ) ) );
1492 xmember->AddAttribute( wxT( "net" ), net );
1493 }
1494
1495 if( !chain->GetTerminalRefDes( 0 ).IsEmpty() || !chain->GetTerminalRefDes( 1 ).IsEmpty() )
1496 {
1497 XNODE* xterms;
1498 xchain->AddChild( xterms = node( wxT( "terminal_pins" ) ) );
1499
1500 for( int i = 0; i < 2; ++i )
1501 {
1502 if( chain->GetTerminalRefDes( i ).IsEmpty() )
1503 continue;
1504
1505 XNODE* xterm;
1506 xterms->AddChild( xterm = node( wxT( "terminal_pin" ) ) );
1507 xterm->AddAttribute( wxT( "ref" ), chain->GetTerminalRefDes( i ) );
1508 xterm->AddAttribute( wxT( "pin" ), chain->GetTerminalPinNum( i ) );
1509 }
1510 }
1511 }
1512
1513 return xchains;
1514}
1515
1516
1517XNODE* NETLIST_EXPORTER_XML::node( const wxString& aName, const wxString& aTextualContent )
1518{
1519 XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );
1520
1521 if( aTextualContent.Len() > 0 ) // excludes wxEmptyString, the parameter's default value
1522 n->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
1523
1524 return n;
1525}
1526
1527
1528static bool sortPinsByNumber( SCH_PIN* aPin1, SCH_PIN* aPin2 )
1529{
1530 // return "lhs < rhs"
1531 return StrNumCmp( aPin1->GetShownNumber(), aPin2->GetShownNumber(), CMP_T::IGNORE_CASE ) < 0;
1532}
1533
1534
1536{
1538
1539 SCH_SHEET_LIST sheetList = m_exportSheets;
1540
1541 auto getComponentClassFields =
1542 [&]( const std::vector<SCH_FIELD>& fields, const SCH_SHEET_PATH* sheetPath )
1543 {
1544 std::unordered_set<wxString> componentClasses;
1545
1546 for( const SCH_FIELD& field : fields )
1547 {
1548 if( field.GetUntranslatedName() == wxT( "Component Class" ) )
1549 {
1550 if( field.GetShownText( sheetPath, m_resolveTextVars ) != wxEmptyString )
1551 componentClasses.insert( field.GetShownText( sheetPath, m_resolveTextVars ) );
1552 }
1553 }
1554
1555 return componentClasses;
1556 };
1557
1558 for( const SCH_SHEET_PATH& sheet : sheetList )
1559 {
1560 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SHEET_T ) )
1561 {
1562 SCH_SHEET* sheetItem = static_cast<SCH_SHEET*>( item );
1563 std::unordered_set<wxString> sheetComponentClasses;
1564 const std::unordered_set<SCH_RULE_AREA*>& sheetRuleAreas = sheetItem->GetRuleAreaCache();
1565
1566 for( const SCH_RULE_AREA* ruleArea : sheetRuleAreas )
1567 {
1568 for( const SCH_DIRECTIVE_LABEL* label : ruleArea->GetDirectives() )
1569 {
1570 std::unordered_set<wxString> ruleAreaComponentClasses = getComponentClassFields( label->GetFields(),
1571 &sheet );
1572 sheetComponentClasses.insert( ruleAreaComponentClasses.begin(), ruleAreaComponentClasses.end() );
1573 }
1574 }
1575
1576 SCH_SHEET_PATH newPath = sheet;
1577 newPath.push_back( sheetItem );
1578 wxASSERT( !m_sheetComponentClasses.contains( newPath ) );
1579
1580 m_sheetComponentClasses[newPath] = sheetComponentClasses;
1581 }
1582 }
1583}
const char * name
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
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.
Definition color4d.h:400
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
Represents an (ordered) list of JUMPER_GROUP objects.
const std::vector< JUMPER_GROUP > & GetAll() const
bool IsEmpty() const
Represents a group of jumper pins or pads, keyed by name.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:391
double g
Green component.
Definition color4d.h:392
double a
Alpha component.
Definition color4d.h:394
double b
Blue component.
Definition color4d.h:393
wxString AsString() const
Definition kiid.cpp:264
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.
Definition lib_id.h:108
const wxString GetUniStringLibNickname() const
Definition lib_id.h:84
Define a library symbol object.
Definition lib_symbol.h:114
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.
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.
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
Definition pgm_base.h:126
The backing store for a PROJECT, in JSON format.
std::shared_ptr< NET_SETTINGS > & NetSettings()
Container for project specific data.
Definition project.h:63
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
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).
Definition sch_group.h:48
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
bool ResolveExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:428
const std::unordered_set< SCH_RULE_AREA * > & GetRuleAreaCache() const
Get the cache of rule areas enclosing this item.
Definition sch_item.h:738
bool ResolveExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:392
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:464
bool ResolveExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:410
bool ResolveDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:446
bool ResolveExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:374
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
Definition sch_pin.cpp:717
wxString GetCanonicalElectricalTypeName() const
Definition sch_pin.cpp:470
const wxString & GetShownName() const
Definition sch_pin.cpp:700
const wxString & GetShownNumber() const
Definition sch_pin.cpp:711
const wxString & GetFileName() const
Definition sch_screen.h:157
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:168
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.
Definition sch_sheet.h:50
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.
Schematic symbol object.
Definition sch_symbol.h:76
bool UseLibIdLookup() const
Definition sch_symbol.h:183
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
Definition sch_symbol.h:166
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()
Definition sch_symbol.h:185
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.
Definition title_block.h:38
const wxString & GetCompany() const
Definition title_block.h:93
const wxString & GetRevision() const
Definition title_block.h:83
const wxString & GetDate() const
Definition title_block.h:73
const wxString & GetComment(int aIdx) const
const wxString & GetTitle() const
Definition title_block.h:60
std::map< wxString, wxString > m_Fields
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
void AddAttribute(const wxString &aName, const wxString &aValue) override
Definition xnode.cpp:88
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
@ RAW_VALUE
Definition common.h:98
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
Definition kicad_algo.h:157
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)
#define GNL_ALL
@ GNL_LIBRARIES
@ GNL_OPT_KICAD
@ GNL_SYMBOLS
@ GNL_OPT_BOM
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
static const std::vector< std::string > filters
Definition plugin.cpp:64
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()
@ IGNORE_CASE
std::vector< wxString > m_pinNumbers
Definition lib_symbol.h:731
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
@ UNTRANSLATED
KIBIS_PIN * pin
const SHAPE_LINE_CHAIN chain
wxLogTrace helper definitions.
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_SHEET_T
Definition typeinfo.h:171