2018-07-04 13:28:48 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-04 13:28:48 +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
|
|
|
|
*/
|
|
|
|
|
2019-06-10 00:21:50 +01:00
|
|
|
#include <pcb_base_edit_frame.h>
|
2024-04-27 22:57:24 +03:00
|
|
|
#include <board.h>
|
2018-07-04 13:28:48 +01:00
|
|
|
#include <grid_layer_box_helpers.h>
|
2021-12-16 17:39:58 +03:00
|
|
|
#include <kiplatform/ui.h>
|
2018-07-04 13:28:48 +01:00
|
|
|
#include <widgets/wx_grid.h>
|
2019-06-03 21:06:58 +01:00
|
|
|
#include "dialog_swap_layers.h"
|
2018-07-04 13:28:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LAYER_GRID_TABLE : public wxGridTableBase
|
|
|
|
{
|
2024-07-21 10:49:18 -07:00
|
|
|
std::vector<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>> m_layers;
|
2018-07-04 13:28:48 +01:00
|
|
|
int m_layerCount;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LAYER_GRID_TABLE( int layerCount ) : m_layerCount( layerCount )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
int GetNumberRows() override { return m_layerCount; }
|
|
|
|
int GetNumberCols() override { return 2; }
|
|
|
|
|
|
|
|
wxString GetColLabelValue( int aCol ) override
|
|
|
|
{
|
2018-08-29 22:00:59 +01:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case 0: return _( "Move items on:" );
|
|
|
|
case 1: return _( "To layer:" );
|
|
|
|
default: return wxEmptyString;
|
|
|
|
}
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetValue( int row, int col ) override { return "undefined"; }
|
|
|
|
void SetValue( int row, int col, const wxString& value ) override { }
|
|
|
|
|
|
|
|
long GetValueAsLong( int row, int col ) override
|
|
|
|
{
|
2024-07-21 10:49:18 -07:00
|
|
|
if( row < 0 || row >= m_layerCount )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( col < 0 || col >= 2 )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return col == 0 ? m_layers[ row ].first : m_layers[ row ].second;
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetValueAsLong( int row, int col, long value ) override
|
|
|
|
{
|
2024-07-21 10:49:18 -07:00
|
|
|
if( row < 0 || col < 0 || col >= 2 )
|
|
|
|
return;
|
|
|
|
|
2024-09-27 16:56:17 +02:00
|
|
|
// Ensure there is room in m_layers to store value
|
|
|
|
while( row >= (int)m_layers.size() )
|
|
|
|
{
|
|
|
|
m_layers.emplace_back( F_Cu, F_Cu );
|
|
|
|
}
|
2024-07-21 10:49:18 -07:00
|
|
|
|
|
|
|
col == 0 ? m_layers[row].first = ToLAYER_ID( value )
|
|
|
|
: m_layers[row].second = ToLAYER_ID( value );
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-03-12 19:32:40 -04:00
|
|
|
DIALOG_SWAP_LAYERS::DIALOG_SWAP_LAYERS( PCB_BASE_EDIT_FRAME* aParent,
|
2024-03-17 12:42:45 +00:00
|
|
|
std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap ) :
|
2018-07-04 13:28:48 +01:00
|
|
|
DIALOG_SWAP_LAYERS_BASE( aParent ),
|
|
|
|
m_parent( aParent ),
|
2024-03-17 12:42:45 +00:00
|
|
|
m_layerMap( aLayerMap )
|
2018-07-04 13:28:48 +01:00
|
|
|
{
|
|
|
|
m_gridTable = new LAYER_GRID_TABLE( m_parent->GetBoard()->GetCopperLayerCount() );
|
|
|
|
m_grid->SetTable( m_gridTable );
|
2024-02-05 00:52:11 -05:00
|
|
|
m_grid->SetMinSize( FromDIP( m_grid->GetMinSize() ) );
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + FromDIP( 4 ) );
|
2018-07-04 13:28:48 +01:00
|
|
|
m_grid->SetCellHighlightROPenWidth( 0 );
|
2024-02-05 00:52:11 -05:00
|
|
|
m_grid->SetUseNativeColLabels();
|
2018-07-04 13:28:48 +01:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2018-07-04 13:28:48 +01:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_SWAP_LAYERS::~DIALOG_SWAP_LAYERS()
|
|
|
|
{
|
|
|
|
m_grid->DestroyTable( m_gridTable );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SWAP_LAYERS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
LSET enabledCopperLayers = LSET::AllCuMask( m_parent->GetBoard()->GetCopperLayerCount() );
|
|
|
|
int row = 0;
|
|
|
|
|
2024-09-27 17:55:43 +02:00
|
|
|
LSEQ enabledCopperLayerUIList = enabledCopperLayers.UIOrder();
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : enabledCopperLayerUIList )
|
2018-07-04 13:28:48 +01:00
|
|
|
{
|
2024-09-27 17:55:43 +02:00
|
|
|
auto attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_parent ) );
|
|
|
|
attr->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) );
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_grid->SetAttr( row, 0, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_parent ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_parent, LSET::AllNonCuMask() ) );
|
|
|
|
m_grid->SetAttr( row, 1, attr );
|
|
|
|
m_grid->GetTable()->SetValueAsLong( row, 0, (long) layer );
|
|
|
|
m_grid->GetTable()->SetValueAsLong( row, 1, (long) layer );
|
|
|
|
|
|
|
|
++row;
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SWAP_LAYERS::TransferDataFromWindow()
|
|
|
|
{
|
2018-08-19 17:10:14 +01:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-07-04 13:28:48 +01:00
|
|
|
|
|
|
|
LSET enabledCopperLayers = LSET::AllCuMask( m_parent->GetBoard()->GetCopperLayerCount() );
|
|
|
|
wxGridTableBase* table = m_grid->GetTable();
|
|
|
|
int row = 0;
|
|
|
|
|
2024-09-27 17:55:43 +02:00
|
|
|
LSEQ enabledCopperLayerUIList = enabledCopperLayers.UIOrder();
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : enabledCopperLayerUIList )
|
2018-07-04 13:28:48 +01:00
|
|
|
{
|
2024-09-27 17:55:43 +02:00
|
|
|
int dest = table->GetValueAsLong( row++, 1 );
|
2024-03-17 12:42:45 +00:00
|
|
|
|
2024-09-27 17:55:43 +02:00
|
|
|
if( dest >= 0 && dest < PCB_LAYER_ID_COUNT && enabledCopperLayers.test( dest ) )
|
|
|
|
m_layerMap[ layer ] = ToLAYER_ID( dest );
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 17:39:58 +03:00
|
|
|
void DIALOG_SWAP_LAYERS::adjustGridColumns()
|
2018-07-04 13:28:48 +01:00
|
|
|
{
|
|
|
|
// Account for scroll bars
|
2021-12-16 17:39:58 +03:00
|
|
|
int width = KIPLATFORM::UI::GetUnobscuredSize( m_grid ).x;
|
2018-07-04 13:28:48 +01:00
|
|
|
|
2024-02-05 00:52:11 -05:00
|
|
|
m_grid->SetColSize( 0, std::max( FromDIP( 40 ), width / 2 ) );
|
|
|
|
m_grid->SetColSize( 1, std::max( FromDIP( 40 ), width - m_grid->GetColSize( 0 ) ) );
|
2018-07-04 13:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SWAP_LAYERS::OnSize( wxSizeEvent& event )
|
|
|
|
{
|
2021-12-16 17:39:58 +03:00
|
|
|
adjustGridColumns();
|
2018-07-04 13:28:48 +01:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|