22#include <nlohmann/json.hpp>
38static std::optional<int>
getInPcbUnits(
const nlohmann::json& aObj,
const std::string& aKey,
39 std::optional<int> aDefault = std::optional<int>() )
41 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
48static int getInSchUnits(
const nlohmann::json& aObj,
const std::string& aKey,
int aDefault )
50 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
64 []( nlohmann::json& json_array,
const std::shared_ptr<NETCLASS>& nc )
68 nlohmann::json nc_json = {
69 {
"name", nc->GetName().ToUTF8() },
72 {
"line_style", nc->GetLineStyle() },
73 {
"schematic_color", nc->GetSchematicColor() },
74 {
"pcb_color", nc->GetPcbColor() }
78 []( nlohmann::json&
json,
const std::string& aKey,
int aValue )
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 );
114 [](
const nlohmann::json& entry )
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>() );
166 [&]() -> nlohmann::json
168 nlohmann::json ret = nlohmann::json::array();
174 saveNetclass( ret, netclass );
178 [&](
const nlohmann::json& aJson )
180 if( !aJson.is_array() )
185 for(
const nlohmann::json& entry : aJson )
187 if( !entry.is_object() || !entry.contains(
"name" ) )
190 std::shared_ptr<NETCLASS> nc = readNetClass( entry );
201 [&]() -> nlohmann::json
203 nlohmann::json ret = {};
207 std::string key( netname.ToUTF8() );
213 [&](
const nlohmann::json& aJson )
215 if( !aJson.is_object() )
220 for(
const auto& pair : aJson.items() )
222 wxString key( pair.key().c_str(), wxConvUTF8 );
229 [&]() -> nlohmann::json
231 nlohmann::json ret = {};
235 std::string key( netname.ToUTF8() );
236 ret[key] = netclassName;
241 [&](
const nlohmann::json& aJson )
243 if( !aJson.is_object() )
248 for(
const auto& pair : aJson.items() )
250 wxString key( pair.key().c_str(), wxConvUTF8 );
257 [&]() -> nlohmann::json
259 nlohmann::json ret = nlohmann::json::array();
263 nlohmann::json pattern_json = {
264 {
"pattern", matcher->GetPattern().ToUTF8() },
265 {
"netclass", netclassName.ToUTF8() }
268 ret.push_back( pattern_json );
273 [&](
const nlohmann::json& aJson )
275 if( !aJson.is_array() )
280 for(
const nlohmann::json& entry : aJson )
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() )
325 nlohmann::json migrated = nlohmann::json::array();
327 for(
auto& net : netClass.value()[
"nets"].items() )
330 netClass.value()[
"nets"] = migrated;
343 nlohmann::json patterns = nlohmann::json::array();
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() )
355 nlohmann::json pattern_json = {
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 );
397 return getNetclass( it2->second );
401 if( matcher->StartsWith( aNetName ) )
404 return getNetclass( netclassName );
415 return c ==
'_' || c ==
'^' || c ==
'~';
420 std::vector<wxString>* aMemberList )
424 static wxString digits( wxT(
"0123456789" ) );
425 return digits.Contains( c );
428 size_t busLen = aBus.length();
435 int braceNesting = 0;
437 prefix.reserve( busLen );
441 for( ; i < busLen; ++i )
450 else if( aBus[i] ==
'}' )
455 if( aBus[i] ==
' ' || aBus[i] ==
']' )
471 for( ; i < busLen; ++i )
473 if( aBus[i] ==
'.' && i + 1 < busLen && aBus[i+1] ==
'.' )
475 tmp.ToLong( &begin );
493 for( ; i < busLen; ++i )
510 for( ; i < busLen; ++i )
523 if( braceNesting != 0 )
528 else if( begin > end )
529 std::swap( begin, end );
536 for(
long idx = begin; idx <= end; ++idx )
538 wxString str = prefix;
542 aMemberList->emplace_back( str );
551 std::vector<wxString>* aMemberList )
553 size_t groupLen = aGroup.length();
557 int braceNesting = 0;
559 prefix.reserve( groupLen );
563 for( ; i < groupLen; ++i )
565 if( aGroup[i] ==
'{' )
572 else if( aGroup[i] ==
'}' )
577 if( aGroup[i] ==
' ' || aGroup[i] ==
'[' || aGroup[i] ==
']' )
583 if( braceNesting != 0 )
596 for( ; i < groupLen; ++i )
598 if( aGroup[i] ==
'{' )
605 else if( aGroup[i] ==
'}' )
613 if( aMemberList && !tmp.IsEmpty() )
621 if( aGroup[i] ==
' ' || aGroup[i] ==
',' )
623 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::map< wxString, wxString > m_NetClassPatternAssignmentCache
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)
Like a normal param, but with custom getter and setter functions.
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