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)

This commit is contained in:
charras 2009-12-22 20:08:56 +00:00
parent c200ec9338
commit 2396cdb127
10 changed files with 132 additions and 30 deletions

View File

@ -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 )

View File

@ -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.
* *
@ -152,7 +176,7 @@ public:
void SetCache( void ) { isCache = true; } void SetCache( void ) { isCache = true; }
/** /**
* Load a string array with the names of all the entries in this library. * Load a string array with the names of all the entries in this library.
* *
* @param aNames - String array to place entry names into. * @param aNames - String array to place entry names into.
@ -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;
}; };

View File

@ -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 );

View File

@ -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();

View File

@ -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

View File

@ -34,6 +34,12 @@ public:
~WinEDA_LibeditFrame(); ~WinEDA_LibeditFrame();
/** Function EnsureActiveLibExists
* Must be called after the libraries are reloaded
* (for instance after loading a schematic project)
*/
static void EnsureActiveLibExists();
void Process_Special_Functions( wxCommandEvent& event ); void Process_Special_Functions( wxCommandEvent& event );
void OnImportPart( wxCommandEvent& event ); void OnImportPart( wxCommandEvent& event );
void OnExportPart( wxCommandEvent& event ); void OnExportPart( wxCommandEvent& event );
@ -127,6 +133,10 @@ public:
private: private:
/** OnActivate event funtion( virtual )
*/
virtual void OnActivate( wxActivateEvent& event );
// General: // General:
void SaveOnePartInMemory(); void SaveOnePartInMemory();
void SelectActiveLibrary(); void SelectActiveLibrary();
@ -209,11 +219,11 @@ protected:
/** Default line width for drawing or editing graphic items. */ /** Default line width for drawing or editing graphic items. */
static int m_drawLineWidth; static int m_drawLineWidth;
/** The current active libary. NULL if no active library is selected. */
static CMP_LIBRARY* m_library;
/** The current component being edited. NULL if no component is selected. */ /** The current component being edited. NULL if no component is selected. */
static LIB_COMPONENT* m_component; static LIB_COMPONENT* m_component;
/** The current active libary. NULL if no library is active. */
static CMP_LIBRARY* m_library;
static LIB_DRAW_ITEM* m_lastDrawItem; static LIB_DRAW_ITEM* m_lastDrawItem;
static LIB_DRAW_ITEM* m_drawItem; static LIB_DRAW_ITEM* m_drawItem;
static wxString m_aliasName; static wxString m_aliasName;

View File

@ -43,6 +43,7 @@ int CreateNewLibAndSavePartId = ::wxNewId();
*/ */
LIB_COMPONENT* WinEDA_LibeditFrame::m_component = NULL; LIB_COMPONENT* WinEDA_LibeditFrame::m_component = NULL;
CMP_LIBRARY* WinEDA_LibeditFrame::m_library = NULL; CMP_LIBRARY* WinEDA_LibeditFrame::m_library = NULL;
wxString WinEDA_LibeditFrame::m_aliasName; wxString WinEDA_LibeditFrame::m_aliasName;
int WinEDA_LibeditFrame::m_unit = 1; int WinEDA_LibeditFrame::m_unit = 1;
int WinEDA_LibeditFrame::m_convert = 1; int WinEDA_LibeditFrame::m_convert = 1;
@ -62,6 +63,7 @@ FILL_T WinEDA_LibeditFrame::m_drawFillStyle = NO_FILL;
BEGIN_EVENT_TABLE( WinEDA_LibeditFrame, WinEDA_DrawFrame ) BEGIN_EVENT_TABLE( WinEDA_LibeditFrame, WinEDA_DrawFrame )
EVT_CLOSE( WinEDA_LibeditFrame::OnCloseWindow ) EVT_CLOSE( WinEDA_LibeditFrame::OnCloseWindow )
EVT_SIZE( WinEDA_LibeditFrame::OnSize ) EVT_SIZE( WinEDA_LibeditFrame::OnSize )
EVT_ACTIVATE( WinEDA_LibeditFrame::OnActivate )
/* Main horizontal toolbar. */ /* Main horizontal toolbar. */
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_LibeditFrame::OnZoom ) EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_LibeditFrame::OnZoom )
@ -181,6 +183,8 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( wxWindow* father,
if( DrawPanel ) if( DrawPanel )
DrawPanel->m_Block_Enable = true; DrawPanel->m_Block_Enable = true;
EnsureActiveLibExists();
ReCreateHToolbar(); ReCreateHToolbar();
ReCreateVToolbar(); ReCreateVToolbar();
DisplayLibInfos(); DisplayLibInfos();
@ -905,3 +909,29 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
if( m_ID_current_state == 0 ) if( m_ID_current_state == 0 )
m_lastDrawItem = NULL; m_lastDrawItem = NULL;
} }
/** Called on activate the frame.
* Test if the current library exists
* the library list can be changed by the schematic editor after reloading a new schematic
* and the current m_library can point a non existent lib.
*/
void WinEDA_LibeditFrame::OnActivate( wxActivateEvent& event )
{
WinEDA_DrawFrame::OnActivate( event );
// Verify the existence of the current active library
// (can be removed or changed by the schematic editor)
EnsureActiveLibExists();
}
void WinEDA_LibeditFrame::EnsureActiveLibExists()
{
if( m_library == NULL )
return;
bool exists = CMP_LIBRARY::LibraryExists( m_library );
if ( exists )
return;
else
m_library = NULL;
}

