Commit 0c3541b7 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Component library object refactoring and minor code cleaning.

parent f360d5cc
Loading
Loading
Loading
Loading
+31 −24
Original line number Diff line number Diff line
@@ -103,7 +103,6 @@ SCH_SHEET* SCH_SHEET::GenCopy()
{
    SCH_SHEET* newitem = new SCH_SHEET( m_Pos );


    newitem->m_Size = m_Size;
    newitem->SetParent( m_Parent );
    newitem->m_TimeStamp = GetTimeStamp();
@@ -323,11 +322,10 @@ void SCH_SHEET::CleanupSheet()

SCH_SHEET_PIN* SCH_SHEET::GetLabel( const wxPoint& aPosition )
{
    int size, dy, minx, maxx;

    BOOST_FOREACH( SCH_SHEET_PIN& label, m_labels )
    {
        if (label.HitTest(aPosition)) return &label;
        if( label.HitTest( aPosition ) )
            return &label;
    }

    return NULL;
@@ -758,19 +756,26 @@ void SCH_SHEET::Rotate(wxPoint rotationPoint)
{
    RotatePoint( &m_Pos, rotationPoint, 900 );
    RotatePoint( &m_Size.x, &m_Size.y, 900 );
    if (m_Size.x<0) {

    if( m_Size.x < 0 )
    {
        m_Pos.x += m_Size.x;
        NEGATE( m_Size.x );
    }
    if (m_Size.y<0) {

    if( m_Size.y < 0 )
    {
        m_Pos.y += m_Size.y;
        NEGATE( m_Size.y );
    }

    BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_labels )
    {
        sheetPin.Rotate( rotationPoint );
    }
}


void SCH_SHEET::Mirror_X( int aXaxis_position )
{
    m_Pos.y -= aXaxis_position;
@@ -782,6 +787,8 @@ void SCH_SHEET::Mirror_X( int aXaxis_position )
        sheetPin.Mirror_X( aXaxis_position );
    }
}


/** virtual function Mirror_Y
 * mirror item relative to an Y axis
 * @param aYaxis_position = the y axis position
+29 −35
Original line number Diff line number Diff line
@@ -384,9 +384,7 @@ void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
}


void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* aItem,
                                    WinEDA_DrawPanel* aPanel,
                                    wxDC* aDc )
void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* aItem, WinEDA_DrawPanel* aPanel, wxDC* aDc )
{
    wxASSERT( aItem != NULL );

@@ -409,8 +407,7 @@ from component %s in library %s." ),
    LIB_DRAW_ITEM_LIST::iterator i;

    if( aDc != NULL )
        aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
                    DefaultTransformMatrix );
        aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransformMatrix );

    for( i = drawings.begin(); i < drawings.end(); i++ )
    {
@@ -432,8 +429,7 @@ void LIB_COMPONENT::AddDrawItem( LIB_DRAW_ITEM* aItem )
}


LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* aItem,
                                               KICAD_T aType )
LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* aItem, KICAD_T aType )
{
    /* Return the next draw object pointer.
     * If item is NULL return the first item of type in the list.
@@ -674,8 +670,7 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum,

    if( strcmp( p, "DEF" ) != 0 )
    {
        aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ),
                          *aLineNum );
        aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ), *aLineNum );
        return false;
    }

@@ -696,8 +691,7 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum,
        || ( p = strtok( NULL, " \t\n" ) ) == NULL           /* unitCount: */
        || sscanf( p, "%d", &unitCount ) != 1 )
    {
        aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
                          *aLineNum );
        aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), *aLineNum );
        while( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) )
        {
            p = strtok( aLine, " \t\n" );
@@ -901,7 +895,7 @@ bool LIB_COMPONENT::LoadField( char* aLine, wxString& aErrorMsg )
        LIB_FIELD* fixedField = GetField( field->m_FieldId );

        // this will fire only if somebody broke a constructor or editor.
        // MANDATORY_FIELDS are alway present in ram resident components, no
        // MANDATORY_FIELDS are always present in ram resident components, no
        // exceptions, and they always have their names set, even fixed fields.
        wxASSERT( fixedField );

@@ -960,8 +954,7 @@ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int aUnit, int aConvert )
                                     && ( aUnit != item.m_Unit ) ) )
            continue;

        if( item.m_Convert > 0
            && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
        if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
            continue;

        if ( ( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
@@ -1006,7 +999,7 @@ void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD>& aFields )
    }

    // Reorder drawings: transparent polygons first, pins and text last.
    // so texts have priority on sreen.
    // so texts have priority on screen.
    drawings.sort();
}

