KiCad PCB EDA Suite
NETLIST_EXPORTER_CADSTAR Class Reference

NETLIST_EXPORTER_CADSTAR generates a netlist compatible with CADSTAR. More...

#include <netlist_exporter_cadstar.h>

Inheritance diagram for NETLIST_EXPORTER_CADSTAR:
NETLIST_EXPORTER_BASE

Public Member Functions

 NETLIST_EXPORTER_CADSTAR (SCHEMATIC *aSchematic)
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions) override
 Function WriteList writes to specified output file. More...
 

Static Public Member Functions

static wxString MakeCommandLine (const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
 Function MakeCommandLine builds up a string that describes a command line for executing a child process. More...
 

Protected Member Functions

void CreatePinList (SCH_COMPONENT *aSymbol, SCH_SHEET_PATH *aSheetPath)
 Function findNextSymbolAndCreatePinList finds a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList. More...
 
SCH_COMPONENTfindNextSymbol (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
 Checks if the given symbol should be processed for netlisting. More...
 
void eraseDuplicatePins ()
 Function eraseDuplicatePins erase duplicate Pins from m_sortedSymbolPinList (i.e. More...
 
void findAllUnitsOfSymbol (SCH_COMPONENT *aSymbol, LIB_PART *aPart, SCH_SHEET_PATH *aSheetPath)
 Function findAllUnitsOfSymbol is used for "multiple parts per package" symbols. More...
 

Protected Attributes

std::vector< PIN_INFOm_sortedSymbolPinList
 Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic symbol data in netlist (comp section). More...
 
UNIQUE_STRINGS m_referencesAlreadyFound
 Used for "multiple parts per package" symbols to avoid processing a lib part more than once. More...
 
std::set< LIB_PART *, LIB_PART_LESS_THANm_libParts
 unique library parts used. LIB_PART items are sorted by names More...
 
SCHEMATICm_schematic
 The schematic we're generating a netlist for. More...
 
SCH_SHEET_PATH m_savedCurrentSheet
 The schematic's CurrentSheet when we entered. Restore on exiting. More...
 

Private Member Functions

bool writeListOfNets (FILE *f)
 Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it. More...
 

Detailed Description

NETLIST_EXPORTER_CADSTAR generates a netlist compatible with CADSTAR.

Definition at line 36 of file netlist_exporter_cadstar.h.

Constructor & Destructor Documentation

◆ NETLIST_EXPORTER_CADSTAR()

NETLIST_EXPORTER_CADSTAR::NETLIST_EXPORTER_CADSTAR ( SCHEMATIC aSchematic)
inline

Definition at line 51 of file netlist_exporter_cadstar.h.

51  :
52  NETLIST_EXPORTER_BASE( aSchematic )
53  {
54  }
NETLIST_EXPORTER_BASE(SCHEMATIC *aSchematic)
Constructor.

Member Function Documentation

◆ CreatePinList()

void NETLIST_EXPORTER_BASE::CreatePinList ( SCH_COMPONENT aSymbol,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Function findNextSymbolAndCreatePinList finds a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList.

This list is sorted by pin num. The symbol is the next actual symbol after aSymbol.

Power symbols and virtual symbols that have their reference designators starting with '#' are skipped.

Definition at line 122 of file netlist_exporter_base.cpp.

123 {
124  wxString ref( aSymbol->GetRef( aSheetPath ) );
125 
126  // Power symbols and other symbols which have the reference starting with "#" are not
127  // included in netlist (pseudo or virtual symbols)
128 
129  if( ref[0] == wxChar( '#' ) )
130  return;
131 
132  // if( aSymbol->m_FlagControlMulti == 1 )
133  // continue; /* yes */
134  // removed because with multiple instances of one schematic (several sheets pointing to
135  // 1 screen), this will be erroneously be toggled.
136 
137  if( !aSymbol->GetPartRef() )
138  return;
139 
140  m_sortedSymbolPinList.clear();
141 
142  // If symbol is a "multi parts per package" type
143  if( aSymbol->GetPartRef()->GetUnitCount() > 1 )
144  {
145  // Collect all pins for this reference designator by searching the entire design for
146  // other parts with the same reference designator.
147  // This is only done once, it would be too expensive otherwise.
148  findAllUnitsOfSymbol( aSymbol, aSymbol->GetPartRef().get(), aSheetPath );
149  }
150 
151  else // GetUnitCount() <= 1 means one part per package
152  {
154 
155  for( const SCH_PIN* pin : aSymbol->GetPins( aSheetPath ) )
156  {
157  if( SCH_CONNECTION* conn = pin->Connection( aSheetPath ) )
158  {
159  const wxString& netName = conn->Name();
160 
161  // Skip unconnected pins
162  CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
163 
164  if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
165  continue;
166 
167  m_sortedSymbolPinList.emplace_back( pin->GetNumber(), netName );
168  }
169  }
170  }
171 
172  // Sort pins in m_SortedComponentPinList by pin number
174 
175  // Remove duplicate Pins in m_SortedComponentPinList
177 
178  // record the usage of this library component entry.
179  m_libParts.insert( aSymbol->GetPartRef().get() ); // rejects non-unique pointers
180 }
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:137
Calculates the connectivity of a schematic and generates netlists.
void eraseDuplicatePins()
Function eraseDuplicatePins erase duplicate Pins from m_sortedSymbolPinList (i.e.
static bool sortPinsByNum(PIN_INFO &aPin1, PIN_INFO &aPin2)
Comparison routine for sorting by pin numbers.
void findAllUnitsOfSymbol(SCH_COMPONENT *aSymbol, LIB_PART *aPart, SCH_SHEET_PATH *aSheetPath)
Function findAllUnitsOfSymbol is used for "multiple parts per package" symbols.
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_libParts
unique library parts used. LIB_PART items are sorted by names
A subgraph is a set of items that are electrically connected on a single sheet.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
std::vector< SCH_ITEM * > m_items
std::unique_ptr< LIB_PART > & GetPartRef()
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References SCHEMATIC::ConnectionGraph(), NETLIST_EXPORTER_BASE::eraseDuplicatePins(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetPins(), SCH_COMPONENT::GetRef(), CONNECTION_SUBGRAPH::m_items, NETLIST_EXPORTER_BASE::m_libParts, CONNECTION_SUBGRAPH::m_no_connect, NETLIST_EXPORTER_BASE::m_schematic, NETLIST_EXPORTER_BASE::m_sortedSymbolPinList, and sortPinsByNum().

Referenced by NETLIST_EXPORTER_PSPICE::ProcessNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ eraseDuplicatePins()

void NETLIST_EXPORTER_BASE::eraseDuplicatePins ( )
protectedinherited

Function eraseDuplicatePins erase duplicate Pins from m_sortedSymbolPinList (i.e.

set pointer in this list to NULL). (This is a list of pins found in the whole schematic, for a single symbol.) These duplicate pins were put in list because some pins (power pins...) are found more than once when in "multiple parts per package" symbols. For instance, a 74ls00 has 4 parts, and therefore the VCC pin and GND pin appears 4 times in the list. Note: this list MUST be sorted by pin number (.m_PinNum member value) Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1

Definition at line 183 of file netlist_exporter_base.cpp.

184 {
185  for( unsigned ii = 0; ii < m_sortedSymbolPinList.size(); ii++ )
186  {
187  if( m_sortedSymbolPinList[ii].num.empty() ) /* already deleted */
188  continue;
189 
190  /* Search for duplicated pins
191  * If found, remove duplicates. The priority is to keep connected pins
192  * and remove unconnected
193  * - So this allows (for instance when using multi op amps per package
194  * - to connect only one op amp to power
195  * Because the pin list is sorted by m_PinNum value, duplicated pins
196  * are necessary successive in list
197  */
198  int idxref = ii;
199 
200  for( unsigned jj = ii + 1; jj < m_sortedSymbolPinList.size(); jj++ )
201  {
202  if( m_sortedSymbolPinList[jj].num.empty() ) // Already removed
203  continue;
204 
205  // if other pin num, stop search,
206  // because all pins having the same number are consecutive in list.
207  if( m_sortedSymbolPinList[idxref].num != m_sortedSymbolPinList[jj].num )
208  break;
209 
210  m_sortedSymbolPinList[jj].num.clear();
211  }
212  }
213 }
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...

References NETLIST_EXPORTER_BASE::m_sortedSymbolPinList.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList().

◆ findAllUnitsOfSymbol()

void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol ( SCH_COMPONENT aSymbol,
LIB_PART aPart,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Function findAllUnitsOfSymbol is used for "multiple parts per package" symbols.

Search the entire design for all units of aSymbol based on matching reference designator, and for each unit, add all its pins to the temporary sorted pin list, m_sortedSymbolPinList.

Definition at line 216 of file netlist_exporter_base.cpp.

218 {
219  wxString ref = aSymbol->GetRef( aSheetPath );
220  wxString ref2;
221 
222  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
224 
225  for( unsigned i = 0; i < sheetList.size(); i++ )
226  {
227  for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
228  {
229  SCH_COMPONENT* comp2 = static_cast<SCH_COMPONENT*>( item );
230 
231  ref2 = comp2->GetRef( &sheetList[i] );
232 
233  if( ref2.CmpNoCase( ref ) != 0 )
234  continue;
235 
236  for( const SCH_PIN* pin : comp2->GetPins( aSheetPath ) )
237  {
238  if( SCH_CONNECTION* conn = pin->Connection( aSheetPath ) )
239  {
240  const wxString& netName = conn->Name();
241 
242  // Skip unconnected pins
243  CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
244 
245  if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
246  continue;
247 
248  m_sortedSymbolPinList.emplace_back( pin->GetNumber(), netName );
249  }
250  }
251  }
252  }
253 }
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:97
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:137
Calculates the connectivity of a schematic and generates netlists.
A subgraph is a set of items that are electrically connected on a single sheet.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
std::vector< SCH_ITEM * > m_items
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Schematic symbol object.
Definition: sch_component.h:79
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References SCHEMATIC::ConnectionGraph(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_COMPONENT::GetPins(), SCH_COMPONENT::GetRef(), SCHEMATIC::GetSheets(), CONNECTION_SUBGRAPH::m_items, CONNECTION_SUBGRAPH::m_no_connect, NETLIST_EXPORTER_BASE::m_schematic, NETLIST_EXPORTER_BASE::m_sortedSymbolPinList, and SCH_COMPONENT_T.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList().

◆ findNextSymbol()

SCH_COMPONENT * NETLIST_EXPORTER_BASE::findNextSymbol ( EDA_ITEM aItem,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Checks if the given symbol should be processed for netlisting.

Prevents processing multi-unit symbols more than once, etc.

Parameters
aItemis a symbol to check
aSheetPathis the sheet to check the symbol for
Returns
the symbol if it should be processed, or nullptr

Definition at line 74 of file netlist_exporter_base.cpp.

75 {
76  wxString ref;
77 
78  if( aItem->Type() != SCH_COMPONENT_T )
79  return nullptr;
80 
81  // found next component
82  SCH_COMPONENT* symbol = (SCH_COMPONENT*) aItem;
83 
84  // Power symbols and other symbols which have the reference starting with "#" are not
85  // included in netlist (pseudo or virtual symbols)
86  ref = symbol->GetRef( aSheetPath );
87 
88  if( ref[0] == wxChar( '#' ) )
89  return nullptr;
90 
91  // if( symbol->m_FlagControlMulti == 1 )
92  // continue; /* yes */
93  // removed because with multiple instances of one schematic (several sheets pointing to
94  // 1 screen), this will be erroneously be toggled.
95 
96  if( !symbol->GetPartRef() )
97  return nullptr;
98 
99  // If component is a "multi parts per package" type
100  if( symbol->GetPartRef()->GetUnitCount() > 1 )
101  {
102  // test if this reference has already been processed, and if so skip
103  if( m_referencesAlreadyFound.Lookup( ref ) )
104  return nullptr;
105  }
106 
107  // record the usage of this library component entry.
108  m_libParts.insert( symbol->GetPartRef().get() ); // rejects non-unique pointers
109 
110  return symbol;
111 }
bool Lookup(const wxString &aString)
Function Lookup returns true if aString already exists in the set, otherwise returns false and adds a...
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_libParts
unique library parts used. LIB_PART items are sorted by names
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple parts per package" symbols to avoid processing a lib part more than once.
std::unique_ptr< LIB_PART > & GetPartRef()
Schematic symbol object.
Definition: sch_component.h:79
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetRef(), UNIQUE_STRINGS::Lookup(), NETLIST_EXPORTER_BASE::m_libParts, NETLIST_EXPORTER_BASE::m_referencesAlreadyFound, SCH_COMPONENT_T, and EDA_ITEM::Type().

Referenced by NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and WriteNetlist().

◆ MakeCommandLine()

wxString NETLIST_EXPORTER_BASE::MakeCommandLine ( const wxString &  aFormatString,
const wxString &  aNetlistFile,
const wxString &  aFinalFile,
const wxString &  aProjectDirectory 
)
staticinherited

Function MakeCommandLine builds up a string that describes a command line for executing a child process.

The input and output file names along with any options to the executable are all possibly in the returned string.

Parameters
aFormatStringholds:
  • the name of the external program
  • any options needed by that program
  • formatting sequences, see below.
aNetlistFileis the name of the input file for the external program, that is a intermediate netlist file in xml format.
aFinalFileis the name of the output file that the user expects.
aProjectDirectoryis used for P replacement, it should omit the trailing '/'.

Supported formatting sequences and their meaning:

  • B => base filename of selected output file, minus path and extension.
  • I => complete filename and path of the temporary input file.
  • O => complete filename and path of the user chosen output file.
  • P => project directory, without name and without trailing '/'

Definition at line 38 of file netlist_exporter_base.cpp.

42 {
43  // Expand format symbols in the command line:
44  // %B => base filename of selected output file, minus path and extension.
45  // %P => project directory name, without trailing '/' or '\'.
46  // %I => full filename of the input file (the intermediate net file).
47  // %O => complete filename and path (but without extension) of the user chosen output file.
48 
49  wxString ret = aFormatString;
50  wxFileName in = aNetlistFile;
51  wxFileName out = aFinalFile;
52  wxString str_out = out.GetFullPath();
53 
54  ret.Replace( "%P", aProjectPath, true );
55  ret.Replace( "%B", out.GetName(), true );
56  ret.Replace( "%I", in.GetFullPath(), true );
57 
58 #ifdef __WINDOWS__
59  // A ugly hack to run xsltproc that has a serious bug on Window since a long time:
60  // the filename given after -o option (output filename) cannot use '\' in filename
61  // so replace if by '/' if possible (I mean if the filename does not start by "\\"
62  // that is a filename on a Windows server)
63 
64  if( !str_out.StartsWith( "\\\\" ) )
65  str_out.Replace( "\\", "/" );
66 #endif
67 
68  ret.Replace( "%O", str_out, true );
69 
70  return ret;
71 }

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

◆ writeListOfNets()

bool NETLIST_EXPORTER_CADSTAR::writeListOfNets ( FILE *  f)
private

Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it.

Format:

  • ADD_TER RR2 6 "$42"
  • B U1 100
  • 6 CA

Definition at line 109 of file netlist_exporter_cadstar.cpp.

110 {
111  int ret = 0;
112  int print_ter = 0;
113 
114  wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
115  wxString StartNetDesc = StartLine + wxT( "TER" );
116  wxString InitNetDescLine;
117  wxString netName;
118 
119  for( const auto& it : m_schematic->ConnectionGraph()->GetNetMap() )
120  {
121  auto subgraphs = it.second;
122 
123  netName.Printf( wxT( "\"%s\"" ), it.first.first );
124 
125  std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> sorted_items;
126 
127  for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
128  {
129  SCH_SHEET_PATH sheet = subgraph->m_sheet;
130 
131  for( SCH_ITEM* item : subgraph->m_items )
132  {
133  if( item->Type() == SCH_PIN_T )
134  sorted_items.emplace_back( static_cast<SCH_PIN*>( item ), sheet );
135  }
136  }
137 
138  // Netlist ordering: Net name, then ref des, then pin name
139  std::sort( sorted_items.begin(), sorted_items.end(),
140  []( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, std::pair<SCH_PIN*, SCH_SHEET_PATH> b )
141  {
142  wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
143  wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
144 
145  if( ref_a == ref_b )
146  return a.first->GetNumber() < b.first->GetNumber();
147 
148  return ref_a < ref_b;
149  } );
150 
151  // Some duplicates can exist, for example on multi-unit parts with duplicated
152  // pins across units. If the user connects the pins on each unit, they will
153  // appear on separate subgraphs. Remove those here:
154  sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(),
155  []( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, std::pair<SCH_PIN*, SCH_SHEET_PATH> b )
156  {
157  wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
158  wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
159 
160  return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber();
161  } ),
162  sorted_items.end() );
163 
164  print_ter = 0;
165 
166  for( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& pair : sorted_items )
167  {
168  SCH_PIN* pin = pair.first;
169  SCH_SHEET_PATH sheet = pair.second;
170 
171  wxString refText = pin->GetParentSymbol()->GetRef( &sheet );
172  wxString pinText = pin->GetNumber();
173 
174  // Skip power symbols and virtual symbols
175  if( refText[0] == wxChar( '#' ) )
176  continue;
177 
178  switch( print_ter )
179  {
180  case 0:
181  InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
182  InitNetDesc,
183  refText,
184  pinText,
185  netName );
186  print_ter++;
187  break;
188 
189  case 1:
190  ret |= fprintf( f, "%s\n", TO_UTF8( InitNetDescLine ) );
191  ret |= fprintf( f, "%s %s %.4s\n",
192  TO_UTF8( StartNetDesc ),
193  TO_UTF8( refText ),
194  TO_UTF8( pinText ) );
195  print_ter++;
196  break;
197 
198  default:
199  ret |= fprintf( f, " %s %.4s\n",
200  TO_UTF8( refText ),
201  TO_UTF8( pinText ) );
202  break;
203  }
204  }
205  }
206 
207  return ret >= 0;
208 }
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:137
SCH_COMPONENT * GetParentSymbol() const
Definition: sch_pin.cpp:141
wxString GetNumber() const
Definition: sch_pin.h:116
A subgraph is a set of items that are electrically connected on a single sheet.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
const NET_MAP & GetNetMap() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
static wxString StartLine(wxT("."))
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References SCHEMATIC::ConnectionGraph(), CONNECTION_GRAPH::GetNetMap(), SCH_PIN::GetNumber(), SCH_PIN::GetParentSymbol(), SCH_COMPONENT::GetRef(), NETLIST_EXPORTER_BASE::m_schematic, SCH_PIN_T, StartLine(), TO_UTF8, and EDA_ITEM::Type().

Referenced by WriteNetlist().

◆ WriteNetlist()

bool NETLIST_EXPORTER_CADSTAR::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
overridevirtual

Function WriteList writes to specified output file.

Reimplemented from NETLIST_EXPORTER_BASE.

Definition at line 39 of file netlist_exporter_cadstar.cpp.

40 {
41  (void)aNetlistOptions; //unused
42  int ret = 0;
43  FILE* f = NULL;
44 
45  if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
46  {
47  wxString msg;
48  msg.Printf( _( "Failed to create file \"%s\"" ), aOutFileName );
49  DisplayError( NULL, msg );
50  return false;
51  }
52 
53  wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
54  wxString msg;
55  wxString footprint;
56  SCH_COMPONENT* symbol;
57  wxString title = wxT( "Eeschema " ) + GetBuildVersion();
58 
59  ret |= fprintf( f, "%sHEA\n", TO_UTF8( StartLine ) );
60  ret |= fprintf( f, "%sTIM %s\n", TO_UTF8( StartLine ), TO_UTF8( DateAndTime() ) );
61  ret |= fprintf( f, "%sAPP ", TO_UTF8( StartLine ) );
62  ret |= fprintf( f, "\"%s\"\n", TO_UTF8( title ) );
63  ret |= fprintf( f, ".TYP FULL\n\n" );
64 
65  // Create netlist footprints section
67 
68  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
69 
70  for( unsigned i = 0; i < sheetList.size(); i++ )
71  {
72  for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
73  {
74  symbol = findNextSymbol( item, &sheetList[ i ] );
75 
76  if( !symbol )
77  continue;
78 
79  if( !symbol->GetField( FOOTPRINT_FIELD )->IsVoid() )
80  footprint = symbol->GetField( FOOTPRINT_FIELD )->GetShownText();
81  else
82  footprint = "$noname";
83 
84  msg = symbol->GetRef( &sheetList[i] );
85  ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
86  ret |= fprintf( f, "%s", TO_UTF8( msg ) );
87 
88  msg = symbol->GetValue( &sheetList[i], true );
89  msg.Replace( wxT( " " ), wxT( "_" ) );
90  ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
91  ret |= fprintf( f, " \"%s\"", TO_UTF8( footprint ) );
92  ret |= fprintf( f, "\n" );
93  }
94  }
95 
96  ret |= fprintf( f, "\n" );
97 
98  if( ! writeListOfNets( f ) )
99  ret = -1; // set error
100 
101  ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
102 
103  fclose( f );
104 
105  return ret >= 0;
106 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:253
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:97
void Clear()
Function Clear erases the record.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:104
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:321
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple parts per package" symbols to avoid processing a lib part more than once.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
#define NULL
wxString GetBuildVersion()
Get the full KiCad version string.
SCH_COMPONENT * findNextSymbol(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Checks if the given symbol should be processed for netlisting.
static wxString StartLine(wxT("."))
Field Name Module PCB, i.e. "16DIP300".
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
bool writeListOfNets(FILE *f)
Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it.
#define _(s)
Definition: 3d_actions.cpp:33
Schematic symbol object.
Definition: sch_component.h:79
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
wxString DateAndTime()
Definition: string.cpp:411
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References _, UNIQUE_STRINGS::Clear(), DateAndTime(), DisplayError(), NETLIST_EXPORTER_BASE::findNextSymbol(), FOOTPRINT_FIELD, GetBuildVersion(), SCH_COMPONENT::GetField(), SCH_COMPONENT::GetRef(), SCHEMATIC::GetSheets(), SCH_FIELD::GetShownText(), SCH_COMPONENT::GetValue(), SCH_FIELD::IsVoid(), NETLIST_EXPORTER_BASE::m_referencesAlreadyFound, NETLIST_EXPORTER_BASE::m_schematic, NULL, SCH_COMPONENT_T, StartLine(), TO_UTF8, and writeListOfNets().

Member Data Documentation

◆ m_libParts

std::set<LIB_PART*, LIB_PART_LESS_THAN> NETLIST_EXPORTER_BASE::m_libParts
protectedinherited

◆ m_referencesAlreadyFound

UNIQUE_STRINGS NETLIST_EXPORTER_BASE::m_referencesAlreadyFound
protectedinherited

Used for "multiple parts per package" symbols to avoid processing a lib part more than once.

Definition at line 106 of file netlist_exporter_base.h.

Referenced by NETLIST_EXPORTER_BASE::findNextSymbol(), NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and WriteNetlist().

◆ m_savedCurrentSheet

SCH_SHEET_PATH NETLIST_EXPORTER_BASE::m_savedCurrentSheet
protectedinherited

The schematic's CurrentSheet when we entered. Restore on exiting.

Definition at line 115 of file netlist_exporter_base.h.

Referenced by NETLIST_EXPORTER_BASE::NETLIST_EXPORTER_BASE(), and NETLIST_EXPORTER_BASE::~NETLIST_EXPORTER_BASE().

◆ m_schematic

◆ m_sortedSymbolPinList

std::vector<PIN_INFO> NETLIST_EXPORTER_BASE::m_sortedSymbolPinList
protectedinherited

Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic symbol data in netlist (comp section).

No ownership of members. TODO(snh): Descope this object

Definition at line 102 of file netlist_exporter_base.h.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList(), NETLIST_EXPORTER_BASE::eraseDuplicatePins(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().


The documentation for this class was generated from the following files: