KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_net_chains_class_color.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
20#include <boost/test/unit_test.hpp>
21
24
25#include <connection_graph.h>
26#include <schematic.h>
27#include <sch_netchain.h>
28#include <sch_sheet.h>
30#include <locale_io.h>
31
39
40
41// Validate that the connection graph correctly applies parsed netclass and color
42// overrides to committed net chains. This exercises the writer/parser/loader
43// glue added in the e3ea709483 / 769c2efb85 / dea7492211 / 3b3863a843 commit
44// chain without touching the file-format details directly.
45BOOST_FIXTURE_TEST_CASE( NetChain_ApplyClassAndColorOverrides, SIGNALS_CLASS_COLOR_FIXTURE )
46{
48 KI_TEST::LoadSchematic( m_settingsManager, wxString( "net_chains_four_nets" ),
49 m_schematic );
50
51 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
52 BOOST_REQUIRE( graph );
53
54 graph->Recalculate( m_schematic->BuildSheetListSortedByPageNumbers(), true );
55
56 // Seed override maps as if they had just been parsed from the schematic.
57 std::map<wxString, wxString> classes;
58 std::map<wxString, KIGFX::COLOR4D> colors;
59 classes[wxT( "MY_CHAIN" )] = wxT( "DDR_DATA" );
60 colors[wxT( "MY_CHAIN" )] = KIGFX::COLOR4D( 1.0, 0.5, 0.25, 1.0 );
61
62 graph->SetNetChainNetClassOverrides( classes );
63 graph->SetNetChainColorOverrides( colors );
64
65 // Promote the first detected potential chain so it gets a name we control.
66 const auto& potentials = graph->GetPotentialNetChains();
67 BOOST_REQUIRE( !potentials.empty() );
68
69 SCH_NETCHAIN* potential = potentials.front().get();
70 BOOST_REQUIRE( potential );
71
72 SCH_NETCHAIN* committed = graph->CreateNetChainFromPotential( potential, wxT( "MY_CHAIN" ) );
73 BOOST_REQUIRE( committed );
74 BOOST_CHECK_EQUAL( committed->GetName(), wxT( "MY_CHAIN" ) );
75
76 // The override maps should have been consulted at promotion time and
77 // copied onto the committed chain.
78 BOOST_CHECK_EQUAL( committed->GetNetClass(), wxT( "DDR_DATA" ) );
79 BOOST_CHECK( committed->GetColor() != KIGFX::COLOR4D::UNSPECIFIED );
80 BOOST_CHECK_CLOSE( committed->GetColor().r, 1.0, 1e-6 );
81 BOOST_CHECK_CLOSE( committed->GetColor().g, 0.5, 1e-6 );
82 BOOST_CHECK_CLOSE( committed->GetColor().b, 0.25, 1e-6 );
83 BOOST_CHECK_CLOSE( committed->GetColor().a, 1.0, 1e-6 );
84}
85
86
87// Validate that promoting a chain with no override leaves the chain in
88// its default ("no override") state. This guards against an off-by-one
89// where the override application leaks default values into chains that
90// shouldn't have any.
91BOOST_FIXTURE_TEST_CASE( NetChain_NoOverrideStaysDefault, SIGNALS_CLASS_COLOR_FIXTURE )
92{
94 KI_TEST::LoadSchematic( m_settingsManager, wxString( "net_chains_four_nets" ),
95 m_schematic );
96
97 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
98 BOOST_REQUIRE( graph );
99
100 graph->Recalculate( m_schematic->BuildSheetListSortedByPageNumbers(), true );
101
102 // Make sure the override maps are empty.
103 graph->SetNetChainNetClassOverrides( {} );
104 graph->SetNetChainColorOverrides( {} );
105
106 const auto& potentials = graph->GetPotentialNetChains();
107 BOOST_REQUIRE( !potentials.empty() );
108
109 SCH_NETCHAIN* committed = graph->CreateNetChainFromPotential( potentials.front().get(),
110 wxT( "OTHER" ) );
111 BOOST_REQUIRE( committed );
112
113 BOOST_CHECK( committed->GetNetClass().IsEmpty() );
114 BOOST_CHECK( committed->GetColor() == KIGFX::COLOR4D::UNSPECIFIED );
115}
Calculate the connectivity of a schematic and generates netlists.
void SetNetChainColorOverrides(const std::map< wxString, COLOR4D > &aOverrides)
void SetNetChainNetClassOverrides(const std::map< wxString, wxString > &aOverrides)
Stash per-net-chain netclass overrides read from the schematic file.
SCH_NETCHAIN * CreateNetChainFromPotential(SCH_NETCHAIN *aPotential, const wxString &aName)
Promote a potential net chain to an actual user net chain with the provided name.
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...
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
double r
Red component.
Definition color4d.h:393
double g
Green component.
Definition color4d.h:394
double a
Alpha component.
Definition color4d.h:396
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
double b
Blue component.
Definition color4d.h:395
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
A net chain is a collection of nets that are connected together through passive components.
const wxString & GetNetClass() const
const KIGFX::COLOR4D & GetColor() const
const wxString & GetName() const
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_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(NetChain_ApplyClassAndColorOverrides, SIGNALS_CLASS_COLOR_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")