KiCad PCB EDA Suite
swap_layers.cpp File Reference

Dialog to move board items between layers. More...

#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>

Go to the source code of this file.

Classes

class  MOVE_SWAP_LAYER_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, MOVE_SWAP_LAYER_DIALOG::Sel_Layer) MOVE_SWAP_LAYER_DIALOG
 

Detailed Description

Dialog to move board items between layers.

Definition in file swap_layers.cpp.

Macro Definition Documentation

#define NO_CHANGE   PCB_LAYER_ID(-3)

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 48 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  ,
MOVE_SWAP_LAYER_DIALOG::Sel_Layer   
)

Definition at line 80 of file swap_layers.cpp.

References PCAD2KICAD::Center, DIM, MOVE_SWAP_LAYER_DIALOG::FlexColumnBoxSizer, BOARD_ITEM::GetBoard(), BOARD::GetLayerName(), ID_TEXT_0, MOVE_SWAP_LAYER_DIALOG::layer_list, MOVE_SWAP_LAYER_DIALOG::m_mainBoxSizer, MOVE_SWAP_LAYER_DIALOG::m_outerBoxSizer, MOVE_SWAP_LAYER_DIALOG::m_Parent, MOVE_SWAP_LAYER_DIALOG::StdDialogButtonSizer, and ToLAYER_ID().

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