Share more code.

This commit is contained in:
Jeff Young 2025-07-25 14:27:06 +01:00
parent 93d90962e5
commit 2dfacd648f
21 changed files with 421 additions and 709 deletions

View File

@ -148,47 +148,21 @@ void DIALOG_DESIGN_BLOCK_PROPERTIES::OnDeleteField( wxCommandEvent& event )
void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldUp( wxCommandEvent& event ) void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldUp( wxCommandEvent& event )
{ {
if( !m_fieldsGrid->CommitPendingChanges() ) m_fieldsGrid->OnMoveRowUp(
return; [&]( int row )
{
int row = m_fieldsGrid->GetGridCursorRow(); m_fieldsGrid->SwapRows( row, row - 1 );
} );
if( m_fieldsGrid->GetNumberRows() < 2 || row == 0 )
return;
// Swap the grid at row with the grid at row - 1
wxString temp0 = m_fieldsGrid->GetCellValue( row, 0 );
m_fieldsGrid->SetCellValue( row, 0, m_fieldsGrid->GetCellValue( row - 1, 0 ) );
m_fieldsGrid->SetCellValue( row - 1, 0, temp0 );
wxString temp1 = m_fieldsGrid->GetCellValue( row, 1 );
m_fieldsGrid->SetCellValue( row, 1, m_fieldsGrid->GetCellValue( row - 1, 1 ) );
m_fieldsGrid->SetCellValue( row - 1, 1, temp1 );
m_fieldsGrid->SetGridCursor( row - 1, 0 );
} }
void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldDown( wxCommandEvent& event ) void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldDown( wxCommandEvent& event )
{ {
if( !m_fieldsGrid->CommitPendingChanges() ) m_fieldsGrid->OnMoveRowUp(
return; [&]( int row )
{
int row = m_fieldsGrid->GetGridCursorRow(); m_fieldsGrid->SwapRows( row, row + 1 );
} );
if( m_fieldsGrid->GetNumberRows() < 2 || row == ( (int) m_fieldsGrid->GetNumberRows() - 1 ) )
return;
// Swap the grid at row with the grid at row + 1
wxString temp0 = m_fieldsGrid->GetCellValue( row, 0 );
m_fieldsGrid->SetCellValue( row, 0, m_fieldsGrid->GetCellValue( row + 1, 0 ) );
m_fieldsGrid->SetCellValue( row + 1, 0, temp0 );
wxString temp1 = m_fieldsGrid->GetCellValue( row, 1 );
m_fieldsGrid->SetCellValue( row, 1, m_fieldsGrid->GetCellValue( row + 1, 1 ) );
m_fieldsGrid->SetCellValue( row + 1, 1, temp1 );
m_fieldsGrid->SetGridCursor( row + 1, 0 );
} }

View File

@ -79,8 +79,7 @@ wxArrayString g_lineStyleNames;
PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRAW_FRAME* aFrame, PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRAW_FRAME* aFrame,
std::shared_ptr<NET_SETTINGS> aNetSettings, std::shared_ptr<NET_SETTINGS> aNetSettings,
const std::set<wxString>& aNetNames, const std::set<wxString>& aNetNames, bool aIsEEschema ) :
bool aIsEEschema ) :
PANEL_SETUP_NETCLASSES_BASE( aParentWindow ), PANEL_SETUP_NETCLASSES_BASE( aParentWindow ),
m_frame( aFrame ), m_frame( aFrame ),
m_isEEschema( aIsEEschema ), m_isEEschema( aIsEEschema ),
@ -198,7 +197,6 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
GRID_DIFF_PAIR_WIDTH, GRID_DIFF_PAIR_WIDTH,
GRID_DIFF_PAIR_GAP } ); GRID_DIFF_PAIR_GAP } );
// Be sure the column labels are readable // Be sure the column labels are readable
m_netclassGrid->EnsureColLabelsVisible(); m_netclassGrid->EnsureColLabelsVisible();
@ -378,19 +376,20 @@ void PANEL_SETUP_NETCLASSES::loadNetclasses()
void PANEL_SETUP_NETCLASSES::setNetclassRowNullableEditors( int aRowId, bool aIsDefault ) void PANEL_SETUP_NETCLASSES::setNetclassRowNullableEditors( int aRowId, bool aIsDefault )
{ {
// Set nullable editors // Set nullable editors
auto setCellEditor = [this, aRowId, aIsDefault]( int aCol ) auto setCellEditor =
{ [this, aRowId, aIsDefault]( int aCol )
GRID_CELL_MARK_AS_NULLABLE* cellEditor; {
GRID_CELL_MARK_AS_NULLABLE* cellEditor;
if( aIsDefault ) if( aIsDefault )
cellEditor = new GRID_CELL_MARK_AS_NULLABLE( false ); cellEditor = new GRID_CELL_MARK_AS_NULLABLE( false );
else else
cellEditor = new GRID_CELL_MARK_AS_NULLABLE( true ); cellEditor = new GRID_CELL_MARK_AS_NULLABLE( true );
wxGridCellAttr* attr = m_netclassGrid->GetOrCreateCellAttr( aRowId, aCol ); wxGridCellAttr* attr = m_netclassGrid->GetOrCreateCellAttr( aRowId, aCol );
attr->SetEditor( cellEditor ); attr->SetEditor( cellEditor );
attr->DecRef(); attr->DecRef();
}; };
setCellEditor( GRID_WIREWIDTH ); setCellEditor( GRID_WIREWIDTH );
setCellEditor( GRID_BUSWIDTH ); setCellEditor( GRID_BUSWIDTH );
@ -557,8 +556,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
} }
bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName, bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName, bool focusFirst )
bool focusFirst )
{ {
wxString tmp = aName; wxString tmp = aName;
@ -577,8 +575,8 @@ bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aNa
if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 ) if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
{ {
wxString msg = _( "Netclass name already in use." ); wxString msg = _( "Netclass name already in use." );
PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii,
focusFirst ? aRow : ii, GRID_NAME ); GRID_NAME );
return false; return false;
} }
} }
@ -769,38 +767,31 @@ void PANEL_SETUP_NETCLASSES::OnAddNetclassClick( wxCommandEvent& event )
void PANEL_SETUP_NETCLASSES::OnRemoveNetclassClick( wxCommandEvent& event ) void PANEL_SETUP_NETCLASSES::OnRemoveNetclassClick( wxCommandEvent& event )
{ {
if( !m_netclassGrid->CommitPendingChanges() ) m_netclassGrid->OnDeleteRows(
return; [&]( int row )
{
if( row == m_netclassGrid->GetNumberRows() - 1 )
{
DisplayErrorMessage( wxGetTopLevelParent( this ), _( "The default net class is required." ) );
return false;
}
int curRow = m_netclassGrid->GetGridCursorRow(); return true;
},
[&]( int row )
{
// reset the net class to default for members of the removed class
wxString classname = m_netclassGrid->GetCellValue( row, GRID_NAME );
if( curRow < 0 ) for( int assignment = 0; assignment < m_assignmentGrid->GetNumberRows(); ++assignment )
{ {
return; if( m_assignmentGrid->GetCellValue( assignment, 1 ) == classname )
} m_assignmentGrid->SetCellValue( assignment, 1, NETCLASS::Default );
else if( curRow == m_netclassGrid->GetNumberRows() - 1 ) }
{
wxWindow* topLevelParent = wxGetTopLevelParent( this );
DisplayErrorMessage( topLevelParent, _( "The default net class is required." ) ); m_netclassGrid->DeleteRows( row, 1 );
return; m_netclassesDirty = true;
} } );
// reset the net class to default for members of the removed class
wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
{
if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
}
m_netclassGrid->DeleteRows( curRow, 1 );
m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
m_netclassesDirty = true;
} }
@ -855,21 +846,11 @@ void PANEL_SETUP_NETCLASSES::OnAddAssignmentClick( wxCommandEvent& event )
void PANEL_SETUP_NETCLASSES::OnRemoveAssignmentClick( wxCommandEvent& event ) void PANEL_SETUP_NETCLASSES::OnRemoveAssignmentClick( wxCommandEvent& event )
{ {
if( !m_assignmentGrid->CommitPendingChanges() ) m_assignmentGrid->OnDeleteRows(
return; [&]( int row )
{
int curRow = m_assignmentGrid->GetGridCursorRow(); m_assignmentGrid->DeleteRows( row, 1 );
} );
if( curRow < 0 )
return;
m_assignmentGrid->DeleteRows( curRow, 1 );
if( m_assignmentGrid->GetNumberRows() > 0 )
{
m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
}
} }
@ -1008,79 +989,33 @@ void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTI
void PANEL_SETUP_NETCLASSES::OnMoveNetclassUpClick( wxCommandEvent& event ) void PANEL_SETUP_NETCLASSES::OnMoveNetclassUpClick( wxCommandEvent& event )
{ {
if( !m_netclassGrid->CommitPendingChanges() ) m_netclassGrid->OnMoveRowUp(
return; [&]( int row )
{
// Work out which rows are selected // Can't move the Default netclass
std::vector<int> selectedRows; return row != m_netclassGrid->GetNumberRows() - 1;
},
for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i ) [&]( int row )
{ {
if( m_netclassGrid->IsInSelection( i, 0 ) ) m_netclassGrid->SwapRows( row, row - 1 );
selectedRows.push_back( i ); m_netclassesDirty = true;
} } );
// Only move one row at a time
if( selectedRows.size() != 1 )
return;
// Can't move the first netclass, nor move the Default netclass
if( selectedRows[0] == 0 || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) )
return;
int newRowId = selectedRows[0] - 1;
m_netclassGrid->InsertRows( newRowId );
for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ )
m_netclassGrid->SetCellValue( newRowId, col, m_netclassGrid->GetCellValue( newRowId + 2, col ) );
// Set the row nullable editors
setNetclassRowNullableEditors( newRowId, false );
m_netclassGrid->DeleteRows( newRowId + 2, 1 );
m_netclassGrid->MakeCellVisible( newRowId, 0 );
m_netclassGrid->SetGridCursor( newRowId, 0 );
m_netclassesDirty = true;
} }
void PANEL_SETUP_NETCLASSES::OnMoveNetclassDownClick( wxCommandEvent& event ) void PANEL_SETUP_NETCLASSES::OnMoveNetclassDownClick( wxCommandEvent& event )
{ {
if( !m_netclassGrid->CommitPendingChanges() ) m_netclassGrid->OnMoveRowDown(
return; [&]( int row )
{
// Work out which rows are selected // Can't move the Default netclass
std::vector<int> selectedRows; return row + 1 != m_netclassGrid->GetNumberRows() - 1;
},
for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i ) [&]( int row )
{ {
if( m_netclassGrid->IsInSelection( i, 0 ) ) m_netclassGrid->SwapRows( row, row + 1 );
selectedRows.push_back( i ); m_netclassesDirty = true;
} } );
// Only move one row at a time
if( selectedRows.size() != 1 )
return;
// Can't move the last row down, nor move the Default netclass
if( selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 2 )
|| selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) )
{
return;
}
int newRowId = selectedRows[0] + 2;
m_netclassGrid->InsertRows( newRowId );
for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ )
m_netclassGrid->SetCellValue( newRowId, col, m_netclassGrid->GetCellValue( newRowId - 2, col ) );
m_netclassGrid->DeleteRows( newRowId - 2, 1 );
m_netclassGrid->MakeCellVisible( newRowId - 1, 0 );
m_netclassGrid->SetGridCursor( newRowId - 1, 0 );
m_netclassesDirty = true;
} }

