2013-09-14 16:33:22 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras.
|
2021-03-24 09:25:32 -04:00
|
|
|
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@gmail.com>.
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-14 16:33:22 -04: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
|
|
|
|
*/
|
|
|
|
|
2017-02-26 18:15:23 +01:00
|
|
|
#ifndef PCB_NETLIST_H
|
|
|
|
#define PCB_NETLIST_H
|
|
|
|
|
2013-09-14 16:33:22 -04:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
|
|
|
#include <wx/arrstr.h>
|
2023-08-07 09:16:32 -04:00
|
|
|
#include <nlohmann/json.hpp>
|
2024-09-27 20:48:12 +01:00
|
|
|
#include <unordered_set>
|
2013-09-14 16:33:22 -04:00
|
|
|
|
2016-11-20 18:35:08 -05:00
|
|
|
#include <lib_id.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2024-07-14 17:15:50 +02:00
|
|
|
#include <ctl_flags.h>
|
2013-09-14 16:33:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
class REPORTER;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Used to store the component pin name to net name (and pin function)
|
2019-11-17 10:11:29 +01:00
|
|
|
* associations stored in a netlist.
|
2013-09-14 16:33:22 -04:00
|
|
|
*/
|
|
|
|
class COMPONENT_NET
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
COMPONENT_NET() {}
|
|
|
|
|
2019-11-17 10:11:29 +01:00
|
|
|
COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
|
2021-01-21 21:46:03 +00:00
|
|
|
const wxString& aPinFunction, const wxString& aPinType ) :
|
|
|
|
m_pinName( aPinName ),
|
|
|
|
m_netName( aNetName ),
|
|
|
|
m_pinFunction( aPinFunction ),
|
|
|
|
m_pinType( aPinType )
|
2013-09-14 16:33:22 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString& GetPinName() const { return m_pinName; }
|
|
|
|
const wxString& GetNetName() const { return m_netName; }
|
2019-11-17 10:11:29 +01:00
|
|
|
const wxString& GetPinFunction() const { return m_pinFunction; }
|
2021-01-21 21:46:03 +00:00
|
|
|
const wxString& GetPinType() const { return m_pinType; }
|
2013-09-14 16:33:22 -04:00
|
|
|
|
|
|
|
bool IsValid() const { return !m_pinName.IsEmpty(); }
|
|
|
|
|
|
|
|
bool operator <( const COMPONENT_NET& aNet ) const
|
|
|
|
{
|
|
|
|
return m_pinName < aNet.m_pinName;
|
|
|
|
}
|
|
|
|
|
2014-07-06 23:12:04 -05:00
|
|
|
int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
|
2021-06-04 13:44:22 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxString m_pinName;
|
|
|
|
wxString m_netName;
|
|
|
|
wxString m_pinFunction;
|
|
|
|
wxString m_pinType;
|
2013-09-14 16:33:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
|
|
|
|
|
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Store all of the related footprint information found in a netlist.
|
2013-09-14 16:33:22 -04:00
|
|
|
*/
|
|
|
|
class COMPONENT
|
|
|
|
{
|
|
|
|
public:
|
2021-02-20 20:03:56 -08:00
|
|
|
COMPONENT( const LIB_ID& aFPID,
|
|
|
|
const wxString& aReference,
|
|
|
|
const wxString& aValue,
|
|
|
|
const KIID_PATH& aPath,
|
|
|
|
const std::vector<KIID>& aKiids )
|
2013-09-14 16:33:22 -04:00
|
|
|
{
|
|
|
|
m_fpid = aFPID;
|
|
|
|
m_reference = aReference;
|
|
|
|
m_value = aValue;
|
2018-03-26 19:55:59 +01:00
|
|
|
m_pinCount = 0;
|
2020-02-20 12:11:04 +00:00
|
|
|
m_path = aPath;
|
2021-02-20 20:03:56 -08:00
|
|
|
m_kiids = aKiids;
|
2025-03-22 22:26:07 -04:00
|
|
|
m_duplicatePadNumbersAreJumpers = false;
|
2013-09-14 16:33:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~COMPONENT() { };
|
|
|
|
|
2021-01-21 21:46:03 +00:00
|
|
|
void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
|
|
|
|
const wxString& aPinType )
|
2013-09-14 16:33:22 -04:00
|
|
|
{
|
2022-02-05 19:53:31 -05:00
|
|
|
m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
|
2013-09-14 16:33:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned GetNetCount() const { return m_nets.size(); }
|
|
|
|
|
|
|
|
const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
|
|
|
|
|
2020-05-18 22:40:13 -04:00
|
|
|
const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
|
2013-09-14 16:33:22 -04:00
|
|
|
|
2022-07-24 23:40:47 +01:00
|
|
|
void ClearNets() { m_nets.clear(); }
|
|
|
|
|
2013-09-14 16:33:22 -04:00
|
|
|
void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
|
|
|
|
|
|
|
|
void SetName( const wxString& aName ) { m_name = aName;}
|
|
|
|
const wxString& GetName() const { return m_name; }
|
|
|
|
|
|
|
|
void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
|
|
|
|
const wxString& GetLibrary() const { return m_library; }
|
|
|
|
|
2022-07-24 23:40:47 +01:00
|
|
|
void SetReference( const wxString& aReference ) { m_reference = aReference; }
|
2013-09-14 16:33:22 -04:00
|
|
|
const wxString& GetReference() const { return m_reference; }
|
2022-07-24 23:40:47 +01:00
|
|
|
|
|
|
|
void SetValue( const wxString& aValue ) { m_value = aValue; }
|
2013-09-14 16:33:22 -04:00
|
|
|
const wxString& GetValue() const { return m_value; }
|
|
|
|
|
2023-08-07 09:16:32 -04:00
|
|
|
void SetFields( nlohmann::ordered_map<wxString, wxString>& aFields )
|
|
|
|
{
|
|
|
|
m_fields = std::move( aFields );
|
|
|
|
}
|
|
|
|
const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
|
2023-05-04 09:42:27 -04:00
|
|
|
|
2020-08-08 22:47:57 +01:00
|
|
|
void SetProperties( std::map<wxString, wxString>& aProps )
|
|
|
|
{
|
|
|
|
m_properties = std::move( aProps );
|
|
|
|
}
|
|
|
|
const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
|
|
|
|
|
2020-06-08 19:36:25 +01:00
|
|
|
void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
|
2018-03-26 19:55:59 +01:00
|
|
|
const LIB_ID& GetFPID() const { return m_fpid; }
|
2013-09-14 16:33:22 -04:00
|
|
|
|
2020-06-08 19:36:25 +01:00
|
|
|
void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
|
2016-11-20 18:35:08 -05:00
|
|
|
const LIB_ID& GetAltFPID() const { return m_altFpid; }
|
2014-10-28 16:15:39 +01:00
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
const KIID_PATH& GetPath() const { return m_path; }
|
2013-09-14 16:33:22 -04:00
|
|
|
|
2021-02-20 20:03:56 -08:00
|
|
|
const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
|
|
|
|
|
2020-06-08 19:36:25 +01:00
|
|
|
void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
|
2013-09-14 16:33:22 -04:00
|
|
|
const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
|
|
|
|
|
2020-06-08 19:36:25 +01:00
|
|
|
void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
|
2018-03-26 19:55:59 +01:00
|
|
|
int GetPinCount() const { return m_pinCount; }
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* GetFootprint( bool aRelease = false )
|
2013-09-14 16:33:22 -04:00
|
|
|
{
|
|
|
|
return ( aRelease ) ? m_footprint.release() : m_footprint.get();
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void SetFootprint( FOOTPRINT* aFootprint );
|
2013-09-14 16:33:22 -04:00
|
|
|
|
|
|
|
bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
|
|
|
|
{
|
|
|
|
return aLibrary == m_library && aName == m_name;
|
|
|
|
}
|
|
|
|
|
2014-07-06 23:12:04 -05:00
|
|
|
void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
|
2021-03-24 09:25:32 -04:00
|
|
|
|
2023-12-31 13:24:10 +01:00
|
|
|
void SetHumanReadablePath( const wxString& aPath ) { m_humanReadablePath = aPath; }
|
|
|
|
const wxString& GetHumanReadablePath() const { return m_humanReadablePath; }
|
|
|
|
|
2024-09-27 20:48:12 +01:00
|
|
|
void SetComponentClassNames( const std::unordered_set<wxString>& aClassNames )
|
|
|
|
{
|
|
|
|
m_componentClassNames = aClassNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_set<wxString>& GetComponentClassNames() { return m_componentClassNames; }
|
|
|
|
|
2025-03-22 22:26:07 -04:00
|
|
|
bool GetDuplicatePadNumbersAreJumpers() const { return m_duplicatePadNumbersAreJumpers; }
|
|
|
|
void SetDuplicatePadNumbersAreJumpers( bool aEnabled ) { m_duplicatePadNumbersAreJumpers = aEnabled; }
|
|
|
|
|
|
|
|
std::vector<std::set<wxString>>& JumperPadGroups() { return m_jumperPadGroups; }
|
|
|
|
const std::vector<std::set<wxString>>& JumperPadGroups() const { return m_jumperPadGroups; }
|
|
|
|
|
2021-03-24 09:25:32 -04:00
|
|
|
private:
|
2022-07-24 23:40:47 +01:00
|
|
|
std::vector<COMPONENT_NET> m_nets; ///< list of nets shared by the component pins
|
|
|
|
|
|
|
|
wxArrayString m_footprintFilters;
|
|
|
|
int m_pinCount;
|
|
|
|
wxString m_reference;
|
|
|
|
wxString m_value;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
2023-12-31 13:24:10 +01:00
|
|
|
// human-readable hierarchical sheet path (e.g. /root/block0/sheet1)
|
|
|
|
wxString m_humanReadablePath;
|
|
|
|
|
2021-03-24 09:25:32 -04:00
|
|
|
/// A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID, .. ]
|
2022-07-24 23:40:47 +01:00
|
|
|
KIID_PATH m_path;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
/// A vector of possible KIIDs corresponding to all units in a symbol
|
2022-07-24 23:40:47 +01:00
|
|
|
std::vector<KIID> m_kiids;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
2022-07-24 23:40:47 +01:00
|
|
|
/// The name of the component in #m_library used when it was placed on the schematic.
|
|
|
|
wxString m_name;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
/// The name of the component library where #m_name was found.
|
2022-07-24 23:40:47 +01:00
|
|
|
wxString m_library;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
/// The #LIB_ID of the footprint assigned to the component.
|
2022-07-24 23:40:47 +01:00
|
|
|
LIB_ID m_fpid;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
/// The alt LIB_ID of the footprint, when there are 2 different assigned footprints,
|
|
|
|
/// One from the netlist, the other from the .cmp file.
|
|
|
|
/// this one is a copy of the netlist footprint assignment
|
2022-07-24 23:40:47 +01:00
|
|
|
LIB_ID m_altFpid;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
/// The #FOOTPRINT loaded for #m_FPID.
|
2022-07-24 23:40:47 +01:00
|
|
|
std::unique_ptr<FOOTPRINT> m_footprint;
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
/// Component-specific properties found in the netlist.
|
|
|
|
std::map<wxString, wxString> m_properties;
|
|
|
|
|
2023-05-04 09:42:27 -04:00
|
|
|
/// Component-specific user fields found in the netlist.
|
2023-08-07 09:16:32 -04:00
|
|
|
nlohmann::ordered_map<wxString, wxString> m_fields;
|
2023-05-04 09:42:27 -04:00
|
|
|
|
2024-09-27 20:48:12 +01:00
|
|
|
/// Component classes for this footprint
|
|
|
|
std::unordered_set<wxString> m_componentClassNames;
|
|
|
|
|
2025-03-22 22:26:07 -04:00
|
|
|
/// Jumper pad groups for this footprint
|
|
|
|
std::vector<std::set<wxString>> m_jumperPadGroups;
|
|
|
|
|
|
|
|
/// Flag that this footprint should automatically treat sets of two or more pads with the same
|
|
|
|
/// number as jumpered pin groups
|
|
|
|
bool m_duplicatePadNumbersAreJumpers;
|
|
|
|
|
2022-07-24 23:40:47 +01:00
|
|
|
static COMPONENT_NET m_emptyNet;
|
2013-09-14 16:33:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef boost::ptr_vector< COMPONENT > COMPONENTS;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Store information read from a netlist along with the flags used to update the NETLIST in the
|
|
|
|
* #BOARD.
|
2013-09-14 16:33:22 -04:00
|
|
|
*/
|
|
|
|
class NETLIST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NETLIST() :
|
|
|
|
m_findByTimeStamp( false ),
|
|
|
|
m_replaceFootprints( false )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if there are no components in the netlist.
|
|
|
|
*/
|
|
|
|
bool IsEmpty() const { return m_components.empty(); }
|
|
|
|
|
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Remove all components from the netlist.
|
2013-09-14 16:33:22 -04:00
|
|
|
*/
|
|
|
|
void Clear() { m_components.clear(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the number of components in the netlist.
|
|
|
|
*/
|
|
|
|
unsigned GetCount() const { return m_components.size(); }
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:44:22 -04:00
|
|
|
* Return the #COMPONENT at \a aIndex.
|
2013-09-14 16:33:22 -04:00
|
|
|
*
|
|
|
|
* @param aIndex the index in #m_components to fetch.
|
|
|
|
* @return a pointer to the #COMPONENT at \a Index.
|
|
|
|
*/
|
|
|
|
COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
|
|
|
|
|
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Add \a aComponent to the NETLIST.
|
2013-09-14 16:33:22 -04:00
|
|
|
*
|
|
|
|
* @note If \a aComponent already exists in the NETLIST, \a aComponent is deleted
|
|
|
|
* to prevent memory leaks. An assertion is raised in debug builds.
|
|
|
|
*
|
|
|
|
* @param aComponent is the COMPONENT to save to the NETLIST.
|
|
|
|
*/
|
|
|
|
void AddComponent( COMPONENT* aComponent );
|
|
|
|
|
2014-10-28 16:15:39 +01:00
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Return a #COMPONENT by \a aReference.
|
2013-09-14 16:33:22 -04:00
|
|
|
*
|
|
|
|
* @param aReference is the reference designator the #COMPONENT.
|
|
|
|
* @return a pointer to the #COMPONENT that matches \a aReference if found. Otherwise NULL.
|
|
|
|
*/
|
|
|
|
COMPONENT* GetComponentByReference( const wxString& aReference );
|
|
|
|
|
2014-10-28 16:15:39 +01:00
|
|
|
/**
|
2021-03-24 09:25:32 -04:00
|
|
|
* Return a #COMPONENT by \a aPath.
|
2013-09-14 16:33:22 -04:00
|
|
|
*
|
2020-02-21 22:20:42 +00:00
|
|
|
* @param aPath is the KIID_PATH [ sheetUUID, .., compUUID ] of the #COMPONENT.
|
2020-02-20 12:11:04 +00:00
|
|
|
* @return a pointer to the #COMPONENT that matches \a aPath if found. Otherwise NULL.
|
2013-09-14 16:33:22 -04:00
|
|
|
*/
|
2020-02-21 22:20:42 +00:00
|
|
|
COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
|
2013-09-14 16:33:22 -04:00
|
|
|
|
|
|
|
void SortByFPID();
|
|
|
|
void SortByReference();
|
|
|
|
|
|
|
|
void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
|
|
|
|
bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
|
|
|
|
|
2020-08-26 22:43:38 +01:00
|
|
|
void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
|
2013-09-14 16:33:22 -04:00
|
|
|
bool GetReplaceFootprints() const { return m_replaceFootprints; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if any component with a footprint link is found.
|
|
|
|
*/
|
|
|
|
bool AnyFootprintsLinked() const;
|
|
|
|
|
2014-07-06 23:41:29 -05:00
|
|
|
void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
|
2014-07-06 23:12:04 -05:00
|
|
|
|
2020-10-14 20:20:54 +01:00
|
|
|
#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
|
2014-07-06 23:12:04 -05:00
|
|
|
|
2020-10-14 19:24:27 -04:00
|
|
|
void FormatCvpcbNetlist( OUTPUTFORMATTER* aOut )
|
2014-07-06 23:12:04 -05:00
|
|
|
{
|
2020-10-14 20:20:54 +01:00
|
|
|
Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
|
2014-07-06 23:12:04 -05:00
|
|
|
}
|
2021-03-24 09:25:32 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
COMPONENTS m_components; // Components found in the netlist.
|
|
|
|
|
|
|
|
bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
|
|
|
|
bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
|
2013-09-14 16:33:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PCB_NETLIST_H
|