2019-03-11 21:32:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 CERN
|
|
|
|
* @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 2
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-20 02:26:21 +00:00
|
|
|
#include <regex>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
2019-04-11 05:07:45 +00:00
|
|
|
#include <advanced_config.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <connection_graph.h>
|
2019-05-19 15:40:14 +00:00
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_pin.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_screen.h>
|
|
|
|
|
|
|
|
#include <sch_connection.h>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Buses can be defined in multiple ways. A bus vector consists of a prefix and
|
|
|
|
* a numeric range of suffixes:
|
|
|
|
*
|
|
|
|
* BUS_NAME[M..N]
|
|
|
|
*
|
|
|
|
* For example, the bus A[3..0] will contain nets A3, A2, A1, and A0.
|
|
|
|
* The BUS_NAME is required. M and N must be integers but do not need to be in
|
|
|
|
* any particular order -- A[0..3] produces the same result.
|
|
|
|
*
|
|
|
|
* Like net names, bus names cannot contain whitespace.
|
|
|
|
*
|
|
|
|
* A bus group is just a grouping of signals, separated by spaces, some
|
|
|
|
* of which may be bus vectors. Bus groups can have names, but do not need to.
|
|
|
|
*
|
|
|
|
* MEMORY{A[15..0] D[7..0] RW CE OE}
|
|
|
|
*
|
|
|
|
* In named bus groups, the net names are expanded as <BUS_NAME>.<NET_NAME>
|
|
|
|
* In the above example, the nets would be named like MEMORY.A15, MEMORY.D0, etc.
|
|
|
|
*
|
|
|
|
* {USB_DP USB_DN}
|
|
|
|
*
|
|
|
|
* In the above example, the bus is unnamed and so the underlying net names are
|
|
|
|
* just USB_DP and USB_DN.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-24 02:46:45 +00:00
|
|
|
static std::regex bus_label_re( "^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])(~?)$" );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
static std::regex bus_group_label_re( "^([^[:space:]]+)?\\{((?:[^[:space:]]+(?:\\[[\\d]+\\.+[\\d]+\\])? ?)+)\\}$" );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
SCH_CONNECTION::SCH_CONNECTION( SCH_ITEM* aParent, SCH_SHEET_PATH aPath ) :
|
|
|
|
m_sheet( aPath ),
|
|
|
|
m_parent( aParent )
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::operator==( const SCH_CONNECTION& aOther ) const
|
|
|
|
{
|
|
|
|
// NOTE: Not comparing m_dirty or net/bus/subgraph codes
|
|
|
|
if( ( aOther.m_driver == m_driver ) &&
|
|
|
|
( aOther.m_type == m_type ) &&
|
|
|
|
( aOther.m_name == m_name ) &&
|
|
|
|
( aOther.m_sheet == m_sheet ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::SetDriver( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_driver = aItem;
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& member : m_members )
|
2019-03-11 21:32:05 +00:00
|
|
|
member->SetDriver( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::SetSheet( SCH_SHEET_PATH aSheet )
|
|
|
|
{
|
|
|
|
m_sheet = aSheet;
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& member : m_members )
|
2019-03-11 21:32:05 +00:00
|
|
|
member->SetSheet( aSheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::operator!=( const SCH_CONNECTION& aOther ) const
|
|
|
|
{
|
|
|
|
return !( aOther == *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::ConfigureFromLabel( wxString aLabel )
|
|
|
|
{
|
2019-04-08 03:54:24 +00:00
|
|
|
m_members.clear();
|
|
|
|
|
2020-01-22 03:02:07 +00:00
|
|
|
m_name = aLabel;
|
|
|
|
m_local_name = aLabel;
|
|
|
|
|
|
|
|
wxString unescaped = UnescapeString( aLabel );
|
|
|
|
|
|
|
|
if( IsBusVectorLabel( unescaped ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
m_type = CONNECTION_TYPE::BUS;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
std::vector<wxString> members;
|
|
|
|
|
2020-01-22 03:02:07 +00:00
|
|
|
ParseBusVector( unescaped, &m_vector_prefix, members );
|
2019-05-24 02:46:45 +00:00
|
|
|
long i = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
for( const auto& vector_member : members )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
auto member = std::make_shared<SCH_CONNECTION>( m_parent, m_sheet );
|
|
|
|
member->m_type = CONNECTION_TYPE::NET;
|
|
|
|
member->m_prefix = m_prefix;
|
|
|
|
member->m_name = vector_member;
|
|
|
|
member->m_local_name = vector_member;
|
2019-05-24 02:46:45 +00:00
|
|
|
member->m_vector_index = i++;
|
2019-03-11 21:32:05 +00:00
|
|
|
m_members.push_back( member );
|
|
|
|
}
|
|
|
|
}
|
2020-01-22 03:02:07 +00:00
|
|
|
else if( IsBusGroupLabel( unescaped ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-22 03:02:07 +00:00
|
|
|
m_type = CONNECTION_TYPE::BUS_GROUP;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
std::vector<wxString> members;
|
|
|
|
wxString group_name;
|
|
|
|
|
2020-01-22 03:02:07 +00:00
|
|
|
if( ParseBusGroup( unescaped, &group_name, members ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
// Named bus groups generate a net prefix, unnamed ones don't
|
2019-04-20 01:45:33 +00:00
|
|
|
wxString prefix = group_name != wxT( "" ) ? ( group_name + wxT( "." ) ) : wxT( "" );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
for( const auto& group_member : members )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
// Handle alias inside bus group member list
|
|
|
|
if( auto alias = g_ConnectionGraph->GetBusAlias( group_member ) )
|
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
for( const auto& alias_member : alias->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
|
|
|
|
member->SetPrefix( prefix );
|
|
|
|
member->ConfigureFromLabel( alias_member );
|
|
|
|
m_members.push_back( member );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
|
|
|
|
member->SetPrefix( prefix );
|
|
|
|
member->ConfigureFromLabel( group_member );
|
|
|
|
m_members.push_back( member );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-22 03:02:07 +00:00
|
|
|
m_type = CONNECTION_TYPE::NET;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::Reset()
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
m_type = CONNECTION_TYPE::NONE;
|
2019-04-29 04:36:41 +00:00
|
|
|
m_name.Empty();
|
2020-01-04 03:11:00 +00:00
|
|
|
m_local_name.Empty();
|
2019-04-29 04:36:41 +00:00
|
|
|
m_prefix.Empty();
|
|
|
|
m_suffix .Empty();
|
2019-03-11 21:32:05 +00:00
|
|
|
m_driver = nullptr;
|
|
|
|
m_members.clear();
|
|
|
|
m_dirty = true;
|
|
|
|
m_net_code = 0;
|
|
|
|
m_bus_code = 0;
|
|
|
|
m_subgraph_code = 0;
|
|
|
|
m_vector_start = 0;
|
|
|
|
m_vector_end = 0;
|
|
|
|
m_vector_index = 0;
|
2019-04-29 04:36:41 +00:00
|
|
|
m_vector_prefix.Empty();
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::Clone( SCH_CONNECTION& aOther )
|
|
|
|
{
|
|
|
|
m_type = aOther.Type();
|
|
|
|
m_driver = aOther.Driver();
|
|
|
|
m_sheet = aOther.Sheet();
|
2019-04-20 01:45:33 +00:00
|
|
|
m_name = aOther.m_name;
|
2020-01-04 03:11:00 +00:00
|
|
|
// Note: m_local_name is not cloned
|
2019-03-11 21:32:05 +00:00
|
|
|
m_prefix = aOther.Prefix();
|
2019-05-02 00:48:27 +00:00
|
|
|
m_suffix = aOther.Suffix();
|
2019-03-11 21:32:05 +00:00
|
|
|
m_members = aOther.Members();
|
|
|
|
m_net_code = aOther.NetCode();
|
|
|
|
m_bus_code = aOther.BusCode();
|
|
|
|
m_vector_start = aOther.VectorStart();
|
|
|
|
m_vector_end = aOther.VectorEnd();
|
2020-01-04 15:38:43 +00:00
|
|
|
// Note: m_vector_index is not cloned
|
2019-03-11 21:32:05 +00:00
|
|
|
m_vector_prefix = aOther.VectorPrefix();
|
2019-05-02 00:48:27 +00:00
|
|
|
|
|
|
|
// Note: subgraph code isn't cloned, it should remain with the original object
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsDriver() const
|
|
|
|
{
|
|
|
|
wxASSERT( Parent() );
|
|
|
|
|
|
|
|
switch( Parent()->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2019-03-11 21:32:05 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
case LIB_PIN_T:
|
|
|
|
return true;
|
|
|
|
|
2019-05-19 15:40:14 +00:00
|
|
|
case SCH_PIN_T:
|
|
|
|
{
|
|
|
|
auto pin = static_cast<SCH_PIN*>( Parent() );
|
|
|
|
|
|
|
|
// Only annotated components should drive nets
|
2020-01-04 03:09:56 +00:00
|
|
|
return ( pin->IsPowerConnection()
|
|
|
|
|| pin->GetParentComponent()->IsAnnotated( &m_sheet ) );
|
2019-05-19 15:40:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-03 09:14:36 +00:00
|
|
|
wxString SCH_CONNECTION::Name( bool aIgnoreSheet ) const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
wxString ret = m_prefix + m_name + m_suffix;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-29 04:36:41 +00:00
|
|
|
if( m_name.IsEmpty() )
|
|
|
|
ret = "<NO NET>";
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( !Parent() || m_type == CONNECTION_TYPE::NONE )
|
2019-03-11 21:32:05 +00:00
|
|
|
return ret;
|
|
|
|
|
2019-04-29 23:41:03 +00:00
|
|
|
if( !aIgnoreSheet )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-29 23:41:03 +00:00
|
|
|
bool prepend_path = true;
|
|
|
|
|
|
|
|
if( m_driver )
|
2019-04-02 00:21:20 +00:00
|
|
|
{
|
2019-04-29 23:41:03 +00:00
|
|
|
switch( m_driver->Type() )
|
|
|
|
{
|
|
|
|
case SCH_PIN_T:
|
|
|
|
// Pins are either power connections or belong to a uniquely-annotated
|
|
|
|
// component, so they don't need a path if they are driving the subgraph
|
|
|
|
prepend_path = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
prepend_path = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-04-02 00:21:20 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-29 23:41:03 +00:00
|
|
|
if( prepend_path )
|
|
|
|
ret = m_sheet.PathHumanReadable() + ret;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-08 02:48:25 +00:00
|
|
|
void SCH_CONNECTION::SetPrefix( const wxString& aPrefix )
|
|
|
|
{
|
2019-05-13 03:24:11 +00:00
|
|
|
m_prefix = aPrefix;
|
2019-05-08 02:48:25 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& m : Members() )
|
2019-05-08 02:48:25 +00:00
|
|
|
m->SetPrefix( aPrefix );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::SetSuffix( const wxString& aSuffix )
|
|
|
|
{
|
|
|
|
m_suffix = aSuffix;
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& m : Members() )
|
2019-05-08 02:48:25 +00:00
|
|
|
m->SetSuffix( aSuffix );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
void SCH_CONNECTION::AppendInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const
|
|
|
|
{
|
2019-04-29 21:44:49 +00:00
|
|
|
if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
|
2019-04-11 05:07:45 +00:00
|
|
|
return;
|
2019-03-30 15:57:30 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
wxString msg, group_name;
|
|
|
|
std::vector<wxString> group_members;
|
|
|
|
|
2020-01-22 03:02:07 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Connection Name" ), UnescapeString( Name() ), BROWN ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-18 17:57:02 +00:00
|
|
|
// NOTE(JE) Disabling this for now, because net codes are generated in the netlist exporter
|
|
|
|
// in order to avoid sort costs. It may make sense to just tear out net codes from the
|
|
|
|
// CONNECTION_GRAPH entirely in the future, as they are mostly only useful for netlist exports.
|
|
|
|
#if 0
|
2019-04-23 02:58:41 +00:00
|
|
|
if( !IsBus() )
|
|
|
|
{
|
|
|
|
msg.Printf( "%d", m_net_code );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), msg, BROWN ) );
|
|
|
|
}
|
2020-01-18 17:57:02 +00:00
|
|
|
#endif
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( auto alias = g_ConnectionGraph->GetBusAlias( m_name ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Bus Alias %s Members" ), m_name );
|
|
|
|
|
|
|
|
wxString members;
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& member : alias->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
members << member << " ";
|
|
|
|
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( msg, members, RED ) );
|
|
|
|
}
|
|
|
|
else if( ParseBusGroup( m_name, &group_name, group_members ) )
|
|
|
|
{
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& group_member : group_members )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
if( auto group_alias = g_ConnectionGraph->GetBusAlias( group_member ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() );
|
|
|
|
|
|
|
|
wxString members;
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& member : group_alias->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
members << member << " ";
|
|
|
|
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( msg, members, RED ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::AppendDebugInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const
|
|
|
|
{
|
2019-04-29 21:44:49 +00:00
|
|
|
if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
|
2019-04-11 05:07:45 +00:00
|
|
|
return;
|
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
// These messages are not flagged as translatable, because they are only debug messages
|
2019-03-11 21:32:05 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
AppendInfoToMsgPanel( aList );
|
|
|
|
|
2019-04-23 02:58:41 +00:00
|
|
|
if( IsBus() )
|
|
|
|
{
|
|
|
|
msg.Printf( "%d", m_bus_code );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( "Bus Code", msg, BROWN ) );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
msg.Printf( "%d", m_subgraph_code );
|
2019-04-13 08:12:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( "Subgraph Code", msg, BROWN ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( auto driver = Driver() )
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
msg.Printf( "%s at %p", driver->GetSelectMenuText( EDA_UNITS::MILLIMETRES ), driver );
|
2019-04-13 08:12:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( "Connection Source", msg, RED ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsBusLabel( const wxString& aLabel )
|
|
|
|
{
|
|
|
|
return IsBusVectorLabel( aLabel ) || IsBusGroupLabel( aLabel );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsBusVectorLabel( const wxString& aLabel )
|
|
|
|
{
|
2019-05-01 23:48:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return std::regex_match( std::string( aLabel.mb_str() ), bus_label_re );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsBusGroupLabel( const wxString& aLabel )
|
|
|
|
{
|
2019-05-01 23:48:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return std::regex_match( std::string( aLabel.mb_str() ), bus_group_label_re );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
bool SCH_CONNECTION::ParseBusVector( wxString aBus, wxString* aName,
|
|
|
|
std::vector<wxString>& aMemberList ) const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-05-24 02:46:45 +00:00
|
|
|
auto ss_vector = std::string( aBus.mb_str() );
|
2019-04-20 02:26:21 +00:00
|
|
|
std::smatch matches;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-01 23:48:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if( !std::regex_match( ss_vector, matches, bus_label_re ) )
|
2019-05-24 02:46:45 +00:00
|
|
|
return false;
|
2019-05-01 23:48:29 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-05-24 02:46:45 +00:00
|
|
|
return false;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
long begin = 0, end = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
*aName = wxString( matches[1] );
|
|
|
|
wxString numberString( matches[2] );
|
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
// If we have three match groups, it means there was a tilde at the end of the vector
|
|
|
|
bool append_tilde = wxString( matches[3] ).IsSameAs( wxT( "~" ) );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
// numberString will include the brackets, e.g. [5..0] so skip the first one
|
|
|
|
size_t i = 1, len = numberString.Len();
|
|
|
|
wxString tmp;
|
|
|
|
|
|
|
|
while( i < len && numberString[i] != '.' )
|
|
|
|
{
|
|
|
|
tmp.Append( numberString[i] );
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
tmp.ToLong( &begin );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
while( i < len && numberString[i] == '.' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
tmp.Empty();
|
|
|
|
|
|
|
|
while( i < len && numberString[i] != ']' )
|
|
|
|
{
|
|
|
|
tmp.Append( numberString[i] );
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
tmp.ToLong( &end );
|
|
|
|
|
|
|
|
if( begin < 0 )
|
|
|
|
begin = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
if( end < 0 )
|
|
|
|
end = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
if( begin > end )
|
|
|
|
std::swap( begin, end );
|
|
|
|
|
|
|
|
for( long idx = begin; idx <= end; ++idx )
|
|
|
|
{
|
|
|
|
wxString str = *aName;
|
|
|
|
str << idx;
|
|
|
|
|
|
|
|
if( append_tilde )
|
|
|
|
str << '~';
|
|
|
|
|
|
|
|
aMemberList.emplace_back( str );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
return true;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::ParseBusGroup( wxString aGroup, wxString* aName,
|
|
|
|
std::vector<wxString>& aMemberList ) const
|
|
|
|
{
|
|
|
|
auto ss_group = std::string( aGroup.mb_str() );
|
2019-04-20 02:26:21 +00:00
|
|
|
std::smatch matches;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-01 23:48:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if( !std::regex_match( ss_group, matches, bus_group_label_re ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aName = wxString( matches[1] );
|
|
|
|
|
2019-05-20 23:28:32 +00:00
|
|
|
wxStringTokenizer tokenizer( wxString( matches[2] ), " " );
|
2019-03-11 21:32:05 +00:00
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
aMemberList.push_back( tokenizer.GetNextToken() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsSubsetOf( SCH_CONNECTION* aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther->IsNet() )
|
|
|
|
return IsNet() ? ( aOther->Name( true ) == Name( true ) ) : false;
|
|
|
|
|
|
|
|
if( !IsBus() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<wxString> mine, theirs;
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& m : Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
mine.push_back( m->Name( true ) );
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& m : aOther->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
theirs.push_back( m->Name( true ) );
|
|
|
|
|
|
|
|
std::set<wxString> subset;
|
|
|
|
|
|
|
|
std::set_intersection( mine.begin(), mine.end(),
|
|
|
|
theirs.begin(), theirs.end(),
|
|
|
|
std::inserter(subset, subset.begin() ) );
|
|
|
|
|
|
|
|
return ( !subset.empty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsMemberOfBus( SCH_CONNECTION* aOther ) const
|
|
|
|
{
|
|
|
|
if( !aOther->IsBus() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto me = Name( true );
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& m : aOther->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
if( m->Name( true ) == me )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2019-05-01 23:48:29 +00:00
|
|
|
}
|