Move bus members from wxArray to std::vector and fix some bugs in dialog.

This commit is contained in:
Jeff Young 2022-08-21 20:35:02 +01:00
parent 0bc1188897
commit 88c9177ff6
12 changed files with 68 additions and 149 deletions

View File

@ -185,7 +185,6 @@ set( EESCHEMA_SRCS
annotate.cpp annotate.cpp
autoplace_fields.cpp autoplace_fields.cpp
bom_plugins.cpp bom_plugins.cpp
bus_alias.cpp
bus-wire-junction.cpp bus-wire-junction.cpp
cmp_library_lexer.cpp cmp_library_lexer.cpp
component_references_lister.cpp component_references_lister.cpp

View File

@ -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 <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/>.
*/
#include <core/kicad_algo.h>
#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 );
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 CERN * 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 <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -23,8 +23,8 @@
#define _BUS_ALIAS_H #define _BUS_ALIAS_H
#include <memory> #include <memory>
#include <vector>
#include <wx/string.h> #include <wx/string.h>
#include <wx/arrstr.h>
class SCH_SCREEN; class SCH_SCREEN;
@ -33,67 +33,33 @@ class SCH_SCREEN;
class BUS_ALIAS class BUS_ALIAS
{ {
public: 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<BUS_ALIAS> Clone() const
{ {
return std::make_shared< BUS_ALIAS >( *this ); return std::make_shared<BUS_ALIAS>( *this );
} }
wxString GetName() wxString GetName() { return m_name; }
{ void SetName( const wxString& aName ) { m_name = aName; }
return m_name;
}
void SetName( const wxString& aName ) const std::vector<wxString>& Members() const { return m_members; }
{ std::vector<wxString>& Members() { return m_members; }
m_name = aName;
}
void ClearMembers() SCH_SCREEN* GetParent() { return m_parent; }
{ void SetParent( SCH_SCREEN* aParent ) { m_parent = aParent; }
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;
}
protected: protected:
wxString m_name; wxString m_name;
std::vector<wxString> m_members;
wxArrayString m_members;
/** /**
* The bus alias editor dialog can edit aliases from all open sheets. * Schematic Setup can edit aliases from all sheets, so we have to store a reference back
* This means we have to store a reference back to our parent so that * to our parent so that the dialog can update the parent if aliases are changed or removed.
* the dialog can update the parent if aliases are changed or removed.
*/ */
SCH_SCREEN* m_parent; SCH_SCREEN* m_parent;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 CERN * 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 <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
@ -1725,11 +1725,11 @@ int CONNECTION_GRAPH::assignNewNetCode( SCH_CONNECTION& aConnection )
void CONNECTION_GRAPH::assignNetCodesToBus( SCH_CONNECTION* aConnection ) void CONNECTION_GRAPH::assignNetCodesToBus( SCH_CONNECTION* aConnection )
{ {
auto connections_to_check( aConnection->Members() ); std::vector< std::shared_ptr<SCH_CONNECTION>>& connections_to_check( aConnection->Members() );
for( unsigned i = 0; i < connections_to_check.size(); i++ ) for( unsigned i = 0; i < connections_to_check.size(); i++ )
{ {
auto member = connections_to_check[i]; const std::shared_ptr<SCH_CONNECTION>& member = connections_to_check[i];
if( member->IsBus() ) if( member->IsBus() )
{ {

View File

@ -56,16 +56,16 @@ bool PANEL_SETUP_BUSES::TransferDataToWindow()
[&]( const std::shared_ptr<BUS_ALIAS>& alias ) -> bool [&]( const std::shared_ptr<BUS_ALIAS>& alias ) -> bool
{ {
wxString aName = alias->GetName(); wxString aName = alias->GetName();
wxArrayString aMembers = alias->Members(); std::vector<wxString> aMembers = alias->Members();
aMembers.Sort(); std::sort( aMembers.begin(), aMembers.end() );
for( const std::shared_ptr<BUS_ALIAS>& candidate : m_aliases ) for( const std::shared_ptr<BUS_ALIAS>& candidate : m_aliases )
{ {
wxString bName = candidate->GetName(); wxString bName = candidate->GetName();
wxArrayString bMembers = candidate->Members(); std::vector<wxString> bMembers = candidate->Members();
bMembers.Sort(); std::sort( bMembers.begin(), bMembers.end() );
if( aName == bName && aMembers == bMembers ) if( aName == bName && aMembers == bMembers )
return true; return true;
@ -253,7 +253,7 @@ void PANEL_SETUP_BUSES::OnMemberGridCellChanging( wxGridEvent& event )
const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ m_lastAlias ]; const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ m_lastAlias ];
alias->ClearMembers(); alias->Members().clear();
for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii ) for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii )
{ {
@ -263,33 +263,41 @@ void PANEL_SETUP_BUSES::OnMemberGridCellChanging( wxGridEvent& event )
wxStringTokenizer tok( name, " " ); wxStringTokenizer tok( name, " " );
while( tok.HasMoreTokens() ) while( tok.HasMoreTokens() )
alias->AddMember( tok.GetNextToken() ); alias->Members().push_back( tok.GetNextToken() );
} }
else 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() ) if( m_lastAlias >= 0 && m_lastAlias < m_aliasesGrid->GetNumberRows() )
{ {
const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ m_lastAlias ]; const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ m_lastAlias ];
m_membersGrid->ClearRows(); m_membersGrid->ClearRows();
m_membersGrid->AppendRows( alias->GetMemberCount() ); m_membersGrid->AppendRows( alias->Members().size() );
for( int ii = 0; ii < alias->GetMemberCount(); ++ii ) int ii = 0;
m_membersGrid->SetCellValue( ii, 0, alias->Members()[ii] );
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_source->SetLabel( wxEmptyString );
} }
m_membersGrid->ClearRows(); doReloadMembersGrid();
m_membersGrid->AppendRows( alias->GetMemberCount() );
for( int ii = 0; ii < alias->GetMemberCount(); ++ii )
m_membersGrid->SetCellValue( ii, 0, alias->Members()[ii] );
m_lastAlias = row; m_lastAlias = row;
m_lastAliasName = aliasName; m_lastAliasName = aliasName;

View File

@ -50,7 +50,9 @@ protected:
void OnSizeGrid( wxSizeEvent& event ) override; void OnSizeGrid( wxSizeEvent& event ) override;
void OnUpdateUI( wxUpdateUIEvent& event ) override; void OnUpdateUI( wxUpdateUIEvent& event ) override;
void reloadMembers( wxIdleEvent& aEvent ); void reloadMembersGridOnIdle( wxIdleEvent& aEvent );
void doReloadMembersGrid();
private: private:
SCH_EDIT_FRAME* m_frame; SCH_EDIT_FRAME* m_frame;

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -307,9 +307,15 @@ int ERC_TESTER::TestConflictingBusAliases()
for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases ) for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
{ {
std::vector<wxString> aliasMembers = alias->Members();
std::sort( aliasMembers.begin(), aliasMembers.end() );
for( const std::shared_ptr<BUS_ALIAS>& test : aliases ) for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
{ {
if( alias->GetName() == test->GetName() && alias->Members() != test->Members() ) std::vector<wxString> 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" ), msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ),
alias->GetName(), alias->GetName(),

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 CERN * 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 <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
@ -32,6 +32,7 @@
#include <string_utils.h> #include <string_utils.h>
#include <sch_connection.h> #include <sch_connection.h>
#include <boost/algorithm/string/join.hpp>
/** /**
* *
@ -408,14 +409,10 @@ void SCH_CONNECTION::AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList )
aList.emplace_back( _( "Connection Name" ), UnescapeString( Name() ) ); aList.emplace_back( _( "Connection Name" ), UnescapeString( Name() ) );
if( auto alias = m_graph->GetBusAlias( m_name ) ) if( std::shared_ptr<BUS_ALIAS> alias = m_graph->GetBusAlias( m_name ) )
{ {
msg.Printf( _( "Bus Alias %s Members" ), m_name ); msg.Printf( _( "Bus Alias %s Members" ), m_name );
aList.emplace_back( msg, boost::algorithm::join( alias->Members(), " " ) );
for( const wxString& member : alias->Members() )
members << member << " ";
aList.emplace_back( msg, members );
} }
else if( NET_SETTINGS::ParseBusGroup( m_name, &group_name, &group_members ) ) else if( NET_SETTINGS::ParseBusGroup( m_name, &group_name, &group_members ) )
{ {
@ -424,11 +421,7 @@ void SCH_CONNECTION::AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList )
if( std::shared_ptr<BUS_ALIAS> group_alias = m_graph->GetBusAlias( group_member ) ) if( std::shared_ptr<BUS_ALIAS> group_alias = m_graph->GetBusAlias( group_member ) )
{ {
msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() ); msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() );
aList.emplace_back( msg, boost::algorithm::join( group_alias->Members(), " " ) );
for( const wxString& member : group_alias->Members() )
members << member << " ";
aList.emplace_back( msg, members );
} }
} }
} }

View File

@ -27,6 +27,7 @@
#include <bus_alias.h> #include <bus_alias.h>
#include <core/mirror.h> #include <core/mirror.h>
#include <core/kicad_algo.h>
#include <eda_text.h> #include <eda_text.h>
#include <lib_shape.h> #include <lib_shape.h>
#include <lib_text.h> #include <lib_text.h>
@ -915,8 +916,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
NET_SCH::BUS_TERM busTerm = busPair.second; NET_SCH::BUS_TERM busTerm = busPair.second;
BUS bus = Schematic.Buses.at( busTerm.BusID ); BUS bus = Schematic.Buses.at( busTerm.BusID );
if( !m_busesMap.at( bus.ID )->Contains( netName ) ) if( !alg::contains( m_busesMap.at( bus.ID )->Members(), netName ) )
m_busesMap.at( bus.ID )->AddMember( netName ); m_busesMap.at( bus.ID )->Members().push_back( netName );
SCH_BUS_WIRE_ENTRY* busEntry = SCH_BUS_WIRE_ENTRY* busEntry =
new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false ); new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false );

View File

@ -3716,7 +3716,7 @@ void SCH_SEXPR_PARSER::parseBusAlias( SCH_SCREEN* aScreen )
if( m_requiredVersion < 20210621 ) if( m_requiredVersion < 20210621 )
member = ConvertToNewOverbarNotation( member ); member = ConvertToNewOverbarNotation( member );
busAlias->AddMember( member ); busAlias->Members().push_back( member );
token = NextTok(); token = NextTok();
} }

View File

@ -46,9 +46,7 @@
#include <schematic.h> #include <schematic.h>
#include <sch_plugins/kicad/sch_sexpr_plugin.h> #include <sch_plugins/kicad/sch_sexpr_plugin.h>
#include <sch_screen.h> #include <sch_screen.h>
#include <symbol_library.h>
#include <lib_shape.h> #include <lib_shape.h>
#include <lib_field.h>
#include <lib_pin.h> #include <lib_pin.h>
#include <lib_text.h> #include <lib_text.h>
#include <lib_textbox.h> #include <lib_textbox.h>
@ -63,6 +61,7 @@
#include <string_utils.h> #include <string_utils.h>
#include <wx_filename.h> // for ::ResolvePossibleSymlinks() #include <wx_filename.h> // for ::ResolvePossibleSymlinks()
#include <progress_reporter.h> #include <progress_reporter.h>
#include <boost/algorithm/string/join.hpp>
using namespace TSCHEMATIC_T; using namespace TSCHEMATIC_T;
@ -1175,19 +1174,9 @@ void SCH_SEXPR_PLUGIN::saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNes
{ {
wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" ); 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->Print( aNestLevel, "(bus_alias %s (members %s))\n",
m_out->Quotew( aAlias->GetName() ).c_str(), m_out->Quotew( aAlias->GetName() ).c_str(),
TO_UTF8( members ) ); TO_UTF8( boost::algorithm::join( aAlias->Members(), " " ) ) );
} }

View File

@ -1376,9 +1376,7 @@ std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader
parseUnquotedString( buf, aReader, line, &line, true ); parseUnquotedString( buf, aReader, line, &line, true );
if( buf.Len() > 0 ) if( buf.Len() > 0 )
{ busAlias->Members().push_back( buf );
busAlias->AddMember( buf );
}
} }
return busAlias; return busAlias;