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.

219 lines
6.1 KiB

18 years ago
18 years ago
18 years ago
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: class_hierarchical_PIN_sheet.cpp
  3. // Purpose: member functions Hierarchical_PIN_Sheet_Struct
  4. // header = class_drawsheet.h
  5. // Author: jean-pierre Charras
  6. // Modified by:
  7. // Created: 08/02/2006 18:37:02
  8. // RCS-ID:
  9. // Copyright: License GNU
  10. // Licence:
  11. /////////////////////////////////////////////////////////////////////////////
  12. // For compilers that support precompilation, includes "wx/wx.h".
  13. #include "wx/wxprec.h"
  14. #ifdef __BORLANDC__
  15. #pragma hdrstop
  16. #endif
  17. #ifndef WX_PRECOMP
  18. #include "wx/wx.h"
  19. #endif
  20. #include "fctsys.h"
  21. #include "gr_basic.h"
  22. #include "common.h"
  23. #include "program.h"
  24. #include "libcmp.h"
  25. #include "general.h"
  26. #include "protos.h"
  27. /*******************************************************************/
  28. Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent,
  29. const wxPoint& pos, const wxString& text ) :
  30. SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ),
  31. EDA_TextStruct( text )
  32. /*******************************************************************/
  33. {
  34. wxASSERT( parent );
  35. wxASSERT( Pnext == NULL );
  36. m_Layer = LAYER_SHEETLABEL;
  37. m_Pos = pos;
  38. m_Edge = 0;
  39. m_Shape = NET_INPUT;
  40. m_IsDangling = TRUE;
  41. m_Number = 2;
  42. }
  43. /***********************************************************/
  44. Hierarchical_PIN_Sheet_Struct* Hierarchical_PIN_Sheet_Struct::GenCopy()
  45. /***********************************************************/
  46. {
  47. Hierarchical_PIN_Sheet_Struct* newitem =
  48. new Hierarchical_PIN_Sheet_Struct( (DrawSheetStruct*) m_Parent, m_Pos, m_Text );
  49. newitem->m_Edge = m_Edge;
  50. newitem->m_Shape = m_Shape;
  51. newitem->m_Number = m_Number;
  52. return newitem;
  53. }
  54. /********************************************************************************************/
  55. void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
  56. int DrawMode, int Color )
  57. /********************************************************************************************/
  58. /* Routine de dessin des Labels type hierarchie */
  59. {
  60. int side, txtcolor;
  61. int posx, tposx, posy, size2;
  62. wxSize size;
  63. int NbSegm, coord[20];
  64. int LineWidth = g_DrawMinimunLineWidth;
  65. if( Color >= 0 )
  66. txtcolor = Color;
  67. else
  68. txtcolor = ReturnLayerColor( m_Layer );
  69. GRSetDrawMode( DC, DrawMode );
  70. posx = m_Pos.x + offset.x; posy = m_Pos.y + offset.y; size = m_Size;
  71. if( !m_Text.IsEmpty() )
  72. {
  73. if( m_Edge )
  74. {
  75. tposx = posx - size.x;
  76. side = GR_TEXT_HJUSTIFY_RIGHT;
  77. }
  78. else
  79. {
  80. tposx = posx + size.x + (size.x / 8);
  81. side = GR_TEXT_HJUSTIFY_LEFT;
  82. }
  83. DrawGraphicText( panel, DC, wxPoint( tposx, posy ), txtcolor,
  84. m_Text, TEXT_ORIENT_HORIZ, size,
  85. side, GR_TEXT_VJUSTIFY_CENTER, LineWidth );
  86. }
  87. /* dessin du symbole de connexion */
  88. if( m_Edge )
  89. {
  90. size.x = -size.x;
  91. size.y = -size.y;
  92. }
  93. coord[0] = posx; coord[1] = posy; size2 = size.x / 2;
  94. NbSegm = 0;
  95. switch( m_Shape )
  96. {
  97. case 0: /* input |> */
  98. coord[2] = posx; coord[3] = posy - size2;
  99. coord[4] = posx + size2; coord[5] = posy - size2;
  100. coord[6] = posx + size.x; coord[7] = posy;
  101. coord[8] = posx + size2; coord[9] = posy + size2;
  102. coord[10] = posx; coord[11] = posy + size2;
  103. coord[12] = coord[0]; coord[13] = coord[1];
  104. NbSegm = 7;
  105. break;
  106. case 1: /* output <| */
  107. coord[2] = posx + size2; coord[3] = posy - size2;
  108. coord[4] = posx + size.x; coord[5] = posy - size2;
  109. coord[6] = posx + size.x; coord[7] = posy + size2;
  110. coord[8] = posx + size2; coord[9] = posy + size2;
  111. coord[10] = coord[0]; coord[11] = coord[1];
  112. NbSegm = 6;
  113. break;
  114. case 2: /* bidi <> */
  115. case 3: /* TriSt <> */
  116. coord[2] = posx + size2; coord[3] = posy - size2;
  117. coord[4] = posx + size.x; coord[5] = posy;
  118. coord[6] = posx + size2; coord[7] = posy + size2;
  119. coord[8] = coord[0]; coord[9] = coord[1];
  120. NbSegm = 5;
  121. break;
  122. default: /* unsp []*/
  123. coord[2] = posx; coord[3] = posy - size2;
  124. coord[4] = posx + size.x; coord[5] = posy - size2;
  125. coord[6] = posx + size.x; coord[7] = posy + size2;
  126. coord[8] = posx; coord[9] = posy + size2;
  127. coord[10] = coord[0]; coord[11] = coord[1];
  128. NbSegm = 6;
  129. break;
  130. }
  131. int FillShape = FALSE;
  132. GRPoly( &panel->m_ClipBox, DC, NbSegm, coord, FillShape, LineWidth, txtcolor, txtcolor ); /* Poly Non rempli */
  133. }
  134. /**
  135. * Function Save
  136. * writes the data structures for this object out to a FILE in "*.brd" format.
  137. * @param aFile The FILE to write to.
  138. * @return bool - true if success writing else false.
  139. */
  140. bool Hierarchical_PIN_Sheet_Struct::Save( FILE* aFile ) const
  141. {
  142. int type = 'U', side = 'L';
  143. if( m_Text.IsEmpty() )
  144. return true;
  145. if( m_Edge )
  146. side = 'R';
  147. switch( m_Shape )
  148. {
  149. case NET_INPUT:
  150. type = 'I'; break;
  151. case NET_OUTPUT:
  152. type = 'O'; break;
  153. case NET_BIDI:
  154. type = 'B'; break;
  155. case NET_TRISTATE:
  156. type = 'T'; break;
  157. case NET_UNSPECIFIED:
  158. type = 'U'; break;
  159. }
  160. if( fprintf( aFile, "F%d \"%s\" %c %c %-3d %-3d %-3d\n", m_Number,
  161. CONV_TO_UTF8( m_Text ), type, side,
  162. m_Pos.x, m_Pos.y,
  163. m_Size.x ) == EOF )
  164. {
  165. return false;
  166. }
  167. return true;
  168. }
  169. #if defined(DEBUG)
  170. void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
  171. {
  172. // XML output:
  173. wxString s = GetClass();
  174. NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
  175. << " pin_name=\"" << CONV_TO_UTF8( m_Text ) << '"'
  176. << "/>\n"
  177. << std::flush;
  178. // NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
  179. }
  180. #endif