Rewrite Move And Swap Layers dialog.

Fixes: lp:1670422
* https://bugs.launchpad.net/kicad/+bug/1670422

(cherry picked from commit 356a767)
This commit is contained in:
Jeff Young 2018-07-04 13:28:48 +01:00
parent 7d71861015
commit d016238c82
8 changed files with 680 additions and 447 deletions

View File

@ -137,6 +137,8 @@ set( PCBNEW_DIALOGS
dialogs/dialog_select_pretty_lib_base.cpp dialogs/dialog_select_pretty_lib_base.cpp
dialogs/dialog_set_grid.cpp dialogs/dialog_set_grid.cpp
dialogs/dialog_set_grid_base.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_target_properties_base.cpp
dialogs/dialog_text_properties.cpp dialogs/dialog_text_properties.cpp
dialogs/dialog_text_properties_base.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_export.cpp
specctra_import_export/specctra_import.cpp specctra_import_export/specctra_import.cpp
specctra_import_export/specctra_keywords.cpp specctra_import_export/specctra_keywords.cpp
swap_layers.cpp
target_edit.cpp target_edit.cpp
text_mod_grid_table.cpp text_mod_grid_table.cpp
tool_footprint_editor.cpp tool_footprint_editor.cpp

View File

@ -140,9 +140,9 @@ bool DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow()
// Get the layer selection for this zone // Get the layer selection for this zone
int layer = -1; 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; layer = ii;
break; break;

View File

@ -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 <pcb_edit_frame.h>
#include <class_board.h>
#include <grid_layer_box_helpers.h>
#include <board_commit.h>
#include <class_drawsegment.h>
#include <class_drawpanel.h>
#include <class_track.h>
#include <view/view.h>
#include <widgets/wx_grid.h>
#include <class_zone.h>
#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();
}
}

View File

@ -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 );
}

View File

