Commit 29446320 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Code cleanup and minor fix in viewlib.

parent a094f7d5
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -105,10 +105,10 @@ void LIB_VIEW_FRAME::ReCreateHToolbar()

        m_mainToolBar->AddSeparator();

        SelpartBox = new wxComboBox( m_mainToolBar, ID_LIBVIEW_SELECT_PART_NUMBER,
        m_selpartBox = new wxComboBox( m_mainToolBar, ID_LIBVIEW_SELECT_PART_NUMBER,
                                       wxEmptyString, wxDefaultPosition,
                                       wxSize( 150, -1 ), 0, NULL, wxCB_READONLY );
        m_mainToolBar->AddControl( SelpartBox );
        m_mainToolBar->AddControl( m_selpartBox );

        m_mainToolBar->AddSeparator();
        m_mainToolBar->AddTool( ID_LIBVIEW_VIEWDOC, wxEmptyString,
@@ -116,7 +116,7 @@ void LIB_VIEW_FRAME::ReCreateHToolbar()
                                _( "View component documents" ) );
        m_mainToolBar->EnableTool( ID_LIBVIEW_VIEWDOC, false );

        if( m_Semaphore )
        if( m_semaphore )
        {
            // The library browser is called from a "load component" command
            m_mainToolBar->AddSeparator();
@@ -167,17 +167,17 @@ void LIB_VIEW_FRAME::ReCreateHToolbar()
    if( component )
        parts_count = std::max( component->GetPartCount(), 1 );

    SelpartBox->Clear();
    m_selpartBox->Clear();

    for( ii = 0; ii < parts_count; ii++ )
    {
        wxString msg;
        msg.Printf( _( "Unit %c" ), 'A' + ii );
        SelpartBox->Append( msg );
        m_selpartBox->Append( msg );
    }

    SelpartBox->SetSelection( (m_unit > 0 ) ? m_unit - 1 : 0 );
    SelpartBox->Enable( parts_count > 1 );
    m_selpartBox->SetSelection( (m_unit > 0 ) ? m_unit - 1 : 0 );
    m_selpartBox->Enable( parts_count > 1 );

    m_mainToolBar->EnableTool( ID_LIBVIEW_VIEWDOC,
                               entry && ( entry->GetDocFileName() != wxEmptyString ) );
+59 −116
Original line number Diff line number Diff line
@@ -60,10 +60,6 @@ BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
    EVT_SIZE( LIB_VIEW_FRAME::OnSize )
    EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )

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

    /* Toolbar events */
    EVT_TOOL_RANGE( ID_LIBVIEW_NEXT, ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT,
                    LIB_VIEW_FRAME::Process_Special_Functions )
@@ -96,8 +92,6 @@ static wxAcceleratorEntry accels[] =
};

#define ACCEL_TABLE_CNT ( sizeof( accels ) / sizeof( wxAcceleratorEntry ) )

#define EXTRA_BORDER_SIZE 2
#define LIB_VIEW_FRAME_NAME wxT( "ViewlibFrame" )

LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
@@ -117,13 +111,13 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
    SetIcon( icon );

    m_HotkeysZoomAndGridList = s_Viewlib_Hokeys_Descr;
    m_CmpList = NULL;
    m_LibList = NULL;
    m_LibListWindow = NULL;
    m_CmpListWindow = NULL;
    m_Semaphore     = aSemaphore;
    if( m_Semaphore )
    m_cmpList   = NULL;
    m_libList   = NULL;
    m_semaphore = aSemaphore;

    if( m_semaphore )
        SetModalMode( true );

    m_exportToEeschemaCmpName.Empty();

    SetScreen( new SCH_SCREEN() );
@@ -142,23 +136,13 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
    wxSize  size = GetClientSize();
    size.y -= m_MsgFrameHeight + 2;

    m_LibListSize.y = -1;

    wxPoint win_pos( 0, 0 );

    if( aLibrary == NULL )
    {
        // Creates the libraries window display
        m_LibListWindow =
            new wxSashLayoutWindow( this, ID_LIBVIEW_LIBWINDOW, win_pos,
                                    wxDefaultSize, 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 ), wxDefaultSize,
         m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST,
                                   wxPoint( 0, 0 ), wxSize(m_libListWidth, -1),
                                   0, NULL, wxLB_HSCROLL );
    }
    else
