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
|
|
|
|
*/
|
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
#include <google/protobuf/any.pb.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-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>
|
2024-01-20 23:35:29 +00:00
|
|
|
#include <api/api_enums.h>
|
|
|
|
#include <api/api_utils.h>
|
|
|
|
#include <api/board/board_types.pb.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace kiapi::common;
|
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 ),
|
2023-06-06 17:30:03 +00:00
|
|
|
EDA_TEXT( pcbIUScale )
|
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
|
|
|
|
2024-04-09 19:23:02 +00:00
|
|
|
PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype) :
|
|
|
|
BOARD_ITEM( aParent, idtype ),
|
2023-06-06 17:30:03 +00:00
|
|
|
EDA_TEXT( pcbIUScale )
|
2023-03-30 11:49:23 +00:00
|
|
|
{
|
|
|
|
SetKeepUpright( true );
|
|
|
|
|
|
|
|
// Set text thickness to a default value
|
|
|
|
SetTextThickness( pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ) );
|
|
|
|
SetLayer( F_SilkS );
|
|
|
|
|
|
|
|
if( aParent )
|
|
|
|
{
|
|
|
|
SetTextPos( aParent->GetPosition() );
|
|
|
|
|
2024-04-11 16:39:05 +00:00
|
|
|
// N.B. Do not automatically set text effects
|
|
|
|
// These are optional in the file format and so need to be defaulted
|
|
|
|
// to off.
|
2023-03-30 11:49:23 +00:00
|
|
|
if( IsBackLayer( aParent->GetLayer() ) )
|
|
|
|
SetLayer( B_SilkS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const
|
|
|
|
{
|
|
|
|
kiapi::board::types::Text boardText;
|
|
|
|
boardText.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
|
|
|
|
|
|
|
|
kiapi::common::types::Text& text = *boardText.mutable_text();
|
|
|
|
|
|
|
|
text.mutable_id()->set_value( m_Uuid.AsStdString() );
|
|
|
|
text.mutable_position()->set_x_nm( GetPosition().x );
|
|
|
|
text.mutable_position()->set_y_nm( GetPosition().y );
|
|
|
|
text.set_text( GetText().ToStdString() );
|
|
|
|
text.set_hyperlink( GetHyperlink().ToStdString() );
|
|
|
|
text.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
|
|
|
|
: types::LockedState::LS_UNLOCKED );
|
|
|
|
|
|
|
|
kiapi::common::types::TextAttributes* attrs = text.mutable_attributes();
|
|
|
|
|
|
|
|
if( GetFont() )
|
|
|
|
attrs->set_font_name( GetFont()->GetName().ToStdString() );
|
|
|
|
|
|
|
|
attrs->set_horizontal_alignment(
|
|
|
|
ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
|
|
|
|
|
|
|
|
attrs->set_vertical_alignment(
|
|
|
|
ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
|
|
|
|
|
|
|
|
attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
|
|
|
|
attrs->set_line_spacing( GetLineSpacing() );
|
|
|
|
attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
|
|
|
|
attrs->set_italic( IsItalic() );
|
|
|
|
attrs->set_bold( IsBold() );
|
|
|
|
attrs->set_underlined( GetAttributes().m_Underlined );
|
|
|
|
attrs->set_visible( IsVisible() );
|
|
|
|
attrs->set_mirrored( IsMirrored() );
|
|
|
|
attrs->set_multiline( IsMultilineAllowed() );
|
|
|
|
attrs->set_keep_upright( IsKeepUpright() );
|
|
|
|
attrs->mutable_size()->set_x_nm( GetTextSize().x );
|
|
|
|
attrs->mutable_size()->set_y_nm( GetTextSize().y );
|
|
|
|
|
|
|
|
text.set_knockout( IsKnockout() );
|
|
|
|
|
|
|
|
aContainer.PackFrom( boardText );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_TEXT::Deserialize( const google::protobuf::Any &aContainer )
|
|
|
|
{
|
|
|
|
kiapi::board::types::Text textWrapper;
|
|
|
|
|
|
|
|
if( !aContainer.UnpackTo( &textWrapper ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( textWrapper.layer() ) );
|
|
|
|
|
|
|
|
const kiapi::common::types::Text& text = textWrapper.text();
|
|
|
|
|
|
|
|
const_cast<KIID&>( m_Uuid ) = KIID( text.id().value() );
|
|
|
|
SetPosition( VECTOR2I( text.position().x_nm(), text.position().y_nm() ) );
|
|
|
|
SetLocked( text.locked() == kiapi::common::types::LockedState::LS_LOCKED );
|
|
|
|
SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
|
|
|
|
SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
|
|
|
|
SetIsKnockout( text.knockout() );
|
|
|
|
|
|
|
|
if( text.has_attributes() )
|
|
|
|
{
|
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
|
|
|
|
|
|
|
attrs.m_Bold = text.attributes().bold();
|
|
|
|
attrs.m_Italic = text.attributes().italic();
|
|
|
|
attrs.m_Underlined = text.attributes().underlined();
|
|
|
|
attrs.m_Visible = text.attributes().visible();
|
|
|
|
attrs.m_Mirrored = text.attributes().mirrored();
|
|
|
|
attrs.m_Multiline = text.attributes().multiline();
|
|
|
|
attrs.m_KeepUpright = text.attributes().keep_upright();
|
|
|
|
attrs.m_Size = VECTOR2I( text.attributes().size().x_nm(), text.attributes().size().y_nm() );
|
|
|
|
|
|
|
|
if( !text.attributes().font_name().empty() )
|
|
|
|
{
|
|
|
|
attrs.m_Font = KIFONT::FONT::GetFont(
|
|
|
|
wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
|
|
|
|
attrs.m_Italic );
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
|
|
|
|
attrs.m_LineSpacing = text.attributes().line_spacing();
|
|
|
|
SetTextThickness( text.attributes().stroke_width().value_nm() );
|
|
|
|
|
|
|
|
attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
|
|
|
|
text.attributes().horizontal_alignment() );
|
|
|
|
|
|
|
|
attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
|
|
|
|
text.attributes().vertical_alignment() );
|
|
|
|
|
|
|
|
SetAttributes( attrs );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString PCB_TEXT::GetShownText( bool aAllowExtraText, int aDepth ) 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
|
|
|
};
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
|
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-05-05 13:21:56 +00:00
|
|
|
bool PCB_TEXT::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
|
|
|
|
{
|
|
|
|
return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2023-05-27 21:00:21 +00:00
|
|
|
return GetBoundingBox();
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
if( GetParentFootprint() == nullptr || IsVisible() )
|
|
|
|
aLayers[0] = GetLayer();
|
|
|
|
else
|
2023-08-04 10:13:20 +00:00
|
|
|
aLayers[0] = LAYER_HIDDEN_TEXT;
|
2023-03-30 11:49:23 +00:00
|
|
|
|
|
|
|
aCount = 1;
|
2023-08-20 15:29:09 +00:00
|
|
|
|
|
|
|
if( IsLocked() )
|
|
|
|
aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-08-04 10:13:20 +00:00
|
|
|
// Hidden text gets put on the LAYER_HIDDEN_TEXT for rendering, but
|
2023-03-30 11:49:23 +00:00
|
|
|
// 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
|
2023-06-06 17:30:03 +00:00
|
|
|
if( GetText() == wxT( "${VALUE}" ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
{
|
2023-08-04 10:13:20 +00:00
|
|
|
if( !aView->IsLayerVisible( LAYER_FP_VALUES ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:30:03 +00:00
|
|
|
if( GetText() == wxT( "${REFERENCE}" ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
{
|
2023-08-04 10:13:20 +00:00
|
|
|
if( !aView->IsLayerVisible( LAYER_FP_REFERENCES ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
|
2023-08-04 10:13:20 +00:00
|
|
|
if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
return HIDE;
|
|
|
|
|
2023-08-04 10:13:20 +00:00
|
|
|
if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
return HIDE;
|
|
|
|
|
2023-08-04 10:13:20 +00:00
|
|
|
if( !aView->IsLayerVisible( LAYER_FP_TEXT ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
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 )
|
2023-06-06 17:30:03 +00:00
|
|
|
aList.emplace_back( _( "Type" ), GetTextTypeDescription() );
|
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
|
|
|
|
{
|
2023-05-26 14:39:48 +00:00
|
|
|
return GetKnockoutTextMargin( VECTOR2I( GetTextWidth(), GetTextHeight() ), GetTextThickness() );
|
2022-08-05 22:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 11:19:43 +00:00
|
|
|
void PCB_TEXT::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings )
|
|
|
|
{
|
|
|
|
SetTextSize( settings.GetTextSize( GetLayer() ) );
|
|
|
|
SetTextThickness( settings.GetTextThickness( GetLayer() ) );
|
|
|
|
SetItalic( settings.GetTextItalic( GetLayer() ) );
|
|
|
|
SetKeepUpright( settings.GetTextUpright( GetLayer() ) );
|
|
|
|
SetMirrored( IsBackLayer( GetLayer() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-22 21:20:36 +00:00
|
|
|
void PCB_TEXT::KeepUpright( const EDA_ANGLE& aNewOrientation )
|
2023-03-30 11:49:23 +00:00
|
|
|
{
|
|
|
|
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() )
|
2024-05-11 12:01:19 +00:00
|
|
|
rect = rect.GetBoundingBoxRotated( GetTextPos(), angle );
|
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
|
|
|
{
|
2023-05-28 16:20:11 +00:00
|
|
|
int accuracy = aAccuracy;
|
2022-08-05 22:57:37 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
if( IsKnockout() )
|
|
|
|
accuracy += GetKnockoutTextMargin( GetTextSize(), GetTextThickness() );
|
2022-08-05 22:57:37 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
return EDA_TEXT::TextHitTest( aPoint, accuracy );
|
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-06-06 17:30:03 +00:00
|
|
|
wxString PCB_TEXT::GetTextTypeDescription() const
|
|
|
|
{
|
|
|
|
return _( "Text" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
return wxString::Format( _( "Footprint Text '%s' of %s" ),
|
|
|
|
KIUI::EllipsizeMenuText( GetText() ), parentFP->GetReference() );
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
2023-08-20 15:29:09 +00:00
|
|
|
|
2023-07-16 13:40:44 +00:00
|
|
|
return wxString::Format( _( "PCB Text '%s' on %s" ),
|
|
|
|
KIUI::EllipsizeMenuText( GetText() ),
|
|
|
|
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
|
|
|
|
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() )
|
|
|
|
{
|
2023-05-28 16:20:11 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2023-01-25 18:33:31 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
TransformTextToPolySet( poly, 0, GetBoard()->GetDesignSettings().m_MaxError, ERROR_INSIDE );
|
2023-01-25 18:33:31 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
return std::make_shared<SHAPE_POLY_SET>( poly );
|
2023-01-25 18:33:31 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 22:37:41 +00:00
|
|
|
return GetEffectiveTextShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
void PCB_TEXT::buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
|
|
|
|
int aClearance ) const
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly( aRenderedText );
|
|
|
|
|
|
|
|
poly.Rotate( -GetDrawRotation(), GetDrawPos() );
|
|
|
|
|
|
|
|
BOX2I rect = poly.BBox( aClearance );
|
|
|
|
VECTOR2I corners[4];
|
|
|
|
|
|
|
|
corners[0].x = rect.GetOrigin().x;
|
|
|
|
corners[0].y = rect.GetOrigin().y;
|
|
|
|
corners[1].y = corners[0].y;
|
|
|
|
corners[1].x = rect.GetRight();
|
|
|
|
corners[2].x = corners[1].x;
|
|
|
|
corners[2].y = rect.GetBottom();
|
|
|
|
corners[3].y = corners[2].y;
|
|
|
|
corners[3].x = corners[0].x;
|
|
|
|
|
|
|
|
aBuffer->NewOutline();
|
|
|
|
|
|
|
|
for( VECTOR2I& corner : corners )
|
|
|
|
{
|
|
|
|
RotatePoint( corner, GetDrawPos(), GetDrawRotation() );
|
|
|
|
aBuffer->Append( corner.x, corner.y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-29 14:28:48 +00:00
|
|
|
void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
|
2023-05-28 16:20:11 +00:00
|
|
|
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.
|
2023-05-28 16:20:11 +00:00
|
|
|
SHAPE_POLY_SET textShape;
|
2022-10-16 17:02:12 +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 )
|
|
|
|
{
|
2023-05-29 14:28:48 +00:00
|
|
|
TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
|
2022-01-10 01:53:01 +00:00
|
|
|
},
|
|
|
|
// Triangulation callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
|
|
|
{
|
2023-05-28 16:20:11 +00:00
|
|
|
textShape.NewOutline();
|
2021-10-25 19:50:33 +00:00
|
|
|
|
2022-01-10 01:53:01 +00:00
|
|
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
2023-05-28 16:20:11 +00:00
|
|
|
textShape.Append( point.x, point.y );
|
2022-01-10 01:53:01 +00:00
|
|
|
} );
|
2022-01-10 14:03:53 +00:00
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs, GetFontMetrics() );
|
2023-05-28 16:20:11 +00:00
|
|
|
textShape.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2023-04-02 07:54:53 +00:00
|
|
|
|
|
|
|
if( IsKnockout() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET finalPoly;
|
2023-05-28 16:20:11 +00:00
|
|
|
int margin = GetKnockoutTextMargin( attrs.m_Size, penWidth );
|
2023-04-02 07:54:53 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
buildBoundingHull( &finalPoly, textShape, margin + aClearance );
|
|
|
|
finalPoly.BooleanSubtract( textShape, SHAPE_POLY_SET::PM_FAST );
|
2023-04-02 07:54:53 +00:00
|
|
|
|
|
|
|
aBuffer.Append( finalPoly );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-29 14:28:48 +00:00
|
|
|
if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
|
2023-05-29 12:20:57 +00:00
|
|
|
{
|
2023-05-29 14:28:48 +00:00
|
|
|
if( aErrorLoc == ERROR_OUTSIDE )
|
|
|
|
aClearance += aMaxError;
|
|
|
|
|
2023-10-05 07:34:24 +00:00
|
|
|
textShape.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError );
|
2023-05-29 12:20:57 +00:00
|
|
|
}
|
2023-05-28 16:20:11 +00:00
|
|
|
|
|
|
|
aBuffer.Append( textShape );
|
2023-04-02 07:54:53 +00:00
|
|
|
}
|
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,
|
2023-05-29 14:28:48 +00:00
|
|
|
int aClearance, int aMaxError, ERROR_LOC aErrorLoc,
|
2022-10-21 12:48:45 +00:00
|
|
|
bool aIgnoreLineWidth ) const
|
2021-10-25 19:50:33 +00:00
|
|
|
{
|
2023-05-28 16:20:11 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2023-05-29 14:28:48 +00:00
|
|
|
TransformTextToPolySet( poly, 0, aMaxError, aErrorLoc );
|
2023-05-28 16:20:11 +00:00
|
|
|
|
|
|
|
buildBoundingHull( &aBuffer, poly, aClearance );
|
2021-10-25 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
bool PCB_TEXT::operator==( const BOARD_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aOther );
|
|
|
|
|
|
|
|
return EDA_TEXT::operator==( other );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double PCB_TEXT::Similarity( const BOARD_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aOther );
|
|
|
|
|
|
|
|
return EDA_TEXT::Similarity( other );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-02-05 06:13:16 +00:00
|
|
|
propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
|
|
|
|
|
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;
|