eeschema: Viewlib: listboxes for lib or component selection are now resizable

This commit is contained in:
charras 2009-04-10 13:39:03 +00:00
parent d96039a1fb
commit 9f7ca3444b
5 changed files with 235 additions and 76 deletions

View File

@ -4,6 +4,12 @@ KiCad ChangeLog 2009
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2009-apr-10 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
++eeschema:
Viewlib: listboxes for lib or component selection are now resizable
2009-apr-07 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr> 2009-apr-07 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================ ================================================================================
++pcbnew: ++pcbnew:

View File

@ -109,7 +109,7 @@ void DIALOG_EESCHEMA_CONFIG::Init()
NetlistNameItems.Add( wxT( "OrcadPcb2" ) ); NetlistNameItems.Add( wxT( "OrcadPcb2" ) );
NetlistNameItems.Add( wxT( "CadStar" ) ); NetlistNameItems.Add( wxT( "CadStar" ) );
NetlistNameItems.Add( wxT( "Spice" ) ); NetlistNameItems.Add( wxT( "Spice" ) );
// Add extra neltlist format (using external converter) // Add extra neltlist format (using external converter)
msg = ReturnUserNetlistTypeName( true ); msg = ReturnUserNetlistTypeName( true );
while( !msg.IsEmpty() ) while( !msg.IsEmpty() )
@ -145,9 +145,13 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event )
g_NetFormat = m_NetFormatBox->GetSelection() + NET_TYPE_PCBNEW; g_NetFormat = m_NetFormatBox->GetSelection() + NET_TYPE_PCBNEW;
// Set new default path lib // Set new default path lib
g_UserLibDirBuffer = m_LibDirCtrl->GetValue(); if ( g_UserLibDirBuffer != m_LibDirCtrl->GetValue() )
{
g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
m_LibListChanged = true;
}
// Set new active lib list // Set new active library list if the list of default path was modified
if( m_LibListChanged ) if( m_LibListChanged )
{ {
// Recreate lib list // Recreate lib list

View File

@ -17,23 +17,28 @@
/* class WinEDA_ViewlibFrame */ /* class WinEDA_ViewlibFrame */
/*****************************/ /*****************************/
BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame ) BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow ) /* Window events */
EVT_SIZE( WinEDA_ViewlibFrame::OnSize ) EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate ) EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )
EVT_TOOL_RANGE( ID_LIBVIEW_START_H_TOOL, ID_LIBVIEW_END_H_TOOL, /* Sash drag events */
WinEDA_ViewlibFrame::Process_Special_Functions ) EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
EVT_SASH_DRAGGED( ID_LIBVIEW_CMPWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_ViewlibFrame::OnZoom )
EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, /* Toolbar events */
WinEDA_ViewlibFrame::ExportToSchematicLibraryPart ) 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 )
EVT_KICAD_CHOICEBOX( ID_LIBVIEW_SELECT_PART_NUMBER, /* listbox events */
WinEDA_ViewlibFrame::Process_Special_Functions ) EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
END_EVENT_TABLE() END_EVENT_TABLE()
@ -42,16 +47,17 @@ END_EVENT_TABLE()
* The library viewer does not have any menus so add an accelerator table to * The library viewer does not have any menus so add an accelerator table to
* the main frame. * the main frame.
*/ */
static wxAcceleratorEntry accels[] = { static wxAcceleratorEntry accels[] =
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_POPUP_ZOOM_IN ), {
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_POPUP_ZOOM_OUT ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_ZOOM_IN ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_ZOOM_OUT ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F3, ID_ZOOM_REDRAW ), wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F3, ID_ZOOM_REDRAW ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_POPUP_ZOOM_CENTER ) wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_ZOOM_PAGE )
}; };
#define ACCEL_TABLE_CNT ( sizeof( accels ) / sizeof( wxAcceleratorEntry ) ) #define ACCEL_TABLE_CNT ( sizeof( accels ) / sizeof( wxAcceleratorEntry ) )
#define EXTRA_BORDER_SIZE 2
/******************************************************************************/ /******************************************************************************/
WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father, WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
LibraryStruct* Library, LibraryStruct* Library,
@ -63,46 +69,74 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
wxAcceleratorTable table( ACCEL_TABLE_CNT, accels ); wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
m_FrameName = wxT( "ViewlibFrame" ); m_FrameName = wxT( "ViewlibFrame" );
m_ConfigPath = wxT( "LibraryViewer" );
// Give an icon // Give an icon
SetIcon( wxIcon( library_browse_xpm ) ); SetIcon( wxIcon( library_browse_xpm ) );
m_CmpList = NULL; m_CmpList = NULL;
m_LibList = NULL; m_LibList = NULL;
m_Semaphore = semaphore; m_LibListWindow = NULL;
m_CmpListWindow = NULL;
m_Semaphore = semaphore;
if( m_Semaphore ) if( m_Semaphore )
SetWindowStyle( GetWindowStyle() | wxSTAY_ON_TOP ); SetWindowStyle( GetWindowStyle() | wxSTAY_ON_TOP );
SetBaseScreen( new SCH_SCREEN() ); SetBaseScreen( new SCH_SCREEN() );
GetScreen()->m_Center = true; // set to true to have the coordinates origine -0,0) centered on screen GetScreen()->m_Center = true; // set to true to have the coordinates origine -0,0) centered on screen
if( Library == NULL )
{
m_LibListSize.x = 150; // Width of library list
m_LibListSize.y = -1;
m_LibList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ),
m_LibListSize, 0, NULL, wxLB_HSCROLL );
m_LibList->SetFont( *g_DialogFont );
m_LibList->SetBackgroundColour( wxColour( 255, 255, 255 ) ); // Library background listbox color (white)
m_LibList->SetForegroundColour( wxColour( 0, 0, 0 ) ); // Library foreground listbox color (black)
}
else
g_CurrentViewLibraryName = Library->m_Name;
m_CmpListSize.x = 150; // Width of component list
m_CmpListSize.y = -1;
m_CmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST,
wxPoint( m_LibListSize.x, 0 ),
m_CmpListSize, 0, NULL, wxLB_HSCROLL );
m_CmpList->SetFont( *g_DialogFont );
m_CmpList->SetBackgroundColour( wxColour( 255, 255, 255 ) ); // Component background listbox color (white)
m_CmpList->SetForegroundColour( wxColour( 0, 0, 0 ) ); // Component foreground listbox color (black)
LoadSettings(); LoadSettings();
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
ReCreateHToolbar(); ReCreateHToolbar();
ReCreateVToolbar(); ReCreateVToolbar();
wxSize size = GetClientSize();
size.y -= m_MsgFrameHeight + 2;
m_LibListSize.y = size.y;
wxPoint win_pos( 0, 0 );
if( Library == NULL )
{
// Creates the libraries window display
m_LibListWindow =
new wxSashLayoutWindow( this, ID_LIBVIEW_LIBWINDOW, win_pos, m_LibListSize,
wxCLIP_CHILDREN | wxSW_3D, wxT(
"LibWindow" ) );
m_LibListWindow->SetOrientation( wxLAYOUT_VERTICAL );
m_LibListWindow->SetAlignment( wxLAYOUT_LEFT );
m_LibListWindow->SetSashVisible( wxSASH_RIGHT, TRUE );
m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_LibList = new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ),
m_LibListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0),
0, NULL, wxLB_HSCROLL );
m_LibList->SetFont( *g_DialogFont );
}
else
{
g_CurrentViewLibraryName = Library->m_Name;
m_LibListSize.x = 0;
}
// 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,
win_pos, m_CmpListSize,
wxCLIP_CHILDREN | wxSW_3D, wxT( "CmpWindow" ) );
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 ),
m_CmpListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0),
0, NULL, wxLB_HSCROLL );
m_CmpList->SetFont( *g_DialogFont );
if( m_LibList ) if( m_LibList )
ReCreateListLib(); ReCreateListLib();
DisplayLibInfos(); DisplayLibInfos();
@ -137,17 +171,56 @@ void WinEDA_ViewlibFrame::OnCloseWindow( wxCloseEvent& Event )
} }
/****************************************************/
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 );
// Ensure the panel is always redrawn (sometimes some garbage remains):
DrawPanel->Refresh();
}
/*****************************************************/ /*****************************************************/
void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv ) void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
/*****************************************************/ /*****************************************************/
{ {
wxSize size; wxSize clientsize;
wxSize maintoolbar_size; wxSize maintoolbar_size;
wxSize Vtoolbar_size; wxSize Vtoolbar_size;
GetClientSize( &size.x, &size.y ); clientsize = GetClientSize();
m_FrameSize = size; m_FrameSize = clientsize;
size.y -= m_MsgFrameHeight; clientsize.y -= m_MsgFrameHeight;
if( m_HToolBar ) if( m_HToolBar )
{ {
@ -157,32 +230,37 @@ void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
if( m_VToolBar ) if( m_VToolBar )
{ {
Vtoolbar_size = m_VToolBar->GetSize(); Vtoolbar_size = m_VToolBar->GetSize();
m_VToolBar->SetSize( size.x - maintoolbar_size.y, 0, -1, size.y ); m_VToolBar->SetSize( clientsize.x - maintoolbar_size.y, 0, -1, clientsize.y );
} }
if( MsgPanel ) if( MsgPanel )
{ {
MsgPanel->SetSize( 0, size.y, size.x, m_MsgFrameHeight ); MsgPanel->SetSize( 0, clientsize.y, clientsize.x, m_MsgFrameHeight );
} }
if( DrawPanel ) if( DrawPanel )
{ {
DrawPanel->SetSize( m_LibListSize.x + m_CmpListSize.x, 0, DrawPanel->SetSize( m_LibListSize.x + m_CmpListSize.x, 0,
size.x - Vtoolbar_size.x - m_LibListSize.x - m_CmpListSize.x, clientsize.x - Vtoolbar_size.x - m_LibListSize.x - m_CmpListSize.x,
size.y ); clientsize.y );
} }
if( m_LibList ) if( m_LibList && m_LibListWindow )
{ {
m_LibListSize.y = size.y; m_LibListSize.y = clientsize.y - 2;
m_LibList->SetSize( 0, 0, m_LibListSize.x, m_LibListSize.y ); m_LibListWindow->SetSize( m_LibListSize );
m_LibList->SetSize( m_LibListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0) );
} }
if( m_CmpList ) if( m_CmpList && m_CmpListWindow )
{ {
m_CmpListSize.y = size.y; m_CmpListSize.y = clientsize.y - 2;
m_CmpList->SetSize( m_LibListSize.x, 0, m_CmpListSize.x, m_CmpListSize.y ); m_CmpListWindow->SetSize( m_CmpListSize );
m_CmpListWindow->SetPosition( wxPoint( m_LibListSize.x, 0 ) );
m_CmpList->SetSize( m_CmpListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0) );
} }
SizeEv.Skip();
} }
@ -195,7 +273,7 @@ int WinEDA_ViewlibFrame::BestZoom()
EDA_LibComponentStruct* CurrentLibEntry = NULL; EDA_LibComponentStruct* CurrentLibEntry = NULL;
CurrentLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(), CurrentLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName.GetData(), FIND_ROOT ); g_CurrentViewLibraryName.GetData(), FIND_ROOT );
if( CurrentLibEntry == NULL ) if( CurrentLibEntry == NULL )
{ {
@ -208,11 +286,11 @@ int WinEDA_ViewlibFrame::BestZoom()
EDA_Rect BoundaryBox = CurrentLibEntry->GetBoundaryBox( g_ViewUnit, g_ViewConvert ); EDA_Rect BoundaryBox = CurrentLibEntry->GetBoundaryBox( g_ViewUnit, g_ViewConvert );
itemsize = BoundaryBox.GetSize(); itemsize = BoundaryBox.GetSize();
size = DrawPanel->GetClientSize(); size = DrawPanel->GetClientSize();
size -= wxSize( 100, 100 ); // reserve a 100 mils margin size -= wxSize( 100, 100 ); // reserve a 100 mils margin
ii = itemsize.x / size.x; ii = itemsize.x / size.x;
jj = itemsize.y / size.y; jj = itemsize.y / size.y;
bestzoom = MAX( ii, jj ) + 1; bestzoom = MAX( ii, jj ) + 1;
GetScreen()->m_Curseur = BoundaryBox.Centre(); GetScreen()->m_Curseur = BoundaryBox.Centre();
@ -265,7 +343,10 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
void WinEDA_ViewlibFrame::ReCreateListCmp() void WinEDA_ViewlibFrame::ReCreateListCmp()
/***********************************************/ /***********************************************/
{ {
int ii; if( m_CmpList == NULL )
return;
int ii;
EDA_LibComponentStruct* LibEntry = NULL; EDA_LibComponentStruct* LibEntry = NULL;
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() ); LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
@ -339,3 +420,57 @@ void WinEDA_ViewlibFrame::ExportToSchematicLibraryPart( wxCommandEvent& event )
g_CurrentViewComponentName.Empty(); g_CurrentViewComponentName.Empty();
Close( TRUE ); Close( TRUE );
} }
#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 );
// 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 );
}

