KiCad PCB EDA Suite
swap_layers.cpp File Reference

Dialog to swap layers. More...

#include <fctsys.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <dialog_shim.h>
#include <class_board.h>
#include <class_track.h>
#include <class_drawsegment.h>
#include <pcbnew.h>
#include <wx/statline.h>

Go to the source code of this file.

Classes

class  SWAP_LAYERS_DIALOG
 

Macros

#define NO_CHANGE   PCB_LAYER_ID(-3)
 

Enumerations

enum  swap_layer_id {
  ID_WINEDA_SWAPLAYERFRAME = 1800, ID_BUTTON_0, ID_TEXT_0 = ID_BUTTON_0 + PCB_LAYER_ID_COUNT, ID_LAYERS_MAP_DIALOG = ID_GERBER_END_LIST,
  ID_BUTTON_0, ID_TEXT_0 = ID_BUTTON_0 + GERBER_DRAWLAYERS_COUNT
}
 

Functions

 EVT_COMMAND_RANGE (ID_BUTTON_0, ID_BUTTON_0+PCB_LAYER_ID_COUNT-1, wxEVT_COMMAND_BUTTON_CLICKED, SWAP_LAYERS_DIALOG::Sel_Layer) SWAP_LAYERS_DIALOG
 

Detailed Description

Dialog to swap layers.

Definition in file swap_layers.cpp.

Macro Definition Documentation

#define NO_CHANGE   PCB_LAYER_ID(-3)

Definition at line 44 of file swap_layers.cpp.

Referenced by SWAP_LAYERS_DIALOG::Sel_Layer(), and PCB_EDIT_FRAME::Swap_Layers().

Enumeration Type Documentation

Enumerator
ID_WINEDA_SWAPLAYERFRAME 
ID_BUTTON_0 
ID_TEXT_0 
ID_LAYERS_MAP_DIALOG 
ID_BUTTON_0 
ID_TEXT_0 

Definition at line 47 of file swap_layers.cpp.

Function Documentation

EVT_COMMAND_RANGE ( ID_BUTTON_0  ,
ID_BUTTON_0+PCB_LAYER_ID_COUNT 1,
wxEVT_COMMAND_BUTTON_CLICKED  ,
SWAP_LAYERS_DIALOG::Sel_Layer   
)

Definition at line 83 of file swap_layers.cpp.

References PCAD2KICAD::Center, DIM, BOARD_ITEM::GetBoard(), BOARD::GetLayerName(), ID_TEXT_0, and ToLAYER_ID().

