Commit 9f7ca344 authored by charras's avatar charras
Browse files

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

parent d96039a1
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -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:
+7 −3
Original line number Original line Diff line number Diff line
@@ -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
    if ( g_UserLibDirBuffer != m_LibDirCtrl->GetValue() )
    {
        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
+199 −64
Original line number Original line Diff line number Diff line
@@ -17,21 +17,26 @@
/* class WinEDA_ViewlibFrame */
/* class WinEDA_ViewlibFrame */
/*****************************/
/*****************************/
BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
/* Window events */
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )


/* Sash drag events */
EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
EVT_SASH_DRAGGED( ID_LIBVIEW_CMPWINDOW, WinEDA_ViewlibFrame::OnSashDrag )


/* Toolbar events */
EVT_TOOL_RANGE( ID_LIBVIEW_START_H_TOOL, ID_LIBVIEW_END_H_TOOL,
EVT_TOOL_RANGE( ID_LIBVIEW_START_H_TOOL, ID_LIBVIEW_END_H_TOOL,
                WinEDA_ViewlibFrame::Process_Special_Functions )
                WinEDA_ViewlibFrame::Process_Special_Functions )

EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_ViewlibFrame::OnZoom )
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_ViewlibFrame::OnZoom )

EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC,
EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC,
          WinEDA_ViewlibFrame::ExportToSchematicLibraryPart )
          WinEDA_ViewlibFrame::ExportToSchematicLibraryPart )

EVT_KICAD_CHOICEBOX( ID_LIBVIEW_SELECT_PART_NUMBER,
EVT_KICAD_CHOICEBOX( ID_LIBVIEW_SELECT_PART_NUMBER,
                     WinEDA_ViewlibFrame::Process_Special_Functions )
                     WinEDA_ViewlibFrame::Process_Special_Functions )


/* listbox events */
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
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,12 +69,15 @@ 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_LibListWindow = NULL;
    m_CmpListWindow = NULL;
    m_Semaphore     = semaphore;
    m_Semaphore     = semaphore;


    if( m_Semaphore )
    if( m_Semaphore )
@@ -76,33 +85,58 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,


    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
    LoadSettings();
    SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );


    ReCreateHToolbar();
    ReCreateVToolbar();

    wxSize  size = GetClientSize();
    size.y -= m_MsgFrameHeight + 2;

    m_LibListSize.y = size.y;

    wxPoint win_pos( 0, 0 );
    if( Library == NULL )
    if( Library == NULL )
    {
    {
        m_LibListSize.x = 150; // Width of library list
        // Creates the libraries window display
        m_LibListSize.y = -1;
        m_LibListWindow =
        m_LibList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ),
            new wxSashLayoutWindow( this, ID_LIBVIEW_LIBWINDOW, win_pos, m_LibListSize,
                                   m_LibListSize, 0, NULL, wxLB_HSCROLL );
                                   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 );
        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
    else
    {
        g_CurrentViewLibraryName = Library->m_Name;
        g_CurrentViewLibraryName = Library->m_Name;
        m_LibListSize.x = 0; 
    }


    m_CmpListSize.x = 150; // Width of component list
    // Creates the component window display
    m_CmpListSize.y = -1;
    m_CmpListSize.y = size.y;
    m_CmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST,
    win_pos.x = m_LibListSize.x;
                               wxPoint( m_LibListSize.x, 0 ),
    win_pos.y = 0;
                               m_CmpListSize, 0, NULL, wxLB_HSCROLL );
    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 );
    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();
    SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
    ReCreateHToolbar();
    ReCreateVToolbar();
    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();
}
}




@@ -265,6 +343,9 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
void WinEDA_ViewlibFrame::ReCreateListCmp()
void WinEDA_ViewlibFrame::ReCreateListCmp()
/***********************************************/
/***********************************************/
{
{
    if( m_CmpList == NULL )
        return;

    int ii;
    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 );
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -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
+19 −5
Original line number Original line Diff line number Diff line
@@ -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 );