View File

@ -309,8 +309,7 @@ void WX_GRID::EnableAlternateRowColors( bool aEnable )
{ {
wxGridTableBase* table = wxGrid::GetTable(); wxGridTableBase* table = wxGrid::GetTable();
wxCHECK_MSG( table, /* void */, wxCHECK_MSG( table, /* void */, "Tried to enable alternate row colors without a table assigned to the grid" );
"Tried to enable alternate row colors without a table assigned to the grid" );
if( aEnable ) if( aEnable )
{ {
@ -510,18 +509,6 @@ void WX_GRID::ShowHideColumns( const wxString& shownColumns )
} }
void WX_GRID::ShowHideColumns( const std::bitset<64>& aShownColumns )
{
for( int ii = 0; ii < GetNumberCols(); ++ ii )
{
if( aShownColumns[ii] )
ShowCol( ii );
else
HideCol( ii );
}
}
void WX_GRID::DrawCornerLabel( wxDC& dc ) void WX_GRID::DrawCornerLabel( wxDC& dc )
{ {
if( m_nativeColumnLabels ) if( m_nativeColumnLabels )
@ -745,6 +732,83 @@ void WX_GRID::OnDeleteRows( const std::function<bool( int row )>& aFilter,
} }
void WX_GRID::SwapRows( int aRowA, int aRowB )
{
for( int col = 0; col < GetNumberCols(); ++col )
{
wxString temp = GetCellValue( aRowA, col );
SetCellValue( aRowA, col, GetCellValue( aRowB, col ) );
SetCellValue( aRowB, col, temp );
}
}
void WX_GRID::OnMoveRowUp( const std::function<void( int row )>& aMover )
{
OnMoveRowUp(
[]( int row )
{
return true;
},
aMover );
}
void WX_GRID::OnMoveRowUp( const std::function<bool( int row )>& aFilter,
const std::function<void( int row )>& aMover )
{
if( !CommitPendingChanges() )
return;
int i = GetGridCursorRow();
if( i > 0 && aFilter( i ) )
{
aMover( i );
SetGridCursor( i - 1, GetGridCursorCol() );
MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
}
else
{
wxBell();
}
}
void WX_GRID::OnMoveRowDown( const std::function<void( int row )>& aMover )
{
OnMoveRowDown(
[]( int row )
{
return true;
},
aMover );
}
void WX_GRID::OnMoveRowDown( const std::function<bool( int row )>& aFilter,
const std::function<void( int row )>& aMover )
{
if( !CommitPendingChanges() )
return;
int i = GetGridCursorRow();
if( i + 1 < GetNumberRows() && aFilter( i ) )
{
aMover( i );
SetGridCursor( i + 1, GetGridCursorCol() );
MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
}
else
{
wxBell();
}
}
void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol ) void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol )
{ {
m_unitsProviders[ aCol ] = aProvider; m_unitsProviders[ aCol ] = aProvider;

View File

@ -42,8 +42,7 @@
#include <sch_commit.h> #include <sch_commit.h>
DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_LABEL_BASE* aLabel, DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_LABEL_BASE* aLabel, bool aNew ) :
bool aNew ) :
DIALOG_LABEL_PROPERTIES_BASE( aParent ), DIALOG_LABEL_PROPERTIES_BASE( aParent ),
m_Parent( aParent ), m_Parent( aParent ),
m_currentLabel( aLabel ), m_currentLabel( aLabel ),
@ -616,30 +615,19 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow()
if( m_shapeSizer->AreAnyItemsShown() ) if( m_shapeSizer->AreAnyItemsShown() )
{ {
if( m_bidirectional->GetValue() ) if( m_bidirectional->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); else if( m_input->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
else if( m_input->GetValue() ) else if( m_output->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); else if( m_triState->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
else if( m_output->GetValue() ) else if( m_passive->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); else if( m_dot->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT );
else if( m_triState->GetValue() ) else if( m_circle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND );
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE ); else if( m_diamond->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND );
else if( m_passive->GetValue() ) else if( m_rectangle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE );
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
else if( m_dot->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT );
else if( m_circle->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND );
else if( m_diamond->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND );
else if( m_rectangle->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE );
} }
if( m_fontCtrl->HaveFontSelection() ) if( m_fontCtrl->HaveFontSelection() )
{
m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) ); m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
}
if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T ) if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->SetPinLength( m_textSize.GetIntValue() ); static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->SetPinLength( m_textSize.GetIntValue() );
@ -825,49 +813,31 @@ void DIALOG_LABEL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
void DIALOG_LABEL_PROPERTIES::OnMoveUp( wxCommandEvent& event ) void DIALOG_LABEL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); return row > m_currentLabel->GetMandatoryFieldCount();
},
if( i > m_currentLabel->GetMandatoryFieldCount() ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_grid->ForceRefresh();
m_fields->insert( m_fields->begin() + i - 1, tmp ); } );
m_grid->ForceRefresh();
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
} }
void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); return row >= m_currentLabel->GetMandatoryFieldCount();
},
if( i >= m_currentLabel->GetMandatoryFieldCount() && i < m_grid->GetNumberRows() - 1 ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_grid->ForceRefresh();
m_fields->insert( m_fields->begin() + i + 1, tmp ); } );
m_grid->ForceRefresh();
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
} }

View File

@ -385,7 +385,6 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::Validate()
if( parentName.IsEmpty() ) if( parentName.IsEmpty() )
{ {
m_delayedErrorMessage = _( "Derived symbol must have a parent selected" ); m_delayedErrorMessage = _( "Derived symbol must have a parent selected" );
return false; return false;
} }
} }
@ -701,53 +700,33 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); return row > m_fields->GetMandatoryRowCount();
},
if( i > m_fields->GetMandatoryRowCount() ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_grid->ForceRefresh();
m_fields->insert( m_fields->begin() + i - 1, tmp ); OnModify();
m_grid->ForceRefresh(); } );
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
OnModify();
}
else
{
wxBell();
}
} }
void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowDown(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); return row >= m_fields->GetMandatoryRowCount();
},
if( i >= m_fields->GetMandatoryRowCount() && i + 1 < m_fields->GetNumberRows() ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_grid->ForceRefresh();
m_fields->insert( m_fields->begin() + i + 1, tmp ); OnModify();
m_grid->ForceRefresh(); } );
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
OnModify();
}
else
{
wxBell();
}
} }

