2011-12-07 14:08:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_bus_entry.cpp
|
|
|
|
*
|
|
|
|
*/
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <plot_common.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-05-24 06:51:52 +00:00
|
|
|
#include <eeschema_config.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <sch_bus_entry.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_ENTRY_BASE::SCH_BUS_ENTRY_BASE( KICAD_T aType, const wxPoint& pos, char shape ) :
|
|
|
|
SCH_ITEM( NULL, aType )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
m_pos = pos;
|
|
|
|
m_size.x = 100;
|
|
|
|
m_size.y = 100;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( shape == '/' )
|
2011-12-07 14:08:52 +00:00
|
|
|
m_size.y = -100;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY::SCH_BUS_WIRE_ENTRY( const wxPoint& pos, char shape ) :
|
|
|
|
SCH_BUS_ENTRY_BASE( SCH_BUS_WIRE_ENTRY_T, pos, shape )
|
|
|
|
{
|
|
|
|
m_Layer = LAYER_WIRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_BUS_BUS_ENTRY::SCH_BUS_BUS_ENTRY( const wxPoint& pos, char shape ) :
|
|
|
|
SCH_BUS_ENTRY_BASE( SCH_BUS_BUS_ENTRY_T, pos, shape )
|
|
|
|
{
|
2013-04-06 12:28:02 +00:00
|
|
|
m_Layer = LAYER_BUS;
|
2013-04-01 10:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EDA_ITEM* SCH_BUS_WIRE_ENTRY::Clone() const
|
|
|
|
{
|
|
|
|
return new SCH_BUS_WIRE_ENTRY( *this );
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
EDA_ITEM* SCH_BUS_BUS_ENTRY::Clone() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-04-01 10:35:20 +00:00
|
|
|
return new SCH_BUS_BUS_ENTRY( *this );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
wxPoint SCH_BUS_ENTRY_BASE::m_End() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
return wxPoint( m_pos.x + m_size.x, m_pos.y + m_size.y );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::SwapData( SCH_ITEM* aItem )
|
2011-10-19 20:32:21 +00:00
|
|
|
{
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_ENTRY_BASE* item = dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem );
|
|
|
|
wxCHECK_RET( item, wxT( "Cannot swap bus entry data with invalid item." ) );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-12-07 14:08:52 +00:00
|
|
|
EXCHG( m_pos, item->m_pos );
|
|
|
|
EXCHG( m_size, item->m_size );
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_WIRE_ENTRY::Save( FILE* aFile ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-04-01 10:35:20 +00:00
|
|
|
if( fprintf( aFile, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
|
|
|
|
m_pos.x, m_pos.y, m_End().x, m_End().y ) == EOF )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_BUS_ENTRY::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
if( fprintf( aFile, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
|
2011-12-07 14:08:52 +00:00
|
|
|
m_pos.x, m_pos.y, m_End().x, m_End().y ) == EOF )
|
2013-04-01 10:35:20 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::Load( LINE_READER& aLine, wxString& aErrorMsg,
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_ITEM **out )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
char* line = (char*) aLine;
|
2013-04-01 10:35:20 +00:00
|
|
|
*out = NULL;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
while( (*line != ' ' ) && *line )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( sscanf( line, "%s %s", Name1, Name2 ) != 2 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file bus entry load error at line %d" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_ENTRY_BASE *this_new;
|
2011-02-28 18:36:19 +00:00
|
|
|
if( Name1[0] == 'B' )
|
2013-04-01 10:35:20 +00:00
|
|
|
this_new = new SCH_BUS_BUS_ENTRY;
|
|
|
|
else
|
|
|
|
this_new = new SCH_BUS_WIRE_ENTRY;
|
|
|
|
*out = this_new;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( !aLine.ReadLine() || sscanf( (char*) aLine, "%d %d %d %d ",
|
2013-04-01 10:35:20 +00:00
|
|
|
&this_new->m_pos.x, &this_new->m_pos.y,
|
|
|
|
&this_new->m_size.x, &this_new->m_size.y ) != 4 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file bus entry load error at line %d" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
this_new->m_size.x -= this_new->m_pos.x;
|
|
|
|
this_new->m_size.y -= this_new->m_pos.y;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT box;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 14:08:52 +00:00
|
|
|
box.SetOrigin( m_pos );
|
2011-02-28 18:36:19 +00:00
|
|
|
box.SetEnd( m_End() );
|
|
|
|
|
|
|
|
box.Normalize();
|
2013-04-01 10:35:20 +00:00
|
|
|
box.Inflate( GetPenSize() / 2 );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
int SCH_BUS_WIRE_ENTRY::GetPenSize() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-04-01 10:35:20 +00:00
|
|
|
return GetDefaultLineThickness();
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
int SCH_BUS_BUS_ENTRY::GetPenSize() const
|
|
|
|
{
|
|
|
|
return GetDefaultBusThickness();
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
2012-09-02 12:06:47 +00:00
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( aColor >= 0 )
|
|
|
|
color = aColor;
|
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( m_Layer );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( aPanel->GetClipBox(), aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
|
2011-02-28 18:36:19 +00:00
|
|
|
m_End().x + aOffset.x, m_End().y + aOffset.y, GetPenSize(), color );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::MirrorX( int aXaxis_position )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
m_pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_pos.y );
|
|
|
|
m_pos.y += aXaxis_position;
|
|
|
|
NEGATE( m_size.y );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::MirrorY( int aYaxis_position )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
m_pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_pos.x );
|
|
|
|
m_pos.x += aYaxis_position;
|
|
|
|
NEGATE( m_size.x );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::Rotate( wxPoint aPosition )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
RotatePoint( &m_pos, aPosition, 900 );
|
2011-12-07 14:08:52 +00:00
|
|
|
RotatePoint( &m_size.x, &m_size.y, 900 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
DANGLING_END_ITEM item( ENTRY_END, this, m_pos );
|
2011-02-28 18:36:19 +00:00
|
|
|
aItemList.push_back( item );
|
2011-12-06 21:02:21 +00:00
|
|
|
|
|
|
|
DANGLING_END_ITEM item1( ENTRY_END, this, m_End() );
|
2011-02-28 18:36:19 +00:00
|
|
|
aItemList.push_back( item1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::IsSelectStateChanged( const wxRect& aRect )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
|
|
|
// If either end of the bus entry is inside the selection rectangle, the entire
|
|
|
|
// bus entry is selected. Bus entries have a fixed length and angle.
|
2011-12-07 14:08:52 +00:00
|
|
|
if( aRect.Contains( m_pos ) || aRect.Contains( m_End() ) )
|
2013-04-01 10:35:20 +00:00
|
|
|
SetFlags( SELECTED );
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
2013-04-01 10:35:20 +00:00
|
|
|
ClearFlags( SELECTED );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
return previousState != IsSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-13 16:27:30 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
aPoints.push_back( m_pos );
|
2011-02-28 18:36:19 +00:00
|
|
|
aPoints.push_back( m_End() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
wxString SCH_BUS_WIRE_ENTRY::GetSelectMenuText() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-04-06 12:28:02 +00:00
|
|
|
return wxString( _( "Bus to Wire Entry" ) );
|
2013-04-01 10:35:20 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
wxString SCH_BUS_BUS_ENTRY::GetSelectMenuText() const
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
return wxString( _( "Bus to Bus Entry" ) );
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
return TestSegmentHit( aPosition, m_pos, m_End(), aAccuracy );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( GetPenSize() );
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( GetLayer() ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->MoveTo( m_pos );
|
|
|
|
aPlotter->FinishTo( m_End() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2011-12-18 17:57:05 +00:00
|
|
|
|
|
|
|
/* SetBusEntryShape:
|
|
|
|
* Set the shape of the bus entry.
|
|
|
|
* aShape = ascii code '/' or '\'
|
|
|
|
*/
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::SetBusEntryShape( char aShape )
|
2011-12-18 17:57:05 +00:00
|
|
|
{
|
|
|
|
switch( aShape )
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
if( m_size.y < 0 )
|
|
|
|
m_size.y = -m_size.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '/':
|
|
|
|
if( m_size.y > 0 )
|
|
|
|
m_size.y = -m_size.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* GetBusEntryShape:
|
|
|
|
* return the shape of the bus entry, as an ascii code '/' or '\'
|
|
|
|
*/
|
2013-04-01 10:35:20 +00:00
|
|
|
char SCH_BUS_ENTRY_BASE::GetBusEntryShape() const
|
2011-12-18 17:57:05 +00:00
|
|
|
{
|
|
|
|
if( GetSize().y < 0 )
|
2013-04-01 10:35:20 +00:00
|
|
|
return '/';
|
|
|
|
else
|
|
|
|
return '\\';
|
2011-12-18 17:57:05 +00:00
|
|
|
}
|
2013-04-01 10:35:20 +00:00
|
|
|
|