KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_signals.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_signals.h"
21#include <algorithm>
22#include <stdexcept>
23
24namespace SCH_CONNECTIVITY
25{
26namespace
27{
28 // Unsuffixed name only, bus-member names are finalized during publication
29 NAME_ID SignalBaseName( const SUMMARY& aSummary )
30 {
31 if( !aSummary.best )
32 return INVALID_ID;
33
34 const CLAIM& claim = *aSummary.best;
35
36 if( claim.priority == PRIORITY::PIN && ( !aSummary.pinWitnesses[1] || aSummary.noConnect ) )
37 return claim.ncName;
38
39 return claim.fullName;
40 }
41} // namespace
42
44 const SLOT_STORE::SLOT_CACHE& aSlots, const SESSION_KEYS& aKeys )
45{
47
48 for( const auto& [node, version] : aPartition.identity )
49 {
50 const NODE_KEY& key = aKeys.Node( node );
51 SUMMARY source;
52 std::optional<SLOT_KEY> sourceSlot;
53
54 if( std::holds_alternative<NAME_KEY>( key ) && version == 0 )
55 continue;
56
57 if( const auto* record = std::get_if<RECORD_NODE>( &key ) )
58 {
59 const auto* entry = aRecords.Find( record->record );
60
61 if( record->kind != KIND::SIGNAL || !entry || entry->version != version
62 || entry->value.kind != KIND::SIGNAL )
63 throw std::invalid_argument( "Signal partition does not match current records" );
64
65 source = MakeSummary( record->record, entry->value );
66
67 for( const KIID& item : entry->value.items )
68 result.items.push_back( { item, record->record.inst } );
69 }
70 else if( const auto* slot = std::get_if<SLOT_KEY>( &key ) )
71 {
72 const auto* entry = aSlots.Find( *slot );
73
74 if( !entry || entry->version != version || entry->value.key != *slot )
75 throw std::invalid_argument( "Signal partition does not match current slots" );
76
77 source.best = entry->value.claim;
78 source.netclasses = entry->value.parentNetclasses;
79 sourceSlot = *slot;
80 result.slots.push_back( *slot );
81 }
82 else
83 {
84 throw std::invalid_argument( "Signal partition contains an invalid name version" );
85 }
86
87 SUMMARY joined = SUMMARY::Join( result.summary, source, aKeys );
88
89 if( joined.best != result.summary.best )
90 result.nameSlot = sourceSlot;
91 else if( sourceSlot && source.best == joined.best
92 && ( !result.nameSlot || aKeys.Less( *sourceSlot, *result.nameSlot ) ) )
93 result.nameSlot = sourceSlot;
94
95 result.summary = std::move( joined );
96 }
97
98 result.baseName = SignalBaseName( result.summary );
99 const KEY_LESS less{ aKeys };
100 std::ranges::sort( result.items, less );
101 std::ranges::sort( result.slots, less );
102 return result;
103}
104} // namespace SCH_CONNECTIVITY
Definition kiid.h:46
const ENTRY * Find(const KEY &aKey) const
Entry references survive unchanged writes, but not replacement or erasure of their key.
Definition conn_cache.h:80
CACHE_TABLE< RECORD_KEY, ISLAND_RECORD, KEY_LESS > RECORD_CACHE
Session IDs are dense handles, never a canonical ordering.
Definition conn_keys.h:146
const NODE_KEY & Node(NODE_ID aId) const
Definition conn_keys.h:164
bool Less(const ITEM_KEY &aLeft, const ITEM_KEY &aRight) const
Definition conn_keys.cpp:98
CACHE_TABLE< SLOT_KEY, SLOT_INPUT, KEY_LESS > SLOT_CACHE
Value keys and the key session of the schematic connectivity engine.
std::variant< RECORD_NODE, NAME_KEY, SLOT_KEY > NODE_KEY
Any node of the union-find graph.
Definition conn_keys.h:136
uint32_t NAME_ID
Session handle of a name, ordered by UTF-8 value through NAME_LESS.
Definition conn_keys.h:42
SUMMARY MakeSummary(const RECORD_KEY &aKey, const ISLAND_RECORD &aRecord)
Consumes a canonical BuildIslandRecord() result.
constexpr uint32_t INVALID_ID
Marks an unset handle.
Definition conn_keys.h:47
@ PIN
Symbol pin that is not a power input. The name is "Net-(...)".
Definition conn_claims.h:39
SIGNAL_RESULT DeriveSignal(const PARTITION &aPartition, const RECORD_STORE::RECORD_CACHE &aRecords, const SLOT_STORE::SLOT_CACHE &aSlots, const SESSION_KEYS &aKeys)
Fold current signal inputs and retain canonical membership for publication and succession.
The claim of one item for the name of its island.
Definition conn_claims.h:53
NAME_ID ncName
Name of an unconnected pin net.
Definition conn_claims.h:58
Orders keys by value through SESSION_KEYS::Less().
Definition conn_keys.h:255
Exact identity of one connected component.
std::vector< std::pair< NODE_ID, uint64_t > > identity
Derived state of one net before publication.
Fold state of one net.
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.
wxString result
Test unit parsing edge cases and error handling.