KiCad PCB EDA Suite
fields_grid_table.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) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <kiway.h>
25 #include <kiway_player.h>
26 #include <dialog_shim.h>
27 #include <fields_grid_table.h>
28 #include <sch_base_frame.h>
29 #include <sch_field.h>
30 #include <sch_validators.h>
31 #include <validators.h>
32 #include <symbol_library.h>
33 #include <template_fieldnames.h>
36 #include <project/project_file.h>
37 #include "eda_doc.h"
38 #include <wx/settings.h>
39 #include <string_utils.h>
40 
41 
42 enum
43 {
44  MYID_SELECT_FOOTPRINT = GRIDTRICKS_FIRST_SHOWHIDE - 2, // must be within GRID_TRICKS' enum range
46 };
47 
48 
49 template <class T>
51  WX_GRID* aGrid, LIB_SYMBOL* aSymbol ) :
52  m_frame( aFrame ),
53  m_dialog( aDialog ),
54  m_grid( aGrid ),
55  m_parentType( SCH_SYMBOL_T ),
56  m_mandatoryFieldCount( MANDATORY_FIELDS ),
57  m_part( aSymbol ),
58  m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ),
59  m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), REFERENCE_FIELD ),
60  m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ),
61  m_libIdValidator(),
62  m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
63  m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
64  m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME )
65 {
66  initGrid( aGrid );
67 }
68 
69 
70 template <class T>
72  WX_GRID* aGrid, SCH_SHEET* aSheet ) :
73  m_frame( aFrame ),
74  m_dialog( aDialog ),
75  m_grid( aGrid ),
76  m_parentType( SCH_SHEET_T ),
77  m_mandatoryFieldCount( SHEET_MANDATORY_FIELDS ),
78  m_part( nullptr ),
79  m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ),
80  m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETNAME_V ),
81  m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ),
82  m_libIdValidator(),
83  m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
84  m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
85  m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME_V )
86 {
87  initGrid( aGrid );
88 }
89 
90 
91 template <class T>
93 {
94  // Build the various grid cell attributes.
95  // NOTE: validators and cellAttrs are member variables to get the destruction order
96  // right. wxGrid is VERY cranky about this.
97 
98  m_readOnlyAttr = new wxGridCellAttr;
99  m_readOnlyAttr->SetReadOnly( true );
100 
101  m_fieldNameAttr = new wxGridCellAttr;
102  GRID_CELL_TEXT_EDITOR* nameEditor = new GRID_CELL_TEXT_EDITOR();
103  nameEditor->SetValidator( m_fieldNameValidator );
104  m_fieldNameAttr->SetEditor( nameEditor );
105 
106  m_referenceAttr = new wxGridCellAttr;
107  GRID_CELL_TEXT_EDITOR* referenceEditor = new GRID_CELL_TEXT_EDITOR();
108  referenceEditor->SetValidator( m_referenceValidator );
109  m_referenceAttr->SetEditor( referenceEditor );
110 
111  m_valueAttr = new wxGridCellAttr;
112  GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
113  valueEditor->SetValidator( m_valueValidator );
114  m_valueAttr->SetEditor( valueEditor );
115 
116  m_footprintAttr = new wxGridCellAttr;
117  GRID_CELL_FOOTPRINT_ID_EDITOR* fpIdEditor = new GRID_CELL_FOOTPRINT_ID_EDITOR( m_dialog );
118  fpIdEditor->SetValidator( m_libIdValidator );
119  m_footprintAttr->SetEditor( fpIdEditor );
120 
121  m_urlAttr = new wxGridCellAttr;
122  GRID_CELL_URL_EDITOR* urlEditor =
123  new GRID_CELL_URL_EDITOR( m_dialog, m_frame->Prj().SchSearchS() );
124  urlEditor->SetValidator( m_urlValidator );
125  m_urlAttr->SetEditor( urlEditor );
126 
127  m_nonUrlAttr = new wxGridCellAttr;
128  GRID_CELL_TEXT_EDITOR* nonUrlEditor = new GRID_CELL_TEXT_EDITOR();
129  nonUrlEditor->SetValidator( m_nonUrlValidator );
130  m_nonUrlAttr->SetEditor( nonUrlEditor );
131 
132  m_curdir = m_frame->Prj().GetProjectPath();
133  m_filepathAttr = new wxGridCellAttr;
134 
135  // Create a wild card using wxFileDialog syntax.
136  wxString wildCard( _( "Schematic Files" ) );
137  std::vector<std::string> exts;
138  exts.push_back( KiCadSchematicFileExtension );
139  wildCard += AddFileExtListToFilter( exts );
140 
141  auto filepathEditor = new GRID_CELL_PATH_EDITOR( m_dialog, aGrid, &m_curdir, wildCard );
142  filepathEditor->SetValidator( m_filepathValidator );
143  m_filepathAttr->SetEditor( filepathEditor );
144 
145  m_boolAttr = new wxGridCellAttr;
146  m_boolAttr->SetRenderer( new wxGridCellBoolRenderer() );
147  m_boolAttr->SetEditor( new wxGridCellBoolEditor() );
148  m_boolAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
149 
150  wxArrayString vAlignNames;
151  vAlignNames.Add( _( "Top" ) );
152  vAlignNames.Add( _( "Center" ) );
153  vAlignNames.Add( _( "Bottom" ) );
154  m_vAlignAttr = new wxGridCellAttr;
155  m_vAlignAttr->SetEditor( new wxGridCellChoiceEditor( vAlignNames ) );
156  m_vAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
157 
158  wxArrayString hAlignNames;
159  hAlignNames.Add( _( "Left" ) );
160  hAlignNames.Add(_( "Center" ) );
161  hAlignNames.Add(_( "Right" ) );
162  m_hAlignAttr = new wxGridCellAttr;
163  m_hAlignAttr->SetEditor( new wxGridCellChoiceEditor( hAlignNames ) );
164  m_hAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
165 
166  wxArrayString orientationNames;
167  orientationNames.Add( _( "Horizontal" ) );
168  orientationNames.Add(_( "Vertical" ) );
169  m_orientationAttr = new wxGridCellAttr;
170  m_orientationAttr->SetEditor( new wxGridCellChoiceEditor( orientationNames ) );
171  m_orientationAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
172 
173  m_frame->Bind( UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
174 }
175 
176 
177 template <class T>
179 {
180  m_readOnlyAttr->DecRef();
181  m_fieldNameAttr->DecRef();
182  m_boolAttr->DecRef();
183  m_referenceAttr->DecRef();
184  m_valueAttr->DecRef();
185  m_footprintAttr->DecRef();
186  m_urlAttr->DecRef();
187  m_nonUrlAttr->DecRef();
188  m_filepathAttr->DecRef();
189  m_vAlignAttr->DecRef();
190  m_hAlignAttr->DecRef();
191  m_orientationAttr->DecRef();
192 
193  m_frame->Unbind( UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
194 }
195 
196 
197 template <class T>
198 void FIELDS_GRID_TABLE<T>::onUnitsChanged( wxCommandEvent& aEvent )
199 {
200  if( GetView() )
201  GetView()->ForceRefresh();
202 
203  aEvent.Skip();
204 }
205 
206 
207 template <class T>
209 {
210  switch( aCol )
211  {
212  case FDC_NAME: return _( "Name" );
213  case FDC_VALUE: return _( "Value" );
214  case FDC_SHOWN: return _( "Show" );
215  case FDC_H_ALIGN: return _( "H Align" );
216  case FDC_V_ALIGN: return _( "V Align" );
217  case FDC_ITALIC: return _( "Italic" );
218  case FDC_BOLD: return _( "Bold" );
219  case FDC_TEXT_SIZE: return _( "Text Size" );
220  case FDC_ORIENTATION: return _( "Orientation" );
221  case FDC_POSX: return _( "X Position" );
222  case FDC_POSY: return _( "Y Position" );
223  default: wxFAIL; return wxEmptyString;
224  }
225 }
226 
227 
228 template <class T>
229 bool FIELDS_GRID_TABLE<T>::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
230 {
231  switch( aCol )
232  {
233  case FDC_NAME:
234  case FDC_VALUE:
235  case FDC_H_ALIGN:
236  case FDC_V_ALIGN:
237  case FDC_TEXT_SIZE:
238  case FDC_ORIENTATION:
239  case FDC_POSX:
240  case FDC_POSY:
241  return aTypeName == wxGRID_VALUE_STRING;
242 
243  case FDC_SHOWN:
244  case FDC_ITALIC:
245  case FDC_BOLD:
246  return aTypeName == wxGRID_VALUE_BOOL;
247 
248  default:
249  wxFAIL;
250  return false;
251  }
252 }
253 
254 
255 template <class T>
256 bool FIELDS_GRID_TABLE<T>::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
257 {
258  return CanGetValueAs( aRow, aCol, aTypeName );
259 }
260 
261 
262 template <class T>
263 wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
264 {
265  wxGridCellAttr* tmp;
266 
267  switch( aCol )
268  {
269  case FDC_NAME:
270  if( aRow < m_mandatoryFieldCount )
271  {
272  tmp = m_fieldNameAttr->Clone();
273  tmp->SetReadOnly( true );
274  return tmp;
275  }
276  else
277  {
278  m_fieldNameAttr->IncRef();
279  return m_fieldNameAttr;
280  }
281 
282  case FDC_VALUE:
283  if( m_parentType == SCH_SYMBOL_T && aRow == REFERENCE_FIELD )
284  {
285  m_referenceAttr->IncRef();
286  return m_referenceAttr;
287  }
288  else if( m_parentType == SCH_SYMBOL_T && aRow == VALUE_FIELD )
289  {
290  // For power symbols, the value is not editable, because value and pin name must
291  // be the same and can be edited only in library editor.
292  if( ( m_part && m_part->IsPower() && !m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) ) )
293  {
294  tmp = m_readOnlyAttr->Clone();
295  tmp->SetReadOnly( true );
296  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
297  return tmp;
298  }
299  else
300  {
301  m_valueAttr->IncRef();
302  return m_valueAttr;
303  }
304  }
305  else if( m_parentType == SCH_SYMBOL_T && aRow == FOOTPRINT_FIELD )
306  {
307  m_footprintAttr->IncRef();
308  return m_footprintAttr;
309  }
310  else if( m_parentType == SCH_SYMBOL_T && aRow == DATASHEET_FIELD )
311  {
312  m_urlAttr->IncRef();
313  return m_urlAttr;
314  }
315  else if( m_parentType == SCH_SHEET_T && aRow == SHEETNAME )
316  {
317  m_referenceAttr->IncRef();
318  return m_referenceAttr;
319  }
320  else if( m_parentType == SCH_SHEET_T && aRow == SHEETFILENAME )
321  {
322  m_filepathAttr->IncRef();
323  return m_filepathAttr;
324  }
325  else
326  {
327  wxString fn = GetValue( aRow, FDC_NAME );
328 
329  SCHEMATIC_SETTINGS* settings = m_frame->Prj().GetProjectFile().m_SchematicSettings;
330 
331  const TEMPLATE_FIELDNAME* templateFn =
332  settings ? settings->m_TemplateFieldNames.GetFieldName( fn ) : nullptr;
333 
334  if( templateFn && templateFn->m_URL )
335  {
336  m_urlAttr->IncRef();
337  return m_urlAttr;
338  }
339  else
340  {
341  m_nonUrlAttr->IncRef();
342  return m_nonUrlAttr;
343  }
344  }
345 
346  return nullptr;
347 
348  case FDC_TEXT_SIZE:
349  case FDC_POSX:
350  case FDC_POSY:
351  return nullptr;
352 
353  case FDC_H_ALIGN:
354  m_hAlignAttr->IncRef();
355  return m_hAlignAttr;
356 
357  case FDC_V_ALIGN:
358  m_vAlignAttr->IncRef();
359  return m_vAlignAttr;
360 
361  case FDC_ORIENTATION:
362  m_orientationAttr->IncRef();
363  return m_orientationAttr;
364 
365  case FDC_SHOWN:
366  case FDC_ITALIC:
367  case FDC_BOLD:
368  m_boolAttr->IncRef();
369  return m_boolAttr;
370 
371  default:
372  wxFAIL;
373  return nullptr;
374  }
375 }
376 
377 
378 template <class T>
379 wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
380 {
381  wxCHECK( aRow < GetNumberRows(), wxEmptyString );
382  const T& field = this->at( (size_t) aRow );
383 
384  switch( aCol )
385  {
386  case FDC_NAME:
387  // Use default field name for mandatory fields, because they are translated
388  // according to the current locale
389  if( aRow < m_mandatoryFieldCount )
390  {
391  if( m_parentType == SCH_SYMBOL_T )
393  else if( m_parentType == SCH_SHEET_T )
394  return SCH_SHEET::GetDefaultFieldName( aRow );
395  }
396 
397  return field.GetName( false );
398 
399  case FDC_VALUE:
400  return UnescapeString( field.GetText() );
401 
402  case FDC_SHOWN:
403  return StringFromBool( field.IsVisible() );
404 
405  case FDC_H_ALIGN:
406  switch ( field.GetHorizJustify() )
407  {
408  case GR_TEXT_HJUSTIFY_LEFT: return _( "Left" );
409  case GR_TEXT_HJUSTIFY_CENTER: return _( "Center" );
410  case GR_TEXT_HJUSTIFY_RIGHT: return _( "Right" );
411  }
412 
413  break;
414 
415  case FDC_V_ALIGN:
416  switch ( field.GetVertJustify() )
417  {
418  case GR_TEXT_VJUSTIFY_TOP: return _( "Top" );
419  case GR_TEXT_VJUSTIFY_CENTER: return _( "Center" );
420  case GR_TEXT_VJUSTIFY_BOTTOM: return _( "Bottom" );
421  }
422 
423  break;
424 
425  case FDC_ITALIC:
426  return StringFromBool( field.IsItalic() );
427 
428  case FDC_BOLD:
429  return StringFromBool( field.IsBold() );
430 
431  case FDC_TEXT_SIZE:
432  return StringFromValue( m_frame->GetUserUnits(), field.GetTextSize().GetHeight(), true );
433 
434  case FDC_ORIENTATION:
435  switch ( (int) field.GetTextAngle() )
436  {
437  case TEXT_ANGLE_HORIZ: return _( "Horizontal" );
438  case TEXT_ANGLE_VERT: return _( "Vertical" );
439  }
440 
441  break;
442 
443  case FDC_POSX:
444  return StringFromValue( m_frame->GetUserUnits(), field.GetTextPos().x, true );
445 
446  case FDC_POSY:
447  return StringFromValue( m_frame->GetUserUnits(), field.GetTextPos().y, true );
448 
449  default:
450  // we can't assert here because wxWidgets sometimes calls this without checking
451  // the column type when trying to see if there's an overflow
452  break;
453  }
454 
455  return wxT( "bad wxWidgets!" );
456 }
457 
458 
459 template <class T>
460 bool FIELDS_GRID_TABLE<T>::GetValueAsBool( int aRow, int aCol )
461 {
462  wxCHECK( aRow < GetNumberRows(), false );
463  const T& field = this->at( (size_t) aRow );
464 
465  switch( aCol )
466  {
467  case FDC_SHOWN: return field.IsVisible();
468  case FDC_ITALIC: return field.IsItalic();
469  case FDC_BOLD: return field.IsBold();
470  default:
471  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
472  return false;
473  }
474 }
475 
476 
477 template <class T>
478 void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue )
479 {
480  wxCHECK( aRow < GetNumberRows(), /*void*/ );
481  T& field = this->at( (size_t) aRow );
482  wxPoint pos;
483 
484  switch( aCol )
485  {
486  case FDC_NAME:
487  field.SetName( aValue );
488  break;
489 
490  case FDC_VALUE:
491  {
492  wxString value( aValue );
493 
494  if( m_parentType == SCH_SHEET_T && aRow == SHEETFILENAME )
495  {
496  wxFileName fn( value );
497 
498  // It's annoying to throw up nag dialogs when the extension isn't right. Just
499  // fix it.
500  if( fn.GetExt().CmpNoCase( KiCadSchematicFileExtension ) != 0 )
501  {
502  fn.SetExt( KiCadSchematicFileExtension );
503  value = fn.GetFullPath();
504  }
505  }
506  else if( m_parentType == SCH_SYMBOL_T && aRow == VALUE_FIELD )
507  {
508  value = EscapeString( value, CTX_LIBID );
509  }
510 
511  field.SetText( value );
512  }
513  break;
514 
515  case FDC_SHOWN:
516  field.SetVisible( BoolFromString( aValue ) );
517  break;
518 
519  case FDC_H_ALIGN:
520  if( aValue == _( "Left" ) )
521  field.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
522  else if( aValue == _( "Center" ) )
523  field.SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
524  else if( aValue == _( "Right" ) )
525  field.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
526  else
527  wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + aValue );
528  break;
529 
530  case FDC_V_ALIGN:
531  if( aValue == _( "Top" ) )
532  field.SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
533  else if( aValue == _( "Center" ) )
534  field.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
535  else if( aValue == _( "Bottom" ) )
536  field.SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
537  else
538  wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + aValue);
539  break;
540 
541  case FDC_ITALIC:
542  field.SetItalic( BoolFromString( aValue ) );
543  break;
544 
545  case FDC_BOLD:
546  field.SetBold( BoolFromString( aValue ) );
547  break;
548 
549  case FDC_TEXT_SIZE:
550  field.SetTextSize( wxSize( ValueFromString( m_frame->GetUserUnits(), aValue ),
551  ValueFromString( m_frame->GetUserUnits(), aValue ) ) );
552  break;
553 
554  case FDC_ORIENTATION:
555  if( aValue == _( "Horizontal" ) )
556  field.SetTextAngle( TEXT_ANGLE_HORIZ );
557  else if( aValue == _( "Vertical" ) )
558  field.SetTextAngle( TEXT_ANGLE_VERT );
559  else
560  wxFAIL_MSG( wxT( "unknown orientation: " ) + aValue );
561  break;
562 
563  case FDC_POSX:
564  case FDC_POSY:
565  pos = field.GetTextPos();
566  if( aCol == FDC_POSX )
567  pos.x = ValueFromString( m_frame->GetUserUnits(), aValue );
568  else
569  pos.y = ValueFromString( m_frame->GetUserUnits(), aValue );
570  field.SetTextPos( pos );
571  break;
572 
573  default:
574  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
575  break;
576  }
577 
578  m_dialog->OnModify();
579 
580  GetView()->Refresh();
581 }
582 
583 
584 template <class T>
585 void FIELDS_GRID_TABLE<T>::SetValueAsBool( int aRow, int aCol, bool aValue )
586 {
587  wxCHECK( aRow < GetNumberRows(), /*void*/ );
588  T& field = this->at( (size_t) aRow );
589 
590  switch( aCol )
591  {
592  case FDC_SHOWN:
593  field.SetVisible( aValue );
594  break;
595  case FDC_ITALIC:
596  field.SetItalic( aValue );
597  break;
598  case FDC_BOLD:
599  field.SetBold( aValue );
600  break;
601  default:
602  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
603  break;
604  }
605 
606  m_dialog->OnModify();
607 }
608 
609 
610 // Explicit Instantiations
611 
612 template class FIELDS_GRID_TABLE<SCH_FIELD>;
613 template class FIELDS_GRID_TABLE<LIB_FIELD>;
614 
615 
617 {
618  if( m_grid->GetGridCursorRow() == FOOTPRINT_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE )
619  {
620  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
621  _( "Browse for footprint" ) );
622  menu.AppendSeparator();
623  }
624  else if( m_grid->GetGridCursorRow() == DATASHEET_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE )
625  {
626  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
627  _( "Show datasheet in browser" ) );
628  menu.AppendSeparator();
629  }
630 
632 }
633 
634 
635 void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
636 {
637  if( event.GetId() == MYID_SELECT_FOOTPRINT )
638  {
639  // pick a footprint using the footprint picker.
640  wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE );
642 
643  if( frame->ShowModal( &fpid, m_dlg ) )
644  m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid );
645 
646  frame->Destroy();
647  }
648  else if (event.GetId() == MYID_SHOW_DATASHEET )
649  {
650  wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE );
651  GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(), m_dlg->Prj().SchSearchS() );
652  }
653  else
654  {
656  }
657 }
658 
659 
660 template <class T>
661 wxString FIELDS_GRID_TABLE<T>::StringFromBool( bool aValue ) const
662 {
663  if( aValue )
664  return wxT( "1" );
665  else
666  return wxT( "0" );
667 }
668 
669 
670 template <class T>
671 bool FIELDS_GRID_TABLE<T>::BoolFromString( wxString aValue ) const
672 {
673  if( aValue == wxT( "1" ) )
674  {
675  return true;
676  }
677  else if( aValue == wxT( "0" ) )
678  {
679  return false;
680  }
681  else
682  {
683  wxFAIL_MSG( wxString::Format( wxT( "string '%s' can't be converted to boolean " )
684  wxT( "correctly, it will have been perceived as FALSE" ), aValue ) );
685  return false;
686  }
687 }
Field Reference of part, i.e. "IC21".
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
bool BoolFromString(wxString aValue) const
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:71
virtual void showPopupMenu(wxMenu &menu) override
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
This file is part of the common library.
TEMPLATES m_TemplateFieldNames
#define FIELD_VALUE
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:53
void initGrid(WX_GRID *aGrid)
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:393
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:82
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:74
wxString GetColLabelValue(int aCol) override
Define a library symbol object.
Definition: lib_symbol.h:96
#define SHEETNAME_V
name of datasheet
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
Definition: validators.h:44
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
wxString StringFromBool(bool aValue) const
Field Value of part, i.e. "3.3K".
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:416
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Definitions of control validators for schematic dialogs.
wxString GetValue(int aRow, int aCol) override
#define SHEETFILENAME_V
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override
Definition of file extensions used in Kicad.
#define FIELD_NAME
Definition for symbol library class.
#define _(s)
FIELDS_GRID_TABLE(DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, WX_GRID *aGrid, LIB_SYMBOL *aSymbol)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
void onUnitsChanged(wxCommandEvent &aEvent)
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) override
wxString UnescapeString(const wxString &aSource)
virtual void SetValidator(const wxValidator &validator) override
Definition: validators.cpp:46
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
virtual void doPopupSelection(wxCommandEvent &event)
bool GetValueAsBool(int aRow, int aCol) override
virtual void showPopupMenu(wxMenu &menu)
void SetValue(int aRow, int aCol, const wxString &aValue) override
const std::string KiCadSchematicFileExtension
These settings were stored in SCH_BASE_FRAME previously.
Hold a name of a symbol's field, field value, and default visibility.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
#define TEXT_ANGLE_VERT
Definition: eda_text.h:72
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
void SetValueAsBool(int aRow, int aCol, bool aValue) override
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
virtual void doPopupSelection(wxCommandEvent &event) override
Custom text control validator definitions.
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
Field Name Module PCB, i.e. "16DIP300".