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

Fix @JP messages (no bugs, just comment lines)

Eeschema: Viewlib is now accessible from Libedit (to browse libs or load a component to edit)
Libedit: uses now the same dialog as the schematic editor to load a component
Some code cleaning.
parent 9ef6ae5b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
/*********************************/

#include <fctsys.h>
//#include "gr_basic.h"
#include <common.h>
#include <macros.h>
#include <wxstruct.h>
@@ -46,6 +45,7 @@ void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList )
{
    SetFocus();
    m_GetExtraFunction = false;
    m_selectionIsKeyword = false;
    m_historyList->Append( aHistoryList );
    if( !m_auxToolSelector )
    {
@@ -63,6 +63,7 @@ void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event )

void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
{
    m_selectionIsKeyword = false;
    switch( event.GetId() )
    {
    case ID_SEL_BY_LISTBOX:
@@ -74,7 +75,8 @@ void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
        break;

    case ID_ACCEPT_KEYWORD:
        m_Text = wxT( "= " ) + m_textCmpNameCtrl->GetValue();
        m_selectionIsKeyword = true;
        m_Text = m_textCmpNameCtrl->GetValue();
        break;

    case ID_LIST_ALL:
+701 −701

File changed.

Preview size limit exceeded, changes collapsed.

+126 −94
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include <protos.h>
#include <class_library.h>
#include <sch_component.h>
#include <libeditframe.h>
#include <viewlib_frame.h>
#include <eeschema_id.h>

@@ -48,7 +49,7 @@
#include <boost/foreach.hpp>


wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
{
    wxSemaphore semaphore( 0, 1 );
    wxString cmpname;
@@ -60,6 +61,12 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
        m_ViewlibFrame = NULL;
    }

    if( m_LibeditFrame && m_LibeditFrame->m_ViewlibFrame )
    {
        m_LibeditFrame->m_ViewlibFrame->Destroy();
        m_LibeditFrame->m_ViewlibFrame = NULL;
    }

    m_ViewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore );
    // Show the library viewer frame until it is closed
    while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event
@@ -74,36 +81,38 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
    return cmpname;
}


/*
 * load from a library and place a component
 *  if libname != "", search in lib "libname"
 *  else search in all loaded libs
 * Function SelectComponentFromLib
 * Calls the library viewer to select component to import into schematic.
 * if the library viewer is currently running, it is closed and reopened
 * in modal mode.
 * param aLibname = the lib name or an empty string.
 *     if aLibname is empty, the full list of libraries is used
 * param aList = list of previously loaded components
 * param aUseLibBrowser = bool to call the library viewer to select the component
 * param aUnit = a point to int to return the selected unit (if any)
 * param aConvert = a point to int to return the selected De Morgan shape (if any)
 *
 * return the component name
 */
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC*           DC,
                                               const wxString& libname,
                                               wxArrayString&  HistoryList,
                                               bool            UseLibBrowser )
wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
                                                     wxArrayString&  aHistoryList,
                                                     bool            aUseLibBrowser,
                                                     int*            aUnit,
                                                     int*            aConvert )
{
    int             CmpCount  = 0;
    int             unit      = 1;
    int             convert   = 1;
    LIB_COMPONENT*  Entry     = NULL;
    SCH_COMPONENT*  component = NULL;
    CMP_LIBRARY*    Library   = NULL;
    wxString        Name, keys, msg;
    bool            AllowWildSeach = true;
    static wxString lastCommponentName;
    LIB_COMPONENT*  libEntry     = NULL;
    CMP_LIBRARY*    currLibrary   = NULL;
    wxString        cmpName, keys, msg;
    bool            allowWildSeach = true;

    m_itemToRepeat = NULL;
    m_canvas->SetIgnoreMouseEvents( true );

    if( !libname.IsEmpty() )
    if( !aLibname.IsEmpty() )
    {
        Library = CMP_LIBRARY::FindLibrary( libname );
        currLibrary = CMP_LIBRARY::FindLibrary( aLibname );

        if( Library != NULL )
            CmpCount = Library->GetCount();
        if( currLibrary != NULL )
            CmpCount = currLibrary->GetCount();
    }
    else
    {
@@ -116,109 +125,132 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
    /* Ask for a component name or key words */
    msg.Printf( _( "component selection (%d items loaded):" ), CmpCount );

    DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList,
                              msg, UseLibBrowser );
    dlg.SetComponentName( lastCommponentName );
    DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), aHistoryList,
                              msg, aUseLibBrowser );
    if(  aHistoryList.GetCount() )
        dlg.SetComponentName( aHistoryList[0] );

    if ( dlg.ShowModal() == wxID_CANCEL )
    {
        m_canvas->SetIgnoreMouseEvents( false );
        m_canvas->MoveCursorToCrossHair();
        return NULL;
    }
        return wxEmptyString;

    if( dlg.m_GetExtraFunction )
    {
        Name = SelectFromLibBrowser();
        unit = m_ViewlibFrame->GetUnit();
        convert = m_ViewlibFrame->GetConvert();
        cmpName = SelectComponentFromLibBrowser();
        if( aUnit )
            *aUnit = m_ViewlibFrame->GetUnit();
        if( aConvert )
            *aConvert = m_ViewlibFrame->GetConvert();
        if( !cmpName.IsEmpty() )
            AddHistoryComponentName( aHistoryList, cmpName );
        return cmpName;
    }
    else
    {
        Name = dlg.GetComponentName();
    }
        cmpName = dlg.GetComponentName();

    if( Name.IsEmpty() )
    {
        m_canvas->SetIgnoreMouseEvents( false );
        m_canvas->MoveCursorToCrossHair();
        return NULL;
    }
    if( cmpName.IsEmpty() )
        return wxEmptyString;

