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-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
25 #include <wx/tooltip.h>
26 #include <wx/hyperlink.h>
27 #include <wx/url.h>
28 
29 #include <fctsys.h>
30 #include <pgm_base.h>
31 #include <kiway.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <sch_edit_frame.h>
35 #include <base_units.h>
36 
37 #include <sch_reference_list.h>
38 #include <class_library.h>
39 #include <sch_component.h>
40 #include <dialog_helpers.h>
41 #include <sch_validators.h>
42 #include <kicad_device_context.h>
43 #include <symbol_lib_table.h>
44 
45 #include <bitmaps.h>
46 
48 #include <invoke_sch_dialog.h>
49 
50 #ifdef KICAD_SPICE
51 #include <dialog_spice_model.h>
53 #endif /* KICAD_SPICE */
54 
55 #include "common.h"
56 #include "eda_doc.h"
57 #include <list>
58 
59 
67 {
68 public:
70 
76  void InitBuffers( SCH_COMPONENT* aComponent );
77 
78  SCH_EDIT_FRAME* GetParent() { return dynamic_cast< SCH_EDIT_FRAME* >( wxDialog::GetParent() ); }
79 
80 private:
81 
82  friend class SCH_EDIT_FRAME;
83 
87 
88  static int s_SelectedRow;
89 
92 
93  void setSelectedFieldNdx( int aFieldNdx );
94 
95  int getSelectedFieldNdx();
96 
101 
109 
110  void copyOptionsToPanel();
111 
112  void copyPanelToOptions();
113 
114  void setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue );
115 
116  void setRowItem( int aFieldNdx, const SCH_FIELD& aField )
117  {
118  // Use default field name for mandatory fields, because they are transalted
119  // according to the current locale
120  wxString f_name;
121 
122  if( aFieldNdx < MANDATORY_FIELDS )
123  f_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldNdx );
124  else
125  f_name = aField.GetName( false );
126 
127  setRowItem( aFieldNdx, f_name, aField.GetText() );
128  }
129 
130  // event handlers
131  void OnCloseDialog( wxCloseEvent& event ) override;
132  void OnListItemDeselected( wxListEvent& event ) override;
133  void OnListItemSelected( wxListEvent& event ) override;
134  void OnCancelButtonClick( wxCommandEvent& event ) override;
135  void OnOKButtonClick( wxCommandEvent& event ) override;
136  void SetInitCmp( wxCommandEvent& event ) override;
137  void UpdateFields( wxCommandEvent& event ) override;
138  void addFieldButtonHandler( wxCommandEvent& event ) override;
139  void deleteFieldButtonHandler( wxCommandEvent& event ) override;
140  void moveUpButtonHandler( wxCommandEvent& event ) override;
141  void moveDownButtonHandler( wxCommandEvent& event ) override;
142  void showButtonHandler( wxCommandEvent& event ) override;
143  void OnTestChipName( wxCommandEvent& event ) override;
144  void OnSelectChipName( wxCommandEvent& event ) override;
145  void OnInitDlg( wxInitDialogEvent& event ) override
146  {
147  TransferDataToWindow();
148 
149  // Now all widgets have the size fixed, call FinishDialogSettings
151  }
152 
153  void EditSpiceModel( wxCommandEvent& event ) override;
154 
155  SCH_FIELD* findField( const wxString& aFieldName );
156 
163  {
164  fieldListCtrl->DeleteAllItems();
165 
166  for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ )
167  setRowItem( ii, m_FieldsBuf[ii] );
168  }
169 };
170 
171 
173 
174 
176 {
177  wxCHECK_RET( aComponent != NULL && aComponent->Type() == SCH_COMPONENT_T,
178  wxT( "Invalid component object pointer. Bad Programmer!" ) );
179 
181 
183 
184  dlg->InitBuffers( aComponent );
185 
186  // make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
188 
189  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
190  // frame. Therefore this dialog as a modal frame parent, MUST be run under
191  // quasimodal mode for the quasimodal frame support to work. So don't use
192  // the QUASIMODAL macros here.
193  int ret = dlg->ShowQuasiModal();
194 
195  if( m_autoplaceFields )
196  aComponent->AutoAutoplaceFields( GetScreen() );
197 
198  m_canvas->SetIgnoreMouseEvents( false );
200  dlg->Destroy();
201 
202  if( ret == wxID_OK )
203  GetCanvas()->Refresh();
204 }
205 
206 
209 {
210 #ifndef KICAD_SPICE
211  spiceFieldsButton->Hide();
212 #endif /* not KICAD_SPICE */
213 
214  m_cmp = NULL;
215  m_part = NULL;
216  m_skipCopyFromPanel = false;
217 
218  wxListItem columnLabel;
219 
220  columnLabel.SetImage( -1 );
221 
222  columnLabel.SetText( _( "Name" ) );
223  fieldListCtrl->InsertColumn( 0, columnLabel );
224 
225  columnLabel.SetText( _( "Value" ) );
226  fieldListCtrl->InsertColumn( 1, columnLabel );
227 
231 
232  wxToolTip::Enable( true );
233  stdDialogButtonSizerOK->SetDefault();
234 
235  // Configure button logos
236  addFieldButton->SetBitmap( KiBitmap( plus_xpm ) );
237  deleteFieldButton->SetBitmap( KiBitmap( minus_xpm ) );
238  moveUpButton->SetBitmap( KiBitmap( go_up_xpm ) );
239  moveDownButton->SetBitmap( KiBitmap( go_down_xpm ) );
240 
241  Fit();
242 }
243 
244 
246 {
247  if( !m_skipCopyFromPanel )
248  {
249  if( !copyPanelToSelectedField() )
250  event.Skip(); // do not go to the next row
251  }
252 }
253 
255 {
256  LIB_ID id;
257  wxString msg;
258  wxString partname = chipnameTextCtrl->GetValue();
259 
260  if( id.Parse( partname ) != -1 || !id.IsValid() )
261  {
262  msg.Printf( _( "\"%s\" is not a valid library symbol indentifier." ), partname );
263  DisplayError( this, msg );
264  return;
265  }
266 
267  LIB_ALIAS* alias = NULL;
268 
269  try
270  {
271  alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
272  }
273  catch( ... )
274  {
275  }
276 
277  if( !alias )
278  {
279  msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"" ),
280  id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
281  DisplayError( this, msg );
282  return;
283  }
284 
285  msg.Printf( _( "Symbol \"%s\" found in library \"%s\"" ),
286  id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
287 
288  DisplayInfoMessage( this, msg );
289 }
290 
291 
293 {
295 
296  auto sel = GetParent()->SelectComponentFromLibrary( NULL, dummy, true, 0, 0, false );
297 
298  if( !sel.LibId.IsValid() )
299  return;
300 
301  chipnameTextCtrl->SetValue( sel.LibId.Format() );
302 }
303 
304 
306 {
307 #ifdef KICAD_SPICE
308  setSelectedFieldNdx( 0 );
309  DIALOG_SPICE_MODEL dialog( this, *m_cmp, m_FieldsBuf );
310 
311  if( dialog.ShowModal() == wxID_OK )
312  updateDisplay();
313 #endif /* KICAD_SPICE */
314 }
315 
316 
318 {
319  // remember the selected row, statically
320  s_SelectedRow = event.GetIndex();
321 
323 }
324 
325 
327 {
328  // On wxWidgets 2.8, and on Linux, calling EndQuasiModal here is mandatory
329  // Otherwise, the main event loop is never restored, and Eeschema does not
330  // respond to any event, because the DIALOG_SHIM destructor is never called.
331  // On wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
332  // and calls EndQuasiModal.
333  // therefore calling EndQuasiModal here is not always mandatory but it creates no issues
334  EndQuasiModal( wxID_CANCEL );
335 }
336 
337 
339 {
340  EndQuasiModal( wxID_CANCEL );
341 }
342 
343 
345 {
346  LIB_ID id;
347  wxString msg;
348  wxString tmp = chipnameTextCtrl->GetValue();
349 
350  tmp.Replace( wxT( " " ), wxT( "_" ) );
351 
352  id.Parse( tmp );
353 
354  // Save current flags which could be modified by next change settings
355  STATUS_FLAGS flags = m_cmp->GetFlags();
356 
357  if( !id.IsValid() )
358  {
359  msg.Printf( _( "Symbol library identifier \"%s\" is not valid!" ), tmp );
360  DisplayError( this, msg );
361  }
362  else if( id != m_cmp->GetLibId() )
363  {
364  LIB_ALIAS* alias = NULL;
365 
366  try
367  {
368  alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
369  }
370  catch( ... )
371  {
372  }
373 
374  if( !alias )
375  {
376  msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"!" ),
377  id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
378  DisplayError( this, msg );
379  }
380  else // Change symbol from lib!
381  {
382  m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
383  }
384  }
385 
386  // For symbols with multiple shapes (De Morgan representation) Set the selected shape:
387  if( convertCheckBox->IsEnabled() )
388  {
389  m_cmp->SetConvert( convertCheckBox->GetValue() ? 2 : 1 );
390  }
391 
392  //Set the part selection in multiple part per package
393  if( m_cmp->GetUnit() )
394  {
395  int unit_selection = unitChoice->GetCurrentSelection() + 1;
396 
397  m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
398  m_cmp->SetUnit( unit_selection );
399  }
400 
401  switch( orientationRadioBox->GetSelection() )
402  {
403  case 0:
405  break;
406 
407  case 1:
409  break;
410 
411  case 2:
413  break;
414 
415  case 3:
417  break;
418  }
419 
420  int mirror = mirrorRadioBox->GetSelection();
421 
422  switch( mirror )
423  {
424  case 0:
425  break;
426 
427  case 1:
429  break;
430 
431  case 2:
433  break;
434  }
435 
436  // Restore m_Flag modified by SetUnit() and other change settings
437  m_cmp->ClearFlags();
438  m_cmp->SetFlags( flags );
439 }
440 
441 
443 {
444  bool removeRemainingFields = false;
445 
446  if( !copyPanelToSelectedField() )
447  return;
448 
450  {
451  DisplayError( NULL, _( "Illegal reference. A reference must start with a letter" ) );
452  return;
453  }
454 
455  // save old cmp in undo list if not already in edit, or moving ...
456  // or the component to be edited is part of a block
457  if( m_cmp->GetFlags() == 0
460 
462 
463  // Delete any fields with no name before we copy all of m_FieldsBuf back into the component.
464  for( unsigned i = MANDATORY_FIELDS; i<m_FieldsBuf.size(); )
465  {
466  if( m_FieldsBuf[i].GetName( false ).IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() )
467  {
468  // If a field has no value and is not it the field template list, warn the user
469  // that it will be remove from the component. This gives the user a chance to
470  // correct the problem before removing the undefined fields. It should also
471  // resolve most of the bug reports and questions regarding missing fields.
472  if( !m_FieldsBuf[i].GetName( false ).IsEmpty() && m_FieldsBuf[i].GetText().IsEmpty()
473  && !GetParent()->GetTemplates().HasFieldName( m_FieldsBuf[i].GetName( false ) )
474  && !removeRemainingFields )
475  {
476  wxString msg = wxString::Format(
477  _( "The field name \"%s\" does not have a value and is not defined in "
478  "the field template list. Empty field values are invalid an will "
479  "be removed from the component. Do you wish to remove this and "
480  "all remaining undefined fields?" ),
481  GetChars( m_FieldsBuf[i].GetName( false ) )
482  );
483 
484  wxMessageDialog dlg( this, msg, _( "Remove Fields" ), wxYES_NO | wxNO_DEFAULT );
485 
486  if( dlg.ShowModal() == wxID_NO )
487  return;
488 
489  removeRemainingFields = true;
490  }
491 
492  m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
493  continue;
494  }
495 
496  ++i;
497  }
498 
499  // change all field positions from relative to absolute
500  for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
501  {
502  m_FieldsBuf[i].Offset( m_cmp->m_Pos );
503  }
504 
505  LIB_PART* entry = GetParent()->GetLibPart( m_cmp->GetLibId() );
506 
507  if( entry && entry->IsPower() )
508  m_FieldsBuf[VALUE].SetText( m_cmp->GetLibId().GetLibItemName() );
509 
510  // copy all the fields back, and change the length of m_Fields.
512 
513  // Reference has a specific initialization, depending on the current active sheet
514  // because for a given component, in a complex hierarchy, there are more than one
515  // reference.
517 
518  // The value, footprint and datasheet fields should be kept in sync in multi-unit
519  // parts.
520  if( m_cmp->GetUnitCount() > 1 )
521  {
522  const LIB_ID thisLibId = m_cmp->GetLibId();
523  const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) );
524  int thisUnit = m_cmp->GetUnit();
525 
526  SCH_REFERENCE_LIST components;
527  GetParent()->GetCurrentSheet().GetComponents( components );
528  for( unsigned i = 0; i < components.GetCount(); i++ )
529  {
530  SCH_REFERENCE component = components[i];
531  if( component.GetLibPart()->GetLibId() == thisLibId
532  && component.GetRef() == thisRef
533  && component.GetUnit() != thisUnit )
534  {
535  SCH_COMPONENT* otherUnit = component.GetComp();
536  GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
537  otherUnit->GetField( VALUE )->SetText( m_FieldsBuf[VALUE].GetText() );
538  otherUnit->GetField( FOOTPRINT )->SetText( m_FieldsBuf[FOOTPRINT].GetText() );
539  otherUnit->GetField( DATASHEET )->SetText( m_FieldsBuf[DATASHEET].GetText() );
540  }
541  }
542  }
543 
544  GetParent()->OnModify();
546 
547  EndQuasiModal( wxID_OK );
548 }
549 
550 
552 {
553  // in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
554  // screen contents.
555  if( !copyPanelToSelectedField() )
556  return;
557 
558  unsigned fieldNdx = m_FieldsBuf.size();
559 
560  SCH_FIELD blank( wxPoint(), fieldNdx, m_cmp );
561 
562  blank.SetTextAngle( m_FieldsBuf[REFERENCE].GetTextAngle() );
563 
564  m_FieldsBuf.push_back( blank );
565  m_FieldsBuf[fieldNdx].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx ) );
566 
567  m_skipCopyFromPanel = true;
568  setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
569 
570  setSelectedFieldNdx( fieldNdx );
571  m_skipCopyFromPanel = false;
572 }
573 
574 
576 {
577  unsigned fieldNdx = getSelectedFieldNdx();
578 
579  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
580  return;
581 
582  if( fieldNdx < MANDATORY_FIELDS )
583  {
584  wxBell();
585  return;
586  }
587 
588  m_skipCopyFromPanel = true;
589  m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
590  fieldListCtrl->DeleteItem( fieldNdx );
591 
592  if( fieldNdx >= m_FieldsBuf.size() )
593  --fieldNdx;
594 
595  updateDisplay();
596 
597  setSelectedFieldNdx( fieldNdx );
598  m_skipCopyFromPanel = false;
599 }
600 
601 static wxString resolveUriByEnvVars( const wxString& aUri )
602 {
603  // URL-like URI: return as is.
604  wxURL url( aUri );
605  if( url.GetError() == wxURL_NOERR )
606  {
607  return aUri;
608  }
609  // Otherwise, the path points to a local file. Resolve environment
610  // variables if any.
611  return ExpandEnvVarSubstitutions( aUri );
612 }
613 
615 {
616  unsigned fieldNdx = getSelectedFieldNdx();
617 
618  if( fieldNdx == DATASHEET )
619  {
620  wxString datasheet_uri = fieldValueTextCtrl->GetValue();
621  datasheet_uri = resolveUriByEnvVars( datasheet_uri );
622  GetAssociatedDocument( this, datasheet_uri );
623  }
624  else if( fieldNdx == FOOTPRINT )
625  {
626  // pick a footprint using the footprint picker.
627  wxString fpid;
628 
629  KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, this );
630 
631  if( frame->ShowModal( &fpid, this ) )
632  {
633  // DBG( printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); )
634  fieldValueTextCtrl->SetValue( fpid );
635 
636  setRowItem( fieldNdx, m_FieldsBuf[fieldNdx].GetName( false ), fpid );
637  }
638 
639  frame->Destroy();
640  }
641 }
642 
643 
645 {
646  unsigned fieldNdx = getSelectedFieldNdx();
647 
648  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
649  return;
650 
651  if( fieldNdx <= MANDATORY_FIELDS )
652  {
653  wxBell();
654  return;
655  }
656 
657  if( !copyPanelToSelectedField() )
658  return;
659 
660  // swap the fieldNdx field with the one before it, in both the vector
661  // and in the fieldListCtrl
662  SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1];
663 
664  DBG( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n",
665  TO_UTF8( tmp.GetText() ), TO_UTF8( tmp.GetName( false ) ) ); )
666 
667  m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx];
668  setRowItem( fieldNdx - 1, m_FieldsBuf[fieldNdx] );
669 
670  m_FieldsBuf[fieldNdx] = tmp;
671  setRowItem( fieldNdx, tmp );
672 
673  updateDisplay();
674 
675  m_skipCopyFromPanel = true;
676  setSelectedFieldNdx( fieldNdx - 1 );
677  m_skipCopyFromPanel = false;
678 }
679 
680 
682 {
683  unsigned fieldNdx = getSelectedFieldNdx();
684 
685  // Ensure there is at least one field after this one
686  if( fieldNdx >= ( m_FieldsBuf.size() - 1 ) )
687  {
688  return;
689  }
690 
691  // The first field which can be moved up is the second user field
692  // so any field which id < MANDATORY_FIELDS cannot be moved down
693  if( fieldNdx < MANDATORY_FIELDS )
694  return;
695 
696  if( !copyPanelToSelectedField() )
697  return;
698 
699  // swap the fieldNdx field with the one before it, in both the vector
700  // and in the fieldListCtrl
701  SCH_FIELD tmp = m_FieldsBuf[fieldNdx + 1];
702 
703  m_FieldsBuf[fieldNdx + 1] = m_FieldsBuf[fieldNdx];
704  setRowItem( fieldNdx + 1, m_FieldsBuf[fieldNdx] );
705  m_FieldsBuf[fieldNdx + 1].SetId( fieldNdx + 1 );
706 
707  m_FieldsBuf[fieldNdx] = tmp;
708  setRowItem( fieldNdx, tmp );
709  m_FieldsBuf[fieldNdx].SetId( fieldNdx );
710 
711  updateDisplay( );
712 
713  m_skipCopyFromPanel = true;
714  setSelectedFieldNdx( fieldNdx + 1 );
715  m_skipCopyFromPanel = false;
716 }
717 
718 
720 {
721  /* deselect old selection, but I think this is done by single selection
722  * flag within fieldListCtrl.
723  * fieldListCtrl->SetItemState( s_SelectedRow, 0,
724  * wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
725  */
726 
727  if( aFieldNdx >= (int) m_FieldsBuf.size() )
728  aFieldNdx = m_FieldsBuf.size() - 1;
729 
730  if( aFieldNdx < 0 )
731  aFieldNdx = 0;
732 
733  fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
734  fieldListCtrl->EnsureVisible( aFieldNdx );
735 
736  s_SelectedRow = aFieldNdx;
737 }
738 
739 
741 {
742  return s_SelectedRow;
743 }
744 
745 
747 {
748  for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
749  {
750  if( aFieldName == m_FieldsBuf[i].GetName( false ) )
751  return &m_FieldsBuf[i];
752  }
753 
754  return NULL;
755 }
756 
757 
759 {
760  m_cmp = aComponent;
761 
762  /* We have 3 component related field lists to be aware of: 1) UI
763  presentation, 2) fields in component ram copy, and 3) fields recorded
764  with component on disk. m_FieldsBuf is the list of UI fields, and this
765  list is not the same as the list which is in the component, which is
766  also not the same as the list on disk. All 3 lists are potentially
767  different. In the UI we choose to preserve the order of the first
768  MANDATORY_FIELDS which are sometimes called fixed fields. Then we append
769  the template fieldnames in the exact same order as the template
770  fieldname editor shows them. Then we append any user defined fieldnames
771  which came from the component.
772  */
773 
774  m_part = GetParent()->GetLibPart( m_cmp->GetLibId(), true );
775 
776 #if 0 && defined(DEBUG)
777  for( int i = 0; i<aComponent->GetFieldCount(); ++i )
778  {
779  printf( "Orig[%d] (x=%d, y=%d)\n", i,
780  aComponent->m_Fields[i].GetTextPos().x,
781  aComponent->m_Fields[i].GetTextPos().y );
782  }
783 
784 #endif
785 
786  // When this code was written, all field constructors ensure that the fixed fields
787  // are all present within a component. So we can knowingly copy them over
788  // in the normal order. Copy only the fixed fields at first.
789  // Please do not break the field constructors.
790 
791  m_FieldsBuf.clear();
792 
793  for( int i=0; i<MANDATORY_FIELDS; ++i )
794  {
795  m_FieldsBuf.push_back( aComponent->m_Fields[i] );
796 
797  // make the editable field position relative to the component
798  m_FieldsBuf[i].Offset( -m_cmp->m_Pos );
799 
800  // Ensure the Field name reflects the default name, even if the
801  // local has changed since schematic was read
803  }
804 
805  // Add template fieldnames:
806  // Now copy in the template fields, in the order that they are present in the
807  // template field editor UI.
809 
810  for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
811  {
812  // add a new field unconditionally to the UI only
813  SCH_FIELD fld( wxPoint(0,0), -1 /* id is a relic */, m_cmp, it->m_Name );
814 
815  // See if field by same name already exists in component.
816  SCH_FIELD* schField = aComponent->FindField( it->m_Name );
817 
818  // If the field does not already exist in the component, then we
819  // use defaults from the template fieldname, otherwise the original
820  // values from the component will be set.
821  if( !schField )
822  {
823  if( !it->m_Visible )
824  fld.SetVisible( false );
825  else
826  fld.SetVisible( true );
827 
828  fld.SetText( it->m_Value ); // empty? ok too.
829  }
830  else
831  {
832  fld = *schField;
833 
834  // make the editable field position relative to the component
835  fld.Offset( -m_cmp->m_Pos );
836  }
837 
838  m_FieldsBuf.push_back( fld );
839  }
840 
841  // Lastly, append any original fields from the component which were not added
842  // from the set of fixed fields nor from the set of template fields.
843  for( unsigned i=MANDATORY_FIELDS; i<aComponent->m_Fields.size(); ++i )
844  {
845  SCH_FIELD* cmp = &aComponent->m_Fields[i];
846  SCH_FIELD* buf = findField( cmp->GetName( false ) );
847 
848  if( !buf )
849  {
850  int newNdx = m_FieldsBuf.size();
851  m_FieldsBuf.push_back( *cmp );
852 
853  // make the editable field position relative to the component
854  m_FieldsBuf[newNdx].Offset( -m_cmp->m_Pos );
855  }
856  }
857 
858 
859 #if 0 && defined(DEBUG)
860  for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
861  {
862  printf( "m_FieldsBuf[%d] (x=%-3d, y=%-3d) name:%s\n", i, m_FieldsBuf[i].m_Pos.x,
863  m_FieldsBuf[i].m_Pos.y, TO_UTF8(m_FieldsBuf[i].GetName( false ) ) );
864  }
865 #endif
866 
868 
869  for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
870  {
871  setRowItem( i, m_FieldsBuf[i] );
872  }
873 
874 #if 0 && defined(DEBUG)
875  for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
876  {
877  printf( "after[%d] (x=%d, y=%d)\n", i, m_FieldsBuf[i].m_Pos.x,
878  m_FieldsBuf[i].m_Pos.y );
879  }
880 
881 #endif
882 
884 
885  // disable some options inside the edit dialog
886  // which can cause problems while dragging
887  if( m_cmp->IsDragging() )
888  {
889  orientationRadioBox->Disable();
890  mirrorRadioBox->Disable();
891  chipnameTextCtrl->Disable();
892  }
893 
894  // put focus on the list ctrl
895  fieldListCtrl->SetFocus();
896 
897  // resume editing at the last row edited, last time dialog was up.
899 
901 }
902 
903 
904 void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue )
905 {
906  wxASSERT( aFieldNdx >= 0 );
907 
908  // insert blanks if aFieldNdx is referencing a "yet to be defined" row
909  while( aFieldNdx >= fieldListCtrl->GetItemCount() )
910  {
911  long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString );
912 
913  wxASSERT( ndx >= 0 );
914 
915  fieldListCtrl->SetItem( ndx, 1, wxEmptyString );
916  }
917 
918  fieldListCtrl->SetItem( aFieldNdx, 0, aName );
919  fieldListCtrl->SetItem( aFieldNdx, 1, aValue );
920 
921  // recompute the column widths here, after setting texts
922  fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
923  fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
924 }
925 
926 
928 {
929  wxCHECK_RET( m_cmp != NULL, wxT( "Component pointer not initialized." ) );
930 
931  unsigned fieldNdx = getSelectedFieldNdx();
932 
933  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
934  return;
935 
936  SCH_FIELD& field = m_FieldsBuf[fieldNdx];
937 
938  showCheckBox->SetValue( field.IsVisible() );
939 
940  rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
941 
942  int style = 0;
943 
944  if( field.IsItalic() )
945  style = 1;
946 
947  if( field.IsBold() )
948  style |= 2;
949 
950  m_StyleRadioBox->SetSelection( style );
951 
952  // Select the right text justification
953  if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
954  m_FieldHJustifyCtrl->SetSelection( 0 );
955  else if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
956  m_FieldHJustifyCtrl->SetSelection( 2 );
957  else
958  m_FieldHJustifyCtrl->SetSelection( 1 );
959 
960  if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
961  m_FieldVJustifyCtrl->SetSelection( 0 );
962  else if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
963  m_FieldVJustifyCtrl->SetSelection( 2 );
964  else
965  m_FieldVJustifyCtrl->SetSelection( 1 );
966 
967 
968  fieldNameTextCtrl->SetValue( field.GetName( false ) );
969 
970  // the names of the fixed fields are not editable, others are.
971  fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
972  fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
973 
974  // only user defined fields may be moved, and not the top most user defined
975  // field since it would be moving up into the fixed fields, > not >=
976  moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
977  moveDownButton->Enable( ( fieldNdx >= MANDATORY_FIELDS ) && ( fieldNdx < ( m_FieldsBuf.size() - 1 ) ) );
978 
979  // may only delete user defined fields
980  deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
981 
982  fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( false, field.GetId() ) );
983  fieldValueTextCtrl->SetValue( field.GetText() );
984 
985  m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT );
986 
987  if( fieldNdx == DATASHEET )
988  {
989  m_show_datasheet_button->SetLabel( _( "Show Datasheet" ) );
990  m_show_datasheet_button->SetToolTip(
991  _("If your datasheet is given as an http:// link,"
992  " then pressing this button should bring it up in your webbrowser.") );
993  }
994  else if( fieldNdx == FOOTPRINT )
995  {
996  m_show_datasheet_button->SetLabel( _( "Browse Footprints" ) );
997  m_show_datasheet_button->SetToolTip(
998  _("Open the footprint browser to choose a footprint and assign it.") );
999  }
1000  else
1001  {
1002  m_show_datasheet_button->SetLabel( wxEmptyString );
1003  m_show_datasheet_button->SetToolTip(
1004  _("Used only for fields Footprint and Datasheet.") );
1005  }
1006 
1007  // For power symbols, the value is NOR editable, because value and pin
1008  // name must be same and can be edited only in library editor
1009  if( fieldNdx == VALUE && m_part && m_part->IsPower() )
1010  fieldValueTextCtrl->Enable( false );
1011  else
1012  fieldValueTextCtrl->Enable( true );
1013 
1015 
1016  wxPoint coord = field.GetTextPos();
1017  wxPoint zero = -m_cmp->m_Pos; // relative zero
1018 
1019  // If the field value is empty and the position is at relative zero, we
1020  // set the initial position as a small offset from the ref field, and
1021  // orient it the same as the ref field. That is likely to put it at least
1022  // close to the desired position.
1023  if( coord == zero && field.GetText().IsEmpty() )
1024  {
1025  rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].GetTextAngle() == TEXT_ANGLE_VERT );
1026 
1027  coord.x = m_FieldsBuf[REFERENCE].GetTextPos().x
1028  + ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
1029 
1030  coord.y = m_FieldsBuf[REFERENCE].GetTextPos().y
1031  + ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
1032 
1033  // coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
1034  // That is ok, we basically don't want all the new empty fields on
1035  // top of each other.
1036  }
1037 
1038  wxString coordText = StringFromValue( g_UserUnit, coord.x );
1039  posXTextCtrl->SetValue( coordText );
1040 
1041  coordText = StringFromValue( g_UserUnit, coord.y );
1042  posYTextCtrl->SetValue( coordText );
1043 }
1044 
1045 
1047 {
1048  unsigned fieldNdx = getSelectedFieldNdx();
1049 
1050  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
1051  return true;
1052 
1053  // Check for illegal field text.
1054  if( fieldValueTextCtrl->GetValidator()
1055  && !fieldValueTextCtrl->GetValidator()->Validate( this ) )
1056  return false;
1057 
1058  SCH_FIELD& field = m_FieldsBuf[fieldNdx];
1059 
1060  field.SetVisible( showCheckBox->GetValue() );
1061 
1062  if( rotateCheckBox->GetValue() )
1063  field.SetTextAngle( TEXT_ANGLE_VERT );
1064  else
1065  field.SetTextAngle( TEXT_ANGLE_HORIZ );
1066 
1067  rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
1068 
1069  // Copy the text justification
1070  static const EDA_TEXT_HJUSTIFY_T hjustify[] = {
1074  };
1075 
1076  static const EDA_TEXT_VJUSTIFY_T vjustify[] = {
1080  };
1081 
1082  field.SetHorizJustify( hjustify[m_FieldHJustifyCtrl->GetSelection()] );
1083  field.SetVertJustify( vjustify[m_FieldVJustifyCtrl->GetSelection()] );
1084 
1085  field.SetName( fieldNameTextCtrl->GetValue() );
1086 
1087  /* Void fields texts for REFERENCE and VALUE (value is the name of the
1088  * component in lib ! ) are not allowed
1089  * change them only for a new non void value
1090  * When void, usually netlists are broken
1091  */
1092  if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
1093  field.SetText( fieldValueTextCtrl->GetValue() );
1094 
1095  setRowItem( fieldNdx, field ); // update fieldListCtrl
1096 
1098  field.SetTextSize( wxSize( tmp, tmp ) );
1099  int style = m_StyleRadioBox->GetSelection();
1100 
1101  field.SetItalic( (style & 1 ) != 0 );
1102  field.SetBold( (style & 2 ) != 0 );
1103 
1104  wxPoint pos;
1105  pos.x = ValueFromString( g_UserUnit, posXTextCtrl->GetValue() );
1106  pos.y = ValueFromString( g_UserUnit, posYTextCtrl->GetValue() );
1107  field.SetTextPos( pos );
1108 
1109  return true;
1110 }
1111 
1112 
1114 {
1115  // Remove non existing choices (choiceCount must be <= number for parts)
1116  int unitcount = m_part ? m_part->GetUnitCount() : 1;
1117 
1118  if( unitcount < 1 )
1119  unitcount = 1;
1120 
1121  unitChoice->Clear();
1122 
1123  for( int ii = 1; ii <= unitcount; ii++ )
1124  {
1125  unitChoice->Append( LIB_PART::SubReference( ii, false ) );
1126  }
1127 
1128  // For symbols with multiple parts per package, set the unit selection
1129  if( m_cmp->GetUnit() <= (int)unitChoice->GetCount() )
1130  unitChoice->SetSelection( m_cmp->GetUnit() - 1 );
1131 
1132  // Disable unit selection if only one unit exists:
1133  if( m_cmp->GetUnitCount() <= 1 )
1134  {
1135  unitChoice->Enable( false );
1136  unitsInterchageableLabel->Show( false );
1137  unitsInterchageableText->Show( false );
1138  }
1139  else
1140  {
1141  // Show the "Units are not interchangeable" message option?
1142  if( !m_part || !m_part->UnitsLocked() )
1143  unitsInterchageableLabel->SetLabel( _( "Yes" ) );
1144  else
1145  unitsInterchageableLabel->SetLabel( _( "No" ) );
1146  }
1147 
1148  int orientation = m_cmp->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
1149 
1150  if( orientation == CMP_ORIENT_90 )
1151  orientationRadioBox->SetSelection( 1 );
1152  else if( orientation == CMP_ORIENT_180 )
1153  orientationRadioBox->SetSelection( 2 );
1154  else if( orientation == CMP_ORIENT_270 )
1155  orientationRadioBox->SetSelection( 3 );
1156  else
1157  orientationRadioBox->SetSelection( 0 );
1158 
1159  int mirror = m_cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
1160 
1161  if( mirror == CMP_MIRROR_X )
1162  {
1163  mirrorRadioBox->SetSelection( 1 );
1164  DBG( printf( "mirror=X,1\n" ); )
1165  }
1166  else if( mirror == CMP_MIRROR_Y )
1167  {
1168  mirrorRadioBox->SetSelection( 2 );
1169  DBG( printf( "mirror=Y,2\n" ); )
1170  }
1171  else
1172  mirrorRadioBox->SetSelection( 0 );
1173 
1174  // Activate/Desactivate the normal/convert option ? (activated only if
1175  // the component has more than one shape)
1176  if( m_cmp->GetConvert() > 1 )
1177  convertCheckBox->SetValue( true );
1178 
1179  if( m_part == NULL || !m_part->HasConversion() )
1180  convertCheckBox->Enable( false );
1181 
1182  // Set the component's library name.
1183  chipnameTextCtrl->SetValue( m_cmp->GetLibId().Format() );
1184 
1185  // Set the component's unique ID time stamp.
1186  m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ),
1187  (unsigned long) m_cmp->GetTimeStamp() ) );
1188 }
1189 
1190 
1192 {
1193  if( !m_cmp )
1194  return;
1195 
1196  if( LIB_PART* part = GetParent()->GetLibPart( m_cmp->GetLibId() ) )
1197  {
1198  // save old cmp in undo list if not already in edit, or moving ...
1199  if( m_cmp->GetFlags() == 0 )
1201 
1203  m_cmp->Draw( GetParent()->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode );
1204 
1205  // Initialize fixed field values to default values found in library
1206  // Note: the field texts are not modified because they are set in schematic,
1207  // the text from libraries is most of time a dummy text
1208  // Only VALUE, REFERENCE , FOOTPRINT and DATASHEET are re-initialized
1209  LIB_FIELD& refField = part->GetReferenceField();
1210 
1211  m_cmp->GetField( REFERENCE )->ImportValues( refField );
1212  m_cmp->GetField( REFERENCE )->SetTextPos( refField.GetTextPos() + m_cmp->m_Pos );
1213 
1214  LIB_FIELD& valField = part->GetValueField();
1215 
1216  m_cmp->GetField( VALUE )->ImportValues( valField );
1217  m_cmp->GetField( VALUE )->SetTextPos( valField.GetTextPos() + m_cmp->m_Pos );
1218 
1219  LIB_FIELD* field = part->GetField(FOOTPRINT);
1220 
1221  if( field && m_cmp->GetField( FOOTPRINT ) )
1222  {
1223  m_cmp->GetField( FOOTPRINT )->ImportValues( *field );
1224  m_cmp->GetField( FOOTPRINT )->SetTextPos( field->GetTextPos() + m_cmp->m_Pos );
1225  }
1226 
1227  field = part->GetField(DATASHEET);
1228 
1229  if( field && m_cmp->GetField( DATASHEET ) )
1230  {
1231  m_cmp->GetField( DATASHEET )->ImportValues( *field );
1232  m_cmp->GetField( DATASHEET )->SetTextPos( field->GetTextPos() + m_cmp->m_Pos );
1233  }
1234 
1236 
1237  GetParent()->OnModify();
1238 
1239  m_cmp->Draw( GetParent()->GetCanvas(), &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
1240 
1241  EndQuasiModal( wxID_OK );
1242  }
1243 }
1244 
1245 
1247 {
1248  SCH_COMPONENT copy( *m_cmp );
1249  std::list<SCH_COMPONENT*> components;
1250  components.push_back( &copy );
1251  InvokeDialogUpdateFields( GetParent(), components, false );
1252 
1253  // Copy fields from the modified component copy to the dialog buffer
1254  m_FieldsBuf.clear();
1255 
1256  for( int i = 0; i < copy.GetFieldCount(); ++i )
1257  {
1258  copy.m_Fields[i].SetParent( m_cmp );
1259  m_FieldsBuf.push_back( copy.m_Fields[i] );
1260  m_FieldsBuf[i].Offset( -m_cmp->m_Pos );
1261  }
1262 
1263  // Update the selected field as well
1265  updateDisplay();
1266 }
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:154
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
Class SCH_FIELD instances are attached to a component and provide a place for the component&#39;s value...
Definition: sch_field.h:56
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:227
bool UnitsLocked() const
Check whether part units are interchangeable.
void EditComponent(SCH_COMPONENT *aComponent)
Display the edit component dialog to edit the parameters of aComponent.
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:284
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
bool copyPanelToSelectedField()
Copy the values displayed on the panel fields to the currently selected field.
Part library alias object definition.
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:424
const TEMPLATES & GetTemplates()
Return the field names template for read only access.
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
name of datasheet
void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminorParseARG_PDECL)
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
void moveDownButtonHandler(wxCommandEvent &event) override
int GetOrientation()
Get the display symbol orientation.
SCH_FIELDS m_FieldsBuf
a copy of the edited symbol&#39;s SCH_FIELDs
SCH_FIELD * findField(const wxString &aFieldName)
bool IsItalic() const
Definition: eda_text.h:168
bool IsPower() const
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:339
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
void OnOKButtonClick(wxCommandEvent &event) override
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:342
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
SCH_FIELDS m_Fields
Variable length list of fields.
Definition: sch_component.h:91
int GetId() const
Definition: sch_field.h:87
This file is part of the common library.
void ImportValues(const LIB_FIELD &aSource)
Function ImportValues copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:221
void addFieldButtonHandler(wxCommandEvent &event) override
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:204
wxPoint m_Pos
Name and library where symbol was loaded from, i.e. "74xx:74LS00".
Definition: sch_component.h:77
void SetItalic(bool isItalic)
Definition: eda_text.h:167
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
void OnInitDlg(wxInitDialogEvent &event) override
Field object used in symbol libraries.
Definition: lib_field.h:59
int GetTextWidth() const
Definition: eda_text.h:216
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
void SetVisible(bool aVisible)
Definition: eda_text.h:173
const LIB_ID & GetLibId() const
void OnCancelButtonClick(wxCommandEvent &event) override
static int ParseSize(const wxString &sizeText, EDA_UNITS_T user_unit)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:86
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)
void SetUnitSelection(SCH_SHEET_PATH *aSheet, int aUnitSelection)
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
int GetUnitCount() const
Return the number of units per package of the symbol.
void deleteFieldButtonHandler(wxCommandEvent &event) override
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:361
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
#define TEXT_ANGLE_VERT
Definition: common.h:92
int GetUnit() const
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
Class SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierar...
void SetConvert(int aConvert)
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void setRowItem(int aFieldNdx, const wxString &aName, const wxString &aValue)
int GetConvert() const
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 SetLibId(const LIB_ID &aName, PART_LIBS *aLibs=NULL)
void OnTestChipName(wxCommandEvent &event) override
a helper to handle the real device context used in KiCad
bool EnsureTextCtrlWidth(wxTextCtrl *aCtrl, const wxString *aString)
Function EnsureTextCtrlWidth sets the minimum pixel width on a text control in order to make a text s...
Definition: common.cpp:108
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:282
void SetFields(const SCH_FIELDS &aFields)
Set multiple schematic fields.
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:254
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:300
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
int ShowQuasiModal()
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
std::vector< SCH_FIELD > SCH_FIELDS
A container for several SCH_FIELD items.
Definition: sch_component.h:53
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit)
Definition: base_units.cpp:484
Defintions of control validators for schematic dialogs.
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.
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:369
Define a library symbol object.
void OnListItemDeselected(wxListEvent &event) override
Helper dialog and control classes.
unsigned STATUS_FLAGS
Definition: base_struct.h:160
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void SetUnit(int aUnit)
Change the unit number to aUnit.
int GetUnit() const
void OnListItemSelected(wxListEvent &event) override
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
void UpdateFields(wxCommandEvent &event) override
int InvokeDialogUpdateFields(SCH_EDIT_FRAME *aCaller, const list< SCH_COMPONENT * > aComponents, bool aCreateUndoEntry)
bool m_autoplaceFields
automatically place component fields
static wxString resolveUriByEnvVars(const wxString &aUri)
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54
int GetUnitCount() const
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void OnSelectChipName(wxCommandEvent &event) override
void moveUpButtonHandler(wxCommandEvent &event) override
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
wxString GetRef() const
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)
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
Definition the SCH_COMPONENT class for Eeschema.
Class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP.
bool HasFieldName(const wxString &aName) const
Function HasFieldName checks for aName in the the template field name list.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field names list for read only access.
see class PGM_BASE
void updateDisplay()
Update the listbox showing fields according to the field&#39;s text.
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
int GetFieldCount() const
Return the number of fields in this symbol.
BLOCK_STATE_T GetState() const
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...
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
#define INSTALL_UNBUFFERED_DC(name, parent)
bool IsVisible() const
Definition: eda_text.h:174
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:915
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Dialog used to edit SCH_COMPONENT objects in a schematic.
void SetIgnoreMouseEvents(bool aIgnore)
void SetName(const wxString &aName)
Definition: sch_field.h:85
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
void EditSpiceModel(wxCommandEvent &event) override
const LIB_ID & GetLibId() const
The common library.
void copySelectedFieldToPanel()
Sets the values displayed on the panel according to the currently selected field row.
UTF8 Format() const
Definition: lib_id.cpp:263
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:283
COMPONENT_SELECTION SelectComponentFromLibrary(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:102
#define DBG(x)
Definition: fctsys.h:33
void InitBuffers(SCH_COMPONENT *aComponent)
Initialize controls with aComponent.
LIB_PART * GetLibPart() const
class SCH_FILED_VALIDATOR
Definition for part library class.
void showButtonHandler(wxCommandEvent &event) override
static bool IsReferenceStringValid(const wxString &aReferenceString)
Tests for an acceptable reference string.
void setRowItem(int aFieldNdx, const SCH_FIELD &aField)
unsigned GetCount()
Function GetCount.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:105
SCH_COMPONENT * GetComp() const
#define VALUE
void SetBold(bool aBold)
Definition: eda_text.h:170
static wxString FormatSize(EDA_UNITS_T user_unit, int textSize)
Function FormatSize formats a string containing the size in the desired units.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:74
VTBL_ENTRY bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...
Class SCH_REFERENCE is used as a helper to define a component&#39;s reference designator in a schematic...
timestamp_t GetTimeStamp() const
Definition: base_struct.h:233
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
bool IsDragging() const
Definition: base_struct.h:248