2011-10-12 14:03:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-03-23 12:16:27 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-05-14 17:44:17 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2022-01-02 14:08:09 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-12 14:03:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
#include <pgm_base.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_text.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
#include <sch_painter.h>
|
|
|
|
#include <default_values.h>
|
2019-09-06 20:15:14 +00:00
|
|
|
#include <wx/debug.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2021-09-14 18:26:03 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
2020-07-07 10:17:30 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2021-10-01 10:52:34 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2011-07-03 18:51:07 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
using KIGFX::SCH_RENDER_SETTINGS;
|
|
|
|
|
|
|
|
|
2020-12-04 12:48:32 +00:00
|
|
|
bool IncrementLabelMember( wxString& name, int aIncrement )
|
2020-05-27 11:13:57 +00:00
|
|
|
{
|
2021-08-18 23:08:08 +00:00
|
|
|
if( name.IsEmpty() )
|
|
|
|
return true;
|
2020-05-27 11:13:57 +00:00
|
|
|
|
2021-11-21 18:00:49 +00:00
|
|
|
wxString suffix;
|
|
|
|
wxString digits;
|
2021-12-01 13:20:35 +00:00
|
|
|
wxString outputFormat;
|
|
|
|
wxString outputNumber;
|
|
|
|
int ii = name.Len() - 1;
|
|
|
|
int dCount = 0;
|
2020-12-04 12:48:32 +00:00
|
|
|
|
2021-11-21 18:00:49 +00:00
|
|
|
while( ii >= 0 && !wxIsdigit( name.GetChar( ii ) ) )
|
|
|
|
{
|
|
|
|
suffix = name.GetChar( ii ) + suffix;
|
2021-08-18 23:08:08 +00:00
|
|
|
ii--;
|
2021-11-21 18:00:49 +00:00
|
|
|
}
|
2020-05-27 11:13:57 +00:00
|
|
|
|
|
|
|
while( ii >= 0 && wxIsdigit( name.GetChar( ii ) ) )
|
|
|
|
{
|
2021-08-18 23:08:08 +00:00
|
|
|
digits = name.GetChar( ii ) + digits;
|
2020-05-27 11:13:57 +00:00
|
|
|
ii--;
|
2021-12-01 13:20:35 +00:00
|
|
|
dCount++;
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 23:08:08 +00:00
|
|
|
if( digits.IsEmpty() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
long number = 0;
|
2020-05-27 11:13:57 +00:00
|
|
|
|
2021-08-18 23:08:08 +00:00
|
|
|
if( digits.ToLong( &number ) )
|
2020-05-27 11:13:57 +00:00
|
|
|
{
|
|
|
|
number += aIncrement;
|
2020-12-04 12:48:32 +00:00
|
|
|
|
|
|
|
// Don't let result go below zero
|
|
|
|
|
|
|
|
if( number > -1 )
|
|
|
|
{
|
2021-08-18 23:08:08 +00:00
|
|
|
name.Remove( ii + 1 );
|
2021-12-01 13:20:35 +00:00
|
|
|
//write out a format string with correct number of leading zeroes
|
|
|
|
outputFormat.Printf( "%%0%dd", dCount );
|
|
|
|
//write out the number using the format string
|
|
|
|
outputNumber.Printf( outputFormat, number );
|
|
|
|
name << outputNumber << suffix;
|
2020-12-04 12:48:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2020-12-04 12:48:32 +00:00
|
|
|
return false;
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-01 23:13:53 +00:00
|
|
|
LABEL_SPIN_STYLE LABEL_SPIN_STYLE::RotateCW()
|
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::LEFT: newSpin = LABEL_SPIN_STYLE::UP; break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: newSpin = LABEL_SPIN_STYLE::RIGHT; break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: newSpin = LABEL_SPIN_STYLE::BOTTOM; break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: newSpin = LABEL_SPIN_STYLE::LEFT; break;
|
|
|
|
default: wxLogWarning( "RotateCW encountered unknown current spin style" ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LABEL_SPIN_STYLE( newSpin );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LABEL_SPIN_STYLE LABEL_SPIN_STYLE::RotateCCW()
|
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::LEFT: newSpin = LABEL_SPIN_STYLE::BOTTOM; break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: newSpin = LABEL_SPIN_STYLE::RIGHT; break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: newSpin = LABEL_SPIN_STYLE::UP; break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: newSpin = LABEL_SPIN_STYLE::LEFT; break;
|
|
|
|
default: wxLogWarning( "RotateCCW encountered unknown current spin style" ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LABEL_SPIN_STYLE( newSpin );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LABEL_SPIN_STYLE LABEL_SPIN_STYLE::MirrorX()
|
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::UP: newSpin = LABEL_SPIN_STYLE::BOTTOM; break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: newSpin = LABEL_SPIN_STYLE::UP; break;
|
|
|
|
case LABEL_SPIN_STYLE::LEFT: break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: break;
|
|
|
|
default: wxLogWarning( "MirrorX encountered unknown current spin style" ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LABEL_SPIN_STYLE( newSpin );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LABEL_SPIN_STYLE LABEL_SPIN_STYLE::MirrorY()
|
|
|
|
{
|
|
|
|
SPIN newSpin = m_spin;
|
|
|
|
|
|
|
|
switch( m_spin )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::LEFT: newSpin = LABEL_SPIN_STYLE::RIGHT; break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: newSpin = LABEL_SPIN_STYLE::LEFT; break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: break;
|
|
|
|
default: wxLogWarning( "MirrorY encountered unknown current spin style" ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LABEL_SPIN_STYLE( newSpin );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_TEXT::SCH_TEXT( const VECTOR2I& pos, const wxString& text, KICAD_T aType ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, aType ),
|
2021-10-12 20:05:37 +00:00
|
|
|
EDA_TEXT( text )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = LAYER_NOTES;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
SetTextPos( pos );
|
2021-11-27 17:03:20 +00:00
|
|
|
SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) :
|
2020-04-16 13:22:19 +00:00
|
|
|
SCH_ITEM( aText ),
|
|
|
|
EDA_TEXT( aText ),
|
|
|
|
m_spin_style( aText.m_spin_style )
|
|
|
|
{ }
|
2008-01-21 16:21:41 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2020-12-04 12:48:32 +00:00
|
|
|
bool SCH_TEXT::IncrementLabel( int aIncrement )
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
wxString text = GetText();
|
2020-12-04 12:48:32 +00:00
|
|
|
bool ReturnVal = IncrementLabelMember( text, aIncrement );
|
2021-03-10 16:56:09 +00:00
|
|
|
|
2020-12-04 12:48:32 +00:00
|
|
|
if( ReturnVal )
|
|
|
|
SetText( text );
|
|
|
|
|
|
|
|
return ReturnVal;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_TEXT::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2022-01-07 14:49:17 +00:00
|
|
|
return VECTOR2I( 0, 0 );
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_TEXT::MirrorHorizontally( int aCenter )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2013-03-01 19:59:29 +00:00
|
|
|
// Text is NOT really mirrored; it is moved to a suitable horizontal position
|
2020-01-08 19:07:55 +00:00
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().MirrorY() );
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_TEXT::MirrorVertically( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2013-03-01 19:59:29 +00:00
|
|
|
// Text is NOT really mirrored; it is moved to a suitable vertical position
|
2020-01-08 19:07:55 +00:00
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().MirrorX() );
|
2015-06-26 13:41:56 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_TEXT::Rotate( const VECTOR2I& aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pt = GetTextPos();
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( pt, aCenter, ANGLE_90 );
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I offset = pt - GetTextPos();
|
2021-12-02 15:33:49 +00:00
|
|
|
|
2020-11-24 18:16:03 +00:00
|
|
|
Rotate90( false );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2021-12-04 04:28:14 +00:00
|
|
|
SetTextPos( GetTextPos() + offset );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 21:40:04 +00:00
|
|
|
void SCH_TEXT::Rotate90( bool aClockwise )
|
|
|
|
{
|
|
|
|
if( aClockwise )
|
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
|
|
|
|
else
|
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().RotateCCW() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 23:34:03 +00:00
|
|
|
void SCH_TEXT::MirrorSpinStyle( bool aLeftRight )
|
|
|
|
{
|
|
|
|
if( aLeftRight )
|
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().MirrorY() );
|
|
|
|
else
|
|
|
|
SetLabelSpinStyle( GetLabelSpinStyle().MirrorX() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2021-06-09 19:32:58 +00:00
|
|
|
// Thus we want to left justify text up against the anchor if we are on the right
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( aSpinStyle )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
default:
|
2021-10-12 20:05:37 +00:00
|
|
|
wxFAIL_MSG( "Bad spin style" );
|
|
|
|
m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
|
|
|
|
KI_FALLTHROUGH;
|
2020-01-10 23:14:37 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
|
2022-01-13 12:29:46 +00:00
|
|
|
SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_TEXT::SwapData( SCH_ITEM* aItem )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_TEXT* item = static_cast<SCH_TEXT*>( aItem );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, item->m_layer );
|
2017-01-23 20:30:11 +00:00
|
|
|
std::swap( m_spin_style, item->m_spin_style );
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
SwapText( *item );
|
2021-12-28 22:13:54 +00:00
|
|
|
SwapAttributes( *item );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2020-01-28 15:42:42 +00:00
|
|
|
bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
|
|
|
auto other = static_cast<const SCH_TEXT*>( &aItem );
|
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
if( GetLayer() != other->GetLayer() )
|
|
|
|
return GetLayer() < other->GetLayer();
|
2020-01-28 15:42:42 +00:00
|
|
|
|
|
|
|
if( GetPosition().x != other->GetPosition().x )
|
|
|
|
return GetPosition().x < other->GetPosition().x;
|
|
|
|
|
|
|
|
if( GetPosition().y != other->GetPosition().y )
|
|
|
|
return GetPosition().y < other->GetPosition().y;
|
|
|
|
|
|
|
|
return GetText() < other->GetText();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
int SCH_TEXT::GetTextOffset( const RENDER_SETTINGS* aSettings ) const
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
double ratio;
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
if( aSettings )
|
2020-12-20 18:18:54 +00:00
|
|
|
ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_TextOffsetRatio;
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( Schematic() )
|
|
|
|
ratio = Schematic()->Settings().m_TextOffsetRatio;
|
|
|
|
else
|
|
|
|
ratio = DEFAULT_TEXT_OFFSET_RATIO; // For previews (such as in Preferences), etc.
|
|
|
|
|
|
|
|
return KiROUND( ratio * GetTextSize().y );
|
2020-04-14 12:25:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_TEXT::GetPenWidth() const
|
|
|
|
{
|
|
|
|
return GetEffectiveTextPenWidth();
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 00:47:23 +00:00
|
|
|
KIFONT::FONT* SCH_TEXT::GetDrawFont() const
|
|
|
|
{
|
|
|
|
KIFONT::FONT* font = EDA_TEXT::GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
COLOR4D color = aSettings->GetLayerColor( m_layer );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I 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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
if( !GetTextAngle().IsZero() ) // Rotate rect.
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = rect.GetOrigin();
|
|
|
|
VECTOR2I end = rect.GetEnd();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
RotatePoint( pos, GetTextPos(), GetTextAngle() );
|
|
|
|
RotatePoint( end, GetTextPos(), GetTextAngle() );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
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
|
|
|
|
2021-12-02 15:43:19 +00:00
|
|
|
rect.Normalize();
|
2010-11-03 14:13:15 +00:00
|
|
|
return rect;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
wxString getElectricalTypeLabel( LABEL_FLAG_SHAPE aType )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_INPUT: return _( "Input" );
|
|
|
|
case LABEL_FLAG_SHAPE::L_OUTPUT: return _( "Output" );
|
|
|
|
case LABEL_FLAG_SHAPE::L_BIDI: return _( "Bidirectional" );
|
|
|
|
case LABEL_FLAG_SHAPE::L_TRISTATE: return _( "Tri-State" );
|
|
|
|
case LABEL_FLAG_SHAPE::L_UNSPECIFIED: return _( "Passive" );
|
|
|
|
default: return wxT( "???" );
|
2020-03-29 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString SCH_TEXT::GetShownText( int aDepth ) const
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-04-05 19:51:48 +00:00
|
|
|
std::function<bool( wxString* )> textResolver =
|
2020-04-06 13:06:57 +00:00
|
|
|
[&]( wxString* token ) -> bool
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( token->Contains( ':' ) )
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( Schematic()->ResolveCrossReference( token, aDepth ) )
|
|
|
|
return true;
|
2020-04-05 19:51:48 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCHEMATIC* schematic = Schematic();
|
|
|
|
SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
|
2020-04-05 19:51:48 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-05 19:51:48 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2021-07-06 12:27:36 +00:00
|
|
|
std::function<bool( wxString* )> schematicTextResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
return Schematic()->ResolveTextVar( token, aDepth + 1 );
|
|
|
|
};
|
|
|
|
|
2021-06-29 12:54:40 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText();
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2021-06-12 17:58:15 +00:00
|
|
|
if( text == "~" ) // Legacy placeholder for empty string
|
|
|
|
{
|
|
|
|
text = "";
|
|
|
|
}
|
2021-06-29 12:54:40 +00:00
|
|
|
else if( HasTextVars() )
|
2020-04-24 20:33:59 +00:00
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
PROJECT* project = nullptr;
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2020-05-21 02:27:48 +00:00
|
|
|
if( Schematic() )
|
|
|
|
project = &Schematic()->Prj();
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2020-04-24 20:33:59 +00:00
|
|
|
if( aDepth < 10 )
|
2021-07-06 12:27:36 +00:00
|
|
|
text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project );
|
2020-04-24 20:33:59 +00:00
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return text;
|
2020-03-29 01:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2020-10-16 00:39:55 +00:00
|
|
|
return wxString::Format( _( "Graphic Text '%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
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_TEXT::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::text;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void SCH_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 2;
|
|
|
|
aLayers[0] = m_layer;
|
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_TEXT::Plot( PLOTTER* aPlotter ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
static std::vector<VECTOR2I> s_poly;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-12-13 22:42:29 +00:00
|
|
|
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
|
|
|
SCH_CONNECTION* connection = Connection();
|
|
|
|
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
|
|
|
COLOR4D color = settings->GetLayerColor( layer );
|
|
|
|
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
2022-01-07 00:47:23 +00:00
|
|
|
KIFONT::FONT* font = GetDrawFont();
|
2020-12-13 22:42:29 +00:00
|
|
|
|
|
|
|
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
2020-04-13 19:55:27 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> positions;
|
2021-10-12 20:05:37 +00:00
|
|
|
wxArrayString strings_list;
|
|
|
|
wxStringSplit( GetShownText(), strings_list, '\n' );
|
|
|
|
positions.reserve( strings_list.Count() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
GetLinePositions( positions, (int) strings_list.Count() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
|
2021-10-12 20:05:37 +00:00
|
|
|
wxString& txt = strings_list.Item( ii );
|
|
|
|
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
|
2022-01-07 00:47:23 +00:00
|
|
|
GetVertJustify(), penWidth, IsItalic(), IsBold(), false, font );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-03-03 16:38:41 +00:00
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
2021-10-12 20:05:37 +00:00
|
|
|
aList.emplace_back( _( "Graphic Text" ), UnescapeString( GetText() ) );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
|
2021-10-12 20:05:37 +00:00
|
|
|
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Style" ), textStyle[style] );
|
2012-11-20 11:35:09 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( aFrame->GetUserUnits(),
|
|
|
|
GetTextWidth() ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
|
|
|
switch( GetLabelSpinStyle() )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
2021-09-26 23:22:32 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: msg = _( "Align right" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: msg = _( "Align bottom" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: msg = _( "Align left" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: msg = _( "Align top" ); break;
|
|
|
|
default: msg = wxT( "???" ); break;
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Justification" ), msg );
|
2012-11-20 11:35:09 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
|
2020-11-14 14:29:11 +00:00
|
|
|
<< " layer=\"" << m_layer << '"'
|
2009-05-05 17:32:07 +00:00
|
|
|
<< '>'
|
2019-08-02 00:10:25 +00:00
|
|
|
<< TO_UTF8( GetText() )
|
2009-05-05 17:32:07 +00:00
|
|
|
<< "</" << s.Lower().mb_str() << ">\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_LABEL_BASE::SCH_LABEL_BASE( const VECTOR2I& aPos, const wxString& aText, KICAD_T aType ) :
|
2021-12-30 23:42:06 +00:00
|
|
|
SCH_TEXT( aPos, aText, aType ),
|
|
|
|
m_shape( L_UNSPECIFIED ),
|
|
|
|
m_connectionType( CONNECTION_TYPE::NONE ),
|
|
|
|
m_isDangling( true )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
SetMultilineAllowed( false );
|
2022-01-02 14:08:09 +00:00
|
|
|
ClearFieldsAutoplaced(); // fiels are not yet autoplaced.
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LABEL_BASE::SCH_LABEL_BASE( const SCH_LABEL_BASE& aLabel ) :
|
|
|
|
SCH_TEXT( aLabel ),
|
|
|
|
m_shape( aLabel.m_shape ),
|
|
|
|
m_connectionType( aLabel.m_connectionType ),
|
|
|
|
m_isDangling( aLabel.m_isDangling )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
SetMultilineAllowed( false );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
m_fields = aLabel.m_fields;
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
field.SetParent( this );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
const wxString SCH_LABEL_BASE::GetDefaultFieldName( const wxString& aName, bool aUseDefaultName )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
static void* locale = nullptr;
|
|
|
|
static wxString intersheetRefsDefault;
|
|
|
|
static wxString netclassRefDefault;
|
|
|
|
static wxString userFieldDefault;
|
|
|
|
|
|
|
|
// Fetching translations can take a surprising amount of time when loading libraries,
|
|
|
|
// so only do it when necessary.
|
|
|
|
if( Pgm().GetLocale() != locale )
|
|
|
|
{
|
|
|
|
intersheetRefsDefault = _( "Sheet References" );
|
|
|
|
netclassRefDefault = _( "Net Class" );
|
|
|
|
userFieldDefault = _( "Field" );
|
|
|
|
locale = Pgm().GetLocale();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aName == wxT( "Intersheetrefs" ) )
|
|
|
|
return intersheetRefsDefault;
|
|
|
|
else if( aName == wxT( "Netclass" ) )
|
|
|
|
return netclassRefDefault;
|
|
|
|
else if( aName.IsEmpty() && aUseDefaultName )
|
|
|
|
return userFieldDefault;
|
|
|
|
else
|
|
|
|
return aName;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
bool SCH_LABEL_BASE::IsType( const KICAD_T aScanTypes[] ) const
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
static KICAD_T wireTypes[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T, EOT };
|
|
|
|
static KICAD_T busTypes[] = { SCH_ITEM_LOCATE_BUS_T, EOT };
|
2019-06-30 22:06:34 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( SCH_TEXT::IsType( aScanTypes ) )
|
2019-06-30 22:06:34 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( *p == SCH_LABEL_LOCATE_ANY_T )
|
|
|
|
return true;
|
|
|
|
|
2019-06-30 22:06:34 +00:00
|
|
|
if( *p == SCH_LABEL_LOCATE_WIRE_T )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
wxCHECK_MSG( Schematic(), false, "No parent SCHEMATIC set for SCH_LABEL!" );
|
2020-01-17 02:33:16 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_ITEM* connection : m_connected_items.at( Schematic()->CurrentSheet() ) )
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
|
|
|
if( connection->IsType( wireTypes ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if ( *p == SCH_LABEL_LOCATE_BUS_T )
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
wxCHECK_MSG( Schematic(), false, "No parent SCHEMATIC set for SCH_LABEL!" );
|
2020-01-17 02:33:16 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_ITEM* connection : m_connected_items.at( Schematic()->CurrentSheet() ) )
|
2019-06-30 22:06:34 +00:00
|
|
|
{
|
|
|
|
if( connection->IsType( busTypes ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void SCH_LABEL_BASE::SwapData( SCH_ITEM* aItem )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_TEXT::SwapData( aItem );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
m_fields.swap( label->m_fields );
|
|
|
|
std::swap( m_fieldsAutoplaced, label->m_fieldsAutoplaced );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
field.SetParent( this );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : label->m_fields )
|
|
|
|
field.SetParent( label );
|
2021-02-26 00:21:33 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
std::swap( m_shape, label->m_shape );
|
|
|
|
std::swap( m_connectionType, label->m_connectionType );
|
|
|
|
std::swap( m_isDangling, label->m_isDangling );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 14:49:17 +00:00
|
|
|
VECTOR2I SCH_LABEL_BASE::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const
|
|
|
|
{
|
|
|
|
VECTOR2I text_offset;
|
|
|
|
|
|
|
|
// add an offset to x (or y) position to aid readability of text on a wire or line
|
|
|
|
int dist = GetTextOffset( aSettings ) + GetPenWidth();
|
|
|
|
|
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::UP:
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: text_offset.x = -dist; break; // Vert Orientation
|
|
|
|
default:
|
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: text_offset.y = -dist; break; // Horiz Orientation
|
|
|
|
}
|
|
|
|
|
|
|
|
return text_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LABEL_BASE::Rotate( const VECTOR2I& aCenter )
|
2021-12-06 18:50:00 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pt = GetTextPos();
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( pt, aCenter, ANGLE_90 );
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I offset = pt - GetTextPos();
|
2021-12-07 20:47:12 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
Rotate90( false );
|
2021-12-06 18:50:00 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
SetTextPos( GetTextPos() + offset );
|
2021-12-06 18:50:00 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
field.SetTextPos( field.GetTextPos() + offset );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void SCH_LABEL_BASE::Rotate90( bool aClockwise )
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_TEXT::Rotate90( aClockwise );
|
2017-02-20 12:20:39 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( m_fieldsAutoplaced == FIELDS_AUTOPLACED_AUTO )
|
|
|
|
{
|
|
|
|
AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
if( field.GetTextAngle().IsVertical()
|
|
|
|
&& field.GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( !aClockwise )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2017-02-20 12:20:39 +00:00
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( field.GetTextAngle().IsVertical()
|
|
|
|
&& field.GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( !aClockwise )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( field.GetTextAngle().IsHorizontal()
|
|
|
|
&& field.GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( aClockwise )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-11-18 21:40:04 +00:00
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( field.GetTextAngle().IsHorizontal()
|
|
|
|
&& field.GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( aClockwise )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( pos, GetPosition(), aClockwise ? -ANGLE_90 : ANGLE_90 );
|
2021-10-12 20:05:37 +00:00
|
|
|
field.SetTextPos( pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LABEL_BASE::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
int margin = GetTextOffset() * 2;
|
|
|
|
int labelLen = GetBodyBoundingBox().GetSizeMax();
|
|
|
|
int accumulated = GetTextHeight() / 2;
|
|
|
|
|
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
accumulated += margin + GetPenWidth() + margin;
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I offset( 0, 0 );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T && field.GetId() == 0 )
|
|
|
|
offset.x = - ( labelLen + margin );
|
|
|
|
else
|
|
|
|
offset.y = accumulated + field.GetTextHeight() / 2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_SPIN_STYLE::UP:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T && field.GetId() == 0 )
|
|
|
|
offset.y = - ( labelLen + margin );
|
|
|
|
else
|
|
|
|
offset.x = accumulated + field.GetTextHeight() / 2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T && field.GetId() == 0 )
|
|
|
|
offset.x = labelLen + margin;
|
|
|
|
else
|
|
|
|
offset.y = accumulated + field.GetTextHeight() / 2;
|
|
|
|
|
|
|
|
break;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T && field.GetId() == 0 )
|
|
|
|
offset.y = labelLen + margin;
|
|
|
|
else
|
|
|
|
offset.x = accumulated + field.GetTextHeight() / 2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
field.SetTextPos( GetTextPos() + offset );
|
|
|
|
|
|
|
|
if( Type() != SCH_GLOBAL_LABEL_T || field.GetId() > 0 )
|
|
|
|
accumulated += field.GetTextHeight() + margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fieldsAutoplaced = FIELDS_AUTOPLACED_AUTO;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( ( Type() == SCH_GLOBAL_LABEL_T || Type() == SCH_HIER_LABEL_T || Type() == SCH_SHEET_PIN_T )
|
|
|
|
&& token->IsSameAs( wxT( "CONNECTION_TYPE" ) ) )
|
|
|
|
{
|
|
|
|
const SCH_LABEL_BASE* label = static_cast<const SCH_LABEL_BASE*>( this );
|
|
|
|
*token = getElectricalTypeLabel( label->GetShape() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_fields.size(); ++i )
|
|
|
|
{
|
|
|
|
if( token->IsSameAs( m_fields[i].GetName() ) )
|
|
|
|
{
|
|
|
|
*token = m_fields[i].GetShownText( aDepth + 1 );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Type() == SCH_SHEET_PIN_T && m_parent )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
|
|
|
|
|
|
|
|
if( sheet->ResolveTextVar( token, aDepth ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
wxString SCH_LABEL_BASE::GetShownText( int aDepth ) const
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
std::function<bool( wxString* )> textResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
return ResolveTextVar( token, aDepth );
|
|
|
|
};
|
|
|
|
|
|
|
|
std::function<bool( wxString* )> schematicTextResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
return Schematic()->ResolveTextVar( token, aDepth + 1 );
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString text = EDA_TEXT::GetShownText();
|
|
|
|
|
|
|
|
if( text == "~" ) // Legacy placeholder for empty string
|
|
|
|
{
|
|
|
|
text = "";
|
|
|
|
}
|
|
|
|
else if( HasTextVars() )
|
|
|
|
{
|
|
|
|
PROJECT* project = nullptr;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( Schematic() )
|
|
|
|
project = &Schematic()->Prj();
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( aDepth < 10 )
|
|
|
|
text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project );
|
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
return text;
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void SCH_LABEL_BASE::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
|
|
|
|
{
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
aFunction( &field );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SEARCH_RESULT SCH_LABEL_BASE::Visit( INSPECTOR aInspector, void* testData,
|
|
|
|
const KICAD_T aFilterTypes[] )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
|
|
|
KICAD_T stype;
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( IsType( aFilterTypes ) )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( this, nullptr ) )
|
|
|
|
return SEARCH_RESULT::QUIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
|
|
|
|
{
|
|
|
|
if( stype == SCH_LOCATE_ANY_T || stype == SCH_FIELD_T )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
{
|
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( &field, this ) )
|
|
|
|
return SEARCH_RESULT::QUIT;
|
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SEARCH_RESULT::CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LABEL_BASE::GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
DANGLING_END_ITEM item( LABEL_END, this, GetTextPos() );
|
2021-10-12 20:05:37 +00:00
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> SCH_LABEL_BASE::GetConnectionPoints() const
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
return { GetTextPos() };
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LABEL_BASE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 5;
|
|
|
|
aLayers[0] = LAYER_DANGLING;
|
|
|
|
aLayers[1] = LAYER_DEVICE;
|
|
|
|
aLayers[2] = LAYER_NETCLASS_REFS;
|
|
|
|
aLayers[3] = LAYER_FIELDS;
|
|
|
|
aLayers[4] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_LABEL_BASE::GetLabelBoxExpansion( const RENDER_SETTINGS* aSettings ) const
|
|
|
|
{
|
|
|
|
double ratio;
|
|
|
|
|
|
|
|
if( aSettings )
|
|
|
|
ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_LabelSizeRatio;
|
|
|
|
else if( Schematic() )
|
|
|
|
ratio = Schematic()->Settings().m_LabelSizeRatio;
|
|
|
|
else
|
|
|
|
ratio = DEFAULT_LABEL_SIZE_RATIO; // For previews (such as in Preferences), etc.
|
|
|
|
|
|
|
|
return KiROUND( ratio * GetTextSize().y );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT SCH_LABEL_BASE::GetBodyBoundingBox() const
|
|
|
|
{
|
|
|
|
// build the bounding box of the label only, without taking into account its fields
|
|
|
|
|
|
|
|
EDA_RECT box;
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
CreateGraphicShape( nullptr, pts, GetTextPos() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& pt : pts )
|
2021-10-12 20:05:37 +00:00
|
|
|
box.Merge( pt );
|
|
|
|
|
|
|
|
box.Inflate( GetEffectiveTextPenWidth() / 2 );
|
|
|
|
box.Normalize();
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT SCH_LABEL_BASE::GetBoundingBox() const
|
|
|
|
{
|
|
|
|
// build the bounding box of the entire net class flag, including both the symbol and the
|
|
|
|
// net class reference text
|
|
|
|
|
|
|
|
EDA_RECT box( GetBodyBoundingBox() );
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : m_fields )
|
2022-01-07 17:42:43 +00:00
|
|
|
{
|
|
|
|
if( field.IsVisible() )
|
|
|
|
box.Merge( field.GetBoundingBox() );
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
box.Normalize();
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_LABEL_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
EDA_RECT bbox = GetBodyBoundingBox();
|
|
|
|
bbox.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( bbox.Contains( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : m_fields )
|
|
|
|
{
|
|
|
|
if( field.IsVisible() )
|
|
|
|
{
|
|
|
|
bbox = field.GetBoundingBox();
|
|
|
|
bbox.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( bbox.Contains( aPosition ) )
|
|
|
|
return bbox.Contains( aPosition );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LABEL_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect = aRect;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
{
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( rect.Intersects( GetBodyBoundingBox() ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : m_fields )
|
|
|
|
{
|
|
|
|
if( field.IsVisible() && rect.Intersects( field.GetBoundingBox() ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LABEL_BASE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
|
|
|
|
const SCH_SHEET_PATH* aPath )
|
|
|
|
{
|
|
|
|
bool previousState = m_isDangling;
|
|
|
|
m_isDangling = true;
|
|
|
|
m_connectionType = CONNECTION_TYPE::NONE;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aItemList.size(); ii++ )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM& item = aItemList[ii];
|
|
|
|
|
|
|
|
if( item.GetItem() == this )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item.GetType() )
|
|
|
|
{
|
|
|
|
case PIN_END:
|
|
|
|
case LABEL_END:
|
|
|
|
case SHEET_LABEL_END:
|
|
|
|
case NO_CONNECT_END:
|
|
|
|
if( GetTextPos() == item.GetPosition() )
|
|
|
|
{
|
|
|
|
m_isDangling = false;
|
|
|
|
|
|
|
|
if( aPath && item.GetType() != PIN_END )
|
|
|
|
m_connected_items[ *aPath ].insert( static_cast<SCH_ITEM*>( item.GetItem() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUS_END:
|
|
|
|
m_connectionType = CONNECTION_TYPE::BUS;
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
|
|
|
case WIRE_END:
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM& nextItem = aItemList[++ii];
|
|
|
|
|
|
|
|
int accuracy = 1; // We have rounding issues with an accuracy of 0
|
|
|
|
|
|
|
|
m_isDangling = !TestSegmentHit( GetTextPos(), item.GetPosition(),
|
|
|
|
nextItem.GetPosition(), accuracy );
|
|
|
|
|
|
|
|
if( !m_isDangling )
|
|
|
|
{
|
|
|
|
if( m_connectionType != CONNECTION_TYPE::BUS )
|
|
|
|
m_connectionType = CONNECTION_TYPE::NET;
|
|
|
|
|
|
|
|
// Add the line to the connected items, since it won't be picked
|
|
|
|
// up by a search of intersecting connection points
|
|
|
|
if( aPath )
|
|
|
|
{
|
|
|
|
auto sch_item = static_cast<SCH_ITEM*>( item.GetItem() );
|
|
|
|
AddConnectionTo( *aPath, sch_item );
|
|
|
|
sch_item->AddConnectionTo( *aPath, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_isDangling )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_isDangling )
|
|
|
|
m_connectionType = CONNECTION_TYPE::NONE;
|
|
|
|
|
|
|
|
return previousState != m_isDangling;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LABEL_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T: msg = _( "Label" ); break;
|
|
|
|
case SCH_NETCLASS_FLAG_T: msg = _( "Net Class Flag" ); 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;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
|
|
|
aList.emplace_back( msg, UnescapeString( GetText() ) );
|
|
|
|
|
|
|
|
// Display electrical type if it is relevant
|
|
|
|
if( Type() == SCH_GLOBAL_LABEL_T || Type() == SCH_HIER_LABEL_T || Type() == SCH_SHEET_PIN_T )
|
|
|
|
aList.emplace_back( _( "Type" ), getElectricalTypeLabel( GetShape() ) );
|
|
|
|
|
|
|
|
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
|
|
|
|
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
|
|
|
|
aList.emplace_back( _( "Style" ), textStyle[style] );
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( aFrame->GetUserUnits(),
|
|
|
|
GetTextWidth() ) );
|
|
|
|
|
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::LEFT: msg = _( "Align right" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: msg = _( "Align bottom" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: msg = _( "Align left" ); break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: msg = _( "Align top" ); break;
|
|
|
|
default: msg = wxT( "???" ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Justification" ), msg );
|
|
|
|
|
|
|
|
SCH_CONNECTION* conn = nullptr;
|
|
|
|
|
|
|
|
if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
|
|
|
|
conn = Connection();
|
|
|
|
|
|
|
|
if( conn )
|
|
|
|
{
|
|
|
|
conn->AppendInfoToMsgPanel( aList );
|
|
|
|
|
|
|
|
if( !conn->IsBus() )
|
|
|
|
{
|
|
|
|
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
|
|
|
|
const wxString& netname = conn->Name( true );
|
|
|
|
|
|
|
|
if( netSettings.m_NetClassAssignments.count( netname ) )
|
|
|
|
{
|
|
|
|
const wxString& netclassName = netSettings.m_NetClassAssignments[ netname ];
|
|
|
|
aList.emplace_back( _( "Assigned Netclass" ), netclassName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter ) const
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
static std::vector<VECTOR2I> s_poly;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
|
|
|
SCH_CONNECTION* connection = Connection();
|
|
|
|
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
|
|
|
COLOR4D color = settings->GetLayerColor( layer );
|
|
|
|
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
|
|
|
|
|
|
|
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
|
|
|
|
GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold() );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
CreateGraphicShape( aPlotter->RenderSettings(), s_poly, GetTextPos() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( s_poly.size() )
|
|
|
|
aPlotter->PlotPoly( s_poly, FILL_T::NO_FILL, penWidth );
|
2022-01-12 10:08:34 +00:00
|
|
|
|
|
|
|
for( const SCH_FIELD& field : m_fields )
|
|
|
|
field.Plot( aPlotter );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LABEL_BASE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
static std::vector<VECTOR2I> s_poly;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
SCH_CONNECTION* connection = Connection();
|
|
|
|
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
COLOR4D color = aSettings->GetLayerColor( layer );
|
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
EDA_TEXT::Print( aSettings, text_offset, color );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
CreateGraphicShape( aSettings, s_poly, GetTextPos() + aOffset );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( !s_poly.empty() )
|
|
|
|
GRPoly( nullptr, DC, s_poly.size(), &s_poly[0], false, penWidth, color, color );
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
field.Print( aSettings, aOffset );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_LABEL::SCH_LABEL( const VECTOR2I& pos, const wxString& text ) :
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_LABEL_BASE( pos, text, SCH_LABEL_T )
|
|
|
|
{
|
|
|
|
m_layer = LAYER_LOCLABEL;
|
|
|
|
m_shape = LABEL_FLAG_SHAPE::L_INPUT;
|
|
|
|
m_isDangling = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT SCH_LABEL::GetBodyBoundingBox() const
|
|
|
|
{
|
|
|
|
EDA_RECT rect = GetTextBox();
|
|
|
|
|
|
|
|
rect.Offset( 0, -GetTextOffset() );
|
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
if( !GetTextAngle().IsZero() )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
// Rotate rect
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = rect.GetOrigin();
|
|
|
|
VECTOR2I end = rect.GetEnd();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
RotatePoint( pos, GetTextPos(), GetTextAngle() );
|
|
|
|
RotatePoint( end, GetTextPos(), GetTextAngle() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
rect.SetOrigin( pos );
|
|
|
|
rect.SetEnd( end );
|
|
|
|
|
|
|
|
rect.Normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Labels have a position point that is outside of the TextBox
|
|
|
|
rect.Merge( GetPosition() );
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
|
|
|
{
|
|
|
|
return wxString::Format( _( "Label '%s'" ), ShortenedShownText() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAPS SCH_LABEL::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return BITMAPS::add_line_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_NETCLASS_FLAG::SCH_NETCLASS_FLAG( const VECTOR2I& pos ) :
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_LABEL_BASE( pos, wxEmptyString, SCH_NETCLASS_FLAG_T )
|
|
|
|
{
|
|
|
|
m_layer = LAYER_NETCLASS_REFS;
|
|
|
|
m_shape = LABEL_FLAG_SHAPE::F_ROUND;
|
|
|
|
m_pinLength = Mils2iu( 100 );
|
|
|
|
m_symbolSize = Mils2iu( 20 );
|
|
|
|
m_isDangling = true;
|
|
|
|
|
|
|
|
m_fields.emplace_back( SCH_FIELD( { 0, 0 }, 0, this, _( "Net Class" ) ) );
|
|
|
|
m_fields[0].SetLayer( LAYER_NETCLASS_REFS );
|
|
|
|
m_fields[0].SetVisible( true );
|
|
|
|
m_fields[0].SetItalic( true );
|
2021-12-28 22:13:54 +00:00
|
|
|
m_fields[0].SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_NETCLASS_FLAG::SCH_NETCLASS_FLAG( const SCH_NETCLASS_FLAG& aClassLabel ) :
|
|
|
|
SCH_LABEL_BASE( aClassLabel )
|
|
|
|
{
|
|
|
|
m_pinLength = aClassLabel.m_pinLength;
|
|
|
|
m_symbolSize = aClassLabel.m_symbolSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NETCLASS_FLAG::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings,
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I>& aPoints,
|
|
|
|
const VECTOR2I& aPos ) const
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
int symbolSize = m_symbolSize;
|
|
|
|
|
|
|
|
aPoints.clear();
|
|
|
|
|
|
|
|
switch( m_shape )
|
|
|
|
{
|
|
|
|
case LABEL_FLAG_SHAPE::F_DOT:
|
|
|
|
symbolSize = KiROUND( symbolSize * 0.7 );
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
|
|
|
case LABEL_FLAG_SHAPE::F_ROUND:
|
|
|
|
// First 3 points are used for generating shape
|
2022-01-01 06:04:08 +00:00
|
|
|
aPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
// These points are just used to bulk out the bounding box
|
2022-01-01 06:04:08 +00:00
|
|
|
aPoints.emplace_back( VECTOR2I( -m_symbolSize, m_pinLength ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( m_symbolSize, m_pinLength + symbolSize ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_FLAG_SHAPE::F_DIAMOND:
|
2022-01-01 06:04:08 +00:00
|
|
|
aPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( -2 * m_symbolSize, m_pinLength ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength + symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 2 * m_symbolSize, m_pinLength ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_FLAG_SHAPE::F_RECTANGLE:
|
|
|
|
symbolSize = KiROUND( symbolSize * 0.8 );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
aPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( -2 * symbolSize, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( -2 * symbolSize, m_pinLength + symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 2 * symbolSize, m_pinLength + symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 2 * symbolSize, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, m_pinLength - symbolSize ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rotate outlines and move corners to real position
|
2022-01-01 06:04:08 +00:00
|
|
|
for( VECTOR2I& aPoint : aPoints )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
default:
|
2022-01-18 02:18:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: RotatePoint( aPoint, -ANGLE_90 ); break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: RotatePoint( aPoint, ANGLE_180 ); break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: RotatePoint( aPoint, ANGLE_90 ); break;
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aPoint += aPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NETCLASS_FLAG::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual )
|
|
|
|
{
|
|
|
|
int margin = GetTextOffset();
|
|
|
|
int symbolWidth = m_symbolSize;
|
|
|
|
int origin = m_pinLength;
|
|
|
|
|
|
|
|
if( m_shape == LABEL_FLAG_SHAPE::F_DIAMOND || m_shape == LABEL_FLAG_SHAPE::F_RECTANGLE )
|
|
|
|
symbolWidth *= 2;
|
|
|
|
|
|
|
|
if( IsItalic() )
|
|
|
|
margin = KiROUND( margin * 1.5 );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I offset;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
{
|
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case LABEL_SPIN_STYLE::LEFT:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
offset = { symbolWidth + margin, origin };
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_SPIN_STYLE::UP:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
offset = { -origin, -( symbolWidth + margin ) };
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
offset = { symbolWidth + margin, -origin };
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM:
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2021-10-12 20:05:37 +00:00
|
|
|
offset = { origin, -( symbolWidth + margin ) };
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-10-12 20:05:37 +00:00
|
|
|
field.SetTextPos( GetPosition() + offset );
|
|
|
|
|
|
|
|
origin -= field.GetTextHeight() + margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fieldsAutoplaced = FIELDS_AUTOPLACED_AUTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_NETCLASS_FLAG::GetSelectMenuText( EDA_UNITS aUnits ) const
|
|
|
|
{
|
|
|
|
return wxString::Format( _( "Net Class Flag" ), ShortenedShownText() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_GLOBALLABEL::SCH_GLOBALLABEL( const VECTOR2I& pos, const wxString& text ) :
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_LABEL_BASE( pos, text, SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
|
|
|
m_layer = LAYER_GLOBLABEL;
|
|
|
|
m_shape = LABEL_FLAG_SHAPE::L_BIDI;
|
|
|
|
m_isDangling = true;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
m_fields.emplace_back( SCH_FIELD( { 0, 0 }, 0, this, _( "Sheet References" ) ) );
|
|
|
|
m_fields[0].SetText( wxT( "${INTERSHEET_REFS}" ) );
|
|
|
|
m_fields[0].SetVisible( true );
|
|
|
|
m_fields[0].SetLayer( LAYER_INTERSHEET_REFS );
|
2021-12-28 22:13:54 +00:00
|
|
|
m_fields[0].SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_GLOBALLABEL::SCH_GLOBALLABEL( const SCH_GLOBALLABEL& aGlobalLabel ) :
|
|
|
|
SCH_LABEL_BASE( aGlobalLabel )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_GLOBALLABEL::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2021-07-25 11:42:19 +00:00
|
|
|
int horiz = GetLabelBoxExpansion( aSettings );
|
2021-07-25 11:37:23 +00:00
|
|
|
|
|
|
|
// Center the text on the center line of "E" instead of "R" to make room for an overbar
|
|
|
|
int vert = GetTextHeight() * 0.0715;
|
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
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_INPUT:
|
|
|
|
case LABEL_FLAG_SHAPE::L_BIDI:
|
|
|
|
case LABEL_FLAG_SHAPE::L_TRISTATE:
|
2021-07-25 11:37:23 +00:00
|
|
|
horiz += GetTextHeight() * 3 / 4; // Use three-quarters-height as proxy for triangle size
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_OUTPUT:
|
|
|
|
case LABEL_FLAG_SHAPE::L_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:
|
2022-01-01 06:04:08 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: return VECTOR2I( -horiz, vert );
|
|
|
|
case LABEL_SPIN_STYLE::UP: return VECTOR2I( vert, -horiz );
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: return VECTOR2I( horiz, vert );
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: return VECTOR2I( vert, horiz );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
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
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_TEXT::SetLabelSpinStyle( aSpinStyle );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2020-11-18 21:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 23:34:03 +00:00
|
|
|
void SCH_GLOBALLABEL::MirrorSpinStyle( bool aLeftRight )
|
|
|
|
{
|
|
|
|
SCH_TEXT::MirrorSpinStyle( aLeftRight );
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2020-11-18 23:34:03 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
if( ( aLeftRight && field.GetTextAngle().IsHorizontal() )
|
|
|
|
|| ( !aLeftRight && field.GetTextAngle().IsVertical() ) )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
if( field.GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
|
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2020-11-18 23:34:03 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
|
|
|
VECTOR2I delta = (VECTOR2I)GetPosition() - pos;
|
2020-11-18 23:34:03 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( aLeftRight )
|
|
|
|
pos.x = GetPosition().x + delta.x;
|
|
|
|
else
|
|
|
|
pos.y = GetPosition().y + delta.y;
|
2020-11-18 23:34:03 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
field.SetTextPos( pos );
|
|
|
|
}
|
2020-11-18 23:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_GLOBALLABEL::MirrorHorizontally( int aCenter )
|
2021-02-03 19:54:09 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I old_pos = GetPosition();
|
2021-02-16 20:45:25 +00:00
|
|
|
SCH_TEXT::MirrorHorizontally( aCenter );
|
2021-02-03 19:54:09 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
{
|
2022-01-02 14:44:52 +00:00
|
|
|
switch( field.GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
break;
|
|
|
|
}
|
2021-02-03 19:54:09 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
|
|
|
VECTOR2I delta = old_pos - pos;
|
2021-10-12 20:05:37 +00:00
|
|
|
pos.x = GetPosition().x + delta.x;
|
2021-02-03 19:54:09 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
field.SetPosition( pos );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2021-02-03 19:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_GLOBALLABEL::MirrorVertically( int aCenter )
|
2021-02-03 19:54:09 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I old_pos = GetPosition();
|
2021-02-16 20:45:25 +00:00
|
|
|
SCH_TEXT::MirrorVertically( aCenter );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
|
|
|
VECTOR2I delta = old_pos - pos;
|
2021-10-12 20:05:37 +00:00
|
|
|
pos.y = GetPosition().y + delta.y;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
field.SetPosition( pos );
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
|
|
|
|
{
|
|
|
|
if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() )
|
|
|
|
{
|
2021-04-02 10:18:25 +00:00
|
|
|
SCHEMATIC_SETTINGS& settings = Schematic()->Settings();
|
|
|
|
wxString ref;
|
|
|
|
auto it = Schematic()->GetPageRefsMap().find( GetText() );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-04-02 10:18:25 +00:00
|
|
|
if( it == Schematic()->GetPageRefsMap().end() )
|
|
|
|
{
|
|
|
|
ref = "?";
|
|
|
|
}
|
|
|
|
else
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
|
|
|
std::vector<wxString> pageListCopy;
|
|
|
|
|
|
|
|
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
|
2021-10-01 10:52:34 +00:00
|
|
|
std::sort( pageListCopy.begin(), pageListCopy.end(),
|
|
|
|
[]( const wxString& a, const wxString& b ) -> bool
|
|
|
|
{
|
2021-11-08 19:25:13 +00:00
|
|
|
return StrNumCmp( a, b, true ) < 0;
|
2021-10-01 10:52:34 +00:00
|
|
|
} );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-03-04 21:29:41 +00:00
|
|
|
if( !settings.m_IntersheetRefsListOwnPage )
|
|
|
|
{
|
2021-12-06 12:47:18 +00:00
|
|
|
wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
|
2021-10-01 10:52:34 +00:00
|
|
|
alg::delete_matching( pageListCopy, currentPage );
|
2021-03-04 21:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) )
|
|
|
|
{
|
2021-04-02 10:18:25 +00:00
|
|
|
ref.Append( wxString::Format( wxT( "%s..%s" ),
|
|
|
|
pageListCopy.front(),
|
|
|
|
pageListCopy.back() ) );
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( const wxString& pageNo : pageListCopy )
|
2021-04-02 10:18:25 +00:00
|
|
|
ref.Append( wxString::Format( wxT( "%s," ), pageNo ) );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-04-02 10:18:25 +00:00
|
|
|
if( !ref.IsEmpty() && ref.Last() == ',' )
|
|
|
|
ref.RemoveLast();
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 10:18:25 +00:00
|
|
|
*token = settings.m_IntersheetRefsPrefix + ref + settings.m_IntersheetRefsSuffix;
|
2020-11-17 16:02:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
return SCH_LABEL_BASE::ResolveTextVar( token, aDepth );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2021-05-14 17:44:17 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void SCH_GLOBALLABEL::ViewGetLayers( int aLayers[], int& aCount ) const
|
2020-11-23 13:29:40 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
aCount = 5;
|
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_INTERSHEET_REFS;
|
|
|
|
aLayers[2] = LAYER_NETCLASS_REFS;
|
|
|
|
aLayers[3] = LAYER_FIELDS;
|
|
|
|
aLayers[4] = LAYER_SELECTION_SHADOWS;
|
2020-11-23 13:29:40 +00:00
|
|
|
}
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2021-05-14 17:44:17 +00:00
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
void SCH_GLOBALLABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings,
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I>& aPoints,
|
|
|
|
const VECTOR2I& aPos ) const
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2021-07-25 11:42:19 +00:00
|
|
|
int margin = GetLabelBoxExpansion( aRenderSettings );
|
2020-04-17 11:34:32 +00:00
|
|
|
int halfSize = ( GetTextHeight() / 2 ) + margin;
|
2020-04-14 12:25:00 +00:00
|
|
|
int linewidth = GetPenWidth();
|
2021-12-31 14:07:24 +00:00
|
|
|
int symb_len = GetTextBox().GetWidth() + 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
|
2022-01-01 06:04:08 +00:00
|
|
|
aPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
|
|
|
aPoints.emplace_back( VECTOR2I( 0, -y ) ); // Up
|
|
|
|
aPoints.emplace_back( VECTOR2I( -x, -y ) ); // left
|
|
|
|
aPoints.emplace_back( VECTOR2I( -x, 0 ) ); // Up left
|
|
|
|
aPoints.emplace_back( VECTOR2I( -x, y ) ); // left down
|
|
|
|
aPoints.emplace_back( VECTOR2I( 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
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_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;
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_OUTPUT:
|
2016-03-23 07:41:47 +00:00
|
|
|
aPoints[3].x -= halfSize;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_BIDI:
|
|
|
|
case LABEL_FLAG_SHAPE::L_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;
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_UNSPECIFIED:
|
2010-09-11 16:33:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
// Rotate outlines and move corners in real position
|
2022-01-01 06:04:08 +00:00
|
|
|
for( VECTOR2I& 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
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
default:
|
2022-01-18 02:18:55 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: RotatePoint( aPoint, -ANGLE_90 ); break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: RotatePoint( aPoint, ANGLE_180 ); break;
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: RotatePoint( aPoint, ANGLE_90 ); break;
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
aPoint += aPos;
|
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
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_GLOBALLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2020-09-19 18:53:58 +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
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_GLOBALLABEL::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_glabel;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_HIERLABEL::SCH_HIERLABEL( const VECTOR2I& pos, const wxString& text, KICAD_T aType ) :
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_LABEL_BASE( pos, text, aType )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = LAYER_HIERLABEL;
|
2021-10-12 20:05:37 +00:00
|
|
|
m_shape = LABEL_FLAG_SHAPE::L_INPUT;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = true;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
void SCH_HIERLABEL::SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_TEXT::SetLabelSpinStyle( aSpinStyle );
|
2021-12-28 22:13:54 +00:00
|
|
|
SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2008-02-20 19:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_HIERLABEL::CreateGraphicShape( const RENDER_SETTINGS* aSettings,
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I>& aPoints, const VECTOR2I& aPos ) const
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
CreateGraphicShape( aSettings, aPoints, aPos, m_shape );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_HIERLABEL::CreateGraphicShape( const RENDER_SETTINGS* aSettings,
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I>& aPoints, const VECTOR2I& aPos,
|
2021-10-12 20:05:37 +00:00
|
|
|
LABEL_FLAG_SHAPE aShape ) const
|
2021-03-06 09:27:41 +00:00
|
|
|
{
|
|
|
|
int* Template = TemplateShape[static_cast<int>( aShape )][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
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I corner;
|
2021-03-06 09:27:41 +00:00
|
|
|
corner.x = ( halfSize * (*Template) ) + aPos.x;
|
2010-11-03 14:13:15 +00:00
|
|
|
Template++;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
corner.y = ( halfSize * (*Template) ) + aPos.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
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
const EDA_RECT SCH_HIERLABEL::GetBodyBoundingBox() const
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth();
|
2020-11-17 16:02:47 +00:00
|
|
|
int margin = GetTextOffset();
|
2020-04-17 11:34:32 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int x = GetTextPos().x;
|
|
|
|
int y = GetTextPos().y;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2021-02-24 22:14:39 +00:00
|
|
|
int height = GetTextHeight() + penWidth + margin;
|
2021-12-31 14:07:24 +00:00
|
|
|
int length = GetTextBox().GetWidth();
|
|
|
|
|
|
|
|
length += height; // add height for triangular shapes
|
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
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
EDA_RECT box( VECTOR2I( x, y ), VECTOR2I( dx, dy ) );
|
2008-03-30 09:27:53 +00:00
|
|
|
box.Normalize();
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_HIERLABEL::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I 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-05-10 21:33:43 +00:00
|
|
|
case LABEL_SPIN_STYLE::LEFT: text_offset.x = -dist; break; // Orientation horiz normale
|
|
|
|
case LABEL_SPIN_STYLE::UP: text_offset.y = -dist; break; // Orientation vert UP
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: text_offset.x = dist; break; // Orientation horiz inverse
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: text_offset.y = dist; 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
|
|
|
{
|
2020-09-19 18:53:58 +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
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_HIERLABEL::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_hierarchical_label;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
2020-05-09 20:27:06 +00:00
|
|
|
|
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
HTML_MESSAGE_BOX* SCH_TEXT::ShowSyntaxHelp( wxWindow* aParentWindow )
|
2020-05-09 20:27:06 +00:00
|
|
|
{
|
2020-10-04 17:49:21 +00:00
|
|
|
wxString msg =
|
|
|
|
#include "sch_text_help_md.h"
|
|
|
|
;
|
2020-05-09 20:27:06 +00:00
|
|
|
|
2021-10-17 23:29:40 +00:00
|
|
|
HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
|
2020-11-13 16:14:44 +00:00
|
|
|
wxSize sz( 320, 320 );
|
|
|
|
|
|
|
|
dlg->SetMinSize( dlg->ConvertDialogToPixels( sz ) );
|
|
|
|
dlg->SetDialogSizeInDU( sz.x, sz.y );
|
2020-05-09 20:27:06 +00:00
|
|
|
|
2020-10-04 17:49:21 +00:00
|
|
|
wxString html_txt;
|
|
|
|
ConvertMarkdown2Html( wxGetTranslation( msg ), html_txt );
|
2021-09-14 18:26:03 +00:00
|
|
|
dlg->AddHTML_Text( html_txt );
|
2020-08-24 22:17:14 +00:00
|
|
|
dlg->ShowModeless();
|
2020-09-05 16:00:29 +00:00
|
|
|
|
|
|
|
return dlg;
|
2020-05-09 20:27:06 +00:00
|
|
|
}
|