KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_pin_syntax.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
22
23#include <advanced_config.h>
24#include <erc/erc.h>
25#include <locale_io.h>
26#include <sch_marker.h>
27#include <sch_pin.h>
28#include <sch_symbol.h>
29#include <schematic.h>
31#include <scoped_set_reset.h>
32
33BOOST_AUTO_TEST_CASE( ERCStackedPinSyntaxUsesSharedInstanceUnits )
34{
35 LOCALE_IO locale;
36 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
37 SCOPED_SET_RESET restore( enabled, enabled );
38
39 for( bool backend : { false, true } )
40 {
41 BOOST_TEST_CONTEXT( "new engine=" << backend )
42 {
43 enabled = backend;
44 SETTINGS_MANAGER settings;
45 std::unique_ptr<SCHEMATIC> schematic;
46 KI_TEST::LoadSchematic( settings, "legacy_hierarchy/legacy_hierarchy", schematic );
47 std::vector<SCH_SHEET_PATH> paths;
48
49 for( const SCH_SHEET_PATH& path : schematic->Hierarchy() )
50 {
51 if( path.LastScreen()->GetFileName().EndsWith( "ampli_ht.kicad_sch" ) )
52 paths.push_back( path );
53 }
54
55 BOOST_REQUIRE_EQUAL( paths.size(), 2 );
56 SCH_SCREEN* screen = paths[0].LastScreen();
57 BOOST_REQUIRE( screen == paths[1].LastScreen() );
58 SCH_SYMBOL* symbol = nullptr;
59
60 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
61 {
62 auto* candidate = static_cast<SCH_SYMBOL*>( item );
63
64 if( candidate->GetUnitCount() > 1 )
65 {
66 symbol = candidate;
67 break;
68 }
69 }
70
71 BOOST_REQUIRE( symbol );
72 symbol->SetUnitSelection( &paths[0], 1 );
73 symbol->SetUnitSelection( &paths[1], 2 );
74 SCH_PIN* pin = nullptr;
75
76 for( const auto& candidate : symbol->GetRawPins() )
77 {
78 if( candidate->GetNumber() == wxString( "5" ) )
79 {
80 pin = candidate.get();
81 break;
82 }
83 }
84
86 BOOST_REQUIRE_EQUAL( pin->GetUnit(), 2 );
87 pin->SetNumber( "1[" );
88 bool valid;
89 pin->GetStackedPinNumbers( &valid );
90 BOOST_REQUIRE( !valid );
91 screen->Update( symbol, false );
92 schematic->RebuildConnectivity();
93 schematic->SetCurrentSheet( paths[0] );
94 ERC_TESTER tester( schematic.get() );
96 int count = 0;
97
98 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
99 {
100 auto* marker = static_cast<SCH_MARKER*>( item );
101 const auto error = std::static_pointer_cast<ERC_ITEM>( marker->GetRCItem() );
102
103 if( error->GetErrorCode() != ERCE_STACKED_PIN_SYNTAX || error->GetMainItemID() != pin->m_Uuid )
104 continue;
105
106 ++count;
107 BOOST_CHECK( error->IsSheetSpecific() );
108
109 if( error->IsSheetSpecific() )
110 BOOST_CHECK( error->GetSpecificSheetPath().PathRef() == paths[1].PathRef() );
111
112 BOOST_CHECK( marker->GetPosition() == pin->GetPosition() );
113 }
114
115 BOOST_CHECK_EQUAL( count, 1 );
116 }
117 }
118}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
int TestStackedPinNotation()
Checks for pin numbers that resemble stacked pin notation but are invalid.
Definition erc.cpp:2560
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:170
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Refresh a changed item in the tree and invalidate connectivity.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:74
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
Definition sch_symbol.h:678
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
RAII class that sets an value at construction and resets it to the original value at destruction.
@ ERCE_STACKED_PIN_SYNTAX
Pin name resembles stacked pin notation.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
BOOST_AUTO_TEST_CASE(ERCStackedPinSyntaxUsesSharedInstanceUnits)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
KIBIS_PIN * pin
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_MARKER_T
Definition typeinfo.h:154