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_line.cpp
|
|
|
|
* @brief Class SCH_LINE implementation
|
|
|
|
*/
|
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 <richio.h>
|
|
|
|
#include <plot_common.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
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_line.h>
|
|
|
|
#include <class_netlist_object.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
|
|
|
|
SCH_ITEM( NULL, SCH_LINE_T )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start = pos;
|
|
|
|
m_end = pos;
|
|
|
|
m_startIsDangling = m_endIsDangling = false;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
switch( layer )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
m_Layer = LAYER_NOTES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
|
|
|
m_Layer = LAYER_WIRE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_BUS:
|
|
|
|
m_Layer = LAYER_BUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LINE::SCH_LINE( const SCH_LINE& aLine ) :
|
|
|
|
SCH_ITEM( aLine )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start = aLine.m_start;
|
|
|
|
m_end = aLine.m_end;
|
|
|
|
m_startIsDangling = m_endIsDangling = false;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_LINE::Clone() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
return new SCH_LINE( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::Move( const wxPoint& aOffset )
|
|
|
|
{
|
|
|
|
if( (m_Flags & STARTPOINT) == 0 && aOffset != wxPoint( 0, 0 ) )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start += aOffset;
|
2011-02-28 18:36:19 +00:00
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (m_Flags & ENDPOINT) == 0 && aOffset != wxPoint( 0, 0 ) )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_end += aOffset;
|
2011-02-28 18:36:19 +00:00
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
|
|
|
|
void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
|
|
|
|
{
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
|
|
|
|
<< " layer=\"" << m_Layer << '"'
|
2011-12-07 20:19:29 +00:00
|
|
|
<< " startIsDangling=\"" << m_startIsDangling
|
2011-02-28 18:36:19 +00:00
|
|
|
<< '"' << " endIsDangling=\""
|
2011-12-07 20:19:29 +00:00
|
|
|
<< m_endIsDangling << '"' << ">"
|
|
|
|
<< " <start" << m_start << "/>"
|
|
|
|
<< " <end" << m_end << "/>" << "</"
|
2011-02-28 18:36:19 +00:00
|
|
|
<< GetClass().Lower().mb_str() << ">\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT SCH_LINE::GetBoundingBox() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
int width = 25;
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
int xmin = std::min( m_start.x, m_end.x ) - width;
|
|
|
|
int ymin = std::min( m_start.y, m_end.y ) - width;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
int xmax = std::max( m_start.x, m_end.x ) + width;
|
|
|
|
int ymax = std::max( m_start.y, m_end.y ) + width;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
// return a rectangle which is [pos,dim) in nature. therefore the +1
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
double SCH_LINE::GetLength() const
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
return GetLineLength( m_start, m_end );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
bool SCH_LINE::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
const char* layer = "Notes";
|
|
|
|
const char* width = "Line";
|
|
|
|
|
|
|
|
if( GetLayer() == LAYER_WIRE )
|
|
|
|
layer = "Wire";
|
|
|
|
|
|
|
|
if( GetLayer() == LAYER_BUS )
|
|
|
|
layer = "Bus";
|
|
|
|
|
|
|
|
if( fprintf( aFile, "Wire %s %s\n", layer, width ) == EOF )
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n", m_start.x, m_start.y,
|
|
|
|
m_end.x, m_end.y ) == EOF )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
char* line = (char*) aLine;
|
|
|
|
|
|
|
|
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 segment error at line %d, aborted" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Layer = LAYER_NOTES;
|
|
|
|
|
|
|
|
if( Name1[0] == 'W' )
|
|
|
|
m_Layer = LAYER_WIRE;
|
|
|
|
|
|
|
|
if( Name1[0] == 'B' )
|
|
|
|
m_Layer = LAYER_BUS;
|
|
|
|
|
|
|
|
if( !aLine.ReadLine() || sscanf( (char*) aLine, "%d %d %d %d ",
|
2011-12-07 20:19:29 +00:00
|
|
|
&m_start.x, &m_start.y, &m_end.x, &m_end.y ) != 4 )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file Segment struct error at line %d, aborted" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_LINE::GetPenSize() const
|
|
|
|
{
|
|
|
|
|
2012-05-24 06:51:52 +00:00
|
|
|
if( m_Layer == LAYER_BUS )
|
2013-04-01 11:59:19 +00:00
|
|
|
return GetDefaultBusThickness();
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2013-04-01 11:59:19 +00:00
|
|
|
return GetDefaultLineThickness();
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
|
2012-09-02 12:06:47 +00:00
|
|
|
GR_DRAWMODE DrawMode, EDA_COLOR_T Color )
|
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
|
|
|
int width = GetPenSize();
|
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( m_Layer );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
wxPoint start = m_start;
|
|
|
|
wxPoint end = m_end;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( ( m_Flags & STARTPOINT ) == 0 )
|
|
|
|
start += offset;
|
2011-12-29 20:11:42 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( ( m_Flags & ENDPOINT ) == 0 )
|
|
|
|
end += offset;
|
|
|
|
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRDashedLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color );
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, start, end, width, color );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_startIsDangling )
|
2011-02-28 18:36:19 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, start, color );
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_endIsDangling )
|
2011-02-28 18:36:19 +00:00
|
|
|
DrawDanglingSymbol( panel, DC, end, color );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_LINE::MirrorX( int aXaxis_position )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start.y -= aXaxis_position;
|
|
|
|
NEGATE( m_start.y );
|
|
|
|
m_start.y += aXaxis_position;
|
|
|
|
m_end.y -= aXaxis_position;
|
|
|
|
NEGATE( m_end.y );
|
|
|
|
m_end.y += aXaxis_position;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_LINE::MirrorY( int aYaxis_position )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start.x -= aYaxis_position;
|
|
|
|
NEGATE( m_start.x );
|
|
|
|
m_start.x += aYaxis_position;
|
|
|
|
m_end.x -= aYaxis_position;
|
|
|
|
NEGATE( m_end.x );
|
|
|
|
m_end.x += aYaxis_position;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_LINE::Rotate( wxPoint aPosition )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
RotatePoint( &m_start, aPosition, 900 );
|
|
|
|
RotatePoint( &m_end, aPosition, 900 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
/*
|
|
|
|
* helper sort function, used by MergeOverlap
|
|
|
|
* sorts ref and test by x values, or (for same x values) by y values
|
|
|
|
*/
|
|
|
|
bool sort_by_ends_position(const wxPoint * ref, const wxPoint * tst )
|
|
|
|
{
|
|
|
|
if( ref->x == tst->x )
|
|
|
|
return ref->y < tst->y;
|
|
|
|
return ref->x < tst->x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MergeOverlap try to merge 2 lines that are colinear.
|
|
|
|
* this function expects these 2 lines have at least a common end
|
|
|
|
*/
|
2011-02-28 18:36:19 +00:00
|
|
|
bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false,
|
|
|
|
wxT( "Cannot test line segment for overlap." ) );
|
|
|
|
|
|
|
|
if( this == aLine || GetLayer() != aLine->GetLayer() )
|
|
|
|
return false;
|
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
// Search for a common end:
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start == aLine->m_start )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-19 07:48:29 +00:00
|
|
|
if( m_end == aLine->m_end ) // Trivial case
|
2011-02-28 18:36:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_start == aLine->m_end )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-19 07:48:29 +00:00
|
|
|
if( m_end == aLine->m_start ) // Trivial case
|
|
|
|
return true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_end == aLine->m_end )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
EXCHG( aLine->m_start, aLine->m_end );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_end != aLine->m_start )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
// No common end point, segments cannot be merged.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
bool colinear = false;
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
/* Test alignment: */
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start.y == m_end.y ) // Horizontal segment
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
if( aLine->m_start.y == aLine->m_end.y )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-19 07:48:29 +00:00
|
|
|
colinear = true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_start.x == m_end.x ) // Vertical segment
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
if( aLine->m_start.x == aLine->m_end.x )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-19 07:48:29 +00:00
|
|
|
colinear = true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
if( atan2( (double) ( m_start.x - m_end.x ), (double) ( m_start.y - m_end.y ) )
|
|
|
|
== atan2( (double) ( aLine->m_start.x - aLine->m_end.x ),
|
|
|
|
(double) ( aLine->m_start.y - aLine->m_end.y ) ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-19 07:48:29 +00:00
|
|
|
colinear = true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
// Make a segment which merge the 2 segments
|
|
|
|
// we must find the extremums
|
|
|
|
// i.e. the more to the left and to the right points, or
|
|
|
|
// for horizontal segments the uppermost and the lowest point
|
|
|
|
if( colinear )
|
|
|
|
{
|
|
|
|
static std::vector <wxPoint*> candidates;
|
|
|
|
candidates.clear();
|
|
|
|
candidates.push_back( &m_start );
|
|
|
|
candidates.push_back( &m_end );
|
|
|
|
candidates.push_back( &aLine->m_start );
|
|
|
|
candidates.push_back( &aLine->m_end );
|
|
|
|
sort( candidates.begin(), candidates.end(), sort_by_ends_position );
|
|
|
|
wxPoint tmp = *candidates[3];
|
|
|
|
m_start = *candidates[0];
|
|
|
|
m_end = tmp;
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
|
|
|
if( GetLayer() == LAYER_NOTES )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( ( GetLayer() == LAYER_BUS ) || ( GetLayer() == LAYER_WIRE ) )
|
|
|
|
{
|
2011-12-06 21:02:21 +00:00
|
|
|
DANGLING_END_ITEM item( (GetLayer() == LAYER_BUS) ? BUS_START_END : WIRE_START_END, this,
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start );
|
2011-02-28 18:36:19 +00:00
|
|
|
aItemList.push_back( item );
|
2011-12-06 21:02:21 +00:00
|
|
|
|
|
|
|
DANGLING_END_ITEM item1( (GetLayer() == LAYER_BUS) ? BUS_END_END : WIRE_END_END, this,
|
2011-12-07 20:19:29 +00:00
|
|
|
m_end );
|
2011-02-28 18:36:19 +00:00
|
|
|
aItemList.push_back( item1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
bool previousStartState = m_startIsDangling;
|
|
|
|
bool previousEndState = m_endIsDangling;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
m_startIsDangling = m_endIsDangling = true;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( GetLayer() == LAYER_WIRE )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( DANGLING_END_ITEM item, aItemList )
|
|
|
|
{
|
2011-12-06 21:02:21 +00:00
|
|
|
if( item.GetItem() == this )
|
2011-02-28 18:36:19 +00:00
|
|
|
continue;
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start == item.GetPosition() )
|
|
|
|
m_startIsDangling = false;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_end == item.GetPosition() )
|
|
|
|
m_endIsDangling = false;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( (m_startIsDangling == false) && (m_endIsDangling == false) )
|
2011-02-28 18:36:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( GetLayer() == LAYER_BUS || GetLayer() == LAYER_NOTES )
|
|
|
|
{
|
|
|
|
// Lines on the notes layer and the bus layer cannot be tested for dangling ends.
|
2011-12-07 20:19:29 +00:00
|
|
|
previousStartState = previousEndState = m_startIsDangling = m_endIsDangling = false;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
return ( previousStartState != m_startIsDangling ) || ( previousEndState != m_endIsDangling );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::IsSelectStateChanged( const wxRect& aRect )
|
|
|
|
{
|
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( aRect.Contains( m_start ) && aRect.Contains( m_end ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-03-30 19:55:26 +00:00
|
|
|
SetFlags( SELECTED );
|
|
|
|
ClearFlags( STARTPOINT | ENDPOINT );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( aRect.Contains( m_start ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-03-30 19:55:26 +00:00
|
|
|
ClearFlags( STARTPOINT );
|
|
|
|
SetFlags( SELECTED | ENDPOINT );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( aRect.Contains( m_end ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-03-30 19:55:26 +00:00
|
|
|
ClearFlags( ENDPOINT );
|
|
|
|
SetFlags( SELECTED | STARTPOINT );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-30 19:55:26 +00:00
|
|
|
ClearFlags( SELECTED | STARTPOINT | ENDPOINT );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return previousState != IsSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::IsConnectable() const
|
|
|
|
{
|
|
|
|
if( m_Layer == LAYER_WIRE || m_Layer == LAYER_BUS )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::GetConnectionPoints( vector< wxPoint >& aPoints ) const
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
aPoints.push_back( m_start );
|
|
|
|
aPoints.push_back( m_end );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_LINE::GetSelectMenuText() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString menuText, txtfmt, orient;
|
2011-10-11 13:38:13 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start.x == m_end.x )
|
2011-03-26 10:08:50 +00:00
|
|
|
orient = _("Vert.");
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_start.y == m_end.y )
|
2011-03-26 10:08:50 +00:00
|
|
|
orient = _("Horiz.");
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
switch( m_Layer )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
case LAYER_NOTES:
|
2011-03-26 10:08:50 +00:00
|
|
|
txtfmt = _( "%s Graphic Line from (%s,%s) to (%s,%s) " );
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
case LAYER_WIRE:
|
2011-03-26 10:08:50 +00:00
|
|
|
txtfmt = _( "%s Wire from (%s,%s) to (%s,%s)" );
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
case LAYER_BUS:
|
2011-03-26 10:08:50 +00:00
|
|
|
txtfmt = _( "%s Bus from (%s,%s) to (%s,%s)" );
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
default:
|
2011-06-17 13:24:22 +00:00
|
|
|
txtfmt += _( "%s Line on Unknown Layer from (%s,%s) to (%s,%s)" );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-26 10:08:50 +00:00
|
|
|
menuText.Printf( txtfmt, GetChars( orient ),
|
2012-04-13 18:51:24 +00:00
|
|
|
GetChars( CoordinateToString( m_start.x ) ),
|
|
|
|
GetChars( CoordinateToString( m_start.y ) ),
|
|
|
|
GetChars( CoordinateToString( m_end.x ) ),
|
|
|
|
GetChars( CoordinateToString( m_end.y ) ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
return menuText;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
BITMAP_DEF SCH_LINE::GetMenuImage() const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
2011-08-29 03:04:59 +00:00
|
|
|
return add_dashed_line_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
else if( m_Layer == LAYER_WIRE )
|
2011-08-29 03:04:59 +00:00
|
|
|
return add_line_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
return add_bus_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-11 13:38:13 +00:00
|
|
|
void SCH_LINE::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
|
|
|
// Net list item not required for graphic lines.
|
|
|
|
if( (GetLayer() != LAYER_BUS) && (GetLayer() != LAYER_WIRE) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT();
|
|
|
|
item->m_SheetList = *aSheetPath;
|
|
|
|
item->m_SheetListInclude = *aSheetPath;
|
|
|
|
item->m_Comp = (SCH_ITEM*) this;
|
2011-12-07 20:19:29 +00:00
|
|
|
item->m_Start = m_start;
|
|
|
|
item->m_End = m_end;
|
2011-10-11 13:38:13 +00:00
|
|
|
|
|
|
|
if( GetLayer() == LAYER_BUS )
|
|
|
|
{
|
|
|
|
item->m_Type = NET_BUS;
|
|
|
|
}
|
|
|
|
else /* WIRE */
|
|
|
|
{
|
|
|
|
item->m_Type = NET_SEGMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
aNetListItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
|
|
|
SCH_LINE* line = (SCH_LINE*) &aItem;
|
|
|
|
|
|
|
|
if( GetLength() != line->GetLength() )
|
|
|
|
return GetLength() < line->GetLength();
|
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start.x != line->m_start.x )
|
|
|
|
return m_start.x < line->m_start.x;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start.y != line->m_start.y )
|
|
|
|
return m_start.y < line->m_start.y;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_LINE::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_start, m_end, aAccuracy );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_LINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2011-02-28 18:36:19 +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;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const
|
|
|
|
{
|
|
|
|
if( m_Layer != LAYER_WIRE && m_Layer != LAYER_BUS )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return IsEndPoint( aPosition );
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_LINE::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( GetLayer() ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( GetPenSize() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetDash( true );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->MoveTo( m_start );
|
|
|
|
aPlotter->FinishTo( m_end );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetDash( false );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2011-10-19 20:32:21 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_LINE::SetPosition( const wxPoint& aPosition )
|
2011-10-19 20:32:21 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_end = m_end - ( m_start - aPosition );
|
|
|
|
m_start = aPosition;
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|