KiCad PCB EDA Suite
dialog_edit_component_in_schematic.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) 2004-2019 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 
25 
26 #include <wx/tooltip.h>
27 
28 #include <confirm.h>
29 #include <grid_tricks.h>
30 #include <kiface_i.h>
31 #include <menus_helpers.h>
32 #include <pgm_base.h>
33 
34 #include <widgets/wx_grid.h>
35 
36 #include <class_library.h>
37 #include <fields_grid_table.h>
38 #include <invoke_sch_dialog.h>
39 #include <sch_draw_panel.h>
40 #include <sch_edit_frame.h>
41 #include <sch_reference_list.h>
42 #include <sch_validators.h>
43 #include <symbol_lib_table.h>
44 
45 #ifdef KICAD_SPICE
46 #include <dialog_spice_model.h>
48 #endif /* KICAD_SPICE */
49 
50 
51 #define SymbolFieldsShownColumnsKey wxT( "SymbolFieldsShownColumns" )
52 
53 
55  SCH_COMPONENT* aComponent ) :
57 {
59 
60  m_cmp = aComponent;
61  m_part = GetParent()->GetLibPart( m_cmp->GetLibId(), true );
62  m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_part );
63 
64  m_width = 0;
67 
68 #ifndef KICAD_SPICE
69  m_spiceFieldsButton->Hide();
70 #endif /* not KICAD_SPICE */
71 
72  // disable some options inside the edit dialog which can cause problems while dragging
73  if( m_cmp->IsDragging() )
74  {
75  m_rbOrientation->Disable();
76  m_rbMirror->Disable();
77  m_libraryNameTextCtrl->Disable();
78  }
79 
80  // Give a bit more room for combobox editors
81  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
82 
84  m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );
85 
86  // Show/hide columns according to user's preference
87  m_config->Read( SymbolFieldsShownColumnsKey, &m_shownColumns, wxT( "0 1 2 3 4 5 6 7" ) );
89 
90  wxToolTip::Enable( true );
91  m_stdDialogButtonSizerOK->SetDefault();
92 
93  // Configure button logos
94  m_buttonBrowseLibrary->SetBitmap( KiBitmap( small_library_xpm ) );
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 
100  // wxFormBuilder doesn't include this event...
101  m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
103  NULL, this );
104 
106 }
107 
108 
110 {
112 
113  // Prevents crash bug in wxGrid's d'tor
115 
116  m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
118  NULL, this );
119 
120  // Delete the GRID_TRICKS.
121  m_grid->PopEventHandler( true );
122 }
123 
124 
126 {
127  return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
128 }
129 
130 
132 {
133  if( !wxDialog::TransferDataToWindow() )
134  return false;
135 
136  std::set<wxString> defined;
137 
138  // Push a copy of each field into m_fields
139  for( int i = 0; i < m_cmp->GetFieldCount(); ++i )
140  {
141  SCH_FIELD field( *m_cmp->GetField( i ) );
142 
143  // change offset to be symbol-relative
144  field.Offset( -m_cmp->GetPosition() );
145 
146  defined.insert( field.GetName() );
147  m_fields->push_back( field );
148  }
149 
150  // Add in any template fieldnames not yet defined:
151  for( TEMPLATE_FIELDNAME templateFieldname : GetParent()->GetTemplateFieldNames() )
152  {
153  if( defined.count( templateFieldname.m_Name ) <= 0 )
154  {
155  SCH_FIELD field( wxPoint( 0, 0 ), -1, m_cmp, templateFieldname.m_Name );
156  field.SetVisible( templateFieldname.m_Visible );
157  m_fields->push_back( field );
158  }
159  }
160 
161  // notify the grid
162  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
163  m_grid->ProcessTableMessage( msg );
164  AdjustGridColumns( m_grid->GetRect().GetWidth() );
165 
166  // If a multi-unit component, set up the unit selector and interchangeable checkbox.
167  if( m_cmp->GetUnitCount() > 1 )
168  {
169  for( int ii = 1; ii <= m_cmp->GetUnitCount(); ii++ )
170  m_unitChoice->Append( LIB_PART::SubReference( ii, false ) );
171 
172  if( m_cmp->GetUnit() <= ( int )m_unitChoice->GetCount() )
173  m_unitChoice->SetSelection( m_cmp->GetUnit() - 1 );
174  }
175  else
176  {
177  m_unitLabel->Enable( false );
178  m_unitChoice->Enable( false );
179  }
180 
181  if( m_part != nullptr && m_part->HasConversion() )
182  {
183  if( m_cmp->GetConvert() > LIB_ITEM::LIB_CONVERT::BASE )
184  m_cbAlternateSymbol->SetValue( true );
185  }
186  else
187  m_cbAlternateSymbol->Enable( false );
188 
189  // Set the symbol orientation and mirroring.
190  int orientation = m_cmp->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
191 
192  if( orientation == CMP_ORIENT_90 )
193  m_rbOrientation->SetSelection( 1 );
194  else if( orientation == CMP_ORIENT_180 )
195  m_rbOrientation->SetSelection( 2 );
196  else if( orientation == CMP_ORIENT_270 )
197  m_rbOrientation->SetSelection( 3 );
198  else
199  m_rbOrientation->SetSelection( 0 );
200 
201  int mirror = m_cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
202 
203  if( mirror == CMP_MIRROR_X )
204  {
205  m_rbMirror->SetSelection( 1 );
206  DBG( printf( "mirror=X,1\n" ); )
207  }
208  else if( mirror == CMP_MIRROR_Y )
209  {
210  m_rbMirror->SetSelection( 2 );
211  DBG( printf( "mirror=Y,2\n" ); )
212  }
213  else
214  m_rbMirror->SetSelection( 0 );
215 
216  // Set the component's unique ID time stamp.
217  m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ),
218  (unsigned long) m_cmp->GetTimeStamp() ) );
219 
220  // Set the component's library name.
221  m_libraryNameTextCtrl->SetValue( m_cmp->GetLibId().Format() );
222 
223  Layout();
224 
225  return true;
226 }
227 
228 
230 {
232 
233  LIB_ID id;
234  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
235 
236  auto sel = GetParent()->SelectCompFromLibTree( nullptr, dummy, true, 0, 0, false, &id );
237 
238  if( !sel.LibId.IsValid() )
239  return;
240 
241  m_libraryNameTextCtrl->SetValue( sel.LibId.Format() );
242 
243  LIB_PART* entry = GetParent()->GetLibPart( sel.LibId );
244 
245  if( entry )
246  {
247  // Update the value field for Power symbols
248  if( entry->IsPower() )
249  m_grid->SetCellValue( VALUE, FDC_VALUE, sel.LibId.GetLibItemName() );
250 
251  // Update the units control
252  int unit = m_unitChoice->GetSelection();
253  m_unitChoice->Clear();
254 
255  if( entry->GetUnitCount() > 1 )
256  {
257  for( int ii = 1; ii <= entry->GetUnitCount(); ii++ )
258  m_unitChoice->Append( LIB_PART::SubReference( ii, false ) );
259 
260  if( unit < 0 || static_cast<unsigned>( unit ) >= m_unitChoice->GetCount() )
261  unit = 0;
262 
263  m_unitChoice->SetSelection( unit );
264  m_unitLabel->Enable( true );
265  m_unitChoice->Enable( true );
266  }
267  else
268  {
269  m_unitChoice->SetSelection( -1 );
270  m_unitLabel->Enable( false );
271  m_unitChoice->Enable( false );
272  }
273 
274  // Update the deMorgan conversion controls
275  bool conversion = m_cbAlternateSymbol->GetValue();
276 
277  m_cbAlternateSymbol->SetValue( conversion && entry->HasConversion() );
278  m_cbAlternateSymbol->Enable( entry->HasConversion() );
279  }
280 }
281 
282 
284 {
285 #ifdef KICAD_SPICE
286  int diff = m_fields->size();
287 
288  DIALOG_SPICE_MODEL dialog( this, *m_cmp, m_fields );
289 
290  if( dialog.ShowModal() != wxID_OK )
291  return;
292 
293  diff = m_fields->size() - diff;
294 
295  if( diff > 0 )
296  {
297  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
298  m_grid->ProcessTableMessage( msg );
299  }
300  else if( diff < 0 )
301  {
302  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, diff );
303  m_grid->ProcessTableMessage( msg );
304  }
305 
306  m_grid->ForceRefresh();
307 #endif /* KICAD_SPICE */
308 }
309 
310 
312 {
313  // Running the Footprint Browser gums up the works and causes the automatic cancel
314  // stuff to no longer work. So we do it here ourselves.
315  EndQuasiModal( wxID_CANCEL );
316 }
317 
318 
320 {
321  wxString msg;
322  LIB_ID id;
323 
324  if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
325  return false;
326 
327  if( !SCH_COMPONENT::IsReferenceStringValid( m_fields->at( REFERENCE ).GetText() ) )
328  {
329  DisplayErrorMessage( this, _( "References must start with a letter." ) );
330 
333 
334  return false;
335  }
336 
337  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
338 
339  if( !id.IsValid() )
340  {
341  DisplayErrorMessage( this, _( "Library reference is not valid." ) );
342 
343  m_libraryNameTextCtrl->SetFocus();
344 
345  return false;
346  }
347  else if( id != m_cmp->GetLibId() )
348  {
349  LIB_ALIAS* alias = nullptr;
350 
351  try
352  {
353  alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
354  }
355  catch( ... )
356  {
357  }
358 
359  if( !alias )
360  {
361  msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"." ),
362  id.GetLibItemName().wx_str(),
363  id.GetLibNickname().wx_str() );
364  DisplayErrorMessage( this, msg );
365 
366  m_libraryNameTextCtrl->SetFocus();
367 
368  return false;
369  }
370  }
371  m_libraryNameTextCtrl->SetValue( id.Format() );
372 
373  // Check for missing field names.
374  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
375  {
376  SCH_FIELD& field = m_fields->at( i );
377  wxString fieldName = field.GetName( false );
378 
379  if( fieldName.IsEmpty() )
380  {
381  DisplayErrorMessage( this, _( "Fields must have a name." ) );
382 
385 
386  return false;
387  }
388  }
389 
390  return true;
391 }
392 
393 
395 {
396  if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
397  return false;
398 
399  // save old cmp in undo list if not already in edit, or moving ...
400  if( m_cmp->GetEditFlags() == 0 )
402 
403  // Save current flags which could be modified by next change settings
404  STATUS_FLAGS flags = m_cmp->GetFlags();
405 
406  // Library symbol identifier
407  LIB_ID id;
408  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true );
409  m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
410 
411  // For symbols with multiple shapes (De Morgan representation) Set the selected shape:
412  if( m_cbAlternateSymbol->IsEnabled() && m_cbAlternateSymbol->GetValue() )
413  m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::DEMORGAN );
414  else
415  m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::BASE );
416 
417  //Set the part selection in multiple part per package
418  int unit_selection = m_unitChoice->IsEnabled()
419  ? m_unitChoice->GetSelection() + 1
420  : 1;
421  m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
422  m_cmp->SetUnit( unit_selection );
423 
424  switch( m_rbOrientation->GetSelection() )
425  {
426  case 0: m_cmp->SetOrientation( CMP_ORIENT_0 ); break;
427  case 1: m_cmp->SetOrientation( CMP_ORIENT_90 ); break;
428  case 2: m_cmp->SetOrientation( CMP_ORIENT_180 ); break;
429  case 3: m_cmp->SetOrientation( CMP_ORIENT_270 ); break;
430  }
431 
432  switch( m_rbMirror->GetSelection() )
433  {
434  case 0: break;
435  case 1: m_cmp->SetOrientation( CMP_MIRROR_X ); break;
436  case 2: m_cmp->SetOrientation( CMP_MIRROR_Y ); break;
437  }
438 
439  // Restore m_Flag modified by SetUnit() and other change settings
440  m_cmp->ClearFlags();
441  m_cmp->SetFlags( flags );
442 
443  // change all field positions from relative to absolute
444  for( unsigned i = 0; i < m_fields->size(); ++i )
445  m_fields->at( i ).Offset( m_cmp->GetPosition() );
446 
447  LIB_PART* entry = GetParent()->GetLibPart( m_cmp->GetLibId() );
448 
449  if( entry && entry->IsPower() )
450  m_fields->at( VALUE ).SetText( m_cmp->GetLibId().GetLibItemName() );
451 
452  // Remove any TEMPLATE_FIELDNAMES which were not set (given values).
453  TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames();
454 
455  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
456  {
457  SCH_FIELD& field = m_fields->at( i );
458 
459  for( auto fieldname : templateFieldnames )
460  {
461  if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() )
462  {
463  m_fields->erase( m_fields->begin() + i );
464 
465  // grid needs to be notified about the size change,
466  // as it still accesses the data on close (size event)
467  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, i, 1 );
468  m_grid->ProcessTableMessage( msg );
469  i--;
470  break;
471  }
472  }
473  }
474 
475  m_cmp->SetFields( *m_fields );
476 
477  // Reference has a specific initialization, depending on the current active sheet
478  // because for a given component, in a complex hierarchy, there are more than one
479  // reference.
480  m_cmp->SetRef( &GetParent()->GetCurrentSheet(), m_fields->at( REFERENCE ).GetText() );
481 
482  // The value, footprint and datasheet fields should be kept in sync in multi-unit
483  // parts.
484  if( m_cmp->GetUnitCount() > 1 )
485  {
486  const LIB_ID thisLibId = m_cmp->GetLibId();
487  const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) );
488  int thisUnit = m_cmp->GetUnit();
489 
490  SCH_REFERENCE_LIST components;
491  GetParent()->GetCurrentSheet().GetComponents( components );
492 
493  for( unsigned i = 0; i < components.GetCount(); i++ )
494  {
495  SCH_REFERENCE component = components[i];
496 
497  if( component.GetLibPart()->GetLibId() == thisLibId
498  && component.GetRef() == thisRef
499  && component.GetUnit() != thisUnit )
500  {
501  SCH_COMPONENT* otherUnit = component.GetComp();
502  GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
503  otherUnit->GetField( VALUE )->SetText( m_fields->at( VALUE ).GetText() );
504  otherUnit->GetField( FOOTPRINT )->SetText( m_fields->at( FOOTPRINT ).GetText() );
505  otherUnit->GetField( DATASHEET )->SetText( m_fields->at( DATASHEET ).GetText() );
506  }
507  }
508  }
509 
510  m_cmp->UpdatePins();
511 
514  GetParent()->OnModify();
515 
516  return true;
517 }
518 
519 
521 {
522  wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
523  wxControl* control = editor->GetControl();
524 
525  if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
526  {
527  event.Veto();
528  m_delayedFocusRow = event.GetRow();
529  m_delayedFocusColumn = event.GetCol();
530  }
531 
532  editor->DecRef();
533 }
534 
535 
537 {
538  if( !m_grid->CommitPendingChanges() )
539  return;
540 
541  int fieldID = m_fields->size();
542  SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_cmp );
543 
544  newField.SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID ) );
545  newField.SetTextAngle( m_fields->at( REFERENCE ).GetTextAngle() );
546 
547  m_fields->push_back( newField );
548 
549  // notify the grid
550  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
551  m_grid->ProcessTableMessage( msg );
552 
553  m_grid->MakeCellVisible( m_fields->size() - 1, 0 );
554  m_grid->SetGridCursor( m_fields->size() - 1, 0 );
555 
556  m_grid->EnableCellEditControl();
557  m_grid->ShowCellEditControl();
558 }
559 
560 
562 {
563  int curRow = m_grid->GetGridCursorRow();
564 
565  if( curRow < 0 )
566  return;
567  else if( curRow < MANDATORY_FIELDS )
568  {
569  DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
570  MANDATORY_FIELDS ) );
571  return;
572  }
573 
574  m_grid->CommitPendingChanges( true /* quiet mode */ );
575 
576  m_fields->erase( m_fields->begin() + curRow );
577 
578  // notify the grid
579  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
580  m_grid->ProcessTableMessage( msg );
581 
582  if( m_grid->GetNumberRows() > 0 )
583  {
584  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
585  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
586  }
587 }
588 
589 
590 void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnMoveUp( wxCommandEvent& event )
591 {
592  if( !m_grid->CommitPendingChanges() )
593  return;
594 
595  int i = m_grid->GetGridCursorRow();
596 
597  if( i > MANDATORY_FIELDS )
598  {
599  SCH_FIELD tmp = m_fields->at( (unsigned) i );
600  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
601  m_fields->insert( m_fields->begin() + i - 1, tmp );
602  m_grid->ForceRefresh();
603 
604  m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
605  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
606  }
607  else
608  wxBell();
609 }
610 
611 
613 {
614  if( !m_grid->CommitPendingChanges() )
615  return;
616 
617  int i = m_grid->GetGridCursorRow();
618 
619  if( i >= MANDATORY_FIELDS && i < m_grid->GetNumberRows() - 1 )
620  {
621  SCH_FIELD tmp = m_fields->at( (unsigned) i );
622  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
623  m_fields->insert( m_fields->begin() + i + 1, tmp );
624  m_grid->ForceRefresh();
625 
626  m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
627  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
628  }
629  else
630  wxBell();
631 }
632 
633 
635 {
636  if( !m_grid->CommitPendingChanges() )
637  return;
638 
639  SCH_COMPONENT copy( *m_cmp );
640  copy.SetFields( *m_fields );
641 
642  LIB_ID id;
643  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true );
644  copy.SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
645 
646  // Update the requested fields in the component copy
647  std::list<SCH_COMPONENT*> components;
648  components.push_back( &copy );
649  InvokeDialogUpdateFields( GetParent(), components, false );
650 
651  wxGridTableMessage clear( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_fields->size() );
652  m_grid->ProcessTableMessage( clear );
653 
654  // Copy fields from the component copy to the dialog buffer
655  m_fields->clear();
656  std::set<wxString> defined;
657 
658  for( int i = 0; i < copy.GetFieldCount(); ++i )
659  {
660  copy.GetField( i )->SetParent( m_cmp );
661 
662  defined.insert( copy.GetField( i )->GetName() );
663  m_fields->push_back( *copy.GetField( i ) );
664  }
665 
666  // Add in any template fieldnames not yet defined:
667  for( TEMPLATE_FIELDNAME templateFieldname : GetParent()->GetTemplateFieldNames() )
668  {
669  if( defined.count( templateFieldname.m_Name ) <= 0 )
670  {
671  SCH_FIELD field( wxPoint( 0, 0 ), -1, m_cmp, templateFieldname.m_Name );
672  field.SetVisible( templateFieldname.m_Visible );
673  m_fields->push_back( field );
674  }
675  }
676 
677  wxGridTableMessage refresh( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
678  m_grid->ProcessTableMessage( refresh );
679 }
680 
681 
683 {
684  m_width = aWidth;
685  // Account for scroll bars
686  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
687 
688  m_grid->AutoSizeColumn( 0 );
689 
690  int fixedColsWidth = m_grid->GetColSize( 0 );
691 
692  for( int i = 2; i < m_grid->GetNumberCols(); i++ )
693  fixedColsWidth += m_grid->GetColSize( i );
694 
695  m_grid->SetColSize( 1, aWidth - fixedColsWidth );
696 }
697 
698 
700 {
701  wxString shownColumns = m_grid->GetShownColumns();
702 
703  if( shownColumns != m_shownColumns )
704  {
705  m_shownColumns = shownColumns;
706 
707  if( !m_grid->IsCellEditControlShown() )
708  AdjustGridColumns( m_grid->GetRect().GetWidth() );
709  }
710 
711  // Handle a delayed focus
712  if( m_delayedFocusRow >= 0 )
713  {
714  m_grid->SetFocus();
715  m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
716  m_grid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
717 
718 
719  m_grid->EnableCellEditControl( true );
720  m_grid->ShowCellEditControl();
721 
722  m_delayedFocusRow = -1;
724  }
725 }
726 
727 
729 {
730  auto new_size = event.GetSize().GetX();
731 
732  if( m_width != new_size )
733  {
734  AdjustGridColumns( new_size );
735  }
736 
737  // Always propagate for a grid repaint (needed if the height changes, as well as width)
738  event.Skip();
739 }
740 
741 
742 void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnInitDlg( wxInitDialogEvent& event )
743 {
745 
746  // Now all widgets have the size fixed, call FinishDialogSettings
748 }
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false)
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet.
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC(SCH_EDIT_FRAME *aParent, SCH_COMPONENT *aComponent)
static void UpdatePins(const EE_COLLECTOR &aComponents)
Update the pin cache for all components in aComponents.
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
int GetUnitCount() const
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:223
void UpdateFieldsFromLibrary(wxCommandEvent &event) override
Part library alias object definition.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
name of datasheet
int GetOrientation()
Get the display symbol orientation.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:258
void OnMoveDown(wxCommandEvent &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:119
void OnAddField(wxCommandEvent &event) override
SCH_COMPONENT * GetComp() const
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
void OnEditSpiceModel(wxCommandEvent &event) override
void OnInitDlg(wxInitDialogEvent &event) override
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int GetUnitCount() const
Return the number of units per package of the symbol.
void SetVisible(bool aVisible)
Definition: eda_text.h:169
void OnCancelButtonClick(wxCommandEvent &event) override
std::vector< COMPONENT_SELECTION > HISTORY_LIST
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
Schematic editor (Eeschema) main window.
LIB_PART * GetLibPart(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
void SetUnitSelection(SCH_SHEET_PATH *aSheet, int aUnitSelection)
int GetUnit() const
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:57
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool IsDragging() const
Definition: base_struct.h:218
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:51
Class SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierar...
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
void SetConvert(int aConvert)
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:88
wxString GetRef() const
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
#define VALUE
void SetLibId(const LIB_ID &aName, PART_LIBS *aLibs=NULL)
int GetUnit() const
void OnBrowseLibrary(wxCommandEvent &event) override
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:252
void SetFields(const SCH_FIELDS &aFields)
Set multiple schematic fields.
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:112
COMPONENT_SELECTION SelectCompFromLibTree(const SCHLIB_FILTER *aFilter, std::vector< COMPONENT_SELECTION > &aHistoryList, bool aUseLibBrowser, int aUnit, int aConvert, bool aShowFootprints, const LIB_ID *aHighlight=nullptr, bool aAllowFields=true)
Function SelectComponentFromLib Calls the library viewer to select component to import into schematic...
Definition: getpart.cpp:94
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:212
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:256
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
Definitions of control validators for schematic dialogs.
SCH_SHEET_PATH & GetCurrentSheet()
const LIB_ID & GetLibId() const
#define SymbolFieldsShownColumnsKey
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
Define a library symbol object.
void OnDeleteField(wxCommandEvent &event) override
timestamp_t GetTimeStamp() const
Definition: base_struct.h:203
unsigned STATUS_FLAGS
Definition: base_struct.h:143
void SetUnit(int aUnit)
Change the unit number to aUnit.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
#define _(s)
int GetFieldCount() const
Return the number of fields in this symbol.
int InvokeDialogUpdateFields(SCH_EDIT_FRAME *aCaller, const list< SCH_COMPONENT * > aComponents, bool aCreateUndoEntry)
UTF8 Format() const
Definition: lib_id.cpp:237
Class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_BASE.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:101
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void EndQuasiModal(int retCode)
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:205
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define max(a, b)
Definition: auxiliary.h:86
void RefreshItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
LIB_PART * GetLibPart() const
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:371
size_t i
Definition: json11.cpp:597
void SetName(const wxString &aName)
Definition: sch_field.h:101
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
wxPoint GetPosition() const override
Function GetPosition.
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:253
int GetConvert() const
#define DBG(x)
Definition: fctsys.h:33
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames() const
Return a template field names list for read only access.
Definition for part library class.
static bool IsReferenceStringValid(const wxString &aReferenceString)
Tests for an acceptable reference string.
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
unsigned GetCount()
Function GetCount.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:254
const LIB_ID & GetLibId() const
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:243
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
void OnUpdateUI(wxUpdateUIEvent &event) override
Class SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...