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.

195 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-2022 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 VECTOR2I& pos ) :
  38. SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
  39. {
  40. m_pos = pos;
  41. m_size = schIUScale.MilsToIU( 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 BOX2I SCH_NO_CONNECT::GetBoundingBox() const
  57. {
  58. int delta = ( GetPenWidth() + GetSize() ) / 2;
  59. BOX2I bbox( m_pos );
  60. bbox.Inflate( delta );
  61. return bbox;
  62. }
  63. void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
  64. {
  65. aCount = 2;
  66. aLayers[0] = LAYER_NOCONNECT;
  67. aLayers[1] = LAYER_SELECTION_SHADOWS;
  68. }
  69. void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
  70. {
  71. DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
  72. aItemList.push_back( item );
  73. }
  74. int SCH_NO_CONNECT::GetPenWidth() const
  75. {
  76. if( !Schematic() )
  77. return 1;
  78. return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
  79. }
  80. void SCH_NO_CONNECT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
  81. {
  82. wxDC* DC = aSettings->GetPrintDC();
  83. int half = GetSize() / 2;
  84. int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
  85. int pX = m_pos.x + aOffset.x;
  86. int pY = m_pos.y + aOffset.y;
  87. COLOR4D color = aSettings->GetLayerColor( LAYER_NOCONNECT );
  88. GRLine( DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
  89. GRLine( DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
  90. }
  91. void SCH_NO_CONNECT::MirrorVertically( int aCenter )
  92. {
  93. MIRROR( m_pos.y, aCenter );
  94. }
  95. void SCH_NO_CONNECT::MirrorHorizontally( int aCenter )
  96. {
  97. MIRROR( m_pos.x, aCenter );
  98. }
  99. void SCH_NO_CONNECT::Rotate( const VECTOR2I& aCenter )
  100. {
  101. RotatePoint( m_pos, aCenter, ANGLE_90 );
  102. }
  103. std::vector<VECTOR2I> SCH_NO_CONNECT::GetConnectionPoints() const
  104. {
  105. return { m_pos };
  106. }
  107. bool SCH_NO_CONNECT::doIsConnected( const VECTOR2I& aPosition ) const
  108. {
  109. return m_pos == aPosition;
  110. }
  111. bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  112. {
  113. int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
  114. VECTOR2I dist = aPosition - m_pos;
  115. if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
  116. return true;
  117. return false;
  118. }
  119. bool SCH_NO_CONNECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  120. {
  121. BOX2I rect = aRect;
  122. rect.Inflate( aAccuracy );
  123. if( aContained )
  124. return rect.Contains( GetBoundingBox() );
  125. return rect.Intersects( GetBoundingBox() );
  126. }
  127. void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter, bool aBackground ) const
  128. {
  129. if( aBackground )
  130. return;
  131. int delta = GetSize() / 2;
  132. int pX = m_pos.x;
  133. int pY = m_pos.y;
  134. int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
  135. aPlotter->SetCurrentLineWidth( penWidth );
  136. aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
  137. aPlotter->MoveTo( VECTOR2I( pX - delta, pY - delta ) );
  138. aPlotter->FinishTo( VECTOR2I( pX + delta, pY + delta ) );
  139. aPlotter->MoveTo( VECTOR2I( pX + delta, pY - delta ) );
  140. aPlotter->FinishTo( VECTOR2I( pX - delta, pY + delta ) );
  141. }
  142. BITMAPS SCH_NO_CONNECT::GetMenuImage() const
  143. {
  144. return BITMAPS::noconn;
  145. }