View File

@ -760,49 +760,31 @@ void DIALOG_SHEET_PROPERTIES::OnDeleteField( wxCommandEvent& event )
void DIALOG_SHEET_PROPERTIES::OnMoveUp( wxCommandEvent& event ) void DIALOG_SHEET_PROPERTIES::OnMoveUp( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); return row > m_fields->GetMandatoryRowCount();
},
if( i > m_fields->GetMandatoryRowCount() ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_grid->ForceRefresh();
m_fields->insert( m_fields->begin() + i - 1, tmp ); } );
m_grid->ForceRefresh();
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
} }
void DIALOG_SHEET_PROPERTIES::OnMoveDown( wxCommandEvent& event ) void DIALOG_SHEET_PROPERTIES::OnMoveDown( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); return row >= m_fields->GetMandatoryRowCount();
},
if( i >= m_fields->GetMandatoryRowCount() && i < m_grid->GetNumberRows() - 1 ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_grid->ForceRefresh();
m_fields->insert( m_fields->begin() + i + 1, tmp ); } );
m_grid->ForceRefresh();
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
} }

View File

@ -898,53 +898,33 @@ void DIALOG_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
void DIALOG_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event ) void DIALOG_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
{ {
if( !m_fieldsGrid->CommitPendingChanges() ) m_fieldsGrid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_fieldsGrid->GetGridCursorRow(); return row > m_fields->GetMandatoryRowCount();
},
if( i > m_fields->GetMandatoryRowCount() ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_fieldsGrid->ForceRefresh();
m_fields->insert( m_fields->begin() + i - 1, tmp ); OnModify();
m_fieldsGrid->ForceRefresh(); } );
m_fieldsGrid->SetGridCursor( i - 1, m_fieldsGrid->GetGridCursorCol() );
m_fieldsGrid->MakeCellVisible( m_fieldsGrid->GetGridCursorRow(), m_fieldsGrid->GetGridCursorCol() );
OnModify();
}
else
{
wxBell();
}
} }
void DIALOG_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) void DIALOG_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
{ {
if( !m_fieldsGrid->CommitPendingChanges() ) m_fieldsGrid->OnMoveRowDown(
return; [&]( int row )
{
int i = m_fieldsGrid->GetGridCursorRow(); return row >= m_fields->GetMandatoryRowCount();
},
if( i >= m_fields->GetMandatoryRowCount() && i < m_fieldsGrid->GetNumberRows() - 1 ) [&]( int row )
{ {
SCH_FIELD tmp = m_fields->at( (unsigned) i ); std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); m_fieldsGrid->ForceRefresh();
m_fields->insert( m_fields->begin() + i + 1, tmp ); OnModify();
m_fieldsGrid->ForceRefresh(); } );
m_fieldsGrid->SetGridCursor( i + 1, m_fieldsGrid->GetGridCursorCol() );
m_fieldsGrid->MakeCellVisible( m_fieldsGrid->GetGridCursorRow(), m_fieldsGrid->GetGridCursorCol() );
OnModify();
}
else
{
wxBell();
}
} }

View File

@ -265,28 +265,18 @@ void PANEL_SETUP_BUSES::OnAddMember( wxCommandEvent& aEvent )
void PANEL_SETUP_BUSES::OnRemoveMember( wxCommandEvent& aEvent ) void PANEL_SETUP_BUSES::OnRemoveMember( wxCommandEvent& aEvent )
{ {
if( !m_membersGrid->CommitPendingChanges() ) m_membersGrid->OnDeleteRows(
return; [&]( int row )
{
m_membersGrid->DeleteRows( row, 1 );
int curRow = m_membersGrid->GetGridCursorRow(); // Update the member list of the current bus alias from the members grid
const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ m_lastAlias ];
alias->Members().clear();
if( curRow < 0 ) for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii )
return; alias->Members().push_back( m_membersGrid->GetCellValue( ii, 0 ) );
} );
m_membersGrid->DeleteRows( curRow, 1 );
// Update the member list of the current bus alias from the members grid
const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ m_lastAlias ];
alias->Members().clear();
for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii )
alias->Members().push_back( m_membersGrid->GetCellValue( ii, 0 ) );
if( m_membersGrid->GetNumberRows() > 0 )
{
m_membersGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
m_membersGrid->SelectRow( std::max( 0, curRow-1 ) );
}
} }

View File