92  :
93  DIALOG_SHIM( parent, -1, _( "Swap Layers:" ), wxPoint( -1, -1 ),
94  wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
95  m_callers_nlayers( aArray )
96 {
97  memset( layer_list, 0, sizeof( layer_list ) );
98 
99  BOARD* board = parent->GetBoard();
100 
101  OuterBoxSizer = NULL;
102  MainBoxSizer = NULL;
103  FlexColumnBoxSizer = NULL;
104  label = NULL;
105  Button = NULL;
106  text = NULL;
107  Line = NULL;
108  StdDialogButtonSizer = NULL;
109 
110  m_Parent = parent;
111 
112  int item_ID;
113  wxSize goodSize;
114 
115  /* Experimentation has shown that buttons in the Windows version can be
116  * 20 pixels wide and 20 pixels high, but that they need to be 26 pixels
117  * wide and 26 pixels high in the Linux version. (And although the
118  * dimensions of those buttons could be set to 26 pixels wide and 26
119  * pixels high in both of those versions, that would result in a dialog
120  * box which would be excessively high in the Windows version.)
121  */
122 #ifdef __WINDOWS__
123  int w = 20;
124  int h = 20;
125 #else
126  int w = 26;
127  int h = 26;
128 #endif
129 
130  /* As currently implemented, the dimensions of the buttons in the Mac
131  * version are also 26 pixels wide and 26 pixels high. If appropriate,
132  * the above code should be modified as required in the event that those
133  * buttons should be some other size in that version.
134  */
135 
136  OuterBoxSizer = new wxBoxSizer( wxVERTICAL );
137  SetSizer( OuterBoxSizer );
138 
139  MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
140  OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
141 
142  for( unsigned layer = 0; layer < DIM( layer_list ); ++layer )
143  {
144  // Provide a vertical line to separate the two FlexGrid sizers
145  if( layer == 32 )
146  {
147  Line = new wxStaticLine( this,
148  -1,
149  wxDefaultPosition,
150  wxDefaultSize,
151  wxLI_VERTICAL );
152  MainBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT, 5 );
153  }
154 
155  // Provide a separate FlexGrid sizer for every sixteen sets of controls
156  if( layer % 16 == 0 )
157  {
158  /* Each layer has an associated static text string (to identify
159  * that layer), a button (for invoking a child dialog box to
160  * change which layer that the layer is mapped to), and a second
161  * static text string (to depict which layer that the layer has
162  * been mapped to). Each of those items are placed into the left
163  * hand column, middle column, and right hand column (respectively)
164  * of the Flexgrid sizer, and the color of the second text string
165  * is set to fuchsia or blue (to respectively indicate whether the
166  * layer has been swapped to another layer or is not being swapped
167  * at all). (Experimentation has shown that if a text control is
168  * used to depict which layer that each layer is mapped to (instead
169  * of a static text string), then those controls do not behave in
170  * a fully satisfactory manner in the Linux version. Even when the
171  * read-only attribute is specified for all of those controls, they
172  * can still be selected when the arrow keys or Tab key is used
173  * to step through all of the controls within the dialog box, and
174  * directives to set the foreground color of the text of each such
175  * control to blue (to indicate that the text is of a read-only
176  * nature) are disregarded.)
177  *
178  * Specify a FlexGrid sizer with sixteen rows and three columns.
179  */
180  FlexColumnBoxSizer = new wxFlexGridSizer( 16, 3, 0, 0 );
181 
182  // Specify that all of the rows can be expanded.
183  for( int jj = 0; jj < 16; jj++ )
184  {
185  FlexColumnBoxSizer->AddGrowableRow( jj );
186  }
187 
188  // Specify that (just) the right-hand column can be expanded.
189  FlexColumnBoxSizer->AddGrowableCol( 2 );
190 
191  MainBoxSizer->Add( FlexColumnBoxSizer, 1, wxGROW | wxTOP, 5 );
192  }
193 
194  /* Provide a text string to identify this layer (with trailing spaces
195  * within that string being purged).
196  */
197  label = new wxStaticText( this, wxID_STATIC, board->GetLayerName( ToLAYER_ID( layer ) ),
198  wxDefaultPosition, wxDefaultSize,
199  wxALIGN_RIGHT );
200 
201  FlexColumnBoxSizer->Add( label, 0,
202  wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL |
203  wxLEFT | wxBOTTOM,
204  5 );
205 
206  // Provide a button for this layer (which will invoke a child dialog box)
207  item_ID = ID_BUTTON_0 + layer;
208 
209  Button = new wxButton( this, item_ID, wxT( "..." ), wxDefaultPosition,
210  wxSize( w, h ), 0 );
211  FlexColumnBoxSizer->Add( Button, 0,
212  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
213  wxLEFT | wxBOTTOM, 5 );
214 
215  /* Provide another text string to specify which layer that this layer
216  * is mapped to, set the initial text to "No Change" (to indicate that
217  * this layer is currently unmapped to any other layer), and set the
218  * foreground color of the text to blue (which also indicates that the
219  * layer is currently unmapped to any other layer).
220  */
221  item_ID = ID_TEXT_0 + layer;
222 
223  /* When the first of these text strings is being added, determine
224  * what size is necessary to to be able to display the longest
225  * string without truncation. Then use that size as the
226  * minimum size for all text strings. (If the minimum
227  * size is not this size, strings can be truncated after
228  * some other layer is selected.)
229  */
230  if( layer == 0 )
231  {
232  text = new wxStaticText( this, item_ID, board->GetLayerName( PCB_LAYER_ID( 0 ) ),
233  wxDefaultPosition, wxDefaultSize, 0 );
234  goodSize = text->GetSize();
235 
236  for( unsigned jj = 1; jj < DIM( layer_list ); ++jj )
237  {
238  text->SetLabel( board->GetLayerName( ToLAYER_ID( jj ) ) );
239 
240  if( goodSize.x < text->GetSize().x )
241  goodSize.x = text->GetSize().x;
242  }
243 
244  text->SetLabel( _( "No Change" ) );
245 
246  if( goodSize.x < text->GetSize().x )
247  goodSize.x = text->GetSize().x;
248  }
249  else
250  {
251  text = new wxStaticText( this, item_ID, _( "No Change" ),
252  wxDefaultPosition, wxDefaultSize, 0 );
253  }
254 
255  text->SetMinSize( goodSize );
256  FlexColumnBoxSizer->Add( text, 1,
257  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
258  wxLEFT | wxRIGHT | wxBOTTOM, 5 );
259  layer_list[layer] = text;
260  }
261 
262  /* Provide spacers to occupy otherwise blank cells within the second
263  * FlexGrid sizer. (Becuse there are three columns, three spacers
264  * are thus required for each unused row.)
265  for( int ii = 3 * NB_PCB_LAYERS; ii < 96; ii++ )
266  {
267  FlexColumnBoxSizer->Add( 5, h, 0, wxALIGN_CENTER_HORIZONTAL |
268  wxALIGN_CENTER_VERTICAL | wxLEFT |
269  wxRIGHT | wxBOTTOM, 5 );
270  }
271  */
272 
273  // Provide a line to separate the controls which have been provided so far
274  // from the OK and Cancel buttons (which will be provided after this line)
275  Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
276  OuterBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
277 
278  // Provide a StdDialogButtonSizer to accommodate the OK and Cancel buttons;
279  // using that type of sizer results in those buttons being automatically
280  // located in positions appropriate for each (OS) version of KiCad.
281  StdDialogButtonSizer = new wxStdDialogButtonSizer;
282  OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 );
283 
284  Button = new wxButton( this, wxID_OK, _( "&OK" ), wxDefaultPosition, wxDefaultSize, 0 );
285  Button->SetDefault();
286  StdDialogButtonSizer->AddButton( Button );
287 
288  Button = new wxButton( this, wxID_CANCEL, _( "&Cancel" ),
289  wxDefaultPosition, wxDefaultSize, 0 );
290  StdDialogButtonSizer->AddButton( Button );
291  StdDialogButtonSizer->Realize();
292 
293  // Resize the dialog
294  if( GetSizer() )
295  {
296  GetSizer()->SetSizeHints( this );
297  }
298 
299  Center();
300 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:60
PCB_LAYER_ID
A quick note on layer IDs:
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767