2011-10-12 14:03:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* @brief Code for handling schematic sheet labels.
|
|
|
|
*/
|
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>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
#include <plot_common.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <class_netlist_object.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-07-03 18:51:07 +00:00
|
|
|
|
2011-10-12 14:03:43 +00:00
|
|
|
extern void IncrementLabelMember( wxString& name );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Names of sheet label types. */
|
2009-04-05 20:49:15 +00:00
|
|
|
const char* SheetLabelType[] =
|
|
|
|
{
|
|
|
|
"Input",
|
|
|
|
"Output",
|
|
|
|
"BiDi",
|
|
|
|
"3State",
|
|
|
|
"UnSpc",
|
|
|
|
"?????"
|
|
|
|
};
|
|
|
|
|
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 ),
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT( text )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
m_Layer = LAYER_NOTES;
|
2010-12-21 15:13:09 +00:00
|
|
|
m_Pos = pos;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = 0;
|
|
|
|
m_isDangling = false;
|
2010-12-21 15:13:09 +00:00
|
|
|
m_MultilineAllowed = true;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_schematicOrientation = 0;
|
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
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
m_Pos = aText.m_Pos;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = aText.m_shape;
|
2010-12-21 15:13:09 +00:00
|
|
|
m_MultilineAllowed = aText.m_MultilineAllowed;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_schematicOrientation = aText.m_schematicOrientation;
|
|
|
|
m_isDangling = false;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
2008-01-21 16:21:41 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
EDA_ITEM* SCH_TEXT::doClone() const
|
|
|
|
{
|
|
|
|
return new SCH_TEXT( *this );
|
|
|
|
}
|
2007-09-01 12:00:30 +00:00
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
void SCH_TEXT::IncrementLabel()
|
|
|
|
{
|
|
|
|
IncrementLabelMember( m_Text );
|
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;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
// add a small offset (TXTMARGE) to x ( or y) position to allow a text to
|
|
|
|
// be on a wire or a line and be readable
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: /* Horiz Normal Orientation (left justified) */
|
|
|
|
text_offset.y = -TXTMARGE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
text_offset.x = -TXTMARGE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Horiz Orientation - Right justified */
|
|
|
|
text_offset.y = -TXTMARGE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
text_offset.x = -TXTMARGE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2011-12-13 15:37:33 +00:00
|
|
|
wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText() );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
void SCH_TEXT::Mirror_Y( int aYaxis_position )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
// Text is NOT really mirrored; it is moved to a suitable position
|
|
|
|
// which is the closest position for a true mirrored text
|
2009-11-03 13:26:31 +00:00
|
|
|
// The center position is mirrored and the text is moved for half
|
|
|
|
// horizontal len
|
2009-07-27 14:32:40 +00:00
|
|
|
int px = m_Pos.x;
|
|
|
|
int dx;
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( GetOrientation() )
|
2010-07-11 16:24:44 +00:00
|
|
|
{
|
|
|
|
case 0: /* horizontal text */
|
2009-07-27 14:32:40 +00:00
|
|
|
dx = LenSize( m_Text ) / 2;
|
2010-07-11 16:24:44 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
dx = -m_Size.x / 2;
|
|
|
|
break;
|
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
case 2: /* invert horizontal text*/
|
2009-07-27 14:32:40 +00:00
|
|
|
dx = -LenSize( m_Text ) / 2;
|
2010-07-11 16:24:44 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
dx = m_Size.x / 2;
|
|
|
|
break;
|
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
default:
|
2009-07-27 14:32:40 +00:00
|
|
|
dx = 0;
|
2010-07-11 16:24:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:32:40 +00:00
|
|
|
px += dx;
|
|
|
|
px -= aYaxis_position;
|
2009-11-03 13:26:31 +00:00
|
|
|
NEGATE( px );
|
2009-07-27 14:32:40 +00:00
|
|
|
px += aYaxis_position;
|
|
|
|
px -= dx;
|
|
|
|
m_Pos.x = px;
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_TEXT::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
// Text is NOT really mirrored; it is moved to a suitable position
|
|
|
|
// which is the closest position for a true mirrored text
|
|
|
|
// The center position is mirrored and the text is moved for half
|
|
|
|
// horizontal len
|
|
|
|
int py = m_Pos.y;
|
|
|
|
int dy;
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( GetOrientation() )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
|
|
|
case 0: /* horizontal text */
|
|
|
|
dy = -m_Size.y / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
dy = -LenSize( m_Text ) / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* invert horizontal text*/
|
|
|
|
dy = m_Size.y / 2; // how to calculate text height?
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
dy = LenSize( m_Text ) / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
py += dy;
|
|
|
|
py -= aXaxis_position;
|
|
|
|
NEGATE( py );
|
|
|
|
py += aXaxis_position;
|
|
|
|
py -= dy;
|
|
|
|
m_Pos.y = py;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_TEXT::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
int dy;
|
|
|
|
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( (GetOrientation() + 1) % 4 );
|
|
|
|
|
|
|
|
switch( GetOrientation() )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
|
|
|
case 0: /* horizontal text */
|
|
|
|
dy = m_Size.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* invert horizontal text*/
|
|
|
|
dy = m_Size.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Pos.y += dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
void SCH_TEXT::SetOrientation( int aOrientation )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_schematicOrientation = aOrientation;
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2009-05-12 12:12:34 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
default:
|
|
|
|
case 0: /* Horiz Normal Orientation (left justified) */
|
|
|
|
m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 2: /* Horiz Orientation - Right justified */
|
|
|
|
m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
2009-05-12 12:12:34 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
m_VJustify = 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;
|
|
|
|
|
|
|
|
EXCHG( m_Text, item->m_Text );
|
|
|
|
EXCHG( m_Pos, item->m_Pos );
|
|
|
|
EXCHG( m_Size, item->m_Size );
|
|
|
|
EXCHG( m_Thickness, item->m_Thickness );
|
2011-12-08 15:45:01 +00:00
|
|
|
EXCHG( m_shape, item->m_shape );
|
2011-10-19 20:32:21 +00:00
|
|
|
EXCHG( m_Orient, item->m_Orient );
|
|
|
|
|
|
|
|
EXCHG( m_Layer, item->m_Layer );
|
|
|
|
EXCHG( m_HJustify, item->m_HJustify );
|
|
|
|
EXCHG( m_VJustify, item->m_VJustify );
|
2011-12-08 15:45:01 +00:00
|
|
|
EXCHG( m_isDangling, item->m_isDangling );
|
|
|
|
EXCHG( m_schematicOrientation, item->m_schematicOrientation );
|
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
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
int pensize = m_Thickness;
|
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
|
|
|
|
{
|
|
|
|
if( m_Bold )
|
|
|
|
pensize = GetPenSizeForBold( m_Size.x );
|
|
|
|
else
|
|
|
|
pensize = g_DrawDefaultLineThickness;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
// Clip pen size for small texts:
|
|
|
|
pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
|
|
|
|
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,
|
2010-11-03 14:13:15 +00:00
|
|
|
int DrawMode, int Color )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
EDA_Colors color;
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
|
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = (EDA_Colors) Color;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( 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();
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( linewidth, m_Thickness ); // Set the minimum width
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT::Draw( panel, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR );
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( linewidth, m_Thickness ); // set initial value
|
2011-10-12 14:03:43 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_isDangling )
|
2010-11-03 14:13:15 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
|
|
|
|
|
|
|
|
// Enable these line to draw the bounding box (debug tests purposes only)
|
|
|
|
#if 0
|
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2011-12-29 20:11:42 +00:00
|
|
|
GRRect( panel->GetClipBox(), 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
|
|
|
bool SCH_TEXT::Save( FILE* aFile ) const
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
bool success = true;
|
|
|
|
const char* shape = "~";
|
|
|
|
|
|
|
|
if( m_Italic )
|
|
|
|
shape = "Italic";
|
|
|
|
|
2011-10-05 12:36:32 +00:00
|
|
|
// For compatibility reason, the text must be saved in only one text line
|
|
|
|
// so we replace all E.O.L. by \\n
|
2010-11-03 14:13:15 +00:00
|
|
|
wxString text = m_Text;
|
|
|
|
|
2011-10-05 12:36:32 +00:00
|
|
|
text.Replace( wxT("\n"), wxT( "\\n" ) );
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2011-10-05 12:36:32 +00:00
|
|
|
// Here we should have no CR or LF character in line
|
|
|
|
// This is not always the case if a multiline text was copied (using a copy/paste function)
|
|
|
|
// from a text that uses E.O.L characters that differs from the current EOL format
|
|
|
|
// This is mainly the case under Linux using LF symbol when copying a text from
|
|
|
|
// Windows (using CRLF symbol)
|
|
|
|
// So we must just remove the extra CR left (or LF left under MacOSX)
|
|
|
|
for( unsigned ii = 0; ii < text.Len(); )
|
|
|
|
{
|
|
|
|
if( text[ii] == 0x0A || text[ii] == 0x0D )
|
|
|
|
text.erase( ii, 1 );
|
|
|
|
else
|
|
|
|
ii++;
|
2010-07-11 16:24:44 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 12:36:32 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
if( fprintf( aFile, "Text Notes %-4d %-4d %-4d %-4d %s %d\n%s\n",
|
2011-12-08 15:45:01 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_schematicOrientation, m_Size.x,
|
2011-02-28 18:36:19 +00:00
|
|
|
shape, m_Thickness, TO_UTF8( text ) ) == EOF )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_TEXT::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
char Name3[256];
|
|
|
|
int thickness = 0, size = 0, orient = 0;
|
|
|
|
|
|
|
|
Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;
|
|
|
|
|
|
|
|
char* sline = (char*) aLine;
|
|
|
|
|
|
|
|
while( ( *sline != ' ' ) && *sline )
|
|
|
|
sline++;
|
|
|
|
|
|
|
|
// sline points the start of parameters
|
|
|
|
int ii = sscanf( sline, "%s %d %d %d %d %s %s %d", Name1, &m_Pos.x, &m_Pos.y,
|
|
|
|
&orient, &size, Name2, Name3, &thickness );
|
|
|
|
|
|
|
|
if( ii < 4 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file text load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aLine.ReadLine() )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file text load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
|
|
|
|
char* text = strtok( (char*) aLine, "\n\r" );
|
|
|
|
|
|
|
|
if( text == NULL )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file text load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
wxString val = FROM_UTF8( text );
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2011-03-03 19:08:13 +00:00
|
|
|
for( ; ; )
|
2010-11-10 15:30:12 +00:00
|
|
|
{
|
|
|
|
int i = val.find( wxT( "\\n" ) );
|
|
|
|
|
|
|
|
if( i == wxNOT_FOUND )
|
|
|
|
break;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
val.erase( i, 2 );
|
|
|
|
val.insert( i, wxT( "\n" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Text = val;
|
|
|
|
m_Size.x = m_Size.y = size;
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( orient );
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
if( isdigit( Name3[0] ) )
|
|
|
|
{
|
|
|
|
thickness = atol( Name3 );
|
|
|
|
m_Bold = ( thickness != 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Name2, "Italic", 6 ) == 0 )
|
|
|
|
m_Italic = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-12-06 21:02:21 +00:00
|
|
|
DANGLING_END_ITEM item( LABEL_END, this, m_Pos );
|
2010-11-03 14:13:15 +00:00
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_TEXT::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList )
|
|
|
|
{
|
|
|
|
// 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:
|
2011-12-06 21:02:21 +00:00
|
|
|
if( m_Pos == 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];
|
2011-12-08 15:45:01 +00:00
|
|
|
m_isDangling = !SegmentIntersect( item.GetPosition(), nextItem.GetPosition(), m_Pos );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_isDangling == false )
|
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();
|
|
|
|
|
|
|
|
if( aRect.Contains( m_Pos ) )
|
|
|
|
m_Flags |= SELECTED;
|
|
|
|
else
|
|
|
|
m_Flags &= ~SELECTED;
|
|
|
|
|
|
|
|
return previousState != IsSelected();
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_TEXT::GetConnectionPoints( 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
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
aPoints.push_back( m_Pos );
|
2009-05-12 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
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
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
|
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
|
|
|
|
|
|
|
if( m_Orient ) // 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();
|
|
|
|
RotatePoint( &pos, m_Pos, m_Orient );
|
|
|
|
RotatePoint( &end, m_Pos, m_Orient );
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_TEXT::GetSelectMenuText() const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString tmp = GetText();
|
|
|
|
tmp.Replace( wxT( "\n" ), wxT( " " ) );
|
|
|
|
tmp.Replace( wxT( "\r" ), wxT( " " ) );
|
|
|
|
tmp.Replace( wxT( "\t" ), wxT( " " ) );
|
|
|
|
tmp =( tmp.Length() > 15 ) ? tmp.Left( 12 ) + wxT( "..." ) : tmp;
|
|
|
|
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString msg;
|
2011-04-27 19:44:32 +00:00
|
|
|
msg.Printf( _( "Graphic Text %s" ), GetChars( tmp ) );
|
2011-03-26 10:08:50 +00:00
|
|
|
return msg;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-10-12 14:03:43 +00:00
|
|
|
void SCH_TEXT::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
|
|
|
if( GetLayer() == LAYER_NOTES || GetLayer() == LAYER_SHEETLABEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT();
|
|
|
|
item->m_SheetList = *aSheetPath;
|
|
|
|
item->m_SheetListInclude = *aSheetPath;
|
|
|
|
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;
|
|
|
|
item->m_Start = item->m_End = m_Pos;
|
|
|
|
|
|
|
|
aNetListItems.push_back( item );
|
|
|
|
|
|
|
|
/* If a bus connects to label */
|
|
|
|
if( IsBusLabel( m_Text ) )
|
2011-10-12 15:34:52 +00:00
|
|
|
item->ConvertBusToNetListItems( aNetListItems );
|
2011-10-12 14:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_TEXT::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
return TextHitTest( aPoint, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
bool SCH_TEXT::doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
|
|
|
return TextHitTest( aRect, aContained, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void SCH_TEXT::doPlot( PLOTTER* aPlotter )
|
|
|
|
{
|
|
|
|
static std::vector <wxPoint> Poly;
|
|
|
|
|
|
|
|
EDA_Colors color = ReturnLayerColor( GetLayer() );
|
|
|
|
wxPoint textpos = m_Pos + GetSchematicTextOffset();
|
|
|
|
int thickness = GetPenSize();
|
|
|
|
|
|
|
|
aPlotter->set_current_line_width( thickness );
|
|
|
|
|
|
|
|
if( m_MultilineAllowed )
|
|
|
|
{
|
|
|
|
wxPoint pos = textpos;
|
|
|
|
wxArrayString* list = wxStringSplit( m_Text, '\n' );
|
|
|
|
wxPoint offset;
|
|
|
|
|
|
|
|
offset.y = GetInterline();
|
|
|
|
|
|
|
|
RotatePoint( &offset, m_Orient );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i<list->Count(); i++ )
|
|
|
|
{
|
|
|
|
wxString txt = list->Item( i );
|
|
|
|
aPlotter->text( pos, color, txt, m_Orient, m_Size, m_HJustify,
|
|
|
|
m_VJustify, thickness, m_Italic, m_Bold );
|
|
|
|
pos += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete (list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aPlotter->text( textpos, color, m_Text, m_Orient, m_Size, m_HJustify,
|
|
|
|
m_VJustify, thickness, m_Italic, m_Bold );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw graphic symbol for global or hierarchical labels */
|
|
|
|
CreateGraphicShape( Poly, m_Pos );
|
|
|
|
|
|
|
|
aPlotter->set_current_line_width( GetPenSize() );
|
|
|
|
|
|
|
|
if( Poly.size() )
|
|
|
|
aPlotter->PlotPoly( Poly, NO_FILL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2010-12-21 15:13:09 +00:00
|
|
|
m_MultilineAllowed = false;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
EDA_ITEM* SCH_LABEL::doClone() const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
return new SCH_LABEL( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
wxPoint SCH_LABEL::GetSchematicTextOffset() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return SCH_TEXT::GetSchematicTextOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
void SCH_LABEL::SetOrientation( int aOrientation )
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2011-03-03 01:58:12 +00:00
|
|
|
SCH_TEXT::SetOrientation( aOrientation );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_LABEL::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
// Text is NOT really mirrored; it is moved to a suitable position
|
|
|
|
// which is the closest position for a true mirrored text
|
|
|
|
// The center position is mirrored and the text is moved for half
|
|
|
|
// horizontal len
|
|
|
|
int py = m_Pos.y;
|
|
|
|
|
|
|
|
py -= aXaxis_position;
|
|
|
|
NEGATE( py );
|
|
|
|
py += aXaxis_position;
|
|
|
|
m_Pos.y = py;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LABEL::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( (GetOrientation() + 1) % 4 );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
bool SCH_LABEL::Save( FILE* aFile ) const
|
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
bool success = true;
|
|
|
|
const char* shape = "~";
|
|
|
|
|
|
|
|
if( m_Italic )
|
2008-12-19 20:40:08 +00:00
|
|
|
shape = "Italic";
|
|
|
|
|
|
|
|
if( fprintf( aFile, "Text Label %-4d %-4d %-4d %-4d %s %d\n%s\n",
|
2011-12-08 15:45:01 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_schematicOrientation, m_Size.x, shape,
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Thickness, TO_UTF8( m_Text ) ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_LABEL::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
char Name3[256];
|
|
|
|
int thickness = 0, size = 0, orient = 0;
|
|
|
|
|
|
|
|
Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;
|
|
|
|
|
|
|
|
char* sline = (char*) aLine;
|
|
|
|
|
|
|
|
while( ( *sline != ' ' ) && *sline )
|
|
|
|
sline++;
|
|
|
|
|
|
|
|
// sline points the start of parameters
|
|
|
|
int ii = sscanf( sline, "%s %d %d %d %d %s %s %d", Name1, &m_Pos.x, &m_Pos.y,
|
|
|
|
&orient, &size, Name2, Name3, &thickness );
|
|
|
|
|
|
|
|
if( ii < 4 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aLine.ReadLine() )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file label load error atline %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
|
|
|
|
char* text = strtok( (char*) aLine, "\n\r" );
|
|
|
|
|
|
|
|
if( text == NULL )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Text = FROM_UTF8( text );
|
2010-11-10 15:30:12 +00:00
|
|
|
m_Size.x = m_Size.y = size;
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( orient );
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
if( isdigit( Name3[0] ) )
|
|
|
|
{
|
|
|
|
thickness = atol( Name3 );
|
|
|
|
m_Bold = ( thickness != 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( stricmp( Name2, "Italic" ) == 0 )
|
|
|
|
m_Italic = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_LABEL::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
|
2010-11-03 14:13:15 +00:00
|
|
|
int DrawMode, int Color )
|
|
|
|
{
|
|
|
|
SCH_TEXT::Draw( panel, DC, offset, DrawMode, Color );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT SCH_LABEL::GetBoundingBox() const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
int x, y, dx, dy, length, height;
|
|
|
|
|
|
|
|
x = m_Pos.x;
|
|
|
|
y = m_Pos.y;
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = (m_Thickness == 0) ? g_DrawDefaultLineThickness : m_Thickness;
|
2010-11-03 14:13:15 +00:00
|
|
|
length = LenSize( m_Text );
|
|
|
|
height = m_Size.y + width;
|
|
|
|
dx = dy = 0;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case 0: /* Horiz Normal Orientation (left justified) */
|
|
|
|
dx = 2 * DANGLING_SYMBOL_SIZE + length;
|
|
|
|
dy = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE;
|
|
|
|
x -= DANGLING_SYMBOL_SIZE;
|
|
|
|
y += DANGLING_SYMBOL_SIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
dx = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE;
|
|
|
|
dy = -2 * DANGLING_SYMBOL_SIZE - length;
|
|
|
|
x += DANGLING_SYMBOL_SIZE;
|
|
|
|
y += DANGLING_SYMBOL_SIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Horiz Orientation - Right justified */
|
|
|
|
dx = -2 * DANGLING_SYMBOL_SIZE - length;
|
|
|
|
dy = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE;
|
|
|
|
x += DANGLING_SYMBOL_SIZE;
|
|
|
|
y += DANGLING_SYMBOL_SIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
dx = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE;
|
|
|
|
dy = 2 * DANGLING_SYMBOL_SIZE + length;
|
|
|
|
x += DANGLING_SYMBOL_SIZE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_LABEL::GetSelectMenuText() const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString tmp = ( GetText().Length() > 15 ) ? GetText().Left( 12 ) + wxT( "..." ) : GetText();
|
|
|
|
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Label %s" ), GetChars(tmp) );
|
|
|
|
return msg;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
bool SCH_LABEL::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
2010-12-13 15:59:00 +00:00
|
|
|
return TextHitTest( aPoint, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2009-05-12 12:12:34 +00:00
|
|
|
m_MultilineAllowed = false;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
EDA_ITEM* SCH_GLOBALLABEL::doClone() const
|
|
|
|
{
|
|
|
|
return new SCH_GLOBALLABEL( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
bool SCH_GLOBALLABEL::Save( FILE* aFile ) const
|
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
bool success = true;
|
|
|
|
const char* shape = "~";
|
|
|
|
|
|
|
|
if( m_Italic )
|
2008-12-19 20:40:08 +00:00
|
|
|
shape = "Italic";
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
if( fprintf( aFile, "Text GLabel %-4d %-4d %-4d %-4d %s %s %d\n%s\n",
|
2011-12-08 15:45:01 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_schematicOrientation, m_Size.x,
|
|
|
|
SheetLabelType[m_shape], shape, m_Thickness, TO_UTF8( m_Text ) ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_GLOBALLABEL::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
char Name3[256];
|
|
|
|
int thickness = 0, size = 0, orient = 0;
|
|
|
|
|
|
|
|
Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;
|
|
|
|
|
|
|
|
char* sline = (char*) aLine;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
while( (*sline != ' ' ) && *sline )
|
|
|
|
sline++;
|
|
|
|
|
|
|
|
// sline points the start of parameters
|
|
|
|
int ii = sscanf( sline, "%s %d %d %d %d %s %s %d", Name1, &m_Pos.x, &m_Pos.y,
|
|
|
|
&orient, &size, Name2, Name3, &thickness );
|
|
|
|
|
|
|
|
if( ii < 4 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file global label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aLine.ReadLine() )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file global label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
|
|
|
|
char* text = strtok( (char*) aLine, "\n\r" );
|
|
|
|
|
|
|
|
if( text == NULL )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file global label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Text = FROM_UTF8( text );
|
2010-11-10 15:30:12 +00:00
|
|
|
m_Size.x = m_Size.y = size;
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( orient );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_INPUT;
|
2010-11-10 15:30:12 +00:00
|
|
|
m_Bold = ( thickness != 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_OUTPUT] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_OUTPUT;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_BIDI] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_BIDI;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_TRISTATE] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_TRISTATE;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_UNSPECIFIED] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_UNSPECIFIED;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name3, "Italic" ) == 0 )
|
|
|
|
m_Italic = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_GLOBALLABEL::Mirror_Y( int aYaxis_position )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
/* The global label is NOT really mirrored.
|
|
|
|
* for an horizontal label, the schematic orientation is changed.
|
2010-11-11 17:54:24 +00:00
|
|
|
* for a vertical label, the schematic orientation is not changed.
|
2010-11-03 14:13:15 +00:00
|
|
|
* and the label is moved to a suitable position
|
|
|
|
*/
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( GetOrientation() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case 0: /* horizontal text */
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 2 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* invert horizontal text*/
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 0 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Pos.x );
|
|
|
|
m_Pos.x += aYaxis_position;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_GLOBALLABEL::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( GetOrientation() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case 1: /* vertical text */
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 3 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* invert vertical text*/
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 1 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Pos.y );
|
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_GLOBALLABEL::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( (GetOrientation() + 3) % 4 );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = (m_Thickness == 0) ? g_DrawDefaultLineThickness : m_Thickness;
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
width = Clamp_Text_PenSize( width, m_Size, m_Bold );
|
|
|
|
int HalfSize = m_Size.x / 2;
|
|
|
|
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:
|
|
|
|
offset += HalfSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_OUTPUT:
|
|
|
|
case NET_UNSPECIFIED:
|
|
|
|
offset += TXTMARGE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case 0: /* Orientation horiz normal */
|
|
|
|
text_offset.x -= offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Orientation vert UP */
|
|
|
|
text_offset.y -= offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Orientation horiz inverse */
|
|
|
|
text_offset.x += offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Orientation vert BOTTOM */
|
|
|
|
text_offset.y += offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text_offset;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
void SCH_GLOBALLABEL::SetOrientation( int aOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_schematicOrientation = aOrientation;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: /* Horiz Normal Orientation */
|
|
|
|
m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 2: /* Horiz Orientation */
|
|
|
|
m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
2009-05-05 17:32:07 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
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,
|
|
|
|
int DrawMode,
|
|
|
|
int Color )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2008-12-14 19:45:05 +00:00
|
|
|
EDA_Colors color;
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset = aOffset + GetSchematicTextOffset();
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2008-02-20 19:37:17 +00:00
|
|
|
if( Color >= 0 )
|
2009-05-05 17:32:07 +00:00
|
|
|
color = (EDA_Colors) Color;
|
2008-02-20 19:37:17 +00:00
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = (m_Thickness == 0) ? g_DrawDefaultLineThickness : m_Thickness;
|
2010-11-03 14:13:15 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( linewidth, m_Thickness ); // Set the minimum width
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT::Draw( panel, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR );
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( linewidth, m_Thickness ); // set initial value
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
CreateGraphicShape( Poly, m_Pos + aOffset );
|
2011-12-29 20:11:42 +00:00
|
|
|
GRPoly( panel->GetClipBox(), DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_isDangling )
|
2010-11-03 14:13:15 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
|
2009-11-28 09:24:37 +00:00
|
|
|
|
|
|
|
// Enable these line to draw the bounding box (debug tests purposes only)
|
|
|
|
#if 0
|
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2011-12-29 20:11:42 +00:00
|
|
|
GRRect( panel->GetClipBox(), 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
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
int HalfSize = m_Size.y / 2;
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = (m_Thickness == 0) ? g_DrawDefaultLineThickness : m_Thickness;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
|
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
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
int symb_len = LenSize( m_Text ) + ( TXTMARGE * 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;
|
|
|
|
|
|
|
|
// 50% more for negation bar
|
|
|
|
int y = wxRound( (double) HalfSize * 1.5 + (double) linewidth + 3.0 );
|
|
|
|
|
|
|
|
// 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:
|
2010-11-03 14:13:15 +00:00
|
|
|
x_offset = -HalfSize;
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints[0].x += HalfSize;
|
2010-09-11 16:33:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_OUTPUT:
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints[3].x -= HalfSize;
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_BIDI:
|
|
|
|
case NET_TRISTATE:
|
|
|
|
x_offset = -HalfSize;
|
2011-06-17 13:24:22 +00:00
|
|
|
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;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case 0: /* Orientation horiz normal */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Orientation vert UP */
|
|
|
|
angle = -900;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Orientation horiz inverse */
|
|
|
|
angle = 1800;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Orientation vert BOTTOM */
|
|
|
|
angle = 900;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rotate outlines and move corners in real position
|
2011-06-17 13:24:22 +00:00
|
|
|
for( unsigned ii = 0; ii < aPoints.size(); ii++ )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints[ii].x += x_offset;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
if( angle )
|
2011-06-17 13:24:22 +00:00
|
|
|
RotatePoint( &aPoints[ii], angle );
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
aPoints[ii] += 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
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
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
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
x = m_Pos.x;
|
|
|
|
y = m_Pos.y;
|
2008-03-30 11:48:18 +00:00
|
|
|
dx = dy = 0;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = (m_Thickness == 0) ? g_DrawDefaultLineThickness : m_Thickness;
|
2010-11-03 14:13:15 +00:00
|
|
|
height = ( (m_Size.y * 15) / 10 ) + width + 2 * TXTMARGE;
|
|
|
|
|
|
|
|
// text X size add height for triangular shapes(bidirectional)
|
|
|
|
length = LenSize( m_Text ) + height + DANGLING_SYMBOL_SIZE;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation ) // respect orientation
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +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;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
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;
|
|
|
|
|
|
|
|
case 2: /* Horiz Orientation - Right justified */
|
|
|
|
dx = length;
|
|
|
|
dy = height;
|
|
|
|
x -= DANGLING_SYMBOL_SIZE;
|
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_GLOBALLABEL::GetSelectMenuText() const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString tmp = ( GetText().Length() > 15 ) ? GetText().Left( 12 ) + wxT( "..." ) : GetText();
|
|
|
|
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Global Label %s" ), GetChars(tmp) );
|
|
|
|
return msg;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
bool SCH_GLOBALLABEL::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
2010-12-13 15:59:00 +00:00
|
|
|
return TextHitTest( aPoint, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2010-11-03 14:13:15 +00:00
|
|
|
m_MultilineAllowed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
EDA_ITEM* SCH_HIERLABEL::doClone() const
|
|
|
|
{
|
|
|
|
return new SCH_HIERLABEL( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
bool SCH_HIERLABEL::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
const char* shape = "~";
|
|
|
|
|
|
|
|
if( m_Italic )
|
|
|
|
shape = "Italic";
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
if( fprintf( aFile, "Text HLabel %-4d %-4d %-4d %-4d %s %s %d\n%s\n",
|
2011-12-08 15:45:01 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_schematicOrientation, m_Size.x,
|
|
|
|
SheetLabelType[m_shape], shape, m_Thickness, TO_UTF8( m_Text ) ) == EOF )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_HIERLABEL::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
char Name3[256];
|
|
|
|
int thickness = 0, size = 0, orient = 0;
|
|
|
|
|
|
|
|
Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;
|
|
|
|
|
|
|
|
char* sline = (char*) aLine;
|
2011-10-12 14:03:43 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
while( (*sline != ' ' ) && *sline )
|
|
|
|
sline++;
|
|
|
|
|
|
|
|
// sline points the start of parameters
|
|
|
|
int ii = sscanf( sline, "%s %d %d %d %d %s %s %d", Name1, &m_Pos.x, &m_Pos.y,
|
|
|
|
&orient, &size, Name2, Name3, &thickness );
|
|
|
|
|
|
|
|
if( ii < 4 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file hierarchical label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aLine.ReadLine() )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file hierarchical label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
|
|
|
|
char* text = strtok( (char*) aLine, "\n\r" );
|
|
|
|
|
|
|
|
if( text == NULL )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file hierarchical label load error at line %d" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Text = FROM_UTF8( text );
|
2010-11-10 15:30:12 +00:00
|
|
|
m_Size.x = m_Size.y = size;
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( orient );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_INPUT;
|
2010-11-10 15:30:12 +00:00
|
|
|
m_Bold = ( thickness != 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_OUTPUT] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_OUTPUT;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_BIDI] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_BIDI;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_TRISTATE] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_TRISTATE;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_UNSPECIFIED] ) == 0 )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_UNSPECIFIED;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( stricmp( Name3, "Italic" ) == 0 )
|
|
|
|
m_Italic = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
void SCH_HIERLABEL::SetOrientation( int aOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_schematicOrientation = aOrientation;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: /* Horiz Normal Orientation */
|
|
|
|
m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Horiz Orientation */
|
|
|
|
m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
m_VJustify = 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,
|
|
|
|
int DrawMode,
|
|
|
|
int Color )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
static std::vector <wxPoint> Poly;
|
2008-12-14 19:45:05 +00:00
|
|
|
EDA_Colors color;
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
|
|
|
if( Color >= 0 )
|
2009-05-05 17:32:07 +00:00
|
|
|
color = (EDA_Colors) Color;
|
2008-02-20 19:37:17 +00:00
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( linewidth, m_Thickness ); // Set the minimum width
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint text_offset = offset + GetSchematicTextOffset();
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT::Draw( panel, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR );
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( linewidth, m_Thickness ); // set initial value
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
CreateGraphicShape( Poly, m_Pos + offset );
|
2011-12-29 20:11:42 +00:00
|
|
|
GRPoly( panel->GetClipBox(), DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_isDangling )
|
2010-11-03 14:13:15 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, m_Pos + offset, color );
|
2009-11-28 09:24:37 +00:00
|
|
|
|
|
|
|
// Enable these line to draw the bounding box (debug tests purposes only)
|
|
|
|
#if 0
|
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
2011-12-29 20:11:42 +00:00
|
|
|
GRRect( panel->GetClipBox(), 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
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
int* Template = TemplateShape[m_shape][m_schematicOrientation];
|
2010-11-03 14:13:15 +00:00
|
|
|
int HalfSize = m_Size.x / 2;
|
2009-06-02 07:26:49 +00:00
|
|
|
|
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;
|
|
|
|
corner.x = ( HalfSize * (*Template) ) + Pos.x;
|
|
|
|
Template++;
|
2008-02-20 19:37:17 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
corner.y = ( HalfSize * (*Template) ) + Pos.y;
|
|
|
|
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
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
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
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
x = m_Pos.x;
|
|
|
|
y = m_Pos.y;
|
2008-03-30 11:48:18 +00:00
|
|
|
dx = dy = 0;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = (m_Thickness == 0) ? g_DrawDefaultLineThickness : m_Thickness;
|
2010-11-03 14:13:15 +00:00
|
|
|
height = m_Size.y + width + 2 * TXTMARGE;
|
|
|
|
length = LenSize( m_Text )
|
|
|
|
+ height // add height for triangular shapes
|
|
|
|
+ 2 * DANGLING_SYMBOL_SIZE;
|
2008-03-30 09:27:53 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation ) // respect orientation
|
2008-03-30 09:27:53 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +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;
|
|
|
|
|
|
|
|
case 1: /* Vert Orientation UP */
|
|
|
|
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;
|
|
|
|
|
|
|
|
case 2: /* Horiz Orientation - Right justified */
|
|
|
|
dx = length;
|
|
|
|
dy = height;
|
|
|
|
x -= DANGLING_SYMBOL_SIZE;
|
|
|
|
y -= height / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Vert Orientation BOTTOM */
|
|
|
|
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;
|
2008-03-27 21:24:50 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = MAX( m_Thickness, g_DrawDefaultLineThickness );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
int ii = m_Size.x + TXTMARGE + width;
|
2008-03-27 21:24:50 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_schematicOrientation )
|
2008-03-27 21:24:50 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
case 0: /* Orientation horiz normale */
|
|
|
|
text_offset.x = -ii;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 1: /* Orientation vert UP */
|
|
|
|
text_offset.y = -ii;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 2: /* Orientation horiz inverse */
|
|
|
|
text_offset.x = ii;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
case 3: /* Orientation vert BOTTOM */
|
|
|
|
text_offset.y = ii;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
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
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_HIERLABEL::Mirror_Y( int aYaxis_position )
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
/* The hierarchical label is NOT really mirrored for an horizontal label, the schematic
|
2011-06-07 15:29:01 +00:00
|
|
|
* orientation is changed. For a vertical label, the schematic orientation is not changed
|
2010-12-21 15:13:09 +00:00
|
|
|
* and the label is moved to a suitable position.
|
|
|
|
*/
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( GetOrientation() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
case 0: /* horizontal text */
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 2 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2009-11-28 09:24:37 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
case 2: /* invert horizontal text*/
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 0 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Pos.x );
|
|
|
|
m_Pos.x += aYaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_HIERLABEL::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
2011-03-03 01:58:12 +00:00
|
|
|
switch( GetOrientation() )
|
2009-11-28 09:24:37 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
case 1: /* vertical text */
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 3 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* invert vertical text*/
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( 1 );
|
2010-11-03 14:13:15 +00:00
|
|
|
break;
|
2009-11-28 09:24:37 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
m_Pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Pos.y );
|
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_HIERLABEL::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
2011-03-03 01:58:12 +00:00
|
|
|
SetOrientation( (GetOrientation() + 3) % 4 );
|
2009-11-28 09:24:37 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_HIERLABEL::GetSelectMenuText() const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString tmp = ( GetText().Length() > 15 ) ? GetText().Left( 12 ) + wxT( "..." ) : GetText();
|
|
|
|
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Hierarchical Label %s" ), GetChars( tmp ) );
|
|
|
|
return msg;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
bool SCH_HIERLABEL::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
2010-12-13 15:59:00 +00:00
|
|
|
return TextHitTest( aPoint, aAccuracy );
|
|
|
|
}
|