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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* 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_no_connect.cpp
|
|
|
|
* @brief Class SCH_NO_CONNECT implementation.
|
|
|
|
*/
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "richio.h"
|
2011-06-17 13:24:22 +00:00
|
|
|
#include "plot_common.h"
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
#include "sch_no_connect.h"
|
2011-10-11 13:38:13 +00:00
|
|
|
#include "class_netlist_object.h"
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
|
|
|
|
SCH_ITEM( NULL, SCH_NO_CONNECT_T )
|
|
|
|
{
|
|
|
|
#define DRAWNOCONNECT_SIZE 48 /* No symbol connection range. */
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos = pos;
|
|
|
|
m_size.x = m_size.y = DRAWNOCONNECT_SIZE;
|
2011-02-28 18:36:19 +00:00
|
|
|
#undef DRAWNOCONNECT_SIZE
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
SetLayer( LAYER_NOCONNECT );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* SCH_NO_CONNECT::doClone() const
|
|
|
|
{
|
|
|
|
return new SCH_NO_CONNECT( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T),
|
|
|
|
wxT( "Cannot swap no connect data with invalid item." ) );
|
|
|
|
|
|
|
|
SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
|
2011-12-07 20:19:29 +00:00
|
|
|
EXCHG( m_pos, item->m_pos );
|
|
|
|
EXCHG( m_size, item->m_size );
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT SCH_NO_CONNECT::GetBoundingBox() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
int delta = ( GetPenSize() + m_size.x ) / 2;
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT box;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
box.SetOrigin( m_pos );
|
2011-02-28 18:36:19 +00:00
|
|
|
box.Inflate( delta );
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_NO_CONNECT::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( fprintf( aFile, "NoConn ~ %-4d %-4d\n", m_pos.x, m_pos.y ) == EOF )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_NO_CONNECT::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 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file No Connect load error at line %d" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( ((char*)aLine) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_NO_CONNECT::GetPenSize() const
|
|
|
|
{
|
|
|
|
return g_DrawDefaultLineThickness;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
int aDrawMode, int aColor )
|
|
|
|
{
|
|
|
|
int pX, pY, color;
|
2011-12-07 20:19:29 +00:00
|
|
|
int delta = m_size.x / 2;
|
2011-02-28 18:36:19 +00:00
|
|
|
int width = g_DrawDefaultLineThickness;
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
pX = m_pos.x + aOffset.x;
|
|
|
|
pY = m_pos.y + aOffset.y;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( aColor >= 0 )
|
|
|
|
color = aColor;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( LAYER_NOCONNECT );
|
|
|
|
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( aPanel->GetClipBox(), aDC, pX - delta, pY - delta, pX + delta, pY + delta,
|
|
|
|
width, color );
|
|
|
|
GRLine( aPanel->GetClipBox(), aDC, pX + delta, pY - delta, pX - delta, pY + delta,
|
|
|
|
width, color );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_pos.y );
|
|
|
|
m_pos.y += aXaxis_position;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_pos.x );
|
|
|
|
m_pos.x += aYaxis_position;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
RotatePoint( &m_pos, rotationPoint, 900 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_NO_CONNECT::IsSelectStateChanged( const wxRect& aRect )
|
|
|
|
{
|
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( aRect.Contains( m_pos ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Flags |= SELECTED;
|
|
|
|
else
|
|
|
|
m_Flags &= ~SELECTED;
|
|
|
|
|
|
|
|
return previousState != IsSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::GetConnectionPoints( vector< wxPoint >& aPoints ) const
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
aPoints.push_back( m_pos );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 13:38:13 +00:00
|
|
|
|
|
|
|
void SCH_NO_CONNECT::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT();
|
|
|
|
|
|
|
|
item->m_SheetList = *aSheetPath;
|
|
|
|
item->m_SheetListInclude = *aSheetPath;
|
|
|
|
item->m_Comp = this;
|
|
|
|
item->m_Type = NET_NOCONNECT;
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
return m_pos == aPosition;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_NO_CONNECT::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
int delta = ( ( m_size.x + g_DrawDefaultLineThickness ) / 2 ) + aAccuracy;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
wxPoint dist = aPoint - m_pos;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( ( ABS( dist.x ) <= delta ) && ( ABS( dist.y ) <= delta ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
bool SCH_NO_CONNECT::doHitTest( 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
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::doPlot( PLOTTER* aPlotter )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
int delta = m_size.x / 2;
|
2011-06-17 13:24:22 +00:00
|
|
|
int pX, pY;
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
pX = m_pos.x;
|
|
|
|
pY = m_pos.y;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
aPlotter->set_current_line_width( GetPenSize() );
|
|
|
|
aPlotter->set_color( ReturnLayerColor( GetLayer() ) );
|
|
|
|
aPlotter->move_to( wxPoint( pX - delta, pY - delta ) );
|
|
|
|
aPlotter->finish_to( wxPoint( pX + delta, pY + delta ) );
|
|
|
|
aPlotter->move_to( wxPoint( pX + delta, pY - delta ) );
|
|
|
|
aPlotter->finish_to( wxPoint( pX - delta, pY + delta ) );
|
|
|
|
}
|