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.

373 lines
11 KiB

  1. /******************************************/
  2. /* Kicad: Common plot Postscript Routines */
  3. /******************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "trigo.h"
  7. #include "wxstruct.h"
  8. #include "base_struct.h"
  9. #include "common.h"
  10. #include "plot_common.h"
  11. #include "worksheet.h"
  12. #include "macros.h"
  13. // Variables partagees avec Common plot Postscript et HPLG Routines
  14. wxPoint LastPenPosition;
  15. wxPoint PlotOffset;
  16. FILE* PlotOutputFile;
  17. double XScale, YScale;
  18. int g_DefaultPenWidth;
  19. int g_CurrentPenWidth = -1;
  20. int PlotOrientOptions, etat_plume;
  21. // Locales
  22. static Ki_PageDescr* SheetPS;
  23. /*************************/
  24. void ForcePenReinit()
  25. /*************************/
  26. /* set the flag g_CurrentPenWidth to -1 in order to force a pen width redefinition
  27. * for the next draw command
  28. */
  29. {
  30. g_CurrentPenWidth = -1;
  31. }
  32. /**********************************************/
  33. void SetPlotScale( double xscale, double yscale )
  34. /**********************************************/
  35. /* Set the plot scale for the current plotting)
  36. */
  37. {
  38. XScale = xscale;
  39. YScale = yscale;
  40. }
  41. /*********************************/
  42. void SetPlotOffset( wxPoint offset )
  43. /*********************************/
  44. /* Set the plot offset for the current plotting)
  45. */
  46. {
  47. PlotOffset = offset;
  48. }
  49. /***************************************************************************/
  50. void InitPlotParametresGERBER( wxPoint offset, double xscale, double yscale )
  51. /***************************************************************************/
  52. /* Set the plot offset for the current plotting
  53. * xscale,yscale = coordinate scale (scale coefficient for coordinates)
  54. */
  55. {
  56. PlotOrientOptions = 0;
  57. PlotOffset = offset;
  58. SheetPS = NULL;
  59. XScale = xscale;
  60. YScale = yscale;
  61. g_DefaultPenWidth = 120; /* epaisseur du trait standard en 1/1000 pouce */
  62. g_CurrentPenWidth = -1;
  63. }
  64. /*******************************************************/
  65. void PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
  66. /*******************************************************/
  67. /* Plot sheet references
  68. * margin is in mils (1/1000 inch)
  69. */
  70. {
  71. #define WSTEXTSIZE 50 // Text size in mils
  72. Ki_PageDescr* Sheet = screen->m_CurrentSheetDesc;
  73. int ii, jj, xg, yg, ipas, gxpas, gypas;
  74. wxSize PageSize;
  75. wxPoint pos, ref;
  76. int color;
  77. Ki_WorkSheetData* WsItem;
  78. int conv_unit = screen->GetInternalUnits() / 1000; /* Scale to convert dimension in 1/1000 in into internal units
  79. * (1/1000 inc for EESchema, 1/10000 for pcbnew */
  80. wxString msg;
  81. wxSize text_size;
  82. void (*FctPlume)( wxPoint pos, int state );
  83. int UpperLimit = VARIABLE_BLOCK_START_POSITION;
  84. switch( format_plot )
  85. {
  86. case PLOT_FORMAT_POST:
  87. FctPlume = LineTo_PS;
  88. break;
  89. case PLOT_FORMAT_HPGL:
  90. FctPlume = Move_Plume_HPGL;
  91. break;
  92. case PLOT_FORMAT_GERBER:
  93. default:
  94. return;
  95. }
  96. color = BLACK;
  97. PageSize.x = Sheet->m_Size.x;
  98. PageSize.y = Sheet->m_Size.y;
  99. /* trace de la bordure */
  100. ref.x = Sheet->m_LeftMargin * conv_unit;
  101. ref.y = Sheet->m_TopMargin * conv_unit; /* Upper left corner */
  102. xg = (PageSize.x - Sheet->m_RightMargin) * conv_unit;
  103. yg = (PageSize.y - Sheet->m_BottomMargin) * conv_unit; /* lower right corner */
  104. for( ii = 0; ii < 2; ii++ )
  105. {
  106. FctPlume( ref, 'U' );
  107. pos.x = xg; pos.y = ref.y;
  108. FctPlume( pos, 'D' );
  109. pos.x = xg; pos.y = yg;
  110. FctPlume( pos, 'D' );
  111. pos.x = ref.x; pos.y = yg;
  112. FctPlume( pos, 'D' );
  113. FctPlume( ref, 'D' );
  114. ref.x += GRID_REF_W * conv_unit; ref.y += GRID_REF_W * conv_unit;
  115. xg -= GRID_REF_W * conv_unit; yg -= GRID_REF_W * conv_unit;
  116. }
  117. /* trace des reperes */
  118. text_size.x = WSTEXTSIZE * conv_unit;
  119. text_size.y = WSTEXTSIZE * conv_unit;
  120. ref.x = Sheet->m_LeftMargin;
  121. ref.y = Sheet->m_TopMargin; /* Upper left corner in 1/1000 inch */
  122. xg = (PageSize.x - Sheet->m_RightMargin);
  123. yg = (PageSize.y - Sheet->m_BottomMargin); /* lower right corner in 1/1000 inch */
  124. /* Trace des reperes selon l'axe X */
  125. ipas = (xg - ref.x) / PAS_REF;
  126. gxpas = ( xg - ref.x) / ipas;
  127. for( ii = ref.x + gxpas, jj = 1; ipas > 0; ii += gxpas, jj++, ipas-- )
  128. {
  129. msg.Empty(); msg << jj;
  130. if( ii < xg - PAS_REF / 2 )
  131. {
  132. pos.x = ii * conv_unit; pos.y = ref.y * conv_unit;
  133. FctPlume( pos, 'U' );
  134. pos.x = ii * conv_unit; pos.y = (ref.y + GRID_REF_W) * conv_unit;
  135. FctPlume( pos, 'D' );
  136. }
  137. pos.x = (ii - gxpas / 2) * conv_unit;
  138. pos.y = (ref.y + GRID_REF_W / 2) * conv_unit;
  139. PlotGraphicText( format_plot, pos, color,
  140. msg, TEXT_ORIENT_HORIZ, text_size,
  141. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER );
  142. if( ii < xg - PAS_REF / 2 )
  143. {
  144. pos.x = ii * conv_unit; pos.y = yg * conv_unit;
  145. FctPlume( pos, 'U' );
  146. pos.x = ii * conv_unit; pos.y = (yg - GRID_REF_W) * conv_unit;
  147. FctPlume( pos, 'D' );
  148. }
  149. pos.x = (ii - gxpas / 2) * conv_unit;
  150. pos.y = (yg - GRID_REF_W / 2) * conv_unit;
  151. PlotGraphicText( format_plot, pos, color,
  152. msg, TEXT_ORIENT_HORIZ, text_size,
  153. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER );
  154. }
  155. /* Trace des reperes selon l'axe Y */
  156. ipas = (yg - ref.y) / PAS_REF;
  157. gypas = ( yg - ref.y) / ipas;
  158. for( ii = ref.y + gypas, jj = 0; ipas > 0; ii += gypas, jj++, ipas-- )
  159. {
  160. msg.Empty(); msg << jj;
  161. if( ii < yg - PAS_REF / 2 )
  162. {
  163. pos.x = ref.x * conv_unit; pos.y = ii * conv_unit;
  164. FctPlume( pos, 'U' );
  165. pos.x = (ref.x + GRID_REF_W) * conv_unit; pos.y = ii * conv_unit;
  166. FctPlume( pos, 'D' );
  167. }
  168. pos.x = (ref.x + GRID_REF_W / 2) * conv_unit;
  169. pos.y = (ii - gypas / 2) * conv_unit;
  170. PlotGraphicText( format_plot, pos, color,
  171. msg, TEXT_ORIENT_HORIZ, text_size,
  172. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER );
  173. if( ii < yg - PAS_REF / 2 )
  174. {
  175. pos.x = xg * conv_unit; pos.y = ii * conv_unit;
  176. FctPlume( pos, 'U' );
  177. pos.x = (xg - GRID_REF_W) * conv_unit; pos.y = ii * conv_unit;
  178. FctPlume( pos, 'D' );
  179. }
  180. pos.x = (xg - GRID_REF_W / 2) * conv_unit;
  181. pos.y = (ii - gypas / 2) * conv_unit;
  182. PlotGraphicText( format_plot, pos, color, msg, TEXT_ORIENT_HORIZ, text_size,
  183. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER );
  184. }
  185. /* Trace du cartouche */
  186. text_size.x = SIZETEXT * conv_unit;
  187. text_size.y = SIZETEXT * conv_unit;
  188. ref.x = PageSize.x - GRID_REF_W - Sheet->m_RightMargin;
  189. ref.y = PageSize.y - GRID_REF_W - Sheet->m_BottomMargin;
  190. for( WsItem = &WS_Date; WsItem != NULL; WsItem = WsItem->Pnext )
  191. {
  192. pos.x = (ref.x - WsItem->m_Posx) * conv_unit;
  193. pos.y = (ref.y - WsItem->m_Posy) * conv_unit;
  194. if( WsItem->m_Legende )
  195. msg = WsItem->m_Legende;
  196. else
  197. msg.Empty();
  198. switch( WsItem->m_Type )
  199. {
  200. case WS_DATE:
  201. msg += screen->m_Date;
  202. break;
  203. case WS_REV:
  204. msg += screen->m_Revision;
  205. break;
  206. case WS_KICAD_VERSION:
  207. msg += g_ProductName;
  208. break;
  209. case WS_SIZESHEET:
  210. msg += screen->m_CurrentSheetDesc->m_Name;
  211. break;
  212. case WS_IDENTSHEET:
  213. msg << screen->m_ScreenNumber << wxT( "/" ) << screen->m_NumberOfScreen;
  214. break;
  215. case WS_FILENAME:
  216. {
  217. wxString fname, fext;
  218. wxFileName::SplitPath( screen->m_FileName, (wxString*) NULL, &fname, &fext );
  219. msg << fname << wxT( "." ) << fext;
  220. }
  221. break;
  222. case WS_FULLSHEETNAME:
  223. // msg += GetScreenDesc();
  224. break;
  225. case WS_COMPANY_NAME:
  226. msg += screen->m_Company;
  227. if( !msg.IsEmpty() )
  228. UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
  229. break;
  230. case WS_TITLE:
  231. msg += screen->m_Title;
  232. break;
  233. case WS_COMMENT1:
  234. msg += screen->m_Commentaire1;
  235. if( !msg.IsEmpty() )
  236. UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
  237. break;
  238. case WS_COMMENT2:
  239. msg += screen->m_Commentaire2;
  240. if( !msg.IsEmpty() )
  241. UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
  242. break;
  243. case WS_COMMENT3:
  244. msg += screen->m_Commentaire3;
  245. if( !msg.IsEmpty() )
  246. UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
  247. break;
  248. case WS_COMMENT4:
  249. msg += screen->m_Commentaire4;
  250. if( !msg.IsEmpty() )
  251. UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
  252. break;
  253. case WS_UPPER_SEGMENT:
  254. if( UpperLimit == 0 )
  255. break;
  256. case WS_LEFT_SEGMENT:
  257. WS_MostUpperLine.m_Posy =
  258. WS_MostUpperLine.m_Endy =
  259. WS_MostLeftLine.m_Posy = UpperLimit;
  260. pos.y = (ref.y - WsItem->m_Posy) * conv_unit;
  261. case WS_SEGMENT:
  262. {
  263. wxPoint auxpos;
  264. auxpos.x = (ref.x - WsItem->m_Endx) * conv_unit;;
  265. auxpos.y = (ref.y - WsItem->m_Endy) * conv_unit;;
  266. FctPlume( pos, 'U' );
  267. FctPlume( auxpos, 'D' );
  268. }
  269. break;
  270. }
  271. if( !msg.IsEmpty() )
  272. {
  273. PlotGraphicText( format_plot, pos, color,
  274. msg.GetData(), TEXT_ORIENT_HORIZ, text_size,
  275. GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER );
  276. }
  277. }
  278. switch( format_plot )
  279. {
  280. case PLOT_FORMAT_HPGL:
  281. Plume_HPGL( 'U' );
  282. break;
  283. case PLOT_FORMAT_POST:
  284. break;
  285. }
  286. }
  287. /******************************************/
  288. void UserToDeviceCoordinate( wxPoint& pos )
  289. /******************************************/
  290. /* modifie les coord pos.x et pos.y pour le trace selon l'orientation,
  291. * l'echelle, les offsets de trace */
  292. {
  293. pos.x = (int) (pos.x * XScale);
  294. pos.y = (int) (pos.y * YScale);
  295. switch( PlotOrientOptions ) /* Calcul du cadrage */
  296. {
  297. default:
  298. pos.x -= PlotOffset.x; pos.y = PlotOffset.y - pos.y;
  299. break;
  300. case PLOT_MIROIR:
  301. pos.x -= PlotOffset.x; pos.y = -PlotOffset.y + pos.y;
  302. break;
  303. }
  304. }
  305. /************************************/
  306. void UserToDeviceSize( wxSize& size )
  307. /************************************/
  308. /* modifie les dimension size.x et size.y pour le trace selon l'echelle */
  309. {
  310. size.x = (int) (size.x * XScale);
  311. size.y = (int) (size.y * YScale);
  312. }