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 along
19 * with this program. If not, see <http://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
40{
41public:
42 NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath );
43
44 virtual ~NET_SETTINGS();
45
46 bool operator==( const NET_SETTINGS& aOther ) const;
47
48 bool operator!=( const NET_SETTINGS& aOther ) const { return !operator==( aOther ); }
49
52 void SetDefaultNetclass( std::shared_ptr<NETCLASS> netclass );
53
55 std::shared_ptr<NETCLASS> GetDefaultNetclass();
56
58 bool HasNetclass( const wxString& netclassName ) const;
59
62 void SetNetclass( const wxString& netclassName, std::shared_ptr<NETCLASS>& netclass );
63
66 void SetNetclasses( const std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses );
67
69 const std::map<wxString, std::shared_ptr<NETCLASS>>& GetNetclasses() const;
70
72 // Note the full connectivity or board net synchronisation must be run before calling
73 // this, otherwise resolved netclasses may be missing
74 const std::map<wxString, std::shared_ptr<NETCLASS>>& GetCompositeNetclasses() const;
75
78 void ClearNetclasses();
79
81 const std::map<wxString, std::set<wxString>>& GetNetclassLabelAssignments() const;
82
85 void ClearNetclassLabelAssignments();
86
89 void ClearNetclassLabelAssignment( const wxString& netName );
90
93 void SetNetclassLabelAssignment( const wxString& netName,
94 const std::set<wxString>& netclasses );
95
98 void AppendNetclassLabelAssignment( const wxString& netName,
99 const std::set<wxString>& netclasses );
100
102 bool HasNetclassLabelAssignment( const wxString& netName ) const;
103
106 void SetNetclassPatternAssignment( const wxString& pattern, const wxString& netclass );
107
110 void SetNetclassPatternAssignments(
111 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&&
112 netclassPatterns );
113
115 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&
116 GetNetclassPatternAssignments();
117
119 void ClearNetclassPatternAssignments();
120
122 void ClearCacheForNet( const wxString& netName );
123
125 void ClearAllCaches();
126
129 void SetNetColorAssignment( const wxString& netName, const KIGFX::COLOR4D& color );
130
132 const std::map<wxString, KIGFX::COLOR4D>& GetNetColorAssignments() const;
133
136 void ClearNetColorAssignments();
137
139 bool HasEffectiveNetClass( const wxString& aNetName ) const;
140
143 std::shared_ptr<NETCLASS> GetCachedEffectiveNetClass( const wxString& aNetName ) const;
144
146 // If the effective netclass has not been computed, it will be created and cached.
147 std::shared_ptr<NETCLASS> GetEffectiveNetClass( const wxString& aNetName );
148
152 void RecomputeEffectiveNetclasses();
153
160 std::shared_ptr<NETCLASS> GetNetClassByName( const wxString& aNetName ) const;
161
172 static bool ParseBusVector( const wxString& aBus, wxString* aName,
173 std::vector<wxString>* aMemberList );
174
183 static bool ParseBusGroup( const wxString& aGroup, wxString* name,
184 std::vector<wxString>* aMemberList );
185
198 static void ForEachBusMember( const wxString& aBusPattern,
199 const std::function<void( const wxString& )>& aFunction );
200
201private:
202 bool migrateSchema0to1();
203 bool migrateSchema1to2();
204 bool migrateSchema2to3();
205 bool migrateSchema3to4();
206 bool migrateSchema4to5();
207
217 void makeEffectiveNetclass( std::shared_ptr<NETCLASS>& effectiveNetclass,
218 std::vector<NETCLASS*>& netclasses ) const;
219
222 bool addMissingDefaults( NETCLASS* nc ) const;
223
225 void addSinglePatternAssignment( const wxString& pattern, const wxString& netclass );
226
228 std::shared_ptr<NETCLASS> m_defaultNetClass;
229
231 std::map<wxString, std::shared_ptr<NETCLASS>> m_netClasses;
232
234 std::map<wxString, std::set<wxString>> m_netClassLabelAssignments;
235
237 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>
239
241 // composite (multiple netclass assignment / missing defaults) netclasses
242 std::map<wxString, std::shared_ptr<NETCLASS>> m_compositeNetClasses;
243
249 // to the effective netclasses which contain them.
250 std::map<wxString, std::shared_ptr<NETCLASS>> m_impicitNetClasses;
251
253 std::map<wxString, std::shared_ptr<NETCLASS>> m_effectiveNetclassCache;
254
261 std::map<wxString, KIGFX::COLOR4D> m_netColorAssignments;
262
263 // TODO: Add diff pairs, bus information, etc.
264};
265
266#endif // KICAD_NET_SETTINGS_H
const char * name
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
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:45
std::map< wxString, std::shared_ptr< NETCLASS > > m_compositeNetClasses
Map of netclass names to netclass definitions for.
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, std::shared_ptr< NETCLASS > > m_impicitNetClasses
Map of netclass names to netclass definitions for implicit netclasses.
std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > m_netClassPatternAssignments
List of net class pattern assignments.
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.
bool operator!=(const NET_SETTINGS &aOther) const
std::map< wxString, std::set< wxString > > m_netClassLabelAssignments
Map of net names to resolved netclasses.
NET_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
Abstract pattern-matching tool and implementations.
#define KICOMMON_API
Definition kicommon.h:28