KiCad PCB EDA Suite
Loading...
Searching...
No Matches
net_settings.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 (C) 2020 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jon Evans <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef KICAD_NET_SETTINGS_H
23#define KICAD_NET_SETTINGS_H
24
25#include <functional>
26#include <map>
27#include <memory>
28#include <set>
29#include <vector>
30
31#include <netclass.h>
33#include <eda_pattern_match.h>
34
47
53{
54public:
55 NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath );
56
57 virtual ~NET_SETTINGS();
58
59 bool operator==( const NET_SETTINGS& aOther ) const;
60
61 bool operator!=( const NET_SETTINGS& aOther ) const { return !operator==( aOther ); }
62
87 void CopyFrom( NET_SETTINGS& aOther );
88
91 void SetDefaultNetclass( std::shared_ptr<NETCLASS> netclass );
92
94 std::shared_ptr<NETCLASS> GetDefaultNetclass() const;
95
97 bool HasNetclass( const wxString& netclassName ) const;
98
101 void SetNetclass( const wxString& netclassName, std::shared_ptr<NETCLASS>& netclass );
102
105 void SetNetclasses( const std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses );
106
108 const std::map<wxString, std::shared_ptr<NETCLASS>>& GetNetclasses() const;
109
111 // Note the full connectivity or board net synchronisation must be run before calling
112 // this, otherwise resolved netclasses may be missing
113 const std::map<wxString, std::shared_ptr<NETCLASS>>& GetCompositeNetclasses() const;
114
117 void ClearNetclasses();
118
120 const std::map<wxString, std::set<wxString>>& GetNetclassLabelAssignments() const;
121
124 void ClearNetclassLabelAssignments();
125
128 void ClearNetclassLabelAssignment( const wxString& netName );
129
132 void SetNetclassLabelAssignment( const wxString& netName,
133 const std::set<wxString>& netclasses );
134
137 void AppendNetclassLabelAssignment( const wxString& netName,
138 const std::set<wxString>& netclasses );
139
141 bool HasNetclassLabelAssignment( const wxString& netName ) const;
142
145 void SetNetclassPatternAssignment( const wxString& pattern, const wxString& netclass );
146
149 void SetNetclassPatternAssignments(
150 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&&
151 netclassPatterns );
152
154 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&
155 GetNetclassPatternAssignments();
156
158 void ClearNetclassPatternAssignments();
159
166 void SetChainPatternAssignment( NET_CHAIN_SOURCE aSource, const wxString& pattern,
167 const wxString& netclass );
168
172 void ClearChainPatternAssignments( NET_CHAIN_SOURCE aSource );
173
176 {
177 auto it = m_netClassChainPatternAssignments.find( aSource );
178 return it != m_netClassChainPatternAssignments.end() && !it->second.empty();
179 }
180
182 void ClearCacheForNet( const wxString& netName );
183
185 void ClearAllCaches();
186
189 void SetNetColorAssignment( const wxString& netName, const KIGFX::COLOR4D& color );
190
192 const std::map<wxString, KIGFX::COLOR4D>& GetNetColorAssignments() const;
193
196 void ClearNetColorAssignments();
197
201 bool RenameNetPathPrefix( const wxString& aOldPrefix, const wxString& aNewPrefix );
202
204 void SetNetChainClass( const wxString& aChain, const wxString& aClass )
205 {
206 if( aClass.IsEmpty() )
207 m_netChainClasses.erase( aChain );
208 else
209 m_netChainClasses[aChain] = aClass;
210 }
211
213 wxString GetNetChainClass( const wxString& aChain ) const
214 {
215 auto it = m_netChainClasses.find( aChain );
216 return it != m_netChainClasses.end() ? it->second : wxString();
217 }
218
219 const std::map<wxString, wxString>& GetNetChainClasses() const
220 {
221 return m_netChainClasses;
222 }
223
226 {
227 m_netChainClasses.clear();
228 }
229
231 void SetNetChainNetClass( const wxString& aChain, const wxString& aNetclass )
232 {
233 if( aNetclass.IsEmpty() )
234 m_netChainNetClasses.erase( aChain );
235 else
236 m_netChainNetClasses[aChain] = aNetclass;
237 }
238
240 wxString GetNetChainNetClass( const wxString& aChain ) const
241 {
242 auto it = m_netChainNetClasses.find( aChain );
243 return it != m_netChainNetClasses.end() ? it->second : wxString();
244 }
245
246 const std::map<wxString, wxString>& GetNetChainNetClasses() const
247 {
249 }
250
253 {
254 m_netChainNetClasses.clear();
255 }
256
258 bool HasEffectiveNetClass( const wxString& aNetName ) const;
259
262 std::shared_ptr<NETCLASS> GetCachedEffectiveNetClass( const wxString& aNetName ) const;
263
265 // If the effective netclass has not been computed, it will be created and cached.
266 std::shared_ptr<NETCLASS> GetEffectiveNetClass( const wxString& aNetName );
267
271 void RecomputeEffectiveNetclasses();
272
279 std::shared_ptr<NETCLASS> GetNetClassByName( const wxString& aNetName ) const;
280
291 static bool ParseBusVector( const wxString& aBus, wxString* aName,
292 std::vector<wxString>* aMemberList );
293
302 static bool ParseBusGroup( const wxString& aGroup, wxString* name,
303 std::vector<wxString>* aMemberList );
304
317 static void ForEachBusMember( const wxString& aBusPattern,
318 const std::function<void( const wxString& )>& aFunction );
319
320private:
321 bool migrateSchema0to1();
322 bool migrateSchema1to2();
323 bool migrateSchema2to3();
324 bool migrateSchema3to4();
325 bool migrateSchema4to5();
326
336 void makeEffectiveNetclass( std::shared_ptr<NETCLASS>& effectiveNetclass,
337 std::vector<NETCLASS*>& netclasses ) const;
338
341 bool addMissingDefaults( NETCLASS* nc ) const;
342
344 void addSinglePatternAssignment( const wxString& pattern, const wxString& netclass );
345
347 void addSingleChainPatternAssignment( NET_CHAIN_SOURCE aSource, const wxString& pattern,
348 const wxString& netclass );
349
351 std::shared_ptr<NETCLASS> m_defaultNetClass;
352
354 std::map<wxString, std::shared_ptr<NETCLASS>> m_netClasses;
355
357 std::map<wxString, std::set<wxString>> m_netClassLabelAssignments;
358
360 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>
362
369 std::map<NET_CHAIN_SOURCE,
370 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>>
372
374 // composite (multiple netclass assignment / missing defaults) netclasses
375 std::map<wxString, std::shared_ptr<NETCLASS>> m_compositeNetClasses;
376
382 // to the effective netclasses which contain them.
383 std::map<wxString, std::shared_ptr<NETCLASS>> m_impicitNetClasses;
384
386 std::map<wxString, std::shared_ptr<NETCLASS>> m_effectiveNetclassCache;
387
394 std::map<wxString, KIGFX::COLOR4D> m_netColorAssignments;
395
402 std::map<wxString, wxString> m_netChainClasses;
403
411 std::map<wxString, wxString> m_netChainNetClasses;
412
413 // TODO: Add diff pairs, bus information, etc.
414};
415
416#endif // KICAD_NET_SETTINGS_H
const char * name
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
NESTED_SETTINGS(const std::string &aName, int aSchemaVersion, JSON_SETTINGS *aParent, const std::string &aPath, bool aLoadFromFile=true)
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:38
NET_SETTINGS stores various net-related settings in a project context.
std::map< wxString, std::shared_ptr< NETCLASS > > m_compositeNetClasses
Map of netclass names to netclass definitions for.
const std::map< wxString, wxString > & GetNetChainNetClasses() const
void SetNetChainClass(const wxString &aChain, const wxString &aClass)
Assign a net chain to a named class (used by inNetChainClass() DRC scope).
void SetNetChainNetClass(const wxString &aChain, const wxString &aNetclass)
Assign the netclass a net chain applies to all of its member nets.
wxString GetNetChainClass(const wxString &aChain) const
Look up the class assigned to a chain. Empty string means "no class".
std::map< wxString, KIGFX::COLOR4D > m_netColorAssignments
A map of fully-qualified net names to colors used in the board context.
std::shared_ptr< NETCLASS > m_defaultNetClass
The default netclass.
std::map< wxString, wxString > m_netChainNetClasses
Map of net-chain name -> netclass name applied to every net in the chain.
std::map< wxString, std::shared_ptr< NETCLASS > > m_impicitNetClasses
Map of netclass names to netclass definitions for implicit netclasses.
std::map< NET_CHAIN_SOURCE, std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > > m_netClassChainPatternAssignments
Chain-derived netclass pattern assignments, keyed by the editor that derived them.
std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > m_netClassPatternAssignments
List of net class pattern assignments.
wxString GetNetChainNetClass(const wxString &aChain) const
Look up the netclass a chain applies to its members. Empty string means "none".
std::map< wxString, std::shared_ptr< NETCLASS > > m_effectiveNetclassCache
Cache of nets to pattern-matched netclasses.
std::map< wxString, std::shared_ptr< NETCLASS > > m_netClasses
Map of netclass names to netclass definitions.
const std::map< wxString, wxString > & GetNetChainClasses() const
bool operator!=(const NET_SETTINGS &aOther) const
void ClearNetChainClasses()
Removes all chain-to-class assignments.
void ClearNetChainNetClasses()
Removes all chain-to-netclass assignments.
bool HasChainPatternAssignments(NET_CHAIN_SOURCE aSource) const
Returns true if aSource has contributed any chain-derived pattern assignment.
std::map< wxString, std::set< wxString > > m_netClassLabelAssignments
Map of net names to resolved netclasses.
NET_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
std::map< wxString, wxString > m_netChainClasses
Map of net-chain name -> chain-class name.
Holds all the data relating to one schematic.
Definition schematic.h:90
Abstract pattern-matching tool and implementations.
#define KICOMMON_API
Definition kicommon.h:27
NET_CHAIN_SOURCE
Owner of a set of chain-derived netclass pattern assignments.