Commit b739b227 authored by stambaughw's avatar stambaughw

Schematic library component objects can now load themselves.

This is the first in a series of updates to the schematic library component
object code.  The goal is to eliminate the external manipulation of these
objects and push this code back into the objects themselves.  Also replace
the priority queue and internal linked list implementations with DLIST or
Boost pointer containers.
parent 5bf0a259
......@@ -350,7 +350,7 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
if( strcmp( p, "DEF" ) != 0 )
{
errorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ),
errorMsg.Printf( _( "DEF command expected in line %d, aborted." ),
*lineNum );
return false;
}
......@@ -372,7 +372,7 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_UnitCount: */
|| sscanf( p, "%d", &m_UnitCount ) != 1 )
{
errorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
errorMsg.Printf( _( "Wrong DEF format in line %d, skipped." ),
*lineNum );
while( GetLine( file, line, lineNum, 1024 ) )
{
......@@ -422,29 +422,27 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
if( (line[0] == 'T') && (line[1] == 'i') )
Res = LoadDateAndTime( line );
else if( line[0] == 'F' )
Res = LoadField( strcat( p, line ), errorMsg );
Res = LoadField( line, Msg );
else if( strcmp( p, "ENDDEF" ) == 0 )
break;
else if( strcmp( p, "DRAW" ) == 0 )
Res = LoadDrawEntries( file, line, lineNum, errorMsg );
Res = LoadDrawEntries( file, line, lineNum, Msg );
else if( strncmp( p, "ALIAS", 5 ) == 0 )
{
p = strtok( NULL, "\r\n" );
Res = LoadAliases( p, errorMsg );
}
else if( strncmp( p, "$FPLIST", 5 ) == 0 )
Res = LoadFootprints( file, line, lineNum, errorMsg );
Res = LoadFootprints( file, line, lineNum, Msg );
/* End line or block analysis: test for an error */
if( !Res )
{
Msg.Printf( wxT( "%d " ), *lineNum );
if( errorMsg.IsEmpty() )
errorMsg = wxT( "error at line " ) + Msg;
if( Msg.IsEmpty() )
errorMsg.Printf( wxT( "error occurred at line %d " ), *lineNum );
else
errorMsg = wxT( "error <" ) + errorMsg +
wxT( "> at line " ) + Msg;
errorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
( const wxChar* ) Msg, *lineNum );
return false;
}
}
......@@ -459,7 +457,6 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
int* lineNum, wxString& errorMsg )
{
bool entryLoaded;
LibEDA_BaseStruct* newEntry = NULL;
LibEDA_BaseStruct* headEntry = NULL;
LibEDA_BaseStruct* tailEntry = NULL;
......@@ -468,7 +465,7 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
{
if( GetLine( f, line, lineNum, 1024 ) == NULL )
{
errorMsg = wxT( "File ended prematurely" );
errorMsg = _( "file ended prematurely loading component draw element" );
return false;
}
......@@ -481,46 +478,38 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
{
case 'A': /* Arc */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawArc(this);
entryLoaded = newEntry->Load( line, errorMsg );
break;
case 'C': /* Circle */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawCircle(this);
entryLoaded = newEntry->Load( line, errorMsg );
break;
case 'T': /* Text */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawText(this);
entryLoaded = newEntry->Load( line, errorMsg );
break;
case 'S': /* Square */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawSquare(this);
entryLoaded = newEntry->Load( line, errorMsg );
break;
case 'X': /* Pin Description */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawPin(this);
entryLoaded = newEntry->Load( line, errorMsg );
break;
case 'P': /* Polyline */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawPolyline(this);
entryLoaded = newEntry->Load( line, errorMsg );
break;
default:
errorMsg.Printf( wxT( "Undefined DRAW command in line %d\n%s, aborted." ),
*lineNum, line );
errorMsg.Printf( _( "undefined DRAW command %c" ), line[0] );
m_Drawings = headEntry;
return false;
}
if( !entryLoaded )
if( !newEntry->Load( line, errorMsg ) )
{
errorMsg.Printf( wxT( "> in DRAW command %c in line %d" ), line[0],
*lineNum );
errorMsg = wxT( "Error <" ) + errorMsg + wxT( ", aborted." );
errorMsg.Printf( _( "error <%s> in DRAW command %c" ),
( const wxChar* ) errorMsg, line[0] );
SAFE_DELETE( newEntry );
/* Flush till end of draw section */
......@@ -528,13 +517,12 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
{
if( GetLine( f, line, lineNum, 1024 ) == NULL )
{
errorMsg = wxT( "File ended prematurely while attempting \
errorMsg = _( "file ended prematurely while attempting \
to flush to end of drawing section." );
return false;
}
} while( strncmp( line, "ENDDRAW", 7 ) != 0 );
SAFE_DELETE( headEntry );
return false;
}
......@@ -550,6 +538,7 @@ to flush to end of drawing section." );
}
}
m_Drawings = headEntry;
return true;
}
......@@ -570,7 +559,7 @@ bool EDA_LibComponentStruct::LoadAliases( char* line, wxString& errorMsg )
bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg )
{
LibDrawField* field = new LibDrawField(this);
LibDrawField* field = new LibDrawField( this );
if ( !field->Load( line, errorMsg ) )
{
......@@ -579,11 +568,19 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg )
}
if( field->m_FieldId == REFERENCE )
field = &m_Prefix;
{
m_Prefix = *field;
SAFE_DELETE( field );
}
else if ( field->m_FieldId == VALUE )
field = &m_Name;
{
m_Name = *field;
SAFE_DELETE( field );
}
else
{
m_Fields.PushBack( field );
}
return true;
}
......@@ -592,7 +589,7 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg )
bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line,
int* lineNum, wxString& errorMsg )
{
while( stricmp( line, "$ENDFPLIST" ) != 0 )
while( true )
{
if( GetLine( file, line, lineNum, 1024 ) == NULL )
{
......@@ -600,6 +597,9 @@ bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line,
return false;
}
if( stricmp( line, "$ENDFPLIST" ) == 0 )
break;
m_FootprintList.Add( CONV_FROM_UTF8( line + 1 ) );
}
......@@ -690,7 +690,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields
aFields[REFERENCE].Copy( &m_Prefix );
// Remove others fields:
CurrentLibEntry->m_Fields.DeleteAll();
m_Fields.DeleteAll();
for( unsigned ii = FOOTPRINT; ii < aFields.size(); ii++ )
{
......@@ -704,7 +704,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields
{
LibDrawField*Field = new LibDrawField( this, ii );
aFields[ii].Copy( Field );
CurrentLibEntry->m_Fields.PushBack( Field );
m_Fields.PushBack( Field );
}
}
......@@ -714,8 +714,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields
* text is like a void text and for non editable names, remove the name
* (set to the default name)
*/
for( LibDrawField* Field = CurrentLibEntry->m_Fields; Field;
Field = Field->Next() )
for( LibDrawField* Field = m_Fields; Field; Field = Field->Next() )
{
Field->SetParent( this );
if( Field->m_FieldId >= FIELD1 )
......
/****************************************************************/
/* Headers fo lib component (or libentry) definitions */
/****************************************************************/
/******************************************/
/* Library component object definitions. */
/******************************************/
#ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H
......@@ -25,8 +25,11 @@ enum LibrEntryOptions {
};
/* basic class to describe components in libraries (true component or alias),
* non used directly */
/**
* Base class to describe library components and aliases.
*
* This class is not to be used directly.
*/
class LibCmpEntry : public EDA_BaseStruct
{
public:
......@@ -36,7 +39,7 @@ public:
wxString m_Doc; /* documentation for info */
wxString m_KeyWord; /* keyword list (used to select a group of
* components by keyword) */
wxString m_DocFile; /* Associed doc filename */
wxString m_DocFile; /* Associate doc file name */
LibrEntryOptions m_Options; // special features (i.e. Entry is a POWER)
public:
......@@ -49,18 +52,23 @@ public:
/**
* Function SaveDoc
* writes the doc info out to a FILE in "*.dcm" format.
* Writes the doc info out 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 );
};
/*********************************************/
/* class to handle an usual component in lib */
/*********************************************/
/**
* Library component object definition.
*
* A library component object is typically save and loaded in a component
* library file (.lib). Library components are different from schematic
* components.
*/
class EDA_LibComponentStruct : public LibCmpEntry
{
public:
......@@ -70,7 +78,7 @@ public:
* for the component (wildcard names
* accepted) */
int m_UnitCount; /* Units (or sections) per package */
bool m_UnitSelectionLocked; /* True if units are differents
bool m_UnitSelectionLocked; /* True if units are different
* and their selection is
* locked (i.e. if part A cannot
* be automatically changed in
......@@ -81,10 +89,9 @@ public:
* m_TextInside in mils */
bool m_DrawPinNum;
bool m_DrawPinName;
DLIST<LibDrawField> m_Fields; /* Auxiliairy Field list (id >= 2 ) */
DLIST<LibDrawField> m_Fields; /* Auxiliary Field list (id >= 2 ) */
LibEDA_BaseStruct* m_Drawings; /* How to draw this part */
long m_LastDate; // Last change Date
DLIST<LibEDA_BaseStruct> m_DrawItems;
public:
virtual wxString GetClass() const
......@@ -104,10 +111,10 @@ public:
bool LoadDateAndTime( char* Line );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.lib"
* format.
* @param aFile The FILE to write to.
* Write the data structures out to a FILE in "*.lib" format.
*
* @param aFile - The FILE to write to.
*
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile );
......@@ -115,10 +122,10 @@ public:
/**
* Load component definition from file.
*
* @param file - File discriptor of file to load form.
* @param file - File descriptor of file to load form.
* @param line - The first line of the component definition.
* @param lineNum - The current line number in the file.
* @param parent - The parent window for displaying message boxes.
* @param errorMsg - Description of error on load failure.
*
* @return bool - Result of the load, false if there was an error.
*/
......@@ -130,17 +137,25 @@ public:
bool LoadFootprints( FILE* file, char* line,
int* lineNum, wxString& errorMsg );
/** Function SetFields
* initialize fields from a vector of fields
* @param aFields a std::vector <LibDrawField> to import.
/**
* Initialize fields from a vector of fields.
*
* @param aFields - a std::vector <LibDrawField> to import.
*/
void SetFields( const std::vector <LibDrawField> aFields );
};
/**************************************************************************/
/* class to handle an alias of an usual component in lib (root component) */
/**************************************************************************/
/**
* Component library alias object definition.
*
* Component aliases are not really components. They are references
* to an actual component object.
*
* @todo Alias objects should really be defined as children of a component
* object not as children of a library object. This would greatly
* simply searching for components in libraries.
*/
class EDA_LibCmpAliasStruct : public LibCmpEntry
{
public:
......@@ -149,6 +164,7 @@ public:
public:
EDA_LibCmpAliasStruct( const wxChar* CmpName, const wxChar* CmpRootName );
~EDA_LibCmpAliasStruct();
virtual wxString GetClass() const
{
return wxT( "EDA_LibCmpAliasStruct" );
......
......@@ -108,7 +108,10 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
if( sscanf( line + 1, "%d", &m_FieldId ) != 1
|| m_FieldId < REFERENCE || m_FieldId >= NUMBER_OF_FIELDS )
{
errorMsg = _( "invalid field number defined" );
return false;
}
/* Recherche du debut des donnees (debut du texte suivant) */
while( *line != 0 )
......@@ -144,7 +147,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
&textOrient, &textVisible, &textHJustify, textVJustify );
if( cnt < 5 )
{
errorMsg.Printf( _( "field %d does not have the correct number of \
parameters" ),
m_FieldId );
return false;
}
m_Text = CONV_FROM_UTF8( text );
m_Size.x = m_Size.y;
......@@ -154,14 +162,24 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
else if( textOrient == 'V' )
m_Orient = TEXT_ORIENT_VERT;
else
{
errorMsg.Printf( _( "field %d text orientation parameter <%c> is \
not valid" ),
textOrient );
return false;
}
if( textVisible == 'V' )
m_Attributs &= ~TEXT_NO_VISIBLE;
else if ( textVisible == 'I' )
m_Attributs |= TEXT_NO_VISIBLE;
else
{
errorMsg.Printf( _( "field %d text visible parameter <%c> is not \
valid" ),
textVisible );
return false;
}
m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
......@@ -175,7 +193,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
else if( textHJustify == 'R' )
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
else
{
errorMsg.Printf( _( "field %d text horizontal justification \
parameter <%c> is not valid" ),
textHJustify );
return false;
}
if( textVJustify[0] == 'C' )
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
......@@ -184,7 +207,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
else if( textVJustify[0] == 'T' )
m_VJustify = GR_TEXT_VJUSTIFY_TOP;
else
{
errorMsg.Printf( _( "field %d text vertical justification \
parameter <%c> is not valid" ),
textVJustify[0] );
return false;
}
if ( textVJustify[1] == 'I' ) // Italic
m_Italic = true;
......
......@@ -2,12 +2,9 @@
/* Functions to handle component library files : read functions */
/*****************************************************************/
#include <iostream>
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "trigo.h"
#include "confirm.h"
#include "kicad_string.h"
#include "gestfich.h"
......@@ -21,21 +18,16 @@
#include "dialog_load_error.h"
/* Local Functions */
static LibEDA_BaseStruct* ReadDrawEntryItemDescription( EDA_LibComponentStruct* aParent, FILE* f,
char* Line, int* LineNum );
static bool AddAliasNames( EDA_LibComponentStruct* LibEntry, char* line );
static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts );
static int AddFootprintFilterList( EDA_LibComponentStruct* LibEntryLibEntry,
FILE* f, char* Line, int* LineNum );
// If this code was written in C++ then this would not be needed.
static wxString currentLibraryName;
/****************************************************************************/
/** Function LoadLibraryName
* Routine to load the given library name. FullLibName should hold full path
* of file name to open, while LibName should hold only its name.
......@@ -144,7 +136,7 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
tmp = wxGetApp().FindLibraryPath( fn );
if( !tmp )
{
libraries_not_found += fn.GetName() + _("\n");
libraries_not_found += fn.GetName() + _( "\n" );
continue;
}
}
......@@ -155,7 +147,6 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
// Loaded library statusbar message
msg = _( "Library " ) + tmp;
frame->PrintMsg( msg );
if( LoadLibraryName( frame, tmp, fn.GetName() ) )
msg += _( " loaded" );
......@@ -168,18 +159,17 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
/* Print the libraries not found */
if( !libraries_not_found.IsEmpty() )
{
DIALOG_LOAD_ERROR dialog(frame);
dialog.MessageSet(_("The following libraries could not be found:"));
dialog.ListSet(libraries_not_found);
DIALOG_LOAD_ERROR dialog( frame );
dialog.MessageSet( _( "The following libraries could not be found:" ) );
dialog.ListSet( libraries_not_found );
libraries_not_found.empty();
dialog.ShowModal();
}
// reorder the linked list to match the order filename list:
int NumOfLibs;
for( NumOfLibs = 0, lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext )
int NumOfLibs = 0;
for( lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext )
{
lib->m_Flags = 0;
NumOfLibs++;
......@@ -192,6 +182,7 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
(LibraryStruct**) MyZMalloc( sizeof(LibraryStruct*) * (NumOfLibs + 2) );
int jj = 0;
for( ii = 0; ii < frame->m_ComponentLibFiles.GetCount(); ii++ )
{
if( jj >= NumOfLibs )
......@@ -228,11 +219,12 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
/**************************************************************/
/** Function FreeCmpLibrary
* Routine to remove and free a library from the current loaded libraries.
*/
/**************************************************************/
void FreeCmpLibrary (wxWindow* frame, const wxString& LibName)
void FreeCmpLibrary( wxWindow* frame, const wxString& LibName )
{
int NumOfLibs = NumOfLibraries();
LibraryStruct* Lib, * TempLib;
......@@ -277,8 +269,8 @@ void FreeCmpLibrary (wxWindow* frame, const wxString& LibName)
* Routine to compare two EDA_LibComponentStruct for the PriorQue module.
* Comparison (insensitive case) is based on Part name.
*/
int LibraryEntryCompare (EDA_LibComponentStruct* LE1,
EDA_LibComponentStruct* LE2)
int LibraryEntryCompare( EDA_LibComponentStruct* LE1,
EDA_LibComponentStruct* LE2 )
{
return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text );
}
......@@ -302,15 +294,16 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
if( GetLine( libfile, Line, &LineNum, sizeof(Line) ) == NULL )
{
msg = _( "File <" ) + Library->m_Name + _( "> is empty!" );
msg.Printf( _( "File <%s> is empty!" ),
(const wxChar*) Library->m_Name );
DisplayError( frame, msg );
return NULL;
}
if( strnicmp( Line, LIBFILE_IDENT, 10 ) != 0 )
{
msg = _( "File <" ) + Library->m_Name +
_( "> is NOT EESCHEMA library!" );
msg.Printf( _( "File <%s> is NOT an EESCHEMA library!" ),
(const wxChar*) Library->m_Name );
DisplayError( frame, msg );
return NULL;
}
......@@ -327,8 +320,8 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
{
if( Library && !Library->ReadHeader( libfile, &LineNum ) )
{
msg = _( "Library <" ) + Library->m_Name +
_( "> header read error" );
msg.Printf( _( "Library <%s> header read error" ),
(const wxChar*) Library->m_Name );
DisplayError( frame, msg, 30 );
}
continue;
......@@ -337,331 +330,34 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
if( strnicmp( Line, "DEF", 3 ) == 0 )
{
/* Read one DEF/ENDDEF part entry from library: */
LibEntry = Read_Component_Definition( frame, Line, libfile,
&LineNum );
if( LibEntry )
{
/* If we are here, this part is O.k. - put it in: */
++ * NumOfParts;
PQInsert( &PQ, LibEntry );
InsertAlias( &PQ, LibEntry, NumOfParts );
}
}
}
return PQ;
}
/*****************************************************************************/
/* Analyse la ligne de description du champ de la forme:
* Fn "CA3130" 150 -200 50 H V
* ou n = 0 (REFERENCE), 1 (VALUE) , 2 .. 11 = autres champs, facultatifs
*/
/*****************************************************************************/
static bool GetLibEntryField ( EDA_LibComponentStruct* LibEntry, char* line,
wxString& errorMsg )
{
LibDrawField* field = new LibDrawField();
if ( !field->Load( line, errorMsg ) )
{
SAFE_DELETE( field );
return false;
}
switch( field->m_FieldId )
{
case REFERENCE:
LibEntry->m_Prefix = *field;
SAFE_DELETE( field );
break;
case VALUE:
LibEntry->m_Name = *field;
SAFE_DELETE( field );
break;
default:
LibEntry->m_Fields.PushBack( field );
break;
}
return true;
}
/*****************************************************************************/
/* Routine to Read a DEF/ENDDEF part entry from given open file.
*/
/*****************************************************************************/
EDA_LibComponentStruct* Read_Component_Definition( WinEDA_DrawFrame* frame,
char* Line,
FILE* f,
int* LineNum )
{
int unused;
char* p;
char* name;
char* prefix = NULL;
EDA_LibComponentStruct* LibEntry = NULL;
bool Res;
wxString Msg, errorMsg;
p = strtok( Line, " \t\r\n" );
if( strcmp( p, "DEF" ) != 0 )
{
Msg.Printf( wxT( "DEF command expected in line %d, aborted." ),
*LineNum );
DisplayError( frame, Msg );
return NULL;
}
/* Read DEF line: */
char drawnum = 0;
char drawname = 0;
LibEntry = new EDA_LibComponentStruct( NULL );
if( ( name = strtok( NULL, " \t\n" ) ) == NULL /* Part name: */
|| ( prefix = strtok( NULL, " \t\n" ) ) == NULL /* Prefix name: */
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* NumOfPins: */
|| sscanf( p, "%d", &unused ) != 1
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* TextInside: */
|| sscanf( p, "%d", &LibEntry->m_TextInside ) != 1
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* DrawNums: */
|| sscanf( p, "%c", &drawnum ) != 1
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* DrawNums: */
|| sscanf( p, "%c", &drawname ) != 1
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_UnitCount: */
|| sscanf( p, "%d", &LibEntry->m_UnitCount ) != 1 )
{
Msg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), *LineNum );
DisplayError( frame, Msg );
while( GetLine( f, Line, LineNum, 1024 ) )
{
p = strtok( Line, " \t\n" );
if( stricmp( p, "ENDDEF" ) == 0 )
break;
}
return NULL;
}
else /* Update infos read from the line "DEF" */
{
LibEntry->m_DrawPinNum = (drawnum == 'N') ? FALSE : TRUE;
LibEntry->m_DrawPinName = (drawname == 'N') ? FALSE : TRUE;
/* Copy part name and prefix. */
strupper( name );
if( name[0] != '~' )
LibEntry->m_Name.m_Text = CONV_FROM_UTF8( name );
else
{
LibEntry->m_Name.m_Text = CONV_FROM_UTF8( &name[1] );
LibEntry->m_Name.m_Attributs |= TEXT_NO_VISIBLE;
}
if( strcmp( prefix, "~" ) == 0 )
{
LibEntry->m_Prefix.m_Text.Empty();
LibEntry->m_Prefix.m_Attributs |= TEXT_NO_VISIBLE;
}
else
LibEntry->m_Prefix.m_Text = CONV_FROM_UTF8( prefix );
// Copy optional infos
// m_UnitSelectionLocked param
if( ( p = strtok( NULL, " \t\n" ) ) != NULL )
{
if( *p == 'L' )
LibEntry->m_UnitSelectionLocked = TRUE;
}
if( ( p = strtok( NULL, " \t\n" ) ) != NULL ) /* Type Of Component */
{
if( *p == 'P' )
LibEntry->m_Options = ENTRY_POWER;
}
}
/* Read next lines */
while( GetLine( f, Line, LineNum, 1024 ) )
{
p = strtok( Line, " \t\n" );
/* This is the error flag ( if an error occurs, Res = FALSE) */
Res = TRUE;
if( (Line[0] == 'T') && (Line[1] == 'i') )
{
Res = LibEntry->LoadDateAndTime( Line );
}
else if( Line[0] == 'F' )
{
Res = GetLibEntryField( LibEntry, Line, errorMsg );
}
else if( strcmp( p, "ENDDEF" ) == 0 )
{
p = strtok( Line, " \t\n" );
break;
}
else if( strcmp( p, "DRAW" ) == 0 )
{
LibEntry->m_Drawings = ReadDrawEntryItemDescription( LibEntry, f, Line, LineNum );
}
else if( strncmp( p, "ALIAS", 5 ) == 0 )
{
p = strtok( NULL, "\r\n" );
Res = AddAliasNames( LibEntry, p );
}
else if( strncmp( p, "$FPLIST", 5 ) == 0 )
{
Res = AddFootprintFilterList( LibEntry, f, Line, LineNum );
}
else
if( LibEntry->Load( libfile, Line, &LineNum, msg ) )
{
Msg.Printf( wxT( "Undefined command \"%s\" in line %d, skipped." ),
p, *LineNum );
frame->PrintMsg( Msg );
}
/* End line or block analysis: test for an error */
if( !Res )
{ /* Something went wrong there. */
if( errorMsg.IsEmpty() )
Msg.Printf( wxT( "Error at line %d of library \n\"%s\",\nlibrary not loaded" ),
*LineNum, currentLibraryName.GetData() );
else
Msg.Printf( wxT( "Error <%s> at line %d of library \n\"%s\",\nlibrary not loaded" ),
errorMsg.c_str(), *LineNum,
currentLibraryName.GetData() );
DisplayError( frame, Msg );
SAFE_DELETE( LibEntry );
return NULL;
}
}
/* If we are here, this part is O.k. - put it in: */
LibEntry->SortDrawItems();
return LibEntry;
}
/*****************************************************************************
* Routine to load a DRAW definition from given file. Note "DRAW" line has *
* been read already. Reads upto and include ENDDRAW, or an error (NULL ret). *
*****************************************************************************/
static LibEDA_BaseStruct* ReadDrawEntryItemDescription (EDA_LibComponentStruct* aParent, FILE* f,
char* Line, int* LineNum)
{
wxString MsgLine, errorMsg;
bool entryLoaded;
LibEDA_BaseStruct* Tail = NULL;
LibEDA_BaseStruct* New = NULL;
LibEDA_BaseStruct* Head = NULL;
while( TRUE )
{
if( GetLine( f, Line, LineNum, 1024 ) == NULL )
{
DisplayError( NULL, wxT( "File ended prematurely" ) );
return Head;
}
if( strncmp( Line, "ENDDRAW", 7 ) == 0 )
{
break;
}
New = NULL;
switch( Line[0] )
{
case 'A': /* Arc */
New = ( LibEDA_BaseStruct* ) new LibDrawArc(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
case 'C': /* Circle */
New = ( LibEDA_BaseStruct* ) new LibDrawCircle(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
case 'T': /* Text */
New = ( LibEDA_BaseStruct* ) new LibDrawText(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
case 'S': /* Square */
New = ( LibEDA_BaseStruct* ) new LibDrawSquare(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
case 'X': /* Pin Description */
New = ( LibEDA_BaseStruct* ) new LibDrawPin(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
case 'P': /* Polyline */
New = ( LibEDA_BaseStruct* ) new LibDrawPolyline(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
case 'B': /* Bezier */
New = ( LibEDA_BaseStruct* ) new LibDrawBezier(aParent);
entryLoaded = New->Load( Line, errorMsg );
break;
default:
MsgLine.Printf( wxT( "Undefined DRAW command in line %d\n%s, aborted." ),
*LineNum, Line );
DisplayError( NULL, MsgLine );
return Head;
}
if( !entryLoaded )
{
MsgLine.Printf( wxT( "Error <%s %s> in DRAW command %c in line %d, aborted." ),
errorMsg.c_str(), MsgLine.c_str(),
Line[0], *LineNum );
DisplayError( NULL, MsgLine );
SAFE_DELETE( New );
/* FLush till end of draw: */
do
{
if( GetLine( f, Line, LineNum, 1024 ) == NULL )
{
DisplayError( NULL, wxT( "File ended prematurely" ) );
return Head;
}
} while( strncmp( Line, "ENDDRAW", 7 ) != 0 );
return Head;
++*NumOfParts;
PQInsert( &PQ, LibEntry );
InsertAlias( &PQ, LibEntry, NumOfParts );
}
else
{
if( Head == NULL )
Head = Tail = New;
else
{
Tail->SetNext( New );
Tail = New;
wxLogWarning( _( "Library <%s> component load error %s." ),
(const wxChar*) Library->m_Name,
(const wxChar*) msg );
msg.Clear();
delete LibEntry;
}
}
}
return Head;
return PQ;
}
/*****************************************************************************
* Routine to find the library given its name. *
*****************************************************************************/
LibraryStruct* FindLibrary (const wxString& Name)
LibraryStruct* FindLibrary( const wxString& Name )
{
LibraryStruct* Lib = g_LibraryList;
......@@ -691,48 +387,22 @@ int NumOfLibraries()
}
/********************************************************************/
/* Read the alias names (in buffer line) and add them in alias list
* names are separated by spaces
*/
/********************************************************************/
static bool AddAliasNames (EDA_LibComponentStruct* LibEntry, char* line )
{
char* text;
wxString name;
text = strtok( line, " \t\r\n" );
while( text )
{
name = CONV_FROM_UTF8( text );
LibEntry->m_AliasList.Add( name );
text = strtok( NULL, " \t\r\n" );
}
return TRUE;
}
/********************************************************************/
/* create in library (in list PQ) aliases of the "root" component LibEntry*/
/********************************************************************/
static void InsertAlias (PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts)
static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts )
{
EDA_LibCmpAliasStruct* AliasEntry;
unsigned ii;
if( LibEntry->m_AliasList.GetCount() == 0 )
return; /* No alias for this component */
for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ )
{
AliasEntry =
new EDA_LibCmpAliasStruct( LibEntry->m_AliasList[ii],
LibEntry->m_Name.m_Text.GetData() );
++ * NumOfParts;
++*NumOfParts;
PQInsert( PQ, AliasEntry );
}
}
......@@ -815,33 +485,3 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
fclose( f );
return 1;
}
/*****************************************************************************/
/* read the FootprintFilter List stating with:
* FPLIST
* and ending with:
* ENDFPLIST
*/
/*****************************************************************************/
int AddFootprintFilterList(EDA_LibComponentStruct* LibEntryLibEntry,
FILE* f, char* Line, int* LineNum)
{
for( ; ; )
{
if( GetLine( f, Line, LineNum, 1024 ) == NULL )
{
DisplayError( NULL, wxT( "File ended prematurely" ) );
return 0;
}
if( stricmp( Line, "$ENDFPLIST" ) == 0 )
{
break; /*normal exit on end of list */
}
LibEntryLibEntry->m_FootprintList.Add( CONV_FROM_UTF8( Line + 1 ) );
}
return 1;
}
......@@ -60,9 +60,6 @@ void DrawLibraryDrawStruct(WinEDA_DrawPanel * aPanel, wxDC * aDC,
bool MapAngles(int *Angle1, int *Angle2, const int TransMat[2][2]);
EDA_LibComponentStruct * Read_Component_Definition(WinEDA_DrawFrame * frame, char * Line,
FILE *f, int *LineNum);
/* Routine to Read a DEF/ENDDEF part entry from given open file. */
/** Function TransformCoordinate
* Calculate the wew coordinate from the old one, according to the transform matrix.
......
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