Commit d8fae88f authored by charras's avatar charras
Browse files

Eeschema, libedit: fixed last problems when editing alias info.

Now alias changes can be undone, and are correctly updated in lib
parent 124074c6
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,16 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with
email address.

2010-Feb-17 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
Eeschema, libedit: fixed last problems when editing alias info.
    Now alias changes can be undone, and are correctly updated in lib
    when updating the current edited component in memory
    New code could be a good starting point to store all aliases info in the
    root component,
    and also easily store it to the *.lib files and remove the .dcm associated files
    (most of code is done)


2010-Feb-14 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
+144 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem

/* Class to define an alias of a component
 *  An alias uses the component definition (graphic, pins...)
 *  but has its own name and documentation.
 *  but has its own name, keywords and documentation.
 *  Therefore, when the component is modified, alias of this component are
 *   modified.
 *  This is a simple method to create components with differs very few
@@ -140,6 +140,8 @@ LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent,
    wxASSERT( aRootComponent != NULL && aRootComponent->isComponent() );

    root = aRootComponent;
    if( aLibrary == NULL )
        library = aRootComponent->GetLibrary();
}


@@ -201,6 +203,7 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary )
    LIB_DRAW_ITEM* newItem;

    m_AliasList           = aComponent.m_AliasList;
    m_aliasListData       = aComponent.m_aliasListData;
    m_FootprintList       = aComponent.m_FootprintList;
    unitCount             = aComponent.unitCount;
    m_UnitSelectionLocked = aComponent.m_UnitSelectionLocked;
@@ -1304,3 +1307,143 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert )
        }
    }
}


/* accessors to aliases data, used by the component editor, during edition
*/
/** Function LocateAliasData
 * @return an index in array string to the alias data (doc, keywords, docfile)
 *         or -1 if not found
 * @param aAliasName = the alias name
 * @param aCreateIfNotExist = true if the alias data must be created, when not exists
 */
int LIB_COMPONENT::LocateAliasData( const wxString & aAliasName, bool aCreateIfNotExist)
{
    int idx = -1;
    for( unsigned ii = 0; ii < m_aliasListData.size(); ii += ALIAS_NEXT_IDX )
    {
        if( aAliasName.CmpNoCase( m_aliasListData[ii] ) != 0 )
            continue;
        // Found!
        idx = (int) ii;
        break;
    }

    // Alias not found, create on demand
    if( aCreateIfNotExist && (idx < 0) )
    {
        idx = (int) m_aliasListData.size();
        m_aliasListData.Add(aAliasName);
        // Add void strinds for data:
        m_aliasListData.Add(wxEmptyString);     //Doc string
        m_aliasListData.Add(wxEmptyString);     //keywords string
        m_aliasListData.Add(wxEmptyString);     //Doc fliname string
    }

    return idx;
}


/** Function GetAliasDataDoc
 * @param aAliasName = the alias name
 * @return the Doc string
 */
wxString LIB_COMPONENT::GetAliasDataDoc( const wxString & aAliasName )
{
    wxString data;
    int idx = LocateAliasData( aAliasName);
    if ( idx >= 0 )
        data = m_aliasListData[idx + ALIAS_DOC_IDX];

    return data;
}


/** Function GetAliasDataKeyWords
 * @param aAliasName = the alias name
 * @return aAliasData = the keywords string
 */
wxString LIB_COMPONENT::GetAliasDataKeyWords( const wxString & aAliasName )
{
    wxString data;
    int idx = LocateAliasData( aAliasName);
    if ( idx >= 0 )
        data = m_aliasListData[idx + ALIAS_KEYWORD_IDX];

    return data;
}


/** Function GetAliasDataDocFileName
 * @param aAliasName = the alias name
 * @return the Doc filename string
 */
wxString LIB_COMPONENT::GetAliasDataDocFileName( const wxString & aAliasName )
{
    wxString data;
    int idx = LocateAliasData( aAliasName);
    if ( idx >= 0 )
        data = m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX];

    return data;
}



/** Function SetAliasDataDoc
 * @param aAliasName = the alias name
 * @param aAliasData = the Doc string
 */
void LIB_COMPONENT::SetAliasDataDoc( const wxString & aAliasName, const wxString & aAliasData )
{
    int idx = LocateAliasData( aAliasName, true);
    m_aliasListData[idx + ALIAS_DOC_IDX] = aAliasData;
}

/** Function SetAliasDataKeywords
 * @param aAliasName = the alias name
 * @param aAliasData = the keywords string
 */
void LIB_COMPONENT::SetAliasDataKeywords( const wxString & aAliasName, const wxString & aAliasData )
{
    int idx = LocateAliasData( aAliasName, true);
    m_aliasListData[idx + ALIAS_KEYWORD_IDX] = aAliasData;
}

/** Function SetAliasDataDocFileName
 * @param aAliasName = the alias name
 * @param aAliasData = the Doc filename string
 */
void LIB_COMPONENT::SetAliasDataDocFileName( const wxString & aAliasName, const wxString & aAliasData )
{
    int idx = LocateAliasData( aAliasName, true);
    m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX] = aAliasData;
}


