68 REPORTER* aReporter,
const wxString& aExt )
76 wxString fname =
m_schematic->GetUniqueFilenameForCurrentSheet();
81 fname.Replace(
"/",
"_" );
82 fname.Replace(
"\\",
"_" );
110 m_schematic->CurrentSheet().UpdateAllScreenReferences();
146 if( sheetList.empty() )
167 wxFileName plotFileName;
169 for(
unsigned i = 0; i < sheetList.size(); i++ )
172 m_schematic->CurrentSheet().UpdateAllScreenReferences();
180 msg = wxS(
"AUTHOR" );
182 if(
m_schematic->ResolveTextVar( &sheetList[i], &msg, 0 ) )
185 msg = wxS(
"SUBJECT" );
187 if(
m_schematic->ResolveTextVar( &sheetList[i], &msg, 0 ) )
201 if( !plotFileName.IsOk() )
204 if( !plotter->
OpenFile( plotFileName.GetFullPath() ) )
208 msg.Printf(
_(
"Failed to create file '%s'." ), plotFileName.GetFullPath() );
218 plotter->
StartPlot( sheetList[i].GetPageNumber(), sheetName );
225 msg.Printf( wxT(
"PDF Plotter exception: %s" ), e.
What() );
240 if( parentSheet.
size() > 1 )
249 plotter->
StartPage( sheetList[i].GetPageNumber(), sheetName, parentSheet.
GetPageNumber(), parentSheetName );
258 msg.Printf(
_(
"Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
287 wxString sheetName =
m_schematic->CurrentSheet().Last()->GetName();
288 wxString sheetPath =
m_schematic->CurrentSheet().PathHumanReadable();
301 aScreen->
Plot( aPlotter, aPlotOpts );
316 plotPage.
SetType( wxT(
"A" ) );
321 plotPage.
SetType( wxT(
"A4" ) );
327 plotPage = actualPage;
333 double scale = std::min( scalex, scaley );
371 for(
unsigned i = 0; i < sheetList.size(); i++ )
374 m_schematic->CurrentSheet().UpdateAllScreenReferences();
383 plotPage.
SetType( wxT(
"A" ) );
388 plotPage.
SetType( wxT(
"A4" ) );
394 plotPage = actualPage;
400 double scale = std::min( scalex, scaley );
405 wxFileName plotFileName;
411 if( plotFileName.GetExt().IsEmpty() )
416 wxString fname =
m_schematic->GetUniqueFilenameForCurrentSheet();
421 fname.Replace(
"/",
"_" );
422 fname.Replace(
"\\",
"_" );
431 if( !plotFileName.IsOk() )
436 msg.Printf(
_(
"Failed to create file '%s'." ), plotFileName.GetFullPath() );
440 else if(
plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings,
441 actualPage, plot_offset,
scale, aPlotOpts ) )
445 msg.Printf(
_(
"Plotted to '%s'." ), plotFileName.GetFullPath() );
454 msg.Printf(
_(
"Failed to create file '%s'." ), plotFileName.GetFullPath() );
466 msg.Printf( wxT(
"PS Plotter exception: %s" ), e.
What() );
479 const VECTOR2I& aPlot0ffset,
double aScale,
493 if( !plotter->
OpenFile( aFileName ) )
515 wxString sheetName =
m_schematic->CurrentSheet().Last()->GetName();
516 wxString sheetPath =
m_schematic->CurrentSheet().PathHumanReadable();
529 aScreen->
Plot( plotter, aPlotOpts );
561 for(
unsigned i = 0; i < sheetList.size(); i++ )
566 m_schematic->CurrentSheet().UpdateAllScreenReferences();
573 wxFileName plotFileName;
579 if( plotFileName.GetExt().IsEmpty() )
584 wxString fname =
m_schematic->GetUniqueFilenameForCurrentSheet();
589 fname.Replace(
"/",
"_" );
590 fname.Replace(
"\\",
"_" );
599 if( !plotFileName.IsOk() )
602 bool success =
plotOneSheetSVG( plotFileName.GetFullPath(), screen, aRenderSettings, aPlotOpts );
608 msg.Printf(
_(
"Failed to create file '%s'." ), plotFileName.GetFullPath() );
616 msg.Printf(
_(
"Plotted to '%s'." ), plotFileName.GetFullPath() );
629 msg.Printf( wxT(
"SVG Plotter exception: %s" ), e.
What() );
654 plotPage.
SetType( wxT(
"A" ) );
659 plotPage.
SetType( wxT(
"A4" ) );
665 plotPage = actualPage;
677 double scale = std::min( scalex, scaley );
685 if( !plotter->
OpenFile( aFileName ) )
706 wxString sheetName =
m_schematic->CurrentSheet().Last()->GetName();
707 wxString sheetPath =
m_schematic->CurrentSheet().PathHumanReadable();
720 aScreen->
Plot( plotter, aPlotOpts );
750 for(
unsigned i = 0; i < sheetList.size(); i++ )
755 m_schematic->CurrentSheet().UpdateAllScreenReferences();
762 wxFileName plotFileName;
768 if( plotFileName.GetExt().IsEmpty() )
773 wxString fname =
m_schematic->GetUniqueFilenameForCurrentSheet();
775 fname.Replace(
"/",
"_" );
776 fname.Replace(
"\\",
"_" );
785 if( !plotFileName.IsOk() )
788 bool success =
plotOneSheetPNG( plotFileName.GetFullPath(), screen, aRenderSettings,
795 msg.Printf(
_(
"Failed to create file '%s'." ), plotFileName.GetFullPath() );
800 msg.Printf(
_(
"Plotted to '%s'." ), plotFileName.GetFullPath() );
812 msg.Printf( wxT(
"PNG Plotter exception: %s" ), e.
What() );
835 plotPage.
SetType( wxT(
"A" ) );
840 plotPage.
SetType( wxT(
"A4" ) );
846 plotPage = actualPage;
871 double scale = std::min( scalex, scaley );
876 if( !plotter->
OpenFile( aFileName ) )
896 wxString sheetName =
m_schematic->CurrentSheet().Last()->GetName();
897 wxString sheetPath =
m_schematic->CurrentSheet().PathHumanReadable();
911 aScreen->
Plot( plotter, aPlotOpts );
913 bool success = plotter->
EndPlot();
947 for(
unsigned i = 0; i < sheetList.size(); i++ )
950 m_schematic->CurrentSheet().UpdateAllScreenReferences();
959 wxFileName plotFileName;
965 if( plotFileName.GetExt().IsEmpty() )
970 wxString fname =
m_schematic->GetUniqueFilenameForCurrentSheet();
975 fname.Replace(
"/",
"_" );
976 fname.Replace(
"\\",
"_" );
985 if( !plotFileName.IsOk() )
988 if(
plotOneSheetDXF( plotFileName.GetFullPath(), screen, aRenderSettings, plot_offset,
993 msg.Printf(
_(
"Plotted to '%s'." ), plotFileName.GetFullPath() );
1001 msg.Printf(
_(
"Failed to create file '%s'." ), plotFileName.GetFullPath() );
1013 msg.Printf( wxT(
"DXF Plotter exception: %s" ), e.
What() );
1046 plotter->
SetCreator( wxT(
"Eeschema-DXF" ) );
1048 if( !plotter->
OpenFile( aFileName ) )
1058 wxString sheetName =
m_schematic->CurrentSheet().Last()->GetName();
1059 wxString sheetPath =
m_schematic->CurrentSheet().PathHumanReadable();
1062 wxString variantName =
m_schematic->GetCurrentVariant();
1063 wxString variantDesc =
m_schematic->GetVariantDescription( variantName );
1071 aScreen->
Plot( plotter, aPlotOpts );
1082 const wxString& aPlotFileName,
1083 const wxString& aExtension,
REPORTER* aReporter )
1089 retv.SetPath( tmp.GetPath() );
1091 if( !aPlotFileName.IsEmpty() )
1092 retv.SetName( aPlotFileName );
1094 retv.SetName(
_(
"Schematic" ) );
1096 retv.SetExt( aExtension );
1102 wxString msg = wxString::Format(
_(
"Failed to write plot files to folder '%s'." ),
1114 retv.SetPath( tmp.GetPath() );
1128 wxString oldVariant =
m_schematic->GetCurrentVariant();
1132 switch( aPlotFormat )
1149 std::unique_ptr<LIB_SYMBOL> flatSymbol = aSymbol.
Flatten();
1151 BOX2I symbolBB = flatSymbol->GetUnitBoundingBox( aUnit, aBodyStyle, !aIncludeHiddenFields );
1159 const int expansion =
schIUScale.mmToIU( 2 );
1160 symbolBB.
Inflate( expansion );
1174 std::unique_ptr<SVG_PLOTTER> plotter = std::make_unique<SVG_PLOTTER>();
1175 plotter->SetRenderSettings( &aRenderSettings );
1176 plotter->SetPageSettings( pageInfo );
1177 plotter->SetColorMode( !aBlackAndWhite );
1182 plotter->SetPlotBBox( aBBox );
1184 plotter->SetCreator( wxT(
"Eeschema-SVG" ) );
1186 if( !plotter->OpenFile( aFileName ) )
1190 aReporter->
Report( wxString::Format(
_(
"Unable to open destination '%s'" ) + wxS(
"\n" ),
1200 plotter->StartPlot( wxS(
"1" ) );
1202 constexpr bool background =
true;
1203 aDrawSymbol.
Plot( plotter.get(), background, plotOpts, aUnit, aBodyStyle,
VECTOR2I( 0, 0 ),
false );
1204 aDrawSymbol.
Plot( plotter.get(), !background, plotOpts, aUnit, aBodyStyle,
VECTOR2I( 0, 0 ),
false );
1205 aFieldsSymbol.
PlotFields( plotter.get(), !background, plotOpts, aUnit, aBodyStyle,
VECTOR2I( 0, 0 ),
false );
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
int GetVirtualPageNumber() const
const wxString & GetPageNumber() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
static const COLOR4D BLACK
static wxString GetDefaultFileExtension()
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the scale/position for the DXF plot.
virtual bool StartPlot(const wxString &aPageNumber) override
Open the DXF plot with a skeleton header.
virtual bool EndPlot() override
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A color representation with 4 components: red, green, blue, alpha.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetDefaultPenWidth(int aWidth)
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
Define a library symbol object.
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
void PlotFields(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed)
Plot symbol fields.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
int GetHeightIU(double aIUScale) const
Get the page height in IU.
bool SetType(PAGE_SIZE_TYPE aPageSize, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
void SetHeightMils(double aHeightInMils)
double GetHeightMils() const
int GetWidthIU(double aIUScale) const
Get the page width in IU.
double GetWidthMils() const
void SetWidthMils(double aWidthInMils)
virtual void ClosePage()
Close the current page in the PDF document (and emit its compressed stream).
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
virtual bool StartPlot(const wxString &aPageNumber) override
The PDF engine supports multiple pages; the first one is opened 'for free' the following are to be cl...
static wxString GetDefaultFileExtension()
virtual void StartPage(const wxString &aPageNumber, const wxString &aPageName=wxEmptyString, const wxString &aParentPageNumber=wxEmptyString, const wxString &aParentPageName=wxEmptyString)
Start a new page in the PDF document.
Base plotter engine class.
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
virtual void SetAuthor(const wxString &aAuthor)
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetRenderSettings(RENDER_SETTINGS *aSettings)
virtual void SetTitle(const wxString &aTitle)
RENDER_SETTINGS * RenderSettings()
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0)=0
virtual void SetCreator(const wxString &aCreator)
bool GetColorMode() const
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror)=0
Set the plot offset and scaling for the current plot.
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
virtual void SetSubject(const wxString &aSubject)
virtual void SetColor(const COLOR4D &color)=0
SCH_SHEET_PATH m_previousSheetPath
PLOT_CONTEXT(PLOTTER *aPlotter, SCHEMATIC *aSchematic)
PNG rasterization plotter using Cairo graphics library.
void SetPixelSize(int aWidth, int aHeight)
Set the output image dimensions in pixels.
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T aFill, int aWidth, int aCornerRadius=0) override
void SetResolution(int aDPI)
Set the output resolution in dots per inch.
virtual bool EndPlot() override
void SetAntialias(bool aEnable)
Enable or disable anti-aliasing.
virtual void SetColor(const COLOR4D &aColor) override
static wxString GetDefaultFileExtension()
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual bool StartPlot(const wxString &aPageNumber) override
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb values,...
virtual bool EndPlot() override
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual bool StartPlot(const wxString &aPageNumber) override
The code within this function (and the CloseFilePS function) creates postscript files whose contents ...
static wxString GetDefaultFileExtension()
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
These are loaded from Eeschema settings but then overwritten by the project settings.
wxString m_PlotDirectoryName
Holds all the data relating to one schematic.
wxString GetVariantDescription(const wxString &aVariantName) const
Return the description for a variant.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
wxString GetCurrentVariant() const
Return the current variant being edited.
const std::map< wxString, wxString > * GetProperties()
Schematic editor (Eeschema) main window.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
void Plot(PLOT_FORMAT aPlotFormat, const SCH_PLOT_OPTS &aPlotOpts, SCH_RENDER_SETTINGS *aRenderSettings, REPORTER *aReporter=nullptr)
Perform the plotting of the schematic using the given aPlotFormat and a\ aPlotSettings.
wxFileName getOutputFilenameSingle(const SCH_PLOT_OPTS &aPlotOpts, REPORTER *aReporter, const wxString &ext)
Return the output filename for formats where the output is a single file.
void createSVGFiles(const SCH_PLOT_OPTS &aPlotOpts, SCH_RENDER_SETTINGS *aRenderSettings, REPORTER *aReporter)
void createPSFiles(const SCH_PLOT_OPTS &aPlotOpts, SCH_RENDER_SETTINGS *aRenderSettings, REPORTER *aReporter)
void plotOneSheetPDF(PLOTTER *aPlotter, SCH_SCREEN *aScreen, const SCH_PLOT_OPTS &aPlotOpts)
wxFileName createPlotFileName(const SCH_PLOT_OPTS &aPlotOpts, const wxString &aPlotFileName, const wxString &aExtension, REPORTER *aReporter=nullptr)
Create a file name with an absolute path name.
SCH_PLOTTER(SCH_EDIT_FRAME *aFrame)
Constructor for usage with a frame having the schematic we want to print loaded.
bool plotOneSheetDXF(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, const VECTOR2I &aPlotOffset, double aScale, const SCH_PLOT_OPTS &aPlotOpts)
void createDXFFiles(const SCH_PLOT_OPTS &aPlotOpts, SCH_RENDER_SETTINGS *aRenderSettings, REPORTER *aReporter)
wxString m_lastOutputFilePath
std::vector< wxString > m_outputFilePaths
void createPNGFiles(const SCH_PLOT_OPTS &aPlotOpts, SCH_RENDER_SETTINGS *aRenderSettings, REPORTER *aReporter)
bool plotOneSheetSVG(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, const SCH_PLOT_OPTS &aPlotOpts)
void setupPlotPagePDF(PLOTTER *aPlotter, SCH_SCREEN *aScreen, const SCH_PLOT_OPTS &aPlotOpts)
bool plotOneSheetPNG(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, const SCH_PLOT_OPTS &aPlotOpts)
void createPDFFile(const SCH_PLOT_OPTS &aPlotOpts, SCH_RENDER_SETTINGS *aRenderSettings, REPORTER *aReporter)
COLOR_SETTINGS * m_colorSettings
bool plotOneSheetPS(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, const PAGE_INFO &aPageInfo, const VECTOR2I &aPlot0ffset, double aScale, const SCH_PLOT_OPTS &aPlotOpts)
const PAGE_INFO & GetPageSettings() const
const wxString & GetFileName() const
SCHEMATIC * Schematic() const
TITLE_BLOCK & GetTitleBlock()
void Plot(PLOTTER *aPlotter, const SCH_PLOT_OPTS &aPlotOpts) const
Plot all the schematic objects to aPlotter.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void TrimToPageNumbers(const std::vector< wxString > &aPageInclusions)
Truncates the list by removing sheet's with page numbers not in the given list.
void SortByHierarchicalPageNumbers(bool aUpdateVirtualPageNums=true)
This works like SortByPageNumbers, but it sorts the sheets first by their hierarchical depth and then...
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetPageNumber() const
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
size_t size() const
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
virtual bool StartPlot(const wxString &aPageNumber) override
Create SVG file header.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
virtual bool EndPlot() override
static wxString GetDefaultFileExtension()
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
void PlotDrawingSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, const std::map< wxString, wxString > *aProperties, const wxString &aSheetNumber, int aSheetCount, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aFilename, COLOR4D aColor, bool aIsFirstPage, const wxString &aVariantName, const wxString &aVariantDesc)
@ FILLED_SHAPE
Fill with object color.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
@ LAYER_SCHEMATIC_DRAWINGSHEET
@ LAYER_SCHEMATIC_BACKGROUND
PLOT_FORMAT
The set of supported output plot formats.
constexpr int MIN_PNG_DPI
constexpr int MAX_PNG_DPI
Plotting engines similar to ps (PostScript, Gerber, svg)
bool PlotSymbolToSVG(LIB_SYMBOL &aDrawSymbol, LIB_SYMBOL &aFieldsSymbol, int aUnit, int aBodyStyle, const BOX2I &aBBox, SCH_RENDER_SETTINGS &aRenderSettings, bool aBlackAndWhite, const wxString &aFileName, REPORTER *aReporter)
Plot a single symbol variant (unit and body style) to an SVG file.
BOX2I GetSymbolPlotBBox(const LIB_SYMBOL &aSymbol, int aUnit, int aBodyStyle, bool aIncludeHiddenFields)
Compute the bounding box used to size a symbol SVG plot.
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
std::vector< wxString > m_plotPages
DXF_UNITS m_DXF_File_Unit
wxString m_outputDirectory
std::optional< SCH_SHEET_PATH > m_sheetPath
bool m_useBackgroundColor
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I