2014-10-19 22:17:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2007-2017 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2014-10-19 22:17:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
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>
|
2017-10-06 18:07:43 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <template_fieldnames.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
#include <dialog_edit_one_field.h>
|
2017-11-12 19:55:34 +00:00
|
|
|
#include <lib_manager.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
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
wxString newFieldValue;
|
2010-07-20 10:30:40 +00:00
|
|
|
wxString title;
|
2010-12-02 21:41:56 +00:00
|
|
|
wxString caption;
|
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
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
LIB_PART* parent = aField->GetParent();
|
2017-11-12 19:55:34 +00:00
|
|
|
wxCHECK( parent, /* void */ );
|
2014-10-26 11:42:25 +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
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// The dialog may invoke a kiway player for footprint fields
|
|
|
|
// so we must use a quasimodal dialog.
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2010-10-22 12:11:52 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
newFieldValue = dlg.GetText();
|
2010-12-02 21:41:56 +00:00
|
|
|
wxString fieldText = aField->GetFullText( m_unit );
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2017-11-13 17:21:23 +00:00
|
|
|
bool creatingNewComponent = aField->GetId() == VALUE && newFieldValue != aField->GetText();
|
|
|
|
|
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
|
|
|
*/
|
2017-11-13 17:21:23 +00:00
|
|
|
if( creatingNewComponent )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
wxString msg;
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString lib = GetCurLib();
|
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
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
// Test the current library for name conflicts.
|
2017-11-12 19:55:34 +00:00
|
|
|
if( !lib.empty() && m_libMgr->PartExists( newFieldValue, lib ) )
|
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( _(
|
2017-12-24 15:04:02 +00:00
|
|
|
"The name \"%s\" conflicts with an existing entry in the symbol library \"%s\".\n\n"
|
|
|
|
"Do you wish to replace the current symbol in the library with this one?" ),
|
2017-10-06 18:07:43 +00:00
|
|
|
newFieldValue,
|
|
|
|
lib
|
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
|
|
|
);
|
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.
|
2016-04-02 12:25:44 +00:00
|
|
|
if( parent->HasAlias( newFieldValue ) )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "The current component already has an alias named \"%s\".\n\n"
|
2016-04-02 12:25:44 +00:00
|
|
|
"Do you wish to remove this alias from the component?" ),
|
|
|
|
GetChars( newFieldValue ) );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
|
|
|
int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this );
|
|
|
|
|
|
|
|
if( rsp == wxNO )
|
|
|
|
return;
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
parent->RemoveAlias( newFieldValue );
|
2010-12-02 21:41:56 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
parent->SetName( newFieldValue );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
|
|
|
// Test the library for any conflicts with the any aliases in the current component.
|
2017-10-06 18:07:43 +00:00
|
|
|
if( parent->GetAliasCount() > 1 && !lib.empty() )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
2016-10-25 22:43:54 +00:00
|
|
|
bool conflicts = false;
|
|
|
|
wxArrayString libAliasNames, symbolAliasNames;
|
2010-12-02 21:41:56 +00:00
|
|
|
|
2017-11-12 19:55:34 +00:00
|
|
|
libAliasNames = m_libMgr->GetAliasNames( lib );
|
2016-10-25 22:43:54 +00:00
|
|
|
symbolAliasNames = parent->GetAliasNames();
|
2010-12-02 21:41:56 +00:00
|
|
|
|
2016-10-25 22:43:54 +00:00
|
|
|
for( size_t i = 0; i < symbolAliasNames.GetCount(); i++ )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
2016-10-25 22:43:54 +00:00
|
|
|
if( libAliasNames.Index( symbolAliasNames[i] ) != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
conflicts = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-12-02 21:41:56 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 22:43:54 +00:00
|
|
|
if( conflicts )
|
2010-12-02 21:41:56 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
msg.Printf( _( "The new symbol contains alias names that conflict with "
|
2017-12-15 11:37:46 +00:00
|
|
|
"entries in the library \"%s\".\n\n"
|
2016-10-25 22:43:54 +00:00
|
|
|
"Do you wish to remove all of the conflicting aliases from "
|
2017-10-06 18:07:43 +00:00
|
|
|
"this symbol?" ),
|
|
|
|
lib );
|
2016-10-25 22:43:54 +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++ )
|
|
|
|
{
|
2017-11-12 19:55:34 +00:00
|
|
|
if( m_libMgr->GetAlias( aliases[i], lib ) != NULL )
|
2016-10-25 22:43:54 +00:00
|
|
|
parent->RemoveAlias( aliases[ i ] );
|
|
|
|
}
|
2010-12-02 21:41:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !parent->HasAlias( m_aliasName ) )
|
2016-04-02 12:25:44 +00:00
|
|
|
m_aliasName = newFieldValue;
|
2017-11-12 19:55:34 +00:00
|
|
|
|
2018-01-09 08:37:31 +00:00
|
|
|
if( newFieldValue != fieldText )
|
|
|
|
m_libMgr->RemovePart( fieldText, lib );
|
|
|
|
|
|
|
|
m_libMgr->UpdatePart( parent, lib );
|
2010-12-02 21:41:56 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
|
2017-11-13 17:21:23 +00:00
|
|
|
if( !aField->InEditMode() && !creatingNewComponent )
|
|
|
|
{
|
2010-10-22 12:11:52 +00:00
|
|
|
SaveCopyInUndoList( parent );
|
2017-11-13 17:21:23 +00:00
|
|
|
}
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2017-11-13 17:21:23 +00:00
|
|
|
dlg.UpdateField( aField );
|
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
|
|
|
}
|