KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_net_chains_remove.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
24
25#include <connection_graph.h>
26#include <schematic.h>
27#include <sch_screen.h>
28#include <sch_sheet.h>
29#include <sch_symbol.h>
31#include <locale_io.h>
32
40
41BOOST_FIXTURE_TEST_CASE( RemoveFromSignal_DisablesPropagationAndSplitsGroup, SIGNALS_REMOVE_TEST_FIXTURE )
42{
44 KI_TEST::LoadSchematic( m_settingsManager, wxString( "net_chains_four_nets" ), m_schematic );
45
46 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
47 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
48 graph->Recalculate( sheets, /*aUnconditional=*/true );
49
50 size_t fourCount = 0;
51 SCH_NETCHAIN* four = nullptr;
52 for( const auto& sig : graph->GetPotentialNetChains() )
53 {
54 if( sig && sig->GetNets().size() == 4 )
55 {
56 four = sig.get();
57 fourCount++;
58 }
59 }
60
61 BOOST_REQUIRE_MESSAGE( fourCount >= 1, "Expected initial 4-net signal present" );
62
63 wxString firstNet = *four->GetNets().begin();
64 SCH_SCREEN* screen = m_schematic->CurrentSheet().LastScreen();
65
66 auto effectiveNetNameForPin = [&]( SCH_PIN* aPin ) -> wxString {
67 if( CONNECTION_SUBGRAPH* sg = graph->GetSubgraphForItem( aPin ) )
68 {
69 wxString n = sg->GetNetName();
70 if( !n.IsEmpty() )
71 return n;
72 }
73 return aPin->GetDefaultNetName( m_schematic->CurrentSheet() );
74 };
75
76 int disabledCount = 0;
77 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
78 {
79 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
80 auto pins = sym->GetPins( &m_schematic->CurrentSheet() );
81 if( pins.size() != 2 )
82 continue;
83
84 wxString nameA = effectiveNetNameForPin( pins[0] );
85 wxString nameB = effectiveNetNameForPin( pins[1] );
86
87 if( ( nameA == firstNet && nameB != firstNet ) || ( nameB == firstNet && nameA != firstNet ) )
88 {
89 sym->SetPassthrough( false );
90 disabledCount++;
91 }
92 }
93
94 BOOST_REQUIRE_MESSAGE( disabledCount > 0, "Test did not find any bridging 2-pin symbol to disable" );
95
96 graph->Recalculate( sheets, /*aUnconditional=*/true );
97
98 bool stillHasFour = false;
99 for( const auto& sig : graph->GetPotentialNetChains() )
100 {
101 if( sig && sig->GetNets().size() == 4 )
102 {
103 stillHasFour = true;
104 break;
105 }
106 }
107
108 BOOST_CHECK_MESSAGE( !stillHasFour, "Expected removal to split the 4-net signal" );
109}
110
111// EOF
Calculate the connectivity of a schematic and generates netlists.
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Update the connection graph for the given list of sheets.
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetPotentialNetChains() const
Potential net chains are inferred groupings produced by RebuildNetChains() but not yet user-committed...
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem) const
A subgraph is a set of items that are electrically connected on a single sheet.
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
A net chain is a collection of nets that are connected together through passive components.
const std::set< wxString > & GetNets() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Schematic symbol object.
Definition sch_symbol.h:69
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
void SetPassthrough(bool aEnable)
Definition sch_symbol.h:850
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(RemoveFromSignal_DisablesPropagationAndSplitsGroup, SIGNALS_REMOVE_TEST_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_SYMBOL_T
Definition typeinfo.h:169