2013-09-14 20:33:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2011 Jean-Pierre Charras.
|
2021-03-24 13:25:32 +00:00
|
|
|
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>.
|
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-14 20:33:22 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-01-29 10:50:50 +00:00
|
|
|
#include <refdes_utils.h>
|
2019-11-17 12:58:38 +00:00
|
|
|
#include "pcb_netlist.h"
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
|
2014-07-07 04:12:04 +00:00
|
|
|
int COMPONENT_NET::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2014-07-07 04:12:04 +00:00
|
|
|
return aOut->Print( aNestLevel, "(pin_net %s %s)",
|
2018-10-19 11:28:34 +00:00
|
|
|
aOut->Quotew( m_pinName ).c_str(),
|
|
|
|
aOut->Quotew( m_netName ).c_str() );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void COMPONENT::SetFootprint( FOOTPRINT* aFootprint )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
m_footprint.reset( aFootprint );
|
2021-02-21 04:03:56 +00:00
|
|
|
KIID_PATH path = m_path;
|
|
|
|
|
2021-04-25 13:13:42 +00:00
|
|
|
if( !m_kiids.empty() )
|
|
|
|
path.push_back( m_kiids.front() );
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( aFootprint == nullptr )
|
2013-09-14 20:33:22 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetReference( m_reference );
|
|
|
|
aFootprint->SetValue( m_value );
|
|
|
|
aFootprint->SetFPID( m_fpid );
|
2021-02-21 04:03:56 +00:00
|
|
|
aFootprint->SetPath( path );
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetProperties( m_properties );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COMPONENT_NET COMPONENT::m_emptyNet;
|
|
|
|
|
|
|
|
|
2020-05-19 02:40:13 +00:00
|
|
|
const COMPONENT_NET& COMPONENT::GetNet( const wxString& aPinName ) const
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2020-08-08 21:47:57 +00:00
|
|
|
for( const COMPONENT_NET& net : m_nets )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2020-08-08 21:47:57 +00:00
|
|
|
if( net.GetPinName() == aPinName )
|
|
|
|
return net;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_emptyNet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-07 04:12:04 +00:00
|
|
|
void COMPONENT::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2014-07-07 04:12:04 +00:00
|
|
|
int nl = aNestLevel;
|
|
|
|
|
|
|
|
aOut->Print( nl, "(ref %s ", aOut->Quotew( m_reference ).c_str() );
|
2014-07-28 09:24:15 +00:00
|
|
|
aOut->Print( 0, "(fpid %s)\n", aOut->Quotew( m_fpid.Format() ).c_str() );
|
2014-07-07 04:12:04 +00:00
|
|
|
|
2021-03-24 13:25:32 +00:00
|
|
|
if( !( aCtl & CTL_OMIT_EXTRA ) )
|
2014-07-07 04:12:04 +00:00
|
|
|
{
|
|
|
|
aOut->Print( nl+1, "(value %s)\n", aOut->Quotew( m_value ).c_str() );
|
|
|
|
aOut->Print( nl+1, "(name %s)\n", aOut->Quotew( m_name ).c_str() );
|
|
|
|
aOut->Print( nl+1, "(library %s)\n", aOut->Quotew( m_library ).c_str() );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
|
|
|
wxString path;
|
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
for( const KIID& pathStep : m_path )
|
2020-02-20 12:11:04 +00:00
|
|
|
path += '/' + pathStep.AsString();
|
|
|
|
|
2021-03-24 13:25:32 +00:00
|
|
|
if( !( aCtl & CTL_OMIT_FP_UUID ) && !m_kiids.empty() )
|
2021-02-21 04:03:56 +00:00
|
|
|
path += '/' + m_kiids.front().AsString();
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
aOut->Print( nl+1, "(timestamp %s)\n", aOut->Quotew( path ).c_str() );
|
2014-07-07 04:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !( aCtl & CTL_OMIT_FILTERS ) && m_footprintFilters.GetCount() )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2014-07-07 04:12:04 +00:00
|
|
|
aOut->Print( nl+1, "(fp_filters" );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_footprintFilters.GetCount(); ++i )
|
|
|
|
aOut->Print( 0, " %s", aOut->Quotew( m_footprintFilters[i] ).c_str() );
|
|
|
|
|
|
|
|
aOut->Print( 0, ")\n" );
|
|
|
|
}
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2014-07-07 04:12:04 +00:00
|
|
|
if( !( aCtl & CTL_OMIT_NETS ) && m_nets.size() )
|
|
|
|
{
|
|
|
|
int llen = aOut->Print( nl+1, "(nets " );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_nets.size(); ++i )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2014-07-07 04:12:04 +00:00
|
|
|
if( llen > 80 )
|
|
|
|
{
|
|
|
|
aOut->Print( 0, "\n" );
|
|
|
|
llen = aOut->Print( nl+1, " " );
|
|
|
|
}
|
|
|
|
|
|
|
|
llen += m_nets[i].Format( aOut, 0, aCtl );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:12:04 +00:00
|
|
|
aOut->Print( 0, ")\n" );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:12:04 +00:00
|
|
|
aOut->Print( nl, ")\n" ); // </ref>
|
|
|
|
}
|
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2014-07-07 04:41:29 +00:00
|
|
|
void NETLIST::Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
|
2014-07-07 04:12:04 +00:00
|
|
|
{
|
|
|
|
int nl = aNestLevel;
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2014-07-07 04:41:29 +00:00
|
|
|
aOut->Print( nl, "(%s\n", aDocName );
|
2014-07-07 04:12:04 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_components.size(); i++ )
|
|
|
|
{
|
|
|
|
m_components[i].Format( aOut, nl+1, aCtl );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:12:04 +00:00
|
|
|
aOut->Print( nl, ")\n" );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NETLIST::AddComponent( COMPONENT* aComponent )
|
|
|
|
{
|
|
|
|
m_components.push_back( aComponent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COMPONENT* NETLIST::GetComponentByReference( const wxString& aReference )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
COMPONENT* component = nullptr;
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_components.size(); i++ )
|
|
|
|
{
|
|
|
|
if( m_components[i].GetReference() == aReference )
|
|
|
|
{
|
|
|
|
component = &m_components[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
COMPONENT* NETLIST::GetComponentByPath( const KIID_PATH& aUuidPath )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2021-02-22 01:27:38 +00:00
|
|
|
if( aUuidPath.empty() )
|
|
|
|
return nullptr;
|
|
|
|
|
2021-02-21 04:03:56 +00:00
|
|
|
KIID comp_uuid = aUuidPath.back();
|
|
|
|
KIID_PATH base = aUuidPath;
|
|
|
|
|
|
|
|
if( !base.empty() )
|
|
|
|
base.pop_back();
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
for( COMPONENT& component : m_components )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2021-02-21 04:03:56 +00:00
|
|
|
const std::vector<KIID>& kiids = component.GetKIIDs();
|
|
|
|
|
|
|
|
if( base != component.GetPath() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( std::find( kiids.begin(), kiids.end(), comp_uuid ) != kiids.end() )
|
2020-02-20 12:11:04 +00:00
|
|
|
return &component;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
return nullptr;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 13:25:32 +00:00
|
|
|
* A helper function used to sort the component list used by loadNewModules.
|
2013-09-14 20:33:22 +00:00
|
|
|
*/
|
|
|
|
static bool ByFPID( const COMPONENT& ref, const COMPONENT& cmp )
|
|
|
|
{
|
|
|
|
return ref.GetFPID() > cmp.GetFPID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NETLIST::SortByFPID()
|
|
|
|
{
|
|
|
|
m_components.sort( ByFPID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 13:25:32 +00:00
|
|
|
* Compare two #COMPONENT objects by reference designator.
|
2013-09-14 20:33:22 +00:00
|
|
|
*/
|
|
|
|
bool operator < ( const COMPONENT& item1, const COMPONENT& item2 )
|
|
|
|
{
|
2019-01-29 10:50:50 +00:00
|
|
|
return UTIL::RefDesStringCompare( item1.GetReference(), item2.GetReference() ) < 0;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NETLIST::SortByReference()
|
|
|
|
{
|
|
|
|
m_components.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool NETLIST::AnyFootprintsLinked() const
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < m_components.size(); i++ )
|
|
|
|
{
|
|
|
|
if( !m_components[i].GetFPID().empty() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|