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 )
{
if( !m_fieldsGrid->CommitPendingChanges() )
return;
int row = m_fieldsGrid->GetGridCursorRow();
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 );
m_fieldsGrid->OnMoveRowUp(
[&]( int row )
{
m_fieldsGrid->SwapRows( row, row - 1 );
} );
}
void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldDown( wxCommandEvent& event )
{
if( !m_fieldsGrid->CommitPendingChanges() )
return;
int row = m_fieldsGrid->GetGridCursorRow();
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 );
m_fieldsGrid->OnMoveRowUp(
[&]( int row )
{
m_fieldsGrid->SwapRows( row, row + 1 );
} );
}

View File

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

View File

@ -309,8 +309,7 @@ void WX_GRID::EnableAlternateRowColors( bool aEnable )
{
wxGridTableBase* table = wxGrid::GetTable();
wxCHECK_MSG( table, /* void */,
"Tried to enable alternate row colors without a table assigned to the grid" );
wxCHECK_MSG( table, /* void */, "Tried to enable alternate row colors without a table assigned to the grid" );
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 )
{
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 )
{
m_unitsProviders[ aCol ] = aProvider;

View File

@ -42,8 +42,7 @@
#include <sch_commit.h>
DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_LABEL_BASE* aLabel,
bool aNew ) :
DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_LABEL_BASE* aLabel, bool aNew ) :
DIALOG_LABEL_PROPERTIES_BASE( aParent ),
m_Parent( aParent ),
m_currentLabel( aLabel ),
@ -616,30 +615,19 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow()
if( m_shapeSizer->AreAnyItemsShown() )
{
if( m_bidirectional->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
else if( m_input->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
else if( m_output->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
else if( m_triState->GetValue() )
m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
else if( m_passive->GetValue() )
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_bidirectional->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
else if( m_input->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
else if( m_output->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
else if( m_triState->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
else if( m_passive->GetValue() ) 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() )
{
m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
}
if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
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 )
{
if( !m_grid->CommitPendingChanges() )
return;
int i = m_grid->GetGridCursorRow();
if( i > m_currentLabel->GetMandatoryFieldCount() )
{
SCH_FIELD tmp = m_fields->at( (unsigned) i );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
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();
}
m_grid->OnMoveRowUp(
[&]( int row )
{
return row > m_currentLabel->GetMandatoryFieldCount();
},
[&]( int row )
{
std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
m_grid->ForceRefresh();
} );
}
void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
{
if( !m_grid->CommitPendingChanges() )
return;
int i = m_grid->GetGridCursorRow();
if( i >= m_currentLabel->GetMandatoryFieldCount() && i < m_grid->GetNumberRows() - 1 )
{
SCH_FIELD tmp = m_fields->at( (unsigned) i );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
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();
}
m_grid->OnMoveRowUp(
[&]( int row )
{
return row >= m_currentLabel->GetMandatoryFieldCount();
},
[&]( int row )
{
std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
m_grid->ForceRefresh();
} );
}

View File

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

View File

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

View File

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

View File

@ -265,28 +265,18 @@ void PANEL_SETUP_BUSES::OnAddMember( wxCommandEvent& aEvent )
void PANEL_SETUP_BUSES::OnRemoveMember( wxCommandEvent& aEvent )
{
if( !m_membersGrid->CommitPendingChanges() )
return;
m_membersGrid->OnDeleteRows(
[&]( 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 )
return;
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 ) );
}
for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii )
alias->Members().push_back( m_membersGrid->GetCellValue( ii, 0 ) );
} );
}

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 )
{
if( !m_grid->CommitPendingChanges() )
return;
int i = m_grid->GetGridCursorRow();
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();
}
m_grid->OnMoveRowUp(
[&]( int row )
{
m_grid->SwapRows( row, row - 1 );
} );
}
void PANEL_TEMPLATE_FIELDNAMES::OnMoveDown( wxCommandEvent& event )
{
if( !m_grid->CommitPendingChanges() )
return;
int i = m_grid->GetGridCursorRow();
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();
}
m_grid->OnMoveRowDown(
[&]( int row )
{
m_grid->SwapRows( row, row + 1 );
} );
}

