Commit 2396cdb1 authored by charras's avatar charras

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
......@@ -210,7 +210,7 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias )
}
entries.push_back( (CMP_LIB_ENTRY*) aAlias );
isModified = true;
SetModifyFlags( );
return true;
}
......@@ -225,7 +225,7 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
return NULL;
entries.push_back( (CMP_LIB_ENTRY*) newCmp );
isModified = true;
SetModifyFlags( );
/* Cache libraries are component only libraries. Do not create alias
* entries. */
......@@ -280,7 +280,7 @@ void CMP_LIBRARY::RemoveEntry( CMP_LIB_ENTRY* aEntry )
LIB_COMPONENT* root;
LIB_ALIAS* alias;
isModified = true;
SetModifyFlags( );
if( aEntry->isAlias() )
{
......@@ -393,7 +393,7 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
entries.push_back( (CMP_LIB_ENTRY*) newCmp );
entries.sort();
isModified = true;
SetModifyFlags( );
return newCmp;
}
......@@ -739,7 +739,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
return false;
}
isModified = false;
ClearModifyFlag( );
timeStamp = GetTimeStamp();
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 )
{
BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
......
......@@ -63,6 +63,24 @@ public:
int m_Type; /* type indicator */
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:
CMP_LIBRARY( int aType, const wxFileName& aFileName );
CMP_LIBRARY( int aType, const wxString& aFileName )
......@@ -71,6 +89,12 @@ public:
}
~CMP_LIBRARY();
/** Modify flags handling:
*/
void SetModifyFlags( ) { isModified = true; }
void ClearModifyFlag( ) { isModified = false; }
bool getModifyFlag( ) { return isModified;}
/**
* Save library to file.
*
......@@ -152,7 +176,7 @@ public:
void SetCache( void ) { isCache = true; }
/**
/**
* Load a string array with the names of all the entries in this library.
*
* @param aNames - String array to place entry names into.
......@@ -341,6 +365,14 @@ public:
* 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.
*
......@@ -442,22 +474,6 @@ public:
{
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;
};
......
......@@ -17,6 +17,7 @@
#include "general.h"
#include "protos.h"
#include "netlist.h"
#include "libeditfrm.h"
#include "libviewfrm.h"
#include <wx/tokenzr.h>
......@@ -160,8 +161,9 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event )
// take new list in account
m_Parent->LoadLibraries();
if( m_Parent->m_ViewlibFrame )
m_Parent->m_ViewlibFrame->ReCreateListLib();
// Clear (if needed) the current active library in libedit because it could be
// removed from memory
WinEDA_LibeditFrame::EnsureActiveLibExists();
}
m_Parent->SaveProjectFile( this );
......
......@@ -13,6 +13,7 @@
#include "protos.h"
#include "eeschema_id.h"
#include "class_library.h"
#include "libeditfrm.h"
......@@ -104,8 +105,6 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName,
GetScreen()->ClrModify();
//m_CurrentSheet->m_AssociatedScreen->Pnext = NULL; should be by default
if( IsNew )
{
screen->m_CurrentSheetDesc = &g_Sheet_A4;
......@@ -131,6 +130,10 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName,
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.
CMP_LIBRARY::RemoveCacheLibrary();
......
......@@ -24,6 +24,8 @@ void WinEDA_LibeditFrame::DisplayLibInfos()
{
wxString msg = _( "Component Library Editor: " );
EnsureActiveLibExists();
if( m_library )
msg += m_library->GetFullFileName();
else
......
......@@ -34,6 +34,12 @@ public:
~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 OnImportPart( wxCommandEvent& event );
void OnExportPart( wxCommandEvent& event );
......@@ -127,6 +133,10 @@ public:
private:
/** OnActivate event funtion( virtual )
*/
virtual void OnActivate( wxActivateEvent& event );
// General:
void SaveOnePartInMemory();
void SelectActiveLibrary();
......@@ -209,11 +219,11 @@ protected:
/** Default line width for drawing or editing graphic items. */
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. */
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_drawItem;
static wxString m_aliasName;
......
......@@ -43,6 +43,7 @@ int CreateNewLibAndSavePartId = ::wxNewId();
*/
LIB_COMPONENT* WinEDA_LibeditFrame::m_component = NULL;
CMP_LIBRARY* WinEDA_LibeditFrame::m_library = NULL;
wxString WinEDA_LibeditFrame::m_aliasName;
int WinEDA_LibeditFrame::m_unit = 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 )
EVT_CLOSE( WinEDA_LibeditFrame::OnCloseWindow )
EVT_SIZE( WinEDA_LibeditFrame::OnSize )
EVT_ACTIVATE( WinEDA_LibeditFrame::OnActivate )
/* Main horizontal toolbar. */
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_LibeditFrame::OnZoom )
......@@ -181,6 +183,8 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( wxWindow* father,
if( DrawPanel )
DrawPanel->m_Block_Enable = true;
EnsureActiveLibExists();
ReCreateHToolbar();
ReCreateVToolbar();
DisplayLibInfos();
......@@ -905,3 +909,29 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
if( m_ID_current_state == 0 )
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;
}
......@@ -72,6 +72,10 @@ public:
int GetConvert( void ) { return m_convert; }
private:
/** OnActivate event funtion( virtual )
*/
virtual void OnActivate( wxActivateEvent& event );
void SelectCurrentLibrary();
void SelectAndViewLibraryPart( int option );
void ExportToSchematicLibraryPart( wxCommandEvent& event );
......
......@@ -33,7 +33,7 @@ BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
/* Window events */
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )
EVT_ACTIVATE( WinEDA_ViewlibFrame::OnActivate )
/* Sash drag events */
EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
......@@ -195,7 +195,9 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
if( m_LibList )
ReCreateListLib();
DisplayLibInfos();
if( DrawPanel )
DrawPanel->SetAcceleratorTable( table );
Zoom_Automatique( false );
......@@ -600,3 +602,15 @@ void WinEDA_ViewlibFrame::SaveSettings()
cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.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();
}
......@@ -272,7 +272,6 @@ public:
void ToPrinter( wxCommandEvent& event );
void SVG_Print( wxCommandEvent& event );
void OnActivate( wxActivateEvent& event );
void TraceWorkSheet( wxDC* DC, BASE_SCREEN* screen, int line_width );
void PlotWorkSheet( PLOTTER *plotter, BASE_SCREEN* screen );
......@@ -297,6 +296,12 @@ public:
virtual void ToolOnRightClick( wxCommandEvent& event );
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
* updates the status bar information.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment