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
|
2015-02-21 08:11:58 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
|
2020-03-29 01:12:29 +00:00
|
|
|
* Copyright (C) 1992-2020 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file sch_text.cpp
|
2016-03-23 12:16:27 +00:00
|
|
|
* @brief Code for handling schematic texts (texts, labels, hlabels and global labels).
|
2011-10-07 14:41:30 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <trigo.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2020-04-06 13:06:57 +00:00
|
|
|
#include <sch_component.h>
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2018-01-28 18:12:26 +00:00
|
|
|
#include <plotter.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2016-03-23 12:16:27 +00:00
|
|
|
#include <gal/stroke_font.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2020-04-24 23:44:09 +00:00
|
|
|
#include <macros.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-03-29 01:12:29 +00:00
|
|
|
#include <kiway.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_text.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <netlist_object.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2018-04-17 16:25:19 +00:00
|
|
|
#include <trace_helpers.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>
|
|
|
|
|
2011-07-03 18:51:07 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
using KIGFX::SCH_RENDER_SETTINGS;
|
|
|
|
|
|
|
|
|
2015-04-22 11:39:00 +00:00
|
|
|
extern void IncrementLabelMember( wxString& name, int aIncrement );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
/* Coding polygons for global symbol graphic shapes.
|
|
|
|
* the first parml is the number of corners
|
|
|
|
* others are the corners coordinates in reduced units
|
|
|
|
* the real coordinate is the reduced coordinate * text half size
|
|
|
|
*/
|
2009-05-12 12:12:34 +00:00
|
|
|
static int TemplateIN_HN[] = { 6, 0, 0, -1, -1, -2, -1, -2, 1, -1, 1, 0, 0 };
|
|
|
|
static int TemplateIN_HI[] = { 6, 0, 0, 1, 1, 2, 1, 2, -1, 1, -1, 0, 0 };
|
|
|
|
static int TemplateIN_UP[] = { 6, 0, 0, 1, -1, 1, -2, -1, -2, -1, -1, 0, 0 };
|
|
|
|
static int TemplateIN_BOTTOM[] = { 6, 0, 0, 1, 1, 1, 2, -1, 2, -1, 1, 0, 0 };
|
|
|
|
|
|
|
|
static int TemplateOUT_HN[] = { 6, -2, 0, -1, 1, 0, 1, 0, -1, -1, -1, -2, 0 };
|
|
|
|
static int TemplateOUT_HI[] = { 6, 2, 0, 1, -1, 0, -1, 0, 1, 1, 1, 2, 0 };
|
|
|
|
static int TemplateOUT_UP[] = { 6, 0, -2, 1, -1, 1, 0, -1, 0, -1, -1, 0, -2 };
|
|
|
|
static int TemplateOUT_BOTTOM[] = { 6, 0, 2, 1, 1, 1, 0, -1, 0, -1, 1, 0, 2 };
|
|
|
|
|
|
|
|
static int TemplateUNSPC_HN[] = { 5, 0, -1, -2, -1, -2, 1, 0, 1, 0, -1 };
|
|
|
|
static int TemplateUNSPC_HI[] = { 5, 0, -1, 2, -1, 2, 1, 0, 1, 0, -1 };
|
|
|
|
static int TemplateUNSPC_UP[] = { 5, 1, 0, 1, -2, -1, -2, -1, 0, 1, 0 };
|
|
|
|
static int TemplateUNSPC_BOTTOM[] = { 5, 1, 0, 1, 2, -1, 2, -1, 0, 1, 0 };
|
|
|
|
|
|
|
|
static int TemplateBIDI_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
|
|
|
|
static int TemplateBIDI_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
|
|
|
|
static int TemplateBIDI_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
|
|
|
|
static int TemplateBIDI_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
|
|
|
|
|
|
|
|
static int Template3STATE_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
|
|
|
|
static int Template3STATE_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
|
|
|
|
static int Template3STATE_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
|
|
|
|
static int Template3STATE_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
|
|
|
|
|
|
|
|
static int* TemplateShape[5][4] =
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
{ TemplateIN_HN, TemplateIN_UP, TemplateIN_HI, TemplateIN_BOTTOM },
|
|
|
|
{ TemplateOUT_HN, TemplateOUT_UP, TemplateOUT_HI, TemplateOUT_BOTTOM },
|
|
|
|
{ TemplateBIDI_HN, TemplateBIDI_UP, TemplateBIDI_HI, TemplateBIDI_BOTTOM },
|
|
|
|
{ Template3STATE_HN, Template3STATE_UP, Template3STATE_HI, Template3STATE_BOTTOM },
|
|
|
|
{ TemplateUNSPC_HN, TemplateUNSPC_UP, TemplateUNSPC_HI, TemplateUNSPC_BOTTOM }
|
2009-04-05 20:49:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
|
2020-04-14 12:25:00 +00:00
|
|
|
SCH_ITEM( NULL, aType ),
|
2020-04-18 20:04:41 +00:00
|
|
|
EDA_TEXT( text ),
|
2020-04-16 13:22:19 +00:00
|
|
|
m_shape( PINSHEETLABEL_SHAPE::PS_INPUT ),
|
|
|
|
m_isDangling( false ),
|
|
|
|
m_connectionType( CONNECTION_TYPE::NONE ),
|
|
|
|
m_spin_style( LABEL_SPIN_STYLE::LEFT )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-04-16 13:22:19 +00:00
|
|
|
m_Layer = LAYER_NOTES;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
SetTextPos( pos );
|
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_shape( aText.m_shape ),
|
|
|
|
m_isDangling( aText.m_isDangling ),
|
|
|
|
m_connectionType( aText.m_connectionType ),
|
|
|
|
m_spin_style( aText.m_spin_style )
|
|
|
|
{ }
|
2008-01-21 16:21:41 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_TEXT::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_TEXT( *this );
|
|
|
|
}
|
2007-09-01 12:00:30 +00:00
|
|
|
|
|
|
|
|
2015-04-22 11:39:00 +00:00
|
|
|
void SCH_TEXT::IncrementLabel( int aIncrement )
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
wxString text = GetText();
|
|
|
|
IncrementLabelMember( text, aIncrement );
|
|
|
|
SetText(text );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
wxPoint SCH_TEXT::GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
|
|
|
wxPoint text_offset;
|
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
// add an offset to x (or y) position to aid readability of text on a wire or line
|
2020-04-14 12:25:00 +00:00
|
|
|
int dist = GetTextOffset( aSettings ) + GetPenWidth();
|
2016-04-16 07:49:17 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP:
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2020-04-14 12:25:00 +00:00
|
|
|
text_offset.x = -dist;
|
2020-01-08 19:07:55 +00:00
|
|
|
break; // Vert Orientation
|
2009-05-12 12:12:34 +00:00
|
|
|
default:
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2020-04-14 12:25:00 +00:00
|
|
|
text_offset.y = -dist;
|
2020-01-08 19:07:55 +00:00
|
|
|
break; // Horiz Orientation
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_TEXT::MirrorY( int aYaxis_position )
|
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
|
2020-01-08 19:07:55 +00:00
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().MirrorY() );
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextX( Mirror( GetTextPos().x, aYaxis_position ) );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_TEXT::MirrorX( int aXaxis_position )
|
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
|
2020-01-08 19:07:55 +00:00
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().MirrorX() );
|
2015-06-26 13:41:56 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( Mirror( GetTextPos().y, aXaxis_position ) );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_TEXT::Rotate( wxPoint aPosition )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, aPosition, 900 );
|
|
|
|
SetTextPos( pt );
|
2011-03-03 01:58:12 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
if( this->Type() == SCH_TEXT_T )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-04-16 13:22:19 +00:00
|
|
|
int dy = 0;
|
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
|
|
|
dy = GetTextHeight();
|
|
|
|
break;
|
|
|
|
case LABEL_SPIN_STYLE::UP:
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
|
|
|
default:
|
|
|
|
dy = 0;
|
|
|
|
break;
|
2018-09-16 10:42:28 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
SetTextY( GetTextPos().y + dy );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
void SCH_TEXT::SetLabelSpinStyle( LABEL_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
|
|
|
|
// Thus we want to left justify text up agaisnt 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:
|
2019-09-06 20:15:14 +00:00
|
|
|
wxASSERT_MSG( 1, "Bad spin style" );
|
2020-01-10 23:14:37 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
|
2019-09-06 20:15:14 +00:00
|
|
|
//
|
2020-01-08 19:07:55 +00:00
|
|
|
m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-10-19 20:32:21 +00:00
|
|
|
SCH_TEXT* item = (SCH_TEXT*) aItem;
|
|
|
|
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_Layer, item->m_Layer );
|
2017-01-27 21:06:18 +00:00
|
|
|
|
|
|
|
std::swap( m_shape, item->m_shape );
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_isDangling, item->m_isDangling );
|
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 );
|
2017-01-23 20:30:11 +00:00
|
|
|
SwapEffects( *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-04-14 12:25:00 +00:00
|
|
|
int SCH_TEXT::GetTextOffset( RENDER_SETTINGS* aSettings ) const
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
SCH_RENDER_SETTINGS* renderSettings = static_cast<SCH_RENDER_SETTINGS*>( aSettings );
|
|
|
|
|
|
|
|
if( renderSettings )
|
|
|
|
return KiROUND( renderSettings->m_TextOffsetRatio * GetTextSize().y );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_TEXT::GetPenWidth() const
|
|
|
|
{
|
|
|
|
return GetEffectiveTextPenWidth();
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void SCH_TEXT::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
COLOR4D color = aSettings->GetLayerColor( m_Layer );
|
|
|
|
wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_TEXT::Print( aSettings, text_offset, color );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_TEXT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
// Normal text labels cannot be tested for dangling ends.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( Type() == SCH_TEXT_T )
|
2010-11-03 14:13:15 +00:00
|
|
|
return;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
DANGLING_END_ITEM item( LABEL_END, this, GetTextPos() );
|
2010-11-03 14:13:15 +00:00
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
|
|
|
|
const SCH_SHEET_PATH* aPath )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
// Normal text labels cannot be tested for dangling ends.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( Type() == SCH_TEXT_T )
|
2010-11-03 14:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
bool previousState = m_isDangling;
|
2020-01-18 20:51:28 +00:00
|
|
|
m_isDangling = true;
|
|
|
|
m_connectionType = CONNECTION_TYPE::NONE;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aItemList.size(); ii++ )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
DANGLING_END_ITEM& item = aItemList[ii];
|
|
|
|
|
2011-12-06 21:02:21 +00:00
|
|
|
if( item.GetItem() == this )
|
2010-11-03 14:13:15 +00:00
|
|
|
continue;
|
|
|
|
|
2011-12-06 21:02:21 +00:00
|
|
|
switch( item.GetType() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case PIN_END:
|
|
|
|
case LABEL_END:
|
|
|
|
case SHEET_LABEL_END:
|
2018-10-24 22:49:51 +00:00
|
|
|
case NO_CONNECT_END:
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextPos() == item.GetPosition() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = false;
|
2011-12-06 21:02:21 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
if( aPath && item.GetType() != PIN_END )
|
|
|
|
m_connected_items[ *aPath ].insert( static_cast<SCH_ITEM*>( item.GetItem() ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case BUS_START_END:
|
2020-01-18 20:51:28 +00:00
|
|
|
m_connectionType = CONNECTION_TYPE::BUS;
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
case WIRE_START_END:
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
// These schematic items have created 2 DANGLING_END_ITEM one per end. But being
|
|
|
|
// a paranoid programmer, I'll check just in case.
|
|
|
|
ii++;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
wxCHECK_MSG( ii < aItemList.size(), previousState != m_isDangling,
|
2010-11-03 14:13:15 +00:00
|
|
|
wxT( "Dangling end type list overflow. Bad programmer!" ) );
|
|
|
|
|
2020-04-19 16:04:14 +00:00
|
|
|
int accuracy = 1; // We have rounding issues with an accuracy of 0
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
DANGLING_END_ITEM & nextItem = aItemList[ii];
|
2020-04-19 16:04:14 +00:00
|
|
|
m_isDangling = !TestSegmentHit( GetTextPos(), item.GetPosition(),
|
|
|
|
nextItem.GetPosition(), accuracy );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( !m_isDangling )
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
if( m_connectionType != CONNECTION_TYPE::BUS )
|
|
|
|
m_connectionType = CONNECTION_TYPE::NET;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
// Add the line to the connected items, since it won't be picked
|
|
|
|
// up by a search of intersecting connection points
|
2020-01-17 02:33:16 +00:00
|
|
|
if( aPath )
|
|
|
|
{
|
|
|
|
auto sch_item = static_cast<SCH_ITEM*>( item.GetItem() );
|
|
|
|
AddConnectionTo( *aPath, sch_item );
|
|
|
|
sch_item->AddConnectionTo( *aPath, this );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-30 19:55:26 +00:00
|
|
|
if( !m_isDangling )
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( m_isDangling )
|
2020-01-18 20:51:28 +00:00
|
|
|
m_connectionType = CONNECTION_TYPE::NONE;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
return previousState != m_isDangling;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-13 16:27:30 +00:00
|
|
|
void SCH_TEXT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
// Normal text labels do not have connection points. All others do.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( Type() == SCH_TEXT_T )
|
2010-11-03 14:13:15 +00:00
|
|
|
return;
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
aPoints.push_back( GetTextPos() );
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_TEXT::GetBoundingBox() const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_RECT rect = GetTextBox();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
if( GetTextAngle() != 0 ) // Rotate rect
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint pos = rect.GetOrigin();
|
|
|
|
wxPoint end = rect.GetEnd();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
RotatePoint( &pos, GetTextPos(), GetTextAngle() );
|
|
|
|
RotatePoint( &end, GetTextPos(), GetTextAngle() );
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
rect.SetOrigin( pos );
|
|
|
|
rect.SetEnd( end );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
rect.Normalize();
|
|
|
|
return rect;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-29 01:12:29 +00:00
|
|
|
wxString getElectricalTypeLabel( PINSHEETLABEL_SHAPE aType )
|
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_INPUT: return _( "Input" );
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_OUTPUT: return _( "Output" );
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_BIDI: return _( "Bidirectional" );
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_TRISTATE: return _( "Tri-State" );
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: return _( "Passive" );
|
|
|
|
default: return wxT( "???" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if( ( Type() == SCH_GLOBAL_LABEL_T
|
|
|
|
|| Type() == SCH_HIER_LABEL_T
|
|
|
|
|| Type() == SCH_SHEET_PIN_T )
|
|
|
|
&& token->IsSameAs( wxT( "CONNECTION_TYPE" ) ) )
|
|
|
|
{
|
|
|
|
*token = getElectricalTypeLabel( GetShape() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Type() == SCH_SHEET_PIN_T && m_Parent )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_Parent );
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
if( sheet->ResolveTextVar( token, aDepth ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Type() == SCH_TEXT_T )
|
|
|
|
{
|
|
|
|
if( token->Contains( ':' ) )
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
SCH_SHEET_LIST sheetList( g_RootSheet );
|
2020-04-11 19:12:49 +00:00
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token->BeforeFirst( ':', &remainder );
|
2020-04-06 13:06:57 +00:00
|
|
|
SCH_SHEET_PATH dummy;
|
2020-04-11 19:12:49 +00:00
|
|
|
SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &dummy );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
if( refItem && refItem->Type() == SCH_COMPONENT_T )
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
SCH_COMPONENT* refComponent = static_cast<SCH_COMPONENT*>( refItem );
|
2020-04-05 19:51:48 +00:00
|
|
|
|
2020-04-11 19:12:49 +00:00
|
|
|
if( refComponent->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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( refItem && refItem->Type() == SCH_SHEET_T )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
SCH_SHEET* refSheet = static_cast<SCH_SHEET*>( refItem );
|
|
|
|
|
2020-04-11 19:12:49 +00:00
|
|
|
if( refSheet->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-03-29 01:12:29 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
bool processTextVars = false;
|
|
|
|
wxString text = EDA_TEXT::GetShownText( &processTextVars );
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
if( processTextVars )
|
|
|
|
{
|
|
|
|
PROJECT* project = nullptr;
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
if( g_RootSheet && g_RootSheet->GetScreen() )
|
|
|
|
project = &g_RootSheet->GetScreen()->Kiway().Prj();
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
if( aDepth < 10 )
|
|
|
|
text = ExpandTextVars( text, &textResolver, project );
|
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return text;
|
2020-03-29 01:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Graphic Text \"%s\"" ), GetChars( ShortenedShownText() ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF SCH_TEXT::GetMenuImage() const
|
|
|
|
{
|
2017-06-02 09:51:11 +00:00
|
|
|
return text_xpm;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:09:57 +00:00
|
|
|
void SCH_TEXT::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
2011-10-12 14:03:43 +00:00
|
|
|
{
|
|
|
|
if( GetLayer() == LAYER_NOTES || GetLayer() == LAYER_SHEETLABEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT();
|
2020-03-29 01:12:29 +00:00
|
|
|
item->m_SheetPath = *aSheetPath;
|
2013-09-29 18:24:38 +00:00
|
|
|
item->m_SheetPathInclude = *aSheetPath;
|
2020-01-18 20:51:28 +00:00
|
|
|
item->m_Comp = (SCH_ITEM*) this;
|
|
|
|
item->m_Type = NETLIST_ITEM::LABEL;
|
2011-10-12 14:03:43 +00:00
|
|
|
|
|
|
|
if( GetLayer() == LAYER_GLOBLABEL )
|
2020-01-18 20:51:28 +00:00
|
|
|
item->m_Type = NETLIST_ITEM::GLOBLABEL;
|
2011-10-12 14:03:43 +00:00
|
|
|
else if( GetLayer() == LAYER_HIERLABEL )
|
2020-01-18 20:51:28 +00:00
|
|
|
item->m_Type = NETLIST_ITEM::HIERLABEL;
|
2011-10-12 14:03:43 +00:00
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
item->m_Label = GetText();
|
2017-01-23 20:30:11 +00:00
|
|
|
item->m_Start = item->m_End = GetTextPos();
|
2011-10-12 14:03:43 +00:00
|
|
|
|
|
|
|
aNetListItems.push_back( item );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
// If a bus connects to label
|
2020-04-16 13:22:19 +00:00
|
|
|
if( SCH_CONNECTION::IsBusLabel( GetText() ) )
|
2011-10-12 15:34:52 +00:00
|
|
|
item->ConvertBusToNetListItems( aNetListItems );
|
2011-10-12 14:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_TEXT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2013-04-07 18:49:13 +00:00
|
|
|
EDA_RECT bBox = GetBoundingBox();
|
|
|
|
bBox.Inflate( aAccuracy );
|
|
|
|
return bBox.Contains( aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2013-04-07 18:49:13 +00:00
|
|
|
EDA_RECT bBox = GetBoundingBox();
|
|
|
|
bBox.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return aRect.Contains( bBox );
|
|
|
|
|
|
|
|
return aRect.Intersects( bBox );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_TEXT::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
static std::vector<wxPoint> Poly;
|
2020-04-14 12:25:00 +00:00
|
|
|
COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( GetLayer() );
|
2020-04-30 06:59:43 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth( aPlotter->RenderSettings()->GetDefaultPenWidth() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-04-13 19:55:27 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMultilineAllowed() )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2013-11-29 08:13:43 +00:00
|
|
|
std::vector<wxPoint> positions;
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings_list;
|
|
|
|
wxStringSplit( GetShownText(), strings_list, '\n' );
|
|
|
|
positions.reserve( strings_list.Count() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
GetLinePositions( positions, (int) strings_list.Count() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxPoint textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString& txt = strings_list.Item( ii );
|
2019-05-31 12:15:25 +00:00
|
|
|
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
|
2020-04-18 20:04:41 +00:00
|
|
|
GetVertJustify(), penWidth, IsItalic(), IsBold() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxPoint textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
|
2020-04-18 20:04:41 +00:00
|
|
|
GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
// Draw graphic symbol for global or hierarchical labels
|
2020-04-17 11:34:32 +00:00
|
|
|
CreateGraphicShape( aPlotter->RenderSettings(), Poly, GetTextPos() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
if( Poly.size() )
|
2020-04-29 14:48:21 +00:00
|
|
|
aPlotter->PlotPoly( Poly, NO_FILL, penWidth );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( Type() )
|
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
case SCH_TEXT_T: msg = _( "Graphic Text" ); break;
|
|
|
|
case SCH_LABEL_T: msg = _( "Label" ); break;
|
|
|
|
case SCH_GLOBAL_LABEL_T: msg = _( "Global Label" ); break;
|
|
|
|
case SCH_HIER_LABEL_T: msg = _( "Hierarchical Label" ); break;
|
|
|
|
case SCH_SHEET_PIN_T: msg = _( "Hierarchical Sheet Pin" ); break;
|
2018-09-16 10:42:28 +00:00
|
|
|
default: return;
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( msg, GetShownText(), DARKCYAN ) );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
2020-01-11 00:04:01 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: msg = _( "Horizontal left" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: msg = _( "Vertical up" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: msg = _( "Horizontal right" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: msg = _( "Vertical down" ); break;
|
|
|
|
default: msg = wxT( "???" ); break;
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, BROWN ) );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
|
2012-11-20 11:35:09 +00:00
|
|
|
int style = 0;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsItalic() )
|
2012-11-20 11:35:09 +00:00
|
|
|
style = 1;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsBold() )
|
2012-11-20 11:35:09 +00:00
|
|
|
style += 2;
|
|
|
|
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Style" ), textStyle[style], BROWN ) );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
// Display electrical type if it is relevant
|
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T || Type() == SCH_HIER_LABEL_T || Type() == SCH_SHEET_PIN_T )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
2020-03-29 01:12:29 +00:00
|
|
|
msg = getElectricalTypeLabel( GetShape() );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, BLUE ) );
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display text size (X or Y value, with are the same value in Eeschema)
|
2020-04-24 13:36:10 +00:00
|
|
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextWidth(), true );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Size" ), msg, RED ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
if( auto conn = Connection( *g_CurrentSheet ) )
|
|
|
|
conn->AppendDebugInfoToMsgPanel( aList );
|
|
|
|
|
|
|
|
msg.Printf( "%p", this );
|
2019-04-13 08:12:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( "Object Address", msg, RED ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
#endif
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +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()
|
2009-05-05 17:32:07 +00:00
|
|
|
<< " layer=\"" << m_Layer << '"'
|
2020-01-08 19:07:55 +00:00
|
|
|
<< " shape=\"" << static_cast<int>( m_shape ) << '"'
|
2011-12-08 15:45:01 +00:00
|
|
|
<< " dangling=\"" << m_isDangling << '"'
|
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
|
|
|
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text )
|
|
|
|
: SCH_TEXT( pos, text, SCH_LABEL_T )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
m_Layer = LAYER_LOCLABEL;
|
2020-01-09 07:52:30 +00:00
|
|
|
m_shape = PINSHEETLABEL_SHAPE::PS_INPUT;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = true;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( false );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_LABEL::Clone() const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
return new SCH_LABEL( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
bool SCH_LABEL::IsType( const KICAD_T aScanTypes[] ) const
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
|
|
|
static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
|
|
|
|
static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, EOT };
|
|
|
|
|
|
|
|
if( SCH_ITEM::IsType( aScanTypes ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
|
|
|
|
{
|
|
|
|
if( *p == SCH_LABEL_LOCATE_WIRE_T )
|
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
wxASSERT( m_connected_items.count( *g_CurrentSheet ) );
|
|
|
|
|
|
|
|
for( SCH_ITEM* connection : m_connected_items.at( *g_CurrentSheet ) )
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
|
|
|
if( connection->IsType( wireTypes ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( *p == SCH_LABEL_LOCATE_BUS_T )
|
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
wxASSERT( m_connected_items.count( *g_CurrentSheet ) );
|
|
|
|
|
|
|
|
for( SCH_ITEM* connection : m_connected_items.at( *g_CurrentSheet ) )
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
|
|
|
if( connection->IsType( busTypes ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_LABEL::GetBoundingBox() const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_RECT rect = GetTextBox();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
// In practice this is controlled by the current TextOffsetRatio, but the default is
|
|
|
|
// close enough for hit-testing, etc.
|
|
|
|
int margin = Mils2iu( TXT_MARGIN );
|
|
|
|
|
|
|
|
rect.Inflate( margin );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextAngle() != 0.0 )
|
|
|
|
{
|
|
|
|
// Rotate rect
|
2016-03-23 07:41:47 +00:00
|
|
|
wxPoint pos = rect.GetOrigin();
|
|
|
|
wxPoint end = rect.GetEnd();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
RotatePoint( &pos, GetTextPos(), GetTextAngle() );
|
|
|
|
RotatePoint( &end, GetTextPos(), GetTextAngle() );
|
|
|
|
|
2016-03-23 07:41:47 +00:00
|
|
|
rect.SetOrigin( pos );
|
|
|
|
rect.SetEnd( end );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2016-03-23 07:41:47 +00:00
|
|
|
rect.Normalize();
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 07:41:47 +00:00
|
|
|
return rect;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Label %s" ), ShortenedShownText() );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF SCH_LABEL::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_line_label_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text )
|
|
|
|
: SCH_TEXT( pos, text, SCH_GLOBAL_LABEL_T )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
m_Layer = LAYER_GLOBLABEL;
|
2020-01-09 07:52:30 +00:00
|
|
|
m_shape = PINSHEETLABEL_SHAPE::PS_BIDI;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = true;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( false );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_GLOBALLABEL::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_GLOBALLABEL( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
wxPoint SCH_GLOBALLABEL::GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset;
|
2020-04-17 11:34:32 +00:00
|
|
|
int dist = GetTextOffset( aSettings );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_shape )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2020-01-09 07:52:30 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_INPUT:
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_BIDI:
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_TRISTATE:
|
2020-04-17 11:34:32 +00:00
|
|
|
dist += GetTextHeight() * 3 / 4; // Use three-quarters-height as proxy for triangle size
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-09 07:52:30 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_OUTPUT:
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED:
|
2010-11-03 14:13:15 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
default:
|
2020-04-14 12:25:00 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: text_offset.x -= dist; break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: text_offset.y -= dist; break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: text_offset.x += dist; break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: text_offset.y += dist; break;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text_offset;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
void SCH_GLOBALLABEL::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_spin_style = aSpinStyle;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( aSpinStyle )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
default:
|
2019-09-06 20:15:14 +00:00
|
|
|
wxASSERT_MSG( 1, "Bad spin style" );
|
2020-01-10 23:14:37 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
|
2019-09-06 20:15:14 +00:00
|
|
|
//
|
2020-01-08 19:07:55 +00:00
|
|
|
m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
2020-01-08 19:07:55 +00:00
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
2020-01-08 19:07:55 +00:00
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-31 18:08:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void SCH_GLOBALLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2020-04-04 20:32:14 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
COLOR4D color = aSettings->GetLayerColor( m_Layer );
|
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
|
|
|
wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_TEXT::Print( aSettings, text_offset, color );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
CreateGraphicShape( aSettings, Poly, GetTextPos() + aOffset );
|
2020-04-14 12:25:00 +00:00
|
|
|
GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2008-02-20 19:37:17 +00:00
|
|
|
|
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
void SCH_GLOBALLABEL::CreateGraphicShape( RENDER_SETTINGS* aRenderSettings,
|
|
|
|
std::vector<wxPoint>& aPoints, const wxPoint& Pos )
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2020-04-17 11:34:32 +00:00
|
|
|
int margin = GetTextOffset( aRenderSettings );
|
|
|
|
int halfSize = ( GetTextHeight() / 2 ) + margin;
|
2020-04-14 12:25:00 +00:00
|
|
|
int linewidth = GetPenWidth();
|
2020-04-18 20:04:41 +00:00
|
|
|
int symb_len = LenSize( GetShownText(), linewidth ) + 2 * margin;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
int x = symb_len + linewidth + 3;
|
2020-05-05 15:52:12 +00:00
|
|
|
int y = halfSize + linewidth + 3;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
aPoints.clear();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
// Create outline shape : 6 points
|
2019-07-10 10:59:09 +00:00
|
|
|
aPoints.emplace_back( wxPoint( 0, 0 ) );
|
|
|
|
aPoints.emplace_back( wxPoint( 0, -y ) ); // Up
|
|
|
|
aPoints.emplace_back( wxPoint( -x, -y ) ); // left
|
|
|
|
aPoints.emplace_back( wxPoint( -x, 0 ) ); // Up left
|
|
|
|
aPoints.emplace_back( wxPoint( -x, y ) ); // left down
|
|
|
|
aPoints.emplace_back( wxPoint( 0, y ) ); // down
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
int x_offset = 0;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_shape )
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2020-01-09 07:52:30 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_INPUT:
|
2016-03-23 07:41:47 +00:00
|
|
|
x_offset = -halfSize;
|
|
|
|
aPoints[0].x += halfSize;
|
2010-09-11 16:33:43 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-09 07:52:30 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_OUTPUT:
|
2016-03-23 07:41:47 +00:00
|
|
|
aPoints[3].x -= halfSize;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-09 07:52:30 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_BIDI:
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_TRISTATE:
|
2016-03-23 07:41:47 +00:00
|
|
|
x_offset = -halfSize;
|
|
|
|
aPoints[0].x += halfSize;
|
|
|
|
aPoints[3].x -= halfSize;
|
2010-09-11 16:33:43 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-09 07:52:30 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED:
|
2010-09-11 16:33:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
int angle = 0;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
default:
|
2020-04-14 12:25:00 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: angle = -900; break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: angle = 1800; break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: angle = 900; break;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rotate outlines and move corners in real position
|
2018-09-16 10:42:28 +00:00
|
|
|
for( wxPoint& aPoint : aPoints )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
aPoint.x += x_offset;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
if( angle )
|
2018-09-16 10:42:28 +00:00
|
|
|
RotatePoint( &aPoint, angle );
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
aPoint += Pos;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints.push_back( aPoints[0] ); // closing
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2020-04-17 11:34:32 +00:00
|
|
|
int x = GetTextPos().x;
|
|
|
|
int y = GetTextPos().y;
|
|
|
|
int penWidth = GetEffectiveTextPenWidth();
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
// In practice this is controlled by the current TextOffsetRatio, but the default is
|
|
|
|
// close enough for hit-testing, etc.
|
|
|
|
int margin = Mils2iu( TXT_MARGIN );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
int height = ( (GetTextHeight() * 15) / 10 ) + penWidth + 2 * margin;
|
2020-04-18 20:04:41 +00:00
|
|
|
int length = LenSize( GetShownText(), penWidth )
|
2020-04-17 11:34:32 +00:00
|
|
|
+ height // add height for triangular shapes
|
|
|
|
+ 2 * margin;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
int dx, dy;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() ) // respect orientation
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
default:
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = -length;
|
|
|
|
dy = height;
|
2020-04-17 11:34:32 +00:00
|
|
|
x += margin;
|
2009-05-05 17:32:07 +00:00
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = height;
|
2009-05-12 12:12:34 +00:00
|
|
|
dy = -length;
|
2009-05-05 17:32:07 +00:00
|
|
|
x -= height / 2;
|
2020-04-17 11:34:32 +00:00
|
|
|
y += margin;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = length;
|
|
|
|
dy = height;
|
2020-04-17 11:34:32 +00:00
|
|
|
x -= margin;
|
2009-05-05 17:32:07 +00:00
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2010-11-03 14:13:15 +00:00
|
|
|
dx = height;
|
|
|
|
dy = length;
|
|
|
|
x -= height / 2;
|
2020-04-17 11:34:32 +00:00
|
|
|
y -= margin;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
|
2010-11-03 14:13:15 +00:00
|
|
|
box.Normalize();
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_GLOBALLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
return wxString::Format( _( "Global Label %s" ), ShortenedShownText() );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF SCH_GLOBALLABEL::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_glabel_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType )
|
|
|
|
: SCH_TEXT( pos, text, aType )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
m_Layer = LAYER_HIERLABEL;
|
2020-01-09 07:52:30 +00:00
|
|
|
m_shape = PINSHEETLABEL_SHAPE::PS_INPUT;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = true;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( false );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_HIERLABEL::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_HIERLABEL( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
void SCH_HIERLABEL::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_spin_style = aSpinStyle;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// Assume "Right" and Left" mean which side of the port symbol the text will be on
|
|
|
|
// If we are left of the symbol, we want to right justify to line up with the symbol
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( aSpinStyle )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
default:
|
2020-01-08 19:07:55 +00:00
|
|
|
wxLogWarning( "SetLabelSpinStyle bad spin style" );
|
2020-01-10 23:14:37 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
2019-09-06 20:15:14 +00:00
|
|
|
//
|
2020-01-08 19:07:55 +00:00
|
|
|
m_spin_style = LABEL_SPIN_STYLE::LEFT; // Handle the error spin style by resetting
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP:
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
2008-03-30 09:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void SCH_HIERLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& offset )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
SCH_CONNECTION* conn = Connection( *g_CurrentSheet );
|
|
|
|
bool isBus = conn && conn->IsBus();
|
|
|
|
COLOR4D color = aSettings->GetLayerColor( isBus ? LAYER_BUS : m_Layer );
|
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
|
|
|
wxPoint textOffset = offset + GetSchematicTextOffset( aSettings );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
EDA_TEXT::Print( aSettings, textOffset, color );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
CreateGraphicShape( aSettings, Poly, GetTextPos() + offset );
|
2020-04-14 12:25:00 +00:00
|
|
|
GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
|
2008-02-20 19:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
void SCH_HIERLABEL::CreateGraphicShape( RENDER_SETTINGS* aRenderSettings,
|
|
|
|
std::vector<wxPoint>& aPoints, const wxPoint& Pos )
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
int* Template = TemplateShape[static_cast<int>( m_shape )][static_cast<int>( m_spin_style )];
|
2020-04-29 14:48:21 +00:00
|
|
|
int halfSize = GetTextHeight() / 2;
|
|
|
|
int imax = *Template;
|
|
|
|
Template++;
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints.clear();
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
for( int ii = 0; ii < imax; ii++ )
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint corner;
|
2016-03-23 07:41:47 +00:00
|
|
|
corner.x = ( halfSize * (*Template) ) + Pos.x;
|
2010-11-03 14:13:15 +00:00
|
|
|
Template++;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2016-03-23 07:41:47 +00:00
|
|
|
corner.y = ( halfSize * (*Template) ) + Pos.y;
|
2010-11-03 14:13:15 +00:00
|
|
|
Template++;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints.push_back( corner );
|
2008-02-20 19:37:17 +00:00
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-03-27 21:24:50 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_HIERLABEL::GetBoundingBox() const
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth();
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
// In practice this is controlled by the current TextOffsetRatio, but the default is
|
|
|
|
// close enough for hit-testing, etc.
|
|
|
|
int margin = Mils2iu( TXT_MARGIN );
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int x = GetTextPos().x;
|
|
|
|
int y = GetTextPos().y;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2020-04-17 11:34:32 +00:00
|
|
|
int height = GetTextHeight() + penWidth + 2 * margin;
|
2020-04-18 20:04:41 +00:00
|
|
|
int length = LenSize( GetShownText(), penWidth )
|
2020-04-14 12:25:00 +00:00
|
|
|
+ height // add height for triangular shapes
|
2020-04-17 11:34:32 +00:00
|
|
|
+ 2 * margin;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int dx, dy;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
default:
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = -length;
|
|
|
|
dy = height;
|
2019-12-30 18:28:00 +00:00
|
|
|
x += Mils2iu( DANGLING_SYMBOL_SIZE );
|
2009-05-05 17:32:07 +00:00
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = height;
|
2009-05-12 12:12:34 +00:00
|
|
|
dy = -length;
|
2009-05-05 17:32:07 +00:00
|
|
|
x -= height / 2;
|
2019-12-30 18:28:00 +00:00
|
|
|
y += Mils2iu( DANGLING_SYMBOL_SIZE );
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = length;
|
|
|
|
dy = height;
|
2019-12-30 18:28:00 +00:00
|
|
|
x -= Mils2iu( DANGLING_SYMBOL_SIZE );
|
2009-05-05 17:32:07 +00:00
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = height;
|
2009-05-12 12:12:34 +00:00
|
|
|
dy = length;
|
2009-05-05 17:32:07 +00:00
|
|
|
x -= height / 2;
|
2019-12-30 18:28:00 +00:00
|
|
|
y -= Mils2iu( DANGLING_SYMBOL_SIZE );
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
2008-03-30 09:27:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
|
2008-03-30 09:27:53 +00:00
|
|
|
box.Normalize();
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
wxPoint SCH_HIERLABEL::GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset;
|
2020-04-17 11:34:32 +00:00
|
|
|
int dist = GetTextOffset( aSettings );
|
2020-04-14 12:25:00 +00:00
|
|
|
|
|
|
|
dist += GetTextWidth();
|
2008-03-27 21:24:50 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2008-03-27 21:24:50 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
default:
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
2020-04-14 12:25:00 +00:00
|
|
|
text_offset.x = -dist;
|
2020-01-08 19:07:55 +00:00
|
|
|
break; // Orientation horiz normale
|
|
|
|
case LABEL_SPIN_STYLE::UP:
|
2020-04-14 12:25:00 +00:00
|
|
|
text_offset.y = -dist;
|
2020-01-08 19:07:55 +00:00
|
|
|
break; // Orientation vert UP
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2020-04-14 12:25:00 +00:00
|
|
|
text_offset.x = dist;
|
2020-01-08 19:07:55 +00:00
|
|
|
break; // Orientation horiz inverse
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2020-04-14 12:25:00 +00:00
|
|
|
text_offset.y = dist;
|
2020-01-08 19:07:55 +00:00
|
|
|
break; // Orientation vert BOTTOM
|
2008-03-27 21:24:50 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
return text_offset;
|
2008-03-27 21:24:50 +00:00
|
|
|
}
|
2009-11-28 09:24:37 +00:00
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_HIERLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
return wxString::Format( _( "Hierarchical Label %s" ), ShortenedShownText() );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2017-02-20 12:20:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
BITMAP_DEF SCH_HIERLABEL::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_hierarchical_label_xpm;
|
|
|
|
}
|