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 = m_cmp->GetPartRef().get();
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
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( const 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  m_rbMirror->SetSelection( 1 );
205  else if( mirror == CMP_MIRROR_Y )
206  m_rbMirror->SetSelection( 2 );
207  else
208  m_rbMirror->SetSelection( 0 );
209 
210  // Set the component's unique ID time stamp.
211  m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ),
212  (unsigned long) m_cmp->GetTimeStamp() ) );
213 
214  // Set the component's library name.
215  m_libraryNameTextCtrl->SetValue( m_cmp->GetLibId().Format() );
216 
217  Layout();
218 
219  return true;
220 }
221 
222 
224 {
226 
227  LIB_ID id;
228  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
229 
230  auto sel = GetParent()->SelectCompFromLibTree( nullptr, dummy, true, 0, 0, false, &id );
231 
232  if( !sel.LibId.IsValid() )
233  return;
234 
235  m_libraryNameTextCtrl->SetValue( sel.LibId.Format() );
236 
237  LIB_PART* entry = GetParent()->GetLibPart( sel.LibId );
238 
239  if( entry )
240  {
241  // Update the value field for Power symbols
242  if( entry->IsPower() )
243  m_grid->SetCellValue( VALUE, FDC_VALUE, sel.LibId.GetLibItemName() );
244 
245  // Update the units control
246  int unit = m_unitChoice->GetSelection();
247  m_unitChoice->Clear();
248 
249  if( entry->GetUnitCount() > 1 )
250  {
251  for( int ii = 1; ii <= entry->GetUnitCount(); ii++ )
252  m_unitChoice->Append( LIB_PART::SubReference( ii, false ) );
253 
254  if( unit < 0 || static_cast<unsigned>( unit ) >= m_unitChoice->GetCount() )
255  unit = 0;
256 
257  m_unitChoice->SetSelection( unit );
258  m_unitLabel->Enable( true );
259  m_unitChoice->Enable( true );
260  }
261  else
262  {
263  m_unitChoice->SetSelection( -1 );
264  m_unitLabel->Enable( false );
265  m_unitChoice->Enable( false );
266  }
267 
268  // Update the deMorgan conversion controls
269  bool conversion = m_cbAlternateSymbol->GetValue();
270 
271  m_cbAlternateSymbol->SetValue( conversion && entry->HasConversion() );
272  m_cbAlternateSymbol->Enable( entry->HasConversion() );
273  }
274 }
275 
276 
278 {
279 #ifdef KICAD_SPICE
280  int diff = m_fields->size();
281 
282  DIALOG_SPICE_MODEL dialog( this, *m_cmp, m_fields );
283 
284  if( dialog.ShowModal() != wxID_OK )
285  return;
286 
287  diff = m_fields->size() - diff;
288 
289  if( diff > 0 )
290  {
291  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
292  m_grid->ProcessTableMessage( msg );
293  }
294  else if( diff < 0 )
295  {
296  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, diff );
297  m_grid->ProcessTableMessage( msg );
298  }
299 
300  m_grid->ForceRefresh();
301 #endif /* KICAD_SPICE */
302 }
303 
304 
306 {
307  // Running the Footprint Browser gums up the works and causes the automatic cancel
308  // stuff to no longer work. So we do it here ourselves.
309  EndQuasiModal( wxID_CANCEL );
310 }
311 
312 
314 {
315  wxString msg;
316  LIB_ID id;
317 
318  if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
319  return false;
320 
321  if( !SCH_COMPONENT::IsReferenceStringValid( m_fields->at( REFERENCE ).GetText() ) )
322  {
323  DisplayErrorMessage( this, _( "References must start with a letter." ) );
324 
327 
328  return false;
329  }
330 
331  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
332 
333  if( !id.IsValid() )
334  {
335  DisplayErrorMessage( this, _( "Library reference is not valid." ) );
336 
337  m_libraryNameTextCtrl->SetFocus();
338 
339  return false;
340  }
341  else if( id != m_cmp->GetLibId() )
342  {
343  LIB_PART* alias = nullptr;
344 
345  try
346  {
347  alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
348  }
349  catch( ... )
350  {
351  }
352 
353  if( !alias )
354  {
355  msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"." ),
356  id.GetLibItemName().wx_str(),
357  id.GetLibNickname().wx_str() );
358  DisplayErrorMessage( this, msg );
359 
360  m_libraryNameTextCtrl->SetFocus();
361 
362  return false;
363  }
364  }
365  m_libraryNameTextCtrl->SetValue( id.Format() );
366 
367  // Check for missing field names.
368  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
369  {
370  SCH_FIELD& field = m_fields->at( i );
371  wxString fieldName = field.GetName( false );
372 
373  if( fieldName.IsEmpty() )
374  {
375  DisplayErrorMessage( this, _( "Fields must have a name." ) );
376 
378  m_delayedFocusRow = i;
379 
380  return false;
381  }
382  }
383 
384  return true;
385 }
386 
387 
389 {
390  if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
391  return false;
392 
393  // save old cmp in undo list if not already in edit, or moving ...
394  if( m_cmp->GetEditFlags() == 0 )
396 
397  // Save current flags which could be modified by next change settings
398  STATUS_FLAGS flags = m_cmp->GetFlags();
399 
400  // Library symbol identifier
401  LIB_ID id;
402  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true );
403  m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
404 
405  // For symbols with multiple shapes (De Morgan representation) Set the selected shape:
406  if( m_cbAlternateSymbol->IsEnabled() && m_cbAlternateSymbol->GetValue() )
407  m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::DEMORGAN );
408  else
409  m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::BASE );
410 
411  //Set the part selection in multiple part per package
412  int unit_selection = m_unitChoice->IsEnabled()
413  ? m_unitChoice->GetSelection() + 1
414  : 1;
415  m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
416  m_cmp->SetUnit( unit_selection );
417 
418  switch( m_rbOrientation->GetSelection() )
419  {
420  case 0: m_cmp->SetOrientation( CMP_ORIENT_0 ); break;
421  case 1: m_cmp->SetOrientation( CMP_ORIENT_90 ); break;
422  case 2: m_cmp->SetOrientation( CMP_ORIENT_180 ); break;
423  case 3: m_cmp->SetOrientation( CMP_ORIENT_270 ); break;
424  }
425 
426  switch( m_rbMirror->GetSelection() )
427  {
428  case 0: break;
429  case 1: m_cmp->SetOrientation( CMP_MIRROR_X ); break;
430  case 2: m_cmp->SetOrientation( CMP_MIRROR_Y ); break;
431  }
432 
433  // Restore m_Flag modified by SetUnit() and other change settings
434  m_cmp->ClearFlags();
435  m_cmp->SetFlags( flags );
436 
437  // change all field positions from relative to absolute
438  for( unsigned i = 0; i < m_fields->size(); ++i )
439  m_fields->at( i ).Offset( m_cmp->GetPosition() );
440 
441  LIB_PART* entry = GetParent()->GetLibPart( m_cmp->GetLibId() );
442 
443  if( entry && entry->IsPower() )
444  m_fields->at( VALUE ).SetText( m_cmp->GetLibId().GetLibItemName() );
445 
446  // Remove any TEMPLATE_FIELDNAMES which were not set (given values).
447  TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames();
448 
449  for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
450  {
451  SCH_FIELD& field = m_fields->at( i );
452 
453  for( const auto& fieldname : templateFieldnames )
454  {
455  if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() )
456  {
457  m_fields->erase( m_fields->begin() + i );
458 
459  // grid needs to be notified about the size change,
460  // as it still accesses the data on close (size event)
461  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, i, 1 );
462  m_grid->ProcessTableMessage( msg );
463  i--;
464  break;
465  }
466  }
467  }
468 
469  m_cmp->SetFields( *m_fields );
470 
471  // Reference has a specific initialization, depending on the current active sheet
472  // because for a given component, in a complex hierarchy, there are more than one
473  // reference.
474  m_cmp->SetRef( &GetParent()->GetCurrentSheet(), m_fields->at( REFERENCE ).GetText() );
475 
476  // The value, footprint and datasheet fields should be kept in sync in multi-unit
477  // parts.
478  if( m_cmp->GetUnitCount() > 1 )
479  {
480  const LIB_ID thisLibId = m_cmp->GetLibId();
481  const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) );
482  int thisUnit = m_cmp->GetUnit();
483 
484  SCH_REFERENCE_LIST components;
485  GetParent()->GetCurrentSheet().GetComponents( components );
486 
487  for( unsigned i = 0; i < components.GetCount(); i++ )
488  {
489  SCH_REFERENCE component = components[i];
490 
491  if( component.GetLibPart()->GetLibId() == thisLibId
492  && component.GetRef() == thisRef
493  && component.GetUnit() != thisUnit )
494  {
495  SCH_COMPONENT* otherUnit = component.GetComp();
496  GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
497  otherUnit->GetField( VALUE )->SetText( m_fields->at( VALUE ).GetText() );
498  otherUnit->GetField( FOOTPRINT )->SetText( m_fields->at( FOOTPRINT ).GetText() );
499  otherUnit->GetField( DATASHEET )->SetText( m_fields->at( DATASHEET ).GetText() );
500  }
501  }
502  }
503 
504  m_cmp->UpdatePins();
505 
508  GetParent()->OnModify();
509 
510  return true;
511 }
512 
513 
515 {
516  wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
517  wxControl* control = editor->GetControl();
518 
519  if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
520  {
521  event.Veto();
522  m_delayedFocusRow = event.GetRow();
523  m_delayedFocusColumn = event.GetCol();
524  }
525 
526  editor->DecRef();
527 }
528 
529 
531 {
532  if( !m_grid->CommitPendingChanges() )
533  return;
534 
535  int fieldID = m_fields->size();
536  SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_cmp );
537 
538  newField.SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID ) );
539  newField.SetTextAngle( m_fields->at( REFERENCE ).GetTextAngle() );
540 
541  m_fields->push_back( newField );
542 
543  // notify the grid
544  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
545  m_grid->ProcessTableMessage( msg );
546 
547  m_grid->MakeCellVisible( m_fields->size() - 1, 0 );
548  m_grid->SetGridCursor( m_fields->size() - 1, 0 );
549 
550  m_grid->EnableCellEditControl();
551  m_grid->ShowCellEditControl();
552 }
553 
554 
556 {
557  int curRow = m_grid->GetGridCursorRow();
558 
559  if( curRow < 0 )
560  return;
561  else if( curRow < MANDATORY_FIELDS )
562  {
563  DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
564  MANDATORY_FIELDS ) );
565  return;
566  }
567 
568  m_grid->CommitPendingChanges( true /* quiet mode */ );
569 
570  m_fields->erase( m_fields->begin() + curRow );
571 
572  // notify the grid
573  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
574  m_grid->ProcessTableMessage( msg );
575 
576  if( m_grid->GetNumberRows() > 0 )
577  {
578  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
579  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
580  }
581 }
582 
583 
584 void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnMoveUp( wxCommandEvent& event )
585 {
586  if( !m_grid->CommitPendingChanges() )
587  return;
588 
589  int i = m_grid->GetGridCursorRow();
590 
591  if( i > MANDATORY_FIELDS )
592  {
593  SCH_FIELD tmp = m_fields->at( (unsigned) i );
594  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
595  m_fields->insert( m_fields->begin() + i - 1, tmp );
596  m_grid->ForceRefresh();
597 
598  m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
599  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
600  }
601  else
602  wxBell();
603 }
604 
605 
607 {
608  if( !m_grid->CommitPendingChanges() )
609  return;
610 
611  int i = m_grid->GetGridCursorRow();
612 
613  if( i >= MANDATORY_FIELDS && i < m_grid->GetNumberRows() - 1 )
614  {
615  SCH_FIELD tmp = m_fields->at( (unsigned) i );
616  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
617  m_fields->insert( m_fields->begin() + i + 1, tmp );
618  m_grid->ForceRefresh();
619 
620  m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
621  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
622  }
623  else
624  wxBell();
625 }
626 
627 
629 {
630  if( !m_grid->CommitPendingChanges() )
631  return;
632 
633  SCH_COMPONENT copy( *m_cmp );
634  copy.SetFields( *m_fields );
635 
636  LIB_ID id;
637  id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true );
638  copy.SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
639 
640  // Update the requested fields in the component copy
641  std::list<SCH_COMPONENT*> components;
642  components.push_back( &copy );
643  InvokeDialogUpdateFields( GetParent(), components, false );
644 
645  wxGridTableMessage clear( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_fields->size() );
646  m_grid->ProcessTableMessage( clear );
647 
648  // Copy fields from the component copy to the dialog buffer
649  m_fields->clear();
650  std::set<wxString> defined;
651 
652  for( int i = 0; i < copy.GetFieldCount(); ++i )
653  {
654  copy.GetField( i )->SetParent( m_cmp );
655 
656  defined.insert( copy.GetField( i )->GetName() );
657  m_fields->push_back( *copy.GetField( i ) );
658  }
659 
660  // Add in any template fieldnames not yet defined:
661  for( const TEMPLATE_FIELDNAME& templateFieldname : GetParent()->GetTemplateFieldNames() )
662  {
663  if( defined.count( templateFieldname.m_Name ) <= 0 )
664  {
665  SCH_FIELD field( wxPoint( 0, 0 ), -1, m_cmp, templateFieldname.m_Name );
666  field.SetVisible( templateFieldname.m_Visible );
667  m_fields->push_back( field );
668  }
669  }
670 
671  wxGridTableMessage refresh( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
672  m_grid->ProcessTableMessage( refresh );
673 }
674 
675 
677 {
678  m_width = aWidth;
679  // Account for scroll bars
680  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
681 
682  m_grid->AutoSizeColumn( 0 );
683 
684  int fixedColsWidth = m_grid->GetColSize( 0 );
685 
686  for( int i = 2; i < m_grid->GetNumberCols(); i++ )
687  fixedColsWidth += m_grid->GetColSize( i );
688 
689  m_grid->SetColSize( 1, aWidth - fixedColsWidth );
690 }
691 
692 
694 {
695  wxString shownColumns = m_grid->GetShownColumns();
696 
697  if( shownColumns != m_shownColumns )
698  {
699  m_shownColumns = shownColumns;
700 
701  if( !m_grid->IsCellEditControlShown() )
702  AdjustGridColumns( m_grid->GetRect().GetWidth() );
703  }
704 
705  // Handle a delayed focus
706  if( m_delayedFocusRow >= 0 )
707  {
708  m_grid->SetFocus();
709  m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
710  m_grid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
711 
712 
713  m_grid->EnableCellEditControl( true );
714  m_grid->ShowCellEditControl();
715 
716  m_delayedFocusRow = -1;
718  }
719 }
720 
721 
723 {
724  auto new_size = event.GetSize().GetX();
725 
726  if( m_width != new_size )
727  {
728  AdjustGridColumns( new_size );
729  }
730 
731  // Always propagate for a grid repaint (needed if the height changes, as well as width)
732  event.Skip();
733 }
734 
735 
736 void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnInitDlg( wxInitDialogEvent& event )
737 {
739 
740  // Now all widgets have the size fixed, call FinishDialogSettings
742 }
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:236
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:249
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)
Load symbol from symbol library table.
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:221
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: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:255
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:216
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:260
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 UpdatePins(SCH_SHEET_PATH *aSheet=nullptr)
Updates the local cache of SCH_PIN_CONNECTION objects for each pin.
#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:213
unsigned STATUS_FLAGS
Definition: base_struct.h:156
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
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
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
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.
void RefreshItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
#define _(s)
Definition: 3d_actions.cpp:31
LIB_PART * GetLibPart() const
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:371
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:89
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:256
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...
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:257
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.
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...