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"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.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"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
#include "id.h"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
wxString msg;
|
|
|
|
EDA_LibComponentStruct* LibEntry;
|
|
|
|
int ii, id = event.GetId();
|
|
|
|
wxPoint pos;
|
|
|
|
|
|
|
|
wxGetMousePosition( &pos.x, &pos.y );
|
|
|
|
pos.y += 20;
|
|
|
|
|
|
|
|
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:
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry =
|
|
|
|
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
|
|
|
|
g_CurrentViewLibraryName,
|
|
|
|
ALIAS );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( LibEntry && ( !LibEntry->m_DocFile.IsEmpty() ) )
|
2009-04-07 15:54:40 +00:00
|
|
|
GetAssociatedDocument( this, LibEntry->m_DocFile,
|
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 );
|
|
|
|
g_ViewConvert = 1;
|
|
|
|
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 );
|
|
|
|
g_ViewConvert = 2;
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_SELECT_PART_NUMBER:
|
|
|
|
ii = SelpartBox->GetChoice();
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
g_ViewUnit = ii + 1;
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg << wxT( "WinEDA_ViewlibFrame::Process_Special_Functions error: id = " ) << id;
|
|
|
|
DisplayError( this, msg );
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
void WinEDA_ViewlibFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
bool WinEDA_ViewlibFrame::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Affiche en Ligne d'info la librairie en cours de visualisation */
|
2009-09-02 18:12:45 +00:00
|
|
|
void WinEDA_ViewlibFrame::DisplayLibInfos()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
wxString msg;
|
|
|
|
LibraryStruct* Lib;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
Lib = FindLibrary( g_CurrentViewLibraryName );
|
|
|
|
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-04-14 16:45:22 +00:00
|
|
|
msg << Lib->m_FullFileName;
|
2009-02-04 15:25:03 +00:00
|
|
|
else
|
|
|
|
msg += _( "none 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-09-02 18:12:45 +00:00
|
|
|
/* Routine to Select Current library */
|
2009-02-04 15:25:03 +00:00
|
|
|
/*****************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_ViewlibFrame::SelectCurrentLibrary()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
LibraryStruct* Lib;
|
|
|
|
|
|
|
|
Lib = SelectLibraryFromList( this );
|
|
|
|
if( Lib )
|
|
|
|
{
|
|
|
|
g_CurrentViewComponentName.Empty();
|
|
|
|
g_CurrentViewLibraryName = Lib->m_Name;
|
|
|
|
DisplayLibInfos();
|
|
|
|
if( m_LibList )
|
|
|
|
{
|
|
|
|
ReCreateListCmp();
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
DisplayLibInfos();
|
|
|
|
ReCreateHToolbar();
|
|
|
|
int id = m_LibList->FindString( g_CurrentViewLibraryName.GetData() );
|
|
|
|
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)
|
|
|
|
*/
|
2009-02-04 15:25:03 +00:00
|
|
|
void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
LibraryStruct* Lib;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( g_CurrentViewLibraryName.IsEmpty() )
|
|
|
|
SelectCurrentLibrary();
|
|
|
|
if( g_CurrentViewLibraryName.IsEmpty() )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
Lib = FindLibrary( g_CurrentViewLibraryName );
|
|
|
|
if( Lib == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( ( g_CurrentViewComponentName.IsEmpty() ) || ( option == NEW_PART ) )
|
|
|
|
{
|
|
|
|
ViewOneLibraryContent( Lib, NEW_PART );
|
|
|
|
return;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
LibCmpEntry* LibEntry = FindLibPart( g_CurrentViewComponentName,
|
|
|
|
g_CurrentViewLibraryName,
|
|
|
|
ALIAS );
|
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. */
|
|
|
|
/*************************************************/
|
2009-02-04 15:25:03 +00:00
|
|
|
void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
int NumOfParts = 0;
|
|
|
|
LibCmpEntry* LibEntry;
|
|
|
|
wxString CmpName;
|
|
|
|
wxClientDC dc( DrawPanel );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
DrawPanel->PrepareGraphicContext( &dc );
|
|
|
|
|
|
|
|
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-09-02 18:12:45 +00:00
|
|
|
DisplayComponentsNamesInLib( this, Lib, CmpName,
|
2009-02-04 15:25:03 +00:00
|
|
|
g_CurrentViewComponentName );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Flag == NEXT_PART )
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry = Lib->GetNextEntry( g_CurrentViewComponentName );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
if( LibEntry )
|
|
|
|
CmpName = LibEntry->m_Name.m_Text;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Flag == PREVIOUS_PART )
|
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry = Lib->GetPreviousEntry( g_CurrentViewComponentName );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( LibEntry )
|
|
|
|
CmpName = LibEntry->m_Name.m_Text;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_ViewUnit = 1;
|
|
|
|
g_ViewConvert = 1;
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry = Lib->FindEntry( CmpName );
|
2009-02-04 15:25:03 +00:00
|
|
|
g_CurrentViewComponentName = CmpName;
|
|
|
|
DisplayLibInfos();
|
|
|
|
Zoom_Automatique( FALSE );
|
|
|
|
RedrawActiveWindow( &dc, TRUE );
|
|
|
|
|
|
|
|
if( m_CmpList )
|
|
|
|
{
|
|
|
|
int id = m_CmpList->FindString( g_CurrentViewComponentName.GetData() );
|
|
|
|
if( id >= 0 )
|
|
|
|
m_CmpList->SetSelection( id );
|
|
|
|
}
|
|
|
|
ReCreateHToolbar();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Routine d'affichage du composant selectionne */
|
2009-09-02 18:12:45 +00:00
|
|
|
/* Si Le composant est un alias, le composant ROOT est recherche et affiche */
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************************/
|
2009-02-04 15:25:03 +00:00
|
|
|
void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
EDA_LibComponentStruct* LibEntry = NULL;
|
|
|
|
LibCmpEntry* ViewCmpEntry = NULL;
|
|
|
|
const wxChar* RootName, * CmpName;
|
|
|
|
wxString Msg;
|
|
|
|
|
|
|
|
ActiveScreen = GetScreen();
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry =
|
|
|
|
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
|
|
|
|
g_CurrentViewLibraryName,
|
|
|
|
ALIAS );
|
2009-04-13 05:58:11 +00:00
|
|
|
ViewCmpEntry = (LibCmpEntry*) LibEntry;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
/* Forcage de la reinit de la brosse et plume courante */
|
|
|
|
GRResetPenAndBrush( DC );
|
|
|
|
DC->SetBackground( *wxBLACK_BRUSH );
|
|
|
|
DC->SetBackgroundMode( wxTRANSPARENT );
|
|
|
|
|
|
|
|
if( EraseBg )
|
|
|
|
DrawPanel->EraseScreen( DC );
|
|
|
|
|
|
|
|
DrawPanel->DrawBackGround( DC );
|
|
|
|
|
|
|
|
if( LibEntry )
|
|
|
|
{
|
|
|
|
CmpName = LibEntry->m_Name.m_Text.GetData();
|
|
|
|
if( LibEntry->Type != ROOT )
|
|
|
|
{
|
|
|
|
RootName =
|
|
|
|
( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName.GetData();
|
|
|
|
Msg.Printf( _( "Current Part: <%s> (is Alias of <%s>)" ),
|
|
|
|
CmpName, RootName );
|
2009-08-27 11:41:56 +00:00
|
|
|
LibEntry =
|
|
|
|
( EDA_LibComponentStruct* ) FindLibPart( RootName,
|
|
|
|
g_CurrentViewLibraryName,
|
|
|
|
ROOT );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
if( LibEntry == NULL )
|
|
|
|
{
|
|
|
|
Msg.Printf( _( "Error: Root Part <%s> not found" ), RootName );
|
|
|
|
DisplayError( this, Msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Affichage du composant ROOT, avec nom de l'alias */
|
|
|
|
wxString RealName;
|
|
|
|
RealName = LibEntry->m_Name.m_Text;
|
|
|
|
LibEntry->m_Name.m_Text = CmpName;
|
|
|
|
if( g_ViewUnit < 1 )
|
|
|
|
g_ViewUnit = 1;
|
|
|
|
if( g_ViewConvert < 1 )
|
|
|
|
g_ViewConvert = 1;
|
2009-09-04 18:57:37 +00:00
|
|
|
LibEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_ViewUnit,
|
|
|
|
g_ViewConvert, GR_DEFAULT_DRAWMODE );
|
2009-02-04 15:25:03 +00:00
|
|
|
LibEntry->m_Name.m_Text = RealName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Msg.Printf( _( "Current Part: <%s>" ),
|
|
|
|
ViewCmpEntry->m_Name.m_Text.GetData() );
|
2009-09-04 18:57:37 +00:00
|
|
|
LibEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_ViewUnit,
|
|
|
|
g_ViewConvert, GR_DEFAULT_DRAWMODE );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
AfficheDoc( this, ViewCmpEntry->m_Doc, ViewCmpEntry->m_KeyWord );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetStatusText( Msg, 0 );
|
|
|
|
|
|
|
|
DrawPanel->Trace_Curseur( DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|