@@ -167,25 +151,16 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
        m_entryName.Clear();
        m_unit = 1;
        m_convert = 1;
        m_LibListSize.x = 0;
        m_libListWidth = 0;
    }

    // Creates the component window display
    m_CmpListSize.y = size.y;
    win_pos.x = m_LibListSize.x;
    m_CmpListWindow = new wxSashLayoutWindow( this, ID_LIBVIEW_CMPWINDOW,
                                              win_pos, wxDefaultSize,
                                              wxCLIP_CHILDREN | wxSW_3D,
                                              wxT( "CmpWindow" ) );
    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 ), wxDefaultSize,
    win_pos.x = m_libListWidth;
    m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST,
                               wxPoint( 0, 0 ), wxSize(m_cmpListWidth, -1),
                               0, NULL, wxLB_HSCROLL );

    if( m_LibList )
    if( m_libList )
        ReCreateListLib();

    DisplayLibInfos();
@@ -213,16 +188,14 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
    m_auimgr.AddPane( m_mainToolBar,
                      wxAuiPaneInfo( horiz ).Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) );

    wxSize minsize( 60, -1 );

    // Manage the left window (list of libraries)
    if( m_LibListWindow )
        m_auimgr.AddPane( m_LibListWindow, wxAuiPaneInfo( info ).Name( wxT( "m_LibList" ) ).
    if( m_libList )
        m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ).
                          Left().Row( 0 ) );

    // Manage the list of components)
    m_auimgr.AddPane( m_CmpListWindow,
                      wxAuiPaneInfo( info ).Name( wxT( "m_CmpList" ) ).
    m_auimgr.AddPane( m_cmpList,
                      wxAuiPaneInfo( info ).Name( wxT( "m_cmpList" ) ).
                      Left().Row( 1 ) );

    // Manage the draw panel
@@ -236,13 +209,14 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
    /* Now the minimum windows are fixed, set library list
     * and component list of the previous values from last viewlib use
     */
    if( m_LibListWindow )
    if( m_libList )
    {
        wxAuiPaneInfo& pane = m_auimgr.GetPane(m_LibListWindow);
        pane.MinSize( wxSize(m_LibListSize.x, -1));
        m_auimgr.GetPane( m_libList ).MinSize( wxSize( 80, -1) );
        m_auimgr.GetPane( m_libList ).BestSize( wxSize(m_libListWidth, -1) );
    }
    wxAuiPaneInfo& pane = m_auimgr.GetPane(m_CmpListWindow);
    pane.MinSize(wxSize(m_CmpListSize.x, -1));

    m_auimgr.GetPane( m_cmpList ).MinSize( wxSize( 80, -1) );
    m_auimgr.GetPane( m_cmpList ).BestSize(wxSize(m_cmpListWidth, -1) );

    m_auimgr.Update();

@@ -278,9 +252,9 @@ void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
{
    SaveSettings();

    if( m_Semaphore )
    if( m_semaphore )
    {
        m_Semaphore->Post();
        m_semaphore->Post();
        // This window will be destroyed by the calling function,
        // if needed
        SetModalMode( false );
@@ -292,38 +266,6 @@ void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
}


void LIB_VIEW_FRAME::OnSashDrag( wxSashEvent& event )
{
    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 )
        {
            wxAuiPaneInfo& pane = m_auimgr.GetPane( m_LibListWindow );
            m_LibListSize.x = event.GetDragRect().width;
            pane.MinSize( m_LibListSize );
            m_auimgr.Update();
        }
        break;

    case ID_LIBVIEW_CMPWINDOW:
        {
            wxAuiPaneInfo& pane = m_auimgr.GetPane( m_CmpListWindow );
            m_CmpListSize.x = event.GetDragRect().width;
            pane.MinSize( m_CmpListSize );
            m_auimgr.Update();
        }
        break;
    }
}


