KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_swap_layers.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <pcb_base_edit_frame.h>
26#include <view/view.h>
27#include <kiplatform/ui.h>
28#include <widgets/wx_grid.h>
29#include <board.h>
30#include "dialog_swap_layers.h"
31
32
33class LAYER_GRID_TABLE : public wxGridTableBase
34{
37
38public:
39 LAYER_GRID_TABLE( int layerCount ) : m_layerCount( layerCount )
40 { }
41
42 int GetNumberRows() override { return m_layerCount; }
43 int GetNumberCols() override { return 2; }
44
45 wxString GetColLabelValue( int aCol ) override
46 {
47 switch( aCol )
48 {
49 case 0: return _( "Move items on:" );
50 case 1: return _( "To layer:" );
51 default: return wxEmptyString;
52 }
53 }
54
55 wxString GetValue( int row, int col ) override { return "undefined"; }
56 void SetValue( int row, int col, const wxString& value ) override { }
57
58 long GetValueAsLong( int row, int col ) override
59 {
60 return m_layers[ row ][ col ];
61 }
62
63 void SetValueAsLong( int row, int col, long value ) override
64 {
65 m_layers[ row ][ col ] = value;
66 }
67};
68
69
71 DIALOG_SWAP_LAYERS_BASE( aParent ),
72 m_parent( aParent ),
73 m_layerDestinations( aArray )
74{
77 m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
78 m_grid->SetCellHighlightROPenWidth( 0 );
79
81
83}
84
85
87{
89}
90
91
93{
94 LSET enabledCopperLayers = LSET::AllCuMask( m_parent->GetBoard()->GetCopperLayerCount() );
95 int row = 0;
96
97 for( size_t layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
98 {
99 if( enabledCopperLayers.test( layer ) )
100 {
101 auto attr = new wxGridCellAttr;
102 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_parent ) );
103 attr->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) );
104 attr->SetReadOnly();
105 m_grid->SetAttr( row, 0, attr );
106
107 attr = new wxGridCellAttr;
108 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_parent ) );
109 attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_parent, LSET::AllNonCuMask() ) );
110 m_grid->SetAttr( row, 1, attr );
111
112 m_grid->GetTable()->SetValueAsLong( row, 0, (long) layer );
113 m_grid->GetTable()->SetValueAsLong( row, 1, (long) layer );
114
115 ++row;
116 }
117 }
118
119 return true;
120}
121
122
124{
126 return false;
127
128 LSET enabledCopperLayers = LSET::AllCuMask( m_parent->GetBoard()->GetCopperLayerCount() );
129 wxGridTableBase* table = m_grid->GetTable();
130 int row = 0;
131
132 for( size_t layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
133 {
134 if( enabledCopperLayers.test( layer ) )
135 m_layerDestinations[ layer ] = (PCB_LAYER_ID) table->GetValueAsLong( row++, 1 );
136 else
137 m_layerDestinations[ layer ] = (PCB_LAYER_ID) layer;
138 }
139
140 return true;
141}
142
143
145{
146 // Account for scroll bars
148
149 m_grid->SetColSize( 0, std::max( 40, width / 2 ) );
150 m_grid->SetColSize( 1, std::max( 40, width - m_grid->GetColSize( 0 ) ) );
151}
152
153
154void DIALOG_SWAP_LAYERS::OnSize( wxSizeEvent& event )
155{
157
158 event.Skip();
159}
160
161
int GetCopperLayerCount() const
Definition: board.cpp:625
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SWAP_LAYERS_BASE.
PCB_LAYER_ID * m_layerDestinations
bool TransferDataToWindow() override
bool TransferDataFromWindow() override
PCB_BASE_EDIT_FRAME * m_parent
DIALOG_SWAP_LAYERS(PCB_BASE_EDIT_FRAME *aParent, PCB_LAYER_ID *aArray)
void OnSize(wxSizeEvent &event) override
LAYER_GRID_TABLE * m_gridTable
void SetValue(int row, int col, const wxString &value) override
int m_layers[MAX_CU_LAYERS][2]
void SetValueAsLong(int row, int col, long value) override
int GetNumberRows() override
wxString GetValue(int row, int col) override
LAYER_GRID_TABLE(int layerCount)
wxString GetColLabelValue(int aCol) override
int GetNumberCols() override
long GetValueAsLong(int row, int col) override
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:556
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:803
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:782
Common, abstract interface for edit frames.
BOARD * GetBoard() const
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:156
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:254
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:448
#define _(s)
#define MAX_CU_LAYERS
Definition: layer_ids.h:141
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:138
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: gtk/ui.cpp:195