22#include <nlohmann/json.hpp>
39 std::optional<int> aDefault = std::optional<int>() )
41 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
50 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
64 [](
nlohmann::json& json_array,
const std::shared_ptr<NETCLASS>& nc )
69 {
"name", nc->GetName().ToUTF8() },
72 {
"line_style", nc->GetLineStyle() },
73 {
"schematic_color", nc->GetSchematicColor() },
74 {
"pcb_color", nc->GetPcbColor() }
83 if( nc->HasClearance() )
84 saveInPcbUnits( nc_json,
"clearance", nc->GetClearance() );
86 if( nc->HasTrackWidth() )
87 saveInPcbUnits( nc_json,
"track_width", nc->GetTrackWidth() );
89 if( nc->HasViaDiameter() )
90 saveInPcbUnits( nc_json,
"via_diameter", nc->GetViaDiameter() );
92 if( nc->HasViaDrill() )
93 saveInPcbUnits( nc_json,
"via_drill", nc->GetViaDrill() );
95 if( nc->HasuViaDiameter() )
96 saveInPcbUnits( nc_json,
"microvia_diameter", nc->GetuViaDiameter() );
98 if( nc->HasuViaDrill() )
99 saveInPcbUnits( nc_json,
"microvia_drill", nc->GetuViaDrill() );
101 if( nc->HasDiffPairWidth() )
102 saveInPcbUnits( nc_json,
"diff_pair_width", nc->GetDiffPairWidth() );
104 if( nc->HasDiffPairGap() )
105 saveInPcbUnits( nc_json,
"diff_pair_gap", nc->GetDiffPairGap() );
107 if( nc->HasDiffPairViaGap() )
108 saveInPcbUnits( nc_json,
"diff_pair_via_gap", nc->GetDiffPairViaGap() );
110 json_array.push_back( nc_json );
116 wxString
name = entry[
"name"];
118 std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>(
name );
121 nc->SetClearance( *value );
124 nc->SetTrackWidth( *value );
127 nc->SetViaDiameter( *value );
130 nc->SetViaDrill( *value );
132 if(
auto value =
getInPcbUnits( entry,
"microvia_diameter" ) )
133 nc->SetuViaDiameter( *value );
136 nc->SetuViaDrill( *value );
139 nc->SetDiffPairWidth( *value );
142 nc->SetDiffPairGap( *value );
144 if(
auto value =
getInPcbUnits( entry,
"diff_pair_via_gap" ) )
145 nc->SetDiffPairViaGap( *value );
147 nc->SetWireWidth(
getInSchUnits( entry,
"wire_width", nc->GetWireWidth() ) );
148 nc->SetBusWidth(
getInSchUnits( entry,
"bus_width", nc->GetBusWidth() ) );
150 if( entry.contains(
"line_style" ) && entry[
"line_style"].is_number() )
151 nc->SetLineStyle( entry[
"line_style"].get<int>() );
153 if( entry.contains(
"pcb_color" ) && entry[
"pcb_color"].is_string() )
154 nc->SetPcbColor( entry[
"pcb_color"].get<KIGFX::COLOR4D>() );
156 if( entry.contains(
"schematic_color" )
157 && entry[
"schematic_color"].is_string() )
159 nc->SetSchematicColor( entry[
"schematic_color"].get<KIGFX::COLOR4D>() );
174 saveNetclass( ret, netclass );
180 if( !aJson.is_array() )
187 if( !entry.is_object() || !entry.contains(
"name" ) )
190 std::shared_ptr<NETCLASS> nc = readNetClass( entry );
207 std::string key( netname.ToUTF8() );
215 if( !aJson.is_object() )
220 for(
const auto& pair : aJson.items() )
222 wxString key( pair.key().c_str(), wxConvUTF8 );
235 std::string key( netname.ToUTF8() );
236 ret[key] = netclassName;
243 if( !aJson.is_object() )
248 for(
const auto& pair : aJson.items() )
250 wxString key( pair.key().c_str(), wxConvUTF8 );
264 {
"pattern", matcher->GetPattern().ToUTF8() },
265 {
"netclass", netclassName.ToUTF8() }
268 ret.push_back( pattern_json );
275 if( !aJson.is_array() )
282 if( !entry.is_object() )
285 if( entry.contains(
"pattern" ) && entry[
"pattern"].is_string()
286 && entry.contains(
"netclass" ) && entry[
"netclass"].is_string() )
288 wxString pattern = entry[
"pattern"].get<wxString>();
289 wxString netclass = entry[
"netclass"].get<wxString>();
293 std::make_unique<EDA_COMBINED_MATCHER>( pattern,
CTX_NETCLASS ),
321 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
323 if( netClass.value().contains(
"nets" ) && netClass.value()[
"nets"].is_array() )
327 for(
auto& net : netClass.value()[
"nets"].items() )
330 netClass.value()[
"nets"] = migrated;
345 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
347 if( netClass.value().contains(
"name" )
348 && netClass.value().contains(
"nets" )
349 && netClass.value()[
"nets"].is_array() )
351 wxString netClassName = netClass.value()[
"name"].get<wxString>();
353 for(
auto& net : netClass.value()[
"nets"].items() )
356 {
"pattern", net.value().get<wxString>() },
357 {
"netclass", netClassName }
360 patterns.push_back( pattern_json );
365 m_internals->SetFromString(
"netclass_patterns", patterns );
375 [&](
const wxString& netclass )
386 if( aNetName.IsEmpty() )
392 return getNetclass( it->second );
399 if( matcher->Find( aNetName, matches, offset ) && offset == 0 )
400 return getNetclass( netclassName );
409 return c ==
'_' || c ==
'^' || c ==
'~';
414 std::vector<wxString>* aMemberList )
418 static wxString digits( wxT(
"0123456789" ) );
419 return digits.Contains( c );
422 size_t busLen = aBus.length();
429 int braceNesting = 0;
431 prefix.reserve( busLen );
435 for( ; i < busLen; ++i )
444 else if( aBus[i] ==
'}' )
449 if( aBus[i] ==
' ' || aBus[i] ==
']' )
465 for( ; i < busLen; ++i )
467 if( aBus[i] ==
'.' && i + 1 < busLen && aBus[i+1] ==
'.' )
469 tmp.ToLong( &begin );
487 for( ; i < busLen; ++i )
504 for( ; i < busLen; ++i )
517 if( braceNesting != 0 )
522 else if( begin > end )
523 std::swap( begin, end );
530 for(
long idx = begin; idx <= end; ++idx )
532 wxString str = prefix;
536 aMemberList->emplace_back( str );
545 std::vector<wxString>* aMemberList )
547 size_t groupLen = aGroup.length();
551 int braceNesting = 0;
553 prefix.reserve( groupLen );
557 for( ; i < groupLen; ++i )
559 if( aGroup[i] ==
'{' )
566 else if( aGroup[i] ==
'}' )
571 if( aGroup[i] ==
' ' || aGroup[i] ==
'[' || aGroup[i] ==
']' )
577 if( braceNesting != 0 )
590 for( ; i < groupLen; ++i )
592 if( aGroup[i] ==
'{' )
599 else if( aGroup[i] ==
'}' )
607 if( aMemberList && !tmp.IsEmpty() )
615 if( aGroup[i] ==
' ' || aGroup[i] ==
',' )
617 if( aMemberList && !tmp.IsEmpty() )
constexpr EDA_IU_SCALE schIUScale
constexpr EDA_IU_SCALE pcbIUScale
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.
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
A color representation with 4 components: red, green, blue, alpha.
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
static const char Default[]
the name of the default NETCLASS
std::shared_ptr< NETCLASS > m_DefaultNetClass
std::map< wxString, KIGFX::COLOR4D > m_NetColorAssignments
A map of fully-qualified net names to colors used in the board context.
std::map< wxString, wxString > m_NetClassLabelAssignments
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.
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const wxString &aNetName) const
std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > m_NetClassPatternAssignments
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
std::map< wxString, std::shared_ptr< NETCLASS > > m_NetClasses
NET_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
static bool isSuperSubOverbar(wxChar c)
const int netSettingsSchemaVersion
static int getInSchUnits(const nlohmann::json &aObj, const std::string &aKey, int aDefault)
static std::optional< int > getInPcbUnits(const nlohmann::json &aObj, const std::string &aKey, std::optional< int > aDefault=std::optional< int >())
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:...
constexpr double IUTomm(int iu) const
constexpr int IUToMils(int iu) const
constexpr int MilsToIU(int mils) const
constexpr int mmToIU(double mm) const