void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
{
    if( m_auimgr.GetManagedWindow() )
@@ -388,18 +330,18 @@ double LIB_VIEW_FRAME::BestZoom()

void LIB_VIEW_FRAME::ReCreateListLib()
{
    if( m_LibList == NULL )
    if( m_libList == NULL )
        return;

    m_LibList->Clear();
    m_LibList->Append( CMP_LIBRARY::GetLibraryNames() );
    m_libList->Clear();
    m_libList->Append( CMP_LIBRARY::GetLibraryNames() );

    // Search for a previous selection:
    int index =  m_LibList->FindString( m_libraryName );
    int index = m_libList->FindString( m_libraryName );

    if( index != wxNOT_FOUND )
    {
        m_LibList->SetSelection( index, true );
        m_libList->SetSelection( index, true );
    }
    else
    {
@@ -420,10 +362,10 @@ void LIB_VIEW_FRAME::ReCreateListLib()

void LIB_VIEW_FRAME::ReCreateListCmp()
{
    if( m_CmpList == NULL )
    if( m_cmpList == NULL )
        return;

    m_CmpList->Clear();
    m_cmpList->Clear();

    CMP_LIBRARY* Library = CMP_LIBRARY::FindLibrary( m_libraryName );

@@ -438,9 +380,9 @@ void LIB_VIEW_FRAME::ReCreateListCmp()

    wxArrayString  nameList;
    Library->GetEntryNames( nameList );
    m_CmpList->Append( nameList );
    m_cmpList->Append( nameList );

    int index = m_CmpList->FindString( m_entryName );
    int index = m_cmpList->FindString( m_entryName );

    if( index == wxNOT_FOUND )
    {
@@ -450,19 +392,19 @@ void LIB_VIEW_FRAME::ReCreateListCmp()
    }
    else
    {
        m_CmpList->SetSelection( index, true );
        m_cmpList->SetSelection( index, true );
    }
}


void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
{
    int ii = m_LibList->GetSelection();
    int ii = m_libList->GetSelection();

    if( ii < 0 )
        return;

    wxString name = m_LibList->GetString( ii );
    wxString name = m_libList->GetString( ii );

    if( m_libraryName == name )
        return;
@@ -477,12 +419,12 @@ void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )

void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
{
    int ii = m_CmpList->GetSelection();
    int ii = m_cmpList->GetSelection();

    if( ii < 0 )
        return;

    wxString name = m_CmpList->GetString( ii );
    wxString name = m_cmpList->GetString( ii );

    if( m_entryName.CmpNoCase( name ) != 0 )
    {
@@ -498,7 +440,7 @@ void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )

void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
{
    if( m_Semaphore )
    if( m_semaphore )
    {
        ExportToSchematicLibraryPart( event );

@@ -512,10 +454,10 @@ void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )

void LIB_VIEW_FRAME::ExportToSchematicLibraryPart( wxCommandEvent& event )
{
    int ii = m_CmpList->GetSelection();
    int ii = m_cmpList->GetSelection();

    if( ii >= 0 )
        m_exportToEeschemaCmpName = m_CmpList->GetString( ii );
        m_exportToEeschemaCmpName = m_cmpList->GetString( ii );
    else
        m_exportToEeschemaCmpName.Empty();

@@ -523,8 +465,8 @@ void LIB_VIEW_FRAME::ExportToSchematicLibraryPart( wxCommandEvent& event )
}


#define LIBLIST_WIDTH_KEY wxT( "Liblist_width" )
#define CMPLIST_WIDTH_KEY wxT( "Cmplist_width" )
#define LIBLIST_WIDTH_KEY wxT( "ViewLiblistWidth" )
#define CMPLIST_WIDTH_KEY wxT( "ViewCmplistWidth" )


void LIB_VIEW_FRAME::LoadSettings( )
@@ -536,18 +478,15 @@ void LIB_VIEW_FRAME::LoadSettings( )
    wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
    cfg = wxGetApp().GetSettings();

    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 );
    cfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 100 );
    cfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 100 );

    // Set parameters to a reasonable value.
    if ( m_LibListSize.x > m_FrameSize.x/2 )
        m_LibListSize.x = m_FrameSize.x/2;
    if ( m_libListWidth > m_FrameSize.x/2 )
        m_libListWidth = m_FrameSize.x/2;

    if ( m_CmpListSize.x > m_FrameSize.x/2 )
        m_CmpListSize.x = m_FrameSize.x/2;
    if ( m_cmpListWidth > m_FrameSize.x/2 )
        m_cmpListWidth = m_FrameSize.x/2;
}


@@ -560,10 +499,14 @@ void LIB_VIEW_FRAME::SaveSettings()
    wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
    cfg = wxGetApp().GetSettings();

    if ( m_LibListSize.x )
        cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.x );
    if( m_libListWidth && m_libList)
    {
        m_libListWidth = m_libList->GetSize().x;
        cfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
    }

    cfg->Write( CMPLIST_WIDTH_KEY, m_CmpListSize.x );
    m_cmpListWidth = m_cmpList->GetSize().x;
    cfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
}


