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
|
|
|
|
*/
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.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>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <footprint.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2020-06-27 18:01:00 +00:00
|
|
|
#include <pcb_painter.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2021-03-03 16:38:41 +00:00
|
|
|
#include <kicad_string.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <geometry/shape_compound.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
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT::PCB_TEXT( 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
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT::~PCB_TEXT()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
wxString PCB_TEXT::GetShownText( int aDepth ) const
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
2020-09-12 14:23:07 +00:00
|
|
|
BOARD* board = dynamic_cast<BOARD*>( GetParent() );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
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
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
if( refItem && refItem->Type() == PCB_FOOTPRINT_T )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* refFP = static_cast<FOOTPRINT*>( refItem );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( refFP->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 );
|
|
|
|
};
|
|
|
|
|
2021-06-29 12:54:40 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText();
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2021-06-29 12:54:40 +00:00
|
|
|
if( board && HasTextVars() && aDepth < 10 )
|
2021-01-17 15:47:04 +00:00
|
|
|
text = ExpandTextVars( text, &pcbTextResolver, &boardTextResolver, board->GetProject() );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return text;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void PCB_TEXT::SetTextAngle( double aAngle )
|
2017-01-23 20:30:11 +00:00
|
|
|
{
|
2017-10-23 13:35:03 +00:00
|
|
|
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2020-11-30 14:35:48 +00:00
|
|
|
EDA_UNITS units = aFrame->GetUserUnits();
|
2009-05-01 16:46:56 +00:00
|
|
|
|
2021-03-03 16:38:41 +00:00
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
|
|
|
aList.emplace_back( _( "PCB Text" ), UnescapeString( GetText() ) );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2021-01-12 09:00:21 +00:00
|
|
|
if( IsLocked() )
|
2021-04-21 14:40:16 +00:00
|
|
|
aList.emplace_back( _( "Status" ), _( "Locked" ) );
|
2021-01-12 09:00:21 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName() );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-12-11 15:23:40 +00:00
|
|
|
aList.emplace_back( _( "Angle" ), wxString::Format( "%g", GetTextAngleDegrees() ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Thickness" ), MessageTextFromValue( units, GetTextThickness() ) );
|
|
|
|
aList.emplace_back( _( "Width" ), MessageTextFromValue( units, GetTextWidth() ) );
|
|
|
|
aList.emplace_back( _( "Height" ), MessageTextFromValue( units, GetTextHeight() ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
const EDA_RECT PCB_TEXT::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
|
|
|
|
2021-05-06 16:48:23 +00:00
|
|
|
bool PCB_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
return EDA_TEXT::TextHitTest( aPoint, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_TEXT::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(), GetDrawRotation() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void PCB_TEXT::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
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void PCB_TEXT::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2020-08-02 15:12:33 +00:00
|
|
|
if( aFlipLeftRight )
|
|
|
|
{
|
2021-03-18 21:09:45 +00:00
|
|
|
SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
|
|
|
|
SetTextAngle( -GetTextAngle() );
|
2020-08-02 15:12:33 +00:00
|
|
|
}
|
2020-05-15 21:17:24 +00:00
|
|
|
else
|
2020-08-02 15:12:33 +00:00
|
|
|
{
|
2021-03-18 21:09:45 +00:00
|
|
|
SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
|
|
|
|
SetTextAngle( 1800 - GetTextAngle() );
|
2020-08-02 15:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
|
|
|
SetMirrored( !IsMirrored() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
wxString PCB_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2020-09-19 18:53:58 +00:00
|
|
|
return wxString::Format( _( "PCB Text '%s' on %s"), ShortenedShownText(), GetLayerName() );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS PCB_TEXT::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::text;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
EDA_ITEM* PCB_TEXT::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
return new PCB_TEXT( *this );
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void PCB_TEXT::SwapData( BOARD_ITEM* aImage )
|
2017-10-31 13:59:03 +00:00
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_TEXT_T );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
std::swap( *((PCB_TEXT*) this), *((PCB_TEXT*) aImage) );
|
2017-10-31 13:59:03 +00:00
|
|
|
}
|
2020-03-26 11:02:59 +00:00
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
|
2020-08-08 22:37:41 +00:00
|
|
|
{
|
|
|
|
return GetEffectiveTextShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-02 18:40:14 +00:00
|
|
|
static struct TEXTE_PCB_DESC
|
|
|
|
{
|
|
|
|
TEXTE_PCB_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2020-10-04 23:34:59 +00:00
|
|
|
REGISTER_TYPE( PCB_TEXT );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_TEXT, BOARD_ITEM> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_TEXT, EDA_TEXT> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_TEXT ), TYPE_HASH( BOARD_ITEM ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ) );
|
2020-02-02 18:40:14 +00:00
|
|
|
}
|
|
|
|
} _TEXTE_PCB_DESC;
|