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 )
{
if( DrawList->Type() != TYPE_SCH_COMPONENT )
continue;
SCH_COMPONENT* DrawLibItem =
(SCH_COMPONENT*) DrawList;
EDA_LibComponentStruct* Entry = FindLibPart(
DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList;
EDA_LibComponentStruct* Entry =
( EDA_LibComponentStruct* )FindLibPart( DrawLibItem->m_ChipName );
if( (Entry == NULL) || (Entry->m_Options != ENTRY_POWER) )
continue;
......@@ -354,9 +354,7 @@ int AddComponentsInSheetToList( std::vector <OBJ_CMP_TO_LIST>& aComponentsList,
if( DrawList->Type() == TYPE_SCH_COMPONENT )
{
DrawLibItem = (SCH_COMPONENT*) DrawList;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(),
wxEmptyString,
FIND_ROOT );
Entry = ( EDA_LibComponentStruct* )FindLibPart( DrawLibItem->m_ChipName );
if( Entry == NULL )
continue;
......
......@@ -869,10 +869,12 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
if( aDrawLibItem )
{
NextItem = NULL;
if( ( Entry =
FindLibPart( aDrawLibItem->m_ChipName.GetData(), wxEmptyString,
FIND_ROOT ) ) == NULL )
Entry =
( EDA_LibComponentStruct* )FindLibPart( aDrawLibItem->m_ChipName );
if( Entry == NULL )
return NULL;
DEntry = Entry->m_Drawings;
Multi = aDrawLibItem->m_Multi;
convert = aDrawLibItem->m_Convert;
......
......@@ -512,7 +512,7 @@ void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
if( item->m_Selected == 0 )
continue;
item->m_Selected = 0;
LibEDA_BaseStruct* newitem = CopyDrawEntryStruct( NULL, item );
LibEDA_BaseStruct* newitem = CopyDrawEntryStruct( item );
newitem->m_Selected = IS_SELECTED;
newitem->SetNext( LibEntry->m_Drawings );
LibEntry->m_Drawings = newitem;
......
......@@ -649,7 +649,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef(
Multi = 0;
Unit = ' ';
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry )
Multi = Entry->m_UnitCount;
......@@ -749,7 +749,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal(
Multi = 0;
Unit = ' ';
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry )
Multi = Entry->m_UnitCount;
......
......@@ -168,12 +168,29 @@ LibCmpEntry::LibCmpEntry( LibrEntryType CmpType, const wxChar* CmpName ) :
}
/******************************/
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 */
/*******************************/
......
......@@ -10,6 +10,9 @@
#include "classes_body_items.h"
#include "class_libentry_fields.h"
#include <boost/ptr_container/ptr_vector.hpp>
/* Types for components in libraries
* components can be a true component or an alias of a true component.
*/
......@@ -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.
*
* @return bool - true if success writing else false.
*/
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.
*
......
/**********************************************************/
/* libclass.cpp */
/* libclass.cpp */
/**********************************************************/
#include "fctsys.h"
......@@ -8,6 +8,7 @@
#include "kicad_string.h"
#include "confirm.h"
#include "gestfich.h"
#include "eda_doc.h"
#include "program.h"
#include "libcmp.h"
......@@ -15,12 +16,23 @@
#include "protos.h"
#include "class_library.h"
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <wx/listimpl.cpp>
WX_DEFINE_LIST( LIB_CMP_LIST );
void FreeLibraryEntry( LibCmpEntry* Entry )
{
SAFE_DELETE( Entry );
}
bool operator==( const LibraryStruct& lib, const wxChar* name )
{
return lib.m_Name.CmpNoCase( name ) == 0;
}
bool operator!=( const LibraryStruct& lib, const wxChar* name )
{
return !( lib == name );
}
LibraryStruct::LibraryStruct( int type, const wxString& name,
......@@ -30,13 +42,13 @@ LibraryStruct::LibraryStruct( int type, const wxString& name,
m_Name = name; /* Name of library loaded. */
m_FullFileName = fullname; /* File name (with path) of library loaded. */
m_NumOfParts = 0; /* Number of parts this library has. */
m_Entries = NULL; /* Parts themselves are saved here. */
m_Pnext = NULL; /* Point to next library in chain. */
m_Modified = FALSE; /* flag indicateur d'edition */
m_TimeStamp = 0;
m_Flags = 0;
m_IsLibCache = FALSE;
m_DateTime = wxDateTime::Now();
m_Pnext = NULL; /* Point to next library in chain. */
m_Entries = NULL;
m_Modified = FALSE; /* flag indicateur d'edition */
m_TimeStamp = 0;
m_Flags = 0;
m_IsLibCache = FALSE;
m_DateTime = wxDateTime::Now();
}
......@@ -49,57 +61,413 @@ LibraryStruct::LibraryStruct( const wxChar* fileName )
}
/*****************************************/
/* Used by PQFreeFunc() to delete all entries
*/
/*****************************************/
void FreeLibraryEntry( LibCmpEntry* Entry )
LibraryStruct::~LibraryStruct()
{
SAFE_DELETE( Entry );
if( m_Entries )
PQFreeFunc( m_Entries, ( void( * ) ( void* ) )FreeLibraryEntry );
}
/******************************/
LibraryStruct::~LibraryStruct()
void LibraryStruct::GetEntryNames( wxArrayString& names, bool sort )
{
if( m_Entries )
PQFreeFunc( m_Entries, ( void( * ) ( void* ) )FreeLibraryEntry );
LibCmpEntry* entry = ( LibCmpEntry* ) PQFirst( &m_Entries, false );
while( entry != NULL )
{
names.Add( entry->m_Name.m_Text );
entry = ( LibCmpEntry* ) PQNext( m_Entries, entry, NULL );
}
if( sort )
names.Sort();
}
void LibraryStruct::SearchEntryNames( wxArrayString& names,
const wxString& nameSearch,
const wxString& keySearch,
bool sort )
{
LibCmpEntry* Entry;
Entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
while( Entry )
{
if( !keySearch.IsEmpty() && KeyWordOk( keySearch, Entry->m_KeyWord ) )
names.Add( Entry->m_Name.m_Text );
if( !nameSearch.IsEmpty() && WildCompareString( nameSearch,
Entry->m_Name.m_Text,
false ) )
names.Add( Entry->m_Name.m_Text );
Entry = (LibCmpEntry*) PQNext( m_Entries, Entry, NULL );
}
}
LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name )
{
static LibCmpEntry tmp( ALIAS, wxEmptyString );
tmp.m_Name.m_Text = name;
PQCompFunc( ( PQCompFuncType ) LibraryEntryCompare );
return ( LibCmpEntry* ) PQFind( m_Entries, &tmp );
}
LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name, LibrEntryType type )
{
LibCmpEntry* entry = FindEntry( name );
if( entry != NULL && entry->Type != ROOT && type == ROOT )
{
EDA_LibCmpAliasStruct* alias = ( EDA_LibCmpAliasStruct* ) entry;
entry = FindEntry( alias->m_RootName );
}
return entry;
}
EDA_LibComponentStruct* LibraryStruct::AddComponent( EDA_LibComponentStruct* cmp )
{
wxASSERT( cmp != NULL );
EDA_LibCmpAliasStruct* Alias;
EDA_LibComponentStruct* newCmp = CopyLibEntryStruct( cmp );
if( newCmp == NULL )
return NULL;
newCmp->m_AliasList.Clear();
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
PQInsert( &m_Entries, (void*) newCmp );
m_NumOfParts++;
m_Modified = 1;
for( unsigned ii = 0; ii < cmp->m_AliasList.GetCount(); ii += ALIAS_NEXT )
{
wxString aliasname = cmp->m_AliasList[ii + ALIAS_NAME];
newCmp->m_AliasList.Add( aliasname );
Alias = new EDA_LibCmpAliasStruct( aliasname, newCmp->m_Name.m_Text );
Alias->m_Doc = cmp->m_AliasList[ii + ALIAS_DOC];
Alias->m_KeyWord = cmp->m_AliasList[ii + ALIAS_KEYWORD];
Alias->m_DocFile = cmp->m_AliasList[ii + ALIAS_DOC_FILENAME];
PQInsert( &m_Entries, (void*) Alias );
m_NumOfParts++;
}
return newCmp;
}
void LibraryStruct::RemoveEntry( LibCmpEntry* entry )
{
wxASSERT( entry != NULL );
EDA_LibComponentStruct* Root;
EDA_LibCmpAliasStruct* Alias;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
m_Modified = 1;
if( entry->Type == ALIAS )
{
Alias = (EDA_LibCmpAliasStruct*) entry;
Root = ( EDA_LibComponentStruct* ) FindEntry( Alias->m_RootName, ROOT );
/* Remove alias name from the root component alias list */
if( Root == NULL )
{
wxLogWarning( wxT( "No root component found for alias <%s> in " \
"library <%s>." ),
( const wxChar* ) entry->m_Name.m_Text,
( const wxChar* ) m_Name );
}
else
{
int index = Root->m_AliasList.Index( entry->m_Name.m_Text, false );
if( index == wxNOT_FOUND )
wxLogWarning( wxT( "Alias <%s> not found in component <%s> \
alias list in library <%s>" ),
( const wxChar* ) entry->m_Name.m_Text,
( const wxChar* ) Root->m_Name.m_Text,
( const wxChar* ) m_Name );
else
Root->m_AliasList.RemoveAt( index );
}
/* Effacement memoire pour cet alias */
PQDelete( &m_Entries, (void*) Alias );
SAFE_DELETE( Alias );
if( m_NumOfParts > 0 )
m_NumOfParts--;
return;
}
Root = ( EDA_LibComponentStruct* ) entry;
/* Entry is a component with no aliases so removal is simple */
if( Root->m_AliasList.GetCount() == 0 )
{
PQDelete( &m_Entries, (void*) Root );
SAFE_DELETE( Root );
if( m_NumOfParts > 0 )
m_NumOfParts--;
return;
}
/* Entry is a component with alias
* We must change the first alias to a "root" component, and for all the
* aliases we must change the root component (which is deleted) by the
* first alias */
wxString AliasName = Root->m_AliasList[0];
/* The root component is not really deleted, it is renamed with the first
* alias name */
Alias = (EDA_LibCmpAliasStruct*) FindEntry( AliasName, ALIAS );
if( Alias == NULL || Alias->Type == ROOT )
{
wxLogWarning( wxT( "Alias <%s> for component <%s> not found in \
library <%s>" ),
( const wxChar* ) AliasName,
( const wxChar* ) Root->m_Name.m_Text,
( const wxChar* ) m_Name );
}
else
{
if( m_NumOfParts > 0 )
m_NumOfParts--;
/* remove the root component from library */
PQDelete( &m_Entries, Root );
/* remove the first alias from library*/
PQDelete( &m_Entries, Alias );
m_componentList.DeleteContents( true );
/* remove the first alias name from alias list: */
Root->m_AliasList.RemoveAt( 0 );
/* change the old name. New name for "root" is the name of the first
* alias */
entry->m_Name.m_Text = AliasName;
entry->m_Doc = Alias->m_Doc;
entry->m_KeyWord = Alias->m_KeyWord;
FreeLibraryEntry( ( LibCmpEntry* ) Alias );
/* root component (renamed) placed in library */
PQInsert( &m_Entries, entry );
}
/* Change the "RootName", for other aliases */
for( unsigned ii = 0; ii < Root->m_AliasList.GetCount(); ii++ )
{
AliasName = Root->m_AliasList[ii];
Alias = (EDA_LibCmpAliasStruct*) FindEntry( AliasName, ALIAS );
if( Alias == NULL )
{
// Should not occurs. If happens, this is an error (or bug)
wxLogWarning( wxT( "Alias <%s> for component <%s> not found in \
library <%s>." ),
( const wxChar* ) AliasName,
( const wxChar* ) Root->m_Name.m_Text,
( const wxChar* ) m_Name );
continue;
}
if( Alias->Type != ALIAS )
{
// Should not occurs. If happens, this is an error (or bug)
wxLogWarning( wxT( "Entry <%s> for component <%s> in library \
<%s> is not an alias." ),
( const wxChar* ) AliasName,
( const wxChar* ) Root->m_Name.m_Text,
( const wxChar* ) m_Name );
continue;
}
Alias->m_RootName = entry->m_Name.m_Text;
}
}
LibCmpEntry* LibraryStruct::GetNextEntry( const wxChar* name )
{
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibCmpEntry* entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
while( entry )
{
if( entry->m_Name.m_Text.CmpNoCase( name ) == 0 )
{
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
break;
}
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
}
if( entry == NULL )
entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
return entry;
}
LibCmpEntry* LibraryStruct::GetPreviousEntry( const wxChar* name )
{
LibCmpEntry* previousEntry = NULL;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibCmpEntry* entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
while( entry )
{
if( entry->m_Name.m_Text.CmpNoCase( name ) == 0 )
{
if( previousEntry )
break;
}
previousEntry = entry;
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
}
return previousEntry;
}
/*******************************************/
/* Ecrit l'entete du fichier librairie
*/
/*******************************************/
bool LibraryStruct::WriteHeader( FILE* file )
{
char BufLine[1024];
bool succes = TRUE;
bool succes = false;
DateAndTime( BufLine );
if( fprintf( file, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) != 5 )
succes = FALSE;
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
succes = false;
#if 0
if( fprintf( file, "$HEADER\n" ) != 1 )
succes = FALSE;
if( fprintf( file, "TimeStamp %8.8lX\n", m_TimeStamp ) != 2 )
succes = FALSE;
if( fprintf( file, "Parts %d\n", m_NumOfParts ) != 2 )
succes = FALSE;
if( fprintf( file, "$ENDHEADER\n" ) != 1 )
succes = FALSE;
if( ( fprintf( file, "$HEADER\n" ) < 0 )
|| ( fprintf( file, "TimeStamp %8.8lX\n", m_TimeStamp ) < 0 )
|| ( fprintf( file, "Parts %d\n", m_NumOfParts ) != 2 )
|| ( fprintf( file, "$ENDHEADER\n" ) != 1 ) )
succes = false;
#endif
return succes;
}
/***********************************************************/
/* Ecrit l'entete du fichier librairie
*/
/***********************************************************/
bool LibraryStruct::Load( wxString& errMsg )
{
FILE* f;
int LineNum = 0;
char Line[1024];
EDA_LibComponentStruct* LibEntry;
wxString msg;
if( m_FullFileName.IsEmpty() )
{
errMsg = _( "library file name not set" );
return false;
}
f = wxFopen( m_FullFileName, wxT( "rt" ) );
if( f == NULL )
{
errMsg = _( "could not open file" );
return false;
}
m_NumOfParts = 0;
if( GetLine( f, Line, &LineNum, sizeof( Line ) ) == NULL )
{
errMsg = _( "file is empty!" );
return false;
}
if( strnicmp( Line, LIBFILE_IDENT, 10 ) != 0 )
{
errMsg = _( "file is NOT an EESCHEMA library!" );
return false;
}
PQInit( &m_Entries );
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
/* There is no header if this is a symbol library. */
if( m_Type == LIBRARY_TYPE_EESCHEMA )
m_Header = CONV_FROM_UTF8( Line );
while( GetLine( f, Line, &LineNum, sizeof( Line ) ) )
{
if( m_Type == LIBRARY_TYPE_EESCHEMA
&& strnicmp( Line, "$HEADER", 7 ) == 0 )
{
if( !ReadHeader( f, &LineNum ) )
{
errMsg = _( "header read error" );
return false;
}
continue;
}
if( strnicmp( Line, "DEF", 3 ) == 0 )
{
/* Read one DEF/ENDDEF part entry from library: */
LibEntry = new EDA_LibComponentStruct( NULL );
if( LibEntry->Load( f, Line, &LineNum, msg ) )
{
/* If we are here, this part is O.k. - put it in: */
m_NumOfParts += 1;
PQInsert( &m_Entries, LibEntry );
InsertAliases( &m_Entries, LibEntry );
}
else
{
wxLogWarning( wxT( "Library <%s> component load error %s." ),
(const wxChar*) m_Name,
(const wxChar*) msg );
msg.Clear();
delete LibEntry;
}
}
}
return true;
}
void LibraryStruct::InsertAliases( PriorQue** PQ,
EDA_LibComponentStruct* component )
{
wxASSERT( component != NULL && PQ != NULL );
EDA_LibCmpAliasStruct* AliasEntry;
unsigned ii;
for( ii = 0; ii < component->m_AliasList.GetCount(); ii++ )
{
AliasEntry =
new EDA_LibCmpAliasStruct( component->m_AliasList[ii],
component->m_Name.m_Text );
PQInsert( PQ, AliasEntry );
m_NumOfParts += 1;
}
}
bool LibraryStruct::ReadHeader( FILE* libfile, int* LineNum )
{
char Line[1024], * text, * data;
......@@ -118,19 +486,9 @@ bool LibraryStruct::ReadHeader( FILE* libfile, int* LineNum )
}
/**
* Function SaveLibrary
* writes the data structures for this object out to 2 file
* the library in "*.lib" format.
* the doc file in "*.dcm" format.
* creates a backup file for each file (.bak and .bck)
* @param aFullFileName The full lib filename.
* @return bool - true if success writing else false.
*/
bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
{
FILE* libfile, *docfile;
EDA_LibComponentStruct* LibEntry;
wxString msg;
wxFileName libFileName = FullFileName;
wxFileName backupFileName = FullFileName;
......@@ -147,7 +505,7 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
{
msg = wxT( "Failed to rename old lib file " ) +
backupFileName.GetFullPath();
DisplayError( NULL, msg, 20 );
DisplayError( NULL, msg );
}
}
......@@ -164,7 +522,7 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
{
msg = wxT( "Failed to save old doc lib file " ) +
backupFileName.GetFullPath();
DisplayError( NULL, msg, 20 );
DisplayError( NULL, msg );
}
}
......@@ -174,7 +532,7 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
if( libfile == NULL )
{
msg = wxT( "Failed to create Lib File " ) + libFileName.GetFullPath();
DisplayError( NULL, msg, 20 );
DisplayError( NULL, msg );
return false;
}
......@@ -184,7 +542,7 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
{
msg = wxT( "Failed to create DocLib File " ) +
docFileName.GetFullPath();
DisplayError( NULL, msg, 20 );
DisplayError( NULL, msg );
}
m_Modified = 0;
......@@ -194,28 +552,30 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
WriteHeader( libfile );
/* Sauvegarde des composant: */
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &m_Entries, FALSE );
char Line[256];
fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT,
DateAndTime( Line ) );
bool success = true;
while( LibEntry )
LibCmpEntry* entry = ( LibCmpEntry* ) PQFirst( &m_Entries, false );
while( entry != NULL )
{
if ( LibEntry->Type == ROOT )
if ( entry->Type == ROOT )
{
if ( ! LibEntry->Save( libfile ) )
EDA_LibComponentStruct* component =
( EDA_LibComponentStruct* ) entry;
if ( ! component->Save( libfile ) )
success = false;
}
if ( docfile )
{
if ( ! LibEntry->SaveDoc( docfile ) )
if ( ! entry->SaveDoc( docfile ) )
success = false;
}
LibEntry = (EDA_LibComponentStruct*) PQNext( m_Entries,
LibEntry, NULL );
entry = ( LibCmpEntry* ) PQNext( m_Entries, entry, NULL );
}
fprintf( libfile, "#\n#End Library\n" );
......@@ -229,5 +589,5 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
wxString LibraryStruct::GetName()
{
return m_fileName.GetName();
return m_Name;
}
/**********************************/
/* Headers fo library definition */
/**********************************/
/***********************************/
/* Headers for library definition */
/***********************************/
#ifndef CLASS_LIBRARY_H
#define CLASS_LIBRARY_H
......@@ -8,11 +8,9 @@
#include "class_libentry.h"
WX_DECLARE_LIST( EDA_LibComponentStruct, LIB_CMP_LIST );
/******************************/
/* Classe to handle a library */
/* Class to handle a library */
/******************************/
class LibraryStruct
......@@ -23,7 +21,6 @@ public:
wxString m_FullFileName; /* Full File Name (with path) of library. */
wxString m_Header; /* first line of loaded library. */
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. */
int m_Modified; /* flag indicateur d'edition */
int m_Size; // Size in bytes (for statistics)
......@@ -37,36 +34,173 @@ public:
~LibraryStruct();
/**
* Function SaveLibrary
* writes the data structures for this object out to 2 file
* the library in "*.lib" format.
* the doc file in "*.dcm" format.
* creates a backup file for each file (.bak and .bck)
* @param aFullFileName The full lib filename.
* Save library to file.
*
* Two files are created. The component objects are save as component
* library (*.lib) files. The alias objects are save as document
* definition (*.dcm) files. If the component library already exists,
* 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.
*/
bool SaveLibrary( const wxString& aFullFileName );
bool ReadHeader( FILE* file, int* LineNum );
bool Load( wxString& errMsg );
void InsertAliases( PriorQue** PQ, EDA_LibComponentStruct* component );
private:
bool WriteHeader( FILE* file );
/* NOTE: For future expansion, do not delete. */
public:
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 );
wxString GetName();
protected:
wxFileName m_fileName; /* Library file name. */
wxDateTime m_DateTime; /* Library save time and date. */
wxString m_Version; /* Library save version. */
LIB_CMP_LIST m_componentList; /* List of components in this library. */
wxFileName m_fileName; /* Library file name. */
wxDateTime m_DateTime; /* Library save time and date. */
wxString m_Version; /* Library save version. */
PriorQue* m_Entries; /* Parts themselves are saved here. */
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
......@@ -424,8 +424,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
m_AddExtraText = 0;
if( fieldNdx == REFERENCE )
{
Entry = FindLibPart( component->m_ChipName.GetData(), wxEmptyString,
FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( component->m_ChipName );
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
......
......@@ -211,8 +211,9 @@ void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
int ii;
bool dummy = FALSE;
if( ( Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString,
FIND_ROOT ) ) == NULL )
Entry = ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
if( Entry == NULL )
{
/* composant non trouve, on affiche un composant "dummy" */
dummy = TRUE;
......@@ -518,8 +519,8 @@ void SCH_COMPONENT::AddField( const SCH_CMP_FIELD& aField )
EDA_Rect SCH_COMPONENT::GetBoundaryBox() const
{
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(),
wxEmptyString, FIND_ROOT );
EDA_LibComponentStruct* Entry =
( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
EDA_Rect BoundaryBox;
int x0, xm, y0, ym;
......@@ -634,7 +635,7 @@ void SCH_COMPONENT::ClearAnnotation( DrawSheetPath* aSheet )
wxString separators( wxT( " " ) );
wxArrayString reference_fields;
Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
if( Entry && Entry->m_UnitSelectionLocked )
KeepMulti = true;
......@@ -1058,8 +1059,8 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox()
void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
{
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(),
wxEmptyString, FIND_ROOT );
EDA_LibComponentStruct* Entry =
( EDA_LibComponentStruct* ) FindLibPart( m_ChipName );
wxString msg;
......
......@@ -388,7 +388,7 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList )
#undef STRUCT
#define STRUCT ( (SCH_COMPONENT*) DrawItem )
EDA_LibComponentStruct* Entry;
Entry = FindLibPart( STRUCT->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( STRUCT->m_ChipName );
if( Entry == NULL )
break;
......
/****************************/
/* EESchema - database.cpp */
/* EESchema - database.cpp */
/****************************/
/* Routine de selection d'un composant en librairie
......@@ -19,16 +19,6 @@
#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,
* Keys pointe la liste des mots cles de filtrage
......@@ -41,103 +31,59 @@ bool DataBaseGetName( WinEDA_DrawFrame* frame,
* place le nom du composant a charger, selectionne a partir d'une liste dans
* BufName
*/
wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys,
wxString& BufName )
{
int ii;
EDA_LibComponentStruct* LibEntry;
LibraryStruct* Lib;
WinEDAListBox* ListBox;
const wxChar** ListNames;
LibraryStruct* Lib;
wxArrayString nameList;
wxString msg;
BufName.MakeUpper();
Keys.MakeUpper();
/* 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 );
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 );
}
Lib->SearchEntryNames( nameList, BufName, Keys );
}
if( ii == 0 )
if( nameList.IsEmpty() )
{
DisplayError( frame, _( "No Component found" ) );
return 0;
}
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 = _( "No components found matching " );
if( !BufName.IsEmpty() )
{
msg += _( "name search criteria <" ) + BufName + wxT( "> " );
if( !Keys.IsEmpty() )
{
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 );
msg += _( "and " );
}
}
ListBox = new WinEDAListBox( frame, _( "Selection" ), ListNames,
wxEmptyString, DisplayCmpDoc,
wxColour( 200, 200, 255 ) );
ListBox->MoveMouseToOrigin();
if( !Keys.IsEmpty() )
msg += _( "key search criteria <" ) + Keys + wxT( "> " );
/* Affichage de la liste selectionnee */
if( ii )
{
ii = ListBox->ShowModal(); ListBox->Destroy();
if( ii < 0 )
ii = 0;
else
{
BufName = ListNames[ii];
ii = 1;
}
DisplayError( frame, msg );
return wxEmptyString;
}
wxSingleChoiceDialog dlg( frame, wxEmptyString, _( "Select Component" ),
nameList );
free( ListNames );
return ii;
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
return wxEmptyString;
return dlg.GetStringSelection();
}
/**********************************/
void DisplayCmpDoc( wxString& Name )
/**********************************/
{
LibCmpEntry* CmpEntry;
CmpEntry = FindLibPart( Name.GetData(), wxEmptyString, FIND_ALIAS );
CmpEntry = FindLibPart( Name, wxEmptyString, ALIAS );
if( CmpEntry == NULL )
return;
Name = wxT( "Descr: " ) + CmpEntry->m_Doc;
Name += wxT( "\nKeyW: " ) + CmpEntry->m_KeyWord;
Name = wxT( "Description: " ) + CmpEntry->m_Doc;
Name += wxT( "\nKey Words: " ) + CmpEntry->m_KeyWord;
}
......@@ -171,7 +171,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()
else if( newname.CmpNoCase( m_Cmp->m_ChipName ) )
{
if( FindLibPart( newname.GetData(), wxEmptyString, FIND_ALIAS ) == NULL )
if( FindLibPart( newname, wxEmptyString, ALIAS ) == NULL )
{
wxString message;
message.Printf( _( "Component [%s] not found!" ), newname.GetData() );
......@@ -263,8 +263,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
++i;
}
EDA_LibComponentStruct* entry = FindLibPart(
m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
EDA_LibComponentStruct* entry =
( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName );
if( entry && entry->m_Options == ENTRY_POWER )
m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName;
......@@ -411,7 +411,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* 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)
for( int i = 0; i<aComponent->GetFieldCount(); ++i )
......@@ -705,7 +705,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
if( m_Cmp == NULL )
return;
entry = FindLibPart( m_Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
entry = ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName );
if( entry == NULL )
return;
......
......@@ -452,7 +452,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
{
for( ii = OldNumUnits + 1; ii <= MaxUnit; ii++ )
{
NextDrawItem = CopyDrawEntryStruct( this, DrawItem );
NextDrawItem = CopyDrawEntryStruct( DrawItem );
NextDrawItem->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = NextDrawItem;
NextDrawItem->m_Unit = ii;
......@@ -499,7 +499,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
g_AsDeMorgan = 0; return FALSE;
}
}
NextDrawItem = CopyDrawEntryStruct( this, DrawItem );
NextDrawItem = CopyDrawEntryStruct( DrawItem );
NextDrawItem->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = NextDrawItem;
NextDrawItem->m_Convert = 2;
......
......@@ -68,7 +68,8 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC )
m_Multiflag = 0;
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->m_UnitCount > 1 )
......@@ -103,7 +104,8 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC )
fieldNdx = Field->m_FieldId;
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) )
{
DisplayInfoMessage( this,
......@@ -117,7 +119,8 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC )
flag = 0;
if( fieldNdx == REFERENCE )
{
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
......@@ -259,8 +262,8 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC )
flag = 0;
if( fieldNdx == REFERENCE )
{
Entry = FindLibPart( ( (SCH_COMPONENT*) Field->GetParent() )->m_ChipName.GetData(),
wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( ( (SCH_COMPONENT*) Field->GetParent() )->m_ChipName );
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
......@@ -296,7 +299,8 @@ void WinEDA_SchematicFrame::EditComponentReference( SCH_COMPONENT* Cmp, wxDC* DC
if( Cmp == NULL )
return;
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry == NULL )
return;
......@@ -335,7 +339,8 @@ void WinEDA_SchematicFrame::EditComponentValue( SCH_COMPONENT* Cmp, wxDC* DC )
if( Cmp == NULL )
return;
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry == NULL )
return;
......@@ -373,7 +378,8 @@ void WinEDA_SchematicFrame::EditComponentFootprint( SCH_COMPONENT* Cmp, wxDC* DC
if( Cmp == NULL )
return;
Entry = FindLibPart( Cmp->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName );
if( Entry == NULL )
return;
......
......@@ -164,23 +164,12 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC,
* Alias = FIND_ROOT, ou Alias = FIND_ALIAS
*/
/*****************************************************************************/
EDA_LibComponentStruct* FindLibPart( const wxChar* Name,
const wxString& LibName,
int Alias )
LibCmpEntry* FindLibPart( const wxChar* Name, const wxString& LibName,
LibrEntryType type )
{
EDA_LibComponentStruct* Entry;
/* Used only to call PQFind. */
static EDA_LibComponentStruct DummyEntry( wxEmptyString );
LibCmpEntry* Entry = NULL;
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();
while( Lib )
......@@ -197,7 +186,8 @@ EDA_LibComponentStruct* FindLibPart( const wxChar* Name,
if( Lib == NULL )
break;
Entry = (EDA_LibComponentStruct*) PQFind( Lib->m_Entries, &DummyEntry );
Entry = Lib->FindEntry( Name, type );
if( Entry != NULL )
{
FindLibName = Lib->m_Name;
......@@ -207,15 +197,6 @@ EDA_LibComponentStruct* FindLibPart( const wxChar* Name,
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;
}
......
......@@ -17,14 +17,6 @@
#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,
const wxString& FullLibName,
const wxString& LibName )
{
int NumOfParts;
FILE* f;
LibraryStruct* NewLib;
PriorQue* Entries;
wxFileName fn;
wxString errMsg;
if( ( NewLib = FindLibrary( LibName ) ) != NULL )
{
if( NewLib->m_FullFileName == FullLibName )
return NewLib;
FreeCmpLibrary( frame, LibName );
}
NewLib = NULL;
f = wxFopen( FullLibName, wxT( "rt" ) );
if( f == NULL )
{
wxString msg;
msg.Printf( _( "Library <%s> not found" ), FullLibName.GetData() );
DisplayError( frame, msg );
return NULL;
delete NewLib;
}
currentLibraryName = FullLibName;
NewLib = new LibraryStruct( LIBRARY_TYPE_EESCHEMA, LibName, FullLibName );
Entries = LoadLibraryAux( frame, NewLib, f, &NumOfParts );
if( Entries != NULL )
{
NewLib->m_Entries = Entries;
NewLib->m_NumOfParts = NumOfParts;
wxBusyCursor ShowWait;
if( NewLib->Load( errMsg ) )
{
if( g_LibraryList == NULL )
g_LibraryList = NewLib;
else
......@@ -90,9 +66,15 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame,
}
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 );
}
fclose( f );
return NewLib;
}
......@@ -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. *
*****************************************************************************/
......@@ -363,7 +267,7 @@ LibraryStruct* FindLibrary( const wxString& Name )
while( Lib )
{
if( Lib->m_Name == Name )
if( *Lib == Name )
return Lib;
Lib = Lib->m_Pnext;
}
......@@ -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 */
/*******************************************************/
......@@ -418,7 +301,7 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
{
int LineNum = 0;
char Line[1024], * Name, * Text;
EDA_LibComponentStruct* Entry;
LibCmpEntry* Entry;
FILE* f;
wxString msg;
......@@ -455,7 +338,8 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
Name = strtok( Line + 5, "\n\r" );
wxString cmpname;
cmpname = CONV_FROM_UTF8( Name );
Entry = FindLibPart( cmpname.GetData(), Libname, FIND_ALIAS );
Entry = FindLibPart( cmpname, Libname, ALIAS );
while( GetLine( f, Line, &LineNum, sizeof(Line) ) )
{
if( strncmp( Line, "$ENDCMP", 7 ) == 0 )
......
......@@ -259,8 +259,8 @@ void DrawStructsInGhost( WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem
EDA_LibComponentStruct* LibEntry;
SCH_COMPONENT* Struct;
Struct = (SCH_COMPONENT*) aItem;
LibEntry = FindLibPart( Struct->m_ChipName.GetData(), wxEmptyString,
FIND_ROOT );
LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Struct->m_ChipName );
if( LibEntry == NULL )
break;
DrawingLibInGhost( aPanel, aDC, LibEntry, Struct, Struct->m_Pos.x + aOffset.x,
......
......@@ -624,51 +624,54 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem(
}
/*************************************************************/
void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
/*************************************************************/
/* Search for a given component.
* The serach is made in loaded libraries,
* and if not found in all libraries found in lib paths.
/*
* Search for a given component.
*
* The search 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;
EDA_LibComponentStruct* LibEntry;
bool FoundInLib = FALSE; // True si reference trouvee ailleurs qu'en cache
wxArrayString nameList;
wxString Text, FindList;
bool FoundInLib = false;
Text = m_NewTextCtrl->GetValue();
if( Text.IsEmpty() )
{
Close(); return;
Close();
return;
}
s_OldStringFound = Text;
if( NumOfLibraries() == 0 )
if( NumOfLibraries() == 0 )
{
DisplayError( this, _( "No libraries are loaded" ) );
Close(); return;
Close();
return;
}
int nbitemsFound = 0;
for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
while( LibEntry )
Lib->SearchEntryNames( nameList, Text );
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 ) )
{
nbitemsFound++;
if( !Lib->m_IsLibCache )
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 );
if( !FindList.IsEmpty() )
FindList += wxT( "\n" );
FindList << _( "Found " ) + nameList[i] + _( " in library " )
+ Lib->m_Name;
}
}
......@@ -690,7 +693,9 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
}
}
else
{
DisplayInfoMessage( this, FindList );
}
Close();
}
......
......@@ -83,7 +83,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
Library = g_LibraryList;
while( Library )
{
if( Library->m_Name == libname )
if( Library->GetName().CmpNoCase( libname ) == 0 )
{
CmpCount = Library->m_NumOfParts;
break;
......@@ -118,7 +118,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
{
AllowWildSeach = FALSE;
keys = Name.AfterFirst( '=' );
if( DataBaseGetName( this, keys, Name ) == 0 )
Name = DataBaseGetName( this, keys, Name );
if( Name.IsEmpty() )
{
DrawPanel->m_IgnoreMouseEvents = FALSE;
DrawPanel->MouseToCursorSchema();
......@@ -138,7 +139,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) )
{
AllowWildSeach = FALSE;
if( DataBaseGetName( this, keys, Name ) == 0 )
Name = DataBaseGetName( this, keys, Name );
if( Name.IsEmpty() )
{
DrawPanel->m_IgnoreMouseEvents = FALSE;
DrawPanel->MouseToCursorSchema();
......@@ -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 */
{
AllowWildSeach = FALSE;
wxString wildname = wxChar( '*' ) + Name + wxChar( '*' );
Name = wildname;
if( DataBaseGetName( this, keys, Name ) )
Entry = FindLibPart( Name.GetData(), libname, FIND_ROOT );
Name = DataBaseGetName( this, keys, Name );
if( !Name.IsEmpty() )
Entry = ( EDA_LibComponentStruct* ) FindLibPart( Name, libname );
if( Entry == NULL )
{
DrawPanel->m_IgnoreMouseEvents = FALSE;
......@@ -352,8 +358,8 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
if( DrawComponent == NULL )
return;
LibEntry = FindLibPart(
DrawComponent->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( DrawComponent->m_ChipName );
if( LibEntry == NULL )
return;
......@@ -401,8 +407,8 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
if( DrawComponent == NULL )
return;
LibEntry = FindLibPart(
DrawComponent->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( DrawComponent->m_ChipName );
if( LibEntry == NULL )
return;
......
......@@ -37,10 +37,10 @@ extern int ExportPartId;
/*************************************************/
void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event )
{
wxFileName fn;
LibraryStruct* LibTmp;
EDA_LibComponentStruct* LibEntry;
int err = 1;
wxFileName fn;
LibraryStruct* LibTmp;
LibCmpEntry* LibEntry;
bool entryLoaded;
LibItemToRepeat = NULL;
......@@ -58,14 +58,13 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event )
if( g_LibraryList )
{
LibEntry = (EDA_LibComponentStruct*) PQFirst( &g_LibraryList->m_Entries,
false );
LibEntry = g_LibraryList->GetFirstEntry();
if( LibEntry )
err = LoadOneLibraryPartAux( LibEntry, g_LibraryList, 1 );
entryLoaded = LoadOneLibraryPartAux( LibEntry, g_LibraryList );
FreeCmpLibrary( this, g_LibraryList->m_Name );
if( err == 0 )
if( entryLoaded )
{
fn = dlg.GetPath();
m_LastLibImportPath = fn.GetPath();
......@@ -75,7 +74,7 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event )
DrawPanel->Refresh();
}
else
DisplayError( this, _( "File is empty" ), 30 );
DisplayError( this, _( "File is empty" ) );
}
g_LibraryList = LibTmp;
......
......@@ -36,19 +36,15 @@ bool BuildAliasData( LibraryStruct* Lib, EDA_LibComponentStruct* component )
LibCmpEntry* CmpEntry;
unsigned ii;
if( component == NULL )
return FALSE;
if( Lib == NULL )
return FALSE;
if( component->m_AliasList.GetCount() == 0 )
return FALSE;
if( component == NULL || Lib == NULL
|| component->m_AliasList.GetCount() == 0 )
return false;
List = component->m_AliasList;
component->m_AliasList.Clear();
for( ii = 0; ii < List.GetCount(); ii++ )
{
CmpEntry = (LibCmpEntry*) FindLibPart( List[ii].GetData(),
Lib->m_Name, FIND_ALIAS );
CmpEntry = FindLibPart( List[ii], Lib->m_Name, ALIAS );
if( CmpEntry && CmpEntry->Type != ALIAS )
{
DisplayError( NULL,
......
......@@ -52,7 +52,8 @@ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName )
continue;
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
ListEntry.push_back( Entry );
}
......
......@@ -34,11 +34,6 @@ enum LocateDrawStructType {
#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"
......
......@@ -22,10 +22,8 @@
#include "dialog_create_component.h"
/**********************************************/
void WinEDA_LibeditFrame::DisplayLibInfos()
/**********************************************/
/* Affiche dans la zone messages la librairie , et le composant edite */
void WinEDA_LibeditFrame::DisplayLibInfos()
{
wxString msg = wxT( "Libedit: " );
......@@ -58,12 +56,8 @@ void WinEDA_LibeditFrame::DisplayLibInfos()
}
/**************************************************/
/* Function to select the current library (working library) */
void WinEDA_LibeditFrame::SelectActiveLibrary()
/**************************************************/
/* Function to select the current library (working library)
*/
{
LibraryStruct* Lib;
......@@ -76,8 +70,6 @@ void WinEDA_LibeditFrame::SelectActiveLibrary()
}
bool WinEDA_LibeditFrame::LoadOneLibraryPart()
/**
* Function LoadOneLibraryPart()
* load a library component from the current selected library
......@@ -85,11 +77,12 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart()
* If there is no current selected library,
* prompt user for library name and make the selected library the current lib.
*/
bool WinEDA_LibeditFrame::LoadOneLibraryPart()
{
int i;
wxString msg;
wxString CmpName;
EDA_LibComponentStruct* LibEntry = NULL;
int i;
wxString msg;
wxString CmpName;
LibCmpEntry* LibEntry = NULL;
if( g_ScreenLib->IsModify() )
{
......@@ -97,7 +90,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart()
return FALSE;
}
if( CurrentLib == NULL ) // No current lib, ask user for the library to use
if( CurrentLib == NULL ) // No current lib, ask user for the library to use
{
SelectActiveLibrary();
if( CurrentLib == NULL )
......@@ -118,17 +111,20 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart()
}
/* Load the new library component */
LibEntry = FindLibPart( CmpName.GetData(), CurrentLib->m_Name, FIND_ALIAS );
LibEntry = CurrentLib->FindEntry( CmpName, ALIAS );
if( LibEntry == NULL )
{
msg = _( "Component \"" ); msg << CmpName << _( "\" not found." );
DisplayError( this, msg, 20 );
DisplayError( this, msg );
return FALSE;
}
GetScreen()->ClearUndoRedoList();
LoadOneLibraryPartAux( LibEntry, CurrentLib );
if( !LoadOneLibraryPartAux( LibEntry, CurrentLib ) )
return false;
ReCreateHToolbar();
Zoom_Automatique( FALSE );
DrawPanel->Refresh();
......@@ -136,46 +132,52 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart()
}
/**************************************************************************/
int WinEDA_LibeditFrame::LoadOneLibraryPartAux(
EDA_LibComponentStruct* LibEntry,
LibraryStruct* Library,
int noMsg )
/**************************************************************************/
/* Routine Pour Charger en memoire la copie de 1 libpart.
/*
* Routine Pour Charger en memoire la copie de 1 libpart.
* retourne
* 0 si OK
* 1 si err
* CurrentLibEntry pointe la copie ainsi creee
*/
bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( LibCmpEntry* LibEntry,
LibraryStruct* Library )
{
wxString msg;
const wxChar* CmpName, * RootName = NULL;
wxString msg, cmpName, rootName;
if( (LibEntry == NULL) || (Library == NULL) )
return 1;
return false;
CmpName = LibEntry->m_Name.m_Text.GetData();
if( LibEntry->m_Name.m_Text.IsEmpty() )
{
wxLogWarning( wxT( "Entry in library <%s> has empty name field." ),
(const wxChar*) LibEntry );
return false;
}
cmpName = LibEntry->m_Name.m_Text;
CurrentAliasName.Empty();
if( LibEntry->Type != ROOT )
{
RootName = ( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName.GetData();
if( !noMsg )
{
msg.Printf( wxT( "\"<%s>\" is Alias of \"<%s>\"" ), CmpName,
RootName );
}
rootName = ( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName;
wxASSERT( !rootName.IsEmpty() );
wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ),
(const wxChar*) cmpName, (const wxChar*) rootName );
LibEntry = FindLibPart( RootName, Library->m_Name, FIND_ROOT );
LibEntry = Library->FindEntry( rootName, ROOT );
if( LibEntry == NULL )
{
msg.Printf( wxT( "Root Part \"<%s>\" not found." ), RootName );
DisplayError( this, msg, 20 );
return 1;
msg.Printf( wxT( "Root entry <%s> for alias <%s> not found in \
library <%s>." ),
(const wxChar*) rootName,
(const wxChar*) cmpName,
(const wxChar*) Library->m_Name );
DisplayError( this, msg );
return false;
}
CurrentAliasName = CmpName;
CurrentAliasName = cmpName;
}
if( CurrentLibEntry )
......@@ -183,8 +185,9 @@ int WinEDA_LibeditFrame::LoadOneLibraryPartAux(
SAFE_DELETE( CurrentLibEntry );
}
CurrentLibEntry = CopyLibEntryStruct( this, LibEntry );
CurrentUnit = 1; CurrentConvert = 1;
CurrentLibEntry = CopyLibEntryStruct( (EDA_LibComponentStruct*) LibEntry );
CurrentUnit = 1;
CurrentConvert = 1;
DisplayLibInfos();
BuildAliasData( Library, CurrentLibEntry );
......@@ -195,15 +198,12 @@ int WinEDA_LibeditFrame::LoadOneLibraryPartAux(
if( LookForConvertPart( CurrentLibEntry ) > 1 )
g_AsDeMorgan = 1;
return 0;
return true;
}
/*********************************************************************/
/* Function to redraw the current loaded library component */
void WinEDA_LibeditFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
/*********************************************************************/
/* Function to redraw the current loaded library component
*/
{
if( GetScreen() == NULL )
return;
......@@ -217,7 +217,7 @@ void WinEDA_LibeditFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
DrawPanel->CursorOff( DC ); // erase cursor
if( DrawPanel->ManageCurseur )
{
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE ); // effacement affichage lie au curseur
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
}
if( EraseBg )
......@@ -242,16 +242,14 @@ void WinEDA_LibeditFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
}
/*************************************************/
void WinEDA_LibeditFrame::SaveActiveLibrary()
/*************************************************/
/* Save (on disk) the current library
/*
* Save (on disk) the current library
* if exists the old file is renamed (.bak)
*/
void WinEDA_LibeditFrame::SaveActiveLibrary()
{
wxFileName fn;
wxString msg;
wxString msg;
if( CurrentLib == NULL )
{
......@@ -273,7 +271,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary()
if( !success )
{
msg = _( "Error while saving Library File \"" ) + fn.GetFullPath() +
_( "\"." );
_( "\"." );
Affiche_1_Parametre( this, 1, wxT( " *** ERROR : **" ), msg, BLUE );
DisplayError( this, msg );
}
......@@ -282,27 +280,25 @@ void WinEDA_LibeditFrame::SaveActiveLibrary()
msg = _( "Library File \"" ) + fn.GetFullName() + wxT( "\" Ok" );
fn.SetExt( DOC_EXT );
wxString msg1 = _( "Document File \"" ) + fn.GetFullPath() +
wxT( "\" Ok" );
wxT( "\" Ok" );
Affiche_1_Parametre( this, 1, msg, msg1, BLUE );
}
}
/**************************************************************/
void WinEDA_LibeditFrame::DisplayCmpDoc( const wxString& Name )
/**************************************************************/
/*
* Affiche la documentation du composant selectionne
* Utilise lors de l'affichage de la liste des composants en librairie
* Utilise lors de l'affichage de la liste des composants en librairie
*/
void WinEDA_LibeditFrame::DisplayCmpDoc( const wxString& Name )
{
LibCmpEntry* CmpEntry;
if( CurrentLib == NULL )
return;
MsgPanel->EraseMsgBox();
CmpEntry = FindLibPart( Name.GetData(), CurrentLib->m_Name, FIND_ALIAS );
CmpEntry = CurrentLib->FindEntry( Name );
if( CmpEntry == NULL )
return;
......@@ -311,11 +307,8 @@ void WinEDA_LibeditFrame::DisplayCmpDoc( const wxString& Name )
}
/*********************************************/
void WinEDA_LibeditFrame::DeleteOnePart()
/*********************************************/
/* Routine de suppression d'un composant dans la librairie courante
/*
* Routine de suppression d'un composant dans la librairie courante
* (effacement en memoire uniquement, le fichier n'est pas modifie)
* Le composant peut etre un alias, ou la definition de base.
* Si c'est un alias:
......@@ -326,94 +319,80 @@ void WinEDA_LibeditFrame::DeleteOnePart()
* Sinon le premier alias devient le composant de base, et les autres
* alias deviennent dependants de celui ci.
*/
void WinEDA_LibeditFrame::DeleteOnePart()
{
wxString CmpName;
int NumOfParts;
EDA_LibComponentStruct* LibEntry;
WinEDAListBox* ListBox;
const wxChar** ListNames;
wxString msg;
wxString CmpName;
LibCmpEntry* LibEntry;
wxArrayString ListNames;
wxString msg;
CurrentDrawItem = NULL;
if( CurrentLib == NULL )
{
SelectActiveLibrary();
if( CurrentLib == NULL )
{
DisplayError( this, _( "No Active Library" ), 20 );
DisplayError( this, _( "Please select a component library." ) );
return;
}
}
NumOfParts = 0;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &CurrentLib->m_Entries,
FALSE );
while( LibEntry != NULL )
{
NumOfParts++;
LibEntry = (EDA_LibComponentStruct*)
PQNext( CurrentLib->m_Entries, LibEntry, NULL );
}
CurrentLib->GetEntryNames( ListNames );
ListNames = (const wxChar**) MyZMalloc( (NumOfParts + 1) * sizeof(wxChar*) );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &CurrentLib->m_Entries,
FALSE );
msg.Printf( _( "Select Component (%d items)" ), NumOfParts );
NumOfParts = 0;
while( LibEntry != NULL )
if( ListNames.IsEmpty() )
{
ListNames[NumOfParts] = LibEntry->m_Name.m_Text.GetData();
NumOfParts++;
LibEntry = (EDA_LibComponentStruct*)
PQNext( CurrentLib->m_Entries, LibEntry, NULL );
msg.Printf( _( "Component library <%s> does not have any entries to delete." ),
( const wxChar* ) CurrentLib->m_Name );
wxMessageBox( msg, _( "Delete Entry Error" ),
wxID_OK | wxICON_EXCLAMATION, this );
return;
}
ListBox = new WinEDAListBox( this, msg, ListNames, wxEmptyString, NULL,
wxColour( 255, 255, 255 ) );
msg.Printf( _( "Select 1 of %d components to\ndelete from library <%s>." ),
ListNames.GetCount(), ( const wxChar* ) CurrentLib->m_Name );
wxSingleChoiceDialog dlg( this, msg, _( "Delete Component" ), ListNames );
int ii = ListBox->ShowModal();
ListBox->Destroy();
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
return;
if( ii >= 0 )
{
CmpName = ListNames[ii];
LibEntry = FindLibPart( CmpName.GetData(), CurrentLib->m_Name,
FIND_ALIAS );
LibEntry = CurrentLib->FindEntry( dlg.GetStringSelection() );
if( LibEntry == NULL )
DisplayError( this, _( "Component not found" ), 20 );
else
{
msg = _( "Delete component \"" ) + LibEntry->m_Name.m_Text +
_( "\" from library \"" ) + CurrentLib->m_Name + wxT( "\"?" );
if( IsOK( this, msg ) )
{
DeletePartInLib( CurrentLib, LibEntry );
}
}
if( LibEntry == NULL )
{
msg.Printf( _( "Entry <%s> not found in library <%s>." ),
( const wxChar* ) dlg.GetStringSelection(),
( const wxChar* ) CurrentLib->m_Name );
DisplayError( this, msg );
return;
}
free( ListNames );
}
msg = _( "Delete component \"" ) + LibEntry->m_Name.m_Text +
_( "\" from library \"" ) + CurrentLib->m_Name + wxT( "\"?" );
if( IsOK( this, msg ) )
{
CurrentLib->RemoveEntry( LibEntry );
}
}
/****************************************************/
void WinEDA_LibeditFrame::CreateNewLibraryPart()
/****************************************************/
/* Routine to create a new library component
* If an old component is currently in edit, it is deleted.
/*
* Routine to create a new library component
*
* If an old component is currently in edit, it is deleted.
*/
void WinEDA_LibeditFrame::CreateNewLibraryPart()
{
wxString msg;
EDA_LibComponentStruct* NewStruct;
int diag;
if( CurrentLibEntry
&& !IsOK( this, _( "Clear old component from screen (changes will be lost)?" ) ) )
&& !IsOK( this,
_( "Clear old component from screen (changes will be lost)?" ) ) )
return;
CurrentDrawItem = NULL;
......@@ -431,7 +410,7 @@ void WinEDA_LibeditFrame::CreateNewLibraryPart()
/* Test: y a t-il un composant deja de ce nom */
if( CurrentLib )
{
if( FindLibPart( msg.GetData(), CurrentLib->m_Name, FIND_ALIAS ) )
if( CurrentLib->FindEntry( msg ) )
{
wxString msg;
msg << _( "Component \"" ) << Dialogbox.ReturnCmpName() <<
......@@ -462,166 +441,23 @@ void WinEDA_LibeditFrame::CreateNewLibraryPart()
}
/*******************************************************************/
void WinEDA_LibeditFrame::DeletePartInLib( LibraryStruct* Library,
EDA_LibComponentStruct* Entry )
/*******************************************************************/
/* Suppression du composant Entry en librairie Library.
* (effacement en memoire uniquement, le fichier n'est pas modifie)
* Le composant peut etre un alias, ou la definition de base.
* Si c'est un alias:
* il est supprime, et la liste des alias de la definition
* de base est modifiee
* Si c'est le composant de base:
* Si la liste des alias est nulle, il est supprime
* Sinon le premier alias devient le composant de base, et les autres
* alias deviennent dependants de celui ci.
/*
* Routine de sauvegarde de la "partlib" courante dans la librairie courante
*
* Sauvegarde en memoire uniquement, et PAS sur fichier
* La routine efface l'ancien composant ( ou / et les alias ) a remplacer
* s'il existe, et sauve le nouveau et cree les alias correspondants.
*/
{
EDA_LibComponentStruct* RootEntry;
EDA_LibCmpAliasStruct* AliasEntry;
if( ( Library == NULL ) || ( Entry == NULL ) )
return;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
Library->m_Modified = 1;
if( Entry->Type == ALIAS )
{
RootEntry = FindLibPart(
( (EDA_LibCmpAliasStruct*) Entry )->m_RootName.GetData(),
Library->m_Name, FIND_ROOT );
/* Remove alias name from the root component alias list */
if( RootEntry == NULL )
{
DisplayError( this, wxT( "Warning: for Alias, root not found" ),
30 );
}
else
{
int index = wxNOT_FOUND;
if( RootEntry->m_AliasList.GetCount() != 0 )
{
index = RootEntry->m_AliasList.Index( Entry->m_Name.m_Text.GetData(),
FALSE );
if( index != wxNOT_FOUND )
RootEntry->m_AliasList.RemoveAt( index );
}
if( index == wxNOT_FOUND )
DisplayError( this,
wxT( "Warning: Root for Alias as no alias list" ),
30 );
}
/* Effacement memoire pour cet alias */
PQDelete( &Library->m_Entries, (void*) Entry );
SAFE_DELETE( Entry );
if( Library->m_NumOfParts > 0 )
CurrentLib->m_NumOfParts--;
return;
}
/* Entry is a standard component (not an alias) */
if( Entry->m_AliasList.GetCount() == 0 ) // Trivial case: no alias, we can safety delete e=this entry
{
PQDelete( &Library->m_Entries, Entry );
SAFE_DELETE( Entry );
if( Library->m_NumOfParts > 0 )
Library->m_NumOfParts--;
return;
}
/* Entry is a component with alias
* We must change the first alias to a "root" component, and for all the aliases
* we must change the root component (which is deleted) by the first alias */
wxString AliasName = Entry->m_AliasList[0];
/* The root component is not really deleted, it is renamed with the first alias name */
AliasEntry = (EDA_LibCmpAliasStruct*) FindLibPart(
AliasName.GetData(), Library->m_Name, FIND_ALIAS );
if( AliasEntry == NULL )
{
wxString msg;
msg.Printf( wxT( "Warning: Alias <%s> not found" ),
AliasName.GetData() );
DisplayError( this, msg, 30 );
}
else
{
if( Library->m_NumOfParts > 0 )
Library->m_NumOfParts--;
/* remove the root component from library */
PQDelete( &Library->m_Entries, Entry );
/* remove the first alias from library*/
PQDelete( &Library->m_Entries, AliasEntry );
/* remove the first alias name from alias list: */
Entry->m_AliasList.RemoveAt( 0 );
/* change the old name. New name for "root" is the name of the first alias */
Entry->m_Name.m_Text = AliasName;
Entry->m_Doc = AliasEntry->m_Doc;
Entry->m_KeyWord = AliasEntry->m_KeyWord;
FreeLibraryEntry( (EDA_LibComponentStruct*) AliasEntry );
/* root component (renamed) placed in library */
PQInsert( &Library->m_Entries, Entry );
}
/* Change the "RootName", for other aliases */
for( unsigned ii = 0; ii < Entry->m_AliasList.GetCount(); ii++ )
{
AliasName = Entry->m_AliasList[ii];
AliasEntry = (EDA_LibCmpAliasStruct*) FindLibPart( AliasName.GetData(),
Library->m_Name,
FIND_ALIAS );
if( AliasEntry == NULL )
{
// Should not occurs. If happens, this is an error (or bug)
wxString msg;
msg.Printf( wxT( "Warning: Alias <%s> not found" ),
AliasName.GetData() );
DisplayError( this, msg, 30 );
continue;
}
if( AliasEntry->Type != ALIAS )
{
// Should not occurs. If happens, this is an error (or bug)
wxString msg;
msg.Printf( wxT( "Warning: <%s> is not an Alias" ),
AliasName.GetData() );
DisplayError( this, msg, 30 );
continue;
}
AliasEntry->m_RootName = Entry->m_Name.m_Text;
}
}
/***************************************************/
void WinEDA_LibeditFrame::SaveOnePartInMemory()
/***************************************************/
/* Routine de sauvegarde de la "partlib" courante dans la librairie courante
* Sauvegarde en memoire uniquement, et PAS sur fichier
* La routine efface l'ancien composant ( ou / et les alias ) a remplacer
* s'il existe, et sauve le nouveau et cree les alias correspondants.
*/
{
EDA_LibComponentStruct* Entry;
EDA_LibCmpAliasStruct* AliasEntry;
LibCmpEntry* Entry;
EDA_LibComponentStruct* Component;
wxString msg;
bool NewCmp = TRUE;
if( CurrentLibEntry == NULL )
{
DisplayError( this, _( "No component to Save." ) );
DisplayError( this, _( "No component to save." ) );
return;
}
......@@ -630,69 +466,50 @@ void WinEDA_LibeditFrame::SaveOnePartInMemory()
if( CurrentLib == NULL )
{
DisplayError( this, _( "No Library specified." ), 20 );
DisplayError( this, _( "No Library specified." ) );
return;
}
CurrentLib->m_Modified = 1;
g_ScreenLib->ClrModify();
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
Entry = CurrentLib->FindEntry( CurrentLibEntry->m_Name.m_Text, ROOT );
if( ( Entry = FindLibPart( CurrentLibEntry->m_Name.m_Text.GetData(),
CurrentLib->m_Name, FIND_ROOT ) ) != NULL )
if( Entry != NULL )
{
msg.Printf( _( "Component \"%s\" exists. Change it?" ),
Entry->m_Name.m_Text.GetData() );
(const wxChar*) Entry->m_Name.m_Text );
if( !IsOK( this, msg ) )
return;
NewCmp = FALSE;
}
wxASSERT( CurrentLibEntry->Type == ROOT );
/* Effacement des alias deja existants en librairie */
for( unsigned ii = 0;
ii < CurrentLibEntry->m_AliasList.GetCount();
ii += ALIAS_NEXT )
{
EDA_LibComponentStruct* LocalEntry;
wxString aliasname = CurrentLibEntry->m_AliasList[ii + ALIAS_NAME];
while( ( LocalEntry = FindLibPart( aliasname.GetData(),
CurrentLib->m_Name,
FIND_ALIAS ) ) != NULL )
LibCmpEntry* LocalEntry;
wxString aliasname = CurrentLibEntry->m_AliasList[ii];
LocalEntry = CurrentLib->FindEntry( aliasname, ALIAS );
while( LocalEntry != NULL && LocalEntry->Type == ALIAS )
{
DeletePartInLib( CurrentLib, LocalEntry );
CurrentLib->RemoveEntry( LocalEntry );
}
}
if( !NewCmp )
DeletePartInLib( CurrentLib, Entry );
CurrentLib->RemoveEntry( Entry );
Entry = CopyLibEntryStruct( this, CurrentLibEntry );
Entry->m_AliasList.Clear();
PQInsert( &CurrentLib->m_Entries, (void*) Entry );
CurrentLib->m_NumOfParts++;
Component = CurrentLib->AddComponent( CurrentLibEntry );
/* Creation des nouveaux alias */
for( unsigned ii = 0;
ii < CurrentLibEntry->m_AliasList.GetCount();
ii += ALIAS_NEXT )
{
wxString aliasname = CurrentLibEntry->m_AliasList[ii + ALIAS_NAME];
Entry->m_AliasList.Add( aliasname );
AliasEntry = new EDA_LibCmpAliasStruct( aliasname.GetData(),
Entry->m_Name.m_Text );
AliasEntry->m_Doc = CurrentLibEntry->m_AliasList[ii + ALIAS_DOC];
AliasEntry->m_KeyWord =
CurrentLibEntry->m_AliasList[ii + ALIAS_KEYWORD];
AliasEntry->m_DocFile =
CurrentLibEntry->m_AliasList[ii + ALIAS_DOC_FILENAME];
/* Placement en liste des composants de l'Alias */
PQInsert( &CurrentLib->m_Entries, (void*) AliasEntry );
CurrentLib->m_NumOfParts++;
}
if( Component == NULL )
return;
msg.Printf( _( "Component %s saved in %s" ),
Entry->m_Name.m_Text.GetData(), CurrentLib->m_Name.GetData() );
msg.Printf( _( "Component %s saved in library %s" ),
( const wxChar* ) Component->m_Name.m_Text,
( const wxChar* ) CurrentLib->m_Name );
Affiche_Message( msg );
}
......@@ -23,7 +23,10 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy,
EDA_LibComponentStruct* CopyItem;
PICKED_ITEMS_LIST* lastcmd;
CopyItem = CopyLibEntryStruct( this, (EDA_LibComponentStruct*) ItemToCopy );
CopyItem = CopyLibEntryStruct( (EDA_LibComponentStruct*) ItemToCopy );
if( CopyItem == NULL )
return;
lastcmd = new PICKED_ITEMS_LIST();
ITEM_PICKER wrapper(CopyItem, UR_LIBEDIT);
......
......@@ -722,7 +722,8 @@ LibDrawPin* LocatePinByNumber( const wxString& ePin_Number,
LibDrawPin* Pin;
int Unit, Convert;
Entry = FindLibPart( eComponent->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* )FindLibPart( eComponent->m_ChipName );
if( Entry == NULL )
return NULL;
......@@ -858,7 +859,8 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos,
if( DrawStruct->Type() != TYPE_SCH_COMPONENT )
continue;
LibItem = (SCH_COMPONENT*) DrawStruct;
Entry = FindLibPart( LibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( LibItem->m_ChipName );
if( Entry == NULL )
continue;
Pin = (LibDrawPin*) LocatePin( RefPos, Entry, LibItem->m_Multi,
......
......@@ -130,7 +130,8 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
// removed because with multiple instances of one schematic
// (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 )
continue;
......@@ -549,9 +550,10 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
break;
/* Get the Component FootprintFilter and put the component in CmpList if filter is not void */
EDA_LibComponentStruct* Entry;
if( ( Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString,
FIND_ROOT ) ) != NULL )
EDA_LibComponentStruct* Entry =
( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName );
if( Entry != NULL )
{
if( Entry->m_FootprintList.GetCount() != 0 ) /* Put in list */
{
......@@ -630,7 +632,7 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
for( int ii = 0; ii < CmpListCount; ii++ )
{
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.Replace( wxT( " " ), wxT( "_" ) );
......
......@@ -472,7 +472,8 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist,
case TYPE_SCH_COMPONENT:
DrawLibItem = (SCH_COMPONENT*) DrawList;
Entry = FindLibPart( DrawLibItem->m_ChipName, wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* )FindLibPart(
DrawLibItem->m_ChipName );
if( Entry == NULL )
break;
......
......@@ -251,7 +251,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
EDA_LibComponentStruct* LibEntry;
LibEntry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName );
if( !Component->m_Flags )
{
......@@ -323,7 +323,8 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
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() )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), datasheet_xpm );
}
......
......@@ -57,7 +57,7 @@ static void PlotLibPart( Plotter* plotter, SCH_COMPONENT* DrawLibItem )
wxPoint pos;
bool draw_bgfill = false;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName );
if( Entry == NULL )
return;;
memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
......
......@@ -2,12 +2,13 @@
/* prototypage des fonctions de EESchema */
/*****************************************/
void FreeLibraryEntry(LibCmpEntry * Entry);
LibEDA_BaseStruct* LocatePin( const wxPoint& RefPos,
EDA_LibComponentStruct* Entry,
int Unit,
int Convert,
SCH_COMPONENT* DrawItem = NULL );
LibEDA_BaseStruct * LocatePin(const wxPoint & RefPos,
EDA_LibComponentStruct * Entry,
int Unit, int Convert, SCH_COMPONENT * DrawItem = NULL);
/* Routine de localisation d'une PIN de la PartLib pointee par Entry */
/* Routine de localisation d'une PIN de la PartLib pointee par Entry */
wxString ReturnDefaultFieldName( int aFieldNdx );
......@@ -15,207 +16,258 @@ wxString ReturnDefaultFieldName( int aFieldNdx );
/****************/
/* DATABASE.CPP */
/****************/
void DisplayCmpDoc(wxString & Name);
bool DataBaseGetName(WinEDA_DrawFrame * frame,
wxString & Keys, wxString & BufName);
void DisplayCmpDoc( wxString& Name );
wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys,
wxString& BufName );
/*********************/
/* DANGLING_ENDS.CPP */
/*********************/
bool SegmentIntersect(int Sx1, int Sy1, int Sx2, int Sy2, int Px1, int Py1);
bool SegmentIntersect( int Sx1, int Sy1, int Sx2, int Sy2, int Px1, int Py1 );
/****************/
/* BUS_WIRE_JUNCTION.CPP */
/****************/
void IncrementLabelMember(wxString & name);
void IncrementLabelMember( wxString& name );
/****************/
/* EDITPART.CPP */
/****************/
void InstallCmpeditFrame(WinEDA_SchematicFrame * parent, wxPoint & pos,
SCH_COMPONENT * m_Cmp);
void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos,
SCH_COMPONENT* m_Cmp );
/******************************/
/* EELIBS_DRAW_COMPONENTS.CPP */
/******************************/
int NumOfLibraries();
LibCmpEntry* FindLibPart( const wxChar* Name,
const wxString& LibName = wxEmptyString,
LibrEntryType Alias = ROOT );
void DrawingLibInGhost( WinEDA_DrawPanel* panel,
wxDC* DC,
EDA_LibComponentStruct* LibEntry,
SCH_COMPONENT* DrawLibItem,
int PartX,
int PartY,
int Multi,
int convert,
int Color,
bool DrawPinText );
void DrawLibEntry( WinEDA_DrawPanel* panel,
wxDC* DC,
EDA_LibComponentStruct* LibEntry,
const wxPoint& aOffset,
int Multi,
int convert,
int DrawMode,
int Color = -1 );
void DrawLibraryDrawStruct( WinEDA_DrawPanel* aPanel,
wxDC* aDC,
EDA_LibComponentStruct* aLibEntry,
wxPoint aPosition,
LibEDA_BaseStruct* aDrawItem,
int aDrawMode,
int aColor = -1 );
bool MapAngles( int* Angle1,
int* Angle2,
const int TransMat[2][2] );
/******************************/
/* EELIBS_DRAW_COMPONENTS.CPP */
/******************************/
int LibraryEntryCompare(EDA_LibComponentStruct *LE1, EDA_LibComponentStruct *LE2);
int NumOfLibraries();
EDA_LibComponentStruct *FindLibPart(const wxChar *Name, const wxString & LibName, int Alias = FIND_ROOT);
void DrawingLibInGhost(WinEDA_DrawPanel * panel, wxDC * DC, EDA_LibComponentStruct *LibEntry,
SCH_COMPONENT * DrawLibItem, int PartX, int PartY,
int Multi, int convert,
int Color, bool DrawPinText);
void DrawLibEntry(WinEDA_DrawPanel * panel, wxDC * DC,
EDA_LibComponentStruct *LibEntry, const wxPoint & aOffset,
int Multi, int convert,
int DrawMode, int Color = -1);
void DrawLibraryDrawStruct(WinEDA_DrawPanel * aPanel, wxDC * aDC,
EDA_LibComponentStruct *aLibEntry, wxPoint aPosition,
LibEDA_BaseStruct *aDrawItem,
int aDrawMode, int aColor = -1);
bool MapAngles(int *Angle1, int *Angle2, const int TransMat[2][2]);
/** Function TransformCoordinate
* Calculate the wew coordinate from the old one, according to the transform matrix.
/**
* Calculate new coordinate according to the transform matrix.
*
* @param aTransformMatrix = rotation, mirror .. matrix
* @param aPosition = the position to transform
*
* @return the new coordinate
*/
wxPoint TransformCoordinate( const int aTransformMatrix[2][2], const wxPoint & aPosition );
LibraryStruct *FindLibrary(const wxString & Name);
int LoadDocLib(WinEDA_DrawFrame * frame, const wxString & FullDocLibName, const wxString & Libname);
PriorQue *LoadLibraryAux(WinEDA_DrawFrame * frame, LibraryStruct * library,
FILE *f, int *NumOfParts);
LibraryStruct * LoadLibraryName(WinEDA_DrawFrame * frame,
const wxString & FullLibName, const wxString & LibName);
void LoadLibraries( WinEDA_SchematicFrame* frame );
void FreeCmpLibrary(wxWindow * frame, const wxString & LibName);
void SnapLibItemPoint(int OrigX, int OrigY, int *ClosestX, int *ClosestY,
SCH_COMPONENT *DrawLibItem);
bool LibItemInBox(int x1, int y1, int x2, int y2,
SCH_COMPONENT *DrawLibItem);
char * StrPurge(char * text);
/* Supprime les caracteres Space en debut de la ligne text
retourne un pointeur sur le 1er caractere non Space de text */
/************/
/* BLOCK.CPP */
/************/
SCH_ITEM * DuplicateStruct(SCH_ITEM *DrawStruct);
void DeleteStruct(WinEDA_DrawPanel * panel, wxDC * DC, SCH_ITEM *DrawStruct);
/*************/
/* LOCATE.CPP */
/*************/
LibDrawPin* LocatePinByNumber( const wxString & ePin_Number,
SCH_COMPONENT* eComponent );
SCH_COMPONENT * LocateSmallestComponent( SCH_SCREEN * Screen );
/* Recherche du plus petit (en surface) composant pointe par la souris */
int PickItemsInBlock(BLOCK_SELECTOR& aBlock, BASE_SCREEN* screen );
/* function PickStruct:
Search at location pos
SearchMask = (bitwise OR):
LIBITEM
WIREITEM
BUSITEM
RACCORDITEM
JUNCTIONITEM
DRAWITEM
TEXTITEM
LABELITEM
SHEETITEM
MARKERITEM
NOCONNECTITEM
SEARCH_PINITEM
SHEETLABELITEM
FIELDCMPITEM
wxPoint TransformCoordinate( const int aTransformMatrix[2][2],
const wxPoint& aPosition );
LibraryStruct* FindLibrary( const wxString& Name );
int LoadDocLib( WinEDA_DrawFrame* frame,
const wxString& FullDocLibName,
const wxString& Libname );
LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame,
const wxString& FullLibName,
const wxString& LibName );
void LoadLibraries( WinEDA_SchematicFrame* frame );
void FreeCmpLibrary( wxWindow* frame,
const wxString& LibName );
void SnapLibItemPoint( int OrigX,
int OrigY,
int* ClosestX,
int* ClosestY,
SCH_COMPONENT* DrawLibItem );
bool LibItemInBox( int x1, int y1, int x2, int y2,
SCH_COMPONENT* DrawLibItem );
char* StrPurge( char* text );
/* Supprime les caracteres Space en debut de la ligne text
* retourne un pointeur sur le 1er caractere non Space de text */
if EXCLUDE_WIRE_BUS_ENDPOINTS is set, in wire ou bus search and locate,
start and end points are not included in search
if WIRE_BUS_ENDPOINTS_ONLY is set, in wire ou bus search and locate,
only start and end points are included in search
Return:
-Bloc search:
pointeur sur liste de pointeurs de structures si Plusieurs
structures selectionnees.
pointeur sur la structure si 1 seule
Positon search:
pointeur sur la structure.
Si pas de structures selectionnees: retourne NULL */
SCH_ITEM * PickStruct(const wxPoint & refpos, BASE_SCREEN* screen, int SearchMask);
/************/
/* BLOCK.CPP */
/************/
SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct );
void DeleteStruct( WinEDA_DrawPanel* panel,
wxDC* DC,
SCH_ITEM* DrawStruct );
/*************/
/* LOCATE.CPP */
/*************/
LibDrawPin* LocatePinByNumber( const wxString& ePin_Number,
SCH_COMPONENT* eComponent );
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen );
LibEDA_BaseStruct * LocateDrawItem(SCH_SCREEN * Screen, const wxPoint & refpoint,
EDA_LibComponentStruct * LibEntry, int Unit, int Convert, int masque);
/* Recherche du plus petit (en surface) composant pointe par la souris */
Hierarchical_PIN_Sheet_Struct * LocateSheetLabel(DrawSheetStruct *Sheet, const wxPoint & pos);
LibDrawPin * LocateAnyPin(SCH_ITEM *DrawList, const wxPoint & RefPos,
SCH_COMPONENT ** libpart = NULL );
int PickItemsInBlock( BLOCK_SELECTOR& aBlock,
BASE_SCREEN* screen );
Hierarchical_PIN_Sheet_Struct * LocateAnyPinSheet(const wxPoint & RefPos,
SCH_ITEM *DrawList);
/* function PickStruct:
* Search at location pos
*
* SearchMask = (bitwise OR):
* LIBITEM
* WIREITEM
* BUSITEM
* RACCORDITEM
* JUNCTIONITEM
* DRAWITEM
* TEXTITEM
* LABELITEM
* SHEETITEM
* MARKERITEM
* NOCONNECTITEM
* SEARCH_PINITEM
* SHEETLABELITEM
* FIELDCMPITEM
*
* if EXCLUDE_WIRE_BUS_ENDPOINTS is set, in wire ou bus search and locate,
* start and end points are not included in search
* if WIRE_BUS_ENDPOINTS_ONLY is set, in wire ou bus search and locate,
* only start and end points are included in search
*
*
* Return:
* -Bloc search:
* pointeur sur liste de pointeurs de structures si Plusieurs
* structures selectionnees.
* pointeur sur la structure si 1 seule
*
* Positon search:
* pointeur sur la structure.
* Si pas de structures selectionnees: retourne NULL */
SCH_ITEM* PickStruct( const wxPoint& refpos,
BASE_SCREEN* screen,
int SearchMask );
LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
const wxPoint& refpoint,
EDA_LibComponentStruct* LibEntry,
int Unit,
int Convert,
int masque );
Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet,
const wxPoint& pos );
LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList,
const wxPoint& RefPos,
SCH_COMPONENT** libpart = NULL );
Hierarchical_PIN_Sheet_Struct* LocateAnyPinSheet( const wxPoint& RefPos,
SCH_ITEM* DrawList );
/***************/
/* EEREDRAW.CPP */
/***************/
void DrawDanglingSymbol(WinEDA_DrawPanel * panel,wxDC * DC,
const wxPoint & pos, int Color);
void DrawStructsInGhost(WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem, const wxPoint & aOffset );
void SetHighLightStruct(SCH_ITEM *HighLight);
void RedrawActiveWindow(WinEDA_DrawPanel * panel, wxDC * DC);
void RedrawStructList(WinEDA_DrawPanel * panel, wxDC * DC, SCH_ITEM *Structs, int DrawMode,
int Color = -1);
void RedrawOneStruct(WinEDA_DrawPanel * panel, wxDC * DC, SCH_ITEM *Struct, int DrawMode,
int Color = -1);
void DrawDanglingSymbol( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& pos, int Color );
void DrawStructsInGhost( WinEDA_DrawPanel* aPanel,
wxDC* aDC,
SCH_ITEM* aItem,
const wxPoint& aOffset );
void SetHighLightStruct( SCH_ITEM* HighLight );
void RedrawActiveWindow( WinEDA_DrawPanel* panel, wxDC* DC );
void RedrawStructList( WinEDA_DrawPanel* panel,
wxDC* DC,
SCH_ITEM* Structs,
int DrawMode,
int Color = -1 );
void RedrawOneStruct( WinEDA_DrawPanel* panel,
wxDC* DC,
SCH_ITEM* Struct,
int DrawMode,
int Color = -1 );
/**************/
/* EELAYER.CPP */
/**************/
void SeedLayers();
EDA_Colors ReturnLayerColor(int Layer);
void DisplayColorSetupFrame(WinEDA_DrawFrame * parent, const wxPoint & pos);
void SeedLayers();
EDA_Colors ReturnLayerColor( int Layer );
void DisplayColorSetupFrame( WinEDA_DrawFrame* parent,
const wxPoint& pos );
/*************/
/* EELOAD.CPP */
/*************/
int CountCmpNumber();
int CountCmpNumber();
/***************/
/* EECONFIG.CPP */
/***************/
bool Read_Hotkey_Config( WinEDA_DrawFrame * frame, bool verbose );
bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose );
/**************/
/* SAVELIB.CPP */
/**************/
LibEDA_BaseStruct * CopyDrawEntryStruct( wxWindow * frame, LibEDA_BaseStruct * DrawItem);
/* Routine de Duplication d'une structure DrawLibItem d'une partlib
Parametres d'entree:
DrawEntry = pointeur sur la structure a dupliquer
La structure nouvelle est creee, mais n'est pas inseree dans le
chainage
Retourne:
Pointeur sur la structure creee (ou NULL si impossible) */
LibEDA_BaseStruct* CopyDrawEntryStruct( LibEDA_BaseStruct* DrawItem );
/* Routine de Duplication d'une structure DrawLibItem d'une partlib
* Parametres d'entree:
* DrawEntry = pointeur sur la structure a dupliquer
* La structure nouvelle est creee, mais n'est pas inseree dans le
* chainage
* Retourne:
* Pointeur sur la structure creee (ou NULL si impossible)
*/
EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry );
EDA_LibComponentStruct * CopyLibEntryStruct (wxWindow * frame, EDA_LibComponentStruct * OldEntry);
/* Routine de copie d'une partlib
Parametres d'entree: pointeur sur la structure de depart
Parametres de sortie: pointeur sur la structure creee */
/* Routine de copie d'une partlib
* Parametres d'entree: pointeur sur la structure de depart
* Parametres de sortie: pointeur sur la structure creee */
/***************/
/* SYMBEDIT.CPP */
/***************/
void SuppressDuplicateDrawItem(EDA_LibComponentStruct * LibEntry);
/* Routine de suppression des elements de trace dupliques, situation
frequente lorsque l'on charge des symboles predessines plusieurs fois
pour definir un composant */
void SuppressDuplicateDrawItem( EDA_LibComponentStruct* LibEntry );
/* Routine de suppression des elements de trace dupliques, situation
* frequente lorsque l'on charge des symboles predessines plusieurs fois
* pour definir un composant */
/**************/
/* NETLIST.CPP */
/**************/
int IsBusLabel(const wxString & LabelDrawList);
int IsBusLabel( const wxString& LabelDrawList );
/***************/
/* ANNOTATE.CPP */
......@@ -226,56 +278,62 @@ void ReAnnotatePowerSymbolsOnly();
/************/
/* PLOT.CPP */
/************/
void PlotDrawlist(Plotter *plotter, SCH_ITEM* drawlist );
void PlotDrawlist( Plotter* plotter, SCH_ITEM* drawlist );
/***************/
/* DELSHEET.CPP */
/***************/
void DeleteSubHierarchy(DrawSheetStruct * Sheet, bool confirm_deletion);
bool ClearProjectDrawList(SCH_SCREEN * FirstWindow, bool confirm_deletion);
void DeleteSubHierarchy( DrawSheetStruct* Sheet, bool confirm_deletion );
bool ClearProjectDrawList( SCH_SCREEN* FirstWindow, bool confirm_deletion );
/* free the draw list screen->EEDrawList and the subhierarchies
clear the screen datas (filenames ..)
*/
* clear the screen datas (filenames ..)
*/
/*************/
/* DELETE.CPP */
/*************/
bool LocateAndDeleteItem(WinEDA_SchematicFrame * frame, wxDC * DC);
void EraseStruct(SCH_ITEM *DrawStruct, SCH_SCREEN * Window);
void DeleteAllMarkers(int type);
/* Effacement des marqueurs du type "type" */
bool LocateAndDeleteItem( WinEDA_SchematicFrame* frame, wxDC* DC );
void EraseStruct( SCH_ITEM* DrawStruct, SCH_SCREEN* Window );
void DeleteAllMarkers( int type );
/* Effacement des marqueurs du type "type" */
void DeleteOneLibraryDrawStruct(WinEDA_DrawPanel * panel,
wxDC *DC, EDA_LibComponentStruct * LibEntry,
LibEDA_BaseStruct * DrawItem, int Affiche);
/* Routine d'effacement d'un "LibraryDrawStruct"
(d'un element de dessin d'un composant )
Parametres d'entree
Pointeur sur le composant comportant la structure
(Si NULL la structure a effacer est supposee non rattachee
a un composant)
Pointeur sur la structure a effacer
Affiche (si != 0 Efface le graphique correspondant de l'ecran) */
void DeleteOneLibraryDrawStruct( WinEDA_DrawPanel* panel,
wxDC* DC, EDA_LibComponentStruct* LibEntry,
LibEDA_BaseStruct* DrawItem, int Affiche );
/* Routine d'effacement d'un "LibraryDrawStruct"
* (d'un element de dessin d'un composant )
* Parametres d'entree
* Pointeur sur le composant comportant la structure
* (Si NULL la structure a effacer est supposee non rattachee
* a un composant)
* Pointeur sur la structure a effacer
* Affiche (si != 0 Efface le graphique correspondant de l'ecran) */
/**************/
/* GETPART.CPP */
/**************/
int LookForConvertPart( EDA_LibComponentStruct * LibEntry );
/* Retourne la plus grande valeur trouvee dans la liste des elements
"drawings" du composant LibEntry, pour le membre .Convert
Si il n'y a pas de representation type "convert", la valeur
retournee est 0 ou 1
Si il y a une representation type "convert",
la valeur retournee est > 1 (typiquement 2) */
int LookForConvertPart( EDA_LibComponentStruct* LibEntry );
/* Retourne la plus grande valeur trouvee dans la liste des elements
* "drawings" du composant LibEntry, pour le membre .Convert
* Si il n'y a pas de representation type "convert", la valeur
* retournee est 0 ou 1
* Si il y a une representation type "convert",
* la valeur retournee est > 1 (typiquement 2) */
/**************/
/* PINEDIT.CPP */
/**************/
void InstallPineditFrame(WinEDA_LibeditFrame * parent, wxDC * DC, const wxPoint & pos);
void InstallPineditFrame( WinEDA_LibeditFrame* parent,
wxDC* DC,
const wxPoint& pos );
/**************/
......@@ -292,17 +350,18 @@ void InstallPineditFrame(WinEDA_LibeditFrame * parent, wxDC * DC, const wxPoint
* 1 si composant selectionne
* 0 si commande annulee
*/
int DisplayComponentsNamesInLib(WinEDA_DrawFrame * frame,
LibraryStruct *Library, wxString & Buffer, wxString & OldName);
int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
LibraryStruct* Library,
wxString& Buffer,
wxString& OldName );
/**
* Function SelectLibraryFromList
* displays a list of current loaded libraries, and allows the user to select a library
* displays a list of current loaded libraries, and allows the user to select
* a library
* This list is sorted, with the library cache always at end of the list
*/
LibraryStruct * SelectLibraryFromList(WinEDA_DrawFrame * frame);
LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame );
/**
* Function GetNameOfPartToLoad
......@@ -315,29 +374,31 @@ LibraryStruct * SelectLibraryFromList(WinEDA_DrawFrame * frame);
* place le nom du composant a charger, selectionne a partir d'une liste dans
* BufName
*/
int GetNameOfPartToLoad(WinEDA_DrawFrame * frame, LibraryStruct * Lib,
wxString & BufName);
int GetNameOfPartToLoad( WinEDA_DrawFrame* frame,
LibraryStruct* Lib,
wxString& BufName );
/**************/
/* LIBARCH.CPP */
/**************/
/**************/
/* LIBARCH.CPP */
/**************/
bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName );
bool LibArchive(wxWindow * frame, const wxString & ArchFullFileName);
/**************/
/* CLEANUP.CPP */
/**************/
void SchematicCleanUp( SCH_SCREEN* screen, wxDC* DC );
/**************/
/* CLEANUP.CPP */
/**************/
/* Routine de nettoyage:
* - regroupe les segments de fils (ou de bus) alignes en 1 seul segment
* - Detecte les objets identiques superposes
*/
void SchematicCleanUp(SCH_SCREEN * screen, wxDC * DC);
/* Routine de nettoyage:
- regroupe les segments de fils (ou de bus) alignes en 1 seul segment
- Detecte les objets identiques superposes
*/
void BreakSegmentOnJunction( SCH_SCREEN* Screen );
void BreakSegmentOnJunction( SCH_SCREEN * Screen );
/* Routine creant des debuts / fin de segment (BUS ou WIRES) sur les jonctions
et les raccords */
/* Routine creant des debuts / fin de segment (BUS ou WIRES) sur les jonctions
* et les raccords */
/* Break a segment ( BUS, WIRE ) int 2 segments at location aBreakpoint,
* if aBreakpoint in on segment segment
......@@ -345,30 +406,31 @@ void BreakSegmentOnJunction( SCH_SCREEN * Screen );
*/
void BreakSegment(SCH_SCREEN * aScreen, wxPoint aBreakpoint );
/**************/
/* EECLASS.CPP */
/**************/
/**************/
/* EECLASS.CPP */
/**************/
void SetaParent(EDA_BaseStruct * Struct, BASE_SCREEN * Screen);
void SetaParent( EDA_BaseStruct* Struct, BASE_SCREEN* Screen );
/***************/
/* LIBALIAS.CPP */
/***************/
/***************/
/* LIBALIAS.CPP */
/***************/
bool BuildAliasData( LibraryStruct* Lib, EDA_LibComponentStruct* component );
bool BuildAliasData(LibraryStruct * Lib, EDA_LibComponentStruct * component);
/* Create the alias data for the lib component to edit */
int LocateAlias( const wxArrayString & AliasData, const wxString & Name);
/* Return an index in alias data list ( -1 if not found ) */
/* Create the alias data for the lib component to edit */
int LocateAlias( const wxArrayString& AliasData, const wxString& Name );
/* Return an index in alias data list ( -1 if not found ) */
/***************/
/* OPTIONS.CPP */
/***************/
void DisplayOptionFrame( WinEDA_SchematicFrame* parent,
const wxPoint& framepos );
const wxPoint& framepos );
/****************/
/* CONTROLE.CPP */
/****************/
void RemoteCommand( const char* cmdline );
......@@ -28,11 +28,10 @@
* A better way to duplicate a DrawLibItem is to have a virtual GenCopy() in
* LibEDA_BaseStruct class (ToDo).
*/
LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame,
LibEDA_BaseStruct* DrawItem )
LibEDA_BaseStruct* CopyDrawEntryStruct( LibEDA_BaseStruct* DrawItem )
{
LibEDA_BaseStruct* NewDrawItem = NULL;
wxString msg;
LibEDA_BaseStruct* NewDrawItem = NULL;
switch( DrawItem->Type() )
{
......@@ -67,7 +66,7 @@ LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame,
default:
msg.Printf( wxT( "CopyDrawLibEntryStruct: unknown Draw Type %d" ),
DrawItem->Type() );
DisplayError( frame, msg );
wxLogError( msg );
break;
}
......@@ -81,9 +80,9 @@ LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame,
* Parametres de sortie: pointeur sur la structure creee
* Do not copy new items ( i.e. with m_Flag & IS_NEW)
*/
EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
EDA_LibComponentStruct* OldEntry )
EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry )
{
wxString msg;
EDA_LibComponentStruct* NewStruct;
LibEDA_BaseStruct* NewDrawings, * OldDrawings;
LibEDA_BaseStruct* LastItem;
......@@ -91,7 +90,9 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
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;
}
......@@ -126,10 +127,10 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
for( OldDrawings = OldEntry->m_Drawings; OldDrawings != NULL;
OldDrawings = OldDrawings->Next() )
{
if( ( OldDrawings->m_Flags & IS_NEW) != 0 )
if( ( OldDrawings->m_Flags & IS_NEW ) != 0 )
continue;
NewDrawings = CopyDrawEntryStruct( frame, OldDrawings );
NewDrawings = CopyDrawEntryStruct( OldDrawings );
if( NewDrawings )
{
if( LastItem == NULL )
......@@ -140,11 +141,15 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
LastItem = NewDrawings;
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
// of OldDrawings
// 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;
}
}
......
......@@ -620,10 +620,10 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event )
if( screen->GetCurItem() == NULL )
break;
{
EDA_LibComponentStruct* LibEntry;
LibCmpEntry* LibEntry;
LibEntry = FindLibPart(
( (SCH_COMPONENT*) screen->GetCurItem() )->m_ChipName.GetData(),
wxEmptyString, FIND_ALIAS );
( (SCH_COMPONENT*) screen->GetCurItem() )->m_ChipName,
wxEmptyString, ALIAS );
if( LibEntry && LibEntry->m_DocFile != wxEmptyString )
{
GetAssociatedDocument( this, LibEntry->m_DocFile ,
......
......@@ -72,16 +72,14 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame )
}
/******************************************************************************************/
int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
LibraryStruct* Library, wxString& Buffer, wxString& OldName )
/******************************************************************************************/
LibraryStruct* Library,
wxString& Buffer, wxString& OldName )
{
int ii;
wxString msg;
EDA_LibComponentStruct* LibEntry;
WinEDAListBox* ListBox;
const wxChar** ListNames;
size_t i;
wxString msg;
wxArrayString nameList;
const wxChar** ListNames;
if( Library == NULL )
Library = SelectLibraryFromList( frame );
......@@ -89,44 +87,32 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
if( Library == NULL )
return 0;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE );
Library->GetEntryNames( nameList );
ii = 0;
while( LibEntry )
{
ii++;
LibEntry = (EDA_LibComponentStruct*) PQNext( Library->m_Entries, LibEntry, NULL );
}
ListNames = (const wxChar**) MyZMalloc( (ii + 1) * sizeof(wxChar*) );
ListNames = (const wxChar**) MyZMalloc( ( nameList.GetCount() + 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;
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE );
while( LibEntry )
{
ListNames[ii++] = LibEntry->m_Name.m_Text.GetData();
LibEntry = (EDA_LibComponentStruct*) PQNext( Library->m_Entries, LibEntry, NULL );
}
for( i = 0; i < nameList.GetCount(); i++ )
ListNames[i] = (const wxChar*) nameList[i];
// Qsort(ListNames,StrNumICmp);
WinEDAListBox dlg( frame, msg, ListNames, OldName, DisplayCmpDoc,
wxColour( 255, 255, 255 ) );
ListBox = new WinEDAListBox( frame, msg,
ListNames, OldName, DisplayCmpDoc,
wxColour( 255, 255, 255 ) ); // Component background listbox color
dlg.MoveMouseToOrigin();
ListBox->MoveMouseToOrigin();
int rsp = dlg.ShowModal();
ii = ListBox->ShowModal(); ListBox->Destroy();
if( ii >= 0 )
Buffer = ListNames[ii];
if( rsp >= 0 )
Buffer = ListNames[rsp];
free( ListNames );
if( ii < 0 )
if( rsp < 0 )
return 0;
return 1;
}
......
......@@ -2,7 +2,7 @@
/* Functions to Load from file and save to file */
/* the graphic shapes used to draw a component */
/* When using the import/export symbol options */
/* files are the *.sym files */
/* files are the *.sym files */
/*************************************************/
/* fichier symbedit.cpp */
......@@ -29,27 +29,25 @@ static bool CompareSymbols( LibEDA_BaseStruct* DEntryRef,
/* Variables locales */
/***********************************************/
void WinEDA_LibeditFrame::LoadOneSymbol( void )
/***********************************************/
/* Read a component shape file (a symbol file *.sym )and add data (graphic items) to the current
* component.
* a symbol file *.sym has the same format as a library, and contains only one symbol
/*
* Read a component shape file (a symbol file *.sym )and add data (graphic
* items) to the current component.
*
* A symbol file *.sym has the same format as a library, and contains only
* one symbol
*/
void WinEDA_LibeditFrame::LoadOneSymbol( void )
{
int NumOfParts;
PriorQue* Entries;
EDA_LibComponentStruct* LibEntry = NULL;
EDA_LibComponentStruct* Component;
LibEDA_BaseStruct* DrawEntry;
wxString FullFileName, mask;
FILE* ImportFile;
wxString msg;
if( CurrentLibEntry == NULL )
return;
if( CurrentDrawItem && CurrentDrawItem->m_Flags ) // a command is in progress
wxString FullFileName, mask;
FILE* ImportFile;
wxString msg, err;
LibraryStruct* Lib;
/* Exit if no library entry is selected or a command is in progress. */
if( CurrentLibEntry == NULL
|| ( CurrentDrawItem && CurrentDrawItem->m_Flags ) )
return;
DrawPanel->m_IgnoreMouseEvents = TRUE;
......@@ -75,83 +73,96 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void )
return;
wxFileName fn = FullFileName;
wxGetApp().SaveLastVisitedLibraryPath(fn.GetPath() );
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
/* Load data */
ImportFile = wxFopen( FullFileName, wxT( "rt" ) );
if( ImportFile == NULL )
{
msg.Printf( _( "Failed to open Symbol File <%s>" ), FullFileName.GetData() );
DisplayError( this, msg, 20 );
msg.Printf( _( "Failed to open Symbol File <%s>" ),
(const wxChar*) FullFileName );
DisplayError( this, msg );
return;
}
Lib = new LibraryStruct( LIBRARY_TYPE_SYMBOL, fn.GetName(),
fn.GetFullPath() );
if( !Lib->Load( err ) )
{
msg.Printf( _( "Error <%s> occurred loading symbol library <%s>." ),
(const wxChar*) err, (const wxChar*) fn.GetName() );
DisplayError( this, msg );
fclose( ImportFile );
delete Lib;
return;
}
Entries = LoadLibraryAux( this, NULL, ImportFile, &NumOfParts );
fclose( ImportFile );
if( Entries == NULL )
if( Lib->IsEmpty() )
{
msg.Printf( _( "No components found in symbol library <%s>." ),
(const wxChar*) fn.GetName() );
delete Lib;
return;
}
if( NumOfParts > 1 )
DisplayError( this, _( "Warning: more than 1 part in Symbol File" ), 20 );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Entries, FALSE );
if( Lib->m_NumOfParts > 1 )
DisplayError( this, _( "Warning: more than 1 part in Symbol File" ) );
if( LibEntry == NULL )
DisplayError( this, _( "Symbol File is void" ), 20 );
Component = (EDA_LibComponentStruct*) Lib->GetFirstEntry();
DrawEntry = Component->m_Drawings;
else /* add data to the current symbol */
while( DrawEntry )
{
DrawEntry = LibEntry->m_Drawings;
while( DrawEntry )
if( DrawEntry->m_Unit )
DrawEntry->m_Unit = CurrentUnit;
if( DrawEntry->m_Convert )
DrawEntry->m_Convert = CurrentConvert;
DrawEntry->m_Flags = IS_NEW;
DrawEntry->m_Selected = IS_SELECTED;
if( DrawEntry->Next() == NULL ) /* Fin de liste trouvee */
{
if( DrawEntry->m_Unit )
DrawEntry->m_Unit = CurrentUnit;
if( DrawEntry->m_Convert )
DrawEntry->m_Convert = CurrentConvert;
DrawEntry->m_Flags = IS_NEW;
DrawEntry->m_Selected = IS_SELECTED;
if( DrawEntry->Next() == NULL )
{ /* Fin de liste trouvee */
DrawEntry->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = LibEntry->m_Drawings;
LibEntry->m_Drawings = NULL;
break;
}
DrawEntry = DrawEntry->Next();
DrawEntry->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = Component->m_Drawings;
Component->m_Drawings = NULL;
break;
}
// Remove duplicated drawings:
SuppressDuplicateDrawItem( CurrentLibEntry );
// crear flags
DrawEntry = CurrentLibEntry->m_Drawings;
while( DrawEntry )
{
DrawEntry->m_Flags = 0;
DrawEntry->m_Selected = 0;
DrawEntry = DrawEntry->Next();
}
DrawEntry = DrawEntry->Next();
}
GetScreen()->SetModify();
// Remove duplicated drawings:
SuppressDuplicateDrawItem( CurrentLibEntry );
DrawPanel->Refresh();
// Clear flags
DrawEntry = CurrentLibEntry->m_Drawings;
while( DrawEntry )
{
DrawEntry->m_Flags = 0;
DrawEntry->m_Selected = 0;
DrawEntry = DrawEntry->Next();
}
PQFreeFunc( Entries, ( void( * ) ( void* ) )FreeLibraryEntry );
GetScreen()->SetModify();
DrawPanel->Refresh();
delete Lib;
}
/********************************************/
void WinEDA_LibeditFrame::SaveOneSymbol()
/********************************************/
/* Save in file the current symbol
* file format is like the standard libraries, but there is only one symbol
* Invisible pins are not saved
/*
* Save in file the current symbol.
*
* The symbol file format is like the standard libraries, but there is only
* one symbol.
*
* Invisible pins are not saved
*/
void WinEDA_LibeditFrame::SaveOneSymbol()
{
EDA_LibComponentStruct* LibEntry = CurrentLibEntry;
int Unit = CurrentUnit, convert = CurrentConvert;
......@@ -167,7 +178,7 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
wxString default_lib_path = wxGetApp().ReturnLastVisitedLibraryPath();
mask = wxT( "*" ) + g_SymbolExtBuffer;
FullFileName = EDA_FileSelector( _( "Export symbol drawings:" ),
default_lib_path, /* Chemin par defaut */
default_lib_path, /* Chemin par defaut */
wxEmptyString, /* nom fichier par defaut */
g_SymbolExtBuffer, /* extension par defaut */
mask, /* Masque d'affichage */
......@@ -179,7 +190,7 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
return;
wxFileName fn = FullFileName;
wxGetApp().SaveLastVisitedLibraryPath(fn.GetPath() );
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
ExportFile = wxFopen( FullFileName, wxT( "wt" ) );
if( ExportFile == NULL )
......@@ -195,17 +206,19 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
/* Creation de l'entete de la librairie */
char Line[256];
fprintf( ExportFile, "%s %d.%d %s Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR,
"SYMBOL", DateAndTime( Line ) );
LIB_VERSION_MAJOR, LIB_VERSION_MINOR,
"SYMBOL", DateAndTime( Line ) );
/* Creation du commentaire donnant le nom du composant */
fprintf( ExportFile, "# SYMBOL %s\n#\n",
(const char*) LibEntry->m_Name.m_Text.GetData() );
(const char*) LibEntry->m_Name.m_Text.GetData() );
/* Generation des lignes utiles */
fprintf( ExportFile, "DEF %s", (const char*) LibEntry->m_Name.m_Text.GetData() );
fprintf( ExportFile, "DEF %s",
(const char*) LibEntry->m_Name.m_Text.GetData() );
if( !LibEntry->m_Prefix.m_Text.IsEmpty() )
fprintf( ExportFile, " %s", (const char*) LibEntry->m_Prefix.m_Text.GetData() );
fprintf( ExportFile, " %s",
(const char*) LibEntry->m_Prefix.m_Text.GetData() );
else
fprintf( ExportFile, " ~" );
......@@ -229,11 +242,13 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
/* Elimination des elements non relatifs a l'unite */
if( Unit && DrawEntry->m_Unit && (DrawEntry->m_Unit != Unit) )
continue;
if( convert && DrawEntry->m_Convert && (DrawEntry->m_Convert != convert) )
if( convert && DrawEntry->m_Convert
&& (DrawEntry->m_Convert != convert) )
continue;
DrawEntry->Save( ExportFile );
}
fprintf( ExportFile, "ENDDRAW\n" );
}
fprintf( ExportFile, "ENDDEF\n" );
......@@ -241,17 +256,16 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
}
/*****************************************************************/
void SuppressDuplicateDrawItem( EDA_LibComponentStruct* LibEntry )
/*****************************************************************/
/* Delete redundant graphic items.
* Useful after loading asymbole from a file symbol, because some graphic items
* can be duplicated.
/*
* Delete redundant graphic items.
*
* Useful after loading asymbole from a file symbol, because some graphic items
* can be duplicated.
*/
void SuppressDuplicateDrawItem( EDA_LibComponentStruct* LibEntry )
{
LibEDA_BaseStruct* DEntryRef, * DEntryCompare;
bool deleted;
bool deleted;
wxDC* DC = NULL;
DEntryRef = LibEntry->m_Drawings;
......@@ -282,15 +296,14 @@ void SuppressDuplicateDrawItem( EDA_LibComponentStruct* LibEntry )
}
/********************************************************************/
/*
* Compare 2 graphic items (arc, lines ...).
*
* return FALSE if different
* TRUE if they are identical, and therefore redundant
*/
static bool CompareSymbols( LibEDA_BaseStruct* DEntryRef,
LibEDA_BaseStruct* DEntryCompare )
/********************************************************************/
/* Compare 2 graphic items (arc, lines ...).
* return FALSE si different
* TRUE si they are identical, and therefore redundant
*/
{
/* Comparaison des proprietes generales */
if( DEntryRef->Type() != DEntryCompare->Type() )
......@@ -393,7 +406,6 @@ static bool CompareSymbols( LibEDA_BaseStruct* DEntryRef,
/* pour repositionner le point repere par le curseur souris au point */
/* d'ancrage ( coord 0,0 ). */
/***************************************************************************/
void WinEDA_LibeditFrame::PlaceAncre()
{
EDA_LibComponentStruct* LibEntry;
......@@ -403,14 +415,14 @@ void WinEDA_LibeditFrame::PlaceAncre()
if( LibEntry == NULL )
return;
wxSize offset( -GetScreen()->m_Curseur.x, GetScreen()->m_Curseur.y );
wxSize offset( -GetScreen()->m_Curseur.x, GetScreen()->m_Curseur.y );
GetScreen()->SetModify();
LibEntry->m_Name.m_Pos += offset;
LibEntry->m_Prefix.m_Pos += offset;
for( LibDrawField* field = LibEntry->m_Fields; field; field = field->Next() )
for( LibDrawField* field = LibEntry->m_Fields; field; field = field->Next() )
{
field->m_Pos += offset;
}
......@@ -423,9 +435,9 @@ void WinEDA_LibeditFrame::PlaceAncre()
case COMPONENT_ARC_DRAW_TYPE:
#undef STRUCT
#define STRUCT ( (LibDrawArc*) DrawEntry )
STRUCT->m_Pos += offset;
STRUCT->m_ArcStart += offset;
STRUCT->m_ArcEnd += offset;
STRUCT->m_Pos += offset;
STRUCT->m_ArcStart += offset;
STRUCT->m_ArcEnd += offset;
break;
case COMPONENT_CIRCLE_DRAW_TYPE:
......@@ -456,8 +468,9 @@ void WinEDA_LibeditFrame::PlaceAncre()
case COMPONENT_POLYLINE_DRAW_TYPE:
#undef STRUCT
#define STRUCT ( (LibDrawPolyline*) DrawEntry )
for( unsigned ii = 0; ii < STRUCT->GetCornerCount(); ii ++ )
for( unsigned ii = 0; ii < STRUCT->GetCornerCount(); ii++ )
STRUCT->m_PolyPoints[ii] += offset;
break;
default:
......
......@@ -28,14 +28,16 @@ void WinEDA_ViewlibFrame::ReCreateHToolbar()
if( (g_CurrentViewLibraryName != wxEmptyString)
&& (g_CurrentViewComponentName != wxEmptyString) )
{
RootLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName.GetData(),
FIND_ROOT );
RootLibEntry =
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName );
if( RootLibEntry && LookForConvertPart( RootLibEntry ) > 1 )
asdeMorgan = TRUE;
CurrentLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName.GetData(),
FIND_ALIAS );
CurrentLibEntry =
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName,
ALIAS );
}
if( m_HToolBar == NULL )
......
......@@ -273,8 +273,9 @@ int WinEDA_ViewlibFrame::BestZoom()
wxSize size, itemsize;
EDA_LibComponentStruct* CurrentLibEntry = NULL;
CurrentLibEntry = FindLibPart( g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName.GetData(), FIND_ROOT );
CurrentLibEntry =
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName );
if( CurrentLibEntry == NULL )
{
......@@ -314,7 +315,7 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
return;
m_LibList->Clear();
wxArrayString libNamesList;
for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{
......@@ -323,13 +324,13 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
else
libNamesList.Add( Lib->m_Name );
}
libNamesList.Sort();
// Add lib cache
if ( libcache )
libNamesList.Add( libcache->m_Name );
m_LibList->Append(libNamesList);
// Search for a previous selection:
......@@ -358,29 +359,22 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
}
/***********************************************/
void WinEDA_ViewlibFrame::ReCreateListCmp()
/***********************************************/
{
if( m_CmpList == NULL )
return;
int ii;
EDA_LibComponentStruct* LibEntry = NULL;
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
wxArrayString nameList;
m_CmpList->Clear();
ii = 0;
g_CurrentViewComponentName.Empty();
g_ViewConvert = 1; /* Select normal/"de morgan" shape */
g_ViewUnit = 1; /* Selec unit to display for multiple parts per package */
g_ViewConvert = 1; /* Select normal/"de morgan" shape */
g_ViewUnit = 1; /* Select unit to display for multiple
* parts per package */
if( Library )
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE );
while( LibEntry )
{
m_CmpList->Append( LibEntry->m_Name.m_Text );
LibEntry = (EDA_LibComponentStruct*) PQNext( Library->m_Entries, LibEntry, NULL );
}
Library->GetEntryNames( nameList );
m_CmpList->Append( nameList );
}
......
......@@ -57,8 +57,10 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_LIBVIEW_VIEWDOC:
LibEntry = FindLibPart( g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName.GetData(), FIND_ALIAS );
LibEntry =
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName,
ALIAS );
if( LibEntry && ( !LibEntry->m_DocFile.IsEmpty() ) )
GetAssociatedDocument( this, LibEntry->m_DocFile,
& wxGetApp().GetLibraryPathList());
......@@ -182,10 +184,9 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option )
return;
}
EDA_LibComponentStruct* LibEntry = FindLibPart(
g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName,
FIND_ALIAS );
LibCmpEntry* LibEntry = FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName,
ALIAS );
if( LibEntry == NULL )
return;
......@@ -203,10 +204,10 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option )
/*************************************************/
void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
{
int NumOfParts = 0;
EDA_LibComponentStruct* LibEntry, * PreviousLibEntry;
wxString CmpName;
wxClientDC dc( DrawPanel );
int NumOfParts = 0;
LibCmpEntry* LibEntry;
wxString CmpName;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
......@@ -223,9 +224,6 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
if( Lib == NULL )
return;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
if( Flag == NEW_PART )
{
DisplayComponentsNamesInLib( this,
......@@ -236,54 +234,24 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
if( Flag == NEXT_PART )
{
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
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 );
}
LibEntry = Lib->GetNextEntry( g_CurrentViewComponentName );
if( LibEntry == NULL )
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries,
FALSE );
if( LibEntry )
CmpName = LibEntry->m_Name.m_Text;
}
if( Flag == PREVIOUS_PART )
{
PreviousLibEntry = NULL;
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
while( LibEntry )
{
if( LibEntry->m_Name.m_Text == g_CurrentViewComponentName )
{
if( PreviousLibEntry )
break;
LibEntry = Lib->GetPreviousEntry( g_CurrentViewComponentName );
/* else : pointage sur 1er element :
* balayage de la liste et Previous pointera dernier element */
}
PreviousLibEntry = LibEntry;
LibEntry = (EDA_LibComponentStruct*)
PQNext( Lib->m_Entries, LibEntry, NULL );
}
if( PreviousLibEntry )
CmpName = PreviousLibEntry->m_Name.m_Text;
if( LibEntry )
CmpName = LibEntry->m_Name.m_Text;
}
g_ViewUnit = 1;
g_ViewConvert = 1;
LibEntry = FindLibPart( CmpName.GetData(), Lib->m_Name, FIND_ALIAS );
LibEntry = Lib->FindEntry( CmpName );
g_CurrentViewComponentName = CmpName;
DisplayLibInfos();
Zoom_Automatique( FALSE );
......@@ -312,8 +280,10 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
ActiveScreen = GetScreen();
LibEntry = FindLibPart( g_CurrentViewComponentName.GetData(),
g_CurrentViewLibraryName, FIND_ALIAS );
LibEntry =
( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName,
g_CurrentViewLibraryName,
ALIAS );
ViewCmpEntry = (LibCmpEntry*) LibEntry;
/* Forcage de la reinit de la brosse et plume courante */
......@@ -335,9 +305,10 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName.GetData();
Msg.Printf( _( "Current Part: <%s> (is Alias of <%s>)" ),
CmpName, RootName );
LibEntry = FindLibPart( RootName,
g_CurrentViewLibraryName,
FIND_ROOT );
LibEntry =
( EDA_LibComponentStruct* ) FindLibPart( RootName,
g_CurrentViewLibraryName,
ROOT );
if( LibEntry == NULL )
{
......
......@@ -20,6 +20,7 @@ class SCH_ITEM;
class DrawNoConnectStruct;
class LibraryStruct;
class EDA_LibComponentStruct;
class LibCmpEntry;
class LibEDA_BaseStruct;
class EDA_BaseStruct;
class DrawBusEntryStruct;
......@@ -507,9 +508,8 @@ private:
bool LoadOneLibraryPart();
void SaveActiveLibrary();
int LoadOneLibraryPartAux( EDA_LibComponentStruct* LibEntry,
LibraryStruct* Library,
int noMsg = 0 );
bool LoadOneLibraryPartAux( LibCmpEntry* LibEntry,
LibraryStruct* Library );
void DisplayCmpDoc( const wxString& Name );
void InstallLibeditFrame();
......@@ -560,7 +560,6 @@ public:
void HandleBlockPlace( wxDC* DC );
int HandleBlockEnd( wxDC* DC );
void DeletePartInLib( LibraryStruct* Library, EDA_LibComponentStruct* Entry );
void PlacePin( wxDC* DC );
void InitEditOnePin();
void GlobalSetPins( wxDC* DC, LibDrawPin* MasterPin, int id );
......
......@@ -50,7 +50,8 @@ class Plotter;
enum id_librarytype {
LIBRARY_TYPE_EESCHEMA,
LIBRARY_TYPE_PCBNEW,
LIBRARY_TYPE_DOC
LIBRARY_TYPE_DOC,
LIBRARY_TYPE_SYMBOL
};
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