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 :(
......
/**********************************************************/ /*************************/
/* lib_entry.cpp */ /* class_libentry.cpp */
/**********************************************************/ /*************************/
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
...@@ -20,6 +20,15 @@ ...@@ -20,6 +20,15 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
// Set this to 1 to print debugging ouput in alias and component destructors to verify
// objects get cleaned up properly.
#if defined( TRACE_DESTRUCTOR )
#undef TRACE_DESTRUCTOR
#endif
#define TRACE_DESTRUCTOR 0
/** class CMP_LIB_ENTRY /** class CMP_LIB_ENTRY
* Base class to describe library components and aliases. * Base class to describe library components and aliases.
* This class is not to be used directly. * This class is not to be used directly.
...@@ -134,41 +143,31 @@ int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem ...@@ -134,41 +143,31 @@ int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem
* (like 74LS00, 74HC00 ... and many op amps ) * (like 74LS00, 74HC00 ... and many op amps )
*/ */
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent, LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent ) :
CMP_LIBRARY* aLibrary ) : CMP_LIB_ENTRY( ALIAS, aName, NULL )
CMP_LIB_ENTRY( ALIAS, aName, aLibrary )
{ {
wxASSERT( aRootComponent != NULL && aRootComponent->isComponent() );
root = aRootComponent; root = aRootComponent;
if( aLibrary == NULL )
library = aRootComponent->GetLibrary();
} }
LIB_ALIAS::LIB_ALIAS( LIB_ALIAS& aAlias, CMP_LIBRARY* aLibrary ) : LIB_ALIAS::LIB_ALIAS( LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent ) : CMP_LIB_ENTRY( aAlias )
CMP_LIB_ENTRY( aAlias )
{ {
root = aAlias.root; root = aRootComponent;
} }
LIB_ALIAS::~LIB_ALIAS() LIB_ALIAS::~LIB_ALIAS()
{ {
#if TRACE_DESTRUCTOR
wxLogDebug( wxT( "Destroying alias \"%s\" of component \"%s\" with alais list count %d." ),
GetChars( name ), GetChars( root->GetName() ), root->m_aliases.size() );
#endif
} }
void LIB_ALIAS::SetComponent( LIB_COMPONENT* aComponent ) /***********************/
{
wxASSERT( aComponent != NULL && aComponent->isComponent() );
root = aComponent;
}
/********************************/
/* class LIB_COMPONENT */ /* class LIB_COMPONENT */
/********************************/ /***********************/
/** /**
* Library component object definition. * Library component object definition.
...@@ -188,6 +187,10 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) : ...@@ -188,6 +187,10 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
m_showPinNumbers = true; m_showPinNumbers = true;
m_showPinNames = true; m_showPinNames = true;
// Create the default alias if the name paremeter is not empty.
if( !aName.IsEmpty() )
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present // Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
// when the field editors are invoked. // when the field editors are invoked.
LIB_FIELD* value = new LIB_FIELD( this, VALUE ); LIB_FIELD* value = new LIB_FIELD( this, VALUE );
...@@ -205,8 +208,6 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) ...@@ -205,8 +208,6 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary )
{ {
LIB_DRAW_ITEM* newItem; LIB_DRAW_ITEM* newItem;
m_AliasList = aComponent.m_AliasList;
m_aliasListData = aComponent.m_aliasListData;
m_FootprintList = aComponent.m_FootprintList; m_FootprintList = aComponent.m_FootprintList;
unitCount = aComponent.unitCount; unitCount = aComponent.unitCount;
m_unitsLocked = aComponent.m_unitsLocked; m_unitsLocked = aComponent.m_unitsLocked;
...@@ -225,13 +226,38 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) ...@@ -225,13 +226,38 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary )
newItem->SetParent( this ); newItem->SetParent( this );
drawings.push_back( newItem ); drawings.push_back( newItem );
} }
for( size_t i = 0; i < aComponent.m_aliases.size(); i++ )
{
LIB_ALIAS* alias = new LIB_ALIAS( *aComponent.m_aliases[i], this );
m_aliases.push_back( alias );
}
} }
LIB_COMPONENT::~LIB_COMPONENT() LIB_COMPONENT::~LIB_COMPONENT()
{ {
#if TRACE_DESTRUCTOR
wxLogDebug( wxT( "Destroying component <%s> with alias list count of %d" ),
GetChars( GetName() ), m_aliases.size() );
#endif
// If the component is being delete directly rather than trough the library, free all
// of the memory allocated by the aliases.
if( !m_aliases.empty() )
{
LIB_ALIAS* alias;
while( !m_aliases.empty() )
{
alias = m_aliases.back();
m_aliases.pop_back();
delete alias;
}
}
} }
/** function IsMulti /** function IsMulti
* @return the sub reference for component having multiple parts per package. * @return the sub reference for component having multiple parts per package.
* The sub reference identify the part (or unit) * The sub reference identify the part (or unit)
...@@ -592,15 +618,17 @@ bool LIB_COMPONENT::Save( FILE* aFile ) ...@@ -592,15 +618,17 @@ bool LIB_COMPONENT::Save( FILE* aFile )
} }
} }
/* Save the alias list: a line starting by "ALIAS" */ // Save the alias list: a line starting by "ALIAS". The first alias is the root
if( m_AliasList.GetCount() != 0 ) // and has the same name as the component. In the old library file format this
// alias does not get added to the alias list.
if( m_aliases.size() > 1 )
{ {
if( fprintf( aFile, "ALIAS" ) < 0 ) if( fprintf( aFile, "ALIAS" ) < 0 )
return false; return false;
for( i = 0; i < m_AliasList.GetCount(); i++ ) for( i = 1; i < m_aliases.size(); i++ )
{ {
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_AliasList[i] ) ) < 0 ) if( fprintf( aFile, " %s", CONV_TO_UTF8( m_aliases[i]->GetName() ) ) < 0 )
return false; return false;
} }
...@@ -616,8 +644,7 @@ bool LIB_COMPONENT::Save( FILE* aFile ) ...@@ -616,8 +644,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
for( i = 0; i < m_FootprintList.GetCount(); i++ ) for( i = 0; i < m_FootprintList.GetCount(); i++ )
{ {
if( fprintf( aFile, " %s\n", if( fprintf( aFile, " %s\n", CONV_TO_UTF8( m_FootprintList[i] ) ) < 0 )
CONV_TO_UTF8( m_FootprintList[i] ) ) < 0 )
return false; return false;
} }
...@@ -655,8 +682,7 @@ bool LIB_COMPONENT::Save( FILE* aFile ) ...@@ -655,8 +682,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
} }
bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg )
wxString& aErrorMsg )
{ {
int unused; int unused;
char* p; char* p;
...@@ -723,6 +749,9 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, ...@@ -723,6 +749,9 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum,
value.m_Attributs |= TEXT_NO_VISIBLE; value.m_Attributs |= TEXT_NO_VISIBLE;
} }
// Add the root alias to the alias list.
m_aliases.push_back( new LIB_ALIAS( name, this ) );
LIB_FIELD& reference = GetReferenceField(); LIB_FIELD& reference = GetReferenceField();
if( strcmp( prefix, "~" ) == 0 ) if( strcmp( prefix, "~" ) == 0 )
...@@ -872,7 +901,7 @@ bool LIB_COMPONENT::LoadAliases( char* aLine, wxString& aErrorMsg ) ...@@ -872,7 +901,7 @@ bool LIB_COMPONENT::LoadAliases( char* aLine, wxString& aErrorMsg )
while( text ) while( text )
{ {
m_AliasList.Add( CONV_FROM_UTF8( text ) ); m_aliases.push_back( new LIB_ALIAS( CONV_FROM_UTF8( text ), this ) );
text = strtok( NULL, " \t\r\n" ); text = strtok( NULL, " \t\r\n" );
} }
...@@ -1454,144 +1483,140 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert ) ...@@ -1454,144 +1483,140 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert )
} }
/* accessors to aliases data, used by the component editor, during edition wxArrayString LIB_COMPONENT::GetAliasNames( bool aIncludeRoot ) const
*/
/** Function LocateAliasData
* @return an index in array string to the alias data (doc, keywords, docfile)
* or -1 if not found
* @param aAliasName = the alias name
* @param aCreateIfNotExist = true if the alias data must be created, when not exists
*/
int LIB_COMPONENT::LocateAliasData( const wxString & aAliasName, bool aCreateIfNotExist)
{ {
int idx = -1; wxArrayString names;
for( unsigned ii = 0; ii < m_aliasListData.size(); ii += ALIAS_NEXT_IDX )
LIB_ALIAS_LIST::const_iterator it;
for( it=m_aliases.begin(); it<m_aliases.end(); ++it )
{ {
if( aAliasName.CmpNoCase( m_aliasListData[ii] ) != 0 ) if( !aIncludeRoot && (*it)->IsRoot() )
continue; continue;
// Found!
idx = (int) ii;
break;
}
// Alias not found, create on demand names.Add( (*it)->GetName() );
if( aCreateIfNotExist && (idx < 0) )
{
idx = (int) m_aliasListData.size();
m_aliasListData.Add( aAliasName );
// Add void strings for data:
m_aliasListData.Add( wxEmptyString ); //Doc string
m_aliasListData.Add( wxEmptyString ); //keywords string
m_aliasListData.Add( wxEmptyString ); //Doc fliname string
} }
return idx; return names;
} }
/** Function GetAliasDataDoc bool LIB_COMPONENT::HasAlias( const wxString& aName ) const
* @param aAliasName = the alias name
* @return the Doc string
*/
wxString LIB_COMPONENT::GetAliasDataDoc( const wxString & aAliasName )
{ {
wxString data; wxCHECK2_MSG( !aName.IsEmpty(), return false,
int idx = LocateAliasData( aAliasName ); wxT( "Cannot get alias with an empty name, bad programmer." ) );
if ( idx >= 0 )
data = m_aliasListData[idx + ALIAS_DOC_IDX];
return data; for( size_t i = 0; i < m_aliases.size(); i++ )
{
if( aName.CmpNoCase( m_aliases[i]->GetName() ) == 0 )
return true;
}
return false;
} }
/** Function GetAliasDataKeyWords void LIB_COMPONENT::SetAliases( const wxArrayString& aAliasList )
* @param aAliasName = the alias name
* @return aAliasData = the keywords string
*/
wxString LIB_COMPONENT::GetAliasDataKeyWords( const wxString & aAliasName )
{ {
wxString data; wxCHECK_RET( library == NULL,
int idx = LocateAliasData( aAliasName ); wxT( "Component aliases cannot be changed when they are owned by a library." ) );
if ( idx >= 0 )
data = m_aliasListData[idx + ALIAS_KEYWORD_IDX];
return data; if( aAliasList == GetAliasNames() )
} return;
// Add names not existing in the current component alias list.
for( size_t i = 0; i < aAliasList.GetCount(); i++ )
{
if( HasAlias( aAliasList[ i ] ) )
continue;
/** Function GetAliasDataDocFileName m_aliases.push_back( new LIB_ALIAS( aAliasList[ i ], this ) );
* @param aAliasName = the alias name }
* @return the Doc filename string
*/
wxString LIB_COMPONENT::GetAliasDataDocFileName( const wxString & aAliasName )
{
wxString data;
int idx = LocateAliasData( aAliasName );
if ( idx >= 0 )
data = m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX];
return data; /* Remove names in the current component that are not in the new alias list. */
} LIB_ALIAS_LIST::iterator it;
for( it = m_aliases.begin(); it < m_aliases.end(); it++ )
{
int index = aAliasList.Index( (*it)->GetName(), false );
if( index != wxNOT_FOUND || (*it)->IsRoot() )
continue;
/** Function SetAliasDataDoc it = m_aliases.erase( it );
* @param aAliasName = the alias name }
* @param aAliasData = the Doc string
*/
void LIB_COMPONENT::SetAliasDataDoc( const wxString & aAliasName, const wxString & aAliasData )
{
int idx = LocateAliasData( aAliasName, true );
m_aliasListData[idx + ALIAS_DOC_IDX] = aAliasData;
} }
/** Function SetAliasDataKeywords
* @param aAliasName = the alias name void LIB_COMPONENT::RemoveAlias( const wxString& aName )
* @param aAliasData = the keywords string
*/
void LIB_COMPONENT::SetAliasDataKeywords( const wxString & aAliasName, const wxString & aAliasData )
{ {
int idx = LocateAliasData( aAliasName, true ); wxCHECK_RET( library == NULL,
m_aliasListData[idx + ALIAS_KEYWORD_IDX] = aAliasData; wxT( "Component aliases cannot be changed when they are owned by a library." ) );
wxCHECK_RET( !aName.IsEmpty(), wxT( "Cannot get alias with an empty name." ) );
LIB_ALIAS_LIST::iterator it;
for( it = m_aliases.begin(); it < m_aliases.end(); it++ )
{
if( aName.CmpNoCase( (*it)->GetName() ) == 0 )
{
m_aliases.erase( it );
break;
}
}
} }
/** Function SetAliasDataDocFileName
* @param aAliasName = the alias name LIB_ALIAS* LIB_COMPONENT::RemoveAlias( LIB_ALIAS* aAlias )
* @param aAliasData = the Doc filename string
*/
void LIB_COMPONENT::SetAliasDataDocFileName( const wxString & aAliasName,
const wxString & aAliasData )
{ {
int idx = LocateAliasData( aAliasName, true ); wxCHECK_MSG( aAlias != NULL, NULL, wxT( "Cannot remove alias by NULL pointer." ) );
m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX] = aAliasData;
LIB_ALIAS* nextAlias = NULL;
LIB_ALIAS_LIST::iterator it = find( m_aliases.begin(), m_aliases.end(), aAlias );
if( it != m_aliases.end() )
{
bool rename = aAlias->IsRoot();
it = m_aliases.erase( it );
delete aAlias;
if( !m_aliases.empty() )
{
if( it == m_aliases.end() )
it = m_aliases.begin();
nextAlias = (*it);
if( rename )
SetName( nextAlias->GetName() );
}
}
return nextAlias;
} }
/** Function RemoveAliasData LIB_ALIAS* LIB_COMPONENT::GetAlias( const wxString& aName )
* remove an alias data from list
* @param aAliasName = the alias name
*/
void LIB_COMPONENT::RemoveAliasData(const wxString & aAliasName )
{ {
int idx = LocateAliasData( aAliasName ); wxCHECK2_MSG( !aName.IsEmpty(), return NULL,
if ( idx >= 0 ) wxT( "Cannot get alias with an empty name. Bad programmer!" ) );
m_aliasListData.RemoveAt( idx + ALIAS_NAME_IDX, ALIAS_NEXT_IDX );
for( size_t i = 0; i < m_aliases.size(); i++ )
{
if( aName.CmpNoCase( m_aliases[i]->GetName() ) == 0 )
return m_aliases[i];
}
return NULL;
} }
/** Function CollectAliasesData
* store in m_aliasListData alias data (doc, keywords, docfile) LIB_ALIAS* LIB_COMPONENT::GetAlias( size_t aIndex )
* for each alias found in m_AliasList
*/
void LIB_COMPONENT::CollectAliasesData( CMP_LIBRARY* aLibrary )
{ {
for( unsigned ii = 0; ii < m_AliasList.GetCount(); ii++ ) wxCHECK2_MSG( aIndex < m_aliases.size(), return NULL,
{ wxT( "Illegal alias list index, bad programmer." ) );
CMP_LIB_ENTRY* entry = aLibrary->FindEntry( m_AliasList[ii] );
if ( ! entry )
continue;
SetAliasDataDoc( m_AliasList[ii], entry->GetDescription() ); return m_aliases[aIndex];
SetAliasDataKeywords( m_AliasList[ii], entry->GetKeyWords() );
SetAliasDataDocFileName( m_AliasList[ii], entry->GetDocFileName() );
}
} }
...@@ -8,11 +8,27 @@ ...@@ -8,11 +8,27 @@
#include "classes_body_items.h" #include "classes_body_items.h"
#include "class_libentry_fields.h" #include "class_libentry_fields.h"
#include <boost/ptr_container/ptr_vector.hpp> #include <map>
class CMP_LIBRARY; class CMP_LIBRARY;
class LIB_ALIAS;
/**
* LIB_ALIAS map sorting.
*/
struct AliasMapSort
{
bool operator() ( const wxString& aItem1, const wxString& aItem2 ) const
{ return aItem1.CmpNoCase( aItem2 ) < 0; }
};
/**
* Alias map used by component library object.
*/
typedef std::map< wxString, LIB_ALIAS*, AliasMapSort > LIB_ALIAS_MAP;
typedef std::vector< LIB_ALIAS* > LIB_ALIAS_LIST;
/* Types for components in libraries /* Types for components in libraries
* components can be a true component or an alias of a true component. * components can be a true component or an alias of a true component.
...@@ -114,10 +130,9 @@ public: ...@@ -114,10 +130,9 @@ public:
{ {
return !( *this == aName ); return !( *this == aName );
} }
};
typedef boost::ptr_vector< CMP_LIB_ENTRY > LIB_ENTRY_LIST;
bool operator==( const wxString& aName ) const { return *this == ( const wxChar* ) aName; }
};
extern bool operator<( const CMP_LIB_ENTRY& aItem1, const CMP_LIB_ENTRY& aItem2 ); extern bool operator<( const CMP_LIB_ENTRY& aItem1, const CMP_LIB_ENTRY& aItem2 );
...@@ -142,42 +157,21 @@ class LIB_COMPONENT : public CMP_LIB_ENTRY ...@@ -142,42 +157,21 @@ class LIB_COMPONENT : public CMP_LIB_ENTRY
LibrEntryOptions m_options; ///< Special component features such as POWER or NORMAL.) LibrEntryOptions m_options; ///< Special component features such as POWER or NORMAL.)
int unitCount; ///< Number of units (parts) per package. int unitCount; ///< Number of units (parts) per package.
LIB_DRAW_ITEM_LIST drawings; ///< How to draw this part. LIB_DRAW_ITEM_LIST drawings; ///< How to draw this part.
wxArrayString m_aliasListData; /* ALIAS data (name, doc, keywords and doc filename).
* Used only by the component editor LibEdit
* to store aliases info during edition
* usually void outside the component editor */
wxArrayString m_AliasList; ///< List of alias names for the component.
wxArrayString m_FootprintList; /**< List of suitable footprint names for the wxArrayString m_FootprintList; /**< List of suitable footprint names for the
component (wildcard names accepted). */ component (wild card names accepted). */
LIB_ALIAS_LIST m_aliases; ///< List of alias object pointers associated with the
///< component.
void deleteAllFields(); void deleteAllFields();
friend class CMP_LIBRARY; friend class CMP_LIBRARY;
friend class LIB_ALIAS;
public: public:
/* Offsets used in editing library component,
* for handle aliases data in m_AliasListData array string
* when editing a library component, aliases data is stored
* in m_AliasListData.
* 4 strings by alias are stored:
* name, doc, keywords and doc filename
* these constants are indexes in m_AliasListData
* to read/write strings for a given alias
*/
enum alias_idx
{
ALIAS_NAME_IDX = 0,
ALIAS_DOC_IDX = 1,
ALIAS_KEYWORD_IDX = 2,
ALIAS_DOC_FILENAME_IDX = 3,
ALIAS_NEXT_IDX = 4
};
LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL ); LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL ); LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );
~LIB_COMPONENT(); virtual ~LIB_COMPONENT();
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
...@@ -191,72 +185,31 @@ public: ...@@ -191,72 +185,31 @@ public:
GetValueField().m_Text = aName; GetValueField().m_Text = aName;
} }
wxArrayString& GetAliasList() { return m_AliasList; } wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
wxArrayString& GetFootPrints() { return m_FootprintList; } size_t GetAliasCount() const { return m_aliases.size(); }
/* accessors to aliases data, used by the component editor, during edition LIB_ALIAS* GetAlias( size_t aIndex );
*/
/** Function CollectAliasesData
* store in m_aliasListData alias data (doc, keywords, docfile)
* for each alias found in m_AliasList
*/
void CollectAliasesData( CMP_LIBRARY* aLibrary );
/** Function LocateAliasData LIB_ALIAS* GetAlias( const wxString& aName );
* @return an index in array string to the alias data (doc, keywords, docfile)
* or -1 if not found
* @param aAliasName = the alias name
* @param aCreateIfNotExist = true if the alias data must be created, when not exists
*/
int LocateAliasData( const wxString & aAliasName, bool aCreateIfNotExist = false );
/** Function GetAliasDataDoc /**
* @param aAliasName = the alias name * Test if alias \a aName is in component alias list.
* @return the Doc string *
*/ * Alias name comparisons are case insensitive.
wxString GetAliasDataDoc( const wxString & aAliasName ); *
* @param aName - Name of alias.
/** Function GetAliasDataKeyWords * @return True if alias name in alias list.
* @param aAliasName = the alias name
* @return aAliasData = the keywords string
*/
wxString GetAliasDataKeyWords( const wxString & aAliasName );
/** Function GetAliasDataDocFileName
* @param aAliasName = the alias name
* @return the Doc filename string
*/
wxString GetAliasDataDocFileName( const wxString & aAliasName );
/** Function SetAliasDataDoc
* @param aAliasName = the alias name
* @return aAliasData = the Doc string
*/ */
void SetAliasDataDoc( const wxString & aAliasName, const wxString & aAliasData ); bool HasAlias( const wxString& aName ) const;
/** Function SetAliasDataKeywords void SetAliases( const wxArrayString& aAliasList );
* @param aAliasName = the alias name
* @param aAliasData = the keywords string
*/
void SetAliasDataKeywords( const wxString & aAliasName, const wxString & aAliasData );
/** Function SetAliasDataDocFileName void RemoveAlias( const wxString& aName );
* @param aAliasName = the alias name
* @param aAliasData = the Doc filename string
*/
void SetAliasDataDocFileName( const wxString & aAliasName, const wxString & aAliasData );
/** Function ClearAliasDataDoc LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
* clear aliases data list
*/
void ClearAliasDataDoc( ) { m_aliasListData.Clear(); }
/** Function RemoveAliasData wxArrayString& GetFootPrints() { return m_FootprintList; }
* remove an alias data from list
* @param aAliasName = the alias name
*/
void RemoveAliasData(const wxString & aAliasName );
EDA_Rect GetBoundaryBox( int aUnit, int aConvert ); EDA_Rect GetBoundaryBox( int aUnit, int aConvert );
...@@ -286,8 +239,8 @@ public: ...@@ -286,8 +239,8 @@ public:
bool LoadAliases( char* aLine, wxString& aErrorMsg ); bool LoadAliases( char* aLine, wxString& aErrorMsg );
bool LoadFootprints( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg ); bool LoadFootprints( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool isPower() { return m_options == ENTRY_POWER; } bool IsPower() { return m_options == ENTRY_POWER; }
bool isNormal() { return m_options == ENTRY_NORMAL; } bool IsNormal() { return m_options == ENTRY_NORMAL; }
void SetPower() { m_options = ENTRY_POWER; } void SetPower() { m_options = ENTRY_POWER; }
void SetNormal() { m_options = ENTRY_NORMAL; } void SetNormal() { m_options = ENTRY_NORMAL; }
...@@ -301,7 +254,7 @@ public: ...@@ -301,7 +254,7 @@ public:
* in \a aFieldsList. The only known caller of this function is the * in \a aFieldsList. The only known caller of this function is the
* library component field editor, and it establishes needed behavior. * library component field editor, and it establishes needed behavior.
* *
* @param aFieldsList is a set of fields to import, removing all previous fields. ` * @param aFieldsList is a set of fields to import, removing all previous fields.
*/ */
void SetFields( const std::vector <LIB_FIELD>& aFieldsList ); void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
...@@ -460,20 +413,6 @@ public: ...@@ -460,20 +413,6 @@ public:
*/ */
bool HasConversion() const; bool HasConversion() const;
/**
* Test if alias \a aName is in component alias list.
*
* Alias name comparisons are case insensitive.
*
* @param aName - Name of alias.
* @return True if alias name in alias list.
*/
bool HasAlias( const wxChar* aName )
{
wxASSERT( aName != NULL );
return m_AliasList.Index( aName ) != wxNOT_FOUND;
}
/** /**
* Clears the status flag all draw objects in this component. * Clears the status flag all draw objects in this component.
*/ */
...@@ -630,6 +569,8 @@ public: ...@@ -630,6 +569,8 @@ public:
void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; } void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
bool ShowPinNumbers() { return m_showPinNumbers; } bool ShowPinNumbers() { return m_showPinNumbers; }
bool operator==( const LIB_COMPONENT* aComponent ) const { return this == aComponent; }
}; };
...@@ -641,23 +582,24 @@ public: ...@@ -641,23 +582,24 @@ public:
*/ */
class LIB_ALIAS : public CMP_LIB_ENTRY class LIB_ALIAS : public CMP_LIB_ENTRY
{ {
friend class LIB_COMPONENT;
protected: protected:
/** /**
* The actual component of the alias. * The actual component of the alias.
* *
* @note - Do not delete the root component. The root component is owned * @note - Do not delete the root component. The root component is actually shared by
* by library the component is part of. Deleting the root component * all of the aliases associated with it. The component pointer will be delete
* will likely cause EESchema to crash. * in the destructor of the last alias that shares this component is deleted.
* Or, if the root component is deleted, aliases must be deleted or their .root member * Deleting the root component will likely cause EESchema to crash.
* must be changed to point a new root component
*/ */
LIB_COMPONENT* root; LIB_COMPONENT* root;
public: public:
LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent, LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent );
CMP_LIBRARY* aLibrary = NULL ); LIB_ALIAS( LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent = NULL );
LIB_ALIAS( LIB_ALIAS& aAlias, CMP_LIBRARY* aLibrary = NULL );
~LIB_ALIAS(); virtual ~LIB_ALIAS();
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
...@@ -672,10 +614,9 @@ public: ...@@ -672,10 +614,9 @@ public:
return root; return root;
} }
/** bool IsRoot() const { return name.CmpNoCase( root->GetName() ) == 0; }
* Set the alias root component.
*/ bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
void SetComponent( LIB_COMPONENT* aComponent );
}; };
......
...@@ -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"
......
...@@ -26,13 +26,6 @@ _( "Library <%s> has duplicate entry name <%s>.\n\ ...@@ -26,13 +26,6 @@ _( "Library <%s> has duplicate entry name <%s>.\n\
This may cause some unexpected behavior when loading components into a schematic." ); This may cause some unexpected behavior when loading components into a schematic." );
static bool DuplicateEntryName( const CMP_LIB_ENTRY& aItem1,
const CMP_LIB_ENTRY& aItem2 )
{
return aItem1.GetName().CmpNoCase( aItem2.GetName() ) == 0;
}
bool operator==( const CMP_LIBRARY& aLibrary, const wxChar* aName ) bool operator==( const CMP_LIBRARY& aLibrary, const wxChar* aName )
{ {
return aLibrary.GetName().CmpNoCase( aName ) == 0; return aLibrary.GetName().CmpNoCase( aName ) == 0;
...@@ -90,22 +83,33 @@ CMP_LIBRARY::CMP_LIBRARY( int aType, const wxFileName& aFileName ) ...@@ -90,22 +83,33 @@ CMP_LIBRARY::CMP_LIBRARY( int aType, const wxFileName& aFileName )
CMP_LIBRARY::~CMP_LIBRARY() CMP_LIBRARY::~CMP_LIBRARY()
{ {
for( LIB_ALIAS_MAP::iterator it=aliases.begin(); it!=aliases.end(); it++ )
{
LIB_ALIAS* alias = (*it).second;
LIB_COMPONENT* component = alias->GetComponent();
alias = component->RemoveAlias( alias );
if( alias == NULL )
delete component;
}
} }
void CMP_LIBRARY::GetEntryNames( wxArrayString& aNames, bool aSort, bool aMakeUpperCase ) void CMP_LIBRARY::GetEntryNames( wxArrayString& aNames, bool aSort, bool aMakeUpperCase )
{ {
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries ) LIB_ALIAS_MAP::iterator it;
for( it=aliases.begin(); it!=aliases.end(); it++ )
{ {
if( aMakeUpperCase ) if( aMakeUpperCase )
{ {
wxString tmp = entry.GetName(); wxString tmp = (*it).first;
tmp.MakeUpper(); tmp.MakeUpper();
aNames.Add( tmp ); aNames.Add( tmp );
} }
else else
{ {
aNames.Add( entry.GetName() ); aNames.Add( (*it).first );
} }
} }
...@@ -119,14 +123,15 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, ...@@ -119,14 +123,15 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames,
const wxString& aKeySearch, const wxString& aKeySearch,
bool aSort ) bool aSort )
{ {
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries ) LIB_ALIAS_MAP::iterator it;
for( it=aliases.begin(); it!=aliases.end(); it++ )
{ {
if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, entry.GetKeyWords() ) ) if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) )
aNames.Add( entry.GetName() ); aNames.Add( (*it).first );
if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch, if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch,
entry.GetName(), (*it).second->GetName(), false ) )
false ) ) aNames.Add( (*it).first );
aNames.Add( entry.GetName() );
} }
if( aSort ) if( aSort )
...@@ -134,16 +139,17 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, ...@@ -134,16 +139,17 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames,
} }
void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, bool aSort )
bool aSort )
{ {
if( !aRe.IsValid() ) if( !aRe.IsValid() )
return; return;
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries ) LIB_ALIAS_MAP::iterator it;
for( it=aliases.begin(); it!=aliases.end(); it++ )
{ {
if( aRe.Matches( entry.GetKeyWords() ) ) if( aRe.Matches( (*it).second->GetKeyWords() ) )
aNames.Add( entry.GetName() ); aNames.Add( (*it).first );
} }
if( aSort ) if( aSort )
...@@ -151,37 +157,43 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, ...@@ -151,37 +157,43 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe,
} }
CMP_LIB_ENTRY* CMP_LIBRARY::FindEntry( const wxChar* aName ) bool CMP_LIBRARY::Conflicts( LIB_COMPONENT* aComponent )
{ {
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries ) wxCHECK_MSG( aComponent != NULL, false,
wxT( "Cannot test NULL component for conflicts in library " ) + GetName() );
for( size_t i=0; i<aComponent->m_aliases.size(); i++ )
{ {
if( entry.GetName().CmpNoCase( aName ) == 0 ) LIB_ALIAS_MAP::iterator it = aliases.find( aComponent->m_aliases[i]->GetName() );
return &entry;
if( it != aliases.end() )
return true;
} }
return NULL; return false;
} }
CMP_LIB_ENTRY* CMP_LIBRARY::FindEntry( const wxChar* aName, LibrEntryType aType ) CMP_LIB_ENTRY* CMP_LIBRARY::FindEntry( const wxChar* aName )
{ {
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries )
{ LIB_ALIAS_MAP::iterator it = aliases.find( wxString( aName ) );
if( entry.GetName().CmpNoCase( aName ) == 0 && entry.GetType() == aType )
return &entry; if( it != aliases.end() )
} return ( CMP_LIB_ENTRY* ) (*it).second;
return NULL; return NULL;
} }
/** /**
* Return the first entry in the library. * Return the first entry in the library.
* @return The first entry or NULL if the library has no entries. * @return The first entry or NULL if the library has no entries.
*/ */
CMP_LIB_ENTRY* CMP_LIBRARY::GetFirstEntry() CMP_LIB_ENTRY* CMP_LIBRARY::GetFirstEntry()
{ {
if( entries.size() ) if( aliases.size() )
return &entries.front(); return ( LIB_ALIAS* ) (*aliases.begin()).second;
else else
return NULL; return NULL;
} }
...@@ -191,15 +203,14 @@ LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* aName ) ...@@ -191,15 +203,14 @@ LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* aName )
LIB_COMPONENT* component = NULL; LIB_COMPONENT* component = NULL;
CMP_LIB_ENTRY* entry = FindEntry( aName ); CMP_LIB_ENTRY* entry = FindEntry( aName );
if( entry != NULL && entry->isAlias() ) if( entry != NULL )
{ {
wxCHECK_MSG( entry->isAlias(), NULL,
wxT( "Component found in library entry list, bad programmer!" ) );
LIB_ALIAS* alias = (LIB_ALIAS*) entry; LIB_ALIAS* alias = (LIB_ALIAS*) entry;
component = alias->GetComponent(); component = alias->GetComponent();
} }
else
{
component = (LIB_COMPONENT*) entry;
}
return component; return component;
} }
...@@ -209,7 +220,9 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias ) ...@@ -209,7 +220,9 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias )
{ {
wxASSERT( aAlias != NULL ); wxASSERT( aAlias != NULL );
if( FindEntry( aAlias->GetName() ) != NULL ) LIB_ALIAS_MAP::iterator it = aliases.find( aAlias->GetName() );
if( it != aliases.end() )
{ {
wxString msg; wxString msg;
...@@ -219,8 +232,8 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias ) ...@@ -219,8 +232,8 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias )
return false; return false;
} }
entries.push_back( (CMP_LIB_ENTRY*) aAlias ); aliases[ aAlias->GetName() ] = aAlias;
SetModifyFlags( ); isModified = true;
return true; return true;
} }
...@@ -242,220 +255,78 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent ) ...@@ -242,220 +255,78 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
if( aComponent == NULL ) if( aComponent == NULL )
return NULL; return NULL;
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this );
newCmp->ClearAliasDataDoc(); // Remove data used only in edition
// Conflict detection: See if already existing aliases exist, // Conflict detection: See if already existing aliases exist,
// and if yes, ask user for continue or abort // and if yes, ask user for continue or abort
// Special case: if the library is the library cache of the project, // Special case: if the library is the library cache of the project,
// old aliases are always removed to avoid conflict, // old aliases are always removed to avoid conflict,
// and user is not prompted ) // and user is not prompted )
if( !IsCache() ) if( Conflicts( aComponent ) && !IsCache() )
{
wxString msg;
int conflict_count = 0;
for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ )
{
LIB_ALIAS* alias = FindAlias( newCmp->m_AliasList[ i ] );
if( alias == NULL )
continue;
LIB_COMPONENT* cparent = alias->GetComponent();
if( cparent == NULL || // Lib error, should not occur.
( cparent->GetName().CmpNoCase( newCmp->GetName() ) != 0 ) )
{ {
if( cparent ) wxFAIL_MSG( wxT( "Cannot add component <" ) + aComponent->GetName() +
msg = cparent->GetName(); wxT( "> to library <" ) + GetName() + wxT( "> due to name conflict." ) );
else return NULL;
msg = _( "unknown" );
wxString msg1;
wxString parentName;
if( cparent )
parentName = cparent->GetName();
else
parentName = _("not found");
msg1.Printf( _( "alias <%s> already exists and has root name<%s>" ),
GetChars( alias->GetName() ),
GetChars( parentName ) );
msg << msg1 << wxT( "\n" );
conflict_count++;
} }
if( conflict_count > 20 )
break;
}
if( conflict_count ) // Conflict: ask user what he wants: remove all aliases or abort: LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this );
{
wxString title;
wxString msg1;
title.Printf( _( "Conflict in library <%s>"), GetChars( fileName.GetName()));
msg1.Printf( _("and appears in alias list of current component <%s>." ),
GetChars( newCmp->GetName() ) );
msg << wxT( "\n\n" ) << msg1;
msg << wxT( "\n\n" ) << _( "All old aliases will be removed. Continue ?" );
int diag = wxMessageBox( msg, title, wxYES | wxICON_QUESTION );
if( diag != wxYES )
{
delete newCmp;
return NULL;
}
}
}
for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ ) for( size_t i = 0; i < newCmp->m_aliases.size(); i++ )
{ {
wxString aliasname = newCmp->m_AliasList[ i ]; wxString aliasname = newCmp->m_aliases[i]->GetName();
LIB_ALIAS* alias = FindAlias( aliasname ); LIB_ALIAS* alias = FindAlias( aliasname );
if( alias == NULL ) if( alias != NULL )
{ RemoveEntry( (CMP_LIB_ENTRY*) alias );
alias = new LIB_ALIAS( aliasname, newCmp );
entries.push_back( alias );
}
else
{
LIB_COMPONENT* cparent = alias->GetComponent();
if( cparent == NULL || // Lib error, should not occurs aliases[ aliasname ] = newCmp->m_aliases[i];
( cparent->GetName().CmpNoCase( newCmp->GetName() ) != 0) )
{
// Remove alias from library and alias list of its root component
RemoveEntry( alias );
alias = new LIB_ALIAS( aliasname, newCmp );
entries.push_back( alias );
}
}
// Update alias data:
alias->SetDescription( aComponent->GetAliasDataDoc( aliasname ) );
alias->SetKeyWords( aComponent->GetAliasDataKeyWords( aliasname ) );
alias->SetDocFileName( aComponent->GetAliasDataDocFileName( aliasname ) );
} }
entries.push_back( (CMP_LIB_ENTRY*) newCmp ); isModified = true;
SetModifyFlags( );
entries.sort();
entries.unique( DuplicateEntryName );
return newCmp; return newCmp;
} }
/** function RemoveEntryName
* Remove an \a aName entry from the library list names.
* Warning: this is a partial 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 in library.
* @param aName - Entry name to remove from library.
*/
void CMP_LIBRARY::RemoveEntryName( const wxString& aName )
{
LIB_ENTRY_LIST::iterator i;
for( i = entries.begin(); i < entries.end(); i++ )
{
if( i->GetName().CmpNoCase( aName ) == 0 )
{
entries.erase( i );
return;
}
}
}
/** CMP_LIB_ENTRY* CMP_LIBRARY::RemoveEntry( CMP_LIB_ENTRY* aEntry )
* Remove safely an \a aEntry from the library.
*
* If the entry is an alias, the alias is removed from the library and from
* the alias list of the root component. If the entry is a root component
* with no aliases, it is removed from the library. If the entry is a root
* component with aliases, the root component is renamed to the name of
* 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.
*/
void CMP_LIBRARY::RemoveEntry( CMP_LIB_ENTRY* aEntry )
{ {
wxASSERT( aEntry != NULL ); wxCHECK_MSG( aEntry != NULL && aEntry->isAlias(), NULL,
wxT( "Only LIB_ALIAS pointers can be removed from library." ) );
LIB_COMPONENT* root; LIB_ALIAS_MAP::iterator it = aliases.find( aEntry->GetName() );
LIB_ALIAS* alias;
SetModifyFlags( ); if( it == aliases.end() )
return NULL;
if( aEntry->isAlias() ) // If the entry pointer doesn't match the name it is mapped to in the library, we
{ // have done someething terribly wrong.
alias = (LIB_ALIAS*) aEntry; wxCHECK_MSG( (*it).second == aEntry, NULL,
root = alias->GetComponent(); wxT( "Pointer mismatch while attempting to remove entry <" ) +
aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) );
/* Remove alias name from the root component alias list */ LIB_ALIAS* alias = (LIB_ALIAS*) aEntry;
if( root == NULL ) // Should not occur, but is not a fatal error LIB_COMPONENT* component = alias->GetComponent();
{ alias = component->RemoveAlias( alias );
wxLogDebug( wxT( "No root component found for alias <%s> in library <%s>." ),
GetChars( aEntry->GetName() ),
GetChars( fileName.GetName() ) );
}
else
{
int index = root->m_AliasList.Index( aEntry->GetName(), false );
if( index == wxNOT_FOUND ) // Should not occur, but is not a fatal error if( alias == NULL )
{ {
wxLogDebug( wxT( "Alias <%s> not found in component <%s> alias list in \ delete component;
library <%s>" ),
GetChars( aEntry->GetName() ),
GetChars( root->GetName() ),
GetChars( fileName.GetName() ) );
}
else
root->m_AliasList.RemoveAt( index );
}
RemoveEntryName( alias->GetName() );
return;
}
root = ( LIB_COMPONENT* ) aEntry;
/* Entry is a component with no aliases so removal is simple. */ if( aliases.size() > 1 )
if( root->m_AliasList.GetCount() == 0 )
{ {
RemoveEntryName( root->GetName() ); LIB_ALIAS_MAP::iterator next = it;
return; next++;
}
/* Entry is a component with one or more alias. */
wxString aliasName = root->m_AliasList[0];
/* The root component is not really deleted, it is renamed with the first if( next == aliases.end() )
* alias name. */ next = aliases.begin();
alias = FindAlias( aliasName );
if( alias == NULL ) alias = (*next).second;
{ }
wxLogWarning( wxT( "Alias <%s> for component <%s> not found in library <%s>" ),
GetChars( aliasName ),
GetChars( root->GetName() ),
GetChars( fileName.GetName() ) );
return;
} }
/* Remove the first alias name from the component alias list. */ aliases.erase( it );
root->m_AliasList.RemoveAt( 0 ); isModified = true;
/* Rename the component to the name of the first alias. */
root->SetDescription( alias->GetDescription() );
root->SetKeyWords( alias->GetKeyWords() );
/* Remove the first alias from library. */
RemoveEntryName( aliasName );
/* Change the root name. */ return (CMP_LIB_ENTRY*) alias;
root->SetName( aliasName );
} }
...@@ -473,79 +344,57 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent, ...@@ -473,79 +344,57 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
wxASSERT( aNewComponent != NULL ); wxASSERT( aNewComponent != NULL );
wxASSERT( aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 ); wxASSERT( aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 );
size_t i; /* Remove the old root component. The component will automatically be removed when all
* it's aliases are deleted.
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
newCmp->ClearAliasDataDoc( ); // this data is currently used only when editing the component
/* We want to remove the old root component, so we must remove old aliases.
* even if they are not modified, because their root component will be removed
*/ */
for( i = 0; i < aOldComponent->m_AliasList.GetCount(); i++ ) BOOST_FOREACH( LIB_ALIAS* alias, aOldComponent->m_aliases )
{ {
RemoveEntryName( aOldComponent->m_AliasList[ i ] ); RemoveEntry( (CMP_LIB_ENTRY*) alias );
} }
/* Now, add current aliases. */ LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
for( i = 0; i < aNewComponent->m_AliasList.GetCount(); i++ )
// Add new aliases to library alias map.
for( size_t i = 0; i < newCmp->m_aliases.size(); i++ )
{ {
wxString aliasname = aNewComponent->m_AliasList[ i ]; aliases[ newCmp->m_aliases[ i ]->GetName() ] = newCmp->m_aliases[ i ];
LIB_ALIAS* alias = new LIB_ALIAS( aliasname, newCmp );
// Update alias data:
alias->SetDescription( aNewComponent->GetAliasDataDoc( aliasname ) );
alias->SetKeyWords( aNewComponent->GetAliasDataKeyWords( aliasname ) );
alias->SetDocFileName( aNewComponent->GetAliasDataDocFileName( aliasname ) );
// Add it in library
entries.push_back( alias );
} }
RemoveEntryName( aOldComponent->GetName() ); isModified = true;
entries.push_back( newCmp );
entries.sort();
SetModifyFlags( );
return newCmp; return newCmp;
} }
CMP_LIB_ENTRY* CMP_LIBRARY::GetNextEntry( const wxChar* aName ) CMP_LIB_ENTRY* CMP_LIBRARY::GetNextEntry( const wxChar* aName )
{ {
size_t i; if( aliases.empty() )
CMP_LIB_ENTRY* entry = NULL; return NULL;
for( i = 0; i < entries.size(); i++ ) LIB_ALIAS_MAP::iterator it = aliases.find( wxString( aName ) );
{
if( entries[i].GetName().CmpNoCase( aName ) == 0 )
{
if( i < entries.size() - 1 )
{
entry = &entries[ i + 1 ];
break;
}
}
}
if( entry == NULL ) it++;
entry = &entries.front();
return entry; if( it == aliases.end() )
it = aliases.begin();
return ( CMP_LIB_ENTRY* ) (*it).second;
} }
CMP_LIB_ENTRY* CMP_LIBRARY::GetPreviousEntry( const wxChar* aName ) CMP_LIB_ENTRY* CMP_LIBRARY::GetPreviousEntry( const wxChar* aName )
{ {
size_t i; if( aliases.empty() )
CMP_LIB_ENTRY* entry = NULL; return NULL;
for( i = 0; i < entries.size(); i++ ) LIB_ALIAS_MAP::iterator it = aliases.find( wxString( aName ) );
{
if( entries[i].GetName().CmpNoCase( aName ) == 0 && entry )
break;
entry = &entries[i]; if( it == aliases.begin() )
} it = aliases.end();
return entry; it--;
return ( CMP_LIB_ENTRY* ) (*it).second;
} }
...@@ -574,6 +423,7 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg ) ...@@ -574,6 +423,7 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
if( GetLine( file, line, &lineNumber, sizeof( line ) ) == NULL ) if( GetLine( file, line, &lineNumber, sizeof( line ) ) == NULL )
{ {
aErrorMsg = _( "The file is empty!" ); aErrorMsg = _( "The file is empty!" );
fclose( file );
return false; return false;
} }
...@@ -597,18 +447,21 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg ) ...@@ -597,18 +447,21 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
|| !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) ) || !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) )
{ {
aErrorMsg = _( "The file is NOT an EESCHEMA library!" ); aErrorMsg = _( "The file is NOT an EESCHEMA library!" );
fclose( file );
return false; return false;
} }
if( !tkn.HasMoreTokens() ) if( !tkn.HasMoreTokens() )
{ {
aErrorMsg = _( "The file header is missing version and time stamp information." ); aErrorMsg = _( "The file header is missing version and time stamp information." );
fclose( file );
return false; return false;
} }
if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() ) if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() )
{ {
aErrorMsg = wxT( "The file header version information is invalid." ); aErrorMsg = wxT( "The file header version information is invalid." );
fclose( file );
return false; return false;
} }
...@@ -647,6 +500,7 @@ the current schematic." ), ...@@ -647,6 +500,7 @@ the current schematic." ),
if( !LoadHeader( file, &lineNumber ) ) if( !LoadHeader( file, &lineNumber ) )
{ {
aErrorMsg = _( "An error occurred attempting to read the header." ); aErrorMsg = _( "An error occurred attempting to read the header." );
fclose( file );
return false; return false;
} }
...@@ -665,14 +519,12 @@ the current schematic." ), ...@@ -665,14 +519,12 @@ the current schematic." ),
*/ */
if( FindEntry( libEntry->GetName() ) != NULL ) if( FindEntry( libEntry->GetName() ) != NULL )
{ {
wxString msg( wxGetTranslation(duplicate_name_msg)); wxString msg( wxGetTranslation( duplicate_name_msg ) );
wxLogWarning( msg, wxLogWarning( msg,
GetChars( fileName.GetName() ), GetChars( fileName.GetName() ),
GetChars( libEntry->GetName() ) ); GetChars( libEntry->GetName() ) );
} }
/* If we are here, this part is O.k. - put it in: */
entries.push_back( libEntry );
LoadAliases( libEntry ); LoadAliases( libEntry );
} }
else else
...@@ -686,7 +538,7 @@ the current schematic." ), ...@@ -686,7 +538,7 @@ the current schematic." ),
} }
} }
entries.sort(); fclose( file );
return true; return true;
} }
...@@ -694,23 +546,20 @@ the current schematic." ), ...@@ -694,23 +546,20 @@ the current schematic." ),
void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component ) void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component )
{ {
wxASSERT( component != NULL && component->isComponent() ); wxCHECK_RET( component != NULL && component->isComponent(),
wxT( "Cannot load aliases of NULL component object. Bad programmer!" ) );
LIB_ALIAS* alias; for( size_t i = 0; i < component->m_aliases.size(); i++ )
unsigned ii;
for( ii = 0; ii < component->GetAliasList().GetCount(); ii++ )
{ {
if( FindEntry( component->m_AliasList[ii] ) != NULL ) if( FindEntry( component->m_aliases[i]->GetName() ) != NULL )
{ {
wxString msg( wxGetTranslation(duplicate_name_msg)); wxString msg( wxGetTranslation( duplicate_name_msg ) );
wxLogError( msg, wxLogError( msg,
GetChars( fileName.GetName() ), GetChars( fileName.GetName() ),
GetChars( component->m_AliasList[ii] ) ); GetChars( component->m_aliases[i]->GetName() ) );
} }
alias = new LIB_ALIAS( component->m_AliasList[ii], component, this ); aliases[ component->m_aliases[i]->GetName() ] = component->m_aliases[i];
entries.push_back( alias );
} }
} }
...@@ -773,8 +622,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg ) ...@@ -773,8 +622,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg )
{ {
if( strncmp( line, "$CMP", 4 ) != 0 ) if( strncmp( line, "$CMP", 4 ) != 0 )
{ {
aErrorMsg.Printf( wxT( "$CMP command expected in line %d, aborted." ), aErrorMsg.Printf( wxT( "$CMP command expected in line %d, aborted." ), lineNumber );
lineNumber );
fclose( file ); fclose( file );
return false; return false;
} }
...@@ -790,27 +638,29 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg ) ...@@ -790,27 +638,29 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg )
{ {
if( strncmp( line, "$ENDCMP", 7 ) == 0 ) if( strncmp( line, "$ENDCMP", 7 ) == 0 )
break; break;
text = strtok( line + 2, "\n\r" ); text = strtok( line + 2, "\n\r" );;
if( entry )
{
wxASSERT( entry->isAlias() );
switch( line[0] ) switch( line[0] )
{ {
case 'D': case 'D':
if( entry )
entry->SetDescription( CONV_FROM_UTF8( text ) ); entry->SetDescription( CONV_FROM_UTF8( text ) );
break; break;
case 'K': case 'K':
if( entry )
entry->SetKeyWords( CONV_FROM_UTF8( text ) ); entry->SetKeyWords( CONV_FROM_UTF8( text ) );
break; break;
case 'F': case 'F':
if( entry )
entry->SetDocFileName( CONV_FROM_UTF8( text ) ); entry->SetDocFileName( CONV_FROM_UTF8( text ) );
break; break;
} }
} }
} }
}
fclose( file ); fclose( file );
return true; return true;
...@@ -830,8 +680,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat ) ...@@ -830,8 +680,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
backupFileName.SetExt( wxT( "bak" ) ); backupFileName.SetExt( wxT( "bak" ) );
wxRemoveFile( backupFileName.GetFullPath() ); wxRemoveFile( backupFileName.GetFullPath() );
if( !wxRenameFile( libFileName.GetFullPath(), if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) )
backupFileName.GetFullPath() ) )
{ {
libFileName.MakeAbsolute(); libFileName.MakeAbsolute();
msg = wxT( "Failed to rename old component library file " ) + msg = wxT( "Failed to rename old component library file " ) +
...@@ -845,13 +694,12 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat ) ...@@ -845,13 +694,12 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
if( libfile == NULL ) if( libfile == NULL )
{ {
libFileName.MakeAbsolute(); libFileName.MakeAbsolute();
msg = wxT( "Failed to create component library file " ) + msg = wxT( "Failed to create component library file " ) + libFileName.GetFullPath();
libFileName.GetFullPath();
DisplayError( NULL, msg ); DisplayError( NULL, msg );
return false; return false;
} }
ClearModifyFlag( ); isModified = false;
timeStamp = GetTimeStamp(); timeStamp = GetTimeStamp();
if( !SaveHeader( libfile ) ) if( !SaveHeader( libfile ) )
...@@ -862,15 +710,14 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat ) ...@@ -862,15 +710,14 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
bool success = true; bool success = true;
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries ) for( LIB_ALIAS_MAP::iterator it=aliases.begin(); it!=aliases.end(); it++ )
{ {
if ( entry.isComponent() ) if( !(*it).second->IsRoot() )
{ continue;
LIB_COMPONENT* component = ( LIB_COMPONENT* ) &entry;
if ( !component->Save( libfile ) ) if ( !(*it).second->GetComponent()->Save( libfile ) )
success = false; success = false;
} }
}
if( fprintf( libfile, "#\n#End Library\n" ) < 0 ) if( fprintf( libfile, "#\n#End Library\n" ) < 0 )
success = false; success = false;
...@@ -900,8 +747,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName ) ...@@ -900,8 +747,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
backupFileName.SetExt( wxT( "bck" ) ); backupFileName.SetExt( wxT( "bck" ) );
wxRemoveFile( backupFileName.GetFullPath() ); wxRemoveFile( backupFileName.GetFullPath() );
if( !wxRenameFile( docFileName.GetFullPath(), if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) )
backupFileName.GetFullPath() ) )
{ {
msg = wxT( "Failed to save old library document file " ) + msg = wxT( "Failed to save old library document file " ) +
backupFileName.GetFullPath(); backupFileName.GetFullPath();
...@@ -921,8 +767,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName ) ...@@ -921,8 +767,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
} }
char line[256]; char line[256];
if( fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT, if( fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT, DateAndTime( line ) ) < 0 )
DateAndTime( line ) ) < 0 )
{ {
fclose( docfile ); fclose( docfile );
return false; return false;
...@@ -930,9 +775,9 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName ) ...@@ -930,9 +775,9 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
bool success = true; bool success = true;
BOOST_FOREACH( CMP_LIB_ENTRY& entry, entries ) for( LIB_ALIAS_MAP::iterator it=aliases.begin(); it!=aliases.end(); it++ )
{ {
if ( !entry.SaveDoc( docfile ) ) if ( !(*it).second->SaveDoc( docfile ) )
success = false; success = false;
} }
...@@ -957,7 +802,7 @@ bool CMP_LIBRARY::SaveHeader( FILE* aFile ) ...@@ -957,7 +802,7 @@ bool CMP_LIBRARY::SaveHeader( FILE* aFile )
#if 0 #if 0
if( ( fprintf( aFile, "$HEADER\n" ) < 0 ) if( ( fprintf( aFile, "$HEADER\n" ) < 0 )
|| ( fprintf( aFile, "TimeStamp %8.8lX\n", m_TimeStamp ) < 0 ) || ( fprintf( aFile, "TimeStamp %8.8lX\n", m_TimeStamp ) < 0 )
|| ( fprintf( aFile, "Parts %d\n", entries.size() ) != 2 ) || ( fprintf( aFile, "Parts %d\n", aliases.size() ) != 2 )
|| ( fprintf( aFile, "$ENDHEADER\n" ) != 1 ) ) || ( fprintf( aFile, "$ENDHEADER\n" ) != 1 ) )
succes = false; succes = false;
#endif #endif
......
...@@ -62,11 +62,11 @@ class CMP_LIBRARY ...@@ -62,11 +62,11 @@ class CMP_LIBRARY
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,9 +221,8 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event ...@@ -221,9 +221,8 @@ 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; wxString msg;
msg.Printf( _( "A new name is entered for this component\n\ msg.Printf( _( "A new name is entered for this component\n\
...@@ -232,7 +231,6 @@ An alias %s already exists!\nCannot update this component" ), ...@@ -232,7 +231,6 @@ An alias %s already exists!\nCannot update this component" ),
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
}
/* save old cmp in undo list */ /* save old cmp in undo list */
m_Parent->SaveCopyInUndoList( m_LibEntry, IS_CHANGED ); m_Parent->SaveCopyInUndoList( m_LibEntry, IS_CHANGED );
......
...@@ -66,9 +66,10 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) ...@@ -66,9 +66,10 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
{ {
/* Update the doc, keyword and doc filename strings */ /* Update the doc, keyword and doc filename strings */
size_t i;
int index; int index;
LIB_ALIAS* alias;
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL ) if( component == NULL )
{ {
EndModal( wxID_CANCEL ); EndModal( wxID_CANCEL );
...@@ -77,51 +78,17 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) ...@@ -77,51 +78,17 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
m_Parent->SaveCopyInUndoList( component ); m_Parent->SaveCopyInUndoList( component );
wxString aliasname = m_Parent->GetAliasName(); alias = component->GetAlias( m_Parent->GetAliasName() );
if( aliasname.IsEmpty() ) // The root component is selected
{
component->SetDescription( m_DocCtrl->GetValue() );
component->SetKeyWords( m_KeywordsCtrl->GetValue() );
component->SetDocFileName( m_DocfileCtrl->GetValue() );
}
else // An alias is selected: update keyworks (if thias alias is new, it will be added in aliacd data list)
{
component->SetAliasDataDoc(aliasname, m_DocCtrl->GetValue() );
component->SetAliasDataKeywords(aliasname, m_KeywordsCtrl->GetValue() );
component->SetAliasDataDocFileName(aliasname, m_DocfileCtrl->GetValue() );
}
if( m_PartAliasListCtrl->GetStrings() != component->GetAliasList() )
{
wxArrayString aliases = m_PartAliasListCtrl->GetStrings();
/* Add names not existing in the current component alias list. */
for( i = 0; i < aliases.GetCount(); i++ )
{
index = component->GetAliasList().Index( aliases[ i ], false );
if( index != wxNOT_FOUND )
continue;
component->GetAliasList().Add( aliases[ i ] );
}
/* Remove names in the current component that are not in the new alias list. */
for( i = 0; i < component->GetAliasList().GetCount(); i++ )
{
index = aliases.Index( component->GetAliasList()[ i ], false );
if( index == wxNOT_FOUND ) wxCHECK_RET( alias != NULL,
continue; wxT( "Alias \"" ) + m_Parent->GetAliasName() + wxT( "\" of component \"" ) +
component->GetName() + wxT( "\" does not exist." ) );
component->GetAliasList().RemoveAt( i ); alias->SetDescription( m_DocCtrl->GetValue() );
i--; alias->SetKeyWords( m_KeywordsCtrl->GetValue() );
} alias->SetDocFileName( m_DocfileCtrl->GetValue() );
component->GetAliasList() = aliases; component->SetAliases( m_PartAliasListCtrl->GetStrings() );
}
index = m_SelNumberOfUnits->GetValue(); index = m_SelNumberOfUnits->GetValue();
ChangeNbUnitsPerPackage( index ); ChangeNbUnitsPerPackage( index );
...@@ -175,13 +142,11 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) ...@@ -175,13 +142,11 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
} }
/*******************************************************************************/
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::CopyDocToAlias( wxCommandEvent& WXUNUSED (event) ) void DIALOG_EDIT_COMPONENT_IN_LIBRARY::CopyDocToAlias( wxCommandEvent& WXUNUSED (event) )
/******************************************************************************/
{ {
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL || m_Parent->GetAliasName().IsEmpty() ) if( component == NULL )
return; return;
m_DocCtrl->SetValue( component->GetDescription() ); m_DocCtrl->SetValue( component->GetDescription() );
...@@ -190,43 +155,30 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::CopyDocToAlias( wxCommandEvent& WXUNUSED ...@@ -190,43 +155,30 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::CopyDocToAlias( wxCommandEvent& WXUNUSED
} }
/**********************************************************/ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllAliasOfPart( wxCommandEvent& WXUNUSED (event) )
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllAliasOfPart(
wxCommandEvent& WXUNUSED (event) )
/**********************************************************/
{ {
if( m_PartAliasListCtrl->FindString( m_Parent->GetAliasName() ) if( m_PartAliasListCtrl->FindString( m_Parent->GetAliasName() ) != wxNOT_FOUND )
!= wxNOT_FOUND )
{ {
wxString msg; wxString msg;
msg.Printf( _( "Alias <%s> cannot be removed while it is being \ msg.Printf( _( "Alias <%s> cannot be removed while it is being edited!" ),
edited!" ),
GetChars( m_Parent->GetAliasName() ) ); GetChars( m_Parent->GetAliasName() ) );
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
LIB_COMPONENT* component = m_Parent->GetComponent();
m_Parent->GetAliasName().Empty();
if( IsOK( this, _( "Remove all aliases from list?" ) ) ) if( IsOK( this, _( "Remove all aliases from list?" ) ) )
{ {
m_PartAliasListCtrl->Clear(); m_PartAliasListCtrl->Clear();
m_ButtonDeleteAllAlias->Enable( false ); m_ButtonDeleteAllAlias->Enable( false );
m_ButtonDeleteOneAlias->Enable( false ); m_ButtonDeleteOneAlias->Enable( false );
if( component )
component->ClearAliasDataDoc();
} }
} }
/*******************************************************************************/
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED (event) )
/*******************************************************************************/
/* Add a new name to the alias list box /* Add a new name to the alias list box
* New name cannot be the root name, and must not exists * New name cannot be the root name, and must not exists
*/ */
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED (event) )
{ {
wxString aliasname; wxString aliasname;
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
...@@ -249,8 +201,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED ...@@ -249,8 +201,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED
|| library->FindEntry( aliasname ) != NULL ) || library->FindEntry( aliasname ) != NULL )
{ {
wxString msg; wxString msg;
msg.Printf( _( "Alias or component name <%s> already exists in \ msg.Printf( _( "Alias or component name <%s> already exists in library <%s>." ),
library <%s>." ),
GetChars( aliasname ), GetChars( aliasname ),
GetChars( library->GetName() ) ); GetChars( library->GetName() ) );
DisplayError( this, msg ); DisplayError( this, msg );
...@@ -258,14 +209,13 @@ library <%s>." ), ...@@ -258,14 +209,13 @@ library <%s>." ),
} }
m_PartAliasListCtrl->Append( aliasname ); m_PartAliasListCtrl->Append( aliasname );
if( m_Parent->GetAliasName().IsEmpty() ) if( m_Parent->GetAliasName().CmpNoCase( component->GetName() ) == 0 )
m_ButtonDeleteAllAlias->Enable( true ); m_ButtonDeleteAllAlias->Enable( true );
m_ButtonDeleteOneAlias->Enable( true ); m_ButtonDeleteOneAlias->Enable( true );
} }
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart( void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart( wxCommandEvent& WXUNUSED (event) )
wxCommandEvent& WXUNUSED (event) )
{ {
wxString aliasname = m_PartAliasListCtrl->GetStringSelection(); wxString aliasname = m_PartAliasListCtrl->GetStringSelection();
...@@ -274,8 +224,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart( ...@@ -274,8 +224,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart(
if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 ) if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 )
{ {
wxString msg; wxString msg;
msg.Printf( _( "Alias <%s> cannot be removed while it is being \ msg.Printf( _( "Alias <%s> cannot be removed while it is being edited!" ),
edited!" ),
GetChars( aliasname ) ); GetChars( aliasname ) );
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
...@@ -284,7 +233,7 @@ edited!" ), ...@@ -284,7 +233,7 @@ edited!" ),
m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() ); m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() );
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
if( component ) if( component )
component->RemoveAliasData(aliasname); component->RemoveAlias( aliasname );
if( m_PartAliasListCtrl->IsEmpty() ) if( m_PartAliasListCtrl->IsEmpty() )
{ {
...@@ -301,8 +250,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit ) ...@@ -301,8 +250,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
{ {
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL || component->GetPartCount() == MaxUnit if( component == NULL || component->GetPartCount() == MaxUnit || MaxUnit < 1 )
|| MaxUnit < 1 )
return false; return false;
if( MaxUnit < component->GetPartCount() if( MaxUnit < component->GetPartCount()
...@@ -327,11 +275,9 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() ...@@ -327,11 +275,9 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
if( m_Parent->GetShowDeMorgan() ) if( m_Parent->GetShowDeMorgan() )
{ {
if( !IsOK( this, _( "Add new pins for alternate body style \ if( !IsOK( this, _( "Add new pins for alternate body style ( DeMorgan ) to component?" ) ) )
( DeMorgan ) to component?" ) ) )
return false; return false;
} }
else if( component->HasConversion() ) else if( component->HasConversion() )
{ {
if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from component?" ) ) ) if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from component?" ) ) )
...@@ -342,20 +288,18 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() ...@@ -342,20 +288,18 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
} }
component->SetConversion( m_Parent->GetShowDeMorgan() ); component->SetConversion( m_Parent->GetShowDeMorgan() );
m_Parent->OnModify( ); m_Parent->OnModify();
return true; return true;
} }
/****************************************************************************/
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& event ) void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& event )
/****************************************************************************/
{ {
wxString FullFileName, mask; wxString FullFileName, mask;
wxString docpath, filename; wxString docpath, filename;
docpath = wxGetApp().ReturnLastVisitedLibraryPath(wxT( "doc" )); docpath = wxGetApp().ReturnLastVisitedLibraryPath( wxT( "doc" ) );
mask = wxT( "*" ); mask = wxT( "*" );
FullFileName = EDA_FileSelector( _( "Doc Files" ), FullFileName = EDA_FileSelector( _( "Doc Files" ),
...@@ -374,25 +318,23 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e ...@@ -374,25 +318,23 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e
* list, just add the library name to the list. Otherwise, add * list, just add the library name to the list. Otherwise, add
* the library name with the full or relative path. * the library name with the full or relative path.
* the relative path, when possible is preferable, * the relative path, when possible is preferable,
* because it preserve use of default libraries paths, when the path is a sub path of these default paths * because it preserve use of default libraries paths, when the path is a sub path of
* these default paths
*/ */
wxFileName fn = FullFileName; wxFileName fn = FullFileName;
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() ); wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
filename = wxGetApp().ReturnFilenameWithRelativePathInLibPath(FullFileName); filename = wxGetApp().ReturnFilenameWithRelativePathInLibPath( FullFileName );
// Filenames are always stored in unix like mode, ie separator "\" is stored as "/" // Filenames are always stored in unix like mode, ie separator "\" is stored as "/"
// to ensure files are identical under unices and windows // to ensure files are identical under unices and windows
#ifdef __WINDOWS__ #ifdef __WINDOWS__
filename.Replace(wxT("\\"), wxT("/") ); filename.Replace( wxT( "\\" ), wxT( "/" ) );
#endif #endif
m_DocfileCtrl->SetValue( filename ); m_DocfileCtrl->SetValue( filename );
} }
/**********************************************************/ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllFootprintFilter( wxCommandEvent& WXUNUSED (event) )
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllFootprintFilter(
wxCommandEvent& WXUNUSED (event) )
/**********************************************************/
{ {
if( IsOK( this, _( "Ok to Delete FootprintFilter LIST" ) ) ) if( IsOK( this, _( "Ok to Delete FootprintFilter LIST" ) ) )
{ {
...@@ -403,13 +345,10 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllFootprintFilter( ...@@ -403,13 +345,10 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllFootprintFilter(
} }
/*******************************************************************************/
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNUSED (event) )
/*******************************************************************************/
/* Add a new name to the footprint filter list box /* Add a new name to the footprint filter list box
* Obvioulsy, cannot be void * Obvioulsy, cannot be void
*/ */
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNUSED (event) )
{ {
wxString Line; wxString Line;
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
...@@ -421,7 +360,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNU ...@@ -421,7 +360,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNU
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
return; // cancelled by user return; // cancelled by user
Line = dlg.GetValue( ); Line = dlg.GetValue();
Line.Replace( wxT( " " ), wxT( "_" ) ); Line.Replace( wxT( " " ), wxT( "_" ) );
if( Line.IsEmpty() ) if( Line.IsEmpty() )
...@@ -434,8 +373,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNU ...@@ -434,8 +373,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNU
{ {
wxString msg; wxString msg;
msg.Printf( _( "Foot print filter <%s> is already defined." ), msg.Printf( _( "Foot print filter <%s> is already defined." ), GetChars( Line ) );
GetChars( Line ) );
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
...@@ -446,10 +384,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNU ...@@ -446,10 +384,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNU
} }
/********************************************************/ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteOneFootprintFilter( wxCommandEvent& WXUNUSED (event) )
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteOneFootprintFilter(
wxCommandEvent& WXUNUSED (event) )
/********************************************************/
{ {
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
int ii = m_FootprintFilterListBox->GetSelection(); int ii = m_FootprintFilterListBox->GetSelection();
......
...@@ -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 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() )
{
nextEntry = m_library->GetNextEntry( m_component->GetName() );
if( nextEntry != NULL ) if( nextEntry != NULL )
newCmpName = nextEntry->GetName();
}
else
{ {
newCmpName = m_component->GetAliasList()[ 0 ]; if( LoadOneLibraryPartAux( nextEntry, m_library ) )
} Zoom_Automatique( false );
} }
else else
{ {
newCmpName = m_component->GetName(); SAFE_DELETE( m_component );
m_aliasName.Empty();
} }
m_library->RemoveEntry( LibEntry );
if( !newCmpName.IsEmpty() )
{
nextEntry = m_library->FindEntry( newCmpName );
if( nextEntry != NULL && LoadOneLibraryPartAux( nextEntry, m_library ) )
Zoom_Automatique( false );
DrawPanel->Refresh(); 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();
......
...@@ -64,132 +64,90 @@ FILL_T WinEDA_LibeditFrame:: m_drawFillStyle = NO_FILL; ...@@ -64,132 +64,90 @@ FILL_T WinEDA_LibeditFrame:: m_drawFillStyle = NO_FILL;
/* class WinEDA_LibeditFrame */ /* class WinEDA_LibeditFrame */
/*****************************/ /*****************************/
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 ) 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 )
EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, WinEDA_LibeditFrame::SaveActiveLibrary )
WinEDA_LibeditFrame::SaveActiveLibrary ) EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, EVT_TOOL( ID_LIBEDIT_DELETE_PART, WinEDA_LibeditFrame::DeleteOnePart )
EVT_TOOL( ID_LIBEDIT_NEW_PART, WinEDA_LibeditFrame::CreateNewLibraryPart )
EVT_TOOL( ID_LIBEDIT_SELECT_PART, WinEDA_LibeditFrame::LoadOneLibraryPart )
EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_PART, WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL( wxID_UNDO, WinEDA_LibeditFrame::GetComponentFromUndoList )
EVT_TOOL( wxID_REDO, WinEDA_LibeditFrame::GetComponentFromRedoList )
EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART, WinEDA_LibeditFrame::OnEditComponentProperties )
EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, WinEDA_LibeditFrame::InstallFieldsEditorDialog )
EVT_TOOL( ID_LIBEDIT_CHECK_PART, WinEDA_LibeditFrame::OnCheckComponent )
EVT_TOOL( ID_DE_MORGAN_NORMAL_BUTT, WinEDA_LibeditFrame::OnSelectBodyStyle )
EVT_TOOL( ID_DE_MORGAN_CONVERT_BUTT, WinEDA_LibeditFrame::OnSelectBodyStyle )
EVT_TOOL( ID_LIBEDIT_VIEW_DOC, WinEDA_LibeditFrame::OnViewEntryDoc )
EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_PIN, WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL( ExportPartId, WinEDA_LibeditFrame::OnExportPart )
EVT_TOOL( CreateNewLibAndSavePartId, WinEDA_LibeditFrame::OnExportPart )
EVT_TOOL( ImportPartId, WinEDA_LibeditFrame::OnImportPart )
EVT_KICAD_CHOICEBOX( ID_LIBEDIT_SELECT_PART_NUMBER, WinEDA_LibeditFrame::OnSelectPart )
EVT_KICAD_CHOICEBOX( ID_LIBEDIT_SELECT_ALIAS, WinEDA_LibeditFrame::OnSelectAlias )
/* Right vertical toolbar. */
EVT_TOOL( ID_NO_SELECT_BUTT, WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_EXPORT_BODY_BUTT,
WinEDA_LibeditFrame::Process_Special_Functions ) WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL( ID_LIBEDIT_DELETE_PART,
WinEDA_LibeditFrame::DeleteOnePart )
EVT_TOOL( ID_LIBEDIT_NEW_PART,
WinEDA_LibeditFrame::CreateNewLibraryPart )
EVT_TOOL( ID_LIBEDIT_SELECT_PART,
WinEDA_LibeditFrame::LoadOneLibraryPart )
EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_PART,
WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL( wxID_UNDO,
WinEDA_LibeditFrame::GetComponentFromUndoList )
EVT_TOOL( wxID_REDO,
WinEDA_LibeditFrame::GetComponentFromRedoList )
EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART,
WinEDA_LibeditFrame::OnEditComponentProperties )
EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS,
WinEDA_LibeditFrame::InstallFieldsEditorDialog )
EVT_TOOL( ID_LIBEDIT_CHECK_PART,
WinEDA_LibeditFrame::OnCheckComponent )
EVT_TOOL( ID_DE_MORGAN_NORMAL_BUTT,
WinEDA_LibeditFrame::OnSelectBodyStyle )
EVT_TOOL( ID_DE_MORGAN_CONVERT_BUTT,
WinEDA_LibeditFrame::OnSelectBodyStyle )
EVT_TOOL( ID_LIBEDIT_VIEW_DOC,
WinEDA_LibeditFrame::OnViewEntryDoc )
EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_PIN,
WinEDA_LibeditFrame::Process_Special_Functions )
EVT_TOOL( ExportPartId, WinEDA_LibeditFrame::OnExportPart )
EVT_TOOL( CreateNewLibAndSavePartId, WinEDA_LibeditFrame::OnExportPart )
EVT_TOOL( ImportPartId, WinEDA_LibeditFrame::OnImportPart )
EVT_KICAD_CHOICEBOX( ID_LIBEDIT_SELECT_PART_NUMBER,
WinEDA_LibeditFrame::OnSelectPart )
EVT_KICAD_CHOICEBOX( ID_LIBEDIT_SELECT_ALIAS,
WinEDA_LibeditFrame::OnSelectAlias )
/* Right vertical toolbar. */ /* menubar commands */
EVT_TOOL( ID_NO_SELECT_BUTT, WinEDA_LibeditFrame::Process_Special_Functions ) EVT_MENU( wxID_EXIT, WinEDA_LibeditFrame::CloseWindow )
EVT_TOOL_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_EXPORT_BODY_BUTT, EVT_MENU( ID_LIBEDIT_SAVE_CURRENT_LIB_AS, WinEDA_LibeditFrame::SaveActiveLibrary )
WinEDA_LibeditFrame::Process_Special_Functions ) EVT_MENU( ID_LIBEDIT_GEN_PNG_FILE, WinEDA_LibeditFrame::OnPlotCurrentComponent )
EVT_MENU( ID_LIBEDIT_GEN_SVG_FILE, WinEDA_LibeditFrame::OnPlotCurrentComponent )
EVT_MENU( ID_GENERAL_HELP, WinEDA_DrawFrame::GetKicadHelp )
/* menubar commands */ EVT_MENU( ID_CONFIG_REQ, WinEDA_LibeditFrame::InstallConfigFrame )
EVT_MENU( wxID_EXIT, EVT_MENU( ID_CONFIG_SAVE, WinEDA_LibeditFrame::Process_Config )
WinEDA_LibeditFrame::CloseWindow ) EVT_MENU( ID_CONFIG_READ, WinEDA_LibeditFrame::Process_Config )
EVT_MENU( ID_LIBEDIT_SAVE_CURRENT_LIB_AS, EVT_MENU( ID_COLORS_SETUP, WinEDA_LibeditFrame::Process_Config )
WinEDA_LibeditFrame::SaveActiveLibrary ) EVT_MENU( ID_LIBEDIT_DIMENSIONS, WinEDA_LibeditFrame::InstallDimensionsDialog )
EVT_MENU( ID_LIBEDIT_GEN_PNG_FILE,
WinEDA_LibeditFrame::OnPlotCurrentComponent )
EVT_MENU( ID_LIBEDIT_GEN_SVG_FILE,
WinEDA_LibeditFrame::OnPlotCurrentComponent )
EVT_MENU( ID_GENERAL_HELP,
WinEDA_DrawFrame::GetKicadHelp )
EVT_MENU( ID_CONFIG_REQ,
WinEDA_LibeditFrame::InstallConfigFrame )
EVT_MENU( ID_CONFIG_SAVE,
WinEDA_LibeditFrame::Process_Config )
EVT_MENU( ID_CONFIG_READ,
WinEDA_LibeditFrame::Process_Config )
EVT_MENU( ID_COLORS_SETUP,
WinEDA_LibeditFrame::Process_Config )
EVT_MENU( ID_LIBEDIT_DIMENSIONS,
WinEDA_LibeditFrame::InstallDimensionsDialog )
EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START,
ID_PREFERENCES_HOTKEY_END, ID_PREFERENCES_HOTKEY_END,
WinEDA_LibeditFrame::Process_Config ) WinEDA_LibeditFrame::Process_Config )
EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, WinEDA_LibeditFrame::SetLanguage )
WinEDA_LibeditFrame::SetLanguage )
/* Context menu events and commands. */
EVT_MENU( ID_LIBEDIT_EDIT_PIN, WinEDA_LibeditFrame::OnEditPin )
EVT_MENU( ID_LIBEDIT_ROTATE_PIN, WinEDA_LibeditFrame::OnRotatePin )
/* Context menu events and commands. */ EVT_MENU_RANGE( ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
EVT_MENU( ID_LIBEDIT_EDIT_PIN, WinEDA_LibeditFrame::OnEditPin )
EVT_MENU( ID_LIBEDIT_ROTATE_PIN, WinEDA_LibeditFrame::OnRotatePin )
EVT_MENU_RANGE( ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT, ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT,
WinEDA_LibeditFrame::Process_Special_Functions ) WinEDA_LibeditFrame::Process_Special_Functions )
EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE, EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
WinEDA_LibeditFrame::Process_Special_Functions ) WinEDA_LibeditFrame::Process_Special_Functions )
/* Update user interface elements. */ /* Update user interface elements. */
EVT_UPDATE_UI( ExportPartId, WinEDA_LibeditFrame::OnUpdateEditingPart ) EVT_UPDATE_UI( ExportPartId, WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( CreateNewLibAndSavePartId, EVT_UPDATE_UI( CreateNewLibAndSavePartId, WinEDA_LibeditFrame::OnUpdateEditingPart )
WinEDA_LibeditFrame::OnUpdateEditingPart ) EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_PART, WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_PART, EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, WinEDA_LibeditFrame::OnUpdateEditingPart )
WinEDA_LibeditFrame::OnUpdateEditingPart ) EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_PART, WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( wxID_UNDO, WinEDA_LibeditFrame::OnUpdateUndo )
EVT_UPDATE_UI( wxID_REDO, WinEDA_LibeditFrame::OnUpdateRedo )
EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_LIB, WinEDA_LibeditFrame::OnUpdateSaveCurrentLib )
EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, WinEDA_LibeditFrame::OnUpdateViewDoc )
EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_PIN, WinEDA_LibeditFrame::OnUpdatePinByPin )
EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER, WinEDA_LibeditFrame::OnUpdatePartNumber )
EVT_UPDATE_UI( ID_LIBEDIT_SELECT_ALIAS, WinEDA_LibeditFrame::OnUpdateSelectAlias )
EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, WinEDA_LibeditFrame::OnUpdateDeMorganNormal )
EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT, WinEDA_LibeditFrame::OnUpdateDeMorganConvert )
EVT_UPDATE_UI_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_EXPORT_BODY_BUTT,
WinEDA_LibeditFrame::OnUpdateEditingPart ) WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART,
WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_PART,
WinEDA_LibeditFrame::OnUpdateEditingPart )
EVT_UPDATE_UI( wxID_UNDO, WinEDA_LibeditFrame::OnUpdateUndo )
EVT_UPDATE_UI( wxID_REDO, WinEDA_LibeditFrame::OnUpdateRedo )
EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_LIB,
WinEDA_LibeditFrame::OnUpdateSaveCurrentLib )
EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, WinEDA_LibeditFrame::OnUpdateViewDoc )
EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_PIN,
WinEDA_LibeditFrame::OnUpdatePinByPin )
EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER,
WinEDA_LibeditFrame::OnUpdatePartNumber )
EVT_UPDATE_UI( ID_LIBEDIT_SELECT_ALIAS,
WinEDA_LibeditFrame::OnUpdateSelectAlias )
EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT,
WinEDA_LibeditFrame::OnUpdateDeMorganNormal )
EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT,
WinEDA_LibeditFrame::OnUpdateDeMorganConvert )
EVT_UPDATE_UI_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_EXPORT_BODY_BUTT,
WinEDA_LibeditFrame::OnUpdateEditingPart )
END_EVENT_TABLE() END_EVENT_TABLE()
WinEDA_LibeditFrame::WinEDA_LibeditFrame( WinEDA_SchematicFrame* aParent, WinEDA_LibeditFrame::WinEDA_LibeditFrame( WinEDA_SchematicFrame* aParent,
const wxString& title, const wxString& title,
const wxPoint& pos, const wxPoint& pos,
...@@ -274,8 +232,7 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( WinEDA_SchematicFrame* aParent, ...@@ -274,8 +232,7 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( WinEDA_SchematicFrame* aParent,
WinEDA_LibeditFrame::~WinEDA_LibeditFrame() WinEDA_LibeditFrame::~WinEDA_LibeditFrame()
{ {
WinEDA_SchematicFrame* frame = WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
(WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
frame->m_LibeditFrame = NULL; frame->m_LibeditFrame = NULL;
m_drawItem = m_lastDrawItem = NULL; m_drawItem = m_lastDrawItem = NULL;
...@@ -404,10 +361,8 @@ int WinEDA_LibeditFrame::BestZoom() ...@@ -404,10 +361,8 @@ int WinEDA_LibeditFrame::BestZoom()
} }
size -= wxSize( 25, 25 ); // reserve 100 mils margin size -= wxSize( 25, 25 ); // reserve 100 mils margin
ii = wxRound( ( (double) dx / (double) size.x ) * ii = wxRound( ( (double) dx / (double) size.x ) * (double) GetScreen()->m_ZoomScalar );
(double) GetScreen()->m_ZoomScalar ); jj = wxRound( ( (double) dy / (double) size.y ) * (double) GetScreen()->m_ZoomScalar );
jj = wxRound( ( (double) dy / (double) size.y ) *
(double) GetScreen()->m_ZoomScalar );
return MAX( ii + 1, jj + 1 ); return MAX( ii + 1, jj + 1 );
} }
...@@ -423,18 +378,13 @@ void WinEDA_LibeditFrame::UpdateAliasSelectList() ...@@ -423,18 +378,13 @@ void WinEDA_LibeditFrame::UpdateAliasSelectList()
if( m_component == NULL ) if( m_component == NULL )
return; return;
m_SelAliasBox->Append( m_component->GetName() ); m_SelAliasBox->Append( m_component->GetAliasNames() );
m_SelAliasBox->SetSelection( 0 ); m_SelAliasBox->SetSelection( 0 );
if( !m_component->GetAliasList().IsEmpty() )
{
m_SelAliasBox->Append( m_component->GetAliasList() );
int index = m_SelAliasBox->FindString( m_aliasName ); int index = m_SelAliasBox->FindString( m_aliasName );
if( index != wxNOT_FOUND ) if( index != wxNOT_FOUND )
m_SelAliasBox->SetSelection( index ); m_SelAliasBox->SetSelection( index );
}
} }
...@@ -443,7 +393,6 @@ void WinEDA_LibeditFrame::UpdatePartSelectList() ...@@ -443,7 +393,6 @@ void WinEDA_LibeditFrame::UpdatePartSelectList()
if( m_SelpartBox == NULL ) if( m_SelpartBox == NULL )
return; return;
if( m_SelpartBox->GetCount() != 0 ) if( m_SelpartBox->GetCount() != 0 )
m_SelpartBox->Clear(); m_SelpartBox->Clear();
...@@ -493,8 +442,7 @@ void WinEDA_LibeditFrame::OnUpdateRedo( wxUpdateUIEvent& event ) ...@@ -493,8 +442,7 @@ void WinEDA_LibeditFrame::OnUpdateRedo( wxUpdateUIEvent& event )
void WinEDA_LibeditFrame::OnUpdateSaveCurrentLib( wxUpdateUIEvent& event ) void WinEDA_LibeditFrame::OnUpdateSaveCurrentLib( wxUpdateUIEvent& event )
{ {
event.Enable( m_library != NULL event.Enable( m_library != NULL && ( m_library->IsModified() || GetScreen()->IsModify() ) );
&& ( m_library->IsModified()|| GetScreen()->IsModify() ) );
} }
...@@ -504,14 +452,11 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event ) ...@@ -504,14 +452,11 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event )
if( m_component != NULL && m_library != NULL ) if( m_component != NULL && m_library != NULL )
{ {
if( !m_aliasName.IsEmpty() ) LIB_ALIAS* alias = m_component->GetAlias( m_aliasName );
{
enable = !m_component->GetAliasDataDocFileName(m_aliasName).IsEmpty(); wxCHECK_RET( alias != NULL, wxT( "Alias not found." ) );
}
else if( !m_component->GetDocFileName().IsEmpty() ) enable = !alias->GetDocFileName().IsEmpty();
{
enable = true;
}
} }
event.Enable( enable ); event.Enable( enable );
...@@ -545,8 +490,7 @@ void WinEDA_LibeditFrame::OnUpdateDeMorganNormal( wxUpdateUIEvent& event ) ...@@ -545,8 +490,7 @@ void WinEDA_LibeditFrame::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
if( m_HToolBar == NULL ) if( m_HToolBar == NULL )
return; return;
event.Enable( GetShowDeMorgan() event.Enable( GetShowDeMorgan() || ( m_component && m_component->HasConversion() ) );
|| ( m_component && m_component->HasConversion() ) );
m_HToolBar->ToggleTool( event.GetId(), m_convert <= 1 ); m_HToolBar->ToggleTool( event.GetId(), m_convert <= 1 );
} }
...@@ -556,8 +500,7 @@ void WinEDA_LibeditFrame::OnUpdateDeMorganConvert( wxUpdateUIEvent& event ) ...@@ -556,8 +500,7 @@ void WinEDA_LibeditFrame::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
if( m_HToolBar == NULL ) if( m_HToolBar == NULL )
return; return;
event.Enable( GetShowDeMorgan() event.Enable( GetShowDeMorgan() || ( m_component && m_component->HasConversion() ) );
|| ( m_component && m_component->HasConversion() ) );
m_HToolBar->ToggleTool( event.GetId(), m_convert > 1 ); m_HToolBar->ToggleTool( event.GetId(), m_convert > 1 );
} }
...@@ -570,8 +513,7 @@ void WinEDA_LibeditFrame::OnUpdateSelectAlias( wxUpdateUIEvent& event ) ...@@ -570,8 +513,7 @@ void WinEDA_LibeditFrame::OnUpdateSelectAlias( wxUpdateUIEvent& event )
/* Using the typical event.Enable() call doesn't seem to work with wxGTK /* Using the typical event.Enable() call doesn't seem to work with wxGTK
* so use the pointer to alias combobox to directly enable or disable. * so use the pointer to alias combobox to directly enable or disable.
*/ */
m_SelAliasBox->Enable( m_component != NULL m_SelAliasBox->Enable( m_component != NULL && m_component->GetAliasCount() > 1 );
&& !m_component->GetAliasList().IsEmpty() );
} }
...@@ -582,11 +524,6 @@ void WinEDA_LibeditFrame::OnSelectAlias( wxCommandEvent& event ) ...@@ -582,11 +524,6 @@ void WinEDA_LibeditFrame::OnSelectAlias( wxCommandEvent& event )
return; return;
m_lastDrawItem = NULL; m_lastDrawItem = NULL;
if( m_SelAliasBox->GetStringSelection().CmpNoCase( m_component->GetName() )
== 0 )
m_aliasName.Empty();
else
m_aliasName = m_SelAliasBox->GetStringSelection(); m_aliasName = m_SelAliasBox->GetStringSelection();
DisplayCmpDoc(); DisplayCmpDoc();
...@@ -614,15 +551,14 @@ void WinEDA_LibeditFrame::OnViewEntryDoc( wxCommandEvent& event ) ...@@ -614,15 +551,14 @@ void WinEDA_LibeditFrame::OnViewEntryDoc( wxCommandEvent& event )
return; return;
wxString fileName; wxString fileName;
LIB_ALIAS* alias = m_component->GetAlias( m_aliasName );
if( !m_aliasName.IsEmpty() ) wxCHECK_RET( alias != NULL, wxT( "Alias not found." ) );
fileName = m_component->GetAliasDataDocFileName(m_aliasName);
else fileName = alias->GetDocFileName();
fileName = m_component->GetDocFileName();
if( !fileName.IsEmpty() ) if( !fileName.IsEmpty() )
GetAssociatedDocument( this, fileName, GetAssociatedDocument( this, fileName, &wxGetApp().GetLibraryPathList() );
&wxGetApp().GetLibraryPathList() );
} }
...@@ -956,8 +892,7 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -956,8 +892,7 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
break; break;
default: default:
DisplayError( this, DisplayError( this, wxT( "WinEDA_LibeditFrame::Process_Special_Functions error" ) );
wxT( "WinEDA_LibeditFrame::Process_Special_Functions error" ) );
break; break;
} }
......
...@@ -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,8 +135,7 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father, ...@@ -136,8 +135,7 @@ 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 );
} }
......
...@@ -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;
DrawPanel->DrawBackGround( DC ); wxCHECK_RET( entry->isAlias(),
wxT( "Entry \"" ) + entry->GetName() + wxT( "\" found in library <" ) +
lib->GetName() + wxT( "> is not a LIB_ALIAS object." ) );
if( entry->isAlias() )
{
LIB_ALIAS* alias = (LIB_ALIAS*) entry; LIB_ALIAS* alias = (LIB_ALIAS*) entry;
component = alias->GetComponent(); component = alias->GetComponent();
if( component == NULL ) // Should not occur DrawPanel->DrawBackGround( DC );
{
wxASSERT( component != NULL ); if( !alias->IsRoot() )
return;
}
if( ! component->isComponent() )
{ {
wxASSERT( component->isComponent() ); if( component == NULL ) // Should not occur
return; 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