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
|
2019-04-04 22:49:49 +00:00
|
|
|
* Copyright (C) 1992-2019 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>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2018-01-28 18:12:26 +00:00
|
|
|
#include <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 <sch_line.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <netlist_object.h>
|
2018-09-04 16:12:15 +00:00
|
|
|
#include <sch_view.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2017-12-06 02:42:37 +00:00
|
|
|
|
|
|
|
static wxPenStyle getwxPenStyle( PlotDashType aType )
|
2017-11-13 03:53:27 +00:00
|
|
|
{
|
2017-12-06 02:42:37 +00:00
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case PLOTDASHTYPE_SOLID: return wxPENSTYLE_SOLID;
|
|
|
|
case PLOTDASHTYPE_DASH: return wxPENSTYLE_SHORT_DASH;
|
|
|
|
case PLOTDASHTYPE_DOT: return wxPENSTYLE_DOT;
|
|
|
|
case PLOTDASHTYPE_DASHDOT: return wxPENSTYLE_DOT_DASH;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFAIL_MSG( "Unhandled PlotDashType" );
|
|
|
|
return wxPENSTYLE_SOLID;
|
|
|
|
}
|
2017-11-13 03:53:27 +00:00
|
|
|
|
|
|
|
|
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;
|
2018-10-29 18:11:04 +00:00
|
|
|
m_startIsDangling = aLine.m_startIsDangling;
|
|
|
|
m_endIsDangling = aLine.m_endIsDangling;
|
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 )
|
|
|
|
{
|
2019-04-27 12:09:04 +00:00
|
|
|
if( aOffset != wxPoint( 0, 0 ) )
|
|
|
|
{
|
|
|
|
m_start += aOffset;
|
|
|
|
m_end += aOffset;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::MoveStart( const wxPoint& aOffset )
|
|
|
|
{
|
|
|
|
if( aOffset != wxPoint( 0, 0 ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_start += aOffset;
|
2011-02-28 18:36:19 +00:00
|
|
|
SetModified();
|
|
|
|
}
|
2019-04-27 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2019-04-27 12:09:04 +00:00
|
|
|
void SCH_LINE::MoveEnd( const wxPoint& aOffset )
|
|
|
|
{
|
|
|
|
if( aOffset != wxPoint( 0, 0 ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
2019-08-03 19:44:20 +00:00
|
|
|
void SCH_LINE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 2;
|
|
|
|
aLayers[0] = m_Layer;
|
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2019-06-30 10:12:18 +00:00
|
|
|
else if( m_Layer == LAYER_WIRE )
|
|
|
|
return GetDefaultWireThickness();
|
2017-10-31 16:33:37 +00:00
|
|
|
|
|
|
|
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;
|
2019-06-30 10:12:18 +00:00
|
|
|
|
|
|
|
return GetDefaultWidth();
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void SCH_LINE::Print( wxDC* DC, const wxPoint& offset )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2019-04-04 22:49:49 +00:00
|
|
|
COLOR4D color = ( m_color != COLOR4D::UNSPECIFIED ) ? m_color : GetLayerColor( m_Layer );
|
|
|
|
int width = GetPenSize();
|
2011-12-07 20:19:29 +00:00
|
|
|
wxPoint start = m_start;
|
|
|
|
wxPoint end = m_end;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
GRLine( nullptr, DC, start.x, start.y, end.x, end.y, width, color,
|
2017-12-06 02:42:37 +00:00
|
|
|
getwxPenStyle( (PlotDashType) GetLineStyle() ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-03 22:46:44 +00:00
|
|
|
void SCH_LINE::RotateStart( wxPoint aPosition )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_start, aPosition, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::RotateEnd( wxPoint aPosition )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_end, aPosition, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 21:38:57 +00:00
|
|
|
bool SCH_LINE::IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
wxPoint first;
|
|
|
|
wxPoint second;
|
|
|
|
|
|
|
|
if( m_start == aPosition )
|
|
|
|
first = m_end - aPosition;
|
|
|
|
else if( m_end == aPosition )
|
|
|
|
first = m_start - aPosition;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aLine->m_start == aPosition )
|
|
|
|
second = aLine->m_end - aPosition;
|
|
|
|
else if( aLine->m_end == aPosition )
|
|
|
|
second = aLine->m_start - aPosition;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2019-06-19 10:31:21 +00:00
|
|
|
return ( sign( first.x ) == sign( second.x ) && sign( first.y ) == sign( second.y ) );
|
2017-10-16 21:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::IsParallel( SCH_LINE* aLine )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false,
|
|
|
|
wxT( "Cannot test line segment for overlap." ) );
|
|
|
|
|
|
|
|
wxPoint firstSeg = m_end - m_start;
|
|
|
|
wxPoint secondSeg = aLine->m_end - aLine->m_start;
|
|
|
|
|
|
|
|
// Use long long here to avoid overflow in calculations
|
|
|
|
return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
EDA_ITEM* SCH_LINE::MergeOverlap( SCH_LINE* aLine )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
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;
|
|
|
|
};
|
2019-04-03 02:46:22 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, NULL,
|
2011-02-28 18:36:19 +00:00
|
|
|
wxT( "Cannot test line segment for overlap." ) );
|
|
|
|
|
|
|
|
if( this == aLine || GetLayer() != aLine->GetLayer() )
|
2017-11-27 19:27:24 +00:00
|
|
|
return NULL;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2019-04-03 02:46:22 +00:00
|
|
|
auto leftmost_start = aLine->m_start;
|
|
|
|
auto leftmost_end = aLine->m_end;
|
|
|
|
|
|
|
|
auto rightmost_start = m_start;
|
|
|
|
auto rightmost_end = m_end;
|
2017-11-17 16:35:20 +00:00
|
|
|
|
|
|
|
// We place the start to the left and below the end of both lines
|
2019-04-03 02:46:22 +00:00
|
|
|
if( leftmost_start != std::min( { leftmost_start, leftmost_end }, less ) )
|
|
|
|
std::swap( leftmost_start, leftmost_end );
|
|
|
|
if( rightmost_start != std::min( { rightmost_start, rightmost_end }, less ) )
|
|
|
|
std::swap( rightmost_start, rightmost_end );
|
2017-11-17 16:35:20 +00:00
|
|
|
|
|
|
|
// -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.
|
2019-04-03 02:46:22 +00:00
|
|
|
if( less( rightmost_start, leftmost_start ) )
|
|
|
|
{
|
|
|
|
std::swap( leftmost_start, rightmost_start );
|
|
|
|
std::swap( leftmost_end, rightmost_end );
|
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
2019-04-03 02:46:22 +00:00
|
|
|
auto other_start = rightmost_start;
|
|
|
|
auto other_end = rightmost_end;
|
2017-11-17 16:35:20 +00:00
|
|
|
|
2019-04-03 02:46:22 +00:00
|
|
|
if( less( rightmost_end, leftmost_end ) )
|
|
|
|
{
|
|
|
|
rightmost_start = leftmost_start;
|
|
|
|
rightmost_end = leftmost_end;
|
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
|
|
|
// If we end one before the beginning of the other, no overlap is possible
|
2019-04-03 02:46:22 +00:00
|
|
|
if( less( leftmost_end, other_start ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2017-11-27 19:27:24 +00:00
|
|
|
return NULL;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
|
|
|
// Search for a common end:
|
2019-04-03 02:46:22 +00:00
|
|
|
if( ( leftmost_start == other_start ) &&
|
|
|
|
( leftmost_end == other_end ) ) // Trivial case
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2019-04-03 20:26:43 +00:00
|
|
|
auto ret = new SCH_LINE( *aLine );
|
|
|
|
ret->SetStartPoint( leftmost_start );
|
2019-04-03 02:46:22 +00:00
|
|
|
ret->SetEndPoint( leftmost_end );
|
|
|
|
return ret;
|
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: */
|
2019-04-03 02:46:22 +00:00
|
|
|
if( ( leftmost_start.y == leftmost_end.y ) &&
|
|
|
|
( other_start.y == other_end.y ) ) // Horizontal segment
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2019-04-03 02:46:22 +00:00
|
|
|
colinear = ( leftmost_start.y == other_start.y );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2019-04-03 02:46:22 +00:00
|
|
|
else if( ( leftmost_start.x == leftmost_end.x ) &&
|
|
|
|
( other_start.x == other_end.x ) ) // Vertical segment
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2019-04-03 02:46:22 +00:00
|
|
|
colinear = ( leftmost_start.x == other_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.
|
2019-04-03 02:46:22 +00:00
|
|
|
long long dx = leftmost_end.x - leftmost_start.x;
|
|
|
|
long long dy = leftmost_end.y - leftmost_start.y;
|
|
|
|
colinear = ( ( ( other_start.y - leftmost_start.y ) * dx ==
|
|
|
|
( other_start.x - leftmost_start.x ) * dy ) &&
|
|
|
|
( ( other_end.y - leftmost_start.y ) * dx ==
|
|
|
|
( other_end.x - leftmost_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 )
|
|
|
|
{
|
2019-04-03 02:46:22 +00:00
|
|
|
leftmost_end = rightmost_end;
|
|
|
|
|
2019-04-03 20:26:43 +00:00
|
|
|
auto ret = new SCH_LINE( *aLine );
|
|
|
|
ret->SetStartPoint( leftmost_start );
|
2019-04-03 02:46:22 +00:00
|
|
|
ret->SetEndPoint( leftmost_end );
|
|
|
|
return ret;
|
2012-03-19 07:48:29 +00:00
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
return NULL;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-29 18:11:04 +00:00
|
|
|
bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
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
|
|
|
|
2018-11-27 14:43:04 +00:00
|
|
|
if( item.GetType() == BUS_START_END ||
|
2017-12-01 01:21:23 +00:00
|
|
|
item.GetType() == BUS_END_END ||
|
|
|
|
item.GetType() == BUS_ENTRY_END )
|
2015-06-08 00:07:42 +00:00
|
|
|
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::IsConnectable() const
|
|
|
|
{
|
|
|
|
if( m_Layer == LAYER_WIRE || m_Layer == LAYER_BUS )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-19 17:45:56 +00:00
|
|
|
bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2017-12-19 17:45:56 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return aItem->GetLayer() == m_Layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-11 20:17:05 +00:00
|
|
|
void SCH_LINE::GetSelectedPoints( std::vector< wxPoint >& aPoints ) const
|
|
|
|
{
|
|
|
|
if( m_Flags & STARTPOINT )
|
|
|
|
aPoints.push_back( m_start );
|
|
|
|
|
|
|
|
if( m_Flags & ENDPOINT )
|
|
|
|
aPoints.push_back( m_end );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_LINE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString 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 )
|
2018-11-11 09:46:26 +00:00
|
|
|
orient = _( "Vertical" );
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_start.y == m_end.y )
|
2018-11-11 09:46:26 +00:00
|
|
|
orient = _( "Horizontal" );
|
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
|
|
|
{
|
2019-06-19 10:31:21 +00:00
|
|
|
case LAYER_NOTES: txtfmt = _( "%s Graphic Line from (%s, %s) to (%s, %s)" ); break;
|
|
|
|
case LAYER_WIRE: txtfmt = _( "%s Wire from (%s, %s) to (%s, %s)" ); break;
|
|
|
|
case LAYER_BUS: txtfmt = _( "%s Bus from (%s, %s) to (%s, %s)" ); break;
|
|
|
|
default: txtfmt = _( "%s Line on Unknown Layer from (%s, %s) to (%s, %s)" ); break;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( txtfmt,
|
|
|
|
orient,
|
|
|
|
MessageTextFromValue( aUnits, m_start.x ),
|
|
|
|
MessageTextFromValue( aUnits, m_start.y ),
|
|
|
|
MessageTextFromValue( aUnits, m_end.x ),
|
|
|
|
MessageTextFromValue( aUnits, m_end.y ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-04-30 00:46:21 +00:00
|
|
|
// Insure minimum accuracy
|
|
|
|
if( aAccuracy == 0 )
|
2019-05-08 02:51:46 +00:00
|
|
|
aAccuracy = ( GetPenSize() / 2 ) + 4;
|
2019-04-30 00:46:21 +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-11-27 19:27:24 +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
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
void SCH_LINE::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( GetLayer() )
|
|
|
|
{
|
2019-06-19 10:31:21 +00:00
|
|
|
case LAYER_WIRE: msg = _( "Net Wire" ); break;
|
|
|
|
case LAYER_BUS: msg = _( "Bus Wire" ); break;
|
|
|
|
default: msg = _( "Graphical" ); return;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Line Type" ), msg, DARKCYAN ) );
|
|
|
|
|
|
|
|
if( auto conn = Connection( *g_CurrentSheet ) )
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
|
|
|
conn->AppendDebugInfoToMsgPanel( aList );
|
|
|
|
|
|
|
|
msg.Printf( "%zu", m_connected_items.size() );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Connections" ), msg, BROWN ) );
|
|
|
|
#else
|
|
|
|
conn->AppendInfoToMsgPanel( aList );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|