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
|
2022-01-28 22:51:34 +00:00
|
|
|
* Copyright (C) 1992-2022 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
|
|
|
|
*/
|
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2022-08-14 11:03:18 +00:00
|
|
|
#include <string_utils.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2020-05-12 14:02:24 +00:00
|
|
|
#include <sch_painter.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_line.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-05-20 03:39:15 +00:00
|
|
|
#include <schematic.h>
|
2021-11-24 13:19:50 +00:00
|
|
|
#include <connection_graph.h>
|
2020-07-07 10:17:30 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2021-02-05 15:46:36 +00:00
|
|
|
#include <board_item.h>
|
2017-12-06 02:42:37 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-01-04 01:00:40 +00:00
|
|
|
SCH_LINE::SCH_LINE( const VECTOR2I& pos, int layer ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, SCH_LINE_T )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
m_start = pos;
|
|
|
|
m_end = pos;
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke.SetWidth( 0 );
|
2020-10-16 12:43:43 +00:00
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
switch( layer )
|
|
|
|
{
|
2021-08-25 18:36:37 +00:00
|
|
|
default: m_layer = LAYER_NOTES; break;
|
2020-11-14 14:29:11 +00:00
|
|
|
case LAYER_WIRE: m_layer = LAYER_WIRE; break;
|
2021-08-25 18:36:37 +00:00
|
|
|
case LAYER_BUS: m_layer = LAYER_BUS; break;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2021-09-24 23:30:26 +00:00
|
|
|
|
|
|
|
if( layer == LAYER_NOTES )
|
|
|
|
m_startIsDangling = m_endIsDangling = true;
|
|
|
|
else
|
|
|
|
m_startIsDangling = m_endIsDangling = false;
|
2021-11-24 13:19:50 +00:00
|
|
|
|
|
|
|
if( layer == LAYER_WIRE )
|
2022-09-16 23:42:20 +00:00
|
|
|
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_WIRE_WIDTH_MILS );
|
2021-11-24 13:19:50 +00:00
|
|
|
else if( layer == LAYER_BUS )
|
2022-09-16 23:42:20 +00:00
|
|
|
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_BUS_WIDTH_MILS );
|
2021-11-24 13:19:50 +00:00
|
|
|
else
|
2022-09-16 23:42:20 +00:00
|
|
|
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
|
2021-11-24 13:19:50 +00:00
|
|
|
|
2022-06-28 01:12:13 +00:00
|
|
|
m_lastResolvedLineStyle = PLOT_DASH_TYPE::SOLID;
|
2021-11-24 13:19:50 +00:00
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke = aLine.m_stroke;
|
2018-10-29 18:11:04 +00:00
|
|
|
m_startIsDangling = aLine.m_startIsDangling;
|
|
|
|
m_endIsDangling = aLine.m_endIsDangling;
|
2021-11-24 13:19:50 +00:00
|
|
|
|
|
|
|
m_lastResolvedLineStyle = aLine.m_lastResolvedLineStyle;
|
|
|
|
m_lastResolvedWidth = aLine.m_lastResolvedWidth;
|
|
|
|
m_lastResolvedColor = aLine.m_lastResolvedColor;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 08:42:15 +00:00
|
|
|
wxString SCH_LINE::GetNetname( const SCH_SHEET_PATH& aSheet )
|
|
|
|
{
|
|
|
|
std::list<const SCH_LINE *> checkedLines;
|
|
|
|
checkedLines.push_back(this);
|
|
|
|
return FindWireSegmentNetNameRecursive( this, checkedLines, aSheet );
|
|
|
|
}
|
|
|
|
|
2022-06-28 01:12:13 +00:00
|
|
|
wxString SCH_LINE::FindWireSegmentNetNameRecursive( SCH_LINE *line,
|
|
|
|
std::list<const SCH_LINE *> &checkedLines,
|
2022-05-02 08:42:15 +00:00
|
|
|
const SCH_SHEET_PATH& aSheet ) const
|
|
|
|
{
|
|
|
|
for ( auto connected : line->ConnectedItems( aSheet ) )
|
|
|
|
{
|
|
|
|
if( connected->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
if( std::find(checkedLines.begin(), checkedLines.end(), connected ) == checkedLines.end() )
|
|
|
|
{
|
2022-06-28 01:12:13 +00:00
|
|
|
SCH_LINE* connectedLine = static_cast<SCH_LINE*>( connected );
|
2022-05-02 08:42:15 +00:00
|
|
|
checkedLines.push_back( connectedLine );
|
2022-06-28 01:12:13 +00:00
|
|
|
|
|
|
|
wxString netName = FindWireSegmentNetNameRecursive( connectedLine, checkedLines,
|
|
|
|
aSheet );
|
|
|
|
|
|
|
|
if( !netName.IsEmpty() )
|
2022-05-02 08:42:15 +00:00
|
|
|
return netName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( connected->Type() == SCH_LABEL_T
|
|
|
|
|| connected->Type() == SCH_GLOBAL_LABEL_T
|
|
|
|
|| connected->Type() == SCH_DIRECTIVE_LABEL_T)
|
|
|
|
{
|
|
|
|
return static_cast<SCH_TEXT*>( connected )->GetText();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
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 );
|
|
|
|
}
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::Move( const VECTOR2I& aOffset )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
if( aOffset != VECTOR2I( 0, 0 ) )
|
2019-04-27 12:09:04 +00:00
|
|
|
{
|
|
|
|
m_start += aOffset;
|
|
|
|
m_end += aOffset;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::MoveStart( const VECTOR2I& aOffset )
|
2019-04-27 12:09:04 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
if( aOffset != VECTOR2I( 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
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::MoveEnd( const VECTOR2I& aOffset )
|
2019-04-27 12:09:04 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
if( aOffset != VECTOR2I( 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()
|
2020-11-14 14:29:11 +00:00
|
|
|
<< " 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
|
|
|
|
{
|
2021-12-06 18:50:00 +00:00
|
|
|
aCount = 3;
|
|
|
|
aLayers[0] = LAYER_DANGLING;
|
|
|
|
aLayers[1] = m_layer;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2019-08-03 19:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_LINE::GetBoundingBox() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
int width = m_stroke.GetWidth() / 2;
|
|
|
|
int extra = m_stroke.GetWidth() & 0x1;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-08-31 09:15:42 +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
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
int xmax = std::max( m_start.x, m_end.x ) + width + extra;
|
|
|
|
int ymax = std::max( m_start.y, m_end.y ) + width + extra;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I ret( VECTOR2I( xmin, ymin ), VECTOR2I( xmax - xmin, ymax - ymin ) );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-17 19:59:27 +00:00
|
|
|
void SCH_LINE::SetLineColor( const COLOR4D& aColor )
|
2017-10-31 16:33:37 +00:00
|
|
|
{
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke.SetColor( aColor );
|
2022-03-16 13:43:19 +00:00
|
|
|
m_lastResolvedColor = GetLineColor();
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
|
|
|
|
{
|
|
|
|
COLOR4D newColor(r, g, b, a);
|
|
|
|
|
2020-02-03 16:46:58 +00:00
|
|
|
if( newColor == COLOR4D::UNSPECIFIED )
|
2021-11-24 13:19:50 +00:00
|
|
|
{
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
2021-11-24 13:19:50 +00:00
|
|
|
}
|
2017-10-31 16:33:37 +00:00
|
|
|
else
|
2017-11-14 23:19:03 +00:00
|
|
|
{
|
|
|
|
// Eeschema does not allow alpha channel in colors
|
|
|
|
newColor.a = 1.0;
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke.SetColor( newColor );
|
2017-11-14 23:19:03 +00:00
|
|
|
}
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COLOR4D SCH_LINE::GetLineColor() const
|
|
|
|
{
|
2020-08-24 17:00:19 +00:00
|
|
|
if( m_stroke.GetColor() != COLOR4D::UNSPECIFIED )
|
2021-11-24 13:19:50 +00:00
|
|
|
m_lastResolvedColor = m_stroke.GetColor();
|
2022-08-14 11:03:18 +00:00
|
|
|
else if( !IsConnectable() )
|
2022-03-14 00:17:37 +00:00
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2022-08-14 11:03:18 +00:00
|
|
|
else if( !IsConnectivityDirty() )
|
|
|
|
m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
return m_lastResolvedColor;
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 16:46:58 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
void SCH_LINE::SetLineStyle( const int aStyleId )
|
|
|
|
{
|
|
|
|
SetLineStyle( static_cast<PLOT_DASH_TYPE>( aStyleId ) );
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
void SCH_LINE::SetLineStyle( const PLOT_DASH_TYPE aStyle )
|
2017-10-31 16:33:37 +00:00
|
|
|
{
|
2022-05-02 16:17:07 +00:00
|
|
|
m_stroke.SetPlotStyle( aStyle );
|
2022-03-16 13:43:19 +00:00
|
|
|
m_lastResolvedLineStyle = GetLineStyle();
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
PLOT_DASH_TYPE SCH_LINE::GetLineStyle() const
|
2017-10-31 16:33:37 +00:00
|
|
|
{
|
2020-10-16 12:43:43 +00:00
|
|
|
if( m_stroke.GetPlotStyle() != PLOT_DASH_TYPE::DEFAULT )
|
|
|
|
return m_stroke.GetPlotStyle();
|
2017-10-31 16:33:37 +00:00
|
|
|
|
2022-06-28 01:12:13 +00:00
|
|
|
return PLOT_DASH_TYPE::SOLID;
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-08 18:29:16 +00:00
|
|
|
PLOT_DASH_TYPE SCH_LINE::GetEffectiveLineStyle() const
|
|
|
|
{
|
2020-10-16 12:43:43 +00:00
|
|
|
if( m_stroke.GetPlotStyle() != PLOT_DASH_TYPE::DEFAULT )
|
2021-11-24 13:19:50 +00:00
|
|
|
m_lastResolvedLineStyle = m_stroke.GetPlotStyle();
|
2022-08-14 11:03:18 +00:00
|
|
|
else if( !IsConnectable() )
|
2022-06-28 01:12:13 +00:00
|
|
|
m_lastResolvedLineStyle = PLOT_DASH_TYPE::SOLID;
|
2022-08-14 11:03:18 +00:00
|
|
|
else if( !IsConnectivityDirty() )
|
|
|
|
m_lastResolvedLineStyle = (PLOT_DASH_TYPE) GetEffectiveNetClass()->GetLineStyle();
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
return m_lastResolvedLineStyle;
|
2020-07-08 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-31 16:33:37 +00:00
|
|
|
void SCH_LINE::SetLineWidth( const int aSize )
|
|
|
|
{
|
2020-06-17 19:59:27 +00:00
|
|
|
m_stroke.SetWidth( aSize );
|
2022-03-16 13:43:19 +00:00
|
|
|
m_lastResolvedWidth = GetPenWidth();
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int SCH_LINE::GetPenWidth() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
SCHEMATIC* schematic = Schematic();
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
switch ( m_layer )
|
2020-08-09 20:51:40 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
if( m_stroke.GetWidth() > 0 )
|
|
|
|
return m_stroke.GetWidth();
|
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( schematic )
|
|
|
|
return schematic->Settings().m_DefaultLineWidth;
|
2020-08-09 20:51:40 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
|
2020-08-09 20:51:40 +00:00
|
|
|
|
|
|
|
case LAYER_WIRE:
|
|
|
|
if( m_stroke.GetWidth() > 0 )
|
2021-11-24 13:19:50 +00:00
|
|
|
m_lastResolvedWidth = m_stroke.GetWidth();
|
|
|
|
else if( !IsConnectivityDirty() )
|
2022-08-14 11:03:18 +00:00
|
|
|
m_lastResolvedWidth = GetEffectiveNetClass()->GetWireWidth();
|
2020-08-18 15:51:45 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
return m_lastResolvedWidth;
|
2020-08-09 20:51:40 +00:00
|
|
|
|
|
|
|
case LAYER_BUS:
|
|
|
|
if( m_stroke.GetWidth() > 0 )
|
2021-11-24 13:19:50 +00:00
|
|
|
m_lastResolvedWidth = m_stroke.GetWidth();
|
|
|
|
else if( !IsConnectivityDirty() )
|
2022-08-14 11:03:18 +00:00
|
|
|
m_lastResolvedWidth = GetEffectiveNetClass()->GetBusWidth();
|
2020-08-18 15:51:45 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
return m_lastResolvedWidth;
|
2020-08-09 20:51:40 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2020-07-27 20:46:22 +00:00
|
|
|
COLOR4D color = GetLineColor();
|
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( GetLayer() );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = m_start;
|
|
|
|
VECTOR2I end = m_end;
|
2021-02-05 15:46:36 +00:00
|
|
|
PLOT_DASH_TYPE lineStyle = GetEffectiveLineStyle();
|
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2021-02-05 15:46:36 +00:00
|
|
|
if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE )
|
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( DC, start.x, start.y, end.x, end.y, penWidth, color );
|
2021-02-05 15:46:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
SHAPE_SEGMENT segment( start, end );
|
2021-02-05 15:46:36 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
STROKE_PARAMS::Stroke( &segment, lineStyle, penWidth, aSettings,
|
2022-01-01 18:08:03 +00:00
|
|
|
[&]( const VECTOR2I& a, const VECTOR2I& b )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
} );
|
2021-02-05 15:46:36 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_LINE::MirrorVertically( int aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-09-23 21:39:29 +00:00
|
|
|
if( m_flags & STARTPOINT )
|
|
|
|
MIRROR( m_start.y, aCenter );
|
|
|
|
|
|
|
|
if( m_flags & ENDPOINT )
|
|
|
|
MIRROR( m_end.y, aCenter );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_LINE::MirrorHorizontally( int aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-09-23 21:39:29 +00:00
|
|
|
if( m_flags & STARTPOINT )
|
|
|
|
MIRROR( m_start.x, aCenter );
|
|
|
|
|
|
|
|
if( m_flags & ENDPOINT )
|
|
|
|
MIRROR( m_end.x, aCenter );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::Rotate( const VECTOR2I& aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-02-25 16:27:55 +00:00
|
|
|
// When we allow off grid items, the
|
|
|
|
// else if should become a plain if to allow
|
|
|
|
// rotation around the center of the line
|
2021-09-23 21:39:29 +00:00
|
|
|
if( m_flags & STARTPOINT )
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( m_start, aCenter, ANGLE_90 );
|
2021-09-23 21:39:29 +00:00
|
|
|
|
2022-02-25 16:27:55 +00:00
|
|
|
else if( m_flags & ENDPOINT )
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( m_end, aCenter, ANGLE_90 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::RotateStart( const VECTOR2I& aCenter )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( m_start, aCenter, ANGLE_90 );
|
2019-05-03 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::RotateEnd( const VECTOR2I& aCenter )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( m_end, aCenter, ANGLE_90 );
|
2019-05-03 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
int SCH_LINE::GetAngleFrom( const VECTOR2I& aPoint ) const
|
2017-10-16 21:38:57 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I vec;
|
2017-10-16 21:38:57 +00:00
|
|
|
|
2021-03-18 16:37:53 +00:00
|
|
|
if( aPoint == m_start )
|
|
|
|
vec = m_end - aPoint;
|
2017-10-16 21:38:57 +00:00
|
|
|
else
|
2021-03-18 16:37:53 +00:00
|
|
|
vec = m_start - aPoint;
|
2017-10-16 21:38:57 +00:00
|
|
|
|
2022-01-18 11:44:55 +00:00
|
|
|
return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
|
2021-03-18 16:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
int SCH_LINE::GetReverseAngleFrom( const VECTOR2I& aPoint ) const
|
2021-03-18 16:37:53 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I vec;
|
2021-03-18 16:37:53 +00:00
|
|
|
|
|
|
|
if( aPoint == m_end )
|
|
|
|
vec = m_start - aPoint;
|
2017-10-16 21:38:57 +00:00
|
|
|
else
|
2021-03-18 16:37:53 +00:00
|
|
|
vec = m_end - aPoint;
|
2017-10-16 21:38:57 +00:00
|
|
|
|
2022-01-18 11:44:55 +00:00
|
|
|
return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
|
2017-10-16 21:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
bool SCH_LINE::IsParallel( const SCH_LINE* aLine ) const
|
2017-10-16 21:38:57 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, false,
|
2017-10-16 21:38:57 +00:00
|
|
|
wxT( "Cannot test line segment for overlap." ) );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I firstSeg = m_end - m_start;
|
|
|
|
VECTOR2I secondSeg = aLine->m_end - aLine->m_start;
|
2017-10-16 21:38:57 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-11-25 00:50:00 +00:00
|
|
|
auto less =
|
2022-01-01 06:04:08 +00:00
|
|
|
[]( const VECTOR2I& lhs, const VECTOR2I& rhs ) -> bool
|
2021-11-25 00:50:00 +00:00
|
|
|
{
|
|
|
|
if( lhs.x == rhs.x )
|
|
|
|
return lhs.y < rhs.y;
|
2020-10-21 17:41:44 +00:00
|
|
|
|
2021-11-25 00:50:00 +00:00
|
|
|
return lhs.x < rhs.x;
|
|
|
|
};
|
2019-04-03 02:46:22 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, nullptr,
|
2011-02-28 18:36:19 +00:00
|
|
|
wxT( "Cannot test line segment for overlap." ) );
|
|
|
|
|
|
|
|
if( this == aLine || GetLayer() != aLine->GetLayer() )
|
2019-12-11 13:22:59 +00:00
|
|
|
return nullptr;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I leftmost_start = aLine->m_start;
|
|
|
|
VECTOR2I leftmost_end = aLine->m_end;
|
2019-04-03 02:46:22 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I rightmost_start = m_start;
|
|
|
|
VECTOR2I 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
|
|
|
|
2020-10-21 17:41:44 +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
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I other_start = rightmost_start;
|
|
|
|
VECTOR2I 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
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
return nullptr;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
2017-11-17 16:35:20 +00:00
|
|
|
|
|
|
|
// Search for a common end:
|
2019-08-31 19:20:44 +00:00
|
|
|
if( ( leftmost_start == other_start ) && ( leftmost_end == other_end ) ) // Trivial case
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-11-25 00:50:00 +00:00
|
|
|
SCH_LINE* ret = new SCH_LINE( *aLine );
|
2019-04-03 20:26:43 +00:00
|
|
|
ret->SetStartPoint( leftmost_start );
|
2019-04-03 02:46:22 +00:00
|
|
|
ret->SetEndPoint( leftmost_end );
|
2021-11-25 00:50:00 +00:00
|
|
|
ret->SetConnectivityDirty( true );
|
2019-08-31 19:20:44 +00:00
|
|
|
|
|
|
|
if( IsSelected() || aLine->IsSelected() )
|
|
|
|
ret->SetSelected();
|
|
|
|
|
2019-04-03 02:46:22 +00:00
|
|
|
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
|
2020-10-21 17:41:44 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
if( !colinear )
|
|
|
|
return nullptr;
|
2019-04-03 02:46:22 +00:00
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
// We either have a true overlap or colinear touching segments. We always want to merge
|
|
|
|
// the former, but the later only get merged if there no junction at the touch point.
|
2019-08-31 19:20:44 +00:00
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
bool touching = leftmost_end == rightmost_start;
|
2019-08-31 19:20:44 +00:00
|
|
|
|
2021-11-04 12:38:15 +00:00
|
|
|
if( touching && aCheckJunctions && aScreen->IsJunction( leftmost_end ) )
|
2020-10-21 17:41:44 +00:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Make a new segment that merges the 2 segments
|
|
|
|
leftmost_end = rightmost_end;
|
|
|
|
|
2021-11-25 00:50:00 +00:00
|
|
|
SCH_LINE* ret = new SCH_LINE( *aLine );
|
2020-10-21 17:41:44 +00:00
|
|
|
ret->SetStartPoint( leftmost_start );
|
|
|
|
ret->SetEndPoint( leftmost_end );
|
2021-11-25 00:50:00 +00:00
|
|
|
ret->SetConnectivityDirty( true );
|
2017-11-17 16:35:20 +00:00
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
if( IsSelected() || aLine->IsSelected() )
|
|
|
|
ret->SetSelected();
|
|
|
|
|
|
|
|
return ret;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2021-09-24 11:18:54 +00:00
|
|
|
if( IsConnectable() )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-09-24 11:18:54 +00:00
|
|
|
aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_start );
|
|
|
|
aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_end );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
|
|
|
|
const SCH_SHEET_PATH* aPath )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-09-24 19:08:42 +00:00
|
|
|
if( IsConnectable() )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-09-24 19:08:42 +00:00
|
|
|
bool previousStartState = m_startIsDangling;
|
|
|
|
bool previousEndState = m_endIsDangling;
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2021-09-24 19:08:42 +00:00
|
|
|
m_startIsDangling = m_endIsDangling = true;
|
|
|
|
|
|
|
|
for( DANGLING_END_ITEM item : aItemList )
|
2021-09-24 11:18:54 +00:00
|
|
|
{
|
2021-09-24 19:08:42 +00:00
|
|
|
if( item.GetItem() == this )
|
|
|
|
continue;
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2021-09-24 19:08:42 +00:00
|
|
|
if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
|
|
|
|
|| ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
|
|
|
|
{
|
|
|
|
if( m_start == item.GetPosition() )
|
|
|
|
m_startIsDangling = false;
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2021-09-24 19:08:42 +00:00
|
|
|
if( m_end == item.GetPosition() )
|
|
|
|
m_endIsDangling = false;
|
|
|
|
|
|
|
|
if( !m_startIsDangling && !m_endIsDangling )
|
|
|
|
break;
|
|
|
|
}
|
2021-09-24 11:18:54 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2021-09-24 19:08:42 +00:00
|
|
|
// We only use the bus dangling state for automatic line starting, so we don't care if it
|
|
|
|
// has changed or not (and returning true will result in extra work)
|
|
|
|
if( IsBus() )
|
|
|
|
return false;
|
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
return previousStartState != m_startIsDangling || previousEndState != m_endIsDangling;
|
2021-09-24 19:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LINE::IsConnectable() const
|
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
if( m_layer == LAYER_WIRE || m_layer == LAYER_BUS )
|
2011-02-28 18:36:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-19 17:45:56 +00:00
|
|
|
bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
|
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
if( m_layer == LAYER_WIRE )
|
2017-12-19 17:45:56 +00:00
|
|
|
{
|
2020-09-11 16:31:38 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2020-09-11 16:31:38 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2020-09-11 16:31:38 +00:00
|
|
|
case SCH_SHEET_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-12-19 17:45:56 +00:00
|
|
|
}
|
2020-11-14 14:29:11 +00:00
|
|
|
else if( m_layer == LAYER_BUS )
|
2020-09-11 16:31:38 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2020-09-11 16:31:38 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
return aItem->GetLayer() == m_layer;
|
2017-12-19 17:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> SCH_LINE::GetConnectionPoints() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
return { m_start, m_end };
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-25 18:36:30 +00:00
|
|
|
bool SCH_LINE::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
|
|
|
return IsBus() == static_cast<const SCH_LINE*>( aItem )->IsBus();
|
|
|
|
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const
|
2019-06-11 20:17:05 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & STARTPOINT )
|
2019-06-11 20:17:05 +00:00
|
|
|
aPoints.push_back( m_start );
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & ENDPOINT )
|
2019-06-11 20:17:05 +00:00
|
|
|
aPoints.push_back( m_end );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
wxString SCH_LINE::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-07-25 11:07:57 +00:00
|
|
|
wxString txtfmt;
|
2011-10-11 13:38:13 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
if( m_start.x == m_end.x )
|
2020-09-19 16:12:00 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
switch( m_layer )
|
2020-09-19 16:12:00 +00:00
|
|
|
{
|
|
|
|
case LAYER_WIRE: txtfmt = _( "Vertical Wire, length %s" ); break;
|
|
|
|
case LAYER_BUS: txtfmt = _( "Vertical Bus, length %s" ); break;
|
|
|
|
default: txtfmt = _( "Vertical Graphic Line, length %s" ); break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 20:19:29 +00:00
|
|
|
else if( m_start.y == m_end.y )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
switch( m_layer )
|
2020-09-19 16:12:00 +00:00
|
|
|
{
|
|
|
|
case LAYER_WIRE: txtfmt = _( "Horizontal Wire, length %s" ); break;
|
|
|
|
case LAYER_BUS: txtfmt = _( "Horizontal Bus, length %s" ); break;
|
|
|
|
default: txtfmt = _( "Horizontal Graphic Line, length %s" ); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
switch( m_layer )
|
2020-09-19 16:12:00 +00:00
|
|
|
{
|
|
|
|
case LAYER_WIRE: txtfmt = _( "Wire, length %s" ); break;
|
|
|
|
case LAYER_BUS: txtfmt = _( "Bus, length %s" ); break;
|
|
|
|
default: txtfmt = _( "Graphic Line, length %s" ); break;
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( txtfmt,
|
2022-09-19 16:09:59 +00:00
|
|
|
aUnitsProvider->MessageTextFromValue( EuclideanNorm( m_start - m_end ) ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_LINE::GetMenuImage() const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
if( m_layer == LAYER_NOTES )
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_dashed_line;
|
2020-11-14 14:29:11 +00:00
|
|
|
else if( m_layer == LAYER_WIRE )
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_line;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_bus;
|
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();
|
|
|
|
|
2021-11-25 00:50:00 +00:00
|
|
|
const SCH_LINE* line = static_cast<const SCH_LINE*>( &aItem );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
if( GetLayer() != line->GetLayer() )
|
|
|
|
return GetLayer() < line->GetLayer();
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
if( GetStartPoint().x != line->GetStartPoint().x )
|
|
|
|
return GetStartPoint().x < line->GetStartPoint().x;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
if( GetStartPoint().y != line->GetStartPoint().y )
|
|
|
|
return GetStartPoint().y < line->GetStartPoint().y;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
if( GetEndPoint().x != line->GetEndPoint().x )
|
|
|
|
return GetEndPoint().x < line->GetEndPoint().x;
|
|
|
|
|
|
|
|
return GetEndPoint().y < line->GetEndPoint().y;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2019-09-09 22:21:59 +00:00
|
|
|
// Performance enhancement for connection-building
|
|
|
|
if( aPosition == m_start || aPosition == m_end )
|
|
|
|
return true;
|
|
|
|
|
2021-03-18 18:31:16 +00:00
|
|
|
if( aAccuracy >= 0 )
|
|
|
|
aAccuracy += GetPenWidth() / 2;
|
|
|
|
else
|
|
|
|
aAccuracy = abs( aAccuracy );
|
2019-04-30 00:46:21 +00:00
|
|
|
|
2022-07-19 08:47:34 +00:00
|
|
|
return TestSegmentHit( aPosition, m_start, m_end, aAccuracy );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_LINE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
|
2012-03-15 14:31:16 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I 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;
|
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, item->m_layer );
|
2017-10-31 16:33:37 +00:00
|
|
|
|
|
|
|
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 );
|
2020-06-17 19:59:27 +00:00
|
|
|
std::swap( m_stroke, item->m_stroke );
|
2017-10-31 16:33:37 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_LINE::doIsConnected( const VECTOR2I& aPosition ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
if( m_layer != LAYER_WIRE && m_layer != LAYER_BUS )
|
2011-02-28 18:36:19 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return IsEndPoint( aPosition );
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
return;
|
|
|
|
|
2020-07-27 20:46:22 +00:00
|
|
|
auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
|
2021-11-12 16:27:08 +00:00
|
|
|
int penWidth = std::max( GetPenWidth(), settings->GetMinPenWidth() );
|
2020-07-27 20:46:22 +00:00
|
|
|
COLOR4D color = GetLineColor();
|
2020-05-12 14:02:24 +00:00
|
|
|
|
2020-07-27 20:46:22 +00:00
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = settings->GetLayerColor( GetLayer() );
|
|
|
|
|
|
|
|
aPlotter->SetColor( color );
|
2017-11-13 03:53:27 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
2022-06-28 18:06:17 +00:00
|
|
|
aPlotter->SetDash( penWidth, GetEffectiveLineStyle() );
|
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
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
|
2022-09-05 23:21:19 +00:00
|
|
|
|
2022-09-08 13:09:33 +00:00
|
|
|
// Plot attributes to a hypertext menu
|
|
|
|
std::vector<wxString> properties;
|
|
|
|
BOX2I bbox = GetBoundingBox();
|
|
|
|
bbox.Inflate( GetPenWidth() * 3 );
|
2022-09-05 23:21:19 +00:00
|
|
|
|
2022-09-08 13:09:33 +00:00
|
|
|
if( GetLayer() == LAYER_WIRE )
|
|
|
|
{
|
|
|
|
if( SCH_CONNECTION* connection = Connection() )
|
2022-09-05 23:21:19 +00:00
|
|
|
{
|
2022-09-08 13:09:33 +00:00
|
|
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
|
|
|
_( "Net" ),
|
|
|
|
connection->Name() ) );
|
2022-09-05 23:21:19 +00:00
|
|
|
|
2022-09-08 13:09:33 +00:00
|
|
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
|
|
|
_( "Resolved netclass" ),
|
|
|
|
GetEffectiveNetClass()->GetName() ) );
|
2022-09-05 23:21:19 +00:00
|
|
|
}
|
2022-09-08 13:09:33 +00:00
|
|
|
}
|
|
|
|
else if( GetLayer() == LAYER_BUS )
|
|
|
|
{
|
|
|
|
if( SCH_CONNECTION* connection = Connection() )
|
2022-09-05 23:21:19 +00:00
|
|
|
{
|
2022-09-08 13:09:33 +00:00
|
|
|
for( std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
|
|
|
|
properties.emplace_back( wxT( "!" ) + member->Name() );
|
2022-09-05 23:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-09-08 13:09:33 +00:00
|
|
|
|
|
|
|
if( !properties.empty() )
|
|
|
|
aPlotter->HyperlinkMenu( bbox, properties );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2011-10-19 20:32:21 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_LINE::SetPosition( const VECTOR2I& 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
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( GetLayer() )
|
|
|
|
{
|
2020-06-24 17:35:33 +00:00
|
|
|
case LAYER_WIRE: msg = _( "Wire" ); break;
|
|
|
|
case LAYER_BUS: msg = _( "Bus" ); break;
|
|
|
|
default: msg = _( "Graphical" ); break;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Line Type" ), msg );
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2022-03-20 15:57:18 +00:00
|
|
|
PLOT_DASH_TYPE lineStyle = GetLineStyle();
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2022-03-20 15:57:18 +00:00
|
|
|
if( GetEffectiveLineStyle() != lineStyle )
|
|
|
|
aList.emplace_back( _( "Line Style" ), _( "from netclass" ) );
|
|
|
|
else
|
2022-09-19 16:09:59 +00:00
|
|
|
m_stroke.GetMsgPanelInfo( aFrame, aList, true, false );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* conn = nullptr;
|
|
|
|
|
|
|
|
if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
|
|
|
|
conn = Connection();
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2021-09-17 13:38:46 +00:00
|
|
|
if( conn )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-09-17 13:38:46 +00:00
|
|
|
conn->AppendInfoToMsgPanel( aList );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-09-17 20:25:05 +00:00
|
|
|
if( !conn->IsBus() )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
aList.emplace_back( _( "Resolved Netclass" ),
|
|
|
|
UnescapeString( GetEffectiveNetClass()->GetName() ) );
|
2021-09-17 20:25:05 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 15:15:34 +00:00
|
|
|
|
|
|
|
bool SCH_LINE::IsGraphicLine() const
|
|
|
|
{
|
|
|
|
return ( GetLayer() == LAYER_NOTES );
|
2020-01-07 14:49:50 +00:00
|
|
|
}
|
2020-03-16 13:04:50 +00:00
|
|
|
|
|
|
|
|
2020-05-09 21:19:34 +00:00
|
|
|
bool SCH_LINE::IsWire() const
|
|
|
|
{
|
|
|
|
return ( GetLayer() == LAYER_WIRE );
|
|
|
|
}
|
|
|
|
|
2022-06-28 01:12:13 +00:00
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
bool SCH_LINE::IsBus() const
|
|
|
|
{
|
|
|
|
return ( GetLayer() == LAYER_BUS );
|
|
|
|
}
|
|
|
|
|