2009-01-29 14:26:20 +00:00
|
|
|
/****************************/
|
2009-09-02 18:12:45 +00:00
|
|
|
/* EESchema - libedit.cpp */
|
2009-01-29 14:26:20 +00:00
|
|
|
/****************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "macros.h"
|
2010-03-18 20:35:29 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "gestfich.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "eeschema_id.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.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-05-06 16:03:28 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
#include "dialogs/dialog_lib_new_component.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
/* Update the main window title bar with the current library name. */
|
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 )
|
|
|
|
msg += m_library->GetFullFileName();
|
2009-09-14 13:24:17 +00:00
|
|
|
else
|
|
|
|
msg += _( "no library selected" );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
SetTitle( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/* Function to select the current library (working library) */
|
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 );
|
|
|
|
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
|
|
|
}
|
|
|
|
DisplayLibInfos();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
/*
|
|
|
|
* function LoadComponentAndSelectLib
|
|
|
|
* Select the current active library.
|
|
|
|
* aLibrary = the CMP_LIBRARY aLibrary to select
|
|
|
|
* aLibEntry = the lib component to load from aLibrary (can be an alias
|
|
|
|
* return true if OK.
|
|
|
|
*/
|
|
|
|
bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary )
|
|
|
|
{
|
|
|
|
if( GetScreen()->IsModify()
|
|
|
|
&& !IsOK( this, _( "Current part not saved.\n\nDiscard current changes?" ) ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SelectActiveLibrary( aLibrary );
|
|
|
|
return LoadComponentFromCurrentLib( aLibEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function LoadComponentFromCurrentLib
|
|
|
|
* load a lib component from the current active library.
|
|
|
|
* @param aLibEntry = the lib component to load from aLibrary (can be an alias
|
|
|
|
* @return true if OK.
|
|
|
|
*/
|
|
|
|
bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry )
|
|
|
|
{
|
|
|
|
if( !LoadOneLibraryPartAux( aLibEntry, m_library ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
g_EditPinByPinIsOn = m_component->UnitsLocked() ? true : false;
|
|
|
|
m_HToolBar->ToggleTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, g_EditPinByPinIsOn );
|
|
|
|
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
SetShowDeMorgan( m_component->HasConversion() );
|
|
|
|
m_HToolBar->Refresh();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function LoadOneLibraryPart
|
2009-03-10 08:26:52 +00:00
|
|
|
* load a library component from the current selected library
|
|
|
|
* Prompt user for component name
|
|
|
|
* If there is no current selected library,
|
|
|
|
* prompt user for library name and make the selected library the current lib.
|
|
|
|
*/
|
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
|
|
|
int i;
|
|
|
|
wxString msg;
|
|
|
|
wxString CmpName;
|
|
|
|
LIB_ALIAS* LibEntry = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-02-24 20:22:12 +00:00
|
|
|
DrawPanel->EndMouseCapture( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor() );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( GetScreen()->IsModify()
|
2010-10-25 15:43:42 +00:00
|
|
|
&& !IsOK( this, _( "Current part 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();
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
i = GetNameOfPartToLoad( this, m_library, CmpName );
|
2009-01-29 14:26:20 +00:00
|
|
|
if( i == 0 )
|
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
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
SAFE_DELETE( m_component );
|
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 */
|
2009-09-25 18:49:04 +00:00
|
|
|
LibEntry = m_library->FindEntry( CmpName );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
if( LibEntry == NULL )
|
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
msg.Printf( _( "Component name \"%s\" not found in library \"%s\"." ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( CmpName ),
|
|
|
|
GetChars( m_library->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
|
|
|
}
|
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
if( ! LoadComponentFromCurrentLib( LibEntry ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Routine to load into memory a copy of 1 library part.
|
|
|
|
* Returns
|
|
|
|
* 0 if OK
|
|
|
|
* 1 if error
|
|
|
|
* m_component advanced copy and created
|
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
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
SAFE_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
|
|
|
{
|
|
|
|
msg.Printf( _( "Could not create copy of part <%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
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/* Function to redraw the current loaded library component */
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
if( GetScreen() == NULL )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
DrawPanel->DrawBackGround( DC );
|
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
|
|
|
|
LIB_FIELD* Field = m_component->GetField( REFERENCE );
|
|
|
|
wxString fieldText = Field->m_Text;
|
|
|
|
wxString fieldfullText = Field->GetFullText( m_unit );
|
|
|
|
Field->m_Text = fieldfullText;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), m_unit,
|
|
|
|
m_convert, GR_DEFAULT_DRAWMODE );
|
2010-07-20 10:30:40 +00:00
|
|
|
Field->m_Text = fieldText;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Save (on disk) the current library
|
2009-03-10 08:26:52 +00:00
|
|
|
* if exists the old file is renamed (.bak)
|
2009-01-29 14:26:20 +00:00
|
|
|
*/
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
|
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-02-24 20:22:12 +00:00
|
|
|
DrawPanel->EndMouseCapture( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor() );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( GetScreen()->IsModify() )
|
|
|
|
{
|
|
|
|
if( IsOK( this, _( "Include last component changes?" ) ) )
|
|
|
|
SaveOnePartInMemory();
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library == NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
DisplayError( this, wxT( "No library specified." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( event.GetId() == ID_LIBEDIT_SAVE_CURRENT_LIB_AS )
|
|
|
|
{ // Get a new name for the library
|
|
|
|
wxString default_path = wxGetApp().ReturnLastVisitedLibraryPath();
|
|
|
|
wxFileDialog dlg( this, _( "Component Library Name:" ), default_path,
|
|
|
|
wxEmptyString, CompLibFileWildcard,
|
|
|
|
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 )
|
|
|
|
return;
|
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() )
|
|
|
|
fn.SetExt( SymbolFileExtension );
|
|
|
|
|
|
|
|
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fn = wxFileName( m_library->GetFullFileName() );
|
|
|
|
|
|
|
|
msg = _( "Modify library file \"" ) + fn.GetFullPath() + _( "\"?" );
|
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
bool success = m_library->Save( fn.GetFullPath(), true );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
if( !success )
|
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
msg = _( "Error while saving library file \"" ) + fn.GetFullPath() + _( "\"." );
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
2009-01-29 14:26:20 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
msg = _( "Library file \"" ) + fn.GetFullName() + wxT( "\" Ok" );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( DOC_EXT );
|
2010-10-04 18:54:14 +00:00
|
|
|
wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() + wxT( "\" Ok" );
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( msg, msg1, BLUE );
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Display the documentation of the selected component.
|
|
|
|
*
|
|
|
|
* Used when displaying the list of library components.
|
2009-01-29 14:26:20 +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
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
AppendMsgPanel( _( "Part" ), 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
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Delete component in the current library.
|
|
|
|
*
|
|
|
|
* (Delete only in memory, the file does not change)
|
|
|
|
*
|
|
|
|
* The entry can be an alias or a component.
|
|
|
|
* If an alias:
|
|
|
|
* It is removed, and the list of alias is updated.
|
|
|
|
*
|
|
|
|
* If a component:
|
|
|
|
* If the list of aliases is zero, it deletes the component
|
|
|
|
* Otherwise the alias becomes the new component name, and the other
|
|
|
|
* aliases become dependent on newly named component.
|
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-02-24 20:22:12 +00:00
|
|
|
DrawPanel->EndMouseCapture( ID_NO_TOOL_SELECTED, DrawPanel->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
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +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
|
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
SAFE_DELETE( m_component );
|
|
|
|
m_aliasName.Empty();
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
DrawPanel->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
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Routine to create a new library component
|
|
|
|
*
|
|
|
|
* If an old component is currently in edit, it is deleted.
|
2009-01-29 14:26:20 +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-02-24 20:22:12 +00:00
|
|
|
DrawPanel->EndMouseCapture( ID_NO_TOOL_SELECTED, DrawPanel->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;
|
|
|
|
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 );
|
2009-10-21 20:02:25 +00:00
|
|
|
component->GetReferenceField().m_Text = dlg.GetReference();
|
2009-10-08 13:19:28 +00:00
|
|
|
component->SetPartCount( dlg.GetPartCount() );
|
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() );
|
|
|
|
if( dlg.GetPinNameInside( ) )
|
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
component->SetPinNameOffset( dlg.GetPinTextPosition() );
|
|
|
|
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() );
|
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
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
SAFE_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();
|
2010-06-24 18:31:43 +00:00
|
|
|
g_EditPinByPinIsOn = m_component->UnitsLocked() ? true : false;
|
2010-03-05 19:49:08 +00:00
|
|
|
m_HToolBar->ToggleTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, g_EditPinByPinIsOn );
|
2009-09-25 18:49:04 +00:00
|
|
|
m_lastDrawItem = NULL;
|
2009-09-22 12:27:57 +00:00
|
|
|
GetScreen()->ClearUndoRedoList();
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2009-09-22 12:27:57 +00:00
|
|
|
DrawPanel->Refresh();
|
2010-03-05 19:49:08 +00:00
|
|
|
m_HToolBar->Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Routine backup of "partlib" current in the current library.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Save in memory only and NOT on file.
|
|
|
|
* The routine deletes the old component (and / or aliases) to replace
|
|
|
|
* If any, and saves the new and creates the corresponding alias.
|
2009-01-29 14:26:20 +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;
|
|
|
|
LIB_COMPONENT* Component;
|
|
|
|
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
|
|
|
{
|
2010-12-02 21:41:56 +00:00
|
|
|
msg.Printf( _( "Component \"%s\" already exists. Change it?" ),
|
|
|
|
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 )
|
2009-09-25 18:49:04 +00:00
|
|
|
Component = m_library->ReplaceComponent( oldComponent, m_component );
|
2009-09-14 13:24:17 +00:00
|
|
|
else
|
2009-09-25 18:49:04 +00:00
|
|
|
Component = m_library->AddComponent( m_component );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( Component == NULL )
|
|
|
|
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" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( Component->GetName() ),
|
|
|
|
GetChars( m_library->GetName() ) );
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|