@@ -575,7 +518,7 @@ void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
    if( m_FrameIsActive )
        m_exportToEeschemaCmpName.Empty();

    if( m_LibList )
    if( m_libList )
        ReCreateListLib();

    DisplayLibInfos();
+9 −17
Original line number Diff line number Diff line
/*
 * 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.
 * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2008-2014 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2014 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
@@ -48,20 +48,18 @@ class CMP_LIBRARY;
class LIB_VIEW_FRAME : public SCH_BASE_FRAME
{
private:
    wxComboBox*         SelpartBox;
    wxComboBox*         m_selpartBox;

    // List of libraries (for selection )
    wxSashLayoutWindow* m_LibListWindow;
    wxListBox*          m_LibList;          // The list of libs
    wxSize              m_LibListSize;      // size of the window
    wxListBox*          m_libList;          // The list of libs
    int                 m_libListWidth;     // Last width of the window

    // List of components in the selected library
    wxSashLayoutWindow* m_CmpListWindow;
    wxListBox*          m_CmpList;          // The list of components
    wxSize              m_CmpListSize;      // size of the window
    wxListBox*          m_cmpList;          // The list of components
    int                 m_cmpListWidth;     // Last width 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 configuration

protected:
@@ -95,12 +93,6 @@ public:

    void OnSize( wxSizeEvent& event );

    /**
     * Function OnSashDrag
     * resizes the child windows when dragging a sash window border.
     */
    void OnSashDrag( wxSashEvent& event );

    /**
     * Function ReCreateListLib
     *
+7 −7
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ void LIB_VIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
        break;

    case ID_LIBVIEW_SELECT_PART_NUMBER:
        ii = SelpartBox->GetCurrentSelection();
        ii = m_selpartBox->GetCurrentSelection();
        if( ii < 0 )
            return;
        m_unit = ii + 1;
@@ -132,16 +132,16 @@ void LIB_VIEW_FRAME::SelectCurrentLibrary()
        m_libraryName = Lib->GetName();
        DisplayLibInfos();

        if( m_LibList )
        if( m_libList )
        {
            ReCreateListCmp();
            m_canvas->Refresh();
            DisplayLibInfos();
            ReCreateHToolbar();
            int id = m_LibList->FindString( m_libraryName.GetData() );
            int id = m_libList->FindString( m_libraryName.GetData() );

            if( id >= 0 )
                m_LibList->SetSelection( id );
                m_libList->SetSelection( id );
        }
    }
}
@@ -234,11 +234,11 @@ void LIB_VIEW_FRAME::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag )
    Zoom_Automatique( false );
    m_canvas->Refresh( );

    if( m_CmpList )
    if( m_cmpList )
    {
        int id = m_CmpList->FindString( m_entryName.GetData() );
        int id = m_cmpList->FindString( m_entryName.GetData() );
        if( id >= 0 )
            m_CmpList->SetSelection( id );
            m_cmpList->SetSelection( id );
    }
    ReCreateHToolbar();
}