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