Commit ab74cfed authored by stambaughw's avatar stambaughw

Component library object improvements.

Moved all library entry manipulation code scattered throughout EESchema into
the component library object itself.  Adding, removing, and searching is now
handled by the library object.  This is the precursor to replacing the current
priority queue code.
parent 4a9dffc3
...@@ -72,10 +72,10 @@ void ReAnnotatePowerSymbolsOnly( void ) ...@@ -72,10 +72,10 @@ void ReAnnotatePowerSymbolsOnly( void )
{ {
if( DrawList->Type() != TYPE_SCH_COMPONENT ) if( DrawList->Type() != TYPE_SCH_COMPONENT )
continue; continue;
SCH_COMPONENT* DrawLibItem = SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList;
(SCH_COMPONENT*) DrawList; EDA_LibComponentStruct* Entry =
EDA_LibComponentStruct* Entry = FindLibPart( ( EDA_LibComponentStruct* )FindLibPart( DrawLibItem->m_ChipName );
DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
if( (Entry == NULL) || (Entry->m_Options != ENTRY_POWER) ) if( (Entry == NULL) || (Entry->m_Options != ENTRY_POWER) )
continue; continue;
...@@ -354,9 +354,7 @@ int AddComponentsInSheetToList( std::vector <OBJ_CMP_TO_LIST>& aComponentsList, ...@@ -354,9 +354,7 @@ int AddComponentsInSheetToList( std::vector <OBJ_CMP_TO_LIST>& aComponentsList,
if( DrawList->Type() == TYPE_SCH_COMPONENT ) if( DrawList->Type() == TYPE_SCH_COMPONENT )
{ {
DrawLibItem = (SCH_COMPONENT*) DrawList; DrawLibItem = (SCH_COMPONENT*) DrawList;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), Entry = ( EDA_LibComponentStruct* )FindLibPart( DrawLibItem->m_ChipName );
wxEmptyString,
FIND_ROOT );
if( Entry == NULL ) if( Entry == NULL )
continue; continue;
......
...@@ -869,10 +869,12 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem, ...@@ -869,10 +869,12 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
if( aDrawLibItem ) if( aDrawLibItem )
{ {
NextItem = NULL; NextItem = NULL;
if( ( Entry = Entry =
FindLibPart( aDrawLibItem->m_ChipName.GetData(), wxEmptyString, ( EDA_LibComponentStruct* )FindLibPart( aDrawLibItem->m_ChipName );
FIND_ROOT ) ) == NULL )
if( Entry == NULL )
return NULL; return NULL;
DEntry = Entry->m_Drawings; DEntry = Entry->m_Drawings;
Multi = aDrawLibItem->m_Multi; Multi = aDrawLibItem->m_Multi;
convert = aDrawLibItem->m_Convert; convert = aDrawLibItem->m_Convert;
......
...@@ -512,7 +512,7 @@ void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ) ...@@ -512,7 +512,7 @@ void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
if( item->m_Selected == 0 ) if( item->m_Selected == 0 )
continue; continue;
item->m_Selected = 0; item->m_Selected = 0;
LibEDA_BaseStruct* newitem = CopyDrawEntryStruct( NULL, item ); LibEDA_BaseStruct* newitem = CopyDrawEntryStruct( item );
newitem->m_Selected = IS_SELECTED; newitem->m_Selected = IS_SELECTED;
newitem->SetNext( LibEntry->m_Drawings ); newitem->SetNext( LibEntry->m_Drawings );
LibEntry->m_Drawings = newitem; LibEntry->m_Drawings = newitem;
......
...@@ -649,7 +649,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( ...@@ -649,7 +649,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef(
Multi = 0; Multi = 0;
Unit = ' '; Unit = ' ';
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry ) if( Entry )
Multi = Entry->m_UnitCount; Multi = Entry->m_UnitCount;
...@@ -749,7 +749,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal( ...@@ -749,7 +749,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal(
Multi = 0; Multi = 0;
Unit = ' '; Unit = ' ';
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry ) if( Entry )
Multi = Entry->m_UnitCount; Multi = Entry->m_UnitCount;
......
...@@ -168,12 +168,29 @@ LibCmpEntry::LibCmpEntry( LibrEntryType CmpType, const wxChar* CmpName ) : ...@@ -168,12 +168,29 @@ LibCmpEntry::LibCmpEntry( LibrEntryType CmpType, const wxChar* CmpName ) :
} }
/******************************/
LibCmpEntry::~LibCmpEntry() LibCmpEntry::~LibCmpEntry()
{ {
} }
bool LibCmpEntry::operator==( const wxChar* name ) const
{
return m_Name.m_Text.CmpNoCase( name ) == 0;
}
bool operator<( LibCmpEntry& item1, LibCmpEntry& item2 )
{
return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) == -1;
}
int LibraryEntryCompare( LibCmpEntry* LE1, LibCmpEntry* LE2 )
{
return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text );
}
/*******************************/ /*******************************/
/* class EDA_LibCmpAliasStruct */ /* class EDA_LibCmpAliasStruct */
/*******************************/ /*******************************/
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#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>
/* 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.
*/ */
...@@ -52,16 +55,32 @@ public: ...@@ -52,16 +55,32 @@ public:
/** /**
* Writes the doc info out to a FILE in "*.dcm" format. * Write the entry document information to a FILE in "*.dcm" format.
* *
* @param aFile The FILE to write to. * @param aFile The FILE to write to.
* *
* @return bool - true if success writing else false. * @return bool - true if success writing else false.
*/ */
bool SaveDoc( FILE* aFile ); bool SaveDoc( FILE* aFile );
/**
* Case insensitive comparison of the component entry name.
*/
bool operator==( const wxChar* name ) const;
bool operator!=( const wxChar* name ) const
{
return !( *this == name );
}
}; };
typedef boost::ptr_vector< LibCmpEntry > LIB_ENTRY_LIST;
extern bool operator<( LibCmpEntry& item1, LibCmpEntry& item2 );
extern int LibraryEntryCompare( LibCmpEntry* LE1, LibCmpEntry* LE2 );
/** /**
* Library component object definition. * Library component object definition.
* *
......
This diff is collapsed.
/**********************************/ /***********************************/
/* Headers fo library definition */ /* Headers for library definition */
/**********************************/ /***********************************/
#ifndef CLASS_LIBRARY_H #ifndef CLASS_LIBRARY_H
#define CLASS_LIBRARY_H #define CLASS_LIBRARY_H
...@@ -8,11 +8,9 @@ ...@@ -8,11 +8,9 @@
#include "class_libentry.h" #include "class_libentry.h"
WX_DECLARE_LIST( EDA_LibComponentStruct, LIB_CMP_LIST );
/******************************/ /******************************/
/* Classe to handle a library */ /* Class to handle a library */
/******************************/ /******************************/
class LibraryStruct class LibraryStruct
...@@ -23,7 +21,6 @@ public: ...@@ -23,7 +21,6 @@ public:
wxString m_FullFileName; /* Full File Name (with path) of library. */ wxString m_FullFileName; /* Full File Name (with path) of library. */
wxString m_Header; /* first line of loaded library. */ wxString m_Header; /* first line of loaded library. */
int m_NumOfParts; /* Number of parts this library has. */ int m_NumOfParts; /* Number of parts this library has. */
PriorQue* m_Entries; /* Parts themselves are saved here. */
LibraryStruct* m_Pnext; /* Point on next lib in chain. */ LibraryStruct* m_Pnext; /* Point on next lib in chain. */
int m_Modified; /* flag indicateur d'edition */ int m_Modified; /* flag indicateur d'edition */
int m_Size; // Size in bytes (for statistics) int m_Size; // Size in bytes (for statistics)
...@@ -37,36 +34,173 @@ public: ...@@ -37,36 +34,173 @@ public:
~LibraryStruct(); ~LibraryStruct();
/** /**
* Function SaveLibrary * Save library to file.
* writes the data structures for this object out to 2 file *
* the library in "*.lib" format. * Two files are created. The component objects are save as component
* the doc file in "*.dcm" format. * library (*.lib) files. The alias objects are save as document
* creates a backup file for each file (.bak and .bck) * definition (*.dcm) files. If the component library already exists,
* @param aFullFileName The full lib filename. * it is backup up in file *.bak. If the document definition file
* already exists, it is backed up in file *.bck.
*
* @param aFullFileName - The library filename with path.
*
* @return bool - true if success writing else false. * @return bool - true if success writing else false.
*/ */
bool SaveLibrary( const wxString& aFullFileName ); bool SaveLibrary( const wxString& aFullFileName );
bool ReadHeader( FILE* file, int* LineNum ); bool ReadHeader( FILE* file, int* LineNum );
bool Load( wxString& errMsg );
void InsertAliases( PriorQue** PQ, EDA_LibComponentStruct* component );
private: private:
bool WriteHeader( FILE* file ); bool WriteHeader( FILE* file );
/* NOTE: For future expansion, do not delete. */
public: public:
LibraryStruct( const wxChar* fileName = NULL ); LibraryStruct( const wxChar* fileName = NULL );
/**
* Get library entry status.
*
* @return true if there are no entries in the library.
*/
bool IsEmpty()
{
return m_Entries == NULL;
}
/**
* Load a string array with the names of all the entries in this library.
*
* @param names - String array to place entry names into.
* @param sort - Sort names if true.
*/
void GetEntryNames( wxArrayString& names, bool sort = true );
/**
* Load string array with entry names matching name and/or key word.
*
* This currently mimics the old behavior of calling KeyWordOk() and
* WildCompareString(). The names array will be populated with the
* library entry names that meat the search criteria on exit.
*
* @todo Convert the search functions to use regular expressions which
* should give better search capability.
*
* @param names - String array to place entry names into.
* @parem nameSearch - Name wild card search criteria.
* @param keySearch - Key word search criteria.
* @param sort - Sort names if true.
*/
void SearchEntryNames( wxArrayString& names,
const wxString& nameSearch = wxEmptyString,
const wxString& keySearch = wxEmptyString,
bool sort = true );
/**
* Find entry by name.
*
* @param name - Name of entry, case insensitive.
*
* @return Pointer to entry if found. NULL if not found.
*/
LibCmpEntry* FindEntry( const wxChar* name );
/**
* Find entry by name and type.
*
* If the search type is an alias, the return entry can be either an
* alias or a component object. If the search type is a component
* (root) type, the object returned will be a component. This was
* done to emulate the old search pattern.
*
* @param name - Name of entry, case insensitive.
* @param type - Type of entry, root or alias.
*
* @return Pointer to entry if found. NULL if not found.
*/
LibCmpEntry* FindEntry( const wxChar* name, LibrEntryType type );
/**
* Add component entry to library.
*
* @param cmp - Component to add.
*
* @return Pointer to added component if successful.
*/
EDA_LibComponentStruct* AddComponent( EDA_LibComponentStruct* cmp );
/**
* Remove an entry 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 entry - Entry to remove from library.
*/
void RemoveEntry( LibCmpEntry* entry );
/**
* Return the first entry in the library.
*
* @return The first entry or NULL if the library has no entries.
*/
LibCmpEntry* GetFirstEntry()
{
return (LibCmpEntry*) PQFirst( &m_Entries, false );
}
/**
* Find next library entry by name.
*
* If the name of the entry is the last entry in the library, the first
* entry in the list is returned.
*
* @param name - Name of current entry.
*
* @return LibCmpEntry - Pointer to next entry if entry name is found.
* Otherwise NULL.
*/
LibCmpEntry* GetNextEntry( const wxChar* name );
/**
* Find previous library entry by name.
*
* If the name of the entry is the first entry in the library, the last
* entry in the list is returned.
*
* @param name - Name of current entry.
*
* @return LibCmpEntry - Pointer to previous entry if entry name is found.
* Otherwise NULL.
*/
LibCmpEntry* GetPreviousEntry( const wxChar* name );
bool Save( const wxString& saveAsFile ); bool Save( const wxString& saveAsFile );
wxString GetName(); wxString GetName();
protected: protected:
wxFileName m_fileName; /* Library file name. */ wxFileName m_fileName; /* Library file name. */
wxDateTime m_DateTime; /* Library save time and date. */ wxDateTime m_DateTime; /* Library save time and date. */
wxString m_Version; /* Library save version. */ wxString m_Version; /* Library save version. */
LIB_CMP_LIST m_componentList; /* List of components in this library. */ PriorQue* m_Entries; /* Parts themselves are saved here. */
friend class EDA_LibComponentStruct; friend class EDA_LibComponentStruct;
}; };
extern void FreeLibraryEntry( LibCmpEntry* Entry );
/**
* Case insensitive library name comparison.
*/
extern bool operator==( const LibraryStruct& lib, const wxChar* name );
extern bool operator!=( const LibraryStruct& lib, const wxChar* name );
#endif // CLASS_LIBRARY_H #endif // CLASS_LIBRARY_H
...@@ -424,8 +424,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) ...@@ -424,8 +424,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
m_AddExtraText = 0; m_AddExtraText = 0;
if( fieldNdx == REFERENCE ) if( fieldNdx == REFERENCE )
{ {
Entry = FindLibPart( component->m_ChipName.GetData(), wxEmptyString, Entry = ( EDA_LibComponentStruct* ) FindLibPart( component->m_ChipName );
FIND_ROOT );
if( Entry != NULL ) if( Entry != NULL )
{ {
if( Entry->m_UnitCount > 1 ) if( Entry->m_UnitCount > 1 )
......
...@@ -211,8 +211,9 @@ void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -211,8 +211,9 @@ void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
int ii; int ii;
bool dummy = FALSE; bool dummy = FALSE;
if( ( Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, Entry = ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
FIND_ROOT ) ) == NULL )
if( Entry == NULL )
{ {
/* composant non trouve, on affiche un composant "dummy" */ /* composant non trouve, on affiche un composant "dummy" */
dummy = TRUE; dummy = TRUE;
...@@ -518,8 +519,8 @@ void SCH_COMPONENT::AddField( const SCH_CMP_FIELD& aField ) ...@@ -518,8 +519,8 @@ void SCH_COMPONENT::AddField( const SCH_CMP_FIELD& aField )
EDA_Rect SCH_COMPONENT::GetBoundaryBox() const EDA_Rect SCH_COMPONENT::GetBoundaryBox() const
{ {
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(), EDA_LibComponentStruct* Entry =
wxEmptyString, FIND_ROOT ); ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
EDA_Rect BoundaryBox; EDA_Rect BoundaryBox;
int x0, xm, y0, ym; int x0, xm, y0, ym;
...@@ -634,7 +635,7 @@ void SCH_COMPONENT::ClearAnnotation( DrawSheetPath* aSheet ) ...@@ -634,7 +635,7 @@ void SCH_COMPONENT::ClearAnnotation( DrawSheetPath* aSheet )
wxString separators( wxT( " " ) ); wxString separators( wxT( " " ) );
wxArrayString reference_fields; wxArrayString reference_fields;
Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
if( Entry && Entry->m_UnitSelectionLocked ) if( Entry && Entry->m_UnitSelectionLocked )
KeepMulti = true; KeepMulti = true;
...@@ -1058,8 +1059,8 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox() ...@@ -1058,8 +1059,8 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox()
void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
{ {
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(), EDA_LibComponentStruct* Entry =
wxEmptyString, FIND_ROOT ); ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
wxString msg; wxString msg;
......
...@@ -388,7 +388,7 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList ) ...@@ -388,7 +388,7 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList )
#undef STRUCT #undef STRUCT
#define STRUCT ( (SCH_COMPONENT*) DrawItem ) #define STRUCT ( (SCH_COMPONENT*) DrawItem )
EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry;
Entry = FindLibPart( STRUCT->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( STRUCT->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
break; break;
......
/****************************/ /****************************/
/* EESchema - database.cpp */ /* EESchema - database.cpp */
/****************************/ /****************************/
/* Routine de selection d'un composant en librairie /* Routine de selection d'un composant en librairie
...@@ -19,16 +19,6 @@ ...@@ -19,16 +19,6 @@
#include "protos.h" #include "protos.h"
/* Routines locales */
/* Variables locales */
/********************************************************************************/
bool DataBaseGetName( WinEDA_DrawFrame* frame,
wxString& Keys, wxString& BufName )
/********************************************************************************/
/* /*
* Routine de selection du nom d'un composant en librairie pour chargement, * Routine de selection du nom d'un composant en librairie pour chargement,
* Keys pointe la liste des mots cles de filtrage * Keys pointe la liste des mots cles de filtrage
...@@ -41,103 +31,59 @@ bool DataBaseGetName( WinEDA_DrawFrame* frame, ...@@ -41,103 +31,59 @@ bool DataBaseGetName( WinEDA_DrawFrame* frame,
* place le nom du composant a charger, selectionne a partir d'une liste dans * place le nom du composant a charger, selectionne a partir d'une liste dans
* BufName * BufName
*/ */
wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys,
wxString& BufName )
{ {
int ii; LibraryStruct* Lib;
EDA_LibComponentStruct* LibEntry; wxArrayString nameList;
LibraryStruct* Lib; wxString msg;
WinEDAListBox* ListBox;
const wxChar** ListNames;
BufName.MakeUpper(); BufName.MakeUpper();
Keys.MakeUpper(); Keys.MakeUpper();
/* Examen de la liste des librairies pour comptage */ /* Examen de la liste des librairies pour comptage */
for( Lib = g_LibraryList, ii = 0; Lib != NULL; Lib = Lib->m_Pnext ) for( Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{ {
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE ); Lib->SearchEntryNames( nameList, BufName, Keys );
while( LibEntry )
{
if( !Keys.IsEmpty() )
{
if( KeyWordOk( Keys, LibEntry->m_KeyWord ) )
ii++;
}
else
{
if( WildCompareString( BufName, LibEntry->m_Name.m_Text, FALSE ) )
ii++;
}
LibEntry = (EDA_LibComponentStruct*) PQNext( Lib->m_Entries,
LibEntry,
NULL );
}
} }
if( ii == 0 ) if( nameList.IsEmpty() )
{ {
DisplayError( frame, _( "No Component found" ) ); msg = _( "No components found matching " );
return 0; if( !BufName.IsEmpty() )
}
ListNames = (const wxChar**) MyZMalloc( (ii + 1) * sizeof(const wxChar*) );
for( Lib = g_LibraryList, ii = 0; Lib != NULL; Lib = Lib->m_Pnext )
{
/* Examen de la liste des elements */
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
while( LibEntry )
{ {
msg += _( "name search criteria <" ) + BufName + wxT( "> " );
if( !Keys.IsEmpty() ) if( !Keys.IsEmpty() )
{ msg += _( "and " );
if( KeyWordOk( Keys, LibEntry->m_KeyWord ) )
{
ListNames[ii] = LibEntry->m_Name.m_Text.GetData(); ii++;
}
}
else if( WildCompareString( BufName, LibEntry->m_Name.m_Text,
FALSE ) )
{
ListNames[ii] = LibEntry->m_Name.m_Text; ii++;
}
LibEntry = (EDA_LibComponentStruct*) PQNext( Lib->m_Entries,
LibEntry,
NULL );
} }
}
ListBox = new WinEDAListBox( frame, _( "Selection" ), ListNames, if( !Keys.IsEmpty() )
wxEmptyString, DisplayCmpDoc, msg += _( "key search criteria <" ) + Keys + wxT( "> " );
wxColour( 200, 200, 255 ) );
ListBox->MoveMouseToOrigin();
/* Affichage de la liste selectionnee */ DisplayError( frame, msg );
if( ii )
{ return wxEmptyString;
ii = ListBox->ShowModal(); ListBox->Destroy();
if( ii < 0 )
ii = 0;
else
{
BufName = ListNames[ii];
ii = 1;
}
} }
wxSingleChoiceDialog dlg( frame, wxEmptyString, _( "Select Component" ),
nameList );
free( ListNames ); if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
return ii; return wxEmptyString;
return dlg.GetStringSelection();
} }
/**********************************/
void DisplayCmpDoc( wxString& Name ) void DisplayCmpDoc( wxString& Name )
/**********************************/
{ {
LibCmpEntry* CmpEntry; LibCmpEntry* CmpEntry;
CmpEntry = FindLibPart( Name.GetData(), wxEmptyString, FIND_ALIAS ); CmpEntry = FindLibPart( Name, wxEmptyString, ALIAS );
if( CmpEntry == NULL ) if( CmpEntry == NULL )
return; return;
Name = wxT( "Descr: " ) + CmpEntry->m_Doc; Name = wxT( "Description: " ) + CmpEntry->m_Doc;
Name += wxT( "\nKeyW: " ) + CmpEntry->m_KeyWord; Name += wxT( "\nKey Words: " ) + CmpEntry->m_KeyWord;
} }
...@@ -171,7 +171,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() ...@@ -171,7 +171,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()
else if( newname.CmpNoCase( m_Cmp->m_ChipName ) ) else if( newname.CmpNoCase( m_Cmp->m_ChipName ) )
{ {
if( FindLibPart( newname.GetData(), wxEmptyString, FIND_ALIAS ) == NULL ) if( FindLibPart( newname, wxEmptyString, ALIAS ) == NULL )
{ {
wxString message; wxString message;
message.Printf( _( "Component [%s] not found!" ), newname.GetData() ); message.Printf( _( "Component [%s] not found!" ), newname.GetData() );
...@@ -263,8 +263,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event ...@@ -263,8 +263,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
++i; ++i;
} }
EDA_LibComponentStruct* entry = FindLibPart( EDA_LibComponentStruct* entry =
m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName );
if( entry && entry->m_Options == ENTRY_POWER ) if( entry && entry->m_Options == ENTRY_POWER )
m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName; m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName;
...@@ -411,7 +411,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent ...@@ -411,7 +411,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent
{ {
m_Cmp = aComponent; m_Cmp = aComponent;
m_LibEntry = FindLibPart( m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); m_LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName );
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
for( int i = 0; i<aComponent->GetFieldCount(); ++i ) for( int i = 0; i<aComponent->GetFieldCount(); ++i )
...@@ -705,7 +705,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) ...@@ -705,7 +705,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
if( m_Cmp == NULL ) if( m_Cmp == NULL )
return; return;
entry = FindLibPart( m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); entry = ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName );
if( entry == NULL ) if( entry == NULL )
return; return;
......
...@@ -452,7 +452,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit ) ...@@ -452,7 +452,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
{ {
for( ii = OldNumUnits + 1; ii <= MaxUnit; ii++ ) for( ii = OldNumUnits + 1; ii <= MaxUnit; ii++ )
{ {
NextDrawItem = CopyDrawEntryStruct( this, DrawItem ); NextDrawItem = CopyDrawEntryStruct( DrawItem );
NextDrawItem->SetNext( CurrentLibEntry->m_Drawings ); NextDrawItem->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = NextDrawItem; CurrentLibEntry->m_Drawings = NextDrawItem;
NextDrawItem->m_Unit = ii; NextDrawItem->m_Unit = ii;
...@@ -499,7 +499,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() ...@@ -499,7 +499,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
g_AsDeMorgan = 0; return FALSE; g_AsDeMorgan = 0; return FALSE;
} }
} }
NextDrawItem = CopyDrawEntryStruct( this, DrawItem ); NextDrawItem = CopyDrawEntryStruct( DrawItem );
NextDrawItem->SetNext( CurrentLibEntry->m_Drawings ); NextDrawItem->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = NextDrawItem; CurrentLibEntry->m_Drawings = NextDrawItem;
NextDrawItem->m_Convert = 2; NextDrawItem->m_Convert = 2;
......
...@@ -68,7 +68,8 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC ) ...@@ -68,7 +68,8 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC )
m_Multiflag = 0; m_Multiflag = 0;
if( aField->m_FieldId == REFERENCE ) if( aField->m_FieldId == REFERENCE )
{ {
Entry = FindLibPart( comp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( comp->m_ChipName );
if( Entry != NULL ) if( Entry != NULL )
{ {
if( Entry->m_UnitCount > 1 ) if( Entry->m_UnitCount > 1 )
...@@ -103,7 +104,8 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC ) ...@@ -103,7 +104,8 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC )
fieldNdx = Field->m_FieldId; fieldNdx = Field->m_FieldId;
if( fieldNdx == VALUE ) if( fieldNdx == VALUE )
{ {
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry && (Entry->m_Options == ENTRY_POWER) ) if( Entry && (Entry->m_Options == ENTRY_POWER) )
{ {
DisplayInfoMessage( this, DisplayInfoMessage( this,
...@@ -117,7 +119,8 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC ) ...@@ -117,7 +119,8 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC )
flag = 0; flag = 0;
if( fieldNdx == REFERENCE ) if( fieldNdx == REFERENCE )
{ {
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry != NULL ) if( Entry != NULL )
{ {
if( Entry->m_UnitCount > 1 ) if( Entry->m_UnitCount > 1 )
...@@ -259,8 +262,8 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC ) ...@@ -259,8 +262,8 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC )
flag = 0; flag = 0;
if( fieldNdx == REFERENCE ) if( fieldNdx == REFERENCE )
{ {
Entry = FindLibPart( ( (SCH_COMPONENT*) Field->GetParent() )->m_ChipName.GetData(), Entry = ( EDA_LibComponentStruct* ) FindLibPart( ( (SCH_COMPONENT*) Field->GetParent() )->m_ChipName );
wxEmptyString, FIND_ROOT );
if( Entry != NULL ) if( Entry != NULL )
{ {
if( Entry->m_UnitCount > 1 ) if( Entry->m_UnitCount > 1 )
...@@ -296,7 +299,8 @@ void WinEDA_SchematicFrame::EditComponentReference( SCH_COMPONENT* Cmp, wxDC* DC ...@@ -296,7 +299,8 @@ void WinEDA_SchematicFrame::EditComponentReference( SCH_COMPONENT* Cmp, wxDC* DC
if( Cmp == NULL ) if( Cmp == NULL )
return; return;
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
return; return;
...@@ -335,7 +339,8 @@ void WinEDA_SchematicFrame::EditComponentValue( SCH_COMPONENT* Cmp, wxDC* DC ) ...@@ -335,7 +339,8 @@ void WinEDA_SchematicFrame::EditComponentValue( SCH_COMPONENT* Cmp, wxDC* DC )
if( Cmp == NULL ) if( Cmp == NULL )
return; return;
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
return; return;
...@@ -373,7 +378,8 @@ void WinEDA_SchematicFrame::EditComponentFootprint( SCH_COMPONENT* Cmp, wxDC* DC ...@@ -373,7 +378,8 @@ void WinEDA_SchematicFrame::EditComponentFootprint( SCH_COMPONENT* Cmp, wxDC* DC
if( Cmp == NULL ) if( Cmp == NULL )
return; return;
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
return; return;
......
...@@ -164,23 +164,12 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -164,23 +164,12 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC,
* Alias = FIND_ROOT, ou Alias = FIND_ALIAS * Alias = FIND_ROOT, ou Alias = FIND_ALIAS
*/ */
/*****************************************************************************/ /*****************************************************************************/
EDA_LibComponentStruct* FindLibPart( const wxChar* Name, LibCmpEntry* FindLibPart( const wxChar* Name, const wxString& LibName,
const wxString& LibName, LibrEntryType type )
int Alias )
{ {
EDA_LibComponentStruct* Entry; LibCmpEntry* Entry = NULL;
/* Used only to call PQFind. */
static EDA_LibComponentStruct DummyEntry( wxEmptyString );
LibraryStruct* Lib = g_LibraryList; LibraryStruct* Lib = g_LibraryList;
DummyEntry.m_Drawings = NULL; /* Used only to call PQFind. */
DummyEntry.m_Name.m_Text = Name;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
Entry = NULL;
FindLibName.Empty(); FindLibName.Empty();
while( Lib ) while( Lib )
...@@ -197,7 +186,8 @@ EDA_LibComponentStruct* FindLibPart( const wxChar* Name, ...@@ -197,7 +186,8 @@ EDA_LibComponentStruct* FindLibPart( const wxChar* Name,
if( Lib == NULL ) if( Lib == NULL )
break; break;
Entry = (EDA_LibComponentStruct*) PQFind( Lib->m_Entries, &DummyEntry ); Entry = Lib->FindEntry( Name, type );
if( Entry != NULL ) if( Entry != NULL )
{ {
FindLibName = Lib->m_Name; FindLibName = Lib->m_Name;
...@@ -207,15 +197,6 @@ EDA_LibComponentStruct* FindLibPart( const wxChar* Name, ...@@ -207,15 +197,6 @@ EDA_LibComponentStruct* FindLibPart( const wxChar* Name,
Lib = Lib->m_Pnext; Lib = Lib->m_Pnext;
} }
/* Si le nom est un alias, recherche du vrai composant */
if( Entry )
{
if( (Entry->Type != ROOT ) && (Alias == FIND_ROOT) )
Entry = FindLibPart(
( (EDA_LibCmpAliasStruct*) Entry )->m_RootName.GetData(),
Lib->m_Name, FIND_ROOT );
}
return Entry; return Entry;
} }
......
...@@ -17,14 +17,6 @@ ...@@ -17,14 +17,6 @@
#include "dialog_load_error.h" #include "dialog_load_error.h"
/* Local Functions */
static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts );
// If this code was written in C++ then this would not be needed.
static wxString currentLibraryName;
/****************************************************************************/ /****************************************************************************/
...@@ -39,40 +31,24 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame, ...@@ -39,40 +31,24 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame,
const wxString& FullLibName, const wxString& FullLibName,
const wxString& LibName ) const wxString& LibName )
{ {
int NumOfParts;
FILE* f;
LibraryStruct* NewLib; LibraryStruct* NewLib;
PriorQue* Entries;
wxFileName fn; wxFileName fn;
wxString errMsg;
if( ( NewLib = FindLibrary( LibName ) ) != NULL ) if( ( NewLib = FindLibrary( LibName ) ) != NULL )
{ {
if( NewLib->m_FullFileName == FullLibName ) if( NewLib->m_FullFileName == FullLibName )
return NewLib; return NewLib;
FreeCmpLibrary( frame, LibName );
}
NewLib = NULL; delete NewLib;
f = wxFopen( FullLibName, wxT( "rt" ) );
if( f == NULL )
{
wxString msg;
msg.Printf( _( "Library <%s> not found" ), FullLibName.GetData() );
DisplayError( frame, msg );
return NULL;
} }
currentLibraryName = FullLibName;
NewLib = new LibraryStruct( LIBRARY_TYPE_EESCHEMA, LibName, FullLibName ); NewLib = new LibraryStruct( LIBRARY_TYPE_EESCHEMA, LibName, FullLibName );
Entries = LoadLibraryAux( frame, NewLib, f, &NumOfParts ); wxBusyCursor ShowWait;
if( Entries != NULL )
{
NewLib->m_Entries = Entries;
NewLib->m_NumOfParts = NumOfParts;
if( NewLib->Load( errMsg ) )
{
if( g_LibraryList == NULL ) if( g_LibraryList == NULL )
g_LibraryList = NewLib; g_LibraryList = NewLib;
else else
...@@ -90,9 +66,15 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame, ...@@ -90,9 +66,15 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame,
} }
else else
{ {
wxString msg;
msg.Printf( _( "Error <%s> occurred attempting to load component \
library <%s>" ),
( const wxChar* ) errMsg,
( const wxChar* ) FullLibName );
DisplayError( frame, msg );
SAFE_DELETE( NewLib ); SAFE_DELETE( NewLib );
} }
fclose( f );
return NewLib; return NewLib;
} }
...@@ -276,84 +258,6 @@ int LibraryEntryCompare( EDA_LibComponentStruct* LE1, ...@@ -276,84 +258,6 @@ int LibraryEntryCompare( EDA_LibComponentStruct* LE1,
} }
/**************************************************/
/* Routine to load a library from given open file */
/**************************************************/
PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
FILE* libfile, int* NumOfParts )
{
int LineNum = 0;
char Line[1024];
PriorQue* PQ = NULL;
EDA_LibComponentStruct* LibEntry;
wxString msg;
wxBusyCursor ShowWait; // Display a Busy Cursor..
*NumOfParts = 0;
if( GetLine( libfile, Line, &LineNum, sizeof(Line) ) == NULL )
{
msg.Printf( _( "File <%s> is empty!" ),
(const wxChar*) Library->m_Name );
DisplayError( frame, msg );
return NULL;
}
if( strnicmp( Line, LIBFILE_IDENT, 10 ) != 0 )
{
msg.Printf( _( "File <%s> is NOT an EESCHEMA library!" ),
(const wxChar*) Library->m_Name );
DisplayError( frame, msg );
return NULL;
}
if( Library )
Library->m_Header = CONV_FROM_UTF8( Line );
PQInit( &PQ );
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
while( GetLine( libfile, Line, &LineNum, sizeof(Line) ) )
{
if( strnicmp( Line, "$HEADER", 7 ) == 0 )
{
if( Library && !Library->ReadHeader( libfile, &LineNum ) )
{
msg.Printf( _( "Library <%s> header read error" ),
(const wxChar*) Library->m_Name );
DisplayError( frame, msg, 30 );
}
continue;
}
if( strnicmp( Line, "DEF", 3 ) == 0 )
{
/* Read one DEF/ENDDEF part entry from library: */
LibEntry = new EDA_LibComponentStruct( NULL );
if( LibEntry->Load( libfile, Line, &LineNum, msg ) )
{
/* If we are here, this part is O.k. - put it in: */
++*NumOfParts;
PQInsert( &PQ, LibEntry );
InsertAlias( &PQ, LibEntry, NumOfParts );
}
else
{
wxLogWarning( _( "Library <%s> component load error %s." ),
(const wxChar*) Library->m_Name,
(const wxChar*) msg );
msg.Clear();
delete LibEntry;
}
}
}
return PQ;
}
/***************************************************************************** /*****************************************************************************
* Routine to find the library given its name. * * Routine to find the library given its name. *
*****************************************************************************/ *****************************************************************************/
...@@ -363,7 +267,7 @@ LibraryStruct* FindLibrary( const wxString& Name ) ...@@ -363,7 +267,7 @@ LibraryStruct* FindLibrary( const wxString& Name )
while( Lib ) while( Lib )
{ {
if( Lib->m_Name == Name ) if( *Lib == Name )
return Lib; return Lib;
Lib = Lib->m_Pnext; Lib = Lib->m_Pnext;
} }
...@@ -387,27 +291,6 @@ int NumOfLibraries() ...@@ -387,27 +291,6 @@ int NumOfLibraries()
} }
/********************************************************************/
/* create in library (in list PQ) aliases of the "root" component LibEntry*/
/********************************************************************/
static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts )
{
EDA_LibCmpAliasStruct* AliasEntry;
unsigned ii;
for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ )
{
AliasEntry =
new EDA_LibCmpAliasStruct( LibEntry->m_AliasList[ii],
LibEntry->m_Name.m_Text.GetData() );
++*NumOfParts;
PQInsert( PQ, AliasEntry );
}
}
/*******************************************************/ /*******************************************************/
/* Routines de lecture des Documentation de composants */ /* Routines de lecture des Documentation de composants */
/*******************************************************/ /*******************************************************/
...@@ -418,7 +301,7 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName, ...@@ -418,7 +301,7 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
{ {
int LineNum = 0; int LineNum = 0;
char Line[1024], * Name, * Text; char Line[1024], * Name, * Text;
EDA_LibComponentStruct* Entry; LibCmpEntry* Entry;
FILE* f; FILE* f;
wxString msg; wxString msg;
...@@ -455,7 +338,8 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName, ...@@ -455,7 +338,8 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
Name = strtok( Line + 5, "\n\r" ); Name = strtok( Line + 5, "\n\r" );
wxString cmpname; wxString cmpname;
cmpname = CONV_FROM_UTF8( Name ); cmpname = CONV_FROM_UTF8( Name );
Entry = FindLibPart( cmpname.GetData(), Libname, FIND_ALIAS ); Entry = FindLibPart( cmpname, Libname, ALIAS );
while( GetLine( f, Line, &LineNum, sizeof(Line) ) ) while( GetLine( f, Line, &LineNum, sizeof(Line) ) )
{ {
if( strncmp( Line, "$ENDCMP", 7 ) == 0 ) if( strncmp( Line, "$ENDCMP", 7 ) == 0 )
......
...@@ -259,8 +259,8 @@ void DrawStructsInGhost( WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem ...@@ -259,8 +259,8 @@ void DrawStructsInGhost( WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem
EDA_LibComponentStruct* LibEntry; EDA_LibComponentStruct* LibEntry;
SCH_COMPONENT* Struct; SCH_COMPONENT* Struct;
Struct = (SCH_COMPONENT*) aItem; Struct = (SCH_COMPONENT*) aItem;
LibEntry = FindLibPart( Struct->m_ChipName.GetData(), wxEmptyString, LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Struct->m_ChipName );
FIND_ROOT );
if( LibEntry == NULL ) if( LibEntry == NULL )
break; break;
DrawingLibInGhost( aPanel, aDC, LibEntry, Struct, Struct->m_Pos.x + aOffset.x, DrawingLibInGhost( aPanel, aDC, LibEntry, Struct, Struct->m_Pos.x + aOffset.x,
......
...@@ -624,51 +624,54 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem( ...@@ -624,51 +624,54 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem(
} }
/*************************************************************/ /*
void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) * Search for a given component.
/*************************************************************/ *
* The search is made in loaded libraries, and if not found in all libraries
/* Search for a given component. * found in lib paths.
* The serach is made in loaded libraries,
* and if not found in all libraries found in lib paths.
*/ */
void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
{ {
wxString Text, FindList; wxArrayString nameList;
EDA_LibComponentStruct* LibEntry; wxString Text, FindList;
bool FoundInLib = FALSE; // True si reference trouvee ailleurs qu'en cache bool FoundInLib = false;
Text = m_NewTextCtrl->GetValue(); Text = m_NewTextCtrl->GetValue();
if( Text.IsEmpty() ) if( Text.IsEmpty() )
{ {
Close(); return; Close();
return;
} }
s_OldStringFound = Text; s_OldStringFound = Text;
if( NumOfLibraries() == 0 ) if( NumOfLibraries() == 0 )
{ {
DisplayError( this, _( "No libraries are loaded" ) ); DisplayError( this, _( "No libraries are loaded" ) );
Close(); return; Close();
return;
} }
int nbitemsFound = 0; int nbitemsFound = 0;
for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{ {
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE ); Lib->SearchEntryNames( nameList, Text );
while( LibEntry )
if( nameList.IsEmpty() )
continue;
nbitemsFound += nameList.GetCount();
if( !Lib->m_IsLibCache )
FoundInLib = true;
for( size_t i = 0; i < nameList.GetCount(); i++ )
{ {
if( WildCompareString( Text, LibEntry->m_Name.m_Text, FALSE ) ) if( !FindList.IsEmpty() )
{ FindList += wxT( "\n" );
nbitemsFound++; FindList << _( "Found " ) + nameList[i] + _( " in library " )
if( !Lib->m_IsLibCache ) + Lib->m_Name;
FoundInLib = TRUE;
if( !FindList.IsEmpty() )
FindList += wxT( "\n" );
FindList << _( "Found " )
+ LibEntry->m_Name.m_Text
+ _( " in lib " ) + Lib->m_Name;
}
LibEntry = (EDA_LibComponentStruct*) PQNext( Lib->m_Entries, LibEntry, NULL );
} }
} }
...@@ -690,7 +693,9 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) ...@@ -690,7 +693,9 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
} }
} }
else else
{
DisplayInfoMessage( this, FindList ); DisplayInfoMessage( this, FindList );
}
Close(); Close();
} }
......
...@@ -83,7 +83,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, ...@@ -83,7 +83,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
Library = g_LibraryList; Library = g_LibraryList;
while( Library ) while( Library )
{ {
if( Library->m_Name == libname ) if( Library->GetName().CmpNoCase( libname ) == 0 )
{ {
CmpCount = Library->m_NumOfParts; CmpCount = Library->m_NumOfParts;
break; break;
...@@ -118,7 +118,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, ...@@ -118,7 +118,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
{ {
AllowWildSeach = FALSE; AllowWildSeach = FALSE;
keys = Name.AfterFirst( '=' ); keys = Name.AfterFirst( '=' );
if( DataBaseGetName( this, keys, Name ) == 0 ) Name = DataBaseGetName( this, keys, Name );
if( Name.IsEmpty() )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = FALSE;
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
...@@ -138,7 +139,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, ...@@ -138,7 +139,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) ) else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) )
{ {
AllowWildSeach = FALSE; AllowWildSeach = FALSE;
if( DataBaseGetName( this, keys, Name ) == 0 ) Name = DataBaseGetName( this, keys, Name );
if( Name.IsEmpty() )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = FALSE;
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
...@@ -146,14 +148,18 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, ...@@ -146,14 +148,18 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
} }
} }
Entry = FindLibPart( Name.GetData(), libname, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Name, libname );
if( (Entry == NULL) && AllowWildSeach ) /* Attemp to search with wildcard */ if( (Entry == NULL) && AllowWildSeach ) /* Attemp to search with wildcard */
{ {
AllowWildSeach = FALSE; AllowWildSeach = FALSE;
wxString wildname = wxChar( '*' ) + Name + wxChar( '*' ); wxString wildname = wxChar( '*' ) + Name + wxChar( '*' );
Name = wildname; Name = wildname;
if( DataBaseGetName( this, keys, Name ) ) Name = DataBaseGetName( this, keys, Name );
Entry = FindLibPart( Name.GetData(), libname, FIND_ROOT );
if( !Name.IsEmpty() )
Entry = ( EDA_LibComponentStruct* ) FindLibPart( Name, libname );
if( Entry == NULL ) if( Entry == NULL )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = FALSE;
...@@ -352,8 +358,8 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent, ...@@ -352,8 +358,8 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
if( DrawComponent == NULL ) if( DrawComponent == NULL )
return; return;
LibEntry = FindLibPart( LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( DrawComponent->m_ChipName );
DrawComponent->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
if( LibEntry == NULL ) if( LibEntry == NULL )
return; return;
...@@ -401,8 +407,8 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent, ...@@ -401,8 +407,8 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
if( DrawComponent == NULL ) if( DrawComponent == NULL )
return; return;
LibEntry = FindLibPart( LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( DrawComponent->m_ChipName );
DrawComponent->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
if( LibEntry == NULL ) if( LibEntry == NULL )
return; return;
......
...@@ -37,10 +37,10 @@ extern int ExportPartId; ...@@ -37,10 +37,10 @@ extern int ExportPartId;
/*************************************************/ /*************************************************/
void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event ) void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event )
{ {
wxFileName fn; wxFileName fn;
LibraryStruct* LibTmp; LibraryStruct* LibTmp;
EDA_LibComponentStruct* LibEntry; LibCmpEntry* LibEntry;
int err = 1; bool entryLoaded;
LibItemToRepeat = NULL; LibItemToRepeat = NULL;
...@@ -58,14 +58,13 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event ) ...@@ -58,14 +58,13 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event )
if( g_LibraryList ) if( g_LibraryList )
{ {
LibEntry = (EDA_LibComponentStruct*) PQFirst( &g_LibraryList->m_Entries, LibEntry = g_LibraryList->GetFirstEntry();
false );
if( LibEntry ) if( LibEntry )
err = LoadOneLibraryPartAux( LibEntry, g_LibraryList, 1 ); entryLoaded = LoadOneLibraryPartAux( LibEntry, g_LibraryList );
FreeCmpLibrary( this, g_LibraryList->m_Name ); FreeCmpLibrary( this, g_LibraryList->m_Name );
if( err == 0 ) if( entryLoaded )
{ {
fn = dlg.GetPath(); fn = dlg.GetPath();
m_LastLibImportPath = fn.GetPath(); m_LastLibImportPath = fn.GetPath();
...@@ -75,7 +74,7 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event ) ...@@ -75,7 +74,7 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event )
DrawPanel->Refresh(); DrawPanel->Refresh();
} }
else else
DisplayError( this, _( "File is empty" ), 30 ); DisplayError( this, _( "File is empty" ) );
} }
g_LibraryList = LibTmp; g_LibraryList = LibTmp;
......
...@@ -36,19 +36,15 @@ bool BuildAliasData( LibraryStruct* Lib, EDA_LibComponentStruct* component ) ...@@ -36,19 +36,15 @@ bool BuildAliasData( LibraryStruct* Lib, EDA_LibComponentStruct* component )
LibCmpEntry* CmpEntry; LibCmpEntry* CmpEntry;
unsigned ii; unsigned ii;
if( component == NULL ) if( component == NULL || Lib == NULL
return FALSE; || component->m_AliasList.GetCount() == 0 )
if( Lib == NULL ) return false;
return FALSE;
if( component->m_AliasList.GetCount() == 0 )
return FALSE;
List = component->m_AliasList; List = component->m_AliasList;
component->m_AliasList.Clear(); component->m_AliasList.Clear();
for( ii = 0; ii < List.GetCount(); ii++ ) for( ii = 0; ii < List.GetCount(); ii++ )
{ {
CmpEntry = (LibCmpEntry*) FindLibPart( List[ii].GetData(), CmpEntry = FindLibPart( List[ii], Lib->m_Name, ALIAS );
Lib->m_Name, FIND_ALIAS );
if( CmpEntry && CmpEntry->Type != ALIAS ) if( CmpEntry && CmpEntry->Type != ALIAS )
{ {
DisplayError( NULL, DisplayError( NULL,
......
...@@ -52,7 +52,8 @@ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ) ...@@ -52,7 +52,8 @@ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName )
continue; continue;
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) SchItem; SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) SchItem;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry ) // if NULL : component not found if( Entry ) // if NULL : component not found
ListEntry.push_back( Entry ); ListEntry.push_back( Entry );
} }
......
...@@ -34,11 +34,6 @@ enum LocateDrawStructType { ...@@ -34,11 +34,6 @@ enum LocateDrawStructType {
#define LOCATE_ALL_DRAW_ITEM 0xFFFFFFFF #define LOCATE_ALL_DRAW_ITEM 0xFFFFFFFF
/* flags utilises dans FindLibPart() : */
#define FIND_ROOT 0 /* Used to search for a root component by its name
* if the name is an alias name, FindLibPart() returns the root component */
#define FIND_ALIAS 1 /* Used to search for a component by its name
* FindLibPart() returns the component (root or alias ) */
#include "class_library.h" #include "class_library.h"
......
This diff is collapsed.
...@@ -23,7 +23,10 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, ...@@ -23,7 +23,10 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy,
EDA_LibComponentStruct* CopyItem; EDA_LibComponentStruct* CopyItem;
PICKED_ITEMS_LIST* lastcmd; PICKED_ITEMS_LIST* lastcmd;
CopyItem = CopyLibEntryStruct( this, (EDA_LibComponentStruct*) ItemToCopy ); CopyItem = CopyLibEntryStruct( (EDA_LibComponentStruct*) ItemToCopy );
if( CopyItem == NULL )
return;
lastcmd = new PICKED_ITEMS_LIST(); lastcmd = new PICKED_ITEMS_LIST();
ITEM_PICKER wrapper(CopyItem, UR_LIBEDIT); ITEM_PICKER wrapper(CopyItem, UR_LIBEDIT);
......
...@@ -722,7 +722,8 @@ LibDrawPin* LocatePinByNumber( const wxString& ePin_Number, ...@@ -722,7 +722,8 @@ LibDrawPin* LocatePinByNumber( const wxString& ePin_Number,
LibDrawPin* Pin; LibDrawPin* Pin;
int Unit, Convert; int Unit, Convert;
Entry = FindLibPart( eComponent->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* )FindLibPart( eComponent->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
return NULL; return NULL;
...@@ -858,7 +859,8 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, ...@@ -858,7 +859,8 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos,
if( DrawStruct->Type() != TYPE_SCH_COMPONENT ) if( DrawStruct->Type() != TYPE_SCH_COMPONENT )
continue; continue;
LibItem = (SCH_COMPONENT*) DrawStruct; LibItem = (SCH_COMPONENT*) DrawStruct;
Entry = FindLibPart( LibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( LibItem->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
continue; continue;
Pin = (LibDrawPin*) LocatePin( RefPos, Entry, LibItem->m_Multi, Pin = (LibDrawPin*) LocatePin( RefPos, Entry, LibItem->m_Multi,
......
...@@ -130,7 +130,8 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( ...@@ -130,7 +130,8 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
// removed because with multiple instances of one schematic // removed because with multiple instances of one schematic
// (several sheets pointing to 1 screen), this will be erroneously be toggled. // (several sheets pointing to 1 screen), this will be erroneously be toggled.
Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
continue; continue;
...@@ -549,9 +550,10 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with ...@@ -549,9 +550,10 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
break; break;
/* Get the Component FootprintFilter and put the component in CmpList if filter is not void */ /* Get the Component FootprintFilter and put the component in CmpList if filter is not void */
EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry =
if( ( Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName );
FIND_ROOT ) ) != NULL )
if( Entry != NULL )
{ {
if( Entry->m_FootprintList.GetCount() != 0 ) /* Put in list */ if( Entry->m_FootprintList.GetCount() != 0 ) /* Put in list */
{ {
...@@ -630,7 +632,7 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with ...@@ -630,7 +632,7 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
for( int ii = 0; ii < CmpListCount; ii++ ) for( int ii = 0; ii < CmpListCount; ii++ )
{ {
Component = CmpList[ii].m_RootCmp; Component = CmpList[ii].m_RootCmp;
Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName );
//Line.Printf(_("%s"), CmpList[ii].m_Ref); //Line.Printf(_("%s"), CmpList[ii].m_Ref);
//Line.Replace( wxT( " " ), wxT( "_" ) ); //Line.Replace( wxT( " " ), wxT( "_" ) );
......
...@@ -472,7 +472,8 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, ...@@ -472,7 +472,8 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist,
case TYPE_SCH_COMPONENT: case TYPE_SCH_COMPONENT:
DrawLibItem = (SCH_COMPONENT*) DrawList; DrawLibItem = (SCH_COMPONENT*) DrawList;
Entry = FindLibPart( DrawLibItem->m_ChipName, wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* )FindLibPart(
DrawLibItem->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
break; break;
......
...@@ -251,7 +251,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) ...@@ -251,7 +251,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
EDA_LibComponentStruct* LibEntry; EDA_LibComponentStruct* LibEntry;
LibEntry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName );
if( !Component->m_Flags ) if( !Component->m_Flags )
{ {
...@@ -323,7 +323,8 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) ...@@ -323,7 +323,8 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CMP, _( "Delete Component" ), delete_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CMP, _( "Delete Component" ), delete_xpm );
} }
LibEntry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ALIAS ); LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName,
wxEmptyString, ALIAS );
if( LibEntry && !LibEntry->m_DocFile.IsEmpty() ) if( LibEntry && !LibEntry->m_DocFile.IsEmpty() )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), datasheet_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), datasheet_xpm );
} }
......
...@@ -57,7 +57,7 @@ static void PlotLibPart( Plotter* plotter, SCH_COMPONENT* DrawLibItem ) ...@@ -57,7 +57,7 @@ static void PlotLibPart( Plotter* plotter, SCH_COMPONENT* DrawLibItem )
wxPoint pos; wxPoint pos;
bool draw_bgfill = false; bool draw_bgfill = false;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry == NULL ) if( Entry == NULL )
return;; return;;
memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) ); memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
......
This diff is collapsed.
...@@ -28,11 +28,10 @@ ...@@ -28,11 +28,10 @@
* A better way to duplicate a DrawLibItem is to have a virtual GenCopy() in * A better way to duplicate a DrawLibItem is to have a virtual GenCopy() in
* LibEDA_BaseStruct class (ToDo). * LibEDA_BaseStruct class (ToDo).
*/ */
LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame, LibEDA_BaseStruct* CopyDrawEntryStruct( LibEDA_BaseStruct* DrawItem )
LibEDA_BaseStruct* DrawItem )
{ {
LibEDA_BaseStruct* NewDrawItem = NULL;
wxString msg; wxString msg;
LibEDA_BaseStruct* NewDrawItem = NULL;
switch( DrawItem->Type() ) switch( DrawItem->Type() )
{ {
...@@ -67,7 +66,7 @@ LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame, ...@@ -67,7 +66,7 @@ LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame,
default: default:
msg.Printf( wxT( "CopyDrawLibEntryStruct: unknown Draw Type %d" ), msg.Printf( wxT( "CopyDrawLibEntryStruct: unknown Draw Type %d" ),
DrawItem->Type() ); DrawItem->Type() );
DisplayError( frame, msg ); wxLogError( msg );
break; break;
} }
...@@ -81,9 +80,9 @@ LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame, ...@@ -81,9 +80,9 @@ LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame,
* Parametres de sortie: pointeur sur la structure creee * Parametres de sortie: pointeur sur la structure creee
* Do not copy new items ( i.e. with m_Flag & IS_NEW) * Do not copy new items ( i.e. with m_Flag & IS_NEW)
*/ */
EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame, EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry )
EDA_LibComponentStruct* OldEntry )
{ {
wxString msg;
EDA_LibComponentStruct* NewStruct; EDA_LibComponentStruct* NewStruct;
LibEDA_BaseStruct* NewDrawings, * OldDrawings; LibEDA_BaseStruct* NewDrawings, * OldDrawings;
LibEDA_BaseStruct* LastItem; LibEDA_BaseStruct* LastItem;
...@@ -91,7 +90,9 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame, ...@@ -91,7 +90,9 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
if( OldEntry->Type != ROOT ) if( OldEntry->Type != ROOT )
{ {
DisplayError( frame, wxT( "CopyLibEntryStruct(): Type != ROOT" ) ); msg.Printf( wxT( "Component <%s> must be root type to make copy." ),
(const wxChar*) OldEntry->m_Name.m_Text );
wxLogError( msg );
return NULL; return NULL;
} }
...@@ -126,10 +127,10 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame, ...@@ -126,10 +127,10 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
for( OldDrawings = OldEntry->m_Drawings; OldDrawings != NULL; for( OldDrawings = OldEntry->m_Drawings; OldDrawings != NULL;
OldDrawings = OldDrawings->Next() ) OldDrawings = OldDrawings->Next() )
{ {
if( ( OldDrawings->m_Flags & IS_NEW) != 0 ) if( ( OldDrawings->m_Flags & IS_NEW ) != 0 )
continue; continue;
NewDrawings = CopyDrawEntryStruct( frame, OldDrawings ); NewDrawings = CopyDrawEntryStruct( OldDrawings );
if( NewDrawings ) if( NewDrawings )
{ {
if( LastItem == NULL ) if( LastItem == NULL )
...@@ -140,11 +141,15 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame, ...@@ -140,11 +141,15 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
LastItem = NewDrawings; LastItem = NewDrawings;
NewDrawings->SetNext( NULL ); NewDrawings->SetNext( NULL );
} }
else // Should nevers occurs, just in case... else // Should never occur, just in case...
{ // CopyDrawEntryStruct() was not able to duplicate the type { // CopyDrawEntryStruct() was not able to duplicate the type
// of OldDrawings // of OldDrawings
// occurs when an unexpected type is encountered // occurs when an unexpected type is encountered
DisplayError( frame, wxT( "CopyLibEntryStruct(): error: aborted" ) ); msg.Printf( wxT( "Error attempting to copy draw item <%s> from \
component <%s>." ),
(const wxChar*) OldDrawings->GetClass(),
(const wxChar*) OldEntry->m_Name.m_Text );
wxLogError( msg );
break; break;
} }
} }
......
...@@ -620,10 +620,10 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -620,10 +620,10 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event )
if( screen->GetCurItem() == NULL ) if( screen->GetCurItem() == NULL )
break; break;
{ {
EDA_LibComponentStruct* LibEntry; LibCmpEntry* LibEntry;
LibEntry = FindLibPart( LibEntry = FindLibPart(
( (SCH_COMPONENT*) screen->GetCurItem() )->m_ChipName.GetData(), ( (SCH_COMPONENT*) screen->GetCurItem() )->m_ChipName,
wxEmptyString, FIND_ALIAS ); wxEmptyString, ALIAS );
if( LibEntry && LibEntry->m_DocFile != wxEmptyString ) if( LibEntry && LibEntry->m_DocFile != wxEmptyString )
{ {
GetAssociatedDocument( this, LibEntry->m_DocFile , GetAssociatedDocument( this, LibEntry->m_DocFile ,
......
...@@ -72,16 +72,14 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame ) ...@@ -72,16 +72,14 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame )
} }
/******************************************************************************************/
int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame, int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
LibraryStruct* Library, wxString& Buffer, wxString& OldName ) LibraryStruct* Library,
/******************************************************************************************/ wxString& Buffer, wxString& OldName )
{ {
int ii; size_t i;
wxString msg; wxString msg;
EDA_LibComponentStruct* LibEntry; wxArrayString nameList;
WinEDAListBox* ListBox; const wxChar** ListNames;
const wxChar** ListNames;
if( Library == NULL ) if( Library == NULL )
Library = SelectLibraryFromList( frame ); Library = SelectLibraryFromList( frame );
...@@ -89,44 +87,32 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame, ...@@ -89,44 +87,32 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
if( Library == NULL ) if( Library == NULL )
return 0; return 0;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare ); Library->GetEntryNames( nameList );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE );
ii = 0; ListNames = (const wxChar**) MyZMalloc( ( nameList.GetCount() + 1 ) *
while( LibEntry ) sizeof( wxChar* ) );
{
ii++;
LibEntry = (EDA_LibComponentStruct*) PQNext( Library->m_Entries, LibEntry, NULL );
}
ListNames = (const wxChar**) MyZMalloc( (ii + 1) * sizeof(wxChar*) );
msg.Printf( _( "Select component (%d items)" ), ii ); msg.Printf( _( "Select 1 of %d components from library <%s>" ),
nameList.GetCount(), (const wxChar*) Library->m_Name );
ii = 0; for( i = 0; i < nameList.GetCount(); i++ )
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE ); ListNames[i] = (const wxChar*) nameList[i];
while( LibEntry )
{
ListNames[ii++] = LibEntry->m_Name.m_Text.GetData();
LibEntry = (EDA_LibComponentStruct*) PQNext( Library->m_Entries, LibEntry, NULL );
}
// Qsort(ListNames,StrNumICmp); WinEDAListBox dlg( frame, msg, ListNames, OldName, DisplayCmpDoc,
wxColour( 255, 255, 255 ) );
ListBox = new WinEDAListBox( frame, msg, dlg.MoveMouseToOrigin();
ListNames, OldName, DisplayCmpDoc,
wxColour( 255, 255, 255 ) ); // Component background listbox color
ListBox->MoveMouseToOrigin(); int rsp = dlg.ShowModal();
ii = ListBox->ShowModal(); ListBox->Destroy(); if( rsp >= 0 )
if( ii >= 0 ) Buffer = ListNames[rsp];
Buffer = ListNames[ii];
free( ListNames ); free( ListNames );
if( ii < 0 ) if( rsp < 0 )
return 0; return 0;
return 1; return 1;
} }
......
This diff is collapsed.
...@@ -28,14 +28,16 @@ void WinEDA_ViewlibFrame::ReCreateHToolbar() ...@@ -28,14 +28,16 @@ void WinEDA_ViewlibFrame::ReCreateHToolbar()
if( (g_CurrentViewLibraryName != wxEmptyString) if( (g_CurrentViewLibraryName != wxEmptyString)
&& (g_CurrentViewComponentName != wxEmptyString) ) && (g_CurrentViewComponentName != wxEmptyString) )
{ {
RootLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(), RootLibEntry =
g_CurrentViewLibraryName.GetData(), ( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
FIND_ROOT ); g_CurrentViewLibraryName );
if( RootLibEntry && LookForConvertPart( RootLibEntry ) > 1 ) if( RootLibEntry && LookForConvertPart( RootLibEntry ) > 1 )
asdeMorgan = TRUE; asdeMorgan = TRUE;
CurrentLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(), CurrentLibEntry =
g_CurrentViewLibraryName.GetData(), ( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
FIND_ALIAS ); g_CurrentViewLibraryName,
ALIAS );
} }
if( m_HToolBar == NULL ) if( m_HToolBar == NULL )
......
...@@ -273,8 +273,9 @@ int WinEDA_ViewlibFrame::BestZoom() ...@@ -273,8 +273,9 @@ int WinEDA_ViewlibFrame::BestZoom()
wxSize size, itemsize; wxSize size, itemsize;
EDA_LibComponentStruct* CurrentLibEntry = NULL; EDA_LibComponentStruct* CurrentLibEntry = NULL;
CurrentLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(), CurrentLibEntry =
g_CurrentViewLibraryName.GetData(), FIND_ROOT ); ( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName );
if( CurrentLibEntry == NULL ) if( CurrentLibEntry == NULL )
{ {
...@@ -314,7 +315,7 @@ void WinEDA_ViewlibFrame::ReCreateListLib() ...@@ -314,7 +315,7 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
return; return;
m_LibList->Clear(); m_LibList->Clear();
wxArrayString libNamesList; wxArrayString libNamesList;
for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{ {
...@@ -323,13 +324,13 @@ void WinEDA_ViewlibFrame::ReCreateListLib() ...@@ -323,13 +324,13 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
else else
libNamesList.Add( Lib->m_Name ); libNamesList.Add( Lib->m_Name );
} }
libNamesList.Sort(); libNamesList.Sort();
// Add lib cache // Add lib cache
if ( libcache ) if ( libcache )
libNamesList.Add( libcache->m_Name ); libNamesList.Add( libcache->m_Name );
m_LibList->Append(libNamesList); m_LibList->Append(libNamesList);
// Search for a previous selection: // Search for a previous selection:
...@@ -358,29 +359,22 @@ void WinEDA_ViewlibFrame::ReCreateListLib() ...@@ -358,29 +359,22 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
} }
/***********************************************/
void WinEDA_ViewlibFrame::ReCreateListCmp() void WinEDA_ViewlibFrame::ReCreateListCmp()
/***********************************************/
{ {
if( m_CmpList == NULL ) if( m_CmpList == NULL )
return; return;
int ii; LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
EDA_LibComponentStruct* LibEntry = NULL; wxArrayString nameList;
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
m_CmpList->Clear(); m_CmpList->Clear();
ii = 0;
g_CurrentViewComponentName.Empty(); g_CurrentViewComponentName.Empty();
g_ViewConvert = 1; /* Select normal/"de morgan" shape */ g_ViewConvert = 1; /* Select normal/"de morgan" shape */
g_ViewUnit = 1; /* Selec unit to display for multiple parts per package */ g_ViewUnit = 1; /* Select unit to display for multiple
* parts per package */
if( Library ) if( Library )
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE ); Library->GetEntryNames( nameList );
while( LibEntry ) m_CmpList->Append( nameList );
{
m_CmpList->Append( LibEntry->m_Name.m_Text );
LibEntry = (EDA_LibComponentStruct*) PQNext( Library->m_Entries, LibEntry, NULL );
}
} }
......
...@@ -57,8 +57,10 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -57,8 +57,10 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_LIBVIEW_VIEWDOC: case ID_LIBVIEW_VIEWDOC:
LibEntry = FindLibPart( g_CurrentViewComponentName.GetData(), LibEntry =
g_CurrentViewLibraryName.GetData(), FIND_ALIAS ); ( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName,
ALIAS );
if( LibEntry && ( !LibEntry->m_DocFile.IsEmpty() ) ) if( LibEntry && ( !LibEntry->m_DocFile.IsEmpty() ) )
GetAssociatedDocument( this, LibEntry->m_DocFile, GetAssociatedDocument( this, LibEntry->m_DocFile,
& wxGetApp().GetLibraryPathList()); & wxGetApp().GetLibraryPathList());
...@@ -182,10 +184,9 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option ) ...@@ -182,10 +184,9 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option )
return; return;
} }
EDA_LibComponentStruct* LibEntry = FindLibPart( LibCmpEntry* LibEntry = FindLibPart( g_CurrentViewComponentName,
g_CurrentViewComponentName.GetData(), g_CurrentViewLibraryName,
g_CurrentViewLibraryName, ALIAS );
FIND_ALIAS );
if( LibEntry == NULL ) if( LibEntry == NULL )
return; return;
...@@ -203,10 +204,10 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option ) ...@@ -203,10 +204,10 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option )
/*************************************************/ /*************************************************/
void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag ) void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
{ {
int NumOfParts = 0; int NumOfParts = 0;
EDA_LibComponentStruct* LibEntry, * PreviousLibEntry; LibCmpEntry* LibEntry;
wxString CmpName; wxString CmpName;
wxClientDC dc( DrawPanel ); wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc ); DrawPanel->PrepareGraphicContext( &dc );
...@@ -223,9 +224,6 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag ) ...@@ -223,9 +224,6 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
if( Lib == NULL ) if( Lib == NULL )
return; return;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
if( Flag == NEW_PART ) if( Flag == NEW_PART )
{ {
DisplayComponentsNamesInLib( this, DisplayComponentsNamesInLib( this,
...@@ -236,54 +234,24 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag ) ...@@ -236,54 +234,24 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
if( Flag == NEXT_PART ) if( Flag == NEXT_PART )
{ {
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE ); LibEntry = Lib->GetNextEntry( g_CurrentViewComponentName );
while( LibEntry )
{
if( LibEntry->m_Name.m_Text == g_CurrentViewComponentName )
{
LibEntry = (EDA_LibComponentStruct*)
PQNext( Lib->m_Entries, LibEntry, NULL );
break;
}
LibEntry = (EDA_LibComponentStruct*)
PQNext( Lib->m_Entries, LibEntry, NULL );
}
if( LibEntry == NULL )
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries,
FALSE );
if( LibEntry ) if( LibEntry )
CmpName = LibEntry->m_Name.m_Text; CmpName = LibEntry->m_Name.m_Text;
} }
if( Flag == PREVIOUS_PART ) if( Flag == PREVIOUS_PART )
{ {
PreviousLibEntry = NULL; LibEntry = Lib->GetPreviousEntry( g_CurrentViewComponentName );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
while( LibEntry )
{
if( LibEntry->m_Name.m_Text == g_CurrentViewComponentName )
{
if( PreviousLibEntry )
break;
/* else : pointage sur 1er element : if( LibEntry )
* balayage de la liste et Previous pointera dernier element */ CmpName = LibEntry->m_Name.m_Text;
}
PreviousLibEntry = LibEntry;
LibEntry = (EDA_LibComponentStruct*)
PQNext( Lib->m_Entries, LibEntry, NULL );
}
if( PreviousLibEntry )
CmpName = PreviousLibEntry->m_Name.m_Text;
} }
g_ViewUnit = 1; g_ViewUnit = 1;
g_ViewConvert = 1; g_ViewConvert = 1;
LibEntry = FindLibPart( CmpName.GetData(), Lib->m_Name, FIND_ALIAS ); LibEntry = Lib->FindEntry( CmpName );
g_CurrentViewComponentName = CmpName; g_CurrentViewComponentName = CmpName;
DisplayLibInfos(); DisplayLibInfos();
Zoom_Automatique( FALSE ); Zoom_Automatique( FALSE );
...@@ -312,8 +280,10 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) ...@@ -312,8 +280,10 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
ActiveScreen = GetScreen(); ActiveScreen = GetScreen();
LibEntry = FindLibPart( g_CurrentViewComponentName.GetData(), LibEntry =
g_CurrentViewLibraryName, FIND_ALIAS ); ( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName,
ALIAS );
ViewCmpEntry = (LibCmpEntry*) LibEntry; ViewCmpEntry = (LibCmpEntry*) LibEntry;
/* Forcage de la reinit de la brosse et plume courante */ /* Forcage de la reinit de la brosse et plume courante */
...@@ -335,9 +305,10 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) ...@@ -335,9 +305,10 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName.GetData(); ( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName.GetData();
Msg.Printf( _( "Current Part: <%s> (is Alias of <%s>)" ), Msg.Printf( _( "Current Part: <%s> (is Alias of <%s>)" ),
CmpName, RootName ); CmpName, RootName );
LibEntry = FindLibPart( RootName, LibEntry =
g_CurrentViewLibraryName, ( EDA_LibComponentStruct* ) FindLibPart( RootName,
FIND_ROOT ); g_CurrentViewLibraryName,
ROOT );
if( LibEntry == NULL ) if( LibEntry == NULL )
{ {
......
...@@ -20,6 +20,7 @@ class SCH_ITEM; ...@@ -20,6 +20,7 @@ class SCH_ITEM;
class DrawNoConnectStruct; class DrawNoConnectStruct;
class LibraryStruct; class LibraryStruct;
class EDA_LibComponentStruct; class EDA_LibComponentStruct;
class LibCmpEntry;
class LibEDA_BaseStruct; class LibEDA_BaseStruct;
class EDA_BaseStruct; class EDA_BaseStruct;
class DrawBusEntryStruct; class DrawBusEntryStruct;
...@@ -507,9 +508,8 @@ private: ...@@ -507,9 +508,8 @@ private:
bool LoadOneLibraryPart(); bool LoadOneLibraryPart();
void SaveActiveLibrary(); void SaveActiveLibrary();
int LoadOneLibraryPartAux( EDA_LibComponentStruct* LibEntry, bool LoadOneLibraryPartAux( LibCmpEntry* LibEntry,
LibraryStruct* Library, LibraryStruct* Library );
int noMsg = 0 );
void DisplayCmpDoc( const wxString& Name ); void DisplayCmpDoc( const wxString& Name );
void InstallLibeditFrame(); void InstallLibeditFrame();
...@@ -560,7 +560,6 @@ public: ...@@ -560,7 +560,6 @@ public:
void HandleBlockPlace( wxDC* DC ); void HandleBlockPlace( wxDC* DC );
int HandleBlockEnd( wxDC* DC ); int HandleBlockEnd( wxDC* DC );
void DeletePartInLib( LibraryStruct* Library, EDA_LibComponentStruct* Entry );
void PlacePin( wxDC* DC ); void PlacePin( wxDC* DC );
void InitEditOnePin(); void InitEditOnePin();
void GlobalSetPins( wxDC* DC, LibDrawPin* MasterPin, int id ); void GlobalSetPins( wxDC* DC, LibDrawPin* MasterPin, int id );
......
...@@ -50,7 +50,8 @@ class Plotter; ...@@ -50,7 +50,8 @@ class Plotter;
enum id_librarytype { enum id_librarytype {
LIBRARY_TYPE_EESCHEMA, LIBRARY_TYPE_EESCHEMA,
LIBRARY_TYPE_PCBNEW, LIBRARY_TYPE_PCBNEW,
LIBRARY_TYPE_DOC LIBRARY_TYPE_DOC,
LIBRARY_TYPE_SYMBOL
}; };
enum id_drawframe { enum id_drawframe {
......
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