2018-07-04 12:28:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2024-03-17 12:42:45 +00:00
|
|
|
* Copyright (C) 2018-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-04 12:28:48 +00: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-09 23:21:50 +00:00
|
|
|
#include <pcb_base_edit_frame.h>
|
2018-07-04 12:28:48 +00:00
|
|
|
#include <grid_layer_box_helpers.h>
|
2021-12-16 14:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2018-07-04 12:28:48 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include "dialog_swap_layers.h"
|
2018-07-04 12:28:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LAYER_GRID_TABLE : public wxGridTableBase
|
|
|
|
{
|
|
|
|
int m_layers[MAX_CU_LAYERS][2];
|
|
|
|
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 21:00:59 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case 0: return _( "Move items on:" );
|
|
|
|
case 1: return _( "To layer:" );
|
|
|
|
default: return wxEmptyString;
|
|
|
|
}
|
2018-07-04 12:28:48 +00: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
|
|
|
|
{
|
|
|
|
return m_layers[ row ][ col ];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetValueAsLong( int row, int col, long value ) override
|
|
|
|
{
|
|
|
|
m_layers[ row ][ col ] = value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-03-12 23:32:40 +00: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 12:28:48 +00:00
|
|
|
DIALOG_SWAP_LAYERS_BASE( aParent ),
|
|
|
|
m_parent( aParent ),
|
2024-03-17 12:42:45 +00:00
|
|
|
m_layerMap( aLayerMap )
|
2018-07-04 12:28:48 +00:00
|
|
|
{
|
|
|
|
m_gridTable = new LAYER_GRID_TABLE( m_parent->GetBoard()->GetCopperLayerCount() );
|
|
|
|
m_grid->SetTable( m_gridTable );
|
2024-02-05 05:52:11 +00:00
|
|
|
m_grid->SetMinSize( FromDIP( m_grid->GetMinSize() ) );
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + FromDIP( 4 ) );
|
2018-07-04 12:28:48 +00:00
|
|
|
m_grid->SetCellHighlightROPenWidth( 0 );
|
2024-02-05 05:52:11 +00:00
|
|
|
m_grid->SetUseNativeColLabels();
|
2018-07-04 12:28:48 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2018-07-04 12:28:48 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-07-04 12:28:48 +00: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;
|
|
|
|
|
|
|
|
for( size_t layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
|
|
|
|
{
|
|
|
|
if( enabledCopperLayers.test( layer ) )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SWAP_LAYERS::TransferDataFromWindow()
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-07-04 12:28:48 +00:00
|
|
|
|
|
|
|
LSET enabledCopperLayers = LSET::AllCuMask( m_parent->GetBoard()->GetCopperLayerCount() );
|
|
|
|
wxGridTableBase* table = m_grid->GetTable();
|
|
|
|
int row = 0;
|
|
|
|
|
2024-03-17 12:42:45 +00:00
|
|
|
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
|
2018-07-04 12:28:48 +00:00
|
|
|
{
|
|
|
|
if( enabledCopperLayers.test( layer ) )
|
2024-03-12 23:32:40 +00:00
|
|
|
{
|
2024-03-17 12:42:45 +00:00
|
|
|
int dest = table->GetValueAsLong( row++, 1 );
|
|
|
|
|
|
|
|
if( dest >= 0 && dest < PCB_LAYER_ID_COUNT && enabledCopperLayers.test( dest ) )
|
|
|
|
m_layerMap[ ToLAYER_ID( layer ) ] = ToLAYER_ID( dest );
|
2024-03-12 23:32:40 +00:00
|
|
|
}
|
2018-07-04 12:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_SWAP_LAYERS::adjustGridColumns()
|
2018-07-04 12:28:48 +00:00
|
|
|
{
|
|
|
|
// Account for scroll bars
|
2021-12-16 14:39:58 +00:00
|
|
|
int width = KIPLATFORM::UI::GetUnobscuredSize( m_grid ).x;
|
2018-07-04 12:28:48 +00:00
|
|
|
|
2024-02-05 05:52:11 +00: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 12:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SWAP_LAYERS::OnSize( wxSizeEvent& event )
|
|
|
|
{
|
2021-12-16 14:39:58 +00:00
|
|
|
adjustGridColumns();
|
2018-07-04 12:28:48 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|