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
|
2022-08-21 19:35:02 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-02-24 13:48:02 +00:00
|
|
|
*
|
2019-03-11 21:32:05 +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 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>
|
|
|
|
|
|
|
|
#include <connection_graph.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-05-19 15:40:14 +00:00
|
|
|
#include <sch_pin.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_screen.h>
|
2020-07-06 10:51:04 +00:00
|
|
|
#include <project/net_settings.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <advanced_config.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
#include <sch_connection.h>
|
2022-08-21 19:35:02 +00:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
SCH_CONNECTION::SCH_CONNECTION( SCH_ITEM* aParent, SCH_SHEET_PATH aPath ) :
|
|
|
|
m_sheet( aPath ),
|
2021-10-26 02:14:48 +00:00
|
|
|
m_local_sheet( aPath ),
|
2020-05-19 02:58:28 +00:00
|
|
|
m_parent( aParent ),
|
2020-10-27 00:25:08 +00:00
|
|
|
m_driver( nullptr ),
|
2020-05-19 02:58:28 +00:00
|
|
|
m_graph( nullptr )
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_CONNECTION::SCH_CONNECTION( CONNECTION_GRAPH* aGraph ) :
|
|
|
|
m_sheet( SCH_SHEET_PATH() ),
|
2021-10-26 02:14:48 +00:00
|
|
|
m_local_sheet( SCH_SHEET_PATH() ),
|
2020-05-19 02:58:28 +00:00
|
|
|
m_parent( nullptr ),
|
2020-10-27 00:25:08 +00:00
|
|
|
m_driver( nullptr ),
|
2020-05-19 02:58:28 +00:00
|
|
|
m_graph( aGraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& member : m_members )
|
2019-03-11 21:32:05 +00:00
|
|
|
member->SetDriver( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::SetSheet( SCH_SHEET_PATH aSheet )
|
|
|
|
{
|
2021-10-26 02:14:48 +00:00
|
|
|
m_sheet = aSheet;
|
|
|
|
m_local_sheet = aSheet;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-10 17:38:44 +00:00
|
|
|
void SCH_CONNECTION::ConfigureFromLabel( const wxString& aLabel )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-08 03:54:24 +00:00
|
|
|
m_members.clear();
|
|
|
|
|
2021-03-05 04:37:33 +00:00
|
|
|
m_name = aLabel;
|
|
|
|
m_local_name = aLabel;
|
|
|
|
m_local_prefix = m_prefix;
|
2020-01-22 03:02:07 +00:00
|
|
|
|
2020-05-10 17:38:44 +00:00
|
|
|
wxString prefix;
|
|
|
|
std::vector<wxString> members;
|
|
|
|
|
2020-01-22 03:02:07 +00:00
|
|
|
wxString unescaped = UnescapeString( aLabel );
|
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( NET_SETTINGS::ParseBusVector( unescaped, &prefix, &members ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
m_type = CONNECTION_TYPE::BUS;
|
2020-05-10 17:38:44 +00:00
|
|
|
m_vector_prefix = prefix;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-24 02:46:45 +00:00
|
|
|
long i = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-10 17:38:44 +00:00
|
|
|
for( const wxString& 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_local_name = vector_member;
|
2021-03-05 04:37:33 +00:00
|
|
|
member->m_local_prefix = m_prefix;
|
2019-05-24 02:46:45 +00:00
|
|
|
member->m_vector_index = i++;
|
2020-02-29 03:21:48 +00:00
|
|
|
member->SetName( vector_member );
|
2020-05-24 23:08:40 +00:00
|
|
|
member->SetGraph( m_graph );
|
2019-03-11 21:32:05 +00:00
|
|
|
m_members.push_back( member );
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
else if( NET_SETTINGS::ParseBusGroup( unescaped, &prefix, &members ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-07-21 00:41:56 +00:00
|
|
|
m_type = CONNECTION_TYPE::BUS_GROUP;
|
|
|
|
m_bus_prefix = prefix;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-10 17:38:44 +00:00
|
|
|
// Named bus groups generate a net prefix, unnamed ones don't
|
|
|
|
if( !prefix.IsEmpty() )
|
|
|
|
prefix += wxT( "." );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-10 17:38:44 +00:00
|
|
|
for( const wxString& group_member : members )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-05-10 17:38:44 +00:00
|
|
|
// Handle alias inside bus group member list
|
2020-05-13 02:00:37 +00:00
|
|
|
if( auto alias = m_graph->GetBusAlias( group_member ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-05-10 17:38:44 +00:00
|
|
|
for( const wxString& 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 );
|
2020-06-30 00:27:08 +00:00
|
|
|
member->SetGraph( m_graph );
|
2020-05-10 17:38:44 +00:00
|
|
|
member->ConfigureFromLabel( alias_member );
|
2019-03-11 21:32:05 +00:00
|
|
|
m_members.push_back( member );
|
|
|
|
}
|
|
|
|
}
|
2020-05-10 17:38:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
|
|
|
|
member->SetPrefix( prefix );
|
2020-06-30 00:27:08 +00:00
|
|
|
member->SetGraph( m_graph );
|
2020-05-10 17:38:44 +00:00
|
|
|
member->ConfigureFromLabel( group_member );
|
|
|
|
m_members.push_back( member );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-22 03:02:07 +00:00
|
|
|
m_type = CONNECTION_TYPE::NET;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2020-02-29 03:21:48 +00:00
|
|
|
|
|
|
|
recacheName();
|
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();
|
2021-03-05 04:37:33 +00:00
|
|
|
m_local_prefix.Empty();
|
2020-02-29 03:21:48 +00:00
|
|
|
m_cached_name.Empty();
|
|
|
|
m_cached_name_with_path.Empty();
|
2019-04-29 04:36:41 +00:00
|
|
|
m_prefix.Empty();
|
2020-07-21 00:41:56 +00:00
|
|
|
m_bus_prefix.Empty();
|
2019-04-29 04:36:41 +00:00
|
|
|
m_suffix .Empty();
|
2020-10-17 18:59:08 +00:00
|
|
|
m_lastDriver = m_driver;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-05 04:37:33 +00:00
|
|
|
void SCH_CONNECTION::Clone( const SCH_CONNECTION& aOther )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-05-24 23:08:40 +00:00
|
|
|
m_graph = aOther.m_graph;
|
2020-11-03 12:06:11 +00:00
|
|
|
// Note: m_lastDriver is not cloned as it needs to be the last driver of *this* connection
|
2019-03-11 21:32:05 +00:00
|
|
|
m_driver = aOther.Driver();
|
2021-01-28 02:47:23 +00:00
|
|
|
m_sheet = aOther.Sheet();
|
2021-10-26 02:14:48 +00:00
|
|
|
// Note: m_local_sheet is not cloned
|
2021-01-28 02:47:23 +00:00
|
|
|
m_name = aOther.m_name;
|
|
|
|
// Note: m_local_name is not cloned if not set yet
|
|
|
|
if( m_local_name.IsEmpty() )
|
2021-03-05 04:37:33 +00:00
|
|
|
{
|
|
|
|
m_local_name = aOther.LocalName();
|
|
|
|
m_local_prefix = aOther.Prefix();
|
|
|
|
}
|
2021-01-28 02:47:23 +00:00
|
|
|
|
|
|
|
m_prefix = aOther.Prefix();
|
2021-03-05 04:37:33 +00:00
|
|
|
// m_bus_prefix is not cloned; only used for local names
|
2021-01-28 02:47:23 +00:00
|
|
|
m_suffix = aOther.Suffix();
|
|
|
|
m_net_code = aOther.NetCode();
|
|
|
|
m_bus_code = aOther.BusCode();
|
2019-03-11 21:32:05 +00:00
|
|
|
m_vector_start = aOther.VectorStart();
|
2021-01-28 02:47:23 +00:00
|
|
|
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
|
2020-02-29 03:21:48 +00:00
|
|
|
|
2021-01-28 02:47:23 +00:00
|
|
|
// Handle vector bus members: make sure local names are preserved where possible
|
2021-03-05 04:37:33 +00:00
|
|
|
const std::vector<std::shared_ptr<SCH_CONNECTION>>& otherMembers = aOther.Members();
|
2021-01-28 02:47:23 +00:00
|
|
|
|
2021-03-05 04:37:33 +00:00
|
|
|
if( m_type == CONNECTION_TYPE::BUS && aOther.Type() == CONNECTION_TYPE::BUS )
|
2021-01-28 02:47:23 +00:00
|
|
|
{
|
2021-03-05 04:37:33 +00:00
|
|
|
if( m_members.empty() )
|
2021-01-28 02:47:23 +00:00
|
|
|
{
|
2021-03-05 04:37:33 +00:00
|
|
|
m_members = otherMembers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t cloneLimit = std::min( m_members.size(), otherMembers.size() );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < cloneLimit; ++i )
|
|
|
|
m_members[i]->Clone( *otherMembers[i] );
|
2021-01-28 02:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 04:37:33 +00:00
|
|
|
else if( m_type == CONNECTION_TYPE::BUS_GROUP && aOther.Type() == CONNECTION_TYPE::BUS_GROUP )
|
2021-01-28 02:47:23 +00:00
|
|
|
{
|
2021-03-11 23:20:56 +00:00
|
|
|
if( m_members.empty() )
|
2021-03-05 04:37:33 +00:00
|
|
|
{
|
|
|
|
m_members = otherMembers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-11 23:20:56 +00:00
|
|
|
// TODO: refactor this once we support deep nesting
|
2021-03-05 04:37:33 +00:00
|
|
|
for( size_t i = 0; i < m_members.size(); ++i )
|
2021-03-11 23:20:56 +00:00
|
|
|
{
|
|
|
|
auto it = std::find_if( otherMembers.begin(), otherMembers.end(),
|
|
|
|
[&]( const std::shared_ptr<SCH_CONNECTION>& aTest )
|
|
|
|
{
|
|
|
|
return aTest->LocalName() == m_members[i]->LocalName();
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( it != otherMembers.end() )
|
|
|
|
m_members[i]->Clone( **it );
|
|
|
|
}
|
2021-03-05 04:37:33 +00:00
|
|
|
}
|
2021-01-28 02:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_type = aOther.Type();
|
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
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() );
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// Only annotated symbols should drive nets.
|
2023-01-18 15:06:46 +00:00
|
|
|
return pin->IsGlobalPower() || pin->GetParentSymbol()->IsAnnotated( &m_sheet );
|
2019-05-19 15:40:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
bool SCH_CONNECTION::HasDriverChanged() const
|
|
|
|
{
|
|
|
|
return m_driver != m_lastDriver;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::ClearDriverChanged()
|
|
|
|
{
|
|
|
|
m_lastDriver = m_driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-24 17:00:19 +00:00
|
|
|
wxString SCH_CONNECTION::Name( bool aIgnoreSheet ) const
|
2020-02-29 03:21:48 +00:00
|
|
|
{
|
|
|
|
wxASSERT( !m_cached_name.IsEmpty() );
|
|
|
|
return aIgnoreSheet ? m_cached_name : m_cached_name_with_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_CONNECTION::recacheName()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-07-09 22:30:52 +00:00
|
|
|
m_cached_name =
|
2023-02-12 21:29:26 +00:00
|
|
|
m_name.IsEmpty() ? wxString( wxT( "<NO NET>" ) ) : wxString( m_prefix ) << m_name << m_suffix;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
bool prepend_path = true;
|
2019-04-29 04:36:41 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( !Parent() || m_type == CONNECTION_TYPE::NONE )
|
2020-02-29 03:21:48 +00:00
|
|
|
prepend_path = false;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
if( m_driver )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-02-29 03:21:48 +00:00
|
|
|
switch( m_driver->Type() )
|
2019-04-02 00:21:20 +00:00
|
|
|
{
|
2020-02-29 03:21:48 +00:00
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_PIN_T:
|
|
|
|
// Pins are either power connections or belong to a uniquely-annotated
|
2021-06-14 18:00:08 +00:00
|
|
|
// symbol, so they don't need a path if they are driving the subgraph.
|
2020-02-29 03:21:48 +00:00
|
|
|
prepend_path = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2019-04-02 00:21:20 +00:00
|
|
|
}
|
2019-04-29 23:41:03 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
m_cached_name_with_path =
|
2022-07-09 22:30:52 +00:00
|
|
|
prepend_path ? m_sheet.PathHumanReadable() << m_cached_name : m_cached_name;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
|
|
|
|
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;
|
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& m : Members() )
|
2019-05-08 02:48:25 +00:00
|
|
|
m->SetSuffix( aSuffix );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_CONNECTION::AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList ) const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
wxString msg, group_name, members;
|
2019-03-11 21:32:05 +00:00
|
|
|
std::vector<wxString> group_members;
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Connection Name" ), UnescapeString( Name() ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-08-21 19:35:02 +00:00
|
|
|
if( std::shared_ptr<BUS_ALIAS> alias = m_graph->GetBusAlias( m_name ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "Bus Alias %s Members" ), m_name );
|
2022-08-21 19:35:02 +00:00
|
|
|
aList.emplace_back( msg, boost::algorithm::join( alias->Members(), " " ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
else if( NET_SETTINGS::ParseBusGroup( m_name, &group_name, &group_members ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
for( const wxString& group_member : group_members )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
if( std::shared_ptr<BUS_ALIAS> group_alias = m_graph->GetBusAlias( group_member ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() );
|
2022-08-21 19:35:02 +00:00
|
|
|
aList.emplace_back( msg, boost::algorithm::join( group_alias->Members(), " " ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:17:30 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
// These messages are not flagged as translatable, because they are only debug messages
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-23 02:58:41 +00:00
|
|
|
if( IsBus() )
|
2022-02-03 21:47:10 +00:00
|
|
|
aList.emplace_back( wxT( "Bus Code" ), wxString::Format( "%d", m_bus_code ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-02-03 21:47:10 +00:00
|
|
|
aList.emplace_back( wxT( "Subgraph Code" ), wxString::Format( "%d", m_subgraph_code ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
if( SCH_ITEM* driver = Driver() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-09-19 16:09:59 +00:00
|
|
|
UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES );
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
msg.Printf( wxS( "%s at %p" ), driver->GetItemDescription( &unitsProvider ), driver );
|
2022-02-03 21:47:10 +00:00
|
|
|
aList.emplace_back( wxT( "Connection Source" ), msg );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2020-07-07 10:17:30 +00:00
|
|
|
#endif
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::IsBusLabel( const wxString& aLabel )
|
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
const wxString& unescaped = UnescapeString( aLabel );
|
|
|
|
|
|
|
|
return NET_SETTINGS::ParseBusVector( unescaped, nullptr, nullptr )
|
|
|
|
|| NET_SETTINGS::ParseBusGroup( unescaped, nullptr, nullptr );
|
2020-05-06 22:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_CONNECTION::MightBeBusLabel( const wxString& aLabel )
|
|
|
|
{
|
2020-02-04 22:37:14 +00:00
|
|
|
// Weak heuristic for performance reasons. Stronger test will be used for connectivity
|
2020-05-06 22:26:56 +00:00
|
|
|
wxString label = UnescapeString( aLabel );
|
|
|
|
|
|
|
|
return label.Contains( wxT( "[" ) ) || label.Contains( wxT( "{" ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-25 21:03:49 +00:00
|
|
|
const std::vector< std::shared_ptr< SCH_CONNECTION > > SCH_CONNECTION::AllMembers() const
|
|
|
|
{
|
|
|
|
std::vector< std::shared_ptr< SCH_CONNECTION > > ret( m_members );
|
|
|
|
|
|
|
|
for( const auto& member : m_members )
|
|
|
|
if( member->IsBus() )
|
|
|
|
ret.insert( ret.end(), member->Members().begin(), member->Members().end() );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-07-06 10:51:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-05-13 15:26:53 +00:00
|
|
|
wxString SCH_CONNECTION::PrintBusForUI( const wxString& aGroup )
|
|
|
|
{
|
|
|
|
size_t groupLen = aGroup.length();
|
|
|
|
size_t i = 0;
|
|
|
|
wxString ret;
|
|
|
|
int braceNesting = 0;
|
|
|
|
|
|
|
|
// Parse prefix
|
|
|
|
//
|
|
|
|
for( ; i < groupLen; ++i )
|
|
|
|
{
|
2021-06-05 13:52:58 +00:00
|
|
|
if( isSuperSubOverbar( aGroup[i] ) && i + 1 < groupLen && aGroup[i+1] == '{' )
|
2020-05-13 15:26:53 +00:00
|
|
|
{
|
|
|
|
braceNesting++;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if( aGroup[i] == '}' )
|
|
|
|
{
|
|
|
|
braceNesting--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += aGroup[i];
|
|
|
|
|
|
|
|
if( aGroup[i] == '{' )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse members
|
|
|
|
//
|
|
|
|
i++; // '{' character
|
|
|
|
|
|
|
|
for( ; i < groupLen; ++i )
|
|
|
|
{
|
2021-06-05 13:52:58 +00:00
|
|
|
if( isSuperSubOverbar( aGroup[i] ) && i + 1 < groupLen && aGroup[i+1] == '{' )
|
2020-05-13 15:26:53 +00:00
|
|
|
{
|
|
|
|
braceNesting++;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if( aGroup[i] == '}' )
|
|
|
|
{
|
|
|
|
braceNesting--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += aGroup[i];
|
|
|
|
|
|
|
|
if( aGroup[i] == '}' )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
bool SCH_CONNECTION::IsSubsetOf( SCH_CONNECTION* aOther ) const
|
|
|
|
{
|
2020-05-25 21:35:26 +00:00
|
|
|
if( !aOther->IsBus() )
|
2019-03-11 21:32:05 +00:00
|
|
|
return false;
|
|
|
|
|
2020-05-25 21:35:26 +00:00
|
|
|
for( const auto& member : aOther->Members() )
|
|
|
|
{
|
|
|
|
if( member->FullLocalName() == FullLocalName() )
|
|
|
|
return true;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-25 21:35:26 +00:00
|
|
|
return false;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2020-06-30 00:27:08 +00:00
|
|
|
}
|