View File

@ -72,6 +72,10 @@ public:
int GetConvert( void ) { return m_convert; } int GetConvert( void ) { return m_convert; }
private: private:
/** OnActivate event funtion( virtual )
*/
virtual void OnActivate( wxActivateEvent& event );
void SelectCurrentLibrary(); void SelectCurrentLibrary();
void SelectAndViewLibraryPart( int option ); void SelectAndViewLibraryPart( int option );
void ExportToSchematicLibraryPart( wxCommandEvent& event ); void ExportToSchematicLibraryPart( wxCommandEvent& event );

View File

@ -33,7 +33,7 @@ BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
/* Window events */ /* 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_ViewlibFrame::OnActivate )
/* Sash drag events */ /* Sash drag events */
EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag ) EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
@ -195,7 +195,9 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
if( m_LibList ) if( m_LibList )
ReCreateListLib(); ReCreateListLib();
DisplayLibInfos(); DisplayLibInfos();
if( DrawPanel ) if( DrawPanel )
DrawPanel->SetAcceleratorTable( table ); DrawPanel->SetAcceleratorTable( table );
Zoom_Automatique( false ); Zoom_Automatique( false );
@ -600,3 +602,15 @@ void WinEDA_ViewlibFrame::SaveSettings()
cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.x ); cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.x );
cfg->Write( CMPLIST_WIDTH_KEY, m_CmpListSize.x ); cfg->Write( CMPLIST_WIDTH_KEY, m_CmpListSize.x );
} }
/** Called on activate the frame.
* Reload the libraries lists that can be changed by the schematic editor or the library editor
*/
void WinEDA_ViewlibFrame::OnActivate( wxActivateEvent& event )
{
WinEDA_DrawFrame::OnActivate( event );
if( m_LibList )
ReCreateListLib();
DisplayLibInfos();
}

View File

@ -272,7 +272,6 @@ public:
void ToPrinter( wxCommandEvent& event ); void ToPrinter( wxCommandEvent& event );
void SVG_Print( wxCommandEvent& event ); void SVG_Print( wxCommandEvent& event );
void OnActivate( wxActivateEvent& event );
void TraceWorkSheet( wxDC* DC, BASE_SCREEN* screen, int line_width ); void TraceWorkSheet( wxDC* DC, BASE_SCREEN* screen, int line_width );
void PlotWorkSheet( PLOTTER *plotter, BASE_SCREEN* screen ); void PlotWorkSheet( PLOTTER *plotter, BASE_SCREEN* screen );
@ -297,6 +296,12 @@ public:
virtual void ToolOnRightClick( wxCommandEvent& event ); virtual void ToolOnRightClick( wxCommandEvent& event );
void AdjustScrollBars(); void AdjustScrollBars();
/** OnActivate event function (virtual)
* called when activating the frame.
* in derived classes with a virtual OnActivate function,
* do not forget to call the WinEDA_DrawFrame::OnActivate( event ) basic function
*/
virtual void OnActivate( wxActivateEvent& event );
/** /**
* Function UpdateStatusBar * Function UpdateStatusBar
* updates the status bar information. * updates the status bar information.