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
|
2019-04-22 10:14:47 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see change_log.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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <sch_component.h>
|
2019-04-03 09:14:36 +00:00
|
|
|
#include <sch_pin.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>
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
SCH_PIN::SCH_PIN( LIB_PIN* aLibPin, SCH_COMPONENT* aParentSymbol ) :
|
|
|
|
SCH_ITEM( aParentSymbol, SCH_PIN_T )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
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.
|
|
|
|
* The LIB_PIN data will be filled in when the pin is resolved (see SCH_COMPONENT::UpdatePins).
|
|
|
|
*/
|
2020-11-15 17:03:27 +00:00
|
|
|
SCH_PIN::SCH_PIN( SCH_COMPONENT* aParentSymbol, const wxString& aNumber, const wxString& aAlt ) :
|
|
|
|
SCH_ITEM( aParentSymbol, SCH_PIN_T )
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
wxString SCH_PIN::GetName() const
|
|
|
|
{
|
|
|
|
if( !m_alt.IsEmpty() )
|
|
|
|
return m_alt;
|
|
|
|
|
|
|
|
return m_libPin->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ELECTRICAL_PINTYPE SCH_PIN::GetType() const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_PIN::GetOrientation() const
|
|
|
|
{
|
|
|
|
return m_libPin->GetOrientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_PIN::GetLength() const
|
|
|
|
{
|
|
|
|
return m_libPin->GetLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:27:51 +00:00
|
|
|
bool SCH_PIN::Matches( const wxFindReplaceData& aSearchData, void* aAuxDat ) const
|
2019-05-30 13:39:31 +00:00
|
|
|
{
|
2020-08-03 21:12:29 +00:00
|
|
|
if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return EDA_ITEM::Matches( GetName(), aSearchData )
|
|
|
|
|| EDA_ITEM::Matches( GetNumber(), aSearchData );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:27:51 +00:00
|
|
|
bool SCH_PIN::Replace( const wxFindReplaceData& 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
SCH_COMPONENT* SCH_PIN::GetParentSymbol() const
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
|
|
|
return static_cast<SCH_COMPONENT*>( GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-22 10:14:47 +00:00
|
|
|
return wxString::Format( "%s %s",
|
2020-11-15 13:58:21 +00:00
|
|
|
GetParentSymbol()->GetSelectMenuText( aUnits ),
|
2019-04-22 10:14:47 +00:00
|
|
|
m_libPin->GetSelectMenuText( aUnits ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), _( "Pin" ) ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
if( m_libPin->GetUnit() == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else
|
|
|
|
msg.Printf( wxT( "%d" ), m_libPin->GetUnit() );
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
if( m_libPin->GetConvert() == LIB_ITEM::LIB_CONVERT::BASE )
|
|
|
|
msg = _( "no" );
|
|
|
|
else if( m_libPin->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
|
|
|
|
msg = _( "yes" );
|
|
|
|
else
|
|
|
|
msg = wxT( "?" );
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetName() ) );
|
2021-02-04 10:14:46 +00:00
|
|
|
msg = GetNumber().IsEmpty() ? wxT( "?" ) : GetNumber();
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Number" ), msg ) );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
msg = PinShapeGetText( GetShape() );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
msg = IsVisible() ? _( "Yes" ) : _( "No" );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), msg ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
// Display pin length
|
2020-10-02 20:51:24 +00:00
|
|
|
msg = StringFromValue( aFrame->GetUserUnits(), GetLength() );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
msg = PinOrientationName( (unsigned) PinOrientationIndex( GetOrientation() ) );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.x );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.emplace_back( _( "Pos X" ), msg );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.y );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.emplace_back( _( "Pos Y" ), msg );
|
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;
|
2020-11-15 13:58:21 +00:00
|
|
|
SCH_COMPONENT* symbol = GetParentSymbol();
|
2020-09-06 12:05:07 +00:00
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.emplace_back( symbol->GetRef( currentSheet ), symbol->GetValue( currentSheet, true ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
|
|
|
|
SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
|
|
|
|
|
|
|
|
if( !frame )
|
|
|
|
return;
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* conn = Connection();
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
if( conn )
|
|
|
|
conn->AppendInfoToMsgPanel( aList );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-04-22 10:14:47 +00:00
|
|
|
if( m_libPin->IsPowerConnection() )
|
|
|
|
return m_libPin->GetName();
|
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-(";
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-01-15 01:55:39 +00:00
|
|
|
if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
|
2021-01-22 13:04:43 +00:00
|
|
|
name = ( "unconnected-(" );
|
2021-01-15 01:55:39 +00:00
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
name << GetParentSymbol()->GetRef( &aPath );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-19 15:40:14 +00:00
|
|
|
bool annotated = true;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Add timestamp for uninitialized symbols
|
2019-05-19 15:40:14 +00:00
|
|
|
if( name.Last() == '?' )
|
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
name << GetParentSymbol()->m_Uuid.AsString();
|
2019-05-19 15:40:14 +00:00
|
|
|
annotated = false;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-22 10:14:47 +00:00
|
|
|
name << "-Pad" << m_libPin->GetNumber() << ")";
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-04 02:40:14 +00:00
|
|
|
wxPoint SCH_PIN::GetTransformedPosition() const
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT SCH_PIN::GetBoundingBox() const
|
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
TRANSFORM t = GetParentSymbol()->GetTransform();
|
2019-04-23 17:40:29 +00:00
|
|
|
EDA_RECT r = m_libPin->GetBoundingBox();
|
|
|
|
|
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() );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2019-04-22 10:14:47 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_RECT rect = GetBoundingBox();
|
|
|
|
return rect.Inflate( aAccuracy ).Contains( aPosition );
|
2019-04-22 10:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-07 00:10:08 +00:00
|
|
|
bool SCH_PIN::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
// Reciprocal checking is done in CONNECTION_GRAPH anyway
|
|
|
|
return !( m_libPin->GetType() == ELECTRICAL_PINTYPE::PT_NC );
|
|
|
|
}
|