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
|
2023-04-14 22:34:14 +00:00
|
|
|
* Copyright (C) 2021-2023 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>
|
|
|
|
|
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>
|
2022-09-17 01:07:36 +00:00
|
|
|
#include <base_units.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;
|
2021-09-17 20:25:05 +00:00
|
|
|
// const int netSettingsSchemaVersion = 1; // new overbar syntax
|
2022-08-14 11:03:18 +00:00
|
|
|
// const int netSettingsSchemaVersion = 2; // exclude buses from netclass members
|
|
|
|
const int netSettingsSchemaVersion = 3; // netclass assignment patterns
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
static std::optional<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey,
|
|
|
|
std::optional<int> aDefault = std::optional<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() )
|
2022-09-16 11:33:56 +00:00
|
|
|
return pcbIUScale.mmToIU( aObj[aKey].get<double>() );
|
2021-08-01 18:32:41 +00:00
|
|
|
else
|
|
|
|
return aDefault;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int getInSchUnits( const nlohmann::json& aObj, const std::string& aKey, int aDefault )
|
|
|
|
{
|
|
|
|
if( aObj.contains( aKey ) && aObj[aKey].is_number() )
|
2022-09-16 23:08:06 +00:00
|
|
|
return schIUScale.MilsToIU( aObj[aKey].get<double>() );
|
2020-10-06 09:22:54 +00:00
|
|
|
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 ) :
|
2022-08-14 11:03:18 +00:00
|
|
|
NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath )
|
2020-05-31 21:42:04 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
m_DefaultNetClass = std::make_shared<NETCLASS>( NETCLASS::Default );
|
|
|
|
m_DefaultNetClass->SetDescription( _( "This is the default net class." ) );
|
|
|
|
|
|
|
|
auto saveNetclass =
|
|
|
|
[]( nlohmann::json& json_array, const std::shared_ptr<NETCLASS>& nc )
|
2020-05-31 21:42:04 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
// Note: we're in common/, but we do happen to know which of these
|
|
|
|
// fields are used in which units system.
|
|
|
|
nlohmann::json nc_json = {
|
|
|
|
{ "name", nc->GetName().ToUTF8() },
|
2022-09-16 23:08:06 +00:00
|
|
|
{ "wire_width", schIUScale.IUToMils( nc->GetWireWidth() ) },
|
|
|
|
{ "bus_width", schIUScale.IUToMils( nc->GetBusWidth() ) },
|
2022-08-14 11:03:18 +00:00
|
|
|
{ "line_style", nc->GetLineStyle() },
|
|
|
|
{ "schematic_color", nc->GetSchematicColor() },
|
|
|
|
{ "pcb_color", nc->GetPcbColor() }
|
|
|
|
};
|
|
|
|
|
|
|
|
auto saveInPcbUnits =
|
|
|
|
[]( nlohmann::json& json, const std::string& aKey, int aValue )
|
|
|
|
{
|
2022-09-16 11:33:56 +00:00
|
|
|
json.push_back( { aKey, pcbIUScale.IUTomm( aValue ) } );
|
2022-08-14 11:03:18 +00:00
|
|
|
};
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasClearance() )
|
|
|
|
saveInPcbUnits( nc_json, "clearance", nc->GetClearance() );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasTrackWidth() )
|
|
|
|
saveInPcbUnits( nc_json, "track_width", nc->GetTrackWidth() );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasViaDiameter() )
|
|
|
|
saveInPcbUnits( nc_json, "via_diameter", nc->GetViaDiameter() );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasViaDrill() )
|
|
|
|
saveInPcbUnits( nc_json, "via_drill", nc->GetViaDrill() );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasuViaDiameter() )
|
|
|
|
saveInPcbUnits( nc_json, "microvia_diameter", nc->GetuViaDiameter() );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasuViaDrill() )
|
|
|
|
saveInPcbUnits( nc_json, "microvia_drill", nc->GetuViaDrill() );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasDiffPairWidth() )
|
|
|
|
saveInPcbUnits( nc_json, "diff_pair_width", nc->GetDiffPairWidth() );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasDiffPairGap() )
|
|
|
|
saveInPcbUnits( nc_json, "diff_pair_gap", nc->GetDiffPairGap() );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->HasDiffPairViaGap() )
|
|
|
|
saveInPcbUnits( nc_json, "diff_pair_via_gap", nc->GetDiffPairViaGap() );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
json_array.push_back( nc_json );
|
|
|
|
};
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto readNetClass =
|
|
|
|
[]( const nlohmann::json& entry )
|
|
|
|
{
|
|
|
|
wxString name = entry["name"];
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>( name );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "clearance" ) )
|
|
|
|
nc->SetClearance( *value );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "track_width" ) )
|
|
|
|
nc->SetTrackWidth( *value );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "via_diameter" ) )
|
|
|
|
nc->SetViaDiameter( *value );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "via_drill" ) )
|
|
|
|
nc->SetViaDrill( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "microvia_diameter" ) )
|
|
|
|
nc->SetuViaDiameter( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "microvia_drill" ) )
|
|
|
|
nc->SetuViaDrill( *value );
|
2020-07-13 23:53:03 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( auto value = getInPcbUnits( entry, "diff_pair_width" ) )
|
|
|
|
nc->SetDiffPairWidth( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "diff_pair_gap" ) )
|
|
|
|
nc->SetDiffPairGap( *value );
|
|
|
|
|
|
|
|
if( auto value = getInPcbUnits( entry, "diff_pair_via_gap" ) )
|
|
|
|
nc->SetDiffPairViaGap( *value );
|
|
|
|
|
|
|
|
nc->SetWireWidth( getInSchUnits( entry, "wire_width", nc->GetWireWidth() ) );
|
|
|
|
nc->SetBusWidth( getInSchUnits( entry, "bus_width", nc->GetBusWidth() ) );
|
|
|
|
|
|
|
|
if( entry.contains( "line_style" ) && entry["line_style"].is_number() )
|
|
|
|
nc->SetLineStyle( entry["line_style"].get<int>() );
|
|
|
|
|
|
|
|
if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() )
|
|
|
|
nc->SetPcbColor( entry["pcb_color"].get<KIGFX::COLOR4D>() );
|
|
|
|
|
|
|
|
if( entry.contains( "schematic_color" )
|
|
|
|
&& entry["schematic_color"].is_string() )
|
|
|
|
{
|
|
|
|
nc->SetSchematicColor( entry["schematic_color"].get<KIGFX::COLOR4D>() );
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
return nc;
|
|
|
|
};
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "classes",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = nlohmann::json::array();
|
|
|
|
|
|
|
|
if( m_DefaultNetClass )
|
|
|
|
saveNetclass( ret, m_DefaultNetClass );
|
|
|
|
|
|
|
|
for( const auto& [ name, netclass ] : m_NetClasses )
|
|
|
|
saveNetclass( ret, netclass );
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_array() )
|
|
|
|
return;
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_NetClasses.clear();
|
2020-05-31 21:42:04 +00:00
|
|
|
|
|
|
|
for( const nlohmann::json& entry : aJson )
|
|
|
|
{
|
|
|
|
if( !entry.is_object() || !entry.contains( "name" ) )
|
|
|
|
continue;
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NETCLASS> nc = readNetClass( entry );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( nc->GetName() == NETCLASS::Default )
|
|
|
|
m_DefaultNetClass = nc;
|
2020-05-31 21:42:04 +00:00
|
|
|
else
|
2022-08-14 11:03:18 +00:00
|
|
|
m_NetClasses[ nc->GetName() ] = nc;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{} ) );
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "net_colors",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = {};
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ netname, color ] : m_NetColorAssignments )
|
|
|
|
{
|
|
|
|
std::string key( netname.ToUTF8() );
|
2023-12-18 17:19:15 +00:00
|
|
|
ret[ std::move( key ) ] = color;
|
2022-08-14 11:03:18 +00:00
|
|
|
}
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_object() )
|
|
|
|
return;
|
2020-10-06 09:22:54 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_NetColorAssignments.clear();
|
2020-07-27 21:14:44 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& pair : aJson.items() )
|
|
|
|
{
|
|
|
|
wxString key( pair.key().c_str(), wxConvUTF8 );
|
2023-12-18 17:19:15 +00:00
|
|
|
m_NetColorAssignments[ std::move( key ) ] = pair.value().get<KIGFX::COLOR4D>();
|
2022-08-14 11:03:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{} ) );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "netclass_assignments",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = {};
|
2020-07-03 23:28:24 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ netname, netclassName ] : m_NetClassLabelAssignments )
|
|
|
|
{
|
|
|
|
std::string key( netname.ToUTF8() );
|
2023-12-18 17:19:15 +00:00
|
|
|
ret[ std::move( key ) ] = netclassName;
|
2022-08-14 11:03:18 +00:00
|
|
|
}
|
2020-07-08 02:21:45 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_object() )
|
|
|
|
return;
|
2020-07-27 21:14:44 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_NetClassLabelAssignments.clear();
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& pair : aJson.items() )
|
|
|
|
{
|
|
|
|
wxString key( pair.key().c_str(), wxConvUTF8 );
|
2023-12-18 17:19:15 +00:00
|
|
|
m_NetClassLabelAssignments[ std::move( key ) ] = pair.value().get<wxString>();
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
},
|
|
|
|
{} ) );
|
2020-07-08 02:21:45 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "netclass_patterns",
|
2020-07-08 02:21:45 +00:00
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
nlohmann::json ret = nlohmann::json::array();
|
2020-07-08 02:21:45 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ matcher, netclassName ] : m_NetClassPatternAssignments )
|
2020-07-08 02:21:45 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
nlohmann::json pattern_json = {
|
|
|
|
{ "pattern", matcher->GetPattern().ToUTF8() },
|
|
|
|
{ "netclass", netclassName.ToUTF8() }
|
|
|
|
};
|
|
|
|
|
2023-12-18 17:19:15 +00:00
|
|
|
ret.push_back( std::move( pattern_json ) );
|
2020-07-08 02:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( !aJson.is_array() )
|
2020-07-08 02:21:45 +00:00
|
|
|
return;
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_NetClassPatternAssignments.clear();
|
2020-07-08 02:21:45 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const nlohmann::json& entry : aJson )
|
2020-07-08 02:21:45 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( !entry.is_object() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( entry.contains( "pattern" ) && entry["pattern"].is_string()
|
|
|
|
&& entry.contains( "netclass" ) && entry["netclass"].is_string() )
|
|
|
|
{
|
|
|
|
wxString pattern = entry["pattern"].get<wxString>();
|
|
|
|
wxString netclass = entry["netclass"].get<wxString>();
|
|
|
|
|
|
|
|
m_NetClassPatternAssignments.push_back(
|
|
|
|
{
|
|
|
|
std::make_unique<EDA_COMBINED_MATCHER>( pattern, CTX_NETCLASS ),
|
|
|
|
netclass
|
|
|
|
} );
|
|
|
|
}
|
2020-07-08 02:21:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{} ) );
|
2021-06-14 23:16:34 +00:00
|
|
|
|
|
|
|
registerMigration( 0, 1, std::bind( &NET_SETTINGS::migrateSchema0to1, this ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
registerMigration( 2, 3, std::bind( &NET_SETTINGS::migrateSchema2to3, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
bool NET_SETTINGS::migrateSchema2to3()
|
|
|
|
{
|
|
|
|
if( m_internals->contains( "classes" ) && m_internals->At( "classes" ).is_array() )
|
|
|
|
{
|
|
|
|
nlohmann::json patterns = nlohmann::json::array();
|
|
|
|
|
|
|
|
for( auto& netClass : m_internals->At( "classes" ).items() )
|
|
|
|
{
|
|
|
|
if( netClass.value().contains( "name" )
|
|
|
|
&& netClass.value().contains( "nets" )
|
|
|
|
&& netClass.value()["nets"].is_array() )
|
|
|
|
{
|
|
|
|
wxString netClassName = netClass.value()["name"].get<wxString>();
|
|
|
|
|
|
|
|
for( auto& net : netClass.value()["nets"].items() )
|
|
|
|
{
|
|
|
|
nlohmann::json pattern_json = {
|
|
|
|
{ "pattern", net.value().get<wxString>() },
|
|
|
|
{ "netclass", netClassName }
|
|
|
|
};
|
|
|
|
|
|
|
|
patterns.push_back( pattern_json );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_internals->SetFromString( "netclass_patterns", patterns );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<NETCLASS> NET_SETTINGS::GetEffectiveNetClass( const wxString& aNetName ) const
|
2020-10-07 14:40:12 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
auto getNetclass =
|
|
|
|
[&]( const wxString& netclass )
|
|
|
|
{
|
|
|
|
auto ii = m_NetClasses.find( netclass );
|
2020-10-07 14:40:12 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( ii == m_NetClasses.end() )
|
|
|
|
return m_DefaultNetClass;
|
|
|
|
else
|
|
|
|
return ii->second;
|
|
|
|
};
|
2020-10-07 14:40:12 +00:00
|
|
|
|
2023-01-06 22:25:27 +00:00
|
|
|
// <no net> is forced to be part of the Default netclass.
|
|
|
|
if( aNetName.IsEmpty() )
|
|
|
|
return m_DefaultNetClass;
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto it = m_NetClassLabelAssignments.find( aNetName );
|
|
|
|
|
|
|
|
if( it != m_NetClassLabelAssignments.end() )
|
|
|
|
return getNetclass( it->second );
|
|
|
|
|
2023-03-06 13:55:40 +00:00
|
|
|
auto it2 = m_NetClassPatternAssignmentCache.find( aNetName );
|
|
|
|
|
|
|
|
if( it2 != m_NetClassPatternAssignmentCache.end() )
|
|
|
|
return getNetclass( it2->second );
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ matcher, netclassName ] : m_NetClassPatternAssignments )
|
|
|
|
{
|
2023-04-14 22:34:14 +00:00
|
|
|
if( matcher->StartsWith( aNetName ) )
|
2023-03-06 13:55:40 +00:00
|
|
|
{
|
|
|
|
m_NetClassPatternAssignmentCache[ aNetName ] = netclassName;
|
2022-08-14 11:03:18 +00:00
|
|
|
return getNetclass( netclassName );
|
2023-03-06 13:55:40 +00:00
|
|
|
}
|
2022-08-14 11:03:18 +00:00
|
|
|
}
|
|
|
|
|
2023-03-06 17:09:30 +00:00
|
|
|
m_NetClassPatternAssignmentCache[ aNetName ] = wxEmptyString;
|
2022-08-14 11:03:18 +00:00
|
|
|
return m_DefaultNetClass;
|
2020-10-07 14:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 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;
|
|
|
|
}
|