You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
5.1 KiB

16 years ago
  1. /*****************************************************/
  2. /* Component library edit field manipulation code. */
  3. /*****************************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "common.h"
  7. #include "class_drawpanel.h"
  8. #include "confirm.h"
  9. #include "class_sch_screen.h"
  10. #include "general.h"
  11. //#include "protos.h"
  12. #include "sch_component.h"
  13. #include "libeditframe.h"
  14. #include "class_library.h"
  15. #include "template_fieldnames.h"
  16. void LIB_EDIT_FRAME::EditField( wxDC* DC, LIB_FIELD* aField )
  17. {
  18. wxString text;
  19. wxString title;
  20. wxString caption;
  21. wxString oldName;
  22. if( aField == NULL )
  23. return;
  24. LIB_COMPONENT* parent = aField->GetParent();
  25. // Editing the component value field is equivalent to creating a new component based
  26. // on the current component. Set the dialog message to inform the user.
  27. if( aField->GetId() == VALUE )
  28. {
  29. caption = _( "Component Name" );
  30. title = _( "Enter a name to create a new component based on this one." );
  31. }
  32. else
  33. {
  34. caption = _( "Edit Field" );
  35. title.Printf( _( "Enter a new value for the %s field." ),
  36. GetChars( aField->GetName().Lower() ) );
  37. }
  38. wxTextEntryDialog dlg( this, title, caption, aField->m_Text );
  39. if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == aField->m_Text )
  40. return;
  41. text = dlg.GetValue();
  42. text.Replace( wxT( " " ), wxT( "_" ) );
  43. // Perform some controls:
  44. if( ( aField->GetId() == REFERENCE || aField->GetId() == VALUE ) && text.IsEmpty ( ) )
  45. {
  46. title.Printf( _( "A %s field cannot be empty." ), GetChars(aField->GetName().Lower() ) );
  47. DisplayError( this, title );
  48. return;
  49. }
  50. // Ensure the reference prefix is acceptable:
  51. if( ( aField->GetId() == REFERENCE ) &&
  52. ! SCH_COMPONENT::IsReferenceStringValid( text ) )
  53. {
  54. DisplayError( this, _( "Illegal reference. A reference must start by a letter" ) );
  55. return;
  56. }
  57. wxString fieldText = aField->GetFullText( m_unit );
  58. /* If the value field is changed, this is equivalent to creating a new component from
  59. * the old one. Rename the component and remove any conflicting aliases to prevent name
  60. * errors when updating the library.
  61. */
  62. if( aField->GetId() == VALUE )
  63. {
  64. wxString msg;
  65. // Test the current library for name conflicts.
  66. if( m_library && m_library->FindEntry( text ) != NULL )
  67. {
  68. msg.Printf( _( "The name <%s> conflicts with an existing entry in the component \
  69. library <%s>.\n\nDo you wish to replace the current component in library with this one?" ),
  70. GetChars( text ),
  71. GetChars( m_library->GetName() ) );
  72. int rsp = wxMessageBox( msg, _( "Confirm" ),
  73. wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT, this );
  74. if( rsp == wxNO )
  75. return;
  76. }
  77. // Test the current component for name conflicts.
  78. if( parent->HasAlias( text ) )
  79. {
  80. msg.Printf( _( "The current component already has an alias named <%s>.\n\nDo you \
  81. wish to remove this alias from the component?" ),
  82. GetChars( text ) );
  83. int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this );
  84. if( rsp == wxNO )
  85. return;
  86. parent->RemoveAlias( text );
  87. }
  88. parent->SetName( text );
  89. // Test the library for any conflicts with the any aliases in the current component.
  90. if( parent->GetAliasCount() > 1 && m_library && m_library->Conflicts( parent ) )
  91. {
  92. msg.Printf( _( "The new component contains alias names that conflict with entries \
  93. in the component library <%s>.\n\nDo you wish to remove all of the conflicting aliases from \
  94. this component?" ),
  95. GetChars( m_library->GetName() ) );
  96. int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this );
  97. if( rsp == wxNO )
  98. {
  99. parent->SetName( fieldText );
  100. return;
  101. }
  102. wxArrayString aliases = parent->GetAliasNames( false );
  103. for( size_t i = 0; i < aliases.GetCount(); i++ )
  104. {
  105. if( m_library->FindEntry( aliases[ i ] ) != NULL )
  106. parent->RemoveAlias( aliases[ i ] );
  107. }
  108. }
  109. if( !parent->HasAlias( m_aliasName ) )
  110. m_aliasName = text;
  111. }
  112. else
  113. {
  114. aField->SetText( text );
  115. }
  116. if( !aField->InEditMode() )
  117. {
  118. SaveCopyInUndoList( parent );
  119. ( (LIB_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode,
  120. &fieldText, DefaultTransform );
  121. }
  122. if( !aField->InEditMode() )
  123. {
  124. fieldText = aField->GetFullText( m_unit );
  125. ( (LIB_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode,
  126. &fieldText, DefaultTransform );
  127. }
  128. OnModify();
  129. UpdateAliasSelectList();
  130. }