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.

222 lines
7.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2010 Lorenzo Marcantonio
  6. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef SCH_PLOTTER_H
  27. #define SCH_PLOTTER_H
  28. #include <wx/filename.h>
  29. #include <wx/string.h>
  30. #include <wx/gdicmn.h>
  31. #include <page_info.h>
  32. #include <sch_render_settings.h>
  33. #include <sch_sheet_path.h>
  34. #include <plotters/plotter.h>
  35. class SCH_EDIT_FRAME;
  36. class PLOTTER;
  37. class SCHEMATIC;
  38. class SCH_SCREEN;
  39. using KIGFX::RENDER_SETTINGS;
  40. class PDF_PLOTTER;
  41. class REPORTER;
  42. enum class HPGL_PLOT_ORIGIN_AND_UNITS
  43. {
  44. PLOTTER_BOT_LEFT,
  45. PLOTTER_CENTER,
  46. USER_FIT_PAGE,
  47. USER_FIT_CONTENT,
  48. };
  49. enum PageFormatReq
  50. {
  51. PAGE_SIZE_AUTO,
  52. PAGE_SIZE_A4,
  53. PAGE_SIZE_A
  54. };
  55. enum class HPGL_PAGE_SIZE
  56. {
  57. DEFAULT = 0,
  58. SIZE_A5,
  59. SIZE_A4,
  60. SIZE_A3,
  61. SIZE_A2,
  62. SIZE_A1,
  63. SIZE_A0,
  64. SIZE_A,
  65. SIZE_B,
  66. SIZE_C,
  67. SIZE_D,
  68. SIZE_E,
  69. };
  70. struct SCH_PLOT_OPTS
  71. {
  72. bool m_plotAll;
  73. bool m_plotDrawingSheet;
  74. std::vector<wxString> m_plotPages;
  75. bool m_blackAndWhite;
  76. int m_pageSizeSelect;
  77. bool m_useBackgroundColor;
  78. double m_HPGLPenSize; // for HPGL format only: pen size
  79. HPGL_PAGE_SIZE m_HPGLPaperSizeSelect;
  80. bool m_PDFPropertyPopups;
  81. bool m_PDFMetadata;
  82. wxString m_theme;
  83. wxString m_outputDirectory;
  84. wxString m_outputFile;
  85. HPGL_PLOT_ORIGIN_AND_UNITS m_HPGLPlotOrigin;
  86. SCH_PLOT_OPTS() :
  87. m_plotAll( true ),
  88. m_plotDrawingSheet( true ),
  89. m_blackAndWhite( false ),
  90. m_pageSizeSelect( 0 ),
  91. m_useBackgroundColor( true ),
  92. m_HPGLPenSize( 1.0 ),
  93. m_HPGLPaperSizeSelect( HPGL_PAGE_SIZE::DEFAULT ),
  94. m_PDFPropertyPopups( false ),
  95. m_PDFMetadata( false ),
  96. m_theme(),
  97. m_outputDirectory(),
  98. m_outputFile(),
  99. m_HPGLPlotOrigin( HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT )
  100. {
  101. }
  102. };
  103. /**
  104. * Schematic plotting class
  105. */
  106. class SCH_PLOTTER
  107. {
  108. public:
  109. /**
  110. * Constructor for usage with a frame having the schematic we want to print loaded
  111. */
  112. SCH_PLOTTER( SCH_EDIT_FRAME* aFrame );
  113. /**
  114. * Constructor for usage with a schematic that can be headless
  115. */
  116. SCH_PLOTTER( SCHEMATIC* aSch );
  117. /**
  118. * Perform the plotting of the schematic using the given aPlotFormat and aPlotSettings
  119. *
  120. * @param aPlotFormat The resulting output plot format (PDF, SVG, DXF, etc)
  121. * @param aPlotSettings The configuration for the plotting operation
  122. * @param aRenderSettings Mandatory object containing render settings for lower level classes
  123. * @param aReporter Optional reporter to print messages to
  124. */
  125. void Plot( PLOT_FORMAT aPlotFormat, const SCH_PLOT_OPTS& aPlotOpts,
  126. SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter = nullptr );
  127. /**
  128. * Get the last output file path, this is mainly intended for PDFs with the open after plot GUI option
  129. */
  130. wxString GetLastOutputFilePath() const { return m_lastOutputFilePath; }
  131. protected:
  132. /**
  133. * Returns the output filename for formats where the output is a single file
  134. */
  135. wxFileName getOutputFilenameSingle( const SCH_PLOT_OPTS& aPlotOpts, REPORTER* aReporter,
  136. const wxString& ext );
  137. // PDF
  138. void createPDFFile( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  139. REPORTER* aReporter );
  140. void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, const SCH_PLOT_OPTS& aPlotOpts );
  141. void setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, const SCH_PLOT_OPTS& aPlotOpts );
  142. // DXF
  143. void createDXFFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  144. REPORTER* aReporter );
  145. bool plotOneSheetDXF( const wxString& aFileName, SCH_SCREEN* aScreen,
  146. RENDER_SETTINGS* aRenderSettings, const VECTOR2I& aPlotOffset,
  147. double aScale, const SCH_PLOT_OPTS& aPlotOpts );
  148. // HPGL
  149. void createHPGLFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  150. REPORTER* aReporter );
  151. bool plotOneSheetHpgl( const wxString& aFileName, SCH_SCREEN* aScreen,
  152. const PAGE_INFO& aPageInfo, RENDER_SETTINGS* aRenderSettings,
  153. const VECTOR2I& aPlot0ffset, double aScale,
  154. const SCH_PLOT_OPTS& aPlotOpts );
  155. // PS
  156. void createPSFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  157. REPORTER* aReporter );
  158. bool plotOneSheetPS( const wxString& aFileName, SCH_SCREEN* aScreen,
  159. RENDER_SETTINGS* aRenderSettings, const PAGE_INFO& aPageInfo,
  160. const VECTOR2I& aPlot0ffset, double aScale,
  161. const SCH_PLOT_OPTS& aPlotOpts );
  162. // SVG
  163. void createSVGFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  164. REPORTER* aReporter );
  165. bool plotOneSheetSVG( const wxString& aFileName, SCH_SCREEN* aScreen,
  166. RENDER_SETTINGS* aRenderSettings, const SCH_PLOT_OPTS& aPlotOpts );
  167. /**
  168. * Everything done, close the plot and restore the environment.
  169. *
  170. * @param aPlotter the plotter to close and destroy (can be null if no current active plotter)
  171. * @param aOldsheetpath the stored old sheet path for the current sheet before the plot started
  172. */
  173. void restoreEnvironment( PDF_PLOTTER* aPlotter, SCH_SHEET_PATH& aOldsheetpath );
  174. /**
  175. * Create a file name with an absolute path name.
  176. *
  177. * @param aPlotFileName the name for the file to plot without a path.
  178. * @param aExtension the extension for the file to plot.
  179. * @param aReporter a point to a REPORTER object use to show messages (can be NULL).
  180. * @return the created file name.
  181. * @throw IO_ERROR on file I/O errors.
  182. */
  183. wxFileName createPlotFileName( const SCH_PLOT_OPTS& aPlotOpts, const wxString& aPlotFileName,
  184. const wxString& aExtension, REPORTER* aReporter = nullptr );
  185. private:
  186. SCHEMATIC* m_schematic;
  187. COLOR_SETTINGS* m_colorSettings;
  188. wxString m_lastOutputFilePath;
  189. };
  190. #endif