1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/**
* @file pcb_netlist.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2011 Jean-Pierre Charras.
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>.
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
#include <macros.h>
#include <kicad_string.h>
#include <reporter.h>
#include <pcb_netlist.h>
#include <class_module.h>
#include <eda_pattern_match.h>
int COMPONENT_NET::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
{
return aOut->Print( aNestLevel, "(pin_net %s %s)",
aOut->Quotew( m_pinName ).c_str(),
aOut->Quotew( m_netName ).c_str() );
}
void COMPONENT::SetModule( MODULE* aModule )
{
m_footprint.reset( aModule );
if( aModule == NULL )
return;
aModule->SetReference( m_reference );
aModule->SetValue( m_value );
aModule->SetFPID( m_fpid );
aModule->SetPath( m_timeStamp );
}
COMPONENT_NET COMPONENT::m_emptyNet;
const COMPONENT_NET& COMPONENT::GetNet( const wxString& aPinName )
{
for( unsigned i = 0; i < m_nets.size(); i++ )
{
if( m_nets[i].GetPinName() == aPinName )
return m_nets[i];
}
return m_emptyNet;
}
void COMPONENT::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
{
int nl = aNestLevel;
aOut->Print( nl, "(ref %s ", aOut->Quotew( m_reference ).c_str() );
aOut->Print( 0, "(fpid %s)\n", aOut->Quotew( m_fpid.Format() ).c_str() );
if( ! ( aCtl & CTL_OMIT_EXTRA ) )
{
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() );
aOut->Print( nl+1, "(timestamp %s)\n", aOut->Quotew( m_timeStamp ).c_str() );
}
if( !( aCtl & CTL_OMIT_FILTERS ) && m_footprintFilters.GetCount() )
{
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" );
}
if( !( aCtl & CTL_OMIT_NETS ) && m_nets.size() )
{
int llen = aOut->Print( nl+1, "(nets " );
for( unsigned i = 0; i < m_nets.size(); ++i )
{
if( llen > 80 )
{
aOut->Print( 0, "\n" );
llen = aOut->Print( nl+1, " " );
}
llen += m_nets[i].Format( aOut, 0, aCtl );
}
aOut->Print( 0, ")\n" );
}
aOut->Print( nl, ")\n" ); // </ref>
}
void NETLIST::Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
{
int nl = aNestLevel;
aOut->Print( nl, "(%s\n", aDocName );
for( unsigned i = 0; i < m_components.size(); i++ )
{
m_components[i].Format( aOut, nl+1, aCtl );
}
aOut->Print( nl, ")\n" );
}
void NETLIST::AddComponent( COMPONENT* aComponent )
{
m_components.push_back( aComponent );
}
COMPONENT* NETLIST::GetComponentByReference( const wxString& aReference )
{
COMPONENT* component = NULL;
for( unsigned i = 0; i < m_components.size(); i++ )
{
if( m_components[i].GetReference() == aReference )
{
component = &m_components[i];
break;
}
}
return component;
}
COMPONENT* NETLIST::GetComponentByTimeStamp( const wxString& aTimeStamp )
{
COMPONENT* component = NULL;
for( unsigned i = 0; i < m_components.size(); i++ )
{
if( m_components[i].GetTimeStamp() == aTimeStamp )
{
component = &m_components[i];
break;
}
}
return component;
}
/**
* Function ByFPID
* is a helper function used to sort the component list used by loadNewModules.
*/
static bool ByFPID( const COMPONENT& ref, const COMPONENT& cmp )
{
return ref.GetFPID() > cmp.GetFPID();
}
void NETLIST::SortByFPID()
{
m_components.sort( ByFPID );
}
/**
* Operator <
* compares two #COMPONENT objects by reference designator.
*/
bool operator < ( const COMPONENT& item1, const COMPONENT& item2 )
{
return RefDesStringCompare(item1.GetReference(), item2.GetReference() ) < 0;
}
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;
}
bool NETLIST::AllFootprintsLinked() const
{
for( unsigned i = 0; i < m_components.size(); i++ )
{
if( m_components[i].GetFPID().empty() )
return false;
}
return true;
}
|