KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_bus_entry_concurrency.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
21
22#include <algorithm>
23
24#include <connection_graph.h>
25#include <schematic.h>
26#include <sch_bus_entry.h>
27#include <sch_line.h>
28#include <sch_screen.h>
29#include <sch_sheet.h>
31#include <thread_pool.h>
32
34{
36 m_mgr()
37 {
38 m_mgr.LoadProject( "" );
39 m_schematic = std::make_unique<SCHEMATIC>( &m_mgr.Prj() );
40 m_schematic->Reset();
41 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
42
43 m_screen = new SCH_SCREEN( m_schematic.get() );
44 m_sheet = new SCH_SHEET( m_schematic.get() );
45 m_sheet->SetScreen( m_screen );
46 m_schematic->AddTopLevelSheet( m_sheet );
47 m_schematic->RemoveTopLevelSheet( defaultSheet );
48 delete defaultSheet;
49 }
50
52 std::unique_ptr<SCHEMATIC> m_schematic;
55};
56
57static SCH_LINE* make_bus( const VECTOR2I& aStart, const VECTOR2I& aEnd )
58{
59 SCH_LINE* const line = new SCH_LINE{ aStart, LAYER_BUS };
60 line->SetEndPoint( aEnd );
61 return line;
62}
63
64static SCH_BUS_BUS_ENTRY* make_entry( const VECTOR2I& aPos, int aDy )
65{
66 SCH_BUS_BUS_ENTRY* entry = new SCH_BUS_BUS_ENTRY( aPos );
67 entry->SetSize( VECTOR2I( 0, aDy ) );
68 return entry;
69}
70
72{
74 tp.reset( 2 );
75
76 SCH_LINE* bus1 = make_bus( { 0, 0 }, { 5000000, 0 } );
77 SCH_LINE* bus2 = make_bus( { 0, 10000 }, { 5000000, 10000 } );
78
79 m_screen->Append( bus1 );
80 m_screen->Append( bus2 );
81
82 std::vector<SCH_BUS_BUS_ENTRY*> entries;
83
84 for( int ii = 0; ii < 50; ++ii )
85 {
86 int x = ii * 10000;
87 SCH_BUS_BUS_ENTRY* entry = make_entry( { x, 0 }, 10000 );
88 m_screen->Append( entry );
89 entries.push_back( entry );
90 }
91
92 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
93 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
94
95 SCH_SHEET_PATH path = sheets[0];
96
97 for( SCH_BUS_BUS_ENTRY* entry : entries )
98 {
99 BOOST_CHECK( entry->m_connected_bus_items[0] == bus1 );
100 BOOST_CHECK( entry->m_connected_bus_items[1] == bus2 );
101 }
102
103 std::vector<SCH_ITEM*> bus1_items = bus1->ConnectedItems( path );
104 std::vector<SCH_ITEM*> bus2_items = bus2->ConnectedItems( path );
105
106 BOOST_CHECK_EQUAL( bus1_items.size(), entries.size() );
107 BOOST_CHECK_EQUAL( bus2_items.size(), entries.size() );
108
109 for( SCH_BUS_BUS_ENTRY* entry : entries )
110 {
111 BOOST_CHECK( std::find( bus1_items.begin(), bus1_items.end(), entry ) != bus1_items.end() );
112 BOOST_CHECK( std::find( bus2_items.begin(), bus2_items.end(), entry ) != bus2_items.end() );
113 }
114}
Class for a bus to bus entry.
void SetSize(const VECTOR2I &aSize)
const std::vector< SCH_ITEM * > & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition sch_item.cpp:558
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:145
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
@ LAYER_BUS
Definition layer_ids.h:451
SCH_SCREEN * m_screen
SCH_SHEET * m_sheet
std::unique_ptr< SCHEMATIC > m_schematic
BUS_ENTRY_CONCURRENCY_FIXTURE()
SETTINGS_MANAGER m_mgr
static SCH_BUS_BUS_ENTRY * make_entry(const VECTOR2I &aPos, int aDy)
BOOST_FIXTURE_TEST_CASE(BusEntryConcurrency, BUS_ENTRY_CONCURRENCY_FIXTURE)
static SCH_LINE * make_bus(const VECTOR2I &aStart, const VECTOR2I &aEnd)
std::string path
BOOST_CHECK_EQUAL(result, "25.4")
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
static thread_pool * tp
BS::priority_thread_pool thread_pool
Definition thread_pool.h:27
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683