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