2011-12-07 14:08:52 +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) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-06-08 14:09:24 +00:00
|
|
|
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-07 14:08:52 +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
|
|
|
|
*/
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2020-06-24 17:35:33 +00:00
|
|
|
#include <schematic.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-10-28 02:05:25 +00:00
|
|
|
#include <sch_junction.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_line.h>
|
2019-03-23 18:21:25 +00:00
|
|
|
#include <sch_text.h>
|
2021-09-17 13:38:46 +00:00
|
|
|
#include <project/net_settings.h>
|
|
|
|
#include <project/project_file.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-07-08 18:29:16 +00:00
|
|
|
#include <netclass.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>
|
|
|
|
#include <connection_graph.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
#include "sch_painter.h"
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_ENTRY_BASE::SCH_BUS_ENTRY_BASE( KICAD_T aType, const wxPoint& pos, bool aFlipY ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, aType )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
m_pos = pos;
|
2020-04-14 18:11:50 +00:00
|
|
|
m_size.x = Mils2iu( DEFAULT_SCH_ENTRY_SIZE );
|
|
|
|
m_size.y = Mils2iu( DEFAULT_SCH_ENTRY_SIZE );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2021-07-01 14:40:06 +00:00
|
|
|
m_stroke.SetWidth( 0 );
|
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
|
|
|
|
2020-06-30 01:08:33 +00:00
|
|
|
if( aFlipY )
|
2020-01-03 01:39:31 +00:00
|
|
|
m_size.y *= -1;
|
2015-06-15 14:01:43 +00:00
|
|
|
|
|
|
|
m_isDanglingStart = m_isDanglingEnd = true;
|
2021-11-26 18:14:13 +00:00
|
|
|
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_WIRE_WIDTH_MILS );
|
|
|
|
m_lastResolvedLineStyle = PLOT_DASH_TYPE::SOLID;
|
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY::SCH_BUS_WIRE_ENTRY( const wxPoint& pos, bool aFlipY ) :
|
|
|
|
SCH_BUS_ENTRY_BASE( SCH_BUS_WIRE_ENTRY_T, pos, aFlipY )
|
2013-04-01 10:35:20 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = LAYER_WIRE;
|
2019-03-11 21:32:05 +00:00
|
|
|
m_connected_bus_item = nullptr;
|
2021-11-24 13:19:50 +00:00
|
|
|
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_WIRE_WIDTH_MILS );
|
|
|
|
m_lastResolvedLineStyle = PLOT_DASH_TYPE::SOLID;
|
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2013-04-01 10:35:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2021-06-15 22:21:53 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY::SCH_BUS_WIRE_ENTRY( const wxPoint& pos, int aQuadrant ) :
|
|
|
|
SCH_BUS_ENTRY_BASE( SCH_BUS_WIRE_ENTRY_T, pos, false )
|
|
|
|
{
|
|
|
|
switch( aQuadrant )
|
|
|
|
{
|
|
|
|
case 1: m_size.x *= 1; m_size.y *= -1; break;
|
|
|
|
case 2: m_size.x *= 1; m_size.y *= 1; break;
|
|
|
|
case 3: m_size.x *= -1; m_size.y *= 1; break;
|
|
|
|
case 4: m_size.x *= -1; m_size.y *= -1; break;
|
|
|
|
default: wxFAIL_MSG( "SCH_BUS_WIRE_ENTRY ctor: unexpected quadrant" );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_layer = LAYER_WIRE;
|
|
|
|
m_connected_bus_item = nullptr;
|
2021-11-24 13:19:50 +00:00
|
|
|
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_WIRE_WIDTH_MILS );
|
|
|
|
m_lastResolvedLineStyle = PLOT_DASH_TYPE::SOLID;
|
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2021-06-15 22:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_BUS_ENTRY::SCH_BUS_BUS_ENTRY( const wxPoint& pos, bool aFlipY ) :
|
|
|
|
SCH_BUS_ENTRY_BASE( SCH_BUS_BUS_ENTRY_T, pos, aFlipY )
|
2013-04-01 10:35:20 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = LAYER_BUS;
|
2019-03-11 21:32:05 +00:00
|
|
|
m_connected_bus_items[0] = nullptr;
|
|
|
|
m_connected_bus_items[1] = nullptr;
|
2021-11-24 13:19:50 +00:00
|
|
|
|
|
|
|
m_lastResolvedWidth = Mils2iu( DEFAULT_WIRE_WIDTH_MILS );
|
|
|
|
m_lastResolvedLineStyle = PLOT_DASH_TYPE::SOLID;
|
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2013-04-01 10:35:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
EDA_ITEM* SCH_BUS_WIRE_ENTRY::Clone() const
|
|
|
|
{
|
|
|
|
return new SCH_BUS_WIRE_ENTRY( *this );
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
EDA_ITEM* SCH_BUS_BUS_ENTRY::Clone() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-04-01 10:35:20 +00:00
|
|
|
return new SCH_BUS_BUS_ENTRY( *this );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 01:21:23 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::doIsConnected( const wxPoint& aPosition ) const
|
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
return ( m_pos == aPosition || GetEnd() == aPosition );
|
2017-12-01 01:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
wxPoint SCH_BUS_ENTRY_BASE::GetEnd() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 14:08:52 +00:00
|
|
|
return wxPoint( m_pos.x + m_size.x, m_pos.y + m_size.y );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::SwapData( SCH_ITEM* aItem )
|
2011-10-19 20:32:21 +00:00
|
|
|
{
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_ENTRY_BASE* item = dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem );
|
|
|
|
wxCHECK_RET( item, wxT( "Cannot swap bus entry data with invalid item." ) );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_pos, item->m_pos );
|
|
|
|
std::swap( m_size, item->m_size );
|
2020-06-19 11:48:00 +00:00
|
|
|
std::swap( m_stroke, item->m_stroke );
|
2021-11-24 13:19:50 +00:00
|
|
|
|
|
|
|
std::swap( m_lastResolvedWidth, item->m_lastResolvedWidth );
|
|
|
|
std::swap( m_lastResolvedLineStyle, item->m_lastResolvedLineStyle );
|
|
|
|
std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2021-12-06 18:50:00 +00:00
|
|
|
aCount = 3;
|
|
|
|
aLayers[0] = LAYER_DANGLING;
|
|
|
|
aLayers[1] = Type() == SCH_BUS_BUS_ENTRY_T ? LAYER_BUS : LAYER_WIRE;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT box;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-12-07 14:08:52 +00:00
|
|
|
box.SetOrigin( m_pos );
|
2020-09-08 13:27:13 +00:00
|
|
|
box.SetEnd( GetEnd() );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
box.Normalize();
|
2020-04-14 12:25:00 +00:00
|
|
|
box.Inflate( ( GetPenWidth() / 2 ) + 1 );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
COLOR4D SCH_BUS_ENTRY_BASE::GetBusEntryColor() const
|
2020-07-08 18:29:16 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
if( m_stroke.GetColor() != COLOR4D::UNSPECIFIED )
|
|
|
|
{
|
|
|
|
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;
|
2020-07-08 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
PLOT_DASH_TYPE SCH_BUS_ENTRY_BASE::GetLineStyle() const
|
2020-07-08 18:29:16 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
if( m_stroke.GetPlotStyle() != PLOT_DASH_TYPE::DEFAULT )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int SCH_BUS_WIRE_ENTRY::GetPenWidth() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-06-13 19:44:13 +00:00
|
|
|
if( m_stroke.GetWidth() > 0 )
|
2021-11-24 13:19:50 +00:00
|
|
|
{
|
|
|
|
m_lastResolvedWidth = m_stroke.GetWidth();
|
|
|
|
}
|
|
|
|
else if( IsConnectable() && !IsConnectivityDirty() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = NetClass();
|
2021-11-13 22:55:46 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedWidth = netclass->GetWireWidth();
|
|
|
|
}
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
return m_lastResolvedWidth;
|
2013-04-01 10:35:20 +00:00
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int SCH_BUS_BUS_ENTRY::GetPenWidth() const
|
2013-04-01 10:35:20 +00:00
|
|
|
{
|
2021-06-13 19:44:13 +00:00
|
|
|
if( m_stroke.GetWidth() > 0 )
|
2021-11-24 13:19:50 +00:00
|
|
|
{
|
|
|
|
m_lastResolvedWidth = m_stroke.GetWidth();
|
|
|
|
}
|
|
|
|
else if( IsConnectable() && !IsConnectivityDirty() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = NetClass();
|
2021-11-13 22:55:46 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedWidth = netclass->GetBusWidth();
|
|
|
|
}
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
return m_lastResolvedWidth;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 01:21:23 +00:00
|
|
|
void SCH_BUS_WIRE_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM item( WIRE_ENTRY_END, this, m_pos );
|
|
|
|
aItemList.push_back( item );
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
DANGLING_END_ITEM item1( WIRE_ENTRY_END, this, GetEnd() );
|
2017-12-01 01:21:23 +00:00
|
|
|
aItemList.push_back( item1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_BUS_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM item( BUS_ENTRY_END, this, m_pos );
|
|
|
|
aItemList.push_back( item );
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
DANGLING_END_ITEM item1( BUS_ENTRY_END, this, GetEnd() );
|
2017-12-01 01:21:23 +00:00
|
|
|
aItemList.push_back( item1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2021-07-17 19:56:18 +00:00
|
|
|
COLOR4D color = ( GetBusEntryColor() == COLOR4D::UNSPECIFIED ) ?
|
|
|
|
aSettings->GetLayerColor( m_layer ) : GetBusEntryColor();
|
2021-02-05 15:46:36 +00:00
|
|
|
wxPoint start = m_pos + aOffset;
|
|
|
|
wxPoint end = GetEnd() + aOffset;
|
2020-06-24 17:35:33 +00:00
|
|
|
int penWidth = ( GetPenWidth() == 0 ) ? aSettings->GetDefaultPenWidth() : GetPenWidth();
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( GetLineStyle() <= PLOT_DASH_TYPE::FIRST_TYPE )
|
2021-02-05 15:46:36 +00:00
|
|
|
{
|
|
|
|
GRLine( nullptr, DC, start.x, start.y, end.x, end.y, penWidth, color );
|
|
|
|
}
|
|
|
|
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, GetLineStyle(), penWidth, aSettings,
|
|
|
|
[&]( const wxPoint& a, const wxPoint& b )
|
|
|
|
{
|
|
|
|
GRLine( nullptr, DC, a.x, a.y, b.x, b.y, penWidth, color );
|
|
|
|
} );
|
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_BUS_ENTRY_BASE::MirrorVertically( int aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.y, aCenter );
|
2015-06-26 13:41:56 +00:00
|
|
|
m_size.y = -m_size.y;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::MirrorHorizontally( int aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.x, aCenter );
|
2015-06-26 13:41:56 +00:00
|
|
|
m_size.x = -m_size.x;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 14:09:24 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::Rotate( const wxPoint& aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-03-19 19:55:59 +00:00
|
|
|
RotatePoint( &m_pos, aCenter, 900 );
|
2011-12-07 14:08:52 +00:00
|
|
|
RotatePoint( &m_size.x, &m_size.y, 900 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
bool SCH_BUS_WIRE_ENTRY::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
|
|
|
|
const SCH_SHEET_PATH* aPath )
|
2015-06-10 18:43:46 +00:00
|
|
|
{
|
|
|
|
bool previousStateStart = m_isDanglingStart;
|
|
|
|
bool previousStateEnd = m_isDanglingEnd;
|
|
|
|
|
|
|
|
m_isDanglingStart = m_isDanglingEnd = true;
|
|
|
|
|
2017-12-15 18:01:19 +00:00
|
|
|
// Store the connection type and state for the start (0) and end (1)
|
|
|
|
bool has_wire[2] = { false };
|
|
|
|
bool has_bus[2] = { false };
|
2015-06-16 13:05:27 +00:00
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemList.size(); ii++ )
|
2015-06-10 18:43:46 +00:00
|
|
|
{
|
2021-09-24 11:18:54 +00:00
|
|
|
DANGLING_END_ITEM& item = aItemList[ii];
|
|
|
|
|
|
|
|
if( item.GetItem() == this )
|
2015-06-10 18:43:46 +00:00
|
|
|
continue;
|
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
switch( item.GetType() )
|
2015-06-10 18:43:46 +00:00
|
|
|
{
|
2021-09-24 11:18:54 +00:00
|
|
|
case WIRE_END:
|
|
|
|
if( m_pos == item.GetPosition() )
|
2017-12-15 18:01:19 +00:00
|
|
|
has_wire[0] = true;
|
2021-09-24 11:18:54 +00:00
|
|
|
else if( GetEnd() == item.GetPosition() )
|
2017-12-15 18:01:19 +00:00
|
|
|
has_wire[1] = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
case BUS_END:
|
|
|
|
{
|
|
|
|
// The bus has created 2 DANGLING_END_ITEMs, one per end.
|
|
|
|
DANGLING_END_ITEM& nextItem = aItemList[++ii];
|
2019-11-17 18:55:27 +00:00
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_pos ) )
|
2017-12-15 18:01:19 +00:00
|
|
|
has_bus[0] = true;
|
2021-09-24 11:18:54 +00:00
|
|
|
else if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetEnd() ) )
|
2017-12-15 18:01:19 +00:00
|
|
|
has_bus[1] = true;
|
2021-09-24 11:18:54 +00:00
|
|
|
}
|
2017-12-15 18:01:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-17 18:55:27 +00:00
|
|
|
// A bus-wire entry is connected at both ends if it has a bus and a wire on its
|
|
|
|
// ends. Otherwise, we connect only one end (in the case of a wire-wire or bus-bus)
|
2017-12-15 18:01:19 +00:00
|
|
|
if( ( has_wire[0] && has_bus[1] ) || ( has_wire[1] && has_bus[0] ) )
|
|
|
|
m_isDanglingEnd = m_isDanglingStart = false;
|
|
|
|
else if( has_wire[0] || has_bus[0] )
|
|
|
|
m_isDanglingStart = false;
|
|
|
|
else if( has_wire[1] || has_bus[1] )
|
|
|
|
m_isDanglingEnd = false;
|
|
|
|
|
|
|
|
return (previousStateStart != m_isDanglingStart) || (previousStateEnd != m_isDanglingEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
bool SCH_BUS_BUS_ENTRY::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
|
|
|
|
const SCH_SHEET_PATH* aPath )
|
2017-12-15 18:01:19 +00:00
|
|
|
{
|
|
|
|
bool previousStateStart = m_isDanglingStart;
|
|
|
|
bool previousStateEnd = m_isDanglingEnd;
|
2015-06-16 13:05:27 +00:00
|
|
|
|
2017-12-15 18:01:19 +00:00
|
|
|
m_isDanglingStart = m_isDanglingEnd = true;
|
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemList.size(); ii++ )
|
2017-12-15 18:01:19 +00:00
|
|
|
{
|
2021-09-24 11:18:54 +00:00
|
|
|
DANGLING_END_ITEM& item = aItemList[ii];
|
|
|
|
|
|
|
|
if( item.GetItem() == this )
|
2017-12-15 18:01:19 +00:00
|
|
|
continue;
|
|
|
|
|
2021-09-24 11:18:54 +00:00
|
|
|
switch( item.GetType() )
|
2017-12-15 18:01:19 +00:00
|
|
|
{
|
2021-09-24 11:18:54 +00:00
|
|
|
case BUS_END:
|
|
|
|
{
|
|
|
|
// The bus has created 2 DANGLING_END_ITEMs, one per end.
|
|
|
|
DANGLING_END_ITEM& nextItem = aItemList[++ii];
|
|
|
|
|
|
|
|
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_pos ) )
|
2015-06-10 18:43:46 +00:00
|
|
|
m_isDanglingStart = false;
|
2021-09-24 11:18:54 +00:00
|
|
|
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetEnd() ) )
|
2015-06-10 18:43:46 +00:00
|
|
|
m_isDanglingEnd = false;
|
2021-09-24 11:18:54 +00:00
|
|
|
}
|
2015-06-16 13:05:27 +00:00
|
|
|
break;
|
2021-09-24 11:18:54 +00:00
|
|
|
|
2015-06-10 18:43:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (previousStateStart != m_isDanglingStart) || (previousStateEnd != m_isDanglingEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_BUS_ENTRY_BASE::IsDangling() const
|
|
|
|
{
|
|
|
|
return m_isDanglingStart || m_isDanglingEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> SCH_BUS_ENTRY_BASE::GetConnectionPoints() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
return { m_pos, GetEnd() };
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_BUS_WIRE_ENTRY::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2013-04-06 12:28:02 +00:00
|
|
|
return wxString( _( "Bus to Wire Entry" ) );
|
2013-04-01 10:35:20 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_BUS_BUS_ENTRY::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2013-04-01 10:35:20 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
return wxString( _( "Bus to Bus Entry" ) );
|
|
|
|
}
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2017-12-01 03:33:22 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_BUS_WIRE_ENTRY::GetMenuImage() const
|
2017-12-01 03:33:22 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_line2bus;
|
2017-12-01 03:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_BUS_BUS_ENTRY::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_bus2bus;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::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 )
|
2020-04-14 12:25:00 +00:00
|
|
|
aAccuracy = ( GetPenWidth() / 2 ) + 4;
|
2019-04-30 00:46:21 +00:00
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
return TestSegmentHit( aPosition, m_pos, GetEnd(), aAccuracy );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::Plot( PLOTTER* aPlotter ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2020-06-24 17:35:33 +00:00
|
|
|
auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
COLOR4D color = ( GetBusEntryColor() == COLOR4D::UNSPECIFIED ) ?
|
|
|
|
settings->GetLayerColor( m_layer ) : GetBusEntryColor();
|
2020-06-24 17:35:33 +00:00
|
|
|
int penWidth = ( GetPenWidth() == 0 ) ? settings->GetDefaultPenWidth() : GetPenWidth();
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-09-08 19:18:50 +00:00
|
|
|
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
2020-06-24 17:35:33 +00:00
|
|
|
aPlotter->SetColor( color );
|
2021-07-17 19:56:18 +00:00
|
|
|
aPlotter->SetDash( GetLineStyle() );
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->MoveTo( m_pos );
|
2020-09-08 13:27:13 +00:00
|
|
|
aPlotter->FinishTo( GetEnd() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2011-12-18 17:57:05 +00:00
|
|
|
|
2017-11-18 13:10:32 +00:00
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_BUS_ENTRY_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-07-30 01:57:41 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( GetLayer() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case LAYER_WIRE: msg = _( "Wire" ); break;
|
|
|
|
case LAYER_BUS: msg = _( "Bus" ); break;
|
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Bus Entry Type" ), msg );
|
2020-05-13 02:00:37 +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
|
|
|
conn->AppendInfoToMsgPanel( aList );
|
2021-09-17 13:38:46 +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();
|
2021-09-17 13:38:46 +00:00
|
|
|
|
2021-09-17 20:25:05 +00:00
|
|
|
if( netSettings.m_NetClassAssignments.count( netname ) )
|
|
|
|
netclassName = netSettings.m_NetClassAssignments[ netname ];
|
2021-09-17 13:38:46 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Assigned Netclass" ), netclassName );
|
2021-09-17 20:25:05 +00:00
|
|
|
}
|
2021-09-17 13:38:46 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
bool SCH_BUS_ENTRY_BASE::operator <( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
auto symbol = static_cast<const SCH_BUS_ENTRY_BASE*>( &aItem );
|
2020-01-28 20:33:23 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
if( GetLayer() != symbol->GetLayer() )
|
|
|
|
return GetLayer() < symbol->GetLayer();
|
2020-01-28 20:33:23 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
if( GetPosition().x != symbol->GetPosition().x )
|
|
|
|
return GetPosition().x < symbol->GetPosition().x;
|
2020-01-28 20:33:23 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
if( GetPosition().y != symbol->GetPosition().y )
|
|
|
|
return GetPosition().y < symbol->GetPosition().y;
|
2020-01-28 20:33:23 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
if( GetEnd().x != symbol->GetEnd().x )
|
|
|
|
return GetEnd().x < symbol->GetEnd().x;
|
2020-01-28 20:33:23 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
return GetEnd().y < symbol->GetEnd().y;
|
2020-01-28 20:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
bool SCH_BUS_WIRE_ENTRY::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
// Don't generate connections between bus entries and buses, since there is
|
|
|
|
// a connectivity change at that point (e.g. A[7..0] to A7)
|
|
|
|
if( ( aItem->Type() == SCH_LINE_T ) &&
|
|
|
|
( static_cast<const SCH_LINE*>( aItem )->GetLayer() == LAYER_BUS ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-28 02:05:25 +00:00
|
|
|
// Same for bus junctions
|
|
|
|
if( ( aItem->Type() == SCH_JUNCTION_T ) &&
|
|
|
|
( static_cast<const SCH_JUNCTION*>( aItem )->GetLayer() == LAYER_BUS_JUNCTION ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-23 18:21:25 +00:00
|
|
|
// Don't generate connections between bus entries and bus labels that happen
|
|
|
|
// to land at the same point on the bus wire as this bus entry
|
|
|
|
if( ( aItem->Type() == SCH_LABEL_T ) &&
|
|
|
|
SCH_CONNECTION::IsBusLabel( static_cast<const SCH_LABEL*>( aItem )->GetText() ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-17 19:40:20 +00:00
|
|
|
// Don't generate connections between two bus-wire entries
|
|
|
|
if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
return false;
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|