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.

130 lines
4.0 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
  1. /*************************/
  2. /**** Plot Postscript ****/
  3. /*************************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "plot_common.h"
  7. #include "confirm.h"
  8. #include "pcbnew.h"
  9. #include "pcbplot.h"
  10. #include "trigo.h"
  11. #include "protos.h"
  12. /* Generate a PostScript file (*. ps) of the circuit layer.
  13. * If layer < 0: all layers are plotted.
  14. */
  15. bool PCB_BASE_FRAME::Genere_PS( const wxString& FullFileName, int Layer,
  16. bool useA4, GRTraceMode trace_mode )
  17. {
  18. wxSize SheetSize;
  19. wxSize PaperSize;
  20. wxSize BoardSize;
  21. wxPoint BoardCenter;
  22. bool Center = false;
  23. Ki_PageDescr* currentsheet = GetScreen()->m_CurrentSheetDesc;
  24. double scale, paperscale;
  25. Ki_PageDescr* SheetPS;
  26. wxPoint offset;
  27. FILE* output_file = wxFopen( FullFileName, wxT( "wt" ) );
  28. if( output_file == NULL )
  29. {
  30. return false;
  31. }
  32. SetLocaleTo_C_standard();
  33. if( g_PcbPlotOptions.m_PlotScale != 1.0 || g_PcbPlotOptions.m_AutoScale )
  34. Center = true; // when scale != 1.0 we must calculate the position in page
  35. // because actual position has no meaning
  36. // Set default line width
  37. if( g_PcbPlotOptions.m_PlotLineWidth < 1 )
  38. g_PcbPlotOptions.m_PlotLineWidth = 1;
  39. SheetSize.x = currentsheet->m_Size.x * U_PCB;
  40. SheetSize.y = currentsheet->m_Size.y * U_PCB;
  41. if( useA4 )
  42. {
  43. SheetPS = &g_Sheet_A4;
  44. PaperSize.x = g_Sheet_A4.m_Size.x * U_PCB;
  45. PaperSize.y = g_Sheet_A4.m_Size.y * U_PCB;
  46. paperscale = (float) PaperSize.x / SheetSize.x;
  47. }
  48. else
  49. {
  50. SheetPS = currentsheet;
  51. PaperSize = SheetSize;
  52. paperscale = 1;
  53. }
  54. m_Pcb->ComputeBoundingBox();
  55. BoardSize = m_Pcb->m_BoundaryBox.GetSize();
  56. BoardCenter = m_Pcb->m_BoundaryBox.Centre();
  57. if( g_PcbPlotOptions.m_AutoScale ) // Optimum scale
  58. {
  59. double Xscale, Yscale;
  60. // Fit to 80% of the page
  61. Xscale = (PaperSize.x * 0.8) / BoardSize.x;
  62. Yscale = (PaperSize.y * 0.8) / BoardSize.y;
  63. scale = MIN( Xscale, Yscale );
  64. }
  65. else
  66. scale = g_PcbPlotOptions.m_PlotScale * paperscale;
  67. if( Center )
  68. {
  69. offset.x = wxRound( (double) BoardCenter.x - ( (double) PaperSize.x / 2.0 ) / scale );
  70. offset.y = wxRound( (double) BoardCenter.y - ( (double) PaperSize.y / 2.0 ) / scale );
  71. }
  72. else
  73. {
  74. offset.x = 0;
  75. offset.y = 0;
  76. }
  77. PS_PLOTTER* plotter = new PS_PLOTTER();
  78. plotter->set_paper_size( SheetPS );
  79. plotter->set_scale_adjust( g_PcbPlotOptions.m_FineScaleAdjustX,
  80. g_PcbPlotOptions.m_FineScaleAdjustX );
  81. plotter->set_viewport( offset, scale, g_PcbPlotOptions.m_PlotMirror );
  82. plotter->set_default_line_width( g_PcbPlotOptions.m_PlotLineWidth );
  83. plotter->set_creator( wxT( "PCBNEW-PS" ) );
  84. plotter->set_filename( FullFileName );
  85. plotter->start_plot( output_file );
  86. /* The worksheet is not significant with scale!=1... It is with
  87. * paperscale!=1, anyway */
  88. if( g_PcbPlotOptions.m_PlotFrameRef && !Center )
  89. PlotWorkSheet( plotter, GetScreen() );
  90. // If plot a negative board:
  91. // Draw a black rectangle (background for plot board in white)
  92. // and switch the current color to WHITE
  93. if( g_PcbPlotOptions.m_PlotPSNegative )
  94. {
  95. int margin = 500; // Add a 0.5 inch margin around the board
  96. plotter->set_negative( true );
  97. plotter->set_color( WHITE ); // Which will be plotted as black
  98. plotter->rect( wxPoint( m_Pcb->m_BoundaryBox.GetX() - margin,
  99. m_Pcb->m_BoundaryBox.GetY() - margin ),
  100. wxPoint( m_Pcb->m_BoundaryBox.GetRight() + margin,
  101. m_Pcb->m_BoundaryBox.GetBottom() + margin ),
  102. FILLED_SHAPE );
  103. plotter->set_color( BLACK );
  104. }
  105. Plot_Layer( plotter, Layer, trace_mode );
  106. plotter->end_plot();
  107. delete plotter;
  108. SetLocaleTo_Default();
  109. return true;
  110. }