View File

@ -392,8 +392,8 @@ enum main_id {
ID_LIBVIEW_SELECT_PART_NUMBER, ID_LIBVIEW_SELECT_PART_NUMBER,
ID_LIBVIEW_LIB_LIST, ID_LIBVIEW_LIB_LIST,
ID_LIBVIEW_CMP_LIST, ID_LIBVIEW_CMP_LIST,
ID_LIBVIEW_UNUSED0, ID_LIBVIEW_LIBWINDOW,
ID_LIBVIEW_UNUSED1, ID_LIBVIEW_CMPWINDOW,
ID_LIBVIEW_UNUSED3, ID_LIBVIEW_UNUSED3,
ID_LIBVIEW_UNUSED4, ID_LIBVIEW_UNUSED4,
ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, // Used in Htoolbar, specific function ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, // Used in Htoolbar, specific function

View File

@ -495,17 +495,27 @@ protected:
}; };
/************************************************************************************************/
/************************************************************************************************/
class LibraryStruct; class LibraryStruct;
class WinEDA_ViewlibFrame : public WinEDA_DrawFrame class WinEDA_ViewlibFrame : public WinEDA_DrawFrame
{ {
public: private:
WinEDAChoiceBox* SelpartBox; WinEDAChoiceBox* SelpartBox;
wxListBox* m_LibList; // List of libraries (for selection
wxSize m_LibListSize; wxSashLayoutWindow* m_LibListWindow; // The redimensionnable window to display the lib list
wxListBox* m_CmpList; wxListBox* m_LibList; // The list of libs
wxSize m_CmpListSize; wxSize m_LibListSize; // size of the window
// List of components in the selected library
wxSashLayoutWindow* m_CmpListWindow; // The redimensionnable window to display the component list
wxListBox* m_CmpList; // The list of components
wxSize m_CmpListSize; // size of the window
// Flags
wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog
wxString m_ConfigPath; // subpath for configuartion
public: public:
WinEDA_ViewlibFrame( wxWindow* father, WinEDA_ViewlibFrame( wxWindow* father,
@ -515,6 +525,7 @@ public:
~WinEDA_ViewlibFrame(); ~WinEDA_ViewlibFrame();
void OnSize( wxSizeEvent& event ); void OnSize( wxSizeEvent& event );
void OnSashDrag( wxSashEvent& event );
void ReCreateListLib(); void ReCreateListLib();
void ReCreateListCmp(); void ReCreateListCmp();
void Process_Special_Functions( wxCommandEvent& event ); void Process_Special_Functions( wxCommandEvent& event );
@ -532,6 +543,9 @@ public:
void GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ); void GeneralControle( wxDC* DC, wxPoint MousePositionInPixels );
void LoadSettings();
void SaveSettings();
private: private:
void SelectCurrentLibrary(); void SelectCurrentLibrary();
void SelectAndViewLibraryPart( int option ); void SelectAndViewLibraryPart( int option );