@ -124,56 +124,23 @@ void PANEL_TEMPLATE_FIELDNAMES::OnDeleteButtonClick( wxCommandEvent& event )
} }
void swapRows( WX_GRID* aGrid, int aRowA, int aRowB )
{
for( int col = 0; col < aGrid->GetNumberCols(); ++col )
{
wxString temp = aGrid->GetCellValue( aRowA, col );
aGrid->SetCellValue( aRowA, col, aGrid->GetCellValue( aRowB, col ) );
aGrid->SetCellValue( aRowB, col, temp );
}
}
void PANEL_TEMPLATE_FIELDNAMES::OnMoveUp( wxCommandEvent& event ) void PANEL_TEMPLATE_FIELDNAMES::OnMoveUp( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowUp(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); m_grid->SwapRows( row, row - 1 );
} );
if( i > 0 )
{
swapRows( m_grid, i, i - 1 );
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
} }
void PANEL_TEMPLATE_FIELDNAMES::OnMoveDown( wxCommandEvent& event ) void PANEL_TEMPLATE_FIELDNAMES::OnMoveDown( wxCommandEvent& event )
{ {
if( !m_grid->CommitPendingChanges() ) m_grid->OnMoveRowDown(
return; [&]( int row )
{
int i = m_grid->GetGridCursorRow(); m_grid->SwapRows( row, row + 1 );
} );
if( i >= 0 && i + 1 < m_grid->GetNumberRows() )
{
swapRows( m_grid, i, i + 1 );
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
} }

View File

@ -92,11 +92,6 @@ public:
*/ */
void ShowHideColumns( const wxString& shownColumns ); void ShowHideColumns( const wxString& shownColumns );
/**
* A more performant version of ShowHideColumns (primarily for OnUpdateUI handlers).
*/
void ShowHideColumns( const std::bitset<64>& aShownColumns );
/** /**
* Hide wxGrid's SetTable() method with one which doesn't mess up the grid column * Hide wxGrid's SetTable() method with one which doesn't mess up the grid column
* widths when setting the table. * widths when setting the table.
@ -127,6 +122,17 @@ public:
void OnDeleteRows( const std::function<bool( int row )>& aFilter, void OnDeleteRows( const std::function<bool( int row )>& aFilter,
const std::function<void( int row )>& aDeleter ); const std::function<void( int row )>& aDeleter );
/**
* These aren't that tricky, but might as well share code.
*/
void SwapRows( int aRowA, int aRowB );
void OnMoveRowUp( const std::function<void( int row )>& aMover );
void OnMoveRowDown( const std::function<void( int row )>& aMover );
void OnMoveRowUp( const std::function<bool( int row )>& aFilter,
const std::function<void( int row )>& aMover );
void OnMoveRowDown( const std::function<bool( int row )>& aFilter,
const std::function<void( int row )>& aMover );
/** /**
* Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters. * Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.
* *

View File

@ -93,8 +93,8 @@ void DIALOG_MANAGE_REPOSITORIES::setColumnWidths()
void DIALOG_MANAGE_REPOSITORIES::OnAdd( wxCommandEvent& event ) void DIALOG_MANAGE_REPOSITORIES::OnAdd( wxCommandEvent& event )
{ {
wxTextEntryDialog entry_dialog( this, _( "Please enter fully qualified repository url" ), wxTextEntryDialog entry_dialog( this, _( "Fully qualified repository url:" ),
_( "Add repository" ) ); _( "Add Repository" ) );
if( entry_dialog.ShowModal() == wxID_OK ) if( entry_dialog.ShowModal() == wxID_OK )
{ {
@ -161,84 +161,32 @@ void DIALOG_MANAGE_REPOSITORIES::OnAddDefault( wxCommandEvent& event )
void DIALOG_MANAGE_REPOSITORIES::OnRemoveButtonClicked( wxCommandEvent& event ) void DIALOG_MANAGE_REPOSITORIES::OnRemoveButtonClicked( wxCommandEvent& event )
{ {
auto selectedRows = m_grid->GetSelectedRows(); m_grid->OnDeleteRows(
[&]( int row )
// If nothing is selected or multiple rows are selected don't do anything. {
if( selectedRows.size() != 1 ) m_grid->DeleteRows( row );
{ setColumnWidths();
wxBell(); } );
return;
}
int selectedRow = selectedRows[0];
m_grid->DeleteRows( selectedRow );
setColumnWidths();
if( m_grid->GetNumberRows() > 0 )
m_grid->SelectRow( selectedRow == m_grid->GetNumberRows() ? selectedRow - 1 : selectedRow );
} }
void DIALOG_MANAGE_REPOSITORIES::OnMoveUpButtonClicked( wxCommandEvent& event ) void DIALOG_MANAGE_REPOSITORIES::OnMoveUpButtonClicked( wxCommandEvent& event )
{ {
auto selectedRows = m_grid->GetSelectedRows(); m_grid->OnMoveRowUp(
[&]( int row )
// If nothing is selected or multiple rows are selected don't do anything. {
if( selectedRows.size() != 1 ) m_grid->SwapRows( row, row - 1 );
return; } );
int selectedRow = selectedRows[0];
// If first row is selected, then it can't go any further up.
if( selectedRow == 0 )
{
wxBell();
return;
}
swapRows( selectedRow, selectedRow - 1 );
selectRow( selectedRow - 1 );
} }
void DIALOG_MANAGE_REPOSITORIES::OnMoveDownButtonClicked( wxCommandEvent& event ) void DIALOG_MANAGE_REPOSITORIES::OnMoveDownButtonClicked( wxCommandEvent& event )
{ {
auto selectedRows = m_grid->GetSelectedRows(); m_grid->OnMoveRowDown(
[&]( int row )
// If nothing is selected or multiple rows are selected don't do anything. {
if( selectedRows.size() != 1 ) m_grid->SwapRows( row, row + 1 );
return; } );
int selectedRow = selectedRows[0];
// If last row is selected, then it can't go any further down.
if( selectedRow + 1 == m_grid->GetNumberRows() )
{
wxBell();
return;
}
swapRows( selectedRow, selectedRow + 1 );
selectRow( selectedRow + 1 );
}
void DIALOG_MANAGE_REPOSITORIES::swapRows( int aRowA, int aRowB )
{
m_grid->Freeze();
wxString tempStr;
for( int column = 0; column < m_grid->GetNumberCols(); column++ )
{
tempStr = m_grid->GetCellValue( aRowA, column );
m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
m_grid->SetCellValue( aRowB, column, tempStr );
}
m_grid->Thaw();
} }

View File

@ -53,7 +53,6 @@ public:
std::vector<std::pair<wxString, wxString>> GetData(); std::vector<std::pair<wxString, wxString>> GetData();
private: private:
void swapRows( int aRowA, int aRowB );
void selectRow( int aRow ); void selectRow( int aRow );
void setColumnWidths(); void setColumnWidths();
void addRepository( const wxString& aUrl ); void addRepository( const wxString& aUrl );

View File

@ -302,7 +302,7 @@ set( ZONE_MANAGER_SRCS
zone_manager/board_edges_bounding_item.cpp zone_manager/board_edges_bounding_item.cpp
zone_manager/dialog_zone_manager.cpp zone_manager/dialog_zone_manager.cpp
zone_manager/dialog_zone_manager_base.cpp zone_manager/dialog_zone_manager_base.cpp
zone_manager/model_zones_overview_table.cpp zone_manager/model_zones_overview.cpp
zone_manager/pane_zone_viewer.cpp zone_manager/pane_zone_viewer.cpp
zone_manager/panel_zone_gal.cpp zone_manager/panel_zone_gal.cpp
zone_manager/panel_zone_properties.cpp zone_manager/panel_zone_properties.cpp

View File

@ -67,8 +67,7 @@ void PLUGINS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
if( std::optional<const PLUGIN_ACTION*> action = mgr.GetAction( id ) ) if( std::optional<const PLUGIN_ACTION*> action = mgr.GetAction( id ) )
{ {
menu.Append( MYID_RECREATE_ENV, _( "Recreate Plugin Environment" ), menu.Append( MYID_RECREATE_ENV, _( "Recreate Plugin Environment" ), _( "Recreate Plugin Environment" ) );
_( "Recreate Plugin Environment" ) );
menu.AppendSeparator(); menu.AppendSeparator();
} }
#endif #endif
@ -87,9 +86,7 @@ void PLUGINS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
PANEL_PCBNEW_ACTION_PLUGINS::COLUMN_SETTINGS_IDENTIFIER ); PANEL_PCBNEW_ACTION_PLUGINS::COLUMN_SETTINGS_IDENTIFIER );
if( std::optional<const PLUGIN_ACTION*> action = mgr.GetAction( id ) ) if( std::optional<const PLUGIN_ACTION*> action = mgr.GetAction( id ) )
{
mgr.RecreatePluginEnvironment( ( *action )->plugin.Identifier() ); mgr.RecreatePluginEnvironment( ( *action )->plugin.Identifier() );
}
#endif #endif
} }
else else
@ -135,45 +132,21 @@ void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow( int aRow )
void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick( wxCommandEvent& event ) void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick( wxCommandEvent& event )
{ {
auto selectedRows = m_grid->GetSelectedRows(); m_grid->OnMoveRowUp(
[&]( int row )
// If nothing is selected or multiple rows are selected don't do anything. {
if( selectedRows.size() != 1 ) return; SwapRows( row, row - 1 );
} );
int selectedRow = selectedRows[0];
// If first row is selected, then it can't go any further up.
if( selectedRow == 0 )
{
wxBell();
return;
}
SwapRows( selectedRow, selectedRow - 1 );
SelectRow( selectedRow - 1 );
} }
void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick( wxCommandEvent& event ) void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick( wxCommandEvent& event )
{ {
auto selectedRows = m_grid->GetSelectedRows(); m_grid->OnMoveRowDown(
[&]( int row )
// If nothing is selected or multiple rows are selected don't do anything. {
if( selectedRows.size() != 1 ) return; SwapRows( row, row + 1 );
} );
int selectedRow = selectedRows[0];
// If last row is selected, then it can't go any further down.
if( selectedRow + 1 == m_grid->GetNumberRows() )
{
wxBell();
return;
}
SwapRows( selectedRow, selectedRow + 1 );
SelectRow( selectedRow + 1 );
} }
@ -181,19 +154,11 @@ void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows( int aRowA, int aRowB )
{ {
m_grid->Freeze(); m_grid->Freeze();
wxString tempStr; m_grid->SwapRows( aRowA, aRowB );
for( int column = 0; column < m_grid->GetNumberCols(); column++ )
{
tempStr = m_grid->GetCellValue( aRowA, column );
m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
m_grid->SetCellValue( aRowB, column, tempStr );
}
// Swap icon column renderers // Swap icon column renderers
auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ACTION_NAME ); auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ACTION_NAME );
m_grid->SetCellRenderer( aRowA, COLUMN_ACTION_NAME, m_grid->SetCellRenderer( aRowA, COLUMN_ACTION_NAME, m_grid->GetCellRenderer( aRowB, COLUMN_ACTION_NAME ) );
m_grid->GetCellRenderer( aRowB, COLUMN_ACTION_NAME ) );
m_grid->SetCellRenderer( aRowB, COLUMN_ACTION_NAME, cellRenderer ); m_grid->SetCellRenderer( aRowB, COLUMN_ACTION_NAME, cellRenderer );
m_grid->Thaw(); m_grid->Thaw();
@ -261,8 +226,7 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
m_grid->ClearRows(); m_grid->ClearRows();
const std::vector<LEGACY_OR_API_PLUGIN>& orderedPlugins = const std::vector<LEGACY_OR_API_PLUGIN>& orderedPlugins = PCB_EDIT_FRAME::GetOrderedActionPlugins();
PCB_EDIT_FRAME::GetOrderedActionPlugins();
m_grid->AppendRows( orderedPlugins.size() ); m_grid->AppendRows( orderedPlugins.size() );
int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size; int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
@ -276,9 +240,8 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
// Icon // Icon
m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME, m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME,
new GRID_CELL_ICON_TEXT_RENDERER( ap->iconBitmap.IsOk() new GRID_CELL_ICON_TEXT_RENDERER( ap->iconBitmap.IsOk() ? wxBitmapBundle( ap->iconBitmap )
? wxBitmapBundle( ap->iconBitmap ) : m_genericIcon,
: m_genericIcon,
iconSize ) ); iconSize ) );
m_grid->SetCellValue( row, COLUMN_ACTION_NAME, ap->GetName() ); m_grid->SetCellValue( row, COLUMN_ACTION_NAME, ap->GetName() );
m_grid->SetCellValue( row, COLUMN_SETTINGS_IDENTIFIER, ap->GetPluginPath() ); m_grid->SetCellValue( row, COLUMN_SETTINGS_IDENTIFIER, ap->GetPluginPath() );
@ -300,9 +263,8 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
#ifdef KICAD_IPC_API #ifdef KICAD_IPC_API
auto action = std::get<const PLUGIN_ACTION*>( orderedPlugins[row] ); auto action = std::get<const PLUGIN_ACTION*>( orderedPlugins[row] );
const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark
? action->icon_dark : action->icon_light;
: action->icon_light;
// Icon // Icon
m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME, new GRID_CELL_ICON_TEXT_RENDERER( m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME, new GRID_CELL_ICON_TEXT_RENDERER(
@ -314,8 +276,7 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() ); m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER ); m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( action->identifier, bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( action->identifier, action->show_button );
action->show_button );
m_grid->SetCellValue( row, COLUMN_VISIBLE, show ? wxT( "1" ) : wxEmptyString ); m_grid->SetCellValue( row, COLUMN_VISIBLE, show ? wxT( "1" ) : wxEmptyString );

View File

@ -135,6 +135,9 @@ PANEL_SETUP_TRACKS_AND_VIAS::~PANEL_SETUP_TRACKS_AND_VIAS()
void PANEL_SETUP_TRACKS_AND_VIAS::OnSortTrackWidthsClick( wxCommandEvent& aEvent ) void PANEL_SETUP_TRACKS_AND_VIAS::OnSortTrackWidthsClick( wxCommandEvent& aEvent )
{ {
if( m_trackWidthsGrid->GetNumberRows() < 2 )
return;
std::vector<int> trackWidths; std::vector<int> trackWidths;
wxString msg; wxString msg;
@ -161,6 +164,9 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnSortTrackWidthsClick( wxCommandEvent& aEvent
void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent ) void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent )
{ {
if( m_viaSizesGrid->GetNumberRows() < 2 )
return;
std::vector<VIA_DIMENSION> vias; std::vector<VIA_DIMENSION> vias;
wxString msg; wxString msg;
@ -197,6 +203,9 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent )
void PANEL_SETUP_TRACKS_AND_VIAS::OnSortDiffPairsClick( wxCommandEvent& aEvent ) void PANEL_SETUP_TRACKS_AND_VIAS::OnSortDiffPairsClick( wxCommandEvent& aEvent )
{ {
if( m_diffPairsGrid->GetNumberRows() < 2 )
return;
wxString msg; wxString msg;
std::vector<DIFF_PAIR_DIMENSION> diffPairs; std::vector<DIFF_PAIR_DIMENSION> diffPairs;
@ -283,12 +292,8 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataToWindow()
bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow() bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow()
{ {
if( !m_trackWidthsGrid->CommitPendingChanges() if( !commitPendingChanges() )
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
return false; return false;
}
std::vector<int> trackWidths; std::vector<int> trackWidths;
std::vector<VIA_DIMENSION> vias; std::vector<VIA_DIMENSION> vias;
@ -353,14 +358,18 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow()
} }
bool PANEL_SETUP_TRACKS_AND_VIAS::commitPendingChanges( bool aQuietMode )
{
return m_trackWidthsGrid->CommitPendingChanges( aQuietMode )
&& m_viaSizesGrid->CommitPendingChanges( aQuietMode )
&& m_diffPairsGrid->CommitPendingChanges( aQuietMode );
}
bool PANEL_SETUP_TRACKS_AND_VIAS::Validate() bool PANEL_SETUP_TRACKS_AND_VIAS::Validate()
{ {
if( !m_trackWidthsGrid->CommitPendingChanges() if( !commitPendingChanges() )
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
return false; return false;
}
wxString msg; wxString msg;
@ -447,12 +456,8 @@ void removeSelectedRows( WX_GRID* aGrid )
void PANEL_SETUP_TRACKS_AND_VIAS::OnAddTrackWidthsClick( wxCommandEvent& aEvent ) void PANEL_SETUP_TRACKS_AND_VIAS::OnAddTrackWidthsClick( wxCommandEvent& aEvent )
{ {
if( !m_trackWidthsGrid->CommitPendingChanges() if( !commitPendingChanges() )
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
return; return;
}
AppendTrackWidth( 0 ); AppendTrackWidth( 0 );
@ -472,12 +477,8 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveTrackWidthsClick( wxCommandEvent& even
void PANEL_SETUP_TRACKS_AND_VIAS::OnAddViaSizesClick( wxCommandEvent& event ) void PANEL_SETUP_TRACKS_AND_VIAS::OnAddViaSizesClick( wxCommandEvent& event )
{ {
if( !m_trackWidthsGrid->CommitPendingChanges() if( !commitPendingChanges() )
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
return; return;
}
AppendViaSize( 0, 0 ); AppendViaSize( 0, 0 );
@ -497,12 +498,8 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveViaSizesClick( wxCommandEvent& event )
void PANEL_SETUP_TRACKS_AND_VIAS::OnAddDiffPairsClick( wxCommandEvent& event ) void PANEL_SETUP_TRACKS_AND_VIAS::OnAddDiffPairsClick( wxCommandEvent& event )
{ {
if( !m_trackWidthsGrid->CommitPendingChanges() if( !commitPendingChanges() )
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
return; return;
}
AppendDiffPairs( 0, 0, 0 ); AppendDiffPairs( 0, 0, 0 );
@ -522,9 +519,7 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveDiffPairsClick( wxCommandEvent& event
void PANEL_SETUP_TRACKS_AND_VIAS::ImportSettingsFrom( BOARD* aBoard ) void PANEL_SETUP_TRACKS_AND_VIAS::ImportSettingsFrom( BOARD* aBoard )
{ {
m_trackWidthsGrid->CommitPendingChanges( true ); commitPendingChanges( true );
m_viaSizesGrid->CommitPendingChanges( true );
m_diffPairsGrid->CommitPendingChanges( true );
// Note: do not change the board, as we need to get the current nets from it for // Note: do not change the board, as we need to get the current nets from it for
// netclass memberships. All the netclass definitions and dimension lists are in // netclass memberships. All the netclass definitions and dimension lists are in

View File

@ -66,6 +66,8 @@ protected:
void AppendViaSize( int aSize, int aDrill ); void AppendViaSize( int aSize, int aDrill );
void AppendDiffPairs( int aWidth, int aGap, int aViaGap ); void AppendDiffPairs( int aWidth, int aGap, int aViaGap );
bool commitPendingChanges( bool aQuietMode = false );
private: private:
PCB_EDIT_FRAME* m_Frame; PCB_EDIT_FRAME* m_Frame;
BOARD* m_Pcb; BOARD* m_Pcb;

View File

@ -43,12 +43,12 @@
#include <zone_filler.h> #include <zone_filler.h>
#include "dialog_zone_manager_base.h" #include "dialog_zone_manager_base.h"
#include "model_zones_overview_table.h" #include "model_zones_overview.h"
#include "panel_zone_properties.h" #include "panel_zone_properties.h"
#include "dialog_zone_manager.h" #include "dialog_zone_manager.h"
#include "widgets/wx_progress_reporters.h" #include "widgets/wx_progress_reporters.h"
#include "zone_management_base.h" #include "zone_management_base.h"
#include "zone_manager/model_zones_overview_table.h" #include "zone_manager/model_zones_overview.h"
#include "zone_manager/panel_zone_gal.h" #include "zone_manager/panel_zone_gal.h"
#include "zone_manager/zone_manager_preference.h" #include "zone_manager/zone_manager_preference.h"
#include "zones_container.h" #include "zones_container.h"
@ -82,17 +82,17 @@ DIALOG_ZONE_MANAGER::DIALOG_ZONE_MANAGER( PCB_BASE_FRAME* aParent, ZONE_SETTINGS
m_checkRepour->SetValue( ZONE_MANAGER_PREFERENCE::GetRepourOnClose() ); m_checkRepour->SetValue( ZONE_MANAGER_PREFERENCE::GetRepourOnClose() );
//m_zoneViewer->SetId( ZONE_VIEWER ); //m_zoneViewer->SetId( ZONE_VIEWER );
for( const auto& [k, v] : MODEL_ZONES_OVERVIEW_TABLE::GetColumnNames() ) for( const auto& [k, v] : MODEL_ZONES_OVERVIEW::GetColumnNames() )
{ {
if( k == MODEL_ZONES_OVERVIEW_TABLE::LAYERS ) if( k == MODEL_ZONES_OVERVIEW::LAYERS )
m_viewZonesOverview->AppendIconTextColumn( v, k ); m_viewZonesOverview->AppendIconTextColumn( v, k );
else else
m_viewZonesOverview->AppendTextColumn( v, k ); m_viewZonesOverview->AppendTextColumn( v, k );
} }
m_modelZoneOverviewTable = new MODEL_ZONES_OVERVIEW_TABLE( m_zonesContainer->GetManagedZones(), m_modelZonesOverview = new MODEL_ZONES_OVERVIEW( m_zonesContainer->GetManagedZones(), aParent->GetBoard(),
aParent->GetBoard(), aParent, this ); aParent, this );
m_viewZonesOverview->AssociateModel( m_modelZoneOverviewTable.get() ); m_viewZonesOverview->AssociateModel( m_modelZonesOverview.get() );
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
m_viewZonesOverview->EnableDragSource( wxDF_UNICODETEXT ); m_viewZonesOverview->EnableDragSource( wxDF_UNICODETEXT );
@ -115,8 +115,8 @@ DIALOG_ZONE_MANAGER::DIALOG_ZONE_MANAGER( PCB_BASE_FRAME* aParent, ZONE_SETTINGS
}, },
m_zoneViewer->GetId() ); m_zoneViewer->GetId() );
if( m_modelZoneOverviewTable->GetCount() ) if( m_modelZonesOverview->GetCount() )
SelectZoneTableItem( m_modelZoneOverviewTable->GetItem( 0 ) ); SelectZoneTableItem( m_modelZonesOverview->GetItem( 0 ) );
Layout(); Layout();
m_MainBoxSizer->Fit( this ); m_MainBoxSizer->Fit( this );
@ -137,7 +137,7 @@ void DIALOG_ZONE_MANAGER::FitCanvasToScreen()
} }
void DIALOG_ZONE_MANAGER::PostProcessZoneViewSelectionChange( wxDataViewItem const& aItem ) void DIALOG_ZONE_MANAGER::PostProcessZoneViewSelChange( wxDataViewItem const& aItem )
{ {
bool textCtrlHasFocus = m_filterCtrl->HasFocus(); bool textCtrlHasFocus = m_filterCtrl->HasFocus();
long filterInsertPos = m_filterCtrl->GetInsertionPoint(); long filterInsertPos = m_filterCtrl->GetInsertionPoint();
@ -149,12 +149,12 @@ void DIALOG_ZONE_MANAGER::PostProcessZoneViewSelectionChange( wxDataViewItem con
} }
else else
{ {
if( m_modelZoneOverviewTable->GetCount() ) if( m_modelZonesOverview->GetCount() )
{ {
wxDataViewItem first_item = m_modelZoneOverviewTable->GetItem( 0 ); wxDataViewItem first_item = m_modelZonesOverview->GetItem( 0 );
m_viewZonesOverview->Select( first_item ); m_viewZonesOverview->Select( first_item );
m_viewZonesOverview->EnsureVisible( first_item ); m_viewZonesOverview->EnsureVisible( first_item );
m_zoneViewer->ActivateSelectedZone( m_modelZoneOverviewTable->GetZone( first_item ) ); m_zoneViewer->ActivateSelectedZone( m_modelZonesOverview->GetZone( first_item ) );
} }
else else
{ {
@ -216,11 +216,8 @@ void DIALOG_ZONE_MANAGER::OnZoneSelectionChanged( ZONE* zone )
{ {
wxWindowUpdateLocker updateLock( this ); wxWindowUpdateLocker updateLock( this );
for( ZONE_SELECTION_CHANGE_NOTIFIER* i : m_panelZoneProperties->OnZoneSelectionChanged( zone );
std::list<ZONE_SELECTION_CHANGE_NOTIFIER*>{ m_panelZoneProperties, m_zoneViewer } ) m_zoneViewer->OnZoneSelectionChanged( zone );
{
i->OnZoneSelectionChanged( zone );
}
Layout(); Layout();
} }
@ -240,7 +237,7 @@ void DIALOG_ZONE_MANAGER::OnDataViewCtrlSelectionChanged( wxDataViewEvent& aEven
void DIALOG_ZONE_MANAGER::SelectZoneTableItem( wxDataViewItem const& aItem ) void DIALOG_ZONE_MANAGER::SelectZoneTableItem( wxDataViewItem const& aItem )
{ {
ZONE* zone = m_modelZoneOverviewTable->GetZone( aItem ); ZONE* zone = m_modelZonesOverview->GetZone( aItem );
if( !zone ) if( !zone )
return; return;
@ -251,11 +248,8 @@ void DIALOG_ZONE_MANAGER::SelectZoneTableItem( wxDataViewItem const& aItem )
void DIALOG_ZONE_MANAGER::OnOk( wxCommandEvent& aEvt ) void DIALOG_ZONE_MANAGER::OnOk( wxCommandEvent& aEvt )
{ {
for( ZONE_MANAGEMENT_BASE* zone_management : m_panelZoneProperties->OnUserConfirmChange();
std::list<ZONE_MANAGEMENT_BASE*>{ m_panelZoneProperties, m_zonesContainer.get() } ) m_zonesContainer->OnUserConfirmChange();
{
zone_management->OnUserConfirmChange();
}
if( m_zoneInfo ) if( m_zoneInfo )
{ {
@ -284,7 +278,7 @@ void DIALOG_ZONE_MANAGER::OnBeginDrag( wxDataViewEvent& aEvent )
const wxDataViewItem it = aEvent.GetItem(); const wxDataViewItem it = aEvent.GetItem();
if( it.IsOk() ) if( it.IsOk() )
m_priorityDragIndex = m_modelZoneOverviewTable->GetRow( it ); m_priorityDragIndex = m_modelZonesOverview->GetRow( it );
} }
@ -313,13 +307,13 @@ void DIALOG_ZONE_MANAGER::OnDrop( wxDataViewEvent& aEvent )
return; return;
} }
unsigned int drop_index = m_modelZoneOverviewTable->GetRow( it ); unsigned int drop_index = m_modelZonesOverview->GetRow( it );
const std::optional<unsigned> rtn = const std::optional<unsigned> rtn = m_modelZonesOverview->SwapZonePriority( *m_priorityDragIndex, drop_index );
m_modelZoneOverviewTable->SwapZonePriority( *m_priorityDragIndex, drop_index );
if( rtn.has_value() ) if( rtn.has_value() )
{ {
const wxDataViewItem item = m_modelZoneOverviewTable->GetItem( *rtn ); const wxDataViewItem item = m_modelZonesOverview->GetItem( *rtn );
if( item.IsOk() ) if( item.IsOk() )
m_viewZonesOverview->Select( item ); m_viewZonesOverview->Select( item );
} }
@ -342,32 +336,31 @@ void DIALOG_ZONE_MANAGER::OnMoveDownClick( wxCommandEvent& aEvent )
void DIALOG_ZONE_MANAGER::OnFilterCtrlCancel( wxCommandEvent& aEvent ) void DIALOG_ZONE_MANAGER::OnFilterCtrlCancel( wxCommandEvent& aEvent )
{ {
PostProcessZoneViewSelectionChange( PostProcessZoneViewSelChange( m_modelZonesOverview->ClearFilter( m_viewZonesOverview->GetSelection() ) );
m_modelZoneOverviewTable->ClearFilter( m_viewZonesOverview->GetSelection() ) );
aEvent.Skip(); aEvent.Skip();
} }
void DIALOG_ZONE_MANAGER::OnFilterCtrlSearch( wxCommandEvent& aEvent ) void DIALOG_ZONE_MANAGER::OnFilterCtrlSearch( wxCommandEvent& aEvent )
{ {
PostProcessZoneViewSelectionChange( m_modelZoneOverviewTable->ApplyFilter( PostProcessZoneViewSelChange( m_modelZonesOverview->ApplyFilter( aEvent.GetString(),
aEvent.GetString(), m_viewZonesOverview->GetSelection() ) ); m_viewZonesOverview->GetSelection() ) );
aEvent.Skip(); aEvent.Skip();
} }
void DIALOG_ZONE_MANAGER::OnFilterCtrlTextChange( wxCommandEvent& aEvent ) void DIALOG_ZONE_MANAGER::OnFilterCtrlTextChange( wxCommandEvent& aEvent )
{ {
PostProcessZoneViewSelectionChange( m_modelZoneOverviewTable->ApplyFilter( PostProcessZoneViewSelChange( m_modelZonesOverview->ApplyFilter( aEvent.GetString(),
aEvent.GetString(), m_viewZonesOverview->GetSelection() ) ); m_viewZonesOverview->GetSelection() ) );
aEvent.Skip(); aEvent.Skip();
} }
void DIALOG_ZONE_MANAGER::OnFilterCtrlEnter( wxCommandEvent& aEvent ) void DIALOG_ZONE_MANAGER::OnFilterCtrlEnter( wxCommandEvent& aEvent )
{ {
PostProcessZoneViewSelectionChange( m_modelZoneOverviewTable->ApplyFilter( PostProcessZoneViewSelChange( m_modelZonesOverview->ApplyFilter( aEvent.GetString(),
aEvent.GetString(), m_viewZonesOverview->GetSelection() ) ); m_viewZonesOverview->GetSelection() ) );
aEvent.Skip(); aEvent.Skip();
} }
@ -429,8 +422,7 @@ void DIALOG_ZONE_MANAGER::OnZoneNameUpdate( wxCommandEvent& aEvent )
if( ZONE* zone = m_panelZoneProperties->GetZone(); zone != nullptr ) if( ZONE* zone = m_panelZoneProperties->GetZone(); zone != nullptr )
{ {
zone->SetZoneName( aEvent.GetString() ); zone->SetZoneName( aEvent.GetString() );
m_modelZoneOverviewTable->RowChanged( m_modelZoneOverviewTable->GetRow( m_modelZonesOverview->RowChanged( m_modelZonesOverview->GetRow( m_modelZonesOverview->GetItemByZone( zone ) ) );
m_modelZoneOverviewTable->GetItemByZone( zone ) ) );
} }
} }
@ -440,7 +432,7 @@ void DIALOG_ZONE_MANAGER::OnZonesTableRowCountChange( wxCommandEvent& aEvent )
unsigned count = aEvent.GetInt(); unsigned count = aEvent.GetInt();
for( STD_BITMAP_BUTTON* btn : { m_btnMoveDown, m_btnMoveUp } ) for( STD_BITMAP_BUTTON* btn : { m_btnMoveDown, m_btnMoveUp } )
btn->Enable( count == m_modelZoneOverviewTable->GetAllZonesCount() ); btn->Enable( count == m_modelZonesOverview->GetAllZonesCount() );
} }
@ -449,19 +441,12 @@ void DIALOG_ZONE_MANAGER::OnCheckBoxClicked( wxCommandEvent& aEvent )
const wxObject* sender = aEvent.GetEventObject(); const wxObject* sender = aEvent.GetEventObject();
if( aEvent.GetEventObject() == m_checkName ) if( aEvent.GetEventObject() == m_checkName )
{ m_modelZonesOverview->EnableFitterByName( aEvent.IsChecked() );
m_modelZoneOverviewTable->EnableFitterByName( aEvent.IsChecked() );
}
else if( aEvent.GetEventObject() == m_checkNet ) else if( aEvent.GetEventObject() == m_checkNet )
{ m_modelZonesOverview->EnableFitterByNet( aEvent.IsChecked() );
m_modelZoneOverviewTable->EnableFitterByNet( aEvent.IsChecked() );
}
if( ( sender == m_checkName || sender == m_checkNet ) && !m_filterCtrl->IsEmpty() ) if( ( sender == m_checkName || sender == m_checkNet ) && !m_filterCtrl->IsEmpty() )
{ m_modelZonesOverview->ApplyFilter( m_filterCtrl->GetValue(), m_viewZonesOverview->GetSelection() );
m_modelZoneOverviewTable->ApplyFilter( m_filterCtrl->GetValue(),
m_viewZonesOverview->GetSelection() );
}
} }
@ -475,13 +460,12 @@ void DIALOG_ZONE_MANAGER::MoveSelectedZonePriority( ZONE_INDEX_MOVEMENT aMove )
if( !selectedItem.IsOk() ) if( !selectedItem.IsOk() )
return; return;
const unsigned int selectedRow = m_modelZoneOverviewTable->GetRow( selectedItem ); const unsigned int selectedRow = m_modelZonesOverview->GetRow( selectedItem );
const std::optional<unsigned> new_index = const std::optional<unsigned> new_index = m_modelZonesOverview->MoveZoneIndex( selectedRow, aMove );
m_modelZoneOverviewTable->MoveZoneIndex( selectedRow, aMove );
if( new_index.has_value() ) if( new_index.has_value() )
{ {
wxDataViewItem new_item = m_modelZoneOverviewTable->GetItem( *new_index ); wxDataViewItem new_item = m_modelZonesOverview->GetItem( *new_index );
PostProcessZoneViewSelectionChange( new_item ); PostProcessZoneViewSelChange( new_item );
} }
} }

View File

@ -47,7 +47,7 @@
class PANEL_ZONE_PROPERTIES; class PANEL_ZONE_PROPERTIES;
class MODEL_ZONES_PRIORITY_LIST; class MODEL_ZONES_PRIORITY_LIST;
class MODEL_ZONES_OVERVIEW_TABLE; class MODEL_ZONES_OVERVIEW;
class MODEL_ZONE_LAYERS_LIST; class MODEL_ZONE_LAYERS_LIST;
class ZONES_CONTAINER; class ZONES_CONTAINER;
class PANE_ZONE_VIEWER; class PANE_ZONE_VIEWER;
@ -100,7 +100,7 @@ protected:
void OnRepourCheck( wxCommandEvent& aEvent ) override; void OnRepourCheck( wxCommandEvent& aEvent ) override;
void OnUpdateDisplayedZonesClick( wxCommandEvent& aEvent ) override; void OnUpdateDisplayedZonesClick( wxCommandEvent& aEvent ) override;
void PostProcessZoneViewSelectionChange( wxDataViewItem const& item ); void PostProcessZoneViewSelChange( wxDataViewItem const& aItem );
void OnTableChar( wxKeyEvent& event ) override; void OnTableChar( wxKeyEvent& event ) override;
void OnTableCharHook( wxKeyEvent& event ) override; void OnTableCharHook( wxKeyEvent& event ) override;
@ -113,17 +113,17 @@ private:
void FitCanvasToScreen(); void FitCanvasToScreen();
private: private:
PCB_BASE_FRAME* m_pcbFrame; PCB_BASE_FRAME* m_pcbFrame;
ZONE_SETTINGS* m_zoneInfo; ZONE_SETTINGS* m_zoneInfo;
std::unique_ptr<ZONES_CONTAINER> m_zonesContainer; std::unique_ptr<ZONES_CONTAINER> m_zonesContainer;
PANEL_ZONE_PROPERTIES* m_panelZoneProperties; PANEL_ZONE_PROPERTIES* m_panelZoneProperties;
wxObjectDataPtr<MODEL_ZONES_OVERVIEW_TABLE> m_modelZoneOverviewTable; wxObjectDataPtr<MODEL_ZONES_OVERVIEW> m_modelZonesOverview;
PANE_ZONE_VIEWER* m_zoneViewer; PANE_ZONE_VIEWER* m_zoneViewer;
std::optional<unsigned> m_priorityDragIndex; std::optional<unsigned> m_priorityDragIndex;
std::unique_ptr<ZONE_FILLER> m_filler; std::unique_ptr<ZONE_FILLER> m_filler;
bool m_needZoomGAL; bool m_needZoomGAL;
bool m_isFillingZones; bool m_isFillingZones;
bool m_zoneFillComplete; bool m_zoneFillComplete;
}; };
#endif #endif

View File

@ -36,7 +36,7 @@
*/ */
class MANAGED_ZONE : public ZONE_MANAGEMENT_BASE class MANAGED_ZONE : public ZONE_MANAGEMENT_BASE
{ {
friend class MODEL_ZONES_OVERVIEW_TABLE; friend class MODEL_ZONES_OVERVIEW;
public: public:
MANAGED_ZONE( std::shared_ptr<ZONE> aZone, unsigned aInitialIndex ) : MANAGED_ZONE( std::shared_ptr<ZONE> aZone, unsigned aInitialIndex ) :

View File

@ -32,11 +32,11 @@
#include <wx/variant.h> #include <wx/variant.h>
#include "zone_manager_preference.h" #include "zone_manager_preference.h"
#include "managed_zone.h" #include "managed_zone.h"
#include "model_zones_overview_table.h" #include "model_zones_overview.h"
wxDEFINE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent ); wxDEFINE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent );
void MODEL_ZONES_OVERVIEW_TABLE::SortZoneContainers() void MODEL_ZONES_OVERVIEW::SortZoneContainers()
{ {
std::sort( m_filteredZones.begin(), m_filteredZones.end(), std::sort( m_filteredZones.begin(), m_filteredZones.end(),
[]( std::shared_ptr<MANAGED_ZONE> const& l, std::shared_ptr<MANAGED_ZONE> const& r ) []( std::shared_ptr<MANAGED_ZONE> const& l, std::shared_ptr<MANAGED_ZONE> const& r )
@ -46,7 +46,7 @@ void MODEL_ZONES_OVERVIEW_TABLE::SortZoneContainers()
} }
void MODEL_ZONES_OVERVIEW_TABLE::OnRowCountChange() void MODEL_ZONES_OVERVIEW::OnRowCountChange()
{ {
wxCommandEvent rowCountChange( EVT_ZONES_OVERVIEW_COUNT_CHANGE ); wxCommandEvent rowCountChange( EVT_ZONES_OVERVIEW_COUNT_CHANGE );
rowCountChange.SetInt( GetCount() ); rowCountChange.SetInt( GetCount() );
@ -69,13 +69,8 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s
if( layer_cout > 4 ) if( layer_cout > 4 )
{ {
for( const PCB_LAYER_ID& i : { layers[0], for( const PCB_LAYER_ID& i : { layers[0], layers[1], layers[layer_cout - 1], layers[layer_cout - 2] } )
layers[1],
layers[layer_cout - 1],
layers[layer_cout - 2] } )
{
layersToDraw.push_back( i ); layersToDraw.push_back( i );
}
} }
else else
{ {
@ -98,9 +93,8 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s
} }
MODEL_ZONES_OVERVIEW_TABLE::MODEL_ZONES_OVERVIEW_TABLE( std::vector<std::shared_ptr<MANAGED_ZONE>> aZones, MODEL_ZONES_OVERVIEW::MODEL_ZONES_OVERVIEW( std::vector<std::shared_ptr<MANAGED_ZONE>> aZones,
BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ) :
wxWindow* a_dialog ) :
m_allZones( aZones ), m_allZones( aZones ),
m_filteredZones( std::move( aZones ) ), m_filteredZones( std::move( aZones ) ),
m_pcb( a_pcb ), m_pcb( a_pcb ),
@ -113,11 +107,7 @@ MODEL_ZONES_OVERVIEW_TABLE::MODEL_ZONES_OVERVIEW_TABLE( std::vector<std::shared_
} }
MODEL_ZONES_OVERVIEW_TABLE::~MODEL_ZONES_OVERVIEW_TABLE() = default; void MODEL_ZONES_OVERVIEW::GetValueByRow( wxVariant& aVariant, unsigned aRow, unsigned aCol ) const
void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aRow,
unsigned aCol ) const
{ {
if( static_cast<size_t>( aRow ) + 1 > m_filteredZones.size() ) if( static_cast<size_t>( aRow ) + 1 > m_filteredZones.size() )
return; return;
@ -142,10 +132,9 @@ void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aR
for( PCB_LAYER_ID layer : cur.GetLayerSet().Seq() ) for( PCB_LAYER_ID layer : cur.GetLayerSet().Seq() )
layers.Add( m_pcb->GetLayerName( layer ) ); layers.Add( m_pcb->GetLayerName( layer ) );
aVariant << wxDataViewIconText( wxJoin( layers, ',' ), aVariant << wxDataViewIconText( wxJoin( layers, ',' ), MakeBitmapForLayers( cur.GetLayerSet().UIOrder(),
MakeBitmapForLayers( cur.GetLayerSet().UIOrder(), *m_PCB_FRAME->GetColorSettings(),
*m_PCB_FRAME->GetColorSettings(), bmSize ) );
bmSize ) );
break; break;
} }
@ -155,32 +144,31 @@ void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aR
} }
void MODEL_ZONES_OVERVIEW_TABLE::EnableFitterByName( bool aEnable ) void MODEL_ZONES_OVERVIEW::EnableFitterByName( bool aEnable )
{ {
m_sortByName = aEnable; m_sortByName = aEnable;
} }
void MODEL_ZONES_OVERVIEW_TABLE::EnableFitterByNet( bool aEnable ) void MODEL_ZONES_OVERVIEW::EnableFitterByNet( bool aEnable )
{ {
m_sortByNet = aEnable; m_sortByNet = aEnable;
} }
bool MODEL_ZONES_OVERVIEW_TABLE::SetValueByRow( const wxVariant& aVariant, unsigned aRow, bool MODEL_ZONES_OVERVIEW::SetValueByRow( const wxVariant& aVariant, unsigned aRow, unsigned aCol )
unsigned aCol )
{ {
return {}; return {};
} }
unsigned int MODEL_ZONES_OVERVIEW_TABLE::GetCount() const unsigned int MODEL_ZONES_OVERVIEW::GetCount() const
{ {
return m_filteredZones.size(); return m_filteredZones.size();
} }
ZONE* MODEL_ZONES_OVERVIEW_TABLE::GetZone( wxDataViewItem const& aItem ) const ZONE* MODEL_ZONES_OVERVIEW::GetZone( wxDataViewItem const& aItem ) const
{ {
if( !aItem.IsOk() ) if( !aItem.IsOk() )
return nullptr; return nullptr;
@ -194,7 +182,7 @@ ZONE* MODEL_ZONES_OVERVIEW_TABLE::GetZone( wxDataViewItem const& aItem ) const
} }
wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::GetItemByZone( ZONE* aZone ) const wxDataViewItem MODEL_ZONES_OVERVIEW::GetItemByZone( ZONE* aZone ) const
{ {
if( !aZone ) if( !aZone )
return {}; return {};
@ -209,8 +197,7 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::GetItemByZone( ZONE* aZone ) const
} }
std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::MoveZoneIndex( unsigned aIndex, std::optional<unsigned> MODEL_ZONES_OVERVIEW::MoveZoneIndex( unsigned aIndex, ZONE_INDEX_MOVEMENT aMovement )
ZONE_INDEX_MOVEMENT aMovement )
{ {
switch( aMovement ) switch( aMovement )
{ {
@ -231,8 +218,7 @@ std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::MoveZoneIndex( unsigned
} }
std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned aDragIndex, std::optional<unsigned> MODEL_ZONES_OVERVIEW::SwapZonePriority( unsigned aDragIndex, unsigned aDropIndex )
unsigned aDropIndex )
{ {
for( const unsigned i : { aDragIndex, aDropIndex } ) for( const unsigned i : { aDragIndex, aDropIndex } )
{ {
@ -243,8 +229,7 @@ std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned a
if( aDragIndex == aDropIndex ) if( aDragIndex == aDropIndex )
return aDragIndex; return aDragIndex;
std::swap( m_filteredZones[aDragIndex]->m_currentPriority, std::swap( m_filteredZones[aDragIndex]->m_currentPriority, m_filteredZones[aDropIndex]->m_currentPriority );
m_filteredZones[aDropIndex]->m_currentPriority );
std::swap( m_filteredZones[aDragIndex], m_filteredZones[aDropIndex] ); std::swap( m_filteredZones[aDragIndex], m_filteredZones[aDropIndex] );
for( const unsigned int row : { aDragIndex, aDropIndex } ) for( const unsigned int row : { aDragIndex, aDropIndex } )
@ -254,8 +239,7 @@ std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned a
} }
wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ApplyFilter( wxString const& aFilterText, wxDataViewItem MODEL_ZONES_OVERVIEW::ApplyFilter( wxString const& aFilterText, wxDataViewItem aSelection )
wxDataViewItem aSelection )
{ {
if( !GetAllZonesCount() ) if( !GetAllZonesCount() )
return {}; return {};
@ -286,7 +270,7 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ApplyFilter( wxString const& aFilterT
} }
wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ClearFilter( wxDataViewItem aSelection ) wxDataViewItem MODEL_ZONES_OVERVIEW::ClearFilter( wxDataViewItem aSelection )
{ {
if( !GetAllZonesCount() ) if( !GetAllZonesCount() )
return {}; return {};

View File

@ -23,8 +23,7 @@
*/ */
#ifndef MODEL_ZONES_OVERVIEW_TABLE_H #pragma once
#define MODEL_ZONES_OVERVIEW_TABLE_H
#include <memory> #include <memory>
#include <utility> #include <utility>
@ -41,6 +40,8 @@ class MANAGED_ZONE;
wxDECLARE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent ); wxDECLARE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent );
#define LAYER_BAR_WIDTH 16
enum class ZONE_INDEX_MOVEMENT enum class ZONE_INDEX_MOVEMENT
{ {
@ -49,7 +50,7 @@ enum class ZONE_INDEX_MOVEMENT
}; };
class MODEL_ZONES_OVERVIEW_TABLE : public wxDataViewVirtualListModel class MODEL_ZONES_OVERVIEW : public wxDataViewVirtualListModel
{ {
public: public:
enum enum
@ -61,13 +62,6 @@ public:
COL_COUNT COL_COUNT
}; };
enum WIDTH_SETTING
{
NAME_WIDTH = 128,
LAYER_BAR_WIDTH = 16
};
static std::map<int, wxString> GetColumnNames() static std::map<int, wxString> GetColumnNames()
{ {
//NOTE - Build the column name dynamicly in case the display language changed //NOTE - Build the column name dynamicly in case the display language changed
@ -79,10 +73,10 @@ public:
return ColNames; return ColNames;
} }
MODEL_ZONES_OVERVIEW_TABLE( std::vector<std::shared_ptr<MANAGED_ZONE>> aZones, BOARD* a_pcb, MODEL_ZONES_OVERVIEW( std::vector<std::shared_ptr<MANAGED_ZONE>> aZones, BOARD* a_pcb,
PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ); PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog );
~MODEL_ZONES_OVERVIEW_TABLE() override; ~MODEL_ZONES_OVERVIEW() override = default;
void EnableFitterByName( bool aEnable ); void EnableFitterByName( bool aEnable );
@ -146,5 +140,3 @@ private:
bool m_sortByName; bool m_sortByName;
bool m_sortByNet; bool m_sortByNet;
}; };
#endif