2015-03-21 10:46:54 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2019-06-25 23:39:58 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers
|
2015-03-21 10:46:54 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NETLIST_EXPORTER_H
|
|
|
|
#define NETLIST_EXPORTER_H
|
|
|
|
|
|
|
|
#include <kicad_string.h>
|
|
|
|
|
2015-11-05 16:28:31 +00:00
|
|
|
#include <class_libentry.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <netlist_object.h>
|
2015-03-21 10:46:54 +00:00
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_sheet.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2015-03-21 10:46:54 +00:00
|
|
|
|
|
|
|
/**
|
2020-01-10 14:31:00 +00:00
|
|
|
* UNIQUE_STRINGS
|
2015-03-21 10:46:54 +00:00
|
|
|
* tracks unique wxStrings and is useful in telling if a string
|
|
|
|
* has been seen before.
|
|
|
|
*/
|
|
|
|
class UNIQUE_STRINGS
|
|
|
|
{
|
|
|
|
std::set<wxString> m_set; ///< set of wxStrings already found
|
|
|
|
|
|
|
|
typedef std::set<wxString>::iterator us_iterator;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Function Clear
|
|
|
|
* erases the record.
|
|
|
|
*/
|
|
|
|
void Clear() { m_set.clear(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Lookup
|
|
|
|
* returns true if \a aString already exists in the set, otherwise returns
|
|
|
|
* false and adds \a aString to the set for next time.
|
|
|
|
*/
|
|
|
|
bool Lookup( const wxString& aString )
|
|
|
|
{
|
|
|
|
std::pair<us_iterator, bool> pair = m_set.insert( aString );
|
|
|
|
|
|
|
|
return !pair.second;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-05 16:28:31 +00:00
|
|
|
/**
|
|
|
|
* Struct LIB_PART_LESS_THAN
|
|
|
|
* is used by std:set<LIB_PART*> instantiation which uses LIB_PART name as its key.
|
|
|
|
*/
|
|
|
|
struct LIB_PART_LESS_THAN
|
|
|
|
{
|
|
|
|
// a "less than" test on two LIB_PARTs (.m_name wxStrings)
|
|
|
|
bool operator()( LIB_PART* const& libpart1, LIB_PART* const& libpart2 ) const
|
|
|
|
{
|
|
|
|
// Use case specific GetName() wxString compare
|
2018-04-22 20:33:34 +00:00
|
|
|
return libpart1->GetLibId() < libpart2->GetLibId();
|
2015-11-05 16:28:31 +00:00
|
|
|
}
|
|
|
|
};
|
2015-03-21 10:46:54 +00:00
|
|
|
|
2020-06-22 01:43:24 +00:00
|
|
|
struct PIN_INFO
|
|
|
|
{
|
|
|
|
PIN_INFO( const wxString& aPinNumber, const wxString& aNetName ) :
|
|
|
|
num( aPinNumber ),
|
|
|
|
netName( aNetName )
|
|
|
|
{}
|
|
|
|
|
|
|
|
wxString num;
|
|
|
|
wxString netName;
|
|
|
|
};
|
|
|
|
|
2015-03-21 10:46:54 +00:00
|
|
|
/**
|
2020-01-10 14:31:00 +00:00
|
|
|
* NETLIST_EXPORTER
|
2015-03-21 10:46:54 +00:00
|
|
|
* is a abstract class used for the netlist exporters that eeschema supports.
|
|
|
|
*/
|
|
|
|
class NETLIST_EXPORTER
|
|
|
|
{
|
|
|
|
protected:
|
2020-06-22 01:43:24 +00:00
|
|
|
/// Used to temporarily store and filter the list of pins of a schematic component
|
|
|
|
/// when generating schematic component data in netlist (comp section). No ownership
|
|
|
|
/// of members.
|
|
|
|
/// TODO(snh): Descope this object
|
|
|
|
std::vector<PIN_INFO> m_SortedComponentPinList;
|
|
|
|
|
2015-03-21 10:46:54 +00:00
|
|
|
/// Used for "multi parts per package" components,
|
|
|
|
/// avoids processing a lib component more than once.
|
2017-10-06 18:07:43 +00:00
|
|
|
UNIQUE_STRINGS m_ReferencesAlreadyFound;
|
2015-03-21 10:46:54 +00:00
|
|
|
|
2020-06-22 01:43:24 +00:00
|
|
|
/// unique library parts used. LIB_PART items are s
|
|
|
|
/// orted by names
|
2015-11-05 16:28:31 +00:00
|
|
|
std::set<LIB_PART*, LIB_PART_LESS_THAN> m_LibParts;
|
2015-03-21 10:46:54 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
/// The schematic we're generating a netlist for
|
|
|
|
SCHEMATIC* m_schematic;
|
|
|
|
|
2020-06-22 01:43:24 +00:00
|
|
|
/**
|
|
|
|
* Function findNextComponentAndCreatePinList
|
|
|
|
* finds a component from the DrawList and builds
|
|
|
|
* its pin list in m_SortedComponentPinList. This list is sorted by pin num.
|
|
|
|
* the component is the next actual component after aItem
|
|
|
|
* (power symbols and virtual components that have their reference starting by '#'are skipped).
|
|
|
|
*/
|
|
|
|
void CreatePinList( SCH_COMPONENT* aItem, SCH_SHEET_PATH* aSheetPath );
|
|
|
|
|
2020-05-23 16:53:05 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given component should be processed for netlisting.
|
|
|
|
* Prevents processing multi-unit components more than once, etc.
|
|
|
|
* @param aItem is a component to check
|
|
|
|
* @param aSheetPath is the sheet to check the component for
|
|
|
|
* @return the component if it should be processed, or nullptr
|
|
|
|
*/
|
2015-03-21 10:46:54 +00:00
|
|
|
SCH_COMPONENT* findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
|
|
|
|
|
2020-06-22 01:43:24 +00:00
|
|
|
/**
|
|
|
|
* Function eraseDuplicatePins
|
|
|
|
* erase duplicate Pins from m_SortedComponentPinList (i.e. set pointer in this list to NULL).
|
|
|
|
* (This is a list of pins found in the whole schematic, for a single
|
|
|
|
* component.) These duplicate pins were put in list because some pins (powers... )
|
|
|
|
* are found more than one time when we have a multiple parts per package
|
|
|
|
* component. 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
|
|
|
|
*/
|
|
|
|
void eraseDuplicatePins();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function findAllUnitsOfComponent
|
|
|
|
* is used for "multiple parts per package" components.
|
|
|
|
* <p>
|
|
|
|
* Search the entire design for all units of \a aComponent based on
|
|
|
|
* matching reference designator, and for each unit, add all its pins
|
|
|
|
* to the temporary sorted pin list, m_SortedComponentPinList.
|
|
|
|
*/
|
|
|
|
void findAllUnitsOfComponent( SCH_COMPONENT* aComponent,
|
|
|
|
LIB_PART* aEntry,
|
|
|
|
SCH_SHEET_PATH* aSheetPath );
|
|
|
|
|
|
|
|
|
2015-03-21 10:46:54 +00:00
|
|
|
public:
|
2015-06-07 18:18:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param aMasterList we take ownership of this here.
|
2017-10-06 18:07:43 +00:00
|
|
|
* @param aLibTable is the symbol library table of the project.
|
2015-06-07 18:18:45 +00:00
|
|
|
*/
|
2020-05-21 03:40:31 +00:00
|
|
|
NETLIST_EXPORTER( SCHEMATIC* aSchematic ) :
|
2020-05-13 02:00:37 +00:00
|
|
|
m_schematic( aSchematic )
|
2015-03-21 10:46:54 +00:00
|
|
|
{
|
2020-05-21 03:40:31 +00:00
|
|
|
wxASSERT( aSchematic );
|
2015-03-21 10:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~NETLIST_EXPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-07 18:18:45 +00:00
|
|
|
* Function WriteNetlist
|
2015-03-21 10:46:54 +00:00
|
|
|
* writes to specified output file
|
|
|
|
*/
|
2015-06-07 18:18:45 +00:00
|
|
|
virtual bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
|
2015-03-21 10:46:54 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param aFormatString holds:
|
|
|
|
* <ul>
|
|
|
|
* <li>the name of the external program
|
|
|
|
* <li>any options needed by that program
|
|
|
|
* <li>formatting sequences, see below.
|
|
|
|
* </ul>
|
|
|
|
*
|
2017-10-09 18:57:41 +00:00
|
|
|
* @param aNetlistFile is the name of the input file for the
|
|
|
|
* external program, that is a intermediate netlist file in xml format.
|
|
|
|
* @param aFinalFile is the name of the output file that
|
2015-03-21 10:46:54 +00:00
|
|
|
* the user expects.
|
2015-05-26 15:13:33 +00:00
|
|
|
* @param aProjectDirectory is used for %P replacement, it should omit
|
|
|
|
* the trailing '/'.
|
2015-03-21 10:46:54 +00:00
|
|
|
*
|
|
|
|
* <p> Supported formatting sequences and their meaning:
|
|
|
|
* <ul>
|
|
|
|
* <li> %B => base filename of selected output file, minus
|
|
|
|
* path and extension.
|
|
|
|
* <li> %I => complete filename and path of the temporary
|
|
|
|
* input file.
|
|
|
|
* <li> %O => complete filename and path of the user chosen
|
|
|
|
* output file.
|
2015-05-26 15:13:33 +00:00
|
|
|
* <li> %P => project directory, without name and without trailing '/'
|
2015-03-21 10:46:54 +00:00
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
static wxString MakeCommandLine( const wxString& aFormatString,
|
2017-10-09 18:57:41 +00:00
|
|
|
const wxString& aNetlistFile, const wxString& aFinalFile,
|
2015-05-26 15:13:33 +00:00
|
|
|
const wxString& aProjectDirectory
|
|
|
|
);
|
2015-03-21 10:46:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|