2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-08-19 18:21:24 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-01-14 19:50:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <base_struct.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <base_units.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_pcb_text.h>
|
2020-06-27 18:01:00 +00:00
|
|
|
#include <pcb_painter.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
|
|
|
|
using KIGFX::PCB_RENDER_SETTINGS;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
TEXTE_PCB::TEXTE_PCB( BOARD_ITEM* parent ) :
|
2011-10-01 19:24:27 +00:00
|
|
|
BOARD_ITEM( parent, PCB_TEXT_T ),
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
TEXTE_PCB::~TEXTE_PCB()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString TEXTE_PCB::GetShownText( int aDepth ) const
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
BOARD* board = static_cast<BOARD*>( GetParent() );
|
2020-03-26 11:02:59 +00:00
|
|
|
wxASSERT( board );
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
std::function<bool( wxString* )> pcbTextResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
|
|
|
if( token->IsSameAs( wxT( "LAYER" ) ) )
|
|
|
|
{
|
|
|
|
*token = GetLayerName();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
if( token->Contains( ':' ) )
|
|
|
|
{
|
2020-04-11 19:12:49 +00:00
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token->BeforeFirst( ':', &remainder );
|
|
|
|
BOARD_ITEM* refItem = board->GetItem( KIID( ref ) );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
if( refItem && refItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* refModule = static_cast<MODULE*>( refItem );
|
|
|
|
|
2020-04-11 19:12:49 +00:00
|
|
|
if( refModule->ResolveTextVar( &remainder, aDepth + 1 ) )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2020-04-11 19:12:49 +00:00
|
|
|
*token = remainder;
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 19:51:48 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-08-19 18:21:24 +00:00
|
|
|
std::function<bool( wxString* )> boardTextResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
return board->ResolveTextVar( token, aDepth + 1 );
|
|
|
|
};
|
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
bool processTextVars = false;
|
|
|
|
wxString text = EDA_TEXT::GetShownText( &processTextVars );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
if( processTextVars && aDepth < 10 )
|
2020-08-19 18:21:24 +00:00
|
|
|
text = ExpandTextVars( text, &pcbTextResolver, board->GetProject(), &boardTextResolver );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return text;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void TEXTE_PCB::SetTextAngle( double aAngle )
|
|
|
|
{
|
2017-10-23 13:35:03 +00:00
|
|
|
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void TEXTE_PCB::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-05-01 16:46:56 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2015-02-28 20:50:35 +00:00
|
|
|
wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
|
2008-03-11 05:41:33 +00:00
|
|
|
|
2015-02-28 20:50:35 +00:00
|
|
|
if( m_Parent->Type() == PCB_DIMENSION_T )
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Dimension" ), GetShownText(), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "PCB Text" ), GetShownText(), DARKGREEN );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName(), BLUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( !IsMirrored() )
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Mirror" ), _( "No" ), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Mirror" ), _( "Yes" ), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Angle" ), msg, DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextThickness() );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Thickness" ), msg, MAGENTA );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextWidth() );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Width" ), msg, RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextHeight() );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Height" ), msg, RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT TEXTE_PCB::GetBoundingBox() const
|
2013-11-05 17:12:27 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_RECT rect = GetTextBox();
|
2013-11-05 17:12:27 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextAngle() )
|
|
|
|
rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
|
2013-11-05 17:12:27 +00:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, aRotCentre, aAngle );
|
|
|
|
SetTextPos( pt );
|
|
|
|
|
|
|
|
SetTextAngle( GetTextAngle() + aAngle );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
void TEXTE_PCB::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2020-08-02 15:12:33 +00:00
|
|
|
double angle = GetTextAngle();
|
|
|
|
bool vertical = KiROUND( angle ) % 1800 == 900;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-08-02 15:12:33 +00:00
|
|
|
if( KiROUND( angle ) != 0 )
|
|
|
|
{
|
|
|
|
Rotate( aCentre, -angle );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-08-02 15:12:33 +00:00
|
|
|
if( vertical )
|
|
|
|
aFlipLeftRight = !aFlipLeftRight;
|
|
|
|
}
|
2019-04-06 23:17:12 +00:00
|
|
|
|
2020-08-02 15:12:33 +00:00
|
|
|
// Flip the bounding box
|
|
|
|
EDA_RECT box = GetTextBox();
|
|
|
|
int left = box.GetLeft();
|
|
|
|
int right = box.GetRight();
|
|
|
|
int top = box.GetTop();
|
|
|
|
int bottom = box.GetBottom();
|
|
|
|
|
|
|
|
if( aFlipLeftRight )
|
|
|
|
{
|
|
|
|
MIRROR( left, aCentre.x );
|
|
|
|
MIRROR( right, aCentre.x );
|
|
|
|
std::swap( left, right );
|
|
|
|
}
|
2020-05-15 21:17:24 +00:00
|
|
|
else
|
2020-08-02 15:12:33 +00:00
|
|
|
{
|
|
|
|
MIRROR( top, aCentre.y );
|
|
|
|
MIRROR( bottom, aCentre.y );
|
|
|
|
std::swap( top, bottom );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now put the text back in it (these look backwards but remember that out text will
|
|
|
|
// be mirrored when all is said and done)
|
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT: SetTextX( right ); break;
|
|
|
|
case GR_TEXT_HJUSTIFY_CENTER: SetTextX( ( left + right ) / 2 ); break;
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT: SetTextX( left ); break;
|
|
|
|
}
|
2020-05-15 21:17:24 +00:00
|
|
|
|
2020-08-02 15:12:33 +00:00
|
|
|
switch( GetVertJustify() )
|
2019-04-06 23:17:12 +00:00
|
|
|
{
|
2020-08-02 15:12:33 +00:00
|
|
|
case GR_TEXT_VJUSTIFY_TOP: SetTextY( bottom ); break;
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER: SetTextY( ( top + bottom ) / 2 ); break;
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM: SetTextY( top ); break;
|
2019-04-06 23:17:12 +00:00
|
|
|
}
|
2020-08-02 15:12:33 +00:00
|
|
|
|
|
|
|
// And restore orientation
|
|
|
|
if( KiROUND( angle ) != 0 )
|
|
|
|
Rotate( aCentre, angle );
|
|
|
|
|
|
|
|
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
|
|
|
SetMirrored( !IsMirrored() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString TEXTE_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Pcb Text \"%s\" on %s"), ShortenedShownText(), GetLayerName() );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF TEXTE_PCB::GetMenuImage() const
|
|
|
|
{
|
2017-06-02 09:51:11 +00:00
|
|
|
return text_xpm;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* TEXTE_PCB::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new TEXTE_PCB( *this );
|
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2017-10-31 13:59:03 +00:00
|
|
|
void TEXTE_PCB::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_TEXT_T );
|
|
|
|
|
|
|
|
std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
|
|
|
|
}
|
2020-03-26 11:02:59 +00:00
|
|
|
|
|
|
|
|
2020-08-08 22:37:41 +00:00
|
|
|
std::shared_ptr<SHAPE> TEXTE_PCB::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
|
|
|
|
{
|
|
|
|
return GetEffectiveTextShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-02 18:40:14 +00:00
|
|
|
static struct TEXTE_PCB_DESC
|
|
|
|
{
|
|
|
|
TEXTE_PCB_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( TEXTE_PCB );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<TEXTE_PCB, BOARD_ITEM> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<TEXTE_PCB, EDA_TEXT> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( TEXTE_PCB ), TYPE_HASH( BOARD_ITEM ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( TEXTE_PCB ), TYPE_HASH( EDA_TEXT ) );
|
|
|
|
}
|
|
|
|
} _TEXTE_PCB_DESC;
|