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>
|
2023-01-17 16:54:08 +00:00
|
|
|
* Copyright (C) 1992-2023 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
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
PCB_TEXT::PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype ) :
|
2023-03-30 11:49:23 +00:00
|
|
|
BOARD_ITEM( parent, idtype ),
|
|
|
|
EDA_TEXT( pcbIUScale ),
|
|
|
|
m_type( TEXT_is_DIVERS )
|
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
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent, TEXT_TYPE text_type ) :
|
|
|
|
BOARD_ITEM( aParent, PCB_TEXT_T ),
|
|
|
|
EDA_TEXT( pcbIUScale ),
|
|
|
|
m_type( text_type )
|
|
|
|
{
|
|
|
|
SetKeepUpright( true );
|
|
|
|
|
|
|
|
// Set text thickness to a default value
|
|
|
|
SetTextThickness( pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ) );
|
|
|
|
SetLayer( F_SilkS );
|
|
|
|
|
|
|
|
if( aParent )
|
|
|
|
{
|
|
|
|
SetTextPos( aParent->GetPosition() );
|
|
|
|
|
|
|
|
if( IsBackLayer( aParent->GetLayer() ) )
|
|
|
|
{
|
|
|
|
SetLayer( B_SilkS );
|
|
|
|
SetMirrored( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-10-22 10:50:26 +00:00
|
|
|
wxString PCB_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
const FOOTPRINT* parentFootprint = GetParentFootprint();
|
|
|
|
const BOARD* board = GetBoard();
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
std::function<bool( wxString* )> resolver =
|
2020-04-06 13:06:57 +00:00
|
|
|
[&]( wxString* token ) -> bool
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
|
|
|
|
return true;
|
|
|
|
|
2020-04-05 19:51:48 +00:00
|
|
|
if( token->IsSameAs( wxT( "LAYER" ) ) )
|
|
|
|
{
|
|
|
|
*token = GetLayerName();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-17 16:54:08 +00:00
|
|
|
if( board->ResolveTextVar( token, aDepth + 1 ) )
|
|
|
|
return true;
|
2020-04-05 19:51:48 +00:00
|
|
|
|
2023-01-17 16:54:08 +00:00
|
|
|
return false;
|
2020-08-19 18:21:24 +00:00
|
|
|
};
|
|
|
|
|
2021-06-29 12:54:40 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText();
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( HasTextVars() )
|
|
|
|
{
|
|
|
|
if( aDepth < 10 )
|
|
|
|
text = ExpandTextVars( text, &resolver );
|
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return text;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
EDA_ANGLE PCB_TEXT::GetDrawRotation() const
|
|
|
|
{
|
|
|
|
EDA_ANGLE rotation = GetTextAngle();
|
|
|
|
|
|
|
|
if( GetParentFootprint() && IsKeepUpright() )
|
|
|
|
{
|
|
|
|
// Keep angle between ]-90..90] deg. Otherwise the text is not easy to read
|
|
|
|
while( rotation > ANGLE_90 )
|
|
|
|
rotation -= ANGLE_180;
|
|
|
|
|
|
|
|
while( rotation <= -ANGLE_90 )
|
|
|
|
rotation += ANGLE_180;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rotation.Normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const BOX2I PCB_TEXT::ViewBBox() const
|
|
|
|
{
|
|
|
|
EDA_ANGLE angle = GetDrawRotation();
|
|
|
|
BOX2I text_area = GetTextBox();
|
|
|
|
|
|
|
|
if( !angle.IsZero() )
|
|
|
|
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
|
|
|
|
|
|
|
|
return BOX2I( text_area.GetPosition(), text_area.GetSize() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
if( GetParentFootprint() == nullptr || IsVisible() )
|
|
|
|
aLayers[0] = GetLayer();
|
|
|
|
else
|
|
|
|
aLayers[0] = LAYER_MOD_TEXT_INVISIBLE;
|
|
|
|
|
|
|
|
aCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-07 17:03:06 +00:00
|
|
|
double PCB_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
|
|
|
{
|
|
|
|
constexpr double HIDE = std::numeric_limits<double>::max();
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( !aView )
|
|
|
|
return 0.0;
|
|
|
|
|
2022-03-07 17:03:06 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( aView->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
// 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;
|
|
|
|
|
2022-03-07 17:03:06 +00:00
|
|
|
if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
|
|
|
|
{
|
|
|
|
// Hide shadow on dimmed tracks
|
|
|
|
if( renderSettings->GetHighContrast() )
|
|
|
|
{
|
|
|
|
if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
|
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( FOOTPRINT* parentFP = GetParentFootprint() )
|
|
|
|
{
|
|
|
|
// Handle Render tab switches
|
|
|
|
if( m_type == TEXT_is_VALUE || GetText() == wxT( "${VALUE}" ) )
|
|
|
|
{
|
|
|
|
if( !aView->IsLayerVisible( LAYER_MOD_VALUES ) )
|
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_type == TEXT_is_REFERENCE || GetText() == wxT( "${REFERENCE}" ) )
|
|
|
|
{
|
|
|
|
if( !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) )
|
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_MOD_FR ) )
|
|
|
|
return HIDE;
|
|
|
|
|
|
|
|
if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_MOD_BK ) )
|
|
|
|
return HIDE;
|
|
|
|
|
|
|
|
if( !aView->IsLayerVisible( LAYER_MOD_TEXT ) )
|
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:03:06 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* parentFP = GetParentFootprint();
|
|
|
|
|
|
|
|
if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
|
|
|
|
aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
|
|
|
|
|
2021-03-03 16:38:41 +00:00
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
|
|
|
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
|
|
|
else
|
|
|
|
aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
|
|
|
|
|
|
|
if( parentFP )
|
|
|
|
{
|
|
|
|
switch( m_type )
|
|
|
|
{
|
|
|
|
case TEXT_is_REFERENCE: aList.emplace_back( _( "Type" ), _( "Reference" ) ); break;
|
|
|
|
case TEXT_is_VALUE: aList.emplace_back( _( "Type" ), _( "Value" ) ); break;
|
|
|
|
case TEXT_is_DIVERS: aList.emplace_back( _( "Type" ), _( "Text" ) ); break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
|
|
|
aList.emplace_back( _( "Display" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
|
|
|
|
|
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
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
|
2022-09-19 09:25:20 +00:00
|
|
|
aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) );
|
|
|
|
aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
|
|
|
|
aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-08-05 22:57:37 +00:00
|
|
|
int PCB_TEXT::getKnockoutMargin() const
|
|
|
|
{
|
|
|
|
VECTOR2I textSize( GetTextWidth(), GetTextHeight() );
|
|
|
|
int thickness = GetTextThickness();
|
|
|
|
|
|
|
|
return thickness * 1.5 + GetKnockoutTextMargin( textSize, thickness );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCB_TEXT::KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation )
|
|
|
|
{
|
|
|
|
if( !IsKeepUpright() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation;
|
|
|
|
newAngle.Normalize();
|
|
|
|
|
|
|
|
bool needsFlipped = newAngle >= ANGLE_180;
|
|
|
|
|
|
|
|
if( needsFlipped )
|
|
|
|
{
|
|
|
|
SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) );
|
|
|
|
SetTextAngle( GetTextAngle() + ANGLE_180 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I PCB_TEXT::GetBoundingBox() const
|
2013-11-05 17:12:27 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
EDA_ANGLE angle = GetDrawRotation();
|
|
|
|
BOX2I rect = GetTextBox();
|
2013-11-05 17:12:27 +00:00
|
|
|
|
2022-08-05 22:57:37 +00:00
|
|
|
if( IsKnockout() )
|
|
|
|
rect.Inflate( getKnockoutMargin() );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( !angle.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
|
|
|
{
|
2022-08-05 22:57:37 +00:00
|
|
|
if( IsKnockout() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
TransformBoundingBoxToPolygon( &poly, getKnockoutMargin());
|
2022-08-05 22:57:37 +00:00
|
|
|
|
|
|
|
return poly.Collide( aPoint, aAccuracy );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return EDA_TEXT::TextHitTest( aPoint, aAccuracy );
|
|
|
|
}
|
2021-05-06 16:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
|
2021-05-06 16:48:23 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I rect = aRect;
|
2021-05-06 16:48:23 +00:00
|
|
|
|
|
|
|
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-09-22 14:05:06 +00:00
|
|
|
void PCB_TEXT::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
|
|
|
|
{
|
|
|
|
// the position and justification are mirrored, but not the text itself
|
|
|
|
|
|
|
|
if( aMirrorAroundXAxis )
|
|
|
|
{
|
|
|
|
if( GetTextAngle() == ANGLE_VERTICAL )
|
|
|
|
SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() );
|
|
|
|
|
|
|
|
SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( GetTextAngle() == ANGLE_HORIZONTAL )
|
|
|
|
SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() );
|
|
|
|
|
|
|
|
SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() ) );
|
2022-10-24 15:22:27 +00:00
|
|
|
|
2022-10-25 11:08:32 +00:00
|
|
|
if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() )
|
2022-10-24 15:22:27 +00:00
|
|
|
SetMirrored( !IsMirrored() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( FOOTPRINT* parentFP = GetParentFootprint() )
|
|
|
|
{
|
|
|
|
switch( m_type )
|
|
|
|
{
|
|
|
|
case TEXT_is_REFERENCE:
|
|
|
|
return wxString::Format( _( "Reference '%s'" ),
|
|
|
|
parentFP->GetReference() );
|
|
|
|
|
|
|
|
case TEXT_is_VALUE:
|
|
|
|
return wxString::Format( _( "Value '%s' of %s" ),
|
|
|
|
GetShownText(),
|
|
|
|
parentFP->GetReference() );
|
|
|
|
|
|
|
|
case TEXT_is_DIVERS:
|
|
|
|
return wxString::Format( _( "Footprint Text '%s' of %s" ),
|
|
|
|
KIUI::EllipsizeMenuText( GetShownText() ),
|
|
|
|
parentFP->GetReference() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return wxString::Format( _( "PCB Text '%s' on %s"),
|
|
|
|
KIUI::EllipsizeMenuText( GetShownText() ),
|
|
|
|
GetLayerName() );
|
|
|
|
}
|
2023-03-31 22:53:11 +00:00
|
|
|
|
|
|
|
// Can't get here, but gcc doesn't seem to know that....
|
|
|
|
return wxEmptyString;
|
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
|
|
|
|
2022-11-11 17:09:25 +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
|
|
|
|
|
|
|
|
2022-03-16 23:48:24 +00:00
|
|
|
std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
|
2020-08-08 22:37:41 +00:00
|
|
|
{
|
2023-01-25 18:33:31 +00:00
|
|
|
if( IsKnockout() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET knockouts;
|
|
|
|
|
|
|
|
TransformTextToPolySet( knockouts, aLayer, 0, GetBoard()->GetDesignSettings().m_MaxError,
|
|
|
|
ERROR_INSIDE );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET finalPoly;
|
|
|
|
int strokeWidth = GetEffectiveTextPenWidth();
|
|
|
|
VECTOR2I fontSize = GetTextSize();
|
|
|
|
int margin = strokeWidth * 1.5 + GetKnockoutTextMargin( fontSize, strokeWidth );
|
|
|
|
|
|
|
|
TransformBoundingBoxToPolygon( &finalPoly, margin );
|
|
|
|
finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
finalPoly.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
return std::make_shared<SHAPE_POLY_SET>( finalPoly );
|
|
|
|
}
|
|
|
|
|
2020-08-08 22:37:41 +00:00
|
|
|
return GetEffectiveTextShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
|
|
|
|
int aClearance, int aError, ERROR_LOC aErrorLoc ) const
|
2021-10-25 19:50:33 +00:00
|
|
|
{
|
2022-01-10 14:03:53 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = getDrawFont();
|
2022-01-10 14:03:53 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth();
|
2023-04-02 07:54:53 +00:00
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
|
|
|
|
|
|
|
attrs.m_Angle = GetDrawRotation();
|
2021-10-25 19:50:33 +00:00
|
|
|
|
2023-01-25 18:33:31 +00:00
|
|
|
// The polygonal shape of a text can have many basic shapes, so combining these shapes can
|
|
|
|
// be very useful to create a final shape with a lot less vertices to speedup calculations.
|
2022-10-16 17:02:12 +00:00
|
|
|
// Simplify shapes is not usually always efficient, but in this case it is.
|
|
|
|
SHAPE_POLY_SET buffer;
|
|
|
|
|
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 )
|
|
|
|
{
|
2023-04-02 07:54:53 +00:00
|
|
|
TransformOvalToPolygon( buffer, aPt1, aPt2, penWidth + ( 2 * aClearance ),
|
2022-01-10 01:53:01 +00:00
|
|
|
aError, ERROR_INSIDE );
|
|
|
|
},
|
|
|
|
// Triangulation callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
|
|
|
{
|
2022-10-16 17:02:12 +00:00
|
|
|
buffer.NewOutline();
|
2021-10-25 19:50:33 +00:00
|
|
|
|
2022-01-10 01:53:01 +00:00
|
|
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
2022-10-16 17:02:12 +00:00
|
|
|
buffer.Append( point.x, point.y );
|
2022-01-10 01:53:01 +00:00
|
|
|
} );
|
2022-01-10 14:03:53 +00:00
|
|
|
|
2023-04-02 07:54:53 +00:00
|
|
|
font->Draw( &callback_gal, GetShownText(), GetTextPos(), attrs );
|
2022-10-16 17:02:12 +00:00
|
|
|
buffer.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2023-04-02 07:54:53 +00:00
|
|
|
|
|
|
|
if( IsKnockout() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET finalPoly;
|
|
|
|
int margin = attrs.m_StrokeWidth * 1.5
|
|
|
|
+ GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
|
|
|
|
|
|
|
|
TransformBoundingBoxToPolygon( &finalPoly, margin );
|
|
|
|
finalPoly.BooleanSubtract( buffer, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
aBuffer.Append( finalPoly );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aBuffer.Append( buffer );
|
|
|
|
}
|
2021-10-25 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
void PCB_TEXT::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
|
|
|
|
int aClearance, int aError, ERROR_LOC aErrorLoc,
|
|
|
|
bool aIgnoreLineWidth ) const
|
2021-10-25 19:50:33 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
EDA_TEXT::TransformBoundingBoxToPolygon( &aBuffer, aClearance );
|
2021-10-25 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-25 01:34:40 +00:00
|
|
|
static struct PCB_TEXT_DESC
|
2020-02-02 18:40:14 +00:00
|
|
|
{
|
2022-11-25 01:34:40 +00:00
|
|
|
PCB_TEXT_DESC()
|
2020-02-02 18:40:14 +00:00
|
|
|
{
|
|
|
|
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 ) );
|
2022-12-03 02:46:03 +00:00
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, BOARD_ITEM>( _HKI( "Knockout" ),
|
|
|
|
&BOARD_ITEM::SetIsKnockout, &BOARD_ITEM::IsKnockout ),
|
|
|
|
_HKI( "Text Properties" ) );
|
2022-12-08 23:06:14 +00:00
|
|
|
|
2023-04-09 23:00:30 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, EDA_TEXT>( _HKI( "Keep Upright" ),
|
|
|
|
&PCB_TEXT::SetKeepUpright, &PCB_TEXT::IsKeepUpright ),
|
|
|
|
_HKI( "Text Properties" ) );
|
|
|
|
|
2022-12-08 23:06:14 +00:00
|
|
|
auto isFootprintText =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( PCB_TEXT* text = dynamic_cast<PCB_TEXT*>( aItem ) )
|
|
|
|
return text->GetParentFootprint();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ),
|
|
|
|
_HKI( "Visible" ), isFootprintText );
|
2022-12-22 22:44:51 +00:00
|
|
|
|
2023-04-09 23:00:30 +00:00
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ),
|
|
|
|
_HKI( "Keep Upright" ), isFootprintText );
|
|
|
|
|
2022-12-22 22:44:51 +00:00
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ),
|
|
|
|
_HKI( "Hyperlink" ),
|
|
|
|
[]( INSPECTABLE* aItem ) { return false; } );
|
2020-02-02 18:40:14 +00:00
|
|
|
}
|
2022-11-25 01:34:40 +00:00
|
|
|
} _PCB_TEXT_DESC;
|