Move bus members from wxArray to std::vector and fix some bugs in dialog.
This commit is contained in:
parent
0bc1188897
commit
88c9177ff6
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
|
@ -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 <jon@craftyjon.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -23,8 +23,8 @@
|
|||
#define _BUS_ALIAS_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <wx/string.h>
|
||||
#include <wx/arrstr.h>
|
||||
|
||||
|
||||
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<BUS_ALIAS> Clone() const
|
||||
{
|
||||
return std::make_shared< BUS_ALIAS >( *this );
|
||||
return std::make_shared<BUS_ALIAS>( *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<wxString>& Members() const { return m_members; }
|
||||
std::vector<wxString>& 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;
|
||||
std::vector<wxString> 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;
|
||||
};
|
||||
|
|
|
@ -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 <jon@craftyjon.com>
|
||||
*
|
||||
|
@ -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<SCH_CONNECTION>>& 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<SCH_CONNECTION>& member = connections_to_check[i];
|
||||
|
||||
if( member->IsBus() )
|
||||
{
|
||||
|
|
|
@ -56,16 +56,16 @@ bool PANEL_SETUP_BUSES::TransferDataToWindow()
|
|||
[&]( const std::shared_ptr<BUS_ALIAS>& alias ) -> bool
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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 )
|
||||
return true;
|
||||
|
@ -253,7 +253,7 @@ void PANEL_SETUP_BUSES::OnMemberGridCellChanging( wxGridEvent& event )
|
|||
|
||||
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 )
|
||||
{
|
||||
|
@ -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<BUS_ALIAS>& 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* 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
|
||||
* 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 )
|
||||
{
|
||||
std::vector<wxString> aliasMembers = alias->Members();
|
||||
std::sort( aliasMembers.begin(), aliasMembers.end() );
|
||||
|
||||
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" ),
|
||||
alias->GetName(),
|
||||
|
|
|
@ -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 <jon@craftyjon.com>
|
||||
*
|
||||
|
@ -32,6 +32,7 @@
|
|||
#include <string_utils.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() ) );
|
||||
|
||||
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 );
|
||||
|
||||
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<MSG_PANEL_ITEM>& aList )
|
|||
if( std::shared_ptr<BUS_ALIAS> 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(), " " ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <bus_alias.h>
|
||||
#include <core/mirror.h>
|
||||
#include <core/kicad_algo.h>
|
||||
#include <eda_text.h>
|
||||
#include <lib_shape.h>
|
||||
#include <lib_text.h>
|
||||
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -46,9 +46,7 @@
|
|||
#include <schematic.h>
|
||||
#include <sch_plugins/kicad/sch_sexpr_plugin.h>
|
||||
#include <sch_screen.h>
|
||||
#include <symbol_library.h>
|
||||
#include <lib_shape.h>
|
||||
#include <lib_field.h>
|
||||
#include <lib_pin.h>
|
||||
#include <lib_text.h>
|
||||
#include <lib_textbox.h>
|
||||
|
@ -63,6 +61,7 @@
|
|||
#include <string_utils.h>
|
||||
#include <wx_filename.h> // for ::ResolvePossibleSymlinks()
|
||||
#include <progress_reporter.h>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
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" );
|
||||
|
||||
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(), " " ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1376,9 +1376,7 @@ std::shared_ptr<BUS_ALIAS> 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;
|
||||
|
|
Loading…
Reference in New Issue