/** Function RemoveAliasData
 * remove an alias data from list
 * @param aAliasName = the alias name
 */
void LIB_COMPONENT::RemoveAliasData(const wxString & aAliasName )
{
    int idx = LocateAliasData( aAliasName);
    if ( idx >= 0 )
        m_aliasListData.RemoveAt(idx + ALIAS_NAME_IDX, ALIAS_NEXT_IDX);
}

/** Function CollectAliasesData
 * store in m_aliasListData alias data (doc, keywords, docfile)
 * for each alias found in m_AliasList
*/
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;
        SetAliasDataDoc( m_AliasList[ii], entry->GetDescription() );
        SetAliasDataKeywords( m_AliasList[ii], entry->GetKeyWords() );
        SetAliasDataDocFileName( m_AliasList[ii], entry->GetDocFileName() );
    }
}
+92 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ enum LibrEntryType
    ALIAS       /* This is an alias of a true component */
};

/* values for member .m_Options */
/* values for member .m_options */
enum  LibrEntryOptions
{
    ENTRY_NORMAL,   // Libentry is a standard component (real or alias)
@@ -67,6 +67,8 @@ public:

    wxString GetLibraryName();

    CMP_LIBRARY* GetLibrary() {return library;}

    virtual const wxString& GetName() const { return name; }

    virtual void SetName( const wxString& aName ) { name = aName; }
@@ -159,6 +161,34 @@ protected:
    LIB_DRAW_ITEM_LIST drawings;       /* How to draw this part */

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
     * in m_AliasListData.
     * 4 strings by alias are stored:
     * name, doc, keywords and doc filename
     * these constants are indexes in m_AliasListData
     * to read/write strings for a given alias
     */
    enum alias_idx
    {
        ALIAS_NAME_IDX         = 0,
        ALIAS_DOC_IDX          = 1,
        ALIAS_KEYWORD_IDX      = 2,
        ALIAS_DOC_FILENAME_IDX = 3,
        ALIAS_NEXT_IDX         = 4
    };
private:
    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 */
public:
    LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
    LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );

    ~LIB_COMPONENT();

    virtual wxString GetClass() const
    {
        return wxT( "LIB_COMPONENT" );
@@ -171,10 +201,68 @@ public:
        GetValueField().m_Text = aName;
    }

    LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
    LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );
    /* accessors to aliases data, used by the component editor, during edition
    */
    /** Function CollectAliasesData
     * store in m_aliasListData alias data (doc, keywords, docfile)
     * for each alias found in m_AliasList
    */
    void CollectAliasesData( CMP_LIBRARY* aLibrary );

    ~LIB_COMPONENT();
    /** Function LocateAliasData
     * @return an index in array string to the alias data (doc, keywords, docfile)
     *         or -1 if not found
     * @param aAliasName = the alias name
     * @param aCreateIfNotExist = true if the alias data must be created, when not exists
     */
    int LocateAliasData( const wxString & aAliasName, bool aCreateIfNotExist = false);

    /** Function GetAliasDataDoc
     * @param aAliasName = the alias name
     * @return the Doc string
     */
    wxString GetAliasDataDoc( const wxString & aAliasName );

    /** Function GetAliasDataKeyWords
     * @param aAliasName = the alias name
     * @return aAliasData = the keywords string
     */
    wxString GetAliasDataKeyWords( const wxString & aAliasName );

    /** Function GetAliasDataDocFileName
     * @param aAliasName = the alias name
     * @return the Doc filename string
     */
    wxString GetAliasDataDocFileName( const wxString & aAliasName );

    /** Function SetAliasDataDoc
     * @param aAliasName = the alias name
     * @return aAliasData = the Doc string
     */
    void SetAliasDataDoc( const wxString & aAliasName, const wxString & aAliasData );

    /** Function SetAliasDataKeywords
     * @param aAliasName = the alias name
     * @param aAliasData = the keywords string
     */
    void SetAliasDataKeywords( const wxString & aAliasName, const wxString & aAliasData );

    /** Function SetAliasDataDocFileName
     * @param aAliasName = the alias name
     * @param aAliasData = the Doc filename string
     */
    void SetAliasDataDocFileName( const wxString & aAliasName, const wxString & aAliasData );

    /** Function ClearAliasDataDoc
     * clear aliases data list
     */
    void ClearAliasDataDoc( ) { m_aliasListData.Clear(); }

    /** Function RemoveAliasData
     * remove an alias data from list
     * @param aAliasName = the alias name
     */
    void RemoveAliasData(const wxString & aAliasName );

    EDA_Rect GetBoundaryBox( int aUnit, int aConvert );

+18 −15
Original line number Diff line number Diff line
@@ -232,6 +232,7 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
    wxASSERT( aComponent != NULL );

    LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this );
    newCmp->ClearAliasDataDoc();    // Remove data used only in edition

    if( newCmp == NULL )
        return NULL;
