2011-10-07 14:41:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
2019-05-17 16:45:27 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-07 14:41:30 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2018-01-28 18:12:26 +00:00
|
|
|
#include <plotter.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <kicad_string.h>
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
|
2019-05-17 16:45:27 +00:00
|
|
|
SCH_HIERLABEL( pos, text, SCH_SHEET_PIN_T ),
|
|
|
|
m_edge( SHEET_UNDEFINED_SIDE )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
SetParent( parent );
|
2008-04-22 16:38:23 +00:00
|
|
|
wxASSERT( parent );
|
2008-12-29 18:02:54 +00:00
|
|
|
m_Layer = LAYER_SHEETLABEL;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
SetTextPos( pos );
|
2011-10-21 13:59:15 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( parent->IsVerticalOrientation() )
|
2015-06-27 09:12:32 +00:00
|
|
|
SetEdge( SHEET_TOP_SIDE );
|
2010-09-05 17:01:48 +00:00
|
|
|
else
|
2015-06-27 09:12:32 +00:00
|
|
|
SetEdge( SHEET_LEFT_SIDE );
|
2011-10-21 13:59:15 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = NET_INPUT;
|
|
|
|
m_isDangling = true;
|
|
|
|
m_number = 2;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_SHEET_PIN::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_SHEET_PIN( *this );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void SCH_SHEET_PIN::Print( wxDC* aDC, const wxPoint& aOffset )
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
// The icon selection is handle by the virtual method CreateGraphicShape called by ::Print
|
|
|
|
SCH_HIERLABEL::Print( aDC, aOffset );
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
void SCH_SHEET_PIN::SwapData( SCH_ITEM* aItem )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2011-06-07 15:29:01 +00:00
|
|
|
wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
|
|
|
|
wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ),
|
|
|
|
GetChars( aItem->GetClass() ) ) );
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem;
|
|
|
|
SCH_TEXT::SwapData( (SCH_TEXT*) pin );
|
2015-06-27 09:12:32 +00:00
|
|
|
int tmp = pin->GetNumber();
|
2011-06-07 15:29:01 +00:00
|
|
|
pin->SetNumber( GetNumber() );
|
2010-09-05 17:01:48 +00:00
|
|
|
SetNumber( tmp );
|
2015-06-27 09:12:32 +00:00
|
|
|
SHEET_SIDE stmp = pin->GetEdge();
|
2011-06-07 15:29:01 +00:00
|
|
|
pin->SetEdge( GetEdge() );
|
2015-06-27 09:12:32 +00:00
|
|
|
SetEdge( stmp );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
|
|
|
return aPin == this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
int SCH_SHEET_PIN::GetPenSize() const
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
2012-09-28 17:47:41 +00:00
|
|
|
return GetDefaultLineThickness();
|
2009-06-30 19:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
void SCH_SHEET_PIN::SetNumber( int aNumber )
|
|
|
|
{
|
|
|
|
wxASSERT( aNumber >= 2 );
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
m_number = aNumber;
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
void SCH_SHEET_PIN::SetEdge( SHEET_SIDE aEdge )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2015-11-03 19:44:05 +00:00
|
|
|
SCH_SHEET* Sheet = GetParent();
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
// use SHEET_UNDEFINED_SIDE to adjust text orientation without changing edge
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
switch( aEdge )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2015-06-27 09:12:32 +00:00
|
|
|
case SHEET_LEFT_SIDE:
|
|
|
|
m_edge = aEdge;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextX( Sheet->m_pos.x );
|
|
|
|
SetLabelSpinStyle( 2 ); // Orientation horiz inverse
|
2010-09-05 17:01:48 +00:00
|
|
|
break;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
case SHEET_RIGHT_SIDE:
|
|
|
|
m_edge = aEdge;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
|
|
|
|
SetLabelSpinStyle( 0 ); // Orientation horiz normal
|
2010-09-05 17:01:48 +00:00
|
|
|
break;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
case SHEET_TOP_SIDE:
|
|
|
|
m_edge = aEdge;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( Sheet->m_pos.y );
|
|
|
|
SetLabelSpinStyle( 3 ); // Orientation vert BOTTOM
|
2010-09-05 17:01:48 +00:00
|
|
|
break;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
case SHEET_BOTTOM_SIDE:
|
|
|
|
m_edge = aEdge;
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
|
|
|
|
SetLabelSpinStyle( 1 ); // Orientation vert UP
|
2010-09-05 17:01:48 +00:00
|
|
|
break;
|
2015-06-27 09:12:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
2009-05-05 18:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
enum SHEET_SIDE SCH_SHEET_PIN::GetEdge() const
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
return m_edge;
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-21 13:59:15 +00:00
|
|
|
void SCH_SHEET_PIN::ConstrainOnEdge( wxPoint Pos )
|
2009-05-05 18:25:47 +00:00
|
|
|
{
|
2015-11-03 19:44:05 +00:00
|
|
|
SCH_SHEET* sheet = GetParent();
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2015-07-24 10:23:34 +00:00
|
|
|
if( sheet == NULL )
|
2010-09-05 17:01:48 +00:00
|
|
|
return;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2015-07-24 10:23:34 +00:00
|
|
|
wxPoint center = sheet->m_pos + ( sheet->m_size / 2 );
|
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
if( m_edge == SHEET_LEFT_SIDE || m_edge == SHEET_RIGHT_SIDE )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2015-07-24 10:23:34 +00:00
|
|
|
if( Pos.x > center.x )
|
2015-06-27 09:12:32 +00:00
|
|
|
SetEdge( SHEET_RIGHT_SIDE );
|
2010-09-05 17:01:48 +00:00
|
|
|
else
|
2015-06-27 09:12:32 +00:00
|
|
|
SetEdge( SHEET_LEFT_SIDE );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( Pos.y );
|
2011-10-21 13:59:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextPos().y < sheet->m_pos.y )
|
2017-08-23 22:33:27 +00:00
|
|
|
SetTextY( sheet->m_pos.y );
|
2011-10-21 13:59:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
|
2017-08-23 22:33:27 +00:00
|
|
|
SetTextY( sheet->m_pos.y + sheet->m_size.y );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2017-08-23 16:06:33 +00:00
|
|
|
else
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2015-07-24 10:23:34 +00:00
|
|
|
if( Pos.y > center.y )
|
2017-08-23 16:06:33 +00:00
|
|
|
SetEdge( SHEET_BOTTOM_SIDE );
|
2010-09-05 17:01:48 +00:00
|
|
|
else
|
2017-08-23 16:06:33 +00:00
|
|
|
SetEdge( SHEET_TOP_SIDE );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextX( Pos.x );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextPos().x < sheet->m_pos.x )
|
2017-08-23 22:33:27 +00:00
|
|
|
SetTextX( sheet->m_pos.x );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
|
2017-08-23 22:33:27 +00:00
|
|
|
SetTextX( sheet->m_pos.x + sheet->m_size.x );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET_PIN::MirrorX( int aXaxis_position )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int p = GetTextPos().y - aXaxis_position;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextY( aXaxis_position - p );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_edge )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
case SHEET_TOP_SIDE: SetEdge( SHEET_BOTTOM_SIDE ); break;
|
|
|
|
case SHEET_BOTTOM_SIDE: SetEdge( SHEET_TOP_SIDE ); break;
|
|
|
|
default: break;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET_PIN::MirrorY( int aYaxis_position )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int p = GetTextPos().x - aYaxis_position;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextX( aYaxis_position - p );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_edge )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
case SHEET_LEFT_SIDE: SetEdge( SHEET_RIGHT_SIDE ); break;
|
|
|
|
case SHEET_RIGHT_SIDE: SetEdge( SHEET_LEFT_SIDE ); break;
|
|
|
|
default: break;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET_PIN::Rotate( wxPoint aPosition )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, aPosition, 900 );
|
|
|
|
SetTextPos( pt );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_edge )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
case SHEET_LEFT_SIDE: SetEdge( SHEET_BOTTOM_SIDE ); break;
|
|
|
|
case SHEET_RIGHT_SIDE: SetEdge( SHEET_TOP_SIDE ); break;
|
|
|
|
case SHEET_TOP_SIDE: SetEdge( SHEET_LEFT_SIDE ); break;
|
|
|
|
case SHEET_BOTTOM_SIDE: SetEdge( SHEET_RIGHT_SIDE ); break;
|
|
|
|
default: break;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
/*
|
|
|
|
* These are the same icon shapes as SCH_HIERLABEL but the graphic icon is slightly
|
|
|
|
* different in 2 cases:
|
2010-11-03 14:13:15 +00:00
|
|
|
* for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
|
|
|
|
* for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
|
|
|
|
*/
|
2016-02-28 18:16:59 +00:00
|
|
|
PINSHEETLABEL_SHAPE tmp = m_shape;
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
switch( m_shape )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
case NET_INPUT: m_shape = NET_OUTPUT; break;
|
|
|
|
case NET_OUTPUT: m_shape = NET_INPUT; break;
|
|
|
|
default: break;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_shape = tmp;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
DANGLING_END_ITEM item( SHEET_LABEL_END, this, GetTextPos() );
|
2010-11-03 14:13:15 +00:00
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_SHEET_PIN::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Hierarchical Sheet Pin %s" ), ShortenedShownText() );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF SCH_SHEET_PIN::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_hierar_pin_xpm;
|
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetBoundingBox();
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
return rect.Contains( aPoint );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os ) const
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
2019-08-02 00:10:25 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">"
|
|
|
|
<< " pin_name=\"" << TO_UTF8( GetText() )
|
2009-11-03 13:26:31 +00:00
|
|
|
<< '"' << "/>\n" << std::flush;
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|