2011-10-11 13:38:13 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_junction.cpp
|
|
|
|
*/
|
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 <class_drawpanel.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <plot_common.h>
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_junction.h>
|
2013-09-25 19:09:57 +00:00
|
|
|
#include <class_netlist_object.h>
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2013-05-24 08:59:40 +00:00
|
|
|
int SCH_JUNCTION::m_symbolSize = 40; // Default diameter of the junction symbol
|
2013-05-19 19:35:49 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) :
|
|
|
|
SCH_ITEM( NULL, SCH_JUNCTION_T )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos = pos;
|
2010-09-05 17:01:48 +00:00
|
|
|
m_Layer = LAYER_JUNCTION;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_JUNCTION::Save( FILE* aFile ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( fprintf( aFile, "Connection ~ %-4d %-4d\n", m_pos.x, m_pos.y ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_JUNCTION::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_JUNCTION( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
|
|
|
|
wxT( "Cannot swap junction data with invalid item." ) );
|
|
|
|
|
|
|
|
SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
|
2011-12-07 20:19:29 +00:00
|
|
|
EXCHG( m_pos, item->m_pos );
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_JUNCTION::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char name[256];
|
|
|
|
char* line = (char*) aLine;
|
|
|
|
|
|
|
|
while( (*line != ' ' ) && *line )
|
|
|
|
line++;
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( sscanf( line, "%s %d %d", name, &m_pos.x, &m_pos.y ) != 3 )
|
2010-11-10 15:30:12 +00:00
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file connection load error at line %d, aborted" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
2011-02-28 18:36:19 +00:00
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
2010-11-10 15:30:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT SCH_JUNCTION::GetBoundingBox() const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
rect.SetOrigin( m_pos );
|
2013-05-19 19:35:49 +00:00
|
|
|
rect.Inflate( ( GetPenSize() + GetSymbolSize() ) / 2 );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
return rect;
|
2010-10-04 12:58:07 +00:00
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_JUNCTION::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 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
if( aColor >= 0 )
|
|
|
|
color = aColor;
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( m_Layer );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
|
2013-05-19 19:35:49 +00:00
|
|
|
( GetSymbolSize() / 2 ), 0, color, color );
|
2009-01-31 18:08:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_JUNCTION::MirrorX( int aXaxis_position )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_pos.y );
|
|
|
|
m_pos.y += aXaxis_position;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_JUNCTION::MirrorY( int aYaxis_position )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_pos.x );
|
|
|
|
m_pos.x += aYaxis_position;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_JUNCTION::Rotate( wxPoint aPosition )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
RotatePoint( &m_pos, aPosition, 900 );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
|
2010-11-03 14:13:15 +00:00
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_JUNCTION::IsSelectStateChanged( const wxRect& aRect )
|
|
|
|
{
|
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( aRect.Contains( m_pos ) )
|
2013-03-30 19:55:26 +00:00
|
|
|
SetFlags( SELECTED );
|
2010-11-03 14:13:15 +00:00
|
|
|
else
|
2013-03-30 19:55:26 +00:00
|
|
|
ClearFlags( SELECTED );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
return previousState != IsSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_JUNCTION::GetConnectionPoints( vector< wxPoint >& aPoints ) const
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
aPoints.push_back( m_pos );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:09:57 +00:00
|
|
|
void SCH_JUNCTION::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
|
2011-10-11 13:38:13 +00:00
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT();
|
|
|
|
|
2013-09-29 18:24:38 +00:00
|
|
|
item->m_SheetPath = *aSheetPath;
|
|
|
|
item->m_SheetPathInclude = *aSheetPath;
|
2011-10-11 13:38:13 +00:00
|
|
|
item->m_Comp = (SCH_ITEM*) this;
|
|
|
|
item->m_Type = NET_JUNCTION;
|
2011-12-07 20:19:29 +00:00
|
|
|
item->m_Start = item->m_End = m_pos;
|
2011-10-11 13:38:13 +00:00
|
|
|
|
|
|
|
aNetListItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
#endif
|
2008-04-22 16:38:23 +00:00
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetBoundingBox();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
return rect.Contains( aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT )
|
|
|
|
return false;
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
2010-12-20 17:44:25 +00:00
|
|
|
return rect.Contains( GetBoundingBox() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
return m_pos == aPosition;
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( GetLayer() ) );
|
2013-05-19 19:35:49 +00:00
|
|
|
aPlotter->Circle( m_pos, GetSymbolSize(), FILLED_SHAPE );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|