KiCad PCB EDA Suite
dialog_lib_symbol_properties.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) 1992-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 <bitmaps.h>
25 #include <confirm.h>
27 #include <kiway.h>
28 #include <symbol_edit_frame.h>
29 #include <symbol_library_manager.h>
30 #include <math/util.h> // for KiROUND
31 #include <sch_symbol.h>
33 #include <widgets/wx_grid.h>
34 #include <kicad_string.h>
35 
36 #ifdef KICAD_SPICE
37 #include <dialog_spice_model.h>
38 #endif /* KICAD_SPICE */
39 
42 #include <symbol_editor_settings.h>
43 
44 
48 
49 
51  LIB_SYMBOL* aLibEntry ) :
53  m_Parent( aParent ),
54  m_libEntry( aLibEntry ),
55  m_pinNameOffset( aParent, m_nameOffsetLabel, m_nameOffsetCtrl, m_nameOffsetUnits, true ),
56  m_delayedFocusCtrl( nullptr ),
57  m_delayedFocusGrid( nullptr ),
58  m_delayedFocusRow( -1 ),
59  m_delayedFocusColumn( -1 ),
60  m_delayedFocusPage( -1 ),
61  m_width( 0 )
62 {
63  // Give a bit more room for combobox editors
64  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
65  m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, aParent, m_grid, m_libEntry );
67  m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );
68 
69  // Show/hide columns according to the user's preference
72 
73  wxGridCellAttr* attr = new wxGridCellAttr;
74  attr->SetEditor( new GRID_CELL_URL_EDITOR( this ) );
75  m_grid->SetAttr( DATASHEET_FIELD, FDC_VALUE, attr );
76 
77  m_SymbolNameCtrl->SetValidator( SCH_FIELD_VALIDATOR( true, VALUE_FIELD ) );
78 
79  // Configure button logos
80  m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
81  m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
82  m_bpMoveUp->SetBitmap( KiBitmap( BITMAPS::small_up ) );
83  m_bpMoveDown->SetBitmap( KiBitmap( BITMAPS::small_down ) );
87 
88  if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
89  {
90  m_stdSizerButtonCancel->SetDefault();
91  m_stdSizerButtonOK->SetLabel( _( "Read Only" ) );
92  m_stdSizerButtonOK->Enable( false );
93  }
94  else
95  {
96  m_stdSizerButtonOK->SetDefault();
97  }
98 
99 #ifndef KICAD_SPICE
100  m_spiceFieldsButton->Hide();
101 #endif
102 
103  // wxFormBuilder doesn't include this event...
104  m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
106  nullptr, this );
107 
109  {
110  if( ( m_lastLayout == DIALOG_LIB_SYMBOL_PROPERTIES::ALIAS && aLibEntry->IsRoot() )
111  || ( m_lastLayout == DIALOG_LIB_SYMBOL_PROPERTIES::PARENT && aLibEntry->IsAlias() ) )
112  {
113  resetSize();
114  }
115  }
116 
119 
120  m_grid->GetParent()->Layout();
122  Layout();
123 
125 }
126 
127 
129 {
130  m_lastOpenedPage = m_NoteBook->GetSelection( );
131 
134 
135  // Prevents crash bug in wxGrid's d'tor
137 
138  m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
140  nullptr, this );
141 
142  // Delete the GRID_TRICKS.
143  m_grid->PopEventHandler( true );
144 }
145 
146 
148 {
149  if( !wxDialog::TransferDataToWindow() )
150  return false;
151 
152  // Push a copy of each field into m_updateFields
154 
155  // The Y axis for components in lib is from bottom to top while the screen axis is top
156  // to bottom: we must change the y coord sign for editing
157  for( size_t i = 0; i < m_fields->size(); ++i )
158  {
159  wxPoint pos = m_fields->at( i ).GetPosition();
160  pos.y = -pos.y;
161  m_fields->at( i ).SetPosition( pos );
162  }
163 
164  // notify the grid
165  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
166  m_grid->ProcessTableMessage( msg );
167  adjustGridColumns( m_grid->GetRect().GetWidth() );
168 
169  m_SymbolNameCtrl->ChangeValue( UnescapeString( m_libEntry->GetName() ) );
170 
171  m_DescCtrl->ChangeValue( m_libEntry->GetDescription() );
172  m_KeywordCtrl->ChangeValue( m_libEntry->GetKeyWords() );
175  m_libEntry->GetUnitCount() == 1 );
176  m_AsConvertButt->SetValue( m_libEntry->HasConversion() );
177  m_OptionPower->SetValue( m_libEntry->IsPower() );
180 
182  m_ShowPinNameButt->SetValue( m_libEntry->ShowPinNames() );
183  m_PinsNameInsideButt->SetValue( m_libEntry->GetPinNameOffset() != 0 );
185 
186  wxArrayString tmp = m_libEntry->GetFPFilters();
187  m_FootprintFilterListBox->Append( tmp );
188 
189  // Populate the list of root parts for inherited objects.
190  if( m_libEntry->IsAlias() )
191  {
192  wxArrayString rootSymbolNames;
193  wxString libName = m_Parent->GetCurLib();
194 
195  // Someone forgot to set the current library in the editor frame window.
196  wxCHECK( !libName.empty(), false );
197 
198  m_Parent->GetLibManager().GetRootSymbolNames( libName, rootSymbolNames );
199  m_inheritanceSelectCombo->Append( rootSymbolNames );
200 
201  LIB_SYMBOL_SPTR rootSymbol = m_libEntry->GetParent().lock();
202 
203  wxCHECK( rootSymbol, false );
204 
205  wxString parentName = UnescapeString( rootSymbol->GetName() );
206  int selection = m_inheritanceSelectCombo->FindString( parentName );
207 
208  wxCHECK( selection != wxNOT_FOUND, false );
209  m_inheritanceSelectCombo->SetSelection( selection );
210 
211  m_lastOpenedPage = 0;
212  }
213 
214  m_NoteBook->SetSelection( (unsigned) m_lastOpenedPage );
215 
216  return true;
217 }
218 
219 
221 {
222  if( !m_grid->CommitPendingChanges() )
223  return false;
224 
225  // Alias symbol reference can be empty because it inherits from the parent symbol.
226  if( m_libEntry->IsRoot() &&
228  {
229  if( m_NoteBook->GetSelection() != 0 )
230  m_NoteBook->SetSelection( 0 );
231 
232  m_delayedErrorMessage = _( "References must start with a letter." );
236  m_delayedFocusPage = 0;
237 
238  return false;
239  }
240 
241  // Check for missing field names.
242  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
243  {
244  LIB_FIELD& field = m_fields->at( i );
245  wxString fieldName = field.GetName( false );
246 
247  if( fieldName.IsEmpty() )
248  {
249  if( m_NoteBook->GetSelection() != 0 )
250  m_NoteBook->SetSelection( 0 );
251 
252  m_delayedErrorMessage = _( "Fields must have a name." );
255  m_delayedFocusRow = i;
256  m_delayedFocusPage = 0;
257 
258  return false;
259  }
260  }
261 
262  // Verify that the parent name is set if the symbol is inherited
263  if( m_libEntry->IsAlias() )
264  {
265  wxString parentName = m_inheritanceSelectCombo->GetValue();
266 
267  if( parentName.IsEmpty() )
268  {
269  m_delayedErrorMessage = _( "Aliased symbol must have a parent selected" );
270 
271  return false;
272  }
273  }
274 
275  if( m_SelNumberOfUnits->GetValue() < m_libEntry->GetUnitCount() )
276  {
277  if( !IsOK( this, _( "Delete extra units from symbol?" ) ) )
278  return false;
279  }
280 
281  if( m_AsConvertButt->GetValue() && !m_libEntry->HasConversion() )
282  {
283  if( !IsOK( this, _( "Add new pins for alternate body style (DeMorgan) to symbol?" ) ) )
284  return false;
285  }
286  else if( !m_AsConvertButt->GetValue() && m_libEntry->HasConversion() )
287  {
288  if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from symbol?" ) ) )
289  return false;
290  }
291 
292  return true;
293 }
294 
295 
297 {
298  if( !wxDialog::TransferDataFromWindow() )
299  return false;
300 
301  if( !m_grid->CommitPendingChanges() )
302  return false;
303 
304  // We need to keep the name and the value the same at the moment!
305  wxString newName = m_fields->at( VALUE_FIELD ).GetText();
306  wxString oldName = m_libEntry->GetName();
307 
308  if( oldName != newName )
309  {
310  wxString libName = m_Parent->GetCurLib();
311 
312  if( m_Parent->GetLibManager().SymbolExists( newName, libName ) )
313  {
314  wxString msg;
315 
316  msg.Printf( _( "The name '%s' conflicts with an existing entry in the library '%s'." ),
317  UnescapeString( newName ),
318  libName );
319  DisplayErrorMessage( this, msg );
320  return false;
321  }
322 
324  }
325  else
326  {
328  }
329 
330  // The Y axis for components in lib is from bottom to top while the screen axis is top
331  // to bottom: we must change the y coord sign when writing back to the library
332  for( size_t i = 0; i < m_fields->size(); ++i )
333  {
334  wxPoint pos = m_fields->at( i ).GetPosition();
335  pos.y = -pos.y;
336  m_fields->at( i ).SetPosition( pos );
337  m_fields->at( i ).SetId( i );
338  }
339 
341 
342  // Update the parent for inherited symbols
343  if( m_libEntry->IsAlias() )
344  {
345  wxString parentName = EscapeString( m_inheritanceSelectCombo->GetValue(), CTX_LIBID );
346 
347  // The parentName was verified to be non-empty in the Validator
348  wxString libName = m_Parent->GetCurLib();
349 
350  // Get the parent from the libManager based on the name set in the inheritance combo box.
351  LIB_SYMBOL* newParent = m_Parent->GetLibManager().GetAlias( parentName, libName );
352 
353  // Verify that the requested parent exists
354  wxCHECK( newParent, false );
355 
356  // Verify that the new parent is not an alias.
357  wxCHECK( !newParent->IsAlias(), false );
358 
359  m_libEntry->SetParent( newParent );
360  }
361 
362  // We need to keep the name and the value the same at the moment!
363  m_libEntry->SetName( newName );
364  m_libEntry->SetDescription( m_DescCtrl->GetValue() );
365  m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() );
368  !m_OptionPartsInterchangeable->GetValue() );
369  m_libEntry->SetConversion( m_AsConvertButt->GetValue() );
370 
371  if( m_OptionPower->GetValue() )
372  m_libEntry->SetPower();
373  else
375 
378 
381 
382  if( m_PinsNameInsideButt->GetValue() )
383  {
384  int offset = KiROUND( (double) m_pinNameOffset.GetValue() );
385 
386  // We interpret an offset of 0 as "outside", so make sure it's non-zero
387  m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
388  }
389  else
390  {
391  m_libEntry->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
392  }
393 
395 
397 
398  // It's possible that the symbol being edited has no pins, in which case there may be no
399  // alternate body style objects causing #LIB_SYMBOL::HasCoversion() to always return false.
400  // This allows the user to edit the alternate body style just in case this condition occurs.
401  m_Parent->SetShowDeMorgan( m_AsConvertButt->GetValue() );
402 
403  return true;
404 }
405 
406 
408 {
409  wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
410  wxControl* control = editor->GetControl();
411 
412  if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
413  {
414  event.Veto();
415 
417  m_delayedFocusRow = event.GetRow();
418  m_delayedFocusColumn = event.GetCol();
419  m_delayedFocusPage = 0;
420  }
421  else if( event.GetCol() == FDC_NAME )
422  {
423  wxString newName = event.GetString();
424 
425  for( int i = 0; i < m_grid->GetNumberRows(); ++i )
426  {
427  if( i == event.GetRow() )
428  continue;
429 
430  if( newName.CmpNoCase( m_grid->GetCellValue( i, FDC_NAME ) ) == 0 )
431  {
432  DisplayError( this, wxString::Format( _( "The name '%s' is already in use." ),
433  newName ) );
434  event.Veto();
435  m_delayedFocusRow = event.GetRow();
436  m_delayedFocusColumn = event.GetCol();
437  }
438  }
439  }
440  else if( event.GetRow() == VALUE_FIELD && event.GetCol() == FDC_VALUE )
441  {
442  m_SymbolNameCtrl->ChangeValue( event.GetString() );
443  }
444 
445  editor->DecRef();
446 }
447 
448 
450 {
452  m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
453 }
454 
455 
457 {
458  if( !m_delayedFocusCtrl && !m_SymbolNameCtrl->GetValidator()->Validate( m_SymbolNameCtrl ) )
459  {
461  m_delayedFocusPage = 0;
462  }
463 
464  event.Skip();
465 }
466 
467 
468 void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
469 {
470  if( !m_grid->CommitPendingChanges() )
471  return;
472 
474  int fieldID = m_fields->size();
475  LIB_FIELD newField( m_libEntry, fieldID );
476 
477  newField.SetTextSize( wxSize( Mils2iu( settings->m_Defaults.text_size ),
478  Mils2iu( settings->m_Defaults.text_size ) ) );
479 
480  m_fields->push_back( newField );
481 
482  // notify the grid
483  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
484  m_grid->ProcessTableMessage( msg );
485 
486  m_grid->MakeCellVisible( (int) m_fields->size() - 1, 0 );
487  m_grid->SetGridCursor( (int) m_fields->size() - 1, 0 );
488 
489  m_grid->EnableCellEditControl();
490  m_grid->ShowCellEditControl();
491 }
492 
493 
494 void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
495 {
496  int curRow = m_grid->GetGridCursorRow();
497 
498  if( curRow < 0 )
499  {
500  return;
501  }
502  else if( curRow < MANDATORY_FIELDS )
503  {
504  DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
505  MANDATORY_FIELDS ) );
506  return;
507  }
508 
509  m_grid->CommitPendingChanges( true /* quiet mode */ );
510 
511  m_fields->erase( m_fields->begin() + curRow );
512 
513  // notify the grid
514  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
515  m_grid->ProcessTableMessage( msg );
516 
517  if( m_grid->GetNumberRows() > 0 )
518  {
519  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
520  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
521  }
522 }
523 
524 
525 void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
526 {
527  if( !m_grid->CommitPendingChanges() )
528  return;
529 
530  int i = m_grid->GetGridCursorRow();
531 
532  if( i > MANDATORY_FIELDS )
533  {
534  LIB_FIELD tmp = m_fields->at( (unsigned) i );
535  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
536  m_fields->insert( m_fields->begin() + i - 1, tmp );
537  m_grid->ForceRefresh();
538 
539  m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
540  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
541  }
542  else
543  {
544  wxBell();
545  }
546 }
547 
548 
549 void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
550 {
551  if( !m_grid->CommitPendingChanges() )
552  return;
553 
554  int i = m_grid->GetGridCursorRow();
555 
556  if( i >= MANDATORY_FIELDS && i + 1 < m_fields->GetNumberRows() )
557  {
558  LIB_FIELD tmp = m_fields->at( (unsigned) i );
559  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
560  m_fields->insert( m_fields->begin() + i + 1, tmp );
561  m_grid->ForceRefresh();
562 
563  m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
564  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
565  }
566  else
567  {
568  wxBell();
569  }
570 }
571 
572 
574 {
575 #ifdef KICAD_SPICE
576  int diff = m_fields->size();
577  auto symbol = SCH_SYMBOL( *m_libEntry, m_libEntry->GetLibId(), nullptr );
578 
579  DIALOG_SPICE_MODEL dialog( this, symbol, m_fields );
580 
581  if( dialog.ShowModal() != wxID_OK )
582  return;
583 
584  diff = (int) m_fields->size() - diff;
585 
586  if( diff > 0 )
587  {
588  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
589  m_grid->ProcessTableMessage( msg );
590  }
591  else if( diff < 0 )
592  {
593  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, -diff );
594  m_grid->ProcessTableMessage( msg );
595  }
596 
597  m_grid->ForceRefresh();
598 #endif /* KICAD_SPICE */
599 }
600 
601 
603 {
604  int idx = m_FootprintFilterListBox->HitTest( event.GetPosition() );
605  wxCommandEvent dummy;
606 
607  if( idx >= 0 )
609  else
611 }
612 
613 
615 {
616  // Running the Footprint Browser gums up the works and causes the automatic cancel
617  // stuff to no longer work. So we do it here ourselves.
618  EndQuasiModal( wxID_CANCEL );
619 }
620 
621 
623 {
624  wxString filterLine;
625  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Add Footprint Filter" ), filterLine );
626 
627  if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue().IsEmpty() )
628  return;
629 
630  filterLine = dlg.GetValue();
631  filterLine.Replace( wxT( " " ), wxT( "_" ) );
632 
633  // duplicate filters do no harm, so don't be a nanny.
634 
635  m_FootprintFilterListBox->Append( filterLine );
636  m_FootprintFilterListBox->SetSelection( (int) m_FootprintFilterListBox->GetCount() - 1 );
637 }
638 
639 
641 {
642  int ii = m_FootprintFilterListBox->GetSelection();
643 
644  if( ii >= 0 )
645  {
646  m_FootprintFilterListBox->Delete( (unsigned) ii );
647 
648  if( m_FootprintFilterListBox->GetCount() == 0 )
649  m_FootprintFilterListBox->SetSelection( wxNOT_FOUND );
650  else
651  m_FootprintFilterListBox->SetSelection( std::max( 0, ii - 1 ) );
652  }
653 }
654 
655 
657 {
658  int idx = m_FootprintFilterListBox->GetSelection();
659 
660  if( idx >= 0 )
661  {
662  wxString filter = m_FootprintFilterListBox->GetStringSelection();
663 
664  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Edit Footprint Filter" ), filter );
665 
666  if( dlg.ShowModal() == wxID_OK && !dlg.GetValue().IsEmpty() )
667  m_FootprintFilterListBox->SetString( (unsigned) idx, dlg.GetValue() );
668  }
669 }
670 
671 
673 {
674  m_width = aWidth;
675 
676  // Account for scroll bars
677  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
678 
679  m_grid->AutoSizeColumn( FDC_NAME );
680 
681  int fixedColsWidth = m_grid->GetColSize( FDC_NAME );
682 
683  for( int i = 2; i < m_grid->GetNumberCols(); i++ )
684  fixedColsWidth += m_grid->GetColSize( i );
685 
686  m_grid->SetColSize( FDC_VALUE, aWidth - fixedColsWidth );
687 }
688 
689 
690 void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
691 {
692  m_OptionPartsInterchangeable->Enable( m_SelNumberOfUnits->GetValue() > 1 );
694 
695  if( m_grid->IsCellEditControlShown() )
696  {
697  int row = m_grid->GetGridCursorRow();
698  int col = m_grid->GetGridCursorCol();
699 
700  if( row == VALUE_FIELD && col == FDC_VALUE )
701  {
702  wxGridCellEditor* editor = m_grid->GetCellEditor( row, col );
703  m_SymbolNameCtrl->ChangeValue( editor->GetValue() );
704  editor->DecRef();
705  }
706  }
707 
708  // Handle shown columns changes
709  wxString shownColumns = m_grid->GetShownColumns();
710 
711  if( shownColumns != m_shownColumns )
712  {
713  m_shownColumns = shownColumns;
714 
715  if( !m_grid->IsCellEditControlShown() )
716  adjustGridColumns( m_grid->GetRect().GetWidth() );
717  }
718 
719  // Handle a delayed focus. The delay allows us to:
720  // a) change focus when the error was triggered from within a killFocus handler
721  // b) show the correct notebook page in the background before the error dialog comes up
722  // when triggered from an OK or a notebook page change
723 
724  if( m_delayedFocusPage >= 0 && m_NoteBook->GetSelection() != m_delayedFocusPage )
725  {
726  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
727  m_delayedFocusPage = -1;
728  }
729 
730  if( !m_delayedErrorMessage.IsEmpty() )
731  {
732  // We will re-enter this routine when the error dialog is displayed, so make
733  // sure we don't keep putting up more dialogs.
734  wxString msg = m_delayedErrorMessage;
735  m_delayedErrorMessage = wxEmptyString;
736 
737  // Do not use DisplayErrorMessage(); it screws up window order on Mac
738  DisplayError( nullptr, msg );
739  }
740 
741  if( m_delayedFocusCtrl )
742  {
743  m_delayedFocusCtrl->SetFocus();
744 
745  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
746  textEntry->SelectAll();
747 
748  m_delayedFocusCtrl = nullptr;
749  }
750  else if( m_delayedFocusGrid )
751  {
752  m_delayedFocusGrid->SetFocus();
755 
756  m_delayedFocusGrid->EnableCellEditControl( true );
757  m_delayedFocusGrid->ShowCellEditControl();
758 
759  m_delayedFocusGrid = nullptr;
760  m_delayedFocusRow = -1;
762  }
763 }
764 
765 
767 {
768  auto new_size = event.GetSize().GetX();
769 
770  if( new_size != m_width )
771  {
772  adjustGridColumns( event.GetSize().GetX() );
773  }
774 
775  // Always propagate a wxSizeEvent:
776  event.Skip();
777 }
778 
779 
781 {
782  bSizerLowerBasicPanel->Show( !aIsAlias );
783  m_inheritanceSelectCombo->Enable( aIsAlias );
784  m_inheritsStaticText->Enable( aIsAlias );
785  m_grid->ForceRefresh();
786 }
787 
788 
789 void DIALOG_LIB_SYMBOL_PROPERTIES::onPowerCheckBox( wxCommandEvent& aEvent )
790 {
791  if( m_OptionPower->IsChecked() )
792  {
793  m_excludeFromBomCheckBox->SetValue( true );
794  m_excludeFromBoardCheckBox->SetValue( true );
795  m_excludeFromBomCheckBox->Enable( false );
796  m_excludeFromBoardCheckBox->Enable( false );
797  }
798  else
799  {
800  m_excludeFromBomCheckBox->Enable( true );
801  m_excludeFromBoardCheckBox->Enable( true );
802  }
803 }
virtual void onPowerCheckBox(wxCommandEvent &aEvent) override
Field Reference of part, i.e. "IC21".
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition: lib_symbol.h:560
wxString GetValue() const
void OnEditSpiceModel(wxCommandEvent &event) override
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:124
int GetPinNameOffset() const
Definition: lib_symbol.h:561
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
Definition: lib_symbol.cpp:888
void GetRootSymbolNames(const wxString &aLibName, wxArrayString &aRootSymbolNames)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:265
int GetNumberRows() override
void SetIncludeOnBoard(bool aIncludeOnBoard)
Set or clear include in board netlist flag.
Definition: lib_symbol.h:592
This file is part of the common library.
wxString GetName() const override
Definition: lib_symbol.h:133
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:129
void SetShowDeMorgan(bool show)
SYMBOL_EDITOR_SETTINGS * GetSettings() const
void SetConversion(bool aSetConvert, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the symbol.
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
Field object used in symbol libraries.
Definition: lib_field.h:59
bool IsAlias() const
Definition: lib_symbol.h:172
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:42
bool ShowPinNumbers() const
Definition: lib_symbol.h:577
bool GetIncludeOnBoard() const
Definition: lib_symbol.h:593
bool IsPower() const
Definition: lib_symbol.cpp:409
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:65
Define a library symbol object.
Definition: lib_symbol.h:96
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
bool IsSymbolFromSchematic() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: lib_field.cpp:363
name of datasheet
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
Definition: lib_symbol.cpp:905
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:97
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
bool SymbolExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
void OnMoveUp(wxCommandEvent &event) override
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
void OnCancelButtonClick(wxCommandEvent &event) override
void OnEditFootprintFilter(wxCommandEvent &event) override
void OnAddField(wxCommandEvent &event) override
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition: lib_symbol.h:568
wxString GetKeyWords() const
Definition: lib_symbol.h:155
Field Value of part, i.e. "3.3K".
LIB_ID GetLibId() const override
Definition: lib_symbol.h:135
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:314
int GetUnitCount() const override
For items with units, return the number of units.
void SaveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT, bool aAppend=false)
Create a copy of the current symbol, and save it in the undo list.
SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SetDescription(const wxString &aDescription)
Definition: lib_symbol.h:140
bool ShowPinNames() const
Definition: lib_symbol.h:569
#define _(s)
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:323
void OnDeleteFootprintFilter(wxCommandEvent &event) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180
void OnSizeGrid(wxSizeEvent &event) override
void OnUpdateUI(wxUpdateUIEvent &event) override
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
void OnSymbolNameText(wxCommandEvent &event) override
void OnMoveDown(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:241
FIELDS_GRID_TABLE< LIB_FIELD > * m_fields
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.
Class DIALOG_LIB_SYMBOL_PROPERTIES_BASE.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:110
void EndQuasiModal(int retCode)
Schematic symbol object.
Definition: sch_symbol.h:78
void OnAddFootprintFilter(wxCommandEvent &event) override
void SetIncludeInBom(bool aIncludeInBom)
Set or clear the include in schematic bill of materials flag.
Definition: lib_symbol.h:584
void SetFPFilters(const wxArrayString &aFilters)
Definition: lib_symbol.h:181
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:222
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Definition: string.cpp:141
void SetPower()
Definition: lib_symbol.cpp:418
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition: lib_symbol.h:576
void resetSize()
Clear the existing dialog size and position.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:183
LIB_SYMBOL * GetAlias(const wxString &aAlias, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
virtual long long int GetValue()
Return the current value in Internal Units.
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:171
A text control validator used for validating the text allowed in library and schematic symbol fields.
wxString GetDescription() override
Definition: lib_symbol.h:142
static bool IsReferenceStringValid(const wxString &aReferenceString)
Test for an acceptable reference string.
Definition: sch_symbol.cpp:466
bool IsSymbolFromLegacyLibrary() const
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:296
void OnSymbolNameKillFocus(wxFocusEvent &event) override
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:153
void SetNormal()
Definition: lib_symbol.cpp:436
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
Definition: lib_symbol.h:235
DIALOG_LIB_SYMBOL_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aLibEntry)
bool GetIncludeInBom() const
Definition: lib_symbol.h:585
virtual void ChangeValue(int aValue)
Change the value (in Internal Units) for the text field, taking care of units conversion but does not...
The symbol library editor main window.
void OnFilterDClick(wxMouseEvent &event) override