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"
|
2009-09-22 12:27:57 +00:00
|
|
|
|
#include "eeschema_id.h"
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "general.h"
|
|
|
|
|
#include "protos.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
|
#include "libeditfrm.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
#include "class_library.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
#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-09-14 13:24:17 +00:00
|
|
|
|
wxString msg = _( "Component Library Editor: " );
|
|
|
|
|
|
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) */
|
2007-09-13 11:55:46 +00:00
|
|
|
|
void WinEDA_LibeditFrame::SelectActiveLibrary()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
|
CMP_LIBRARY* Lib;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
Lib = SelectLibraryFromList( this );
|
|
|
|
|
if( Lib )
|
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_library = Lib;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
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-09-25 18:49:04 +00:00
|
|
|
|
void WinEDA_LibeditFrame::LoadOneLibraryPart( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
|
int i;
|
|
|
|
|
wxString msg;
|
|
|
|
|
wxString CmpName;
|
|
|
|
|
CMP_LIB_ENTRY* LibEntry = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW );
|
|
|
|
|
|
|
|
|
|
if( GetBaseScreen()->IsModify() && !IsOK( this, _( "Current part not \
|
2009-09-22 12:27:57 +00:00
|
|
|
|
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
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
GetBaseScreen()->ClrModify();
|
|
|
|
|
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 );
|
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 )
|
|
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
|
msg.Printf( _( "Component or alias name \"%s\" not found in \
|
|
|
|
|
library \"%s\"." ),
|
|
|
|
|
(const wxChar*) CmpName,
|
2009-09-25 18:49:04 +00:00
|
|
|
|
(const wxChar*) 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
|
|
|
|
}
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( !LoadOneLibraryPartAux( LibEntry, m_library ) )
|
|
|
|
|
return;
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
g_EditPinByPinIsOn = false;
|
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
2009-09-22 12:27:57 +00:00
|
|
|
|
Zoom_Automatique( false );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
DrawPanel->Refresh();
|
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
|
2009-09-25 18:49:04 +00:00
|
|
|
|
* m_component pointe la copie ainsi creee
|
2009-01-29 14:26:20 +00:00
|
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
|
bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry,
|
|
|
|
|
CMP_LIBRARY* Library )
|
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
|
|
|
|
|
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-09-14 13:24:17 +00:00
|
|
|
|
if( LibEntry->GetName().IsEmpty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
|
{
|
|
|
|
|
wxLogWarning( wxT( "Entry in library <%s> has empty name field." ),
|
|
|
|
|
(const wxChar*) LibEntry );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
|
cmpName = LibEntry->GetName();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_aliasName.Empty();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
if( LibEntry->Type != ROOT )
|
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
|
LIB_ALIAS* alias = (LIB_ALIAS*) LibEntry;
|
|
|
|
|
component = alias->GetComponent();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
|
wxASSERT( component != NULL && component->Type == ROOT );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
|
wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ),
|
|
|
|
|
(const wxChar*) cmpName,
|
|
|
|
|
(const wxChar*) component->GetName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_aliasName = cmpName;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
|
component = (LIB_COMPONENT*) LibEntry;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_component )
|
|
|
|
|
SAFE_DELETE( m_component );
|
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>." ),
|
2009-09-14 13:24:17 +00:00
|
|
|
|
(const wxChar*) LibEntry->GetName(),
|
2009-09-18 14:56:05 +00:00
|
|
|
|
(const wxChar*) Library->GetName() );
|
2009-08-27 19:44:13 +00:00
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
GetBaseScreen()->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 */
|
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-09-22 12:27:57 +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-09-25 18:49:04 +00:00
|
|
|
|
if( m_component )
|
|
|
|
|
m_component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), m_unit,
|
|
|
|
|
m_convert, 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-09-22 12:27:57 +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-09-14 13:24:17 +00:00
|
|
|
|
void WinEDA_LibeditFrame::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
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
|
DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW );
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
fn = wxFileName( m_library->GetFullFileName() );
|
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-29 18:38:21 +00:00
|
|
|
|
bool success = m_library->Save( fn.GetFullPath(), true );
|
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-09-18 14:56:05 +00:00
|
|
|
|
MsgPanel->Affiche_1_Parametre( 1, wxT( "*** 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 );
|
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-09-18 14:56:05 +00:00
|
|
|
|
MsgPanel->Affiche_1_Parametre( 1, msg, msg1, BLUE );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
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-09-18 14:56:05 +00:00
|
|
|
|
void WinEDA_LibeditFrame::DisplayCmpDoc()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
LIB_ALIAS* alias = NULL;
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
MsgPanel->EraseMsgBox();
|
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
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Part" ), msg, BLUE, 8 );
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_aliasName.IsEmpty() )
|
2009-09-18 14:56:05 +00:00
|
|
|
|
{
|
|
|
|
|
msg = _( "None" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
msg = m_aliasName;
|
|
|
|
|
alias = m_library->FindAlias( m_aliasName );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Alias" ), msg, RED, 8 );
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Unit" ), msg, BROWN, 8 );
|
|
|
|
|
|
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" );
|
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Body" ), msg, GREEN, 8 );
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_component->m_Options == ENTRY_POWER )
|
2009-09-18 14:56:05 +00:00
|
|
|
|
msg = _( "Power Symbol" );
|
|
|
|
|
else
|
|
|
|
|
msg = _( "Component" );
|
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Type" ), msg, MAGENTA, 8 );
|
|
|
|
|
|
|
|
|
|
if( alias != NULL )
|
|
|
|
|
msg = alias->m_Doc;
|
|
|
|
|
else
|
2009-09-25 18:49:04 +00:00
|
|
|
|
msg = m_component->m_Doc;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Description" ), msg, CYAN, 8 );
|
|
|
|
|
|
|
|
|
|
if( alias != NULL )
|
|
|
|
|
msg = alias->m_KeyWord;
|
|
|
|
|
else
|
2009-09-25 18:49:04 +00:00
|
|
|
|
msg = m_component->m_KeyWord;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
|
|
MsgPanel->AppendMessage( _( "Key words" ), msg, 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
|
|
|
|
/*
|
|
|
|
|
* 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-09-22 12:27:57 +00:00
|
|
|
|
void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
|
wxString CmpName;
|
|
|
|
|
CMP_LIB_ENTRY* LibEntry;
|
|
|
|
|
wxArrayString ListNames;
|
|
|
|
|
wxString msg;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
|
DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW );
|
|
|
|
|
|
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
|
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
|
msg.Printf( _( "Component library <%s> is empty." ),
|
2009-09-25 18:49:04 +00:00
|
|
|
|
( const wxChar* ) m_library->GetName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
wxMessageBox( msg, _( "Delete Entry Error" ),
|
|
|
|
|
wxID_OK | wxICON_EXCLAMATION, this );
|
|
|
|
|
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(),
|
|
|
|
|
( const wxChar* ) 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>." ),
|
|
|
|
|
( const wxChar* ) dlg.GetStringSelection(),
|
2009-09-25 18:49:04 +00:00
|
|
|
|
( const wxChar* ) 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\"?" ),
|
|
|
|
|
(const wxChar*) LibEntry->GetName(),
|
2009-09-25 18:49:04 +00:00
|
|
|
|
(const wxChar*) m_library->GetName() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
|
return;
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_component == NULL
|
|
|
|
|
|| ( m_component->GetName().CmpNoCase( LibEntry->GetName() ) != 0
|
|
|
|
|
&& !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;
|
|
|
|
|
|
|
|
|
|
wxString newCmpName;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
CMP_LIB_ENTRY* nextEntry;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the current component has no aliases, then the next entry
|
|
|
|
|
* in the library will be shown. If the current component has
|
|
|
|
|
* aliases, the updated component will be shown
|
|
|
|
|
*/
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_component->GetName().CmpNoCase( LibEntry->GetName() ) == 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_component->m_AliasList.IsEmpty() )
|
2009-09-14 13:24:17 +00:00
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
nextEntry = m_library->GetNextEntry( m_component->GetName() );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
|
|
if( nextEntry != NULL )
|
|
|
|
|
newCmpName = nextEntry->GetName();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
newCmpName = m_component->m_AliasList[ 0 ];
|
2009-09-14 13:24:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
newCmpName = m_component->GetName();
|
2009-09-14 13:24:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_library->RemoveEntry( LibEntry );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
|
|
if( !newCmpName.IsEmpty() )
|
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
nextEntry = m_library->FindEntry( newCmpName );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( nextEntry != NULL && LoadOneLibraryPartAux( nextEntry, m_library ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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-09-22 12:27:57 +00:00
|
|
|
|
void WinEDA_LibeditFrame::CreateNewLibraryPart( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-09-22 12:27:57 +00:00
|
|
|
|
int diag;
|
|
|
|
|
wxString msg;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
LIB_COMPONENT* NewStruct;
|
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;
|
|
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
|
DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW );
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_drawItem = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
|
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 */
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_library )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
|
if( m_library->FindEntry( msg ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
|
{
|
|
|
|
|
wxString msg;
|
2009-09-22 12:27:57 +00:00
|
|
|
|
msg.Printf( _( "Component \"%s\" already exists in \
|
|
|
|
|
library \"%s\"." ),
|
2009-09-14 13:24:17 +00:00
|
|
|
|
(const wxChar*) Dialogbox.ReturnCmpName(),
|
2009-09-25 18:49:04 +00:00
|
|
|
|
(const wxChar*) m_library->GetName() );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
|
NewStruct = new LIB_COMPONENT( msg );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
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>
|
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 );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_component = NewStruct;
|
|
|
|
|
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();
|
|
|
|
|
g_EditPinByPinIsOn = false;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
m_lastDrawItem = NULL;
|
2009-09-22 12:27:57 +00:00
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
|
|
|
|
DrawPanel->Refresh();
|
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-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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
GetBaseScreen()->ClrModify();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
2009-09-25 18:49:04 +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
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "Component \"%s\" exists. Change it?" ),
|
2009-09-14 13:24:17 +00:00
|
|
|
|
(const wxChar*) oldComponent->GetName() );
|
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;
|
|
|
|
|
|
|
|
|
|
wxASSERT( m_component->Type == ROOT );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
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-09-14 13:24:17 +00:00
|
|
|
|
( const wxChar* ) Component->GetName(),
|
2009-09-25 18:49:04 +00:00
|
|
|
|
( const wxChar* ) m_library->GetName() );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
Affiche_Message( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|