2009-11-04 20:46:53 +00:00
|
|
|
/*****************************************************/
|
|
|
|
/* Component library edit field manipulation code. */
|
|
|
|
/*****************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <class_sch_screen.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <libeditframe.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <template_fieldnames.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
#include <dialog_edit_one_field.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2012-02-21 17:47:30 +00:00
|
|
|
void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-02 21:41:56 +00:00
|
|
|
wxString text;
|
2010-07-20 10:30:40 +00:00
|
|
|
wxString title;
|
2010-12-02 21:41:56 +00:00
|
|
|
wxString caption;
|
2010-10-22 12:11:52 +00:00
|
|
|
wxString oldName;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
if( aField == NULL )
|
2008-11-24 06:53:43 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
LIB_COMPONENT* parent = aField->GetParent();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
// Editing the component value field is equivalent to creating a new component based
|
|
|
|
// on the current component. Set the dialog message to inform the user.
|
2010-12-07 16:10:42 +00:00
|
|
|
if( aField->GetId() == VALUE )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
|
|
|
caption = _( "Component Name" );
|
|
|
|
title = _( "Enter a name to create a new component based on this one." );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-21 17:47:30 +00:00
|
|
|
caption.Printf( _( "Edit Field %s" ), GetChars( aField->GetName() ) );
|
2010-12-02 21:41:56 +00:00
|
|
|
title.Printf( _( "Enter a new value for the %s field." ),
|
|
|
|
GetChars( aField->GetName().Lower() ) );
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-02-21 17:47:30 +00:00
|
|
|
DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
2012-02-21 17:47:30 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2010-10-22 12:11:52 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-21 17:47:30 +00:00
|
|
|
text = dlg.GetTextField();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-31 16:29:14 +00:00
|
|
|
// Perform some controls:
|
2010-12-07 16:10:42 +00:00
|
|
|
if( ( aField->GetId() == REFERENCE || aField->GetId() == VALUE ) && text.IsEmpty ( ) )
|
2010-07-20 10:30:40 +00:00
|
|
|
{
|
2010-12-02 21:41:56 +00:00
|
|
|
title.Printf( _( "A %s field cannot be empty." ), GetChars(aField->GetName().Lower() ) );
|
|
|
|
DisplayError( this, title );
|
2010-10-22 12:11:52 +00:00
|
|
|
return;
|
2010-07-20 10:30:40 +00:00
|
|
|
}
|
|
|
|
|
2011-05-31 16:29:14 +00:00
|
|
|
// Ensure the reference prefix is acceptable:
|
|
|
|
if( ( aField->GetId() == REFERENCE ) &&
|
|
|
|
! SCH_COMPONENT::IsReferenceStringValid( text ) )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Illegal reference. A reference must start by a letter" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
wxString fieldText = aField->GetFullText( m_unit );
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
/* If the value field is changed, this is equivalent to creating a new component from
|
|
|
|
* the old one. Rename the component and remove any conflicting aliases to prevent name
|
|
|
|
* errors when updating the library.
|
2009-05-13 10:26:11 +00:00
|
|
|
*/
|
2012-02-21 17:47:30 +00:00
|
|
|
if( (aField->GetId() == VALUE) && ( text != aField->m_Text ) )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
// Test the current library for name conflicts.
|
2011-03-30 10:51:51 +00:00
|
|
|
if( m_library && m_library->FindEntry( text ) != NULL )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2010-12-02 21:41:56 +00:00
|
|
|
msg.Printf( _( "The name <%s> conflicts with an existing entry in the component \
|
|
|
|
library <%s>.\n\nDo you wish to replace the current component in library with this one?" ),
|
|
|
|
GetChars( text ),
|
2010-10-20 20:24:26 +00:00
|
|
|
GetChars( m_library->GetName() ) );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
|
|
|
int rsp = wxMessageBox( msg, _( "Confirm" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT, this );
|
|
|
|
|
|
|
|
if( rsp == wxNO )
|
|
|
|
return;
|
2009-05-13 10:26:11 +00:00
|
|
|
}
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
// Test the current component for name conflicts.
|
|
|
|
if( parent->HasAlias( text ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The current component already has an alias named <%s>.\n\nDo you \
|
|
|
|
wish to remove this alias from the component?" ),
|
2011-03-30 10:51:51 +00:00
|
|
|
GetChars( text ) );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
|
|
|
int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this );
|
|
|
|
|
|
|
|
if( rsp == wxNO )
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent->RemoveAlias( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->SetName( text );
|
|
|
|
|
|
|
|
// Test the library for any conflicts with the any aliases in the current component.
|
2011-03-30 10:51:51 +00:00
|
|
|
if( parent->GetAliasCount() > 1 && m_library && m_library->Conflicts( parent ) )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "The new component contains alias names that conflict with entries \
|
|
|
|
in the component library <%s>.\n\nDo you wish to remove all of the conflicting aliases from \
|
|
|
|
this component?" ),
|
|
|
|
GetChars( m_library->GetName() ) );
|
|
|
|
|
|
|
|
int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this );
|
|
|
|
|
|
|
|
if( rsp == wxNO )
|
|
|
|
{
|
|
|
|
parent->SetName( fieldText );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString aliases = parent->GetAliasNames( false );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < aliases.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( m_library->FindEntry( aliases[ i ] ) != NULL )
|
|
|
|
parent->RemoveAlias( aliases[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !parent->HasAlias( m_aliasName ) )
|
|
|
|
m_aliasName = text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aField->SetText( text );
|
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
if( !aField->InEditMode() )
|
2010-10-22 12:11:52 +00:00
|
|
|
SaveCopyInUndoList( parent );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2012-02-21 17:47:30 +00:00
|
|
|
// Update field
|
|
|
|
dlg.TransfertDataToField();
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2012-02-21 17:47:30 +00:00
|
|
|
m_canvas->Refresh();
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
OnModify();
|
2009-09-14 13:24:17 +00:00
|
|
|
UpdateAliasSelectList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|