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"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "eeschema_id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2009-09-18 14:56:05 +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-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-02-14 18:14:33 +00:00
|
|
|
#include "hotkeys.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.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.
|
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
wxString LIB_VIEW_FRAME::m_libraryName;
|
|
|
|
wxString LIB_VIEW_FRAME::m_entryName;
|
|
|
|
int LIB_VIEW_FRAME::m_unit = 1;
|
|
|
|
int LIB_VIEW_FRAME::m_convert = 1;
|
|
|
|
|
|
|
|
// When the viewer is used to select a component in schematic, the selected component is here.
|
|
|
|
wxString LIB_VIEW_FRAME::m_exportToEeschemaCmpName;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/*****************************/
|
|
|
|
/* class WinEDA_ViewlibFrame */
|
|
|
|
/*****************************/
|
2011-01-21 19:30:59 +00:00
|
|
|
BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
|
2009-05-21 17:42:42 +00:00
|
|
|
/* Window events */
|
2010-11-20 21:59:00 +00:00
|
|
|
EVT_CLOSE( LIB_VIEW_FRAME::OnCloseWindow )
|
|
|
|
EVT_SIZE( LIB_VIEW_FRAME::OnSize )
|
|
|
|
EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
|
2009-05-21 17:42:42 +00:00
|
|
|
|
|
|
|
/* Sash drag events */
|
2010-11-20 21:59:00 +00:00
|
|
|
EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, LIB_VIEW_FRAME::OnSashDrag )
|
|
|
|
EVT_SASH_DRAGGED( ID_LIBVIEW_CMPWINDOW, LIB_VIEW_FRAME::OnSashDrag )
|
2009-05-21 17:42:42 +00:00
|
|
|
|
|
|
|
/* Toolbar events */
|
2009-09-22 12:27:57 +00:00
|
|
|
EVT_TOOL_RANGE( ID_LIBVIEW_NEXT, ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT,
|
2010-11-20 21:59:00 +00:00
|
|
|
LIB_VIEW_FRAME::Process_Special_Functions )
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2011-04-19 19:19:41 +00:00
|
|
|
EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, LIB_VIEW_FRAME::ExportToSchematicLibraryPart )
|
|
|
|
EVT_COMBOBOX( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::Process_Special_Functions )
|
2009-05-21 17:42:42 +00:00
|
|
|
|
|
|
|
/* listbox events */
|
2010-11-20 21:59:00 +00:00
|
|
|
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, LIB_VIEW_FRAME::ClickOnLibList )
|
|
|
|
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::ClickOnCmpList )
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
EVT_MENU( ID_SET_RELATIVE_OFFSET, LIB_VIEW_FRAME::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
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library, wxSemaphore* semaphore ) :
|
2011-04-07 19:30:49 +00:00
|
|
|
EDA_DRAW_FRAME( father, VIEWER_FRAME, _( "Library Browser" ),
|
|
|
|
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" );
|
2011-04-07 19:30:49 +00:00
|
|
|
m_ConfigPath = wxT( "LibraryViewer" );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
// Give an icon
|
2011-09-08 05:58:45 +00:00
|
|
|
wxIcon icon;
|
|
|
|
icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
|
|
|
|
|
|
|
|
SetIcon( icon );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-02-14 18:14:33 +00:00
|
|
|
m_HotkeysZoomAndGridList = s_Viewlib_Hokeys_Descr;
|
2009-04-10 13:39:03 +00:00
|
|
|
m_CmpList = NULL;
|
|
|
|
m_LibList = NULL;
|
|
|
|
m_LibListWindow = NULL;
|
|
|
|
m_CmpListWindow = NULL;
|
|
|
|
m_Semaphore = semaphore;
|
2011-04-07 19:17:51 +00:00
|
|
|
m_exportToEeschemaCmpName.Empty();
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( m_Semaphore )
|
2011-04-09 10:52:14 +00:00
|
|
|
MakeModal(true);
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
SetScreen( 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;
|
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
m_LibListSize.y = -1;
|
2009-04-10 13:39:03 +00:00
|
|
|
|
|
|
|
wxPoint win_pos( 0, 0 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
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,
|
2010-01-16 19:42:58 +00:00
|
|
|
wxDefaultSize, wxCLIP_CHILDREN | wxSW_3D,
|
2009-05-21 17:42:42 +00:00
|
|
|
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 );
|
2010-10-04 18:54:14 +00:00
|
|
|
m_LibList = new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST,
|
|
|
|
wxPoint( 0, 0 ), wxDefaultSize,
|
|
|
|
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;
|
|
|
|
m_CmpListWindow = new wxSashLayoutWindow( this, ID_LIBVIEW_CMPWINDOW,
|
2010-01-16 19:42:58 +00:00
|
|
|
win_pos, wxDefaultSize,
|
2009-05-21 17:42:42 +00:00
|
|
|
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,
|
2010-01-16 19:42:58 +00:00
|
|
|
wxPoint( 0, 0 ), wxDefaultSize,
|
2009-04-10 13:39:03 +00:00
|
|
|
0, NULL, wxLB_HSCROLL );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( m_LibList )
|
|
|
|
ReCreateListLib();
|
2009-12-22 20:08:56 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
DisplayLibInfos();
|
2009-12-22 20:08:56 +00:00
|
|
|
|
2009-02-12 21:21:01 +00:00
|
|
|
if( DrawPanel )
|
|
|
|
DrawPanel->SetAcceleratorTable( table );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
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
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage main toolbal
|
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
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
wxSize minsize( 60, -1 );
|
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the left window (list of libraries)
|
|
|
|
if( m_LibListWindow )
|
2010-11-20 21:59:00 +00:00
|
|
|
m_auimgr.AddPane( m_LibListWindow, wxAuiPaneInfo( vert ).Name( wxT( "m_LibList" ) ).
|
|
|
|
Left().Row( 0 ).MinSize( minsize ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the list of components)
|
|
|
|
m_auimgr.AddPane( m_CmpListWindow,
|
|
|
|
wxAuiPaneInfo( vert ).Name( wxT( "m_CmpList" ) ).
|
2010-11-20 21:59:00 +00:00
|
|
|
Left().Row( 1 ).MinSize( minsize ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the draw panel
|
2009-11-04 20:46:53 +00:00
|
|
|
m_auimgr.AddPane( DrawPanel,
|
2010-01-16 19:42:58 +00:00
|
|
|
wxAuiPaneInfo( vert ).Name( wxT( "DrawFrame" ) ).Centre() );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the message panel
|
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
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
/* Now the minimum windows are fixed, set library list
|
|
|
|
and component list of the previous values from last viewlib use
|
|
|
|
*/
|
|
|
|
if( m_LibListWindow )
|
|
|
|
{
|
|
|
|
wxAuiPaneInfo& pane = m_auimgr.GetPane(m_LibListWindow);
|
|
|
|
pane.MinSize( wxSize(m_LibListSize.x, -1));
|
|
|
|
}
|
|
|
|
wxAuiPaneInfo& pane = m_auimgr.GetPane(m_CmpListWindow);
|
|
|
|
pane.MinSize(wxSize(m_CmpListSize.x, -1));
|
|
|
|
|
2009-11-02 22:24:55 +00:00
|
|
|
m_auimgr.Update();
|
2011-04-09 18:53:39 +00:00
|
|
|
|
|
|
|
// Now Drawpanel is sized, we can use BestZoom to show the component (if any)
|
|
|
|
#ifdef USE_WX_GRAPHICS_CONTEXT
|
|
|
|
GetScreen()->SetZoom( BestZoom() );
|
|
|
|
#else
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Show( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
LIB_VIEW_FRAME::~LIB_VIEW_FRAME()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) wxGetApp().GetTopWindow();
|
2008-12-08 15:27:13 +00:00
|
|
|
frame->m_ViewlibFrame = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SaveSettings();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2011-04-07 19:30:49 +00:00
|
|
|
if( m_Semaphore )
|
|
|
|
{
|
2011-04-09 10:52:14 +00:00
|
|
|
m_Semaphore->Post();
|
|
|
|
MakeModal(false);
|
|
|
|
// This window will be destroyed by the calling function,
|
|
|
|
// to avoid side effects
|
2011-04-07 19:30:49 +00:00
|
|
|
}
|
2011-04-09 10:52:14 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
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
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::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;
|
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
|
|
|
case ID_LIBVIEW_LIBWINDOW:
|
|
|
|
if( m_LibListWindow )
|
|
|
|
{
|
2010-11-20 21:59:00 +00:00
|
|
|
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_LibListWindow );
|
2010-01-16 19:42:58 +00:00
|
|
|
m_LibListSize.x = event.GetDragRect().width;
|
2010-11-20 21:59:00 +00:00
|
|
|
pane.MinSize( m_LibListSize );
|
2010-01-16 19:42:58 +00:00
|
|
|
m_auimgr.Update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_CMPWINDOW:
|
|
|
|
{
|
2010-11-20 21:59:00 +00:00
|
|
|
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_CmpListWindow );
|
|
|
|
m_CmpListSize.x = event.GetDragRect().width;
|
|
|
|
pane.MinSize( m_CmpListSize );
|
|
|
|
m_auimgr.Update();
|
2010-01-16 19:42:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-04-10 13:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
if( m_auimgr.GetManagedWindow() )
|
|
|
|
m_auimgr.Update();
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
SizeEv.Skip();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
|
2009-10-16 17:18:23 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->m_O_Curseur = GetScreen()->GetCrossHairPosition();
|
2009-10-16 17:18:23 +00:00
|
|
|
UpdateStatusBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
double LIB_VIEW_FRAME::BestZoom()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-04-12 12:41:13 +00:00
|
|
|
/* Please, note: wxMSW before version 2.9 seems have
|
|
|
|
* problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched:
|
|
|
|
* edit file <wxWidgets>/src/msw/dc.cpp
|
|
|
|
* search for line static const int VIEWPORT_EXTENT = 1000;
|
|
|
|
* and replace by static const int VIEWPORT_EXTENT = 10000;
|
|
|
|
*/
|
2011-04-09 18:53:39 +00:00
|
|
|
LIB_COMPONENT* component = NULL;
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* lib;
|
2011-07-05 12:46:14 +00:00
|
|
|
double bestzoom = 16.0; // default value for bestzoom
|
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
|
|
|
|
2011-04-09 18:53:39 +00:00
|
|
|
if( lib )
|
|
|
|
component = lib->FindComponent( m_entryName );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( component == NULL )
|
2009-10-01 14:17:47 +00:00
|
|
|
{
|
2011-04-09 18:53:39 +00:00
|
|
|
GetScreen()->SetScrollCenterPosition( wxPoint( 0, 0 ) );
|
|
|
|
return bestzoom;
|
2009-10-01 14:17:47 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-04-09 18:53:39 +00:00
|
|
|
wxSize size = DrawPanel->GetClientSize();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = component->GetBoundingBox( m_unit, m_convert );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2011-04-09 18:53:39 +00:00
|
|
|
// Reserve a 10% margin around component bounding box.
|
2011-04-12 12:41:13 +00:00
|
|
|
double margin_scale_factor = 0.8;
|
|
|
|
double zx =(double) BoundaryBox.GetWidth() /
|
2011-07-05 12:46:14 +00:00
|
|
|
( margin_scale_factor * (double)size.x );
|
2011-04-12 12:41:13 +00:00
|
|
|
double zy = (double) BoundaryBox.GetHeight() /
|
2011-07-05 12:46:14 +00:00
|
|
|
( margin_scale_factor * (double)size.y);
|
2011-04-12 12:41:13 +00:00
|
|
|
|
|
|
|
// Calculates the best zoom
|
2011-07-05 12:46:14 +00:00
|
|
|
bestzoom = MAX( zx, zy );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2011-04-12 12:41:13 +00:00
|
|
|
// keep it >= minimal existing zoom (can happen for very small components
|
|
|
|
// like small power symbols
|
|
|
|
if( bestzoom < GetScreen()->m_ZoomList[0] )
|
|
|
|
bestzoom = GetScreen()->m_ZoomList[0];
|
2011-03-30 19:20:23 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetScrollCenterPosition( 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
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::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
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::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 );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_libraryName == name )
|
2008-04-14 19:22:48 +00:00
|
|
|
return;
|
2010-11-20 21:59:00 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::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
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::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 )
|
2010-11-20 10:59:59 +00:00
|
|
|
m_exportToEeschemaCmpName = m_CmpList->GetString( ii );
|
2008-04-14 19:22:48 +00:00
|
|
|
else
|
2010-11-20 10:59:59 +00:00
|
|
|
m_exportToEeschemaCmpName.Empty();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
#define LIBLIST_WIDTH_KEY wxT( "Liblist_width" )
|
|
|
|
#define CMPLIST_WIDTH_KEY wxT( "Cmplist_width" )
|
|
|
|
|
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::LoadSettings( )
|
2009-04-10 13:39:03 +00:00
|
|
|
{
|
|
|
|
wxConfig* cfg ;
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_FRAME::LoadSettings();
|
2009-04-10 13:39:03 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::SaveSettings()
|
2009-04-10 13:39:03 +00:00
|
|
|
{
|
|
|
|
wxConfig* cfg;
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_FRAME::SaveSettings();
|
2009-04-10 13:39:03 +00:00
|
|
|
|
|
|
|
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 );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
cfg->Write( CMPLIST_WIDTH_KEY, m_CmpListSize.x );
|
|
|
|
}
|
2009-12-22 20:08:56 +00:00
|
|
|
|
|
|
|
/** Called on activate the frame.
|
|
|
|
* Reload the libraries lists that can be changed by the schematic editor or the library editor
|
|
|
|
*/
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
|
2009-12-22 20:08:56 +00:00
|
|
|
{
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_FRAME::OnActivate( event );
|
2009-12-22 20:08:56 +00:00
|
|
|
|
2010-11-20 10:59:59 +00:00
|
|
|
// Ensure we do not have old selection:
|
|
|
|
if( m_FrameIsActive )
|
|
|
|
m_exportToEeschemaCmpName.Empty();
|
|
|
|
|
2009-12-22 20:08:56 +00:00
|
|
|
if( m_LibList )
|
|
|
|
ReCreateListLib();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-12-22 20:08:56 +00:00
|
|
|
DisplayLibInfos();
|
|
|
|
}
|