2019-03-11 21:32:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 CERN
|
2024-01-31 17:13:23 +00:00
|
|
|
* Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-03-11 21:32:05 +00:00
|
|
|
* @author Jon Evans <jon@craftyjon.com>
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <lib_pin.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-04-03 09:14:36 +00:00
|
|
|
#include <sch_pin.h>
|
2021-09-19 10:05:58 +00:00
|
|
|
#include <schematic.h>
|
|
|
|
#include <schematic_settings.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2020-08-21 15:54:24 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2022-05-26 22:54:23 +00:00
|
|
|
#include "string_utils.h"
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_PIN::SCH_PIN( LIB_PIN* aLibPin, SCH_SYMBOL* aParentSymbol ) :
|
2020-11-15 17:03:27 +00:00
|
|
|
SCH_ITEM( aParentSymbol, SCH_PIN_T )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2024-02-10 20:41:10 +00:00
|
|
|
wxASSERT( aParentSymbol );
|
2022-06-17 09:01:49 +00:00
|
|
|
m_layer = LAYER_PIN;
|
2020-08-31 19:09:07 +00:00
|
|
|
m_alt = wxEmptyString;
|
|
|
|
m_number = aLibPin->GetNumber();
|
|
|
|
m_libPin = aLibPin;
|
2019-04-03 09:14:36 +00:00
|
|
|
SetPosition( aLibPin->GetPosition() );
|
|
|
|
m_isDangling = true;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-28 12:59:59 +00:00
|
|
|
/**
|
|
|
|
* Create a proxy pin from an alternate pin designation.
|
2021-06-10 14:10:55 +00:00
|
|
|
* The LIB_PIN data will be filled in when the pin is resolved (see SCH_SYMBOL::UpdatePins).
|
2020-10-28 12:59:59 +00:00
|
|
|
*/
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt ) :
|
2020-11-15 17:03:27 +00:00
|
|
|
SCH_ITEM( aParentSymbol, SCH_PIN_T )
|
2020-10-28 12:59:59 +00:00
|
|
|
{
|
2024-02-10 20:41:10 +00:00
|
|
|
wxASSERT( aParentSymbol );
|
2022-06-17 09:01:49 +00:00
|
|
|
m_layer = LAYER_PIN;
|
2020-10-28 12:59:59 +00:00
|
|
|
m_alt = aAlt;
|
|
|
|
m_number = aNumber;
|
|
|
|
m_libPin = nullptr;
|
|
|
|
m_isDangling = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-03 09:14:36 +00:00
|
|
|
SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
|
2019-04-22 10:14:47 +00:00
|
|
|
SCH_ITEM( aPin )
|
2019-04-03 09:14:36 +00:00
|
|
|
{
|
2022-06-17 09:01:49 +00:00
|
|
|
m_layer = aPin.m_layer;
|
2020-08-21 15:54:24 +00:00
|
|
|
m_alt = aPin.m_alt;
|
2020-08-31 19:09:07 +00:00
|
|
|
m_number = aPin.m_number;
|
2019-04-22 10:14:47 +00:00
|
|
|
m_libPin = aPin.m_libPin;
|
2019-04-03 09:14:36 +00:00
|
|
|
m_position = aPin.m_position;
|
|
|
|
m_isDangling = aPin.m_isDangling;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 10:14:47 +00:00
|
|
|
SCH_PIN& SCH_PIN::operator=( const SCH_PIN& aPin )
|
|
|
|
{
|
|
|
|
SCH_ITEM::operator=( aPin );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
m_alt = aPin.m_alt;
|
2020-08-31 19:09:07 +00:00
|
|
|
m_number = aPin.m_number;
|
2019-04-22 10:14:47 +00:00
|
|
|
m_libPin = aPin.m_libPin;
|
|
|
|
m_position = aPin.m_position;
|
|
|
|
m_isDangling = aPin.m_isDangling;
|
2019-04-22 23:27:59 +00:00
|
|
|
|
|
|
|
return *this;
|
2019-04-22 10:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-09 16:07:04 +00:00
|
|
|
bool SCH_PIN::IsVisible() const
|
|
|
|
{
|
|
|
|
wxCHECK( m_libPin, false );
|
|
|
|
|
|
|
|
return m_libPin->IsVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
wxString SCH_PIN::GetName() const
|
|
|
|
{
|
|
|
|
if( !m_alt.IsEmpty() )
|
|
|
|
return m_alt;
|
|
|
|
|
2024-02-09 22:11:49 +00:00
|
|
|
return m_libPin ? m_libPin->GetName() : wxString( "??" );
|
2020-08-21 15:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-12 18:54:34 +00:00
|
|
|
wxString SCH_PIN::GetShownName() const
|
|
|
|
{
|
2024-02-09 22:37:36 +00:00
|
|
|
wxString name = m_libPin ? m_libPin->GetName() : wxString( "??" );
|
2021-06-17 09:37:13 +00:00
|
|
|
|
2021-06-12 18:54:34 +00:00
|
|
|
if( !m_alt.IsEmpty() )
|
2021-06-17 09:37:13 +00:00
|
|
|
name = m_alt;
|
|
|
|
|
2022-09-22 17:04:17 +00:00
|
|
|
if( name == wxS( "~" ) )
|
2021-06-17 09:37:13 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
else
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2021-06-12 18:54:34 +00:00
|
|
|
|
2021-06-17 09:37:13 +00:00
|
|
|
wxString SCH_PIN::GetShownNumber() const
|
|
|
|
{
|
2022-09-22 17:04:17 +00:00
|
|
|
if( m_number == wxS( "~" ) )
|
2021-06-17 09:37:13 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
else
|
|
|
|
return m_number;
|
2021-06-12 18:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
ELECTRICAL_PINTYPE SCH_PIN::GetType() const
|
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
wxCHECK( m_libPin, ELECTRICAL_PINTYPE::PT_NC );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
if( !m_alt.IsEmpty() )
|
2020-08-24 00:18:46 +00:00
|
|
|
return m_libPin->GetAlt( m_alt ).m_Type;
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
return m_libPin->GetType();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GRAPHIC_PINSHAPE SCH_PIN::GetShape() const
|
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
wxCHECK( m_libPin, GRAPHIC_PINSHAPE::LINE );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
if( !m_alt.IsEmpty() )
|
2020-08-24 00:18:46 +00:00
|
|
|
return m_libPin->GetAlt( m_alt ).m_Shape;
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
return m_libPin->GetShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
PIN_ORIENTATION SCH_PIN::GetOrientation() const
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
wxCHECK( m_libPin, PIN_ORIENTATION::PIN_RIGHT );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
return m_libPin->GetOrientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_PIN::GetLength() const
|
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
wxCHECK( m_libPin, 0 );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
return m_libPin->GetLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-23 22:26:03 +00:00
|
|
|
const BOX2I SCH_PIN::ViewBBox() const
|
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
return GetBoundingBox( false, true, true );
|
2022-07-23 22:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-06 18:50:00 +00:00
|
|
|
void SCH_PIN::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2023-02-09 17:18:56 +00:00
|
|
|
aCount = 4;
|
2021-12-06 18:50:00 +00:00
|
|
|
aLayers[0] = LAYER_DANGLING;
|
|
|
|
aLayers[1] = LAYER_DEVICE;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2023-02-09 17:18:56 +00:00
|
|
|
aLayers[3] = LAYER_OP_CURRENTS;
|
2021-12-06 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxDat ) const
|
2019-05-30 13:39:31 +00:00
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
const SCH_SEARCH_DATA& schSearchData =
|
|
|
|
dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
|
|
|
|
|
|
|
|
if( !schSearchData.searchAllPins )
|
2020-08-03 21:12:29 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return EDA_ITEM::Matches( GetName(), aSearchData )
|
|
|
|
|| EDA_ITEM::Matches( GetNumber(), aSearchData );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
|
2020-08-03 21:12:29 +00:00
|
|
|
{
|
|
|
|
bool isReplaced = false;
|
|
|
|
|
|
|
|
/* TODO: waiting on a way to override pins in the schematic...
|
|
|
|
isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
|
|
|
|
isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
|
|
|
|
*/
|
|
|
|
|
|
|
|
return isReplaced;
|
2019-05-30 13:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* SCH_PIN::GetParentSymbol() const
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
return static_cast<SCH_SYMBOL*>( GetParent() );
|
2019-04-22 10:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-12-22 22:20:25 +00:00
|
|
|
LIB_PIN::ALT localStorage;
|
|
|
|
LIB_PIN::ALT* alt = nullptr;
|
|
|
|
|
2024-02-09 16:07:04 +00:00
|
|
|
if( !m_alt.IsEmpty() && m_libPin )
|
2023-12-22 22:20:25 +00:00
|
|
|
{
|
|
|
|
localStorage = m_libPin->GetAlt( m_alt );
|
|
|
|
alt = &localStorage;
|
|
|
|
}
|
|
|
|
|
2024-02-09 16:07:04 +00:00
|
|
|
wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt ) :
|
2024-02-10 01:18:13 +00:00
|
|
|
wxString( wxS( "Undefined library pin." ) );
|
2022-08-15 16:59:34 +00:00
|
|
|
return wxString::Format( "Symbol %s %s",
|
2023-05-05 13:21:56 +00:00
|
|
|
UnescapeString( GetParentSymbol()->GetField( REFERENCE_FIELD )->GetText() ),
|
2024-02-09 16:07:04 +00:00
|
|
|
itemDesc );
|
2019-04-22 10:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
2024-01-26 18:11:10 +00:00
|
|
|
wxString msg;
|
|
|
|
SCH_SYMBOL* symbol = GetParentSymbol();
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Type" ), _( "Pin" ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2024-01-26 18:11:10 +00:00
|
|
|
if( LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get() )
|
|
|
|
{
|
|
|
|
if( libSymbol->GetUnitCount() )
|
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
msg = m_libPin ? LIB_ITEM::GetUnitDescription( m_libPin->GetUnit() ) :
|
2024-02-09 22:37:36 +00:00
|
|
|
wxString( "Undefined library pin." );
|
2024-02-09 16:07:04 +00:00
|
|
|
aList.emplace_back( _( "Unit" ), msg );
|
2024-01-26 18:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( libSymbol->HasAlternateBodyStyle() )
|
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
msg = m_libPin ? LIB_ITEM::GetBodyStyleDescription( m_libPin->GetBodyStyle() ) :
|
2024-02-09 22:37:36 +00:00
|
|
|
wxString( "Undefined library pin." );
|
2024-02-09 16:07:04 +00:00
|
|
|
aList.emplace_back( _( "Body Style" ), msg );
|
2024-01-26 18:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Name" ), GetShownName() );
|
|
|
|
aList.emplace_back( _( "Number" ), GetShownNumber() );
|
|
|
|
aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
|
|
|
|
aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength() ), true );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2020-09-06 12:05:07 +00:00
|
|
|
SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
|
|
|
|
SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
// Don't use GetShownText(); we want to see the variable references here
|
|
|
|
aList.emplace_back( symbol->GetRef( currentSheet ),
|
|
|
|
UnescapeString( symbol->GetField( VALUE_FIELD )->GetText() ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2021-11-24 13:19:50 +00:00
|
|
|
if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
|
2021-09-28 13:28:35 +00:00
|
|
|
{
|
|
|
|
SCH_CONNECTION* conn = Connection();
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
if( conn )
|
|
|
|
conn->AppendInfoToMsgPanel( aList );
|
|
|
|
}
|
2020-08-21 15:54:24 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 00:17:42 +00:00
|
|
|
bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
|
|
|
|
{
|
|
|
|
return m_parent == aPin->GetParent()
|
2023-03-07 00:37:33 +00:00
|
|
|
&& GetTransformedPosition() == aPin->GetTransformedPosition()
|
|
|
|
&& GetName() == aPin->GetName()
|
|
|
|
&& ( ( GetType() == aPin->GetType() ) || ( GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE )
|
|
|
|
|| ( aPin->GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE ) );
|
2022-09-10 00:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-31 17:13:23 +00:00
|
|
|
bool SCH_PIN::IsGlobalPower() const
|
|
|
|
{
|
|
|
|
wxCHECK( m_libPin, false );
|
|
|
|
|
|
|
|
return m_libPin->IsGlobalPower();
|
|
|
|
}
|
|
|
|
|
2020-08-13 21:30:30 +00:00
|
|
|
void SCH_PIN::ClearDefaultNetName( const SCH_SHEET_PATH* aPath )
|
|
|
|
{
|
2020-08-15 01:41:11 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
|
2020-08-13 21:30:30 +00:00
|
|
|
|
|
|
|
if( aPath )
|
|
|
|
m_net_name_map.erase( *aPath );
|
|
|
|
else
|
|
|
|
m_net_name_map.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-15 01:55:39 +00:00
|
|
|
wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-01-18 17:49:58 +00:00
|
|
|
// Need to check for parent as power symbol to make sure we aren't dealing
|
|
|
|
// with legacy global power pins on non-power symbols
|
|
|
|
if( IsGlobalPower() )
|
|
|
|
{
|
|
|
|
if( GetLibPin()->GetParent()->IsPower() )
|
2023-05-05 13:21:56 +00:00
|
|
|
{
|
|
|
|
return EscapeString( GetParentSymbol()->GetValueFieldText( true, &aPath, false ),
|
2023-03-08 14:35:17 +00:00
|
|
|
CTX_NETNAME );
|
2023-05-05 13:21:56 +00:00
|
|
|
}
|
2023-01-18 17:49:58 +00:00
|
|
|
else
|
2023-05-05 13:21:56 +00:00
|
|
|
{
|
2024-02-09 22:37:36 +00:00
|
|
|
wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
|
2024-02-09 16:07:04 +00:00
|
|
|
|
|
|
|
return EscapeString( tmp, CTX_NETNAME );
|
2023-05-05 13:21:56 +00:00
|
|
|
}
|
2023-01-18 17:49:58 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-15 01:41:11 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
|
2019-04-10 05:29:00 +00:00
|
|
|
|
2021-01-21 22:05:08 +00:00
|
|
|
auto it = m_net_name_map.find( aPath );
|
|
|
|
|
|
|
|
if( it != m_net_name_map.end() )
|
|
|
|
{
|
|
|
|
if( it->second.second == aForceNoConnect )
|
|
|
|
return it->second.first;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-13 08:12:24 +00:00
|
|
|
wxString name = "Net-(";
|
2023-01-04 18:30:53 +00:00
|
|
|
bool unconnected = false;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-01-15 01:55:39 +00:00
|
|
|
if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
|
2023-01-04 18:30:53 +00:00
|
|
|
{
|
|
|
|
unconnected = true;
|
2021-01-22 13:04:43 +00:00
|
|
|
name = ( "unconnected-(" );
|
2023-01-04 18:30:53 +00:00
|
|
|
}
|
2021-01-15 01:55:39 +00:00
|
|
|
|
2019-05-19 15:40:14 +00:00
|
|
|
bool annotated = true;
|
|
|
|
|
2023-01-04 18:30:53 +00:00
|
|
|
std::vector<SCH_PIN*> pins = GetParentSymbol()->GetPins( &aPath );
|
|
|
|
bool has_multiple = false;
|
|
|
|
|
|
|
|
for( SCH_PIN* pin : pins )
|
|
|
|
{
|
|
|
|
if( pin->GetShownName() == GetShownName()
|
|
|
|
&& pin->GetShownNumber() != GetShownNumber()
|
|
|
|
&& unconnected == ( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) )
|
|
|
|
{
|
|
|
|
has_multiple = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 22:37:36 +00:00
|
|
|
wxString libPinShownName = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
|
|
|
|
wxString libPinShownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
|
2024-02-09 16:07:04 +00:00
|
|
|
|
2021-11-20 00:03:53 +00:00
|
|
|
// Use timestamp for unannotated symbols
|
|
|
|
if( GetParentSymbol()->GetRef( &aPath, false ).Last() == '?' )
|
2019-05-19 15:40:14 +00:00
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
name << GetParentSymbol()->m_Uuid.AsString();
|
2024-02-09 16:07:04 +00:00
|
|
|
|
2024-02-09 22:37:36 +00:00
|
|
|
wxString libPinNumber = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
|
2024-02-09 16:07:04 +00:00
|
|
|
name << "-Pad" << libPinNumber << ")";
|
2019-05-19 15:40:14 +00:00
|
|
|
annotated = false;
|
|
|
|
}
|
2024-02-09 16:07:04 +00:00
|
|
|
else if( !libPinShownName.IsEmpty() && ( libPinShownName != libPinShownNumber ) )
|
2021-11-20 00:03:53 +00:00
|
|
|
{
|
|
|
|
// Pin names might not be unique between different units so we must have the
|
|
|
|
// unit token in the reference designator
|
|
|
|
name << GetParentSymbol()->GetRef( &aPath, true );
|
2024-02-09 16:07:04 +00:00
|
|
|
name << "-" << EscapeString( libPinShownName, CTX_NETNAME );
|
2023-01-04 18:30:53 +00:00
|
|
|
|
|
|
|
if( unconnected || has_multiple )
|
2024-02-09 16:07:04 +00:00
|
|
|
name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME );
|
2023-01-04 18:30:53 +00:00
|
|
|
|
|
|
|
name << ")";
|
2021-11-20 00:03:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-26 22:54:23 +00:00
|
|
|
// Pin numbers are unique, so we skip the unit token
|
2021-11-20 00:03:53 +00:00
|
|
|
name << GetParentSymbol()->GetRef( &aPath, false );
|
2024-02-09 16:07:04 +00:00
|
|
|
name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME ) << ")";
|
2021-11-20 00:03:53 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-19 15:40:14 +00:00
|
|
|
if( annotated )
|
2021-01-21 22:05:08 +00:00
|
|
|
m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_PIN::GetTransformedPosition() const
|
2019-04-04 02:40:14 +00:00
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
TRANSFORM t = GetParentSymbol()->GetTransform();
|
|
|
|
return t.TransformCoordinate( GetLocalPosition() ) + GetParentSymbol()->GetPosition();
|
2019-04-04 02:40:14 +00:00
|
|
|
}
|
2019-04-22 10:14:47 +00:00
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
|
|
|
|
bool aIncludeElectricalType ) const
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
TRANSFORM t = GetParentSymbol()->GetTransform();
|
2024-02-09 16:07:04 +00:00
|
|
|
BOX2I r;
|
|
|
|
|
|
|
|
if( m_libPin )
|
2024-02-10 13:26:52 +00:00
|
|
|
r = m_libPin->GetBoundingBox( aIncludeInvisiblePins, aIncludeNameAndNumber,
|
|
|
|
aIncludeElectricalType );
|
|
|
|
else
|
|
|
|
wxFAIL;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2019-09-08 21:54:13 +00:00
|
|
|
r.RevertYAxis();
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
r = t.TransformCoordinate( r );
|
2020-11-15 13:58:21 +00:00
|
|
|
r.Offset( GetParentSymbol()->GetPosition() );
|
2024-02-19 09:30:33 +00:00
|
|
|
r.Normalize();
|
2019-04-22 10:14:47 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
return r;
|
2019-04-22 10:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
2021-07-01 13:28:01 +00:00
|
|
|
// When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
|
|
|
|
// no pin number or name. Give it a floor.
|
2021-09-19 10:05:58 +00:00
|
|
|
if( Schematic() )
|
|
|
|
aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
|
2021-07-01 13:28:01 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
|
2019-05-05 10:33:34 +00:00
|
|
|
return rect.Inflate( aAccuracy ).Contains( aPosition );
|
2019-04-22 10:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2022-07-03 17:21:59 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I sel = aRect;
|
2022-07-03 17:21:59 +00:00
|
|
|
|
|
|
|
if( aAccuracy )
|
|
|
|
sel.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
2022-07-23 22:26:03 +00:00
|
|
|
return sel.Contains( GetBoundingBox( false, false, false ) );
|
2022-07-03 17:21:59 +00:00
|
|
|
|
2022-07-23 22:26:03 +00:00
|
|
|
return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
|
2022-07-03 17:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-28 18:37:13 +00:00
|
|
|
EDA_ITEM* SCH_PIN::Clone() const
|
|
|
|
{
|
|
|
|
return new SCH_PIN( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
bool SCH_PIN::HasConnectivityChanges( const SCH_ITEM* aItem,
|
|
|
|
const SCH_SHEET_PATH* aInstance ) const
|
|
|
|
{
|
|
|
|
// Do not compare to ourself.
|
|
|
|
if( aItem == this )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
|
|
|
|
|
|
|
|
// Don't compare against a different SCH_ITEM.
|
|
|
|
wxCHECK( pin, false );
|
|
|
|
|
|
|
|
if( GetPosition() != pin->GetPosition() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return GetNumber() != pin->GetNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-07 00:10:08 +00:00
|
|
|
bool SCH_PIN::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
|
|
|
|
{
|
2024-02-09 16:07:04 +00:00
|
|
|
wxCHECK( m_libPin, false );
|
|
|
|
|
2020-07-07 00:10:08 +00:00
|
|
|
// Reciprocal checking is done in CONNECTION_GRAPH anyway
|
|
|
|
return !( m_libPin->GetType() == ELECTRICAL_PINTYPE::PT_NC );
|
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
bool SCH_PIN::operator==( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != SCH_PIN_T )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_PIN& other = static_cast<const SCH_PIN&>( aOther );
|
|
|
|
|
|
|
|
if( m_number != other.m_number )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_position != other.m_position )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_libPin == other.m_libPin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( m_Uuid == aOther.m_Uuid )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
if( aOther.Type() != SCH_PIN_T )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const SCH_PIN& other = static_cast<const SCH_PIN&>( aOther );
|
|
|
|
|
|
|
|
if( m_number != other.m_number )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
if( m_position != other.m_position )
|
|
|
|
return 0.0;
|
|
|
|
|
2024-02-09 16:07:04 +00:00
|
|
|
return m_libPin ? m_libPin->Similarity( *other.m_libPin ) : 0.0;
|
2023-09-14 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
static struct SCH_PIN_DESC
|
|
|
|
{
|
|
|
|
SCH_PIN_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( SCH_PIN );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_PIN ), TYPE_HASH( SCH_ITEM ) );
|
2023-07-02 02:23:31 +00:00
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
|
|
|
|
NO_SETTER( SCH_PIN, wxString ), &SCH_PIN::GetName ) );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
|
|
|
|
NO_SETTER( SCH_PIN, wxString ), &SCH_PIN::GetNumber ) );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
|
|
|
|
NO_SETTER( SCH_PIN, int ), &SCH_PIN::GetLength, PROPERTY_DISPLAY::PT_SIZE ) );
|
2023-06-21 01:57:20 +00:00
|
|
|
}
|
|
|
|
} _SCH_PIN_DESC;
|