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.

265 lines
6.5 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-2020 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 <sch_draw_panel.h>
  28. #include <trigo.h>
  29. #include <common.h>
  30. #include <plotter.h>
  31. #include <bitmaps.h>
  32. #include <macros.h>
  33. #include <geometry/shape_rect.h>
  34. #include <sch_painter.h>
  35. #include <sch_junction.h>
  36. #include <sch_connection.h>
  37. #include <schematic.h>
  38. #include <settings/color_settings.h>
  39. SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
  40. SCH_ITEM( NULL, SCH_JUNCTION_T )
  41. {
  42. m_pos = aPosition;
  43. m_color = COLOR4D::UNSPECIFIED;
  44. m_diameter = aDiameter;
  45. m_Layer = aLayer;
  46. }
  47. EDA_ITEM* SCH_JUNCTION::Clone() const
  48. {
  49. return new SCH_JUNCTION( *this );
  50. }
  51. void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
  52. {
  53. wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
  54. wxT( "Cannot swap junction data with invalid item." ) );
  55. SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
  56. std::swap( m_pos, item->m_pos );
  57. std::swap( m_diameter, item->m_diameter );
  58. std::swap( m_color, item->m_color );
  59. }
  60. void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
  61. {
  62. aCount = 2;
  63. aLayers[0] = m_Layer;
  64. aLayers[1] = LAYER_SELECTION_SHADOWS;
  65. }
  66. SHAPE_CIRCLE SCH_JUNCTION::getEffectiveShape() const
  67. {
  68. int diameter;
  69. if( m_diameter != 0 )
  70. diameter = m_diameter;
  71. else if( Schematic() )
  72. diameter = Schematic()->Settings().m_JunctionSize;
  73. else
  74. diameter = Mils2iu( DEFAULT_JUNCTION_DIAM );
  75. if( diameter != 1 ) // Diameter 1 means users doesn't want to draw junction dots
  76. {
  77. NETCLASSPTR netclass = NetClass();
  78. if( netclass )
  79. diameter = std::max( diameter, KiROUND( netclass->GetWireWidth() * 1.7 ) );
  80. }
  81. return SHAPE_CIRCLE( m_pos, std::max( diameter / 2, 1 ) );
  82. }
  83. const EDA_RECT SCH_JUNCTION::GetBoundingBox() const
  84. {
  85. EDA_RECT rect;
  86. rect.SetOrigin( m_pos );
  87. rect.Inflate( getEffectiveShape().GetRadius() );
  88. return rect;
  89. }
  90. void SCH_JUNCTION::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
  91. {
  92. wxDC* DC = aSettings->GetPrintDC();
  93. COLOR4D color = GetJunctionColor();
  94. if( color == COLOR4D::UNSPECIFIED )
  95. color = aSettings->GetLayerColor( GetLayer() );
  96. SHAPE_CIRCLE circle = getEffectiveShape();
  97. GRFilledCircle( NULL, DC, (wxPoint) circle.GetCenter() + aOffset, circle.GetRadius(), color );
  98. }
  99. void SCH_JUNCTION::MirrorX( int aXaxis_position )
  100. {
  101. MIRROR( m_pos.y, aXaxis_position );
  102. }
  103. void SCH_JUNCTION::MirrorY( int aYaxis_position )
  104. {
  105. MIRROR( m_pos.x, aYaxis_position );
  106. }
  107. void SCH_JUNCTION::Rotate( wxPoint aPosition )
  108. {
  109. RotatePoint( &m_pos, aPosition, 900 );
  110. }
  111. void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
  112. {
  113. DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
  114. aItemList.push_back( item );
  115. }
  116. std::vector<wxPoint> SCH_JUNCTION::GetConnectionPoints() const
  117. {
  118. return { m_pos };
  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 << ", " << m_diameter
  126. << "/>\n";
  127. }
  128. #endif
  129. COLOR4D SCH_JUNCTION::GetJunctionColor() const
  130. {
  131. if( m_color != COLOR4D::UNSPECIFIED )
  132. return m_color;
  133. NETCLASSPTR netclass = NetClass();
  134. if( netclass )
  135. return netclass->GetSchematicColor();
  136. return COLOR4D::UNSPECIFIED;
  137. }
  138. int SCH_JUNCTION::GetDiameter() const
  139. {
  140. return getEffectiveShape().GetRadius() * 2;
  141. }
  142. bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  143. {
  144. return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
  145. }
  146. bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  147. {
  148. if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT )
  149. return false;
  150. if( aContained )
  151. {
  152. EDA_RECT selRect = aRect;
  153. selRect.Inflate( aAccuracy );
  154. return selRect.Contains( GetBoundingBox() );
  155. }
  156. else
  157. {
  158. SHAPE_CIRCLE junction = getEffectiveShape();
  159. SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
  160. return selRect.Collide( &junction, aAccuracy );
  161. }
  162. }
  163. bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
  164. {
  165. return m_pos == aPosition;
  166. }
  167. void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
  168. {
  169. auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
  170. COLOR4D color = GetJunctionColor();
  171. if( color == COLOR4D::UNSPECIFIED )
  172. color = settings->GetLayerColor( GetLayer() );
  173. aPlotter->SetColor( color );
  174. aPlotter->Circle( m_pos, GetDiameter(), FILL_TYPE::FILLED_SHAPE );
  175. }
  176. BITMAP_DEF SCH_JUNCTION::GetMenuImage() const
  177. {
  178. return add_junction_xpm;
  179. }
  180. bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
  181. {
  182. if( Type() != aItem.Type() )
  183. return Type() < aItem.Type();
  184. if( GetLayer() != aItem.GetLayer() )
  185. return GetLayer() < aItem.GetLayer();
  186. auto junction = static_cast<const SCH_JUNCTION*>( &aItem );
  187. if( GetPosition().x != junction->GetPosition().x )
  188. return GetPosition().x < junction->GetPosition().x;
  189. if( GetPosition().y != junction->GetPosition().y )
  190. return GetPosition().y < junction->GetPosition().y;
  191. if( GetDiameter() != junction->GetDiameter() )
  192. return GetDiameter() < junction->GetDiameter();
  193. return GetColor() < junction->GetColor();
  194. }