You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 CERN
  5. * Copyright (C) 2019 KiCad Developers, see change_log.txt for contributors.
  6. * @author Jon Evans <jon@craftyjon.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <lib_pin.h>
  22. #include <sch_component.h>
  23. #include <sch_pin.h>
  24. #include <sch_sheet_path.h>
  25. SCH_PIN::SCH_PIN( LIB_PIN* aLibPin, SCH_COMPONENT* aParentComponent ) :
  26. SCH_ITEM( aParentComponent, SCH_PIN_T ),
  27. m_libPin( aLibPin )
  28. {
  29. SetPosition( aLibPin->GetPosition() );
  30. m_isDangling = true;
  31. }
  32. SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
  33. SCH_ITEM( aPin )
  34. {
  35. m_libPin = aPin.m_libPin;
  36. m_position = aPin.m_position;
  37. m_isDangling = aPin.m_isDangling;
  38. }
  39. SCH_PIN& SCH_PIN::operator=( const SCH_PIN& aPin )
  40. {
  41. SCH_ITEM::operator=( aPin );
  42. m_libPin = aPin.m_libPin;
  43. m_position = aPin.m_position;
  44. m_isDangling = aPin.m_isDangling;
  45. return *this;
  46. }
  47. SCH_COMPONENT* SCH_PIN::GetParentComponent() const
  48. {
  49. return static_cast<SCH_COMPONENT*>( GetParent() );
  50. }
  51. wxString SCH_PIN::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  52. {
  53. return wxString::Format( "%s %s",
  54. GetParentComponent()->GetSelectMenuText( aUnits ),
  55. m_libPin->GetSelectMenuText( aUnits ) );
  56. }
  57. void SCH_PIN::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
  58. {
  59. m_libPin->GetMsgPanelInfo( aUnits, aList, GetParentComponent() );
  60. }
  61. wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH aPath )
  62. {
  63. if( m_libPin->IsPowerConnection() )
  64. return m_libPin->GetName();
  65. std::lock_guard<std::mutex> lock( m_netmap_mutex );
  66. if( m_net_name_map.count( aPath ) > 0 )
  67. return m_net_name_map.at( aPath );
  68. wxString name = "Net-(";
  69. name << GetParentComponent()->GetRef( &aPath );
  70. bool annotated = true;
  71. // Add timestamp for uninitialized components
  72. if( name.Last() == '?' )
  73. {
  74. name << GetParentComponent()->GetTimeStamp();
  75. annotated = false;
  76. }
  77. name << "-Pad" << m_libPin->GetNumber() << ")";
  78. if( annotated )
  79. m_net_name_map[ aPath ] = name;
  80. return name;
  81. }
  82. wxPoint SCH_PIN::GetTransformedPosition() const
  83. {
  84. TRANSFORM t = GetParentComponent()->GetTransform();
  85. return ( t.TransformCoordinate( GetPosition() ) + GetParentComponent()->GetPosition() );
  86. }
  87. const EDA_RECT SCH_PIN::GetBoundingBox() const
  88. {
  89. TRANSFORM t = GetParentComponent()->GetTransform();
  90. EDA_RECT r = m_libPin->GetBoundingBox();
  91. t.y2 = -t.y2;
  92. r = t.TransformCoordinate( r );
  93. r.Offset( GetParentComponent()->GetPosition() );
  94. return r;
  95. }
  96. bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  97. {
  98. EDA_RECT rect = GetBoundingBox();
  99. return rect.Inflate( aAccuracy ).Contains( aPosition );
  100. }