2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-08-01 10:20:23 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2019-04-07 21:09:50 +00:00
|
|
|
* Copyright (C) 1992-2019 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <trigo.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 <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>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
TEXTE_MODULE::TEXTE_MODULE( MODULE* parent, TEXT_TYPE text_type ) :
|
2012-01-14 19:50:32 +00:00
|
|
|
BOARD_ITEM( parent, PCB_MODULE_TEXT_T ),
|
|
|
|
EDA_TEXT()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-09-11 16:35:19 +00:00
|
|
|
MODULE* module = static_cast<MODULE*>( m_Parent );
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
m_Type = text_type;
|
2018-04-28 15:22:25 +00:00
|
|
|
m_keepUpright = true;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2016-02-11 15:02:37 +00:00
|
|
|
// Set text thickness to a default value
|
2018-10-07 22:22:54 +00:00
|
|
|
SetThickness( Millimeter2iu( DEFAULT_TEXT_WIDTH ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
SetLayer( F_SilkS );
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
// Set position and give a default layer if a valid parent footprint exists
|
2012-05-31 15:18:55 +00:00
|
|
|
if( module && ( module->Type() == PCB_MODULE_T ) )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( module->GetPosition() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
if( IsBackLayer( module->GetLayer() ) )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
SetLayer( B_SilkS );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMirrored( true );
|
2013-04-07 11:55:18 +00:00
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2015-07-31 19:04:30 +00:00
|
|
|
|
|
|
|
SetDrawCoord();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
TEXTE_MODULE::~TEXTE_MODULE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void TEXTE_MODULE::SetTextAngle( double aAngle )
|
|
|
|
{
|
2017-10-23 13:35:03 +00:00
|
|
|
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-05-02 06:44:41 +00:00
|
|
|
bool TEXTE_MODULE::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect = GetTextBox( -1 );
|
|
|
|
wxPoint location = aPoint;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
RotatePoint( &location, GetTextPos(), -GetDrawRotation() );
|
|
|
|
|
|
|
|
return rect.Contains( location );
|
|
|
|
}
|
|
|
|
|
2017-05-10 09:40:49 +00:00
|
|
|
|
2017-05-02 06:44:41 +00:00
|
|
|
bool TEXTE_MODULE::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect = aRect;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContains )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
else
|
|
|
|
return rect.Intersects( GetTextBox( -1 ), GetDrawRotation() );
|
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2019-04-07 21:09:50 +00:00
|
|
|
void TEXTE_MODULE::KeepUpright( double aOldOrientation, double aNewOrientation )
|
|
|
|
{
|
|
|
|
if( !IsKeepUpright() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
double currentAngle = GetTextAngle() + aOldOrientation;
|
|
|
|
double newAngle = GetTextAngle() + aNewOrientation;
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE_POS( currentAngle );
|
|
|
|
NORMALIZE_ANGLE_POS( newAngle );
|
|
|
|
|
|
|
|
bool isFlipped = currentAngle >= 1800.0;
|
|
|
|
bool needsFlipped = newAngle >= 1800.0;
|
|
|
|
|
|
|
|
if( isFlipped != needsFlipped )
|
|
|
|
{
|
|
|
|
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
SetHorizJustify(GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
|
|
|
|
SetTextAngle( GetTextAngle() + 1800.0 );
|
|
|
|
SetDrawCoord();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 12:15:37 +00:00
|
|
|
void TEXTE_MODULE::Rotate( const wxPoint& aRotCentre, double aAngle )
|
|
|
|
{
|
2018-06-22 13:05:11 +00:00
|
|
|
// Used in footprint editing
|
2015-07-31 19:04:30 +00:00
|
|
|
// Note also in module editor, m_Pos0 = m_Pos
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, aRotCentre, aAngle );
|
|
|
|
SetTextPos( pt );
|
|
|
|
|
|
|
|
SetTextAngle( GetTextAngle() + aAngle );
|
2015-02-28 17:39:05 +00:00
|
|
|
SetLocalCoord();
|
2013-09-03 12:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
void TEXTE_MODULE::Flip( const wxPoint& aCentre )
|
2014-09-10 15:18:42 +00:00
|
|
|
{
|
2014-09-27 16:39:18 +00:00
|
|
|
// flipping the footprint is relative to the X axis
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
|
|
|
|
|
|
|
|
SetTextAngle( -GetTextAngle() );
|
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer() ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMirrored( IsBackLayer( GetLayer() ) );
|
2015-07-31 19:04:30 +00:00
|
|
|
SetLocalCoord();
|
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() )
|
2019-04-07 21:09:50 +00:00
|
|
|
SetHorizJustify( (EDA_TEXT_HJUSTIFY_T)-GetHorizJustify() );
|
2019-04-06 23:17:12 +00:00
|
|
|
else
|
2019-04-07 21:09:50 +00:00
|
|
|
SetHorizJustify( (EDA_TEXT_HJUSTIFY_T)-GetHorizJustify() );
|
|
|
|
|
2019-04-06 23:17:12 +00:00
|
|
|
SetDrawCoord();
|
|
|
|
}
|
2014-09-10 15:18:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 18:03:22 +00:00
|
|
|
bool TEXTE_MODULE::IsParentFlipped() const
|
|
|
|
{
|
|
|
|
if( GetParent() && GetParent()->GetLayer() == B_Cu )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
void TEXTE_MODULE::Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis )
|
2014-09-10 15:18:42 +00:00
|
|
|
{
|
2014-09-27 16:39:18 +00:00
|
|
|
// Used in modedit, to transform the footprint
|
2015-07-31 19:04:30 +00:00
|
|
|
// the mirror is around the Y axis or X axis if aMirrorAroundXAxis = true
|
2014-09-27 16:39:18 +00:00
|
|
|
// the position is mirrored, but the text itself is not mirrored
|
2015-07-31 19:04:30 +00:00
|
|
|
if( aMirrorAroundXAxis )
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
|
2015-07-31 19:04:30 +00:00
|
|
|
else
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextX( ::Mirror( GetTextPos().x, aCentre.x ) );
|
2015-08-02 09:19:01 +00:00
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
SetLocalCoord();
|
2014-09-10 15:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
void TEXTE_MODULE::Move( const wxPoint& aMoveVector )
|
2014-09-10 15:18:42 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
Offset( aMoveVector );
|
2015-08-02 09:19:01 +00:00
|
|
|
SetLocalCoord();
|
2014-09-27 16:39:18 +00:00
|
|
|
}
|
2014-09-10 15:18:42 +00:00
|
|
|
|
2016-04-20 15:28:44 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
int TEXTE_MODULE::GetLength() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
return m_Text.Len();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 09:59:24 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
void TEXTE_MODULE::SetDrawCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-09-11 16:35:19 +00:00
|
|
|
const MODULE* module = static_cast<const MODULE*>( m_Parent );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( m_Pos0 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-09-11 16:35:19 +00:00
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
double angle = module->GetOrientation();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, angle );
|
|
|
|
SetTextPos( pt );
|
|
|
|
|
|
|
|
Offset( module->GetPosition() );
|
2014-09-11 16:35:19 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
void TEXTE_MODULE::SetLocalCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-09-11 16:35:19 +00:00
|
|
|
const MODULE* module = static_cast<const MODULE*>( m_Parent );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-09-11 16:35:19 +00:00
|
|
|
if( module )
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Pos0 = GetTextPos() - module->GetPosition();
|
|
|
|
|
2014-09-11 16:35:19 +00:00
|
|
|
double angle = module->GetOrientation();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2014-09-11 16:35:19 +00:00
|
|
|
RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
|
|
|
|
}
|
|
|
|
else
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Pos0 = GetTextPos();
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT TEXTE_MODULE::GetBoundingBox() const
|
2008-03-15 10:24:32 +00:00
|
|
|
{
|
2013-05-05 07:17:48 +00:00
|
|
|
double angle = GetDrawRotation();
|
2013-11-05 17:12:27 +00:00
|
|
|
EDA_RECT text_area = GetTextBox( -1, -1 );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2013-11-05 17:12:27 +00:00
|
|
|
if( angle )
|
2017-01-23 20:30:11 +00:00
|
|
|
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
|
|
|
return text_area;
|
2008-03-15 10:24:32 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void TEXTE_MODULE::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
/* parent must *not* be NULL (a footprint text without a footprint parent has no sense) */
|
2014-11-02 16:25:04 +00:00
|
|
|
wxASSERT( m_Parent );
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
BOARD* brd = GetBoard( );
|
|
|
|
KIGFX::COLOR4D color = aFrame->Settings().Colors().GetLayerColor( GetLayer() );
|
|
|
|
PCB_LAYER_ID text_layer = GetLayer();
|
2015-02-02 08:06:39 +00:00
|
|
|
|
2016-04-20 15:28:44 +00:00
|
|
|
if( !brd->IsLayerVisible( m_Layer )
|
2017-03-13 03:19:33 +00:00
|
|
|
|| ( IsFrontLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_FR ) )
|
|
|
|
|| ( IsBackLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_BK ) ) )
|
2014-09-14 15:34:37 +00:00
|
|
|
return;
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2018-02-11 00:49:25 +00:00
|
|
|
if( !brd->IsElementVisible( LAYER_MOD_REFERENCES ) && GetText() == wxT( "%R" ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( !brd->IsElementVisible( LAYER_MOD_VALUES ) && GetText() == wxT( "%V" ) )
|
|
|
|
return;
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
// Invisible texts are still drawn (not plotted) in LAYER_MOD_TEXT_INVISIBLE
|
2014-09-14 15:34:37 +00:00
|
|
|
// Just because we must have to edit them (at least to make them visible)
|
2017-01-23 20:30:11 +00:00
|
|
|
if( !IsVisible() )
|
2013-03-31 18:57:31 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
if( !brd->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) )
|
2013-03-31 18:57:31 +00:00
|
|
|
return;
|
2016-04-20 15:28:44 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
color = aFrame->Settings().Colors().GetItemColor( LAYER_MOD_TEXT_INVISIBLE );
|
2013-03-31 18:57:31 +00:00
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( aFrame->GetDisplayOptions() );
|
2015-05-27 20:13:51 +00:00
|
|
|
|
|
|
|
// Draw mode compensation for the width
|
2017-01-23 20:30:11 +00:00
|
|
|
int width = GetThickness();
|
2015-02-02 08:06:39 +00:00
|
|
|
|
|
|
|
if( displ_opts && displ_opts->m_DisplayModTextFill == SKETCH )
|
2007-08-04 20:05:54 +00:00
|
|
|
width = -width;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pos = GetTextPos() - aOffset;
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2013-03-31 18:57:31 +00:00
|
|
|
// Draw the text proper, with the right attributes
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = GetTextSize();
|
2013-05-05 07:17:48 +00:00
|
|
|
double orient = GetDrawRotation();
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2013-03-31 18:57:31 +00:00
|
|
|
// If the text is mirrored : negate size.x (mirror / Y axis)
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMirrored() )
|
2007-08-04 20:05:54 +00:00
|
|
|
size.x = -size.x;
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( aDC, pos, color, GetShownText(), orient, size, GetHorizJustify(), GetVertJustify(),
|
|
|
|
width, IsItalic(), IsBold() );
|
2010-11-18 13:38:08 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-04-20 15:28:44 +00:00
|
|
|
|
2013-05-05 07:17:48 +00:00
|
|
|
double TEXTE_MODULE::GetDrawRotation() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
2017-01-23 20:30:11 +00:00
|
|
|
double rotation = GetTextAngle();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( module )
|
2013-03-13 18:53:58 +00:00
|
|
|
rotation += module->GetOrientation();
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
if( m_keepUpright )
|
2017-11-25 19:55:32 +00:00
|
|
|
{
|
|
|
|
// Keep angle between -90 .. 90 deg. Otherwise the text is not easy to read
|
|
|
|
while( rotation > 900 )
|
|
|
|
rotation -= 1800;
|
|
|
|
|
|
|
|
while( rotation < -900 )
|
|
|
|
rotation += 1800;
|
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NORMALIZE_ANGLE_POS( rotation );
|
|
|
|
}
|
2016-03-15 00:51:28 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
return rotation;
|
|
|
|
}
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
// see class_text_mod.h
|
2018-04-10 10:52:12 +00:00
|
|
|
void TEXTE_MODULE::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-23 21:03:26 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
if( module == NULL ) // Happens in modedit, and for new texts
|
2007-08-20 19:33:15 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
wxString msg, Line;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-11-23 21:03:26 +00:00
|
|
|
static const wxString text_type_msg[3] =
|
|
|
|
{
|
2008-08-09 08:05:42 +00:00
|
|
|
_( "Ref." ), _( "Value" ), _( "Text" )
|
|
|
|
};
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
Line = module->GetReference();
|
2014-11-02 12:44:57 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), Line, DARKCYAN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
Line = GetShownText();
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Text" ), Line, BROWN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
wxASSERT( m_Type >= TEXT_is_REFERENCE && m_Type <= TEXT_is_DIVERS );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), text_type_msg[m_Type], DARKGREEN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( !IsVisible() )
|
2008-08-09 08:05:42 +00:00
|
|
|
msg = _( "No" );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2008-08-09 08:05:42 +00:00
|
|
|
msg = _( "Yes" );
|
2013-01-12 17:32:24 +00:00
|
|
|
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Display" ), msg, DARKGREEN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
// Display text layer
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), DARKGREEN ) );
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMirrored() )
|
2018-03-09 03:32:01 +00:00
|
|
|
msg = _( "Yes" );
|
2013-04-07 11:55:18 +00:00
|
|
|
else
|
2018-03-09 03:32:01 +00:00
|
|
|
msg = _( "No" );
|
2013-01-12 17:32:24 +00:00
|
|
|
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
msg.Printf( wxT( "%.1f" ), GetTextAngleDegrees() );
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetThickness(), true );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, DARKGREEN ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetTextWidth(), true );
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetTextHeight(), true );
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString TEXTE_MODULE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
|
|
|
switch( m_Type )
|
|
|
|
{
|
|
|
|
case TEXT_is_REFERENCE:
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Reference %s" ),
|
|
|
|
static_cast<MODULE*>( GetParent() )->GetReference() );
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
case TEXT_is_VALUE:
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Value %s of %s" ),
|
|
|
|
GetShownText(),
|
|
|
|
static_cast<MODULE*>( GetParent() )->GetReference() );
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
default: // wrap this one in quotes:
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Text \"%s\" of %s on %s" ),
|
|
|
|
ShortenedShownText(),
|
|
|
|
static_cast<MODULE*>( GetParent() )->GetReference(),
|
|
|
|
GetLayerName() );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF TEXTE_MODULE::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return footprint_text_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* TEXTE_MODULE::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new TEXTE_MODULE( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-07 13:09:27 +00:00
|
|
|
const BOX2I TEXTE_MODULE::ViewBBox() const
|
|
|
|
{
|
|
|
|
double angle = GetDrawRotation();
|
|
|
|
EDA_RECT text_area = GetTextBox( -1, -1 );
|
|
|
|
|
|
|
|
if( angle )
|
2017-01-23 20:30:11 +00:00
|
|
|
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
|
2014-01-07 13:09:27 +00:00
|
|
|
|
|
|
|
return BOX2I( text_area.GetPosition(), text_area.GetSize() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2018-03-14 22:55:01 +00:00
|
|
|
if( IsVisible() )
|
2018-03-15 10:59:59 +00:00
|
|
|
aLayers[0] = GetLayer();
|
2018-03-14 22:55:01 +00:00
|
|
|
else
|
2018-03-15 10:59:59 +00:00
|
|
|
aLayers[0] = LAYER_MOD_TEXT_INVISIBLE;
|
|
|
|
|
|
|
|
aCount = 1;
|
2015-06-16 15:03:36 +00:00
|
|
|
}
|
2014-01-26 21:02:48 +00:00
|
|
|
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
2015-06-16 15:03:36 +00:00
|
|
|
{
|
2018-02-17 18:03:22 +00:00
|
|
|
const int HIDE = std::numeric_limits<unsigned int>::max();
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
if( !aView )
|
2015-07-24 07:42:46 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-03-15 10:59:59 +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;
|
|
|
|
|
2018-02-17 18:03:22 +00:00
|
|
|
// Handle Render tab switches
|
2018-02-11 00:49:25 +00:00
|
|
|
if( ( m_Type == TEXT_is_VALUE || m_Text == wxT( "%V" ) )
|
|
|
|
&& !aView->IsLayerVisible( LAYER_MOD_VALUES ) )
|
2018-02-17 18:03:22 +00:00
|
|
|
return HIDE;
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2018-02-11 00:49:25 +00:00
|
|
|
if( ( m_Type == TEXT_is_REFERENCE || m_Text == wxT( "%R" ) )
|
|
|
|
&& !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) )
|
2018-02-17 18:03:22 +00:00
|
|
|
return HIDE;
|
|
|
|
|
|
|
|
if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
|
|
|
|
return HIDE;
|
|
|
|
|
|
|
|
if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
|
|
|
|
return HIDE;
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2018-02-17 18:03:22 +00:00
|
|
|
if( IsFrontLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) )
|
|
|
|
return HIDE;
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2018-02-17 18:03:22 +00:00
|
|
|
if( IsBackLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) )
|
|
|
|
return HIDE;
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2018-02-17 18:03:22 +00:00
|
|
|
// Other layers are shown without any conditions
|
2015-06-16 15:03:36 +00:00
|
|
|
return 0;
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
}
|
2014-09-10 15:18:42 +00:00
|
|
|
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2014-10-04 15:15:38 +00:00
|
|
|
wxString TEXTE_MODULE::GetShownText() const
|
|
|
|
{
|
|
|
|
/* First order optimization: no % means that no processing is
|
|
|
|
* needed; just hope that RVO and copy constructor implementation
|
|
|
|
* avoid to copy the whole block; anyway it should be better than
|
|
|
|
* rebuild the string one character at a time...
|
|
|
|
* Also it seems wise to only expand macros in user text (but there
|
|
|
|
* is no technical reason, probably) */
|
|
|
|
|
|
|
|
if( (m_Type != TEXT_is_DIVERS) || (wxString::npos == m_Text.find('%')) )
|
|
|
|
return m_Text;
|
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
wxString newbuf;
|
2014-10-04 15:15:38 +00:00
|
|
|
const MODULE *module = static_cast<MODULE*>( GetParent() );
|
|
|
|
|
2016-04-20 15:28:44 +00:00
|
|
|
for( wxString::const_iterator it = m_Text.begin(); it != m_Text.end(); ++it )
|
2014-10-04 15:15:38 +00:00
|
|
|
{
|
|
|
|
// Process '%' and copy everything else
|
|
|
|
if( *it != '%' )
|
|
|
|
newbuf.append(*it);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Look at the next character (if is it there) and append
|
|
|
|
* its expansion */
|
|
|
|
++it;
|
2016-04-20 15:28:44 +00:00
|
|
|
|
2014-10-04 15:15:38 +00:00
|
|
|
if( it != m_Text.end() )
|
|
|
|
{
|
|
|
|
switch( char(*it) )
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
newbuf.append( '%' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
if( module )
|
|
|
|
newbuf.append( module->GetReference() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
if( module )
|
|
|
|
newbuf.append( module->GetValue() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
newbuf.append( '?' );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break; // The string is over and we can't ++ anymore
|
|
|
|
}
|
|
|
|
}
|
2016-04-20 15:28:44 +00:00
|
|
|
|
2014-10-04 15:15:38 +00:00
|
|
|
return newbuf;
|
|
|
|
}
|