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.

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