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) 2009 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_junction.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <common.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.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-11-10 18:07:35 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2020-06-24 17:35:33 +00:00
|
|
|
#include <sch_painter.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_junction.h>
|
2019-05-08 02:50:10 +00:00
|
|
|
#include <sch_connection.h>
|
2020-05-20 03:34:55 +00:00
|
|
|
#include <schematic.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2021-11-24 23:58:52 +00:00
|
|
|
#include <advanced_config.h>
|
|
|
|
#include <connection_graph.h>
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2020-06-24 17:35:33 +00:00
|
|
|
SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, SCH_JUNCTION_T )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-06-24 17:35:33 +00:00
|
|
|
m_pos = aPosition;
|
|
|
|
m_color = COLOR4D::UNSPECIFIED;
|
|
|
|
m_diameter = aDiameter;
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = aLayer;
|
2021-11-24 23:58:52 +00:00
|
|
|
|
|
|
|
m_lastResolvedDiameter = KiROUND( Mils2iu( DEFAULT_WIRE_WIDTH_MILS ) * 1.7 );
|
|
|
|
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_JUNCTION::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_JUNCTION( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_JUNCTION_T ),
|
2011-10-19 20:32:21 +00:00
|
|
|
wxT( "Cannot swap junction data with invalid item." ) );
|
|
|
|
|
|
|
|
SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_pos, item->m_pos );
|
2020-06-24 17:35:33 +00:00
|
|
|
std::swap( m_diameter, item->m_diameter );
|
|
|
|
std::swap( m_color, item->m_color );
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2019-07-30 01:57:41 +00:00
|
|
|
aCount = 2;
|
2020-11-14 14:29:11 +00:00
|
|
|
aLayers[0] = m_layer;
|
2019-07-30 01:57:41 +00:00
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-10 18:07:35 +00:00
|
|
|
SHAPE_CIRCLE SCH_JUNCTION::getEffectiveShape() const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2020-06-24 17:35:33 +00:00
|
|
|
if( m_diameter != 0 )
|
2021-11-24 23:58:52 +00:00
|
|
|
m_lastResolvedDiameter = m_diameter;
|
2020-11-10 18:07:35 +00:00
|
|
|
else if( Schematic() )
|
2021-11-24 23:58:52 +00:00
|
|
|
m_lastResolvedDiameter = Schematic()->Settings().m_JunctionSize;
|
2020-11-10 18:07:35 +00:00
|
|
|
else
|
2021-11-24 23:58:52 +00:00
|
|
|
m_lastResolvedDiameter = Mils2iu( DEFAULT_JUNCTION_DIAM );
|
2020-11-10 18:07:35 +00:00
|
|
|
|
2021-11-24 23:58:52 +00:00
|
|
|
if( m_lastResolvedDiameter != 1 ) // Diameter 1 means users doesn't want to draw junction dots
|
2020-11-10 18:07:35 +00:00
|
|
|
{
|
2021-11-24 23:58:52 +00:00
|
|
|
if( !IsConnectivityDirty() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = NetClass();
|
2020-11-10 18:07:35 +00:00
|
|
|
|
2021-11-24 23:58:52 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedDiameter = std::max( m_lastResolvedDiameter, KiROUND( netclass->GetWireWidth() * 1.7 ) );
|
|
|
|
}
|
2020-11-10 18:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 23:58:52 +00:00
|
|
|
return SHAPE_CIRCLE( m_pos, std::max( m_lastResolvedDiameter / 2, 1 ) );
|
2020-11-10 18:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT SCH_JUNCTION::GetBoundingBox() const
|
|
|
|
{
|
|
|
|
EDA_RECT rect;
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2011-12-07 20:19:29 +00:00
|
|
|
rect.SetOrigin( m_pos );
|
2020-11-10 18:07:35 +00:00
|
|
|
rect.Inflate( getEffectiveShape().GetRadius() );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
return rect;
|
2010-10-04 12:58:07 +00:00
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
void SCH_JUNCTION::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2020-04-23 01:33:57 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2020-11-03 13:39:31 +00:00
|
|
|
COLOR4D color = GetJunctionColor();
|
2020-07-27 20:46:22 +00:00
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( GetLayer() );
|
|
|
|
|
2020-11-10 18:07:35 +00:00
|
|
|
SHAPE_CIRCLE circle = getEffectiveShape();
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
GRFilledCircle( nullptr, DC, (wxPoint) circle.GetCenter() + aOffset, circle.GetRadius(),
|
|
|
|
color );
|
2009-01-31 18:08:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_JUNCTION::MirrorVertically( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.y, aCenter );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_JUNCTION::MirrorHorizontally( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.x, aCenter );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 14:09:24 +00:00
|
|
|
void SCH_JUNCTION::Rotate( const wxPoint& aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-03-19 19:55:59 +00:00
|
|
|
RotatePoint( &m_pos, aCenter, 900 );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
|
2010-11-03 14:13:15 +00:00
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> SCH_JUNCTION::GetConnectionPoints() const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
return { m_pos };
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
2020-06-24 17:35:33 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
|
|
|
|
<< "/>\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
#endif
|
2008-04-22 16:38:23 +00:00
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2020-11-03 13:39:31 +00:00
|
|
|
COLOR4D SCH_JUNCTION::GetJunctionColor() const
|
2020-07-27 20:46:22 +00:00
|
|
|
{
|
2020-08-18 17:01:19 +00:00
|
|
|
if( m_color != COLOR4D::UNSPECIFIED )
|
2021-11-24 23:58:52 +00:00
|
|
|
{
|
|
|
|
m_lastResolvedColor = m_color;
|
|
|
|
}
|
|
|
|
else if( !IsConnectivityDirty() )
|
|
|
|
{
|
|
|
|
NETCLASSPTR netclass = NetClass();
|
2020-07-27 20:46:22 +00:00
|
|
|
|
2021-11-24 23:58:52 +00:00
|
|
|
if( netclass )
|
|
|
|
m_lastResolvedColor = netclass->GetSchematicColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !IsConnectable()
|
|
|
|
|| !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity
|
|
|
|
|| !Schematic() || !Schematic()->ConnectionGraph()->m_allowRealTime,
|
|
|
|
"Connectivity shouldn't be dirty if realtime connectivity is on!" );
|
|
|
|
}
|
2020-07-27 20:46:22 +00:00
|
|
|
|
2021-11-24 23:58:52 +00:00
|
|
|
return m_lastResolvedColor;
|
2020-07-27 20:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-31 10:48:45 +00:00
|
|
|
int SCH_JUNCTION::GetEffectiveDiameter() const
|
2020-07-30 19:03:38 +00:00
|
|
|
{
|
2020-11-10 18:07:35 +00:00
|
|
|
return getEffectiveShape().GetRadius() * 2;
|
2020-07-30 19:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2021-03-18 18:31:16 +00:00
|
|
|
if( aAccuracy >= 0 )
|
|
|
|
return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
|
|
|
|
else
|
|
|
|
return aPosition == m_pos;
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & STRUCT_DELETED || m_flags & SKIP_STRUCT )
|
2012-03-15 14:31:16 +00:00
|
|
|
return false;
|
|
|
|
|
2020-11-10 18:07:35 +00:00
|
|
|
if( aContained )
|
|
|
|
{
|
|
|
|
EDA_RECT selRect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2020-11-10 18:07:35 +00:00
|
|
|
selRect.Inflate( aAccuracy );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2020-11-10 18:07:35 +00:00
|
|
|
return selRect.Contains( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SHAPE_CIRCLE junction = getEffectiveShape();
|
|
|
|
SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2020-11-10 18:07:35 +00:00
|
|
|
return selRect.Collide( &junction, aAccuracy );
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
return m_pos == aPosition;
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_JUNCTION::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() );
|
2020-11-03 13:39:31 +00:00
|
|
|
COLOR4D color = GetJunctionColor();
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2020-07-27 20:46:22 +00:00
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = settings->GetLayerColor( GetLayer() );
|
|
|
|
|
|
|
|
aPlotter->SetColor( color );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
aPlotter->Circle( m_pos, GetEffectiveDiameter(), FILL_T::FILLED_SHAPE );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2017-02-20 12:20:39 +00:00
|
|
|
|
2017-11-18 13:10:32 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_JUNCTION::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_junction;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
2020-05-08 20:01:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
|
|
|
if( GetLayer() != aItem.GetLayer() )
|
|
|
|
return GetLayer() < aItem.GetLayer();
|
|
|
|
|
|
|
|
auto junction = static_cast<const SCH_JUNCTION*>( &aItem );
|
|
|
|
|
|
|
|
if( GetPosition().x != junction->GetPosition().x )
|
|
|
|
return GetPosition().x < junction->GetPosition().x;
|
|
|
|
|
2020-06-24 17:35:33 +00:00
|
|
|
if( GetPosition().y != junction->GetPosition().y )
|
|
|
|
return GetPosition().y < junction->GetPosition().y;
|
|
|
|
|
|
|
|
if( GetDiameter() != junction->GetDiameter() )
|
|
|
|
return GetDiameter() < junction->GetDiameter();
|
2020-05-08 20:01:14 +00:00
|
|
|
|
2020-06-24 17:35:33 +00:00
|
|
|
return GetColor() < junction->GetColor();
|
2020-05-08 20:01:14 +00:00
|
|
|
}
|
|
|
|
|