|
|
|
@ -19,9 +19,11 @@ |
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/ |
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <widgets/wx_grid.h>
|
|
|
|
#include <widgets/std_bitmap_button.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <schematic.h>
|
|
|
|
#include <dialogs/panel_setup_buses.h>
|
|
|
|
@ -92,40 +94,30 @@ PANEL_SETUP_BUSES::~PANEL_SETUP_BUSES() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_BUSES::loadAliases( const SCHEMATIC& aSchematic ) |
|
|
|
void PANEL_SETUP_BUSES::loadAliases() |
|
|
|
{ |
|
|
|
auto contains = |
|
|
|
[&]( const std::shared_ptr<BUS_ALIAS>& alias ) -> bool |
|
|
|
{ |
|
|
|
wxString aName = alias->GetName(); |
|
|
|
std::vector<wxString> aMembers = alias->Members(); |
|
|
|
|
|
|
|
std::sort( aMembers.begin(), aMembers.end() ); |
|
|
|
m_aliases.clear(); |
|
|
|
|
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& candidate : m_aliases ) |
|
|
|
{ |
|
|
|
wxString bName = candidate->GetName(); |
|
|
|
std::vector<wxString> bMembers = candidate->Members(); |
|
|
|
const auto& projectAliases = m_frame->Prj().GetProjectFile().m_BusAliases; |
|
|
|
|
|
|
|
std::sort( bMembers.begin(), bMembers.end() ); |
|
|
|
std::vector<std::pair<wxString, std::vector<wxString>>> aliasList( projectAliases.begin(), |
|
|
|
projectAliases.end() ); |
|
|
|
|
|
|
|
if( aName == bName && aMembers == bMembers ) |
|
|
|
return true; |
|
|
|
} |
|
|
|
std::sort( aliasList.begin(), aliasList.end(), |
|
|
|
[]( const std::pair<wxString, std::vector<wxString>>& a, |
|
|
|
const std::pair<wxString, std::vector<wxString>>& b ) |
|
|
|
{ |
|
|
|
return a.first.CmpNoCase( b.first ) < 0; |
|
|
|
} ); |
|
|
|
|
|
|
|
return false; |
|
|
|
}; |
|
|
|
for( const auto& alias : aliasList ) |
|
|
|
{ |
|
|
|
std::shared_ptr<BUS_ALIAS> entry = std::make_shared<BUS_ALIAS>(); |
|
|
|
|
|
|
|
SCH_SCREENS screens( aSchematic.Root() ); |
|
|
|
entry->SetName( alias.first ); |
|
|
|
entry->Members() = alias.second; |
|
|
|
|
|
|
|
// collect aliases from each open sheet
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) |
|
|
|
{ |
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() ) |
|
|
|
{ |
|
|
|
if( !contains( alias ) ) |
|
|
|
m_aliases.push_back( alias->Clone() ); |
|
|
|
} |
|
|
|
m_aliases.push_back( entry ); |
|
|
|
} |
|
|
|
|
|
|
|
int ii = 0; |
|
|
|
@ -142,7 +134,7 @@ void PANEL_SETUP_BUSES::loadAliases( const SCHEMATIC& aSchematic ) |
|
|
|
|
|
|
|
bool PANEL_SETUP_BUSES::TransferDataToWindow() |
|
|
|
{ |
|
|
|
loadAliases( m_frame->Schematic() ); |
|
|
|
loadAliases(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -159,13 +151,7 @@ bool PANEL_SETUP_BUSES::TransferDataFromWindow() |
|
|
|
// Associate the respective members with the last alias that is active.
|
|
|
|
updateAliasMembers( m_lastAlias ); |
|
|
|
|
|
|
|
SCH_SCREENS screens( m_frame->Schematic().Root() ); |
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) |
|
|
|
screen->ClearBusAliases(); |
|
|
|
|
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : m_aliases ) |
|
|
|
alias->GetParent()->AddBusAlias( alias ); |
|
|
|
m_frame->Schematic().SetBusAliases( m_aliases ); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
@ -179,8 +165,8 @@ void PANEL_SETUP_BUSES::OnAddAlias( wxCommandEvent& aEvent ) |
|
|
|
m_aliasesGrid->OnAddRow( |
|
|
|
[&]() -> std::pair<int, int> |
|
|
|
{ |
|
|
|
// New aliases get stored on the currently visible sheet
|
|
|
|
m_aliases.push_back( std::make_shared<BUS_ALIAS>( m_frame->GetScreen() ) ); |
|
|
|
// New aliases are stored at the project level
|
|
|
|
m_aliases.push_back( std::make_shared<BUS_ALIAS>() ); |
|
|
|
|
|
|
|
int row = m_aliasesGrid->GetNumberRows(); |
|
|
|
|
|
|
|
@ -285,8 +271,7 @@ void PANEL_SETUP_BUSES::OnAliasesGridCellChanging( wxGridEvent& event ) |
|
|
|
if( ii == event.GetRow() ) |
|
|
|
continue; |
|
|
|
|
|
|
|
if( name == m_aliasesGrid->GetCellValue( ii, 0 ) |
|
|
|
&& m_aliases[ row ]->GetParent() == m_aliases[ ii ]->GetParent() ) |
|
|
|
if( name == m_aliasesGrid->GetCellValue( ii, 0 ) ) |
|
|
|
{ |
|
|
|
m_errorMsg = wxString::Format( _( "Alias name '%s' already in use." ), name ); |
|
|
|
m_errorGrid = m_aliasesGrid; |
|
|
|
@ -357,12 +342,6 @@ void PANEL_SETUP_BUSES::doReloadMembersGrid() |
|
|
|
wxString source; |
|
|
|
wxString membersLabel; |
|
|
|
|
|
|
|
if( alias->GetParent() ) |
|
|
|
{ |
|
|
|
wxFileName sheet_name( alias->GetParent()->GetFileName() ); |
|
|
|
source.Printf( wxS( "(" ) + sheet_name.GetFullName() + wxS( ")" ) ); |
|
|
|
} |
|
|
|
|
|
|
|
membersLabel.Printf( m_membersLabelTemplate, m_lastAliasName ); |
|
|
|
|
|
|
|
m_source->SetLabel( source ); |
|
|
|
@ -483,13 +462,39 @@ void PANEL_SETUP_BUSES::OnUpdateUI( wxUpdateUIEvent& event ) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_BUSES::ImportSettingsFrom( const SCHEMATIC& aOtherSchematic ) |
|
|
|
void PANEL_SETUP_BUSES::ImportSettingsFrom( const std::map<wxString, std::vector<wxString>>& aAliases ) |
|
|
|
{ |
|
|
|
loadAliases( aOtherSchematic ); |
|
|
|
m_aliases.clear(); |
|
|
|
|
|
|
|
std::vector<std::pair<wxString, std::vector<wxString>>> aliasList( aAliases.begin(), |
|
|
|
aAliases.end() ); |
|
|
|
|
|
|
|
std::sort( aliasList.begin(), aliasList.end(), |
|
|
|
[]( const std::pair<wxString, std::vector<wxString>>& a, |
|
|
|
const std::pair<wxString, std::vector<wxString>>& b ) |
|
|
|
{ |
|
|
|
return a.first.CmpNoCase( b.first ) < 0; |
|
|
|
} ); |
|
|
|
|
|
|
|
for( const auto& alias : aliasList ) |
|
|
|
{ |
|
|
|
std::shared_ptr<BUS_ALIAS> entry = std::make_shared<BUS_ALIAS>(); |
|
|
|
|
|
|
|
entry->SetName( alias.first ); |
|
|
|
entry->Members() = alias.second; |
|
|
|
|
|
|
|
m_aliases.push_back( entry ); |
|
|
|
} |
|
|
|
|
|
|
|
int ii = 0; |
|
|
|
|
|
|
|
m_aliasesGrid->ClearRows(); |
|
|
|
m_aliasesGrid->AppendRows( m_aliases.size() ); |
|
|
|
|
|
|
|
// New aliases get stored on the currently visible sheet
|
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : m_aliases ) |
|
|
|
alias->SetParent( m_frame->GetScreen() ); |
|
|
|
m_aliasesGrid->SetCellValue( ii++, 0, alias->GetName() ); |
|
|
|
|
|
|
|
m_membersBook->SetSelection( 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|