#ifndef KICAD_KEEPCASE
    Name.MakeUpper();
    cmpName.MakeUpper();
#endif

    if( Name.GetChar( 0 ) == '=' )
    if( dlg.IsKeyword() )
    {
        AllowWildSeach = false;
        keys = Name.AfterFirst( '=' );
        Name = DataBaseGetName( this, keys, Name );
        allowWildSeach = false;
        keys = cmpName;
        cmpName = DataBaseGetName( this, keys, cmpName );

        if( Name.IsEmpty() )
        {
            m_canvas->SetIgnoreMouseEvents( false );
            m_canvas->MoveCursorToCrossHair();
            return NULL;
        if( cmpName.IsEmpty() )
            return wxEmptyString;
     }
    }
    else if( Name == wxT( "*" ) )
    else if( cmpName == wxT( "*" ) )
    {
        AllowWildSeach = false;
        allowWildSeach = false;

        if( GetNameOfPartToLoad( this, Library, Name ) == 0 )
        {
            m_canvas->SetIgnoreMouseEvents( false );
            m_canvas->MoveCursorToCrossHair();
            return NULL;
        if( GetNameOfPartToLoad( this, currLibrary, cmpName ) == 0 )
            return wxEmptyString;
    }
    else if( cmpName.Contains( wxT( "?" ) ) || cmpName.Contains( wxT( "*" ) ) )
    {
        allowWildSeach = false;
        cmpName = DataBaseGetName( this, keys, cmpName );

        if( cmpName.IsEmpty() )
            return wxEmptyString;
    }
    else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) )

    libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname );

    if( ( libEntry == NULL ) && allowWildSeach ) /* Search with wildcard */
    {
        AllowWildSeach = false;
        Name = DataBaseGetName( this, keys, Name );
        allowWildSeach = false;
        wxString wildname = wxChar( '*' ) + cmpName + wxChar( '*' );
        cmpName = wildname;
        cmpName = DataBaseGetName( this, keys, cmpName );

        if( Name.IsEmpty() )
        if( !cmpName.IsEmpty() )
            libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname );

        if( libEntry == NULL )
            return wxEmptyString;
    }

    if( libEntry == NULL )
    {
            m_canvas->SetIgnoreMouseEvents( false );
            m_canvas->MoveCursorToCrossHair();
            return NULL;
        msg = _( "Failed to find part " ) + cmpName + _( " in library" );
        DisplayError( this, msg );
        return wxEmptyString;
    }

    AddHistoryComponentName( aHistoryList, cmpName );
    return cmpName;
}

    Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname );

    if( ( Entry == NULL ) && AllowWildSeach ) /* Search with wildcard */