@@ -283,20 +284,25 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )

    for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ )
    {
        LIB_ALIAS* alias = FindAlias( newCmp->m_AliasList[ i ] );
        wxString aliasname = newCmp->m_AliasList[ i ];
        LIB_ALIAS* alias = FindAlias( aliasname );

        if( alias == NULL )
        {
            alias = new LIB_ALIAS( newCmp->m_AliasList[ i ], newCmp );
            alias = new LIB_ALIAS( aliasname, newCmp );
            entries.push_back( alias );
        }
        else if( alias->GetComponent()->GetName().CmpNoCase( newCmp->GetName() ) != 0 )
        {
            // Remove alias from library and alias list of its root component
            RemoveEntry( alias );
            alias = new LIB_ALIAS( newCmp->m_AliasList[ i ], newCmp );
            alias = new LIB_ALIAS( aliasname, newCmp );
            entries.push_back( alias );
        }
        // Update alias data:
        alias->SetDescription( aComponent->GetAliasDataDoc( aliasname ) );
        alias->SetKeyWords( aComponent->GetAliasDataKeyWords( aliasname ) );
        alias->SetDocFileName( aComponent->GetAliasDataDocFileName( aliasname ) );
    }

    entries.push_back( (CMP_LIB_ENTRY*) newCmp );
@@ -442,29 +448,26 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
    size_t i;

    LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
    newCmp->ClearAliasDataDoc( );   // this data is currently used only when editing the component

    /* We want to remove the old root component, so we must remove old aliases.
     * even if they are not modified, because their root component will be removed
    */
    for( i = 0; i < aOldComponent->m_AliasList.GetCount(); i++ )
    {
/*        wxLogDebug( wxT( "Removing alias <%s> from component <%s> in library <%s>." ),
                    GetChars( aOldComponent->m_AliasList[ i ] ),
                    GetChars( aOldComponent->GetName() ),
                    GetChars( fileName.GetName() ) );
*/
        RemoveEntryName( aOldComponent->m_AliasList[ i ] );
    }

    /* Now, add current aliases. */
    for( i = 0; i < aNewComponent->m_AliasList.GetCount(); i++ )
    {
/*        wxLogDebug( wxT( "Adding alias <%s> from component <%s> in library <%s>." ),
                    GetChars( aNewComponent->m_AliasList[ i ] ),
                    GetChars( aNewComponent->GetName() ),
                    GetChars( fileName.GetName() ) );
*/
        LIB_ALIAS* alias = new LIB_ALIAS( aNewComponent->m_AliasList[ i ], newCmp );
        wxString aliasname = aNewComponent->m_AliasList[ i ];
        LIB_ALIAS* alias = new LIB_ALIAS( aliasname, newCmp );
        // Update alias data:
        alias->SetDescription( aNewComponent->GetAliasDataDoc( aliasname ) );
        alias->SetKeyWords( aNewComponent->GetAliasDataKeyWords( aliasname ) );
        alias->SetDocFileName( aNewComponent->GetAliasDataDocFileName( aliasname ) );
        // Add it in library
        entries.push_back( alias );
    }

@@ -589,7 +592,7 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
            || !vers.GetNextToken().ToLong( & minor ) || minor < 0L
            || minor > 99 )
        {
#if 0   // Note for defeloppers:
#if 0   // Note for developers:
        // Not sure this warning is very useful: old designs *must* be always loadable
            wxLogWarning( wxT( "The component library <%s> header version \
number is invalid.\n\nIn future versions of EESchema this library may not \
+12 −7
Original line number Diff line number Diff line
@@ -1097,9 +1097,12 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox()

void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
{
    LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
    // search for the component in lib
    // Entry and root_component can differ if Entry is an alias
    CMP_LIB_ENTRY* Entry = CMP_LIBRARY::FindLibraryEntry( m_ChipName );
    LIB_COMPONENT* root_component = CMP_LIBRARY::FindLibraryComponent( m_ChipName );

    if( Entry == NULL )
    if( (Entry == NULL) || (root_component == NULL) )
        return;

    wxString msg;
@@ -1110,17 +1113,19 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
                           GetRef(((WinEDA_SchematicFrame*)frame)->GetSheet()),
                           DARKCYAN );

    if( Entry->isPower() )
    if( root_component->isPower() )
        msg = _( "Power symbol" );
    else
        msg = _( "Name" );

    frame->AppendMsgPanel( msg, GetField( VALUE )->m_Text, DARKCYAN );
    frame->AppendMsgPanel( _( "Component" ), m_ChipName, BROWN );

    msg = Entry->GetLibraryName();
    // Display component reference in library and library
    frame->AppendMsgPanel( _( "Component" ), m_ChipName, BROWN );
    if( Entry->isAlias( ) )
        frame->AppendMsgPanel( _( "Alias of" ), root_component->GetName(), BROWN );
    frame->AppendMsgPanel( _( "Library" ), Entry->GetLibraryName(), BROWN );

    frame->AppendMsgPanel( _( "Library" ), msg, DARKRED );
    // Display description of the component, and keywords found in lib
    frame->AppendMsgPanel( _( "Description" ), Entry->GetDescription(), DARKCYAN );
    frame->AppendMsgPanel( _( "Key words" ), Entry->GetKeyWords(), DARKCYAN );
}
Loading