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.

184 lines
6.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 The 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 PageFormatReq
  43. {
  44. PAGE_SIZE_AUTO,
  45. PAGE_SIZE_A4,
  46. PAGE_SIZE_A
  47. };
  48. struct SCH_PLOT_OPTS
  49. {
  50. bool m_plotAll;
  51. bool m_plotDrawingSheet;
  52. std::vector<wxString> m_plotPages;
  53. bool m_blackAndWhite;
  54. int m_pageSizeSelect;
  55. bool m_useBackgroundColor;
  56. bool m_PDFPropertyPopups;
  57. bool m_PDFHierarchicalLinks;
  58. bool m_PDFMetadata;
  59. wxString m_theme;
  60. wxString m_outputDirectory;
  61. wxString m_outputFile;
  62. SCH_PLOT_OPTS() :
  63. m_plotAll( true ),
  64. m_plotDrawingSheet( true ),
  65. m_blackAndWhite( false ),
  66. m_pageSizeSelect( 0 ),
  67. m_useBackgroundColor( true ),
  68. m_PDFPropertyPopups( false ),
  69. m_PDFHierarchicalLinks( false ),
  70. m_PDFMetadata( false ),
  71. m_theme(),
  72. m_outputDirectory(),
  73. m_outputFile()
  74. {
  75. }
  76. };
  77. /**
  78. * Schematic plotting class.
  79. */
  80. class SCH_PLOTTER
  81. {
  82. public:
  83. /**
  84. * Constructor for usage with a frame having the schematic we want to print loaded.
  85. */
  86. SCH_PLOTTER( SCH_EDIT_FRAME* aFrame );
  87. /**
  88. * Constructor for usage with a schematic that can be headless.
  89. */
  90. SCH_PLOTTER( SCHEMATIC* aSch );
  91. /**
  92. * Perform the plotting of the schematic using the given \a aPlotFormat and a\ aPlotSettings.
  93. *
  94. * @param aPlotFormat The resulting output plot format (PDF, SVG, DXF, etc)
  95. * @param aPlotSettings The configuration for the plotting operation
  96. * @param aRenderSettings Mandatory object containing render settings for lower level classes
  97. * @param aReporter Optional reporter to print messages to
  98. */
  99. void Plot( PLOT_FORMAT aPlotFormat, const SCH_PLOT_OPTS& aPlotOpts,
  100. SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter = nullptr );
  101. /**
  102. * Get the last output file path, this is mainly intended for PDFs with the open after
  103. * plot GUI option.
  104. */
  105. wxString GetLastOutputFilePath() const { return m_lastOutputFilePath; }
  106. protected:
  107. /**
  108. * Return the output filename for formats where the output is a single file.
  109. */
  110. wxFileName getOutputFilenameSingle( const SCH_PLOT_OPTS& aPlotOpts, REPORTER* aReporter,
  111. const wxString& ext );
  112. // PDF
  113. void createPDFFile( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  114. REPORTER* aReporter );
  115. void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, const SCH_PLOT_OPTS& aPlotOpts );
  116. void setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, const SCH_PLOT_OPTS& aPlotOpts );
  117. // DXF
  118. void createDXFFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  119. REPORTER* aReporter );
  120. bool plotOneSheetDXF( const wxString& aFileName, SCH_SCREEN* aScreen,
  121. RENDER_SETTINGS* aRenderSettings, const VECTOR2I& aPlotOffset,
  122. double aScale, const SCH_PLOT_OPTS& aPlotOpts );
  123. // PS
  124. void createPSFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  125. REPORTER* aReporter );
  126. bool plotOneSheetPS( const wxString& aFileName, SCH_SCREEN* aScreen,
  127. RENDER_SETTINGS* aRenderSettings, const PAGE_INFO& aPageInfo,
  128. const VECTOR2I& aPlot0ffset, double aScale,
  129. const SCH_PLOT_OPTS& aPlotOpts );
  130. // SVG
  131. void createSVGFiles( const SCH_PLOT_OPTS& aPlotOpts, SCH_RENDER_SETTINGS* aRenderSettings,
  132. REPORTER* aReporter );
  133. bool plotOneSheetSVG( const wxString& aFileName, SCH_SCREEN* aScreen,
  134. RENDER_SETTINGS* aRenderSettings, const SCH_PLOT_OPTS& aPlotOpts );
  135. /**
  136. * Everything done, close the plot and restore the environment.
  137. *
  138. * @param aPlotter the plotter to close and destroy (can be null if no current active plotter)
  139. * @param aOldsheetpath the stored old sheet path for the current sheet before the plot started
  140. */
  141. void restoreEnvironment( PDF_PLOTTER* aPlotter, SCH_SHEET_PATH& aOldsheetpath );
  142. /**
  143. * Create a file name with an absolute path name.
  144. *
  145. * @param aPlotFileName the name for the file to plot without a path.
  146. * @param aExtension the extension for the file to plot.
  147. * @param aReporter a point to a REPORTER object use to show messages (can be NULL).
  148. * @return the created file name.
  149. * @throw IO_ERROR on file I/O errors.
  150. */
  151. wxFileName createPlotFileName( const SCH_PLOT_OPTS& aPlotOpts, const wxString& aPlotFileName,
  152. const wxString& aExtension, REPORTER* aReporter = nullptr );
  153. private:
  154. SCHEMATIC* m_schematic;
  155. COLOR_SETTINGS* m_colorSettings;
  156. wxString m_lastOutputFilePath;
  157. };
  158. #endif