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>
|
2017-11-18 13:10:32 +00:00
|
|
|
* Copyright (C) 1992-2017 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>
|
2018-01-28 21:02:31 +00:00
|
|
|
#include <draw_graphic_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>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2017-11-13 17:38:51 +00:00
|
|
|
#include <list_operations.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>
|
2018-04-17 16:25:19 +00:00
|
|
|
#include <trace_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-07-03 18:51:07 +00:00
|
|
|
|
2015-04-22 11:39:00 +00:00
|
|
|
extern void IncrementLabelMember( wxString& name, int aIncrement );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-03-25 08:26:11 +00:00
|
|
|
// Only for tests: set DRAW_BBOX to 1 to draw the bounding box of labels
|
|
|
|
#define DRAW_BBOX 0
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-04-16 07:49:17 +00:00
|
|
|
// Margin in internal units (mils) between labels and wires
|
|
|
|
#define TXT_MARGIN 4
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
// Names of sheet label types.
|
2009-04-05 20:49:15 +00:00
|
|
|
const char* SheetLabelType[] =
|
|
|
|
{
|
|
|
|
"Input",
|
|
|
|
"Output",
|
|
|
|
"BiDi",
|
|
|
|
"3State",
|
|
|
|
"UnSpc",
|
2013-04-07 11:55:18 +00:00
|
|
|
"???"
|
2009-04-05 20:49:15 +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
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_ITEM( NULL, aType ),
|
2016-02-28 17:33:29 +00:00
|
|
|
EDA_TEXT( text ),
|
|
|
|
m_shape( NET_INPUT )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
m_Layer = LAYER_NOTES;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( pos );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = false;
|
2017-01-23 20:30:11 +00:00
|
|
|
m_spin_style = 0;
|
|
|
|
|
|
|
|
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 ) :
|
|
|
|
SCH_ITEM( aText ),
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT( aText )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = aText.m_shape;
|
|
|
|
m_isDangling = false;
|
2017-01-27 21:06:18 +00:00
|
|
|
m_spin_style = aText.m_spin_style;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
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
|
|
|
{
|
2015-04-22 11:39:00 +00:00
|
|
|
IncrementLabelMember( m_Text, aIncrement );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
wxPoint SCH_TEXT::GetSchematicTextOffset() 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
|
|
|
|
int thick_offset = TXT_MARGIN + ( GetPenSize() + GetDefaultLineThickness() ) / 2;
|
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
|
|
|
{
|
|
|
|
default:
|
2018-09-16 10:42:28 +00:00
|
|
|
case 0: text_offset.y = -thick_offset; break; // Horiz Normal Orientation (left justified)
|
|
|
|
case 1: text_offset.x = -thick_offset; break; // Vert Orientation UP
|
|
|
|
case 2: text_offset.y = -thick_offset; break; // Horiz Orientation - Right justified
|
|
|
|
case 3: text_offset.x = -thick_offset; break; // Vert Orientation BOTTOM
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
bool SCH_TEXT::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint * aFindLocation )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText( MILLIMETRES ) );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( SCH_ITEM::Matches( m_Text, aSearchData ) )
|
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2011-10-12 14:03:43 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( aFindLocation )
|
|
|
|
*aFindLocation = BoundaryBox.Centre();
|
2011-10-12 14:03:43 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
return false;
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2010-07-11 16:24:44 +00:00
|
|
|
{
|
|
|
|
default:
|
2018-09-16 10:42:28 +00:00
|
|
|
case 0: SetLabelSpinStyle( 2 ); break; // horizontal text
|
|
|
|
case 1: break; // Vert Orientation UP
|
|
|
|
case 2: SetLabelSpinStyle( 0 ); break; // invert horizontal text
|
|
|
|
case 3: break; // Vert Orientation BOTTOM
|
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
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
|
|
|
default:
|
2018-09-16 10:42:28 +00:00
|
|
|
case 0: break; // horizontal text
|
|
|
|
case 1: SetLabelSpinStyle( 3 ); break; // Vert Orientation UP
|
|
|
|
case 2: break; // invert horizontal text
|
|
|
|
case 3: SetLabelSpinStyle( 1 ); break; // Vert Orientation BOTTOM
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
int dy;
|
|
|
|
|
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
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetLabelSpinStyle( (GetLabelSpinStyle() + 1) % 4 );
|
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
if( this->Type() == SCH_TEXT_T )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
switch( GetLabelSpinStyle() )
|
|
|
|
{
|
|
|
|
case 0: dy = GetTextHeight(); break; // horizontal text
|
|
|
|
case 1: dy = 0; break; // Vert Orientation UP
|
|
|
|
case 2: dy = GetTextHeight(); break; // invert horizontal text
|
|
|
|
case 3: dy = 0; break; // Vert Orientation BOTTOM
|
|
|
|
default: dy = 0; break;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void SCH_TEXT::SetLabelSpinStyle( int 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
|
|
|
|
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:
|
2017-01-23 20:30:11 +00:00
|
|
|
case 0: // Horiz Normal Orientation (left justified)
|
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 1: // Vert Orientation UP
|
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 2: // Horiz Orientation - Right justified
|
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 3: // Vert Orientation BOTTOM
|
|
|
|
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_Text, item->m_Text );
|
|
|
|
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 );
|
|
|
|
|
|
|
|
SwapEffects( *item );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
int SCH_TEXT::GetPenSize() const
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int pensize = GetThickness();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
if( pensize == 0 ) // Use default values for pen size
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsBold() )
|
|
|
|
pensize = GetPenSizeForBold( GetTextWidth() );
|
2010-11-03 14:13:15 +00:00
|
|
|
else
|
2012-09-28 17:47:41 +00:00
|
|
|
pensize = GetDefaultLineThickness();
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
// Clip pen size for small texts:
|
2017-01-23 20:30:11 +00:00
|
|
|
pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
|
2010-11-03 14:13:15 +00:00
|
|
|
return pensize;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
|
2017-02-20 16:57:41 +00:00
|
|
|
GR_DRAWMODE DrawMode, COLOR4D Color )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color;
|
2017-01-23 20:30:11 +00:00
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
|
|
|
EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
if( Color != COLOR4D::UNSPECIFIED )
|
2012-09-02 12:06:47 +00:00
|
|
|
color = Color;
|
2010-11-03 14:13:15 +00:00
|
|
|
else
|
2016-11-16 10:07:02 +00:00
|
|
|
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
wxPoint text_offset = aOffset + GetSchematicTextOffset();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
int savedWidth = GetThickness();
|
|
|
|
SetThickness( linewidth ); // Set the minimum width
|
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
EDA_TEXT::Draw( clipbox, DC, text_offset, color, DrawMode, FILLED, COLOR4D::UNSPECIFIED );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
SetThickness( savedWidth );
|
2011-10-12 14:03:43 +00:00
|
|
|
|
2015-04-02 11:18:19 +00:00
|
|
|
if( m_isDangling && panel)
|
2017-01-23 20:30:11 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, GetTextPos() + aOffset, color );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
// Enable these line to draw the bounding box (debug tests purposes only)
|
2016-03-23 07:41:47 +00:00
|
|
|
#if DRAW_BBOX
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2013-06-29 09:52:22 +00:00
|
|
|
GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-29 18:11:04 +00:00
|
|
|
bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList )
|
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;
|
|
|
|
m_isDangling = true;
|
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() )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = false;
|
2011-12-06 21:02:21 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case WIRE_START_END:
|
|
|
|
case BUS_START_END:
|
|
|
|
{
|
|
|
|
// 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!" ) );
|
|
|
|
|
|
|
|
DANGLING_END_ITEM & nextItem = aItemList[ii];
|
2017-01-23 20:30:11 +00:00
|
|
|
m_isDangling = !IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetTextPos() );
|
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
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
return previousState != m_isDangling;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
bool SCH_TEXT::IsSelectStateChanged( const wxRect& aRect )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( aRect.Contains( GetTextPos() ) )
|
2013-03-30 19:55:26 +00:00
|
|
|
SetFlags( SELECTED );
|
2010-11-03 14:13:15 +00:00
|
|
|
else
|
2015-02-21 08:11:58 +00:00
|
|
|
ClearFlags( SELECTED );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
return previousState != IsSelected();
|
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
|
|
|
{
|
|
|
|
// We must pass the effective text thickness to GetTextBox
|
|
|
|
// when calculating the bounding box
|
2017-01-23 20:30:11 +00:00
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetTextBox( -1, linewidth );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS_T 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();
|
2013-09-29 18:24:38 +00:00
|
|
|
item->m_SheetPath = *aSheetPath;
|
|
|
|
item->m_SheetPathInclude = *aSheetPath;
|
2011-10-12 14:03:43 +00:00
|
|
|
item->m_Comp = (SCH_ITEM*) this;
|
|
|
|
item->m_Type = NET_LABEL;
|
|
|
|
|
|
|
|
if( GetLayer() == LAYER_GLOBLABEL )
|
|
|
|
item->m_Type = NET_GLOBLABEL;
|
|
|
|
else if( GetLayer() == LAYER_HIERLABEL )
|
|
|
|
item->m_Type = NET_HIERLABEL;
|
|
|
|
|
|
|
|
item->m_Label = m_Text;
|
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
|
2011-10-12 14:03:43 +00:00
|
|
|
if( IsBusLabel( m_Text ) )
|
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
|
|
|
{
|
|
|
|
static std::vector <wxPoint> Poly;
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color = GetLayerColor( GetLayer() );
|
|
|
|
int thickness = GetPenSize();
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( thickness );
|
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
|
|
|
|
2018-09-16 10:42:28 +00:00
|
|
|
GetPositionsOfLinesOfMultilineText(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
|
|
|
{
|
2016-04-16 07:49:17 +00:00
|
|
|
wxPoint textpos = positions[ii] + GetSchematicTextOffset();
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString& txt = strings_list.Item( ii );
|
2017-01-23 20:30:11 +00:00
|
|
|
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(),
|
|
|
|
GetHorizJustify(), GetVertJustify(),
|
|
|
|
thickness, IsItalic(), IsBold() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint textpos = GetTextPos() + GetSchematicTextOffset();
|
|
|
|
|
|
|
|
aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
|
|
|
|
GetHorizJustify(), GetVertJustify(),
|
|
|
|
thickness, 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
|
|
|
|
CreateGraphicShape( Poly, GetTextPos() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( GetPenSize() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
if( Poly.size() )
|
|
|
|
aPlotter->PlotPoly( Poly, NO_FILL );
|
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2012-11-20 11:35:09 +00:00
|
|
|
/*
|
|
|
|
* Display the type, shape, size and some other props to the Message panel
|
|
|
|
*/
|
2018-04-10 10:52:12 +00:00
|
|
|
void SCH_TEXT::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
|
2012-11-20 11:35:09 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( Type() )
|
|
|
|
{
|
2018-09-16 10:42:28 +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_HIERARCHICAL_LABEL_T: msg = _( "Hierarchical Label" ); break;
|
|
|
|
case SCH_SHEET_PIN_T: msg = _( "Hierarchical Sheet Pin" ); break;
|
|
|
|
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
|
|
|
{
|
2018-09-16 10:42:28 +00:00
|
|
|
case 0: msg = _( "Horizontal" ); break;
|
|
|
|
case 1: msg = _( "Vertical up" ); break;
|
|
|
|
case 2: msg = _( "Horizontal invert" ); break;
|
|
|
|
case 3: 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
|
|
|
|
|
|
|
|
|
|
|
// Display electricat type if it is relevant
|
|
|
|
if( (Type() == SCH_GLOBAL_LABEL_T) ||
|
|
|
|
(Type() == SCH_HIERARCHICAL_LABEL_T ) ||
|
|
|
|
(Type() == SCH_SHEET_PIN_T ) )
|
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
2013-01-12 17:32:24 +00:00
|
|
|
case NET_INPUT: msg = _( "Input" ); break;
|
|
|
|
case NET_OUTPUT: msg = _( "Output" ); break;
|
|
|
|
case NET_BIDI: msg = _( "Bidirectional" ); break;
|
|
|
|
case NET_TRISTATE: msg = _( "Tri-State" ); break;
|
|
|
|
case NET_UNSPECIFIED: msg = _( "Passive" ); 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( _( "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)
|
2018-04-10 10:52:12 +00:00
|
|
|
msg = MessageTextFromValue( aUnits, GetTextWidth(), true );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Size" ), msg, RED ) );
|
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 << '"'
|
2011-12-08 15:45:01 +00:00
|
|
|
<< " shape=\"" << m_shape << '"'
|
|
|
|
<< " dangling=\"" << m_isDangling << '"'
|
2009-05-05 17:32:07 +00:00
|
|
|
<< '>'
|
2011-02-28 18:36:19 +00:00
|
|
|
<< TO_UTF8( m_Text )
|
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
|
|
|
|
2010-12-21 15:13:09 +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
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
m_Layer = LAYER_LOCLABEL;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_INPUT;
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_LABEL::GetBoundingBox() const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
|
|
|
EDA_RECT rect = GetTextBox( -1, linewidth );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS_T 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text ) :
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_TEXT( pos, text, SCH_GLOBAL_LABEL_T )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
m_Layer = LAYER_GLOBLABEL;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_BIDI;
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
wxPoint SCH_GLOBALLABEL::GetSchematicTextOffset() const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset;
|
2017-01-23 20:30:11 +00:00
|
|
|
int width = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
width = Clamp_Text_PenSize( width, GetTextSize(), IsBold() );
|
|
|
|
int halfSize = GetTextWidth() / 2;
|
2010-11-03 14:13:15 +00:00
|
|
|
int offset = width;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_shape )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
case NET_INPUT:
|
|
|
|
case NET_BIDI:
|
|
|
|
case NET_TRISTATE:
|
2016-03-23 07:41:47 +00:00
|
|
|
offset += halfSize;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_OUTPUT:
|
|
|
|
case NET_UNSPECIFIED:
|
2016-04-16 07:49:17 +00:00
|
|
|
offset += TXT_MARGIN;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
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:
|
|
|
|
case 0: text_offset.x -= offset; break; // Orientation horiz normal
|
|
|
|
case 1: text_offset.y -= offset; break; // Orientation vert UP
|
|
|
|
case 2: text_offset.x += offset; break; // Orientation horiz inverse
|
|
|
|
case 3: text_offset.y += offset; break; // Orientation vert BOTTOM
|
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
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void SCH_GLOBALLABEL::SetLabelSpinStyle( int 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:
|
2017-01-23 20:30:11 +00:00
|
|
|
case 0: // Horiz Normal Orientation
|
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 1: // Vert Orientation UP
|
|
|
|
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
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 2: // Horiz Orientation
|
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 3: // Vert Orientation BOTTOM
|
|
|
|
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
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_GLOBALLABEL::Draw( EDA_DRAW_PANEL* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
const wxPoint& aOffset,
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE DrawMode,
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D Color )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color;
|
2012-03-26 23:47:08 +00:00
|
|
|
wxPoint text_offset = aOffset + GetSchematicTextOffset();
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
if( Color != COLOR4D::UNSPECIFIED )
|
2012-09-02 12:06:47 +00:00
|
|
|
color = Color;
|
2008-02-20 19:37:17 +00:00
|
|
|
else
|
2016-11-16 10:07:02 +00:00
|
|
|
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
|
|
|
|
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
|
|
|
|
|
|
|
|
int save_width = GetThickness();
|
|
|
|
SetThickness( linewidth );
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
|
2017-02-20 17:48:27 +00:00
|
|
|
EDA_TEXT::Draw( clipbox, DC, text_offset, color, DrawMode, FILLED, COLOR4D::UNSPECIFIED );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetThickness( save_width ); // restore initial value
|
|
|
|
|
|
|
|
CreateGraphicShape( Poly, GetTextPos() + aOffset );
|
2013-06-29 09:52:22 +00:00
|
|
|
GRPoly( clipbox, DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2015-04-02 11:18:19 +00:00
|
|
|
if( m_isDangling && panel )
|
2017-01-23 20:30:11 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, GetTextPos() + aOffset, color );
|
2009-11-28 09:24:37 +00:00
|
|
|
|
|
|
|
// Enable these line to draw the bounding box (debug tests purposes only)
|
2016-03-23 07:41:47 +00:00
|
|
|
#if DRAW_BBOX
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2013-06-29 09:52:22 +00:00
|
|
|
GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
|
2009-11-28 09:24:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2008-02-20 19:37:17 +00:00
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int halfSize = GetTextHeight() / 2;
|
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints.clear();
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2018-09-02 21:51:35 +00:00
|
|
|
int symb_len = LenSize( GetShownText(), linewidth ) + ( TXT_MARGIN * 2 );
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
// Create outline shape : 6 points
|
|
|
|
int x = symb_len + linewidth + 3;
|
|
|
|
|
2012-09-07 19:29:44 +00:00
|
|
|
// Use negation bar Y position to calculate full vertical size
|
2016-03-23 07:41:47 +00:00
|
|
|
// Search for overbar symbol
|
|
|
|
bool hasOverBar = false;
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < m_Text.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( m_Text[ii-1] == '~' && m_Text[ii] != '~' )
|
|
|
|
{
|
|
|
|
hasOverBar = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define Y_CORRECTION 1.40
|
|
|
|
// Note: this factor is due to the fact the Y size of a few letters like [
|
|
|
|
// are bigger than the y size value, and we need a margin for the graphic symbol.
|
|
|
|
int y = KiROUND( halfSize * Y_CORRECTION );
|
|
|
|
|
|
|
|
// Note: this factor is due to the fact we need a margin for the graphic symbol.
|
|
|
|
#define Y_OVERBAR_CORRECTION 1.2
|
|
|
|
if( hasOverBar )
|
2016-03-23 12:16:27 +00:00
|
|
|
y = KiROUND( KIGFX::STROKE_FONT::GetInterline( halfSize, linewidth )
|
|
|
|
* Y_OVERBAR_CORRECTION );
|
2016-03-23 07:41:47 +00:00
|
|
|
|
|
|
|
// Gives room for line thickess and margin
|
|
|
|
y += linewidth // for line thickess
|
|
|
|
+ linewidth/2; // for margin
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
// Starting point(anchor)
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints.push_back( wxPoint( 0, 0 ) );
|
|
|
|
aPoints.push_back( wxPoint( 0, -y ) ); // Up
|
|
|
|
aPoints.push_back( wxPoint( -x, -y ) ); // left
|
|
|
|
aPoints.push_back( wxPoint( -x, 0 ) ); // Up left
|
|
|
|
aPoints.push_back( wxPoint( -x, y ) ); // left down
|
|
|
|
aPoints.push_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
|
|
|
{
|
|
|
|
case NET_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;
|
|
|
|
|
|
|
|
case NET_OUTPUT:
|
2016-03-23 07:41:47 +00:00
|
|
|
aPoints[3].x -= halfSize;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_BIDI:
|
|
|
|
case NET_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;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case NET_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:
|
|
|
|
case 0: break; // Orientation horiz normal
|
|
|
|
case 1: angle = -900; break; // Orientation vert UP
|
|
|
|
case 2: angle = 1800; break; // Orientation horiz inverse
|
|
|
|
case 3: angle = 900; break; // Orientation vert BOTTOM
|
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
|
|
|
{
|
2008-03-30 10:47:03 +00:00
|
|
|
int x, y, dx, dy, length, height;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
x = GetTextPos().x;
|
|
|
|
y = GetTextPos().y;
|
2008-03-30 11:48:18 +00:00
|
|
|
dx = dy = 0;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
int width = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
|
|
|
|
|
|
|
height = ( (GetTextHeight() * 15) / 10 ) + width + 2 * TXT_MARGIN;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
// text X size add height for triangular shapes(bidirectional)
|
2018-09-02 21:51:35 +00:00
|
|
|
length = LenSize( GetShownText(), width ) + height + DANGLING_SYMBOL_SIZE;
|
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:
|
2017-01-23 20:30:11 +00:00
|
|
|
case 0: // Horiz Normal Orientation (left justified)
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = -length;
|
|
|
|
dy = height;
|
|
|
|
x += DANGLING_SYMBOL_SIZE;
|
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 1: // Vert Orientation 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;
|
2009-05-12 12:12:34 +00:00
|
|
|
y += DANGLING_SYMBOL_SIZE;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 2: // Horiz Orientation - Right justified
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = length;
|
|
|
|
dy = height;
|
|
|
|
x -= DANGLING_SYMBOL_SIZE;
|
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 3: // Vert Orientation BOTTOM
|
2010-11-03 14:13:15 +00:00
|
|
|
dx = height;
|
|
|
|
dy = length;
|
|
|
|
x -= height / 2;
|
|
|
|
y -= DANGLING_SYMBOL_SIZE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_GLOBALLABEL::GetSelectMenuText( EDA_UNITS_T 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
|
|
|
|
SCH_TEXT( pos, text, aType )
|
|
|
|
{
|
|
|
|
m_Layer = LAYER_HIERLABEL;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_INPUT;
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void SCH_HIERLABEL::SetLabelSpinStyle( int 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:
|
2017-01-23 20:30:11 +00:00
|
|
|
case 0: // Horiz Normal Orientation
|
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 1: // Vert Orientation UP
|
|
|
|
SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 2: // Horiz Orientation
|
|
|
|
SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 3: // Vert Orientation BOTTOM
|
|
|
|
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
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_HIERLABEL::Draw( EDA_DRAW_PANEL* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
const wxPoint& offset,
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE DrawMode,
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D Color )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color;
|
2017-01-23 20:30:11 +00:00
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
|
|
|
EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
if( Color != COLOR4D::UNSPECIFIED )
|
2012-09-02 12:06:47 +00:00
|
|
|
color = Color;
|
2008-02-20 19:37:17 +00:00
|
|
|
else
|
2016-11-16 10:07:02 +00:00
|
|
|
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
int save_width = GetThickness();
|
|
|
|
SetThickness( linewidth );
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset = offset + GetSchematicTextOffset();
|
2017-02-20 17:48:27 +00:00
|
|
|
EDA_TEXT::Draw( clipbox, DC, text_offset, color, DrawMode, FILLED, COLOR4D::UNSPECIFIED );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetThickness( save_width ); // restore initial value
|
|
|
|
|
|
|
|
CreateGraphicShape( Poly, GetTextPos() + offset );
|
2013-06-29 09:52:22 +00:00
|
|
|
GRPoly( clipbox, DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2015-04-02 11:18:19 +00:00
|
|
|
if( m_isDangling && panel )
|
2017-01-23 20:30:11 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, GetTextPos() + offset, color );
|
2009-11-28 09:24:37 +00:00
|
|
|
|
|
|
|
// Enable these line to draw the bounding box (debug tests purposes only)
|
2016-03-23 07:41:47 +00:00
|
|
|
#if DRAW_BBOX
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2013-06-29 09:52:22 +00:00
|
|
|
GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
|
2009-11-28 09:24:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 19:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void SCH_HIERLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
|
2008-02-20 19:37:17 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int* Template = TemplateShape[m_shape][m_spin_style];
|
|
|
|
int halfSize = GetTextWidth() / 2;
|
2010-11-03 14:13:15 +00:00
|
|
|
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
|
|
|
{
|
2008-03-30 10:47:03 +00:00
|
|
|
int x, y, dx, dy, length, height;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
x = GetTextPos().x;
|
|
|
|
y = GetTextPos().y;
|
2008-03-30 11:48:18 +00:00
|
|
|
dx = dy = 0;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
int width = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
|
|
|
|
|
|
|
height = GetTextHeight() + width + 2 * TXT_MARGIN;
|
2018-09-02 21:51:35 +00:00
|
|
|
length = LenSize( GetShownText(), width )
|
2010-11-03 14:13:15 +00:00
|
|
|
+ height // add height for triangular shapes
|
|
|
|
+ 2 * DANGLING_SYMBOL_SIZE;
|
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:
|
2017-01-23 20:30:11 +00:00
|
|
|
case 0: // Horiz Normal Orientation (left justified)
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = -length;
|
|
|
|
dy = height;
|
|
|
|
x += DANGLING_SYMBOL_SIZE;
|
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 1: // Vert Orientation 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;
|
2009-05-12 12:12:34 +00:00
|
|
|
y += DANGLING_SYMBOL_SIZE;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 2: // Horiz Orientation - Right justified
|
2009-05-05 17:32:07 +00:00
|
|
|
dx = length;
|
|
|
|
dy = height;
|
|
|
|
x -= DANGLING_SYMBOL_SIZE;
|
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
case 3: // Vert Orientation 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;
|
2009-05-12 12:12:34 +00:00
|
|
|
y -= 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
wxPoint SCH_HIERLABEL::GetSchematicTextOffset() const
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset;
|
2017-01-23 20:30:11 +00:00
|
|
|
int width = std::max( GetThickness(), GetDefaultLineThickness() );
|
|
|
|
int ii = GetTextWidth() + TXT_MARGIN + width;
|
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:
|
|
|
|
case 0: text_offset.x = -ii; break; // Orientation horiz normale
|
|
|
|
case 1: text_offset.y = -ii; break; // Orientation vert UP
|
|
|
|
case 2: text_offset.x = ii; break; // Orientation horiz inverse
|
|
|
|
case 3: text_offset.y = ii; 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
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_HIERLABEL::GetSelectMenuText( EDA_UNITS_T 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;
|
|
|
|
}
|