2009-11-04 20:46:53 +00:00
|
|
|
/***********************/
|
|
|
|
/* viewlib_frame.cpp */
|
|
|
|
/***********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#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-09-22 12:27:57 +00:00
|
|
|
#include "eeschema_id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
#include "bitmaps.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "libviewfrm.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
/**
|
|
|
|
* Save previous component library viewer state.
|
|
|
|
*/
|
|
|
|
wxString WinEDA_ViewlibFrame::m_libraryName;
|
|
|
|
wxString WinEDA_ViewlibFrame::m_entryName;
|
|
|
|
int WinEDA_ViewlibFrame::m_unit = 1;
|
|
|
|
int WinEDA_ViewlibFrame::m_convert = 1;
|
|
|
|
wxSize WinEDA_ViewlibFrame::m_clientSize = wxSize( -1, -1 );
|
|
|
|
|
|
|
|
|
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 */
|
2009-09-22 12:27:57 +00:00
|
|
|
EVT_TOOL_RANGE( ID_LIBVIEW_NEXT, ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT,
|
2009-05-21 17:42:42 +00:00
|
|
|
WinEDA_ViewlibFrame::Process_Special_Functions )
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
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 )
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
EVT_MENU( ID_SET_RELATIVE_OFFSET,
|
|
|
|
WinEDA_ViewlibFrame::OnSetRelativeOffset )
|
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-09-27 14:09:26 +00:00
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_POPUP_ZOOM_CENTER ),
|
2009-10-16 17:18:23 +00:00
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_HOME, ID_ZOOM_PAGE ),
|
|
|
|
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_SPACE, ID_SET_RELATIVE_OFFSET )
|
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
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
|
|
|
|
CMP_LIBRARY* Library,
|
|
|
|
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() );
|
2009-11-04 20:46:53 +00:00
|
|
|
GetScreen()->m_Center = true; // Center coordinate origins on screen.
|
2009-04-10 13:39:03 +00:00
|
|
|
LoadSettings();
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
// Initialize grid id to a default value if not found in config or bad:
|
|
|
|
if( ( m_LastGridSizeId <= 0 ) ||
|
|
|
|
( m_LastGridSizeId < ( ID_POPUP_GRID_USER - ID_POPUP_GRID_LEVEL_1000 ) ) )
|
2009-10-17 06:23:18 +00:00
|
|
|
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
|
2009-10-14 19:43:31 +00:00
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
2009-04-10 13:39:03 +00:00
|
|
|
|
|
|
|
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 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-11-05 08:52:41 +00:00
|
|
|
#if !defined(KICAD_AUIMANAGER)
|
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
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
m_libraryName = Library->GetName();
|
|
|
|
m_entryName.Clear();
|
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
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->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 );
|
2009-11-02 22:24:55 +00:00
|
|
|
#else
|
|
|
|
if( Library == NULL )
|
|
|
|
{
|
|
|
|
m_LibList =
|
|
|
|
new wxListBox( this, ID_LIBVIEW_LIB_LIST,
|
|
|
|
wxPoint( 0, 0 ),
|
|
|
|
wxDefaultSize,
|
|
|
|
0, NULL, wxLB_HSCROLL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_libraryName = Library->GetName();
|
|
|
|
m_entryName.Clear();
|
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
|
|
|
m_LibListSize.x = 0;
|
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-11-02 22:24:55 +00:00
|
|
|
m_CmpList = new wxListBox( this , ID_LIBVIEW_CMP_LIST,
|
|
|
|
wxPoint( 0, 0 ),
|
|
|
|
wxDefaultSize,
|
|
|
|
0, NULL, wxLB_HSCROLL );
|
|
|
|
|
|
|
|
#endif
|
2009-11-04 20:46:53 +00:00
|
|
|
|
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 );
|
2009-10-01 14:17:47 +00:00
|
|
|
Zoom_Automatique( false );
|
2008-04-14 19:22:48 +00:00
|
|
|
Show( TRUE );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-05 08:52:41 +00:00
|
|
|
#if defined(KICAD_AUIMANAGER)
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.SetManagedWindow( this );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
|
|
|
wxAuiPaneInfo horiz;
|
2009-11-04 20:46:53 +00:00
|
|
|
horiz.Gripper( false );
|
|
|
|
horiz.DockFixed( true );
|
|
|
|
horiz.Movable( false );
|
|
|
|
horiz.Floatable( false );
|
|
|
|
horiz.CloseButton( false );
|
|
|
|
horiz.CaptionVisible( false );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
wxAuiPaneInfo vert( horiz );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
vert.TopDockable( false ).BottomDockable( false );
|
|
|
|
horiz.LeftDockable( false ).RightDockable( false );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.AddPane( m_HToolBar,
|
|
|
|
wxAuiPaneInfo( horiz ).Name( wxT ("m_HToolBar" ) ).Top().Row( 0 ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.AddPane( m_LibList,
|
|
|
|
wxAuiPaneInfo( vert ).Name( wxT( "m_LibList" ) ).Left().Row( 0 ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.AddPane( m_CmpList,
|
|
|
|
wxAuiPaneInfo( vert ).Name( wxT( "m_CmpList" ) ).Left().Row( 1 ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.AddPane( DrawPanel,
|
|
|
|
wxAuiPaneInfo( vert ).Name( wxT( "DrawFrame" ) ).Center() );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.AddPane( MsgPanel,
|
|
|
|
wxAuiPaneInfo( horiz ).Name( wxT( "MsgPanel" ) ).Bottom() );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
|
|
|
m_auimgr.Update();
|
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_ViewlibFrame::~WinEDA_ViewlibFrame()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
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
|
|
|
|
|
|
|
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-10-01 14:17:47 +00:00
|
|
|
/*
|
|
|
|
* Resize sub windows when dragging a sash window border
|
2009-04-10 13:39:03 +00:00
|
|
|
*/
|
2009-10-01 14:17:47 +00:00
|
|
|
void WinEDA_ViewlibFrame::OnSashDrag( wxSashEvent& event )
|
2009-04-10 13:39:03 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-11-04 20:46:53 +00:00
|
|
|
|
2009-11-05 08:52:41 +00:00
|
|
|
#if defined(KICAD_AUIMANAGER)
|
2009-11-04 20:46:53 +00:00
|
|
|
if( m_auimgr.GetManagedWindow() )
|
|
|
|
m_auimgr.Update();
|
2009-11-02 22:24:55 +00:00
|
|
|
#endif
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
SizeEv.Skip();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
void WinEDA_ViewlibFrame::OnSetRelativeOffset( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
GetScreen()->m_O_Curseur = GetScreen()->m_Curseur;
|
|
|
|
UpdateStatusBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
int WinEDA_ViewlibFrame::BestZoom()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
int bestzoom, ii, jj;
|
2009-10-01 14:17:47 +00:00
|
|
|
wxSize size;
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* component;
|
|
|
|
CMP_LIBRARY* lib;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
GetScreen()->m_Curseur.x = 0;
|
|
|
|
GetScreen()->m_Curseur.y = 0;
|
|
|
|
bestzoom = 16;
|
2008-04-14 19:22:48 +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 bestzoom;
|
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
component = lib->FindComponent( m_entryName );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( component == NULL )
|
2008-04-14 19:22:48 +00:00
|
|
|
return bestzoom;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This fixes a bug where the client size of the drawing area is not
|
|
|
|
* correctly reported until after the window is shown. This is most
|
|
|
|
* likely due to the unmanaged windows ( vertical tool bars and message
|
|
|
|
* panel ) that are drawn in the main window which wxWidgets knows
|
|
|
|
* nothing about. When the library editor is reopened with a component
|
|
|
|
* already loading, the zoom will be calculated correctly.
|
|
|
|
*/
|
|
|
|
if( !IsShownOnScreen() )
|
|
|
|
{
|
|
|
|
if( m_clientSize != wxSize( -1, -1 ) )
|
|
|
|
size = m_clientSize;
|
|
|
|
else
|
|
|
|
size = DrawPanel->GetClientSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_clientSize == wxSize( -1, -1 ) )
|
|
|
|
m_clientSize = DrawPanel->GetClientSize();
|
|
|
|
size = m_clientSize;
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
EDA_Rect BoundaryBox = component->GetBoundaryBox( m_unit, m_convert );
|
|
|
|
|
|
|
|
// Reserve a 25 mils margin around component bounding box.
|
|
|
|
size -= wxSize( 25, 25 );
|
|
|
|
ii = wxRound( ( (double) BoundaryBox.GetWidth() / double( size.x ) ) *
|
|
|
|
(double) GetScreen()->m_ZoomScalar );
|
|
|
|
jj = wxRound( ( (double) BoundaryBox.GetHeight() / (double) size.y ) *
|
|
|
|
(double) GetScreen()->m_ZoomScalar );
|
2009-04-10 13:39:03 +00:00
|
|
|
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-10-01 14:17:47 +00:00
|
|
|
return bestzoom;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/**
|
|
|
|
* Function ReCreateListLib
|
|
|
|
*
|
2009-06-04 10:42:59 +00:00
|
|
|
* Creates or recreates the list of current loaded libraries.
|
|
|
|
* This list is sorted, with the library cache always at end of the list
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
|
|
|
void WinEDA_ViewlibFrame::ReCreateListLib()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
if( m_LibList == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_LibList->Clear();
|
2009-10-01 14:17:47 +00:00
|
|
|
m_LibList->Append( CMP_LIBRARY::GetLibraryNames() );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
|
|
|
// Search for a previous selection:
|
2009-10-01 14:17:47 +00:00
|
|
|
int index = m_LibList->FindString( m_libraryName );
|
|
|
|
|
|
|
|
if( index != wxNOT_FOUND )
|
2009-06-04 10:42:59 +00:00
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
m_LibList->SetSelection( index, true );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
2009-10-01 14:17:47 +00:00
|
|
|
else
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
/* If not found, clear current library selection because it can be
|
|
|
|
* deleted after a config change. */
|
|
|
|
m_libraryName = wxEmptyString;
|
|
|
|
m_entryName = wxEmptyString;
|
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
m_CmpList->Clear();
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
CMP_LIBRARY* Library = CMP_LIBRARY::FindLibrary( m_libraryName );
|
|
|
|
|
|
|
|
if( Library == NULL )
|
|
|
|
{
|
|
|
|
m_libraryName = wxEmptyString;
|
|
|
|
m_entryName = wxEmptyString;
|
|
|
|
m_convert = 1;
|
|
|
|
m_unit = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString nameList;
|
|
|
|
Library->GetEntryNames( nameList );
|
2009-08-27 11:41:56 +00:00
|
|
|
m_CmpList->Append( nameList );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
int index = m_CmpList->FindString( m_entryName );
|
|
|
|
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_entryName = wxEmptyString;
|
|
|
|
m_convert = 1;
|
|
|
|
m_unit = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_CmpList->SetSelection( index, true );
|
|
|
|
}
|
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 );
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_libraryName == name )
|
2008-04-14 19:22:48 +00:00
|
|
|
return;
|
2009-10-01 14:17:47 +00:00
|
|
|
m_libraryName = name;
|
2008-04-14 19:22:48 +00:00
|
|
|
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 );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
if( m_entryName.CmpNoCase( name ) != 0 )
|
|
|
|
{
|
|
|
|
m_entryName = name;
|
|
|
|
DisplayLibInfos();
|
2009-10-18 11:41:05 +00:00
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
2009-10-01 14:17:47 +00:00
|
|
|
Zoom_Automatique( false );
|
|
|
|
ReCreateHToolbar();
|
|
|
|
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 )
|
2009-10-01 14:17:47 +00:00
|
|
|
m_entryName = m_CmpList->GetString( ii );
|
2008-04-14 19:22:48 +00:00
|
|
|
else
|
2009-10-01 14:17:47 +00:00
|
|
|
m_entryName.Empty();
|
2008-04-14 19:22:48 +00:00
|
|
|
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-11-04 20:46:53 +00:00
|
|
|
// Set parameters to a reasonable value.
|
2009-04-10 13:39:03 +00:00
|
|
|
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 );
|
|
|
|
}
|