2009-02-04 15:25:03 +00:00
|
|
|
/****************************/
|
|
|
|
/* EESchema - viewlibs.cpp */
|
|
|
|
/****************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2009-04-07 15:54:40 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "eda_doc.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-02-16 16:21:52 +00:00
|
|
|
#include "viewlib_frame.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "eeschema_id.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
#define NEXT_PART 1
|
|
|
|
#define NEW_PART 0
|
2007-06-05 12:10:51 +00:00
|
|
|
#define PREVIOUS_PART -1
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
wxString msg;
|
|
|
|
LIB_ALIAS* LibEntry;
|
|
|
|
int ii, id = event.GetId();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case ID_LIBVIEW_SELECT_LIB:
|
|
|
|
SelectCurrentLibrary();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_SELECT_PART:
|
|
|
|
SelectAndViewLibraryPart( NEW_PART );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_NEXT:
|
|
|
|
SelectAndViewLibraryPart( NEXT_PART );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_PREVIOUS:
|
|
|
|
SelectAndViewLibraryPart( PREVIOUS_PART );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_VIEWDOC:
|
2010-10-25 15:43:42 +00:00
|
|
|
LibEntry = CMP_LIBRARY::FindLibraryEntry( m_entryName, m_libraryName );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( LibEntry && ( !LibEntry->GetDocFileName().IsEmpty() ) )
|
|
|
|
GetAssociatedDocument( this, LibEntry->GetDocFileName(),
|
2009-09-02 18:12:45 +00:00
|
|
|
&wxGetApp().GetLibraryPathList() );
|
2009-02-04 15:25:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT:
|
|
|
|
m_HToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, TRUE );
|
|
|
|
m_HToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, FALSE );
|
2009-10-01 14:17:47 +00:00
|
|
|
m_convert = 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
DrawPanel->Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT:
|
|
|
|
m_HToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, FALSE );
|
|
|
|
m_HToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, TRUE );
|
2009-10-01 14:17:47 +00:00
|
|
|
m_convert = 2;
|
2009-02-04 15:25:03 +00:00
|
|
|
DrawPanel->Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_SELECT_PART_NUMBER:
|
2011-04-19 19:19:41 +00:00
|
|
|
ii = SelpartBox->GetCurrentSelection();
|
2009-02-04 15:25:03 +00:00
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
2009-10-01 14:17:47 +00:00
|
|
|
m_unit = ii + 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
DrawPanel->Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-11-20 21:59:00 +00:00
|
|
|
msg << wxT( "LIB_VIEW_FRAME::Process_Special_Functions error: id = " ) << id;
|
2009-02-04 15:25:03 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
bool LIB_VIEW_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-08 13:41:20 +00:00
|
|
|
/* Displays the name of the current opened library in the caption */
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::DisplayLibInfos()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString msg;
|
|
|
|
CMP_LIBRARY* Lib;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
Lib = CMP_LIBRARY::FindLibrary( m_libraryName );
|
|
|
|
msg = _( "Library Browser" );
|
2008-10-01 19:57:10 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
msg << wxT( " [" );
|
2008-10-01 19:57:10 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( Lib )
|
2009-09-18 14:56:05 +00:00
|
|
|
msg << Lib->GetFullFileName();
|
2009-02-04 15:25:03 +00:00
|
|
|
else
|
2009-10-01 14:17:47 +00:00
|
|
|
msg += _( "no library selected" );
|
2008-10-01 19:57:10 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
msg << wxT( "]" );
|
|
|
|
SetTitle( msg );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
/*****************************************/
|
2009-12-08 13:41:20 +00:00
|
|
|
/* Function to Select Current library */
|
2009-02-04 15:25:03 +00:00
|
|
|
/*****************************************/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::SelectCurrentLibrary()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* Lib;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
Lib = SelectLibraryFromList( this );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( Lib )
|
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
m_entryName.Empty();
|
|
|
|
m_libraryName = Lib->GetName();
|
2009-02-04 15:25:03 +00:00
|
|
|
DisplayLibInfos();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( m_LibList )
|
|
|
|
{
|
|
|
|
ReCreateListCmp();
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
DisplayLibInfos();
|
|
|
|
ReCreateHToolbar();
|
2009-10-01 14:17:47 +00:00
|
|
|
int id = m_LibList->FindString( m_libraryName.GetData() );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( id >= 0 )
|
|
|
|
m_LibList->SetSelection( id );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/*
|
|
|
|
* Routine to select and view library Part (NEW, NEXT or PREVIOUS)
|
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::SelectAndViewLibraryPart( int option )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* Lib;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_libraryName.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
SelectCurrentLibrary();
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_libraryName.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
Lib = CMP_LIBRARY::FindLibrary( m_libraryName );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( Lib == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( ( m_entryName.IsEmpty() ) || ( option == NEW_PART ) )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
ViewOneLibraryContent( Lib, NEW_PART );
|
|
|
|
return;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* LibEntry = Lib->FindEntry( m_entryName );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( LibEntry == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( option == NEXT_PART )
|
|
|
|
ViewOneLibraryContent( Lib, NEXT_PART );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( option == PREVIOUS_PART )
|
|
|
|
ViewOneLibraryContent( Lib, PREVIOUS_PART );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************/
|
|
|
|
/* Routine to view one selected library content. */
|
|
|
|
/*************************************************/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
int NumOfParts = 0;
|
|
|
|
LIB_ALIAS* LibEntry;
|
|
|
|
wxString CmpName;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
if( Lib )
|
2009-09-02 18:12:45 +00:00
|
|
|
NumOfParts = Lib->GetCount();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
if( NumOfParts == 0 )
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
DisplayError( this, wxT( "No library or library is empty!" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Lib == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( Flag == NEW_PART )
|
|
|
|
{
|
2009-12-21 12:05:36 +00:00
|
|
|
DisplayComponentsNamesInLib( this, Lib, CmpName, m_entryName );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Flag == NEXT_PART )
|
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
LibEntry = Lib->GetNextEntry( m_entryName );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
if( LibEntry )
|
2009-10-21 20:02:25 +00:00
|
|
|
CmpName = LibEntry->GetName();
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Flag == PREVIOUS_PART )
|
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
LibEntry = Lib->GetPreviousEntry( m_entryName );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( LibEntry )
|
2009-10-21 20:02:25 +00:00
|
|
|
CmpName = LibEntry->GetName();
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry = Lib->FindEntry( CmpName );
|
2009-10-01 14:17:47 +00:00
|
|
|
m_entryName = CmpName;
|
2009-02-04 15:25:03 +00:00
|
|
|
DisplayLibInfos();
|
2009-10-01 14:17:47 +00:00
|
|
|
Zoom_Automatique( false );
|
2009-12-19 16:10:25 +00:00
|
|
|
DrawPanel->Refresh( );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
if( m_CmpList )
|
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
int id = m_CmpList->FindString( m_entryName.GetData() );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( id >= 0 )
|
|
|
|
m_CmpList->SetSelection( id );
|
|
|
|
}
|
|
|
|
ReCreateHToolbar();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function RedrawActiveWindow
|
2009-12-08 13:41:20 +00:00
|
|
|
* Display the current selected component.
|
|
|
|
* If the component is an alias, the ROOT component is displayed
|
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* component;
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* entry;
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* lib;
|
|
|
|
wxString msg;
|
|
|
|
wxString tmp;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
lib = CMP_LIBRARY::FindLibrary( m_libraryName );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( lib == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
entry = lib->FindEntry( m_entryName );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( entry == NULL )
|
|
|
|
return;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
component = entry->GetComponent();
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
DrawPanel->DrawBackGround( DC );
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( !entry->IsRoot() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-12-20 19:48:58 +00:00
|
|
|
if( component == NULL ) // Should not occur
|
|
|
|
return;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
// Temporarily change the name field text to reflect the alias name.
|
2010-10-25 15:43:42 +00:00
|
|
|
msg = entry->GetName();
|
2009-09-14 13:24:17 +00:00
|
|
|
tmp = component->GetName();
|
2010-10-04 18:54:14 +00:00
|
|
|
component->SetName( msg );
|
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_unit < 1 )
|
|
|
|
m_unit = 1;
|
|
|
|
if( m_convert < 1 )
|
|
|
|
m_convert = 1;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
msg = _( "None" );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), m_unit, m_convert, GR_DEFAULT_DRAWMODE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2010-01-22 18:13:43 +00:00
|
|
|
/* Redraw the cursor */
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->DrawCrossHair( DC );
|
2010-01-22 18:13:43 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( !tmp.IsEmpty() )
|
2009-10-21 20:02:25 +00:00
|
|
|
component->SetName( tmp );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
|
|
|
AppendMsgPanel( _( "Part" ), component->GetName(), BLUE, 6 );
|
|
|
|
AppendMsgPanel( _( "Alias" ), msg, RED, 6 );
|
2009-12-15 21:11:05 +00:00
|
|
|
AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 );
|
|
|
|
AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|