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
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PART* 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
|
|
|
*/
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( aField->GetId() == VALUE && text != aField->GetText() )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
PART_LIB* lib = GetCurLib();
|
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
// Test the current library for name conflicts.
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( lib && lib->FindEntry( text ) )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
msg.Printf( _(
|
|
|
|
"The name '%s' conflicts with an existing entry in the component library '%s'.\n\n"
|
|
|
|
"Do you wish to replace the current component in library with this one?" ),
|
|
|
|
GetChars( text ),
|
|
|
|
GetChars( lib->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 ) )
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
msg.Printf( _(
|
|
|
|
"The current component already has an alias named '%s'.\n\n"
|
|
|
|
"Do you wish to remove this alias from the component?" ),
|
|
|
|
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.
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( parent->GetAliasCount() > 1 && lib && lib->Conflicts( parent ) )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
msg.Printf( _(
|
|
|
|
"The new component contains alias names that conflict with entries in the component library '%s'.\n\n"
|
|
|
|
"Do you wish to remove all of the conflicting aliases from this component?" ),
|
|
|
|
GetChars( lib->GetName() )
|
|
|
|
);
|
2010-12-02 21:41:56 +00:00
|
|
|
|
|
|
|
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++ )
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( lib->FindEntry( aliases[ i ] ) != NULL )
|
2010-12-02 21:41:56 +00:00
|
|
|
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
|
|
|
}
|