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 
40 
43 {
44  m_choiceUnits->SetFocus();
45  m_sdbSizerOK->SetDefault();
46 
47  // wxformbuilder doesn't seem to let us set minimal sizes. Copy the default
48  // sizes into the minimal sizes, then, and autosize:
49  for( int i = 0; i < m_fieldGrid->GetNumberCols(); ++i )
50  {
51  m_fieldGrid->SetColMinimalWidth( i, m_fieldGrid->GetColSize( i ) );
52  m_fieldGrid->AutoSizeColLabelSize( i );
53  }
54 
55  // Embed the hotkeys list
59 
60  // Embed the color configurator
63 
64  // Make sure we select the first tab of the options tab page
65  m_notebook->SetSelection( 0 );
66 
67  // Lay out all child pages
68  // No, I don't know why this->Layout() doesn't propagate through to these,
69  // but at least on MSW, it does not.
70  for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
71  {
72  m_notebook->GetPage( i )->Layout();
73  }
74 
75  Layout();
76 
77  // Now all widgets have the size fixed, call FinishDialogSettings
79 }
80 
81 
83 {
84  return static_cast<SCH_EDIT_FRAME*>( DIALOG_EESCHEMA_OPTIONS_BASE::GetParent() );
85 }
86 
87 
88 void DIALOG_EESCHEMA_OPTIONS::SetUnits( const wxArrayString& units, int select )
89 {
90  wxASSERT( units.GetCount() > 0
91  && ( select >= 0 && (size_t) select < units.GetCount() ) );
92 
93  m_choiceUnits->Append( units );
94  m_choiceUnits->SetSelection( select );
95 }
96 
97 
98 void DIALOG_EESCHEMA_OPTIONS::SetRefIdSeparator( wxChar aSep, wxChar aFirstId)
99 {
100  // m_choiceSeparatorRefId displays one of
101  // "A" ".A" "-A" "_A" ".1" "-1" "_1" option
102 
103  int sel = 0;
104  switch( aSep )
105  {
106  default:
107  case 0:
108  aFirstId = 'A'; // cannot use a number without separator
109  break;
110 
111  case '.':
112  sel = 1;
113  break;
114 
115  case '-':
116  sel = 2;
117  break;
118 
119  case '_':
120  sel = 3;
121  break;
122  }
123 
124  if( aFirstId == '1' )
125  sel = 4;
126 
127  m_choiceSeparatorRefId->SetSelection( sel );
128 }
129 
130 void DIALOG_EESCHEMA_OPTIONS::GetRefIdSeparator( int& aSep, int& aFirstId)
131 {
132  // m_choiceSeparatorRefId displays one of
133  // "A" ".A" "-A" "_A" ".1" "-1" "_1" option
134 
135  aFirstId = 'A';
136  switch( m_choiceSeparatorRefId->GetSelection() )
137  {
138  default:
139  case 0: aSep = 0; break;
140  case 1: aSep = '.'; break;
141  case 2: aSep = '-'; break;
142  case 3: aSep = '_'; break;
143  case 4: aFirstId = '1'; aSep = '.'; break;
144  case 5: aFirstId = '1'; aSep = '-'; break;
145  case 6: aFirstId = '1'; aSep = '_'; break;
146  }
147 }
148 
149 
150 void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GRIDS& aGridSizes, int aGridId )
151 {
152  wxASSERT( aGridSizes.size() > 0 );
153 
154  int select = wxNOT_FOUND;
155 
156  for( size_t i = 0; i < aGridSizes.size(); i++ )
157  {
158  wxString tmp;
159  tmp.Printf( wxT( "%0.1f" ), aGridSizes[i].m_Size.x );
160  m_choiceGridSize->Append( tmp );
161 
162  if( aGridSizes[i].m_CmdId == aGridId )
163  select = (int) i;
164  }
165 
166  m_choiceGridSize->SetSelection( select );
167 }
168 
169 
170 void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
171 {
172  // If a single row is selected, insert after that row.
173  int selected_row = -1;
174  int n_found = 0;
175 
176  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
177  {
178  bool this_row_selected = false;
179 
180  for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
181  {
182  if( m_fieldGrid->IsInSelection( row, col ) )
183  this_row_selected = true;
184  }
185 
186  if( this_row_selected )
187  {
188  selected_row = row;
189  ++n_found;
190  }
191  }
192 
194 
195  TEMPLATE_FIELDNAMES::iterator pos;
196 
197  if( n_found == 1 )
198  pos = templateFields.begin() + selected_row + 1;
199  else
200  pos = templateFields.end();
201 
202  // Add a new fieldname to the fieldname list
203  TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
204  newFieldname.m_Value = wxT( "Value" );
205  newFieldname.m_Visible = false;
206  templateFields.insert( pos, newFieldname );
208 
209  event.Skip();
210 }
211 
212 
213 void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event )
214 {
215  // wxGrid has a somewhat complex way of detemining selection.
216  // This is pretty much the easiest way to do it, here.
217 
218  std::vector<bool> rows_to_delete( templateFields.size(), false );
219 
220  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
221  {
222  for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
223  {
224  if( m_fieldGrid->IsInSelection( row, col ) )
225  rows_to_delete[row] = true;
226  }
227  }
228 
230 
231  int n_rows = m_fieldGrid->GetNumberRows();
232 
233  for( int count = 0; count < n_rows; ++count )
234  {
235  // Iterate backwards, unsigned-friendly way for future
236  int row = n_rows - count - 1;
237 
238  if( rows_to_delete[row] )
239  {
240  templateFields.erase( templateFields.begin() + row );
241  }
242  }
243 
245 }
246 
247 
249 {
250  if( !wxDialog::TransferDataToWindow() )
251  return false;
252 
254  return false;
255 
256  m_fieldGrid->Freeze();
257 
258  if( m_fieldGrid->GetNumberRows() )
259  m_fieldGrid->DeleteRows( 0, m_fieldGrid->GetNumberRows() );
260 
261  m_fieldGrid->AppendRows( templateFields.size() );
262 
263  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
264  {
265  m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name );
266  m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Value );
267  m_fieldGrid->SetCellValue( row, 2,
268  templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
269 
270  // Set cell properties
271  m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
272  m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_LEFT, wxALIGN_CENTRE );
273 
274  // Render the Visible column as a check box
275  m_fieldGrid->SetCellEditor( row, 2, new wxGridCellBoolEditor() );
276  m_fieldGrid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
277  m_fieldGrid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
278  }
279 
280  m_fieldGrid->AutoSizeRows();
281  m_fieldGrid->Thaw();
282 
283  Layout();
284  return true;
285 }
286 
287 
289 {
290  if( !wxDialog::TransferDataFromWindow() )
291  return false;
292 
294  return false;
295 
297 
299  return false;
300 
301  // Refresh hotkeys
303  GetParent()->Refresh();
304 
305  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
306  {
307  templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 );
308  templateFields[row].m_Value = m_fieldGrid->GetCellValue( row, 1 );
309  templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 2 ) != wxEmptyString );
310  }
311 
312  return true;
313 }
314 
315 
317 {
318  // Set the template fields object
319  templateFields = aFields;
320 
321  // Build and refresh the view
323 }
324 
325 
327 {
328  return templateFields;
329 }
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.
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
void SetRefIdSeparator(wxChar aSep, wxChar aFirstId)
Function SetRefIdSeparator Sets the current RefIdSeparator value in the dialog.
void SetUnits(const wxArrayString &units, int aSelect=0)
Function SetUnits Set the unit options.
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.