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.

216 lines
5.2 KiB

18 years ago
18 years ago
15 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2017 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_junction.cpp
  26. */
  27. #include <fctsys.h>
  28. #include <gr_basic.h>
  29. #include <macros.h>
  30. #include <sch_draw_panel.h>
  31. #include <trigo.h>
  32. #include <common.h>
  33. #include <richio.h>
  34. #include <plotter.h>
  35. #include <bitmaps.h>
  36. #include <sch_junction.h>
  37. #include <netlist_object.h>
  38. int SCH_JUNCTION::m_symbolSize = 40; // Default diameter of the junction symbol
  39. int SCH_JUNCTION::GetEffectiveSymbolSize()
  40. {
  41. return std::max( KiROUND( GetDefaultLineThickness() * 1.5 ), m_symbolSize );
  42. }
  43. SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) :
  44. SCH_ITEM( NULL, SCH_JUNCTION_T )
  45. {
  46. m_pos = pos;
  47. m_Layer = LAYER_JUNCTION;
  48. }
  49. EDA_ITEM* SCH_JUNCTION::Clone() const
  50. {
  51. return new SCH_JUNCTION( *this );
  52. }
  53. void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
  54. {
  55. wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
  56. wxT( "Cannot swap junction data with invalid item." ) );
  57. SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
  58. std::swap( m_pos, item->m_pos );
  59. }
  60. const EDA_RECT SCH_JUNCTION::GetBoundingBox() const
  61. {
  62. EDA_RECT rect;
  63. rect.SetOrigin( m_pos );
  64. rect.Inflate( ( GetPenSize() + GetEffectiveSymbolSize() ) / 2 );
  65. return rect;
  66. }
  67. void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  68. GR_DRAWMODE aDrawMode, COLOR4D aColor )
  69. {
  70. COLOR4D color;
  71. if( aColor != COLOR4D::UNSPECIFIED )
  72. color = aColor;
  73. else
  74. color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
  75. GRSetDrawMode( aDC, aDrawMode );
  76. GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
  77. ( GetEffectiveSymbolSize() / 2 ), 0, color, color );
  78. }
  79. void SCH_JUNCTION::MirrorX( int aXaxis_position )
  80. {
  81. MIRROR( m_pos.y, aXaxis_position );
  82. }
  83. void SCH_JUNCTION::MirrorY( int aYaxis_position )
  84. {
  85. MIRROR( m_pos.x, aYaxis_position );
  86. }
  87. void SCH_JUNCTION::Rotate( wxPoint aPosition )
  88. {
  89. RotatePoint( &m_pos, aPosition, 900 );
  90. }
  91. void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
  92. {
  93. DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
  94. aItemList.push_back( item );
  95. }
  96. bool SCH_JUNCTION::IsSelectStateChanged( const wxRect& aRect )
  97. {
  98. bool previousState = IsSelected();
  99. if( aRect.Contains( m_pos ) )
  100. SetFlags( SELECTED );
  101. else
  102. ClearFlags( SELECTED );
  103. return previousState != IsSelected();
  104. }
  105. void SCH_JUNCTION::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
  106. {
  107. aPoints.push_back( m_pos );
  108. }
  109. void SCH_JUNCTION::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
  110. SCH_SHEET_PATH* aSheetPath )
  111. {
  112. NETLIST_OBJECT* item = new NETLIST_OBJECT();
  113. item->m_SheetPath = *aSheetPath;
  114. item->m_SheetPathInclude = *aSheetPath;
  115. item->m_Comp = (SCH_ITEM*) this;
  116. item->m_Type = NET_JUNCTION;
  117. item->m_Start = item->m_End = m_pos;
  118. aNetListItems.push_back( item );
  119. }
  120. #if defined(DEBUG)
  121. void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
  122. {
  123. // XML output:
  124. wxString s = GetClass();
  125. NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
  126. }
  127. #endif
  128. bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  129. {
  130. EDA_RECT rect = GetBoundingBox();
  131. rect.Inflate( aAccuracy );
  132. return rect.Contains( aPosition );
  133. }
  134. bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  135. {
  136. if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT )
  137. return false;
  138. EDA_RECT rect = aRect;
  139. rect.Inflate( aAccuracy );
  140. if( aContained )
  141. return rect.Contains( GetBoundingBox() );
  142. return rect.Intersects( GetBoundingBox() );
  143. }
  144. bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
  145. {
  146. return m_pos == aPosition;
  147. }
  148. void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
  149. {
  150. aPlotter->SetColor( GetLayerColor( GetLayer() ) );
  151. aPlotter->Circle( m_pos, GetEffectiveSymbolSize(), FILLED_SHAPE );
  152. }
  153. BITMAP_DEF SCH_JUNCTION::GetMenuImage() const
  154. {
  155. return add_junction_xpm;
  156. }