2011-10-12 14:03:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-03-23 12:16:27 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-05-14 17:44:17 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2022-01-02 14:08:09 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-12 14:03:43 +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
|
|
|
|
*/
|
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2021-10-12 20:05:37 +00:00
|
|
|
#include <pgm_base.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_text.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
#include <sch_painter.h>
|
|
|
|
#include <default_values.h>
|
2019-09-06 20:15:14 +00:00
|
|
|
#include <wx/debug.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2021-09-14 18:26:03 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
2020-07-07 10:17:30 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2021-10-01 10:52:34 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2022-07-04 20:39:16 +00:00
|
|
|
#include <tools/sch_navigate_tool.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2011-07-03 18:51:07 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
using KIGFX::SCH_RENDER_SETTINGS;
|
|
|
|
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
TEXT_SPIN_STYLE TEXT_SPIN_STYLE::RotateCW()
|
2021-06-01 23:13:53 +00:00
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::LEFT: newSpin = TEXT_SPIN_STYLE::UP; break;
|
|
|
|
case TEXT_SPIN_STYLE::UP: newSpin = TEXT_SPIN_STYLE::RIGHT; break;
|
|
|
|
case TEXT_SPIN_STYLE::RIGHT: newSpin = TEXT_SPIN_STYLE::BOTTOM; break;
|
|
|
|
case TEXT_SPIN_STYLE::BOTTOM: newSpin = TEXT_SPIN_STYLE::LEFT; break;
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
return TEXT_SPIN_STYLE( newSpin );
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
TEXT_SPIN_STYLE TEXT_SPIN_STYLE::RotateCCW()
|
2021-06-01 23:13:53 +00:00
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::LEFT: newSpin = TEXT_SPIN_STYLE::BOTTOM; break;
|
|
|
|
case TEXT_SPIN_STYLE::BOTTOM: newSpin = TEXT_SPIN_STYLE::RIGHT; break;
|
|
|
|
case TEXT_SPIN_STYLE::RIGHT: newSpin = TEXT_SPIN_STYLE::UP; break;
|
|
|
|
case TEXT_SPIN_STYLE::UP: newSpin = TEXT_SPIN_STYLE::LEFT; break;
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
return TEXT_SPIN_STYLE( newSpin );
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
TEXT_SPIN_STYLE TEXT_SPIN_STYLE::MirrorX()
|
2021-06-01 23:13:53 +00:00
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::UP: newSpin = TEXT_SPIN_STYLE::BOTTOM; break;
|
|
|
|
case TEXT_SPIN_STYLE::BOTTOM: newSpin = TEXT_SPIN_STYLE::UP; break;
|
|
|
|
case TEXT_SPIN_STYLE::LEFT: break;
|
|
|
|
case TEXT_SPIN_STYLE::RIGHT: break;
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
return TEXT_SPIN_STYLE( newSpin );
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
TEXT_SPIN_STYLE TEXT_SPIN_STYLE::MirrorY()
|
2021-06-01 23:13:53 +00:00
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::LEFT: newSpin = TEXT_SPIN_STYLE::RIGHT; break;
|
|
|
|
case TEXT_SPIN_STYLE::RIGHT: newSpin = TEXT_SPIN_STYLE::LEFT; break;
|
|
|
|
case TEXT_SPIN_STYLE::UP: break;
|
|
|
|
case TEXT_SPIN_STYLE::BOTTOM: break;
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
return TEXT_SPIN_STYLE( newSpin );
|
2021-06-01 23:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_TEXT::SCH_TEXT( const VECTOR2I& pos, const wxString& text, KICAD_T aType ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, aType ),
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_TEXT( schIUScale, text )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = LAYER_NOTES;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
SetTextPos( pos );
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( TEXT_SPIN_STYLE::LEFT );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) :
|
2020-04-16 13:22:19 +00:00
|
|
|
SCH_ITEM( aText ),
|
|
|
|
EDA_TEXT( aText ),
|
|
|
|
m_spin_style( aText.m_spin_style )
|
|
|
|
{ }
|
2008-01-21 16:21:41 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_TEXT::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2022-01-07 14:49:17 +00:00
|
|
|
return VECTOR2I( 0, 0 );
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_TEXT::MirrorHorizontally( int aCenter )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2013-03-01 19:59:29 +00:00
|
|
|
// Text is NOT really mirrored; it is moved to a suitable horizontal position
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( GetTextSpinStyle().MirrorY() );
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_TEXT::MirrorVertically( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2013-03-01 19:59:29 +00:00
|
|
|
// Text is NOT really mirrored; it is moved to a suitable vertical position
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( GetTextSpinStyle().MirrorX() );
|
2015-06-26 13:41:56 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_TEXT::Rotate( const VECTOR2I& aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pt = GetTextPos();
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( pt, aCenter, ANGLE_90 );
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I offset = pt - GetTextPos();
|
2021-12-02 15:33:49 +00:00
|
|
|
|
2020-11-24 18:16:03 +00:00
|
|
|
Rotate90( false );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2021-12-04 04:28:14 +00:00
|
|
|
SetTextPos( GetTextPos() + offset );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 21:40:04 +00:00
|
|
|
void SCH_TEXT::Rotate90( bool aClockwise )
|
|
|
|
{
|
|
|
|
if( aClockwise )
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( GetTextSpinStyle().RotateCW() );
|
2020-11-18 21:40:04 +00:00
|
|
|
else
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( GetTextSpinStyle().RotateCCW() );
|
2020-11-18 21:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 23:34:03 +00:00
|
|
|
void SCH_TEXT::MirrorSpinStyle( bool aLeftRight )
|
|
|
|
{
|
|
|
|
if( aLeftRight )
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( GetTextSpinStyle().MirrorY() );
|
2020-11-18 23:34:03 +00:00
|
|
|
else
|
2022-01-24 13:40:39 +00:00
|
|
|
SetTextSpinStyle( GetTextSpinStyle().MirrorX() );
|
2020-11-18 23:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
void SCH_TEXT::SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_spin_style = aSpinStyle;
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// Assume "Right" and Left" mean which side of the anchor the text will be on
|
2021-06-09 19:32:58 +00:00
|
|
|
// Thus we want to left justify text up against the anchor if we are on the right
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( aSpinStyle )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
default:
|
2021-10-12 20:05:37 +00:00
|
|
|
wxFAIL_MSG( "Bad spin style" );
|
2022-01-24 13:40:39 +00:00
|
|
|
m_spin_style = TEXT_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
|
2021-10-12 20:05:37 +00:00
|
|
|
KI_FALLTHROUGH;
|
2020-01-10 23:14:37 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::UP: // Vert Orientation UP
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_TEXT::SwapData( SCH_ITEM* aItem )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_TEXT* item = static_cast<SCH_TEXT*>( aItem );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, item->m_layer );
|
2017-01-23 20:30:11 +00:00
|
|
|
std::swap( m_spin_style, item->m_spin_style );
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
SwapText( *item );
|
2021-12-28 22:13:54 +00:00
|
|
|
SwapAttributes( *item );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2020-01-28 15:42:42 +00:00
|
|
|
bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
|
|
|
auto other = static_cast<const SCH_TEXT*>( &aItem );
|
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
if( GetLayer() != other->GetLayer() )
|
|
|
|
return GetLayer() < other->GetLayer();
|
2020-01-28 15:42:42 +00:00
|
|
|
|
|
|
|
if( GetPosition().x != other->GetPosition().x )
|
|
|
|
return GetPosition().x < other->GetPosition().x;
|
|
|
|
|
|
|
|
if( GetPosition().y != other->GetPosition().y )
|
|
|
|
return GetPosition().y < other->GetPosition().y;
|
|
|
|
|
|
|
|
return GetText() < other->GetText();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
int SCH_TEXT::GetTextOffset( const RENDER_SETTINGS* aSettings ) const
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
double ratio;
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
if( aSettings )
|
2020-12-20 18:18:54 +00:00
|
|
|
ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_TextOffsetRatio;
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( Schematic() )
|
|
|
|
ratio = Schematic()->Settings().m_TextOffsetRatio;
|
|
|
|
else
|
|
|
|
ratio = DEFAULT_TEXT_OFFSET_RATIO; // For previews (such as in Preferences), etc.
|
|
|
|
|
|
|
|
return KiROUND( ratio * GetTextSize().y );
|
2020-04-14 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_TEXT::GetPenWidth() const
|
|
|
|
{
|
|
|
|
return GetEffectiveTextPenWidth();
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 00:47:23 +00:00
|
|
|
KIFONT::FONT* SCH_TEXT::GetDrawFont() const
|
|
|
|
{
|
|
|
|
KIFONT::FONT* font = EDA_TEXT::GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2022-04-29 12:51:49 +00:00
|
|
|
COLOR4D color = GetTextColor();
|
2022-04-27 21:45:22 +00:00
|
|
|
bool blackAndWhiteMode = GetGRForceBlackPenState();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( m_layer );
|
2022-04-27 21:45:22 +00:00
|
|
|
|
2022-04-25 22:22:45 +00:00
|
|
|
// Adjust text drawn in an outline font to more closely mimic the positioning of
|
|
|
|
// SCH_FIELD text.
|
|
|
|
if( GetDrawFont()->IsOutline() )
|
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I firstLineBBox = GetTextBox( 0 );
|
2022-04-25 22:22:45 +00:00
|
|
|
int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
|
|
|
|
int adjust = KiROUND( sizeDiff * 0.4 );
|
|
|
|
VECTOR2I adjust_offset( 0, - adjust );
|
|
|
|
|
|
|
|
RotatePoint( adjust_offset, GetDrawRotation() );
|
|
|
|
text_offset += adjust_offset;
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_TEXT::Print( aSettings, text_offset, color );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_TEXT::GetBoundingBox() const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bbox = GetTextBox();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
if( !GetTextAngle().IsZero() ) // Rotate bbox.
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
VECTOR2I pos = bbox.GetOrigin();
|
|
|
|
VECTOR2I end = bbox.GetEnd();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
RotatePoint( pos, GetTextPos(), GetTextAngle() );
|
|
|
|
RotatePoint( end, GetTextPos(), GetTextAngle() );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox.SetOrigin( pos );
|
|
|
|
bbox.SetEnd( end );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox.Normalize();
|
|
|
|
return bbox;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString SCH_TEXT::GetShownText( int aDepth ) const
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-04-05 19:51:48 +00:00
|
|
|
std::function<bool( wxString* )> textResolver =
|
2020-04-06 13:06:57 +00:00
|
|
|
[&]( wxString* token ) -> bool
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( token->Contains( ':' ) )
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( Schematic()->ResolveCrossReference( token, aDepth ) )
|
|
|
|
return true;
|
2020-04-05 19:51:48 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCHEMATIC* schematic = Schematic();
|
|
|
|
SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
|
2020-04-05 19:51:48 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-05 19:51:48 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2021-07-06 12:27:36 +00:00
|
|
|
std::function<bool( wxString* )> schematicTextResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
return Schematic()->ResolveTextVar( token, aDepth + 1 );
|
|
|
|
};
|
|
|
|
|
2021-06-29 12:54:40 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText();
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2022-09-22 17:04:17 +00:00
|
|
|
if( text == wxS( "~" ) ) // Legacy placeholder for empty string
|
2021-06-12 17:58:15 +00:00
|
|
|
{
|
2022-09-22 17:04:17 +00:00
|
|
|
text = wxS( "" );
|
2021-06-12 17:58:15 +00:00
|
|
|
}
|
2021-06-29 12:54:40 +00:00
|
|
|
else if( HasTextVars() )
|
2020-04-24 20:33:59 +00:00
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
PROJECT* project = nullptr;
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2020-05-21 02:27:48 +00:00
|
|
|
if( Schematic() )
|
|
|
|
project = &Schematic()->Prj();
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
if( aDepth < 10 )
|
2021-07-06 12:27:36 +00:00
|
|
|
text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project );
|
2020-04-24 20:33:59 +00:00
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return text;
|
2020-03-29 01:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
void SCH_TEXT::DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const
|
2022-05-14 13:52:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( IsHypertext(), /* void */,
|
|
|
|
"Calling a hypertext menu on a SCH_TEXT with no hyperlink?" );
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
SCH_NAVIGATE_TOOL* navTool = aFrame->GetToolManager()->GetTool<SCH_NAVIGATE_TOOL>();
|
|
|
|
navTool->HypertextCommand( m_hyperlink );
|
2022-05-14 13:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
wxString SCH_TEXT::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2022-08-22 16:39:19 +00:00
|
|
|
return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2022-08-31 12:56:58 +00:00
|
|
|
BOX2I bBox = GetBoundingBox();
|
2013-04-07 18:49:13 +00:00
|
|
|
bBox.Inflate( aAccuracy );
|
|
|
|
return bBox.Contains( aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_TEXT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I bBox = GetBoundingBox();
|
2013-04-07 18:49:13 +00:00
|
|
|
bBox.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return aRect.Contains( bBox );
|
|
|
|
|
|
|
|
return aRect.Intersects( bBox );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void SCH_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 2;
|
|
|
|
aLayers[0] = m_layer;
|
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
return;
|
|
|
|
|
2020-12-13 22:42:29 +00:00
|
|
|
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
|
|
|
SCH_CONNECTION* connection = Connection();
|
|
|
|
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
2022-04-29 12:51:49 +00:00
|
|
|
COLOR4D color = GetTextColor();
|
2020-12-13 22:42:29 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
2022-01-07 00:47:23 +00:00
|
|
|
KIFONT::FONT* font = GetDrawFont();
|
2022-04-25 22:22:45 +00:00
|
|
|
VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() );
|
2020-12-13 22:42:29 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = settings->GetLayerColor( layer );
|
2022-04-27 21:45:22 +00:00
|
|
|
|
2020-12-13 22:42:29 +00:00
|
|
|
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
2020-04-13 19:55:27 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2022-04-25 22:22:45 +00:00
|
|
|
// Adjust text drawn in an outline font to more closely mimic the positioning of
|
|
|
|
// SCH_FIELD text.
|
|
|
|
if( GetDrawFont()->IsOutline() )
|
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I firstLineBBox = GetTextBox( 0 );
|
2022-04-25 22:22:45 +00:00
|
|
|
int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
|
|
|
|
int adjust = KiROUND( sizeDiff * 0.4 );
|
|
|
|
VECTOR2I adjust_offset( 0, - adjust );
|
|
|
|
|
|
|
|
RotatePoint( adjust_offset, GetDrawRotation() );
|
|
|
|
text_offset += adjust_offset;
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> positions;
|
2021-10-12 20:05:37 +00:00
|
|
|
wxArrayString strings_list;
|
|
|
|
wxStringSplit( GetShownText(), strings_list, '\n' );
|
|
|
|
positions.reserve( strings_list.Count() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
GetLinePositions( positions, (int) strings_list.Count() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-04-25 22:22:45 +00:00
|
|
|
VECTOR2I textpos = positions[ii] + text_offset;
|
2021-10-12 20:05:37 +00:00
|
|
|
wxString& txt = strings_list.Item( ii );
|
|
|
|
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
|
2022-01-07 00:47:23 +00:00
|
|
|
GetVertJustify(), penWidth, IsItalic(), IsBold(), false, font );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2022-05-14 13:52:53 +00:00
|
|
|
|
|
|
|
if( HasHyperlink() )
|
2022-07-03 15:19:55 +00:00
|
|
|
aPlotter->HyperlinkBox( GetBoundingBox(), GetHyperlink() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-03-03 16:38:41 +00:00
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
2022-08-22 16:39:19 +00:00
|
|
|
aList.emplace_back( _( "Graphic Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2022-04-26 17:52:53 +00:00
|
|
|
aList.emplace_back( _( "Font" ), GetDrawFont()->GetName() );
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
|
2021-10-12 20:05:37 +00:00
|
|
|
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Style" ), textStyle[style] );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
switch( GetTextSpinStyle() )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
case TEXT_SPIN_STYLE::LEFT: msg = _( "Align right" ); break;
|
|
|
|
case TEXT_SPIN_STYLE::UP: msg = _( "Align bottom" ); break;
|
|
|
|
case TEXT_SPIN_STYLE::RIGHT: msg = _( "Align left" ); break;
|
|
|
|
case TEXT_SPIN_STYLE::BOTTOM: msg = _( "Align top" ); break;
|
|
|
|
default: msg = wxT( "???" ); break;
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Justification" ), msg );
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
|
2020-11-14 14:29:11 +00:00
|
|
|
<< " layer=\"" << m_layer << '"'
|
2009-05-05 17:32:07 +00:00
|
|
|
<< '>'
|
2019-08-02 00:10:25 +00:00
|
|
|
<< TO_UTF8( GetText() )
|
2009-05-05 17:32:07 +00:00
|
|
|
<< "</" << s.Lower().mb_str() << ">\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
|