KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_publish.h
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#pragma once
21
22#include "conn_signals.h"
23#include "conn_auxiliary.h"
24#include <set>
25
26enum class CONNECTION_TYPE;
27
28namespace SCH_CONNECTIVITY
29{
31{
33 std::optional<CLAIM> best;
34 std::vector<ITEM_KEY> items;
35 std::vector<RECORD_KEY> records;
36 std::vector<SLOT_KEY> slots;
37 // Canonical driver leaf order; slots also retains noncanonical extras.
38 std::vector<SLOT_KEY> members;
39 std::optional<SLOT_KEY> nameSlot;
40 std::vector<NAME_ID> netclasses;
42 bool operator==( const COMPONENT_CONTENT& ) const = default;
43};
44
50{
51 std::shared_ptr<const COMPONENT_CONTENT> content;
52 std::optional<SLOT_KEY> nameSlot;
54
58 uint32_t suffix = 0;
59 int netCode = 0;
60 uint32_t subgraphCode = 0;
61
62 bool operator==( const PUBLISHED_COMPONENT& aOther ) const
63 {
64 return ( content == aOther.content || ( content && aOther.content && *content == *aOther.content ) )
65 && nameSlot == aOther.nameSlot && baseName == aOther.baseName && collisionBase == aOther.collisionBase
66 && name == aOther.name && suffix == aOther.suffix && netCode == aOther.netCode
67 && subgraphCode == aOther.subgraphCode;
68 }
69};
70
75{
78 {
80 std::shared_ptr<const BUS_SCHEMA> schema;
81 bool operator==( const BUS_SOURCE& aOther ) const;
82 };
83
84 std::shared_ptr<const BUS_SOURCE> busSource;
91 std::optional<ITEM_KEY> driver;
92 int netCode = 0;
93 uint32_t subgraphCode = 0;
94 // Null denotes an empty class set; ownership does not retain component membership.
95 std::shared_ptr<const std::vector<NAME_ID>> netclasses;
96
97 bool operator==( const ITEM_RESULT& aOther ) const;
98};
99
105wxString ApplyNameSuffix( const wxString& aName, const BUS_SCHEMA* aSchema, uint32_t aSuffix );
106
114{
115public:
116 using COMPONENTS = std::map<NODE_ID, PUBLISHED_COMPONENT>;
117
118 using NAME_INDEX = std::map<NAME_ID, NODE_ID, NAME_LESS>;
119 using SLOT_INDEX = std::map<SLOT_KEY, NODE_ID, KEY_LESS>;
120 using COMPONENT_LINKS = std::map<NODE_ID, std::vector<NODE_ID>>;
121
122 using ROWS = std::map<ITEM_KEY, ITEM_RESULT, KEY_LESS>;
123 using CLASS_ASSIGNMENTS = std::map<NAME_ID, std::shared_ptr<const std::vector<NAME_ID>>, NAME_LESS>;
124
125 explicit PUBLICATION( SESSION_KEYS& aKeys );
126 void Update( const COMPONENT_CACHE<BUNDLE_BINDING>& aBundles, const COMPONENT_CACHE<SIGNAL_RESULT>& aSignals,
127 const RECORD_STORE::RECORD_CACHE& aRecords, std::span<const FRAME_INSTANCE> aFrame,
128 const INPUT_STORE& aInputs );
129 void Clear();
130
131 const COMPONENTS& Components() const { return m_components; }
132 const CHANGE_SET& Changes() const { return m_changes; }
133
134 const NAME_INDEX& ByName() const { return m_byName; }
135 const SLOT_INDEX& SlotComponents() const { return m_slotComponents; }
136 std::optional<NODE_ID> FindByName( const wxString& aName ) const;
137 // Other published unnamed groups with the same scoped canonical leaf multiset, in name order.
138 std::vector<wxString> EquivalentBusNames( const wxString& aName ) const;
139 // Borrowed spans; callers must reacquire them after Update or Clear.
140 std::span<const NODE_ID> MembersOf( NODE_ID aBundle ) const;
141 std::span<const NODE_ID> ParentsOf( NODE_ID aSignal ) const;
142
143 const AUXILIARY& Auxiliary() const { return m_auxiliary; }
144
145 const ROWS& Rows() const { return m_rows; }
146 const CLASS_ASSIGNMENTS& Netclasses() const { return m_netclasses; }
147
148private:
149 using BUS_SIGNATURE = std::pair<NAME_ID, std::vector<NAME_ID>>;
150 using EQUIVALENT_BUSES = std::map<BUS_SIGNATURE, std::set<NODE_ID>>;
151 using BUS_SIGNATURES = std::map<NODE_ID, EQUIVALENT_BUSES::iterator>;
152 using SLOT_INPUTS = std::map<SLOT_KEY, const SLOT_INPUT*, KEY_LESS>;
153
156 {
157 uint64_t version = 0;
159 std::vector<KIID> items;
160
161 // An island driver keeps its own local name when a same-sheet merge renames its other items.
162 std::optional<std::pair<KIID, ITEM_RESULT>> driver;
163 };
164 using ROW_INPUTS = std::map<RECORD_KEY, std::shared_ptr<const ROW_INPUT>, KEY_LESS>;
165
167 {
168 explicit ROW_UPDATE( const SESSION_KEYS& aKeys ) :
169 upserts( KEY_LESS{ aKeys } ),
170 inputs( KEY_LESS{ aKeys } ),
171 netclasses( NAME_LESS{ &aKeys } )
172 {
173 }
174
176 std::vector<ITEM_KEY> removed;
177 std::vector<RECORD_KEY> removedInputs;
180 };
181
182 ROW_UPDATE PrepareRows( const COMPONENTS& aCurrent, const RECORD_STORE::RECORD_CACHE& aRecords,
183 const SLOT_INPUTS& aSlots, CHANGE_SET& aChanges );
184 void ApplyRows( ROW_UPDATE&& aUpdate );
185 void UpdateIndexes( const COMPONENTS& aCurrent, const SLOT_INPUTS& aSlots );
186 void UpdateBusSignatures( const COMPONENTS& aCurrent, const SLOT_INPUTS& aSlots );
187
200 std::map<NODE_ID, uint64_t> m_versions;
203 uint32_t m_nextSubgraphCode = 1;
204};
205} // namespace SCH_CONNECTIVITY
Source-keyed publication independent of electrical component identity.
Cache current component evaluations by exact node/version identity, within one stratum and key sessio...
Main-thread extraction cache.
Definition conn_inputs.h:41
const NAME_INDEX & ByName() const
const CLASS_ASSIGNMENTS & Netclasses() const
ROW_UPDATE PrepareRows(const COMPONENTS &aCurrent, const RECORD_STORE::RECORD_CACHE &aRecords, const SLOT_INPUTS &aSlots, CHANGE_SET &aChanges)
Definition conn_rows.cpp:62
std::map< SLOT_KEY, NODE_ID, KEY_LESS > SLOT_INDEX
std::span< const NODE_ID > MembersOf(NODE_ID aBundle) const
std::map< NAME_ID, std::shared_ptr< const std::vector< NAME_ID > >, NAME_LESS > CLASS_ASSIGNMENTS
std::map< NODE_ID, uint64_t > m_versions
std::map< ITEM_KEY, ITEM_RESULT, KEY_LESS > ROWS
std::map< RECORD_KEY, std::shared_ptr< const ROW_INPUT >, KEY_LESS > ROW_INPUTS
void Update(const COMPONENT_CACHE< BUNDLE_BINDING > &aBundles, const COMPONENT_CACHE< SIGNAL_RESULT > &aSignals, const RECORD_STORE::RECORD_CACHE &aRecords, std::span< const FRAME_INSTANCE > aFrame, const INPUT_STORE &aInputs)
std::map< NAME_ID, NODE_ID, NAME_LESS > NAME_INDEX
PUBLICATION(SESSION_KEYS &aKeys)
Definition conn_rows.cpp:51
EQUIVALENT_BUSES m_equivalentBuses
uint32_t m_nextSubgraphCode
Never reset, so codes do not repeat.
std::map< BUS_SIGNATURE, std::set< NODE_ID > > EQUIVALENT_BUSES
std::map< NODE_ID, std::vector< NODE_ID > > COMPONENT_LINKS
std::pair< NAME_ID, std::vector< NAME_ID > > BUS_SIGNATURE
const ROWS & Rows() const
const COMPONENTS & Components() const
CLASS_ASSIGNMENTS m_netclasses
std::vector< wxString > EquivalentBusNames(const wxString &aName) const
const AUXILIARY & Auxiliary() const
void ApplyRows(ROW_UPDATE &&aUpdate)
std::map< SLOT_KEY, const SLOT_INPUT *, KEY_LESS > SLOT_INPUTS
std::map< NODE_ID, PUBLISHED_COMPONENT > COMPONENTS
std::span< const NODE_ID > ParentsOf(NODE_ID aSignal) const
const SLOT_INDEX & SlotComponents() const
int m_nextNetCode
Never reset, so codes do not repeat.
std::map< NODE_ID, EQUIVALENT_BUSES::iterator > BUS_SIGNATURES
const CHANGE_SET & Changes() const
void UpdateBusSignatures(const COMPONENTS &aCurrent, const SLOT_INPUTS &aSlots)
void UpdateIndexes(const COMPONENTS &aCurrent, const SLOT_INPUTS &aSlots)
std::optional< NODE_ID > FindByName(const wxString &aName) const
CACHE_TABLE< RECORD_KEY, ISLAND_RECORD, KEY_LESS > RECORD_CACHE
Session IDs are dense handles, never a canonical ordering.
Definition conn_keys.h:146
Value keys and the key session of the schematic connectivity engine.
uint32_t NAME_ID
Session handle of a name, ordered by UTF-8 value through NAME_LESS.
Definition conn_keys.h:42
uint32_t NODE_ID
Session handle of a NODE_KEY graph node.
Definition conn_keys.h:43
KIND
The electrical type of a record or component.
Definition conn_keys.h:55
constexpr uint32_t INVALID_ID
Marks an unset handle.
Definition conn_keys.h:47
wxString ApplyNameSuffix(const wxString &aName, const BUS_SCHEMA *aSchema, uint32_t aSuffix)
Add "_N" to aName.
CONNECTION_TYPE
The parsed form of one bus text.
Definition conn_bus.h:48
Difference between two publications.
std::optional< SLOT_KEY > nameSlot
bool operator==(const COMPONENT_CONTENT &) const =default
std::vector< RECORD_KEY > records
std::vector< SLOT_KEY > members
std::vector< NAME_ID > netclasses
std::vector< SLOT_KEY > slots
std::vector< ITEM_KEY > items
One item or pin in one sheet instance.
Definition conn_keys.h:77
Bus claim of an island that has the canonical shape but a different name.
bool operator==(const BUS_SOURCE &aOther) const
Definition conn_rows.cpp:38
std::shared_ptr< const BUS_SCHEMA > schema
Published connection of one item on one sheet instance.
std::shared_ptr< const std::vector< NAME_ID > > netclasses
std::shared_ptr< const BUS_SOURCE > busSource
NAME_ID localName
Best island claim, or the group winner.
NAME_ID fullLocalName
localName with the component suffix.
bool operator==(const ITEM_RESULT &aOther) const
Definition conn_rows.cpp:43
NAME_ID name
Published name with its suffix.
std::optional< ITEM_KEY > driver
Source of the best component claim.
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
Shared row of one island record.
std::optional< std::pair< KIID, ITEM_RESULT > > driver
ITEM_RESULT connection
Row of every island item except the driver override.
ROW_UPDATE(const SESSION_KEYS &aKeys)
std::vector< RECORD_KEY > removedInputs
One published net or bus with its identity.
bool operator==(const PUBLISHED_COMPONENT &aOther) const
NAME_ID baseName
Name before the suffix.
int netCode
Zero for a bus or without a claim.
uint32_t suffix
Zero for the holder of the base name.
std::optional< SLOT_KEY > nameSlot
Selected naming slot, lowest parent suffix first.
uint32_t subgraphCode
Zero without a claim.
NAME_ID name
Unique name, invalid without a claim.
std::shared_ptr< const COMPONENT_CONTENT > content
NAME_ID collisionBase
Bucket for duplicate names.