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.

256 lines
6.3 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, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2015 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 <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <macros.h>
  31. #include <class_drawpanel.h>
  32. #include <common.h>
  33. #include <plot_common.h>
  34. #include <general.h>
  35. #include <sch_no_connect.h>
  36. #include <class_netlist_object.h>
  37. SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
  38. SCH_ITEM( NULL, SCH_NO_CONNECT_T )
  39. {
  40. #define DRAWNOCONNECT_SIZE 48 /* No symbol connection range. */
  41. m_pos = pos;
  42. m_size.x = m_size.y = DRAWNOCONNECT_SIZE;
  43. #undef DRAWNOCONNECT_SIZE
  44. SetLayer( LAYER_NOCONNECT );
  45. }
  46. EDA_ITEM* SCH_NO_CONNECT::Clone() const
  47. {
  48. return new SCH_NO_CONNECT( *this );
  49. }
  50. void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
  51. {
  52. wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T),
  53. wxT( "Cannot swap no connect data with invalid item." ) );
  54. SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
  55. EXCHG( m_pos, item->m_pos );
  56. EXCHG( m_size, item->m_size );
  57. }
  58. const EDA_RECT SCH_NO_CONNECT::GetBoundingBox() const
  59. {
  60. int delta = ( GetPenSize() + m_size.x ) / 2;
  61. EDA_RECT box;
  62. box.SetOrigin( m_pos );
  63. box.Inflate( delta );
  64. return box;
  65. }
  66. bool SCH_NO_CONNECT::Save( FILE* aFile ) const
  67. {
  68. bool success = true;
  69. if( fprintf( aFile, "NoConn ~ %-4d %-4d\n", m_pos.x, m_pos.y ) == EOF )
  70. {
  71. success = false;
  72. }
  73. return success;
  74. }
  75. bool SCH_NO_CONNECT::Load( LINE_READER& aLine, wxString& aErrorMsg )
  76. {
  77. char name[256];
  78. char* line = (char*) aLine;
  79. while( (*line != ' ' ) && *line )
  80. line++;
  81. if( sscanf( line, "%s %d %d", name, &m_pos.x, &m_pos.y ) != 3 )
  82. {
  83. aErrorMsg.Printf( wxT( "Eeschema file No Connect load error at line %d" ),
  84. aLine.LineNumber() );
  85. aErrorMsg << wxT( "\n" ) << FROM_UTF8( ((char*)aLine) );
  86. return false;
  87. }
  88. return true;
  89. }
  90. void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
  91. {
  92. DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
  93. aItemList.push_back( item );
  94. }
  95. int SCH_NO_CONNECT::GetPenSize() const
  96. {
  97. return GetDefaultLineThickness();
  98. }
  99. void SCH_NO_CONNECT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  100. GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor )
  101. {
  102. int pX, pY;
  103. int delta = m_size.x / 2;
  104. int width = GetDefaultLineThickness();
  105. pX = m_pos.x + aOffset.x;
  106. pY = m_pos.y + aOffset.y;
  107. EDA_COLOR_T color;
  108. if( aColor >= 0 )
  109. color = aColor;
  110. else
  111. color = GetLayerColor( LAYER_NOCONNECT );
  112. GRSetDrawMode( aDC, aDrawMode );
  113. GRLine( aPanel->GetClipBox(), aDC, pX - delta, pY - delta, pX + delta, pY + delta,
  114. width, color );
  115. GRLine( aPanel->GetClipBox(), aDC, pX + delta, pY - delta, pX - delta, pY + delta,
  116. width, color );
  117. }
  118. void SCH_NO_CONNECT::MirrorX( int aXaxis_position )
  119. {
  120. m_pos.y -= aXaxis_position;
  121. NEGATE( m_pos.y );
  122. m_pos.y += aXaxis_position;
  123. }
  124. void SCH_NO_CONNECT::MirrorY( int aYaxis_position )
  125. {
  126. m_pos.x -= aYaxis_position;
  127. NEGATE( m_pos.x );
  128. m_pos.x += aYaxis_position;
  129. }
  130. void SCH_NO_CONNECT::Rotate( wxPoint aPosition )
  131. {
  132. RotatePoint( &m_pos, aPosition, 900 );
  133. }
  134. bool SCH_NO_CONNECT::IsSelectStateChanged( const wxRect& aRect )
  135. {
  136. bool previousState = IsSelected();
  137. if( aRect.Contains( m_pos ) )
  138. SetFlags( SELECTED );
  139. else
  140. ClearFlags( SELECTED );
  141. return previousState != IsSelected();
  142. }
  143. void SCH_NO_CONNECT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
  144. {
  145. aPoints.push_back( m_pos );
  146. }
  147. void SCH_NO_CONNECT::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
  148. SCH_SHEET_PATH* aSheetPath )
  149. {
  150. NETLIST_OBJECT* item = new NETLIST_OBJECT();
  151. item->m_SheetPath = *aSheetPath;
  152. item->m_SheetPathInclude = *aSheetPath;
  153. item->m_Comp = this;
  154. item->m_Type = NET_NOCONNECT;
  155. item->m_Start = item->m_End = m_pos;
  156. aNetListItems.push_back( item );
  157. }
  158. bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
  159. {
  160. return m_pos == aPosition;
  161. }
  162. bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  163. {
  164. int delta = ( ( m_size.x + GetDefaultLineThickness() ) / 2 ) + aAccuracy;
  165. wxPoint dist = aPosition - m_pos;
  166. if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
  167. return true;
  168. return false;
  169. }
  170. bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  171. {
  172. EDA_RECT rect = aRect;
  173. rect.Inflate( aAccuracy );
  174. if( aContained )
  175. return rect.Contains( GetBoundingBox() );
  176. return rect.Intersects( GetBoundingBox() );
  177. }
  178. void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter )
  179. {
  180. int delta = m_size.x / 2;
  181. int pX, pY;
  182. pX = m_pos.x;
  183. pY = m_pos.y;
  184. aPlotter->SetCurrentLineWidth( GetPenSize() );
  185. aPlotter->SetColor( GetLayerColor( GetLayer() ) );
  186. aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
  187. aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
  188. aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
  189. aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
  190. }