KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_summary.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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "conn_summary.h"
21
22#include <algorithm>
23#include <iterator>
24
25namespace SCH_CONNECTIVITY
26{
27SUMMARY MakeSummary( const RECORD_KEY& aKey, const ISLAND_RECORD& aRecord )
28{
30 result.netclasses = aRecord.netclasses;
31
32 if( !aRecord.claims.empty() )
33 result.best = aRecord.claims.front();
34
35 const auto key = [&]( const std::optional<KIID>& aItem ) -> std::optional<ITEM_KEY>
36 {
37 return aItem ? std::optional( ITEM_KEY{ *aItem, aKey.inst } ) : std::nullopt;
38 };
39
40 std::ranges::transform( aRecord.atoms.pinWitnesses, result.pinWitnesses.begin(), key );
41 result.noConnect = key( aRecord.atoms.noConnect );
42 return result;
43}
44
45SUMMARY SUMMARY::Join( const SUMMARY& aLeft, const SUMMARY& aRight, const SESSION_KEYS& aKeys )
46{
48 result.best = !aLeft.best || ( aRight.best && CLAIM_LESS{ aKeys }( *aLeft.best, *aRight.best ) ) ? aRight.best
49 : aLeft.best;
50
51 std::array<ITEM_KEY, 4> witnesses;
52 auto end = witnesses.begin();
53
54 for( const SUMMARY* summary : { &aLeft, &aRight } )
55 {
56 for( const auto& witness : summary->pinWitnesses )
57 {
58 if( witness )
59 *end++ = *witness;
60 }
61 }
62
63 std::sort( witnesses.begin(), end, KEY_LESS{ aKeys } );
64 end = std::unique( witnesses.begin(), end );
65 std::copy( witnesses.begin(), std::min( end, witnesses.begin() + result.pinWitnesses.size() ),
66 result.pinWitnesses.begin() );
67
68 result.noConnect = !aLeft.noConnect || ( aRight.noConnect && !aKeys.Less( *aLeft.noConnect, *aRight.noConnect ) )
69 ? aRight.noConnect
70 : aLeft.noConnect;
71 result.netclasses.reserve( aLeft.netclasses.size() + aRight.netclasses.size() );
72 std::set_union( aLeft.netclasses.begin(), aLeft.netclasses.end(), aRight.netclasses.begin(),
73 aRight.netclasses.end(), std::back_inserter( result.netclasses ), NAME_LESS{ &aKeys } );
74 return result;
75}
76} // namespace SCH_CONNECTIVITY
Session IDs are dense handles, never a canonical ordering.
Definition conn_keys.h:146
bool Less(const ITEM_KEY &aLeft, const ITEM_KEY &aRight) const
Definition conn_keys.cpp:98
Value keys and the key session of the schematic connectivity engine.
SUMMARY MakeSummary(const RECORD_KEY &aKey, const ISLAND_RECORD &aRecord)
Consumes a canonical BuildIslandRecord() result.
Strict weak order on claims by value.
Definition conn_claims.h:77
std::array< std::optional< KIID >, 2 > pinWitnesses
The two smallest witness pin ids.
std::optional< KIID > noConnect
The smallest no-connect marker id.
std::vector< NAME_ID > netclasses
std::vector< CLAIM > claims
Descending by CLAIM_LESS, so front() is the island driver.
One item or pin in one sheet instance.
Definition conn_keys.h:77
Orders keys by value through SESSION_KEYS::Less().
Definition conn_keys.h:255
Orders name handles by UTF-8 value.
Definition conn_keys.h:246
One island in one sheet instance.
Definition conn_keys.h:87
INST_ID inst
The sheet instance of the record.
Definition conn_keys.h:88
Fold state of one net.
std::optional< ITEM_KEY > noConnect
The smallest no-connect marker.
std::optional< CLAIM > best
Greatest claim by CLAIM_LESS.
static SUMMARY Join(const SUMMARY &aLeft, const SUMMARY &aRight, const SESSION_KEYS &aKeys)
Inputs are canonical folds from one source snapshot.
std::vector< NAME_ID > netclasses
Sorted by name.
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.