KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_plotter.cpp
Go to the documentation of this file.
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 <[email protected]>
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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include "core/typeinfo.h"
24#include <wx/log.h>
25#include <common.h>
26#include <sch_plotter.h>
30
31#include <pgm_base.h>
32#include <trace_helpers.h>
33
34#include <lib_symbol.h>
35#include <locale_io.h>
36#include <sch_edit_frame.h>
37#include <sch_painter.h>
38#include <sch_shape.h>
39#include <schematic.h>
40#include <sch_screen.h>
42
43#include <algorithm>
44
45// Note:
46// We need to switch between sheets to plot a hierarchy and update references and sheet number
47// Use SCHEMATIC::SetCurrentSheet( xxx ) to switch to a sheet.
48// Do not use SCH_EDIT_FRAME::SetCurrentSheet( xxx ) to switch to a sheet, because the new sheet
49// is not displayed, but SCH_EDIT_FRAME::SetCurrentSheet() has side effects to the current VIEW
50// (clear some data used to show the sheet on screen) and does not fully restore the "old" screen
51
52
54 m_schematic( aSchematic )
55{
56 m_colorSettings = nullptr;
57}
58
59
61 m_schematic( &aFrame->Schematic() )
62{
63 m_colorSettings = nullptr;
64}
65
66
68 REPORTER* aReporter, const wxString& aExt )
69{
70 if( !aPlotOpts.m_outputFile.empty() )
71 {
72 return aPlotOpts.m_outputFile;
73 }
74 else
75 {
76 wxString fname = m_schematic->GetUniqueFilenameForCurrentSheet();
77
78 // The sub sheet can be in a sub_hierarchy, but we plot the file in the main
79 // project folder (or the folder specified by the caller), so replace separators
80 // to create a unique filename:
81 fname.Replace( "/", "_" );
82 fname.Replace( "\\", "_" );
83
84 return createPlotFileName( aPlotOpts, fname, aExt, aReporter );
85 }
86
87}
88
89
91 SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter )
92{
93 SCH_SHEET_PATH oldsheetpath = m_schematic->CurrentSheet(); // sheetpath is saved here
94
95 /* When printing all pages, the printed page is not the current page. In complex hierarchies,
96 * we must update symbol references and other parameters in the given printed SCH_SCREEN,
97 * according to the sheet path because in complex hierarchies a SCH_SCREEN (a drawing ) is
98 * shared between many sheets and symbol references depend on the actual sheet path used.
99 */
100 SCH_SHEET_LIST sheetList;
101
102 if( aPlotOpts.m_plotAll || aPlotOpts.m_plotPages.size() > 0 )
103 {
104 sheetList.BuildSheetList( &m_schematic->Root(), true );
106
107 // remove the non-selected pages if we are in plot pages mode
108 if( aPlotOpts.m_plotPages.size() > 0 )
109 sheetList.TrimToPageNumbers( aPlotOpts.m_plotPages );
110 }
111 else
112 {
113 // in Eeschema, this prints the current page
114 sheetList.push_back( m_schematic->CurrentSheet() );
115 }
116
117 if( sheetList.empty() )
118 {
119 if( aReporter )
120 aReporter->Report( _( "No sheets to plot." ), RPT_SEVERITY_ERROR );
121
122 return;
123 }
124
125 wxCHECK( m_schematic, /* void */ );
126
127 // Allocate the plotter and set the job level parameter
128 PDF_PLOTTER* plotter = new PDF_PLOTTER( &m_schematic->Project() );
129 plotter->SetRenderSettings( aRenderSettings );
130 plotter->SetColorMode( !aPlotOpts.m_blackAndWhite );
131 plotter->SetCreator( wxT( "Eeschema-PDF" ) );
132 plotter->SetTitle( ExpandTextVars( m_schematic->RootScreen()->GetTitleBlock().GetTitle(),
133 &m_schematic->Project(), FOR_GUI ) );
134
135 wxString msg;
136 wxFileName plotFileName;
137
138 for( unsigned i = 0; i < sheetList.size(); i++ )
139 {
140 m_schematic->SetCurrentSheet( sheetList[i] );
141 m_schematic->CurrentSheet().UpdateAllScreenReferences();
142 m_schematic->SetSheetNumberAndCount();
143
144 SCH_SCREEN* screen = m_schematic->CurrentSheet().LastScreen();
145 wxString sheetName = sheetList[i].Last()->GetField( FIELD_T::SHEET_NAME )->GetShownText( FOR_GUI );
146
147 if( aPlotOpts.m_PDFMetadata )
148 {
149 msg = wxS( "AUTHOR" );
150
151 if( m_schematic->ResolveTextVar( &sheetList[i], &msg, 0 ) )
152 plotter->SetAuthor( msg );
153
154 msg = wxS( "SUBJECT" );
155
156 if( m_schematic->ResolveTextVar( &sheetList[i], &msg, 0 ) )
157 plotter->SetSubject( msg );
158 }
159
160 if( i == 0 )
161 {
162 try
163 {
165 plotFileName = getOutputFilenameSingle( aPlotOpts, aReporter, ext );
166
167 m_lastOutputFilePath = plotFileName.GetFullPath();
169
170 if( !plotFileName.IsOk() )
171 return;
172
173 if( !plotter->OpenFile( plotFileName.GetFullPath() ) )
174 {
175 if( aReporter )
176 {
177 msg.Printf( _( "Failed to create file '%s'." ),
178 plotFileName.GetFullPath() );
179 aReporter->Report( msg, RPT_SEVERITY_ERROR );
180 }
181 delete plotter;
182 return;
183 }
184
185 // Open the plotter and do the first page
186 setupPlotPagePDF( plotter, screen, aPlotOpts );
187
188 plotter->StartPlot( sheetList[i].GetPageNumber(), sheetName );
189 }
190 catch( const IO_ERROR& e )
191 {
192 // Cannot plot PDF file
193 if( aReporter )
194 {
195 msg.Printf( wxT( "PDF Plotter exception: %s" ), e.What() );
196 aReporter->Report( msg, RPT_SEVERITY_ERROR );
197 }
198
199 restoreEnvironment( plotter, oldsheetpath );
200 return;
201 }
202 }
203 else
204 {
205 /* For the following pages you need to close the (finished) page,
206 * reconfigure, and then start a new one */
207 plotter->ClosePage();
208 setupPlotPagePDF( plotter, screen, aPlotOpts );
209 SCH_SHEET_PATH parentSheet = sheetList[i];
210
211 if( parentSheet.size() > 1 )
212 {
213 // The sheet path is the full path to the sheet, so we need to remove the last
214 // sheet name to get the parent sheet path
215 parentSheet.pop_back();
216 }
217
218 wxString parentSheetName = parentSheet.Last()->GetField( FIELD_T::SHEET_NAME )->GetShownText( FOR_GUI );
219
220 plotter->StartPage( sheetList[i].GetPageNumber(), sheetName, parentSheet.GetPageNumber(), parentSheetName );
221 }
222
223 plotOneSheetPDF( plotter, screen, aPlotOpts );
224 }
225
226 // Everything done, close the plot and restore the environment
227 if( aReporter )
228 {
229 msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
230 aReporter->Report( msg, RPT_SEVERITY_ACTION );
231 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
232 }
233
234 restoreEnvironment( plotter, oldsheetpath );
235}
236
237
239 const SCH_PLOT_OPTS& aPlotOpts )
240{
241 if( aPlotOpts.m_useBackgroundColor && aPlotter->GetColorMode() )
242 {
243 aPlotter->SetColor( aPlotter->RenderSettings()->GetBackgroundColor() );
244
245 // Use page size selected in schematic to know the schematic bg area
246 const PAGE_INFO& actualPage = aScreen->GetPageSettings(); // page size selected in schematic
247 VECTOR2I end( actualPage.GetWidthIU( schIUScale.IU_PER_MILS ),
248 actualPage.GetHeightIU( schIUScale.IU_PER_MILS ) );
249
250 aPlotter->Rect( VECTOR2I( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0 );
251 }
252
253 if( aPlotOpts.m_plotDrawingSheet )
254 {
255 COLOR4D color = COLOR4D::BLACK;
256
257 if( aPlotter->GetColorMode() )
259
260 wxString sheetName = m_schematic->CurrentSheet().Last()->GetName();
261 wxString sheetPath = m_schematic->CurrentSheet().PathHumanReadable();
262 const PAGE_INFO& actualPage = aScreen->GetPageSettings(); // page size selected in schematic
263
264 SCHEMATIC* sch = aScreen->Schematic();
265 wxString variantName = sch->GetCurrentVariant();
266 wxString variantDesc = sch->GetVariantDescription( variantName );
267
268 PlotDrawingSheet( aPlotter, &sch->Project(), aScreen->GetTitleBlock(), actualPage, sch->GetProperties(),
269 aScreen->GetPageNumber(), aScreen->GetPageCount(), sheetName, sheetPath,
270 aScreen->GetFileName(), color, aScreen->GetVirtualPageNumber() == 1, variantName,
271 variantDesc );
272 }
273
274 aScreen->Plot( aPlotter, aPlotOpts );
275}
276
277
279 const SCH_PLOT_OPTS& aPlotOpts )
280{
281 PAGE_INFO plotPage; // page size selected to plot
282
283 // Considerations on page size and scaling requests
284 const PAGE_INFO& actualPage = aScreen->GetPageSettings(); // page size selected in schematic
285
286 switch( aPlotOpts.m_pageSizeSelect )
287 {
288 case PAGE_SIZE_A:
289 plotPage.SetType( wxT( "A" ) );
290 plotPage.SetPortrait( actualPage.IsPortrait() );
291 break;
292
293 case PAGE_SIZE_A4:
294 plotPage.SetType( wxT( "A4" ) );
295 plotPage.SetPortrait( actualPage.IsPortrait() );
296 break;
297
298 case PAGE_SIZE_AUTO:
299 default:
300 plotPage = actualPage;
301 break;
302 }
303
304 double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
305 double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
306 double scale = std::min( scalex, scaley );
307 aPlotter->SetPageSettings( plotPage );
308
309 // Currently, plot units are in decimil
310 aPlotter->SetViewport( VECTOR2I( 0, 0 ), schIUScale.IU_PER_MILS / 10, scale, false );
311}
312
313
315 SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter )
316{
317 SCH_SHEET_PATH oldsheetpath = m_schematic->CurrentSheet(); // sheetpath is saved here
318 PAGE_INFO plotPage; // page size selected to plot
319 wxString msg;
320
321 /* When printing all pages, the printed page is not the current page.
322 * In complex hierarchies, we must update symbol references and other parameters in the
323 * given printed SCH_SCREEN, accordant to the sheet path because in complex hierarchies
324 * a SCH_SCREEN (a drawing ) is shared between many sheets and symbol references
325 * depend on the actual sheet path used.
326 */
327 SCH_SHEET_LIST sheetList;
328
329 if( aPlotOpts.m_plotAll )
330 {
331 sheetList.BuildSheetList( &m_schematic->Root(), true );
332 sheetList.SortByPageNumbers();
333
334 // remove the non-selected pages if we are in plot pages mode
335 if( aPlotOpts.m_plotPages.size() > 0 )
336 {
337 sheetList.TrimToPageNumbers( aPlotOpts.m_plotPages );
338 }
339 }
340 else
341 {
342 sheetList.push_back( m_schematic->CurrentSheet() );
343 }
344
345 for( unsigned i = 0; i < sheetList.size(); i++ )
346 {
347 m_schematic->SetCurrentSheet( sheetList[i] );
348 m_schematic->CurrentSheet().UpdateAllScreenReferences();
349 m_schematic->SetSheetNumberAndCount();
350
351 SCH_SCREEN* screen = m_schematic->CurrentSheet().LastScreen();
352 PAGE_INFO actualPage = screen->GetPageSettings();
353
354 switch( aPlotOpts.m_pageSizeSelect )
355 {
356 case PAGE_SIZE_A:
357 plotPage.SetType( wxT( "A" ) );
358 plotPage.SetPortrait( actualPage.IsPortrait() );
359 break;
360
361 case PAGE_SIZE_A4:
362 plotPage.SetType( wxT( "A4" ) );
363 plotPage.SetPortrait( actualPage.IsPortrait() );
364 break;
365
366 case PAGE_SIZE_AUTO:
367 default:
368 plotPage = actualPage;
369 break;
370 }
371
372 double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
373 double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
374 double scale = std::min( scalex, scaley );
375 VECTOR2I plot_offset;
376
377 try
378 {
379 wxFileName plotFileName;
380
381 if( !aPlotOpts.m_outputFile.empty() )
382 {
383 plotFileName = wxFileName( aPlotOpts.m_outputFile );
384
385 if( plotFileName.GetExt().IsEmpty() )
386 plotFileName.SetExt( PS_PLOTTER::GetDefaultFileExtension() );
387 }
388 else
389 {
390 wxString fname = m_schematic->GetUniqueFilenameForCurrentSheet();
391
392 // The sub sheet can be in a sub_hierarchy, but we plot the file in the
393 // main project folder (or the folder specified by the caller),
394 // so replace separators to create a unique filename:
395 fname.Replace( "/", "_" );
396 fname.Replace( "\\", "_" );
397
398 plotFileName = createPlotFileName( aPlotOpts, fname,
400 aReporter );
401 }
402
403 m_lastOutputFilePath = plotFileName.GetFullPath();
405
406 if( !plotFileName.IsOk() )
407 {
408 if( aReporter )
409 {
410 // Error
411 msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() );
412 aReporter->Report( msg, RPT_SEVERITY_ERROR );
413 }
414 }
415 else if( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings,
416 actualPage, plot_offset, scale, aPlotOpts ) )
417 {
418 if( aReporter )
419 {
420 msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() );
421 aReporter->Report( msg, RPT_SEVERITY_ACTION );
422 }
423 }
424 else
425 {
426 if( aReporter )
427 {
428 // Error
429 msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() );
430 aReporter->Report( msg, RPT_SEVERITY_ERROR );
431 }
432 }
433
434 if( !aPlotOpts.m_outputFile.empty() )
435 break;
436 }
437 catch( IO_ERROR& e )
438 {
439 if( aReporter )
440 {
441 msg.Printf( wxT( "PS Plotter exception: %s" ), e.What() );
442 aReporter->Report( msg, RPT_SEVERITY_ERROR );
443 }
444 }
445 }
446
447 if( aReporter )
448 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
449
450 restoreEnvironment( nullptr, oldsheetpath );
451}
452
453
454bool SCH_PLOTTER::plotOneSheetPS( const wxString& aFileName, SCH_SCREEN* aScreen,
455 RENDER_SETTINGS* aRenderSettings, const PAGE_INFO& aPageInfo,
456 const VECTOR2I& aPlot0ffset, double aScale,
457 const SCH_PLOT_OPTS& aPlotOpts )
458{
459 PS_PLOTTER* plotter = new PS_PLOTTER();
460 plotter->SetRenderSettings( aRenderSettings );
461 plotter->SetPageSettings( aPageInfo );
462 plotter->SetColorMode( !aPlotOpts.m_blackAndWhite );
463
464 // Currently, plot units are in decimil
465 plotter->SetViewport( aPlot0ffset, schIUScale.IU_PER_MILS / 10, aScale, false );
466
467 // Init :
468 plotter->SetCreator( wxT( "Eeschema-PS" ) );
469
470 if( !plotter->OpenFile( aFileName ) )
471 {
472 delete plotter;
473 return false;
474 }
475
476 plotter->StartPlot( m_schematic->CurrentSheet().GetPageNumber() );
477
478 if( aPlotOpts.m_useBackgroundColor && plotter->GetColorMode() )
479 {
481
482 // Use page size selected in schematic to know the schematic bg area
483 const PAGE_INFO& actualPage = aScreen->GetPageSettings(); // page size selected in schematic
484 VECTOR2I end( actualPage.GetWidthIU( schIUScale.IU_PER_MILS ),
485 actualPage.GetHeightIU( schIUScale.IU_PER_MILS ) );
486
487 plotter->Rect( VECTOR2I( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0, 0 );
488 }
489
490 if( aPlotOpts.m_plotDrawingSheet )
491 {
492 wxString sheetName = m_schematic->CurrentSheet().Last()->GetName();
493 wxString sheetPath = m_schematic->CurrentSheet().PathHumanReadable();
495
496 SCHEMATIC* sch = aScreen->Schematic();
497 wxString variantName = sch->GetCurrentVariant();
498 wxString variantDesc = sch->GetVariantDescription( variantName );
499
500 PlotDrawingSheet( plotter, &sch->Project(), aScreen->GetTitleBlock(), aPageInfo, sch->GetProperties(),
501 aScreen->GetPageNumber(), aScreen->GetPageCount(), sheetName, sheetPath,
502 aScreen->GetFileName(), plotter->GetColorMode() ? color : COLOR4D::BLACK,
503 aScreen->GetVirtualPageNumber() == 1, variantName, variantDesc );
504 }
505
506 aScreen->Plot( plotter, aPlotOpts );
507
508 plotter->EndPlot();
509 delete plotter;
510
511 return true;
512}
513
514
516 SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter )
517{
518 wxString msg;
519 SCH_SHEET_PATH oldsheetpath = m_schematic->CurrentSheet();
520 SCH_SHEET_LIST sheetList;
521
522 if( aPlotOpts.m_plotAll )
523 {
524 sheetList.BuildSheetList( &m_schematic->Root(), true );
525 sheetList.SortByPageNumbers();
526
527 // remove the non-selected pages if we are in plot pages mode
528 if( aPlotOpts.m_plotPages.size() > 0 )
529 {
530 sheetList.TrimToPageNumbers( aPlotOpts.m_plotPages );
531 }
532 }
533 else
534 {
535 // in Eeschema, this prints the current page
536 sheetList.push_back( m_schematic->CurrentSheet() );
537 }
538
539 for( unsigned i = 0; i < sheetList.size(); i++ )
540 {
541 SCH_SCREEN* screen;
542
543 m_schematic->SetCurrentSheet( sheetList[i] );
544 m_schematic->CurrentSheet().UpdateAllScreenReferences();
545 m_schematic->SetSheetNumberAndCount();
546
547 screen = m_schematic->CurrentSheet().LastScreen();
548
549 try
550 {
551 wxFileName plotFileName;
552
553 if( !aPlotOpts.m_outputFile.empty() )
554 {
555 plotFileName = wxFileName( aPlotOpts.m_outputFile );
556
557 if( plotFileName.GetExt().IsEmpty() )
558 plotFileName.SetExt( SVG_PLOTTER::GetDefaultFileExtension() );
559 }
560 else
561 {
562 wxString fname = m_schematic->GetUniqueFilenameForCurrentSheet();
563
564 // The sub sheet can be in a sub_hierarchy, but we plot the file in the
565 // main project folder (or the folder specified by the caller),
566 // so replace separators to create a unique filename:
567 fname.Replace( "/", "_" );
568 fname.Replace( "\\", "_" );
569
570 plotFileName = createPlotFileName( aPlotOpts, fname,
572 aReporter );
573 }
574
575 m_lastOutputFilePath = plotFileName.GetFullPath();
577
578 if( !plotFileName.IsOk() )
579 return;
580
581 bool success = plotOneSheetSVG( plotFileName.GetFullPath(), screen, aRenderSettings,
582 aPlotOpts );
583
584 if( !success )
585 {
586 if( aReporter )
587 {
588 msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() );
589 aReporter->Report( msg, RPT_SEVERITY_ERROR );
590 }
591 }
592 else
593 {
594 if( aReporter )
595 {
596 msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() );
597 aReporter->Report( msg, RPT_SEVERITY_ACTION );
598 }
599 }
600
601 if( !aPlotOpts.m_outputFile.empty() )
602 break;
603 }
604 catch( const IO_ERROR& e )
605 {
606 if( aReporter )
607 {
608 // Cannot plot SVG file
609 msg.Printf( wxT( "SVG Plotter exception: %s" ), e.What() );
610 aReporter->Report( msg, RPT_SEVERITY_ERROR );
611 }
612 break;
613 }
614 }
615
616 if( aReporter )
617 {
618 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
619 }
620
621 restoreEnvironment( nullptr, oldsheetpath );
622}
623
624
625bool SCH_PLOTTER::plotOneSheetSVG( const wxString& aFileName, SCH_SCREEN* aScreen,
626 RENDER_SETTINGS* aRenderSettings,
627 const SCH_PLOT_OPTS& aPlotOpts )
628{
629 PAGE_INFO plotPage;
630
631 // Adjust page size and scaling requests
632 const PAGE_INFO& actualPage = aScreen->GetPageSettings(); // page size selected in schematic
633
634 switch( aPlotOpts.m_pageSizeSelect )
635 {
636 case PAGE_SIZE_A:
637 plotPage.SetType( wxT( "A" ) );
638 plotPage.SetPortrait( actualPage.IsPortrait() );
639 break;
640
641 case PAGE_SIZE_A4:
642 plotPage.SetType( wxT( "A4" ) );
643 plotPage.SetPortrait( actualPage.IsPortrait() );
644 break;
645
646 case PAGE_SIZE_AUTO:
647 default:
648 plotPage = actualPage;
649 break;
650 }
651
652 SVG_PLOTTER* plotter = new SVG_PLOTTER();
653 plotter->SetRenderSettings( aRenderSettings );
654 plotter->SetPageSettings( plotPage );
655 plotter->SetColorMode( aPlotOpts.m_blackAndWhite ? false : true );
656 VECTOR2I plot_offset;
657
658 double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
659 double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
660 double scale = std::min( scalex, scaley );
661
662 // Currently, plot units are in decimil
663 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
664
665 // Init :
666 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
667
668 if( !plotter->OpenFile( aFileName ) )
669 {
670 delete plotter;
671 return false;
672 }
673
674 plotter->StartPlot( m_schematic->CurrentSheet().GetPageNumber() );
675
676 if( aPlotOpts.m_useBackgroundColor && plotter->GetColorMode() )
677 {
679
680 // Use page size selected in schematic to know the schematic bg area
681 VECTOR2I end( actualPage.GetWidthIU( schIUScale.IU_PER_MILS ),
682 actualPage.GetHeightIU( schIUScale.IU_PER_MILS ) );
683
684 plotter->Rect( VECTOR2I( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0, 0 );
685 }
686
687 if( aPlotOpts.m_plotDrawingSheet )
688 {
689 wxString sheetName = m_schematic->CurrentSheet().Last()->GetName();
690 wxString sheetPath = m_schematic->CurrentSheet().PathHumanReadable();
692
693 SCHEMATIC* sch = aScreen->Schematic();
694 wxString variantName = sch->GetCurrentVariant();
695 wxString variantDesc = sch->GetVariantDescription( variantName );
696
697 PlotDrawingSheet( plotter, &sch->Project(), aScreen->GetTitleBlock(), actualPage, sch->GetProperties(),
698 aScreen->GetPageNumber(), aScreen->GetPageCount(), sheetName, sheetPath,
699 aScreen->GetFileName(), plotter->GetColorMode() ? color : COLOR4D::BLACK,
700 aScreen->GetVirtualPageNumber() == 1, variantName, variantDesc );
701 }
702
703 aScreen->Plot( plotter, aPlotOpts );
704
705 plotter->EndPlot();
706 delete plotter;
707
708 return true;
709}
710
711
713 SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter )
714{
715 wxString msg;
716 SCH_SHEET_PATH oldsheetpath = m_schematic->CurrentSheet();
717 SCH_SHEET_LIST sheetList;
718
719 if( aPlotOpts.m_plotAll )
720 {
721 sheetList.BuildSheetList( &m_schematic->Root(), true );
722 sheetList.SortByPageNumbers();
723
724 if( aPlotOpts.m_plotPages.size() > 0 )
725 sheetList.TrimToPageNumbers( aPlotOpts.m_plotPages );
726 }
727 else
728 {
729 sheetList.push_back( m_schematic->CurrentSheet() );
730 }
731
732 for( unsigned i = 0; i < sheetList.size(); i++ )
733 {
734 SCH_SCREEN* screen;
735
736 m_schematic->SetCurrentSheet( sheetList[i] );
737 m_schematic->CurrentSheet().UpdateAllScreenReferences();
738 m_schematic->SetSheetNumberAndCount();
739
740 screen = m_schematic->CurrentSheet().LastScreen();
741
742 try
743 {
744 wxFileName plotFileName;
745
746 if( !aPlotOpts.m_outputFile.empty() )
747 {
748 plotFileName = wxFileName( aPlotOpts.m_outputFile );
749
750 if( plotFileName.GetExt().IsEmpty() )
751 plotFileName.SetExt( PNG_PLOTTER::GetDefaultFileExtension() );
752 }
753 else
754 {
755 wxString fname = m_schematic->GetUniqueFilenameForCurrentSheet();
756
757 fname.Replace( "/", "_" );
758 fname.Replace( "\\", "_" );
759
760 plotFileName = createPlotFileName( aPlotOpts, fname,
762 aReporter );
763 }
764
765 m_lastOutputFilePath = plotFileName.GetFullPath();
767
768 if( !plotFileName.IsOk() )
769 return;
770
771 bool success = plotOneSheetPNG( plotFileName.GetFullPath(), screen, aRenderSettings,
772 aPlotOpts );
773
774 if( aReporter )
775 {
776 if( !success )
777 {
778 msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() );
779 aReporter->Report( msg, RPT_SEVERITY_ERROR );
780 }
781 else
782 {
783 msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() );
784 aReporter->Report( msg, RPT_SEVERITY_ACTION );
785 }
786 }
787
788 if( !aPlotOpts.m_outputFile.empty() )
789 break;
790 }
791 catch( const IO_ERROR& e )
792 {
793 if( aReporter )
794 {
795 msg.Printf( wxT( "PNG Plotter exception: %s" ), e.What() );
796 aReporter->Report( msg, RPT_SEVERITY_ERROR );
797 }
798
799 break;
800 }
801 }
802
803 if( aReporter )
804 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
805
806 restoreEnvironment( nullptr, oldsheetpath );
807}
808
809
810bool SCH_PLOTTER::plotOneSheetPNG( const wxString& aFileName, SCH_SCREEN* aScreen,
811 RENDER_SETTINGS* aRenderSettings,
812 const SCH_PLOT_OPTS& aPlotOpts )
813{
814 PAGE_INFO plotPage;
815 const PAGE_INFO& actualPage = aScreen->GetPageSettings();
816
817 switch( aPlotOpts.m_pageSizeSelect )
818 {
819 case PAGE_SIZE_A:
820 plotPage.SetType( wxT( "A" ) );
821 plotPage.SetPortrait( actualPage.IsPortrait() );
822 break;
823
824 case PAGE_SIZE_A4:
825 plotPage.SetType( wxT( "A4" ) );
826 plotPage.SetPortrait( actualPage.IsPortrait() );
827 break;
828
829 case PAGE_SIZE_AUTO:
830 default:
831 plotPage = actualPage;
832 break;
833 }
834
835 int dpi = std::clamp( aPlotOpts.m_pngDPI, MIN_PNG_DPI, MAX_PNG_DPI );
836
837 int pixelW = KiROUND( static_cast<double>( plotPage.GetWidthMils() ) * dpi / 1000.0 );
838 int pixelH = KiROUND( static_cast<double>( plotPage.GetHeightMils() ) * dpi / 1000.0 );
839
840 PNG_PLOTTER* plotter = new PNG_PLOTTER();
841
842 plotter->SetPixelSize( pixelW, pixelH );
843 plotter->SetResolution( dpi );
844 plotter->SetAntialias( aPlotOpts.m_pngAntialias );
845
846 // Schematic IU is Y-down (matches Cairo); leave SetYAxisReversed at its default of false.
847 // pcbnew sets it true because PCB IU is Y-up. Do not copy that wiring here.
848
849 plotter->SetRenderSettings( aRenderSettings );
850 plotter->SetPageSettings( plotPage );
851 plotter->SetColorMode( !aPlotOpts.m_blackAndWhite );
852
853 VECTOR2I plot_offset;
854 double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
855 double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
856 double scale = std::min( scalex, scaley );
857
858 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
859 plotter->SetCreator( wxT( "Eeschema-PNG" ) );
860
861 if( !plotter->OpenFile( aFileName ) )
862 {
863 delete plotter;
864 return false;
865 }
866
867 plotter->StartPlot( m_schematic->CurrentSheet().GetPageNumber() );
868
869 if( aPlotOpts.m_useBackgroundColor && plotter->GetColorMode() )
870 {
872
873 VECTOR2I end( actualPage.GetWidthIU( schIUScale.IU_PER_MILS ),
874 actualPage.GetHeightIU( schIUScale.IU_PER_MILS ) );
875
876 plotter->Rect( VECTOR2I( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0, 0 );
877 }
878
879 if( aPlotOpts.m_plotDrawingSheet )
880 {
881 wxString sheetName = m_schematic->CurrentSheet().Last()->GetName();
882 wxString sheetPath = m_schematic->CurrentSheet().PathHumanReadable();
884
885 SCHEMATIC* sch = aScreen->Schematic();
886 wxString variantName = sch->GetCurrentVariant();
887 wxString variantDesc = sch->GetVariantDescription( variantName );
888
889 PlotDrawingSheet( plotter, &sch->Project(), aScreen->GetTitleBlock(), actualPage,
890 sch->GetProperties(), aScreen->GetPageNumber(), aScreen->GetPageCount(),
891 sheetName, sheetPath, aScreen->GetFileName(),
892 plotter->GetColorMode() ? color : COLOR4D::BLACK,
893 aScreen->GetVirtualPageNumber() == 1, variantName, variantDesc );
894 }
895
896 aScreen->Plot( plotter, aPlotOpts );
897
898 bool success = plotter->EndPlot();
899 delete plotter;
900
901 return success;
902}
903
904
906 SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter )
907{
908 SCH_SHEET_PATH oldsheetpath = m_schematic->CurrentSheet();
909
910 /* When printing all pages, the printed page is not the current page. In complex hierarchies,
911 * we must update symbol references and other parameters in the given printed SCH_SCREEN,
912 * according to the sheet path because in complex hierarchies a SCH_SCREEN (a drawing ) is
913 * shared between many sheets and symbol references depend on the actual sheet path used.
914 */
915 SCH_SHEET_LIST sheetList;
916
917 if( aPlotOpts.m_plotAll )
918 {
919 sheetList.BuildSheetList( &m_schematic->Root(), true );
920 sheetList.SortByPageNumbers();
921
922 // remove the non-selected pages if we are in plot pages mode
923 if( aPlotOpts.m_plotPages.size() > 0 )
924 sheetList.TrimToPageNumbers( aPlotOpts.m_plotPages );
925 }
926 else
927 {
928 // in Eeschema, this prints the current page
929 sheetList.push_back( m_schematic->CurrentSheet() );
930 }
931
932 for( unsigned i = 0; i < sheetList.size(); i++ )
933 {
934 m_schematic->SetCurrentSheet( sheetList[i] );
935 m_schematic->CurrentSheet().UpdateAllScreenReferences();
936 m_schematic->SetSheetNumberAndCount();
937
938 SCH_SCREEN* screen = m_schematic->CurrentSheet().LastScreen();
939 VECTOR2I plot_offset;
940 wxString msg;
941
942 try
943 {
944 wxFileName plotFileName;
945
946 if( !aPlotOpts.m_outputFile.empty() )
947 {
948 plotFileName = wxFileName( aPlotOpts.m_outputFile );
949
950 if( plotFileName.GetExt().IsEmpty() )
951 plotFileName.SetExt( DXF_PLOTTER::GetDefaultFileExtension() );
952 }
953 else
954 {
955 wxString fname = m_schematic->GetUniqueFilenameForCurrentSheet();
956
957 // The sub sheet can be in a sub_hierarchy, but we plot the file in the
958 // main project folder (or the folder specified by the caller),
959 // so replace separators to create a unique filename:
960 fname.Replace( "/", "_" );
961 fname.Replace( "\\", "_" );
962
963 plotFileName = createPlotFileName( aPlotOpts, fname,
965 aReporter );
966 }
967
968 m_lastOutputFilePath = plotFileName.GetFullPath();
970
971 if( !plotFileName.IsOk() )
972 return;
973
974 if( plotOneSheetDXF( plotFileName.GetFullPath(), screen, aRenderSettings, plot_offset,
975 1.0, aPlotOpts ) )
976 {
977 if( aReporter )
978 {
979 msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() );
980 aReporter->Report( msg, RPT_SEVERITY_ACTION );
981 }
982 }
983 else // Error
984 {
985 if( aReporter )
986 {
987 msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() );
988 aReporter->Report( msg, RPT_SEVERITY_ERROR );
989 }
990 }
991
992 if( !aPlotOpts.m_outputFile.empty() )
993 break;
994 }
995 catch( IO_ERROR& e )
996 {
997 if( aReporter )
998 {
999 msg.Printf( wxT( "DXF Plotter exception: %s" ), e.What() );
1000 aReporter->Report( msg, RPT_SEVERITY_ERROR );
1001 }
1002
1003 m_schematic->SetCurrentSheet( oldsheetpath );
1004 m_schematic->CurrentSheet().UpdateAllScreenReferences();
1005 m_schematic->SetSheetNumberAndCount();
1006 return;
1007 }
1008 }
1009
1010 if( aReporter )
1011 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
1012
1013 restoreEnvironment( nullptr, oldsheetpath );
1014}
1015
1016
1017bool SCH_PLOTTER::plotOneSheetDXF( const wxString& aFileName, SCH_SCREEN* aScreen,
1018 RENDER_SETTINGS* aRenderSettings, const VECTOR2I& aPlotOffset,
1019 double aScale, const SCH_PLOT_OPTS& aPlotOpts )
1020{
1021 aRenderSettings->LoadColors( m_colorSettings );
1022 aRenderSettings->SetDefaultPenWidth( 0 );
1023
1024 const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
1025 DXF_PLOTTER* plotter = new DXF_PLOTTER();
1026
1027 plotter->SetUnits( aPlotOpts.m_DXF_File_Unit );
1028
1029 plotter->SetRenderSettings( aRenderSettings );
1030 plotter->SetPageSettings( pageInfo );
1031 plotter->SetColorMode( !aPlotOpts.m_blackAndWhite );
1032
1033 // Currently, plot units are in decimil
1034 plotter->SetViewport( aPlotOffset, schIUScale.IU_PER_MILS / 10, aScale, false );
1035
1036 // Init :
1037 plotter->SetCreator( wxT( "Eeschema-DXF" ) );
1038
1039 if( !plotter->OpenFile( aFileName ) )
1040 {
1041 delete plotter;
1042 return false;
1043 }
1044
1045 plotter->StartPlot( m_schematic->CurrentSheet().GetPageNumber() );
1046
1047 if( aPlotOpts.m_plotDrawingSheet )
1048 {
1049 wxString sheetName = m_schematic->CurrentSheet().Last()->GetName();
1050 wxString sheetPath = m_schematic->CurrentSheet().PathHumanReadable();
1052
1053 wxString variantName = m_schematic->GetCurrentVariant();
1054 wxString variantDesc = m_schematic->GetVariantDescription( variantName );
1055
1056 PlotDrawingSheet( plotter, &m_schematic->Project(), aScreen->GetTitleBlock(), pageInfo,
1057 m_schematic->GetProperties(), aScreen->GetPageNumber(), aScreen->GetPageCount(), sheetName,
1058 sheetPath, aScreen->GetFileName(), plotter->GetColorMode() ? color : COLOR4D::BLACK,
1059 aScreen->GetVirtualPageNumber() == 1, variantName, variantDesc );
1060 }
1061
1062 aScreen->Plot( plotter, aPlotOpts );
1063
1064 // finish
1065 plotter->EndPlot();
1066 delete plotter;
1067
1068 return true;
1069}
1070
1071
1073{
1074 if( aPlotter )
1075 {
1076 aPlotter->EndPlot();
1077 delete aPlotter;
1078 }
1079
1080 // Restore the initial sheet
1081 m_schematic->SetCurrentSheet( aOldsheetpath );
1082 m_schematic->CurrentSheet().UpdateAllScreenReferences();
1083 m_schematic->SetSheetNumberAndCount();
1084}
1085
1086
1088 const wxString& aPlotFileName,
1089 const wxString& aExtension, REPORTER* aReporter )
1090{
1091 wxFileName retv;
1092 wxFileName tmp;
1093
1094 tmp.SetPath( aPlotOpts.m_outputDirectory );
1095 retv.SetPath( tmp.GetPath() );
1096
1097 if( !aPlotFileName.IsEmpty() )
1098 retv.SetName( aPlotFileName );
1099 else
1100 retv.SetName( _( "Schematic" ) );
1101
1102 retv.SetExt( aExtension );
1103
1104 if( !EnsureFileDirectoryExists( &tmp, retv.GetFullName(), aReporter ) || !tmp.IsDirWritable() )
1105 {
1106 if( aReporter )
1107 {
1108 wxString msg = wxString::Format( _( "Failed to write plot files to folder '%s'." ),
1109 tmp.GetPath() );
1110 aReporter->Report( msg, RPT_SEVERITY_ERROR );
1111 }
1112
1113 retv.Clear();
1114
1115 SCHEMATIC_SETTINGS& settings = m_schematic->Settings();
1116 settings.m_PlotDirectoryName.Clear();
1117 }
1118 else
1119 {
1120 retv.SetPath( tmp.GetPath() );
1121 }
1122
1123 wxLogTrace( tracePathsAndFiles, "Writing plot file '%s'.", retv.GetFullPath() );
1124
1125 return retv;
1126}
1127
1128
1129void SCH_PLOTTER::Plot( PLOT_FORMAT aPlotFormat, const SCH_PLOT_OPTS& aPlotOpts,
1130 SCH_RENDER_SETTINGS* aRenderSettings, REPORTER* aReporter )
1131{
1132 m_outputFilePaths.clear();
1133
1134 wxString oldVariant = m_schematic->GetCurrentVariant();
1135 m_schematic->SetCurrentVariant( aPlotOpts.m_variant );
1137
1138 switch( aPlotFormat )
1139 {
1140 default:
1141 case PLOT_FORMAT::POST: createPSFiles( aPlotOpts, aRenderSettings, aReporter ); break;
1142 case PLOT_FORMAT::DXF: createDXFFiles( aPlotOpts, aRenderSettings, aReporter ); break;
1143 case PLOT_FORMAT::PDF: createPDFFile( aPlotOpts, aRenderSettings, aReporter ); break;
1144 case PLOT_FORMAT::SVG: createSVGFiles( aPlotOpts, aRenderSettings, aReporter ); break;
1145 case PLOT_FORMAT::PNG: createPNGFiles( aPlotOpts, aRenderSettings, aReporter ); break;
1146 case PLOT_FORMAT::HPGL: /* no longer supported */ break;
1147 }
1148
1149 m_schematic->SetCurrentVariant( oldVariant );
1150}
1151
1152
1153BOX2I GetSymbolPlotBBox( const LIB_SYMBOL& aSymbol, int aUnit, int aBodyStyle, bool aIncludeHiddenFields )
1154{
1155 std::unique_ptr<LIB_SYMBOL> flatSymbol = aSymbol.Flatten();
1156
1157 BOX2I symbolBB = flatSymbol->GetUnitBoundingBox( aUnit, aBodyStyle, !aIncludeHiddenFields );
1158
1159 // Inflate the bbox by "some margin". A lot bounding boxes are slightly
1160 // small because a stroke size of '0' is actually 'inherit', by default 6 mils,
1161 // but the actual value can unly be known for sure with the schematic context.
1162 // A margin of 2mm seems to cover most evantualities, but this is a bit of a
1163 // guess.
1164
1165 const int expansion = schIUScale.mmToIU( 2 );
1166 symbolBB.Inflate( expansion );
1167
1168 return symbolBB;
1169}
1170
1171
1172bool PlotSymbolToSVG( LIB_SYMBOL& aDrawSymbol, LIB_SYMBOL& aFieldsSymbol, int aUnit, int aBodyStyle, const BOX2I& aBBox,
1173 SCH_RENDER_SETTINGS& aRenderSettings, bool aBlackAndWhite, const wxString& aFileName,
1174 REPORTER* aReporter )
1175{
1176 PAGE_INFO pageInfo( PAGE_SIZE_TYPE::User );
1177 pageInfo.SetHeightMils( schIUScale.IUToMils( aBBox.GetHeight() ) );
1178 pageInfo.SetWidthMils( schIUScale.IUToMils( aBBox.GetWidth() ) );
1179
1180 std::unique_ptr<SVG_PLOTTER> plotter = std::make_unique<SVG_PLOTTER>();
1181 plotter->SetRenderSettings( &aRenderSettings );
1182 plotter->SetPageSettings( pageInfo );
1183 plotter->SetColorMode( !aBlackAndWhite );
1184
1185 // Currently, plot units are in decimal. Keep the symbol origin at the SVG origin; the
1186 // viewBox is the content bbox.
1187 plotter->SetViewport( VECTOR2I( 0, 0 ), schIUScale.IU_PER_MILS / 10, 1.0, false );
1188 plotter->SetPlotBBox( aBBox );
1189
1190 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
1191
1192 if( !plotter->OpenFile( aFileName ) )
1193 {
1194 if( aReporter )
1195 {
1196 aReporter->Report( wxString::Format( _( "Unable to open destination '%s'" ) + wxS( "\n" ),
1197 aFileName ),
1199 }
1200 return false;
1201 }
1202
1203 LOCALE_IO toggle;
1204 SCH_PLOT_OPTS plotOpts;
1205
1206 plotter->StartPlot( wxS( "1" ) );
1207
1208 constexpr bool background = true;
1209 aDrawSymbol.Plot( plotter.get(), background, plotOpts, aUnit, aBodyStyle, VECTOR2I( 0, 0 ), false );
1210 aDrawSymbol.Plot( plotter.get(), !background, plotOpts, aUnit, aBodyStyle, VECTOR2I( 0, 0 ), false );
1211 aFieldsSymbol.PlotFields( plotter.get(), !background, plotOpts, aUnit, aBodyStyle, VECTOR2I( 0, 0 ), false );
1212
1213 plotter->EndPlot();
1214 return true;
1215}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
int GetPageCount() const
Definition base_screen.h:68
int GetVirtualPageNumber() const
Definition base_screen.h:71
const wxString & GetPageNumber() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr size_type GetHeight() const
Definition box2.h:212
static const COLOR4D BLACK
Definition color4d.h:403
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.
Definition color4d.h:101
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.
Definition lib_symbol.h:119
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.
Definition locale_io.h:37
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition page_info.h:164
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
Definition page_info.h:143
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition page_info.h:155
double GetWidthMils() const
Definition page_info.h:138
bool IsPortrait() const
Definition page_info.h:124
void SetWidthMils(double aWidthInMils)
virtual void ClosePage()
Close the current page in the PDF document (and emit its compressed stream).
virtual bool EndPlot() override
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.
Definition plotter.h:136
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition plotter.cpp:75
virtual void SetAuthor(const wxString &aAuthor)
Definition plotter.h:190
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition plotter.h:169
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition plotter.h:166
virtual void SetTitle(const wxString &aTitle)
Definition plotter.h:189
RENDER_SETTINGS * RenderSettings()
Definition plotter.h:167
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0)=0
virtual void SetCreator(const wxString &aCreator)
Definition plotter.h:188
bool GetColorMode() const
Definition plotter.h:164
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.
Definition plotter.h:163
virtual void SetSubject(const wxString &aSubject)
Definition plotter.h:191
virtual void SetColor(const COLOR4D &color)=0
PNG rasterization plotter using Cairo graphics library.
Definition plotter_png.h:40
void SetPixelSize(int aWidth, int aHeight)
Set the output image dimensions in pixels.
Definition plotter_png.h:64
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.
Definition plotter_png.h:56
virtual bool EndPlot() override
void SetAntialias(bool aEnable)
Enable or disable anti-aliasing.
Definition plotter_png.h:84
virtual void SetColor(const COLOR4D &aColor) override
static wxString GetDefaultFileExtension()
Definition plotter_png.h:50
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.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
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.
Definition reporter.h:121
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition schematic.h:148
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.
Definition schematic.h:170
wxString GetCurrentVariant() const
Return the current variant being edited.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:173
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
void restoreEnvironment(PDF_PLOTTER *aPlotter, SCH_SHEET_PATH &aOldsheetpath)
Everything done, close the plot and restore the environment.
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)
SCHEMATIC * m_schematic
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:140
const wxString & GetFileName() const
Definition sch_screen.h:153
SCHEMATIC * Schematic() const
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:164
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 SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
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)
Definition common.cpp:60
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.
Definition common.cpp:797
@ FOR_GUI
Definition common.h:89
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)
#define _(s)
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:518
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:510
see class PGM_BASE
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:63
constexpr int MIN_PNG_DPI
Definition plotter_png.h:29
constexpr int MAX_PNG_DPI
Definition plotter_png.h:30
Plotting engines similar to ps (PostScript, Gerber, svg)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
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.
@ PAGE_SIZE_AUTO
Definition sch_plotter.h:46
@ PAGE_SIZE_A
Definition sch_plotter.h:48
@ PAGE_SIZE_A4
Definition sch_plotter.h:47
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
const int scale
std::vector< wxString > m_plotPages
Definition sch_plotter.h:56
wxString m_theme
Definition sch_plotter.h:65
DXF_UNITS m_DXF_File_Unit
Definition sch_plotter.h:72
wxString m_outputDirectory
Definition sch_plotter.h:67
bool m_pngAntialias
Definition sch_plotter.h:75
wxString m_outputFile
Definition sch_plotter.h:68
bool m_blackAndWhite
Definition sch_plotter.h:59
wxString m_variant
Definition sch_plotter.h:69
bool m_useBackgroundColor
Definition sch_plotter.h:61
bool m_plotDrawingSheet
Definition sch_plotter.h:55
VECTOR2I end
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683