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, ...@@ -350,7 +350,7 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
if( strcmp( p, "DEF" ) != 0 ) 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 ); *lineNum );
return false; return false;
} }
...@@ -372,7 +372,7 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum, ...@@ -372,7 +372,7 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_UnitCount: */ || ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_UnitCount: */
|| sscanf( p, "%d", &m_UnitCount ) != 1 ) || 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 ); *lineNum );
while( GetLine( file, line, lineNum, 1024 ) ) while( GetLine( file, line, lineNum, 1024 ) )
{ {
...@@ -422,29 +422,27 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum, ...@@ -422,29 +422,27 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
if( (line[0] == 'T') && (line[1] == 'i') ) if( (line[0] == 'T') && (line[1] == 'i') )
Res = LoadDateAndTime( line ); Res = LoadDateAndTime( line );
else if( line[0] == 'F' ) else if( line[0] == 'F' )
Res = LoadField( strcat( p, line ), errorMsg ); Res = LoadField( line, Msg );
else if( strcmp( p, "ENDDEF" ) == 0 ) else if( strcmp( p, "ENDDEF" ) == 0 )
break; break;
else if( strcmp( p, "DRAW" ) == 0 ) 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 ) else if( strncmp( p, "ALIAS", 5 ) == 0 )
{ {
p = strtok( NULL, "\r\n" ); p = strtok( NULL, "\r\n" );
Res = LoadAliases( p, errorMsg ); Res = LoadAliases( p, errorMsg );
} }
else if( strncmp( p, "$FPLIST", 5 ) == 0 ) 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 */ /* End line or block analysis: test for an error */
if( !Res ) if( !Res )
{ {
Msg.Printf( wxT( "%d " ), *lineNum ); if( Msg.IsEmpty() )
errorMsg.Printf( wxT( "error occurred at line %d " ), *lineNum );
if( errorMsg.IsEmpty() )
errorMsg = wxT( "error at line " ) + Msg;
else else
errorMsg = wxT( "error <" ) + errorMsg + errorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
wxT( "> at line " ) + Msg; ( const wxChar* ) Msg, *lineNum );
return false; return false;
} }
} }
...@@ -459,7 +457,6 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum, ...@@ -459,7 +457,6 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum,
bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line, bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
int* lineNum, wxString& errorMsg ) int* lineNum, wxString& errorMsg )
{ {
bool entryLoaded;
LibEDA_BaseStruct* newEntry = NULL; LibEDA_BaseStruct* newEntry = NULL;
LibEDA_BaseStruct* headEntry = NULL; LibEDA_BaseStruct* headEntry = NULL;
LibEDA_BaseStruct* tailEntry = NULL; LibEDA_BaseStruct* tailEntry = NULL;
...@@ -468,7 +465,7 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line, ...@@ -468,7 +465,7 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
{ {
if( GetLine( f, line, lineNum, 1024 ) == NULL ) if( GetLine( f, line, lineNum, 1024 ) == NULL )
{ {
errorMsg = wxT( "File ended prematurely" ); errorMsg = _( "file ended prematurely loading component draw element" );
return false; return false;
} }
...@@ -481,46 +478,38 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line, ...@@ -481,46 +478,38 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
{ {
case 'A': /* Arc */ case 'A': /* Arc */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawArc(this); newEntry = ( LibEDA_BaseStruct* ) new LibDrawArc(this);
entryLoaded = newEntry->Load( line, errorMsg );
break; break;
case 'C': /* Circle */ case 'C': /* Circle */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawCircle(this); newEntry = ( LibEDA_BaseStruct* ) new LibDrawCircle(this);
entryLoaded = newEntry->Load( line, errorMsg );
break; break;
case 'T': /* Text */ case 'T': /* Text */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawText(this); newEntry = ( LibEDA_BaseStruct* ) new LibDrawText(this);
entryLoaded = newEntry->Load( line, errorMsg );
break; break;
case 'S': /* Square */ case 'S': /* Square */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawSquare(this); newEntry = ( LibEDA_BaseStruct* ) new LibDrawSquare(this);
entryLoaded = newEntry->Load( line, errorMsg );
break; break;
case 'X': /* Pin Description */ case 'X': /* Pin Description */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawPin(this); newEntry = ( LibEDA_BaseStruct* ) new LibDrawPin(this);
entryLoaded = newEntry->Load( line, errorMsg );
break; break;
case 'P': /* Polyline */ case 'P': /* Polyline */
newEntry = ( LibEDA_BaseStruct* ) new LibDrawPolyline(this); newEntry = ( LibEDA_BaseStruct* ) new LibDrawPolyline(this);
entryLoaded = newEntry->Load( line, errorMsg );
break; break;
default: default:
errorMsg.Printf( wxT( "Undefined DRAW command in line %d\n%s, aborted." ), errorMsg.Printf( _( "undefined DRAW command %c" ), line[0] );
*lineNum, line );
m_Drawings = headEntry; m_Drawings = headEntry;
return false; return false;
} }
if( !entryLoaded ) if( !newEntry->Load( line, errorMsg ) )
{ {
errorMsg.Printf( wxT( "> in DRAW command %c in line %d" ), line[0], errorMsg.Printf( _( "error <%s> in DRAW command %c" ),
*lineNum ); ( const wxChar* ) errorMsg, line[0] );
errorMsg = wxT( "Error <" ) + errorMsg + wxT( ", aborted." );
SAFE_DELETE( newEntry ); SAFE_DELETE( newEntry );
/* Flush till end of draw section */ /* Flush till end of draw section */
...@@ -528,13 +517,12 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line, ...@@ -528,13 +517,12 @@ bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line,
{ {
if( GetLine( f, line, lineNum, 1024 ) == NULL ) 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." ); to flush to end of drawing section." );
return false; return false;
} }
} while( strncmp( line, "ENDDRAW", 7 ) != 0 ); } while( strncmp( line, "ENDDRAW", 7 ) != 0 );
SAFE_DELETE( headEntry ); SAFE_DELETE( headEntry );
return false; return false;
} }
...@@ -550,6 +538,7 @@ to flush to end of drawing section." ); ...@@ -550,6 +538,7 @@ to flush to end of drawing section." );
} }
} }
m_Drawings = headEntry;
return true; return true;
} }
...@@ -570,7 +559,7 @@ bool EDA_LibComponentStruct::LoadAliases( char* line, wxString& errorMsg ) ...@@ -570,7 +559,7 @@ bool EDA_LibComponentStruct::LoadAliases( char* line, wxString& errorMsg )
bool EDA_LibComponentStruct::LoadField( 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 ) ) if ( !field->Load( line, errorMsg ) )
{ {
...@@ -579,11 +568,19 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg ) ...@@ -579,11 +568,19 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg )
} }
if( field->m_FieldId == REFERENCE ) if( field->m_FieldId == REFERENCE )
field = &m_Prefix; {
m_Prefix = *field;
SAFE_DELETE( field );
}
else if ( field->m_FieldId == VALUE ) else if ( field->m_FieldId == VALUE )
field = &m_Name; {
m_Name = *field;
SAFE_DELETE( field );
}
else else
{
m_Fields.PushBack( field ); m_Fields.PushBack( field );
}
return true; return true;
} }
...@@ -592,7 +589,7 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg ) ...@@ -592,7 +589,7 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg )
bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line, bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line,
int* lineNum, wxString& errorMsg ) int* lineNum, wxString& errorMsg )
{ {
while( stricmp( line, "$ENDFPLIST" ) != 0 ) while( true )
{ {
if( GetLine( file, line, lineNum, 1024 ) == NULL ) if( GetLine( file, line, lineNum, 1024 ) == NULL )
{ {
...@@ -600,6 +597,9 @@ bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line, ...@@ -600,6 +597,9 @@ bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line,
return false; return false;
} }
if( stricmp( line, "$ENDFPLIST" ) == 0 )
break;
m_FootprintList.Add( CONV_FROM_UTF8( line + 1 ) ); m_FootprintList.Add( CONV_FROM_UTF8( line + 1 ) );
} }
...@@ -690,7 +690,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields ...@@ -690,7 +690,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields
aFields[REFERENCE].Copy( &m_Prefix ); aFields[REFERENCE].Copy( &m_Prefix );
// Remove others fields: // Remove others fields:
CurrentLibEntry->m_Fields.DeleteAll(); m_Fields.DeleteAll();
for( unsigned ii = FOOTPRINT; ii < aFields.size(); ii++ ) for( unsigned ii = FOOTPRINT; ii < aFields.size(); ii++ )
{ {
...@@ -704,7 +704,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields ...@@ -704,7 +704,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector <LibDrawField> aFields
{ {
LibDrawField*Field = new LibDrawField( this, ii ); LibDrawField*Field = new LibDrawField( this, ii );
aFields[ii].Copy( Field ); 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 ...@@ -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 * text is like a void text and for non editable names, remove the name
* (set to the default name) * (set to the default name)
*/ */
for( LibDrawField* Field = CurrentLibEntry->m_Fields; Field; for( LibDrawField* Field = m_Fields; Field; Field = Field->Next() )
Field = Field->Next() )
{ {
Field->SetParent( this ); Field->SetParent( this );
if( Field->m_FieldId >= FIELD1 ) if( Field->m_FieldId >= FIELD1 )
......
/****************************************************************/ /******************************************/
/* Headers fo lib component (or libentry) definitions */ /* Library component object definitions. */
/****************************************************************/ /******************************************/
#ifndef CLASS_LIBENTRY_H #ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H #define CLASS_LIBENTRY_H
...@@ -25,8 +25,11 @@ enum LibrEntryOptions { ...@@ -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 class LibCmpEntry : public EDA_BaseStruct
{ {
public: public:
...@@ -36,7 +39,7 @@ public: ...@@ -36,7 +39,7 @@ public:
wxString m_Doc; /* documentation for info */ wxString m_Doc; /* documentation for info */
wxString m_KeyWord; /* keyword list (used to select a group of wxString m_KeyWord; /* keyword list (used to select a group of
* components by keyword) */ * 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) LibrEntryOptions m_Options; // special features (i.e. Entry is a POWER)
public: public:
...@@ -49,18 +52,23 @@ 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. * @param aFile The FILE to write to.
*
* @return bool - true if success writing else false. * @return bool - true if success writing else false.
*/ */
bool SaveDoc( FILE* aFile ); bool SaveDoc( FILE* aFile );
}; };
/*********************************************/ /**
/* 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 class EDA_LibComponentStruct : public LibCmpEntry
{ {
public: public:
...@@ -70,7 +78,7 @@ public: ...@@ -70,7 +78,7 @@ public:
* for the component (wildcard names * for the component (wildcard names
* accepted) */ * accepted) */
int m_UnitCount; /* Units (or sections) per package */ 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 * and their selection is
* locked (i.e. if part A cannot * locked (i.e. if part A cannot
* be automatically changed in * be automatically changed in
...@@ -81,10 +89,9 @@ public: ...@@ -81,10 +89,9 @@ public:
* m_TextInside in mils */ * m_TextInside in mils */
bool m_DrawPinNum; bool m_DrawPinNum;
bool m_DrawPinName; 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 */ LibEDA_BaseStruct* m_Drawings; /* How to draw this part */
long m_LastDate; // Last change Date long m_LastDate; // Last change Date
DLIST<LibEDA_BaseStruct> m_DrawItems;
public: public:
virtual wxString GetClass() const virtual wxString GetClass() const
...@@ -104,10 +111,10 @@ public: ...@@ -104,10 +111,10 @@ public:
bool LoadDateAndTime( char* Line ); bool LoadDateAndTime( char* Line );
/** /**
* Function Save * Write the data structures out to a FILE in "*.lib" format.
* writes the data structures for this object out to a FILE in "*.lib" *
* format. * @param aFile - The FILE to write to.
* @param aFile The FILE to write to. *
* @return bool - true if success writing else false. * @return bool - true if success writing else false.
*/ */
bool Save( FILE* aFile ); bool Save( FILE* aFile );
...@@ -115,10 +122,10 @@ public: ...@@ -115,10 +122,10 @@ public:
/** /**
* Load component definition from file. * 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 line - The first line of the component definition.
* @param lineNum - The current line number in the file. * @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. * @return bool - Result of the load, false if there was an error.
*/ */
...@@ -130,17 +137,25 @@ public: ...@@ -130,17 +137,25 @@ public:
bool LoadFootprints( FILE* file, char* line, bool LoadFootprints( FILE* file, char* line,
int* lineNum, wxString& errorMsg ); int* lineNum, wxString& errorMsg );
/** Function SetFields /**
* initialize fields from a vector of fields * Initialize fields from a vector of fields.
* @param aFields a std::vector <LibDrawField> to import. *
* @param aFields - a std::vector <LibDrawField> to import.
*/ */
void SetFields( const std::vector <LibDrawField> aFields ); 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 class EDA_LibCmpAliasStruct : public LibCmpEntry
{ {
public: public:
...@@ -149,6 +164,7 @@ public: ...@@ -149,6 +164,7 @@ public:
public: public:
EDA_LibCmpAliasStruct( const wxChar* CmpName, const wxChar* CmpRootName ); EDA_LibCmpAliasStruct( const wxChar* CmpName, const wxChar* CmpRootName );
~EDA_LibCmpAliasStruct(); ~EDA_LibCmpAliasStruct();
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
return wxT( "EDA_LibCmpAliasStruct" ); return wxT( "EDA_LibCmpAliasStruct" );
......
...@@ -108,7 +108,10 @@ bool LibDrawField::Load( char* line, wxString& errorMsg ) ...@@ -108,7 +108,10 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
if( sscanf( line + 1, "%d", &m_FieldId ) != 1 if( sscanf( line + 1, "%d", &m_FieldId ) != 1
|| m_FieldId < REFERENCE || m_FieldId >= NUMBER_OF_FIELDS ) || m_FieldId < REFERENCE || m_FieldId >= NUMBER_OF_FIELDS )
{
errorMsg = _( "invalid field number defined" );
return false; return false;
}
/* Recherche du debut des donnees (debut du texte suivant) */ /* Recherche du debut des donnees (debut du texte suivant) */
while( *line != 0 ) while( *line != 0 )
...@@ -144,7 +147,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg ) ...@@ -144,7 +147,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
&textOrient, &textVisible, &textHJustify, textVJustify ); &textOrient, &textVisible, &textHJustify, textVJustify );
if( cnt < 5 ) if( cnt < 5 )
{
errorMsg.Printf( _( "field %d does not have the correct number of \
parameters" ),
m_FieldId );
return false; return false;
}
m_Text = CONV_FROM_UTF8( text ); m_Text = CONV_FROM_UTF8( text );
m_Size.x = m_Size.y; m_Size.x = m_Size.y;
...@@ -154,14 +162,24 @@ bool LibDrawField::Load( char* line, wxString& errorMsg ) ...@@ -154,14 +162,24 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
else if( textOrient == 'V' ) else if( textOrient == 'V' )
m_Orient = TEXT_ORIENT_VERT; m_Orient = TEXT_ORIENT_VERT;
else else
{
errorMsg.Printf( _( "field %d text orientation parameter <%c> is \
not valid" ),
textOrient );
return false; return false;
}
if( textVisible == 'V' ) if( textVisible == 'V' )
m_Attributs &= ~TEXT_NO_VISIBLE; m_Attributs &= ~TEXT_NO_VISIBLE;
else if ( textVisible == 'I' ) else if ( textVisible == 'I' )
m_Attributs |= TEXT_NO_VISIBLE; m_Attributs |= TEXT_NO_VISIBLE;
else else
{
errorMsg.Printf( _( "field %d text visible parameter <%c> is not \
valid" ),
textVisible );
return false; return false;
}
m_HJustify = GR_TEXT_HJUSTIFY_CENTER; m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
m_VJustify = GR_TEXT_VJUSTIFY_CENTER; m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
...@@ -175,7 +193,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg ) ...@@ -175,7 +193,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
else if( textHJustify == 'R' ) else if( textHJustify == 'R' )
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT; m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
else else
{
errorMsg.Printf( _( "field %d text horizontal justification \
parameter <%c> is not valid" ),
textHJustify );
return false; return false;
}
if( textVJustify[0] == 'C' ) if( textVJustify[0] == 'C' )
m_VJustify = GR_TEXT_VJUSTIFY_CENTER; m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
...@@ -184,7 +207,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg ) ...@@ -184,7 +207,12 @@ bool LibDrawField::Load( char* line, wxString& errorMsg )
else if( textVJustify[0] == 'T' ) else if( textVJustify[0] == 'T' )
m_VJustify = GR_TEXT_VJUSTIFY_TOP; m_VJustify = GR_TEXT_VJUSTIFY_TOP;
else else
{
errorMsg.Printf( _( "field %d text vertical justification \
parameter <%c> is not valid" ),
textVJustify[0] );
return false; return false;
}
if ( textVJustify[1] == 'I' ) // Italic if ( textVJustify[1] == 'I' ) // Italic
m_Italic = true; m_Italic = true;
......
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
/* Functions to handle component library files : read functions */ /* Functions to handle component library files : read functions */
/*****************************************************************/ /*****************************************************************/
#include <iostream>
#include "fctsys.h" #include "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
#include "common.h" #include "common.h"
#include "trigo.h"
#include "confirm.h" #include "confirm.h"
#include "kicad_string.h" #include "kicad_string.h"
#include "gestfich.h" #include "gestfich.h"
...@@ -21,21 +18,16 @@ ...@@ -21,21 +18,16 @@
#include "dialog_load_error.h" #include "dialog_load_error.h"
/* Local Functions */ /* 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, static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts ); 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. // If this code was written in C++ then this would not be needed.
static wxString currentLibraryName; static wxString currentLibraryName;
/****************************************************************************/ /****************************************************************************/
/** Function LoadLibraryName /** Function LoadLibraryName
* Routine to load the given library name. FullLibName should hold full path * Routine to load the given library name. FullLibName should hold full path
* of file name to open, while LibName should hold only its name. * of file name to open, while LibName should hold only its name.
...@@ -144,7 +136,7 @@ void LoadLibraries( WinEDA_SchematicFrame* frame ) ...@@ -144,7 +136,7 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
tmp = wxGetApp().FindLibraryPath( fn ); tmp = wxGetApp().FindLibraryPath( fn );
if( !tmp ) if( !tmp )
{ {
libraries_not_found += fn.GetName() + _("\n"); libraries_not_found += fn.GetName() + _( "\n" );
continue; continue;
} }
} }
...@@ -155,7 +147,6 @@ void LoadLibraries( WinEDA_SchematicFrame* frame ) ...@@ -155,7 +147,6 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
// Loaded library statusbar message // Loaded library statusbar message
msg = _( "Library " ) + tmp; msg = _( "Library " ) + tmp;
frame->PrintMsg( msg );
if( LoadLibraryName( frame, tmp, fn.GetName() ) ) if( LoadLibraryName( frame, tmp, fn.GetName() ) )
msg += _( " loaded" ); msg += _( " loaded" );
...@@ -168,18 +159,17 @@ void LoadLibraries( WinEDA_SchematicFrame* frame ) ...@@ -168,18 +159,17 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
/* Print the libraries not found */ /* Print the libraries not found */
if( !libraries_not_found.IsEmpty() ) if( !libraries_not_found.IsEmpty() )
{ {
DIALOG_LOAD_ERROR dialog(frame); DIALOG_LOAD_ERROR dialog( frame );
dialog.MessageSet(_("The following libraries could not be found:")); dialog.MessageSet( _( "The following libraries could not be found:" ) );
dialog.ListSet(libraries_not_found); dialog.ListSet( libraries_not_found );
libraries_not_found.empty(); libraries_not_found.empty();
dialog.ShowModal(); dialog.ShowModal();
} }
// reorder the linked list to match the order filename list: // reorder the linked list to match the order filename list:
int NumOfLibs; int NumOfLibs = 0;
for( NumOfLibs = 0, lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext )
for( lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext )
{ {
lib->m_Flags = 0; lib->m_Flags = 0;
NumOfLibs++; NumOfLibs++;
...@@ -192,6 +182,7 @@ void LoadLibraries( WinEDA_SchematicFrame* frame ) ...@@ -192,6 +182,7 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
(LibraryStruct**) MyZMalloc( sizeof(LibraryStruct*) * (NumOfLibs + 2) ); (LibraryStruct**) MyZMalloc( sizeof(LibraryStruct*) * (NumOfLibs + 2) );
int jj = 0; int jj = 0;
for( ii = 0; ii < frame->m_ComponentLibFiles.GetCount(); ii++ ) for( ii = 0; ii < frame->m_ComponentLibFiles.GetCount(); ii++ )
{ {
if( jj >= NumOfLibs ) if( jj >= NumOfLibs )
...@@ -228,11 +219,12 @@ void LoadLibraries( WinEDA_SchematicFrame* frame ) ...@@ -228,11 +219,12 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
/**************************************************************/ /**************************************************************/
/** Function FreeCmpLibrary /** Function FreeCmpLibrary
* Routine to remove and free a library from the current loaded libraries. * 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(); int NumOfLibs = NumOfLibraries();
LibraryStruct* Lib, * TempLib; LibraryStruct* Lib, * TempLib;
...@@ -277,8 +269,8 @@ void FreeCmpLibrary (wxWindow* frame, const wxString& LibName) ...@@ -277,8 +269,8 @@ void FreeCmpLibrary (wxWindow* frame, const wxString& LibName)
* Routine to compare two EDA_LibComponentStruct for the PriorQue module. * Routine to compare two EDA_LibComponentStruct for the PriorQue module.
* Comparison (insensitive case) is based on Part name. * Comparison (insensitive case) is based on Part name.
*/ */
int LibraryEntryCompare (EDA_LibComponentStruct* LE1, int LibraryEntryCompare( EDA_LibComponentStruct* LE1,
EDA_LibComponentStruct* LE2) EDA_LibComponentStruct* LE2 )
{ {
return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text ); return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text );
} }
...@@ -302,15 +294,16 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library, ...@@ -302,15 +294,16 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
if( GetLine( libfile, Line, &LineNum, sizeof(Line) ) == NULL ) 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 ); DisplayError( frame, msg );
return NULL; return NULL;
} }
if( strnicmp( Line, LIBFILE_IDENT, 10 ) != 0 ) if( strnicmp( Line, LIBFILE_IDENT, 10 ) != 0 )
{ {
msg = _( "File <" ) + Library->m_Name + msg.Printf( _( "File <%s> is NOT an EESCHEMA library!" ),
_( "> is NOT EESCHEMA library!" ); (const wxChar*) Library->m_Name );
DisplayError( frame, msg ); DisplayError( frame, msg );
return NULL; return NULL;
} }
...@@ -327,8 +320,8 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library, ...@@ -327,8 +320,8 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
{ {
if( Library && !Library->ReadHeader( libfile, &LineNum ) ) if( Library && !Library->ReadHeader( libfile, &LineNum ) )
{ {
msg = _( "Library <" ) + Library->m_Name + msg.Printf( _( "Library <%s> header read error" ),
_( "> header read error" ); (const wxChar*) Library->m_Name );
DisplayError( frame, msg, 30 ); DisplayError( frame, msg, 30 );
} }
continue; continue;
...@@ -337,331 +330,34 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library, ...@@ -337,331 +330,34 @@ PriorQue* LoadLibraryAux( WinEDA_DrawFrame* frame, LibraryStruct* Library,
if( strnicmp( Line, "DEF", 3 ) == 0 ) if( strnicmp( Line, "DEF", 3 ) == 0 )
{ {
/* Read one DEF/ENDDEF part entry from library: */ /* 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 ); LibEntry = new EDA_LibComponentStruct( NULL );
if( ( name = strtok( NULL, " \t\n" ) ) == NULL /* Part name: */ if( LibEntry->Load( libfile, Line, &LineNum, msg ) )
|| ( 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
{ {
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: */ /* If we are here, this part is O.k. - put it in: */
LibEntry->SortDrawItems(); ++*NumOfParts;
return LibEntry; PQInsert( &PQ, LibEntry );
} InsertAlias( &PQ, LibEntry, NumOfParts );
/*****************************************************************************
* 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;
} }
else else
{ {
if( Head == NULL ) wxLogWarning( _( "Library <%s> component load error %s." ),
Head = Tail = New; (const wxChar*) Library->m_Name,
else (const wxChar*) msg );
{ msg.Clear();
Tail->SetNext( New ); delete LibEntry;
Tail = New;
} }
} }
} }
return Head; return PQ;
} }
/***************************************************************************** /*****************************************************************************
* Routine to find the library given its name. * * Routine to find the library given its name. *
*****************************************************************************/ *****************************************************************************/
LibraryStruct* FindLibrary (const wxString& Name) LibraryStruct* FindLibrary( const wxString& Name )
{ {
LibraryStruct* Lib = g_LibraryList; LibraryStruct* Lib = g_LibraryList;
...@@ -691,48 +387,22 @@ int NumOfLibraries() ...@@ -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*/ /* create in library (in list PQ) aliases of the "root" component LibEntry*/
/********************************************************************/ /********************************************************************/
static void InsertAlias (PriorQue** PQ, EDA_LibComponentStruct* LibEntry, static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry,
int* NumOfParts) int* NumOfParts )
{ {
EDA_LibCmpAliasStruct* AliasEntry; EDA_LibCmpAliasStruct* AliasEntry;
unsigned ii; unsigned ii;
if( LibEntry->m_AliasList.GetCount() == 0 )
return; /* No alias for this component */
for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ ) for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ )
{ {
AliasEntry = AliasEntry =
new EDA_LibCmpAliasStruct( LibEntry->m_AliasList[ii], new EDA_LibCmpAliasStruct( LibEntry->m_AliasList[ii],
LibEntry->m_Name.m_Text.GetData() ); LibEntry->m_Name.m_Text.GetData() );
++ * NumOfParts; ++*NumOfParts;
PQInsert( PQ, AliasEntry ); PQInsert( PQ, AliasEntry );
} }
} }
...@@ -815,33 +485,3 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName, ...@@ -815,33 +485,3 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
fclose( f ); fclose( f );
return 1; 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, ...@@ -60,9 +60,6 @@ void DrawLibraryDrawStruct(WinEDA_DrawPanel * aPanel, wxDC * aDC,
bool MapAngles(int *Angle1, int *Angle2, const int TransMat[2][2]); 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 /** Function TransformCoordinate
* Calculate the wew coordinate from the old one, according to the transform matrix. * 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