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
|
|
|
|
|
|
|
|
|
/* Routines de maintenanace des librairies:
|
2009-01-29 14:26:20 +00:00
|
|
|
|
* sauvegarde, modification de librairies.
|
|
|
|
|
* creation edition suppression de composants
|
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
|
#include "confirm.h"
|
|
|
|
|
#include "gestfich.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "libcmp.h"
|
|
|
|
|
#include "general.h"
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
#include "id.h"
|
|
|
|
|
#include "dialog_create_component.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Affiche dans la zone messages la librairie , et le composant edite */
|
2009-08-27 11:41:56 +00:00
|
|
|
|
void WinEDA_LibeditFrame::DisplayLibInfos()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
|
wxString msg = wxT( "Libedit: " );
|
|
|
|
|
|
|
|
|
|
msg += CurrentLib ? CurrentLib->m_FullFileName : wxT( "No Lib" );
|
|
|
|
|
SetTitle( msg );
|
|
|
|
|
|
|
|
|
|
msg = _( " Part: " );
|
|
|
|
|
if( CurrentLibEntry == NULL )
|
|
|
|
|
{
|
|
|
|
|
msg += _( "None" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
msg += CurrentLibEntry->m_Name.m_Text;
|
|
|
|
|
if( !CurrentAliasName.IsEmpty() )
|
|
|
|
|
msg << wxT( " Alias " ) << CurrentAliasName;
|
|
|
|
|
}
|
2009-03-10 08:26:52 +00:00
|
|
|
|
static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
msg << wxT( " Unit " ) << UnitLetter[CurrentUnit];
|
|
|
|
|
|
|
|
|
|
if( CurrentConvert > 1 )
|
|
|
|
|
msg += _( " Convert" );
|
|
|
|
|
else
|
|
|
|
|
msg += _( " Normal" );
|
|
|
|
|
|
|
|
|
|
if( CurrentLibEntry && (CurrentLibEntry->m_Options == ENTRY_POWER) )
|
|
|
|
|
msg += _( " (Power Symbol)" );
|
|
|
|
|
|
|
|
|
|
SetStatusText( msg, 0 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
/* Function to select the current library (working library) */
|
2007-09-13 11:55:46 +00:00
|
|
|
|
void WinEDA_LibeditFrame::SelectActiveLibrary()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
|
LibraryStruct* Lib;
|
|
|
|
|
|
|
|
|
|
Lib = SelectLibraryFromList( this );
|
|
|
|
|
if( Lib )
|
|
|
|
|
{
|
|
|
|
|
CurrentLib = Lib;
|
|
|
|
|
}
|
|
|
|
|
DisplayLibInfos();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* Function LoadOneLibraryPart()
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2009-08-27 11:41:56 +00:00
|
|
|
|
bool WinEDA_LibeditFrame::LoadOneLibraryPart()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
int i;
|
|
|
|
|
wxString msg;
|
|
|
|
|
wxString CmpName;
|
|
|
|
|
LibCmpEntry* LibEntry = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
if( g_ScreenLib->IsModify() )
|
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
|
if( !IsOK( this, _( "Current part not saved.\nContinue?" ) ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
if( CurrentLib == NULL ) // No current lib, ask user for the library to use
|
2009-01-29 14:26:20 +00:00
|
|
|
|
{
|
|
|
|
|
SelectActiveLibrary();
|
2009-03-10 08:26:52 +00:00
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
return FALSE;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = GetNameOfPartToLoad( this, CurrentLib, CmpName );
|
|
|
|
|
if( i == 0 )
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
g_ScreenLib->ClrModify();
|
|
|
|
|
CurrentDrawItem = NULL;
|
|
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
|
// Delete previous library component, if any
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( CurrentLibEntry )
|
|
|
|
|
{
|
|
|
|
|
SAFE_DELETE( CurrentLibEntry );
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
|
/* Load the new library component */
|
2009-08-27 11:41:56 +00:00
|
|
|
|
LibEntry = CurrentLib->FindEntry( CmpName, ALIAS );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
if( LibEntry == NULL )
|
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
|
msg = _( "Component \"" );
|
|
|
|
|
msg << CmpName << _( "\" not found." );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
DisplayError( this, msg );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
|
|
if( !LoadOneLibraryPartAux( LibEntry, CurrentLib ) )
|
|
|
|
|
return false;
|
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
ReCreateHToolbar();
|
|
|
|
|
Zoom_Automatique( FALSE );
|
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
|
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
|
|
|
|
/*
|
|
|
|
|
* Routine Pour Charger en memoire la copie de 1 libpart.
|
2009-01-29 14:26:20 +00:00
|
|
|
|
* retourne
|
|
|
|
|
* 0 si OK
|
|
|
|
|
* 1 si err
|
|
|
|
|
* CurrentLibEntry pointe la copie ainsi creee
|
|
|
|
|
*/
|
2009-08-27 11:41:56 +00:00
|
|
|
|
bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( LibCmpEntry* LibEntry,
|
|
|
|
|
LibraryStruct* Library )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
wxString msg, cmpName, rootName;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
|
if( ( LibEntry == NULL ) || ( Library == NULL ) )
|
2009-08-27 11:41:56 +00:00
|
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
if( LibEntry->m_Name.m_Text.IsEmpty() )
|
|
|
|
|
{
|
|
|
|
|
wxLogWarning( wxT( "Entry in library <%s> has empty name field." ),
|
|
|
|
|
(const wxChar*) LibEntry );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmpName = LibEntry->m_Name.m_Text;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
CurrentAliasName.Empty();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( LibEntry->Type != ROOT )
|
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
rootName = ( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName;
|
|
|
|
|
wxASSERT( !rootName.IsEmpty() );
|
|
|
|
|
wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ),
|
|
|
|
|
(const wxChar*) cmpName, (const wxChar*) rootName );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
LibEntry = Library->FindEntry( rootName, ROOT );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
if( LibEntry == NULL )
|
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
msg.Printf( wxT( "Root entry <%s> for alias <%s> not found in \
|
|
|
|
|
library <%s>." ),
|
|
|
|
|
(const wxChar*) rootName,
|
|
|
|
|
(const wxChar*) cmpName,
|
|
|
|
|
(const wxChar*) Library->m_Name );
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
|
|
CurrentAliasName = cmpName;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( CurrentLibEntry )
|
|
|
|
|
{
|
|
|
|
|
SAFE_DELETE( CurrentLibEntry );
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
CurrentLibEntry = CopyLibEntryStruct( (EDA_LibComponentStruct*) LibEntry );
|
2009-08-27 19:44:13 +00:00
|
|
|
|
|
|
|
|
|
if( CurrentLibEntry == NULL )
|
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "Could not create copy of part <%s> in library <%s>." ),
|
|
|
|
|
(const wxChar*) LibEntry->m_Name.m_Text,
|
|
|
|
|
(const wxChar*) Library->m_Name );
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
CurrentUnit = 1;
|
|
|
|
|
CurrentConvert = 1;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
DisplayLibInfos();
|
|
|
|
|
|
|
|
|
|
BuildAliasData( Library, CurrentLibEntry );
|
|
|
|
|
|
|
|
|
|
g_ScreenLib->ClrModify();
|
|
|
|
|
g_AsDeMorgan = 0;
|
|
|
|
|
|
|
|
|
|
if( LookForConvertPart( CurrentLibEntry ) > 1 )
|
|
|
|
|
g_AsDeMorgan = 1;
|
|
|
|
|
|
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 */
|
2009-01-29 14:26:20 +00:00
|
|
|
|
void WinEDA_LibeditFrame::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
|
|
|
|
ActiveScreen = GetScreen();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
DC->SetBackground( *wxBLACK_BRUSH );
|
|
|
|
|
DC->SetBackgroundMode( wxTRANSPARENT );
|
2009-03-10 08:26:52 +00:00
|
|
|
|
GRResetPenAndBrush( DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
|
DrawPanel->CursorOff( DC ); // erase cursor
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( DrawPanel->ManageCurseur )
|
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( EraseBg )
|
|
|
|
|
DrawPanel->EraseScreen( DC );
|
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-01-29 14:26:20 +00:00
|
|
|
|
if( CurrentLibEntry )
|
2009-09-04 18:57:37 +00:00
|
|
|
|
CurrentLibEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), CurrentUnit,
|
|
|
|
|
CurrentConvert, GR_DEFAULT_DRAWMODE );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-03-10 08:26:52 +00:00
|
|
|
|
DrawPanel->CursorOn( DC ); // redraw cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( DrawPanel->ManageCurseur )
|
|
|
|
|
{
|
2009-03-10 08:26:52 +00:00
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
GetScreen()->ClrRefreshReq();
|
|
|
|
|
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
|
|
|
|
*/
|
2009-08-27 11:41:56 +00:00
|
|
|
|
void WinEDA_LibeditFrame::SaveActiveLibrary()
|
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
|
|
|
|
|
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
|
DisplayError( this, wxT( "No library specified" ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
|
fn = wxFileName( CurrentLib->m_FullFileName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
|
msg = _( "Modify library file \"" ) + fn.GetFullPath() + _( "\"?" );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
|
return;
|
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
|
bool success = CurrentLib->Save( fn.GetFullPath() );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
MsgPanel->EraseMsgBox();
|
|
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
|
msg = _( "Error while saving library file \"" ) + fn.GetFullPath() +
|
2009-08-27 11:41:56 +00:00
|
|
|
|
_( "\"." );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
Affiche_1_Parametre( this, 1, wxT( " *** ERROR : **" ), msg, BLUE );
|
|
|
|
|
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 );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() +
|
2009-08-27 11:41:56 +00:00
|
|
|
|
wxT( "\" Ok" );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
Affiche_1_Parametre( this, 1, msg, msg1, BLUE );
|
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-01-29 14:26:20 +00:00
|
|
|
|
* Affiche la documentation du composant selectionne
|
2009-08-27 11:41:56 +00:00
|
|
|
|
* Utilis<EFBFBD>e lors de l'affichage de la liste des composants en librairie
|
2009-01-29 14:26:20 +00:00
|
|
|
|
*/
|
2009-08-27 11:41:56 +00:00
|
|
|
|
void WinEDA_LibeditFrame::DisplayCmpDoc( const wxString& Name )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
|
LibCmpEntry* CmpEntry;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
return;
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
MsgPanel->EraseMsgBox();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
CmpEntry = CurrentLib->FindEntry( Name );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( CmpEntry == NULL )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AfficheDoc( this, CmpEntry->m_Doc, CmpEntry->m_KeyWord );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
/*
|
|
|
|
|
* Routine de suppression d'un composant dans la librairie courante
|
2009-01-29 14:26:20 +00:00
|
|
|
|
* (effacement en memoire uniquement, le fichier n'est pas modifie)
|
|
|
|
|
* Le composant peut etre un alias, ou la definition de base.
|
|
|
|
|
* Si c'est un alias:
|
|
|
|
|
* il est supprime, et la liste des alias de la definition
|
|
|
|
|
* de base est modifiee
|
|
|
|
|
* Si c'est le composant de base:
|
|
|
|
|
* Si la liste des alias est nulle, il est supprime
|
|
|
|
|
* Sinon le premier alias devient le composant de base, et les autres
|
|
|
|
|
* alias deviennent dependants de celui ci.
|
|
|
|
|
*/
|
2009-08-27 11:41:56 +00:00
|
|
|
|
void WinEDA_LibeditFrame::DeleteOnePart()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
wxString CmpName;
|
|
|
|
|
LibCmpEntry* LibEntry;
|
|
|
|
|
wxArrayString ListNames;
|
|
|
|
|
wxString msg;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
CurrentDrawItem = NULL;
|
|
|
|
|
|
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
{
|
|
|
|
|
SelectActiveLibrary();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
{
|
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-08-27 11:41:56 +00:00
|
|
|
|
CurrentLib->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
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
msg.Printf( _( "Component library <%s> does not have any entries to delete." ),
|
|
|
|
|
( const wxChar* ) CurrentLib->m_Name );
|
|
|
|
|
wxMessageBox( msg, _( "Delete Entry Error" ),
|
|
|
|
|
wxID_OK | wxICON_EXCLAMATION, this );
|
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
msg.Printf( _( "Select 1 of %d components to\ndelete from library <%s>." ),
|
|
|
|
|
ListNames.GetCount(), ( const wxChar* ) CurrentLib->m_Name );
|
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-08-27 11:41:56 +00:00
|
|
|
|
LibEntry = CurrentLib->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>." ),
|
|
|
|
|
( const wxChar* ) dlg.GetStringSelection(),
|
|
|
|
|
( const wxChar* ) CurrentLib->m_Name );
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
msg = _( "Delete component \"" ) + LibEntry->m_Name.m_Text +
|
|
|
|
|
_( "\" from library \"" ) + CurrentLib->m_Name + wxT( "\"?" );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
if( IsOK( this, msg ) )
|
|
|
|
|
{
|
|
|
|
|
CurrentLib->RemoveEntry( LibEntry );
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +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
|
|
|
|
*/
|
2009-08-27 11:41:56 +00:00
|
|
|
|
void WinEDA_LibeditFrame::CreateNewLibraryPart()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
EDA_LibComponentStruct* NewStruct;
|
|
|
|
|
int diag;
|
|
|
|
|
|
|
|
|
|
if( CurrentLibEntry
|
2009-08-27 11:41:56 +00:00
|
|
|
|
&& !IsOK( this,
|
|
|
|
|
_( "Clear old component from screen (changes will be lost)?" ) ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CurrentDrawItem = NULL;
|
|
|
|
|
|
|
|
|
|
WinEDA_CreateCmpDialog Dialogbox( this );
|
|
|
|
|
diag = Dialogbox.ShowModal();
|
|
|
|
|
if( diag != wxID_OK )
|
|
|
|
|
return;
|
|
|
|
|
msg = Dialogbox.ReturnCmpName();
|
|
|
|
|
if( msg.IsEmpty() )
|
|
|
|
|
return;
|
|
|
|
|
msg.MakeUpper();
|
|
|
|
|
msg.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
|
|
|
|
|
|
/* Test: y a t-il un composant deja de ce nom */
|
|
|
|
|
if( CurrentLib )
|
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
if( CurrentLib->FindEntry( msg ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
{
|
|
|
|
|
wxString msg;
|
|
|
|
|
msg << _( "Component \"" ) << Dialogbox.ReturnCmpName() <<
|
2009-03-10 08:26:52 +00:00
|
|
|
|
_( "\" exists in library \"" ) << CurrentLib->m_Name <<
|
|
|
|
|
_( "\"." );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NewStruct = new EDA_LibComponentStruct( msg );
|
|
|
|
|
Dialogbox.SetComponentData( *NewStruct );
|
|
|
|
|
if( NewStruct->m_Prefix.m_Text.IsEmpty() )
|
|
|
|
|
NewStruct->m_Prefix.m_Text = wxT( "U" );
|
|
|
|
|
NewStruct->m_Prefix.m_Text.MakeUpper();
|
|
|
|
|
|
|
|
|
|
// Effacement ancien composant affich<63>
|
|
|
|
|
if( CurrentLibEntry )
|
|
|
|
|
{
|
|
|
|
|
SAFE_DELETE( CurrentLibEntry );
|
|
|
|
|
}
|
|
|
|
|
CurrentLibEntry = NewStruct;
|
|
|
|
|
CurrentUnit = 1;
|
|
|
|
|
CurrentConvert = 1;
|
|
|
|
|
ReCreateHToolbar();
|
|
|
|
|
|
|
|
|
|
DisplayLibInfos();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
/*
|
|
|
|
|
* Routine de sauvegarde de la "partlib" courante dans la librairie courante
|
|
|
|
|
*
|
|
|
|
|
* Sauvegarde en memoire uniquement, et PAS sur fichier
|
|
|
|
|
* La routine efface l'ancien composant ( ou / et les alias ) a remplacer
|
|
|
|
|
* s'il existe, et sauve le nouveau et cree les alias correspondants.
|
2009-01-29 14:26:20 +00:00
|
|
|
|
*/
|
2007-09-13 11:55:46 +00:00
|
|
|
|
void WinEDA_LibeditFrame::SaveOnePartInMemory()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
LibCmpEntry* Entry;
|
|
|
|
|
EDA_LibComponentStruct* Component;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
bool NewCmp = TRUE;
|
|
|
|
|
|
|
|
|
|
if( CurrentLibEntry == NULL )
|
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
DisplayError( this, _( "No component to save." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
SelectActiveLibrary();
|
|
|
|
|
|
|
|
|
|
if( CurrentLib == NULL )
|
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
|
DisplayError( this, _( "No library specified." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_ScreenLib->ClrModify();
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
Entry = CurrentLib->FindEntry( CurrentLibEntry->m_Name.m_Text, ROOT );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
if( Entry != NULL )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "Component \"%s\" exists. Change it?" ),
|
2009-08-27 11:41:56 +00:00
|
|
|
|
(const wxChar*) Entry->m_Name.m_Text );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
|
return;
|
|
|
|
|
NewCmp = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
wxASSERT( CurrentLibEntry->Type == ROOT );
|
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
/* Effacement des alias deja existants en librairie */
|
|
|
|
|
for( unsigned ii = 0;
|
|
|
|
|
ii < CurrentLibEntry->m_AliasList.GetCount();
|
|
|
|
|
ii += ALIAS_NEXT )
|
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
LibCmpEntry* LocalEntry;
|
|
|
|
|
wxString aliasname = CurrentLibEntry->m_AliasList[ii];
|
|
|
|
|
LocalEntry = CurrentLib->FindEntry( aliasname, ALIAS );
|
|
|
|
|
|
|
|
|
|
while( LocalEntry != NULL && LocalEntry->Type == ALIAS )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
|
CurrentLib->RemoveEntry( LocalEntry );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !NewCmp )
|
2009-08-27 11:41:56 +00:00
|
|
|
|
CurrentLib->RemoveEntry( Entry );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
Component = CurrentLib->AddComponent( CurrentLibEntry );
|
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" ),
|
|
|
|
|
( const wxChar* ) Component->m_Name.m_Text,
|
|
|
|
|
( const wxChar* ) CurrentLib->m_Name );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
Affiche_Message( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|