/*
 * load from a library and place a component
 *  if libname != "", search in lib "libname"
 *  else search in all loaded libs
 */
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC*           aDC,
                                               const wxString& aLibname,
                                               wxArrayString&  aHistoryList,
                                               bool            aUseLibBrowser )
{
        AllowWildSeach = false;
        wxString wildname = wxChar( '*' ) + Name + wxChar( '*' );
        Name = wildname;
        Name = DataBaseGetName( this, keys, Name );
    int unit    = 1;
    int convert = 1;

        if( !Name.IsEmpty() )
            Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname );
    m_itemToRepeat = NULL;
    m_canvas->SetIgnoreMouseEvents( true );

        if( Entry == NULL )
    wxString Name = SelectComponentFromLibrary( aLibname, aHistoryList, aUseLibBrowser,
                                                &unit, &convert );

    if( Name.IsEmpty() )
    {
        m_canvas->SetIgnoreMouseEvents( false );
        m_canvas->MoveCursorToCrossHair();
        return NULL;
    }
    }

#ifndef KICAD_KEEPCASE
    Name.MakeUpper();
#endif

    LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( Name, aLibname );

    m_canvas->SetIgnoreMouseEvents( false );
    m_canvas->MoveCursorToCrossHair();

    if( Entry == NULL )
    {
        msg = _( "Failed to find part " ) + Name + _( " in library" );
        DisplayError( this, msg );
        wxString msg;
        msg.Printf( _( "Failed to find part <%s> in library" ), GetChars( Name ) );
        wxMessageBox( msg );
        return NULL;
    }

    lastCommponentName = Name;
    AddHistoryComponentName( HistoryList, Name );

    SCH_COMPONENT*  component;
    component = new SCH_COMPONENT( *Entry, m_CurrentSheet, unit, convert,
                                   GetScreen()->GetCrossHairPosition(), true );

@@ -230,10 +262,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
    // Set the component value that can differ from component name in lib, for aliases
    component->GetField( VALUE )->m_Text = Name;
    component->DisplayInfo( this );
    component->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    component->SetFlags( IS_NEW );

    MoveItem( (SCH_ITEM*) component, DC );
    MoveItem( (SCH_ITEM*) component, aDC );

    return component;
}
+29 −9
Original line number Diff line number Diff line
@@ -113,10 +113,9 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry )

void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
{
    int        i;
    wxString   msg;
    wxString   CmpName;
    LIB_ALIAS* LibEntry = NULL;
    LIB_ALIAS* libEntry = NULL;

    m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );

@@ -133,9 +132,10 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
            return;
    }

    i = GetNameOfPartToLoad( this, m_library, CmpName );
    wxArrayString historyList;
    CmpName = SelectComponentFromLibrary( m_library->GetName(), historyList, true, NULL, NULL );

    if( i == 0 )
    if( CmpName.IsEmpty() )
        return;

    GetScreen()->ClrModify();
@@ -149,19 +149,39 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
    }

    /* Load the new library component */
    LibEntry = m_library->FindEntry( CmpName );
    libEntry = m_library->FindEntry( CmpName );
    CMP_LIBRARY* searchLib = m_library;
    if( libEntry == NULL )
    {   // Not found in the active library: search inside the full list
        // (can happen when using Viewlib to load a component)
        libEntry = CMP_LIBRARY::FindLibraryEntry( CmpName );
        if( libEntry )
        {
            searchLib = libEntry->GetLibrary();
            // The entry to load is not in the active lib
            // Ask for a new active lib
            wxString msg;
            msg << _("The selected component is not in the active library");
            msg << wxT("\n\n");
            msg << _("Do you want to change the active library?");
            if( IsOK( this, msg ) )
                SelectActiveLibrary( searchLib );
        }
    }

    if( LibEntry == NULL )
    if( libEntry == NULL )
    {
        msg.Printf( _( "Component name \"%s\" not found in library \"%s\"." ),
                    GetChars( CmpName ),
                    GetChars( m_library->GetName() ) );
                    GetChars( searchLib->GetName() ) );
        DisplayError( this, msg );
        return;
    }

    if( ! LoadComponentFromCurrentLib( LibEntry ) )
        return;
    EXCHG( searchLib, m_library );
    LoadComponentFromCurrentLib( libEntry );
    EXCHG( searchLib, m_library );
    DisplayLibInfos();
}


+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
    EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::SaveActiveLibrary )
    EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, LIB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( ID_LIBEDIT_DELETE_PART, LIB_EDIT_FRAME::DeleteOnePart )
    EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer )
    EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::CreateNewLibraryPart )
    EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting )

Loading