KiCad PCB EDA Suite
netlist_exporter_base.h
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 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2021 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, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef NETLIST_EXPORTER_H
27 #define NETLIST_EXPORTER_H
28 
29 #include <lib_pin.h>
30 #include <sch_symbol.h>
31 #include <sch_text.h>
32 #include <sch_sheet.h>
33 #include <schematic.h>
34 
39 {
40 public:
44  void Clear() { m_set.clear(); }
45 
50  bool Lookup( const wxString& aString )
51  {
52  std::pair<us_iterator, bool> pair = m_set.insert( aString );
53 
54  return !pair.second;
55  }
56 
57  std::set<wxString> m_set;
58 
59  typedef std::set<wxString>::iterator us_iterator;
60 };
61 
66 {
67  // a "less than" test on two LIB_SYMBOLs (.m_name wxStrings)
68  bool operator()( LIB_SYMBOL* const& libsymbol1, LIB_SYMBOL* const& libsymbol2 ) const
69  {
70  // Use case specific GetName() wxString compare
71  return libsymbol1->GetLibId() < libsymbol2->GetLibId();
72  }
73 };
74 
75 
76 struct PIN_INFO
77 {
78  PIN_INFO( const wxString& aPinNumber, const wxString& aNetName ) :
79  num( aPinNumber ),
80  netName( aNetName )
81  {}
82 
83  wxString num;
84  wxString netName;
85 };
86 
87 
92 {
93 public:
99  m_schematic( aSchematic )
100  {
101  wxASSERT( aSchematic );
103  }
104 
106  {
108  }
109 
113  virtual bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
114  {
115  return false;
116  }
117 
147  static wxString MakeCommandLine( const wxString& aFormatString, const wxString& aNetlistFile,
148  const wxString& aFinalFile,
149  const wxString& aProjectDirectory );
150 
151 protected:
161  void CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath,
162  bool aKeepUnconnectedPins );
163 
173  SCH_SYMBOL* findNextSymbol( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
174 
185  void eraseDuplicatePins();
186 
196  void findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, LIB_SYMBOL* aLibSymbol,
197  SCH_SHEET_PATH* aSheetPath, bool aKeepUnconnectedPins );
198 
202  std::vector<PIN_INFO> m_sortedSymbolPinList;
203 
207 
209  std::set<LIB_SYMBOL*, LIB_SYMBOL_LESS_THAN> m_libParts;
210 
213 
216 };
217 
218 #endif
virtual bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions)
Write to specified output file.
bool Lookup(const wxString &aString)
virtual SCH_SHEET_PATH & CurrentSheet() const =0
std::set< wxString > m_set
set of wxStrings already found
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
Used by std:set<LIB_SYMBOL*> instantiation which uses LIB_SYMBOL name as its key.
void eraseDuplicatePins()
Erase duplicate pins from m_sortedSymbolPinList (i.e.
PIN_INFO(const wxString &aPinNumber, const wxString &aNetName)
bool operator()(LIB_SYMBOL *const &libsymbol1, LIB_SYMBOL *const &libsymbol2) const
void Clear()
Erase the record.
Define a library symbol object.
Definition: lib_symbol.h:96
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Check if the given symbol should be processed for netlisting.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
static wxString MakeCommandLine(const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
Build up a string that describes a command line for executing a child process.
Track unique wxStrings and is useful in telling if a string has been seen before.
LIB_ID GetLibId() const override
Definition: lib_symbol.h:135
void CreatePinList(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
An abstract class used for the netlist exporters that Eeschema supports.
NETLIST_EXPORTER_BASE(SCHEMATIC_IFACE *aSchematic)
virtual void SetCurrentSheet(const SCH_SHEET_PATH &aPath)=0
Schematic symbol object.
Definition: sch_symbol.h:78
std::set< wxString >::iterator us_iterator
void findAllUnitsOfSymbol(SCH_SYMBOL *aSchSymbol, LIB_SYMBOL *aLibSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
Find all units for symbols with multiple symbols per package.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
SCH_SHEET_PATH m_savedCurrentSheet
The schematic's CurrentSheet when we entered. Restore on exiting.