Commit 94f8c2a2 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio
Browse files

Implemented TEXTE_MODULE::GetShownText

Handles % macro expansion in user texts inside pcb modules.
At the moment the following are available:
%%      A plain %
%R      Insert the reference
%V      Insert the value
parent 8b3c14c0
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -382,7 +382,7 @@ public:
     * Function GetValue
     * Function GetValue
     * @return const wxString& - the value text.
     * @return const wxString& - the value text.
     */
     */
    const wxString& GetValue()
    const wxString& GetValue() const
    {
    {
        return m_Value->GetText();
        return m_Value->GetText();
    }
    }
+61 −0
Original line number Original line Diff line number Diff line
@@ -492,3 +492,64 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
    aCount = 1;
    aCount = 1;
}
}


/**
 * Macro-expansion for text in library modules
 */
wxString TEXTE_MODULE::GetShownText() const
{
    /* First order optimization: no % means that no processing is
     * needed; just hope that RVO and copy constructor implementation
     * avoid to copy the whole block; anyway it should be better than
     * rebuild the string one character at a time...
     * Also it seems wise to only expand macros in user text (but there
     * is no technical reason, probably) */

    if( (m_Type != TEXT_is_DIVERS) || (wxString::npos == m_Text.find('%')) )
        return m_Text;
    wxString newbuf;


    const MODULE *module = static_cast<MODULE*>( GetParent() );

    for( wxString::const_iterator it = m_Text.begin();
            it != m_Text.end(); ++it )
    {
        // Process '%' and copy everything else
        if( *it != '%' )
            newbuf.append(*it);
        else
        {
            /* Look at the next character (if is it there) and append
             * its expansion */
            ++it;
            if( it != m_Text.end() )
            {
                switch( char(*it) )
                {
                case '%':
                    newbuf.append( '%' );
                    break;

                case 'R':
                    if( module )
                        newbuf.append( module->GetReference() );
                    break;

                case 'V':
                    if( module )
                        newbuf.append( module->GetValue() );
                    break;

                default:
                    newbuf.append( '?' );
                    break;
                }
            }
            else
                break; // The string is over and we can't ++ anymore
        }
    }
    return newbuf;
}

+2 −0
Original line number Original line Diff line number Diff line
@@ -173,6 +173,8 @@ public:


    EDA_ITEM* Clone() const;
    EDA_ITEM* Clone() const;


    virtual wxString GetShownText() const;

    /// @copydoc VIEW_ITEM::ViewBBox()
    /// @copydoc VIEW_ITEM::ViewBBox()
    virtual const BOX2I ViewBBox() const;
    virtual const BOX2I ViewBBox() const;