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 Diff line number Diff line
@@ -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;
}

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