2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* viewlib_frame.cpp - fonctions des classes du type WinEDA_ViewlibFrame */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "protos.h"
|
|
|
|
#include "id.h"
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/*****************************/
|
|
|
|
/* class WinEDA_ViewlibFrame */
|
|
|
|
/*****************************/
|
2009-01-07 15:59:49 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
|
2009-05-21 17:42:42 +00:00
|
|
|
/* Window events */
|
|
|
|
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
|
|
|
|
EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
|
|
|
|
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )
|
|
|
|
|
|
|
|
/* Sash drag events */
|
|
|
|
EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
|
|
|
|
EVT_SASH_DRAGGED( ID_LIBVIEW_CMPWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
|
|
|
|
|
|
|
|
|
|
|
|
/* Toolbar events */
|
|
|
|
EVT_TOOL_RANGE( ID_LIBVIEW_START_H_TOOL, ID_LIBVIEW_END_H_TOOL,
|
|
|
|
WinEDA_ViewlibFrame::Process_Special_Functions )
|
|
|
|
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_ViewlibFrame::OnZoom )
|
|
|
|
EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC,
|
|
|
|
WinEDA_ViewlibFrame::ExportToSchematicLibraryPart )
|
|
|
|
EVT_KICAD_CHOICEBOX( ID_LIBVIEW_SELECT_PART_NUMBER,
|
|
|
|
WinEDA_ViewlibFrame::Process_Special_Functions )
|
|
|
|
|
|
|
|
/* listbox events */
|
|
|
|
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
|
|
|
|
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
/*
|
|
|
|
* This emulates the zoom menu entries found in the other Kicad applications.
|
|
|
|
* The library viewer does not have any menus so add an accelerator table to
|
|
|
|
* the main frame.
|
|
|
|
*/
|
2009-04-10 13:39:03 +00:00
|
|
|
static wxAcceleratorEntry accels[] =
|
|
|
|
{
|
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_ZOOM_IN ),
|
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_ZOOM_OUT ),
|
2009-01-17 20:31:19 +00:00
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F3, ID_ZOOM_REDRAW ),
|
2009-04-10 13:39:03 +00:00
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_ZOOM_PAGE )
|
2009-01-17 20:31:19 +00:00
|
|
|
};
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
#define ACCEL_TABLE_CNT ( sizeof( accels ) / sizeof( wxAcceleratorEntry ) )
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
#define EXTRA_BORDER_SIZE 2
|
2009-05-21 17:42:42 +00:00
|
|
|
|
|
|
|
|
2008-12-08 18:56:43 +00:00
|
|
|
WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
|
2008-12-05 16:03:05 +00:00
|
|
|
LibraryStruct* Library,
|
2008-12-08 18:56:43 +00:00
|
|
|
wxSemaphore* semaphore ) :
|
2008-12-08 15:27:13 +00:00
|
|
|
WinEDA_DrawFrame( father, VIEWER_FRAME, _( "Library browser" ),
|
2008-04-14 19:22:48 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
m_FrameName = wxT( "ViewlibFrame" );
|
2009-04-10 13:39:03 +00:00
|
|
|
m_ConfigPath = wxT( "LibraryViewer" );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
// Give an icon
|
|
|
|
SetIcon( wxIcon( library_browse_xpm ) );
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
m_CmpList = NULL;
|
|
|
|
m_LibList = NULL;
|
|
|
|
m_LibListWindow = NULL;
|
|
|
|
m_CmpListWindow = NULL;
|
|
|
|
m_Semaphore = semaphore;
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( m_Semaphore )
|
|
|
|
SetWindowStyle( GetWindowStyle() | wxSTAY_ON_TOP );
|
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
SetBaseScreen( new SCH_SCREEN() );
|
2008-12-06 19:44:02 +00:00
|
|
|
GetScreen()->m_Center = true; // set to true to have the coordinates origine -0,0) centered on screen
|
2009-04-10 13:39:03 +00:00
|
|
|
LoadSettings();
|
|
|
|
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
|
|
|
|
|
|
|
|
ReCreateHToolbar();
|
|
|
|
ReCreateVToolbar();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
wxSize size = GetClientSize();
|
|
|
|
size.y -= m_MsgFrameHeight + 2;
|
|
|
|
|
|
|
|
m_LibListSize.y = size.y;
|
|
|
|
|
|
|
|
wxPoint win_pos( 0, 0 );
|
2008-04-14 19:22:48 +00:00
|
|
|
if( Library == NULL )
|
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
// Creates the libraries window display
|
|
|
|
m_LibListWindow =
|
2009-05-21 17:42:42 +00:00
|
|
|
new wxSashLayoutWindow( this, ID_LIBVIEW_LIBWINDOW, win_pos,
|
|
|
|
m_LibListSize, wxCLIP_CHILDREN | wxSW_3D,
|
|
|
|
wxT( "LibWindow" ) );
|
2009-04-10 13:39:03 +00:00
|
|
|
m_LibListWindow->SetOrientation( wxLAYOUT_VERTICAL );
|
|
|
|
m_LibListWindow->SetAlignment( wxLAYOUT_LEFT );
|
|
|
|
m_LibListWindow->SetSashVisible( wxSASH_RIGHT, TRUE );
|
|
|
|
m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
|
2009-05-21 17:42:42 +00:00
|
|
|
m_LibList =
|
|
|
|
new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST,
|
|
|
|
wxPoint( 0, 0 ),
|
2009-09-02 18:12:45 +00:00
|
|
|
m_LibListWindow->GetClientSize() -
|
|
|
|
wxSize( EXTRA_BORDER_SIZE * 2, 0 ),
|
2009-05-21 17:42:42 +00:00
|
|
|
0, NULL, wxLB_HSCROLL );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-10 13:39:03 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
g_CurrentViewLibraryName = Library->m_Name;
|
2009-04-11 15:12:58 +00:00
|
|
|
m_LibListSize.x = 0;
|
2009-04-10 13:39:03 +00:00
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
// Creates the component window display
|
|
|
|
m_CmpListSize.y = size.y;
|
|
|
|
win_pos.x = m_LibListSize.x;
|
|
|
|
win_pos.y = 0;
|
|
|
|
m_CmpListWindow = new wxSashLayoutWindow( this, ID_LIBVIEW_CMPWINDOW,
|
2009-05-21 17:42:42 +00:00
|
|
|
win_pos, m_CmpListSize,
|
|
|
|
wxCLIP_CHILDREN | wxSW_3D,
|
|
|
|
wxT( "CmpWindow" ) );
|
2009-04-10 13:39:03 +00:00
|
|
|
m_CmpListWindow->SetOrientation( wxLAYOUT_VERTICAL );
|
|
|
|
|
|
|
|
// m_CmpListWindow->SetAlignment( wxLAYOUT_LEFT );
|
|
|
|
m_CmpListWindow->SetSashVisible( wxSASH_RIGHT, TRUE );
|
|
|
|
m_CmpListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
|
|
|
|
m_CmpList = new wxListBox( m_CmpListWindow, ID_LIBVIEW_CMP_LIST,
|
|
|
|
wxPoint( 0, 0 ),
|
2009-09-02 18:12:45 +00:00
|
|
|
m_CmpListWindow->GetClientSize() -
|
|
|
|
wxSize( EXTRA_BORDER_SIZE * 2, 0 ),
|
2009-04-10 13:39:03 +00:00
|
|
|
0, NULL, wxLB_HSCROLL );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
if( m_LibList )
|
|
|
|
ReCreateListLib();
|
|
|
|
DisplayLibInfos();
|
2009-02-12 21:21:01 +00:00
|
|
|
if( DrawPanel )
|
|
|
|
DrawPanel->SetAcceleratorTable( table );
|
2008-12-06 19:44:02 +00:00
|
|
|
BestZoom();
|
2008-04-14 19:22:48 +00:00
|
|
|
Show( TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2008-12-06 19:44:02 +00:00
|
|
|
/*******************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_ViewlibFrame::~WinEDA_ViewlibFrame()
|
2008-12-06 19:44:02 +00:00
|
|
|
/*******************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
delete GetScreen();
|
|
|
|
SetBaseScreen( 0 );
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
WinEDA_SchematicFrame* frame =
|
|
|
|
(WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
|
|
|
|
frame->m_ViewlibFrame = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************/
|
2008-04-14 19:22:48 +00:00
|
|
|
void WinEDA_ViewlibFrame::OnCloseWindow( wxCloseEvent& Event )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************/
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SaveSettings();
|
|
|
|
if( m_Semaphore )
|
|
|
|
m_Semaphore->Post();
|
|
|
|
Destroy();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
/****************************************************/
|
|
|
|
void WinEDA_ViewlibFrame::OnSashDrag( wxSashEvent& event )
|
|
|
|
/****************************************************/
|
|
|
|
|
|
|
|
/* Resize sub windows when dragging a sash window border
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if( event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_LibListSize.y = GetClientSize().y - m_MsgFrameHeight;
|
|
|
|
m_CmpListSize.y = m_LibListSize.y;
|
|
|
|
|
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
|
|
|
case ID_LIBVIEW_LIBWINDOW:
|
|
|
|
if( m_LibListWindow )
|
|
|
|
{
|
|
|
|
m_LibListSize.x = event.GetDragRect().width;
|
|
|
|
m_LibListWindow->SetSize( m_LibListSize );
|
|
|
|
m_CmpListWindow->SetPosition( wxPoint( m_LibListSize.x, 0 ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_CMPWINDOW:
|
|
|
|
m_CmpListSize.x = event.GetDragRect().width;
|
|
|
|
m_CmpListWindow->SetSize( m_CmpListSize );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, we must recalculate the position and size of subwindows
|
|
|
|
wxSizeEvent SizeEv;
|
|
|
|
OnSize( SizeEv );
|
2009-04-11 15:12:58 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
// Ensure the panel is always redrawn (sometimes some garbage remains):
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************/
|
2008-04-14 19:22:48 +00:00
|
|
|
void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************/
|
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
wxSize clientsize;
|
2008-04-14 19:22:48 +00:00
|
|
|
wxSize maintoolbar_size;
|
|
|
|
wxSize Vtoolbar_size;
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
clientsize = GetClientSize();
|
|
|
|
m_FrameSize = clientsize;
|
|
|
|
clientsize.y -= m_MsgFrameHeight;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
if( m_HToolBar )
|
|
|
|
{
|
|
|
|
maintoolbar_size = m_HToolBar->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_VToolBar )
|
|
|
|
{
|
|
|
|
Vtoolbar_size = m_VToolBar->GetSize();
|
2009-09-02 18:12:45 +00:00
|
|
|
m_VToolBar->SetSize( clientsize.x - maintoolbar_size.y, 0, -1,
|
|
|
|
clientsize.y );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( MsgPanel )
|
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
MsgPanel->SetSize( 0, clientsize.y, clientsize.x, m_MsgFrameHeight );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( DrawPanel )
|
|
|
|
{
|
|
|
|
DrawPanel->SetSize( m_LibListSize.x + m_CmpListSize.x, 0,
|
2009-09-02 18:12:45 +00:00
|
|
|
clientsize.x - Vtoolbar_size.x -
|
|
|
|
m_LibListSize.x - m_CmpListSize.x,
|
2009-04-10 13:39:03 +00:00
|
|
|
clientsize.y );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
if( m_LibList && m_LibListWindow )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
m_LibListSize.y = clientsize.y - 2;
|
|
|
|
m_LibListWindow->SetSize( m_LibListSize );
|
2009-09-02 18:12:45 +00:00
|
|
|
m_LibList->SetSize( m_LibListWindow->GetClientSize() -
|
|
|
|
wxSize( EXTRA_BORDER_SIZE * 2, 0 ) );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
if( m_CmpList && m_CmpListWindow )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
m_CmpListSize.y = clientsize.y - 2;
|
|
|
|
m_CmpListWindow->SetSize( m_CmpListSize );
|
|
|
|
m_CmpListWindow->SetPosition( wxPoint( m_LibListSize.x, 0 ) );
|
2009-09-02 18:12:45 +00:00
|
|
|
m_CmpList->SetSize( m_CmpListWindow->GetClientSize() -
|
|
|
|
wxSize( EXTRA_BORDER_SIZE * 2, 0 ) );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
2009-04-11 15:12:58 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
SizeEv.Skip();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-06 19:44:02 +00:00
|
|
|
/***********************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
int WinEDA_ViewlibFrame::BestZoom()
|
2008-12-06 19:44:02 +00:00
|
|
|
/***********************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
int bestzoom, ii, jj;
|
|
|
|
wxSize size, itemsize;
|
|
|
|
EDA_LibComponentStruct* CurrentLibEntry = NULL;
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
CurrentLibEntry =
|
|
|
|
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
|
|
|
|
g_CurrentViewLibraryName );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
if( CurrentLibEntry == NULL )
|
|
|
|
{
|
|
|
|
bestzoom = 16;
|
|
|
|
GetScreen()->m_Curseur.x = 0;
|
|
|
|
GetScreen()->m_Curseur.y = 0;
|
|
|
|
return bestzoom;
|
|
|
|
}
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
EDA_Rect BoundaryBox = CurrentLibEntry->GetBoundaryBox( g_ViewUnit,
|
|
|
|
g_ViewConvert );
|
2008-04-14 19:22:48 +00:00
|
|
|
itemsize = BoundaryBox.GetSize();
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
size = DrawPanel->GetClientSize();
|
|
|
|
size -= wxSize( 100, 100 ); // reserve a 100 mils margin
|
|
|
|
ii = itemsize.x / size.x;
|
|
|
|
jj = itemsize.y / size.y;
|
|
|
|
bestzoom = MAX( ii, jj ) + 1;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2008-12-06 19:44:02 +00:00
|
|
|
GetScreen()->m_Curseur = BoundaryBox.Centre();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
return bestzoom * GetScreen()->m_ZoomScalar;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2008-12-06 19:44:02 +00:00
|
|
|
/******************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_ViewlibFrame::ReCreateListLib()
|
2008-12-08 18:56:43 +00:00
|
|
|
/******************************************/
|
2009-06-04 10:42:59 +00:00
|
|
|
/** Function ReCreateListLib
|
|
|
|
* Creates or recreates the list of current loaded libraries.
|
|
|
|
* This list is sorted, with the library cache always at end of the list
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-06-04 10:42:59 +00:00
|
|
|
LibraryStruct * libcache = NULL;
|
2008-04-14 19:22:48 +00:00
|
|
|
bool found = FALSE;
|
|
|
|
|
|
|
|
if( m_LibList == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_LibList->Clear();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-06-04 10:42:59 +00:00
|
|
|
wxArrayString libNamesList;
|
|
|
|
for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-06-04 10:42:59 +00:00
|
|
|
if ( Lib->m_IsLibCache )
|
|
|
|
libcache = Lib;
|
|
|
|
else
|
|
|
|
libNamesList.Add( Lib->m_Name );
|
|
|
|
}
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-06-04 10:42:59 +00:00
|
|
|
libNamesList.Sort();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-06-04 10:42:59 +00:00
|
|
|
// Add lib cache
|
|
|
|
if ( libcache )
|
|
|
|
libNamesList.Add( libcache->m_Name );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
m_LibList->Append( libNamesList );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
|
|
|
// Search for a previous selection:
|
|
|
|
for ( unsigned ii = 0; ii < m_LibList->GetCount(); ii++ )
|
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
if( g_CurrentViewLibraryName.Cmp( m_LibList->GetString( ii ) ) == 0 )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
|
|
|
m_LibList->SetSelection( ii, TRUE );
|
|
|
|
found = TRUE;
|
2009-06-04 10:42:59 +00:00
|
|
|
break;
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/* If not found, clear current library selection because it can be
|
|
|
|
* deleted after a config change.
|
2008-12-06 19:44:02 +00:00
|
|
|
*/
|
2008-04-14 19:22:48 +00:00
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
g_CurrentViewLibraryName.Empty();
|
|
|
|
g_CurrentViewComponentName.Empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReCreateListCmp();
|
|
|
|
ReCreateHToolbar();
|
|
|
|
DisplayLibInfos();
|
2008-12-20 13:12:57 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_ViewlibFrame::ReCreateListCmp()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
if( m_CmpList == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName );
|
2009-08-27 11:41:56 +00:00
|
|
|
wxArrayString nameList;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
m_CmpList->Clear();
|
|
|
|
g_CurrentViewComponentName.Empty();
|
2009-08-27 11:41:56 +00:00
|
|
|
g_ViewConvert = 1; /* Select normal/"de morgan" shape */
|
|
|
|
g_ViewUnit = 1; /* Select unit to display for multiple
|
|
|
|
* parts per package */
|
2008-04-14 19:22:48 +00:00
|
|
|
if( Library )
|
2009-08-27 11:41:56 +00:00
|
|
|
Library->GetEntryNames( nameList );
|
|
|
|
m_CmpList->Append( nameList );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
void WinEDA_ViewlibFrame::ClickOnLibList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
int ii = m_LibList->GetSelection();
|
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString name = m_LibList->GetString( ii );
|
|
|
|
if( g_CurrentViewLibraryName == name )
|
|
|
|
return;
|
|
|
|
g_CurrentViewLibraryName = name;
|
|
|
|
ReCreateListCmp();
|
2008-12-20 13:12:57 +00:00
|
|
|
DrawPanel->Refresh();
|
2008-04-14 19:22:48 +00:00
|
|
|
DisplayLibInfos();
|
|
|
|
ReCreateHToolbar();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
void WinEDA_ViewlibFrame::ClickOnCmpList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
int ii = m_CmpList->GetSelection();
|
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString name = m_CmpList->GetString( ii );
|
|
|
|
g_CurrentViewComponentName = name;
|
|
|
|
DisplayLibInfos();
|
|
|
|
g_ViewUnit = 1;
|
|
|
|
g_ViewConvert = 1;
|
|
|
|
Zoom_Automatique( FALSE );
|
|
|
|
ReCreateHToolbar();
|
2008-12-20 13:12:57 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/*
|
|
|
|
* Export the current component to schematic and close the library browser
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2009-09-02 18:12:45 +00:00
|
|
|
void WinEDA_ViewlibFrame::ExportToSchematicLibraryPart( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
int ii = m_CmpList->GetSelection();
|
|
|
|
|
|
|
|
if( ii >= 0 )
|
|
|
|
g_CurrentViewComponentName = m_CmpList->GetString( ii );
|
|
|
|
else
|
|
|
|
g_CurrentViewComponentName.Empty();
|
|
|
|
Close( TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2009-04-10 13:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define LIBLIST_WIDTH_KEY wxT("Liblist_width")
|
|
|
|
#define CMPLIST_WIDTH_KEY wxT("Cmplist_width")
|
|
|
|
/**
|
|
|
|
* Load library viewer frame specific configuration settings.
|
|
|
|
*
|
|
|
|
* Don't forget to call this base method from any derived classes or the
|
|
|
|
* settings will not get loaded.
|
|
|
|
*/
|
|
|
|
void WinEDA_ViewlibFrame::LoadSettings( )
|
|
|
|
{
|
|
|
|
wxConfig* cfg ;
|
|
|
|
|
|
|
|
WinEDA_DrawFrame::LoadSettings();
|
|
|
|
|
|
|
|
wxConfigPathChanger cpc( wxGetApp().m_EDA_Config, m_ConfigPath );
|
|
|
|
cfg = wxGetApp().m_EDA_Config;
|
|
|
|
|
|
|
|
m_LibListSize.x = 150; // default width of libs list
|
|
|
|
m_CmpListSize.x = 150; // default width of component list
|
|
|
|
|
|
|
|
cfg->Read( LIBLIST_WIDTH_KEY, &m_LibListSize.x );
|
|
|
|
cfg->Read( CMPLIST_WIDTH_KEY, &m_CmpListSize.x );
|
2009-04-11 15:12:58 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
// set parameters to a resonnable value
|
|
|
|
if ( m_LibListSize.x > m_FrameSize.x/2 )
|
|
|
|
m_LibListSize.x = m_FrameSize.x/2;
|
|
|
|
|
|
|
|
if ( m_CmpListSize.x > m_FrameSize.x/2 )
|
|
|
|
m_CmpListSize.x = m_FrameSize.x/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save library viewer frame specific configuration settings.
|
|
|
|
*
|
|
|
|
* Don't forget to call this base method from any derived classes or the
|
|
|
|
* settings will not get saved.
|
|
|
|
*/
|
|
|
|
void WinEDA_ViewlibFrame::SaveSettings()
|
|
|
|
{
|
|
|
|
wxConfig* cfg;
|
|
|
|
|
|
|
|
WinEDA_DrawFrame::SaveSettings();
|
|
|
|
|
|
|
|
wxConfigPathChanger cpc( wxGetApp().m_EDA_Config, m_ConfigPath );
|
|
|
|
cfg = wxGetApp().m_EDA_Config;
|
|
|
|
|
|
|
|
if ( m_LibListSize.x )
|
|
|
|
cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.x );
|
|
|
|
cfg->Write( CMPLIST_WIDTH_KEY, m_CmpListSize.x );
|
|
|
|
}
|