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-2018 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 <base_screen.h>
31 
34 #include "../widgets/widget_eeschema_color_config.h"
35 #include <sch_edit_frame.h>
36 #include <hotkeys.h>
37 #include <bitmap_types.h>
38 
39 #include <wx/settings.h>
40 
42 
45  m_last_scale( -1 )
46 {
47  m_choiceUnits->SetFocus();
48  m_sdbSizerOK->SetDefault();
49 
50  // wxformbuilder doesn't seem to let us set minimal sizes. Copy the default
51  // sizes into the minimal sizes, then, and autosize:
52  for( int i = 0; i < m_fieldGrid->GetNumberCols(); ++i )
53  {
54  m_fieldGrid->SetColMinimalWidth( i, m_fieldGrid->GetColSize( i ) );
55  m_fieldGrid->AutoSizeColLabelSize( i );
56  }
57 
58  m_scaleSlider->SetStep( 25 );
59 
60  // Embed the hotkeys list
64 
65  // Embed the color configurator
68 
69  // Make sure we select the last used tab of the options tab page
70  m_notebook->SetSelection( m_lastPageSelected );
71 
72  // Lay out all child pages
73  // No, I don't know why this->Layout() doesn't propagate through to these,
74  // but at least on MSW, it does not.
75  for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
76  {
77  m_notebook->GetPage( i )->Layout();
78  }
79 
80  Layout();
81 
82  // Now all widgets have the size fixed, call FinishDialogSettings
84 }
85 
86 
88 {
89  return static_cast<SCH_EDIT_FRAME*>( DIALOG_EESCHEMA_OPTIONS_BASE::GetParent() );
90 }
91 
92 
93 void DIALOG_EESCHEMA_OPTIONS::SetUnits( const wxArrayString& aUnits, int aSelect )
94 {
95  wxASSERT( aUnits.GetCount() > 0
96  && ( aSelect >= 0 && (size_t) aSelect < aUnits.GetCount() ) );
97 
98  m_choiceUnits->Append( aUnits );
99  m_choiceUnits->SetSelection( aSelect );
100 }
101 
102 
103 void DIALOG_EESCHEMA_OPTIONS::SetRefIdSeparator( wxChar aSep, wxChar aFirstId)
104 {
105  // m_choiceSeparatorRefId displays one of
106  // "A" ".A" "-A" "_A" ".1" "-1" "_1" option
107 
108  int sel = 0;
109  switch( aSep )
110  {
111  default:
112  case 0:
113  aFirstId = 'A'; // cannot use a number without separator
114  break;
115 
116  case '.':
117  sel = 1;
118  break;
119 
120  case '-':
121  sel = 2;
122  break;
123 
124  case '_':
125  sel = 3;
126  break;
127  }
128 
129  if( aFirstId == '1' )
130  sel = 4;
131 
132  m_choiceSeparatorRefId->SetSelection( sel );
133 }
134 
135 
136 void DIALOG_EESCHEMA_OPTIONS::GetRefIdSeparator( int& aSep, int& aFirstId)
137 {
138  // m_choiceSeparatorRefId displays one of
139  // "A" ".A" "-A" "_A" ".1" "-1" "_1" option
140 
141  aFirstId = 'A';
142  switch( m_choiceSeparatorRefId->GetSelection() )
143  {
144  default:
145  case 0: aSep = 0; break;
146  case 1: aSep = '.'; break;
147  case 2: aSep = '-'; break;
148  case 3: aSep = '_'; break;
149  case 4: aFirstId = '1'; aSep = '.'; break;
150  case 5: aFirstId = '1'; aSep = '-'; break;
151  case 6: aFirstId = '1'; aSep = '_'; break;
152  }
153 }
154 
155 
156 void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GRIDS& aGridSizes, int aGridId )
157 {
158  wxASSERT( aGridSizes.size() > 0 );
159 
160  int select = wxNOT_FOUND;
161 
162  for( size_t i = 0; i < aGridSizes.size(); i++ )
163  {
164  wxString tmp;
165  tmp.Printf( wxT( "%0.1f" ), aGridSizes[i].m_Size.x );
166  m_choiceGridSize->Append( tmp );
167 
168  if( aGridSizes[i].m_CmdId == aGridId )
169  select = (int) i;
170  }
171 
172  m_choiceGridSize->SetSelection( select );
173 }
174 
175 
176 void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
177 {
178  // If a single row is selected, insert after that row.
179  int selected_row = -1;
180  int n_found = 0;
181 
182  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
183  {
184  bool this_row_selected = false;
185 
186  for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
187  {
188  if( m_fieldGrid->IsInSelection( row, col ) )
189  this_row_selected = true;
190  }
191 
192  if( this_row_selected )
193  {
194  selected_row = row;
195  ++n_found;
196  }
197  }
198 
200 
201  TEMPLATE_FIELDNAMES::iterator pos;
202 
203  if( n_found == 1 )
204  pos = templateFields.begin() + selected_row + 1;
205  else
206  pos = templateFields.end();
207 
208  // Add a new fieldname to the fieldname list
209  TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
210  newFieldname.m_Value = wxT( "Value" );
211  newFieldname.m_Visible = false;
212  templateFields.insert( pos, newFieldname );
214 
215  event.Skip();
216 }
217 
218 
219 void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event )
220 {
221  // wxGrid has a somewhat complex way of detemining selection.
222  // This is pretty much the easiest way to do it, here.
223 
224  std::vector<bool> rows_to_delete( templateFields.size(), false );
225 
226  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
227  {
228  for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
229  {
230  if( m_fieldGrid->IsInSelection( row, col ) )
231  rows_to_delete[row] = true;
232  }
233  }
234 
236 
237  int n_rows = m_fieldGrid->GetNumberRows();
238 
239  for( int count = 0; count < n_rows; ++count )
240  {
241  // Iterate backwards, unsigned-friendly way for future
242  int row = n_rows - count - 1;
243 
244  if( rows_to_delete[row] )
245  {
246  templateFields.erase( templateFields.begin() + row );
247  }
248  }
249 
251 }
252 
253 
254 void DIALOG_EESCHEMA_OPTIONS::OnScaleSlider( wxScrollEvent& aEvent )
255 {
256  m_scaleAuto->SetValue( false );
257 }
258 
259 
260 void DIALOG_EESCHEMA_OPTIONS::OnScaleAuto( wxCommandEvent& aEvent )
261 {
262  if( m_scaleAuto->GetValue() )
263  {
264  m_last_scale = m_scaleSlider->GetValue();
265  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
266  }
267  else
268  {
269  if( m_last_scale >= 0 )
270  m_scaleSlider->SetValue( m_last_scale );
271  }
272 }
273 
274 
276 {
277  if( !wxDialog::TransferDataToWindow() )
278  return false;
279 
281  return false;
282 
283  if( !TransferDataToFieldGrid() )
284  return false;
285 
286  int scale_fourths = GetParent()->GetIconScale();
287 
288  if( scale_fourths <= 0 )
289  {
290  m_scaleAuto->SetValue( true );
291  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
292  }
293  else
294  {
295  m_scaleAuto->SetValue( false );
296  m_scaleSlider->SetValue( scale_fourths * 25 );
297  }
298 
299  Layout();
300  return true;
301 }
302 
303 
305 {
306  m_lastPageSelected = m_notebook->GetSelection();
307 
308  if( !wxDialog::TransferDataFromWindow() )
309  return false;
310 
312  return false;
313 
315 
317  return false;
318 
320  return false;
321 
322  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
323 
324  if( GetParent()->GetIconScale() != scale_fourths )
325  GetParent()->SetIconScale( scale_fourths );
326 
327  // Refresh hotkeys
329  GetParent()->Refresh();
330 
331 
332  return true;
333 }
334 
335 
337 {
338  m_fieldGrid->Freeze();
339 
340  if( m_fieldGrid->GetNumberRows() )
341  m_fieldGrid->DeleteRows( 0, m_fieldGrid->GetNumberRows() );
342 
343  m_fieldGrid->AppendRows( templateFields.size() );
344 
345  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
346  {
347  m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name );
348  m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Value );
349  m_fieldGrid->SetCellValue( row, 2,
350  templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
351 
352  // Set cell properties
353  m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
354  m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_LEFT, wxALIGN_CENTRE );
355 
356  // Render the Visible column as a check box
357  m_fieldGrid->SetCellEditor( row, 2, new wxGridCellBoolEditor() );
358  m_fieldGrid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
359  m_fieldGrid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
360  }
361 
362  m_fieldGrid->AutoSizeRows();
363  m_fieldGrid->Thaw();
364 
365  return true;
366 }
367 
368 
370 {
371  for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
372  {
373  templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 );
374  templateFields[row].m_Value = m_fieldGrid->GetCellValue( row, 1 );
375  templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 2 ) != wxEmptyString );
376  }
377 
378  return true;
379 }
380 
382 {
383  // Set the template fields object
384  templateFields = aFields;
385 
386  // Build and refresh the view
388 }
389 
390 
392 {
393  return templateFields;
394 }
bool m_Visible
If first appearance of the field&#39;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...
int KiIconScale(wxWindow *aWindow)
Function KiIconScale Returns the automatic scale factor that would be used for a given window by KiSc...
Definition: bitmap.cpp:88
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.
void InstallOnPanel(wxPanel *aPanel)
Method InstallOnPanel Install this WIDGET_EESCHEMA_COLOR_CONFIG onto an empty panel.
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
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:69
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[]
int m_last_scale
saved icon scale when Auto selected
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.
void OnScaleAuto(wxCommandEvent &aEvent) override
void OnScaleSlider(wxScrollEvent &aEvent) override
void SetIconScale(int aScale) override
Function SetIconScale.
TEMPLATE_FIELDNAMES GetTemplateFields(void)
Function GetTemplateFields Get the dialog&#39;s template field data.
Class DIALOG_EESCHEMA_OPTIONS_BASE.
Struct TEMPLATE_FIELDNAME holds a name of a component&#39;s field, field value, and default visibility...
int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL) override
>
Definition: draw_frame.cpp:393
static int m_lastPageSelected
the active notebook page when closing this dialog strored to keep selection during a session ...
void SetStep(int aSize)
Set the step size.
int GetIconScale() override
Function GetIconScale.
void SetRefIdSeparator(wxChar aSep, wxChar aFirstId)
Function SetRefIdSeparator Sets the current RefIdSeparator value in the dialog.
BASE_SCREEN class implementation.
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.