KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pin_map_netlist.cpp
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <memory>
23
24#include <pin_map.h>
25#include <lib_symbol.h>
26#include <sch_pin.h>
27#include <sch_symbol.h>
28#include <sch_screen.h>
29#include <sch_sheet.h>
30#include <sch_sheet_path.h>
31#include <schematic.h>
32#include <connection_graph.h>
35
36
37namespace
38{
39LIB_ID makeFp( const wxString& aLibNick, const wxString& aName )
40{
41 LIB_ID id;
42 id.SetLibNickname( aLibNick );
43 id.SetLibItemName( aName );
44 return id;
45}
46
47
49class TEST_NETLIST_EXPORTER : public NETLIST_EXPORTER_BASE
50{
51public:
52 explicit TEST_NETLIST_EXPORTER( SCHEMATIC* aSchematic ) : NETLIST_EXPORTER_BASE( aSchematic ) {}
53
54 std::vector<PIN_INFO> Pins( SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aPath )
55 {
56 return CreatePinList( aSymbol, aPath, true );
57 }
58};
59} // namespace
60
61
63{
65 {
66 m_settingsManager.LoadProject( "" );
67 m_schematic = std::make_unique<SCHEMATIC>( &m_settingsManager.Prj() );
68 m_schematic->Reset();
69
70 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
71 SCH_SHEET* root = new SCH_SHEET( m_schematic.get() );
72 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic.get() );
73 root->SetScreen( screen );
74
75 m_schematic->AddTopLevelSheet( root );
76 m_schematic->RemoveTopLevelSheet( defaultSheet );
77 delete defaultSheet;
78 }
79
81 std::unique_ptr<SCHEMATIC> m_schematic;
82 std::unique_ptr<LIB_SYMBOL> m_libSym;
83};
84
85
86BOOST_FIXTURE_TEST_SUITE( PinMapNetlist, PIN_MAP_NETLIST_FIXTURE )
87
88
89// The headline verification (plan step 3): an op-amp pin mapped to "[4,9]" for a DFN-8-EP package
90// must produce netlist entries for BOTH pad 4 and pad 9 on the same net.
91BOOST_AUTO_TEST_CASE( MappedPinEmitsBothStackedPads )
92{
93 SCH_SCREEN* screen = m_schematic->RootScreen();
95 path.push_back( &m_schematic->Root() );
96
97 const LIB_ID dfn = makeFp( wxS( "Package_DFN_QFN" ), wxS( "DFN-8-1EP" ) );
98
99 m_libSym = std::make_unique<LIB_SYMBOL>( "LM358", nullptr );
100
101 for( const wxString& number : { wxString( "1" ), wxString( "4" ) } )
102 {
103 SCH_PIN* pin = new SCH_PIN( m_libSym.get() );
104 pin->SetNumber( number );
106 pin->SetPosition( VECTOR2I( number == "1" ? -508000 : 508000, 0 ) );
107 m_libSym->AddDrawItem( pin );
108 }
109
110 PIN_MAP map( wxS( "DFN-8-EP" ) );
111 map.SetEntry( wxS( "4" ), wxS( "[4,9]" ) ); // V- maps to pad 4 AND the exposed pad 9
112 m_libSym->PinMaps().AddOrReplace( map );
113 m_libSym->SetAssociatedFootprints( { { dfn, wxS( "DFN-8-EP" ) } } );
114
115 SCH_SYMBOL* sym = new SCH_SYMBOL( *m_libSym, m_libSym->GetLibId(), &path, 0, 0,
116 VECTOR2I( 15621000, 6223000 ) );
117 sym->GetField( FIELD_T::REFERENCE )->SetText( wxS( "U1" ) );
118 sym->SetFootprintFieldText( dfn.GetUniStringLibId() );
119 sym->UpdatePins();
120 screen->Append( sym );
121
122 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
123 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
124
125 TEST_NETLIST_EXPORTER exporter( m_schematic.get() );
126 std::vector<PIN_INFO> pins = exporter.Pins( sym, sheets[0] );
127
128 wxString netForFour;
129 wxString netForNine;
130 bool hasPadOne = false;
131
132 for( const PIN_INFO& info : pins )
133 {
134 if( info.num == wxS( "1" ) )
135 hasPadOne = true;
136 else if( info.num == wxS( "4" ) )
137 netForFour = info.netName;
138 else if( info.num == wxS( "9" ) )
139 netForNine = info.netName;
140 }
141
142 BOOST_CHECK( hasPadOne ); // pin 1 resolves by identity to pad 1
143 BOOST_CHECK( !netForFour.IsEmpty() ); // V- reaches pad 4
144 BOOST_CHECK( !netForNine.IsEmpty() ); // V- also reaches the exposed pad 9
145 BOOST_CHECK_EQUAL( netForFour, netForNine ); // both pads are on the same net
146
147 m_libSym.reset();
148}
149
150
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition lib_id.cpp:113
An abstract class used for the netlist exporters that Eeschema supports.
A named pin map.
Definition pin_map.h:64
void SetEntry(const wxString &aPinNumber, const wxString &aPadNumber)
Set the pad number for a symbol pin.
Definition pin_map.cpp:59
void SetText(const wxString &aText) override
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Schematic symbol object.
Definition sch_symbol.h:69
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
void SetFootprintFieldText(const wxString &aFootprint)
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::unique_ptr< LIB_SYMBOL > m_libSym
std::unique_ptr< SCHEMATIC > m_schematic
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683