2020-05-31 21:42:04 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 CERN
|
2021-06-08 17:47:06 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-05-31 21:42:04 +00:00
|
|
|
* @author Jon Evans <jon@craftyjon.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-06-04 03:52:50 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2021-06-14 23:16:34 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project/net_settings.h>
|
|
|
|
#include <settings/parameters.h>
|
2021-06-14 23:16:34 +00:00
|
|
|
#include <settings/json_settings_internals.h>
|
2020-07-08 18:29:16 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-07-08 18:29:16 +00:00
|
|
|
#include <convert_to_biu.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
|
2021-06-14 23:16:34 +00:00
|
|
|
// const int netSettingsSchemaVersion = 0;
|
|
|
|
const int netSettingsSchemaVersion = 1; // new overbar syntax
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
|
|
|
|
static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey,
|
|
|
|
OPT<int> aDefault = OPT<int>() )
|
2020-10-06 09:22:54 +00:00
|
|
|
{
|
2020-10-08 02:00:02 +00:00
|
|
|
if( aObj.contains( aKey ) && aObj[aKey].is_number() )
|
2020-10-06 09:22:54 +00:00
|
|
|
return PcbMillimeter2iu( aObj[aKey].get<double>() );
|
|
|
|
else
|
|
|
|
return aDefault;
|
|
|
|
};
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
|
|
|
|
NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ),
|
|
|
|
m_NetClasses()
|
|
|
|
{
|
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "classes",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = nlohmann::json::array();
|
|
|
|
|
|
|
|
NETCLASSPTR netclass = m_NetClasses.GetDefault();
|
|
|
|
NETCLASSES::const_iterator nc = m_NetClasses.begin();
|
|
|
|
|
|
|
|
for( unsigned int idx = 0; idx <= m_NetClasses.GetCount(); idx++ )
|
|
|
|
{
|
|
|
|
if( idx > 0 )
|
|
|
|
{
|
|
|
|
netclass = nc->second;
|
|
|
|
++nc;
|
|
|
|
}
|
|
|
|
|
2020-07-08 18:29:16 +00:00
|
|
|
// Note: we're in common/, but we do happen to know which of these fields
|
|
|
|
// are used in which units system.
|
2020-07-27 21:14:44 +00:00
|
|
|
nlohmann::json netclassJson = {
|
2020-07-08 18:29:16 +00:00
|
|
|
{ "name", netclass->GetName().ToUTF8() },
|
2020-07-27 21:14:44 +00:00
|
|
|
{ "wire_width", SchIu2Mils( netclass->GetWireWidth() ) },
|
|
|
|
{ "bus_width", SchIu2Mils( netclass->GetBusWidth() ) },
|
2020-09-03 17:54:14 +00:00
|
|
|
{ "line_style", netclass->GetLineStyle() },
|
|
|
|
{ "schematic_color", netclass->GetSchematicColor() },
|
|
|
|
{ "pcb_color", netclass->GetPcbColor() }
|
2020-05-31 21:42:04 +00:00
|
|
|
};
|
|
|
|
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasClearance() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "clearance",
|
|
|
|
PcbIu2Millimeter( netclass->GetClearance() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasTrackWidth() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "track_width",
|
|
|
|
PcbIu2Millimeter( netclass->GetTrackWidth() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasViaDiameter() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "via_diameter",
|
|
|
|
PcbIu2Millimeter( netclass->GetViaDiameter() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasViaDrill() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "via_drill",
|
|
|
|
PcbIu2Millimeter( netclass->GetViaDrill() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasuViaDiameter() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "microvia_diameter",
|
|
|
|
PcbIu2Millimeter( netclass->GetuViaDiameter() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasuViaDrill() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "microvia_drill",
|
|
|
|
PcbIu2Millimeter( netclass->GetuViaDrill() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasDiffPairWidth() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "diff_pair_width",
|
|
|
|
PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasDiffPairGap() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "diff_pair_gap",
|
|
|
|
PcbIu2Millimeter( netclass->GetDiffPairGap() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
|
|
|
if( netclass->HasDiffPairViaGap() )
|
2021-06-08 17:47:06 +00:00
|
|
|
netclassJson.push_back( { "diff_pair_via_gap",
|
|
|
|
PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2020-09-03 17:54:14 +00:00
|
|
|
if( idx > 0 ) // No need to store members of Default netclass
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
|
|
|
nlohmann::json membersJson = nlohmann::json::array();
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-09-03 17:54:14 +00:00
|
|
|
for( const wxString& member : *netclass )
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
2020-09-03 17:54:14 +00:00
|
|
|
if( !member.empty() )
|
|
|
|
membersJson.push_back( member );
|
2020-07-06 10:51:04 +00:00
|
|
|
}
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-07-27 21:14:44 +00:00
|
|
|
netclassJson["nets"] = membersJson;
|
2020-07-06 10:51:04 +00:00
|
|
|
}
|
2020-07-13 23:53:03 +00:00
|
|
|
|
2020-07-27 21:14:44 +00:00
|
|
|
ret.push_back( netclassJson );
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_array() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_NetClasses.Clear();
|
2020-07-06 10:51:04 +00:00
|
|
|
m_NetClassAssignments.clear();
|
2020-05-31 21:42:04 +00:00
|
|
|
NETCLASSPTR netclass;
|
|
|
|
NETCLASSPTR defaultClass = m_NetClasses.GetDefault();
|
|
|
|
|
2020-07-27 21:14:44 +00:00
|
|
|
auto getInSchematicUnits =
|
|
|
|
[]( const nlohmann::json& aObj, const std::string& aKey, int aDefault )
|
|
|
|
{
|
2020-10-08 02:00:02 +00:00
|
|
|
if( aObj.contains( aKey ) && aObj[aKey].is_number() )
|
2020-07-27 21:14:44 +00:00
|
|
|
return SchMils2iu( aObj[aKey].get<double>() );
|
|
|
|
else
|
|
|
|
return aDefault;
|
|
|
|
};
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
for( const nlohmann::json& entry : aJson )
|
|
|
|
{
|
|
|
|
if( !entry.is_object() || !entry.contains( "name" ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString name = entry["name"];
|
|
|
|
|
|
|
|
if( name == defaultClass->GetName() )
|
|
|
|
netclass = defaultClass;
|
|
|
|
else
|
|
|
|
netclass = std::make_shared<NETCLASS>( name );
|
|
|
|
|
2020-10-06 09:22:54 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "clearance" ) )
|
|
|
|
netclass->SetClearance( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "track_width" ) )
|
|
|
|
netclass->SetTrackWidth( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "via_diameter" ) )
|
|
|
|
netclass->SetViaDiameter( *value );
|
|
|
|
|
2020-10-13 08:53:53 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "via_drill" ) )
|
|
|
|
netclass->SetViaDrill( *value );
|
|
|
|
|
2020-10-06 09:22:54 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "microvia_diameter" ) )
|
|
|
|
netclass->SetuViaDiameter( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "microvia_drill" ) )
|
|
|
|
netclass->SetuViaDrill( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "diff_pair_width" ) )
|
|
|
|
netclass->SetDiffPairWidth( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "diff_pair_gap" ) )
|
|
|
|
netclass->SetDiffPairGap( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "diff_pair_via_gap" ) )
|
|
|
|
netclass->SetDiffPairViaGap( *value );
|
|
|
|
|
2020-07-27 21:14:44 +00:00
|
|
|
netclass->SetWireWidth( getInSchematicUnits( entry, "wire_width",
|
|
|
|
netclass->GetWireWidth() ) );
|
|
|
|
netclass->SetBusWidth( getInSchematicUnits( entry, "bus_width",
|
|
|
|
netclass->GetWireWidth() ) );
|
|
|
|
|
|
|
|
if( entry.contains( "line_style" ) && entry["line_style"].is_number() )
|
|
|
|
netclass->SetLineStyle( entry["line_style"].get<int>() );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-07-03 23:28:24 +00:00
|
|
|
if( entry.contains( "nets" ) && entry["nets"].is_array() )
|
|
|
|
{
|
|
|
|
for( const auto& net : entry["nets"].items() )
|
|
|
|
netclass->Add( net.value().get<wxString>() );
|
|
|
|
}
|
|
|
|
|
2020-07-08 02:21:45 +00:00
|
|
|
if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() )
|
|
|
|
netclass->SetPcbColor( entry["pcb_color"].get<KIGFX::COLOR4D>() );
|
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
if( entry.contains( "schematic_color" )
|
|
|
|
&& entry["schematic_color"].is_string() )
|
|
|
|
netclass->SetSchematicColor(
|
|
|
|
entry["schematic_color"].get<KIGFX::COLOR4D>() );
|
2020-07-27 21:14:44 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
if( netclass != defaultClass )
|
|
|
|
m_NetClasses.Add( netclass );
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
for( const wxString& net : *netclass )
|
|
|
|
m_NetClassAssignments[ net ] = netclass->GetName();
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
ResolveNetClassAssignments();
|
|
|
|
},
|
|
|
|
{} ) );
|
2020-07-08 02:21:45 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "net_colors",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = {};
|
|
|
|
|
|
|
|
for( const auto& pair : m_PcbNetColors )
|
|
|
|
{
|
|
|
|
std::string key( pair.first.ToUTF8() );
|
|
|
|
ret[key] = pair.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_object() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_PcbNetColors.clear();
|
|
|
|
|
|
|
|
for( const auto& pair : aJson.items() )
|
|
|
|
{
|
|
|
|
wxString key( pair.key().c_str(), wxConvUTF8 );
|
|
|
|
m_PcbNetColors[key] = pair.value().get<KIGFX::COLOR4D>();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{} ) );
|
2021-06-14 23:16:34 +00:00
|
|
|
|
|
|
|
registerMigration( 0, 1, std::bind( &NET_SETTINGS::migrateSchema0to1, this ) );
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NET_SETTINGS::~NET_SETTINGS()
|
|
|
|
{
|
|
|
|
// Release early before destroying members
|
|
|
|
if( m_parent )
|
|
|
|
{
|
|
|
|
m_parent->ReleaseNestedSettings( this );
|
|
|
|
m_parent = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
|
2021-06-14 23:16:34 +00:00
|
|
|
bool NET_SETTINGS::migrateSchema0to1()
|
|
|
|
{
|
|
|
|
if( m_internals->contains( "classes" ) && m_internals->At( "classes" ).is_array() )
|
|
|
|
{
|
|
|
|
for( auto& netClass : m_internals->At( "classes" ).items() )
|
|
|
|
{
|
|
|
|
if( netClass.value().contains( "nets" ) && netClass.value()["nets"].is_array() )
|
|
|
|
{
|
|
|
|
nlohmann::json migrated = nlohmann::json::array();
|
|
|
|
|
|
|
|
for( auto& net : netClass.value()["nets"].items() )
|
|
|
|
migrated.push_back( ConvertToNewOverbarNotation( net.value().get<wxString>() ) );
|
|
|
|
|
|
|
|
netClass.value()["nets"] = migrated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
const wxString& NET_SETTINGS::GetNetclassName( const wxString& aNetName ) const
|
|
|
|
{
|
|
|
|
static wxString defaultNetname = NETCLASS::Default;
|
|
|
|
|
|
|
|
auto it = m_NetClassAssignments.find( aNetName );
|
|
|
|
|
|
|
|
if( it == m_NetClassAssignments.end() )
|
|
|
|
return defaultNetname;
|
|
|
|
else
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-05 13:52:58 +00:00
|
|
|
static bool isSuperSubOverbar( wxChar c )
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
2021-06-05 13:52:58 +00:00
|
|
|
return c == '_' || c == '^' || c == '~';
|
2020-10-07 14:40:12 +00:00
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool NET_SETTINGS::ParseBusVector( const wxString& aBus, wxString* aName,
|
|
|
|
std::vector<wxString>* aMemberList )
|
|
|
|
{
|
|
|
|
auto isDigit = []( wxChar c )
|
|
|
|
{
|
|
|
|
static wxString digits( wxT( "0123456789" ) );
|
|
|
|
return digits.Contains( c );
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t busLen = aBus.length();
|
|
|
|
size_t i = 0;
|
|
|
|
wxString prefix;
|
|
|
|
wxString suffix;
|
|
|
|
wxString tmp;
|
|
|
|
long begin = 0;
|
|
|
|
long end = 0;
|
|
|
|
int braceNesting = 0;
|
|
|
|
|
|
|
|
prefix.reserve( busLen );
|
|
|
|
|
|
|
|
// Parse prefix
|
|
|
|
//
|
|
|
|
for( ; i < busLen; ++i )
|
|
|
|
{
|
|
|
|
if( aBus[i] == '{' )
|
|
|
|
{
|
2021-06-05 13:52:58 +00:00
|
|
|
if( i > 0 && isSuperSubOverbar( aBus[i-1] ) )
|
2020-07-06 10:51:04 +00:00
|
|
|
braceNesting++;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( aBus[i] == '}' )
|
|
|
|
{
|
|
|
|
braceNesting--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aBus[i] == ' ' || aBus[i] == ']' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aBus[i] == '[' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
prefix += aBus[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse start number
|
|
|
|
//
|
|
|
|
i++; // '[' character
|
|
|
|
|
|
|
|
if( i >= busLen )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( ; i < busLen; ++i )
|
|
|
|
{
|
|
|
|
if( aBus[i] == '.' && i + 1 < busLen && aBus[i+1] == '.' )
|
|
|
|
{
|
|
|
|
tmp.ToLong( &begin );
|
|
|
|
i += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !isDigit( aBus[i] ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tmp += aBus[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse end number
|
|
|
|
//
|
|
|
|
tmp = wxEmptyString;
|
|
|
|
|
|
|
|
if( i >= busLen )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( ; i < busLen; ++i )
|
|
|
|
{
|
|
|
|
if( aBus[i] == ']' )
|
|
|
|
{
|
|
|
|
tmp.ToLong( &end );
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !isDigit( aBus[i] ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tmp += aBus[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse suffix
|
|
|
|
//
|
|
|
|
for( ; i < busLen; ++i )
|
|
|
|
{
|
|
|
|
if( aBus[i] == '}' )
|
|
|
|
{
|
|
|
|
braceNesting--;
|
|
|
|
suffix += aBus[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( braceNesting != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( begin == end )
|
|
|
|
return false;
|
|
|
|
else if( begin > end )
|
|
|
|
std::swap( begin, end );
|
|
|
|
|
|
|
|
if( aName )
|
|
|
|
*aName = prefix;
|
|
|
|
|
|
|
|
if( aMemberList )
|
|
|
|
{
|
|
|
|
for( long idx = begin; idx <= end; ++idx )
|
|
|
|
{
|
|
|
|
wxString str = prefix;
|
|
|
|
str << idx;
|
|
|
|
str << suffix;
|
|
|
|
|
|
|
|
aMemberList->emplace_back( str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
bool NET_SETTINGS::ParseBusGroup( const wxString& aGroup, wxString* aName,
|
2020-07-06 10:51:04 +00:00
|
|
|
std::vector<wxString>* aMemberList )
|
|
|
|
{
|
|
|
|
size_t groupLen = aGroup.length();
|
|
|
|
size_t i = 0;
|
|
|
|
wxString prefix;
|
|
|
|
wxString suffix;
|
|
|
|
wxString tmp;
|
|
|
|
int braceNesting = 0;
|
|
|
|
|
|
|
|
prefix.reserve( groupLen );
|
|
|
|
|
|
|
|
// Parse prefix
|
|
|
|
//
|
|
|
|
for( ; i < groupLen; ++i )
|
|
|
|
{
|
|
|
|
if( aGroup[i] == '{' )
|
|
|
|
{
|
2021-06-05 13:52:58 +00:00
|
|
|
if( i > 0 && isSuperSubOverbar( aGroup[i-1] ) )
|
2020-07-06 10:51:04 +00:00
|
|
|
braceNesting++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( aGroup[i] == '}' )
|
|
|
|
{
|
|
|
|
braceNesting--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aGroup[i] == ' ' || aGroup[i] == '[' || aGroup[i] == ']' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
prefix += aGroup[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( braceNesting != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aName )
|
|
|
|
*aName = prefix;
|
|
|
|
|
|
|
|
// Parse members
|
|
|
|
//
|
|
|
|
i++; // '{' character
|
|
|
|
|
|
|
|
if( i >= groupLen )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( ; i < groupLen; ++i )
|
|
|
|
{
|
|
|
|
if( aGroup[i] == '{' )
|
|
|
|
{
|
2021-06-05 13:52:58 +00:00
|
|
|
if( i > 0 && isSuperSubOverbar( aGroup[i-1] ) )
|
2020-07-06 10:51:04 +00:00
|
|
|
braceNesting++;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( aGroup[i] == '}' )
|
|
|
|
{
|
|
|
|
if( braceNesting )
|
2020-12-20 18:01:34 +00:00
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
braceNesting--;
|
2020-12-20 18:01:34 +00:00
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
else
|
|
|
|
{
|
2021-01-17 16:05:09 +00:00
|
|
|
if( aMemberList && !tmp.IsEmpty() )
|
2020-12-20 18:01:34 +00:00
|
|
|
aMemberList->push_back( EscapeString( tmp, CTX_NETNAME ) );
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-17 16:05:09 +00:00
|
|
|
// Commas aren't strictly legal, but we can be pretty sure what the author had in mind.
|
|
|
|
if( aGroup[i] == ' ' || aGroup[i] == ',' )
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
2021-01-17 16:05:09 +00:00
|
|
|
if( aMemberList && !tmp.IsEmpty() )
|
|
|
|
aMemberList->push_back( EscapeString( tmp, CTX_NETNAME ) );
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
tmp.Clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += aGroup[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
void NET_SETTINGS::ResolveNetClassAssignments( bool aRebuildFromScratch )
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
2020-08-08 14:14:41 +00:00
|
|
|
std::map<wxString, wxString> baseList;
|
2020-07-19 21:22:49 +00:00
|
|
|
|
|
|
|
if( aRebuildFromScratch )
|
|
|
|
{
|
|
|
|
for( const std::pair<const wxString, NETCLASSPTR>& netclass : m_NetClasses )
|
|
|
|
{
|
|
|
|
for( const wxString& net : *netclass.second )
|
|
|
|
baseList[ net ] = netclass.second->GetName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
baseList = m_NetClassAssignments;
|
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
m_NetClassAssignments.clear();
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
for( const auto& ii : baseList )
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
|
|
|
m_NetClassAssignments[ ii.first ] = ii.second;
|
|
|
|
|
|
|
|
wxString unescaped = UnescapeString( ii.first );
|
|
|
|
wxString prefix;
|
|
|
|
std::vector<wxString> members;
|
|
|
|
|
|
|
|
if( ParseBusVector( unescaped, &prefix, &members ) )
|
|
|
|
{
|
|
|
|
prefix = wxEmptyString;
|
|
|
|
}
|
|
|
|
else if( ParseBusGroup( unescaped, &prefix, &members ) )
|
|
|
|
{
|
|
|
|
if( !prefix.IsEmpty() )
|
|
|
|
prefix += wxT( "." );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( wxString& member : members )
|
|
|
|
m_NetClassAssignments[ prefix + member ] = ii.second;
|
|
|
|
}
|
2020-07-08 02:21:45 +00:00
|
|
|
}
|