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.

327 lines
8.1 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
17 years ago
17 years ago
18 years ago
18 years ago
18 years ago
18 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) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  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. #include <fctsys.h>
  25. #include <gr_basic.h>
  26. #include <sch_draw_panel.h>
  27. #include <draw_graphic_text.h>
  28. #include <plotter.h>
  29. #include <trigo.h>
  30. #include <richio.h>
  31. #include <sch_edit_frame.h>
  32. #include <bitmaps.h>
  33. #include <general.h>
  34. #include <sch_sheet.h>
  35. #include <kicad_string.h>
  36. #include <trace_helpers.h>
  37. SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
  38. SCH_HIERLABEL( pos, text, SCH_SHEET_PIN_T ),
  39. m_edge( SHEET_UNDEFINED_SIDE )
  40. {
  41. SetParent( parent );
  42. wxASSERT( parent );
  43. m_Layer = LAYER_SHEETLABEL;
  44. SetTextPos( pos );
  45. if( parent->IsVerticalOrientation() )
  46. SetEdge( SHEET_TOP_SIDE );
  47. else
  48. SetEdge( SHEET_LEFT_SIDE );
  49. m_shape = NET_INPUT;
  50. m_isDangling = true;
  51. m_number = 2;
  52. }
  53. EDA_ITEM* SCH_SHEET_PIN::Clone() const
  54. {
  55. return new SCH_SHEET_PIN( *this );
  56. }
  57. void SCH_SHEET_PIN::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset )
  58. {
  59. // The icon selection is handle by the virtual method CreateGraphicShape
  60. // called by ::Draw
  61. SCH_HIERLABEL::Draw( aPanel, aDC, aOffset );
  62. }
  63. void SCH_SHEET_PIN::SwapData( SCH_ITEM* aItem )
  64. {
  65. wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
  66. wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ),
  67. GetChars( aItem->GetClass() ) ) );
  68. SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem;
  69. SCH_TEXT::SwapData( (SCH_TEXT*) pin );
  70. int tmp = pin->GetNumber();
  71. pin->SetNumber( GetNumber() );
  72. SetNumber( tmp );
  73. SHEET_SIDE stmp = pin->GetEdge();
  74. pin->SetEdge( GetEdge() );
  75. SetEdge( stmp );
  76. }
  77. bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
  78. {
  79. return aPin == this;
  80. }
  81. int SCH_SHEET_PIN::GetPenSize() const
  82. {
  83. return GetDefaultLineThickness();
  84. }
  85. void SCH_SHEET_PIN::SetNumber( int aNumber )
  86. {
  87. wxASSERT( aNumber >= 2 );
  88. m_number = aNumber;
  89. }
  90. void SCH_SHEET_PIN::SetEdge( SHEET_SIDE aEdge )
  91. {
  92. SCH_SHEET* Sheet = GetParent();
  93. // use SHEET_UNDEFINED_SIDE to adjust text orientation without changing edge
  94. switch( aEdge )
  95. {
  96. case SHEET_LEFT_SIDE:
  97. m_edge = aEdge;
  98. SetTextX( Sheet->m_pos.x );
  99. SetLabelSpinStyle( 2 ); // Orientation horiz inverse
  100. break;
  101. case SHEET_RIGHT_SIDE:
  102. m_edge = aEdge;
  103. SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
  104. SetLabelSpinStyle( 0 ); // Orientation horiz normal
  105. break;
  106. case SHEET_TOP_SIDE:
  107. m_edge = aEdge;
  108. SetTextY( Sheet->m_pos.y );
  109. SetLabelSpinStyle( 3 ); // Orientation vert BOTTOM
  110. break;
  111. case SHEET_BOTTOM_SIDE:
  112. m_edge = aEdge;
  113. SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
  114. SetLabelSpinStyle( 1 ); // Orientation vert UP
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. enum SHEET_SIDE SCH_SHEET_PIN::GetEdge() const
  121. {
  122. return m_edge;
  123. }
  124. void SCH_SHEET_PIN::ConstrainOnEdge( wxPoint Pos )
  125. {
  126. SCH_SHEET* sheet = GetParent();
  127. if( sheet == NULL )
  128. return;
  129. wxPoint center = sheet->m_pos + ( sheet->m_size / 2 );
  130. if( m_edge == SHEET_LEFT_SIDE || m_edge == SHEET_RIGHT_SIDE )
  131. {
  132. if( Pos.x > center.x )
  133. SetEdge( SHEET_RIGHT_SIDE );
  134. else
  135. SetEdge( SHEET_LEFT_SIDE );
  136. SetTextY( Pos.y );
  137. if( GetTextPos().y < sheet->m_pos.y )
  138. SetTextY( sheet->m_pos.y );
  139. if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
  140. SetTextY( sheet->m_pos.y + sheet->m_size.y );
  141. }
  142. else
  143. {
  144. if( Pos.y > center.y )
  145. SetEdge( SHEET_BOTTOM_SIDE );
  146. else
  147. SetEdge( SHEET_TOP_SIDE );
  148. SetTextX( Pos.x );
  149. if( GetTextPos().x < sheet->m_pos.x )
  150. SetTextX( sheet->m_pos.x );
  151. if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
  152. SetTextX( sheet->m_pos.x + sheet->m_size.x );
  153. }
  154. }
  155. bool SCH_SHEET_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData )
  156. {
  157. wxCHECK_MSG( GetParent() != NULL, false,
  158. wxT( "Sheet pin " ) + m_Text + wxT( " does not have a parent sheet!" ) );
  159. wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText( MILLIMETRES ) );
  160. return SCH_ITEM::Matches( m_Text, aSearchData );
  161. }
  162. void SCH_SHEET_PIN::MirrorX( int aXaxis_position )
  163. {
  164. int p = GetTextPos().y - aXaxis_position;
  165. SetTextY( aXaxis_position - p );
  166. switch( m_edge )
  167. {
  168. case SHEET_TOP_SIDE: SetEdge( SHEET_BOTTOM_SIDE ); break;
  169. case SHEET_BOTTOM_SIDE: SetEdge( SHEET_TOP_SIDE ); break;
  170. default: break;
  171. }
  172. }
  173. void SCH_SHEET_PIN::MirrorY( int aYaxis_position )
  174. {
  175. int p = GetTextPos().x - aYaxis_position;
  176. SetTextX( aYaxis_position - p );
  177. switch( m_edge )
  178. {
  179. case SHEET_LEFT_SIDE: SetEdge( SHEET_RIGHT_SIDE ); break;
  180. case SHEET_RIGHT_SIDE: SetEdge( SHEET_LEFT_SIDE ); break;
  181. default: break;
  182. }
  183. }
  184. void SCH_SHEET_PIN::Rotate( wxPoint aPosition )
  185. {
  186. wxPoint pt = GetTextPos();
  187. RotatePoint( &pt, aPosition, 900 );
  188. SetTextPos( pt );
  189. switch( m_edge )
  190. {
  191. case SHEET_LEFT_SIDE: SetEdge( SHEET_BOTTOM_SIDE ); break;
  192. case SHEET_RIGHT_SIDE: SetEdge( SHEET_TOP_SIDE ); break;
  193. case SHEET_TOP_SIDE: SetEdge( SHEET_LEFT_SIDE ); break;
  194. case SHEET_BOTTOM_SIDE: SetEdge( SHEET_RIGHT_SIDE ); break;
  195. default: break;
  196. }
  197. }
  198. void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos )
  199. {
  200. /* This is the same icon shapes as SCH_HIERLABEL
  201. * but the graphic icon is slightly different in 2 cases:
  202. * for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
  203. * for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
  204. */
  205. PINSHEETLABEL_SHAPE tmp = m_shape;
  206. switch( m_shape )
  207. {
  208. case NET_INPUT:
  209. m_shape = NET_OUTPUT;
  210. break;
  211. case NET_OUTPUT:
  212. m_shape = NET_INPUT;
  213. break;
  214. default:
  215. break;
  216. }
  217. SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );
  218. m_shape = tmp;
  219. }
  220. void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
  221. {
  222. DANGLING_END_ITEM item( SHEET_LABEL_END, this, GetTextPos() );
  223. aItemList.push_back( item );
  224. }
  225. wxString SCH_SHEET_PIN::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  226. {
  227. return wxString::Format( _( "Hierarchical Sheet Pin %s" ), ShortenedShownText() );
  228. }
  229. BITMAP_DEF SCH_SHEET_PIN::GetMenuImage() const
  230. {
  231. return add_hierar_pin_xpm;
  232. }
  233. bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const
  234. {
  235. EDA_RECT rect = GetBoundingBox();
  236. rect.Inflate( aAccuracy );
  237. return rect.Contains( aPoint );
  238. }
  239. #if defined(DEBUG)
  240. void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os ) const
  241. {
  242. // XML output:
  243. wxString s = GetClass();
  244. NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
  245. << " pin_name=\"" << TO_UTF8( m_Text )
  246. << '"' << "/>\n" << std::flush;
  247. // NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
  248. }
  249. #endif