View File

@ -92,11 +92,6 @@ public:
*/
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
* widths when setting the table.
@ -127,6 +122,17 @@ public:
void OnDeleteRows( const std::function<bool( int row )>& aFilter,
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.
*

View File

@ -93,8 +93,8 @@ void DIALOG_MANAGE_REPOSITORIES::setColumnWidths()
void DIALOG_MANAGE_REPOSITORIES::OnAdd( wxCommandEvent& event )
{
wxTextEntryDialog entry_dialog( this, _( "Please enter fully qualified repository url" ),
_( "Add repository" ) );
wxTextEntryDialog entry_dialog( this, _( "Fully qualified repository url:" ),
_( "Add Repository" ) );
if( entry_dialog.ShowModal() == wxID_OK )
{
@ -161,84 +161,32 @@ void DIALOG_MANAGE_REPOSITORIES::OnAddDefault( wxCommandEvent& event )
void DIALOG_MANAGE_REPOSITORIES::OnRemoveButtonClicked( wxCommandEvent& event )
{
auto selectedRows = m_grid->GetSelectedRows();
// If nothing is selected or multiple rows are selected don't do anything.
if( selectedRows.size() != 1 )
{
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 );
m_grid->OnDeleteRows(
[&]( int row )
{
m_grid->DeleteRows( row );
setColumnWidths();
} );
}
void DIALOG_MANAGE_REPOSITORIES::OnMoveUpButtonClicked( wxCommandEvent& event )
{
auto selectedRows = m_grid->GetSelectedRows();
// If nothing is selected or multiple rows are selected don't do anything.
if( selectedRows.size() != 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 );
m_grid->OnMoveRowUp(
[&]( int row )
{
m_grid->SwapRows( row, row - 1 );
} );
}
void DIALOG_MANAGE_REPOSITORIES::OnMoveDownButtonClicked( wxCommandEvent& event )
{
auto selectedRows = m_grid->GetSelectedRows();
// If nothing is selected or multiple rows are selected don't do anything.
if( selectedRows.size() != 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();
m_grid->OnMoveRowDown(
[&]( int row )
{
m_grid->SwapRows( row, row + 1 );
} );
}

View File

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

View File

@ -302,7 +302,7 @@ set( ZONE_MANAGER_SRCS
zone_manager/board_edges_bounding_item.cpp
zone_manager/dialog_zone_manager.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/panel_zone_gal.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 ) )
{
menu.Append( MYID_RECREATE_ENV, _( "Recreate Plugin Environment" ),
_( "Recreate Plugin Environment" ) );
menu.Append( MYID_RECREATE_ENV, _( "Recreate Plugin Environment" ), _( "Recreate Plugin Environment" ) );
menu.AppendSeparator();
}
#endif
@ -87,9 +86,7 @@ void PLUGINS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
PANEL_PCBNEW_ACTION_PLUGINS::COLUMN_SETTINGS_IDENTIFIER );
if( std::optional<const PLUGIN_ACTION*> action = mgr.GetAction( id ) )
{
mgr.RecreatePluginEnvironment( ( *action )->plugin.Identifier() );
}
#endif
}
else
@ -135,45 +132,21 @@ void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow( int aRow )
void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick( wxCommandEvent& event )
{
auto selectedRows = m_grid->GetSelectedRows();
// If nothing is selected or multiple rows are selected don't do anything.
if( selectedRows.size() != 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 );
m_grid->OnMoveRowUp(
[&]( int row )
{
SwapRows( row, row - 1 );
} );
}
void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick( wxCommandEvent& event )
{
auto selectedRows = m_grid->GetSelectedRows();
// If nothing is selected or multiple rows are selected don't do anything.
if( selectedRows.size() != 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 );
m_grid->OnMoveRowDown(
[&]( int row )
{
SwapRows( row, row + 1 );
} );
}
@ -181,19 +154,11 @@ void PANEL_PCBNEW_ACTION_PLUGINS::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->SwapRows( aRowA, aRowB );
// Swap icon column renderers
auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ACTION_NAME );
m_grid->SetCellRenderer( aRowA, COLUMN_ACTION_NAME,
m_grid->GetCellRenderer( aRowB, COLUMN_ACTION_NAME ) );
m_grid->SetCellRenderer( aRowA, COLUMN_ACTION_NAME, m_grid->GetCellRenderer( aRowB, COLUMN_ACTION_NAME ) );
m_grid->SetCellRenderer( aRowB, COLUMN_ACTION_NAME, cellRenderer );
m_grid->Thaw();
@ -261,8 +226,7 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
m_grid->ClearRows();
const std::vector<LEGACY_OR_API_PLUGIN>& orderedPlugins =
PCB_EDIT_FRAME::GetOrderedActionPlugins();
const std::vector<LEGACY_OR_API_PLUGIN>& orderedPlugins = PCB_EDIT_FRAME::GetOrderedActionPlugins();
m_grid->AppendRows( orderedPlugins.size() );
int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
@ -276,9 +240,8 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
// Icon
m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME,
new GRID_CELL_ICON_TEXT_RENDERER( ap->iconBitmap.IsOk()
? wxBitmapBundle( ap->iconBitmap )
: m_genericIcon,
new GRID_CELL_ICON_TEXT_RENDERER( ap->iconBitmap.IsOk() ? wxBitmapBundle( ap->iconBitmap )
: m_genericIcon,
iconSize ) );
m_grid->SetCellValue( row, COLUMN_ACTION_NAME, ap->GetName() );
m_grid->SetCellValue( row, COLUMN_SETTINGS_IDENTIFIER, ap->GetPluginPath() );
@ -300,9 +263,8 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
#ifdef KICAD_IPC_API
auto action = std::get<const PLUGIN_ACTION*>( orderedPlugins[row] );
const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk()
? action->icon_dark
: action->icon_light;
const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark
: action->icon_light;
// Icon
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->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( action->identifier,
action->show_button );
bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( action->identifier, action->show_button );
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 )
{
if( m_trackWidthsGrid->GetNumberRows() < 2 )
return;
std::vector<int> trackWidths;
wxString msg;
@ -161,6 +164,9 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnSortTrackWidthsClick( wxCommandEvent& aEvent
void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent )
{
if( m_viaSizesGrid->GetNumberRows() < 2 )
return;
std::vector<VIA_DIMENSION> vias;
wxString msg;
@ -197,6 +203,9 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent )
void PANEL_SETUP_TRACKS_AND_VIAS::OnSortDiffPairsClick( wxCommandEvent& aEvent )
{
if( m_diffPairsGrid->GetNumberRows() < 2 )
return;
wxString msg;
std::vector<DIFF_PAIR_DIMENSION> diffPairs;
@ -283,12 +292,8 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataToWindow()
bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow()
{
if( !m_trackWidthsGrid->CommitPendingChanges()
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
if( !commitPendingChanges() )
return false;
}
std::vector<int> trackWidths;
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()
{
if( !m_trackWidthsGrid->CommitPendingChanges()
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
if( !commitPendingChanges() )
return false;
}
wxString msg;
@ -447,12 +456,8 @@ void removeSelectedRows( WX_GRID* aGrid )
void PANEL_SETUP_TRACKS_AND_VIAS::OnAddTrackWidthsClick( wxCommandEvent& aEvent )
{
if( !m_trackWidthsGrid->CommitPendingChanges()
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
if( !commitPendingChanges() )
return;
}
AppendTrackWidth( 0 );
@ -472,12 +477,8 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveTrackWidthsClick( wxCommandEvent& even
void PANEL_SETUP_TRACKS_AND_VIAS::OnAddViaSizesClick( wxCommandEvent& event )
{
if( !m_trackWidthsGrid->CommitPendingChanges()
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
if( !commitPendingChanges() )
return;
}
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 )
{
if( !m_trackWidthsGrid->CommitPendingChanges()
|| !m_viaSizesGrid->CommitPendingChanges()
|| !m_diffPairsGrid->CommitPendingChanges() )
{
if( !commitPendingChanges() )
return;
}
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 )
{
m_trackWidthsGrid->CommitPendingChanges( true );
m_viaSizesGrid->CommitPendingChanges( true );
m_diffPairsGrid->CommitPendingChanges( true );
commitPendingChanges( true );
// 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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,11 +32,11 @@
#include <wx/variant.h>
#include "zone_manager_preference.h"
#include "managed_zone.h"
#include "model_zones_overview_table.h"
#include "model_zones_overview.h"
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::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 );
rowCountChange.SetInt( GetCount() );
@ -69,13 +69,8 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s
if( layer_cout > 4 )
{
for( const PCB_LAYER_ID& i : { layers[0],
layers[1],
layers[layer_cout - 1],
layers[layer_cout - 2] } )
{
for( const PCB_LAYER_ID& i : { layers[0], layers[1], layers[layer_cout - 1], layers[layer_cout - 2] } )
layersToDraw.push_back( i );
}
}
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,
BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME,
wxWindow* a_dialog ) :
MODEL_ZONES_OVERVIEW::MODEL_ZONES_OVERVIEW( std::vector<std::shared_ptr<MANAGED_ZONE>> aZones,
BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ) :
m_allZones( aZones ),
m_filteredZones( std::move( aZones ) ),
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_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aRow,
unsigned aCol ) const
void MODEL_ZONES_OVERVIEW::GetValueByRow( wxVariant& aVariant, unsigned aRow, unsigned aCol ) const
{
if( static_cast<size_t>( aRow ) + 1 > m_filteredZones.size() )
return;
@ -142,10 +132,9 @@ void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aR
for( PCB_LAYER_ID layer : cur.GetLayerSet().Seq() )
layers.Add( m_pcb->GetLayerName( layer ) );
aVariant << wxDataViewIconText( wxJoin( layers, ',' ),
MakeBitmapForLayers( cur.GetLayerSet().UIOrder(),
*m_PCB_FRAME->GetColorSettings(),
bmSize ) );
aVariant << wxDataViewIconText( wxJoin( layers, ',' ), MakeBitmapForLayers( cur.GetLayerSet().UIOrder(),
*m_PCB_FRAME->GetColorSettings(),
bmSize ) );
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;
}
void MODEL_ZONES_OVERVIEW_TABLE::EnableFitterByNet( bool aEnable )
void MODEL_ZONES_OVERVIEW::EnableFitterByNet( bool aEnable )
{
m_sortByNet = aEnable;
}
bool MODEL_ZONES_OVERVIEW_TABLE::SetValueByRow( const wxVariant& aVariant, unsigned aRow,
unsigned aCol )
bool MODEL_ZONES_OVERVIEW::SetValueByRow( const wxVariant& aVariant, unsigned aRow, unsigned aCol )
{
return {};
}
unsigned int MODEL_ZONES_OVERVIEW_TABLE::GetCount() const
unsigned int MODEL_ZONES_OVERVIEW::GetCount() const
{
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() )
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 )
return {};
@ -209,8 +197,7 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::GetItemByZone( ZONE* aZone ) const
}
std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::MoveZoneIndex( unsigned aIndex,
ZONE_INDEX_MOVEMENT aMovement )
std::optional<unsigned> MODEL_ZONES_OVERVIEW::MoveZoneIndex( unsigned aIndex, ZONE_INDEX_MOVEMENT 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,
unsigned aDropIndex )
std::optional<unsigned> MODEL_ZONES_OVERVIEW::SwapZonePriority( unsigned aDragIndex, unsigned aDropIndex )
{
for( const unsigned i : { aDragIndex, aDropIndex } )
{
@ -243,8 +229,7 @@ std::optional<unsigned> MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned a
if( aDragIndex == aDropIndex )
return aDragIndex;
std::swap( m_filteredZones[aDragIndex]->m_currentPriority,
m_filteredZones[aDropIndex]->m_currentPriority );
std::swap( m_filteredZones[aDragIndex]->m_currentPriority, m_filteredZones[aDropIndex]->m_currentPriority );
std::swap( m_filteredZones[aDragIndex], m_filteredZones[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 aSelection )
wxDataViewItem MODEL_ZONES_OVERVIEW::ApplyFilter( wxString const& aFilterText, wxDataViewItem aSelection )
{
if( !GetAllZonesCount() )
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() )
return {};

View File

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