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-2020 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 <class_library.h>
33 #include <template_fieldnames.h>
37 
38 #include "eda_doc.h"
39 
40 
41 enum
42 {
43  MYID_SELECT_FOOTPRINT = 991, // must be within GRID_TRICKS' enum range
45 };
46 
47 
48 template <class T>
50  LIB_PART* aPart ) :
51  m_frame( aFrame ),
52  m_userUnits( aDialog->GetUserUnits() ),
53  m_parentType( SCH_COMPONENT_T ),
54  m_mandatoryFieldCount( MANDATORY_FIELDS ),
55  m_part( aPart ),
56  m_fieldNameValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_NAME ),
57  m_referenceValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), REFERENCE ),
58  m_valueValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), VALUE ),
59  m_libIdValidator( LIB_ID::ID_PCB ),
60  m_urlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_VALUE ),
61  m_nonUrlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_VALUE ),
62  m_filepathValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), SHEETFILENAME )
63 {
64  initGrid( aDialog );
65 }
66 
67 
68 template <class T>
70  SCH_SHEET* aSheet ) :
71  m_frame( aFrame ),
72  m_userUnits( aDialog->GetUserUnits() ),
73  m_parentType( SCH_SHEET_T ),
74  m_mandatoryFieldCount( SHEET_MANDATORY_FIELDS ),
75  m_part( nullptr ),
76  m_fieldNameValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_NAME ),
77  m_referenceValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), REFERENCE ),
78  m_valueValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), VALUE ),
79  m_libIdValidator( LIB_ID::ID_PCB ),
80  m_urlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_VALUE ),
81  m_nonUrlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_VALUE ),
82  m_filepathValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), SHEETFILENAME )
83 {
84  initGrid( aDialog );
85 }
86 
87 
88 template <class T>
90 {
91  // Build the various grid cell attributes.
92  // NOTE: validators and cellAttrs are member variables to get the destruction order
93  // right. wxGrid is VERY cranky about this.
94 
95  m_readOnlyAttr = new wxGridCellAttr;
96  m_readOnlyAttr->SetReadOnly( true );
97 
98  m_fieldNameAttr = new wxGridCellAttr;
99  GRID_CELL_TEXT_EDITOR* nameEditor = new GRID_CELL_TEXT_EDITOR();
100  nameEditor->SetValidator( m_fieldNameValidator );
101  m_fieldNameAttr->SetEditor( nameEditor );
102 
103  m_referenceAttr = new wxGridCellAttr;
104  GRID_CELL_TEXT_EDITOR* referenceEditor = new GRID_CELL_TEXT_EDITOR();
105  referenceEditor->SetValidator( m_referenceValidator );
106  m_referenceAttr->SetEditor( referenceEditor );
107 
108  m_valueAttr = new wxGridCellAttr;
109  GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
110  valueEditor->SetValidator( m_valueValidator );
111  m_valueAttr->SetEditor( valueEditor );
112 
113  m_footprintAttr = new wxGridCellAttr;
115  fpIdEditor->SetValidator( m_libIdValidator );
116  m_footprintAttr->SetEditor( fpIdEditor );
117 
118  m_urlAttr = new wxGridCellAttr;
119  GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( aDialog );
120  urlEditor->SetValidator( m_urlValidator );
121  m_urlAttr->SetEditor( urlEditor );
122 
123  m_nonUrlAttr = new wxGridCellAttr;
124  GRID_CELL_TEXT_EDITOR* nonUrlEditor = new GRID_CELL_TEXT_EDITOR();
125  nonUrlEditor->SetValidator( m_nonUrlValidator );
126  m_nonUrlAttr->SetEditor( nonUrlEditor );
127 
128  m_curdir = m_frame->Prj().GetProjectPath();
129  m_filepathAttr = new wxGridCellAttr;
130  GRID_CELL_PATH_EDITOR* filepathEditor =
131  new GRID_CELL_PATH_EDITOR( aDialog, &m_curdir, LegacySchematicFileExtension );
132  filepathEditor->SetValidator( m_filepathValidator );
133  m_filepathAttr->SetEditor( filepathEditor );
134 
135  m_boolAttr = new wxGridCellAttr;
136  m_boolAttr->SetRenderer( new wxGridCellBoolRenderer() );
137  m_boolAttr->SetEditor( new wxGridCellBoolEditor() );
138  m_boolAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
139 
140  wxArrayString vAlignNames;
141  vAlignNames.Add( _( "Top" ) );
142  vAlignNames.Add( _( "Center" ) );
143  vAlignNames.Add( _( "Bottom" ) );
144  m_vAlignAttr = new wxGridCellAttr;
145  m_vAlignAttr->SetEditor( new wxGridCellChoiceEditor( vAlignNames ) );
146  m_vAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
147 
148  wxArrayString hAlignNames;
149  hAlignNames.Add( _( "Left" ) );
150  hAlignNames.Add(_( "Center" ) );
151  hAlignNames.Add(_( "Right" ) );
152  m_hAlignAttr = new wxGridCellAttr;
153  m_hAlignAttr->SetEditor( new wxGridCellChoiceEditor( hAlignNames ) );
154  m_hAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
155 
156  wxArrayString orientationNames;
157  orientationNames.Add( _( "Horizontal" ) );
158  orientationNames.Add(_( "Vertical" ) );
159  m_orientationAttr = new wxGridCellAttr;
160  m_orientationAttr->SetEditor( new wxGridCellChoiceEditor( orientationNames ) );
161  m_orientationAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
162 }
163 
164 
165 template <class T>
167 {
168  m_readOnlyAttr->DecRef();
169  m_fieldNameAttr->DecRef();
170  m_boolAttr->DecRef();
171  m_referenceAttr->DecRef();
172  m_valueAttr->DecRef();
173  m_footprintAttr->DecRef();
174  m_urlAttr->DecRef();
175  m_nonUrlAttr->DecRef();
176  m_filepathAttr->DecRef();
177  m_vAlignAttr->DecRef();
178  m_hAlignAttr->DecRef();
179  m_orientationAttr->DecRef();
180 }
181 
182 
183 template <class T>
185 {
186  switch( aCol )
187  {
188  case FDC_NAME: return _( "Name" );
189  case FDC_VALUE: return _( "Value" );
190  case FDC_SHOWN: return _( "Show" );
191  case FDC_H_ALIGN: return _( "H Align" );
192  case FDC_V_ALIGN: return _( "V Align" );
193  case FDC_ITALIC: return _( "Italic" );
194  case FDC_BOLD: return _( "Bold" );
195  case FDC_TEXT_SIZE: return _( "Text Size" );
196  case FDC_ORIENTATION: return _( "Orientation" );
197  case FDC_POSX: return _( "X Position" );
198  case FDC_POSY: return _( "Y Position" );
199  default: wxFAIL; return wxEmptyString;
200  }
201 }
202 
203 
204 template <class T>
205 bool FIELDS_GRID_TABLE<T>::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
206 {
207  switch( aCol )
208  {
209  case FDC_NAME:
210  case FDC_VALUE:
211  case FDC_H_ALIGN:
212  case FDC_V_ALIGN:
213  case FDC_TEXT_SIZE:
214  case FDC_ORIENTATION:
215  case FDC_POSX:
216  case FDC_POSY:
217  return aTypeName == wxGRID_VALUE_STRING;
218 
219  case FDC_SHOWN:
220  case FDC_ITALIC:
221  case FDC_BOLD:
222  return aTypeName == wxGRID_VALUE_BOOL;
223 
224  default:
225  wxFAIL;
226  return false;
227  }
228 }
229 
230 
231 template <class T>
232 bool FIELDS_GRID_TABLE<T>::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
233 {
234  return CanGetValueAs( aRow, aCol, aTypeName );
235 }
236 
237 
238 template <class T>
239 wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
240 {
241  wxGridCellAttr* tmp;
242 
243  // Only the VALUE and DATASHEET fields can be edited for inherited symbols.
244  bool rowIsReadOnly = m_part && m_part->IsAlias() && ( aRow == REFERENCE || aRow == FOOTPRINT );
245 
246  switch( aCol )
247  {
248  case FDC_NAME:
249  if( aRow < m_mandatoryFieldCount || rowIsReadOnly )
250  {
251  tmp = m_fieldNameAttr->Clone();
252  tmp->SetReadOnly( true );
253  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
254  return tmp;
255  }
256  else
257  {
258  m_fieldNameAttr->IncRef();
259  return m_fieldNameAttr;
260  }
261 
262  case FDC_VALUE:
263  if( m_parentType == SCH_COMPONENT_T && aRow == REFERENCE )
264  {
265  if( rowIsReadOnly )
266  {
267  tmp = m_referenceAttr->Clone();
268  tmp->SetReadOnly( true );
269  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
270  return tmp;
271  }
272  else
273  {
274  m_referenceAttr->IncRef();
275  return m_referenceAttr;
276  }
277  }
278  else if( m_parentType == SCH_COMPONENT_T && aRow == VALUE )
279  {
280  // For power symbols, the value is not editable, because value and pin name must
281  // be the same and can be edited only in library editor.
282  if( ( m_part && m_part->IsPower() && !m_frame->IsType( FRAME_SCH_LIB_EDITOR ) )
283  || rowIsReadOnly )
284  {
285  tmp = m_readOnlyAttr->Clone();
286  tmp->SetReadOnly( true );
287  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
288  return tmp;
289  }
290  else
291  {
292  m_valueAttr->IncRef();
293  return m_valueAttr;
294  }
295  }
296  else if( m_parentType == SCH_COMPONENT_T && aRow == FOOTPRINT )
297  {
298  if( rowIsReadOnly )
299  {
300  tmp = m_footprintAttr->Clone();
301  tmp->SetReadOnly( true );
302  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
303  return tmp;
304  }
305  else
306  {
307  m_footprintAttr->IncRef();
308  return m_footprintAttr;
309  }
310  }
311  else if( m_parentType == SCH_COMPONENT_T && aRow == DATASHEET )
312  {
313  m_urlAttr->IncRef();
314  return m_urlAttr;
315  }
316  else if( m_parentType == SCH_SHEET_T && aRow == SHEETFILENAME )
317  {
318  m_filepathAttr->IncRef();
319  return m_filepathAttr;
320  }
321  else
322  {
323  wxString fieldname = GetValue( aRow, FDC_NAME );
324  const TEMPLATE_FIELDNAME* templateFn = m_frame->GetTemplateFieldName( fieldname );
325 
326  if( templateFn && templateFn->m_URL )
327  {
328  if( rowIsReadOnly )
329  {
330  tmp = m_urlAttr->Clone();
331  tmp->SetReadOnly( true );
332  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
333  return tmp;
334  }
335  else
336  {
337  m_urlAttr->IncRef();
338  return m_urlAttr;
339  }
340  }
341  else
342  {
343  if( rowIsReadOnly )
344  {
345  tmp = m_nonUrlAttr->Clone();
346  tmp->SetReadOnly( true );
347  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
348  return tmp;
349  }
350  else
351  {
352  m_nonUrlAttr->IncRef();
353  return m_nonUrlAttr;
354  }
355  }
356  }
357 
358  return nullptr;
359 
360  case FDC_TEXT_SIZE:
361  case FDC_POSX:
362  case FDC_POSY:
363  if( rowIsReadOnly )
364  {
365  tmp = m_readOnlyAttr->Clone();
366  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
367  return tmp;
368  }
369  else
370  {
371  return nullptr;
372  }
373 
374  case FDC_H_ALIGN:
375  if( rowIsReadOnly )
376  {
377  tmp = m_hAlignAttr->Clone();
378  tmp->SetReadOnly( true );
379  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
380  return tmp;
381  }
382  else
383  {
384  m_hAlignAttr->IncRef();
385  return m_hAlignAttr;
386  }
387 
388  case FDC_V_ALIGN:
389  if( rowIsReadOnly )
390  {
391  tmp = m_vAlignAttr->Clone();
392  tmp->SetReadOnly( true );
393  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
394  return tmp;
395  }
396  else
397  {
398  m_vAlignAttr->IncRef();
399  return m_vAlignAttr;
400  }
401 
402  case FDC_ORIENTATION:
403  if( rowIsReadOnly )
404  {
405  tmp = m_orientationAttr->Clone();
406  tmp->SetReadOnly( true );
407  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
408  return tmp;
409  }
410  else
411  {
412  m_orientationAttr->IncRef();
413  return m_orientationAttr;
414  }
415 
416  case FDC_SHOWN:
417  case FDC_ITALIC:
418  case FDC_BOLD:
419  if( rowIsReadOnly )
420  {
421  tmp = m_boolAttr->Clone();
422  tmp->SetReadOnly( true );
423  tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
424  return tmp;
425  }
426  else
427  {
428  m_boolAttr->IncRef();
429  return m_boolAttr;
430  }
431 
432  default:
433  wxFAIL;
434  return nullptr;
435  }
436 }
437 
438 
439 template <class T>
440 wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
441 {
442  wxCHECK( aRow < GetNumberRows(), wxEmptyString );
443  const T& field = this->at( (size_t) aRow );
444 
445  switch( aCol )
446  {
447  case FDC_NAME:
448  // Use default field name for mandatory fields, because they are translated
449  // according to the current locale
450  if( aRow < m_mandatoryFieldCount )
451  {
452  if( m_parentType == SCH_COMPONENT_T )
454  else if( m_parentType == SCH_SHEET_T )
455  return SCH_SHEET::GetDefaultFieldName( aRow );
456  }
457 
458  return field.GetName( false );
459 
460  case FDC_VALUE:
461  return field.GetText();
462 
463  case FDC_SHOWN:
464  return StringFromBool( field.IsVisible() );
465 
466  case FDC_H_ALIGN:
467  switch ( field.GetHorizJustify() )
468  {
469  case GR_TEXT_HJUSTIFY_LEFT: return _( "Left" );
470  case GR_TEXT_HJUSTIFY_CENTER: return _( "Center" );
471  case GR_TEXT_HJUSTIFY_RIGHT: return _( "Right" );
472  }
473 
474  break;
475 
476  case FDC_V_ALIGN:
477  switch ( field.GetVertJustify() )
478  {
479  case GR_TEXT_VJUSTIFY_TOP: return _( "Top" );
480  case GR_TEXT_VJUSTIFY_CENTER: return _( "Center" );
481  case GR_TEXT_VJUSTIFY_BOTTOM: return _( "Bottom" );
482  }
483 
484  break;
485 
486  case FDC_ITALIC:
487  return StringFromBool( field.IsItalic() );
488 
489  case FDC_BOLD:
490  return StringFromBool( field.IsBold() );
491 
492  case FDC_TEXT_SIZE:
493  return StringFromValue( m_userUnits, field.GetTextSize().GetHeight(), true, true );
494 
495  case FDC_ORIENTATION:
496  switch ( (int) field.GetTextAngle() )
497  {
498  case TEXT_ANGLE_HORIZ: return _( "Horizontal" );
499  case TEXT_ANGLE_VERT: return _( "Vertical" );
500  }
501 
502  break;
503 
504  case FDC_POSX:
505  return StringFromValue( m_userUnits, field.GetTextPos().x, true );
506 
507  case FDC_POSY:
508  return StringFromValue( m_userUnits, field.GetTextPos().y, true );
509 
510  default:
511  // we can't assert here because wxWidgets sometimes calls this without checking
512  // the column type when trying to see if there's an overflow
513  break;
514  }
515 
516  return wxT( "bad wxWidgets!" );
517 }
518 
519 
520 template <class T>
521 bool FIELDS_GRID_TABLE<T>::GetValueAsBool( int aRow, int aCol )
522 {
523  wxCHECK( aRow < GetNumberRows(), false );
524  const T& field = this->at( (size_t) aRow );
525 
526  switch( aCol )
527  {
528  case FDC_SHOWN: return field.IsVisible();
529  case FDC_ITALIC: return field.IsItalic();
530  case FDC_BOLD: return field.IsBold();
531  default:
532  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
533  return false;
534  }
535 }
536 
537 
538 template <class T>
539 void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue )
540 {
541  wxCHECK( aRow < GetNumberRows(), /*void*/ );
542  T& field = this->at( (size_t) aRow );
543  wxPoint pos;
544 
545  switch( aCol )
546  {
547  case FDC_NAME:
548  field.SetName( aValue );
549  break;
550 
551  case FDC_VALUE:
552  field.SetText( aValue );
553  break;
554 
555  case FDC_SHOWN:
556  field.SetVisible( BoolFromString( aValue ) );
557  break;
558 
559  case FDC_H_ALIGN:
560  if( aValue == _( "Left" ) )
561  field.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
562  else if( aValue == _( "Center" ) )
563  field.SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
564  else if( aValue == _( "Right" ) )
565  field.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
566  else
567  wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + aValue );
568  break;
569 
570  case FDC_V_ALIGN:
571  if( aValue == _( "Top" ) )
572  field.SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
573  else if( aValue == _( "Center" ) )
574  field.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
575  else if( aValue == _( "Bottom" ) )
576  field.SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
577  else
578  wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + aValue);
579  break;
580 
581  case FDC_ITALIC:
582  field.SetItalic( BoolFromString( aValue ) );
583  break;
584 
585  case FDC_BOLD:
586  field.SetBold( BoolFromString( aValue ) );
587  break;
588 
589  case FDC_TEXT_SIZE:
590  field.SetTextSize( wxSize( ValueFromString( m_userUnits, aValue ),
591  ValueFromString( m_userUnits, aValue ) ) );
592  break;
593 
594  case FDC_ORIENTATION:
595  if( aValue == _( "Horizontal" ) )
596  field.SetTextAngle( TEXT_ANGLE_HORIZ );
597  else if( aValue == _( "Vertical" ) )
598  field.SetTextAngle( TEXT_ANGLE_VERT );
599  else
600  wxFAIL_MSG( wxT( "unknown orientation: " ) + aValue );
601  break;
602 
603  case FDC_POSX:
604  case FDC_POSY:
605  pos = field.GetTextPos();
606  if( aCol == FDC_POSX )
607  pos.x = ValueFromString( m_userUnits, aValue );
608  else
609  pos.y = ValueFromString( m_userUnits, aValue );
610  field.SetTextPos( pos );
611  break;
612 
613  default:
614  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
615  break;
616  }
617 
618  GetView()->Refresh();
619 }
620 
621 
622 template <class T>
623 void FIELDS_GRID_TABLE<T>::SetValueAsBool( int aRow, int aCol, bool aValue )
624 {
625  wxCHECK( aRow < GetNumberRows(), /*void*/ );
626  T& field = this->at( (size_t) aRow );
627 
628  switch( aCol )
629  {
630  case FDC_SHOWN:
631  field.SetVisible( aValue );
632  break;
633  case FDC_ITALIC:
634  field.SetItalic( aValue );
635  break;
636  case FDC_BOLD:
637  field.SetBold( aValue );
638  break;
639  default:
640  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
641  break;
642  }
643 }
644 
645 
646 // Explicit Instantiations
647 
648 template class FIELDS_GRID_TABLE<SCH_FIELD>;
649 template class FIELDS_GRID_TABLE<LIB_FIELD>;
650 
651 
653 {
654  if( m_grid->GetGridCursorRow() == FOOTPRINT && m_grid->GetGridCursorCol() == FDC_VALUE )
655  {
656  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
657  _( "Browse for footprint" ) );
658  menu.AppendSeparator();
659  }
660  else if( m_grid->GetGridCursorRow() == DATASHEET && m_grid->GetGridCursorCol() == FDC_VALUE )
661  {
662  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
663  _( "Show datasheet in browser" ) );
664  menu.AppendSeparator();
665  }
666 
668 }
669 
670 
671 void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
672 {
673  if( event.GetId() == MYID_SELECT_FOOTPRINT )
674  {
675  // pick a footprint using the footprint picker.
676  wxString fpid = m_grid->GetCellValue( FOOTPRINT, FDC_VALUE );
678 
679  if( frame->ShowModal( &fpid, m_dlg ) )
680  m_grid->SetCellValue( FOOTPRINT, FDC_VALUE, fpid );
681 
682  frame->Destroy();
683  }
684  else if (event.GetId() == MYID_SHOW_DATASHEET )
685  {
686  wxString datasheet_uri = m_grid->GetCellValue( DATASHEET, FDC_VALUE );
687  GetAssociatedDocument( m_dlg, datasheet_uri );
688  }
689  else
690  {
692  }
693 }
694 
695 
696 template <class T>
698 {
699  if( aValue )
700  return wxT( "1" );
701  else
702  return wxT( "0" );
703 }
704 
705 
706 template <class T>
708 {
709  if( aValue == "1" )
710  {
711  return true;
712  }
713  else if( aValue == "0" )
714  {
715  return false;
716  }
717  else
718  {
719  wxFAIL_MSG( wxString::Format( "string \"%s\" can't be converted to boolean "
720  "correctly, it will have been perceived as FALSE", aValue ) );
721  return false;
722  }
723 }
#define TEXT_ANGLE_HORIZ
virtual void showPopupMenu(wxMenu &menu) override
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
name of datasheet
#define TEXT_ANGLE_VERT
int GetUserUnits()
Returns the currently selected user unit value for the interface.
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:70
This file is part of the common library.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
#define FIELD_VALUE
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:234
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:80
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:84
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxString GetColLabelValue(int aCol) override
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
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:58
#define VALUE
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:341
Definitions of control validators for schematic dialogs.
wxString GetValue(int aRow, int aCol) override
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override
Define a library symbol object.
Definition of file extensions used in Kicad.
#define FIELD_NAME
bool BoolFromString(wxString aValue)
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:43
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) override
const std::string LegacySchematicFileExtension
void initGrid(DIALOG_SHIM *aDialog)
virtual void SetValidator(const wxValidator &validator) override
Definition: validators.cpp:46
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:215
virtual void doPopupSelection(wxCommandEvent &event)
bool GetValueAsBool(int aRow, int aCol) override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual void showPopupMenu(wxMenu &menu)
void SetValue(int aRow, int aCol, const wxString &aValue) override
#define _(s)
Definition: 3d_actions.cpp:33
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:444
Definition for part library class.
FIELDS_GRID_TABLE(DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, LIB_PART *aPart)
void SetValueAsBool(int aRow, int aCol, bool aValue) override
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
virtual void doPopupSelection(wxCommandEvent &event) override
virtual bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...
Custom text control validator definitions.
wxString StringFromBool(bool aValue)