50 m_exportPath = wxFileName( aOutFileName ).GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR )
51 + wxString(
"devices" );
56 wxString msg = wxString::Format(
_(
"Failed to create directory 'devices' ." ) );
63 if( (
m_f = wxFopen( aOutFileName, wxT(
"wt" ) ) ) ==
nullptr )
65 wxString msg = wxString::Format(
_(
"Failed to create file '%s'." ), aOutFileName );
103 wxString refText1 = aItem1.first->GetRef( &aItem1.second );
104 wxString refText2 = aItem2.first->GetRef( &aItem2.second );
106 if( refText1 == refText2 )
108 return aItem1.second.PathHumanReadable() < aItem2.second.PathHumanReadable();
116 const wxString& aRefText2 )
123 return aRefText1 < aRefText2;
147 b->GetRef( &sheet,
false ),
true ) < 0 );
150 std::set<
SCH_SYMBOL*,
decltype( cmp )> ordered_symbols( cmp );
151 std::multiset<
SCH_SYMBOL*,
decltype( cmp )> extra_units( cmp );
156 auto test = ordered_symbols.insert( symbol );
160 if( ( *(
test.first ) )->m_Uuid > symbol->
m_Uuid )
162 extra_units.insert( *(
test.first ) );
163 ordered_symbols.erase(
test.first );
164 ordered_symbols.insert( symbol );
168 extra_units.insert( symbol );
173 for(
EDA_ITEM* item : ordered_symbols )
184 wxString>( sheet.PathHumanReadable(),
185 symbol->
GetRef( &sheet ) ) );
197 NET_RECORD(
const wxString& aName ) :
202 std::vector<NET_NODE> m_Nodes;
205 std::vector<NET_RECORD*> nets;
209 wxString net_name = it.first.Name;
210 const std::vector<CONNECTION_SUBGRAPH*>& subgraphs = it.second;
211 NET_RECORD* net_record =
nullptr;
213 if( subgraphs.empty() )
216 nets.emplace_back(
new NET_RECORD( net_name ) );
217 net_record = nets.back();
221 bool nc = subgraph->GetNoConnect() &&
225 for(
SCH_ITEM* item : subgraph->GetItems() )
235 net_record->m_Nodes.emplace_back(
pin, sheet, nc );
242 std::sort( nets.begin(), nets.end(),
243 [](
const NET_RECORD* a,
const NET_RECORD*b )
245 return StrNumCmp( a->m_Name, b->m_Name ) < 0;
248 for( NET_RECORD* net_record : nets )
251 std::sort( net_record->m_Nodes.begin(), net_record->m_Nodes.end(),
254 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
255 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
258 return a.m_Pin->GetShownNumber() < b.m_Pin->GetShownNumber();
269 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
270 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
272 return refA == refB && a.m_Pin->GetShownNumber() == b.m_Pin->GetShownNumber();
275 for(
const NET_NODE& netNode : net_record->m_Nodes )
281 if( refText[0] == wxChar(
'#' ) )
286 m_netNameNodes.insert( std::pair<wxString, NET_NODE>( net_record->m_Name, netNode ) );
290 for( NET_RECORD* record : nets )
298 wxString deviceFileCreatingError = wxString(
"" );
311 if( it->first->GetValue(
false, &it->second,
false )
312 != first_ele.first->GetValue(
false, &first_ele.second,
false ) )
317 if( it->first->GetFootprintFieldText(
false, &it->second,
false )
318 != first_ele.first->GetFootprintFieldText(
false, &first_ele.second,
false ) )
323 wxString ref1 = it->first->GetRef( &it->second );
324 wxString ref2 = first_ele.first->GetRef( &first_ele.second );
341 struct COMP_PACKAGE_STRUCT
344 wxString m_tolerance;
345 std::vector<std::pair<SCH_SYMBOL*, SCH_SHEET_PATH>> m_symbolSheetpaths;
348 COMP_PACKAGE_STRUCT compPackageStruct;
349 std::map<wxString, COMP_PACKAGE_STRUCT> compPackageMap;
351 for(
int groupIndex = 1; groupIndex < groupCount; groupIndex++ )
354 auto beginIter = pairIter.first;
355 auto endIter = pairIter.second;
357 SCH_SYMBOL* sym = ( beginIter->second ).first;
360 wxString valueText = sym->
GetValue(
false, &sheetPath,
false );
362 wxString deviceType = valueText + wxString(
"_") + footprintText;
364 while( deviceType.GetChar(deviceType.Length()-1) ==
'_' )
366 deviceType.RemoveLast();
371 wxArrayString fieldArray;
372 fieldArray.Add(
"Spice_Model" );
373 fieldArray.Add(
"VALUE" );
378 fieldArray.Add(
"TOLERANCE" );
379 fieldArray.Add(
"TOL" );
382 std::vector<std::pair<SCH_SYMBOL*, SCH_SHEET_PATH>> symbolSheetpaths;
384 for(
auto iter = beginIter; iter != endIter; iter++ )
386 symbolSheetpaths.push_back( std::pair<
SCH_SYMBOL*,
388 iter->second.second ) );
391 std::stable_sort( symbolSheetpaths.begin(), symbolSheetpaths.end(),
394 compPackageStruct.m_value = value;
395 compPackageStruct.m_tolerance = tol;
396 compPackageStruct.m_symbolSheetpaths = symbolSheetpaths;
397 compPackageMap.insert( std::pair( deviceType, compPackageStruct ) );
401 wxString deviceFileName = wxFileName(
m_exportPath, deviceType,
402 wxString(
"txt" ) ).GetFullPath();
404 if( ( d = wxFopen( deviceFileName, wxT(
"wt" ) ) ) ==
nullptr )
407 msg.Printf(
_(
"Failed to create file '%s'.\n" ), deviceFileName );
408 deviceFileCreatingError += msg;
412 footprintText = footprintText.AfterLast(
':' );
414 wxArrayString footprintAlt;
417 for(
const wxString& fp : footprintArray )
419 if( ( fp.Find(
'*' ) != wxNOT_FOUND ) || ( fp.Find(
'?' ) != wxNOT_FOUND ) )
424 footprintAlt.Add( fp.AfterLast(
':' ) );
427 if( footprintText.IsEmpty() )
429 if( !footprintAlt.IsEmpty() )
431 footprintText = footprintAlt[0];
432 footprintAlt.RemoveAt( 0 );
436 footprintText = deviceType;
441 fprintf( d,
"CLASS IC\n" );
455 for(
int ii = 0; ii < (int) pinList.size() - 1; ii++ )
457 if( pinList[ii]->GetNumber() == pinList[ii + 1]->GetNumber() )
460 pinList.erase( pinList.begin() + ii + 1 );
465 unsigned int pinCount = pinList.size();
466 fprintf( d,
"PINCOUNT %u\n", pinCount );
473 if( !value.IsEmpty() )
475 fprintf( d,
"PACKAGEPROP VALUE %s\n",
TO_UTF8( value ) );
480 fprintf( d,
"PACKAGEPROP TOL %s\n",
TO_UTF8( tol ) );
483 if( !footprintAlt.IsEmpty() )
485 fprintf( d,
"PACKAGEPROP ALT_SYMBOLS '(" );
487 wxString footprintAltSymbolsText;
489 for(
const wxString& fp : footprintAlt )
491 footprintAltSymbolsText += fp + wxString(
"," );
494 footprintAltSymbolsText.Truncate( footprintAltSymbolsText.Length() - 1 );
495 fprintf( d,
"%s)'\n",
TO_UTF8( footprintAltSymbolsText ) );
498 wxArrayString propArray;
499 propArray.Add(
"PART_NUMBER" );
500 propArray.Add(
"mpn" );
501 propArray.Add(
"mfr_pn" );
506 fprintf( d,
"PACKAGEPROP %s %s\n",
TO_UTF8( propArray[0] ),
TO_UTF8( data ) );
510 propArray.Add(
"HEIGHT" );
515 fprintf( d,
"PACKAGEPROP %s %s\n",
TO_UTF8( propArray[0] ),
TO_UTF8( data ) );
518 fprintf( d,
"END\n" );
523 for(
auto iter = compPackageMap.begin(); iter != compPackageMap.end(); iter++ )
525 wxString deviceType = iter->first;
526 wxString value = iter->second.m_value;
527 wxString tolerance = iter->second.m_tolerance;
529 if( value.IsEmpty() && tolerance.IsEmpty() )
531 fprintf(
m_f,
"!%s;",
TO_UTF8( deviceType ) );
533 else if( tolerance.IsEmpty() )
543 std::vector<std::pair<SCH_SYMBOL*, SCH_SHEET_PATH>> symbolSheetpaths =
544 iter->second.m_symbolSheetpaths;
546 for(
const auto& [ sym, sheetPath ] : symbolSheetpaths)
547 fprintf(
m_f,
",\n\t%s",
TO_UTF8( sym->GetRef( &sheetPath ) ) );
549 fprintf(
m_f,
"\n" );
552 if( !deviceFileCreatingError.IsEmpty() )
559 if( aString.IsEmpty() )
560 return wxEmptyString;
562 aString.Replace(
"\u03BC",
"u" );
564 std::regex reg(
"[!']|[^ -~]" );
565 wxString processedString = wxString( std::regex_replace( std::string( aString ), reg,
"?" ) );
567 std::regex search_reg(
"[^a-zA-Z0-9_/]" );
569 if( std::regex_search( std::string( processedString ), search_reg ) )
570 return wxString(
"'" ) + processedString + wxString(
"'" );
572 return processedString;
578 wxString pinName4Telesis = aPin.
GetName() + wxString(
"__" ) + aPin.
GetNumber();
579 std::regex reg(
"[^A-Za-z0-9_+?/-]" );
580 return wxString( std::regex_replace( std::string( pinName4Telesis ), reg,
"?" ) );
587 std::list<wxString> pinNameList;
591 for(
auto pin : aPinList )
594 wxString out_str =
"";
597 out_str.Printf( wxT(
"PINORDER %s " ),
TO_UTF8( aName ) );
599 for(
const wxString& pinName : pinNameList )
601 str.Printf(
",\n\t%s",
TO_UTF8( pinName ) );
604 out_str += wxString(
"\n" );
606 str.Printf( wxT(
"FUNCTION %s %s " ),
TO_UTF8( aName ),
TO_UTF8( aName ) );
609 for(
auto pin : aPinList )
611 str.Printf(
",\n\t%s",
TO_UTF8(
pin->GetNumber() ) );
615 out_str += wxString(
"\n" );
626 for(
auto iter = pairIter.first; iter != pairIter.second; ++iter )
631 for(
const wxString& field : aFieldArray )
635 wxString fieldText = fld->GetShownText( &sheetPath,
true );
637 if( !fieldText.IsEmpty() )
648 for(
auto iter = pairIter.first; iter != pairIter.second; ++iter )
652 for(
const wxString& field : aFieldArray )
656 wxString fieldText = fld->GetShownText(
false, 0 );
658 if( !fieldText.IsEmpty() )
669 return wxEmptyString;
676 std::regex reg(
"[^a-z0-9_-]" );
677 return wxString( std::regex_replace( std::string( aString ), reg,
"_" ) );
683 fprintf(
m_f,
"%s\n",
"$PACKAGES" );
684 fprintf(
m_f,
"%s\n",
"$A_PROPERTIES" );
689 wxString sheetPathText = iter->first;
693 std::vector<wxString> refTexts;
697 for( iter = pairIter.first; iter != pairIter.second; ++iter )
699 wxString refText = iter->second;
700 refTexts.push_back( refText );
705 std::stable_sort( refTexts.begin(), refTexts.end(),
708 for(
const wxString& ref : refTexts )
711 fprintf(
m_f,
"\n" );
718 fprintf(
m_f,
"%s\n",
"$NETS" );
722 std::multimap<wxString, NET_NODE>::iterator iter =
m_netNameNodes.begin();
723 std::vector<NET_NODE> netNodes;
725 wxString netName = iter->first;
731 for( iter = pairIter.first; iter != pairIter.second; ++iter )
734 netNodes.push_back( netNode );
739 std::stable_sort( netNodes.begin(), netNodes.end() );
741 for(
const NET_NODE& netNode : netNodes )
743 wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
744 wxString pinText = netNode.m_Pin->GetShownNumber();
748 fprintf(
m_f,
"\n" );
755 while( ( aString.GetChar( aString.Length() - 1 ) >=
'0' )
756 && ( aString.GetChar( aString.Length() - 1 ) <=
'9' ) )
758 aString.RemoveLast();
769 while( ( aString.GetChar( aString.Length() - 1 ) >=
'0' )
770 && ( aString.GetChar( aString.Length() - 1 ) <=
'9' ) )
772 numString.insert( 0, aString.GetChar( aString.Length() - 1 ) );
773 aString.RemoveLast();
779 numString.ToULong( &val );
780 return (
unsigned int) val;
const NET_MAP & GetNetMap() const
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.
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.
void extractComponentsInfo()
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.
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.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
virtual void SetCurrentSheet(const SCH_SHEET_PATH &aPath)=0
virtual wxString GetFileName() const =0
virtual CONNECTION_GRAPH * ConnectionGraph() const =0
virtual SCH_SHEET_LIST Hierarchy() const =0
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
const SYMBOL * GetParentSymbol() const
wxString GetShownNumber() const
const wxString & GetName() const
const wxString & GetNumber() const
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
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true, bool aCaseInsensitive=false)
Search for a SCH_FIELD with aFieldName.
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
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()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
A base class for LIB_SYMBOL and SCH_SYMBOL.
bool GetExcludedFromBoard() const
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
void Clear()
Erase the record.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
Collection of utility functions for component reference designators (refdes)
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.
Definition for symbol library class.