kicad/pcbnew/class_text_mod.cpp

568 lines
15 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file class_module.cpp
* @brief TEXT_MODULE class implementation.
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <trigo.h>
#include <class_drawpanel.h>
2018-01-28 21:02:31 +00:00
#include <draw_graphic_text.h>
#include <kicad_string.h>
#include <richio.h>
#include <macros.h>
2018-01-29 20:58:58 +00:00
#include <pcb_edit_frame.h>
#include <msgpanel.h>
#include <base_units.h>
#include <bitmaps.h>
#include <class_board.h>
#include <class_module.h>
#include <view/view.h>
#include <pcbnew.h>
TEXTE_MODULE::TEXTE_MODULE( MODULE* parent, TEXT_TYPE text_type ) :
BOARD_ITEM( parent, PCB_MODULE_TEXT_T ),
EDA_TEXT()
{
MODULE* module = static_cast<MODULE*>( m_Parent );
m_Type = text_type;
m_keepUpright = true;
2016-02-11 15:02:37 +00:00
// Set text thickness to a default value
SetThickness( Millimeter2iu( 0.15 ) );
SetLayer( F_SilkS );
// Set position and give a default layer if a valid parent footprint exists
if( module && ( module->Type() == PCB_MODULE_T ) )
{
SetTextPos( module->GetPosition() );
2007-08-23 04:28:46 +00:00
if( IsBackLayer( module->GetLayer() ) )
{
SetLayer( B_SilkS );
SetMirrored( true );
}
}
SetDrawCoord();
}
2007-09-01 12:00:30 +00:00
TEXTE_MODULE::~TEXTE_MODULE()
{
}
void TEXTE_MODULE::SetTextAngle( double aAngle )
{
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
}
2017-05-10 09:40:49 +00:00
2017-05-02 06:44:41 +00:00
bool TEXTE_MODULE::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
{
EDA_RECT rect = GetTextBox( -1 );
wxPoint location = aPoint;
rect.Inflate( aAccuracy );
RotatePoint( &location, GetTextPos(), -GetDrawRotation() );
return rect.Contains( location );
}
2017-05-10 09:40:49 +00:00
2017-05-02 06:44:41 +00:00
bool TEXTE_MODULE::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
{
EDA_RECT rect = aRect;
rect.Inflate( aAccuracy );
if( aContains )
{
return rect.Contains( GetBoundingBox() );
}
else
{
return rect.Intersects( GetTextBox( -1 ), GetDrawRotation() );
}
}
void TEXTE_MODULE::Rotate( const wxPoint& aRotCentre, double aAngle )
{
// Used in footprint editing
// Note also in module editor, m_Pos0 = m_Pos
wxPoint pt = GetTextPos();
RotatePoint( &pt, aRotCentre, aAngle );
SetTextPos( pt );
SetTextAngle( GetTextAngle() + aAngle );
SetLocalCoord();
}
void TEXTE_MODULE::Flip( const wxPoint& aCentre )
{
// flipping the footprint is relative to the X axis
SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
SetTextAngle( -GetTextAngle() );
SetLayer( FlipLayer( GetLayer() ) );
SetMirrored( IsBackLayer( GetLayer() ) );
SetLocalCoord();
}
bool TEXTE_MODULE::IsParentFlipped() const
{
if( GetParent() && GetParent()->GetLayer() == B_Cu )
return true;
return false;
}
void TEXTE_MODULE::Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis )
{
// Used in modedit, to transform the footprint
// the mirror is around the Y axis or X axis if aMirrorAroundXAxis = true
// the position is mirrored, but the text itself is not mirrored
if( aMirrorAroundXAxis )
SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
else
SetTextX( ::Mirror( GetTextPos().x, aCentre.x ) );
SetLocalCoord();
}
void TEXTE_MODULE::Move( const wxPoint& aMoveVector )
{
Offset( aMoveVector );
SetLocalCoord();
}
int TEXTE_MODULE::GetLength() const
{
return m_Text.Len();
}
void TEXTE_MODULE::SetDrawCoord()
{
const MODULE* module = static_cast<const MODULE*>( m_Parent );
SetTextPos( m_Pos0 );
if( module )
{
double angle = module->GetOrientation();
wxPoint pt = GetTextPos();
RotatePoint( &pt, angle );
SetTextPos( pt );
Offset( module->GetPosition() );
}
}
void TEXTE_MODULE::SetLocalCoord()
{
const MODULE* module = static_cast<const MODULE*>( m_Parent );
if( module )
{
m_Pos0 = GetTextPos() - module->GetPosition();
double angle = module->GetOrientation();
RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
}
else
2009-08-11 10:27:21 +00:00
{
m_Pos0 = GetTextPos();
2009-08-11 10:27:21 +00:00
}
}
const EDA_RECT TEXTE_MODULE::GetBoundingBox() const
{
double angle = GetDrawRotation();
EDA_RECT text_area = GetTextBox( -1, -1 );
2008-04-01 05:21:50 +00:00
if( angle )
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
2008-04-01 05:21:50 +00:00
return text_area;
}
void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
const wxPoint& aOffset )
{
if( aPanel == NULL )
return;
/* parent must *not* be NULL (a footprint text without a footprint
parent has no sense) */
wxASSERT( m_Parent );
BOARD* brd = GetBoard( );
auto frame = static_cast<PCB_BASE_FRAME*> ( aPanel->GetParent() );
auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
PCB_LAYER_ID text_layer = GetLayer();
if( !brd->IsLayerVisible( m_Layer )
|| ( IsFrontLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_FR ) )
|| ( IsBackLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_BK ) ) )
return;
if( !brd->IsElementVisible( LAYER_MOD_REFERENCES ) && GetText() == wxT( "%R" ) )
return;
if( !brd->IsElementVisible( LAYER_MOD_VALUES ) && GetText() == wxT( "%V" ) )
return;
// Invisible texts are still drawn (not plotted) in LAYER_MOD_TEXT_INVISIBLE
// Just because we must have to edit them (at least to make them visible)
if( !IsVisible() )
{
if( !brd->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) )
return;
color = frame->Settings().Colors().GetItemColor( LAYER_MOD_TEXT_INVISIBLE );
}
2008-03-04 04:22:27 +00:00
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( aPanel->GetDisplayOptions() );
2015-05-27 20:13:51 +00:00
// shade text if high contrast mode is active
if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
2015-05-27 20:13:51 +00:00
{
PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) aPanel->GetScreen() )->m_Active_Layer;
2015-05-27 20:13:51 +00:00
if( !IsOnLayer( curr_layer ) )
color = COLOR4D( DARKDARKGRAY );
2015-05-27 20:13:51 +00:00
}
// Draw mode compensation for the width
int width = GetThickness();
if( displ_opts && displ_opts->m_DisplayModTextFill == SKETCH )
width = -width;
GRSetDrawMode( aDC, aDrawMode );
wxPoint pos = GetTextPos() - aOffset;
// Draw the text anchor point
if( brd->IsElementVisible( LAYER_ANCHOR ) )
{
COLOR4D anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
GRDrawAnchor( aPanel->GetClipBox(), aDC, pos.x, pos.y, DIM_ANCRE_TEXTE, anchor_color );
2009-10-10 01:25:53 +00:00
}
// Draw the text proper, with the right attributes
wxSize size = GetTextSize();
double orient = GetDrawRotation();
// If the text is mirrored : negate size.x (mirror / Y axis)
if( IsMirrored() )
size.x = -size.x;
DrawGraphicText( aPanel->GetClipBox(), aDC, pos, color, GetShownText(), orient,
size, GetHorizJustify(), GetVertJustify(),
width, IsItalic(), IsBold() );
// Enable these line to draw the bounding box (debug test purpose only)
#if 0
{
EDA_RECT BoundaryBox = GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, BoundaryBox, 0, BROWN );
}
#endif
}
void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
GR_DRAWMODE aDrawMode,
const wxPoint& aOffset )
{
MODULE* parent = static_cast<MODULE*>( GetParent() );
if( !parent )
return;
GRSetDrawMode( aDC, GR_XOR );
GRLine( aPanel->GetClipBox(), aDC,
parent->GetPosition(), GetTextPos() + aOffset,
0, UMBILICAL_COLOR);
}
double TEXTE_MODULE::GetDrawRotation() const
{
MODULE* module = (MODULE*) m_Parent;
double rotation = GetTextAngle();
if( module )
rotation += module->GetOrientation();
if( m_keepUpright )
{
// Keep angle between -90 .. 90 deg. Otherwise the text is not easy to read
while( rotation > 900 )
rotation -= 1800;
while( rotation < -900 )
rotation += 1800;
}
else
{
NORMALIZE_ANGLE_POS( rotation );
}
return rotation;
}
2008-03-04 04:22:27 +00:00
// see class_text_mod.h
void TEXTE_MODULE::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
{
MODULE* module = (MODULE*) m_Parent;
2009-08-11 10:27:21 +00:00
if( module == NULL ) // Happens in modedit, and for new texts
return;
2009-08-11 10:27:21 +00:00
wxString msg, Line;
2008-03-04 04:22:27 +00:00
static const wxString text_type_msg[3] =
{
_( "Ref." ), _( "Value" ), _( "Text" )
};
2008-03-04 04:22:27 +00:00
Line = module->GetReference();
aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), Line, DARKCYAN ) );
Line = GetShownText();
aList.push_back( MSG_PANEL_ITEM( _( "Text" ), Line, BROWN ) );
wxASSERT( m_Type >= TEXT_is_REFERENCE && m_Type <= TEXT_is_DIVERS );
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), text_type_msg[m_Type], DARKGREEN ) );
if( !IsVisible() )
msg = _( "No" );
else
msg = _( "Yes" );
aList.push_back( MSG_PANEL_ITEM( _( "Display" ), msg, DARKGREEN ) );
// Display text layer
aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), DARKGREEN ) );
if( IsMirrored() )
msg = _( "Yes" );
else
msg = _( "No" );
aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );
msg.Printf( wxT( "%.1f" ), GetTextAngleDegrees() );
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
msg = MessageTextFromValue( aUnits, GetThickness(), true );
aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, DARKGREEN ) );
msg = MessageTextFromValue( aUnits, GetTextWidth(), true );
aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
msg = MessageTextFromValue( aUnits, GetTextHeight(), true );
aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
}
wxString TEXTE_MODULE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
{
switch( m_Type )
{
case TEXT_is_REFERENCE:
return wxString::Format( _( "Reference %s" ),
static_cast<MODULE*>( GetParent() )->GetReference() );
case TEXT_is_VALUE:
return wxString::Format( _( "Value %s of %s" ),
GetShownText(),
static_cast<MODULE*>( GetParent() )->GetReference() );
default: // wrap this one in quotes:
return wxString::Format( _( "Text \"%s\" of %s on %s" ),
ShortenedShownText(),
static_cast<MODULE*>( GetParent() )->GetReference(),
GetLayerName() );
}
}
BITMAP_DEF TEXTE_MODULE::GetMenuImage() const
{
return footprint_text_xpm;
}
EDA_ITEM* TEXTE_MODULE::Clone() const
{
return new TEXTE_MODULE( *this );
}
2014-01-07 13:09:27 +00:00
const BOX2I TEXTE_MODULE::ViewBBox() const
{
double angle = GetDrawRotation();
EDA_RECT text_area = GetTextBox( -1, -1 );
if( angle )
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
2014-01-07 13:09:27 +00:00
return BOX2I( text_area.GetPosition(), text_area.GetSize() );
}
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
{
if( IsVisible() )
aLayers[0] = GetLayer();
else
aLayers[0] = LAYER_MOD_TEXT_INVISIBLE;
aCount = 1;
}
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
2016-12-09 11:04:32 +00:00
unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
{
const int HIDE = std::numeric_limits<unsigned int>::max();
if( !aView )
return 0;
// Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but
// should only render if its native layer is visible.
if( !aView->IsLayerVisible( GetLayer() ) )
return HIDE;
// Handle Render tab switches
if( ( m_Type == TEXT_is_VALUE || m_Text == wxT( "%V" ) )
&& !aView->IsLayerVisible( LAYER_MOD_VALUES ) )
return HIDE;
if( ( m_Type == TEXT_is_REFERENCE || m_Text == wxT( "%R" ) )
&& !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) )
return HIDE;
if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
return HIDE;
if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
return HIDE;
if( IsFrontLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) )
return HIDE;
if( IsBackLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) )
return HIDE;
// Other layers are shown without any conditions
return 0;
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
}
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;
}