@ -0,0 +1,279 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="13" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="disconnect_mode">source_name</property>
<property name="disconnect_php_events">0</property>
<property name="disconnect_python_events">0</property>
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">dialog_swap_layers_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="internationalize">0</property>
<property name="name">swap_layers</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
<property name="relative_path">1</property>
<property name="skip_lua_events">1</property>
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="event_handler">impl_virtual</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">DIALOG_SWAP_LAYERS_BASE</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h; forward_declare</property>
<property name="title">Swap Layers</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnActivate"></event>
<event name="OnActivateApp"></event>
<event name="OnAuiFindManager"></event>
<event name="OnAuiPaneButton"></event>
<event name="OnAuiPaneClose"></event>
<event name="OnAuiPaneMaximize"></event>
<event name="OnAuiPaneRestore"></event>
<event name="OnAuiRender"></event>
<event name="OnChar"></event>
<event name="OnClose"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnHibernate"></event>
<event name="OnIconize"></event>
<event name="OnIdle"></event>
<event name="OnInitDialog"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bMainSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bMarginsSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxALL</property>
<property name="proportion">1</property>
<object class="wxGrid" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="autosize_cols">0</property>
<property name="autosize_rows">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="cell_bg"></property>
<property name="cell_font"></property>
<property name="cell_horiz_alignment">wxALIGN_LEFT</property>
<property name="cell_text"></property>
<property name="cell_vert_alignment">wxALIGN_TOP</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="col_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="col_label_size">22</property>
<property name="col_label_values"></property>
<property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="cols">2</property>
<property name="column_sizes">125,125</property>
<property name="context_help"></property>
<property name="context_menu">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_col_move">0</property>
<property name="drag_col_size">0</property>
<property name="drag_grid_size">0</property>
<property name="drag_row_size">0</property>
<property name="editing">1</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="grid_line_color"></property>
<property name="grid_lines">1</property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label_bg"></property>
<property name="label_font"></property>
<property name="label_text"></property>
<property name="margin_height">0</property>
<property name="margin_width">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">250,150</property>
<property name="moveable">1</property>
<property name="name">m_grid</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="row_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="row_label_size">0</property>
<property name="row_label_values"></property>
<property name="row_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="row_sizes"></property>
<property name="rows">2</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">WX_GRID; widgets/wx_grid.h; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnGridCellChange"></event>
<event name="OnGridCellLeftClick"></event>
<event name="OnGridCellLeftDClick"></event>
<event name="OnGridCellRightClick"></event>
<event name="OnGridCellRightDClick"></event>
<event name="OnGridCmdCellChange"></event>
<event name="OnGridCmdCellLeftClick"></event>
<event name="OnGridCmdCellLeftDClick"></event>
<event name="OnGridCmdCellRightClick"></event>
<event name="OnGridCmdCellRightDClick"></event>
<event name="OnGridCmdColSize"></event>
<event name="OnGridCmdEditorCreated"></event>
<event name="OnGridCmdEditorHidden"></event>
<event name="OnGridCmdEditorShown"></event>
<event name="OnGridCmdLabelLeftClick"></event>
<event name="OnGridCmdLabelLeftDClick"></event>
<event name="OnGridCmdLabelRightClick"></event>
<event name="OnGridCmdLabelRightDClick"></event>
<event name="OnGridCmdRangeSelect"></event>
<event name="OnGridCmdRowSize"></event>
<event name="OnGridCmdSelectCell"></event>
<event name="OnGridColSize"></event>
<event name="OnGridEditorCreated"></event>
<event name="OnGridEditorHidden"></event>
<event name="OnGridEditorShown"></event>
<event name="OnGridLabelLeftClick"></event>
<event name="OnGridLabelLeftDClick"></event>
<event name="OnGridLabelRightClick"></event>
<event name="OnGridLabelRightDClick"></event>
<event name="OnGridRangeSelect"></event>
<event name="OnGridRowSize"></event>
<event name="OnGridSelectCell"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize">OnSize</event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
<event name="OnApplyButtonClick"></event>
<event name="OnCancelButtonClick"></event>
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>
<event name="OnOKButtonClick"></event>
<event name="OnSaveButtonClick"></event>
<event name="OnYesButtonClick"></event>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@ -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 <wx/artprov.h>
#include <wx/xrc/xmlres.h>
class WX_GRID;
#include "dialog_shim.h"
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/font.h>
#include <wx/grid.h>
#include <wx/gdicmn.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// 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__

View File

@ -475,12 +475,12 @@ void prepareEditMenu( wxMenu* aParentMenu, bool aUseGal )
_( "Edit Text && &Graphic Properties..." ), KiBitmap( reset_text_xpm ) ); _( "Edit Text && &Graphic Properties..." ), KiBitmap( reset_text_xpm ) );
AddMenuItem( aParentMenu, ID_MENU_PCB_EXCHANGE_FOOTPRINTS, AddMenuItem( aParentMenu, ID_MENU_PCB_EXCHANGE_FOOTPRINTS,
_( "Change Footprints..." ), _( "Change &Footprints..." ),
_( "Assign different footprints from the library" ), _( "Assign different footprints from the library" ),
KiBitmap( exchange_xpm ) ); KiBitmap( exchange_xpm ) );
AddMenuItem( aParentMenu, ID_MENU_PCB_SWAP_LAYERS, AddMenuItem( aParentMenu, ID_MENU_PCB_SWAP_LAYERS,
_( "&Move and Swap Layers..." ), _( "&Swap Layers..." ),
_( "Move tracks or drawings from a layer to another layer" ), _( "Move tracks or drawings from a layer to another layer" ),
KiBitmap( swap_layer_xpm ) ); KiBitmap( swap_layer_xpm ) );

View File

@ -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 <fctsys.h>
#include <class_drawpanel.h>
#include <pcb_edit_frame.h>
#include <dialog_shim.h>
#include <class_board.h>
#include <class_track.h>
#include <class_drawsegment.h>
#include <pcbnew.h>
#include <board_commit.h>
#include <wx/statline.h>
#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 );
}