KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_claims.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_bus.h"
23#include "conn_islands.h"
24#include "conn_keys.h"
25#include "conn_frame.h"
26
27#include <algorithm>
28#include <array>
29#include <functional>
30#include <memory>
31#include <ranges>
32#include <span>
33
34namespace SCH_CONNECTIVITY
35{
51
55struct CLAIM
56{
58 uint16_t depth = 0;
64 bool globalPowerParent = false;
65 bool localPowerParent = false;
66 bool outputShape = false;
67 bool hasPad = false;
68 std::shared_ptr<const BUS_SCHEMA> schema;
69 std::optional<INST_ID> portInstance;
70
72 bool Strong() const { return priority >= PRIORITY::HIER_LABEL; }
73 bool operator==( const CLAIM& aOther ) const;
74};
75
80{
82 bool operator()( const CLAIM& aLeft, const CLAIM& aRight ) const;
83};
84
89template <std::ranges::forward_range RANGE, typename PROJ = std::identity>
90std::ranges::iterator_t<RANGE> SelectDriver( RANGE& aClaims, const CLAIM_LESS& aLess, PROJ aProj = {} )
91{
92 const auto end = std::ranges::end( aClaims );
93 auto driver = std::ranges::max_element( aClaims, aLess, aProj );
94
95 while( driver != end )
96 {
97 const CLAIM& current = std::invoke( aProj, *driver );
98 auto wider = end;
99
100 for( auto it = std::ranges::begin( aClaims ); current.schema && it != end; ++it )
101 {
102 const CLAIM& claim = std::invoke( aProj, *it );
103
104 if( claim.priority == current.priority && claim.depth == current.depth && claim.schema
105 && claim.schema->StrictlyContains( *current.schema )
106 && ( wider == end || aLess( std::invoke( aProj, *wider ), claim ) ) )
107 {
108 wider = it;
109 }
110 }
111
112 if( wider == end )
113 break;
114
115 driver = wider;
116 }
117
118 return driver;
119}
120
122{
125 bool pinWitness = false;
126 bool invisiblePower = false;
127 std::optional<INST_ID> portInstance;
128 std::optional<CLAIM> claim;
129 std::vector<NAME_ID> netclasses;
130 bool operator==( const SOURCE_CLAIMS& ) const = default;
131};
132
134{
136 std::map<KIID, SOURCE_CLAIMS> items;
137};
138
140{
141 std::vector<NAME_ID> strongNames;
142 std::array<std::optional<KIID>, 2> pinWitnesses;
143 std::optional<KIID> noConnect;
144 uint32_t pinCount = 0;
145 bool hasSymbolPin = false;
146 bool kindConflict = false;
147 bool mixedBusShapes = false;
149 bool busNoConnect = false;
150 bool operator==( const ERC_ATOMS& ) const = default;
151};
152
154{
156 std::vector<KIID> items;
157 std::vector<CLAIM> claims;
158 std::vector<NAME_KEY> edges;
159 std::vector<NAME_ID> netclasses;
161 bool operator==( const ISLAND_RECORD& ) const = default;
162};
163
166{
167 std::span<const KIID> items;
170};
171
178 const INSTANCE_SCOPE& aScope, SESSION_KEYS& aKeys, BUS_PARSE_CACHE& aParses );
179ISLAND_RECORD BuildIslandRecord( const RECORD_GEOMETRY& aIsland, const INSTANCE_CLAIMS& aInputs,
180 const SESSION_KEYS& aKeys );
181} // namespace SCH_CONNECTIVITY
Definition kiid.h:46
Definition range.h:27
Parse results for each bus text, with invalidation by alias dependency.
Definition conn_bus.h:135
Session IDs are dense handles, never a canonical ordering.
Definition conn_keys.h:146
KIID niluuid(0)
Value keys and the key session of the schematic connectivity engine.
uint32_t INST_ID
Session handle of a sheet instance KIID_PATH.
Definition conn_keys.h:41
std::ranges::iterator_t< RANGE > SelectDriver(RANGE &aClaims, const CLAIM_LESS &aLess, PROJ aProj={})
The driver of aClaims.
Definition conn_claims.h:90
ISLAND_RECORD BuildIslandRecord(const RECORD_GEOMETRY &aIsland, const INSTANCE_CLAIMS &aInputs, const SESSION_KEYS &aKeys)
uint32_t NAME_ID
Session handle of a name, ordered by UTF-8 value through NAME_LESS.
Definition conn_keys.h:42
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
INSTANCE_CLAIMS PrepareInstanceClaims(const SCREEN_FACTS &aFacts, const INSTANCE_FACTS &aText, const INSTANCE_SCOPE &aScope, SESSION_KEYS &aKeys, BUS_PARSE_CACHE &aParses)
Main-thread interning and parse preparation, followed by a pure per-island fold.
PRIORITY
Driver priority of a claim, from low to high.
Definition conn_claims.h:40
@ SHEET_PIN
Sheet pin. The name belongs to the child instance.
Definition conn_claims.h:43
@ GLOBAL_POWER_PIN
Power input pin of a global power symbol, or a hidden power input pin.
Definition conn_claims.h:48
@ LOCAL_POWER_PIN
Power input pin of a local power symbol.
Definition conn_claims.h:46
@ BUS_MEMBER
Synthetic claim of a bus member slot, set by BindBundle().
Definition conn_claims.h:47
@ HIER_LABEL
Hierarchical label. The first strong priority.
Definition conn_claims.h:44
@ NONE
The item makes no claim.
Definition conn_claims.h:41
@ PIN
Symbol pin that is not a power input. The name is "Net-(...)".
Definition conn_claims.h:42
Strict weak order on claims by value.
Definition conn_claims.h:80
const SESSION_KEYS & keys
Definition conn_claims.h:81
bool operator()(const CLAIM &aLeft, const CLAIM &aRight) const
The claim of one item for the name of its island.
Definition conn_claims.h:56
bool globalPowerParent
Pin of a global power symbol.
Definition conn_claims.h:64
bool localPowerParent
Pin of a local power symbol.
Definition conn_claims.h:65
bool operator==(const CLAIM &aOther) const
ITEM_KEY source
The claiming item, the last tie-break.
Definition conn_claims.h:63
bool Strong() const
True for a name that the user placed.
Definition conn_claims.h:72
bool hasPad
The name contains "-Pad".
Definition conn_claims.h:67
uint16_t depth
Sheet path size, or zero if unscoped.
Definition conn_claims.h:58
std::optional< INST_ID > portInstance
Sheet pin child. Members bind there, not in the parent.
Definition conn_claims.h:69
NAME_ID ncName
Name of an unconnected pin net.
Definition conn_claims.h:61
NAME_ID name
Item text without the sheet prefix.
Definition conn_claims.h:60
bool outputShape
Sheet pin with output shape.
Definition conn_claims.h:66
std::shared_ptr< const BUS_SCHEMA > schema
Parsed bus, or null for a signal.
Definition conn_claims.h:68
NAME_ID path
Sheet prefix, or the empty name if unscoped.
Definition conn_claims.h:59
NAME_ID fullName
path followed by name.
Definition conn_claims.h:62
std::array< std::optional< KIID >, 2 > pinWitnesses
The two smallest witness pin ids.
std::optional< KIID > noConnect
The smallest no-connect marker id.
bool operator==(const ERC_ATOMS &) const =default
std::vector< NAME_ID > strongNames
Sorted names of the strong claims.
std::map< KIID, SOURCE_CLAIMS > items
The text and unit data that one sheet instance resolves for the items of its screen.
Definition conn_facts.h:348
The hierarchy position of one sheet instance.
Definition conn_frame.h:35
std::vector< NAME_ID > netclasses
std::vector< NAME_KEY > edges
bool operator==(const ISLAND_RECORD &) const =default
std::vector< CLAIM > claims
front() is the SelectDriver() result, the rest descend by CLAIM_LESS.
One item or pin in one sheet instance.
Definition conn_keys.h:77
Physical inputs to the island record fold.
std::span< const KIID > items
The value copy of one screen.
Definition conn_facts.h:251
std::optional< CLAIM > claim
bool operator==(const SOURCE_CLAIMS &) const =default
std::optional< INST_ID > portInstance
bool pinWitness
Pin whose symbol is not a power symbol.
std::vector< NAME_ID > netclasses
VECTOR2I end
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ TYPE_NOT_INIT
Definition typeinfo.h:73