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>
|
2015-02-28 20:50:35 +00:00
|
|
|
* Copyright (C) 1992-2015 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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file class_pcb_text.cpp
|
|
|
|
* @brief Class TEXTE_PCB texts on copper or technical layers implementation
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <base_struct.h>
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <trigo.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
|
|
|
#include <base_units.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/color_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_pcb_text.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
#include "pcb_painter.h"
|
|
|
|
|
|
|
|
using KIGFX::PCB_RENDER_SETTINGS;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
TEXTE_PCB::TEXTE_PCB( 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
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
TEXTE_PCB::~TEXTE_PCB()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString TEXTE_PCB::GetShownText( int aDepth ) const
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
BOARD* board = static_cast<BOARD*>( GetParent() );
|
2020-03-26 11:02:59 +00:00
|
|
|
wxASSERT( board );
|
|
|
|
|
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
|
|
|
|
|
|
|
if( refItem && refItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* refModule = static_cast<MODULE*>( refItem );
|
|
|
|
|
2020-04-11 19:12:49 +00:00
|
|
|
if( refModule->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-04-06 13:06:57 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText( aDepth );
|
|
|
|
|
|
|
|
if( aDepth < 10 )
|
|
|
|
text = ExpandTextVars( text, &pcbTextResolver, board->GetProject() );
|
|
|
|
|
|
|
|
return text;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void TEXTE_PCB::SetTextAngle( double aAngle )
|
|
|
|
{
|
2017-10-23 13:35:03 +00:00
|
|
|
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
void TEXTE_PCB::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-05-01 16:46:56 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2015-02-28 20:50:35 +00:00
|
|
|
wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
|
2008-03-11 05:41:33 +00:00
|
|
|
|
2015-02-28 20:50:35 +00:00
|
|
|
if( m_Parent->Type() == PCB_DIMENSION_T )
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Dimension" ), GetShownText(), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "PCB Text" ), GetShownText(), DARKGREEN );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName(), BLUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( !IsMirrored() )
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Mirror" ), _( "No" ), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Mirror" ), _( "Yes" ), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Angle" ), msg, DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetTextThickness() );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Thickness" ), msg, MAGENTA );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetTextWidth() );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Width" ), msg, RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetTextHeight() );
|
2019-12-05 15:41:21 +00:00
|
|
|
aList.emplace_back( _( "Height" ), msg, RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT TEXTE_PCB::GetBoundingBox() const
|
2013-11-05 17:12:27 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_RECT rect = GetTextBox();
|
2013-11-05 17:12:27 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextAngle() )
|
|
|
|
rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
|
2013-11-05 17:12:27 +00:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, aRotCentre, aAngle );
|
|
|
|
SetTextPos( pt );
|
|
|
|
|
|
|
|
SetTextAngle( GetTextAngle() + aAngle );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
void TEXTE_PCB::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2019-07-12 21:02:10 +00:00
|
|
|
if( aFlipLeftRight )
|
|
|
|
SetTextX( aCentre.x - ( GetTextPos().x - aCentre.x ) );
|
|
|
|
else
|
|
|
|
SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2015-12-27 15:51:13 +00:00
|
|
|
int copperLayerCount = GetBoard()->GetCopperLayerCount();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2015-12-27 15:51:13 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMirrored( !IsMirrored() );
|
2019-04-06 23:17:12 +00:00
|
|
|
|
|
|
|
// adjust justified text for mirroring
|
|
|
|
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT || GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
{
|
|
|
|
if( ( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT ) == IsMirrored() )
|
2020-04-14 12:25:00 +00:00
|
|
|
SetTextX( GetTextPos().x - GetTextBox().GetWidth() );
|
2019-04-06 23:17:12 +00:00
|
|
|
else
|
2020-04-14 12:25:00 +00:00
|
|
|
SetTextX( GetTextPos().x + GetTextBox().GetWidth() );
|
2019-04-06 23:17:12 +00:00
|
|
|
}
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString TEXTE_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Pcb Text \"%s\" on %s"), ShortenedShownText(), GetLayerName() );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF TEXTE_PCB::GetMenuImage() const
|
|
|
|
{
|
2017-06-02 09:51:11 +00:00
|
|
|
return text_xpm;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* TEXTE_PCB::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new TEXTE_PCB( *this );
|
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2017-10-31 13:59:03 +00:00
|
|
|
void TEXTE_PCB::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_TEXT_T );
|
|
|
|
|
|
|
|
std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
|
|
|
|
}
|
2020-03-26 11:02:59 +00:00
|
|
|
|
|
|
|
|