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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#include <gerbview_frame.h>
31#include <layer_range.h>
32#include <lset.h>
34
35#include <wx/radiobox.h>
36
37
42};
43
44
46{
47public:
48 SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount,
49 wxString aGerberName );
51
53
54protected:
55 bool TransferDataFromWindow() override;
56
57private:
58 void OnLayerSelected( wxCommandEvent& event );
59
61
63 wxRadioBox* m_layerRadioBox;
64 std::vector <int> m_layerId;
65};
66
67
68BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, DIALOG_SHIM )
70END_EVENT_TABLE()
71
72
73int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
74 const wxString& aGerberName )
75{
76 SELECT_LAYER_DIALOG* frame =
77 new SELECT_LAYER_DIALOG( this, aDefaultLayer, aCopperLayerCount, aGerberName );
78
79 frame->ShowModal();
80 frame->Destroy();
81 return frame->GetSelectedLayer();
82}
83
84
86 int aCopperLayerCount, wxString aGerberName )
87 : DIALOG_SHIM( parent, -1, wxString::Format( _( "Select Layer: %s" ), aGerberName ),
88 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
89{
90 wxButton* button;
91 wxArrayString layerList;
92 int selected = -1;
93
94 // Store the passed default layer in case the user hits Cancel
95 m_selectedLayer = aDefaultLayer;
96
97 // Build the layer list; first build copper layers list
98 LSET layers = LSET::AllCuMask( aCopperLayerCount ) | LSET::AllTechMask() | LSET::UserMask();
99
100 for( auto copper_it = layers.copper_layers_begin(); copper_it != layers.copper_layers_end(); ++copper_it )
101 {
102 layerList.Add( LSET::Name( *copper_it ) );
103
104 if( aDefaultLayer == *copper_it )
105 selected = m_layerId.size();
106
107 m_layerId.push_back( *copper_it );
108 }
109
110 for( auto non_copper_it = layers.non_copper_layers_begin(); non_copper_it != layers.non_copper_layers_end(); ++non_copper_it )
111 {
112 layerList.Add( LSET::Name( *non_copper_it ) );
113
114 if( aDefaultLayer == *non_copper_it )
115 selected = m_layerId.size();
116
117 m_layerId.push_back( *non_copper_it );
118 }
119
120 layerList.Add( _( "Hole data" ) );
121
122 if( aDefaultLayer == UNDEFINED_LAYER )
123 selected = m_layerId.size();
124
125 m_layerId.push_back( UNDEFINED_LAYER );
126
127 layerList.Add( _( "Do not export" ) );
128
129 if( aDefaultLayer == UNSELECTED_LAYER )
130 selected = m_layerId.size();
131
132 m_layerId.push_back( UNSELECTED_LAYER );
133
134 m_layerRadioBox = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), wxDefaultPosition,
135 wxDefaultSize, layerList, std::min( int( m_layerId.size() ), 12 ),
136 wxRA_SPECIFY_ROWS );
137
138 if( selected >= 0 )
139 m_layerRadioBox->SetSelection( selected );
140
141 wxBoxSizer* mainSizer = new wxBoxSizer( wxHORIZONTAL );
142 SetSizer( mainSizer );
143 mainSizer->Add( m_layerRadioBox, 1, wxEXPAND | wxALIGN_TOP | wxALL, 5 );
144 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxVERTICAL );
145 mainSizer->Add( buttonsSizer, 0, wxALIGN_BOTTOM | wxALL, 5 );
146
147 button = new wxButton( this, wxID_OK, _( "OK" ) );
148 button->SetDefault();
149 buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
150
151 button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
152 buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
153
154#ifdef __WXOSX__
155 // Hack to fix clipped radio buttons on OSX
156 wxSize size = m_layerRadioBox->GetBestSize() + wxSize( 20, 0 );
157 m_layerRadioBox->SetMinSize( size );
158#endif
159
160 GetSizer()->SetSizeHints( this );
161
162 Center();
163}
164
165
166void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
167{
168 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
169}
170
171
173{
174 if( !wxDialog::TransferDataFromWindow() )
175 return false;
176
177 m_selectedLayer = m_layerId[m_layerRadioBox->GetSelection()];
178 return true;
179}
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:88
int ShowModal() override
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
copper_layers_iterator copper_layers_end() const
Definition: lset.cpp:867
static LSET UserMask()
Definition: lset.cpp:636
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:622
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:562
copper_layers_iterator copper_layers_begin() const
Definition: lset.cpp:861
non_copper_layers_iterator non_copper_layers_begin() const
Definition: lset.cpp:873
non_copper_layers_iterator non_copper_layers_end() const
Definition: lset.cpp:879
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:188
void OnLayerSelected(wxCommandEvent &event)
SELECT_LAYER_DIALOG(GERBVIEW_FRAME *parent, int aDefaultLayer, int aCopperLayerCount, wxString aGerberName)
#define _(s)
@ UNSELECTED_LAYER
Definition: layer_ids.h:62
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
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:198