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>
|
2022-01-10 01:53:01 +00:00
|
|
|
* Copyright (C) 1992-2022 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
|
|
|
|
*/
|
|
|
|
|
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-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <geometry/shape_compound.h>
|
2022-01-10 14:03:53 +00:00
|
|
|
#include <callback_gal.h>
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.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::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-10-31 16:32:24 +00:00
|
|
|
if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && 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
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetTextAngle().AsDegrees() ) );
|
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
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
if( !GetTextAngle().IsZero() )
|
2022-01-16 21:15:20 +00:00
|
|
|
rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
|
2013-11-05 17:12:27 +00:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
|
2021-05-06 16:48:23 +00:00
|
|
|
{
|
|
|
|
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() );
|
2021-12-05 23:50:33 +00:00
|
|
|
|
2021-12-06 00:05:14 +00:00
|
|
|
return rect.Intersects( GetBoundingBox() );
|
2021-05-06 16:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-13 19:32:00 +00:00
|
|
|
void PCB_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pt = GetTextPos();
|
|
|
|
RotatePoint( pt, aRotCentre, aAngle );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( pt );
|
|
|
|
|
2022-02-01 17:06:58 +00:00
|
|
|
EDA_ANGLE new_angle = GetTextAngle() + aAngle;
|
|
|
|
new_angle.Normalize180();
|
|
|
|
SetTextAngle( new_angle );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_TEXT::Flip( const VECTOR2I& 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 ) );
|
2022-01-13 23:30:52 +00:00
|
|
|
SetTextAngle( ANGLE_180 - 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-25 19:50:33 +00:00
|
|
|
void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
2022-01-10 01:53:01 +00:00
|
|
|
PCB_LAYER_ID aLayer, int aClearance,
|
2021-10-25 19:50:33 +00:00
|
|
|
int aError, ERROR_LOC aErrorLoc ) const
|
|
|
|
{
|
2022-01-10 14:03:53 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
|
|
|
KIFONT::FONT* font = GetDrawFont();
|
|
|
|
int penWidth = GetEffectiveTextPenWidth();
|
2021-10-25 19:50:33 +00:00
|
|
|
|
2022-01-10 14:03:53 +00:00
|
|
|
CALLBACK_GAL callback_gal( empty_opts,
|
2022-01-10 01:53:01 +00:00
|
|
|
// Stroke callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
|
|
|
TransformOvalToPolygon( aCornerBuffer, aPt1, aPt2, penWidth+ ( 2 * aClearance ),
|
|
|
|
aError, ERROR_INSIDE );
|
|
|
|
},
|
|
|
|
// Triangulation callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
|
|
|
{
|
|
|
|
aCornerBuffer.NewOutline();
|
2021-10-25 19:50:33 +00:00
|
|
|
|
2022-01-10 01:53:01 +00:00
|
|
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
|
|
|
aCornerBuffer.Append( point.x, point.y );
|
|
|
|
} );
|
2022-01-10 14:03:53 +00:00
|
|
|
|
|
|
|
font->Draw( &callback_gal, GetShownText(), GetTextPos(), GetAttributes() );
|
2021-10-25 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_TEXT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
PCB_LAYER_ID aLayer, int aClearance,
|
|
|
|
int aError, ERROR_LOC aErrorLoc,
|
|
|
|
bool aIgnoreLineWidth ) const
|
|
|
|
{
|
|
|
|
EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon( &aCornerBuffer, aClearance );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|