KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_select_one_pcb_layer.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) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include <gerbview_frame.h>
27#include <layer_range.h>
28#include <lset.h>
30
31#include <wx/radiobox.h>
32
33
39
40
42{
43public:
44 SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount,
45 wxString aGerberName );
47
49
50protected:
51 bool TransferDataFromWindow() override;
52
53private:
54 void OnLayerSelected( wxCommandEvent& event );
55
57
59 wxRadioBox* m_layerRadioBox;
60 std::vector <int> m_layerId;
61};
62
63
64BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, DIALOG_SHIM )
66END_EVENT_TABLE()
67
68
69int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
70 const wxString& aGerberName )
71{
72 SELECT_LAYER_DIALOG* frame =
73 new SELECT_LAYER_DIALOG( this, aDefaultLayer, aCopperLayerCount, aGerberName );
74
75 frame->ShowModal();
76 frame->Destroy();
77 return frame->GetSelectedLayer();
78}
79
80
82 int aCopperLayerCount, wxString aGerberName )
83 : DIALOG_SHIM( parent, -1, wxString::Format( _( "Select Layer: %s" ), aGerberName ),
84 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
85{
86 wxButton* button;
87 wxArrayString layerList;
88 int selected = -1;
89
90 // Store the passed default layer in case the user hits Cancel
91 m_selectedLayer = aDefaultLayer;
92
93 // Build the layer list; first build copper layers list
94 LSET layers = LSET::AllCuMask( aCopperLayerCount ) | LSET::AllTechMask() | LSET::UserMask();
95
96 for( auto copper_it = layers.copper_layers_begin(); copper_it != layers.copper_layers_end(); ++copper_it )
97 {
98 layerList.Add( LSET::Name( *copper_it ) );
99
100 if( aDefaultLayer == *copper_it )
101 selected = m_layerId.size();
102
103 m_layerId.push_back( *copper_it );
104 }
105
106 for( auto non_copper_it = layers.non_copper_layers_begin(); non_copper_it != layers.non_copper_layers_end(); ++non_copper_it )
107 {
108 layerList.Add( LSET::Name( *non_copper_it ) );
109
110 if( aDefaultLayer == *non_copper_it )
111 selected = m_layerId.size();
112
113 m_layerId.push_back( *non_copper_it );
114 }
115
116 layerList.Add( _( "Hole data" ) );
117
118 if( aDefaultLayer == UNDEFINED_LAYER )
119 selected = m_layerId.size();
120
121 m_layerId.push_back( UNDEFINED_LAYER );
122
123 layerList.Add( _( "Do not export" ) );
124
125 if( aDefaultLayer == UNSELECTED_LAYER )
126 selected = m_layerId.size();
127
128 m_layerId.push_back( UNSELECTED_LAYER );
129
130 m_layerRadioBox = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), wxDefaultPosition,
131 wxDefaultSize, layerList, std::min( int( m_layerId.size() ), 12 ),
132 wxRA_SPECIFY_ROWS );
133
134 if( selected >= 0 )
135 m_layerRadioBox->SetSelection( selected );
136
137 wxBoxSizer* mainSizer = new wxBoxSizer( wxHORIZONTAL );
138 SetSizer( mainSizer );
139 mainSizer->Add( m_layerRadioBox, 1, wxEXPAND | wxALIGN_TOP | wxALL, 5 );
140 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxVERTICAL );
141 mainSizer->Add( buttonsSizer, 0, wxALIGN_BOTTOM | wxALL, 5 );
142
143 button = new wxButton( this, wxID_OK, _( "OK" ) );
144 button->SetDefault();
145 buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
146
147 button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
148 buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
149
150#ifdef __WXOSX__
151 // Hack to fix clipped radio buttons on OSX
152 wxSize size = m_layerRadioBox->GetBestSize() + wxSize( 20, 0 );
153 m_layerRadioBox->SetMinSize( size );
154#endif
155
156 GetSizer()->SetSizeHints( this );
157
158 Center();
159}
160
161
162void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
163{
164 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
165}
166
167
169{
170 if( !wxDialog::TransferDataFromWindow() )
171 return false;
172
173 m_selectedLayer = m_layerId[m_layerRadioBox->GetSelection()];
174 return true;
175}
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
int ShowModal() override
int SelectPCBLayer(int aDefaultLayer, int aCopperLayerCount, const wxString &aGerberName)
Show the dialog box for layer selection.
GERBVIEW_FRAME(KIWAY *aKiway, wxWindow *aParent)
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
copper_layers_iterator copper_layers_end() const
Definition lset.cpp:919
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
static const LSET & UserMask()
Definition lset.cpp:686
copper_layers_iterator copper_layers_begin() const
Definition lset.cpp:913
non_copper_layers_iterator non_copper_layers_begin() const
Definition lset.cpp:925
static const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition lset.cpp:672
non_copper_layers_iterator non_copper_layers_end() const
Definition lset.cpp:931
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
void OnLayerSelected(wxCommandEvent &event)
SELECT_LAYER_DIALOG(GERBVIEW_FRAME *parent, int aDefaultLayer, int aCopperLayerCount, wxString aGerberName)
#define _(s)
@ UNSELECTED_LAYER
Definition layer_ids.h:58
@ UNDEFINED_LAYER
Definition layer_ids.h:57
STL namespace.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:194