Commit 2396cdb1 authored by charras's avatar charras
Browse files

Eeschema: fixed a bug that crashes Eeschema when the library editor or/and the...

Eeschema: fixed a bug that crashes Eeschema when the library editor or/and the lib viewer is opened and if the schematic (or an other) is reloaded (that involves libraries are deleted and reloaded)
parent c200ec93
Loading
Loading
Loading
Loading
+21 −5
Original line number Original line Diff line number Diff line
@@ -210,7 +210,7 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias )
    }
    }


    entries.push_back( (CMP_LIB_ENTRY*) aAlias );
    entries.push_back( (CMP_LIB_ENTRY*) aAlias );
    isModified = true;
    SetModifyFlags( );
    return true;
    return true;
}
}


@@ -225,7 +225,7 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
        return NULL;
        return NULL;


    entries.push_back( (CMP_LIB_ENTRY*) newCmp );
    entries.push_back( (CMP_LIB_ENTRY*) newCmp );
    isModified = true;
    SetModifyFlags( );


    /* Cache libraries are component only libraries.  Do not create alias
    /* Cache libraries are component only libraries.  Do not create alias
     * entries. */
     * entries. */
@@ -280,7 +280,7 @@ void CMP_LIBRARY::RemoveEntry( CMP_LIB_ENTRY* aEntry )
    LIB_COMPONENT* root;
    LIB_COMPONENT* root;
    LIB_ALIAS*  alias;
    LIB_ALIAS*  alias;


    isModified = true;
    SetModifyFlags( );


    if( aEntry->isAlias() )
    if( aEntry->isAlias() )
    {
    {
@@ -393,7 +393,7 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
    entries.push_back( (CMP_LIB_ENTRY*) newCmp );
    entries.push_back( (CMP_LIB_ENTRY*) newCmp );
    entries.sort();
    entries.sort();


    isModified = true;
    SetModifyFlags( );
    return newCmp;
    return newCmp;
}
}


@@ -739,7 +739,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
        return false;
        return false;
    }
    }


    isModified = false;
    ClearModifyFlag( );


    timeStamp = GetTimeStamp();
    timeStamp = GetTimeStamp();
    if( !SaveHeader( libfile ) )
    if( !SaveHeader( libfile ) )
@@ -945,6 +945,22 @@ void CMP_LIBRARY::RemoveLibrary( const wxString& aName )
}
}




 /**
 * Test for an existing library.
 * @param aLibptr - aLibptr.
 * @return true found.  false if not found.
 */
bool CMP_LIBRARY::LibraryExists( const CMP_LIBRARY* aLibptr )
{
    BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
    {
        if( &lib == aLibptr )
            return true;
    }

    return false;
}

