2011-10-28 13:43:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-01-01 20:52:37 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
|
2011-10-28 13:43:37 +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
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file libedit.cpp
|
|
|
|
* @brief Eeschema component library editor.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <kiway.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <class_sch_screen.h>
|
|
|
|
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <libeditframe.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <template_fieldnames.h>
|
2012-09-28 17:47:41 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <dialogs/dialog_lib_new_component.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::DisplayLibInfos()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
wxString msg = _( "Component Library Editor: " );
|
|
|
|
|
2009-12-22 20:08:56 +00:00
|
|
|
EnsureActiveLibExists();
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library )
|
2011-08-12 17:43:16 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
msg += m_library->GetFullFileName();
|
2011-08-12 17:43:16 +00:00
|
|
|
|
|
|
|
if( m_library->IsReadOnly() )
|
|
|
|
msg += _( " [Read Only]" );
|
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
else
|
2011-08-12 17:43:16 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
msg += _( "no library selected" );
|
2011-08-12 17:43:16 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
SetTitle( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
void LIB_EDIT_FRAME::SelectActiveLibrary( CMP_LIBRARY* aLibrary )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-05-28 18:51:32 +00:00
|
|
|
if( aLibrary == NULL )
|
|
|
|
aLibrary = SelectLibraryFromList( this );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
if( aLibrary )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2011-05-28 18:51:32 +00:00
|
|
|
m_library = aLibrary;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
DisplayLibInfos();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary )
|
|
|
|
{
|
|
|
|
if( GetScreen()->IsModify()
|
2013-11-09 16:30:49 +00:00
|
|
|
&& !IsOK( this, _( "The current component is not saved.\n\nDiscard current changes?" ) ) )
|
2011-05-28 18:51:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
SelectActiveLibrary( aLibrary );
|
|
|
|
return LoadComponentFromCurrentLib( aLibEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry )
|
|
|
|
{
|
|
|
|
if( !LoadOneLibraryPartAux( aLibEntry, m_library ) )
|
|
|
|
return false;
|
|
|
|
|
2011-10-28 13:43:37 +00:00
|
|
|
m_editPinsPerPartOrConvert = m_component->UnitsLocked() ? true : false;
|
2011-05-28 18:51:32 +00:00
|
|
|
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
SetShowDeMorgan( m_component->HasConversion() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
wxString msg;
|
|
|
|
wxString CmpName;
|
2012-02-19 19:53:11 +00:00
|
|
|
LIB_ALIAS* libEntry = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( GetScreen()->IsModify()
|
2014-01-19 13:12:57 +00:00
|
|
|
&& !IsOK( this, _( "The current component is not saved.\n\nDiscard current changes?" ) ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
// No current lib, ask user for the library to use.
|
|
|
|
if( m_library == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
SelectActiveLibrary();
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
wxArrayString dummyHistoryList;
|
|
|
|
int dummyLastUnit;
|
|
|
|
CmpName = SelectComponentFromLibrary( m_library->GetName(), dummyHistoryList, dummyLastUnit,
|
|
|
|
true, NULL, NULL );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( CmpName.IsEmpty() )
|
2009-09-25 18:49:04 +00:00
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
GetScreen()->ClrModify();
|
2009-09-25 18:49:04 +00:00
|
|
|
m_lastDrawItem = m_drawItem = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
// Delete previous library component, if any
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2013-04-28 14:28:13 +00:00
|
|
|
delete m_component;
|
|
|
|
m_component = NULL;
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliasName.Empty();
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
/* Load the new library component */
|
2012-02-19 19:53:11 +00:00
|
|
|
libEntry = m_library->FindEntry( CmpName );
|
|
|
|
CMP_LIBRARY* searchLib = m_library;
|
2013-11-09 16:30:49 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( libEntry == NULL )
|
|
|
|
{ // Not found in the active library: search inside the full list
|
|
|
|
// (can happen when using Viewlib to load a component)
|
|
|
|
libEntry = CMP_LIBRARY::FindLibraryEntry( CmpName );
|
2013-11-09 16:30:49 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( libEntry )
|
|
|
|
{
|
|
|
|
searchLib = libEntry->GetLibrary();
|
|
|
|
// The entry to load is not in the active lib
|
|
|
|
// Ask for a new active lib
|
|
|
|
wxString msg;
|
|
|
|
msg << _("The selected component is not in the active library");
|
|
|
|
msg << wxT("\n\n");
|
|
|
|
msg << _("Do you want to change the active library?");
|
2013-11-09 16:30:49 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( IsOK( this, msg ) )
|
|
|
|
SelectActiveLibrary( searchLib );
|
|
|
|
}
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( libEntry == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Component name %s not found in library %s" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( CmpName ),
|
2012-02-19 19:53:11 +00:00
|
|
|
GetChars( searchLib->GetName() ) );
|
2009-08-27 11:41:56 +00:00
|
|
|
DisplayError( this, msg );
|
2009-09-25 18:49:04 +00:00
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
EXCHG( searchLib, m_library );
|
|
|
|
LoadComponentFromCurrentLib( libEntry );
|
|
|
|
EXCHG( searchLib, m_library );
|
|
|
|
DisplayLibInfos();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, CMP_LIBRARY* aLibrary )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
wxString msg, cmpName, rootName;
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* component;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( ( aEntry == NULL ) || ( aLibrary == NULL ) )
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( aEntry->GetName().IsEmpty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxT( "Entry in library <%s> has empty name field." ),
|
2010-10-04 18:54:14 +00:00
|
|
|
GetChars( aLibrary->GetName() ) );
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
cmpName = m_aliasName = aEntry->GetName();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* alias = (LIB_ALIAS*) aEntry;
|
|
|
|
component = alias->GetComponent();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
wxASSERT( component != NULL );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ),
|
|
|
|
GetChars( cmpName ),
|
|
|
|
GetChars( component->GetName() ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component )
|
2010-10-04 18:54:14 +00:00
|
|
|
{
|
2013-04-28 14:28:13 +00:00
|
|
|
delete m_component;
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliasName.Empty();
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_component = new LIB_COMPONENT( *component );
|
2009-08-27 19:44:13 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component == NULL )
|
2009-08-27 19:44:13 +00:00
|
|
|
{
|
2013-11-09 16:30:49 +00:00
|
|
|
msg.Printf( _( "Could not create copy of component <%s> in library <%s>." ),
|
2010-10-04 18:54:14 +00:00
|
|
|
GetChars( aEntry->GetName() ),
|
|
|
|
GetChars( aLibrary->GetName() ) );
|
2009-08-27 19:44:13 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
m_aliasName = aEntry->GetName();
|
2009-09-25 18:49:04 +00:00
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_showDeMorgan = false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
if( m_component->HasConversion() )
|
2009-09-25 18:49:04 +00:00
|
|
|
m_showDeMorgan = true;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
GetScreen()->ClrModify();
|
2009-09-14 13:24:17 +00:00
|
|
|
DisplayLibInfos();
|
|
|
|
UpdateAliasSelectList();
|
|
|
|
UpdatePartSelectList();
|
|
|
|
|
|
|
|
/* Display the document information based on the entry selected just in
|
|
|
|
* case the entry is an alias. */
|
2009-09-18 14:56:05 +00:00
|
|
|
DisplayCmpDoc();
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2012-03-06 14:08:59 +00:00
|
|
|
void LIB_EDIT_FRAME::RedrawComponent( wxDC* aDC, wxPoint aOffset )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component )
|
2010-07-20 10:30:40 +00:00
|
|
|
{
|
|
|
|
// display reference like in schematic (a reference U is shown U? or U?A)
|
|
|
|
// although it is stored without ? and part id.
|
|
|
|
// So temporary change the reference by a schematic like reference
|
2013-05-28 08:05:10 +00:00
|
|
|
LIB_FIELD* field = m_component->GetField( REFERENCE );
|
|
|
|
wxString fieldText = field->GetText();
|
|
|
|
wxString fieldfullText = field->GetFullText( m_unit );
|
|
|
|
field->EDA_TEXT::SetText( fieldfullText ); // change the field text string only
|
2013-11-09 16:30:49 +00:00
|
|
|
m_component->Draw( m_canvas, aDC, aOffset, m_unit, m_convert, GR_DEFAULT_DRAWMODE );
|
2013-05-28 08:05:10 +00:00
|
|
|
field->EDA_TEXT::SetText( fieldText ); // restore the field text string
|
2010-07-20 10:30:40 +00:00
|
|
|
}
|
2012-03-06 14:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
|
|
|
{
|
|
|
|
if( GetScreen() == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_canvas->DrawBackGround( DC );
|
|
|
|
|
|
|
|
RedrawComponent( DC, wxPoint( 0, 0 ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->DrawCrossHair( DC );
|
2010-01-22 18:13:43 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
DisplayLibInfos();
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-07 17:35:37 +00:00
|
|
|
void LIB_EDIT_FRAME::OnSaveActiveLibrary( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
bool newFile = false;
|
|
|
|
if( event.GetId() == ID_LIBEDIT_SAVE_CURRENT_LIB_AS )
|
|
|
|
newFile = true;
|
|
|
|
|
|
|
|
this->SaveActiveLibrary( newFile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-08-27 11:41:56 +00:00
|
|
|
wxString msg;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
if( m_library == NULL )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-08-12 17:43:16 +00:00
|
|
|
DisplayError( this, _( "No library specified." ) );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
if( GetScreen()->IsModify() )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2011-08-12 17:43:16 +00:00
|
|
|
if( IsOK( this, _( "Include last component changes?" ) ) )
|
|
|
|
SaveOnePartInMemory();
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-07 17:35:37 +00:00
|
|
|
if( newFile )
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
{
|
|
|
|
PROJECT& prj = Prj();
|
|
|
|
SEARCH_STACK& search = prj.SchSearchS();
|
|
|
|
|
|
|
|
// Get a new name for the library
|
|
|
|
wxString default_path = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
wxFileDialog dlg( this, _( "Component Library Name:" ), default_path,
|
2012-09-28 17:47:41 +00:00
|
|
|
wxEmptyString, SchematicLibraryFileExtension,
|
2010-03-18 20:35:29 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
fn = dlg.GetPath();
|
|
|
|
|
|
|
|
/* The GTK file chooser doesn't return the file extension added to
|
|
|
|
* file name so add it here. */
|
|
|
|
if( fn.GetExt().IsEmpty() )
|
2012-09-28 17:47:41 +00:00
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
2010-03-18 20:35:29 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( fn.GetPath() );
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fn = wxFileName( m_library->GetFullFileName() );
|
|
|
|
|
2013-05-24 21:30:27 +00:00
|
|
|
msg.Printf( _( "Modify library file <%s> ?" ),
|
2013-04-09 17:49:01 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2010-03-18 20:35:29 +00:00
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
// Verify the user has write privileges before attempting to save the library file.
|
2011-08-18 19:25:12 +00:00
|
|
|
if( !IsWritable( fn ) )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
wxFileName libFileName = fn;
|
|
|
|
wxFileName backupFileName = fn;
|
|
|
|
|
|
|
|
// Rename the old .lib file to .bak.
|
|
|
|
if( libFileName.FileExists() )
|
|
|
|
{
|
|
|
|
backupFileName.SetExt( wxT( "bak" ) );
|
2011-12-27 18:08:50 +00:00
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
2011-11-11 20:10:24 +00:00
|
|
|
|
|
|
|
if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
libFileName.MakeAbsolute();
|
|
|
|
msg = wxT( "Failed to rename old component library file " ) +
|
|
|
|
backupFileName.GetFullPath();
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FILE_OUTPUTFORMATTER libFormatter( libFileName.GetFullPath() );
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
if( !m_library->Save( libFormatter ) )
|
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Error occurred while saving library file <%s>" ),
|
|
|
|
GetChars( fn.GetFullPath() ) );
|
2012-10-25 15:41:20 +00:00
|
|
|
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
|
|
|
DisplayError( this, msg );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2012-10-25 15:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... /* IO_ERROR ioe */ )
|
2011-11-11 20:10:24 +00:00
|
|
|
{
|
|
|
|
libFileName.MakeAbsolute();
|
2013-05-24 21:30:27 +00:00
|
|
|
msg.Printf( _( "Failed to create component library file <%s>" ),
|
2013-04-09 17:49:01 +00:00
|
|
|
GetChars( libFileName.GetFullPath() ) );
|
2011-11-11 20:10:24 +00:00
|
|
|
DisplayError( this, msg );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName docFileName = libFileName;
|
|
|
|
|
|
|
|
docFileName.SetExt( DOC_EXT );
|
|
|
|
|
|
|
|
// Rename .doc file to .bck.
|
|
|
|
if( docFileName.FileExists() )
|
|
|
|
{
|
|
|
|
backupFileName.SetExt( wxT( "bck" ) );
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
2011-12-27 18:08:50 +00:00
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
2011-11-11 20:10:24 +00:00
|
|
|
|
|
|
|
if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
msg = wxT( "Failed to save old library document file " ) +
|
|
|
|
backupFileName.GetFullPath();
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FILE_OUTPUTFORMATTER docFormatter( docFileName.GetFullPath() );
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
if( !m_library->SaveDocs( docFormatter ) )
|
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Error occurred while saving library documentation file <%s>" ),
|
|
|
|
GetChars( docFileName.GetFullPath() ) );
|
2012-10-25 15:41:20 +00:00
|
|
|
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
|
|
|
DisplayError( this, msg );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2012-10-25 15:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... /* IO_ERROR ioe */ )
|
2011-11-11 20:10:24 +00:00
|
|
|
{
|
|
|
|
docFileName.MakeAbsolute();
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Failed to create component document library file <%s>" ),
|
|
|
|
GetChars( docFileName.GetFullPath() ) );
|
2011-11-11 20:10:24 +00:00
|
|
|
DisplayError( this, msg );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Library file <%s> OK" ), GetChars( fn.GetFullName() ) );
|
2011-11-11 20:10:24 +00:00
|
|
|
fn.SetExt( DOC_EXT );
|
2013-04-09 17:49:01 +00:00
|
|
|
wxString msg1;
|
|
|
|
msg1.Printf( _( "Documentation file <%s> OK" ), GetChars( fn.GetFullPath() ) );
|
2011-11-11 20:10:24 +00:00
|
|
|
AppendMsgPanel( msg, msg1, BLUE );
|
2013-02-07 17:35:37 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::DisplayCmpDoc()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString msg;
|
2010-10-04 18:54:14 +00:00
|
|
|
LIB_ALIAS* alias;
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL || m_component == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
msg = m_component->GetName();
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2013-11-09 16:30:49 +00:00
|
|
|
AppendMsgPanel( _( "Name" ), msg, BLUE, 8 );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( m_aliasName == m_component->GetName() )
|
2009-09-18 14:56:05 +00:00
|
|
|
msg = _( "None" );
|
|
|
|
else
|
2009-09-25 18:49:04 +00:00
|
|
|
msg = m_aliasName;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
alias = m_component->GetAlias( m_aliasName );
|
|
|
|
|
|
|
|
wxCHECK_RET( alias != NULL, wxT( "Alias not found in component." ) );
|
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( _( "Alias" ), msg, RED, 8 );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
|
2009-09-25 18:49:04 +00:00
|
|
|
msg = UnitLetter[m_unit];
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( _( "Unit" ), msg, BROWN, 8 );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_convert > 1 )
|
2009-09-18 14:56:05 +00:00
|
|
|
msg = _( "Convert" );
|
|
|
|
else
|
|
|
|
msg = _( "Normal" );
|
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( _( "Body" ), msg, GREEN, 8 );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( m_component->IsPower() )
|
2009-09-18 14:56:05 +00:00
|
|
|
msg = _( "Power Symbol" );
|
|
|
|
else
|
|
|
|
msg = _( "Component" );
|
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 );
|
2010-10-04 18:54:14 +00:00
|
|
|
AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 8 );
|
|
|
|
AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
|
|
|
|
AppendMsgPanel( _( "Datasheet" ), alias->GetDocFileName(), DARKDARKGRAY );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
wxString CmpName;
|
|
|
|
LIB_ALIAS* LibEntry;
|
|
|
|
wxArrayString ListNames;
|
|
|
|
wxString msg;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_lastDrawItem = NULL;
|
|
|
|
m_drawItem = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
SelectActiveLibrary();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
DisplayError( this, _( "Please select a component library." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_library->GetEntryNames( ListNames );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( ListNames.IsEmpty() )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
msg.Printf( _( "Component library <%s> is empty." ), GetChars( m_library->GetName() ) );
|
|
|
|
wxMessageBox( msg, _( "Delete Entry Error" ), wxID_OK | wxICON_EXCLAMATION, this );
|
2009-08-27 11:41:56 +00:00
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
msg.Printf( _( "Select 1 of %d components to delete\nfrom library <%s>." ),
|
2009-09-25 18:49:04 +00:00
|
|
|
ListNames.GetCount(),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( m_library->GetName() ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
wxSingleChoiceDialog dlg( this, msg, _( "Delete Component" ), ListNames );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
LibEntry = m_library->FindEntry( dlg.GetStringSelection() );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( LibEntry == NULL )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Entry <%s> not found in library <%s>." ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( dlg.GetStringSelection() ),
|
|
|
|
GetChars( m_library->GetName() ) );
|
2009-08-27 11:41:56 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Delete component %s from library %s?" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( LibEntry->GetName() ),
|
|
|
|
GetChars( m_library->GetName() ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( m_component == NULL || !m_component->HasAlias( LibEntry->GetName() ) )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
m_library->RemoveEntry( LibEntry );
|
2009-09-14 13:24:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If deleting the current entry or removing one of the aliases for
|
|
|
|
* the current entry, sync the changes in the current entry as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( GetScreen()->IsModify()
|
2009-09-28 19:28:22 +00:00
|
|
|
&& !IsOK( this, _( "The component being deleted has been modified. \
|
2009-09-14 13:24:17 +00:00
|
|
|
All changes will be lost. Discard changes?" ) ) )
|
|
|
|
return;
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* nextEntry = m_library->RemoveEntry( LibEntry );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( nextEntry != NULL )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
if( LoadOneLibraryPartAux( nextEntry, m_library ) )
|
|
|
|
Zoom_Automatique( false );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-28 14:28:13 +00:00
|
|
|
delete m_component;
|
|
|
|
m_component = NULL;
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliasName.Empty();
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2009-08-27 11:41:56 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::CreateNewLibraryPart( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
wxString name;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component && GetScreen()->IsModify()
|
2009-09-22 12:27:57 +00:00
|
|
|
&& !IsOK( this, _( "All changes to the current component will be \
|
|
|
|
lost!\n\nClear the current component from the screen?" ) ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
DIALOG_LIB_NEW_COMPONENT dlg( this );
|
2009-12-01 15:14:18 +00:00
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
2009-10-08 13:19:28 +00:00
|
|
|
|
|
|
|
if( dlg.GetName().IsEmpty() )
|
2009-10-10 17:27:53 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
wxMessageBox( _( "This new component has no name and cannot be created. Aborted" ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
2009-10-10 17:27:53 +00:00
|
|
|
}
|
2009-10-08 13:19:28 +00:00
|
|
|
|
2010-10-22 15:02:11 +00:00
|
|
|
#ifndef KICAD_KEEPCASE
|
2009-10-08 13:19:28 +00:00
|
|
|
name = dlg.GetName().MakeUpper();
|
2010-10-22 15:02:11 +00:00
|
|
|
#else
|
|
|
|
name = dlg.GetName();
|
|
|
|
#endif
|
2009-10-08 13:19:28 +00:00
|
|
|
name.Replace( wxT( " " ), wxT( "_" ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Test if there a component with this name already. */
|
2009-10-08 13:19:28 +00:00
|
|
|
if( m_library && m_library->FindEntry( name ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
wxString msg;
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Component %s already exists in library %s" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( name ),
|
|
|
|
GetChars( m_library->GetName() ) );
|
2009-10-08 13:19:28 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_COMPONENT* component = new LIB_COMPONENT( name );
|
2013-03-18 19:36:07 +00:00
|
|
|
component->GetReferenceField().SetText( dlg.GetReference() );
|
2009-10-08 13:19:28 +00:00
|
|
|
component->SetPartCount( dlg.GetPartCount() );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
// Initialize component->m_TextInside member:
|
|
|
|
// if 0, pin text is outside the body (on the pin)
|
|
|
|
// if > 0, pin text is inside the body
|
2009-10-08 13:19:28 +00:00
|
|
|
component->SetConversion( dlg.GetAlternateBodyStyle() );
|
2009-10-10 17:27:53 +00:00
|
|
|
SetShowDeMorgan( dlg.GetAlternateBodyStyle() );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
|
|
|
if( dlg.GetPinNameInside() )
|
2009-10-10 17:27:53 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
component->SetPinNameOffset( dlg.GetPinTextPosition() );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
if( component->GetPinNameOffset() == 0 )
|
|
|
|
component->SetPinNameOffset( 1 );
|
2009-10-10 17:27:53 +00:00
|
|
|
}
|
|
|
|
else
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
component->SetPinNameOffset( 0 );
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
( dlg.GetPowerSymbol() ) ? component->SetPower() : component->SetNormal();
|
2010-06-24 18:31:43 +00:00
|
|
|
component->SetShowPinNumbers( dlg.GetShowPinNumber() );
|
|
|
|
component->SetShowPinNames( dlg.GetShowPinName() );
|
|
|
|
component->LockUnits( dlg.GetLockItems() );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( dlg.GetPartCount() < 2 )
|
2010-06-24 18:31:43 +00:00
|
|
|
component->LockUnits( false );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliasName = component->GetName();
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2013-04-28 14:28:13 +00:00
|
|
|
delete m_component;
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliasName.Empty();
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
2009-10-08 13:19:28 +00:00
|
|
|
|
|
|
|
m_component = component;
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliasName = m_component->GetName();
|
2009-09-25 18:49:04 +00:00
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
2009-01-29 14:26:20 +00:00
|
|
|
DisplayLibInfos();
|
2009-09-18 14:56:05 +00:00
|
|
|
DisplayCmpDoc();
|
2009-09-22 12:27:57 +00:00
|
|
|
UpdateAliasSelectList();
|
|
|
|
UpdatePartSelectList();
|
2011-10-28 13:43:37 +00:00
|
|
|
m_editPinsPerPartOrConvert = m_component->UnitsLocked() ? true : false;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_lastDrawItem = NULL;
|
2009-09-22 12:27:57 +00:00
|
|
|
GetScreen()->ClearUndoRedoList();
|
2011-08-12 17:43:16 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2011-12-16 13:32:23 +00:00
|
|
|
m_mainToolBar->Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::SaveOnePartInMemory()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* oldComponent;
|
2013-05-24 21:30:27 +00:00
|
|
|
LIB_COMPONENT* component;
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString msg;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
DisplayError( this, _( "No component to save." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
SelectActiveLibrary();
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
DisplayError( this, _( "No library specified." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
GetScreen()->ClrModify();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
oldComponent = m_library->FindComponent( m_component->GetName() );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( oldComponent != NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Component %s already exists. Change it?" ),
|
2010-12-02 21:41:56 +00:00
|
|
|
GetChars( m_component->GetName() ) );
|
2010-10-22 12:11:52 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = m_lastDrawItem = NULL;
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( oldComponent != NULL )
|
2013-05-24 21:30:27 +00:00
|
|
|
component = m_library->ReplaceComponent( oldComponent, m_component );
|
2009-09-14 13:24:17 +00:00
|
|
|
else
|
2013-05-24 21:30:27 +00:00
|
|
|
component = m_library->AddComponent( m_component );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2013-05-24 21:30:27 +00:00
|
|
|
if( component == NULL )
|
2009-08-27 11:41:56 +00:00
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
msg.Printf( _( "Component %s saved in library %s" ),
|
2013-05-24 21:30:27 +00:00
|
|
|
GetChars( component->GetName() ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( m_library->GetName() ) );
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|