Fix layer swapping for multi-layer items.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17371

(cherry picked from commit 44c14b1935)
This commit is contained in:
Jeff Young 2024-03-17 12:13:00 +00:00
parent c935ef890a
commit 81f55dfc9c
4 changed files with 38 additions and 22 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -23,10 +23,8 @@
#include <pcb_base_edit_frame.h>
#include <grid_layer_box_helpers.h>
#include <view/view.h>
#include <kiplatform/ui.h>
#include <widgets/wx_grid.h>
#include <board.h>
#include "dialog_swap_layers.h"
@ -67,10 +65,11 @@ public:
};
DIALOG_SWAP_LAYERS::DIALOG_SWAP_LAYERS( PCB_BASE_EDIT_FRAME* aParent, PCB_LAYER_ID* aArray ) :
DIALOG_SWAP_LAYERS::DIALOG_SWAP_LAYERS( PCB_BASE_EDIT_FRAME* aParent,
std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap ) :
DIALOG_SWAP_LAYERS_BASE( aParent ),
m_parent( aParent ),
m_layerDestinations( aArray )
m_layerMap( aLayerMap )
{
m_gridTable = new LAYER_GRID_TABLE( m_parent->GetBoard()->GetCopperLayerCount() );
m_grid->SetTable( m_gridTable );
@ -131,12 +130,15 @@ bool DIALOG_SWAP_LAYERS::TransferDataFromWindow()
wxGridTableBase* table = m_grid->GetTable();
int row = 0;
for( size_t layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
{
if( enabledCopperLayers.test( layer ) )
m_layerDestinations[ layer ] = (PCB_LAYER_ID) table->GetValueAsLong( row++, 1 );
else
m_layerDestinations[ layer ] = (PCB_LAYER_ID) layer;
{
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 );
}
}
return true;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -21,8 +21,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _DIALOG_SCRIPTING_H_
#define _DIALOG_SCRIPTING_H_
#ifndef DIALOG_SWAP_LAYERS_H
#define DIALOG_SWAP_LAYERS_H
#include "dialog_swap_layers_base.h"
@ -33,7 +33,8 @@ class LAYER_GRID_TABLE;
class DIALOG_SWAP_LAYERS : public DIALOG_SWAP_LAYERS_BASE
{
public:
DIALOG_SWAP_LAYERS( PCB_BASE_EDIT_FRAME* aParent, PCB_LAYER_ID* aArray );
DIALOG_SWAP_LAYERS( PCB_BASE_EDIT_FRAME* aParent,
std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aArray );
~DIALOG_SWAP_LAYERS() override;
private:
@ -44,10 +45,11 @@ private:
void adjustGridColumns();
PCB_BASE_EDIT_FRAME* m_parent;
PCB_LAYER_ID* m_layerDestinations;
private:
PCB_BASE_EDIT_FRAME* m_parent;
std::map<PCB_LAYER_ID, PCB_LAYER_ID>& m_layerMap;
LAYER_GRID_TABLE* m_gridTable;
LAYER_GRID_TABLE* m_gridTable;
};
#endif
#endif // DIALOG_SWAP_LAYERS_H

View File

@ -107,12 +107,24 @@ int GLOBAL_EDIT_TOOL::ExchangeFootprints( const TOOL_EVENT& aEvent )
}
bool GLOBAL_EDIT_TOOL::swapBoardItem( BOARD_ITEM* aItem, PCB_LAYER_ID* aLayerMap )
bool GLOBAL_EDIT_TOOL::swapBoardItem( BOARD_ITEM* aItem,
std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap )
{
if( aLayerMap[ aItem->GetLayer() ] != aItem->GetLayer() )
LSET originalLayers = aItem->GetLayerSet();
LSET newLayers;
for( PCB_LAYER_ID original : originalLayers.Seq() )
{
if( aLayerMap.count( original ) )
newLayers.set( aLayerMap[ original ] );
else
newLayers.set( original );
}
if( originalLayers.Seq() != newLayers.Seq() )
{
m_commit->Modify( aItem );
aItem->SetLayer( aLayerMap[ aItem->GetLayer() ] );
aItem->SetLayerSet( newLayers );
frame()->GetCanvas()->GetView()->Update( aItem, KIGFX::GEOMETRY );
return true;
}
@ -123,7 +135,7 @@ bool GLOBAL_EDIT_TOOL::swapBoardItem( BOARD_ITEM* aItem, PCB_LAYER_ID* aLayerMap
int GLOBAL_EDIT_TOOL::SwapLayers( const TOOL_EVENT& aEvent )
{
PCB_LAYER_ID layerMap[PCB_LAYER_ID_COUNT];
std::map<PCB_LAYER_ID, PCB_LAYER_ID> layerMap;
DIALOG_SWAP_LAYERS dlg( frame(), layerMap );

View File

@ -65,7 +65,7 @@ public:
int RemoveUnusedPads( const TOOL_EVENT& aEvent );
private:
bool swapBoardItem( BOARD_ITEM* aItem, PCB_LAYER_ID* aLayerMap );
bool swapBoardItem( BOARD_ITEM* aItem, std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap );
///< Set up handlers for various events.
void setTransitions() override;