2011-11-07 19:04:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file viewlib_frame.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <viewlib_frame.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <hotkeys.h>
|
|
|
|
#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;
|
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
|
|
|
|
/// When the viewer is used to select a component in schematic, the selected component is here.
|
2010-11-20 21:59:00 +00:00
|
|
|
wxString LIB_VIEW_FRAME::m_exportToEeschemaCmpName;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* 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 )
|
2012-12-04 19:04:04 +00:00
|
|
|
EVT_LISTBOX_DCLICK( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::DClickOnCmpList )
|
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
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This emulates the zoom menu entries found in the other KiCad applications.
|
2009-01-17 20:31:19 +00:00
|
|
|
* 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 ) )
|
2012-09-12 09:53:11 +00:00
|
|
|
#define LIB_VIEW_FRAME_NAME wxT( "ViewlibFrame" )
|
2009-05-21 17:42:42 +00:00
|
|
|
|
2012-12-06 21:53:00 +00:00
|
|
|
LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
|
|
|
|
wxSemaphore* aSemaphore, long aStyle ) :
|
|
|
|
SCH_BASE_FRAME( aParent, VIEWER_FRAME_TYPE, _( "Library Browser" ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, aStyle, GetLibViewerFrameName() )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
|
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
m_FrameName = GetLibViewerFrameName();
|
2011-12-09 16:37:11 +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;
|
2014-01-19 16:36:12 +00:00
|
|
|
m_cmpList = NULL;
|
|
|
|
m_libList = NULL;
|
|
|
|
m_semaphore = aSemaphore;
|
|
|
|
|
|
|
|
if( m_semaphore )
|
2012-09-11 19:03:21 +00:00
|
|
|
SetModalMode( true );
|
2014-01-19 16:36:12 +00:00
|
|
|
|
2011-04-07 19:17:51 +00:00
|
|
|
m_exportToEeschemaCmpName.Empty();
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2012-01-05 08:07:11 +00:00
|
|
|
SetScreen( new SCH_SCREEN() );
|
2012-09-11 19:03:21 +00:00
|
|
|
GetScreen()->m_Center = true; // Axis origin centered on screen.
|
2009-04-10 13:39:03 +00:00
|
|
|
LoadSettings();
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-04-10 13:39:03 +00:00
|
|
|
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
|
2012-05-06 16:55:51 +00:00
|
|
|
|
|
|
|
// Initialize grid id to the default value (50 mils):
|
|
|
|
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
|
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;
|
|
|
|
|
|
|
|
wxPoint win_pos( 0, 0 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2012-12-06 21:53:00 +00:00
|
|
|
if( aLibrary == NULL )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-04-10 13:39:03 +00:00
|
|
|
// Creates the libraries window display
|
2014-01-19 16:36:12 +00:00
|
|
|
m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST,
|
|
|
|
wxPoint( 0, 0 ), wxSize(m_libListWidth, -1),
|
2010-10-04 18:54:14 +00:00
|
|
|
0, NULL, wxLB_HSCROLL );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-10 13:39:03 +00:00
|
|
|
{
|
2012-12-06 21:53:00 +00:00
|
|
|
m_libraryName = aLibrary->GetName();
|
2009-10-01 14:17:47 +00:00
|
|
|
m_entryName.Clear();
|
|
|
|
m_unit = 1;
|
|
|
|
m_convert = 1;
|
2014-01-19 16:36:12 +00:00
|
|
|
m_libListWidth = 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
|
2014-01-19 16:36:12 +00:00
|
|
|
win_pos.x = m_libListWidth;
|
|
|
|
m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST,
|
|
|
|
wxPoint( 0, 0 ), wxSize(m_cmpListWidth, -1),
|
2009-04-10 13:39:03 +00:00
|
|
|
0, NULL, wxLB_HSCROLL );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_libList )
|
2008-04-14 19:22:48 +00:00
|
|
|
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
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->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
|
|
|
|
|
|
|
|
2011-09-15 18:25:44 +00:00
|
|
|
EDA_PANEINFO horiz;
|
|
|
|
horiz.HorizontalToolbarPane();
|
|
|
|
|
|
|
|
EDA_PANEINFO vert;
|
|
|
|
vert.VerticalToolbarPane();
|
|
|
|
|
|
|
|
EDA_PANEINFO info;
|
|
|
|
info.InfoToolbarPane();
|
|
|
|
|
|
|
|
EDA_PANEINFO mesg;
|
|
|
|
mesg.MessageToolbarPane();
|
2009-11-02 22:24:55 +00:00
|
|
|
|
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage main toolbal
|
2011-12-16 13:32:23 +00:00
|
|
|
m_auimgr.AddPane( m_mainToolBar,
|
|
|
|
wxAuiPaneInfo( horiz ).Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the left window (list of libraries)
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_libList )
|
|
|
|
m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ).
|
|
|
|
Left().Row( 0 ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the list of components)
|
2014-01-19 16:36:12 +00:00
|
|
|
m_auimgr.AddPane( m_cmpList,
|
|
|
|
wxAuiPaneInfo( info ).Name( wxT( "m_cmpList" ) ).
|
2011-09-15 18:25:44 +00:00
|
|
|
Left().Row( 1 ) );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the draw panel
|
2011-12-22 13:28:11 +00:00
|
|
|
m_auimgr.AddPane( m_canvas,
|
2014-01-29 17:01:42 +00:00
|
|
|
wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() );
|
2009-11-02 22:24:55 +00:00
|
|
|
|
2010-01-16 19:42:58 +00:00
|
|
|
// Manage the message panel
|
2011-12-12 14:02:37 +00:00
|
|
|
m_auimgr.AddPane( m_messagePanel,
|
2011-09-15 18:25:44 +00:00
|
|
|
wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) );
|
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
|
2011-11-07 19:04:24 +00:00
|
|
|
* and component list of the previous values from last viewlib use
|
|
|
|
*/
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_libList )
|
2010-01-16 19:42:58 +00:00
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
m_auimgr.GetPane( m_libList ).MinSize( wxSize( 80, -1) );
|
|
|
|
m_auimgr.GetPane( m_libList ).BestSize( wxSize(m_libListWidth, -1) );
|
2010-01-16 19:42:58 +00:00
|
|
|
}
|
2014-01-19 16:36:12 +00:00
|
|
|
|
|
|
|
m_auimgr.GetPane( m_cmpList ).MinSize( wxSize( 80, -1) );
|
|
|
|
m_auimgr.GetPane( m_cmpList ).BestSize(wxSize(m_cmpListWidth, -1) );
|
2010-01-16 19:42:58 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-09 16:30:49 +00:00
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
const wxChar* LIB_VIEW_FRAME::GetLibViewerFrameName()
|
|
|
|
{
|
|
|
|
return LIB_VIEW_FRAME_NAME;
|
|
|
|
}
|
|
|
|
|
2013-11-09 16:30:49 +00:00
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
LIB_VIEW_FRAME* LIB_VIEW_FRAME::GetActiveLibraryViewer()
|
|
|
|
{
|
|
|
|
return (LIB_VIEW_FRAME*) wxWindow::FindWindowByName(GetLibViewerFrameName());
|
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2013-11-09 16:30:49 +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
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_semaphore )
|
2011-04-07 19:30:49 +00:00
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
m_semaphore->Post();
|
2011-04-09 10:52:14 +00:00
|
|
|
// This window will be destroyed by the calling function,
|
2012-08-31 07:43:37 +00:00
|
|
|
// if needed
|
2012-09-11 19:03:21 +00:00
|
|
|
SetModalMode( false );
|
2011-04-07 19:30:49 +00:00
|
|
|
}
|
2011-04-09 10:52:14 +00:00
|
|
|
else
|
2011-11-07 19:04:24 +00:00
|
|
|
{
|
2011-04-09 10:52:14 +00:00
|
|
|
Destroy();
|
2011-11-07 19:04:24 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +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
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
GetScreen()->m_O_Curseur = 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;
|
|
|
|
*/
|
2013-08-03 05:15:23 +00:00
|
|
|
LIB_COMPONENT* component = NULL;
|
|
|
|
double bestzoom = 16.0; // default value for bestzoom
|
|
|
|
CMP_LIBRARY* 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
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
SetScrollCenterPosition( wxPoint( 0, 0 ) );
|
2011-04-09 18:53:39 +00:00
|
|
|
return bestzoom;
|
2009-10-01 14:17:47 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
wxSize size = m_canvas->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-11-07 19:04:24 +00:00
|
|
|
( margin_scale_factor * (double)size.x );
|
2011-04-12 12:41:13 +00:00
|
|
|
double zy = (double) BoundaryBox.GetHeight() /
|
2011-11-07 19:04:24 +00:00
|
|
|
( margin_scale_factor * (double)size.y);
|
2011-04-12 12:41:13 +00:00
|
|
|
|
|
|
|
// Calculates the best zoom
|
2012-09-22 11:19:37 +00:00
|
|
|
bestzoom = std::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
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
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
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::ReCreateListLib()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_libList == NULL )
|
2008-04-14 19:22:48 +00:00
|
|
|
return;
|
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
m_libList->Clear();
|
|
|
|
m_libList->Append( CMP_LIBRARY::GetLibraryNames() );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
|
|
|
// Search for a previous selection:
|
2014-01-19 16:36:12 +00:00
|
|
|
int index = m_libList->FindString( m_libraryName );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
if( index != wxNOT_FOUND )
|
2009-06-04 10:42:59 +00:00
|
|
|
{
|
2014-01-19 16:36:12 +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();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->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
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_cmpList == NULL )
|
2009-04-10 13:39:03 +00:00
|
|
|
return;
|
|
|
|
|
2014-01-19 16:36:12 +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 );
|
2014-01-19 16:36:12 +00:00
|
|
|
m_cmpList->Append( nameList );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
int index = m_cmpList->FindString( m_entryName );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_entryName = wxEmptyString;
|
|
|
|
m_convert = 1;
|
|
|
|
m_unit = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
m_cmpList->SetSelection( index, true );
|
2009-10-01 14:17:47 +00:00
|
|
|
}
|
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
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
int ii = m_libList->GetSelection();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
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();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->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
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
int ii = m_cmpList->GetSelection();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
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();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2009-10-01 14:17:47 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 19:04:04 +00:00
|
|
|
void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
|
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_semaphore )
|
2012-12-04 19:04:04 +00:00
|
|
|
{
|
2012-12-04 19:09:53 +00:00
|
|
|
ExportToSchematicLibraryPart( event );
|
|
|
|
|
|
|
|
// Prevent the double click from being as a single click in the parent
|
|
|
|
// window which would cause the part to be parked rather than staying
|
|
|
|
// in drag mode.
|
2012-12-07 10:05:19 +00:00
|
|
|
((SCH_BASE_FRAME*) GetParent())->SkipNextLeftButtonReleaseEvent();
|
2012-12-04 19:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-09 16:30:49 +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
|
|
|
{
|
2014-01-19 16:36:12 +00:00
|
|
|
int ii = m_cmpList->GetSelection();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
if( ii >= 0 )
|
2014-01-19 16:36:12 +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
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
Close( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2009-04-10 13:39:03 +00:00
|
|
|
|
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
#define LIBLIST_WIDTH_KEY wxT( "ViewLiblistWidth" )
|
|
|
|
#define CMPLIST_WIDTH_KEY wxT( "ViewCmplistWidth" )
|
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
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
|
|
|
|
cfg = wxGetApp().GetSettings();
|
2009-04-10 13:39:03 +00:00
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
cfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 100 );
|
|
|
|
cfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 100 );
|
2009-04-11 15:12:58 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Set parameters to a reasonable value.
|
2014-01-19 16:36:12 +00:00
|
|
|
if ( m_libListWidth > m_FrameSize.x/2 )
|
|
|
|
m_libListWidth = m_FrameSize.x/2;
|
2009-04-10 13:39:03 +00:00
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
if ( m_cmpListWidth > m_FrameSize.x/2 )
|
|
|
|
m_cmpListWidth = m_FrameSize.x/2;
|
2009-04-10 13:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
|
|
|
|
cfg = wxGetApp().GetSettings();
|
2009-04-10 13:39:03 +00:00
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_libListWidth && m_libList)
|
|
|
|
{
|
|
|
|
m_libListWidth = m_libList->GetSize().x;
|
|
|
|
cfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
|
|
|
|
}
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
m_cmpListWidth = m_cmpList->GetSize().x;
|
|
|
|
cfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
|
2009-04-10 13:39:03 +00:00
|
|
|
}
|
2009-12-22 20:08:56 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
|
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();
|
|
|
|
|
2014-01-19 16:36:12 +00:00
|
|
|
if( m_libList )
|
2009-12-22 20:08:56 +00:00
|
|
|
ReCreateListLib();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2009-12-22 20:08:56 +00:00
|
|
|
DisplayLibInfos();
|
|
|
|
}
|