@@ -1113,8 +1106,7 @@ bool LIB_COMPONENT::SaveDateAndTime( FILE* aFile )
    mon  = ( m_dateModified >> 22 ) & 15;
    year = ( m_dateModified >> 26 ) + 1990;

    if ( fprintf( aFile, "Ti %d/%d/%d %d:%d:%d\n",
                  year, mon, day, hour, min, sec ) < 0 )
    if ( fprintf( aFile, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec ) < 0 )
        return false;

    return true;
@@ -1132,8 +1124,7 @@ bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
    text = strtok( aLine, " \r\t\n" );
    text = strtok( NULL, " \r\t\n" );

    if (sscanf( aLine, "%d/%d/%d %d:%d:%d",
                &year, &mon, &day, &hour, &min, &sec ) != 6 )
    if (sscanf( aLine, "%d/%d/%d %d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) != 6 )
        return false;

    m_dateModified = ( sec & 63 ) + ( ( min & 63 ) << 6 ) +
@@ -1239,7 +1230,7 @@ void LIB_COMPONENT::DeleteSelectedItems()
    // We *do not* remove the 2 mandatory fields: reference and value
    // so skip them (do not remove) if they are flagged selected.
    // Skip also not visible items.
    // But I think fileds must not be deleted by a block delete command or other global command
    // But I think fields must not be deleted by a block delete command or other global command
    // because they are not really graphic items
    while( item != drawings.end() )
    {
@@ -1488,7 +1479,7 @@ int LIB_COMPONENT::LocateAliasData( const wxString & aAliasName, bool aCreateIfN
    {
        idx = (int) m_aliasListData.size();
        m_aliasListData.Add( aAliasName );
        // Add void strinds for data:
        // Add void strings for data:
        m_aliasListData.Add( wxEmptyString );     //Doc string
        m_aliasListData.Add( wxEmptyString );     //keywords string
        m_aliasListData.Add( wxEmptyString );     //Doc fliname string
@@ -1568,7 +1559,8 @@ void LIB_COMPONENT::SetAliasDataKeywords( const wxString & aAliasName, const wxS
 * @param aAliasName = the alias name
 * @param aAliasData = the Doc filename string
 */
void LIB_COMPONENT::SetAliasDataDocFileName( const wxString & aAliasName, const wxString & aAliasData )
void LIB_COMPONENT::SetAliasDataDocFileName( const wxString & aAliasName,
                                             const wxString & aAliasData )
{
    int idx = LocateAliasData( aAliasName, true );
    m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX] = aAliasData;
@@ -1595,7 +1587,9 @@ void LIB_COMPONENT::CollectAliasesData( CMP_LIBRARY* aLibrary )
    for( unsigned ii = 0; ii < m_AliasList.GetCount(); ii++ )
    {
        CMP_LIB_ENTRY* entry = aLibrary->FindEntry( m_AliasList[ii] );
        if ( ! entry ) continue;
        if ( ! entry )
            continue;

        SetAliasDataDoc( m_AliasList[ii], entry->GetDescription() );
        SetAliasDataKeywords( m_AliasList[ii], entry->GetKeyWords() );
        SetAliasDataDocFileName( m_AliasList[ii], entry->GetDocFileName() );
+28 −25
Original line number Diff line number Diff line
@@ -132,12 +132,30 @@ extern int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY
 */
class LIB_COMPONENT : public CMP_LIB_ENTRY
{
public:
    wxArrayString      m_AliasList;      /* ALIAS list for the component */
    wxArrayString      m_FootprintList;  /* list of suitable footprint names
                                          * for the component (wildcard names
                                          * accepted) */
    int                m_pinNameOffset;  ///< The offset in mils to draw the pin name.  Set to 0
                                         ///< to draw the pin name above the pin.
    bool               m_unitsLocked;    ///< True if component has multiple parts and changing
                                         ///< one part does not automatically change another part.
    bool               m_showPinNames;   ///< Determines if component pin names are visible.
    bool               m_showPinNumbers; ///< Determines if component pin numbers are visible.
    long               m_dateModified;   ///< Date the component was last modified.
    LibrEntryOptions   m_options;        ///< Special component features such as POWER or NORMAL.)
    int                unitCount;        ///< Number of units (parts) per package.
    LIB_DRAW_ITEM_LIST drawings;         ///< How to draw this part.
    wxArrayString      m_aliasListData;  /* ALIAS data (name, doc, keywords and doc filename).
                                          * Used only by the component editor LibEdit
                                          * to store aliases info during edition
                                          * usually void outside the component editor */
    wxArrayString      m_AliasList;      ///< List of alias names for the component.
    wxArrayString      m_FootprintList;  /**< List of suitable footprint names for the
                                              component (wildcard names accepted). */


    void deleteAllFields();

    friend class CMP_LIBRARY;

public:
    /* Offsets used in editing library component,
     * for handle aliases data in m_AliasListData array string
     * when editing a library component, aliases data is stored
@@ -156,25 +174,6 @@ public:
        ALIAS_NEXT_IDX         = 4
    };

private:
    int                m_pinNameOffset;  ///< The offset in mils to draw the pin name.  Set to 0
                                         ///< to draw the pin name above the pin.
    bool               m_unitsLocked;    ///< True if component has multple parts and changing
                                         ///< one part does not automatically change another part.
    bool               m_showPinNames;   ///< Determines if component pin names are visible.
    bool               m_showPinNumbers; ///< Determines if component pin numbers are visible.
    long               m_dateModified;   ///< Date the component was last modified.
    LibrEntryOptions   m_options;        // special features (i.e. Entry is a POWER)
    int                unitCount;        /* Units (parts) per package */
    LIB_DRAW_ITEM_LIST drawings;         /* How to draw this part */
    wxArrayString      m_aliasListData;  /* ALIAS data (name, doc, keywords and doc filename).
                                          * Used only by the component editor LibEdit
                                          * to store aliases info during edition
                                          * usually void outside the component editor */

    void deleteAllFields();

public:
    LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
    LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );

@@ -192,6 +191,10 @@ public:
        GetValueField().m_Text = aName;
    }

    wxArrayString& GetAliasList() { return m_AliasList; }

    wxArrayString& GetFootPrints() { return m_FootprintList; }

    /* accessors to aliases data, used by the component editor, during edition
    */
    /** Function CollectAliasesData
+8 −10
Original line number Diff line number Diff line
@@ -75,10 +75,9 @@ bool operator<( const CMP_LIBRARY& aItem1, const CMP_LIBRARY& aItem2 )

CMP_LIBRARY::CMP_LIBRARY( int aType, const wxFileName& aFileName )
{
    m_Type = aType;
    type = aType;
    isModified = false;
    timeStamp = 0;
    m_Flags = 0;
    isCache = false;
    timeStamp = wxDateTime::Now();

@@ -227,7 +226,7 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias )


/**
 * Add /a aComponent entry to library.
 * Add \a aComponent entry to library.
 * Note a component can have an alias list,
 * so these alias will be added in library.
 * Conflicts can happen if aliases are already existing.
@@ -344,8 +343,8 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
}

/** function RemoveEntryName
 * Remove an /a aName entry from the library list names.
 * Warning: this is a partiel remove, because if aName is an alias
 * Remove an \a aName entry from the library list names.
 * Warning: this is a partial remove, because if aName is an alias
 * it is not removed from its root component.
 * this is for internal use only
 * Use RemoveEntry( CMP_LIB_ENTRY* aEntry ) to remove safely an entry in library.
@@ -367,7 +366,7 @@ void CMP_LIBRARY::RemoveEntryName( const wxString& aName )


/**
 * Remove safely an /a aEntry from the library.
 * Remove safely an \a aEntry from the library.
 *
 * If the entry is an alias, the alias is removed from the library and from
 * the alias list of the root component.  If the entry is a root component
@@ -579,7 +578,7 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
    }

    /* There is no header if this is a symbol library. */
    if( m_Type == LIBRARY_TYPE_EESCHEMA )
    if( type == LIBRARY_TYPE_EESCHEMA )
    {
        wxString tmp;

@@ -643,8 +642,7 @@ the current schematic." ),

    while( GetLine( file, line, &lineNumber, sizeof( line ) ) )
    {
        if( m_Type == LIBRARY_TYPE_EESCHEMA
            && strnicmp( line, "$HEADER", 7 ) == 0 )
        if( type == LIBRARY_TYPE_EESCHEMA && strnicmp( line, "$HEADER", 7 ) == 0 )
        {
            if( !LoadHeader( file, &lineNumber ) )
            {
@@ -701,7 +699,7 @@ void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component )
    LIB_ALIAS* alias;
    unsigned   ii;

    for( ii = 0; ii < component->m_AliasList.GetCount(); ii++ )
    for( ii = 0; ii < component->GetAliasList().GetCount(); ii++ )
    {
        if( FindEntry( component->m_AliasList[ii] ) != NULL )
        {
+19 −24
Original line number Diff line number Diff line
@@ -57,11 +57,7 @@ extern bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 );
 */
class CMP_LIBRARY
{
public:
    int            m_Type;          ///< type indicator
    int            m_Flags;

protected:
    int            type;            ///< Library type indicator.
    wxFileName     fileName;        ///< Library file name.
    wxDateTime     timeStamp;       ///< Library save time and date.
    int            versionMajor;    ///< Library major version number.
@@ -70,14 +66,13 @@ protected:
    bool           isCache;         /**< False for the "standard" libraries,
                                         True for the library cache */
    wxString       header;          ///< first line of loaded library.
    bool           isModified;      ///< Library modification status.

    static CMP_LIBRARY_LIST libraryList;
    static wxArrayString    libraryListSortOrder;

    friend class CMP_LIB_ENTRY;

private:
    bool           isModified;      ///< Library modification status.
    friend class LIB_COMPONENT;

public:
    CMP_LIBRARY( int aType, const wxFileName& aFileName );
@@ -98,11 +93,11 @@ public:
     * saves library to a file.
     * <p>
     * Prior to component library version 3.0, two files were created.  The
     * component objects are wer as component library (*.lib) files.  The
     * library entry ojbect document strings were save in library document
     * component objects are were as component library (*.lib) files.  The
     * library entry object document strings were save in library document
     * definition (*.dcm) files.  After version component library version 3.0,
     * the document string information is saved as part of the library file.
     * Saving separate document is maintained for backwards compatability.
     * Saving separate document is maintained for backwards compatibility.
     * Please note that this behavior may change in the future.  If the
     * component library already exists, it is backup up in file *.bak.
     *
@@ -143,8 +138,8 @@ private:

    /**
     * Function RemoveEntryName
     * removes an /a aName entry from the library list names.
     * Warning: this is a partiel remove, because if aname is an alias
     * removes an \a aName entry from the library list names.
     * Warning: this is a partied remove, because if aname is an alias
     * it is not removed from its root component.
     * this is for internal use only
     * Use RemoveEntry( CMP_LIB_ENTRY* aEntry ) to remove safely an entry.
@@ -216,7 +211,7 @@ public:
     * Find components in library by key word regular expression search.
     *
     * @param aNames - String array to place found component names into.
     * @param aRe - Regular expression used to seach component key words.
     * @param aRe - Regular expression used to search component key words.
     * @param aSort - Sort component name list.
     */
    void SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe,
@@ -231,7 +226,7 @@ public:
    CMP_LIB_ENTRY* FindEntry( const wxChar* aName );

    /**
     * Find entry by /a aName and /a aType.
     * Find entry by \a aName and \a aType.
     *
     * @param aName - Name of entry, case insensitive.
     * @param aType - Type of entry, root or alias.
@@ -240,7 +235,7 @@ public:
    CMP_LIB_ENTRY* FindEntry( const wxChar* aName, LibrEntryType aType );

    /**
     * Find component by /a aName.
     * Find component by \a aName.
     *
     * This is a helper for FindEntry so casting a CMP_LIB_ENTRY pointer to
     * a LIB_COMPONENT pointer is not required.
@@ -251,7 +246,7 @@ public:
    LIB_COMPONENT* FindComponent( const wxChar* aName );

    /**
     * Find alias by /a nName.
     * Find alias by \a nName.
     *
     * This is a helper for FindEntry so casting a CMP_LIB_ENTRY pointer to
     * a LIB_ALIAS pointer is not required.
@@ -265,7 +260,7 @@ public:
    }

    /**
     * Add a new /a aAlias entry to the library.
     * Add a new \a aAlias entry to the library.
     *
     * First check if a component or alias with the same name already exists
     * in the library and add alias if no conflict occurs.  Once the alias
@@ -279,7 +274,7 @@ public:
    bool AddAlias( LIB_ALIAS* aAlias );

    /**
     * Add /a aComponent entry to library.
     * Add \a aComponent entry to library.
     * Note a component can have an alias list,
     * so these alias will be added in library.
     * Conflicts can happen if aliases are already existing.
@@ -290,7 +285,7 @@ public:
    LIB_COMPONENT* AddComponent( LIB_COMPONENT* aComponent );

    /**
     * Remove safely an /a aEntry from the library.
     * Remove safely an \a aEntry from the library.
     *
     * If the entry is an alias, the alias is removed from the library and from
     * the alias list of the root component.  If the entry is a root component
@@ -321,7 +316,7 @@ public:
    CMP_LIB_ENTRY* GetFirstEntry();

    /**
     * Find next library entry by /a aName.
     * Find next library entry by \a aName.
     *
     * If the name of the entry is the last entry in the library, the first
     * entry in the list is returned.
@@ -333,7 +328,7 @@ public:


    /**
     * Find previous library entry by /a aName.
     * Find previous library entry by \a aName.
     *
     * If the name of the entry is the first entry in the library, the last
     * entry in the list is returned.
@@ -420,7 +415,7 @@ public:

    /**
     * Function AddLibrary
     * adds a compnent library to the library list.
     * adds a component library to the library list.
     *
     * @param aFileName - File name object of component library.
     * @param aErrorMsg - Error message if the component library failed to load.
@@ -430,7 +425,7 @@ public:

    /**
     * Function AddLibrary
     * inserts a compnent library into the library list.
     * inserts a component library into the library list.
     *
     * @param aFileName - File name object of component library.
     * @param aErrerMsg - Error message if the component library failed to load.
Loading