KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_facade.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_engine.h"
23#include "conn_subscription.h"
24#include <memory>
25#include <functional>
26
27class SCH_ITEM;
28class SCHEMATIC;
29class NET_SETTINGS;
30
31namespace SCH_CONNECTIVITY
32{
33struct FACADE_STATE;
34struct BUS_MEMBERS;
35
36// Main-thread value view; every read resolves current publication and source lifetime.
38{
39public:
40 wxString Name( bool aIgnoreSheet = false ) const;
41 wxString LocalName() const;
42 wxString FullLocalName() const;
43 bool IsBus() const;
44 bool IsNet() const;
45 // Missing or stale rows are unconnected; Connection() rejects them when acquiring a view.
46 // Inside a RENDER_SCOPE, a stale row of a live item still counts (see sch_conn_revisions_render).
47 bool IsUnconnected() const;
48 int NetCode() const;
49 uint32_t SubgraphCode() const;
50 SCH_ITEM* Driver() const;
51 // Winning driver instance; empty without a driver or when either source is stale.
52 KIID_PATH Sheet() const;
53 BUS_MEMBERS Members() const;
54 // Direct physical neighbors on this instance, resolved from published adjacency.
55 std::vector<SCH_ITEM*> ConnectedItems() const;
56
57private:
58 friend class FACADE;
59 ITEM_VIEW( std::weak_ptr<const FACADE_STATE> aState, ITEM_KEY aItem ) :
60 m_state( std::move( aState ) ), m_item( aItem )
61 {}
62
63 std::weak_ptr<const FACADE_STATE> m_state;
65};
66
67// A published component on one physical or bus-member instance.
69{
70public:
71 NODE_ID Component() const { return m_component; }
72 KIID_PATH Instance() const;
73 wxString Name( bool aIgnoreSheet = false ) const;
74 bool IsBus() const;
75 bool IsNet() const;
76 // Winning driver for the whole component; it may belong to another instance.
77 SCH_ITEM* Driver() const;
78 // Winning driver instance; empty without a driver or when either source is stale.
79 KIID_PATH Sheet() const;
80 BUS_MEMBERS Members() const;
81 // Physical items on this instance; bus-member instances may have none.
82 std::vector<SCH_ITEM*> Items() const;
83
84private:
85 friend class FACADE;
86 friend struct FACADE_STATE;
87 NET_VIEW( std::weak_ptr<const FACADE_STATE> aState, NODE_ID aComponent, INST_ID aInstance ) :
88 m_state( std::move( aState ) ), m_component( aComponent ), m_instance( aInstance )
89 {}
90
91 std::weak_ptr<const FACADE_STATE> m_state;
94};
95
105{
106 std::shared_ptr<const BUS_SCHEMA::NODE> tree;
107 std::shared_ptr<const BUS_SCHEMA> schema;
108 std::vector<NET_VIEW> leaves;
109};
110
112{
113 wxString name;
114 std::vector<NET_VIEW> instances;
115};
116
123{
124public:
125 FACADE();
126 ~FACADE();
127 FACADE( const FACADE& ) = delete;
128 FACADE& operator=( const FACADE& ) = delete;
129
135 void Recalculate( SCHEMATIC& aSchematic, bool aRebuild = false,
136 const std::function<void( SCH_ITEM* )>& aChangedHandler = {} );
137 // Applied, nonempty deltas only. Registrations survive Clear; new listeners start with the next batch.
138 [[nodiscard]] SUBSCRIPTION Subscribe( std::function<void( const CHANGE_SET& )> aListener );
139 // Refresh current model context, including text inputs without revision hooks.
140 void Update( SCHEMATIC& aSchematic, bool aRebuild = false );
141 // Production shadow boundary that traces failures and clears the publication without disturbing legacy flow.
142 bool UpdateShadow( SCHEMATIC& aSchematic, const SCH_SHEET_LIST& aPaths, bool aRebuild = false );
143 void Update( const SCH_SHEET_LIST& aPaths, uint64_t aTextEpoch, const BUS_ALIASES& aAliases,
144 bool aRebuild = false );
145 void Clear();
150 void ApplyNetclasses( NET_SETTINGS& aSettings ) const;
151 std::optional<ITEM_VIEW> Connection( const KIID& aItem, const KIID_PATH& aPath ) const;
152 std::optional<NET_VIEW> GetSubgraphForItem( const KIID& aItem, const KIID_PATH& aPath ) const;
157 std::vector<NET_GROUP> GetNetMap() const;
158 std::vector<wxString> NetNames() const;
159 std::optional<NET_GROUP> NetByName( const wxString& aName ) const;
160 // Current bus queries in canonical name and instance order; members include unmapped slots.
161 std::vector<NET_GROUP> BusWithMembers( const wxString& aName ) const;
162 // Signal handle from this facade session; Clear never recycles session handles.
163 std::vector<NET_GROUP> BundlesOf( NODE_ID aSignal ) const;
164 std::vector<wxString> GetEquivalentBusNames( const wxString& aName ) const;
165 // Explicit ERC text capture after Recalculate; updates retire the owned snapshot.
166 void PrepareTextChecks( SCHEMATIC& aSchematic, bool aIncludeDrawingSheet = false );
167 std::vector<TEXT_CHECK_FACT> TextChecks( const KIID_PATH& aPath, bool aDrawingSheet = false ) const;
168 // Explicit ERC source supplement after Recalculate; ordinary updates retire the batch.
169 void PrepareSimulationModels( SCHEMATIC& aSchematic );
170 // Owned snapshot; unavailable batches and paths outside the captured hierarchy throw.
171 std::vector<SIMULATION_MODEL_FACT> SimulationModels( const KIID_PATH& aPath ) const;
172 const PUBLICATION& Published() const;
173 const ENGINE& Engine() const;
174 const SESSION_KEYS& Keys() const;
175
176private:
177 friend class PUBLICATION_HOLD;
178
182 void updateModel( SCHEMATIC& aSchematic, const SCH_SHEET_LIST& aPaths, bool aRebuild );
183 std::shared_ptr<FACADE_STATE> m_state;
184};
185
194{
195public:
196 explicit PUBLICATION_HOLD( const FACADE& aFacade );
198
201
202private:
203 std::weak_ptr<FACADE_STATE> m_state;
204};
205} // namespace SCH_CONNECTIVITY
Definition kiid.h:46
NET_SETTINGS stores various net-related settings in a project context.
Holds all the data relating to one schematic.
Definition schematic.h:149
Owns one key/version session and its current stage evaluations; main-thread use only.
Model-owned source resolver.
FACADE & operator=(const FACADE &)=delete
std::optional< NET_GROUP > NetByName(const wxString &aName) const
void Update(SCHEMATIC &aSchematic, bool aRebuild=false)
std::optional< NET_VIEW > GetSubgraphForItem(const KIID &aItem, const KIID_PATH &aPath) const
void Recalculate(SCHEMATIC &aSchematic, bool aRebuild=false, const std::function< void(SCH_ITEM *)> &aChangedHandler={})
Update the complete model and apply netclasses, dangling flags and dirty-state clearing.
void ApplyNetclasses(NET_SETTINGS &aSettings) const
Replace label-derived assignments from a complete publication; invalidate changed net caches.
std::vector< NET_GROUP > GetNetMap() const
Owned query-time groups in canonical name order, with unique instances in KIID_PATH order.
std::vector< TEXT_CHECK_FACT > TextChecks(const KIID_PATH &aPath, bool aDrawingSheet=false) const
std::vector< wxString > NetNames() const
FACADE(const FACADE &)=delete
const SESSION_KEYS & Keys() const
void PrepareSimulationModels(SCHEMATIC &aSchematic)
const ENGINE & Engine() const
void updateModel(SCHEMATIC &aSchematic, const SCH_SHEET_LIST &aPaths, bool aRebuild)
Capture the text context and advance the text epoch when it or an external source changed.
void PrepareTextChecks(SCHEMATIC &aSchematic, bool aIncludeDrawingSheet=false)
std::vector< SIMULATION_MODEL_FACT > SimulationModels(const KIID_PATH &aPath) const
bool UpdateShadow(SCHEMATIC &aSchematic, const SCH_SHEET_LIST &aPaths, bool aRebuild=false)
std::optional< ITEM_VIEW > Connection(const KIID &aItem, const KIID_PATH &aPath) const
friend class PUBLICATION_HOLD
const PUBLICATION & Published() const
SUBSCRIPTION Subscribe(std::function< void(const CHANGE_SET &)> aListener)
std::vector< wxString > GetEquivalentBusNames(const wxString &aName) const
std::vector< NET_GROUP > BundlesOf(NODE_ID aSignal) const
std::shared_ptr< FACADE_STATE > m_state
std::vector< NET_GROUP > BusWithMembers(const wxString &aName) const
ITEM_VIEW(std::weak_ptr< const FACADE_STATE > aState, ITEM_KEY aItem)
Definition conn_facade.h:59
BUS_MEMBERS Members() const
wxString Name(bool aIgnoreSheet=false) const
std::weak_ptr< const FACADE_STATE > m_state
Definition conn_facade.h:63
std::vector< SCH_ITEM * > ConnectedItems() const
wxString Name(bool aIgnoreSheet=false) const
BUS_MEMBERS Members() const
SCH_ITEM * Driver() const
NET_VIEW(std::weak_ptr< const FACADE_STATE > aState, NODE_ID aComponent, INST_ID aInstance)
Definition conn_facade.h:87
std::vector< SCH_ITEM * > Items() const
std::weak_ptr< const FACADE_STATE > m_state
Definition conn_facade.h:91
NODE_ID Component() const
Definition conn_facade.h:71
PUBLICATION_HOLD(const FACADE &aFacade)
PUBLICATION_HOLD(const PUBLICATION_HOLD &)=delete
std::weak_ptr< FACADE_STATE > m_state
PUBLICATION_HOLD & operator=(const PUBLICATION_HOLD &)=delete
Main-thread publication.
Session IDs are dense handles, never a canonical ordering.
Definition conn_keys.h:146
Main-thread registration owner.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Value keys and the key session of the schematic connectivity engine.
std::map< wxString, std::vector< wxString > > BUS_ALIASES
Bus alias table, from alias name to member texts.
Definition conn_bus.h:40
uint32_t INST_ID
Session handle of a sheet instance KIID_PATH.
Definition conn_keys.h:41
uint32_t NODE_ID
Session handle of a NODE_KEY graph node.
Definition conn_keys.h:43
STL namespace.
Query-time snapshot; reacquire after Update.
std::shared_ptr< const BUS_SCHEMA > schema
std::shared_ptr< const BUS_SCHEMA::NODE > tree
std::vector< NET_VIEW > leaves
Difference between two publications.
One item or pin in one sheet instance.
Definition conn_keys.h:77
std::vector< NET_VIEW > instances