CMP_LIBRARY* CMP_LIBRARY::FindLibrary( const wxString& aName )
CMP_LIBRARY* CMP_LIBRARY::FindLibrary( const wxString& aName )
{
{
    BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
    BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
+33 −17
Original line number Original line Diff line number Diff line
@@ -63,6 +63,24 @@ public:
    int            m_Type;         /* type indicator */
    int            m_Type;         /* type indicator */
    int            m_Flags;
    int            m_Flags;


protected:
    wxFileName     fileName;        /* Library file name. */
    wxDateTime     timeStamp;       /* Library save time and date. */
    int            versionMajor;    /* Library major version number. */
    int            versionMinor;    /* Library minor version number. */
    LIB_ENTRY_LIST entries;         /* Parts themselves are saved here. */
    bool           isCache;         /* False for the "standard" libraries,
                                     * True for the library cache */
    wxString       header;          /* first line of loaded library. */

    static CMP_LIBRARY_LIST libraryList;
    static wxArrayString    libraryListSortOrder;

    friend class CMP_LIB_ENTRY;

private:
    bool           isModified;      /* Library modification status. */

public:
public:
    CMP_LIBRARY( int aType, const wxFileName& aFileName );
    CMP_LIBRARY( int aType, const wxFileName& aFileName );
    CMP_LIBRARY( int aType, const wxString& aFileName )
    CMP_LIBRARY( int aType, const wxString& aFileName )
@@ -71,6 +89,12 @@ public:
    }
    }
    ~CMP_LIBRARY();
    ~CMP_LIBRARY();


    /** Modify flags handling:
     */
    void SetModifyFlags( ) { isModified = true; }
    void ClearModifyFlag( ) { isModified = false; }
    bool getModifyFlag( ) { return isModified;}

    /**
    /**
     * Save library to file.
     * Save library to file.
     *
     *
@@ -341,6 +365,14 @@ public:
     * of safety from abusing the library list.
     * of safety from abusing the library list.
     */
     */


     /**
     * Test for an existing library.
     *
     * @param aLibptr - aLibptr.
     * @return true found.  false if not found.
     */

    static bool LibraryExists( const CMP_LIBRARY* aLibptr );
    /**
    /**
     * Load a component library file.
     * Load a component library file.
     *
     *
@@ -442,22 +474,6 @@ public:
    {
    {
        return libraryListSortOrder;
        return libraryListSortOrder;
    }
    }

protected:
    wxFileName     fileName;        /* Library file name. */
    wxDateTime     timeStamp;       /* Library save time and date. */
    int            versionMajor;    /* Library major version number. */
    int            versionMinor;    /* Library minor version number. */
    LIB_ENTRY_LIST entries;         /* Parts themselves are saved here. */
    bool           isModified;      /* Library modification status. */
    bool           isCache;         /* False for the "standard" libraries,
                                     * True for the library cache */
    wxString       header;          /* first line of loaded library. */

    static CMP_LIBRARY_LIST libraryList;
    static wxArrayString    libraryListSortOrder;

    friend class CMP_LIB_ENTRY;
};
};




+4 −2
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#include "general.h"
#include "general.h"
#include "protos.h"
#include "protos.h"
#include "netlist.h"
#include "netlist.h"
#include "libeditfrm.h"
#include "libviewfrm.h"
#include "libviewfrm.h"


#include <wx/tokenzr.h>
#include <wx/tokenzr.h>
@@ -160,8 +161,9 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event )


        // take new list in account
        // take new list in account
        m_Parent->LoadLibraries();
        m_Parent->LoadLibraries();
        if( m_Parent->m_ViewlibFrame )
        // Clear (if needed) the current active library in libedit because it could be
            m_Parent->m_ViewlibFrame->ReCreateListLib();
        // removed from memory
        WinEDA_LibeditFrame::EnsureActiveLibExists();
    }
    }


    m_Parent->SaveProjectFile( this );
    m_Parent->SaveProjectFile( this );
+5 −2
Original line number Original line Diff line number Diff line
@@ -13,6 +13,7 @@
#include "protos.h"
#include "protos.h"
#include "eeschema_id.h"
#include "eeschema_id.h"
#include "class_library.h"
#include "class_library.h"
#include "libeditfrm.h"






@@ -104,8 +105,6 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName,


    GetScreen()->ClrModify();
    GetScreen()->ClrModify();


    //m_CurrentSheet->m_AssociatedScreen->Pnext = NULL; should be by default

    if( IsNew )
    if( IsNew )
    {
    {
        screen->m_CurrentSheetDesc = &g_Sheet_A4;
        screen->m_CurrentSheetDesc = &g_Sheet_A4;
@@ -131,6 +130,10 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName,


    LoadProjectFile( wxEmptyString, FALSE );
    LoadProjectFile( wxEmptyString, FALSE );


    // Clear (if needed) the current active library in libedit because it could be
    // removed from memory
    WinEDA_LibeditFrame::EnsureActiveLibExists();

    // Delete old caches.
    // Delete old caches.
    CMP_LIBRARY::RemoveCacheLibrary();
    CMP_LIBRARY::RemoveCacheLibrary();


+2 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@ void WinEDA_LibeditFrame::DisplayLibInfos()
{
{
    wxString msg = _( "Component Library Editor: " );
    wxString msg = _( "Component Library Editor: " );


    EnsureActiveLibExists();

    if( m_library )
    if( m_library )
        msg += m_library->GetFullFileName();
        msg += m_library->GetFullFileName();
    else
    else
Loading