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.

193 lines
5.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanoadoo.fr
  5. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file sch_no_connect.cpp
  26. * @brief Class SCH_NO_CONNECT implementation.
  27. */
  28. #include <sch_draw_panel.h>
  29. #include <plotters/plotter.h>
  30. #include <bitmaps.h>
  31. #include <schematic.h>
  32. #include <sch_no_connect.h>
  33. #include <settings/color_settings.h>
  34. #include <default_values.h> // For some default values
  35. #include <core/mirror.h>
  36. #include <trigo.h>
  37. SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
  38. SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
  39. {
  40. m_pos = pos;
  41. m_size = Mils2iu( DEFAULT_NOCONNECT_SIZE ); ///< No-connect symbol size.
  42. SetLayer( LAYER_NOCONNECT );
  43. }
  44. EDA_ITEM* SCH_NO_CONNECT::Clone() const
  45. {
  46. return new SCH_NO_CONNECT( *this );
  47. }
  48. void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
  49. {
  50. wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
  51. wxT( "Cannot swap no connect data with invalid item." ) );
  52. SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
  53. std::swap( m_pos, item->m_pos );
  54. std::swap( m_size, item->m_size );
  55. }
  56. const EDA_RECT SCH_NO_CONNECT::GetBoundingBox() const
  57. {
  58. int delta = ( GetPenWidth() + GetSize() ) / 2;
  59. EDA_RECT box;
  60. box.SetOrigin( m_pos );
  61. box.Inflate( delta );
  62. return box;
  63. }
  64. void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
  65. {
  66. aCount = 2;
  67. aLayers[0] = LAYER_NOCONNECT;
  68. aLayers[1] = LAYER_SELECTION_SHADOWS;
  69. }
  70. void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
  71. {
  72. DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
  73. aItemList.push_back( item );
  74. }
  75. int SCH_NO_CONNECT::GetPenWidth() const
  76. {
  77. if( !Schematic() )
  78. return 1;
  79. return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
  80. }
  81. void SCH_NO_CONNECT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
  82. {
  83. wxDC* DC = aSettings->GetPrintDC();
  84. int half = GetSize() / 2;
  85. int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
  86. int pX = m_pos.x + aOffset.x;
  87. int pY = m_pos.y + aOffset.y;
  88. COLOR4D color = aSettings->GetLayerColor( LAYER_NOCONNECT );
  89. GRLine( nullptr, DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
  90. GRLine( nullptr, DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
  91. }
  92. void SCH_NO_CONNECT::MirrorVertically( int aCenter )
  93. {
  94. MIRROR( m_pos.y, aCenter );
  95. }
  96. void SCH_NO_CONNECT::MirrorHorizontally( int aCenter )
  97. {
  98. MIRROR( m_pos.x, aCenter );
  99. }
  100. void SCH_NO_CONNECT::Rotate( const wxPoint& aCenter )
  101. {
  102. RotatePoint( &m_pos, aCenter, 900 );
  103. }
  104. std::vector<wxPoint> SCH_NO_CONNECT::GetConnectionPoints() const
  105. {
  106. return { m_pos };
  107. }
  108. bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
  109. {
  110. return m_pos == aPosition;
  111. }
  112. bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  113. {
  114. int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
  115. wxPoint dist = aPosition - m_pos;
  116. if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
  117. return true;
  118. return false;
  119. }
  120. bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  121. {
  122. EDA_RECT rect = aRect;
  123. rect.Inflate( aAccuracy );
  124. if( aContained )
  125. return rect.Contains( GetBoundingBox() );
  126. return rect.Intersects( GetBoundingBox() );
  127. }
  128. void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter ) const
  129. {
  130. int delta = GetSize() / 2;
  131. int pX = m_pos.x;
  132. int pY = m_pos.y;
  133. int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
  134. aPlotter->SetCurrentLineWidth( penWidth );
  135. aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
  136. aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
  137. aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
  138. aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
  139. aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
  140. }
  141. BITMAPS SCH_NO_CONNECT::GetMenuImage() const
  142. {
  143. return BITMAPS::noconn;
  144. }