2009-11-04 20:46:53 +00:00
|
|
|
/*****************************************************/
|
|
|
|
/* Component library edit field manipulation code. */
|
|
|
|
/*****************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
2011-05-31 16:29:14 +00:00
|
|
|
//#include "protos.h"
|
|
|
|
#include "sch_component.h"
|
2010-02-16 16:21:52 +00:00
|
|
|
#include "libeditframe.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "template_fieldnames.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
void LIB_EDIT_FRAME::EditField( wxDC* DC, 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
|
|
|
|
{
|
|
|
|
caption = _( "Edit Field" );
|
|
|
|
title.Printf( _( "Enter a new value for the %s field." ),
|
|
|
|
GetChars( aField->GetName().Lower() ) );
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
wxTextEntryDialog dlg( this, title, caption, aField->m_Text );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == aField->m_Text )
|
2010-10-22 12:11:52 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
text = dlg.GetValue();
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
text.Replace( wxT( " " ), wxT( "_" ) );
|
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
|
|
|
*/
|
2010-12-07 16:10:42 +00:00
|
|
|
if( aField->GetId() == VALUE )
|
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() )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2010-10-22 12:11:52 +00:00
|
|
|
SaveCopyInUndoList( parent );
|
2011-04-27 19:44:32 +00:00
|
|
|
( (LIB_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode,
|
|
|
|
&fieldText, DefaultTransform );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-12-02 21:41:56 +00:00
|
|
|
fieldText = aField->GetFullText( m_unit );
|
2011-04-27 19:44:32 +00:00
|
|
|
( (LIB_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode,
|
|
|
|
&fieldText, DefaultTransform );
|
2010-10-22 12:11:52 +00:00
|
|
|
}
|
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
|
|
|
}
|