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.

264 lines
8.2 KiB

  1. /***********************************************************************/
  2. /* Methodes de base de gestion des classes des elements de schematique */
  3. /***********************************************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "common.h"
  7. #include "program.h"
  8. #include "libcmp.h"
  9. #include "general.h"
  10. #include "id.h"
  11. #include "protos.h"
  12. /************************/
  13. /* class DrawTextStruct */
  14. /* class DrawLabelStruct */
  15. /* class DrawGlobalLabelStruct */
  16. /************************/
  17. /**************************************************************************/
  18. DrawTextStruct::DrawTextStruct(const wxPoint & pos, const wxString & text):
  19. EDA_BaseStruct(DRAW_TEXT_STRUCT_TYPE),
  20. EDA_TextStruct(text)
  21. /**************************************************************************/
  22. {
  23. m_Layer = LAYER_NOTES;
  24. m_Pos = pos;
  25. m_Shape = 0;
  26. m_IsDangling = FALSE;
  27. }
  28. /*********************************************/
  29. DrawTextStruct * DrawTextStruct::GenCopy(void)
  30. /*********************************************/
  31. {
  32. DrawTextStruct * newitem = new DrawTextStruct(m_Pos, m_Text);
  33. newitem->m_StructType = m_StructType;
  34. newitem->m_Layer = m_Layer;
  35. newitem->m_Shape = m_Shape;
  36. newitem->m_Orient = m_Orient;
  37. newitem->m_Size = m_Size;
  38. newitem->m_Width = m_Width;
  39. newitem->m_HJustify = m_HJustify;
  40. newitem->m_VJustify = m_VJustify;
  41. newitem->m_IsDangling = m_IsDangling ;
  42. return newitem;
  43. }
  44. /********************************************************/
  45. void DrawTextStruct::SwapData(DrawTextStruct * copyitem)
  46. /********************************************************/
  47. {
  48. EXCHG(m_Text, copyitem->m_Text);
  49. EXCHG(m_Pos, copyitem->m_Pos);
  50. EXCHG(m_Size, copyitem->m_Size);
  51. EXCHG(m_Width, copyitem->m_Width);
  52. EXCHG(m_Shape, copyitem->m_Shape);
  53. EXCHG(m_Orient, copyitem->m_Orient);
  54. EXCHG(m_StructType, copyitem->m_StructType);
  55. EXCHG(m_Layer, copyitem->m_Layer);
  56. EXCHG(m_HJustify, copyitem->m_HJustify);
  57. EXCHG(m_VJustify, copyitem->m_VJustify);
  58. EXCHG(m_IsDangling, copyitem->m_IsDangling);
  59. }
  60. /***************************************************************/
  61. void DrawTextStruct::Place(WinEDA_DrawFrame * frame, wxDC * DC)
  62. /***************************************************************/
  63. {
  64. /* save old text in undo list */
  65. if ( g_ItemToUndoCopy && ((m_Flags & IS_NEW) == 0) )
  66. {
  67. /* restore old values and save new ones */
  68. SwapData( (DrawTextStruct*)g_ItemToUndoCopy);
  69. /* save in undo list */
  70. ((WinEDA_SchematicFrame*)frame)->SaveCopyInUndoList(this, IS_CHANGED);
  71. /* restore new values */
  72. SwapData((DrawTextStruct*)g_ItemToUndoCopy);
  73. delete g_ItemToUndoCopy;
  74. g_ItemToUndoCopy = NULL;
  75. }
  76. EDA_BaseStruct::Place(frame, DC);
  77. }
  78. /****************************************************************************/
  79. DrawLabelStruct::DrawLabelStruct(const wxPoint & pos, const wxString & text):
  80. DrawTextStruct(pos, text)
  81. /****************************************************************************/
  82. {
  83. m_StructType = DRAW_LABEL_STRUCT_TYPE;
  84. m_Layer = LAYER_LOCLABEL;
  85. m_IsDangling = TRUE;
  86. }
  87. /***********************************************************************************/
  88. DrawGlobalLabelStruct::DrawGlobalLabelStruct(const wxPoint & pos, const wxString & text):
  89. DrawTextStruct(pos, text)
  90. /***********************************************************************************/
  91. {
  92. m_StructType = DRAW_GLOBAL_LABEL_STRUCT_TYPE;
  93. m_Layer = LAYER_GLOBLABEL;
  94. m_Shape = NET_INPUT;
  95. m_IsDangling = TRUE;
  96. }
  97. /***************************************************************/
  98. void DrawTextStruct::Draw(WinEDA_DrawPanel * panel,wxDC * DC, const wxPoint & offset,
  99. int DrawMode, int Color)
  100. /***************************************************************/
  101. /* Les textes type label ou notes peuvent avoir 4 directions, mais
  102. sont tj cadres par rapport a la 1ere lettre du texte
  103. */
  104. {
  105. switch ( m_StructType )
  106. {
  107. case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
  108. DrawAsGlobalLabel(panel, DC, offset, DrawMode, Color);
  109. break;
  110. case DRAW_LABEL_STRUCT_TYPE:
  111. DrawAsLabel(panel, DC, offset, DrawMode, Color);
  112. break;
  113. default:
  114. DrawAsText(panel, DC, offset, DrawMode, Color);
  115. }
  116. }
  117. /*******************************************************************************************/
  118. void DrawTextStruct::DrawAsText(WinEDA_DrawPanel * panel,wxDC * DC, const wxPoint & offset,
  119. int DrawMode, int Color)
  120. /*******************************************************************************************/
  121. /* Texts type Label or Comment (text on layer "NOTE") have 4 directions, and the Text origin is the first letter
  122. */
  123. {
  124. int color;
  125. int width = MAX(m_Width, g_DrawMinimunLineWidth);
  126. if( Color >= 0 ) color = Color;
  127. else color = ReturnLayerColor(m_Layer);
  128. GRSetDrawMode(DC, DrawMode);
  129. switch(m_Orient)
  130. {
  131. case 0: /* Orientation horiz normale */
  132. DrawGraphicText(panel, DC,
  133. wxPoint(m_Pos.x + offset.x, m_Pos.y - TXTMARGE + offset.y),
  134. color,
  135. m_Text, m_Orient*900, m_Size,
  136. GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM, width);
  137. break;
  138. case 1: /* Orientation vert UP */
  139. DrawGraphicText(panel, DC,
  140. wxPoint(m_Pos.x - TXTMARGE + offset.x, m_Pos.y + offset.y), color,
  141. m_Text, m_Orient*900, m_Size,
  142. GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, width);
  143. break;
  144. case 2: /* Orientation horiz inverse */
  145. DrawGraphicText(panel, DC,
  146. wxPoint(m_Pos.x + offset.x, m_Pos.y + TXTMARGE + offset.y), color,
  147. m_Text, m_Orient*900, m_Size,
  148. GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_TOP, width);
  149. break;
  150. case 3: /* Orientation vert BOTTOM */
  151. DrawGraphicText(panel, DC,
  152. wxPoint(m_Pos.x + TXTMARGE + offset.y, m_Pos.y + offset.y), color,
  153. m_Text, m_Orient*900, m_Size,
  154. GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, width);
  155. break;
  156. }
  157. if ( m_IsDangling )
  158. DrawDanglingSymbol(panel, DC, m_Pos + offset, color);
  159. }
  160. /***************************************************************/
  161. void DrawTextStruct::DrawAsLabel(WinEDA_DrawPanel * panel,wxDC * DC, const wxPoint & offset,
  162. int DrawMode, int Color)
  163. /***************************************************************/
  164. {
  165. DrawAsText(panel, DC, offset, DrawMode, Color);
  166. }
  167. /*****************************************************************************/
  168. void DrawTextStruct::DrawAsGlobalLabel(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint& offset,
  169. int DrawMode, int Color)
  170. /*****************************************************************************/
  171. /* Texts type Global Label have 4 directions, and the Text origin is the graphic icon
  172. */
  173. {
  174. int * Template;
  175. int Poly[12];
  176. int ii, jj, imax, color, HalfSize;
  177. wxSize Size = m_Size;
  178. int width = MAX(m_Width, g_DrawMinimunLineWidth);
  179. if( Color >= 0 ) color = Color;
  180. else color = ReturnLayerColor(m_Layer);
  181. GRSetDrawMode(DC, DrawMode);
  182. HalfSize = Size.x / 2; ii = Size.x + TXTMARGE;
  183. switch(m_Orient)
  184. {
  185. case 0: /* Orientation horiz normale */
  186. DrawGraphicText(panel, DC,
  187. wxPoint(m_Pos.x - ii + offset.x, m_Pos.y + offset.y), color,
  188. m_Text, TEXT_ORIENT_HORIZ, Size,
  189. GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, width);
  190. break;
  191. case 1: /* Orientation vert UP */
  192. DrawGraphicText(panel, DC,
  193. wxPoint(m_Pos.x + offset.x, m_Pos.y + ii + offset.y), color,
  194. m_Text, TEXT_ORIENT_VERT, Size,
  195. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, width);
  196. break;
  197. case 2: /* Orientation horiz inverse */
  198. DrawGraphicText(panel, DC,
  199. wxPoint(m_Pos.x + ii + offset.x, m_Pos.y + offset.y), color,
  200. m_Text, TEXT_ORIENT_HORIZ, Size,
  201. GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, width);
  202. break;
  203. case 3: /* Orientation vert BOTTOM */
  204. DrawGraphicText(panel, DC,
  205. wxPoint(m_Pos.x + offset.x, m_Pos.y - ii + offset.y), color,
  206. m_Text, TEXT_ORIENT_VERT, Size,
  207. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM, width);
  208. break;
  209. }
  210. Template = TemplateShape[m_Shape][m_Orient];
  211. imax = *Template; Template++;
  212. for ( ii = 0, jj = 0; ii < imax ; ii++ )
  213. {
  214. Poly[jj] = ( HalfSize * (*Template) ) + m_Pos.x + offset.x;
  215. jj++; Template++;
  216. Poly[jj] = ( HalfSize * (*Template) ) + m_Pos.y + offset.y;
  217. jj++; Template++;
  218. }
  219. // GRPoly(&panel->m_ClipBox, DC, imax,Poly,1, width, color, color ); /* Polygne Rempli */
  220. GRPoly(&panel->m_ClipBox, DC, imax,Poly,0, width, color, color ); /* Polygne Non Rempli */
  221. if ( m_IsDangling )
  222. DrawDanglingSymbol(panel, DC, m_Pos + offset, color);
  223. }