// SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2026 ZiroEDA and contributors. // Portions derived from KiCad, copyright The KiCad Developers. See NOTICE.md. /** * Plot dialog. Counterpart: `eeschema/dialogs/dialog_plot_schematic_base.cpp` + * `dialog_plot_schematic.cpp` (DIALOG_PLOT_SCHEMATIC). Same layout as upstream: * the output-directory row on top; a three-column row holding the "Output * Format" radio box, the "Options" grid and a right column with the selected * format's group (PDF / DXF / PNG) plus "Other Options"; the Output Messages * report panel; and the std-button row Plot Current Page (Apply) / Close / * Plot All Pages (OK). * * KiCad's enable rules are reproduced exactly (onPlotFormatSelection + * onColorMode): the colour theme follows "Output mode: Color"; the background * colour needs a format that can carry one (Postscript / PDF / SVG / PNG); the * minimum line width is disabled for DXF; PDF and DXF options grey out unless * their format is picked and the PNG group only appears for PNG. * * Web deltas: the browser's downloads folder stands for the output folder on * disk, so everything plotted is downloaded - one run of several files as one * zip, the output directory kept as the folder inside it (designer * output_downloads.ts) - and "Open file after plot" shows it in a new tab * (upstream opens the system PDF viewer). Controls a browser cannot * honour are left out rather than shown dead: PNG anti-aliasing (canvas always * anti-aliases). */ import { Button, Combo } from '@ziroeda/wx/controls.js'; import { useRef, useState, type JSX } from 'react'; import { mmToIU, iuToMM, type ReportLine } from '@ziroeda/common'; import type { PlotOpts, PlotPageSize } from '../sch_plotter.js'; import { IU_PER_MILS } from '../schematic_settings.js'; import { BUILTIN_THEMES } from '../sch_render_settings.js'; import type { EESCHEMA_SETTINGS_STORE } from '../browser/eeschema_app.js'; import { HtmlReportPanel, RPT_SEVERITY_ALL } from '@ziroeda/common/widgets/wx_html_report_panel.js'; import { DialogShim } from '@ziroeda/common/dialog_shim.js'; export type PlotFormat = 'ps' | 'pdf' | 'svg' | 'dxf' | 'png'; /** One "Plot Current Page" / "Plot All Pages" run. */ export interface PlotRequest { format: PlotFormat; /** Render options; the editor adds the per-sheet ones (drawing sheet, ...). */ opts: PlotOpts; /** OK plots every sheet, Apply just the current one. */ allPages: boolean; /** "Color theme:" selection (BUILTIN_THEMES key). */ themeId: string; /** Project-relative output folder ('' = the project's own folder). */ outputDir: string; /** Fill the PDF document properties from AUTHOR / SUBJECT. */ pdfMetadata: boolean; /** `m_PDFPropertyPopups`: a popup of each item's properties on the page. */ pdfPropertyPopups: boolean; /** `m_PDFHierarchicalLinks`: sheets, pins and hierarchical labels link to their pages. */ pdfHierarchicalLinks: boolean; /** Open the plotted file in a new tab (upstream OpenPDF). */ openAfter: boolean; /** Output Messages sink (the dialog's WX_HTML_REPORT_PANEL reporter). */ report: (message: string, severity: number) => void; } interface Props { /** The editor's active theme id (the "Color theme:" default selection). */ themeId?: string; onPlot: (request: PlotRequest) => void; onClose: () => void; /** `Pgm().GetSettingsManager()`'s eeschema slice (`EESCHEMA_APP.settings`), * which this dialog reads its defaults from and writes back to. */ settings: EESCHEMA_SETTINGS_STORE; } const FORMATS: { id: PlotFormat; label: string }[] = [ { id: 'ps', label: 'Postscript' }, { id: 'pdf', label: 'PDF' }, { id: 'svg', label: 'SVG' }, { id: 'dxf', label: 'DXF' }, { id: 'png', label: 'PNG' }, ]; /** Formats whose files carry a background colour (DIALOG_PLOT_SCHEMATIC::onColorMode). */ const BACKGROUND_FORMATS: PlotFormat[] = ['ps', 'pdf', 'svg', 'png']; /** Formats a minimum pen width applies to (onPlotFormatSelection). */ const PEN_WIDTH_FORMATS: PlotFormat[] = ['ps', 'pdf', 'svg', 'png']; /** Formats a browser tab can display ("Open file after plot"). */ const VIEWABLE_FORMATS: PlotFormat[] = ['pdf', 'svg', 'png']; export function DialogPlot({ settings, themeId, onPlot, onClose }: Props): JSX.Element { const [format, setFormat] = useState('pdf'); const [pageSize, setPageSize] = useState('auto'); const [color, setColor] = useState(true); const [drawingSheet, setDrawingSheet] = useState(true); const [background, setBackground] = useState(false); const [themeSel, setThemeSel] = useState( themeId && BUILTIN_THEMES[themeId] ? themeId : '_builtin_default', ); const [dpi, setDpi] = useState(300); const [dxfUnits, setDxfUnits] = useState<'in' | 'mm'>('in'); // The three PDF checkboxes, each `SetValue(true)` in the base file // (dialog_plot_schematic_base.cpp:139-151). const [pdfPropertyPopups, setPdfPropertyPopups] = useState(true); const [pdfHierarchicalLinks, setPdfHierarchicalLinks] = useState(true); const [pdfMetadata, setPdfMetadata] = useState(true); // TransferDataToWindow seeds the pen width from the drawing defaults (mils). const [minWidthMm, setMinWidthMm] = useState(() => String( Math.round(iuToMM(settings.eeschema.drawing.default_line_thickness * IU_PER_MILS) * 10000) / 10000, ), ); // Output directory: a folder inside the project, '' = the project folder. const [outputDir, setOutputDir] = useState(''); const [openAfter, setOpenAfter] = useState(false); // Output Messages (WX_HTML_REPORT_PANEL). const [messages, setMessages] = useState([]); const [severities, setSeverities] = useState(RPT_SEVERITY_ALL); const report = useRef((message: string, severity: number): void => { setMessages((m) => [...m, { message, severity, location: 'body' as const }]); }).current; const bgAvailable = color && BACKGROUND_FORMATS.includes(format); const penEnabled = PEN_WIDTH_FORMATS.includes(format); const canOpenAfter = VIEWABLE_FORMATS.includes(format); const doPlot = (allPages: boolean): void => { const opts: PlotOpts = { color, drawingSheet, background: bgAvailable && background, dpi, defaultPenIU: penEnabled ? mmToIU(Number(minWidthMm) || 0) : 0, pageSizeSelect: pageSize, dxfUnits, }; onPlot({ format, opts, allPages, themeId: themeSel, outputDir: outputDir.trim().replace(/^\/+|\/+$/g, ''), pdfMetadata: format === 'pdf' && pdfMetadata, pdfPropertyPopups: format === 'pdf' && pdfPropertyPopups, pdfHierarchicalLinks: format === 'pdf' && pdfHierarchicalLinks, openAfter: openAfter && canOpenAfter && !allPages, report, }); }; const group: React.CSSProperties = { border: '1px solid var(--chrome-border)', borderRadius: 4, padding: '6px 10px 8px', margin: 0, }; const legend: React.CSSProperties = { fontSize: 11.5, padding: '0 4px', fontWeight: 600 }; const row: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 8, fontSize: 12.5, }; const lab: React.CSSProperties = { fontSize: 12 }; // The Options group is a gridbag (label | control | units) like KiCad. const optGrid: React.CSSProperties = { display: 'grid', gridTemplateColumns: 'max-content 1fr max-content', alignItems: 'center', gap: '10px 8px', fontSize: 12.5, }; const span3: React.CSSProperties = { gridColumn: '1 / 4' }; const ctrl2: React.CSSProperties = { gridColumn: '2 / 4', width: '100%', boxSizing: 'border-box', }; const check = (disabled?: boolean): React.CSSProperties => ({ display: 'block', margin: '4px 0', fontSize: 12.5, opacity: disabled ? 0.5 : 1, }); return (
{/* Output directory (upstream bOutputDir): the folder inside the download. No browse button: the files are downloaded, so there is no folder on disk to pick. */}
Output directory: setOutputDir(e.target.value)} />
{/* Three columns (upstream m_optionsSizer): Output Format and Options take their natural width; the right column grows to fill. */}
Output Format {FORMATS.map((f) => ( ))}
Options
Page size: setPageSize(aValue as PlotPageSize)} />
Output mode: setColor(aValue === 'color')} /> Color theme: ({ value: String(id), label: t.name, }))} disabled={!color} title="Select the color theme to use for plotting" className="ze-select" style={ctrl2} onChange={(aValue) => setThemeSel(aValue)} />
Minimum line width: setMinWidthMm(e.target.value)} /> mm
{/* Right column: the format groups + Other Options (bOptionsRight). */}
PDF Options
DXF Options
Export units: setDxfUnits(aValue as 'in' | 'mm')} />
{format === 'png' && (
PNG Options
DPI: setDpi(Math.max(72, Math.min(2400, Number(e.target.value) || 300))) } />
)}
Other Options
{/* Output Messages (WX_HTML_REPORT_PANEL). */}
{/* KiCad std-button order (GTK): Plot Current Page (Apply), Close, Plot All Pages (OK). */}
); }