KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netlist_exporter_allegro.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <confirm.h>
25#include <refdes_utils.h>
26#include <sch_edit_frame.h>
27#include <sch_reference_list.h>
28#include <string_utils.h>
29#include <connection_graph.h>
30#include <core/kicad_algo.h>
31#include <netlist.h>
34#include <regex>
35#include <fmt.h>
36#include <fmt/ranges.h>
37
38bool NETLIST_EXPORTER_ALLEGRO::WriteNetlist( const wxString& aOutFileName,
39 unsigned /* aNetlistOptions */,
40 REPORTER& aReporter )
41{
42 m_f = nullptr;
43 bool success = true;
44
45 // Create the devices directory
46 m_exportPath = wxFileName( aOutFileName ).GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR )
47 + wxString( "devices" );
48 if( !wxDirExists( m_exportPath ) )
49 {
50 if( !wxMkdir( m_exportPath, wxS_DIR_DEFAULT ) )
51 {
52 wxString msg = wxString::Format( _( "Failed to create directory 'devices' ." ) );
53 aReporter.Report( msg, RPT_SEVERITY_ERROR );
54 return false;
55 }
56 }
57
58 // Write the netlist file
59 if( ( m_f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == nullptr )
60 {
61 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), aOutFileName );
62 aReporter.Report( msg, RPT_SEVERITY_ERROR );
63 return false;
64 }
65
66 try
67 {
68 fmt::print( m_f, "(NETLIST)\n" );
69 fmt::print( m_f, "(Source: {})\n", TO_UTF8( m_schematic->GetFileName() ) );
70 fmt::print( m_f, "(Date: {})\n", TO_UTF8( GetISO8601CurrentDateTime() ) );
71
72 m_packageProperties.clear();
73 m_componentGroups.clear();
75 m_netNameNodes.clear();
76
78
79 // Start with package definitions, which we create from component groups.
81
82 // Write out package properties. NOTE: Allegro doesn't recognize much...
84
85 // Write out nets
87
88 fmt::print( m_f, "$END\n" );
89 }
90 catch (...)
91 {
92 success = false;
93 }
94
95 // Done with the netlist
96 fclose( m_f );
97
98 m_f = nullptr;
99
100 return success;
101}
102
103
105 SCH_SHEET_PATH>& aItem1,
106 const std::pair<SCH_SYMBOL*,
107 SCH_SHEET_PATH>& aItem2 )
108{
109 wxString refText1 = aItem1.first->GetRef( &aItem1.second );
110 wxString refText2 = aItem2.first->GetRef( &aItem2.second );
111
112 if( refText1 == refText2 )
113 {
114 return aItem1.second.PathHumanReadable() < aItem2.second.PathHumanReadable();
115 }
116
117 return CompareSymbolRef( refText1, refText2 );
118}
119
120
121bool NETLIST_EXPORTER_ALLEGRO::CompareSymbolRef( const wxString& aRefText1,
122 const wxString& aRefText2 )
123{
124 if( removeTailDigits( aRefText1 ) == removeTailDigits( aRefText2 ) )
125 {
126 return extractTailNumber( aRefText1 ) < extractTailNumber( aRefText2 );
127 }
128
129 return aRefText1 < aRefText2;
130}
131
132
134{
135 // return "lhs < rhs"
136 return StrNumCmp( aPin1->GetShownNumber(), aPin2->GetShownNumber(), true ) < 0;
137}
138
139
141{
143 m_libParts.clear();
144
145 for( const SCH_SHEET_PATH& sheet : m_schematic->Hierarchy() )
146 {
147 m_schematic->SetCurrentSheet( sheet );
148
149 auto cmp =
150 [&sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b )
151 {
152 return ( StrNumCmp( a->GetRef( &sheet, false ),
153 b->GetRef( &sheet, false ), true ) < 0 );
154 };
155
156 std::set<SCH_SYMBOL*, decltype( cmp )> ordered_symbols( cmp );
157 std::multiset<SCH_SYMBOL*, decltype( cmp )> extra_units( cmp );
158
159 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
160 {
161 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
162 auto test = ordered_symbols.insert( symbol );
163
164 if( !test.second )
165 {
166 if( ( *( test.first ) )->m_Uuid > symbol->m_Uuid )
167 {
168 extra_units.insert( *( test.first ) );
169 ordered_symbols.erase( test.first );
170 ordered_symbols.insert( symbol );
171 }
172 else
173 {
174 extra_units.insert( symbol );
175 }
176 }
177 }
178
179 for( EDA_ITEM* item : ordered_symbols )
180 {
181 SCH_SYMBOL* symbol = findNextSymbol( item, sheet );
182
183 if( !symbol || symbol->GetExcludedFromBoard() )
184 continue;
185
186 if( symbol->GetLibPins().empty() )
187 continue;
188
189 m_packageProperties.insert( std::pair<wxString,
190 wxString>( sheet.PathHumanReadable(),
191 symbol->GetRef( &sheet ) ) );
192 m_orderedSymbolsSheetpath.push_back( std::pair<SCH_SYMBOL*,
193 SCH_SHEET_PATH>( symbol, sheet ) );
194 }
195 }
196
197 struct NET_RECORD
198 {
199 NET_RECORD( const wxString& aName ) :
200 m_Name( aName )
201 {};
202
203 wxString m_Name;
204 std::vector<NET_NODE> m_Nodes;
205 };
206
207 std::vector<NET_RECORD*> nets;
208
209 for( const auto& it : m_schematic->ConnectionGraph()->GetNetMap() )
210 {
211 wxString net_name = it.first.Name;
212 const std::vector<CONNECTION_SUBGRAPH*>& subgraphs = it.second;
213 NET_RECORD* net_record = nullptr;
214
215 if( subgraphs.empty() )
216 continue;
217
218 nets.emplace_back( new NET_RECORD( net_name ) );
219 net_record = nets.back();
220
221 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
222 {
223 bool nc = subgraph->GetNoConnect() &&
224 subgraph->GetNoConnect()->Type() == SCH_NO_CONNECT_T;
225 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
226
227 for( SCH_ITEM* item : subgraph->GetItems() )
228 {
229 if( item->Type() == SCH_PIN_T )
230 {
231 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
232 SYMBOL* symbol = pin->GetParentSymbol();
233
234 if( !symbol || symbol->GetExcludedFromBoard() )
235 continue;
236
237 net_record->m_Nodes.emplace_back( pin, sheet, nc );
238 }
239 }
240 }
241 }
242
243 // Netlist ordering: Net name, then ref des, then pin name
244 std::sort( nets.begin(), nets.end(),
245 []( const NET_RECORD* a, const NET_RECORD*b )
246 {
247 return StrNumCmp( a->m_Name, b->m_Name ) < 0;
248 } );
249
250 for( NET_RECORD* net_record : nets )
251 {
252 // Netlist ordering: Net name, then ref des, then pin name
253 std::sort( net_record->m_Nodes.begin(), net_record->m_Nodes.end(),
254 []( const NET_NODE& a, const NET_NODE& b )
255 {
256 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
257 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
258
259 if( refA == refB )
260 return a.m_Pin->GetShownNumber() < b.m_Pin->GetShownNumber();
261
262 return refA < refB;
263 } );
264
265 // Some duplicates can exist, for example on multi-unit parts with duplicated pins across
266 // units. If the user connects the pins on each unit, they will appear on separate
267 // subgraphs. Remove those here:
268 alg::remove_duplicates( net_record->m_Nodes,
269 []( const NET_NODE& a, const NET_NODE& b )
270 {
271 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
272 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
273
274 return refA == refB && a.m_Pin->GetShownNumber() == b.m_Pin->GetShownNumber();
275 } );
276
277 for( const NET_NODE& netNode : net_record->m_Nodes )
278 {
279 wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
280
281 // Skip power symbols and virtual symbols
282 if( refText[0] == wxChar( '#' ) )
283 {
284 continue;
285 }
286
287 m_netNameNodes.insert( std::pair<wxString, NET_NODE>( net_record->m_Name, netNode ) );
288 }
289 }
290
291 for( NET_RECORD* record : nets )
292 delete record;
293}
294
295
297{
298 int groupCount = 1;
299 wxString deviceFileCreatingError = wxString( "" );
300
301 //Group the components......
302 while(!m_orderedSymbolsSheetpath.empty())
303 {
304 std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> first_ele = m_orderedSymbolsSheetpath.front();
305 m_orderedSymbolsSheetpath.pop_front();
306 m_componentGroups.insert( std::pair<int, std::pair<SCH_SYMBOL*,
307 SCH_SHEET_PATH>>( groupCount, first_ele ) );
308
309 for( auto it = m_orderedSymbolsSheetpath.begin(); it != m_orderedSymbolsSheetpath.end();
310 ++it )
311 {
312 if( it->first->GetValue( false, &it->second, false )
313 != first_ele.first->GetValue( false, &first_ele.second, false ) )
314 {
315 continue;
316 }
317
318 if( it->first->GetFootprintFieldText( false, &it->second, false )
319 != first_ele.first->GetFootprintFieldText( false, &first_ele.second, false ) )
320 {
321 continue;
322 }
323
324 wxString ref1 = it->first->GetRef( &it->second );
325 wxString ref2 = first_ele.first->GetRef( &first_ele.second );
326
327 if( removeTailDigits( ref1 ) == removeTailDigits( ref2 ) )
328 {
329 m_componentGroups.insert( std::pair<int, std::pair<SCH_SYMBOL*,
330 SCH_SHEET_PATH>>( groupCount, ( *it ) ) );
331 it = m_orderedSymbolsSheetpath.erase( it );
332
333 if( std::distance( it, m_orderedSymbolsSheetpath.begin() ) > 0 )
334 it--;
335 else if( it == m_orderedSymbolsSheetpath.end() )
336 break;
337 }
338 }
339 groupCount++;
340 }
341
342 struct COMP_PACKAGE_STRUCT
343 {
344 wxString m_value;
345 wxString m_tolerance;
346 std::vector<std::pair<SCH_SYMBOL*, SCH_SHEET_PATH>> m_symbolSheetpaths;
347 };
348
349 COMP_PACKAGE_STRUCT compPackageStruct;
350 std::map<wxString, COMP_PACKAGE_STRUCT> compPackageMap;
351
352 for( int groupIndex = 1; groupIndex < groupCount; groupIndex++ )
353 {
354 auto pairIter = m_componentGroups.equal_range( groupIndex );
355 auto beginIter = pairIter.first;
356 auto endIter = pairIter.second;
357
358 SCH_SYMBOL* sym = ( beginIter->second ).first;
359 SCH_SHEET_PATH sheetPath = ( beginIter->second ).second;
360
361 wxString valueText = sym->GetValue( false, &sheetPath, false );
362 wxString footprintText = sym->GetFootprintFieldText( false, &sheetPath, false);
363 wxString deviceType = valueText + wxString("_") + footprintText;
364
365 while( deviceType.GetChar(deviceType.Length()-1) == '_' )
366 {
367 deviceType.RemoveLast();
368 }
369
370 deviceType = formatDevice( deviceType );
371
372 wxArrayString fieldArray;
373 fieldArray.Add( "Spice_Model" );
374 fieldArray.Add( "VALUE" );
375
376 wxString value = getGroupField( groupIndex, fieldArray );
377
378 fieldArray.clear();
379 fieldArray.Add( "TOLERANCE" );
380 fieldArray.Add( "TOL" );
381 wxString tol = getGroupField( groupIndex, fieldArray );
382
383 std::vector<std::pair<SCH_SYMBOL*, SCH_SHEET_PATH>> symbolSheetpaths;
384
385 for( auto iter = beginIter; iter != endIter; iter++ )
386 {
387 symbolSheetpaths.push_back( std::pair<SCH_SYMBOL*,
388 SCH_SHEET_PATH>( iter->second.first,
389 iter->second.second ) );
390 }
391
392 std::stable_sort( symbolSheetpaths.begin(), symbolSheetpaths.end(),
394
395 compPackageStruct.m_value = value;
396 compPackageStruct.m_tolerance = tol;
397 compPackageStruct.m_symbolSheetpaths = symbolSheetpaths;
398 compPackageMap.insert( std::pair( deviceType, compPackageStruct ) );
399
400 // Write out the corresponding device file
401 FILE* d = nullptr;
402 wxString deviceFileName = wxFileName( m_exportPath, deviceType,
403 wxString( "txt" ) ).GetFullPath();
404
405 if( ( d = wxFopen( deviceFileName, wxT( "wt" ) ) ) == nullptr )
406 {
407 wxString msg;
408 msg.Printf( _( "Failed to create file '%s'.\n" ), deviceFileName );
409 deviceFileCreatingError += msg;
410 continue;
411 }
412
413 footprintText = footprintText.AfterLast( ':' );
414
415 wxArrayString footprintAlt;
416 wxArrayString footprintArray = sym->GetLibSymbolRef()->GetFPFilters();
417
418 for( const wxString& fp : footprintArray )
419 {
420 if( ( fp.Find( '*' ) != wxNOT_FOUND ) || ( fp.Find( '?' ) != wxNOT_FOUND ) )
421 {
422 continue;
423 }
424
425 footprintAlt.Add( fp.AfterLast( ':' ) );
426 }
427
428 if( footprintText.IsEmpty() )
429 {
430 if( !footprintAlt.IsEmpty() )
431 {
432 footprintText = footprintAlt[0];
433 footprintAlt.RemoveAt( 0 );
434 }
435 else
436 {
437 footprintText = deviceType;
438 }
439 }
440
441 fmt::print( d, "PACKAGE '{}'\n", TO_UTF8( formatDevice( footprintText ) ) );
442 fmt::print( d, "CLASS IC\n" );
443
444 std::vector<SCH_PIN*> pinList = sym->GetLibSymbolRef()->GetPins();
445
446 /*
447 * We must erase redundant Pins references in pinList
448 * These redundant pins exist because some pins are found more than one time when a
449 * symbol has multiple parts per package or has 2 representations (DeMorgan conversion).
450 * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes, and
451 * therefore each pin appears 2 times in the list. Common pins (VCC, GND) can also be
452 * found more than once.
453 */
454 sort( pinList.begin(), pinList.end(), NETLIST_EXPORTER_ALLEGRO::CompareLibPin );
455
456 for( int ii = 0; ii < (int) pinList.size() - 1; ii++ )
457 {
458 if( pinList[ii]->GetNumber() == pinList[ii + 1]->GetNumber() )
459 {
460 // 2 pins have the same number, remove the redundant pin at index i+1
461 pinList.erase( pinList.begin() + ii + 1 );
462 ii--;
463 }
464 }
465
466 unsigned int pinCount = pinList.size();
467 fmt::print( d, "PINCOUNT {}\n", pinCount );
468
469 if( pinCount > 0 )
470 {
471 fmt::print( d, "{}", TO_UTF8( formatFunction( "main", pinList ) ) );
472 }
473
474 if( !value.IsEmpty() )
475 {
476 fmt::print( d, "PACKAGEPROP VALUE {}\n", TO_UTF8( value ) );
477 }
478
479 if( !tol.IsEmpty() )
480 {
481 fmt::print( d, "PACKAGEPROP TOL {}\n", TO_UTF8( tol ) );
482 }
483
484 if( !footprintAlt.IsEmpty() )
485 {
486 fmt::print( d, "PACKAGEPROP ALT_SYMBOLS '({})'\n", fmt::join( footprintAlt, "," ) );
487 }
488
489 wxArrayString propArray;
490 propArray.Add( "PART_NUMBER" );
491 propArray.Add( "mpn" );
492 propArray.Add( "mfr_pn" );
493 wxString data = getGroupField( groupIndex, propArray );
494
495 if(!data.IsEmpty())
496 {
497 fmt::print( d, "PACKAGEPROP {} {}\n", TO_UTF8( propArray[0] ), TO_UTF8( data ) );
498 }
499
500 propArray.clear();
501 propArray.Add( "HEIGHT" );
502 data = getGroupField( groupIndex, propArray );
503
504 if(!data.IsEmpty())
505 {
506 fmt::print( d, "PACKAGEPROP {} {}\n", TO_UTF8( propArray[0] ), TO_UTF8( data ) );
507 }
508
509 fmt::print( d, "END\n" );
510
511 fclose( d );
512 }
513
514 fmt::print( m_f, "$PACKAGES\n" );
515
516 for( auto iter = compPackageMap.begin(); iter != compPackageMap.end(); iter++ )
517 {
518 wxString deviceType = iter->first;
519 wxString value = iter->second.m_value;
520 wxString tolerance = iter->second.m_tolerance;
521
522 if( value.IsEmpty() && tolerance.IsEmpty() )
523 {
524 fmt::print( m_f, "! '{}' ; ", TO_UTF8( deviceType ) );
525 }
526 else if( tolerance.IsEmpty() )
527 {
528 fmt::print( m_f, "! '{}' ! '{}' ; ", TO_UTF8( deviceType ), TO_UTF8( value ) );
529 }
530 else
531 {
532 fmt::print( m_f, "! '{}' ! '{}' ! {} ; ", TO_UTF8( deviceType ), TO_UTF8( value ),
533 TO_UTF8( tolerance ) );
534 }
535
536 std::vector<std::pair<SCH_SYMBOL*, SCH_SHEET_PATH>> symbolSheetpaths =
537 iter->second.m_symbolSheetpaths;
538
539 std::vector<wxString> refTexts;
540 for( const auto& [ sym, sheetPath ] : symbolSheetpaths)
541 refTexts.push_back( sym->GetRef( &sheetPath ) );
542
543 fmt::print( m_f, "{}", fmt::join( refTexts, ",\n\t" ) );
544
545 fmt::print( m_f, "\n" );
546 }
547
548 if( !deviceFileCreatingError.IsEmpty() )
549 DisplayError( nullptr, deviceFileCreatingError );
550}
551
552
553wxString NETLIST_EXPORTER_ALLEGRO::formatText( wxString aString )
554{
555 if( aString.IsEmpty() )
556 return wxEmptyString;
557
558 aString.Replace( "\u03BC", "u" );
559
560 std::regex reg( "[!']|[^ -~]" );
561 wxString processedString = wxString( std::regex_replace( std::string( aString ), reg, "?" ) );
562
563 std::regex search_reg( "[^a-zA-Z0-9_/]" );
564
565 if( std::regex_search( std::string( processedString ), search_reg ) )
566 return wxString( "'" ) + processedString + wxString( "'" );
567
568 return processedString;
569}
570
571
573{
574 wxString pinName4Telesis = aPin.GetName() + wxString( "__" ) + aPin.GetNumber();
575 std::regex reg( "[^A-Za-z0-9_+?/-]" );
576 return wxString( std::regex_replace( std::string( pinName4Telesis ), reg, "?" ) );
577}
578
579
580wxString NETLIST_EXPORTER_ALLEGRO::formatFunction( wxString aName, std::vector<SCH_PIN*> aPinList )
581{
582 aName.MakeUpper();
583 std::list<wxString> pinNameList;
584
585 std::stable_sort( aPinList.begin(), aPinList.end(), NETLIST_EXPORTER_ALLEGRO::CompareLibPin );
586
587 for( auto pin : aPinList )
588 pinNameList.push_back( formatPin( *pin ) );
589
590 wxString out_str = "";
591 wxString str;
592
593 out_str.Printf( wxT( "PINORDER %s " ), TO_UTF8( aName ) );
594
595 for( const wxString& pinName : pinNameList )
596 {
597 str.Printf( ",\n\t%s", TO_UTF8( pinName ) );
598 out_str += str;
599 }
600 out_str += wxString( "\n" );
601
602 str.Printf( wxT( "FUNCTION %s %s " ), TO_UTF8( aName ), TO_UTF8( aName ) );
603 out_str += str;
604
605 for( auto pin : aPinList )
606 {
607 str.Printf( ",\n\t%s", TO_UTF8( pin->GetNumber() ) );
608 out_str += str;
609 }
610
611 out_str += wxString( "\n" );
612
613 return out_str;
614}
615
616
617wxString NETLIST_EXPORTER_ALLEGRO::getGroupField( int aGroupIndex, const wxArrayString& aFieldArray,
618 bool aSanitize )
619{
620 auto pairIter = m_componentGroups.equal_range( aGroupIndex );
621
622 for( auto iter = pairIter.first; iter != pairIter.second; ++iter )
623 {
624 SCH_SYMBOL* sym = ( iter->second ).first;
625 SCH_SHEET_PATH sheetPath = ( iter->second ).second;
626
627 for( const wxString& field : aFieldArray )
628 {
629 if( SCH_FIELD* fld = sym->FindFieldCaseInsensitive( field ) )
630 {
631 wxString fieldText = fld->GetShownText( &sheetPath, true );
632
633 if( !fieldText.IsEmpty() )
634 {
635 if( aSanitize )
636 return formatText( fieldText );
637 else
638 return fieldText;
639 }
640 }
641 }
642 }
643
644 for( auto iter = pairIter.first; iter != pairIter.second; ++iter )
645 {
646 SCH_SYMBOL* sym = ( iter->second ).first;
647
648 for( const wxString& field : aFieldArray )
649 {
650 if( SCH_FIELD* fld = sym->GetLibSymbolRef()->FindFieldCaseInsensitive( field ) )
651 {
652 wxString fieldText = fld->GetShownText( false, 0 );
653
654 if( !fieldText.IsEmpty() )
655 {
656 if( aSanitize )
657 return formatText( fieldText );
658 else
659 return fieldText;
660 }
661 }
662 }
663 }
664
665 return wxEmptyString;
666}
667
668
669wxString NETLIST_EXPORTER_ALLEGRO::formatDevice( wxString aString )
670{
671 aString.MakeLower();
672 std::regex reg( "[^a-z0-9_-]" );
673 return wxString( std::regex_replace( std::string( aString ), reg, "_" ) );
674}
675
676
678{
679 fmt::print( m_f, "$A_PROPERTIES\n" );
680
681 while( !m_packageProperties.empty() )
682 {
683 std::multimap<wxString, wxString>::iterator iter = m_packageProperties.begin();
684 wxString sheetPathText = iter->first;
685
686 fmt::print( m_f, "'ROOM' '{}' ; ", TO_UTF8( formatText( sheetPathText ) ) );
687
688 std::vector<wxString> refTexts;
689
690 auto pairIter = m_packageProperties.equal_range( sheetPathText );
691
692 for( iter = pairIter.first; iter != pairIter.second; ++iter )
693 {
694 wxString refText = iter->second;
695 refTexts.push_back( refText );
696 }
697
698 m_packageProperties.erase( pairIter.first, pairIter.second );
699
700 std::stable_sort( refTexts.begin(), refTexts.end(),
702
703 fmt::print( m_f, "{}", fmt::join( refTexts, ",\n\t" ) );
704
705 fmt::print( m_f, "\n" );
706 }
707}
708
709
711{
712 fmt::print( m_f, "$NETS\n" );
713
714 while( !m_netNameNodes.empty() )
715 {
716 std::multimap<wxString, NET_NODE>::iterator iter = m_netNameNodes.begin();
717 std::vector<NET_NODE> netNodes;
718
719 wxString netName = iter->first;
720
721 fmt::print( m_f, "{}; ", TO_UTF8( formatText( netName ).MakeUpper() ) );
722
723 auto pairIter = m_netNameNodes.equal_range( netName );
724
725 for( iter = pairIter.first; iter != pairIter.second; ++iter )
726 {
727 NET_NODE netNode = iter->second;
728 netNodes.push_back( netNode );
729 }
730
731 m_netNameNodes.erase( pairIter.first, pairIter.second );
732
733 std::stable_sort( netNodes.begin(), netNodes.end() );
734
735 std::vector<wxString> nets;
736 for( const NET_NODE& netNode : netNodes )
737 {
738 wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
739 wxString pinText = netNode.m_Pin->GetShownNumber();
740 nets.push_back( refText + wxString( "." ) + pinText );
741 }
742
743 fmt::print( m_f, "{}", fmt::join( nets, ",\n\t" ) );
744
745 fmt::print( m_f, "\n" );
746 }
747}
748
749
751{
752 while( ( aString.GetChar( aString.Length() - 1 ) >= '0' )
753 && ( aString.GetChar( aString.Length() - 1 ) <= '9' ) )
754 {
755 aString.RemoveLast();
756 }
757
758 return aString;
759}
760
761
762unsigned int NETLIST_EXPORTER_ALLEGRO::extractTailNumber( wxString aString )
763{
764 wxString numString;
765
766 while( ( aString.GetChar( aString.Length() - 1 ) >= '0' )
767 && ( aString.GetChar( aString.Length() - 1 ) <= '9' ) )
768 {
769 numString.insert( 0, aString.GetChar( aString.Length() - 1 ) );
770 aString.RemoveLast();
771 }
772
773 unsigned long val;
774
775 //From wxWidgets 3.1.6, here we can use ToUInt instead of ToULong function.
776 numString.ToULong( &val );
777 return (unsigned int) val;
778}
A subgraph is a set of items that are electrically connected on a single sheet.
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:516
SCH_FIELD * FindFieldCaseInsensitive(const wxString &aFieldName)
wxArrayString GetFPFilters() const
Definition lib_symbol.h:217
std::vector< SCH_PIN * > GetPins() const override
wxString formatDevice(wxString aString)
Convert a string into one safe for a Telesis device name.
wxString m_exportPath
Directory to store device files.
static unsigned int extractTailNumber(wxString aString)
Extract the str's tailing number.
FILE * m_f
File pointer for netlist file writing operation.
static wxString removeTailDigits(wxString aString)
Remove the str's tailing digits.
void toAllegroPackageProperties()
Write $A_PROPERTIES section.
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter) override
Write netlist to aOutFileName.
std::list< std::pair< SCH_SYMBOL *, SCH_SHEET_PATH > > m_orderedSymbolsSheetpath
Store the ordered symbols with sheetpath.
static bool CompareSymbolSheetpath(const std::pair< SCH_SYMBOL *, SCH_SHEET_PATH > &aItem1, const std::pair< SCH_SYMBOL *, SCH_SHEET_PATH > &aItem2)
Compare two std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> variables.
wxString formatText(wxString aString)
Convert a string into Telesis-safe format.
std::multimap< wxString, wxString > m_packageProperties
wxString formatFunction(wxString aName, std::vector< SCH_PIN * > aPinList)
Generate the definition of a function in Telesis format, which consists of multiple declarations (PIN...
static bool CompareLibPin(const SCH_PIN *aPin1, const SCH_PIN *aPin2)
Compare two SCH_PIN* variables.
wxString formatPin(const SCH_PIN &aPin)
Generate a Telesis-compatible pin name from a pin node.
static bool CompareSymbolRef(const wxString &aRefText1, const wxString &aRefText2)
Compare two wxString variables.
wxString getGroupField(int aGroupIndex, const wxArrayString &aFieldArray, bool aSanitize=true)
Look up a field for a component group, which may have mismatched case, or the component group may not...
void toAllegroPackages()
Write the $PACKAGES section.
std::multimap< wxString, NET_NODE > m_netNameNodes
Store the NET_NODE with the net name.
std::multimap< int, std::pair< SCH_SYMBOL *, SCH_SHEET_PATH > > m_componentGroups
Store the component group.
void toAllegroNets()
Write the $NETS section.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath)
Check if the given symbol should be processed for netlisting.
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:250
wxString GetShownNumber() const
Definition sch_pin.cpp:588
const wxString & GetName() const
Definition sch_pin.cpp:401
const wxString & GetNumber() const
Definition sch_pin.h:124
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const SCH_SHEET * GetSheet(unsigned aIndex) const
Schematic symbol object.
Definition sch_symbol.h:76
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
SCH_FIELD * FindFieldCaseInsensitive(const wxString &aFieldName)
Search for a SCH_FIELD with aFieldName.
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const
std::vector< SCH_PIN * > GetLibPins() const
Populate a vector with all the pins from the library object that match the current unit and bodyStyle...
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:63
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
bool GetExcludedFromBoard() const override
Definition symbol.h:208
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
This file is part of the common library.
#define _(s)
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
Definition kicad_algo.h:161
Collection of utility functions for component reference designators (refdes)
@ RPT_SEVERITY_ERROR
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ SCH_NO_CONNECT_T
Definition typeinfo.h:164
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_PIN_T
Definition typeinfo.h:157