KiCad PCB EDA Suite
dialog_edit_libentry_fields_in_lib.cpp
Go to the documentation of this file.
1 
2 /*
3  * This program source code file is part of KiCad, a free EDA CAD application.
4  *
5  * Copyright (C) 2011-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2007-2017 KiCad Developers, see change_log.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 #include <algorithm>
28 
29 #include <fctsys.h>
30 #include <pgm_base.h>
31 #include <kiway.h>
32 #include <confirm.h>
33 #include <class_drawpanel.h>
34 #include <schframe.h>
35 #include <id.h>
36 #include <base_units.h>
37 
38 #include <general.h>
39 #include <libeditframe.h>
40 #include <class_library.h>
41 #include <sch_component.h>
42 #include <sch_field.h>
43 #include <template_fieldnames.h>
44 #include <dialog_helpers.h>
45 #include <sch_validators.h>
46 
48 #ifdef KICAD_SPICE
49 #include <dialog_spice_model.h>
51 #endif /* KICAD_SPICE */
52 
53 // Local variables:
54 static int s_SelectedRow;
55 
56 #define COLUMN_FIELD_NAME 0
57 #define COLUMN_TEXT 1
58 
60 {
61 public:
63  //~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB() {}
64 
65 private:
66  // Events handlers:
67  void OnInitDialog( wxInitDialogEvent& event ) override;
68  void OnCloseDialog( wxCloseEvent& event ) override;
69 
70  void OnListItemDeselected( wxListEvent& event ) override;
71  void OnListItemSelected( wxListEvent& event ) override;
72  void addFieldButtonHandler( wxCommandEvent& event ) override;
73  void EditSpiceModel( wxCommandEvent& event ) override;
74 
82  void deleteFieldButtonHandler( wxCommandEvent& event ) override;
83 
84  void moveUpButtonHandler( wxCommandEvent& event ) override;
85  void OnCancelButtonClick( wxCommandEvent& event ) override;
86  void OnOKButtonClick( wxCommandEvent& event ) override;
87  void showButtonHandler( wxCommandEvent& event ) override;
88 
89  // internal functions:
90  void setSelectedFieldNdx( int aFieldNdx );
91 
92  int getSelectedFieldNdx();
93 
98  void initBuffers();
99 
105  LIB_FIELD* findField( const wxString& aFieldName );
106 
113 
121 
122  void setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue );
123  void setRowItem( int aFieldNdx, const LIB_FIELD& aField )
124  {
125  setRowItem( aFieldNdx, aField.GetName(), aField.GetText() );
126  }
127 
134  {
135  for( unsigned ii = MANDATORY_FIELDS; ii<m_FieldsBuf.size(); ii++ )
136  setRowItem( ii, m_FieldsBuf[ii] );
137  }
138 
142 
144  std::vector <LIB_FIELD> m_FieldsBuf;
145 };
146 
147 
148 void LIB_EDIT_FRAME::InstallFieldsEditorDialog( wxCommandEvent& event )
149 {
150  if( !GetCurPart() )
151  return;
152 
154 
156 
157  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
158  // frame. Therefore this dialog as a modal frame parent, MUST be run under
159  // quasimodal mode for the quasimodal frame support to work. So don't use
160  // the QUASIMODAL macros here.
161  if( dlg.ShowQuasiModal() != wxID_OK )
162  return;
163 
166  DisplayLibInfos();
167  Refresh();
168 }
169 
170 
172  LIB_EDIT_FRAME* aParent,
173  LIB_PART* aLibEntry ) :
175 {
176  m_parent = aParent;
177  m_libEntry = aLibEntry;
178  m_skipCopyFromPanel = false;
179 
180 #ifndef KICAD_SPICE
181  m_spiceFieldsButton->Show(false);
182 #endif
183 }
184 
185 
186 void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnInitDialog( wxInitDialogEvent& event )
187 {
188  m_skipCopyFromPanel = false;
189  wxListItem columnLabel;
190 
191  columnLabel.SetImage( -1 );
192 
193  columnLabel.SetText( _( "Name" ) );
194  fieldListCtrl->InsertColumn( COLUMN_FIELD_NAME, columnLabel );
195 
196  columnLabel.SetText( _( "Value" ) );
197  fieldListCtrl->InsertColumn( COLUMN_TEXT, columnLabel );
198 
202 
203  initBuffers();
205 
206  stdDialogButtonSizerOK->SetDefault();
207 
208  // Now all widgets have the size fixed, call FinishDialogSettings
210 }
211 
212 
214 {
215  if( !m_skipCopyFromPanel )
216  {
217  if( !copyPanelToSelectedField() )
218  event.Skip(); // do not go to the next row
219  }
220 }
221 
222 
224 {
225  // remember the selected row, statically
226  s_SelectedRow = event.GetIndex();
227 
229 }
230 
231 
233 {
234  EndQuasiModal( wxID_CANCEL );
235 }
236 
237 
239 {
240  // On wxWidgets 2.8, and on Linux, call EndQuasiModal here is mandatory
241  // Otherwise, the main event loop is never restored, and Eeschema does not
242  // respond to any event, because the DIALOG_SHIM destructor is never called.
243  // on wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
244  // and calls EndQuasiModal.
245  // Therefore calling EndQuasiModal here is not mandatory but it creates no issues.
246  EndQuasiModal( wxID_CANCEL );
247 }
248 
249 
251 {
252  if( !copyPanelToSelectedField() )
253  return;
254 
255  // test if reference prefix is acceptable
257  {
258  DisplayError( NULL, _( "Illegal reference. References must start with a letter." ) );
259  return;
260  }
261 
262  /* Note: this code is now (2010-dec-04) not used, because the value field is no more editable
263  * because changing the value is equivalent to create a new component or alias.
264  * This is now handled in libedit main frame, and no more in this dialog
265  * but this code is not removed, just in case
266  */
267  /* If a new name entered in the VALUE field, that it not an existing alias name
268  * or root alias of the component */
269  wxString newvalue = m_FieldsBuf[VALUE].GetText();
270 
271  if( m_libEntry->HasAlias( newvalue ) && !m_libEntry->GetAlias( newvalue )->IsRoot() )
272  {
273  wxString msg = wxString::Format(
274  _( "A new name is entered for this component\n"
275  "An alias %s already exists!\n"
276  "Cannot update this component" ),
277  GetChars( newvalue )
278  );
279  DisplayError( this, msg );
280  return;
281  }
282  /* End unused code */
283 
284  // save old cmp in undo list
286 
287  // delete any fields with no name or no value before we copy all of m_FieldsBuf
288  // back into the component
289  for( unsigned i = MANDATORY_FIELDS; i < m_FieldsBuf.size(); )
290  {
291  if( m_FieldsBuf[i].GetName().IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() )
292  {
293  m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
294  continue;
295  }
296 
297  ++i;
298  }
299 
300  // copy all the fields back, fully replacing any previous fields
302 
303  // We need to keep the name and the value the same at the moment!
304  SetName( m_libEntry->GetValueField().GetText() );
305 
306  m_parent->OnModify();
307 
308  EndQuasiModal( wxID_OK );
309 }
310 
311 
313 {
314 #ifdef KICAD_SPICE
315  // DIALOG_SPICE_MODEL expects a SCH_COMPONENT,
316  // and a list of SCH_FIELDS to create/edit/delete Spice fields.
317  SCH_COMPONENT component; // This dummy component
318 
319  // Build fields list from the m_FieldsBuf fields buffer dialog
320  // to be sure to use the current fields.
321  SCH_FIELDS schfields;
322 
323  for( unsigned ii = 0; ii < m_FieldsBuf.size(); ++ii )
324  {
325  LIB_FIELD& libfield = m_FieldsBuf[ii];
326  SCH_FIELD schfield( libfield.GetTextPos(), libfield.GetId(),
327  &component, libfield.GetName() );
328  schfield.ImportValues( m_FieldsBuf[ii] );
329  schfield.SetText( m_FieldsBuf[ii].GetText() );
330 
331  schfields.push_back( schfield );
332  }
333 
334  component.SetFields( schfields );
335 
336  DIALOG_SPICE_MODEL dialog( this, component, schfields );
337 
338  if( dialog.ShowModal() != wxID_OK )
339  return;
340 
341  // Transfert sch fields to the m_FieldsBuf fields buffer dialog:
342  m_FieldsBuf.clear();
343 
344  for( unsigned ii = 0; ii < schfields.size(); ii++ )
345  {
346  LIB_FIELD libfield;
347  schfields[ii].ExportValues( libfield );
348  m_FieldsBuf.push_back( libfield );
349  }
350 
351  updateDisplay();
352 #endif /* KICAD_SPICE */
353 }
354 
355 
357 {
358  // in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
359  // screen contents.
360  if( !copyPanelToSelectedField() )
361  return;
362 
363  unsigned fieldNdx = m_FieldsBuf.size();
364 
365  LIB_FIELD blank( fieldNdx );
366 
367  m_FieldsBuf.push_back( blank );
368  m_FieldsBuf[fieldNdx].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx ) );
369 
370  setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
371 
372  m_skipCopyFromPanel = true;
373  setSelectedFieldNdx( fieldNdx );
374  m_skipCopyFromPanel = false;
375 }
376 
377 
379 {
380  unsigned fieldNdx = getSelectedFieldNdx();
381 
382  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
383  return;
384 
385  if( fieldNdx < MANDATORY_FIELDS )
386  {
387  wxBell();
388  return;
389  }
390 
391  m_skipCopyFromPanel = true;
392 
393  if( m_FieldsBuf[fieldNdx].GetText().IsEmpty() )
394  {
395  m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
396  fieldListCtrl->DeleteItem( fieldNdx );
397 
398  if( fieldNdx >= m_FieldsBuf.size() )
399  --fieldNdx;
400  }
401  else
402  {
403  m_FieldsBuf[fieldNdx].Empty();
405  }
406 
407  updateDisplay( );
408 
409  setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
410  setSelectedFieldNdx( fieldNdx );
411  m_skipCopyFromPanel = false;
412 }
413 
414 
416 {
417  unsigned fieldNdx = getSelectedFieldNdx();
418 
419  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
420  return;
421 
422  // The first field which can be moved up is the second user field
423  // so any field which id <= MANDATORY_FIELDS cannot be moved up
424  if( fieldNdx <= MANDATORY_FIELDS )
425  return;
426 
427  if( !copyPanelToSelectedField() )
428  return;
429 
430  // swap the fieldNdx field with the one before it, in both the vector
431  // and in the fieldListCtrl
432  LIB_FIELD tmp = m_FieldsBuf[fieldNdx - 1];
433 
434  m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx];
435  setRowItem( fieldNdx - 1, m_FieldsBuf[fieldNdx] );
436  m_FieldsBuf[fieldNdx - 1].SetId(fieldNdx - 1);
437 
438  m_FieldsBuf[fieldNdx] = tmp;
439  setRowItem( fieldNdx, tmp );
440  m_FieldsBuf[fieldNdx].SetId(fieldNdx);
441 
442  updateDisplay( );
443 
444  m_skipCopyFromPanel = true;
445  setSelectedFieldNdx( fieldNdx - 1 );
446  m_skipCopyFromPanel = false;
447 }
448 
449 
451 {
452  unsigned fieldNdx = getSelectedFieldNdx();
453 
454  if( fieldNdx == DATASHEET )
455  {
456  wxString datasheet_uri = fieldValueTextCtrl->GetValue();
457  ::wxLaunchDefaultBrowser( datasheet_uri );
458  }
459  else if( fieldNdx == FOOTPRINT )
460  {
461  // pick a footprint using the footprint picker.
462  wxString fpid;
463 
465 
466  if( frame->ShowModal( &fpid, this ) )
467  {
468  fieldValueTextCtrl->SetValue( fpid );
469  setRowItem( fieldNdx, m_FieldsBuf[fieldNdx].GetName( false ), fpid );
470  }
471 
472  frame->Destroy();
473  }
474 }
475 
476 
478 {
479  // deselect old selection, but I think this is done by single selection
480  // flag within fieldListCtrl
481  // fieldListCtrl->SetItemState( s_SelectedRow, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
482 
483  if( aFieldNdx >= (int) m_FieldsBuf.size() )
484  aFieldNdx = m_FieldsBuf.size() - 1;
485 
486  if( aFieldNdx < 0 )
487  aFieldNdx = 0;
488 
489  fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
490  fieldListCtrl->EnsureVisible( aFieldNdx );
491 
492  s_SelectedRow = aFieldNdx;
493 }
494 
495 
497 {
498  return s_SelectedRow;
499 }
500 
501 
506 static LIB_FIELD* findfield( const LIB_FIELDS& aList, const wxString& aFieldName )
507 {
508  const LIB_FIELD* field = NULL;
509 
510  for( unsigned i=0; i<aList.size(); ++i )
511  {
512  if( aFieldName == aList[i].GetName() )
513  {
514  field = &aList[i]; // best to avoid casting here.
515  break;
516  }
517  }
518  return (LIB_FIELD*) field; // remove const-ness last
519 }
520 
521 
523 {
524  for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
525  {
526  if( aFieldName == m_FieldsBuf[i].GetName() )
527  return &m_FieldsBuf[i];
528  }
529  return NULL;
530 }
531 
532 
534 {
535  LIB_FIELDS cmpFields;
536 
537  m_libEntry->GetFields( cmpFields );
538 
539  /* We have 3 component related field lists to be aware of: 1) UI
540  presentation (m_FieldsBuf), 2) fields in component ram copy, and 3)
541  fields recorded with component on disk. m_FieldsBuf is the list of UI
542  fields, and this list is not the same as the list which is in the
543  component, which is also not the same as the list on disk. All 3 lists
544  are potentially different. In the UI we choose to preserve the order of
545  the first MANDATORY_FIELDS which are sometimes called fixed fields. Then
546  we append the template fieldnames in the exact same order as the
547  template fieldname editor shows them. Then we append any user defined
548  fieldnames which came from the component, and user can modify it during
549  editing, but cannot delete or move a fixed field.
550  */
551 
552  m_FieldsBuf.clear();
553 
554  /* When this code was written, all field constructors ensured that the
555  MANDATORY_FIELDS are all present within a component (in ram only). So we can
556  knowingly copy them over in the normal order. Copy only the fixed fields
557  at first. Please do not break the field constructors.
558  */
559 
560  // fixed fields:
561  for( int i=0; i<MANDATORY_FIELDS; ++i )
562  {
563  m_FieldsBuf.push_back( cmpFields[i] );
564  }
565 
566  // Add template fieldnames:
567  // Now copy in the template fields, in the order that they are present in the
568  // template field editor UI.
569  SCH_EDIT_FRAME* editor = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, true );
570 
571  const TEMPLATE_FIELDNAMES& tfnames = editor->GetTemplateFieldNames();
572 
573  for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
574  {
575  // add a new field unconditionally to the UI only for this template fieldname
576 
577  // field id must not be in range 0 - MANDATORY_FIELDS, set before saving to disk
578  LIB_FIELD fld( m_libEntry, -1 );
579 
580  // See if field by same name already exists in component.
581  LIB_FIELD* libField = findfield( cmpFields, it->m_Name );
582 
583  // If the field does not already exist in the component, then we
584  // use defaults from the template fieldname, otherwise the original
585  // values from the component will be set.
586  if( !libField )
587  {
588  fld.SetName( it->m_Name );
589  fld.SetText( it->m_Value ); // empty? ok too.
590 
591  if( !it->m_Visible )
592  fld.SetVisible( false );
593  else
594  fld.SetVisible( true );
595  }
596  else
597  {
598  fld = *libField; // copy values from component, m_Name too
599  }
600 
601  m_FieldsBuf.push_back( fld );
602  }
603 
604  // Lastly, append any original fields from the component which were not added
605  // from the set of fixed fields nor from the set of template fields.
606  for( unsigned i=MANDATORY_FIELDS; i<cmpFields.size(); ++i )
607  {
608  LIB_FIELD* cmp = &cmpFields[i];
609  LIB_FIELD* buf = findField( cmp->GetName() );
610 
611  if( !buf )
612  {
613  m_FieldsBuf.push_back( *cmp );
614  }
615  }
616 
617  /* field names have become more important than field ids, so we cannot
618  mangle the names in the buffer, but can do so in the panel, see elsewhere.
619  m_FieldsBuf[VALUE].m_Name << wxT( "/" ) << _( "Chip Name" );
620  */
621 
622  for( unsigned ii = 0; ii < m_FieldsBuf.size(); ++ii )
623  {
624  setRowItem( ii, m_FieldsBuf[ii] );
625  }
626 
627  // put focus on the list ctrl
628  fieldListCtrl->SetFocus();
629 
630  // resume editing at the last row edited, last time dialog was up.
631  if ( s_SelectedRow < (int) m_FieldsBuf.size() )
632  s_SelectedRow = 0;
633 
635 }
636 
637 
638 void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue )
639 {
640  wxASSERT( aFieldNdx >= 0 );
641 
642  // insert blanks if aFieldNdx is referencing a "yet to be defined" row
643  while( aFieldNdx >= fieldListCtrl->GetItemCount() )
644  {
645  long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString );
646 
647  wxASSERT( ndx >= 0 );
648 
649  fieldListCtrl->SetItem( ndx, COLUMN_TEXT, wxEmptyString );
650  }
651 
652  fieldListCtrl->SetItem( aFieldNdx, COLUMN_FIELD_NAME, aName );
653  fieldListCtrl->SetItem( aFieldNdx, COLUMN_TEXT, aValue );
654 
655  // recompute the column widths here, after setting texts
656  fieldListCtrl->SetColumnWidth( COLUMN_FIELD_NAME, wxLIST_AUTOSIZE );
657  fieldListCtrl->SetColumnWidth( COLUMN_TEXT, wxLIST_AUTOSIZE );
658 }
659 
660 
662 {
663  unsigned fieldNdx = getSelectedFieldNdx();
664 
665  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
666  return;
667 
668  LIB_FIELD& field = m_FieldsBuf[fieldNdx];
669 
670  showCheckBox->SetValue( field.IsVisible() );
671 
672  rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
673 
674  int style = 0;
675 
676  if( field.IsItalic() )
677  style = 1;
678 
679  if( field.IsBold() )
680  style |= 2;
681 
682  m_StyleRadioBox->SetSelection( style );
683 
684  // Select the right text justification
685  if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
686  m_FieldHJustifyCtrl->SetSelection(0);
687  else if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
688  m_FieldHJustifyCtrl->SetSelection(2);
689  else
690  m_FieldHJustifyCtrl->SetSelection(1);
691 
692  if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
693  m_FieldVJustifyCtrl->SetSelection(0);
694  else if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
695  m_FieldVJustifyCtrl->SetSelection(2);
696  else
697  m_FieldVJustifyCtrl->SetSelection(1);
698 
699 
700  // Field names have become more important than field ids, so we cannot
701  // mangle the names in the buffer but we can do so in the panel.
702  if( field.GetId() == VALUE )
703  {
704  // This field is the lib name and the default value when loading this component in
705  // schematic. The value is now not editable here (in this dialog) because changing
706  // it is equivalent to create a new component or alias. This is handles in libedir,
707  // not in this dialog.
708  fieldNameTextCtrl->SetValue( field.GetName() + wxT( " / " ) + _( "Chip Name" ) );
709  fieldValueTextCtrl->Enable( false );
710  }
711  else
712  {
713  fieldValueTextCtrl->Enable( true );
714  fieldNameTextCtrl->SetValue( field.GetName() );
715  }
716 
717  // if fieldNdx == REFERENCE, VALUE, FOOTPRINT, or DATASHEET, then disable field name editing
718  fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
719  fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
720 
721  // only user defined fields may be moved, and not the top most user defined
722  // field since it would be moving up into the fixed fields, > not >=
723  moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
724 
725  // if fieldNdx == REFERENCE, VALUE, then disable delete button
726  deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
727 
728  fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( true, field.GetId() ) );
729  fieldValueTextCtrl->SetValue( field.GetText() );
730 
732 
733  m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT );
734 
735  if( fieldNdx == DATASHEET )
736  {
737  m_show_datasheet_button->SetLabel( _( "Show Datasheet" ) );
738  m_show_datasheet_button->SetToolTip(
739  _("If your datasheet is given as an http:// link,"
740  " then pressing this button should bring it up in your webbrowser.") );
741  }
742  else if( fieldNdx == FOOTPRINT )
743  {
744  m_show_datasheet_button->SetLabel( _( "Browse Footprints" ) );
745  m_show_datasheet_button->SetToolTip(
746  _("Open the footprint browser to choose a footprint and assign it.") );
747  }
748  else
749  {
750  m_show_datasheet_button->SetLabel( wxEmptyString );
751  m_show_datasheet_button->SetToolTip(
752  _("Used only for fields Footprint and Datasheet.") );
753  }
754 
755  wxPoint coord = field.GetTextPos();
756  wxPoint zero;
757 
758  // If the field value is empty and the position is at relative zero, we set the
759  // initial position as a small offset from the ref field, and orient
760  // it the same as the ref field. That is likely to put it at least
761  // close to the desired position.
762  if( coord == zero && field.GetText().IsEmpty() )
763  {
764  rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].GetTextAngle() == TEXT_ANGLE_VERT );
765 
766  coord.x = m_FieldsBuf[REFERENCE].GetTextPos().x +
767  (fieldNdx - MANDATORY_FIELDS + 1) * 100;
768  coord.y = m_FieldsBuf[REFERENCE].GetTextPos().y +
769  (fieldNdx - MANDATORY_FIELDS + 1) * 100;
770 
771  // coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
772  // That is ok, we basically don't want all the new empty fields on
773  // top of each other.
774  }
775 
776  wxString coordText = StringFromValue( g_UserUnit, coord.x );
777  posXTextCtrl->SetValue( coordText );
778 
779  // Note: the Y axis for components in lib is from bottom to top
780  // and the screen axis is top to bottom: we must change the y coord sign for editing
781  coord.y = -coord.y;
782  coordText = StringFromValue( g_UserUnit, coord.y );
783  posYTextCtrl->SetValue( coordText );
784 }
785 
786 
788 {
789  unsigned fieldNdx = getSelectedFieldNdx();
790 
791  if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
792  return true;
793 
794  // Check for illegal field text.
795  if( fieldValueTextCtrl->GetValidator()
796  && !fieldValueTextCtrl->GetValidator()->Validate( this ) )
797  return false;
798 
799  LIB_FIELD& field = m_FieldsBuf[fieldNdx];
800 
801  if( showCheckBox->GetValue() )
802  field.SetVisible( true );
803  else
804  field.SetVisible( false );
805 
806  if( rotateCheckBox->GetValue() )
807  field.SetTextAngle( TEXT_ANGLE_VERT );
808  else
810 
811  // Copy the text justification
812  static const EDA_TEXT_HJUSTIFY_T hjustify[3] = {
815  };
816 
817  static const EDA_TEXT_VJUSTIFY_T vjustify[3] = {
820  };
821 
822  field.SetHorizJustify( hjustify[m_FieldHJustifyCtrl->GetSelection()] );
823  field.SetVertJustify( vjustify[m_FieldVJustifyCtrl->GetSelection()] );
824 
825  // Blank/empty field texts for REFERENCE and VALUE are not allowed.
826  // (Value is the name of the component in lib!)
827  // Change them only if user provided a non blank value
828  if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
829  field.SetText( fieldValueTextCtrl->GetValue() );
830 
831  // FieldNameTextCtrl has a tricked value in it for VALUE index, do not copy it back.
832  // It has the "Chip Name" appended.
833  if( field.GetId() >= MANDATORY_FIELDS )
834  {
835  wxString name = fieldNameTextCtrl->GetValue();
836  field.SetName( name );
837  }
838 
839  setRowItem( fieldNdx, field ); // update fieldListCtrl
840 
842 
843  field.SetTextSize( wxSize( tmp, tmp ) );
844 
845  int style = m_StyleRadioBox->GetSelection();
846 
847  field.SetItalic( (style & 1 ) != 0 );
848  field.SetBold( (style & 2 ) != 0 );
849 
850  wxPoint pos( ValueFromString( g_UserUnit, posXTextCtrl->GetValue() ),
851  ValueFromString( g_UserUnit, posYTextCtrl->GetValue() ) );
852 
853  // Note: the Y axis for components in lib is from bottom to top
854  // and the screen axis is top to bottom: we must change the y coord sign for editing
855  pos.y = -pos.y;
856 
857  field.SetTextPos( pos );
858 
859  return true;
860 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
#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
LIB_FIELD * findField(const wxString &aFieldName)
Function findField searches m_FieldsBuf and returns a LIB_FIELD with aFieldName or NULL if not found...
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
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
bool copyPanelToSelectedField()
Function copyPanelToSelectedField copies the values displayed on the panel fields to the currently se...
void setRowItem(int aFieldNdx, const wxString &aName, const wxString &aValue)
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
bool IsItalic() const
Definition: eda_text.h:170
LIB_ALIAS * GetAlias(size_t aIndex)
Implementation of conversion functions that require both schematic and board internal units...
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
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:203
void SetItalic(bool isItalic)
Definition: eda_text.h:169
void setRowItem(int aFieldNdx, const LIB_FIELD &aField)
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool HasAlias(const wxString &aName) const
Test if alias aName is in part alias list.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void OnInitDialog(wxInitDialogEvent &event) override
void SetVisible(bool aVisible)
Definition: eda_text.h:175
void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
LIB_FIELD & GetValueField()
Return reference to the value field.
static int ParseSize(const wxString &sizeText, EDA_UNITS_T user_unit)
Definition: wxwineda.cpp:123
void OnModify()
Function OnModify Must be called after a schematic change in order to set the "modify" flag of the cu...
Definition: libeditframe.h:369
void deleteFieldButtonHandler(wxCommandEvent &event) override
Function deleteFieldButtonHandler deletes a field.
void OnListItemSelected(wxListEvent &event) override
static LIB_FIELD * findfield(const LIB_FIELDS &aList, const wxString &aFieldName)
Function findfield searches a LIB_FIELD_LIST for aFieldName.
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.
Definition: schframe.h:117
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
std::vector< LIB_FIELD > m_FieldsBuf
a copy of the edited component's LIB_FIELDs
void SetName(const wxString &aName)
Function SetName.
Definition: lib_field.cpp:659
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
void UpdateAliasSelectList()
#define TEXT_ANGLE_VERT
Definition: common.h:92
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
void DisplayLibInfos()
Function DisplayLibInfos updates the main window title bar with the current library name and read onl...
Definition: libedit.cpp:55
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB(LIB_EDIT_FRAME *aParent, LIB_PART *aLibEntry)
bool IsRoot() const
void updateDisplay()
Function updateDisplay update the listbox showing fields, according to the fields texts must be calle...
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
void SetFields(const SCH_FIELDS &aFields)
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:679
void Refresh()
int GetId() const
Definition: lib_field.h:136
int ShowQuasiModal()
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
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:194
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit)
Definition: base_units.cpp:479
Defintions of control validators for schematic dialogs.
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:368
Class LIB_PART defines a library part object.
Helper dialog and control classes.
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void addFieldButtonHandler(wxCommandEvent &event) override
void InstallFieldsEditorDialog(wxCommandEvent &event)
void EditSpiceModel(wxCommandEvent &event) override
void initBuffers()
Function initBuffers sets up to edit the given component.
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:609
void showButtonHandler(wxCommandEvent &event) override
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
Field Value of part, i.e. "3.3K".
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void EndQuasiModal(int retCode)
Definition the SCH_COMPONENT class for Eeschema.
The component library editor main window.
Definition: libeditframe.h:51
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()
Function GetTemplateFieldName returns a template field names list for read only access.
Definition: schframe.h:327
see class PGM_BASE
void OnListItemDeselected(wxListEvent &event) override
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
bool IsVisible() const
Function IsVisible.
Definition: lib_field.h:168
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void OnOKButtonClick(wxCommandEvent &event) override
void moveUpButtonHandler(wxCommandEvent &event) override
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:261
LIB_PART * GetCurPart()
Function GetCurPart returns the current part being edited, or NULL if none selected.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
const char * name
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
const wxSize & GetTextSize() const
Definition: eda_text.h:215
class SCH_FILED_VALIDATOR
Definition for part library class.
Definition of the SCH_FIELD class for Eeschema.
static bool IsReferenceStringValid(const wxString &aReferenceString)
Function IsReferenceStringValid (static) Tests for an acceptable reference string An acceptable refer...
int GetDefaultCursor() const
Function GetDefaultCursor return the default cursor shape.
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Function SetFields overwrites all the existing in this part with fields supplied in aFieldsList...
void SetBold(bool aBold)
Definition: eda_text.h:172
static wxString FormatSize(EDA_UNITS_T user_unit, int textSize)
Function FormatSize formats a string containing the size in the desired units.
Definition: wxwineda.cpp:84
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
void UpdatePartSelectList()
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 DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE.
static int s_SelectedRow
Definition of class LIB_EDIT_FRAME.
void OnCancelButtonClick(wxCommandEvent &event) override
void GetFields(LIB_FIELDS &aList)
Function GetFields returns a list of fields withing this part.
void copySelectedFieldToPanel()
Function copySelectedFieldToPanel sets the values displayed on the panel according to the currently s...
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Function SaveCopyInUndoList.