KiCad PCB EDA Suite
dialog_eeschema_options.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) 2009 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 1992-2016 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 
29 #include <fctsys.h>
30 #include <class_base_screen.h>
31 
34 #include "../widgets/widget_eeschema_color_config.h"
35 #include <schframe.h>
36 #include <hotkeys.h>
37 
38 #include <wx/settings.h>
39 
41 
44 {
45  m_choiceUnits->SetFocus();
46  m_sdbSizerOK->SetDefault();
47 
48  // wxformbuilder doesn't seem to let us set minimal sizes. Copy the default
49  // sizes into the minimal sizes, then, and autosize:
50  for( int i = 0; i < m_fieldGrid->GetNumberCols(); ++i )
51  {
52  m_fieldGrid->SetColMinimalWidth( i, m_fieldGrid->GetColSize( i ) );
53  m_fieldGrid->AutoSizeColLabelSize( i );
54  }
55 
56  // Embed the hotkeys list
60 
61  // Embed the color configurator
64 
65  // Make sure we select the last used tab of the options tab page
66  m_notebook->SetSelection( m_lastPageSelected );
67 
68  // Lay out all child pages
69  // No, I don't know why this->Layout() doesn't propagate through to these,
70  // but at least on MSW, it does not.
71  for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
72  {
73  m_notebook->GetPage( i )->Layout();
74  }
75 
76  Layout();
77 
78  // Now all widgets have the size fixed, call FinishDialogSettings
80 }
81 
82 
84 {
85  return static_cast<SCH_EDIT_FRAME*>( DIALOG_EESCHEMA_OPTIONS_BASE::GetParent() );
86 }
87 
88 
89 void DIALOG_EESCHEMA_OPTIONS::SetUnits( const wxArrayString& aUnits, int aSelect )
90 {
91  wxASSERT( aUnits.GetCount() > 0
92  && ( aSelect >= 0 && (size_t) aSelect < aUnits.GetCount() ) );
93 
94  m_choiceUnits->Append( aUnits );
95  m_choiceUnits->SetSelection( aSelect );
96 }
97 
98 
99 void DIALOG_EESCHEMA_OPTIONS::SetRefIdSeparator( wxChar aSep, wxChar aFirstId)
100 {
101  // m_choiceSeparatorRefId displays one of
102  // "A" ".A" "-A" "_A" ".1" "-1" "_1" option
103 
104  int sel = 0;
105  switch( aSep )
106  {
107  default:
108  case 0:
109  aFirstId = 'A'; // cannot use a number without separator
110  break;
111 
112  case '.':
113  sel = 1;
114  break;
115 
116  case '-':
117  sel = 2;
118  break;
119 
120  case '_':
121  sel = 3;
122  break;
123  }
124 
125  if( aFirstId == '1' )
126  sel = 4;
127 
128  m_choiceSeparatorRefId->SetSelection( sel );
129 }
130 
131 void DIALOG_EESCHEMA_OPTIONS::GetRefIdSeparator( int& aSep, int& aFirstId)
132 {
133  // m_choiceSeparatorRefId displays one of
134  // "A" ".A" "-A" "_A" ".1" "-1" "_1" option
135 
136  aFirstId = 'A';
137  switch( m_choiceSeparatorRefId->GetSelection() )
138  {
139  default:
140  case 0: aSep = 0; break;
141  case 1: aSep = '.'; break;
142  case 2: aSep = '-'; break;
143  case 3: aSep = '_'; break;
144  case 4: aFirstId = '1'; aSep = '.'; break;
145  case 5: aFirstId = '1'; aSep = '-'; break;
146  case 6: aFirstId = '1'; aSep = '_'; break;
147  }
148 }
149 
150 
151 void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GRIDS& aGridSizes, int aGridId )
152 {
153  wxASSERT( aGridSizes.size() > 0 );
154 
155  int select = wxNOT_FOUND;
156 
157  for( size_t i = 0; i < aGridSizes.size(); i++ )
158  {
159  wxString tmp;
160  tmp.Printf( wxT( "%0.1f" ), aGridSizes[i].m_Size.x );
161  m_choiceGridSize->Append( tmp );
162 
163  if( aGridSizes[i].m_CmdId == aGridId )
164  select = (int) i;
165  }
166 
167  m_choiceGridSize->SetSelection( select );
168 }
169 
170 
171 void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
172 {
173  // If a single row is selected, insert after that row.
174  int selected_row = -1;
175  int n_found = 0;
176 
177  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
178  {
179  bool this_row_selected = false;
180 
181  for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
182  {
183  if( m_fieldGrid->IsInSelection( row, col ) )
184  this_row_selected = true;
185  }
186 
187  if( this_row_selected )
188  {
189  selected_row = row;
190  ++n_found;
191  }
192  }
193 
195 
196  TEMPLATE_FIELDNAMES::iterator pos;
197 
198  if( n_found == 1 )
199  pos = templateFields.begin() + selected_row + 1;
200  else
201  pos = templateFields.end();
202 
203  // Add a new fieldname to the fieldname list
204  TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
205  newFieldname.m_Value = wxT( "Value" );
206  newFieldname.m_Visible = false;
207  templateFields.insert( pos, newFieldname );
209 
210  event.Skip();
211 }
212 
213 
214 void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event )
215 {
216  // wxGrid has a somewhat complex way of detemining selection.
217  // This is pretty much the easiest way to do it, here.
218 
219  std::vector<bool> rows_to_delete( templateFields.size(), false );
220 
221  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
222  {
223  for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
224  {
225  if( m_fieldGrid->IsInSelection( row, col ) )
226  rows_to_delete[row] = true;
227  }
228  }
229 
231 
232  int n_rows = m_fieldGrid->GetNumberRows();
233 
234  for( int count = 0; count < n_rows; ++count )
235  {
236  // Iterate backwards, unsigned-friendly way for future
237  int row = n_rows - count - 1;
238 
239  if( rows_to_delete[row] )
240  {
241  templateFields.erase( templateFields.begin() + row );
242  }
243  }
244 
246 }
247 
248 
250 {
251  if( !wxDialog::TransferDataToWindow() )
252  return false;
253 
255  return false;
256 
257  m_fieldGrid->Freeze();
258 
259  if( m_fieldGrid->GetNumberRows() )
260  m_fieldGrid->DeleteRows( 0, m_fieldGrid->GetNumberRows() );
261 
262  m_fieldGrid->AppendRows( templateFields.size() );
263 
264  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
265  {
266  m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name );
267  m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Value );
268  m_fieldGrid->SetCellValue( row, 2,
269  templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
270 
271  // Set cell properties
272  m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
273  m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_LEFT, wxALIGN_CENTRE );
274 
275  // Render the Visible column as a check box
276  m_fieldGrid->SetCellEditor( row, 2, new wxGridCellBoolEditor() );
277  m_fieldGrid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
278  m_fieldGrid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
279  }
280 
281  m_fieldGrid->AutoSizeRows();
282  m_fieldGrid->Thaw();
283 
284  Layout();
285  return true;
286 }
287 
288 
290 {
291  m_lastPageSelected = m_notebook->GetSelection();
292 
293  if( !wxDialog::TransferDataFromWindow() )
294  return false;
295 
297  return false;
298 
300 
302  return false;
303 
304  // Refresh hotkeys
306  GetParent()->Refresh();
307 
308  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
309  {
310  templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 );
311  templateFields[row].m_Value = m_fieldGrid->GetCellValue( row, 1 );
312  templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 2 ) != wxEmptyString );
313  }
314 
315  return true;
316 }
317 
318 
320 {
321  // Set the template fields object
322  templateFields = aFields;
323 
324  // Build and refresh the view
326 }
327 
328 
330 {
331  return templateFields;
332 }
bool m_Visible
If first appearance of the field's editor has as visible.
wxString m_Value
The default value or empty.
bool TransferDataToWindow() override
Function TransferDataToWindow Transfer data into the GUI.
bool TransferDataFromWindow() override
Function TransferDataFromWindow Transfer data out of the GUI.
virtual SCH_EDIT_FRAME * GetParent()
void SetTemplateFields(const TEMPLATE_FIELDNAMES &aFields)
Function SetTemplateFields Set the template field data in the dialog.
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data into the control.
void SetUnits(const wxArrayString &aUnits, int aSelect=0)
Function SetUnits Set the unit options.
DIALOG_EESCHEMA_OPTIONS(SCH_EDIT_FRAME *parent)
Public constructor.
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void InstallOnPanel(wxPanel *aPanel)
Method InstallOnPanel Install this WIDGET_EESCHEMA_COLOR_CONFIG onto an empty panel.
std::vector< GRID_TYPE > GRIDS
void GetRefIdSeparator(int &aSep, int &aFirstId)
Function GetRefIdSeparator Returns the current RefIdSeparator value from the dialog.
void OnDeleteButtonClick(wxCommandEvent &event) override
Function OnDeleteButtonClick Process the wxWidgets event produced when the user presses the Delete bu...
Pcbnew hotkeys.
static HOTKEY_SECTIONS GenSections(EDA_HOTKEY_CONFIG *aHotkeys)
Static method GenSections Generate a list of sections and names from an EDA_HOTKEY_CONFIG*.
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
void InstallOnPanel(wxPanel *aPanel)
Method InstallOnPanel Install this WIDGET_HOTKEY_LIST onto an empty panel.
TEMPLATE_FIELDNAMES templateFields
The template fieldnames for this dialog.
struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[]
void OnAddButtonClick(wxCommandEvent &event) override
Function OnAddButtonClick Process the wxWidgets event produced when the user presses the Add buton fo...
std::vector< HOTKEY_SECTION > HOTKEY_SECTIONS
Subclass of DIALOG_EESCHEMA_OPTIONS_BASE, which is generated by wxFormBuilder.
BASE_SCREEN class implementation.
TEMPLATE_FIELDNAMES GetTemplateFields(void)
Function GetTemplateFields Get the dialog's template field data.
Class DIALOG_EESCHEMA_OPTIONS_BASE.
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility...
int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL) override
>
Definition: draw_frame.cpp:379
static int m_lastPageSelected
the active notebook page when closing this dialog strored to keep selection during a session ...
void SetRefIdSeparator(wxChar aSep, wxChar aFirstId)
Function SetRefIdSeparator Sets the current RefIdSeparator value in the dialog.
void SetGridSizes(const GRIDS &aGridSizes, int aGridId)
Function SetGridSizes Sets the available grid size choices aGridSizes and selectd the current option ...
WIDGET_EESCHEMA_COLOR_CONFIG * m_colorConfigCtrl
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.