2024-01-03 19:47:35 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 John Beard, john.j.beard@gmail.com
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2024-01-03 19:47:35 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dialogs/dialog_multichannel_generate_rule_areas.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
2024-11-25 18:51:54 -05:00
|
|
|
#include <grid_tricks.h>
|
2024-01-03 19:47:35 +01:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
|
|
|
|
#include <tools/multichannel_tool.h>
|
|
|
|
|
2025-07-27 20:54:36 +01:00
|
|
|
DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS( PCB_BASE_FRAME* aFrame,
|
|
|
|
MULTICHANNEL_TOOL* aParentTool ) :
|
2024-01-03 19:47:35 +01:00
|
|
|
DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS_BASE( aFrame ),
|
|
|
|
m_parentTool( aParentTool )
|
|
|
|
{
|
2025-04-22 15:06:37 +02:00
|
|
|
m_bSizer1 = new wxBoxSizer( wxVERTICAL );
|
|
|
|
m_bSizer2 = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2024-11-03 21:43:55 +00:00
|
|
|
// Generate the sheet source grid
|
2025-04-22 15:06:37 +02:00
|
|
|
m_sheetGrid = new WX_GRID( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
|
2024-11-25 18:51:54 -05:00
|
|
|
m_sheetGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_sheetGrid ) ) );
|
2024-11-03 21:43:55 +00:00
|
|
|
m_sheetGrid->CreateGrid( 0, 3 );
|
|
|
|
m_sheetGrid->EnableEditing( false );
|
|
|
|
m_sheetGrid->EnableGridLines( true );
|
|
|
|
m_sheetGrid->EnableDragGridSize( false );
|
|
|
|
m_sheetGrid->SetMargins( 0, 0 );
|
|
|
|
m_sheetGrid->SetColSize( 0, 100 );
|
|
|
|
m_sheetGrid->SetColSize( 1, 300 );
|
|
|
|
m_sheetGrid->SetColSize( 2, 100 );
|
|
|
|
m_sheetGrid->AutoSizeColumns();
|
|
|
|
m_sheetGrid->EnableDragColMove( true );
|
|
|
|
m_sheetGrid->EnableDragColSize( true );
|
|
|
|
m_sheetGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_sheetGrid->AutoSizeRows();
|
|
|
|
m_sheetGrid->EnableDragRowSize( true );
|
|
|
|
m_sheetGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
|
|
|
|
m_sheetGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_sheetGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
|
|
|
|
m_sheetGrid->EnableEditing( true );
|
|
|
|
m_sheetGrid->HideRowLabels();
|
2025-02-16 20:02:30 +03:00
|
|
|
m_sheetGrid->SetColLabelValue( 0, _( "Generate" ) );
|
|
|
|
m_sheetGrid->SetColLabelValue( 1, _( "Sheet Path" ) );
|
|
|
|
m_sheetGrid->SetColLabelValue( 2, _( "Sheet Name" ) );
|
2024-11-03 21:43:55 +00:00
|
|
|
m_sheetGrid->AutoSizeColumn( 1 );
|
2025-04-22 15:06:37 +02:00
|
|
|
m_bSizer1->Add( m_sheetGrid, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
m_panel1->SetSizer( m_bSizer1 );
|
|
|
|
m_panel1->Layout();
|
|
|
|
m_bSizer1->Fit( m_panel1 );
|
2024-11-03 21:43:55 +00:00
|
|
|
|
|
|
|
// Generate the component class source grid
|
2025-04-22 15:06:37 +02:00
|
|
|
m_componentClassGrid = new WX_GRID( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
|
2024-11-03 21:43:55 +00:00
|
|
|
m_componentClassGrid->CreateGrid( 0, 2 );
|
|
|
|
m_componentClassGrid->EnableEditing( false );
|
|
|
|
m_componentClassGrid->EnableGridLines( true );
|
|
|
|
m_componentClassGrid->EnableDragGridSize( false );
|
|
|
|
m_componentClassGrid->SetMargins( 0, 0 );
|
|
|
|
m_componentClassGrid->SetColSize( 0, 100 );
|
|
|
|
m_componentClassGrid->SetColSize( 1, 300 );
|
|
|
|
m_componentClassGrid->AutoSizeColumns();
|
|
|
|
m_componentClassGrid->EnableDragColMove( true );
|
|
|
|
m_componentClassGrid->EnableDragColSize( true );
|
|
|
|
m_componentClassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_componentClassGrid->AutoSizeRows();
|
|
|
|
m_componentClassGrid->EnableDragRowSize( true );
|
|
|
|
m_componentClassGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
|
|
|
|
m_componentClassGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_componentClassGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
|
|
|
|
m_componentClassGrid->EnableEditing( true );
|
|
|
|
m_componentClassGrid->HideRowLabels();
|
2025-02-16 20:02:30 +03:00
|
|
|
m_componentClassGrid->SetColLabelValue( 0, _( "Generate" ) );
|
|
|
|
m_componentClassGrid->SetColLabelValue( 1, _( "Component Class" ) );
|
2024-11-03 21:43:55 +00:00
|
|
|
m_componentClassGrid->AutoSizeColumn( 1 );
|
2025-04-22 15:06:37 +02:00
|
|
|
m_bSizer2->Add( m_componentClassGrid, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
m_panel2->SetSizer( m_bSizer2 );
|
|
|
|
m_panel2->Layout();
|
|
|
|
m_bSizer2->Fit( m_panel2 );
|
2024-01-03 19:47:35 +01:00
|
|
|
|
2025-05-07 09:03:28 -04:00
|
|
|
// Generate the group source grid
|
|
|
|
m_groupGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
m_groupGrid->CreateGrid( 0, 2 );
|
|
|
|
m_groupGrid->EnableEditing( false );
|
|
|
|
m_groupGrid->EnableGridLines( true );
|
|
|
|
m_groupGrid->EnableDragGridSize( false );
|
|
|
|
m_groupGrid->SetMargins( 0, 0 );
|
|
|
|
m_groupGrid->SetColSize( 0, 100 );
|
|
|
|
m_groupGrid->SetColSize( 1, 300 );
|
|
|
|
m_groupGrid->AutoSizeColumns();
|
|
|
|
m_groupGrid->EnableDragColMove( true );
|
|
|
|
m_groupGrid->EnableDragColSize( true );
|
|
|
|
m_groupGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_groupGrid->AutoSizeRows();
|
|
|
|
m_groupGrid->EnableDragRowSize( true );
|
|
|
|
m_groupGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
|
|
|
|
m_groupGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_groupGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
|
|
|
|
m_groupGrid->EnableEditing( true );
|
|
|
|
m_groupGrid->HideRowLabels();
|
|
|
|
m_groupGrid->SetColLabelValue( 0, _( "Generate" ) );
|
|
|
|
m_groupGrid->SetColLabelValue( 1, _( "Name" ) );
|
|
|
|
m_groupGrid->AutoSizeColumn( 1 );
|
|
|
|
m_sourceNotebook->AddPage( m_groupGrid, _( "Groups" ) );
|
|
|
|
|
2024-01-09 18:45:39 +01:00
|
|
|
RULE_AREAS_DATA* raData = m_parentTool->GetData();
|
2024-01-03 19:47:35 +01:00
|
|
|
|
2024-11-03 21:43:55 +00:00
|
|
|
int sheetRowIdx = 0;
|
|
|
|
int componentClassRowIdx = 0;
|
2025-05-07 09:03:28 -04:00
|
|
|
int groupIdx = 0;
|
2024-11-03 21:43:55 +00:00
|
|
|
|
|
|
|
for( RULE_AREA& ruleArea : raData->m_areas )
|
|
|
|
{
|
2025-06-07 17:22:08 +01:00
|
|
|
if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
|
2024-11-03 21:43:55 +00:00
|
|
|
sheetRowIdx++;
|
2025-06-07 17:22:08 +01:00
|
|
|
else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
|
2024-11-03 21:43:55 +00:00
|
|
|
componentClassRowIdx++;
|
2025-06-07 17:22:08 +01:00
|
|
|
else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::GROUP_PLACEMENT )
|
2025-05-07 09:03:28 -04:00
|
|
|
groupIdx++;
|
2024-11-03 21:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( sheetRowIdx > 0 )
|
|
|
|
m_sheetGrid->AppendRows( sheetRowIdx );
|
|
|
|
|
|
|
|
if( componentClassRowIdx > 0 )
|
|
|
|
m_componentClassGrid->AppendRows( componentClassRowIdx );
|
2024-01-03 19:47:35 +01:00
|
|
|
|
2025-05-07 09:03:28 -04:00
|
|
|
if( groupIdx > 0 )
|
|
|
|
m_groupGrid->AppendRows( groupIdx );
|
|
|
|
|
2024-11-03 21:43:55 +00:00
|
|
|
sheetRowIdx = 0;
|
|
|
|
componentClassRowIdx = 0;
|
2025-05-07 09:03:28 -04:00
|
|
|
groupIdx = 0;
|
2024-11-03 21:43:55 +00:00
|
|
|
|
|
|
|
for( RULE_AREA& ruleArea : raData->m_areas )
|
2024-01-09 18:45:39 +01:00
|
|
|
{
|
2025-06-07 17:22:08 +01:00
|
|
|
if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
|
2024-11-03 21:43:55 +00:00
|
|
|
{
|
|
|
|
m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
|
|
|
|
m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
|
|
|
|
m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
|
|
|
|
m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
|
2025-07-27 20:54:36 +01:00
|
|
|
m_sheetGrid->SetCellValue( sheetRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
|
2024-11-03 21:43:55 +00:00
|
|
|
sheetRowIdx++;
|
|
|
|
}
|
2025-06-07 17:22:08 +01:00
|
|
|
else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
|
2024-11-03 21:43:55 +00:00
|
|
|
{
|
2025-07-27 20:54:36 +01:00
|
|
|
m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, ruleArea.m_componentClass );
|
|
|
|
m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, new wxGridCellBoolRenderer );
|
|
|
|
m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, new wxGridCellBoolEditor );
|
|
|
|
m_componentClassGrid->SetCellValue( componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" )
|
|
|
|
: wxT( "" ) );
|
2024-11-03 21:43:55 +00:00
|
|
|
componentClassRowIdx++;
|
|
|
|
}
|
2025-05-07 09:03:28 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_groupGrid->SetCellValue( groupIdx, 1, ruleArea.m_groupName );
|
|
|
|
m_groupGrid->SetCellRenderer( groupIdx, 0, new wxGridCellBoolRenderer );
|
|
|
|
m_groupGrid->SetCellEditor( groupIdx, 0, new wxGridCellBoolEditor );
|
|
|
|
m_groupGrid->SetCellValue( groupIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
|
|
|
|
groupIdx++;
|
|
|
|
}
|
2024-01-03 19:47:35 +01:00
|
|
|
}
|
|
|
|
|
2024-11-03 21:43:55 +00:00
|
|
|
m_sheetGrid->Fit();
|
|
|
|
m_componentClassGrid->Fit();
|
2025-05-07 09:03:28 -04:00
|
|
|
m_groupGrid->SetMaxSize( wxSize( -1, 800 ) );
|
|
|
|
m_groupGrid->Fit();
|
2024-11-01 21:24:07 +01:00
|
|
|
m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
|
2024-01-05 15:51:18 +01:00
|
|
|
m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
|
2024-01-03 19:47:35 +01:00
|
|
|
Layout();
|
2024-11-03 21:43:55 +00:00
|
|
|
|
2025-05-07 09:03:28 -04:00
|
|
|
if( m_sheetGrid->GetNumberRows() == 1 )
|
|
|
|
{
|
|
|
|
if( m_componentClassGrid->GetNumberRows() > 0 )
|
|
|
|
m_sourceNotebook->SetSelection( 1 );
|
|
|
|
else if( m_groupGrid->GetNumberRows() > 0 )
|
|
|
|
m_sourceNotebook->SetSelection( 2 );
|
|
|
|
}
|
2024-11-03 21:43:55 +00:00
|
|
|
|
2024-01-03 19:47:35 +01:00
|
|
|
SetupStandardButtons();
|
|
|
|
finishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-25 18:51:54 -05:00
|
|
|
DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::~DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS()
|
|
|
|
{
|
|
|
|
m_sheetGrid->PopEventHandler( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-03 19:47:35 +01:00
|
|
|
bool DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::TransferDataFromWindow()
|
|
|
|
{
|
2024-01-09 18:45:39 +01:00
|
|
|
RULE_AREAS_DATA* raData = m_parentTool->GetData();
|
2024-01-03 19:47:35 +01:00
|
|
|
|
2024-11-03 21:43:55 +00:00
|
|
|
int sheetRowIdx = 0;
|
|
|
|
int componentClassRowIdx = 0;
|
2025-05-07 09:03:28 -04:00
|
|
|
int groupIdx = 0;
|
2024-11-03 21:43:55 +00:00
|
|
|
|
2024-01-09 18:45:39 +01:00
|
|
|
for( size_t i = 0; i < raData->m_areas.size(); i++ )
|
2024-01-03 19:47:35 +01:00
|
|
|
{
|
2024-11-03 21:43:55 +00:00
|
|
|
wxString enabled;
|
|
|
|
|
2025-06-07 17:22:08 +01:00
|
|
|
if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
|
2024-11-03 21:43:55 +00:00
|
|
|
{
|
|
|
|
enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
|
|
|
|
sheetRowIdx++;
|
|
|
|
}
|
2025-06-07 17:22:08 +01:00
|
|
|
else if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
|
2024-11-03 21:43:55 +00:00
|
|
|
{
|
|
|
|
enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
|
|
|
|
componentClassRowIdx++;
|
|
|
|
}
|
2025-05-07 09:03:28 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
enabled = m_groupGrid->GetCellValue( groupIdx, 0 );
|
|
|
|
groupIdx++;
|
|
|
|
}
|
2024-11-03 21:43:55 +00:00
|
|
|
|
2024-01-09 18:45:39 +01:00
|
|
|
raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
|
2024-01-03 19:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
|
2025-05-07 09:03:28 -04:00
|
|
|
|
|
|
|
// Don't allow grouping for groups
|
2025-05-07 14:22:27 -04:00
|
|
|
if( m_sourceNotebook->GetSelection() == 2 )
|
2025-05-07 09:03:28 -04:00
|
|
|
raData->m_options.m_groupItems = false;
|
|
|
|
else
|
|
|
|
raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
|
2024-01-05 15:51:18 +01:00
|
|
|
|
2024-01-03 19:47:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::TransferDataToWindow()
|
|
|
|
{
|
2024-01-05 15:51:18 +01:00
|
|
|
// fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
|
|
|
|
// grid cells from within this method.
|
2024-01-03 19:47:35 +01:00
|
|
|
return true;
|
2024-07-15 23:32:33 +02:00
|
|
|
}
|
2024-11-25 18:51:54 -05:00
|
|
|
|
2025-05-07 09:03:28 -04:00
|
|
|
|
|
|
|
void DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::OnNotebookPageChanged( wxNotebookEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetSelection() == 2 )
|
|
|
|
m_cbGroupItems->Disable();
|
|
|
|
else
|
|
|
|
m_cbGroupItems->Enable();
|
|
|
|
}
|