KiCad PCB EDA Suite
dialog_edit_component_in_lib.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <fctsys.h>
29 #include <kiway.h>
30 #include <common.h>
31 #include <confirm.h>
32 #include <pgm_base.h>
33 #include <kiface_i.h>
34 #include <dialog_text_entry.h>
35 
36 #include <general.h>
37 #include <widgets/wx_grid.h>
39 #include <lib_edit_frame.h>
40 #include <class_library.h>
41 #include <symbol_lib_table.h>
42 #include <sch_component.h>
43 #include <dialog_helpers.h>
44 #include <bitmaps.h>
45 
47 
48 
49 #define LibEditFieldsShownColumnsKey wxT( "LibEditFieldsShownColumns" )
50 
52 
53 
55  LIB_PART* aLibEntry ) :
57  m_Parent( aParent ),
58  m_libEntry( aLibEntry ),
59  m_currentAlias( wxNOT_FOUND ),
60  m_pinNameOffset( aParent, m_nameOffsetLabel, m_nameOffsetCtrl, m_nameOffsetUnits, true ),
61  m_delayedFocusCtrl( nullptr ),
62  m_delayedFocusGrid( nullptr )
63 {
65 
66  // Give a bit more room for combobox editors
67  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
68  m_aliasGrid->SetDefaultRowSize( m_aliasGrid->GetDefaultRowSize() + 4 );
69  m_aliasGrid->SetMinClientSize( wxSize( -1, 24 + m_aliasGrid->GetDefaultRowSize() * 2 ) );
70 
71  m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, aParent, m_libEntry );
73 
74  m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );
75  m_aliasGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );
76 
77  // Show/hide columns according to the user's preference
78  m_config->Read( LibEditFieldsShownColumnsKey, &m_shownColumns, wxT( "0 1 2 3 4 5 6 7" ) );
80  // Hide non-overridden rows in aliases grid
81  m_aliasGrid->HideRow( REFERENCE );
82  m_aliasGrid->HideRow( FOOTPRINT );
83 
84  wxGridCellAttr* attr = new wxGridCellAttr;
85  attr->SetReadOnly();
86  m_aliasGrid->SetColAttr( FDC_NAME, attr );
89 
90  attr = new wxGridCellAttr;
91  attr->SetEditor( new GRID_CELL_URL_EDITOR( this ) );
92  m_aliasGrid->SetAttr( DATASHEET, FDC_VALUE, attr );
93 
94  // Configure button logos
95  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
96  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
97  m_bpMoveUp->SetBitmap( KiBitmap( small_up_xpm ) );
98  m_bpMoveDown->SetBitmap( KiBitmap( small_down_xpm ) );
99  m_addAliasButton->SetBitmap( KiBitmap( small_plus_xpm ) );
100  m_deleteAliasButton->SetBitmap( KiBitmap( trash_xpm ) );
101  m_addFilterButton->SetBitmap( KiBitmap( small_plus_xpm ) );
102  m_deleteFilterButton->SetBitmap( KiBitmap( trash_xpm ) );
103  m_editFilterButton->SetBitmap( KiBitmap( small_edit_xpm ) );
104 
105  m_stdSizerButtonOK->SetDefault();
106 
107  // wxFormBuilder doesn't include this event...
108  m_grid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnGridCellChanging ), NULL, this );
109  m_aliasGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAliasGridCellChanging ), NULL, this );
110 
111  m_grid->GetParent()->Layout();
112  m_aliasGrid->GetParent()->Layout();
113  Layout();
114 
116 }
117 
118 
120 {
121  m_lastOpenedPage = m_NoteBook->GetSelection( );
122 
124 
125  // Prevents crash bug in wxGrid's d'tor
127 
128  m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnGridCellChanging ), NULL, this );
129  m_aliasGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAliasGridCellChanging ), NULL, this );
130 
131  // Delete the GRID_TRICKS.
132  m_grid->PopEventHandler( true );
133  m_aliasGrid->PopEventHandler( true );
134 
135  // An OK will have transferred these and cleared the buffer, but we have to delete them
136  // on a Cancel.
137  for( LIB_ALIAS* alias : m_aliasesBuffer )
138  delete alias;
139 }
140 
141 
143 {
144  if( !wxDialog::TransferDataToWindow() )
145  return false;
146 
147  // Push a copy of each field into m_fields
149 
150  // The Y axis for components in lib is from bottom to top while the screen axis is top
151  // to bottom: we must change the y coord sign for editing
152  for( size_t i = 0; i < m_fields->size(); ++i )
153  {
154  wxPoint pos = m_fields->at( i ).GetPosition();
155  pos.y = -pos.y;
156  m_fields->at( i ).SetPosition( pos );
157  }
158 
159  // notify the grid
160  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
161  m_grid->ProcessTableMessage( msg );
162  adjustGridColumns( m_grid->GetRect().GetWidth());
163 
164  m_SymbolNameCtrl->SetValue( m_libEntry->GetName() );
165 
166  LIB_ALIAS* rootAlias = m_libEntry->GetAlias( m_libEntry->GetName() );
167  m_DescCtrl->SetValue( rootAlias->GetDescription() );
168  m_KeywordCtrl->SetValue( rootAlias->GetKeyWords() );
169 
172  m_AsConvertButt->SetValue( m_libEntry->HasConversion() );
173  m_OptionPower->SetValue( m_libEntry->IsPower() );
174 
176  m_ShowPinNameButt->SetValue( m_libEntry->ShowPinNames() );
177  m_PinsNameInsideButt->SetValue( m_libEntry->GetPinNameOffset() != 0 );
179 
180  const LIB_ALIASES aliases = m_libEntry->GetAliases();
181 
182  for( LIB_ALIAS* alias : aliases )
183  {
184  if( alias->IsRoot() )
185  continue;
186 
187  m_aliasesBuffer.push_back( new LIB_ALIAS( *alias, m_libEntry ) );
188  m_aliasListBox->Append( alias->GetName() );
189  }
190 
191  if( m_aliasListBox->GetCount() )
192  {
193  m_aliasListBox->SetSelection( 0 );
194 
195  wxCommandEvent dummy;
196  OnSelectAlias( dummy );
197  }
198 
199  adjustAliasGridColumns( m_aliasGrid->GetClientRect().GetWidth() - 4 );
200 
202 
203  m_NoteBook->SetSelection( (unsigned) m_lastOpenedPage );
204 
205  return true;
206 }
207 
208 
210 {
212  return false;
213 
214  if( !SCH_COMPONENT::IsReferenceStringValid( m_fields->at( REFERENCE ).GetText() ) )
215  {
216  if( m_NoteBook->GetSelection() != 0 )
217  m_NoteBook->SetSelection( 0 );
218 
219  m_delayedErrorMessage = _( "References must start with a letter." );
223 
224  return false;
225  }
226 
227  // Check for missing field names.
228  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
229  {
230  LIB_FIELD& field = m_fields->at( i );
231  wxString fieldName = field.GetName( false );
232 
233  if( fieldName.IsEmpty() )
234  {
235  if( m_NoteBook->GetSelection() != 0 )
236  m_NoteBook->SetSelection( 0 );
237 
238  m_delayedErrorMessage = _( "Fields must have a name." );
242 
243  return false;
244  }
245  }
246 
247  if( m_SelNumberOfUnits->GetValue() < m_libEntry->GetUnitCount() )
248  {
249  if( !IsOK( this, _( "Delete extra units from symbol?" ) ) )
250  return false;
251  }
252 
253  if( m_AsConvertButt->GetValue() && !m_libEntry->HasConversion() )
254  {
255  if( !IsOK( this, _( "Add new pins for alternate body style (DeMorgan) to symbol?" ) ) )
256  return false;
257  }
258  else if( !m_AsConvertButt->GetValue() && m_libEntry->HasConversion() )
259  {
260  if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from symbol?" ) ) )
261  return false;
262  }
263 
264  return true;
265 }
266 
267 
269 {
270  if( !Validate() )
271  return false;
272 
274 
275  // The Y axis for components in lib is from bottom to top while the screen axis is top
276  // to bottom: we must change the y coord sign when writing back to the library
277  for( size_t i = 0; i < m_fields->size(); ++i )
278  {
279  wxPoint pos = m_fields->at( i ).GetPosition();
280  pos.y = -pos.y;
281  m_fields->at( i ).SetPosition( pos );
282  }
283 
285 
286  // We need to keep the name and the value the same at the moment!
287  SetName( m_libEntry->GetValueField().GetText() );
288 
289  LIB_ALIAS* rootAlias = m_libEntry->GetAlias( m_libEntry->GetName() );
290 
291  rootAlias->SetDescription( m_DescCtrl->GetValue() );
292  rootAlias->SetKeyWords( m_KeywordCtrl->GetValue() );
293 
296 
297  m_libEntry->SetConversion( m_AsConvertButt->GetValue() );
298 
299  if( m_OptionPower->GetValue() )
300  m_libEntry->SetPower();
301  else
303 
306 
307  if( m_PinsNameInsideButt->GetValue() )
308  {
309  int offset = KiROUND( (double) m_pinNameOffset.GetValue() / IU_PER_MILS );
310 
311  // We interpret an offset of 0 as "outside", so make sure it's non-zero
312  m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
313  }
314  else
315  {
316  m_libEntry->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
317  }
318 
321 
322  for( LIB_ALIAS* alias : m_aliasesBuffer )
323  m_libEntry->AddAlias( alias ); // Transfers ownership; no need to delete
324 
325  m_aliasesBuffer.clear();
326 
327  m_libEntry->GetFootprints().Clear();
329 
330  m_Parent->OnModify();
331 
332  return true;
333 }
334 
335 
337 {
338  wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
339  wxControl* control = editor->GetControl();
340 
341  if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
342  {
343  event.Veto();
344 
345  if( m_NoteBook->GetSelection() != 0 )
346  m_NoteBook->SetSelection( 0 );
347 
349  m_delayedFocusRow = event.GetRow();
350  m_delayedFocusColumn = event.GetCol();
351  }
352 
353  editor->DecRef();
354 }
355 
356 
357 void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAddField( wxCommandEvent& event )
358 {
359  if( !m_grid->CommitPendingChanges() )
360  return;
361 
362  int fieldID = m_fields->size();
363  LIB_FIELD newField( m_libEntry, fieldID );
364 
365  m_fields->push_back( newField );
366 
367  // notify the grid
368  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
369  m_grid->ProcessTableMessage( msg );
370 
371  m_grid->MakeCellVisible( m_fields->size() - 1, 0 );
372  m_grid->SetGridCursor( m_fields->size() - 1, 0 );
373 
374  m_grid->EnableCellEditControl();
375  m_grid->ShowCellEditControl();
376 }
377 
378 
380 {
381  int curRow = m_grid->GetGridCursorRow();
382 
383  if( curRow < 0 )
384  return;
385  else if( curRow < MANDATORY_FIELDS )
386  {
387  DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
388  MANDATORY_FIELDS ) );
389  return;
390  }
391 
392  m_grid->CommitPendingChanges( true /* quiet mode */ );
393 
394  m_fields->erase( m_fields->begin() + curRow );
395 
396  // notify the grid
397  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
398  m_grid->ProcessTableMessage( msg );
399 
400  if( m_grid->GetNumberRows() > 0 )
401  {
402  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
403  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
404  }
405 }
406 
407 
408 void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnMoveUp( wxCommandEvent& event )
409 {
410  if( !m_grid->CommitPendingChanges() )
411  return;
412 
413  int i = m_grid->GetGridCursorRow();
414 
415  if( i > MANDATORY_FIELDS )
416  {
417  LIB_FIELD tmp = m_fields->at( (unsigned) i );
418  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
419  m_fields->insert( m_fields->begin() + i - 1, tmp );
420  m_grid->ForceRefresh();
421 
422  m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
423  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
424  }
425  else
426  wxBell();
427 }
428 
429 
430 void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnMoveDown( wxCommandEvent& event )
431 {
432  if( !m_grid->CommitPendingChanges() )
433  return;
434 
435  int i = m_grid->GetGridCursorRow();
436 
437  if( i >= MANDATORY_FIELDS )
438  {
439  LIB_FIELD tmp = m_fields->at( (unsigned) i );
440  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
441  m_fields->insert( m_fields->begin() + i + 1, tmp );
442  m_grid->ForceRefresh();
443 
444  m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
445  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
446  }
447  else
448  wxBell();
449 }
450 
451 
452 void DIALOG_EDIT_COMPONENT_IN_LIBRARY::updateAliasName( bool aFromGrid, const wxString& aName )
453 {
454  int idx = m_aliasListBox->GetSelection();
455 
456  if( idx >= 0 )
457  {
458  m_aliasListBox->SetString( (unsigned) idx, aName );
459  m_aliasesBuffer[ idx ]->SetName( aName );
460 
461  if( aFromGrid )
462  m_AliasNameCtrl->ChangeValue( aName );
463  else
464  m_aliasGrid->SetCellValue( VALUE, FDC_VALUE, aName );
465  }
466 }
467 
468 
470 {
471  if( event.GetRow() == VALUE )
472  {
473  int idx = m_aliasListBox->GetSelection();
474  wxString newName = event.GetString();
475 
476  if( idx < 0 || !checkAliasName( newName ) )
477  {
478  event.Veto();
479 
480  if( m_NoteBook->GetSelection() != 1 )
481  m_NoteBook->SetSelection( 1 );
482 
484  m_delayedFocusRow = event.GetRow();
485  m_delayedFocusColumn = event.GetCol();
486  }
487  }
488 }
489 
490 
492 {
493  updateAliasName( false, m_AliasNameCtrl->GetValue() );
494 }
495 
496 
498 {
499  static bool inKillFocus = false;
500 
501  // If we get an error then we're going to throw up a dialog. Since we haven't yet
502  // finished the KillFocus event, we'll end up getting another one. Side-effects may
503  // include death.
504  if( inKillFocus )
505  return;
506 
507  inKillFocus = true;
508 
509  if( !checkAliasName( m_AliasNameCtrl->GetValue() ) )
511 
512  inKillFocus = false;
513 
514  event.Skip();
515 }
516 
517 
519 {
520  if( m_currentAlias >= 0 )
521  {
523 
524  alias->SetName( m_aliasGrid->GetCellValue( VALUE, FDC_VALUE ) );
525  alias->SetDocFileName( m_aliasGrid->GetCellValue( DATASHEET, FDC_VALUE ) );
526  alias->SetDescription( m_AliasDescCtrl->GetValue() );
527  alias->SetKeyWords( m_AliasKeywordsCtrl->GetValue() );
528  }
529 }
530 
531 
533 {
535  {
536  m_aliasListBox->SetSelection( m_currentAlias ); // veto selection change
537  return;
538  }
539 
540  // Copy any pending changes back into the buffer
542 
543  LIB_ALIAS* alias = nullptr;
544  int newIdx = m_aliasListBox->GetSelection();
545 
546  if( newIdx >= 0 )
547  {
548  alias = m_aliasesBuffer[ newIdx ];
549 
550  m_aliasGrid->SetCellValue( VALUE, FDC_VALUE, alias->GetName() );
551  m_aliasGrid->SetCellValue( DATASHEET, FDC_VALUE, alias->GetDocFileName() );
552 
553  // Use ChangeValue() so we don't generate events
554  m_AliasNameCtrl->ChangeValue( alias->GetName() );
555  m_AliasDescCtrl->ChangeValue( alias->GetDescription() );
556  m_AliasKeywordsCtrl->ChangeValue( alias->GetKeyWords() );
557  }
558  else
559  {
560  m_aliasGrid->SetCellValue( VALUE, FDC_VALUE, wxEmptyString );
561  m_aliasGrid->SetCellValue( DATASHEET, FDC_VALUE, wxEmptyString );
562 
563  // Use ChangeValue() so we don't generate events
564  m_AliasNameCtrl->ChangeValue( wxEmptyString );
565  m_AliasDescCtrl->ChangeValue( wxEmptyString );
566  m_AliasKeywordsCtrl->ChangeValue( wxEmptyString );
567  }
568 
569  m_currentAlias = newIdx;
570 }
571 
572 
574 {
575  if( aName.IsEmpty() )
576  return false;
577 
578  for( size_t i = 0; i < m_aliasListBox->GetCount(); ++i )
579  {
580  if( i == m_aliasListBox->GetSelection() )
581  continue;
582 
583  if( m_aliasListBox->GetString( i ).CmpNoCase( aName ) == 0 )
584  {
585  wxString msg;
586  msg.Printf( _( "Alias \"%s\" already exists." ), aName );
587  DisplayInfoMessage( this, msg );
588  return false;
589  }
590  }
591 
592  wxString library = m_Parent->GetCurLib();
593 
594  if( !library.empty() )
595  {
596  LIB_ALIAS* existing = Prj().SchSymbolLibTable()->LoadSymbol( library, aName );
597 
598  if( existing && existing->GetPart()->GetName() != m_libEntry->GetName() )
599  {
600  wxString msg;
601  msg.Printf( _( "Symbol name \"%s\" already exists in library \"%s\"." ), aName, library );
602  DisplayErrorMessage( this, msg );
603  return false;
604  }
605  }
606 
607  return true;
608 }
609 
610 
611 void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAddAlias( wxCommandEvent& event )
612 {
614  return;
615 
616  wxCommandEvent dummy;
617  wxString aliasname = _( "untitled" );
618  int suffix = 1;
619 
620  while( m_libEntry->HasAlias( aliasname ) )
621  aliasname = wxString::Format( _( "untitled%i" ), suffix++ );
622 
623  LIB_ALIAS* alias = new LIB_ALIAS( aliasname, m_libEntry );
624 
625  // Initialize with parent's data
626  alias->SetDescription( m_DescCtrl->GetValue() );
627  alias->SetKeyWords( m_KeywordCtrl->GetValue() );
628  alias->SetDocFileName( m_grid->GetCellValue( DATASHEET, FDC_VALUE ) );
629 
630  m_aliasesBuffer.push_back( alias ); // transfers ownership of alias to aliasesBuffer
631 
632  m_aliasListBox->Append( aliasname );
633  m_aliasListBox->SetSelection( m_aliasListBox->GetCount() - 1 );
634  OnSelectAlias( dummy );
635 }
636 
637 
639 {
641  return;
642 
643  int sel = m_aliasListBox->GetSelection();
644 
645  if( sel == wxNOT_FOUND )
646  return;
647 
648  m_aliasListBox->Delete( (unsigned) sel );
649  m_aliasesBuffer.erase( m_aliasesBuffer.begin() + sel );
650 
651  if( m_aliasListBox->GetCount() == 0 )
652  m_aliasListBox->SetSelection( wxNOT_FOUND );
653  else
654  m_aliasListBox->SetSelection( std::max( 0, sel - 1 ) );
655 
656  wxCommandEvent dummy;
657  OnSelectAlias( dummy );
658 }
659 
660 
662 {
663  wxString filterLine;
664  LIB_PART* component = m_Parent->GetCurPart();
665 
666  if( component == NULL )
667  return;
668 
669  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Add Footprint Filter" ), filterLine );
670 
671  if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue().IsEmpty() )
672  return;
673 
674  filterLine = dlg.GetValue();
675  filterLine.Replace( wxT( " " ), wxT( "_" ) );
676 
677  // duplicate filters do no harm, so don't be a nanny.
678 
679  m_FootprintFilterListBox->Append( filterLine );
680  m_FootprintFilterListBox->SetSelection( m_FootprintFilterListBox->GetCount() - 1 );
681 }
682 
683 
685 {
686  int ii = m_FootprintFilterListBox->GetSelection();
687 
688  if( ii >= 0 )
689  {
690  m_FootprintFilterListBox->Delete( (unsigned) ii );
691 
692  if( m_FootprintFilterListBox->GetCount() == 0 )
693  m_FootprintFilterListBox->SetSelection( wxNOT_FOUND );
694  else
695  m_FootprintFilterListBox->SetSelection( std::max( 0, ii - 1 ) );
696  }
697 }
698 
700 {
701  int idx = m_FootprintFilterListBox->GetSelection();
702 
703  if( idx >= 0 )
704  {
705  wxString filter = m_FootprintFilterListBox->GetStringSelection();
706 
707  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Edit Footprint Filter" ), filter );
708 
709  if( dlg.ShowModal() == wxID_OK && !dlg.GetValue().IsEmpty() )
710  m_FootprintFilterListBox->SetString( (unsigned) idx, dlg.GetValue() );
711  }
712 }
713 
714 
716 {
717  // Account for scroll bars
718  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
719 
720  m_grid->AutoSizeColumn( FDC_NAME );
721 
722  int fixedColsWidth = m_grid->GetColSize( FDC_NAME );
723 
724  for( int i = 2; i < m_grid->GetNumberCols(); i++ )
725  fixedColsWidth += m_grid->GetColSize( i );
726 
727  m_grid->SetColSize( FDC_VALUE, aWidth - fixedColsWidth );
728 }
729 
730 
732 {
733  m_aliasGrid->AutoSizeColumn( FDC_NAME );
734  m_aliasGrid->SetColSize( FDC_VALUE, aWidth - m_aliasGrid->GetColSize( FDC_NAME ) - 2 );
735 }
736 
737 
738 void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnUpdateUI( wxUpdateUIEvent& event )
739 {
740  m_OptionPartsLocked->Enable( m_SelNumberOfUnits->GetValue() > 1 );
742 
743  // Synthesize a Select event when the selection is cleared
744  if( m_aliasListBox->GetSelection() == wxNOT_FOUND && m_currentAlias != wxNOT_FOUND )
745  {
746  wxCommandEvent dummy;
747  OnSelectAlias( dummy );
748  }
749 
750  // Handle shown columns changes
751  wxString shownColumns = m_grid->GetShownColumns();
752 
753  if( shownColumns != m_shownColumns )
754  {
755  m_shownColumns = shownColumns;
756 
757  if( !m_grid->IsCellEditControlShown() )
758  adjustGridColumns( m_grid->GetRect().GetWidth());
759  }
760 
761  // Handle a delayed focus
762  if( m_delayedFocusCtrl )
763  {
764  m_delayedFocusCtrl->SetFocus();
765 
766  if( dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
767  dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl )->SelectAll();
768 
769  m_delayedFocusCtrl = nullptr;
770  }
771  else if( m_delayedFocusGrid )
772  {
773  m_delayedFocusGrid->SetFocus();
776 
777  if( !m_delayedErrorMessage.IsEmpty() )
779 
780  m_delayedFocusGrid->EnableCellEditControl( true );
781  m_delayedFocusGrid->ShowCellEditControl();
782 
783  m_delayedErrorMessage = wxEmptyString;
784  m_delayedFocusGrid = nullptr;
785  }
786 }
787 
788 
790 {
791  adjustGridColumns( event.GetSize().GetX());
792 
793  event.Skip();
794 }
795 
796 
798 {
799  adjustAliasGridColumns( event.GetSize().GetX());
800 
801  event.Skip();
802 }
void OnAddFootprintFilter(wxCommandEvent &event) override
bool UnitsLocked() const
Check whether part units are interchangeable.
Part library alias object definition.
void SetConversion(bool aSetConvert)
Set or clear the alternate body style (DeMorgan) for the part.
void SetPower()
name of datasheet
void OnUpdateUI(wxUpdateUIEvent &event) override
int GetPinNameOffset()
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:247
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
void OnAliasNameText(wxCommandEvent &event) override
bool IsPower() const
int GetNumberRows() override
LIB_ALIAS * GetAlias(size_t aIndex)
void OnEditFootprintFilter(wxCommandEvent &event) override
void OnSizeGrid(wxSizeEvent &event) override
This file is part of the common library.
void updateAliasName(bool aFromGrid, const wxString &aName)
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:76
LIB_ALIASES GetAliases() const
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 FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool HasAlias(const wxString &aName) const
Test if alias aName is in part alias list.
LIB_FIELD & GetValueField()
Return reference to the value field.
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen...
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
std::vector< LIB_ALIAS * > LIB_ALIASES
void AddAlias(const wxString &aName)
Add an alias aName to the part.
void SetDocFileName(const wxString &aDocFileName)
void OnDeleteFootprintFilter(wxCommandEvent &event) override
Field Name Module PCB, i.e. "16DIP300".
virtual int GetValue() const
Function GetValue Returns the current value in Internal Units.
Field Reference of part, i.e. "IC21".
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
void OnAliasNameKillFocus(wxFocusEvent &event) override
void OnMoveUp(wxCommandEvent &event) override
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:47
bool ShowPinNames()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
void SetName(const wxString &aName)
bool ShowPinNumbers()
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
const wxString & GetKeyWords() const
void SetUnitCount(int count)
Set the units per part count.
void OnDeleteField(wxCommandEvent &event) override
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
Define a library symbol object.
Helper dialog and control classes.
void OnSelectAlias(wxCommandEvent &event) override
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
void OnSizeAliasGrid(wxSizeEvent &event) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:124
void SetDescription(const wxString &aDescription)
void OnMoveDown(wxCommandEvent &event) override
wxArrayString & GetFootprints()
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:432
LIB_PART * GetPart() const
Get the shared LIB_PART.
void OnDeleteAlias(wxCommandEvent &event) override
int GetUnitCount() const
const wxString & GetDescription() override
void SetTable(wxGridTableBase *table)
Hide wxGrid&#39;s SetTable() method with one which doesn&#39;t mess up the grid column widths when setting th...
Definition: wx_grid.cpp:29
const wxString & GetDocFileName() const
#define LibEditFieldsShownColumnsKey
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:58
Definition the SCH_COMPONENT class for Eeschema.
wxString GetValue()
The symbol library editor main window.
see class PGM_BASE
const wxString & GetName() const override
void RemoveAllAliases()
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
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
#define max(a, b)
Definition: auxiliary.h:86
void SetKeyWords(const wxString &aKeyWords)
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy, UNDO_REDO_T undoType=UR_LIBEDIT)
Create a copy of the current component, and save it in the undo list.
size_t i
Definition: json11.cpp:597
The common library.
Class DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE.
const wxString & GetName() const
Definition of class LIB_EDIT_FRAME.
void OnAddAlias(wxCommandEvent &event) override
Definition for part library class.
static bool IsReferenceStringValid(const wxString &aReferenceString)
Tests for an acceptable reference string.
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:264
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
#define VALUE
void OnAddField(wxCommandEvent &event) override
FIELDS_GRID_TABLE< LIB_FIELD > * m_fields
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:233
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:281
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
void GetFields(LIB_FIELDS &aList)
Return a list of fields withing this part.
void LockUnits(bool aLockUnits)
Set interchangeable the property for part units.
void SetNormal()