Commit b739b227 authored by stambaughw's avatar stambaughw
Browse files

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
Loading
Loading
Loading
Loading
+35 −36
Original line number Original line Diff line number Diff line
@@ -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,
        || ( 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,
        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,
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,
    {
    {
        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,
        {
        {
        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,
            {
            {
                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." );
        }
        }
    }
    }


    m_Drawings = headEntry;
    return true;
    return true;
}
}


@@ -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 )
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,
            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
    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
        {
        {
            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
     * 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 )
+43 −27
Original line number Original line Diff line number Diff line
/****************************************************************/
/******************************************/
/*	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 {
};
};




/* 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:
    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:




    /**
    /**
     * 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:
                                          * 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:
                                          * 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:
    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:
    /**
    /**
     * 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:
    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:
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" );
+28 −0
Original line number Original line Diff line number Diff line
@@ -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 )
                  &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 )
    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 )
        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 )
        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;