2011-10-11 13:38:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-11-16 11:45:53 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-11 13:38:13 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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>
|
2017-11-16 11:45:53 +00:00
|
|
|
#include <class_plotter.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>
|
2017-10-31 16:33:37 +00:00
|
|
|
#include <schframe.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_netlist_object.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2017-10-31 16:33:37 +00:00
|
|
|
#include <dialogs/dialog_edit_line_style.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
const enum wxPenStyle SCH_LINE::PenStyle[] =
|
|
|
|
{
|
|
|
|
[PLOTDASHTYPE_SOLID] = wxPENSTYLE_SOLID,
|
|
|
|
[PLOTDASHTYPE_DASH] = wxPENSTYLE_SHORT_DASH,
|
|
|
|
[PLOTDASHTYPE_DOT] = wxPENSTYLE_DOT,
|
|
|
|
[PLOTDASHTYPE_DASHDOT] = wxPENSTYLE_DOT_DASH
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
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;
|
2017-10-31 16:33:37 +00:00
|
|
|
m_size = 0;
|
2017-11-13 03:53:27 +00:00
|
|
|
m_style = -1;
|
2017-10-31 16:33:37 +00:00
|
|
|
m_color = COLOR4D::UNSPECIFIED;
|
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;
|
2017-10-31 16:33:37 +00:00
|
|
|
m_size = aLine.m_size;
|
|
|
|
m_style = aLine.m_style;
|
|
|
|
m_color = aLine.m_color;
|
2011-12-07 20:19:29 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
static const char* style_names[] =
|
|
|
|
{
|
|
|
|
"solid", "dashed", "dotted", "dash_dot", nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* SCH_LINE::GetLineStyleName( int aStyle )
|
|
|
|
{
|
|
|
|
const char * styleName = style_names[1];
|
|
|
|
|
|
|
|
switch( aStyle )
|
|
|
|
{
|
|
|
|
case PLOTDASHTYPE_SOLID:
|
|
|
|
styleName = style_names[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case PLOTDASHTYPE_DASH:
|
|
|
|
styleName = style_names[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLOTDASHTYPE_DOT:
|
|
|
|
styleName = style_names[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLOTDASHTYPE_DASHDOT:
|
|
|
|
styleName = style_names[3];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return styleName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_LINE::GetLineStyleInternalId( const wxString& aStyleName )
|
|
|
|
{
|
|
|
|
int id = -1; // Default style id
|
|
|
|
|
|
|
|
for( int ii = 0; style_names[ii] != nullptr; ii++ )
|
|
|
|
{
|
|
|
|
if( aStyleName == style_names[ii] )
|
|
|
|
{
|
|
|
|
id = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-31 16:33:37 +00:00
|
|
|
COLOR4D SCH_LINE::GetDefaultColor() const
|
|
|
|
{
|
|
|
|
return GetLayerColor( m_Layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::SetLineColor( const COLOR4D aColor )
|
|
|
|
{
|
|
|
|
if( aColor == GetDefaultColor() )
|
|
|
|
m_color = COLOR4D::UNSPECIFIED;
|
|
|
|
else
|
|
|
|
m_color = aColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
|
|
|
|
{
|
|
|
|
COLOR4D newColor(r, g, b, a);
|
|
|
|
|
2017-11-14 23:19:03 +00:00
|
|
|
if( newColor == GetDefaultColor() || newColor == COLOR4D::UNSPECIFIED )
|
2017-10-31 16:33:37 +00:00
|
|
|
m_color = COLOR4D::UNSPECIFIED;
|
|
|
|
else
|
2017-11-14 23:19:03 +00:00
|
|
|
{
|
|
|
|
// Eeschema does not allow alpha channel in colors
|
|
|
|
newColor.a = 1.0;
|
2017-10-31 16:33:37 +00:00
|
|
|
m_color = newColor;
|
2017-11-14 23:19:03 +00:00
|
|
|
}
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COLOR4D SCH_LINE::GetLineColor() const
|
|
|
|
{
|
|
|
|
if( m_color == COLOR4D::UNSPECIFIED )
|
|
|
|
return GetLayerColor( m_Layer );
|
|
|
|
|
|
|
|
return m_color;
|
|
|
|
}
|
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
int SCH_LINE::GetDefaultStyle() const
|
2017-10-31 16:33:37 +00:00
|
|
|
{
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
2017-11-13 03:53:27 +00:00
|
|
|
return PLOTDASHTYPE_DASH;
|
2017-10-31 16:33:37 +00:00
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
return PLOTDASHTYPE_SOLID;
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::SetLineStyle( const int aStyle )
|
|
|
|
{
|
|
|
|
if( aStyle == GetDefaultStyle() )
|
2017-11-13 03:53:27 +00:00
|
|
|
m_style = -1;
|
2017-10-31 16:33:37 +00:00
|
|
|
else
|
|
|
|
m_style = aStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
int SCH_LINE::GetLineStyle() const
|
2017-10-31 16:33:37 +00:00
|
|
|
{
|
2017-11-13 03:53:27 +00:00
|
|
|
if( m_style >= 0 )
|
|
|
|
return m_style;
|
2017-10-31 16:33:37 +00:00
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
return GetDefaultStyle();
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_LINE::GetDefaultWidth() const
|
|
|
|
{
|
|
|
|
if( m_Layer == LAYER_BUS )
|
|
|
|
return GetDefaultBusThickness();
|
|
|
|
|
|
|
|
return GetDefaultLineThickness();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::SetLineWidth( const int aSize )
|
|
|
|
{
|
|
|
|
if( aSize == GetDefaultWidth() )
|
|
|
|
m_size = 0;
|
|
|
|
else
|
|
|
|
m_size = aSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
int SCH_LINE::GetPenSize() const
|
|
|
|
{
|
2017-10-31 16:33:37 +00:00
|
|
|
if( m_size > 0 )
|
|
|
|
return m_size;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
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,
|
2017-02-20 16:57:41 +00:00
|
|
|
GR_DRAWMODE DrawMode, COLOR4D Color )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color;
|
2011-02-28 18:36:19 +00:00
|
|
|
int width = GetPenSize();
|
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
if( Color != COLOR4D::UNSPECIFIED )
|
2011-02-28 18:36:19 +00:00
|
|
|
color = Color;
|
2017-10-31 16:33:37 +00:00
|
|
|
else if( m_color != COLOR4D::UNSPECIFIED )
|
|
|
|
color = m_color;
|
2011-02-28 18:36:19 +00:00
|
|
|
else
|
2016-11-16 10:07:02 +00:00
|
|
|
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : 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;
|
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color,
|
|
|
|
PenStyle[ GetLineStyle() ] );
|
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
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
MIRROR( m_start.y, aXaxis_position );
|
|
|
|
MIRROR( 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
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
MIRROR( m_start.x, aYaxis_position );
|
|
|
|
MIRROR( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
|
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
auto less = []( const wxPoint& lhs, const wxPoint& rhs ) -> bool
|
|
|
|
{
|
|
|
|
if( lhs.x == rhs.x )
|
|
|
|
return lhs.y < rhs.y;
|
|
|
|
return lhs.x < rhs.x;
|
|
|
|
};
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
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;
|
|
|
|
|
2017-11-17 16:35:20 +00:00
|
|
|
SCH_LINE leftmost = SCH_LINE( *aLine );
|
|
|
|
SCH_LINE rightmost = SCH_LINE( *this );
|
|
|
|
|
|
|
|
// We place the start to the left and below the end of both lines
|
|
|
|
if( leftmost.m_start != std::min( { leftmost.m_start, leftmost.m_end }, less ) )
|
|
|
|
std::swap( leftmost.m_start, leftmost.m_end );
|
|
|
|
if( rightmost.m_start != std::min( { rightmost.m_start, rightmost.m_end }, less ) )
|
|
|
|
std::swap( rightmost.m_start, rightmost.m_end );
|
|
|
|
|
|
|
|
// -leftmost is the line that starts farthest to the left
|
|
|
|
// -other is the line that is _not_ leftmost
|
|
|
|
// -rightmost is the line that ends farthest to the right. This may or
|
|
|
|
// may not be 'other' as the second line may be completely covered by
|
|
|
|
// the first.
|
|
|
|
if( less( rightmost.m_start, leftmost.m_start ) )
|
|
|
|
std::swap( leftmost, rightmost );
|
|
|
|
|
|
|
|
SCH_LINE other = SCH_LINE( rightmost );
|
|
|
|
|
|
|
|
if( less( rightmost.m_end, leftmost.m_end ) )
|
|
|
|
rightmost = leftmost;
|
|
|
|
|
|
|
|
// If we end one before the beginning of the other, no overlap is possible
|
|
|
|
if( less( leftmost.m_end, other.m_start ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
return false;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
|
|
|
// Search for a common end:
|
|
|
|
if( ( leftmost.m_start == other.m_start )
|
|
|
|
&& ( leftmost.m_end == other.m_end ) ) // Trivial case
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
m_start = leftmost.m_start;
|
|
|
|
m_end = leftmost.m_end;
|
|
|
|
return true;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
bool colinear = false;
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
/* Test alignment: */
|
2017-11-17 16:35:20 +00:00
|
|
|
if( ( leftmost.m_start.y == leftmost.m_end.y )
|
|
|
|
&& ( other.m_start.y == other.m_end.y ) ) // Horizontal segment
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
colinear = ( leftmost.m_start.y == other.m_start.y );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
else if( ( leftmost.m_start.x == leftmost.m_end.x )
|
|
|
|
&& ( other.m_start.x == other.m_end.x ) ) // Vertical segment
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
colinear = ( leftmost.m_start.x == other.m_start.x );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
// We use long long here to avoid overflow -- it enforces promotion
|
|
|
|
// Don't use double as we need to make a direct comparison
|
|
|
|
// The slope of the left-most line is dy/dx. Then we check that the slope
|
|
|
|
// from the left most start to the right most start is the same as well as
|
|
|
|
// the slope from the left most start to right most end.
|
|
|
|
long long dx = leftmost.m_end.x - leftmost.m_start.x;
|
|
|
|
long long dy = leftmost.m_end.y - leftmost.m_start.y;
|
|
|
|
colinear = ( ( ( other.m_start.y - leftmost.m_start.y ) * dx ==
|
|
|
|
( other.m_start.x - leftmost.m_start.x ) * dy ) &&
|
|
|
|
( ( other.m_end.y - leftmost.m_start.y ) * dx ==
|
|
|
|
( other.m_end.x - leftmost.m_start.x ) * dy ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 16:35:20 +00:00
|
|
|
// Make a new segment that merges the 2 segments
|
2012-03-19 07:48:29 +00:00
|
|
|
if( colinear )
|
|
|
|
{
|
2017-11-17 16:35:20 +00:00
|
|
|
m_start = leftmost.m_start;
|
|
|
|
m_end = rightmost.m_end;
|
2012-03-19 07:48:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
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 )
|
|
|
|
{
|
2016-06-29 20:07:55 +00:00
|
|
|
for( DANGLING_END_ITEM item : aItemList )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-06 21:02:21 +00:00
|
|
|
if( item.GetItem() == this )
|
2011-02-28 18:36:19 +00:00
|
|
|
continue;
|
2015-06-08 00:07:42 +00:00
|
|
|
|
|
|
|
if( item.GetType() == NO_CONNECT_END )
|
|
|
|
continue;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-13 16:27:30 +00:00
|
|
|
void SCH_LINE::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
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 )
|
2017-11-18 13:10:32 +00:00
|
|
|
orient = _( "Vert." );
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_start.y == m_end.y )
|
2017-11-18 13:10:32 +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:
|
2017-06-18 19:23:21 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:09:57 +00:00
|
|
|
void SCH_LINE::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
2011-10-11 13:38:13 +00:00
|
|
|
{
|
|
|
|
// Net list item not required for graphic lines.
|
|
|
|
if( (GetLayer() != LAYER_BUS) && (GetLayer() != LAYER_WIRE) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
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
|
|
|
{
|
2014-10-28 12:03:50 +00:00
|
|
|
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
2012-03-15 14:31:16 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2014-10-28 12:03:50 +00:00
|
|
|
if ( aAccuracy )
|
2016-11-16 10:07:02 +00:00
|
|
|
rect.Inflate( aAccuracy );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( aContained )
|
2014-10-28 12:03:50 +00:00
|
|
|
return rect.Contains( m_start ) && rect.Contains( m_end );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2014-10-28 12:03:50 +00:00
|
|
|
return rect.Intersects( m_start, m_end );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 16:33:37 +00:00
|
|
|
void SCH_LINE::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
SCH_LINE* item = (SCH_LINE*) aItem;
|
|
|
|
|
|
|
|
std::swap( m_Layer, item->m_Layer );
|
|
|
|
|
|
|
|
std::swap( m_start, item->m_start );
|
|
|
|
std::swap( m_end, item->m_end );
|
|
|
|
std::swap( m_startIsDangling, item->m_startIsDangling );
|
|
|
|
std::swap( m_endIsDangling, item->m_endIsDangling );
|
|
|
|
std::swap( m_style, item->m_style );
|
|
|
|
std::swap( m_size, item->m_size );
|
|
|
|
std::swap( m_color, item->m_color );
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-11-13 03:53:27 +00:00
|
|
|
if( m_color != COLOR4D::UNSPECIFIED )
|
|
|
|
aPlotter->SetColor( m_color );
|
|
|
|
else
|
|
|
|
aPlotter->SetColor( GetLayerColor( GetLayer() ) );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( GetPenSize() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
aPlotter->SetDash( GetLineStyle() );
|
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
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
aPlotter->SetDash( 0 );
|
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
|
|
|
}
|
2017-07-13 12:42:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxPoint SCH_LINE::MidPoint()
|
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
return wxPoint( ( m_start.x + m_end.x ) / 2, ( m_start.y + m_end.y ) / 2 );
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
2017-10-31 16:33:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDIT_FRAME::EditLine( SCH_LINE* aLine, bool aRedraw )
|
|
|
|
{
|
|
|
|
if( aLine == NULL )
|
|
|
|
return wxID_CANCEL;
|
|
|
|
|
|
|
|
// We purposely disallow editing everything except graphic lines
|
|
|
|
if( aLine->GetLayer() != LAYER_NOTES )
|
|
|
|
return wxID_CANCEL;
|
|
|
|
|
|
|
|
DIALOG_EDIT_LINE_STYLE dlg( this );
|
2017-11-16 23:56:41 +00:00
|
|
|
wxString units = GetAbbreviatedUnitsLabel( g_UserUnit );
|
2017-10-31 16:33:37 +00:00
|
|
|
int old_style = aLine->GetLineStyle();
|
|
|
|
int old_width = aLine->GetPenSize();
|
|
|
|
COLOR4D old_color = aLine->GetLineColor();
|
|
|
|
|
|
|
|
dlg.SetDefaultStyle( aLine->GetDefaultStyle() );
|
|
|
|
dlg.SetDefaultWidth( StringFromValue( g_UserUnit, aLine->GetDefaultWidth(), false ) );
|
|
|
|
dlg.SetDefaultColor( aLine->GetDefaultColor() );
|
|
|
|
|
|
|
|
dlg.SetWidth( StringFromValue( g_UserUnit, old_width, false ) );
|
|
|
|
dlg.SetStyle( old_style );
|
|
|
|
dlg.SetLineWidthUnits( units );
|
2017-11-14 23:19:03 +00:00
|
|
|
dlg.SetColor( old_color, true );
|
2017-10-31 16:33:37 +00:00
|
|
|
|
|
|
|
dlg.Layout();
|
|
|
|
dlg.Fit();
|
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return wxID_CANCEL;
|
|
|
|
|
|
|
|
int new_width = std::max( 1, ValueFromString( dlg.GetWidth() ) );
|
|
|
|
int new_style = dlg.GetStyle();
|
|
|
|
COLOR4D new_color = dlg.GetColor();
|
|
|
|
|
|
|
|
if( new_width != old_width || new_style != old_style || new_color != old_color )
|
|
|
|
{
|
|
|
|
SaveCopyInUndoList( (SCH_ITEM*) aLine, UR_CHANGED );
|
|
|
|
aLine->SetLineWidth( new_width );
|
|
|
|
aLine->SetLineStyle( new_style );
|
|
|
|
aLine->SetLineColor( new_color );
|
|
|
|
|
|
|
|
OnModify();
|
|
|
|
if( aRedraw )
|
|
|
|
m_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxID_OK;
|
|
|
|
}
|