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.

191 lines
5.0 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-2019 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 <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 <trigo.h>
  36. SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
  37. SCH_ITEM( NULL, SCH_NO_CONNECT_T )
  38. {
  39. m_pos = pos;
  40. m_size = Mils2iu( DEFAULT_NOCONNECT_SIZE ); ///< No-connect symbol size.
  41. SetLayer( LAYER_NOCONNECT );
  42. }
  43. EDA_ITEM* SCH_NO_CONNECT::Clone() const
  44. {
  45. return new SCH_NO_CONNECT( *this );
  46. }
  47. void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
  48. {
  49. wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T),
  50. wxT( "Cannot swap no connect data with invalid item." ) );
  51. SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
  52. std::swap( m_pos, item->m_pos );
  53. std::swap( m_size, item->m_size );
  54. }
  55. const EDA_RECT SCH_NO_CONNECT::GetBoundingBox() const
  56. {
  57. int delta = ( GetPenWidth() + GetSize() ) / 2;
  58. EDA_RECT box;
  59. box.SetOrigin( m_pos );
  60. box.Inflate( delta );
  61. return box;
  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( RENDER_SETTINGS* aSettings, const wxPoint& 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( nullptr, DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
  89. GRLine( nullptr, DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
  90. }
  91. void SCH_NO_CONNECT::MirrorX( int aXaxis_position )
  92. {
  93. MIRROR( m_pos.y, aXaxis_position );
  94. }
  95. void SCH_NO_CONNECT::MirrorY( int aYaxis_position )
  96. {
  97. MIRROR( m_pos.x, aYaxis_position );
  98. }
  99. void SCH_NO_CONNECT::Rotate( wxPoint aPosition )
  100. {
  101. RotatePoint( &m_pos, aPosition, 900 );
  102. }
  103. std::vector<wxPoint> SCH_NO_CONNECT::GetConnectionPoints() const
  104. {
  105. return { m_pos };
  106. }
  107. bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
  108. {
  109. return m_pos == aPosition;
  110. }
  111. bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  112. {
  113. int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
  114. wxPoint 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 EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  120. {
  121. EDA_RECT 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 )
  128. {
  129. int delta = GetSize() / 2;
  130. int pX = m_pos.x;
  131. int pY = m_pos.y;
  132. int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );
  133. aPlotter->SetCurrentLineWidth( penWidth );
  134. aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
  135. aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
  136. aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
  137. aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
  138. aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
  139. }
  140. BITMAP_DEF SCH_NO_CONNECT::GetMenuImage() const
  141. {
  142. return noconn_xpm;
  143. }