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 <pgm_base.h>
32 #include <sch_symbol.h>
34 #include <widgets/wx_grid.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_PART* 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
70  auto cfg = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
71  m_grid->ShowHideColumns( cfg->m_EditComponentVisibleColumns );
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( small_plus_xpm ) );
81  m_bpDelete->SetBitmap( KiBitmap( small_trash_xpm ) );
82  m_bpMoveUp->SetBitmap( KiBitmap( small_up_xpm ) );
83  m_bpMoveDown->SetBitmap( KiBitmap( small_down_xpm ) );
84  m_addFilterButton->SetBitmap( KiBitmap( small_plus_xpm ) );
87 
88  if( aParent->IsSymbolFromLegacyLibrary() )
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  NULL, 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 
132  auto cfg = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
134 
135  // Prevents crash bug in wxGrid's d'tor
137 
138  m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
140  NULL, 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->SetValue( m_libEntry->GetName() );
170 
171  m_DescCtrl->SetValue( m_libEntry->GetDescription() );
172  m_KeywordCtrl->SetValue( m_libEntry->GetKeyWords() );
175  m_AsConvertButt->SetValue( m_libEntry->HasConversion() );
176  m_OptionPower->SetValue( m_libEntry->IsPower() );
179 
181  m_ShowPinNameButt->SetValue( m_libEntry->ShowPinNames() );
182  m_PinsNameInsideButt->SetValue( m_libEntry->GetPinNameOffset() != 0 );
184 
185  wxArrayString tmp = m_libEntry->GetFPFilters();
186  m_FootprintFilterListBox->Append( tmp );
187 
188  // Populate the list of root parts for inherited objects.
189  if( m_libEntry->IsAlias() )
190  {
191  wxArrayString rootSymbolNames;
192  wxString libName = m_Parent->GetCurLib();
193 
194  // Someone forgot to set the current library in the editor frame window.
195  wxCHECK( !libName.empty(), false );
196 
197  m_Parent->GetLibManager().GetRootSymbolNames( libName, rootSymbolNames );
198  m_inheritanceSelectCombo->Append( rootSymbolNames );
199 
200  PART_SPTR rootPart = m_libEntry->GetParent().lock();
201 
202  wxCHECK( rootPart, false );
203 
204  wxString parentName = rootPart->GetName();
205  int selection = m_inheritanceSelectCombo->FindString( parentName );
206 
207  wxCHECK( selection != wxNOT_FOUND, false );
208  m_inheritanceSelectCombo->SetSelection( selection );
209 
210  m_lastOpenedPage = 0;
211  }
212 
213  m_NoteBook->SetSelection( (unsigned) m_lastOpenedPage );
214 
215  return true;
216 }
217 
218 
220 {
221  if( !m_grid->CommitPendingChanges() )
222  return false;
223 
224  // Alias symbol reference can be empty because it inherits from the parent symbol.
225  if( m_libEntry->IsRoot() &&
227  {
228  if( m_NoteBook->GetSelection() != 0 )
229  m_NoteBook->SetSelection( 0 );
230 
231  m_delayedErrorMessage = _( "References must start with a letter." );
235  m_delayedFocusPage = 0;
236 
237  return false;
238  }
239 
240  // Check for missing field names.
241  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
242  {
243  LIB_FIELD& field = m_fields->at( i );
244  wxString fieldName = field.GetName( false );
245 
246  if( fieldName.IsEmpty() )
247  {
248  if( m_NoteBook->GetSelection() != 0 )
249  m_NoteBook->SetSelection( 0 );
250 
251  m_delayedErrorMessage = _( "Fields must have a name." );
254  m_delayedFocusRow = i;
255  m_delayedFocusPage = 0;
256 
257  return false;
258  }
259  }
260 
261  // Verify that the parent name is set if the symbol is inherited
262  if( m_libEntry->IsAlias() )
263  {
264  wxString parentName = m_inheritanceSelectCombo->GetValue();
265 
266  if( parentName.IsEmpty() )
267  {
268  m_delayedErrorMessage = _( "Aliased symbol must have a parent selected" );
269 
270  return false;
271  }
272  }
273 
274  if( m_SelNumberOfUnits->GetValue() < m_libEntry->GetUnitCount() )
275  {
276  if( !IsOK( this, _( "Delete extra units from symbol?" ) ) )
277  return false;
278  }
279 
280  if( m_AsConvertButt->GetValue() && !m_libEntry->HasConversion() )
281  {
282  if( !IsOK( this, _( "Add new pins for alternate body style (DeMorgan) to symbol?" ) ) )
283  return false;
284  }
285  else if( !m_AsConvertButt->GetValue() && m_libEntry->HasConversion() )
286  {
287  if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from symbol?" ) ) )
288  return false;
289  }
290 
291  return true;
292 }
293 
294 
296 {
297  if( !wxDialog::TransferDataFromWindow() )
298  return false;
299 
300  // We need to keep the name and the value the same at the moment!
301  wxString newName = m_fields->at( VALUE_FIELD ).GetText();
302  wxString oldName = m_libEntry->GetName();
303 
304  if( oldName != newName )
305  {
306  wxString libName = m_Parent->GetCurLib();
307 
308  if( m_Parent->GetLibManager().PartExists( newName, libName ) )
309  {
310  wxString msg;
311 
312  msg.Printf( _( "The name '%s' conflicts with an existing entry in the library '%s'." ),
313  newName, libName );
314  DisplayErrorMessage( this, msg );
315  return false;
316  }
317 
319  }
320  else
321  {
323  }
324 
325  // The Y axis for components in lib is from bottom to top while the screen axis is top
326  // to bottom: we must change the y coord sign when writing back to the library
327  for( size_t i = 0; i < m_fields->size(); ++i )
328  {
329  wxPoint pos = m_fields->at( i ).GetPosition();
330  pos.y = -pos.y;
331  m_fields->at( i ).SetPosition( pos );
332  }
333 
335 
336  // Update the parent for inherited symbols
337  if( m_libEntry->IsAlias() )
338  {
339  wxString parentName = m_inheritanceSelectCombo->GetValue();
340 
341  // The parentName was verified to be non-empty in the Validator
342  wxString libName = m_Parent->GetCurLib();
343 
344  // Get the parent from the libManager based on the name set in the inheritance combo box.
345  LIB_PART* newParent = m_Parent->GetLibManager().GetAlias( parentName, libName );
346 
347  // Verify that the requested parent exists
348  wxCHECK( newParent, false );
349 
350  // Verify that the new parent is not an alias.
351  wxCHECK( !newParent->IsAlias(), false );
352 
353  m_libEntry->SetParent( newParent );
354  }
355 
356  // We need to keep the name and the value the same at the moment!
357  m_libEntry->SetName( newName );
358  m_libEntry->SetDescription( m_DescCtrl->GetValue() );
359  m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() );
362  m_libEntry->SetConversion( m_AsConvertButt->GetValue() );
363 
364  if( m_OptionPower->GetValue() )
365  m_libEntry->SetPower();
366  else
368 
371 
374 
375  if( m_PinsNameInsideButt->GetValue() )
376  {
377  int offset = KiROUND( (double) m_pinNameOffset.GetValue() );
378 
379  // We interpret an offset of 0 as "outside", so make sure it's non-zero
380  m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
381  }
382  else
383  {
384  m_libEntry->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
385  }
386 
388 
390 
391  // It's possible that the symbol being edited has no pins, in which case there may be no
392  // alternate body style objects causing #LIB_PART::HasCoversion() to always return false.
393  // This allows the user to edit the alternate body style just in case this condition occurs.
394  m_Parent->SetShowDeMorgan( m_AsConvertButt->GetValue() );
395 
396  return true;
397 }
398 
399 
401 {
402  wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
403  wxControl* control = editor->GetControl();
404 
405  if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
406  {
407  event.Veto();
408 
410  m_delayedFocusRow = event.GetRow();
411  m_delayedFocusColumn = event.GetCol();
412  m_delayedFocusPage = 0;
413  }
414  else if( event.GetCol() == FDC_NAME )
415  {
416  wxString newName = event.GetString();
417 
418  for( int i = 0; i < m_grid->GetNumberRows(); ++i )
419  {
420  if( i == event.GetRow() )
421  continue;
422 
423  if( newName.CmpNoCase( m_grid->GetCellValue( i, FDC_NAME ) ) == 0 )
424  {
425  DisplayError( this, wxString::Format( _( "The name '%s' is already in use." ),
426  newName ) );
427  event.Veto();
428  m_delayedFocusRow = event.GetRow();
429  m_delayedFocusColumn = event.GetCol();
430  }
431  }
432  }
433  else if( event.GetRow() == VALUE_FIELD && event.GetCol() == FDC_VALUE )
434  m_SymbolNameCtrl->ChangeValue( event.GetString() );
435 
436  editor->DecRef();
437 }
438 
439 
441 {
442  m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
443 }
444 
445 
447 {
448  if( !m_delayedFocusCtrl && !m_SymbolNameCtrl->GetValidator()->Validate( m_SymbolNameCtrl ) )
449  {
451  m_delayedFocusPage = 0;
452  }
453 
454  event.Skip();
455 }
456 
457 
458 void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
459 {
460  if( !m_grid->CommitPendingChanges() )
461  return;
462 
463  auto* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
464  int fieldID = m_fields->size();
465  LIB_FIELD newField( m_libEntry, fieldID );
466 
467  newField.SetTextSize( wxSize( Mils2iu( settings->m_Defaults.text_size ),
468  Mils2iu( settings->m_Defaults.text_size ) ) );
469 
470  m_fields->push_back( newField );
471 
472  // notify the grid
473  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
474  m_grid->ProcessTableMessage( msg );
475 
476  m_grid->MakeCellVisible( (int) m_fields->size() - 1, 0 );
477  m_grid->SetGridCursor( (int) m_fields->size() - 1, 0 );
478 
479  m_grid->EnableCellEditControl();
480  m_grid->ShowCellEditControl();
481 }
482 
483 
484 void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
485 {
486  int curRow = m_grid->GetGridCursorRow();
487 
488  if( curRow < 0 )
489  {
490  return;
491  }
492  else if( curRow < MANDATORY_FIELDS )
493  {
494  DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
495  MANDATORY_FIELDS ) );
496  return;
497  }
498 
499  m_grid->CommitPendingChanges( true /* quiet mode */ );
500 
501  m_fields->erase( m_fields->begin() + curRow );
502 
503  // notify the grid
504  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
505  m_grid->ProcessTableMessage( msg );
506 
507  if( m_grid->GetNumberRows() > 0 )
508  {
509  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
510  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
511  }
512 }
513 
514 
515 void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
516 {
517  if( !m_grid->CommitPendingChanges() )
518  return;
519 
520  int i = m_grid->GetGridCursorRow();
521 
522  if( i > MANDATORY_FIELDS )
523  {
524  LIB_FIELD tmp = m_fields->at( (unsigned) i );
525  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
526  m_fields->insert( m_fields->begin() + i - 1, tmp );
527  m_grid->ForceRefresh();
528 
529  m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
530  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
531  }
532  else
533  wxBell();
534 }
535 
536 
537 void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
538 {
539  if( !m_grid->CommitPendingChanges() )
540  return;
541 
542  int i = m_grid->GetGridCursorRow();
543 
544  if( i >= MANDATORY_FIELDS && i + 1 < m_fields->GetNumberRows() )
545  {
546  LIB_FIELD tmp = m_fields->at( (unsigned) i );
547  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
548  m_fields->insert( m_fields->begin() + i + 1, tmp );
549  m_grid->ForceRefresh();
550 
551  m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
552  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
553  }
554  else
555  wxBell();
556 }
557 
558 
560 {
561 #ifdef KICAD_SPICE
562  int diff = m_fields->size();
563  auto cmp = SCH_COMPONENT( *m_libEntry, m_libEntry->GetLibId(), nullptr );
564 
565  DIALOG_SPICE_MODEL dialog( this, cmp, m_fields );
566 
567  if( dialog.ShowModal() != wxID_OK )
568  return;
569 
570  diff = (int) m_fields->size() - diff;
571 
572  if( diff > 0 )
573  {
574  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
575  m_grid->ProcessTableMessage( msg );
576  }
577  else if( diff < 0 )
578  {
579  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, -diff );
580  m_grid->ProcessTableMessage( msg );
581  }
582 
583  m_grid->ForceRefresh();
584 #endif /* KICAD_SPICE */
585 }
586 
587 
589 {
590  int idx = m_FootprintFilterListBox->HitTest( event.GetPosition() );
591  wxCommandEvent dummy;
592 
593  if( idx >= 0 )
595  else
597 }
598 
599 
601 {
602  // Running the Footprint Browser gums up the works and causes the automatic cancel
603  // stuff to no longer work. So we do it here ourselves.
604  EndQuasiModal( wxID_CANCEL );
605 }
606 
607 
609 {
610  wxString filterLine;
611  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Add Footprint Filter" ), filterLine );
612 
613  if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue().IsEmpty() )
614  return;
615 
616  filterLine = dlg.GetValue();
617  filterLine.Replace( wxT( " " ), wxT( "_" ) );
618 
619  // duplicate filters do no harm, so don't be a nanny.
620 
621  m_FootprintFilterListBox->Append( filterLine );
622  m_FootprintFilterListBox->SetSelection( (int) m_FootprintFilterListBox->GetCount() - 1 );
623 }
624 
625 
627 {
628  int ii = m_FootprintFilterListBox->GetSelection();
629 
630  if( ii >= 0 )
631  {
632  m_FootprintFilterListBox->Delete( (unsigned) ii );
633 
634  if( m_FootprintFilterListBox->GetCount() == 0 )
635  m_FootprintFilterListBox->SetSelection( wxNOT_FOUND );
636  else
637  m_FootprintFilterListBox->SetSelection( std::max( 0, ii - 1 ) );
638  }
639 }
640 
641 
643 {
644  int idx = m_FootprintFilterListBox->GetSelection();
645 
646  if( idx >= 0 )
647  {
648  wxString filter = m_FootprintFilterListBox->GetStringSelection();
649 
650  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Edit Footprint Filter" ), filter );
651 
652  if( dlg.ShowModal() == wxID_OK && !dlg.GetValue().IsEmpty() )
653  m_FootprintFilterListBox->SetString( (unsigned) idx, dlg.GetValue() );
654  }
655 }
656 
657 
659 {
660  m_width = aWidth;
661 
662  // Account for scroll bars
663  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
664 
665  m_grid->AutoSizeColumn( FDC_NAME );
666 
667  int fixedColsWidth = m_grid->GetColSize( FDC_NAME );
668 
669  for( int i = 2; i < m_grid->GetNumberCols(); i++ )
670  fixedColsWidth += m_grid->GetColSize( i );
671 
672  m_grid->SetColSize( FDC_VALUE, aWidth - fixedColsWidth );
673 }
674 
675 
676 void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
677 {
678  m_OptionPartsInterchangeable->Enable( m_SelNumberOfUnits->GetValue() > 1 );
680 
681  if( m_grid->IsCellEditControlShown() )
682  {
683  int row = m_grid->GetGridCursorRow();
684  int col = m_grid->GetGridCursorCol();
685 
686  if( row == VALUE_FIELD && col == FDC_VALUE )
687  {
688  wxGridCellEditor* editor = m_grid->GetCellEditor( row, col );
689  m_SymbolNameCtrl->ChangeValue( editor->GetValue() );
690  editor->DecRef();
691  }
692  }
693 
694  // Handle shown columns changes
695  wxString shownColumns = m_grid->GetShownColumns();
696 
697  if( shownColumns != m_shownColumns )
698  {
699  m_shownColumns = shownColumns;
700 
701  if( !m_grid->IsCellEditControlShown() )
702  adjustGridColumns( m_grid->GetRect().GetWidth() );
703  }
704 
705  // Handle a delayed focus. The delay allows us to:
706  // a) change focus when the error was triggered from within a killFocus handler
707  // b) show the correct notebook page in the background before the error dialog comes up
708  // when triggered from an OK or a notebook page change
709 
710  if( m_delayedFocusPage >= 0 && m_NoteBook->GetSelection() != m_delayedFocusPage )
711  {
712  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
713  m_delayedFocusPage = -1;
714  }
715 
716  if( !m_delayedErrorMessage.IsEmpty() )
717  {
718  // We will re-enter this routine when the error dialog is displayed, so make
719  // sure we don't keep putting up more dialogs.
720  wxString msg = m_delayedErrorMessage;
721  m_delayedErrorMessage = wxEmptyString;
722 
723  // Do not use DisplayErrorMessage(); it screws up window order on Mac
724  DisplayError( nullptr, msg );
725  }
726 
727  if( m_delayedFocusCtrl )
728  {
729  m_delayedFocusCtrl->SetFocus();
730 
731  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
732  textEntry->SelectAll();
733 
734  m_delayedFocusCtrl = nullptr;
735  }
736  else if( m_delayedFocusGrid )
737  {
738  m_delayedFocusGrid->SetFocus();
741 
742  m_delayedFocusGrid->EnableCellEditControl( true );
743  m_delayedFocusGrid->ShowCellEditControl();
744 
745  m_delayedFocusGrid = nullptr;
746  m_delayedFocusRow = -1;
748  }
749 }
750 
751 
753 {
754  auto new_size = event.GetSize().GetX();
755 
756  if( new_size != m_width )
757  {
758  adjustGridColumns( event.GetSize().GetX() );
759  }
760 
761  // Always propagate a wxSizeEvent:
762  event.Skip();
763 }
764 
765 
767 {
768  bSizerLowerBasicPanel->Show( !aIsAlias );
769 
770 #ifdef KICAD_SPICE
771  m_spiceFieldsButton->Show( !aIsAlias );
772 #endif
773 
774  m_inheritanceSelectCombo->Enable( aIsAlias );
775  m_inheritsStaticText->Enable( aIsAlias );
776  m_grid->ForceRefresh();
777 }
778 
779 
780 void DIALOG_LIB_SYMBOL_PROPERTIES::onPowerCheckBox( wxCommandEvent& aEvent )
781 {
782  if( m_OptionPower->IsChecked() )
783  {
784  m_excludeFromBomCheckBox->SetValue( true );
785  m_excludeFromBoardCheckBox->SetValue( true );
786  m_excludeFromBomCheckBox->Enable( false );
787  m_excludeFromBoardCheckBox->Enable( false );
788  }
789  else
790  {
791  m_excludeFromBomCheckBox->Enable( true );
792  m_excludeFromBoardCheckBox->Enable( true );
793  }
794 }
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:253
wxString GetValue() const
void OnEditSpiceModel(wxCommandEvent &event) override
void SetFPFilters(const wxArrayString &aFilters)
Definition: lib_symbol.h:177
LIB_PART * GetAlias(const wxString &aAlias, const wxString &aLibrary) const
Return either an alias of a working LIB_PART copy, or alias of the original part if there is no worki...
void SetPower()
Definition: lib_symbol.cpp:413
LIB_ID GetLibId() const override
Definition: lib_symbol.h:131
void GetRootSymbolNames(const wxString &aLibName, wxArrayString &aRootSymbolNames)
int GetPinNameOffset()
Definition: lib_symbol.h:554
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:266
int GetNumberRows() override
wxString GetName() const override
Definition: lib_symbol.h:129
This file is part of the common library.
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
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)
bool PartExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if part with a specific alias exists in library (either original one or buffered).
A KICAD version of wxTextEntryDialog which supports the various improvments/work-arounds from DIALOG_...
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per part count.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:179
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
Definition: lib_symbol.h:42
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
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
wxString GetKeyWords() const
Definition: lib_symbol.h:151
void SetIncludeInBom(bool aIncludeInBom)
Set or clear the include in schematic bill of materials flag.
Definition: lib_symbol.h:577
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
wxString GetName(bool aUseDefaultName=true) const
Returns the field name.
Definition: lib_field.cpp:364
name of datasheet
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
void OnMoveUp(wxCommandEvent &event) override
bool ShowPinNames()
Definition: lib_symbol.h:562
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void OnCancelButtonClick(wxCommandEvent &event) override
void OnEditFootprintFilter(wxCommandEvent &event) override
void OnAddField(wxCommandEvent &event) override
bool ShowPinNumbers()
Definition: lib_symbol.h:570
DIALOG_LIB_SYMBOL_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_PART *aLibEntry)
Constructors.
void SetConversion(bool aSetConvert, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the part.
Field Value of part, i.e. "3.3K".
#define NULL
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.
void SetDescription(const wxString &aDescription)
Definition: lib_symbol.h:136
SYMBOL_LIBRARY_MANAGER & GetLibManager()
const BITMAP_OPAQUE small_down_xpm[1]
Definition: small_down.cpp:23
void SetParent(LIB_PART *aParent=nullptr)
Definition: lib_symbol.cpp:318
PART_REF & GetParent()
Definition: lib_symbol.h:120
Define a library symbol object.
Definition: lib_symbol.h:93
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this part.
Definition: lib_symbol.cpp:894
wxString GetDescription() override
Definition: lib_symbol.h:138
void OnDeleteFootprintFilter(wxCommandEvent &event) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182
void OnSizeGrid(wxSizeEvent &event) override
void OnUpdateUI(wxUpdateUIEvent &event) override
const BITMAP_OPAQUE small_up_xpm[1]
Definition: small_up.cpp:23
void OnSymbolNameText(wxCommandEvent &event) override
const BITMAP_OPAQUE small_trash_xpm[1]
Definition: small_trash.cpp:23
void OnMoveDown(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
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)
const BITMAP_OPAQUE small_edit_xpm[1]
Definition: small_edit.cpp:22
bool IsPower() const
Definition: lib_symbol.cpp:404
see class PGM_BASE
void OnAddFootprintFilter(wxCommandEvent &event) override
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition: lib_symbol.h:569
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:149
bool IsAlias() const
Definition: lib_symbol.h:168
Schematic symbol object.
Definition: sch_symbol.h:79
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:68
bool GetIncludeOnBoard() const
Definition: lib_symbol.h:586
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:167
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:307
void SetIncludeOnBoard(bool aIncludeOnBoard)
Set or clear include in board netlist flag.
Definition: lib_symbol.h:585
A text control validator used for validating the text allowed in library and schematic component fiel...
static bool IsReferenceStringValid(const wxString &aReferenceString)
Tests for an acceptable reference string.
Definition: sch_symbol.cpp:460
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition: lib_symbol.h:561
bool GetIncludeInBom() const
Definition: lib_symbol.h:578
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition: lib_symbol.h:553
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:879
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:297
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:18
void OnSymbolNameKillFocus(wxFocusEvent &event) override
bool UnitsLocked() const
Check whether part units are interchangeable.
Definition: lib_symbol.h:237
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void LockUnits(bool aLockUnits)
Set interchangeable the property for part units.
Definition: lib_symbol.h:231
void SetNormal()
Definition: lib_symbol.cpp:431
The symbol library editor main window.
void OnFilterDClick(wxMouseEvent &event) override