From d016238c82e2a7a731435e78ba41612e8f3c4899 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 4 Jul 2018 13:28:48 +0100 Subject: [PATCH] Rewrite Move And Swap Layers dialog. Fixes: lp:1670422 * https://bugs.launchpad.net/kicad/+bug/1670422 (cherry picked from commit 356a767) --- pcbnew/CMakeLists.txt | 3 +- .../dialog_non_copper_zones_properties.cpp | 4 +- pcbnew/dialogs/dialog_swap_layers.cpp | 260 +++++++++++ pcbnew/dialogs/dialog_swap_layers_base.cpp | 82 ++++ pcbnew/dialogs/dialog_swap_layers_base.fbp | 279 +++++++++++ pcbnew/dialogs/dialog_swap_layers_base.h | 53 +++ pcbnew/menubar_pcb_editor.cpp | 4 +- pcbnew/swap_layers.cpp | 442 ------------------ 8 files changed, 680 insertions(+), 447 deletions(-) create mode 100644 pcbnew/dialogs/dialog_swap_layers.cpp create mode 100644 pcbnew/dialogs/dialog_swap_layers_base.cpp create mode 100644 pcbnew/dialogs/dialog_swap_layers_base.fbp create mode 100644 pcbnew/dialogs/dialog_swap_layers_base.h delete mode 100644 pcbnew/swap_layers.cpp diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index d430d14319..5cac7e2071 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -137,6 +137,8 @@ set( PCBNEW_DIALOGS dialogs/dialog_select_pretty_lib_base.cpp dialogs/dialog_set_grid.cpp dialogs/dialog_set_grid_base.cpp + dialogs/dialog_swap_layers.cpp + dialogs/dialog_swap_layers_base.cpp dialogs/dialog_target_properties_base.cpp dialogs/dialog_text_properties.cpp dialogs/dialog_text_properties_base.cpp @@ -281,7 +283,6 @@ set( PCBNEW_CLASS_SRCS specctra_import_export/specctra_export.cpp specctra_import_export/specctra_import.cpp specctra_import_export/specctra_keywords.cpp - swap_layers.cpp target_edit.cpp text_mod_grid_table.cpp tool_footprint_editor.cpp diff --git a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp index 825a7d80ae..caff0b3a05 100644 --- a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp +++ b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp @@ -140,9 +140,9 @@ bool DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow() // Get the layer selection for this zone int layer = -1; - for( unsigned int ii = 0; ii < (int) m_layers->GetItemCount(); ++ii ) + for( int ii = 0; ii < m_layers->GetItemCount(); ++ii ) { - if( m_layers->GetToggleValue( ii, 0 ) ) + if( m_layers->GetToggleValue( (unsigned) ii, 0 ) ) { layer = ii; break; diff --git a/pcbnew/dialogs/dialog_swap_layers.cpp b/pcbnew/dialogs/dialog_swap_layers.cpp new file mode 100644 index 0000000000..90adb324e6 --- /dev/null +++ b/pcbnew/dialogs/dialog_swap_layers.cpp @@ -0,0 +1,260 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 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 + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dialog_swap_layers_base.h" + + +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 + { + return aCol == 1 ? wxString( _( "Move To:" ) ) : wxString( wxEmptyString ); + } + + 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; + } +}; + + +class DIALOG_SWAP_LAYERS : public DIALOG_SWAP_LAYERS_BASE +{ +private: + PCB_EDIT_FRAME* m_parent; + PCB_LAYER_ID* m_layerDestinations; + + LAYER_GRID_TABLE* m_gridTable; + +public: + DIALOG_SWAP_LAYERS( PCB_EDIT_FRAME* aParent, PCB_LAYER_ID* aArray ); + ~DIALOG_SWAP_LAYERS() override; + +private: + bool TransferDataToWindow() override; + bool TransferDataFromWindow() override; + + void OnSize( wxSizeEvent& event ) override; + + void adjustGridColumns( int aWidth ); +}; + + +DIALOG_SWAP_LAYERS::DIALOG_SWAP_LAYERS( PCB_EDIT_FRAME* aParent, PCB_LAYER_ID* aArray ) : + DIALOG_SWAP_LAYERS_BASE( aParent ), + m_parent( aParent ), + m_layerDestinations( aArray ) +{ + m_gridTable = new LAYER_GRID_TABLE( m_parent->GetBoard()->GetCopperLayerCount() ); + m_grid->SetTable( m_gridTable ); + m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 ); + m_grid->SetCellHighlightROPenWidth( 0 ); + + m_sdbSizerOK->SetDefault(); + + FinishDialogSettings(); +} + + +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() +{ + // Commit any pending changes + m_grid->DisableCellEditControl(); + + LSET enabledCopperLayers = LSET::AllCuMask( m_parent->GetBoard()->GetCopperLayerCount() ); + wxGridTableBase* table = m_grid->GetTable(); + int row = 0; + + for( size_t 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; + } + + return true; +} + + +void DIALOG_SWAP_LAYERS::adjustGridColumns( int aWidth ) +{ + // Account for scroll bars + aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x ); + + m_grid->SetColSize( 0, aWidth / 2 ); + m_grid->SetColSize( 1, aWidth - m_grid->GetColSize( 0 ) ); +} + + +void DIALOG_SWAP_LAYERS::OnSize( wxSizeEvent& event ) +{ + adjustGridColumns( event.GetSize().GetX() ); + + event.Skip(); +} + + +bool processBoardItem( PCB_EDIT_FRAME* aFrame, BOARD_COMMIT& commit, BOARD_ITEM* aItem, + PCB_LAYER_ID* new_layer ) +{ + if( new_layer[ aItem->GetLayer() ] != aItem->GetLayer() ) + { + commit.Modify( aItem ); + aItem->SetLayer( new_layer[ aItem->GetLayer() ] ); + aFrame->GetGalCanvas()->GetView()->Update( aItem, KIGFX::GEOMETRY ); + return true; + } + + return false; +} + + +void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event ) +{ + PCB_LAYER_ID new_layer[PCB_LAYER_ID_COUNT]; + + DIALOG_SWAP_LAYERS dlg( this, new_layer ); + + if( dlg.ShowModal() != wxID_OK ) + return; + + BOARD_COMMIT commit( this ); + bool hasChanges = false; + + // Change tracks. + for( TRACK* segm = GetBoard()->m_Track; segm; segm = segm->Next() ) + { + if( segm->Type() == PCB_VIA_T ) + { + VIA* via = (VIA*) segm; + PCB_LAYER_ID top_layer, bottom_layer; + + if( via->GetViaType() == VIA_THROUGH ) + continue; + + via->LayerPair( &top_layer, &bottom_layer ); + + if( new_layer[bottom_layer] != bottom_layer || new_layer[top_layer] != top_layer ) + { + commit.Modify( via ); + via->SetLayerPair( new_layer[top_layer], new_layer[bottom_layer] ); + GetGalCanvas()->GetView()->Update( via, KIGFX::GEOMETRY ); + hasChanges = true; + } + } + else + { + hasChanges |= processBoardItem( this, commit, segm, new_layer ); + } + } + + for( TRACK* segm = GetBoard()->m_SegZoneDeprecated; segm; segm = segm->Next() ) + { + // Note: deprecated zone segment fills only found in very old boards + hasChanges |= processBoardItem( this, commit, segm, new_layer ); + } + + for( BOARD_ITEM* zone : GetBoard()->Zones() ) + { + hasChanges |= processBoardItem( this, commit, zone, new_layer ); + } + + for( BOARD_ITEM* drawing : GetBoard()->Drawings() ) + { + hasChanges |= processBoardItem( this, commit, drawing, new_layer ); + } + + if( hasChanges ) + { + OnModify(); + commit.Push( "Layers moved" ); + GetCanvas()->Refresh(); + } +} diff --git a/pcbnew/dialogs/dialog_swap_layers_base.cpp b/pcbnew/dialogs/dialog_swap_layers_base.cpp new file mode 100644 index 0000000000..26c1ae6ebe --- /dev/null +++ b/pcbnew/dialogs/dialog_swap_layers_base.cpp @@ -0,0 +1,82 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Dec 30 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "widgets/wx_grid.h" + +#include "dialog_swap_layers_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_SWAP_LAYERS_BASE::DIALOG_SWAP_LAYERS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bMainSizer; + bMainSizer = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bMarginsSizer; + bMarginsSizer = new wxBoxSizer( wxVERTICAL ); + + m_grid = new WX_GRID( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + // Grid + m_grid->CreateGrid( 2, 2 ); + m_grid->EnableEditing( true ); + m_grid->EnableGridLines( true ); + m_grid->EnableDragGridSize( false ); + m_grid->SetMargins( 0, 0 ); + + // Columns + m_grid->SetColSize( 0, 125 ); + m_grid->SetColSize( 1, 125 ); + m_grid->EnableDragColMove( false ); + m_grid->EnableDragColSize( false ); + m_grid->SetColLabelSize( 22 ); + m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Rows + m_grid->EnableDragRowSize( false ); + m_grid->SetRowLabelSize( 0 ); + m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Label Appearance + + // Cell Defaults + m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + m_grid->SetMinSize( wxSize( 250,150 ) ); + + bMarginsSizer->Add( m_grid, 1, wxEXPAND|wxALL, 5 ); + + + bMainSizer->Add( bMarginsSizer, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 10 ); + + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizer->Realize(); + + bMainSizer->Add( m_sdbSizer, 0, wxALL|wxEXPAND, 5 ); + + + this->SetSizer( bMainSizer ); + this->Layout(); + bMainSizer->Fit( this ); + + this->Centre( wxBOTH ); + + // Connect Events + m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SWAP_LAYERS_BASE::OnSize ), NULL, this ); +} + +DIALOG_SWAP_LAYERS_BASE::~DIALOG_SWAP_LAYERS_BASE() +{ + // Disconnect Events + m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SWAP_LAYERS_BASE::OnSize ), NULL, this ); + +} diff --git a/pcbnew/dialogs/dialog_swap_layers_base.fbp b/pcbnew/dialogs/dialog_swap_layers_base.fbp new file mode 100644 index 0000000000..d09937aa2c --- /dev/null +++ b/pcbnew/dialogs/dialog_swap_layers_base.fbp @@ -0,0 +1,279 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_swap_layers_base + 1000 + none + 0 + swap_layers + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_SWAP_LAYERS_BASE + + + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h; forward_declare + Swap Layers + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bMainSizer + wxVERTICAL + none + + 10 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 1 + + + bMarginsSizer + wxVERTICAL + none + + 5 + wxEXPAND|wxALL + 1 + + 1 + 1 + 1 + 1 + + + + + 0 + 0 + + + + 1 + + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_CENTRE + 22 + + wxALIGN_CENTRE + 2 + 125,125 + + 0 + 0 + Dock + 0 + Left + 0 + 0 + 0 + 0 + 1 + 1 + + 1 + + + 1 + 0 + 0 + wxID_ANY + + + + 0 + 0 + + 0 + + + 0 + 250,150 + 1 + m_grid + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTRE + 0 + + wxALIGN_CENTRE + + 2 + 1 + + WX_GRID; widgets/wx_grid.h; forward_declare + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OnSize + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer + protected + + + + + + + + + + + + + + diff --git a/pcbnew/dialogs/dialog_swap_layers_base.h b/pcbnew/dialogs/dialog_swap_layers_base.h new file mode 100644 index 0000000000..430e6003a0 --- /dev/null +++ b/pcbnew/dialogs/dialog_swap_layers_base.h @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Dec 30 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_SWAP_LAYERS_BASE_H__ +#define __DIALOG_SWAP_LAYERS_BASE_H__ + +#include +#include +class WX_GRID; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_SWAP_LAYERS_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_SWAP_LAYERS_BASE : public DIALOG_SHIM +{ + private: + + protected: + WX_GRID* m_grid; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerCancel; + + // Virtual event handlers, overide them in your derived class + virtual void OnSize( wxSizeEvent& event ) { event.Skip(); } + + + public: + + DIALOG_SWAP_LAYERS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Swap Layers"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_SWAP_LAYERS_BASE(); + +}; + +#endif //__DIALOG_SWAP_LAYERS_BASE_H__ diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 1675177275..dd17e491e0 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -475,12 +475,12 @@ void prepareEditMenu( wxMenu* aParentMenu, bool aUseGal ) _( "Edit Text && &Graphic Properties..." ), KiBitmap( reset_text_xpm ) ); AddMenuItem( aParentMenu, ID_MENU_PCB_EXCHANGE_FOOTPRINTS, - _( "Change Footprints..." ), + _( "Change &Footprints..." ), _( "Assign different footprints from the library" ), KiBitmap( exchange_xpm ) ); AddMenuItem( aParentMenu, ID_MENU_PCB_SWAP_LAYERS, - _( "&Move and Swap Layers..." ), + _( "&Swap Layers..." ), _( "Move tracks or drawings from a layer to another layer" ), KiBitmap( swap_layer_xpm ) ); diff --git a/pcbnew/swap_layers.cpp b/pcbnew/swap_layers.cpp deleted file mode 100644 index 1a7adbf428..0000000000 --- a/pcbnew/swap_layers.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2007-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2018 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 - * 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 - */ - -/** - * @file swap_layers.cpp - * @brief Dialog to move board items between layers. - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - - -#define NO_CHANGE PCB_LAYER_ID(-3) - - -enum swap_layer_id { - ID_WINEDA_SWAPLAYERFRAME = 1800, - ID_BUTTON_0, - ID_TEXT_0 = ID_BUTTON_0 + PCB_LAYER_ID_COUNT -}; - - -class MOVE_SWAP_LAYER_DIALOG : public DIALOG_SHIM -{ -public: - MOVE_SWAP_LAYER_DIALOG( PCB_BASE_FRAME* parent, PCB_LAYER_ID* aArray ); - // ~MOVE_SWAP_LAYER_DIALOG() { }; - -private: - PCB_BASE_FRAME* m_Parent; - wxBoxSizer* m_outerBoxSizer; - wxBoxSizer* m_mainBoxSizer; - wxFlexGridSizer* FlexColumnBoxSizer; - wxStdDialogButtonSizer* StdDialogButtonSizer; - - PCB_LAYER_ID* m_callers_nlayers; // DIM() is PCB_LAYER_ID_COUNT - wxStaticText* layer_list[PCB_LAYER_ID_COUNT]; - - void Sel_Layer( wxCommandEvent& event ); - void OnOkClick( wxCommandEvent& event ); - void OnCancelClick( wxCommandEvent& event ); - - DECLARE_EVENT_TABLE() -}; - - -BEGIN_EVENT_TABLE( MOVE_SWAP_LAYER_DIALOG, wxDialog ) - EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + PCB_LAYER_ID_COUNT - 1, - wxEVT_COMMAND_BUTTON_CLICKED, MOVE_SWAP_LAYER_DIALOG::Sel_Layer ) - - EVT_BUTTON( wxID_OK, MOVE_SWAP_LAYER_DIALOG::OnOkClick ) - - EVT_BUTTON( wxID_CANCEL, MOVE_SWAP_LAYER_DIALOG::OnCancelClick ) -END_EVENT_TABLE() - - -MOVE_SWAP_LAYER_DIALOG::MOVE_SWAP_LAYER_DIALOG( PCB_BASE_FRAME* parent, PCB_LAYER_ID* aArray ) : - DIALOG_SHIM( parent, -1, _( "Move Layers:" ), wxPoint( -1, -1 ), - wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ), - m_callers_nlayers( aArray ) -{ - memset( layer_list, 0, sizeof( layer_list ) ); - - BOARD* board = parent->GetBoard(); - - m_outerBoxSizer = NULL; - m_mainBoxSizer = NULL; - FlexColumnBoxSizer = NULL; - StdDialogButtonSizer = NULL; - - m_Parent = parent; - - int item_ID; - wxSize goodSize; - - /* Experimentation has shown that buttons in the Windows version can be - * 20 pixels wide and 20 pixels high, but that they need to be 26 pixels - * wide and 26 pixels high in the Linux version. (And although the - * dimensions of those buttons could be set to 26 pixels wide and 26 - * pixels high in both of those versions, that would result in a dialog - * box which would be excessively high in the Windows version.) - */ -#ifdef __WINDOWS__ - int w = 20; - int h = 20; -#else - int w = 26; - int h = 26; -#endif - - /* As currently implemented, the dimensions of the buttons in the Mac - * version are also 26 pixels wide and 26 pixels high. If appropriate, - * the above code should be modified as required in the event that those - * buttons should be some other size in that version. - */ - - m_outerBoxSizer = new wxBoxSizer( wxVERTICAL ); - SetSizer( m_outerBoxSizer ); - - m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - m_outerBoxSizer->Add( m_mainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); - - for( unsigned layer = 0; layer < DIM( layer_list ); ++layer ) - { - // Provide a vertical line to separate the two FlexGrid sizers - if( layer == 32 ) - { - wxStaticLine* line = new wxStaticLine( this, -1, wxDefaultPosition, - wxDefaultSize, wxLI_VERTICAL ); - m_mainBoxSizer->Add( line, 0, wxGROW | wxLEFT | wxRIGHT, 5 ); - } - - // Provide a separate FlexGrid sizer for every sixteen sets of controls - if( layer % 16 == 0 ) - { - /* Each layer has an associated static text string (to identify - * that layer), a button (for invoking a child dialog box to - * change which layer that the layer is mapped to), and a second - * static text string (to depict which layer that the layer has - * been mapped to). Each of those items are placed into the left - * hand column, middle column, and right hand column (respectively) - * of the Flexgrid sizer, and the color of the second text string - * is set to fuchsia or blue (to respectively indicate whether the - * layer has been swapped to another layer or is not being swapped - * at all). (Experimentation has shown that if a text control is - * used to depict which layer that each layer is mapped to (instead - * of a static text string), then those controls do not behave in - * a fully satisfactory manner in the Linux version. Even when the - * read-only attribute is specified for all of those controls, they - * can still be selected when the arrow keys or Tab key is used - * to step through all of the controls within the dialog box, and - * directives to set the foreground color of the text of each such - * control to blue (to indicate that the text is of a read-only - * nature) are disregarded.) - * - * Specify a FlexGrid sizer with sixteen rows and three columns. - */ - FlexColumnBoxSizer = new wxFlexGridSizer( 16, 3, 0, 0 ); - - // Specify that all of the rows can be expanded. - for( int jj = 0; jj < 16; jj++ ) - { - FlexColumnBoxSizer->AddGrowableRow( jj ); - } - - // Specify that (just) the right-hand column can be expanded. - FlexColumnBoxSizer->AddGrowableCol( 2 ); - - m_mainBoxSizer->Add( FlexColumnBoxSizer, 1, wxGROW | wxTOP, 5 ); - } - - /* Provide a text string to identify this layer (with trailing spaces - * within that string being purged). - */ - wxStaticText* label = new wxStaticText( this, wxID_STATIC, - board->GetLayerName( ToLAYER_ID( layer ) ), - wxDefaultPosition, wxDefaultSize, - wxALIGN_RIGHT ); - - FlexColumnBoxSizer->Add( label, 0, - wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | - wxLEFT | wxBOTTOM, - 5 ); - - // Provide a button for this layer (which will invoke a child dialog box) - item_ID = ID_BUTTON_0 + layer; - - wxButton* Button = new wxButton( this, item_ID, wxT( "..." ), wxDefaultPosition, - wxSize( w, h ), 0 ); - FlexColumnBoxSizer->Add( Button, 0, - wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | - wxLEFT | wxBOTTOM, 5 ); - - /* Provide another text string to specify which layer that this layer - * is mapped to, set the initial text to "No Change" (to indicate that - * this layer is currently unmapped to any other layer), and set the - * foreground color of the text to blue (which also indicates that the - * layer is currently unmapped to any other layer). - */ - item_ID = ID_TEXT_0 + layer; - - /* When the first of these text strings is being added, determine - * what size is necessary to to be able to display the longest - * string without truncation. Then use that size as the - * minimum size for all text strings. (If the minimum - * size is not this size, strings can be truncated after - * some other layer is selected.) - */ - wxStaticText* text; - - if( layer == 0 ) - { - text = new wxStaticText( this, item_ID, - board->GetLayerName( PCB_LAYER_ID( 0 ) ), - wxDefaultPosition, wxDefaultSize, 0 ); - goodSize = text->GetSize(); - - for( unsigned jj = 1; jj < DIM( layer_list ); ++jj ) - { - text->SetLabel( board->GetLayerName( ToLAYER_ID( jj ) ) ); - - if( goodSize.x < text->GetSize().x ) - goodSize.x = text->GetSize().x; - } - - text->SetLabel( _( "No Change" ) ); - - if( goodSize.x < text->GetSize().x ) - goodSize.x = text->GetSize().x; - } - else - { - text = new wxStaticText( this, item_ID, _( "No Change" ), - wxDefaultPosition, wxDefaultSize, 0 ); - } - - text->SetMinSize( goodSize ); - FlexColumnBoxSizer->Add( text, 1, - wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | - wxLEFT | wxRIGHT | wxBOTTOM, 5 ); - layer_list[layer] = text; - } - - /* Provide spacers to occupy otherwise blank cells within the second - * FlexGrid sizer. (Because there are three columns, three spacers - * are thus required for each unused row.) - for( int ii = 3 * NB_PCB_LAYERS; ii < 96; ii++ ) - { - FlexColumnBoxSizer->Add( 5, h, 0, wxALIGN_CENTER_HORIZONTAL | - wxALIGN_CENTER_VERTICAL | wxLEFT | - wxRIGHT | wxBOTTOM, 5 ); - } - */ - - // Provide a line to separate the controls which have been provided so far - // from the OK and Cancel buttons (which will be provided after this line) - wxStaticLine* line = new wxStaticLine( this, -1, wxDefaultPosition, - wxDefaultSize, wxLI_HORIZONTAL ); - m_outerBoxSizer->Add( line, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); - - // Provide a StdDialogButtonSizer to accommodate the OK and Cancel buttons; - // using that type of sizer results in those buttons being automatically - // located in positions appropriate for each (OS) version of KiCad. - StdDialogButtonSizer = new wxStdDialogButtonSizer; - m_outerBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 ); - - wxButton* Button = new wxButton( this, wxID_OK, _( "&OK" ), - wxDefaultPosition, wxDefaultSize, 0 ); - Button->SetDefault(); - StdDialogButtonSizer->AddButton( Button ); - - Button = new wxButton( this, wxID_CANCEL, _( "&Cancel" ), - wxDefaultPosition, wxDefaultSize, 0 ); - StdDialogButtonSizer->AddButton( Button ); - StdDialogButtonSizer->Realize(); - - // Resize the dialog - GetSizer()->SetSizeHints( this ); - - Center(); -} - - -void MOVE_SWAP_LAYER_DIALOG::Sel_Layer( wxCommandEvent& event ) -{ - int ii; - - ii = event.GetId(); - - if( ii < ID_BUTTON_0 || ii >= ID_BUTTON_0 + PCB_LAYER_ID_COUNT ) - return; - - ii = event.GetId() - ID_BUTTON_0; - - PCB_LAYER_ID layer = m_callers_nlayers[ii]; - - LSET notallowed_mask = IsCopperLayer( ii ) ? LSET::AllNonCuMask() : LSET::AllCuMask(); - - layer = m_Parent->SelectLayer( layer == NO_CHANGE ? ToLAYER_ID( ii ): layer, notallowed_mask ); - - if( !IsValidLayer( layer ) ) - return; - - if( layer != m_callers_nlayers[ii] ) - { - m_callers_nlayers[ii] = layer; - - if( layer == NO_CHANGE || layer == ii ) - { - layer_list[ii]->SetLabel( _( "No Change" ) ); - - // Change the text color to blue (to highlight - // that this layer is *not* being swapped) - layer_list[ii]->SetForegroundColour( *wxBLUE ); - } - else - { - layer_list[ii]->SetLabel( m_Parent->GetBoard()->GetLayerName( layer ) ); - - // Change the text color to fuchsia (to highlight - // that this layer *is* being swapped) - layer_list[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) ); - } - - layer_list[ii]->Refresh(); - } -} - - -void MOVE_SWAP_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event ) -{ - EndModal( wxID_CANCEL ); -} - - -void MOVE_SWAP_LAYER_DIALOG::OnOkClick( wxCommandEvent& event ) -{ - EndModal( wxID_OK ); -} - - -void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event ) -{ - PCB_LAYER_ID new_layer[PCB_LAYER_ID_COUNT]; - - for( unsigned i = 0; i < DIM( new_layer ); ++i ) - new_layer[i] = NO_CHANGE; - - MOVE_SWAP_LAYER_DIALOG dlg( this, new_layer ); - - if( dlg.ShowModal() != wxID_OK ) - return; // (Canceled dialog box returns -1 instead) - - BOARD_COMMIT commit( this ); - bool hasChanges = false; - - // Change traces. - for( TRACK* segm = GetBoard()->m_Track; segm; segm = segm->Next() ) - { - OnModify(); - - if( segm->Type() == PCB_VIA_T ) - { - VIA* via = (VIA*) segm; - - if( via->GetViaType() == VIA_THROUGH ) - continue; - - PCB_LAYER_ID top_layer, bottom_layer; - - via->LayerPair( &top_layer, &bottom_layer ); - - if( new_layer[bottom_layer] != NO_CHANGE ) - bottom_layer = new_layer[bottom_layer]; - - if( new_layer[top_layer] != NO_CHANGE ) - top_layer = new_layer[top_layer]; - - commit.Modify( via ); - hasChanges = true; - - via->SetLayerPair( top_layer, bottom_layer ); - } - else - { - int jj = segm->GetLayer(); - - if( new_layer[jj] != NO_CHANGE ) - { - commit.Modify( segm ); - hasChanges = true; - segm->SetLayer( new_layer[jj] ); - } - } - } - - // Change deprecated zones segments, only found in very old boards. - for( TRACK* segm = GetBoard()->m_SegZoneDeprecated; segm; segm = segm->Next() ) - { - OnModify(); - int jj = segm->GetLayer(); - - if( new_layer[jj] != NO_CHANGE ) - segm->SetLayer( new_layer[jj] ); - } - - // Change other segments. - for( auto item : GetBoard()->Drawings() ) - { - if( item->Type() == PCB_LINE_T ) - { - OnModify(); - - DRAWSEGMENT* drawsegm = (DRAWSEGMENT*) item; - int jj = drawsegm->GetLayer(); - - if( new_layer[jj] != NO_CHANGE ) - { - commit.Modify( drawsegm ); - hasChanges = true; - drawsegm->SetLayer( new_layer[jj] ); - } - } - } - - if( hasChanges ) - commit.Push( "Layers moved" ); - - m_canvas->Refresh( true ); -}