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
This commit is contained in:
parent
8b3c14c08b
commit
94f8c2a276
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue