22 #include <nlohmann/json.hpp> 41 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
42 return PcbMm2iu( aObj[aKey].get<double>() );
50 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
80 {
"name", nc->GetName().ToUTF8() },
81 {
"wire_width",
SchIu2Mils( nc->GetWireWidth() ) },
82 {
"bus_width",
SchIu2Mils( nc->GetBusWidth() ) },
83 {
"line_style", nc->GetLineStyle() },
84 {
"schematic_color", nc->GetSchematicColor() },
85 {
"pcb_color", nc->GetPcbColor() }
94 if( nc->HasClearance() )
95 saveInPcbUnits( nc_json,
"clearance", nc->GetClearance() );
97 if( nc->HasTrackWidth() )
98 saveInPcbUnits( nc_json,
"track_width", nc->GetTrackWidth() );
100 if( nc->HasViaDiameter() )
101 saveInPcbUnits( nc_json,
"via_diameter", nc->GetViaDiameter() );
103 if( nc->HasViaDrill() )
104 saveInPcbUnits( nc_json,
"via_drill", nc->GetViaDrill() );
106 if( nc->HasuViaDiameter() )
107 saveInPcbUnits( nc_json,
"microvia_diameter", nc->GetuViaDiameter() );
109 if( nc->HasuViaDrill() )
110 saveInPcbUnits( nc_json,
"microvia_drill", nc->GetuViaDrill() );
112 if( nc->HasDiffPairWidth() )
113 saveInPcbUnits( nc_json,
"diff_pair_width", nc->GetDiffPairWidth() );
115 if( nc->HasDiffPairGap() )
116 saveInPcbUnits( nc_json,
"diff_pair_gap", nc->GetDiffPairGap() );
118 if( nc->HasDiffPairViaGap() )
119 saveInPcbUnits( nc_json,
"diff_pair_via_gap", nc->GetDiffPairViaGap() );
125 for(
const wxString& member : *nc )
127 if( !member.empty() )
128 membersJson.push_back( member );
131 nc_json[
"nets"] = membersJson;
134 ret.push_back( nc_json );
141 if( !aJson.is_array() )
151 if( !entry.is_object() || !entry.contains(
"name" ) )
154 wxString
name = entry[
"name"];
156 if(
name == defaultClass->GetName() )
159 nc = std::make_shared<NETCLASS>(
name );
162 nc->SetClearance( *value );
165 nc->SetTrackWidth( *value );
168 nc->SetViaDiameter( *value );
171 nc->SetViaDrill( *value );
173 if(
auto value =
getInPcbUnits( entry,
"microvia_diameter" ) )
174 nc->SetuViaDiameter( *value );
177 nc->SetuViaDrill( *value );
180 nc->SetDiffPairWidth( *value );
183 nc->SetDiffPairGap( *value );
185 if(
auto value =
getInPcbUnits( entry,
"diff_pair_via_gap" ) )
186 nc->SetDiffPairViaGap( *value );
188 nc->SetWireWidth(
getInSchUnits( entry,
"wire_width", nc->GetWireWidth() ) );
189 nc->SetBusWidth(
getInSchUnits( entry,
"bus_width", nc->GetBusWidth() ) );
191 if( entry.contains(
"line_style" ) && entry[
"line_style"].is_number() )
192 nc->SetLineStyle( entry[
"line_style"].get<
int>() );
194 if( entry.contains(
"nets" ) && entry[
"nets"].is_array() )
196 for(
const auto& net : entry[
"nets"].items() )
198 wxString netname = net.value().get<wxString>();
207 std::vector<wxString> members;
219 if( entry.contains(
"pcb_color" ) && entry[
"pcb_color"].is_string() )
222 if( entry.contains(
"schematic_color" )
223 && entry[
"schematic_color"].is_string() )
225 nc->SetSchematicColor( entry[
"schematic_color"].get<KIGFX::COLOR4D>() );
228 if( nc != defaultClass )
231 for(
const wxString& net : *nc )
244 std::string key( pair.first.ToUTF8() );
245 ret[key] = pair.second;
252 if( !aJson.is_object() )
257 for(
const auto& pair : aJson.items() )
259 wxString key( pair.key().c_str(), wxConvUTF8 );
284 for(
auto& netClass :
m_internals->At(
"classes" ).items() )
286 if( netClass.value().contains(
"nets" ) && netClass.value()[
"nets"].is_array() )
290 for(
auto& net : netClass.value()[
"nets"].items() )
293 netClass.value()[
"nets"] = migrated;
309 return defaultNetname;
317 return c ==
'_' || c ==
'^' || c ==
'~';
322 std::vector<wxString>* aMemberList )
326 static wxString digits( wxT(
"0123456789" ) );
327 return digits.Contains( c );
330 size_t busLen = aBus.length();
337 int braceNesting = 0;
339 prefix.reserve( busLen );
343 for( ; i < busLen; ++i )
352 else if( aBus[i] ==
'}' )
357 if( aBus[i] ==
' ' || aBus[i] ==
']' )
373 for( ; i < busLen; ++i )
375 if( aBus[i] ==
'.' && i + 1 < busLen && aBus[i+1] ==
'.' )
377 tmp.ToLong( &begin );
395 for( ; i < busLen; ++i )
412 for( ; i < busLen; ++i )
425 if( braceNesting != 0 )
430 else if( begin > end )
431 std::swap( begin, end );
438 for(
long idx = begin; idx <= end; ++idx )
440 wxString str = prefix;
444 aMemberList->emplace_back( str );
453 std::vector<wxString>* aMemberList )
455 size_t groupLen = aGroup.length();
460 int braceNesting = 0;
462 prefix.reserve( groupLen );
466 for( ; i < groupLen; ++i )
468 if( aGroup[i] ==
'{' )
475 else if( aGroup[i] ==
'}' )
480 if( aGroup[i] ==
' ' || aGroup[i] ==
'[' || aGroup[i] ==
']' )
486 if( braceNesting != 0 )
499 for( ; i < groupLen; ++i )
501 if( aGroup[i] ==
'{' )
508 else if( aGroup[i] ==
'}' )
516 if( aMemberList && !tmp.IsEmpty() )
524 if( aGroup[i] ==
' ' || aGroup[i] ==
',' )
526 if( aMemberList && !tmp.IsEmpty() )
544 for(
const std::pair<const wxString, NETCLASSPTR>& netclass :
m_NetClasses )
546 for(
const wxString& net : *netclass.second )
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
static int getInSchUnits(const nlohmann::json &aObj, const std::string &aKey, int aDefault)
std::map< wxString, wxString > m_NetClassAssignments
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
const wxString & GetNetclassName(const wxString &aNetName) const
std::map< wxString, KIGFX::COLOR4D > m_PcbNetColors
A map of fully-qualified net names to colors used in the board context.
constexpr double PcbIu2mm(int iu)
void RebuildNetClassAssignments()
Rebuild netclass assignments from the netclass membership lists.
NETCLASS_MAP::const_iterator const_iterator
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.
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
static const char Default[]
the name of the default NETCLASS
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
constexpr double SchIu2Mils(int iu)
wxString UnescapeString(const wxString &aSource)
bool Add(const NETCLASSPTR &aNetclass)
Add aNetclass and puts it into this NETCLASSES container.
void Clear()
Destroy any contained NETCLASS instances except the default one, and clears any members from the defa...
static bool isSuperSubOverbar(wxChar c)
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
constexpr int SchMils2iu(double mils)
unsigned GetCount() const
NETCLASSPTR GetDefault() const
static OPT< int > getInPcbUnits(const nlohmann::json &aObj, const std::string &aKey, OPT< int > aDefault=OPT< int >())
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
const int netSettingsSchemaVersion
NET_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
int m_schemaVersion
Version of this settings schema.
constexpr int PcbMm2iu(double mm)
A color representation with 4 components: red, green, blue, alpha.