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>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <macros.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>
|
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>
|
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
|
|
|
|
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-05-31 12:15:25 +00:00
|
|
|
void TEXTE_PCB::Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-10-30 17:21:07 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2010-01-31 20:01:46 +00:00
|
|
|
|
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-07 06:21:19 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
auto color = aFrame->Settings().Colors().GetLayerColor( m_Layer );
|
|
|
|
EDA_DRAW_MODE_T fillmode = FILLED;
|
2019-11-07 14:23:09 +00:00
|
|
|
auto& displ_opts = aFrame->GetDisplayOptions();
|
2012-01-03 17:14:17 +00:00
|
|
|
|
2019-11-07 14:23:09 +00:00
|
|
|
if( displ_opts.m_DisplayDrawItemsFill == SKETCH )
|
2009-05-12 13:46:43 +00:00
|
|
|
fillmode = SKETCH;
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
EDA_TEXT::Print( DC, offset, color, fillmode );
|
2007-08-07 06:21:19 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
void TEXTE_PCB::GetMsgPanelInfo( EDA_UNITS_T 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
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetThickness() );
|
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
|
|
|
{
|
|
|
|
EDA_RECT rect = GetTextBox( -1, -1 );
|
|
|
|
|
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() )
|
|
|
|
SetTextX( GetTextPos().x - GetTextBox().GetWidth() );
|
|
|
|
else
|
|
|
|
SetTextX( GetTextPos().x + GetTextBox().GetWidth() );
|
|
|
|
}
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString TEXTE_PCB::GetSelectMenuText( EDA_UNITS_T 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
|
|
|
|
|
|
|
void TEXTE_PCB::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_TEXT_T );
|
|
|
|
|
|
|
|
std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
|
|
|
|
}
|