31 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
53 netclass = nc->second;
60 {
"name", netclass->GetName().ToUTF8() },
61 {
"wire_width",
SchIu2Mils( netclass->GetWireWidth() ) },
62 {
"bus_width",
SchIu2Mils( netclass->GetBusWidth() ) },
63 {
"line_style", netclass->GetLineStyle() },
64 {
"schematic_color", netclass->GetSchematicColor() },
65 {
"pcb_color", netclass->GetPcbColor() }
69 if( netclass->HasClearance() )
70 netclassJson.push_back( {
"clearance", PcbIu2Millimeter( netclass->GetClearance() ) } );
72 if( netclass->HasTrackWidth() )
73 netclassJson.push_back( {
"track_width", PcbIu2Millimeter( netclass->GetTrackWidth() ) } );
75 if( netclass->HasViaDiameter() )
76 netclassJson.push_back( {
"via_diameter", PcbIu2Millimeter( netclass->GetViaDiameter() ) } );
78 if( netclass->HasViaDrill() )
79 netclassJson.push_back( {
"via_drill", PcbIu2Millimeter( netclass->GetViaDrill() ) } );
81 if( netclass->HasuViaDiameter() )
82 netclassJson.push_back( {
"microvia_diameter", PcbIu2Millimeter( netclass->GetuViaDiameter() ) } );
84 if( netclass->HasuViaDrill() )
85 netclassJson.push_back( {
"microvia_drill", PcbIu2Millimeter( netclass->GetuViaDrill() ) } );
87 if( netclass->HasDiffPairWidth() )
88 netclassJson.push_back( {
"diff_pair_width", PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } );
90 if( netclass->HasDiffPairGap() )
91 netclassJson.push_back( {
"diff_pair_gap", PcbIu2Millimeter( netclass->GetDiffPairGap() ) } );
93 if( netclass->HasDiffPairViaGap() )
94 netclassJson.push_back( {
"diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } );
100 for(
const wxString& member : *netclass )
102 if( !member.empty() )
103 membersJson.push_back( member );
106 netclassJson[
"nets"] = membersJson;
109 ret.push_back( netclassJson );
116 if( !aJson.is_array() )
121 NETCLASSPTR netclass;
124 auto getInSchematicUnits =
125 [](
const nlohmann::json& aObj,
const std::string& aKey,
int aDefault )
127 if( aObj.contains( aKey ) && aObj[aKey].is_number() )
128 return SchMils2iu( aObj[aKey].get<double>() );
135 if( !entry.is_object() || !entry.contains(
"name" ) )
138 wxString
name = entry[
"name"];
140 if(
name == defaultClass->GetName() )
141 netclass = defaultClass;
143 netclass = std::make_shared<NETCLASS>(
name );
146 netclass->SetClearance( *value );
149 netclass->SetTrackWidth( *value );
152 netclass->SetViaDiameter( *value );
155 netclass->SetViaDrill( *value );
157 if(
auto value =
getInPcbUnits( entry,
"microvia_diameter" ) )
158 netclass->SetuViaDiameter( *value );
161 netclass->SetuViaDrill( *value );
164 netclass->SetDiffPairWidth( *value );
167 netclass->SetDiffPairGap( *value );
169 if(
auto value =
getInPcbUnits( entry,
"diff_pair_via_gap" ) )
170 netclass->SetDiffPairViaGap( *value );
172 netclass->SetWireWidth( getInSchematicUnits( entry,
"wire_width",
173 netclass->GetWireWidth() ) );
174 netclass->SetBusWidth( getInSchematicUnits( entry,
"bus_width",
175 netclass->GetWireWidth() ) );
177 if( entry.contains(
"line_style" ) && entry[
"line_style"].is_number() )
178 netclass->SetLineStyle( entry[
"line_style"].get<
int>() );
180 if( entry.contains(
"nets" ) && entry[
"nets"].is_array() )
182 for(
const auto& net : entry[
"nets"].items() )
183 netclass->Add( net.value().get<wxString>() );
186 if( entry.contains(
"pcb_color" ) && entry[
"pcb_color"].is_string() )
187 netclass->SetPcbColor( entry[
"pcb_color"].get<
KIGFX::COLOR4D>() );
189 if( entry.contains(
"schematic_color" ) && entry[
"schematic_color"].is_string() )
190 netclass->SetSchematicColor( entry[
"schematic_color"].get<
KIGFX::COLOR4D>() );
192 if( netclass != defaultClass )
195 for(
const wxString& net : *netclass )
210 std::string key( pair.first.ToUTF8() );
211 ret[key] = pair.second;
218 if( !aJson.is_object() )
223 for(
const auto& pair : aJson.items() )
225 wxString key( pair.key().c_str(), wxConvUTF8 );
251 return defaultNetname;
259 return c ==
'_' || c ==
'^';
264 std::vector<wxString>* aMemberList )
268 static wxString digits( wxT(
"0123456789" ) );
269 return digits.Contains( c );
272 size_t busLen = aBus.length();
279 int braceNesting = 0;
281 prefix.reserve( busLen );
285 for( ; i < busLen; ++i )
294 else if( aBus[i] ==
'}' )
299 if( aBus[i] ==
' ' || aBus[i] ==
']' )
315 for( ; i < busLen; ++i )
317 if( aBus[i] ==
'.' && i + 1 < busLen && aBus[i+1] ==
'.' )
319 tmp.ToLong( &begin );
337 for( ; i < busLen; ++i )
354 for( ; i < busLen; ++i )
361 else if( aBus[i] ==
'~' )
371 if( braceNesting != 0 )
376 else if( begin > end )
377 std::swap( begin, end );
384 for(
long idx = begin; idx <= end; ++idx )
386 wxString str = prefix;
390 aMemberList->emplace_back( str );
399 std::vector<wxString>* aMemberList )
401 size_t groupLen = aGroup.length();
406 int braceNesting = 0;
408 prefix.reserve( groupLen );
412 for( ; i < groupLen; ++i )
414 if( aGroup[i] ==
'{' )
421 else if( aGroup[i] ==
'}' )
426 if( aGroup[i] ==
' ' || aGroup[i] ==
'[' || aGroup[i] ==
']' )
432 if( braceNesting != 0 )
445 for( ; i < groupLen; ++i )
447 if( aGroup[i] ==
'{' )
454 else if( aGroup[i] ==
'}' )
462 if( aMemberList && !tmp.IsEmpty() )
470 if( aGroup[i] ==
' ' || aGroup[i] ==
',' )
472 if( aMemberList && !tmp.IsEmpty() )
488 std::map<wxString, wxString> baseList;
490 if( aRebuildFromScratch )
492 for(
const std::pair<const wxString, NETCLASSPTR>& netclass :
m_NetClasses )
494 for(
const wxString& net : *netclass.second )
495 baseList[ net ] = netclass.second->GetName();
505 for(
const auto& ii : baseList )
511 std::vector<wxString> members;
515 prefix = wxEmptyString;
519 if( !prefix.IsEmpty() )
520 prefix += wxT(
"." );
523 for( wxString& member : members )
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.
NETCLASS_MAP::const_iterator const_iterator
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
constexpr int PcbMillimeter2iu(double mm)
static bool ParseBusGroup(wxString aGroup, wxString *name, std::vector< wxString > *aMemberList)
Parses a bus group label into the name and a list of components.
static const char Default[]
the name of the default NETCLASS
void ResolveNetClassAssignments(bool aRebuildFromScratch=false)
Explodes the list of netclass assignments to include atomic members of composite labels (buses).
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
constexpr double SchIu2Mils(int iu)
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...
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which ar...
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parses a bus vector (e.g.
unsigned GetCount() const
NETCLASSPTR GetDefault() const
static bool isSuperSub(wxChar c)
static OPT< int > getInPcbUnits(const nlohmann::json &aObj, const std::string &aKey, OPT< int > aDefault=OPT< int >())
constexpr int SchMils2iu(int mils)
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)
A color representation with 4 components: red, green, blue, alpha.