diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 332b9427b9..c3ed694809 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -185,7 +185,6 @@ set( EESCHEMA_SRCS annotate.cpp autoplace_fields.cpp bom_plugins.cpp - bus_alias.cpp bus-wire-junction.cpp cmp_library_lexer.cpp component_references_lister.cpp diff --git a/eeschema/bus_alias.cpp b/eeschema/bus_alias.cpp deleted file mode 100644 index 04d4a7e840..0000000000 --- a/eeschema/bus_alias.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2018 CERN - * @author Jon Evans - * - * 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 . - */ - -#include -#include "bus_alias.h" - - -BUS_ALIAS::BUS_ALIAS( SCH_SCREEN* aParent ) : - m_parent( aParent ) -{ -} - - -BUS_ALIAS::~BUS_ALIAS() -{ -} - - -bool BUS_ALIAS::Contains( const wxString& aName ) -{ - return alg::contains( m_members, aName ); -} diff --git a/eeschema/bus_alias.h b/eeschema/bus_alias.h index 1104467b86..d7efc26923 100644 --- a/eeschema/bus_alias.h +++ b/eeschema/bus_alias.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -23,8 +23,8 @@ #define _BUS_ALIAS_H #include +#include #include -#include class SCH_SCREEN; @@ -33,67 +33,33 @@ class SCH_SCREEN; class BUS_ALIAS { public: - BUS_ALIAS( SCH_SCREEN* aParent = nullptr ); + BUS_ALIAS( SCH_SCREEN* aParent = nullptr ) + { } - ~BUS_ALIAS(); + ~BUS_ALIAS() + { } - std::shared_ptr< BUS_ALIAS > Clone() const + std::shared_ptr Clone() const { - return std::make_shared< BUS_ALIAS >( *this ); + return std::make_shared( *this ); } - wxString GetName() - { - return m_name; - } + wxString GetName() { return m_name; } + void SetName( const wxString& aName ) { m_name = aName; } - void SetName( const wxString& aName ) - { - m_name = aName; - } + const std::vector& Members() const { return m_members; } + std::vector& Members() { return m_members; } - void ClearMembers() - { - m_members.clear(); - } - - void AddMember( const wxString& aName ) - { - m_members.push_back( aName ); - } - - int GetMemberCount() - { - return m_members.size(); - } - - wxArrayString& Members() - { - return m_members; - } - - bool Contains( const wxString& aName ); - - SCH_SCREEN* GetParent() - { - return m_parent; - } - - void SetParent( SCH_SCREEN* aParent ) - { - m_parent = aParent; - } + SCH_SCREEN* GetParent() { return m_parent; } + void SetParent( SCH_SCREEN* aParent ) { m_parent = aParent; } protected: - - wxString m_name; - - wxArrayString m_members; + wxString m_name; + std::vector m_members; /** - * The bus alias editor dialog can edit aliases from all open sheets. - * This means we have to store a reference back to our parent so that - * the dialog can update the parent if aliases are changed or removed. + * Schematic Setup can edit aliases from all sheets, so we have to store a reference back + * to our parent so that the dialog can update the parent if aliases are changed or removed. */ SCH_SCREEN* m_parent; }; diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 4a8023e8f8..df94495811 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Jon Evans * @@ -1725,11 +1725,11 @@ int CONNECTION_GRAPH::assignNewNetCode( SCH_CONNECTION& aConnection ) void CONNECTION_GRAPH::assignNetCodesToBus( SCH_CONNECTION* aConnection ) { - auto connections_to_check( aConnection->Members() ); + std::vector< std::shared_ptr>& connections_to_check( aConnection->Members() ); for( unsigned i = 0; i < connections_to_check.size(); i++ ) { - auto member = connections_to_check[i]; + const std::shared_ptr& member = connections_to_check[i]; if( member->IsBus() ) { diff --git a/eeschema/dialogs/panel_setup_buses.cpp b/eeschema/dialogs/panel_setup_buses.cpp index 2c9028678e..6885e2c638 100644 --- a/eeschema/dialogs/panel_setup_buses.cpp +++ b/eeschema/dialogs/panel_setup_buses.cpp @@ -55,17 +55,17 @@ bool PANEL_SETUP_BUSES::TransferDataToWindow() auto contains = [&]( const std::shared_ptr& alias ) -> bool { - wxString aName = alias->GetName(); - wxArrayString aMembers = alias->Members(); + wxString aName = alias->GetName(); + std::vector aMembers = alias->Members(); - aMembers.Sort(); + std::sort( aMembers.begin(), aMembers.end() ); for( const std::shared_ptr& candidate : m_aliases ) { - wxString bName = candidate->GetName(); - wxArrayString bMembers = candidate->Members(); + wxString bName = candidate->GetName(); + std::vector bMembers = candidate->Members(); - bMembers.Sort(); + std::sort( bMembers.begin(), bMembers.end() ); if( aName == bName && aMembers == bMembers ) return true; @@ -253,7 +253,7 @@ void PANEL_SETUP_BUSES::OnMemberGridCellChanging( wxGridEvent& event ) const std::shared_ptr& alias = m_aliases[ m_lastAlias ]; - alias->ClearMembers(); + alias->Members().clear(); for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii ) { @@ -263,33 +263,41 @@ void PANEL_SETUP_BUSES::OnMemberGridCellChanging( wxGridEvent& event ) wxStringTokenizer tok( name, " " ); while( tok.HasMoreTokens() ) - alias->AddMember( tok.GetNextToken() ); + alias->Members().push_back( tok.GetNextToken() ); } else { - alias->AddMember( m_membersGrid->GetCellValue( ii, 0 ) ); + alias->Members().push_back( m_membersGrid->GetCellValue( ii, 0 ) ); } } - Bind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembers, this ); + Bind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembersGridOnIdle, this ); } } -void PANEL_SETUP_BUSES::reloadMembers( wxIdleEvent& aEvent ) +void PANEL_SETUP_BUSES::doReloadMembersGrid() { if( m_lastAlias >= 0 && m_lastAlias < m_aliasesGrid->GetNumberRows() ) { const std::shared_ptr& alias = m_aliases[ m_lastAlias ]; m_membersGrid->ClearRows(); - m_membersGrid->AppendRows( alias->GetMemberCount() ); + m_membersGrid->AppendRows( alias->Members().size() ); - for( int ii = 0; ii < alias->GetMemberCount(); ++ii ) - m_membersGrid->SetCellValue( ii, 0, alias->Members()[ii] ); + int ii = 0; + + for( const wxString& member : alias->Members() ) + m_membersGrid->SetCellValue( ii++, 0, member ); } +} - Unbind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembers, this ); + +void PANEL_SETUP_BUSES::reloadMembersGridOnIdle( wxIdleEvent& aEvent ) +{ + doReloadMembersGrid(); + + Unbind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembersGridOnIdle, this ); } @@ -388,11 +396,7 @@ void PANEL_SETUP_BUSES::OnUpdateUI( wxUpdateUIEvent& event ) m_source->SetLabel( wxEmptyString ); } - m_membersGrid->ClearRows(); - m_membersGrid->AppendRows( alias->GetMemberCount() ); - - for( int ii = 0; ii < alias->GetMemberCount(); ++ii ) - m_membersGrid->SetCellValue( ii, 0, alias->Members()[ii] ); + doReloadMembersGrid(); m_lastAlias = row; m_lastAliasName = aliasName; diff --git a/eeschema/dialogs/panel_setup_buses.h b/eeschema/dialogs/panel_setup_buses.h index 1124b134f5..962bc1b70f 100644 --- a/eeschema/dialogs/panel_setup_buses.h +++ b/eeschema/dialogs/panel_setup_buses.h @@ -50,7 +50,9 @@ protected: void OnSizeGrid( wxSizeEvent& event ) override; void OnUpdateUI( wxUpdateUIEvent& event ) override; - void reloadMembers( wxIdleEvent& aEvent ); + void reloadMembersGridOnIdle( wxIdleEvent& aEvent ); + + void doReloadMembersGrid(); private: SCH_EDIT_FRAME* m_frame; diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index c955d08db8..b061585519 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -307,9 +307,15 @@ int ERC_TESTER::TestConflictingBusAliases() for( const std::shared_ptr& alias : screen_aliases ) { + std::vector aliasMembers = alias->Members(); + std::sort( aliasMembers.begin(), aliasMembers.end() ); + for( const std::shared_ptr& test : aliases ) { - if( alias->GetName() == test->GetName() && alias->Members() != test->Members() ) + std::vector testMembers = test->Members(); + std::sort( testMembers.begin(), testMembers.end() ); + + if( alias->GetName() == test->GetName() && aliasMembers != testMembers ) { msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ), alias->GetName(), diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index 89e2921c4e..b902ce3eec 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Jon Evans * @@ -32,6 +32,7 @@ #include #include +#include /** * @@ -408,14 +409,10 @@ void SCH_CONNECTION::AppendInfoToMsgPanel( std::vector& aList ) aList.emplace_back( _( "Connection Name" ), UnescapeString( Name() ) ); - if( auto alias = m_graph->GetBusAlias( m_name ) ) + if( std::shared_ptr alias = m_graph->GetBusAlias( m_name ) ) { msg.Printf( _( "Bus Alias %s Members" ), m_name ); - - for( const wxString& member : alias->Members() ) - members << member << " "; - - aList.emplace_back( msg, members ); + aList.emplace_back( msg, boost::algorithm::join( alias->Members(), " " ) ); } else if( NET_SETTINGS::ParseBusGroup( m_name, &group_name, &group_members ) ) { @@ -424,11 +421,7 @@ void SCH_CONNECTION::AppendInfoToMsgPanel( std::vector& aList ) if( std::shared_ptr group_alias = m_graph->GetBusAlias( group_member ) ) { msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() ); - - for( const wxString& member : group_alias->Members() ) - members << member << " "; - - aList.emplace_back( msg, members ); + aList.emplace_back( msg, boost::algorithm::join( group_alias->Members(), " " ) ); } } } diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 2cd669e8e3..6323d95f5a 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -915,8 +916,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets() NET_SCH::BUS_TERM busTerm = busPair.second; BUS bus = Schematic.Buses.at( busTerm.BusID ); - if( !m_busesMap.at( bus.ID )->Contains( netName ) ) - m_busesMap.at( bus.ID )->AddMember( netName ); + if( !alg::contains( m_busesMap.at( bus.ID )->Members(), netName ) ) + m_busesMap.at( bus.ID )->Members().push_back( netName ); SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index ea3e0fd5af..c2038f48f3 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -3716,7 +3716,7 @@ void SCH_SEXPR_PARSER::parseBusAlias( SCH_SCREEN* aScreen ) if( m_requiredVersion < 20210621 ) member = ConvertToNewOverbarNotation( member ); - busAlias->AddMember( member ); + busAlias->Members().push_back( member ); token = NextTok(); } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index bd330a6af0..8c3f9a64f0 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -46,9 +46,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -63,6 +61,7 @@ #include #include // for ::ResolvePossibleSymlinks() #include +#include using namespace TSCHEMATIC_T; @@ -1175,19 +1174,9 @@ void SCH_SEXPR_PLUGIN::saveBusAlias( std::shared_ptr aAlias, int aNes { wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" ); - wxString members; - - for( auto member : aAlias->Members() ) - { - if( members.IsEmpty() ) - members = m_out->Quotew( member ); - else - members += " " + m_out->Quotew( member ); - } - m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n", m_out->Quotew( aAlias->GetName() ).c_str(), - TO_UTF8( members ) ); + TO_UTF8( boost::algorithm::join( aAlias->Members(), " " ) ) ); } diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index a2c6308710..9b5b271b63 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -1376,9 +1376,7 @@ std::shared_ptr SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader parseUnquotedString( buf, aReader, line, &line, true ); if( buf.Len() > 0 ) - { - busAlias->AddMember( buf ); - } + busAlias->Members().push_back( buf ); } return busAlias;