Commit 3335ccd9 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Initial work on new component library stucture.

* Use C++ map in component library instead of boost::ptr_vector.
* Drop Boost pointer containers for standard C++ containers.
* Moved duplicate name user interface elements from library object to
  library editor.
* Added code to support direct addition and replacement of component
  alias objects into libraries.
* Removed temporary strings used to add and remove alias objects.
* Libraries only store alias objects, components now accessed thru alias.
* Simplify library API for adding, removing, and replacing components.
* Updated edit component in library dialog and library editor to reflect
  component library object changes.
* Fixed bug in library viewer when displaying alias name.
* Made a few header files compile stand alone per the new coding policy.
* Remove some dead code and the usual code formatting fixes.
parent ffec0b84
...@@ -817,7 +817,7 @@ void WinEDA_DrawPanel::DrawGrid( wxDC* DC ) ...@@ -817,7 +817,7 @@ void WinEDA_DrawPanel::DrawGrid( wxDC* DC )
if( double_size ) if( double_size )
{ {
wxRealPoint dblgrid = screen_grid_size + screen_grid_size; wxRealPoint dblgrid = screen_grid_size + screen_grid_size;
m_Parent->PutOnGrid(&org, &dblgrid); m_Parent->PutOnGrid( &org, &dblgrid );
} }
// Draw grid: the best algorithm depend on the platform. // Draw grid: the best algorithm depend on the platform.
...@@ -862,9 +862,9 @@ void WinEDA_DrawPanel::DrawGrid( wxDC* DC ) ...@@ -862,9 +862,9 @@ void WinEDA_DrawPanel::DrawGrid( wxDC* DC )
break; break;
xpos = org.x + xg; xpos = org.x + xg;
xpos = GRMapX( xpos ); xpos = GRMapX( xpos );
if( xpos < m_ClipBox.GetOrigin().x) // column not in active screen area. if( xpos < m_ClipBox.GetOrigin().x ) // column not in active screen area.
continue; continue;
if( xpos > m_ClipBox.GetEnd().x) // end of active area reached. if( xpos > m_ClipBox.GetEnd().x ) // end of active area reached.
break; break;
for( jj = 0; ; jj += increment ) for( jj = 0; ; jj += increment )
{ {
...@@ -872,9 +872,9 @@ void WinEDA_DrawPanel::DrawGrid( wxDC* DC ) ...@@ -872,9 +872,9 @@ void WinEDA_DrawPanel::DrawGrid( wxDC* DC )
if( yg > size.y ) if( yg > size.y )
break; break;
ypos = org.y + yg; ypos = org.y + yg;
if( ypos < m_ClipBox.GetOrigin().y) // column not in active screen area. if( ypos < m_ClipBox.GetOrigin().y ) // column not in active screen area.
continue; continue;
if( ypos > m_ClipBox.GetEnd().y) // end of active area reached. if( ypos > m_ClipBox.GetEnd().y ) // end of active area reached.
break; break;
DC->DrawPoint( xpos, GRMapY( ypos ) ); DC->DrawPoint( xpos, GRMapY( ypos ) );
} }
......
...@@ -76,7 +76,7 @@ void ReAnnotatePowerSymbolsOnly( void ) ...@@ -76,7 +76,7 @@ void ReAnnotatePowerSymbolsOnly( void )
LIB_COMPONENT* Entry = LIB_COMPONENT* Entry =
CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName );
if( ( Entry == NULL ) || !Entry->isPower() ) if( ( Entry == NULL ) || !Entry->IsPower() )
continue; continue;
//DrawLibItem->ClearAnnotation(sheet); this clears all annotation :( //DrawLibItem->ClearAnnotation(sheet); this clears all annotation :(
......
This diff is collapsed.
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CLASS_LIBENTRY_FIELDS_H #ifndef CLASS_LIBENTRY_FIELDS_H
#define CLASS_LIBENTRY_FIELDS_H #define CLASS_LIBENTRY_FIELDS_H
#include "program.h"
#include "classes_body_items.h" #include "classes_body_items.h"
......
This diff is collapsed.
...@@ -57,16 +57,16 @@ extern bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 ); ...@@ -57,16 +57,16 @@ extern bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 );
*/ */
class CMP_LIBRARY class CMP_LIBRARY
{ {
int type; ///< Library type indicator. int type; ///< Library type indicator.
wxFileName fileName; ///< Library file name. wxFileName fileName; ///< Library file name.
wxDateTime timeStamp; ///< Library save time and date. wxDateTime timeStamp; ///< Library save time and date.
int versionMajor; ///< Library major version number. int versionMajor; ///< Library major version number.
int versionMinor; ///< Library minor version number. int versionMinor; ///< Library minor version number.
LIB_ENTRY_LIST entries; ///< Parts themselves are saved here. bool isCache; /**< False for the "standard" libraries,
bool isCache; /**< False for the "standard" libraries, True for the library cache */
True for the library cache */ wxString header; ///< first line of loaded library.
wxString header; ///< first line of loaded library. bool isModified; ///< Library modification status.
bool isModified; ///< Library modification status. LIB_ALIAS_MAP aliases; ///< Map of aliases objects associated with the library.
static CMP_LIBRARY_LIST libraryList; static CMP_LIBRARY_LIST libraryList;
static wxArrayString libraryListSortOrder; static wxArrayString libraryListSortOrder;
...@@ -82,12 +82,6 @@ public: ...@@ -82,12 +82,6 @@ public:
} }
~CMP_LIBRARY(); ~CMP_LIBRARY();
/** Modify flags handling:
*/
void SetModifyFlags( ) { isModified = true; }
void ClearModifyFlag( ) { isModified = false; }
bool getModifyFlag( ) { return isModified;}
/** /**
* Function Save * Function Save
* saves library to a file. * saves library to a file.
...@@ -136,17 +130,6 @@ private: ...@@ -136,17 +130,6 @@ private:
bool LoadHeader( FILE* aFile, int* aLineNum ); bool LoadHeader( FILE* aFile, int* aLineNum );
void LoadAliases( LIB_COMPONENT* aComponent ); void LoadAliases( LIB_COMPONENT* aComponent );
/**
* Function RemoveEntryName
* removes an \a aName entry from the library list names.
* Warning: this is a partied remove, because if aname is an alias
* it is not removed from its root component.
* this is for internal use only
* Use RemoveEntry( CMP_LIB_ENTRY* aEntry ) to remove safely an entry.
* @param aName - Entry name to remove from library.
*/
void RemoveEntryName( const wxString& aName );
public: public:
/** /**
* Get library entry status. * Get library entry status.
...@@ -155,7 +138,7 @@ public: ...@@ -155,7 +138,7 @@ public:
*/ */
bool IsEmpty() const bool IsEmpty() const
{ {
return entries.empty(); return aliases.empty();
} }
/** /**
...@@ -166,7 +149,7 @@ public: ...@@ -166,7 +149,7 @@ public:
*/ */
int GetCount() const int GetCount() const
{ {
return entries.size(); return aliases.size();
} }
bool IsModified() const bool IsModified() const
...@@ -176,8 +159,6 @@ public: ...@@ -176,8 +159,6 @@ public:
bool IsCache() const { return isCache; } bool IsCache() const { return isCache; }
void SetModified( void ) { isModified = true; }
void SetCache( void ) { isCache = true; } void SetCache( void ) { isCache = true; }
/** /**
...@@ -214,25 +195,23 @@ public: ...@@ -214,25 +195,23 @@ public:
* @param aRe - Regular expression used to search component key words. * @param aRe - Regular expression used to search component key words.
* @param aSort - Sort component name list. * @param aSort - Sort component name list.
*/ */
void SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, void SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, bool aSort = true );
bool aSort = true );
/** /**
* Find entry by name. * Checks \a aComponent for name conflict in the library.
* *
* @param aName - Name of entry, case insensitive. * @param aComponent - The component to check.
* @return Entry if found. NULL if not found. * @erturn True if a conflict exists. Otherwise false.
*/ */
CMP_LIB_ENTRY* FindEntry( const wxChar* aName ); bool Conflicts( LIB_COMPONENT* aComponent );
/** /**
* Find entry by \a aName and \a aType. * Find entry by name.
* *
* @param aName - Name of entry, case insensitive. * @param aName - Name of entry, case insensitive.
* @param aType - Type of entry, root or alias.
* @return Entry if found. NULL if not found. * @return Entry if found. NULL if not found.
*/ */
CMP_LIB_ENTRY* FindEntry( const wxChar* aName, LibrEntryType aType ); CMP_LIB_ENTRY* FindEntry( const wxChar* aName );
/** /**
* Find component by \a aName. * Find component by \a aName.
...@@ -256,7 +235,7 @@ public: ...@@ -256,7 +235,7 @@ public:
*/ */
LIB_ALIAS* FindAlias( const wxChar* aName ) LIB_ALIAS* FindAlias( const wxChar* aName )
{ {
return (LIB_ALIAS*) FindEntry( aName, ALIAS ); return (LIB_ALIAS*) FindEntry( aName );
} }
/** /**
...@@ -285,18 +264,17 @@ public: ...@@ -285,18 +264,17 @@ public:
LIB_COMPONENT* AddComponent( LIB_COMPONENT* aComponent ); LIB_COMPONENT* AddComponent( LIB_COMPONENT* aComponent );
/** /**
* Remove safely an \a aEntry from the library. * Safely remove \a aEntry from the library and return the next entry.
* *
* If the entry is an alias, the alias is removed from the library and from * The next entry returned depends on the entry being removed. If the entry being
* the alias list of the root component. If the entry is a root component * remove also removes the component, then the next entry from the list is returned.
* with no aliases, it is removed from the library. If the entry is a root * If the entry being used only removes an alias from a component, then the next alias
* component with aliases, the root component is renamed to the name of * of the component is returned.
* the first alias and the root name for all remaining aliases are updated
* to reflect the new root name.
* *
* @param aEntry - Entry to remove from library. * @param aEntry - Entry to remove from library.
* @return The next entry in the library or NULL if the library is empty.
*/ */
void RemoveEntry( CMP_LIB_ENTRY* aEntry ); CMP_LIB_ENTRY* RemoveEntry( CMP_LIB_ENTRY* aEntry );
/** /**
* Replace an existing component entry in the library. * Replace an existing component entry in the library.
...@@ -410,8 +388,7 @@ public: ...@@ -410,8 +388,7 @@ public:
* @return Library object if library file loaded successfully, * @return Library object if library file loaded successfully,
* otherwise NULL. * otherwise NULL.
*/ */
static CMP_LIBRARY* LoadLibrary( const wxFileName& aFileName, static CMP_LIBRARY* LoadLibrary( const wxFileName& aFileName, wxString& aErrorMsg );
wxString& aErrorMsg );
/** /**
* Function AddLibrary * Function AddLibrary
...@@ -443,6 +420,8 @@ public: ...@@ -443,6 +420,8 @@ public:
*/ */
static void RemoveLibrary( const wxString& aName ); static void RemoveLibrary( const wxString& aName );
static void RemoveAllLibraries() { libraryList.clear(); }
/** /**
* Function FindLibrary * Function FindLibrary
* finds a component library by \a aName. * finds a component library by \a aName.
......
...@@ -1158,7 +1158,7 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) ...@@ -1158,7 +1158,7 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
GetRef( ( (WinEDA_SchematicFrame*) frame )->GetSheet() ), GetRef( ( (WinEDA_SchematicFrame*) frame )->GetSheet() ),
DARKCYAN ); DARKCYAN );
if( root_component->isPower() ) if( root_component->IsPower() )
msg = _( "Power symbol" ); msg = _( "Power symbol" );
else else
msg = _( "Name" ); msg = _( "Name" );
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base_struct.h" #include "base_struct.h"
#include <boost/ptr_container/ptr_vector.hpp>
class LIB_COMPONENT; class LIB_COMPONENT;
class PLOTTER; class PLOTTER;
......
...@@ -27,9 +27,9 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY( WinEDA_Libed ...@@ -27,9 +27,9 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY( WinEDA_Libed
Init(); Init();
if (GetSizer()) if( GetSizer() )
{ {
GetSizer()->SetSizeHints(this); GetSizer()->SetSizeHints( this );
} }
} }
...@@ -40,7 +40,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::~DIALOG_EDIT_COMPONENT_IN_LIBRARY() ...@@ -40,7 +40,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::~DIALOG_EDIT_COMPONENT_IN_LIBRARY()
/* Initialize state of check boxes and texts /* Initialize state of check boxes and texts
*/ */
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::Init( ) void DIALOG_EDIT_COMPONENT_IN_LIBRARY::Init()
{ {
SetFocus(); SetFocus();
m_AliasLocation = -1; m_AliasLocation = -1;
...@@ -55,7 +55,9 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::Init( ) ...@@ -55,7 +55,9 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::Init( )
wxString title = _( "Properties for " ); wxString title = _( "Properties for " );
if( !m_Parent->GetAliasName().IsEmpty() ) bool isRoot = m_Parent->GetAliasName().CmpNoCase( component->GetName() ) == 0;
if( !isRoot )
{ {
title += m_Parent->GetAliasName() + _( " (alias of " ) + title += m_Parent->GetAliasName() + _( " (alias of " ) +
component->GetName() + wxT( ")" ); component->GetName() + wxT( ")" );
...@@ -63,20 +65,19 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::Init( ) ...@@ -63,20 +65,19 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::Init( )
else else
{ {
title += component->GetName(); title += component->GetName();
m_Parent->GetAliasName().Empty();
} }
SetTitle( title ); SetTitle( title );
InitPanelDoc(); InitPanelDoc();
InitBasicPanel(); InitBasicPanel();
if( !m_Parent->GetAliasName().IsEmpty() ) if( isRoot && component->GetAliasCount() == 1 )
m_ButtonDeleteAllAlias->Enable( false ); m_ButtonDeleteAllAlias->Enable( false );
/* Place list of alias names in listbox */ /* Place list of alias names in listbox */
m_PartAliasListCtrl->Append( component->GetAliasList() ); m_PartAliasListCtrl->Append( component->GetAliasNames( false ) );
if( component->GetAliasList().GetCount() == 0 ) if( component->GetAliasCount() <= 1 )
{ {
m_ButtonDeleteAllAlias->Enable( false ); m_ButtonDeleteAllAlias->Enable( false );
m_ButtonDeleteOneAlias->Enable( false ); m_ButtonDeleteOneAlias->Enable( false );
...@@ -102,23 +103,24 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnCancelClick( wxCommandEvent& event ) ...@@ -102,23 +103,24 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnCancelClick( wxCommandEvent& event )
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc() void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc()
{ {
LIB_ALIAS* alias;
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL ) if( component == NULL )
return; return;
wxString aliasname = m_Parent->GetAliasName(); wxString aliasname = m_Parent->GetAliasName();
if( aliasname.IsEmpty() ) // The root component is selected
{ if( aliasname.IsEmpty() )
m_DocCtrl->SetValue( component->GetDescription() ); return;
m_KeywordsCtrl->SetValue( component->GetKeyWords() );
m_DocfileCtrl->SetValue( component->GetDocFileName() ); alias = component->GetAlias( aliasname );
}
else // An alias is currently selected if( alias != NULL )
{ {
m_DocCtrl->SetValue( component->GetAliasDataDoc( aliasname ) ); m_DocCtrl->SetValue( alias->GetDescription() );
m_KeywordsCtrl->SetValue( component->GetAliasDataKeyWords( aliasname ) ); m_KeywordsCtrl->SetValue( alias->GetKeyWords() );
m_DocfileCtrl->SetValue( component->GetAliasDataDocFileName( aliasname ) ); m_DocfileCtrl->SetValue( alias->GetDocFileName() );
} }
} }
...@@ -151,6 +153,6 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitBasicPanel() ...@@ -151,6 +153,6 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitBasicPanel()
m_PinsNameInsideButt->SetValue( component->GetPinNameOffset() != 0 ); m_PinsNameInsideButt->SetValue( component->GetPinNameOffset() != 0 );
m_SelNumberOfUnits->SetValue( component->GetPartCount() ); m_SelNumberOfUnits->SetValue( component->GetPartCount() );
m_SetSkew->SetValue( component->GetPinNameOffset() ); m_SetSkew->SetValue( component->GetPinNameOffset() );
m_OptionPower->SetValue( component->isPower() ); m_OptionPower->SetValue( component->IsPower() );
m_OptionPartsLocked->SetValue( component->UnitsLocked() ); m_OptionPartsLocked->SetValue( component->UnitsLocked() );
} }
...@@ -253,7 +253,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event ...@@ -253,7 +253,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
LIB_COMPONENT* entry = LIB_COMPONENT* entry =
CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName ); CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName );
if( entry && entry->isPower() ) if( entry && entry->IsPower() )
m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName; m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName;
// copy all the fields back, and change the length of m_Fields. // copy all the fields back, and change the length of m_Fields.
...@@ -592,7 +592,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel() ...@@ -592,7 +592,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
// For power symbols, the value is NOR editable, because value and pin // For power symbols, the value is NOR editable, because value and pin
// name must be same and can be edited only in library editor // name must be same and can be edited only in library editor
if( fieldNdx == VALUE && m_LibEntry && m_LibEntry->isPower() ) if( fieldNdx == VALUE && m_LibEntry && m_LibEntry->IsPower() )
fieldValueTextCtrl->Enable( false ); fieldValueTextCtrl->Enable( false );
else else
fieldValueTextCtrl->Enable( true ); fieldValueTextCtrl->Enable( true );
......
...@@ -221,17 +221,15 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event ...@@ -221,17 +221,15 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event
/* A new name could be entered in VALUE field. /* A new name could be entered in VALUE field.
* Must not be an existing alias name in alias list box */ * Must not be an existing alias name in alias list box */
wxString* newvalue = &m_FieldsBuf[VALUE].m_Text; wxString* newvalue = &m_FieldsBuf[VALUE].m_Text;
for( size_t i = 0; i < m_LibEntry->GetAliasList().GetCount(); i++ )
if( m_LibEntry->HasAlias( *newvalue ) )
{ {
if( newvalue->CmpNoCase( m_LibEntry->GetAliasList()[i] ) == 0 ) wxString msg;
{ msg.Printf( _( "A new name is entered for this component\n\
wxString msg;
msg.Printf( _( "A new name is entered for this component\n\
An alias %s already exists!\nCannot update this component" ), An alias %s already exists!\nCannot update this component" ),
newvalue->GetData() ); newvalue->GetData() );
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
}
} }
/* save old cmp in undo list */ /* save old cmp in undo list */
......
This diff is collapsed.
...@@ -102,7 +102,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_FIELD* Field, wxDC* DC ) ...@@ -102,7 +102,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_FIELD* Field, wxDC* DC )
{ {
Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName ); Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName );
if( Entry && Entry->isPower() ) if( Entry && Entry->IsPower() )
{ {
DisplayInfoMessage( this, _( "Part is a POWER, value cannot be \ DisplayInfoMessage( this, _( "Part is a POWER, value cannot be \
modified!\nYou must create a new power" ) ); modified!\nYou must create a new power" ) );
......
...@@ -89,6 +89,7 @@ saved.\n\nDiscard current changes?" ) ) ) ...@@ -89,6 +89,7 @@ saved.\n\nDiscard current changes?" ) ) )
if( m_component ) if( m_component )
{ {
SAFE_DELETE( m_component ); SAFE_DELETE( m_component );
m_aliasName.Empty();
} }
/* Load the new library component */ /* Load the new library component */
...@@ -96,8 +97,7 @@ saved.\n\nDiscard current changes?" ) ) ) ...@@ -96,8 +97,7 @@ saved.\n\nDiscard current changes?" ) ) )
if( LibEntry == NULL ) if( LibEntry == NULL )
{ {
msg.Printf( _( "Component or alias name \"%s\" not found in \ msg.Printf( _( "Component or alias name \"%s\" not found in library \"%s\"." ),
library \"%s\"." ),
GetChars( CmpName ), GetChars( CmpName ),
GetChars( m_library->GetName() ) ); GetChars( m_library->GetName() ) );
DisplayError( this, msg ); DisplayError( this, msg );
...@@ -113,7 +113,7 @@ library \"%s\"." ), ...@@ -113,7 +113,7 @@ library \"%s\"." ),
GetScreen()->ClearUndoRedoList(); GetScreen()->ClearUndoRedoList();
Zoom_Automatique( false ); Zoom_Automatique( false );
DrawPanel->Refresh(); DrawPanel->Refresh();
SetShowDeMorgan(m_component->HasConversion() ); SetShowDeMorgan( m_component->HasConversion() );
m_HToolBar->Refresh(); m_HToolBar->Refresh();
} }
...@@ -125,28 +125,26 @@ library \"%s\"." ), ...@@ -125,28 +125,26 @@ library \"%s\"." ),
* 1 if error * 1 if error
* m_component advanced copy and created * m_component advanced copy and created
*/ */
bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* aEntry, CMP_LIBRARY* aLibrary )
CMP_LIBRARY* Library )
{ {
wxString msg, cmpName, rootName; wxString msg, cmpName, rootName;
LIB_COMPONENT* component; LIB_COMPONENT* component;
if( ( LibEntry == NULL ) || ( Library == NULL ) ) if( ( aEntry == NULL ) || ( aLibrary == NULL ) )
return false; return false;
if( LibEntry->GetName().IsEmpty() ) if( aEntry->GetName().IsEmpty() )
{ {
wxLogWarning( wxT( "Entry in library <%s> has empty name field." ), wxLogWarning( wxT( "Entry in library <%s> has empty name field." ),
GetChars( Library->GetName() ) ); GetChars( aLibrary->GetName() ) );
return false; return false;
} }
cmpName = LibEntry->GetName(); cmpName = m_aliasName = aEntry->GetName();
m_aliasName.Empty();
if( LibEntry->isAlias() ) if( aEntry->isAlias() )
{ {
LIB_ALIAS* alias = (LIB_ALIAS*) LibEntry; LIB_ALIAS* alias = (LIB_ALIAS*) aEntry;
component = alias->GetComponent(); component = alias->GetComponent();
wxASSERT( component != NULL && component->isComponent() ); wxASSERT( component != NULL && component->isComponent() );
...@@ -154,28 +152,30 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, ...@@ -154,28 +152,30 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry,
wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ), wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ),
GetChars( cmpName ), GetChars( cmpName ),
GetChars( component->GetName() ) ); GetChars( component->GetName() ) );
m_aliasName = cmpName;
} }
else else
{ {
component = (LIB_COMPONENT*) LibEntry; component = (LIB_COMPONENT*) aEntry;
} }
if( m_component ) if( m_component )
{
SAFE_DELETE( m_component ); SAFE_DELETE( m_component );
m_aliasName.Empty();
}
m_component = new LIB_COMPONENT( *component ); m_component = new LIB_COMPONENT( *component );
if( m_component == NULL ) if( m_component == NULL )
{ {
msg.Printf( _( "Could not create copy of part <%s> in library <%s>." ), msg.Printf( _( "Could not create copy of part <%s> in library <%s>." ),
GetChars( LibEntry->GetName() ), GetChars( aEntry->GetName() ),
GetChars( Library->GetName() ) ); GetChars( aLibrary->GetName() ) );
DisplayError( this, msg ); DisplayError( this, msg );
return false; return false;
} }
m_aliasName = aEntry->GetName();
m_unit = 1; m_unit = 1;
m_convert = 1; m_convert = 1;
...@@ -184,9 +184,6 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, ...@@ -184,9 +184,6 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry,
if( m_component->HasConversion() ) if( m_component->HasConversion() )
m_showDeMorgan = true; m_showDeMorgan = true;
// Collect aliases data and store it in the root component, for edition:
m_component->CollectAliasesData( Library );
GetBaseScreen()->ClrModify(); GetBaseScreen()->ClrModify();
DisplayLibInfos(); DisplayLibInfos();
UpdateAliasSelectList(); UpdateAliasSelectList();
...@@ -294,8 +291,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) ...@@ -294,8 +291,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event )
if( !success ) if( !success )
{ {
msg = _( "Error while saving library file \"" ) + fn.GetFullPath() + msg = _( "Error while saving library file \"" ) + fn.GetFullPath() + _( "\"." );
_( "\"." );
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED ); AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
DisplayError( this, msg ); DisplayError( this, msg );
} }
...@@ -303,8 +299,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) ...@@ -303,8 +299,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event )
{ {
msg = _( "Library file \"" ) + fn.GetFullName() + wxT( "\" Ok" ); msg = _( "Library file \"" ) + fn.GetFullName() + wxT( "\" Ok" );
fn.SetExt( DOC_EXT ); fn.SetExt( DOC_EXT );
wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() + wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() + wxT( "\" Ok" );
wxT( "\" Ok" );
AppendMsgPanel( msg, msg1, BLUE ); AppendMsgPanel( msg, msg1, BLUE );
} }
} }
...@@ -318,6 +313,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) ...@@ -318,6 +313,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event )
void WinEDA_LibeditFrame::DisplayCmpDoc() void WinEDA_LibeditFrame::DisplayCmpDoc()
{ {
wxString msg; wxString msg;
LIB_ALIAS* alias;
ClearMsgPanel(); ClearMsgPanel();
...@@ -328,11 +324,15 @@ void WinEDA_LibeditFrame::DisplayCmpDoc() ...@@ -328,11 +324,15 @@ void WinEDA_LibeditFrame::DisplayCmpDoc()
AppendMsgPanel( _( "Part" ), msg, BLUE, 8 ); AppendMsgPanel( _( "Part" ), msg, BLUE, 8 );
if( m_aliasName.IsEmpty() ) if( m_aliasName == m_component->GetName() )
msg = _( "None" ); msg = _( "None" );
else else
msg = m_aliasName; msg = m_aliasName;
alias = m_component->GetAlias( m_aliasName );
wxCHECK_RET( alias != NULL, wxT( "Alias not found in component." ) );
AppendMsgPanel( _( "Alias" ), msg, RED, 8 ); AppendMsgPanel( _( "Alias" ), msg, RED, 8 );
static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
...@@ -347,34 +347,15 @@ void WinEDA_LibeditFrame::DisplayCmpDoc() ...@@ -347,34 +347,15 @@ void WinEDA_LibeditFrame::DisplayCmpDoc()
AppendMsgPanel( _( "Body" ), msg, GREEN, 8 ); AppendMsgPanel( _( "Body" ), msg, GREEN, 8 );
if( m_component->isPower() ) if( m_component->IsPower() )
msg = _( "Power Symbol" ); msg = _( "Power Symbol" );
else else
msg = _( "Component" ); msg = _( "Component" );
AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 ); AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 );
AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 8 );
if( m_aliasName.IsEmpty() ) AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
AppendMsgPanel( _( "Datasheet" ), alias->GetDocFileName(), DARKDARKGRAY );
msg = m_component->GetDescription();
else
msg = m_component->GetAliasDataDoc( m_aliasName );
AppendMsgPanel( _( "Description" ), msg, CYAN, 8 );
if( m_aliasName.IsEmpty() )
msg = m_component->GetKeyWords();
else
msg = m_component->GetAliasDataKeyWords( m_aliasName );
AppendMsgPanel( _( "Key words" ), msg, DARKDARKGRAY );
if( m_aliasName.IsEmpty() )
msg = m_component->GetDocFileName();
else
msg = m_component->GetAliasDataDocFileName( m_aliasName );
AppendMsgPanel( _( "Datasheet" ), msg, DARKDARKGRAY );
} }
...@@ -419,10 +400,8 @@ void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event ) ...@@ -419,10 +400,8 @@ void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event )
if( ListNames.IsEmpty() ) if( ListNames.IsEmpty() )
{ {
msg.Printf( _( "Component library <%s> is empty." ), msg.Printf( _( "Component library <%s> is empty." ), GetChars( m_library->GetName() ) );
GetChars( m_library->GetName() ) ); wxMessageBox( msg, _( "Delete Entry Error" ), wxID_OK | wxICON_EXCLAMATION, this );
wxMessageBox( msg, _( "Delete Entry Error" ),
wxID_OK | wxICON_EXCLAMATION, this );
return; return;
} }
...@@ -453,9 +432,7 @@ void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event ) ...@@ -453,9 +432,7 @@ void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event )
if( !IsOK( this, msg ) ) if( !IsOK( this, msg ) )
return; return;
if( m_component == NULL if( m_component == NULL || !m_component->HasAlias( LibEntry->GetName() ) )
|| ( m_component->GetName().CmpNoCase( LibEntry->GetName() ) != 0
&& !m_component->HasAlias( LibEntry->GetName() ) ) )
{ {
m_library->RemoveEntry( LibEntry ); m_library->RemoveEntry( LibEntry );
return; return;
...@@ -470,47 +447,24 @@ void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event ) ...@@ -470,47 +447,24 @@ void WinEDA_LibeditFrame::DeleteOnePart( wxCommandEvent& event )
All changes will be lost. Discard changes?" ) ) ) All changes will be lost. Discard changes?" ) ) )
return; return;
wxString newCmpName; CMP_LIB_ENTRY* nextEntry = m_library->RemoveEntry( LibEntry );
CMP_LIB_ENTRY* nextEntry;
/* if( nextEntry != NULL )
* If the current component has no aliases, then the next entry
* in the library will be shown. If the current component has
* aliases, the updated component will be shown
*/
if( m_component->GetName().CmpNoCase( LibEntry->GetName() ) == 0 )
{ {
if( m_component->GetAliasList().IsEmpty() ) if( LoadOneLibraryPartAux( nextEntry, m_library ) )
{ Zoom_Automatique( false );
nextEntry = m_library->GetNextEntry( m_component->GetName() );
if( nextEntry != NULL )
newCmpName = nextEntry->GetName();
}
else
{
newCmpName = m_component->GetAliasList()[ 0 ];
}
} }
else else
{ {
newCmpName = m_component->GetName(); SAFE_DELETE( m_component );
m_aliasName.Empty();
} }
m_library->RemoveEntry( LibEntry ); DrawPanel->Refresh();
if( !newCmpName.IsEmpty() )
{
nextEntry = m_library->FindEntry( newCmpName );
if( nextEntry != NULL && LoadOneLibraryPartAux( nextEntry, m_library ) )
Zoom_Automatique( false );
DrawPanel->Refresh();
}
} }
/* /*
* Routine to create a new library component * Routine to create a new library component
* *
...@@ -537,8 +491,7 @@ lost!\n\nClear the current component from the screen?" ) ) ) ...@@ -537,8 +491,7 @@ lost!\n\nClear the current component from the screen?" ) ) )
if( dlg.GetName().IsEmpty() ) if( dlg.GetName().IsEmpty() )
{ {
wxMessageBox( _( "This new component has no name and cannot be \ wxMessageBox( _( "This new component has no name and cannot be created. Aborted" ) );
created. Aborted" ) );
return; return;
} }
...@@ -582,12 +535,16 @@ created. Aborted" ) ); ...@@ -582,12 +535,16 @@ created. Aborted" ) );
if( dlg.GetPartCount() < 2 ) if( dlg.GetPartCount() < 2 )
component->LockUnits( false ); component->LockUnits( false );
m_aliasName = component->GetName();
if( m_component ) if( m_component )
{ {
SAFE_DELETE( m_component ); SAFE_DELETE( m_component );
m_aliasName.Empty();
} }
m_component = component; m_component = component;
m_aliasName = m_component->GetName();
m_unit = 1; m_unit = 1;
m_convert = 1; m_convert = 1;
DisplayLibInfos(); DisplayLibInfos();
......
This diff is collapsed.
...@@ -186,7 +186,7 @@ void WinEDA_LibeditFrame::EditField( wxDC* DC, LIB_FIELD* Field ) ...@@ -186,7 +186,7 @@ void WinEDA_LibeditFrame::EditField( wxDC* DC, LIB_FIELD* Field )
wxString msg; wxString msg;
/* Test for an existing name in the current components alias list. */ /* Test for an existing name in the current components alias list. */
if( Field->GetParent()->GetAliasList().Index( Text, false ) != wxNOT_FOUND ) if( Field->GetParent()->HasAlias( Text ) )
{ {
msg.Printf( _( "The field name <%s> is an existing alias of the \ msg.Printf( _( "The field name <%s> is an existing alias of the \
component <%s>.\nPlease choose another name that does not conflict with any \ component <%s>.\nPlease choose another name that does not conflict with any \
......
...@@ -284,7 +284,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) ...@@ -284,7 +284,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
msg = AddHotkeyName( _( "Edit" ), s_Schematic_Hokeys_Descr, HK_EDIT ); msg = AddHotkeyName( _( "Edit" ), s_Schematic_Hokeys_Descr, HK_EDIT );
ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, msg, edit_component_xpm ); ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, msg, edit_component_xpm );
if( libComponent && libComponent->isNormal() ) if( libComponent && libComponent->IsNormal() )
{ {
msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_VALUE ); msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_VALUE );
ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_VALUE_CMP, msg, edit_comp_value_xpm ); ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_VALUE_CMP, msg, edit_comp_value_xpm );
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "eeschema_id.h" #include "eeschema_id.h"
#include "netlist.h" #include "netlist.h"
#include "class_pin.h" #include "class_pin.h"
#include "class_library.h"
#include "annotate_dialog.h" #include "annotate_dialog.h"
#include "dialog_build_BOM.h" #include "dialog_build_BOM.h"
...@@ -258,6 +259,7 @@ WinEDA_SchematicFrame::~WinEDA_SchematicFrame() ...@@ -258,6 +259,7 @@ WinEDA_SchematicFrame::~WinEDA_SchematicFrame()
SAFE_DELETE( g_RootSheet ); SAFE_DELETE( g_RootSheet );
SAFE_DELETE( m_CurrentSheet ); // a SCH_SHEET_PATH, on the heap. SAFE_DELETE( m_CurrentSheet ); // a SCH_SHEET_PATH, on the heap.
SAFE_DELETE( m_findReplaceData ); SAFE_DELETE( m_findReplaceData );
CMP_LIBRARY::RemoveAllLibraries();
} }
......
...@@ -54,8 +54,7 @@ BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame ) ...@@ -54,8 +54,7 @@ BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList ) EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList ) EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
EVT_MENU( ID_SET_RELATIVE_OFFSET, EVT_MENU( ID_SET_RELATIVE_OFFSET, WinEDA_ViewlibFrame::OnSetRelativeOffset )
WinEDA_ViewlibFrame::OnSetRelativeOffset )
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -136,10 +135,9 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father, ...@@ -136,10 +135,9 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
m_LibListWindow->SetAlignment( wxLAYOUT_LEFT ); m_LibListWindow->SetAlignment( wxLAYOUT_LEFT );
m_LibListWindow->SetSashVisible( wxSASH_RIGHT, TRUE ); m_LibListWindow->SetSashVisible( wxSASH_RIGHT, TRUE );
m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE ); m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_LibList = m_LibList = new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST,
new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ), wxDefaultSize,
wxPoint( 0, 0 ), wxDefaultSize, 0, NULL, wxLB_HSCROLL );
0, NULL, wxLB_HSCROLL );
} }
else else
{ {
......
...@@ -266,43 +266,36 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) ...@@ -266,43 +266,36 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
if( entry == NULL ) if( entry == NULL )
return; return;
wxCHECK_RET( entry->isAlias(),
wxT( "Entry \"" ) + entry->GetName() + wxT( "\" found in library <" ) +
lib->GetName() + wxT( "> is not a LIB_ALIAS object." ) );
LIB_ALIAS* alias = (LIB_ALIAS*) entry;
component = alias->GetComponent();
DrawPanel->DrawBackGround( DC ); DrawPanel->DrawBackGround( DC );
if( entry->isAlias() ) if( !alias->IsRoot() )
{ {
LIB_ALIAS* alias = (LIB_ALIAS*) entry;
component = alias->GetComponent();
if( component == NULL ) // Should not occur if( component == NULL ) // Should not occur
{
wxASSERT( component != NULL );
return; return;
}
if( ! component->isComponent() )
{
wxASSERT( component->isComponent() );
return;
}
// Temporarily change the name field text to reflect the alias name.
msg = alias->GetName(); msg = alias->GetName();
/* Temporarily change the name field text to reflect the alias name. */
tmp = component->GetName(); tmp = component->GetName();
component->SetName( alias->GetName() ); component->SetName( msg );
if( m_unit < 1 ) if( m_unit < 1 )
m_unit = 1; m_unit = 1;
if( m_convert < 1 ) if( m_convert < 1 )
m_convert = 1; m_convert = 1;
component->SetName( tmp );
} }
else else
{ {
component = (LIB_COMPONENT*) entry;
msg = _( "None" ); msg = _( "None" );
} }
component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), m_unit, m_convert, component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), m_unit, m_convert, GR_DEFAULT_DRAWMODE );
GR_DEFAULT_DRAWMODE );
/* Redraw the cursor */ /* Redraw the cursor */
DrawPanel->DrawCursor( DC ); DrawPanel->DrawCursor( DC );
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef _COLORS_H #ifndef _COLORS_H
#define _COLORS_H #define _COLORS_H
#include <wx/wx.h>
/* Number of colors ( 32 bit palette. ) */ /* Number of colors ( 32 bit palette. ) */
#define NBCOLOR 24 #define NBCOLOR 24
......
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