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>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_component.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#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>
|
2018-01-09 12:48:00 +00:00
|
|
|
|
2017-11-12 19:55:34 +00:00
|
|
|
#include <lib_manager.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <widgets/symbol_tree_pane.h>
|
|
|
|
#include <widgets/lib_tree.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-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 )
|
2018-07-06 17:03:57 +00:00
|
|
|
caption = _( "Edit Component Name" );
|
2010-12-02 21:41:56 +00:00
|
|
|
else
|
2018-07-06 17:03:57 +00:00
|
|
|
caption.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
|
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
|
|
|
|
2018-06-28 12:58:22 +00:00
|
|
|
newFieldValue = LIB_ID::FixIllegalChars( dlg.GetText(), LIB_ID::ID_SCH );
|
2018-01-10 11:08:27 +00:00
|
|
|
wxString oldFieldValue = aField->GetFullText( m_unit );
|
|
|
|
bool renamed = aField->GetId() == VALUE && newFieldValue != oldFieldValue;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2018-01-10 11:08:27 +00:00
|
|
|
if( renamed )
|
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
|
|
|
|
2018-01-10 11:08:27 +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( _(
|
2018-01-10 11:08:27 +00:00
|
|
|
"The name \"%s\" conflicts with an existing entry in the symbol library \"%s\"." ),
|
|
|
|
newFieldValue, lib );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
2018-01-10 11:08:27 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
return;
|
2010-12-02 21:41:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 18:56:01 +00:00
|
|
|
SaveCopyInUndoList( parent, UR_LIB_RENAME );
|
2016-04-02 12:25:44 +00:00
|
|
|
parent->SetName( newFieldValue );
|
2010-12-02 21:41:56 +00:00
|
|
|
|
2018-01-19 18:56:01 +00:00
|
|
|
m_libMgr->UpdatePartAfterRename( parent, oldFieldValue, lib );
|
2018-01-09 12:48:00 +00:00
|
|
|
|
|
|
|
// Reselect the renamed part
|
2018-07-27 20:47:51 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newFieldValue ) );
|
2010-12-02 21:41:56 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2018-01-10 11:08:27 +00:00
|
|
|
if( !aField->InEditMode() && !renamed )
|
2010-10-22 12:11:52 +00:00
|
|
|
SaveCopyInUndoList( parent );
|
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();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|