33#include <unordered_set>
44static std::optional<int>
getInPcbUnits(
const nlohmann::json& aObj,
const std::string& aKey,
45 std::optional<int> aDefault = std::optional<int>() )
47 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
48 return pcbIUScale.mmToIU( aObj[aKey].get<double>() );
54static std::optional<int>
getInSchUnits(
const nlohmann::json& aObj,
const std::string& aKey,
55 std::optional<int> aDefault = std::optional<int>() )
57 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
58 return schIUScale.MilsToIU( aObj[aKey].get<double>() );
72 []( nlohmann::json& json_array,
const std::shared_ptr<NETCLASS>& nc )
76 nlohmann::json nc_json = { {
"name", nc->GetName().ToUTF8() },
77 {
"priority", nc->GetPriority() },
78 {
"schematic_color", nc->GetSchematicColor(
true ) },
79 {
"pcb_color", nc->GetPcbColor(
true ) },
80 {
"tuning_profile", nc->GetTuningProfile() } };
83 []( nlohmann::json&
json,
const std::string& aKey,
int aValue )
88 if( nc->HasWireWidth() )
90 {
"wire_width",
schIUScale.IUToMils( nc->GetWireWidth() ) } );
92 if( nc->HasBusWidth() )
93 nc_json.push_back( {
"bus_width",
schIUScale.IUToMils( nc->GetBusWidth() ) } );
95 if( nc->HasLineStyle() )
96 nc_json.push_back( {
"line_style", nc->GetLineStyle() } );
98 if( nc->HasClearance() )
99 saveInPcbUnits( nc_json,
"clearance", nc->GetClearance() );
101 if( nc->HasTrackWidth() )
102 saveInPcbUnits( nc_json,
"track_width", nc->GetTrackWidth() );
104 if( nc->HasViaDiameter() )
105 saveInPcbUnits( nc_json,
"via_diameter", nc->GetViaDiameter() );
107 if( nc->HasViaDrill() )
108 saveInPcbUnits( nc_json,
"via_drill", nc->GetViaDrill() );
110 if( nc->HasuViaDiameter() )
111 saveInPcbUnits( nc_json,
"microvia_diameter", nc->GetuViaDiameter() );
113 if( nc->HasuViaDrill() )
114 saveInPcbUnits( nc_json,
"microvia_drill", nc->GetuViaDrill() );
116 if( nc->HasDiffPairWidth() )
117 saveInPcbUnits( nc_json,
"diff_pair_width", nc->GetDiffPairWidth() );
119 if( nc->HasDiffPairGap() )
120 saveInPcbUnits( nc_json,
"diff_pair_gap", nc->GetDiffPairGap() );
122 if( nc->HasDiffPairViaGap() )
123 saveInPcbUnits( nc_json,
"diff_pair_via_gap", nc->GetDiffPairViaGap() );
125 json_array.push_back( nc_json );
129 [](
const nlohmann::json& entry )
131 wxString
name = entry[
"name"];
133 std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>(
name,
false );
135 if( entry.contains(
"priority" ) && entry[
"priority"].is_number() )
136 nc->SetPriority( entry[
"priority"].get<int>() );
138 if( entry.contains(
"tuning_profile" ) && entry[
"tuning_profile"].is_string() )
139 nc->SetTuningProfile( entry[
"tuning_profile"].get<wxString>() );
142 nc->SetClearance( *value );
145 nc->SetTrackWidth( *value );
148 nc->SetViaDiameter( *value );
151 nc->SetViaDrill( *value );
153 if(
auto value =
getInPcbUnits( entry,
"microvia_diameter" ) )
154 nc->SetuViaDiameter( *value );
157 nc->SetuViaDrill( *value );
160 nc->SetDiffPairWidth( *value );
163 nc->SetDiffPairGap( *value );
165 if(
auto value =
getInPcbUnits( entry,
"diff_pair_via_gap" ) )
166 nc->SetDiffPairViaGap( *value );
169 nc->SetWireWidth( *value );
172 nc->SetBusWidth( *value );
174 if( entry.contains(
"line_style" ) && entry[
"line_style"].is_number() )
175 nc->SetLineStyle( entry[
"line_style"].get<int>() );
177 if( entry.contains(
"pcb_color" ) && entry[
"pcb_color"].is_string() )
178 nc->SetPcbColor( entry[
"pcb_color"].get<KIGFX::COLOR4D>() );
180 if( entry.contains(
"schematic_color" )
181 && entry[
"schematic_color"].is_string() )
183 nc->SetSchematicColor( entry[
"schematic_color"].get<KIGFX::COLOR4D>() );
190 [&]() -> nlohmann::json
192 nlohmann::json ret = nlohmann::json::array();
198 saveNetclass( ret, netclass );
202 [&](
const nlohmann::json& aJson )
204 if( !aJson.is_array() )
209 for(
const nlohmann::json& entry : aJson )
211 if( !entry.is_object() || !entry.contains(
"name" ) )
214 std::shared_ptr<NETCLASS> nc = readNetClass( entry );
216 if( nc->IsDefault() )
225 [&]() -> nlohmann::json
227 nlohmann::json ret = {};
231 std::string key( netname.ToUTF8() );
232 ret[ std::move( key ) ] = color;
237 [&](
const nlohmann::json& aJson )
239 if( !aJson.is_object() )
244 for(
const auto& pair : aJson.items() )
246 wxString key( pair.key().c_str(), wxConvUTF8 );
253 m_params.back()->SetClearUnknownKeys();
256 [&]() -> nlohmann::json
261 nlohmann::json ret = nlohmann::json::object();
264 ret[ std::string(
chain.ToUTF8() ) ] = std::string( className.ToUTF8() );
268 [&](
const nlohmann::json& aJson )
270 if( !aJson.is_object() )
275 for(
const auto& pair : aJson.items() )
277 wxString
chain( pair.key().c_str(), wxConvUTF8 );
278 wxString className = pair.value().get<wxString>();
280 if( !className.IsEmpty() )
287 m_params.back()->SetClearUnknownKeys();
290 [&]() -> nlohmann::json
295 nlohmann::json ret = nlohmann::json::object();
298 ret[ std::string(
chain.ToUTF8() ) ] = std::string( netclass.ToUTF8() );
302 [&](
const nlohmann::json& aJson )
304 if( !aJson.is_object() )
309 for(
const auto& pair : aJson.items() )
311 wxString
chain( pair.key().c_str(), wxConvUTF8 );
312 wxString netclass = pair.value().get<wxString>();
314 if( !netclass.IsEmpty() )
321 m_params.back()->SetClearUnknownKeys();
324 [&]() -> nlohmann::json
326 nlohmann::json ret = {};
330 nlohmann::json netclassesJson = nlohmann::json::array();
332 for(
const auto& netclass : netclassNames )
334 std::string netclassStr( netclass.ToUTF8() );
335 netclassesJson.push_back( std::move( netclassStr ) );
338 std::string key( netname.ToUTF8() );
339 ret[std::move( key )] = netclassesJson;
344 [&](
const nlohmann::json& aJson )
346 if( !aJson.is_object() )
351 for(
const auto& pair : aJson.items() )
353 wxString key( pair.key().c_str(), wxConvUTF8 );
355 for(
const auto& netclassName : pair.value() )
362 [&]() -> nlohmann::json
364 nlohmann::json ret = nlohmann::json::array();
368 nlohmann::json pattern_json = {
369 {
"pattern", matcher->GetPattern().ToUTF8() },
370 {
"netclass", netclassName.ToUTF8() }
373 ret.push_back( std::move( pattern_json ) );
378 [&](
const nlohmann::json& aJson )
380 if( !aJson.is_array() )
385 for(
const nlohmann::json& entry : aJson )
387 if( !entry.is_object() )
390 if( entry.contains(
"pattern" ) && entry[
"pattern"].is_string()
391 && entry.contains(
"netclass" ) && entry[
"netclass"].is_string() )
393 wxString pattern = entry[
"pattern"].get<wxString>();
394 wxString netclass = entry[
"netclass"].get<wxString>();
398 [&](
const wxString& memberPattern )
420 m_parent->ReleaseNestedSettings(
this );
432 auto netclassEntryEqual = [](
const auto& aLhs,
const auto& aRhs )
434 if( aLhs.first != aRhs.first )
437 if( aLhs.second.get() == aRhs.second.get() )
440 if( !aLhs.second || !aRhs.second )
443 return aLhs.second->EqualsByPersistedFields( *aRhs.second );
448 netclassEntryEqual ) )
467 auto patternEqual = [](
const auto& aLhs,
const auto& aRhs )
469 if( !aLhs.first || !aRhs.first )
470 return aLhs.first.get() == aRhs.first.get() && aLhs.second == aRhs.second;
472 return aLhs.first->GetPattern() == aRhs.first->GetPattern() && aLhs.second == aRhs.second;
510 if( &aOther ==
this )
544 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
546 if( netClass.value().contains(
"nets" ) && netClass.value()[
"nets"].is_array() )
548 nlohmann::json migrated = nlohmann::json::array();
550 for(
auto& net : netClass.value()[
"nets"].items() )
553 netClass.value()[
"nets"] = migrated;
572 nlohmann::json patterns = nlohmann::json::array();
574 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
576 if( netClass.value().contains(
"name" )
577 && netClass.value().contains(
"nets" )
578 && netClass.value()[
"nets"].is_array() )
580 wxString netClassName = netClass.value()[
"name"].get<wxString>();
582 for(
auto& net : netClass.value()[
"nets"].items() )
584 nlohmann::json pattern_json = {
585 {
"pattern", net.value().get<wxString>() },
586 {
"netclass", netClassName }
589 patterns.push_back( pattern_json );
594 m_internals->SetFromString(
"netclass_patterns", patterns );
608 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
611 netClass.value()[
"priority"] = std::numeric_limits<int>::max();
613 netClass.value()[
"priority"] = priority++;
618 if(
m_internals->contains(
"netclass_assignments" )
619 &&
m_internals->At(
"netclass_assignments" ).is_object() )
621 nlohmann::json migrated = {};
623 for(
const auto& pair :
m_internals->At(
"netclass_assignments" ).items() )
625 nlohmann::json netclassesJson = nlohmann::json::array();
627 if( pair.value().get<wxString>() != wxEmptyString )
628 netclassesJson.push_back( pair.value() );
630 migrated[pair.key()] = netclassesJson;
633 m_internals->SetFromString(
"netclass_assignments", migrated );
645 const wxString emptyStr =
"";
647 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
648 netClass.value()[
"tuning_profile"] = emptyStr.ToUTF8();
725 const std::set<wxString>& netclasses )
732 const std::set<wxString>& netclasses )
750 [&](
const wxString& memberPattern )
765 if( assignment.first->GetPattern() == pattern && assignment.second == netclass )
771 { std::make_unique<EDA_COMBINED_MATCHER>( pattern,
CTX_NETCLASS ), netclass } );
776 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&& netclassPatterns )
783std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&
797 const wxString& netclass )
800 [&](
const wxString& memberPattern )
810 const wxString& pattern,
811 const wxString& netclass )
813 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>& assignments =
816 for(
auto& assignment : assignments )
818 if( !assignment.first )
821 if( assignment.first->GetPattern() == pattern && assignment.second == netclass )
825 assignments.push_back(
826 { std::make_unique<EDA_COMBINED_MATCHER>( pattern,
CTX_NETCLASS ), netclass } );
875 if( aOldPrefix.IsEmpty() || aOldPrefix == aNewPrefix )
878 bool changed =
false;
883 const wxString pattern = matcher->GetPattern();
885 if( pattern.StartsWith( aOldPrefix ) )
887 wxString updated = aNewPrefix + pattern.Mid( aOldPrefix.length() );
888 matcher = std::make_unique<EDA_COMBINED_MATCHER>( updated,
CTX_NETCLASS );
894 std::map<wxString, KIGFX::COLOR4D> updatedColors;
898 if( netName.StartsWith( aOldPrefix ) )
900 updatedColors[aNewPrefix + netName.Mid( aOldPrefix.length() )] = color;
905 updatedColors[netName] = color;
934 auto getExplicitNetclass =
935 [
this](
const wxString& netclass ) -> std::shared_ptr<NETCLASS>
951 auto getOrAddImplicitNetcless =
952 [
this](
const wxString& netclass ) -> std::shared_ptr<NETCLASS>
958 std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>( netclass,
false );
959 nc->SetPriority( std::numeric_limits<int>::max() - 1 );
970 if( aNetName.IsEmpty() )
977 return cacheItr->second;
980 std::unordered_set<std::shared_ptr<NETCLASS>> resolvedNetclasses;
987 for(
const wxString& netclassName : it->second )
989 std::shared_ptr<NETCLASS> netclass = getExplicitNetclass( netclassName );
993 resolvedNetclasses.insert( std::move( netclass ) );
997 resolvedNetclasses.insert( getOrAddImplicitNetcless( netclassName ) );
1003 auto applyPatternList =
1004 [&](
const std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>>&
1007 for(
const auto& [matcher, netclassName] : patterns )
1009 if( matcher->StartsWith( aNetName ) )
1011 std::shared_ptr<NETCLASS> netclass = getExplicitNetclass( netclassName );
1014 resolvedNetclasses.insert( std::move( netclass ) );
1016 resolvedNetclasses.insert( getOrAddImplicitNetcless( netclassName ) );
1024 applyPatternList( chainPatterns );
1027 if( resolvedNetclasses.size() == 0 )
1031 std::shared_ptr<NETCLASS> sharedNetclass;
1032 bool allSameNetclass =
true;
1033 bool isBusPattern =
false;
1036 [&](
const wxString& member )
1040 if( member == aNetName )
1043 isBusPattern =
true;
1045 if( !allSameNetclass )
1050 if( !sharedNetclass )
1052 sharedNetclass = memberNc;
1054 else if( memberNc->GetName() != sharedNetclass->GetName() )
1056 allSameNetclass =
false;
1060 if( isBusPattern && allSameNetclass && sharedNetclass
1064 return sharedNetclass;
1075 std::vector<NETCLASS*> netclassPtrs;
1077 for(
const std::shared_ptr<NETCLASS>& nc : resolvedNetclasses )
1078 netclassPtrs.push_back( nc.get() );
1081 name.Printf(
"Effective for net: %s", aNetName );
1082 std::shared_ptr<NETCLASS> effectiveNetclass = std::make_shared<NETCLASS>(
name,
false );
1085 if( netclassPtrs.size() == 1 )
1089 return *resolvedNetclasses.begin();
1093 effectiveNetclass->SetConstituentNetclasses( std::move( netclassPtrs ) );
1098 return effectiveNetclass;
1108 std::vector<NETCLASS*> constituents = nc->GetConstituentNetclasses();
1110 wxASSERT( constituents.size() > 0 );
1115 constituents.pop_back();
1119 nc->ResetParameters();
1121 nc->SetConstituentNetclasses( std::move( constituents ) );
1127 std::vector<NETCLASS*>& constituentNetclasses )
const
1131 std::sort( constituentNetclasses.begin(), constituentNetclasses.end(),
1134 int p1 = nc1->GetPriority();
1135 int p2 = nc2->GetPriority();
1141 return nc1->GetName().Cmp( nc2->GetName() ) < 0;
1147 for(
auto itr = constituentNetclasses.rbegin(); itr != constituentNetclasses.rend(); ++itr )
1154 effectiveNetclass->SetClearanceParent( nc );
1160 effectiveNetclass->SetTrackWidthParent( nc );
1166 effectiveNetclass->SetViaDiameterParent( nc );
1171 effectiveNetclass->SetViaDrill( nc->
GetViaDrill() );
1172 effectiveNetclass->SetViaDrillParent( nc );
1178 effectiveNetclass->SetuViaDiameterParent( nc );
1184 effectiveNetclass->SetuViaDrillParent( nc );
1190 effectiveNetclass->SetDiffPairWidthParent( nc );
1196 effectiveNetclass->SetDiffPairGapParent( nc );
1202 effectiveNetclass->SetDiffPairViaGapParent( nc );
1208 effectiveNetclass->SetWireWidthParent( nc );
1213 effectiveNetclass->SetBusWidth( nc->
GetBusWidth() );
1214 effectiveNetclass->SetBusWidthParent( nc );
1220 effectiveNetclass->SetLineStyleParent( nc );
1227 effectiveNetclass->SetPcbColor( pcbColor );
1228 effectiveNetclass->SetPcbColorParent( nc );
1235 effectiveNetclass->SetSchematicColor( schColor );
1236 effectiveNetclass->SetSchematicColorParent( nc );
1242 effectiveNetclass->SetTuningProfileParent( nc );
1254 bool addedDefault =
false;
1258 addedDefault =
true;
1265 addedDefault =
true;
1272 addedDefault =
true;
1279 addedDefault =
true;
1286 addedDefault =
true;
1293 addedDefault =
true;
1300 addedDefault =
true;
1307 addedDefault =
true;
1322 addedDefault =
true;
1329 addedDefault =
true;
1337 addedDefault =
true;
1342 return addedDefault;
1359 return c ==
'_' || c ==
'^' || c ==
'~';
1376 int backslashCount = 0;
1379 while( pos > 0 && aStr[pos - 1] ==
'\\' )
1386 return ( backslashCount % 2 ) == 1;
1391 std::vector<wxString>* aMemberList )
1396 static wxString digits( wxT(
"0123456789" ) );
1397 return digits.Contains( c );
1400 size_t busLen = aBus.length();
1407 int braceNesting = 0;
1408 bool fmtWrapsName =
false;
1409 bool inQuotes =
false;
1411 prefix.reserve( busLen );
1420 for( ; i < busLen; ++i )
1423 if( aBus[i] ==
'"' && !
isEscaped( aBus, i ) )
1425 inQuotes = !inQuotes;
1432 if( aBus[i] ==
'\\' && i + 1 < busLen )
1435 prefix += aBus[++i];
1445 if( aBus[i] ==
'{' )
1450 prefix += wxT(
'{' );
1456 else if( aBus[i] ==
'}' )
1459 prefix += wxT(
'}' );
1464 if( aBus[i] ==
'\\' && i + 1 < busLen && aBus[i + 1] ==
' ' )
1466 prefix += aBus[++i];
1471 if( aBus[i] ==
' ' || aBus[i] ==
']' )
1474 if( aBus[i] ==
'[' )
1476 if( braceNesting > 0 )
1478 size_t fmtStart = prefix.rfind( wxT(
'{' ) );
1480 if( fmtStart != wxString::npos && fmtStart > 0
1483 if( fmtStart == prefix.length() - 1 )
1488 prefix.erase( fmtStart - 1 );
1495 fmtWrapsName =
true;
1513 for( ; i < busLen; ++i )
1515 if( aBus[i] ==
'.' && i + 1 < busLen && aBus[i+1] ==
'.' )
1517 tmp.ToLong( &begin );
1530 tmp = wxEmptyString;
1535 for( ; i < busLen; ++i )
1537 if( aBus[i] ==
']' )
1552 for( ; i < busLen; ++i )
1554 if( aBus[i] ==
'}' )
1561 else if( aBus[i] ==
'+' || aBus[i] ==
'-' || aBus[i] ==
'P' || aBus[i] ==
'N' )
1571 if( braceNesting != 0 )
1576 else if( begin >
end )
1577 std::swap( begin,
end );
1584 for(
long idx = begin; idx <=
end; ++idx )
1586 wxString str = prefix;
1590 aMemberList->emplace_back( str );
1599 std::vector<wxString>* aMemberList )
1601 size_t groupLen = aGroup.length();
1605 int braceNesting = 0;
1606 bool inQuotes =
false;
1608 prefix.reserve( groupLen );
1613 auto escapeSpacesForBus =
1614 [](
const wxString& aMember ) -> wxString
1617 escaped.reserve( aMember.length() * 2 );
1619 for( wxUniChar c : aMember )
1622 escaped += wxT(
"\\ " );
1636 for( ; i < groupLen; ++i )
1639 if( aGroup[i] ==
'"' && !
isEscaped( aGroup, i ) )
1641 inQuotes = !inQuotes;
1648 if( aGroup[i] ==
'\\' && i + 1 < groupLen )
1651 prefix += aGroup[++i];
1655 prefix += aGroup[i];
1661 if( aGroup[i] ==
'{' )
1666 prefix += wxT(
'{' );
1672 else if( aGroup[i] ==
'}' )
1675 prefix += wxT(
'}' );
1680 if( aGroup[i] ==
'\\' && i + 1 < groupLen && aGroup[i + 1] ==
' ' )
1682 prefix += aGroup[++i];
1687 if( aGroup[i] ==
' ' || aGroup[i] ==
'[' || aGroup[i] ==
']' )
1690 prefix += aGroup[i];
1693 if( braceNesting != 0 )
1708 for( ; i < groupLen; ++i )
1711 if( aGroup[i] ==
'"' && !
isEscaped( aGroup, i ) )
1713 inQuotes = !inQuotes;
1720 if( aGroup[i] ==
'\\' && i + 1 < groupLen )
1733 if( aGroup[i] ==
'{' )
1749 else if( aGroup[i] ==
'}' )
1759 if( aMemberList && !tmp.IsEmpty() )
1767 if( aGroup[i] ==
'\\' && i + 1 < groupLen && aGroup[i + 1] ==
' ' )
1774 if( aGroup[i] ==
' ' || aGroup[i] ==
',' )
1776 if( aMemberList && !tmp.IsEmpty() )
1791 const std::function<
void(
const wxString& )>& aFunction )
1793 std::vector<wxString> members;
1798 for(
const wxString& member : members )
1799 aFunction( member );
1804 for(
const wxString& member : members )
1810 aFunction( aBusPattern );
constexpr EDA_IU_SCALE schIUScale
constexpr EDA_IU_SCALE pcbIUScale
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
void CloneFrom(const JSON_SETTINGS_INTERNALS &aOther)
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
JSON_SETTINGS_INTERNALS * Internals()
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
A color representation with 4 components: red, green, blue, alpha.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
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.
void SetViaDiameter(int aDia)
void SetViaDrill(int aSize)
bool HasLineStyle() const
int GetViaDiameter() const
void SetWireWidthParent(NETCLASS *parent)
static const char Default[]
the name of the default NETCLASS
void SetuViaDrillParent(NETCLASS *parent)
bool HasuViaDrill() const
void SetDiffPairWidthParent(NETCLASS *parent)
void SetuViaDiameter(int aSize)
void SetDiffPairWidth(int aSize)
int GetDiffPairViaGap() const
void SetViaDrillParent(NETCLASS *parent)
wxString GetTuningProfile() const
void SetDiffPairGapParent(NETCLASS *parent)
void SetTuningProfileParent(NETCLASS *aParent)
int GetDiffPairGap() const
bool HasViaDiameter() const
bool HasDiffPairWidth() const
bool HasuViaDiameter() const
void SetTrackWidthParent(NETCLASS *parent)
int GetuViaDiameter() const
bool HasTrackWidth() const
void SetViaDiameterParent(NETCLASS *parent)
int GetDiffPairWidth() const
void SetuViaDrill(int aSize)
void SetDiffPairGap(int aSize)
void SetBusWidthParent(NETCLASS *parent)
void SetClearance(int aClearance)
COLOR4D GetPcbColor(bool aIsForSave=false) const
bool HasDiffPairGap() const
COLOR4D GetSchematicColor(bool aIsForSave=false) const
void SetBusWidth(int aWidth)
void SetClearanceParent(NETCLASS *parent)
int GetTrackWidth() const
void SetWireWidth(int aWidth)
void SetTuningProfile(const wxString &aTuningProfile)
bool HasTuningProfile() const
bool HasWireWidth() const
void SetuViaDiameterParent(NETCLASS *parent)
void SetTrackWidth(int aWidth)
bool HasDiffPairViaGap() const
bool HasClearance() const
void ClearAllCaches()
Clears the effective netclass cache for all nets.
std::map< wxString, std::shared_ptr< NETCLASS > > m_compositeNetClasses
Map of netclass names to netclass definitions for.
bool addMissingDefaults(NETCLASS *nc) const
Adds any missing fields to the given netclass from the default netclass.
void ClearNetColorAssignments()
Clears all net name to color assignments Calling user is responsible for resetting the effective netc...
bool operator==(const NET_SETTINGS &aOther) const
void ClearCacheForNet(const wxString &netName)
Clears effective netclass cache for the given net.
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const wxString &aNetName)
Fetches the effective (may be aggregate) netclass for the given net name.
bool HasEffectiveNetClass(const wxString &aNetName) const
Determines if an effective netclass for the given net name has been cached.
void addSinglePatternAssignment(const wxString &pattern, const wxString &netclass)
Adds a single pattern assignment without bus expansion (internal helper)
void ClearNetclassLabelAssignments()
Clears all net name to netclasses assignments Calling user is responsible for resetting the effective...
bool RenameNetPathPrefix(const wxString &aOldPrefix, const wxString &aNewPrefix)
Retarget netclass patterns and net colors after a path prefix changes (sheet rename).
void ClearNetclassLabelAssignment(const wxString &netName)
Clears a specific net name to netclass assignment Calling user is responsible for resetting the effec...
void ClearNetclassPatternAssignments()
Clears all netclass pattern assignments.
std::map< wxString, KIGFX::COLOR4D > m_netColorAssignments
A map of fully-qualified net names to colors used in the board context.
void SetNetclasses(const std::map< wxString, std::shared_ptr< NETCLASS > > &netclasses)
Sets all netclass Calling this method will reset the effective netclass calculation caches.
bool HasNetclassLabelAssignment(const wxString &netName) const
Determines if a given net name has netclasses assigned.
void SetNetclassLabelAssignment(const wxString &netName, const std::set< wxString > &netclasses)
Sets a net name to netclasses assignment Calling user is responsible for resetting the effective netc...
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.
static bool ParseBusGroup(const wxString &aGroup, wxString *name, std::vector< wxString > *aMemberList)
Parse a bus group label into the name and a list of components.
void ClearNetclasses()
Clears all netclasses Calling this method will reset the effective netclass calculation caches.
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.
const std::map< wxString, std::shared_ptr< NETCLASS > > & GetCompositeNetclasses() const
Gets all composite (multiple assignment / missing defaults) 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.
void SetNetclassPatternAssignments(std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > &&netclassPatterns)
Sets all netclass pattern assignments Calling user is responsible for resetting the effective netclas...
void SetNetclassPatternAssignment(const wxString &pattern, const wxString &netclass)
Sets a netclass pattern assignment Calling this method will reset the effective netclass calculation ...
std::map< wxString, std::shared_ptr< NETCLASS > > m_netClasses
Map of netclass names to netclass definitions.
const std::map< wxString, std::set< wxString > > & GetNetclassLabelAssignments() const
Gets all current net name to netclasses assignments.
const std::map< wxString, std::shared_ptr< NETCLASS > > & GetNetclasses() const
Gets all netclasses.
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
void SetChainPatternAssignment(NET_CHAIN_SOURCE aSource, const wxString &pattern, const wxString &netclass)
Sets a chain-derived netclass pattern assignment owned by aSource.
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
const std::map< wxString, KIGFX::COLOR4D > & GetNetColorAssignments() const
Gets all net name to color assignments.
void ClearChainPatternAssignments(NET_CHAIN_SOURCE aSource)
Clears the chain-derived pattern assignments owned by aSource, leaving the other source's entries in ...
void CopyFrom(NET_SETTINGS &aOther)
Deep-copy the persisted contents of aOther into this instance.
std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > & GetNetclassPatternAssignments()
Gets the netclass pattern assignments.
void RecomputeEffectiveNetclasses()
Recomputes the internal values of all aggregate effective netclasses Called when a value of a user-de...
std::shared_ptr< NETCLASS > GetCachedEffectiveNetClass(const wxString &aNetName) const
Returns an already cached effective netclass for the given net name.
std::map< wxString, std::set< wxString > > m_netClassLabelAssignments
Map of net names to resolved netclasses.
void SetNetclass(const wxString &netclassName, std::shared_ptr< NETCLASS > &netclass)
Sets the given netclass Calling user is responsible for resetting the effective netclass calculation ...
void makeEffectiveNetclass(std::shared_ptr< NETCLASS > &effectiveNetclass, std::vector< NETCLASS * > &netclasses) const
Creates an effective aggregate netclass from the given constituent netclasses.
void AppendNetclassLabelAssignment(const wxString &netName, const std::set< wxString > &netclasses)
Apppends to a net name to netclasses assignment Calling user is responsible for resetting the effecti...
void SetDefaultNetclass(std::shared_ptr< NETCLASS > netclass)
Sets the default netclass for the project Calling user is responsible for resetting the effective net...
static void ForEachBusMember(const wxString &aBusPattern, const std::function< void(const wxString &)> &aFunction)
Call a function for each member of an expanded bus pattern.
std::shared_ptr< NETCLASS > GetNetClassByName(const wxString &aNetName) const
Get a NETCLASS object from a given Netclass name string.
void SetNetColorAssignment(const wxString &netName, const KIGFX::COLOR4D &color)
Sets a net to color assignment Calling user is responsible for resetting the effective netclass calcu...
NET_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
bool HasNetclass(const wxString &netclassName) const
Determines if the given netclass exists.
void addSingleChainPatternAssignment(NET_CHAIN_SOURCE aSource, const wxString &pattern, const wxString &netclass)
Adds a single chain-derived pattern assignment without bus expansion (internal helper)
std::map< wxString, wxString > m_netChainClasses
Map of net-chain name -> chain-class name.
Like a normal param, but with custom getter and setter functions.
static bool isSuperSubOverbar(wxChar c)
const int netSettingsSchemaVersion
static bool isEscaped(const wxString &aStr, size_t aPos)
Check if a character at the given position is escaped by a backslash.
static std::optional< int > getInSchUnits(const nlohmann::json &aObj, const std::string &aKey, std::optional< int > aDefault=std::optional< int >())
static std::optional< int > getInPcbUnits(const nlohmann::json &aObj, const std::string &aKey, std::optional< int > aDefault=std::optional< int >())
NET_CHAIN_SOURCE
Owner of a set of chain-derived netclass pattern assignments.
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
const SHAPE_LINE_CHAIN chain