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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 */
20
21#include <boost/test/unit_test.hpp>
22
25
26#include <connection_graph.h>
27#include <schematic.h>
28#include <sch_screen.h>
29#include <sch_sheet.h>
30#include <sch_symbol.h>
32#include <locale_io.h>
33
41
42BOOST_FIXTURE_TEST_CASE( RemoveFromSignal_DisablesPropagationAndSplitsGroup, SIGNALS_REMOVE_TEST_FIXTURE )
43{
45 KI_TEST::LoadSchematic( m_settingsManager, wxString( "net_chains_four_nets" ), m_schematic );
46
47 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
48 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
49 graph->Recalculate( sheets, /*aUnconditional=*/true );
50
51 size_t fourCount = 0;
52 SCH_NETCHAIN* four = nullptr;
53 for( const auto& sig : graph->GetPotentialNetChains() )
54 {
55 if( sig && sig->GetNets().size() == 4 )
56 {
57 four = sig.get();
58 fourCount++;
59 }
60 }
61
62 BOOST_REQUIRE_MESSAGE( fourCount >= 1, "Expected initial 4-net signal present" );
63
64 wxString firstNet = *four->GetNets().begin();
65 SCH_SCREEN* screen = m_schematic->CurrentSheet().LastScreen();
66
67 auto effectiveNetNameForPin = [&]( SCH_PIN* aPin ) -> wxString {
68 if( CONNECTION_SUBGRAPH* sg = graph->GetSubgraphForItem( aPin ) )
69 {
70 wxString n = sg->GetNetName();
71 if( !n.IsEmpty() )
72 return n;
73 }
74 return aPin->GetDefaultNetName( m_schematic->CurrentSheet() );
75 };
76
77 int disabledCount = 0;
78 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
79 {
80 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
81 auto pins = sym->GetPins( &m_schematic->CurrentSheet() );
82 if( pins.size() != 2 )
83 continue;
84
85 wxString nameA = effectiveNetNameForPin( pins[0] );
86 wxString nameB = effectiveNetNameForPin( pins[1] );
87
88 if( ( nameA == firstNet && nameB != firstNet ) || ( nameB == firstNet && nameA != firstNet ) )
89 {
90 sym->SetPassthrough( false );
91 disabledCount++;
92 }
93 }
94
95 BOOST_REQUIRE_MESSAGE( disabledCount > 0, "Test did not find any bridging 2-pin symbol to disable" );
96
97 graph->Recalculate( sheets, /*aUnconditional=*/true );
98
99 bool stillHasFour = false;
100 for( const auto& sig : graph->GetPotentialNetChains() )
101 {
102 if( sig && sig->GetNets().size() == 4 )
103 {
104 stillHasFour = true;
105 break;
106 }
107 }
108
109 BOOST_CHECK_MESSAGE( !stillHasFour, "Expected removal to split the 4-net signal" );
110}
111
112// 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:225
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
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:119
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Schematic symbol object.
Definition sch_symbol.h:76
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:857
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:173