2011-10-11 13:38:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-01-28 18:12:26 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanoadoo.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_no_connect.cpp
|
|
|
|
* @brief Class SCH_NO_CONNECT implementation.
|
|
|
|
*/
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.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-08-25 12:46:16 +00:00
|
|
|
#include <schematic.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_no_connect.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-04-14 18:11:50 +00:00
|
|
|
#include <default_values.h> // For some default values
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_NO_CONNECT::SCH_NO_CONNECT( const VECTOR2I& pos ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
m_pos = pos;
|
2022-09-16 23:42:20 +00:00
|
|
|
m_size = schIUScale.MilsToIU( DEFAULT_NOCONNECT_SIZE ); ///< No-connect symbol size.
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
SetLayer( LAYER_NOCONNECT );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_NO_CONNECT::Clone() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
return new SCH_NO_CONNECT( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
2023-07-08 17:37:47 +00:00
|
|
|
SCH_ITEM::SwapFlags( aItem );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
|
2011-10-19 20:32:21 +00:00
|
|
|
wxT( "Cannot swap no connect data with invalid item." ) );
|
|
|
|
|
|
|
|
SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_pos, item->m_pos );
|
|
|
|
std::swap( m_size, item->m_size );
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_NO_CONNECT::GetBoundingBox() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
int delta = ( GetPenWidth() + GetSize() ) / 2;
|
|
|
|
BOX2I bbox( m_pos );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox.Inflate( delta );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
return bbox;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-13 20:00:41 +00:00
|
|
|
void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2019-07-30 01:57:41 +00:00
|
|
|
aCount = 2;
|
2018-11-13 20:00:41 +00:00
|
|
|
aLayers[0] = LAYER_NOCONNECT;
|
2019-07-30 01:57:41 +00:00
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
2018-11-13 20:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-08 00:07:42 +00:00
|
|
|
void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
|
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int SCH_NO_CONNECT::GetPenWidth() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-08-25 17:26:20 +00:00
|
|
|
if( !Schematic() )
|
|
|
|
return 1;
|
|
|
|
|
2020-08-25 12:46:16 +00:00
|
|
|
return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_NO_CONNECT::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
int half = GetSize() / 2;
|
2024-04-06 13:14:44 +00:00
|
|
|
int penWidth = GetEffectivePenWidth( aSettings );
|
2020-04-14 12:25:00 +00:00
|
|
|
int pX = m_pos.x + aOffset.x;
|
|
|
|
int pY = m_pos.y + aOffset.y;
|
|
|
|
COLOR4D color = aSettings->GetLayerColor( LAYER_NOCONNECT );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
|
|
|
|
GRLine( DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_NO_CONNECT::MirrorVertically( int aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.y, aCenter );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_NO_CONNECT::MirrorHorizontally( int aCenter )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.x, aCenter );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
void SCH_NO_CONNECT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2024-04-04 22:51:22 +00:00
|
|
|
RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_270 : ANGLE_90 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
bool SCH_NO_CONNECT::HasConnectivityChanges( const SCH_ITEM* aItem,
|
|
|
|
const SCH_SHEET_PATH* aInstance ) const
|
|
|
|
{
|
|
|
|
// Do not compare to ourself.
|
|
|
|
if( aItem == this )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_NO_CONNECT* noConnect = dynamic_cast<const SCH_NO_CONNECT*>( aItem );
|
|
|
|
|
|
|
|
// Don't compare against a different SCH_ITEM.
|
|
|
|
wxCHECK( noConnect, false );
|
|
|
|
|
|
|
|
return GetPosition() != noConnect->GetPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> SCH_NO_CONNECT::GetConnectionPoints() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
return { m_pos };
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 13:38:13 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_NO_CONNECT::doIsConnected( const VECTOR2I& aPosition ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-12-07 20:19:29 +00:00
|
|
|
return m_pos == aPosition;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I dist = aPosition - m_pos;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_NO_CONNECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I 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
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
|
|
|
|
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
return;
|
|
|
|
|
2018-09-09 23:04:42 +00:00
|
|
|
int delta = GetSize() / 2;
|
2020-04-14 12:25:00 +00:00
|
|
|
int pX = m_pos.x;
|
|
|
|
int pY = m_pos.y;
|
2024-04-06 13:14:44 +00:00
|
|
|
int penWidth = GetEffectivePenWidth( getRenderSettings( aPlotter ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( penWidth );
|
|
|
|
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
|
2022-01-01 18:08:03 +00:00
|
|
|
aPlotter->MoveTo( VECTOR2I( pX - delta, pY - delta ) );
|
|
|
|
aPlotter->FinishTo( VECTOR2I( pX + delta, pY + delta ) );
|
|
|
|
aPlotter->MoveTo( VECTOR2I( pX + delta, pY - delta ) );
|
|
|
|
aPlotter->FinishTo( VECTOR2I( pX - delta, pY + delta ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_NO_CONNECT::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::noconn;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_NO_CONNECT::operator==( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
|
|
|
|
|
|
|
|
if( m_pos != other->m_pos )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SCH_NO_CONNECT::Similarity( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( m_Uuid == aOther.m_Uuid )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
|
|
|
|
|
|
|
|
if( m_pos != other->m_pos )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
return 1.0;
|
2024-03-09 13:50:26 +00:00
|
|
|
}
|