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
|
2021-06-08 14:09:24 +00:00
|
|
|
* Copyright (C) 1992-2021 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
|
|
|
|
*/
|
|
|
|
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.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>
|
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>
|
2021-11-24 13:19:50 +00:00
|
|
|
#include <advanced_config.h>
|
2017-12-06 02:42:37 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
SCH_LINE::SCH_LINE( const wxPoint& 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 )
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_WIRE_WIDTH_MILS );
|
|
|
|
else if( layer == LAYER_BUS )
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_BUS_WIDTH_MILS );
|
|
|
|
else
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_LINE_WIDTH_MILS );
|
|
|
|
|
|
|
|
m_lastResolvedLineStyle = GetDefaultStyle();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Conversion between PLOT_DASH_TYPE values and style names displayed
|
|
|
|
*/
|
|
|
|
const std::map<PLOT_DASH_TYPE, const char*> lineStyleNames{
|
|
|
|
{ PLOT_DASH_TYPE::SOLID, "solid" },
|
|
|
|
{ PLOT_DASH_TYPE::DASH, "dashed" },
|
|
|
|
{ PLOT_DASH_TYPE::DASHDOT, "dash_dot" },
|
|
|
|
{ PLOT_DASH_TYPE::DOT, "dotted" },
|
2017-11-15 13:08:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
const char* SCH_LINE::GetLineStyleName( PLOT_DASH_TYPE aStyle )
|
|
|
|
{
|
|
|
|
auto resultIt = lineStyleNames.find( aStyle );
|
2017-11-15 13:08:27 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
//legacy behavior is to default to dash if there is no name
|
|
|
|
return resultIt == lineStyleNames.end() ? lineStyleNames.find( PLOT_DASH_TYPE::DASH )->second :
|
|
|
|
resultIt->second;
|
2017-11-15 13:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
PLOT_DASH_TYPE SCH_LINE::GetLineStyleByName( const wxString& aStyleName )
|
2017-11-15 13:08:27 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
PLOT_DASH_TYPE id = PLOT_DASH_TYPE::DEFAULT; // Default style id
|
2017-11-15 13:08:27 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
//find the name by value
|
|
|
|
auto resultIt = std::find_if( lineStyleNames.begin(), lineStyleNames.end(),
|
2021-11-25 00:50:00 +00:00
|
|
|
[aStyleName]( const auto& it )
|
|
|
|
{
|
|
|
|
return it.second == aStyleName;
|
|
|
|
} );
|
2019-12-28 00:55:11 +00:00
|
|
|
|
|
|
|
if( resultIt != lineStyleNames.end() )
|
|
|
|
id = resultIt->first;
|
2017-11-15 13:08:27 +00:00
|
|
|
|
|
|
|
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()
|
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
|
|
|
|
{
|
|
|
|
aCount = 2;
|
2020-11-14 14:29:11 +00:00
|
|
|
aLayers[0] = m_layer;
|
2019-08-03 19:44:20 +00:00
|
|
|
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
|
|
|
{
|
2020-06-17 19:59:27 +00:00
|
|
|
int width = m_stroke.GetWidth() / 2;
|
|
|
|
int extra = m_stroke.GetWidth() & 0x1;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
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
|
|
|
|
2020-01-07 14:49:50 +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
|
|
|
|
2020-01-07 14:49:50 +00:00
|
|
|
EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( 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 );
|
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();
|
|
|
|
}
|
|
|
|
else if( IsConnectable() && !IsConnectivityDirty() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = NetClass();
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedColor = netclass->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
|
|
|
PLOT_DASH_TYPE SCH_LINE::GetDefaultStyle() const
|
2017-10-31 16:33:37 +00:00
|
|
|
{
|
2019-12-26 15:15:34 +00:00
|
|
|
if( IsGraphicLine() )
|
2019-12-28 00:55:11 +00:00
|
|
|
return PLOT_DASH_TYPE::DASH;
|
2017-10-31 16:33:37 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
return PLOT_DASH_TYPE::SOLID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if( aStyle == GetDefaultStyle() )
|
2020-10-16 12:43:43 +00:00
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
2017-10-31 16:33:37 +00:00
|
|
|
else
|
2020-10-16 12:43:43 +00:00
|
|
|
m_stroke.SetPlotStyle( aStyle );
|
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
|
|
|
|
2017-11-13 03:53:27 +00:00
|
|
|
return GetDefaultStyle();
|
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();
|
|
|
|
}
|
|
|
|
else if( IsConnectable() && !IsConnectivityDirty() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = NetClass();
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedLineStyle = static_cast<PLOT_DASH_TYPE>( netclass->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 );
|
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();
|
2021-11-13 22:55:46 +00:00
|
|
|
NETCLASSPTR netclass;
|
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
|
|
|
|
2021-08-25 18:36:37 +00:00
|
|
|
return Mils2iu( 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() )
|
|
|
|
{
|
|
|
|
netclass = NetClass();
|
2021-11-13 22:55:46 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( !netclass && schematic )
|
|
|
|
netclass = schematic->Prj().GetProjectFile().NetSettings().m_NetClasses.GetDefault();
|
2021-11-13 22:55:46 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedWidth = netclass->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() )
|
|
|
|
{
|
|
|
|
netclass = NetClass();
|
2021-11-13 22:55:46 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( !netclass && schematic )
|
|
|
|
netclass = schematic->Prj().GetProjectFile().NetSettings().m_NetClasses.GetDefault();
|
2021-11-13 22:55:46 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedWidth = netclass->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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
void SCH_LINE::Print( const RENDER_SETTINGS* aSettings, const wxPoint& 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() );
|
|
|
|
|
2021-02-05 15:46:36 +00:00
|
|
|
wxPoint start = m_start;
|
|
|
|
wxPoint end = m_end;
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
GRLine( nullptr, DC, start.x, start.y, end.x, end.y, penWidth, color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EDA_RECT clip( (wxPoint) start, wxSize( end.x - start.x, end.y - start.y ) );
|
|
|
|
clip.Normalize();
|
|
|
|
|
|
|
|
double theta = atan2( end.y - start.y, end.x - start.x );
|
2021-10-10 16:38:10 +00:00
|
|
|
double strokes[] = { 1.0, dash_gap_len( penWidth ), 1.0, dash_gap_len( penWidth ) };
|
2021-02-05 15:46:36 +00:00
|
|
|
|
|
|
|
switch( lineStyle )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case PLOT_DASH_TYPE::DASH:
|
2021-10-10 16:38:10 +00:00
|
|
|
strokes[0] = strokes[2] = dash_mark_len( penWidth );
|
2021-02-05 15:46:36 +00:00
|
|
|
break;
|
|
|
|
case PLOT_DASH_TYPE::DOT:
|
2021-10-10 16:38:10 +00:00
|
|
|
strokes[0] = strokes[2] = dot_mark_len( penWidth );
|
2021-02-05 15:46:36 +00:00
|
|
|
break;
|
|
|
|
case PLOT_DASH_TYPE::DASHDOT:
|
2021-10-10 16:38:10 +00:00
|
|
|
strokes[0] = dash_mark_len( penWidth );
|
|
|
|
strokes[2] = dot_mark_len( penWidth );
|
2021-02-05 15:46:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t i = 0; i < 10000; ++i )
|
|
|
|
{
|
|
|
|
// Calculations MUST be done in doubles to keep from accumulating rounding
|
|
|
|
// errors as we go.
|
|
|
|
wxPoint next( start.x + strokes[ i % 4 ] * cos( theta ),
|
|
|
|
start.y + strokes[ i % 4 ] * sin( theta ) );
|
|
|
|
|
|
|
|
// Drawing each segment can be done rounded to ints.
|
|
|
|
wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
|
|
|
|
wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
|
|
|
|
|
|
|
|
if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
|
|
|
|
break;
|
|
|
|
else if( i % 2 == 0 )
|
|
|
|
GRLine( nullptr, DC, segStart.x, segStart.y, segEnd.x, segEnd.y, penWidth, color );
|
|
|
|
|
|
|
|
start = next;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 14:09:24 +00:00
|
|
|
void SCH_LINE::Rotate( const wxPoint& aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-09-23 21:39:29 +00:00
|
|
|
if( m_flags & STARTPOINT )
|
|
|
|
RotatePoint( &m_start, aCenter, 900 );
|
|
|
|
|
|
|
|
if( m_flags & ENDPOINT )
|
|
|
|
RotatePoint( &m_end, aCenter, 900 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 14:09:24 +00:00
|
|
|
void SCH_LINE::RotateStart( const wxPoint& aCenter )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
2021-03-19 19:55:59 +00:00
|
|
|
RotatePoint( &m_start, aCenter, 900 );
|
2019-05-03 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 14:09:24 +00:00
|
|
|
void SCH_LINE::RotateEnd( const wxPoint& aCenter )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
2021-03-19 19:55:59 +00:00
|
|
|
RotatePoint( &m_end, aCenter, 900 );
|
2019-05-03 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 16:37:53 +00:00
|
|
|
int SCH_LINE::GetAngleFrom( const wxPoint& aPoint ) const
|
2017-10-16 21:38:57 +00:00
|
|
|
{
|
2021-03-18 16:37:53 +00:00
|
|
|
wxPoint 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
|
|
|
|
2021-03-18 16:37:53 +00:00
|
|
|
return KiROUND( ArcTangente( vec.y, vec.x ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_LINE::GetReverseAngleFrom( const wxPoint& aPoint ) const
|
|
|
|
{
|
|
|
|
wxPoint vec;
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-03-18 16:37:53 +00:00
|
|
|
return KiROUND( ArcTangente( vec.y, vec.x ) );
|
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." ) );
|
|
|
|
|
|
|
|
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
|
|
|
|
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 =
|
|
|
|
[]( const wxPoint& lhs, const wxPoint& rhs ) -> bool
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-11-25 00:50:00 +00:00
|
|
|
wxPoint leftmost_start = aLine->m_start;
|
|
|
|
wxPoint leftmost_end = aLine->m_end;
|
2019-04-03 02:46:22 +00:00
|
|
|
|
2021-11-25 00:50:00 +00:00
|
|
|
wxPoint rightmost_start = m_start;
|
|
|
|
wxPoint 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
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
wxPoint other_start = rightmost_start;
|
|
|
|
wxPoint 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:
|
|
|
|
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:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-11 20:17:05 +00:00
|
|
|
void SCH_LINE::GetSelectedPoints( std::vector< wxPoint >& aPoints ) const
|
|
|
|
{
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_LINE::GetSelectMenuText( EDA_UNITS 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 )
|
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,
|
2020-09-19 16:12:00 +00:00
|
|
|
MessageTextFromValue( aUnits, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
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-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
|
|
|
|
2021-09-21 17:15:41 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_start, m_end, aAccuracy ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
aAccuracy += Mils2iu( DANGLING_SYMBOL_SIZE );
|
|
|
|
|
|
|
|
return ( EuclideanNorm( aPosition - m_start ) < aAccuracy
|
|
|
|
|| EuclideanNorm( aPosition - 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
|
|
|
{
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) 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 false;
|
|
|
|
|
|
|
|
return IsEndPoint( aPosition );
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_LINE::Plot( PLOTTER* aPlotter ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
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 );
|
2020-07-08 18:29:16 +00:00
|
|
|
aPlotter->SetDash( 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
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if( GetLineStyle() != GetEffectiveLineStyle() )
|
|
|
|
msg = _( "from netclass" );
|
|
|
|
else
|
|
|
|
msg = GetLineStyleName( GetLineStyle() );
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Line Style" ), msg );
|
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() )
|
|
|
|
{
|
|
|
|
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
|
|
|
|
wxString netname = conn->Name();
|
|
|
|
wxString netclassName = netSettings.m_NetClasses.GetDefaultPtr()->GetName();
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2021-09-17 20:25:05 +00:00
|
|
|
if( netSettings.m_NetClassAssignments.count( netname ) )
|
|
|
|
netclassName = netSettings.m_NetClassAssignments[ netname ];
|
2020-08-24 17:00:19 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Assigned Netclass" ), netclassName );
|
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 );
|
|
|
|
}
|
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
bool SCH_LINE::IsBus() const
|
|
|
|
{
|
|
|
|
return ( GetLayer() == LAYER_BUS );
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:19:34 +00:00
|
|
|
|
2020-03-16 13:04:50 +00:00
|
|
|
bool SCH_LINE::UsesDefaultStroke() const
|
|
|
|
{
|
2020-06-17 19:59:27 +00:00
|
|
|
return m_stroke.GetWidth() == 0 && m_stroke.GetColor() == COLOR4D::UNSPECIFIED
|
2020-10-16 12:43:43 +00:00
|
|
|
&& ( m_stroke.GetPlotStyle() == GetDefaultStyle()
|
|
|
|
|| m_stroke.GetPlotStyle() == PLOT_DASH_TYPE::DEFAULT );
|
2020-03-16 13:04:50 +00:00
|
|
|
}
|