KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema_jobs_handler.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) 2022 Mark Roszko <[email protected]>
5 * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <common.h>
23#include <pgm_base.h>
24#include <cli/exit_codes.h>
25#include <sch_plotter.h>
31#include <jobs/job_sch_erc.h>
34#include <schematic.h>
35#include <wx/dir.h>
36#include <wx/file.h>
37#include <memory>
38#include <connection_graph.h>
39#include "eeschema_helpers.h"
40#include <filename_resolver.h>
41#include <kiway.h>
42#include <sch_painter.h>
43#include <locale_io.h>
44#include <erc/erc.h>
45#include <erc/erc_report.h>
49#include <reporter.h>
50#include <string_utils.h>
51
53
54#include <sch_file_versions.h>
56
57#include <netlist.h>
67
68#include <fields_data_model.h>
69
72
73
75 JOB_DISPATCHER( aKiway ),
76 m_cliSchematic( nullptr )
77{
78 Register( "bom",
79 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ),
80 []( JOB* job, wxWindow* aParent ) -> bool
81 {
82 JOB_EXPORT_SCH_BOM* bomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( job );
83
84 if( !bomJob )
85 return false;
86
87 return false;
88 } );
89 Register( "pythonbom",
90 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, this, std::placeholders::_1 ),
91 []( JOB* job, wxWindow* aParent ) -> bool
92 {
93 return false;
94 });
95 Register( "netlist",
96 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ),
97 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
98 {
100 dynamic_cast < JOB_EXPORT_SCH_NETLIST*>( job );
101
102 if( !netJob )
103 return false;
104
105 SCH_EDIT_FRAME* editFrame =
106 dynamic_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
107
108 DIALOG_EXPORT_NETLIST dlg( editFrame, aParent, netJob );
109 dlg.ShowModal();
110
111 return dlg.GetReturnCode() == wxID_OK;
112 } );
113 Register( "plot",
114 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPlot, this, std::placeholders::_1 ),
115 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
116 {
117 JOB_EXPORT_SCH_PLOT* plotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( job );
118
119 if( !plotJob )
120 return false;
121
122 SCH_EDIT_FRAME* editFrame =
123 dynamic_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
124
125 DIALOG_PLOT_SCHEMATIC dlg( editFrame, aParent, plotJob );
126 dlg.ShowModal();
127
128 return false;
129 } );
130 Register( "symupgrade",
131 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymUpgrade, this, std::placeholders::_1 ),
132 []( JOB* job, wxWindow* aParent ) -> bool
133 {
134 return false;
135 } );
136 Register( "symsvg",
137 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymExportSvg, this, std::placeholders::_1 ),
138 []( JOB* job, wxWindow* aParent ) -> bool
139 {
140 return false;
141 } );
142 Register( "erc", std::bind( &EESCHEMA_JOBS_HANDLER::JobSchErc, this, std::placeholders::_1 ),
143 []( JOB* job, wxWindow* aParent ) -> bool
144 {
145 return false;
146 } );
147}
148
150{
151 SCHEMATIC* sch = nullptr;
152
153 if( !Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpenNotDummy() )
154 {
156
157 wxString schPath = aPath;
158 if( schPath.IsEmpty() )
159 {
160 wxFileName path = project.GetProjectFullName();
162 path.MakeAbsolute();
163 schPath = path.GetFullPath();
164 }
165
166 if( !m_cliSchematic )
167 {
168 m_reporter->Report( _( "Loading schematic\n" ), RPT_SEVERITY_INFO );
169 m_cliSchematic = EESCHEMA_HELPERS::LoadSchematic( schPath, true, false, &project );
170 }
171
172 sch = m_cliSchematic;
173 }
174 else if( Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpen() )
175 {
176 SCH_EDIT_FRAME* editFrame =
177 dynamic_cast<SCH_EDIT_FRAME*>( m_kiway->Player( FRAME_SCH, false ) );
178
179 if( editFrame )
180 {
181 sch = &editFrame->Schematic();
182 }
183 }
184 else if( !aPath.IsEmpty() )
185 {
186 m_reporter->Report( _( "Loading schematic\n" ), RPT_SEVERITY_INFO );
187 sch = EESCHEMA_HELPERS::LoadSchematic( aPath, true, false );
188 }
189
190 if( !sch )
191 {
192 m_reporter->Report( _( "Failed to load schematic\n" ), RPT_SEVERITY_ERROR );
193 }
194
195 return sch;
196}
197
199 const wxString& aTheme, SCHEMATIC* aSch,
200 const wxString& aDrawingSheetOverride )
201{
203 aRenderSettings->LoadColors( cs );
204 aRenderSettings->m_ShowHiddenPins = false;
205 aRenderSettings->m_ShowHiddenFields = false;
206 aRenderSettings->m_ShowPinAltIcons = false;
207
208 aRenderSettings->SetDefaultPenWidth( aSch->Settings().m_DefaultLineWidth );
209 aRenderSettings->m_LabelSizeRatio = aSch->Settings().m_LabelSizeRatio;
210 aRenderSettings->m_TextOffsetRatio = aSch->Settings().m_TextOffsetRatio;
211 aRenderSettings->m_PinSymbolSize = aSch->Settings().m_PinSymbolSize;
212
213 aRenderSettings->SetDashLengthRatio( aSch->Settings().m_DashedLineDashRatio );
214 aRenderSettings->SetGapLengthRatio( aSch->Settings().m_DashedLineGapRatio );
215
216 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
217 // If empty, or not existing, the default drawing sheet is loaded.
218
219 auto loadSheet =
220 [&]( const wxString& path ) -> bool
221 {
222 wxString msg;
223 FILENAME_RESOLVER resolve;
224 resolve.SetProject( &aSch->Prj() );
225 resolve.SetProgramBase( &Pgm() );
226
227 wxString absolutePath = resolve.ResolvePath( path,
228 wxGetCwd(),
229 aSch->GetEmbeddedFiles() );
230
231 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath, &msg ) )
232 {
233 m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ),
234 path )
235 + wxS( "\n" ) + msg + wxS( "\n" ),
237 return false;
238 }
239
240 return true;
241 };
242
243 // try to load the override first
244 if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
245 return;
246
247 // no override or failed override continues here
248 loadSheet( aSch->Settings().m_SchDrawingSheetFileName );
249}
250
251
253{
254 JOB_EXPORT_SCH_PLOT* aPlotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( aJob );
255
256 if( !aPlotJob )
258
259 SCHEMATIC* sch = getSchematic( aPlotJob->m_filename );
260
261 if( !sch )
263
264 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
265
266 std::unique_ptr<SCH_RENDER_SETTINGS> renderSettings = std::make_unique<SCH_RENDER_SETTINGS>();
267 InitRenderSettings( renderSettings.get(), aPlotJob->m_theme, sch, aPlotJob->m_drawingSheet );
268
269 std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
270
271 PLOT_FORMAT format = PLOT_FORMAT::PDF;
272 switch( aPlotJob->m_plotFormat )
273 {
274 case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF; break;
275 case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF; break;
276 case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG; break;
277 case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST; break;
278 case SCH_PLOT_FORMAT::HPGL: format = PLOT_FORMAT::HPGL; break;
279 case SCH_PLOT_FORMAT::GERBER: format = PLOT_FORMAT::GERBER; break;
280 }
281
282 HPGL_PAGE_SIZE hpglPageSize = HPGL_PAGE_SIZE::DEFAULT;
283 switch( aPlotJob->m_HPGLPaperSizeSelect )
284 {
285 case JOB_HPGL_PAGE_SIZE::DEFAULT: hpglPageSize = HPGL_PAGE_SIZE::DEFAULT; break;
286 case JOB_HPGL_PAGE_SIZE::SIZE_A: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A; break;
287 case JOB_HPGL_PAGE_SIZE::SIZE_A0: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A0; break;
288 case JOB_HPGL_PAGE_SIZE::SIZE_A1: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A1; break;
289 case JOB_HPGL_PAGE_SIZE::SIZE_A2: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A2; break;
290 case JOB_HPGL_PAGE_SIZE::SIZE_A3: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A3; break;
291 case JOB_HPGL_PAGE_SIZE::SIZE_A4: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A4; break;
292 case JOB_HPGL_PAGE_SIZE::SIZE_A5: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A5; break;
293 case JOB_HPGL_PAGE_SIZE::SIZE_B: hpglPageSize = HPGL_PAGE_SIZE::SIZE_B; break;
294 case JOB_HPGL_PAGE_SIZE::SIZE_C: hpglPageSize = HPGL_PAGE_SIZE::SIZE_C; break;
295 case JOB_HPGL_PAGE_SIZE::SIZE_D: hpglPageSize = HPGL_PAGE_SIZE::SIZE_D; break;
296 case JOB_HPGL_PAGE_SIZE::SIZE_E: hpglPageSize = HPGL_PAGE_SIZE::SIZE_E; break;
297 }
298
299 HPGL_PLOT_ORIGIN_AND_UNITS hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE;
300 switch( aPlotJob->m_HPGLPlotOrigin )
301 {
302 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT:
303 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT;
304 break;
305 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER:
306 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER;
307 break;
308 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT:
309 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT;
310 break;
311 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE:
312 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE;
313 break;
314 }
315
316 int pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
317
318 switch( aPlotJob->m_pageSizeSelect )
319 {
320 case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A; break;
321 case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4; break;
322 case JOB_PAGE_SIZE::PAGE_SIZE_AUTO: pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO; break;
323 }
324
325 SCH_PLOT_OPTS plotOpts;
326 plotOpts.m_blackAndWhite = aPlotJob->m_blackAndWhite;
327 plotOpts.m_HPGLPaperSizeSelect = hpglPageSize;
328 plotOpts.m_HPGLPenSize = aPlotJob->m_HPGLPenSize;
329 plotOpts.m_HPGLPlotOrigin = hpglOrigin;
330 plotOpts.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups;
332 plotOpts.m_PDFMetadata = aPlotJob->m_PDFMetadata;
333 plotOpts.m_outputDirectory = aPlotJob->m_outputDirectory;
334 plotOpts.m_outputFile = aPlotJob->m_outputFile;
335 plotOpts.m_pageSizeSelect = pageSizeSelect;
336 plotOpts.m_plotAll = aPlotJob->m_plotAll;
337 plotOpts.m_plotDrawingSheet = aPlotJob->m_plotDrawingSheet;
338 plotOpts.m_plotPages = aPlotJob->m_plotPages;
339 plotOpts.m_theme = aPlotJob->m_theme;
340 plotOpts.m_useBackgroundColor = aPlotJob->m_useBackgroundColor;
341
342 schPlotter->Plot( format, plotOpts, renderSettings.get(), m_reporter );
343
344 return CLI::EXIT_CODES::OK;
345}
346
347
349{
350 JOB_EXPORT_SCH_NETLIST* aNetJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( aJob );
351
352 if( !aNetJob )
354
355 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
356
357 if( !sch )
359
360 // Annotation warning check
361 SCH_REFERENCE_LIST referenceList;
362 sch->Hierarchy().GetSymbols( referenceList );
363
364 if( referenceList.GetCount() > 0 )
365 {
366 if( referenceList.CheckAnnotation(
367 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
368 {
369 // We're only interested in the end result -- either errors or not
370 } )
371 > 0 )
372 {
373 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
374 "schematic editor to fix them\n" ),
376 }
377 }
378
379 // Test duplicate sheet names:
380 ERC_TESTER erc( sch );
381
382 if( erc.TestDuplicateSheetNames( false ) > 0 )
383 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
384
385 std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
386 unsigned netlistOption = 0;
387
388 wxString fileExt;
389
390 switch( aNetJob->format )
391 {
394 helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
395 break;
396
399 helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
400 break;
401
404 helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
405 break;
406
410 helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
411 break;
412
415 helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
416 break;
417
419 fileExt = wxS( "xml" );
420 helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
421 break;
422
424 fileExt = wxS( "asc" );
425 helper = std::make_unique<NETLIST_EXPORTER_PADS>( sch );
426 break;
427
429 fileExt = wxS( "txt" );
430 helper = std::make_unique<NETLIST_EXPORTER_ALLEGRO>( sch );
431 break;
432
433 default:
434 m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR );
436 }
437
438 if( aNetJob->GetOutputPath().IsEmpty() )
439 {
440 wxFileName fn = sch->GetFileName();
441 fn.SetName( fn.GetName() );
442 fn.SetExt( fileExt );
443
444 aNetJob->SetOutputPath( fn.GetFullName() );
445 }
446
447 bool res = helper->WriteNetlist( aNetJob->GetOutputPath(), netlistOption, *m_reporter );
448
449 if( !res )
451
452 return CLI::EXIT_CODES::OK;
453}
454
455
457{
458 JOB_EXPORT_SCH_BOM* aBomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( aJob );
459
460 if( !aBomJob )
462
463 SCHEMATIC* sch = getSchematic( aBomJob->m_filename );
464
465 if( !sch )
467
468 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
469
470 // Annotation warning check
471 SCH_REFERENCE_LIST referenceList;
472 sch->Hierarchy().GetSymbols( referenceList, false, false );
473
474 if( referenceList.GetCount() > 0 )
475 {
476 SCH_REFERENCE_LIST copy = referenceList;
477
478 // Check annotation splits references...
479 if( copy.CheckAnnotation(
480 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
481 {
482 // We're only interested in the end result -- either errors or not
483 } )
484 > 0 )
485 {
487 _( "Warning: schematic has annotation errors, please use the schematic "
488 "editor to fix them\n" ),
490 }
491 }
492
493 // Test duplicate sheet names:
494 ERC_TESTER erc( sch );
495
496 if( erc.TestDuplicateSheetNames( false ) > 0 )
497 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
498
499 // Build our data model
500 FIELDS_EDITOR_GRID_DATA_MODEL dataModel( referenceList );
501
502 // Mandatory fields + quantity virtual field first
503 for( int i = 0; i < MANDATORY_FIELDS; ++i )
505 TEMPLATE_FIELDNAME::GetDefaultFieldName( i, true ), false );
506
507 // User field names in symbols second
508 std::set<wxString> userFieldNames;
509
510 for( size_t i = 0; i < referenceList.GetCount(); ++i )
511 {
512 SCH_SYMBOL* symbol = referenceList[i].GetSymbol();
513
514 for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j )
515 userFieldNames.insert( symbol->GetFields()[j].GetName() );
516 }
517
518 for( const wxString& fieldName : userFieldNames )
519 dataModel.AddColumn( fieldName, GetTextVars( fieldName ), true );
520
521 // Add any templateFieldNames which aren't already present in the userFieldNames
522 for( const TEMPLATE_FIELDNAME& templateFieldname :
524 {
525 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
526 {
527 dataModel.AddColumn( templateFieldname.m_Name, GetTextVars( templateFieldname.m_Name ),
528 false );
529 }
530 }
531
532 BOM_PRESET preset;
533
534 // Load a preset if one is specified
535 if( !aBomJob->m_bomPresetName.IsEmpty() )
536 {
537 // Make sure the built-in presets are loaded
538 for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
539 sch->Settings().m_BomPresets.emplace_back( p );
540
541 // Find the preset
542 BOM_PRESET* schPreset = nullptr;
543
544 for( BOM_PRESET& p : sch->Settings().m_BomPresets )
545 {
546 if( p.name == aBomJob->m_bomPresetName )
547 {
548 schPreset = &p;
549 break;
550 }
551 }
552
553 if( !schPreset )
554 {
555 m_reporter->Report( wxString::Format( _( "BOM preset '%s' not found" ) + wxS( "\n" ),
556 aBomJob->m_bomPresetName ),
558
560 }
561
562 preset = *schPreset;
563 }
564 else
565 {
566 size_t i = 0;
567
568 for( wxString fieldName : aBomJob->m_fieldsOrdered )
569 {
570 // Handle wildcard. We allow the wildcard anywhere in the list, but it needs to respect
571 // fields that come before and after the wildcard.
572 if( fieldName == wxS( "*" ) )
573 {
574 for( const BOM_FIELD& modelField : dataModel.GetFieldsOrdered() )
575 {
576 struct BOM_FIELD field;
577
578 field.name = modelField.name;
579 field.show = true;
580 field.groupBy = false;
581 field.label = field.name;
582
583 bool fieldAlreadyPresent = false;
584 for( BOM_FIELD& presetField : preset.fieldsOrdered )
585 {
586 if( presetField.name == field.name )
587 {
588 fieldAlreadyPresent = true;
589 break;
590 }
591 }
592
593 bool fieldLaterInList = false;
594 for( const wxString& fieldInList : aBomJob->m_fieldsOrdered )
595 {
596 if( fieldInList == field.name )
597 {
598 fieldLaterInList = true;
599 break;
600 }
601 }
602
603 if( !fieldAlreadyPresent && !fieldLaterInList )
604 preset.fieldsOrdered.emplace_back( field );
605 }
606
607 continue;
608 }
609
610 struct BOM_FIELD field;
611
612 field.name = fieldName;
613 field.show = true;
614 field.groupBy = std::find( aBomJob->m_fieldsGroupBy.begin(),
615 aBomJob->m_fieldsGroupBy.end(), field.name )
616 != aBomJob->m_fieldsGroupBy.end();
617
618 if( ( aBomJob->m_fieldsLabels.size() > i ) && !aBomJob->m_fieldsLabels[i].IsEmpty() )
619 field.label = aBomJob->m_fieldsLabels[i];
620 else if( IsTextVar( field.name ) )
621 field.label = GetTextVars( field.name );
622 else
623 field.label = field.name;
624
625 preset.fieldsOrdered.emplace_back( field );
626 i++;
627 }
628
629 preset.sortAsc = aBomJob->m_sortAsc;
630 preset.sortField = aBomJob->m_sortField;
631 preset.filterString = aBomJob->m_filterString;
632 preset.groupSymbols = ( aBomJob->m_fieldsGroupBy.size() > 0 );
633 preset.excludeDNP = aBomJob->m_excludeDNP;
635 }
636
637 dataModel.ApplyBomPreset( preset );
638
639 if( aBomJob->GetOutputPath().IsEmpty() )
640 {
641 wxFileName fn = sch->GetFileName();
642 fn.SetName( fn.GetName() );
643 fn.SetExt( FILEEXT::CsvFileExtension );
644
645 aBomJob->SetOutputPath( fn.GetFullName() );
646 }
647
648 wxFile f;
649
650 if( !f.Open( aBomJob->GetOutputPath(), wxFile::write ) )
651 {
652 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ),
653 aBomJob->GetOutputPath() ),
655
657 }
658
659 BOM_FMT_PRESET fmt;
660
661 // Load a format preset if one is specified
662 if( !aBomJob->m_bomFmtPresetName.IsEmpty() )
663 {
664 // Make sure the built-in presets are loaded
666 sch->Settings().m_BomFmtPresets.emplace_back( p );
667
668 // Find the preset
669 BOM_FMT_PRESET* schFmtPreset = nullptr;
670
671 for( BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
672 {
673 if( p.name == aBomJob->m_bomFmtPresetName )
674 {
675 schFmtPreset = &p;
676 break;
677 }
678 }
679
680 if( !schFmtPreset )
681 {
683 wxString::Format( _( "BOM format preset '%s' not found" ) + wxS( "\n" ),
684 aBomJob->m_bomFmtPresetName ),
686
688 }
689
690 fmt = *schFmtPreset;
691 }
692 else
693 {
694 fmt.fieldDelimiter = aBomJob->m_fieldDelimiter;
695 fmt.stringDelimiter = aBomJob->m_stringDelimiter;
696 fmt.refDelimiter = aBomJob->m_refDelimiter;
698 fmt.keepTabs = aBomJob->m_keepTabs;
699 fmt.keepLineBreaks = aBomJob->m_keepLineBreaks;
700 }
701
702 bool res = f.Write( dataModel.Export( fmt ) );
703
704 if( !res )
706
707 return CLI::EXIT_CODES::OK;
708}
709
710
712{
713 JOB_EXPORT_SCH_PYTHONBOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_PYTHONBOM*>( aJob );
714
715 if( !aNetJob )
717
718 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
719
720 if( !sch )
722
723 // Annotation warning check
724 SCH_REFERENCE_LIST referenceList;
725 sch->Hierarchy().GetSymbols( referenceList );
726
727 if( referenceList.GetCount() > 0 )
728 {
729 if( referenceList.CheckAnnotation(
730 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
731 {
732 // We're only interested in the end result -- either errors or not
733 } )
734 > 0 )
735 {
737 _( "Warning: schematic has annotation errors, please use the schematic "
738 "editor to fix them\n" ),
740 }
741 }
742
743 // Test duplicate sheet names:
744 ERC_TESTER erc( sch );
745
746 if( erc.TestDuplicateSheetNames( false ) > 0 )
747 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
748
749 std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
750 std::make_unique<NETLIST_EXPORTER_XML>( sch );
751
752 if( aNetJob->GetOutputPath().IsEmpty() )
753 {
754 wxFileName fn = sch->GetFileName();
755 fn.SetName( fn.GetName() + "-bom" );
756 fn.SetExt( FILEEXT::XmlFileExtension );
757
758 aNetJob->SetOutputPath( fn.GetFullName() );
759 }
760
761 bool res = xmlNetlist->WriteNetlist( aNetJob->GetOutputPath(), GNL_OPT_BOM, *m_reporter );
762
763 if( !res )
765
766 return CLI::EXIT_CODES::OK;
767}
768
769
771 SCH_RENDER_SETTINGS* aRenderSettings,
772 LIB_SYMBOL* symbol )
773{
774 wxASSERT( symbol != nullptr );
775
776 if( symbol == nullptr )
778
779 LIB_SYMBOL* symbolToPlot = symbol;
780
781 // if the symbol is an alias, then the draw items are stored in the root symbol
782 if( symbol->IsAlias() )
783 {
784 if( LIB_SYMBOL_SPTR parent = symbol->GetRootSymbol() )
785 {
786 symbolToPlot = parent.get();
787 }
788 else
789 {
790 wxCHECK( false, CLI::EXIT_CODES::ERR_UNKNOWN );
791 }
792 }
793
794 // iterate from unit 1, unit 0 would be "all units" which we don't want
795 for( int unit = 1; unit < symbol->GetUnitCount() + 1; unit++ )
796 {
797 for( int bodyStyle = 1; bodyStyle < ( symbol->HasAlternateBodyStyle() ? 2 : 1 ) + 1; ++bodyStyle )
798 {
799 wxString filename;
800 wxFileName fn;
801 size_t forbidden_char;
802
803 fn.SetPath( aSvgJob->m_outputDirectory );
804 fn.SetExt( FILEEXT::SVGFileExtension );
805
806 filename = symbol->GetName().Lower();
807
808 while( wxString::npos
809 != ( forbidden_char = filename.find_first_of(
810 wxFileName::GetForbiddenChars( wxPATH_DOS ) ) ) )
811 {
812 filename = filename.replace( forbidden_char, 1, wxS( '_' ) );
813 }
814
815 //simplify the name if its single unit
816 if( symbol->GetUnitCount() > 1 )
817 {
818 filename += wxString::Format( "_%d", unit );
819
820 if( bodyStyle == 2 )
821 filename += wxS( "_demorgan" );
822
823 fn.SetName( filename );
824 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ),
825 symbol->GetName(), unit, fn.GetFullPath() ),
827 }
828 else
829 {
830 if( bodyStyle == 2 )
831 filename += wxS( "_demorgan" );
832
833 fn.SetName( filename );
834 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' to '%s'\n" ),
835 symbol->GetName(), fn.GetFullPath() ),
837 }
838
839 // Get the symbol bounding box to fit the plot page to it
840 BOX2I symbolBB = symbol->Flatten()->GetUnitBoundingBox( unit, bodyStyle, !aSvgJob->m_includeHiddenFields );
841 PAGE_INFO pageInfo( PAGE_INFO::Custom );
842 pageInfo.SetHeightMils( schIUScale.IUToMils( symbolBB.GetHeight() * 1.2 ) );
843 pageInfo.SetWidthMils( schIUScale.IUToMils( symbolBB.GetWidth() * 1.2 ) );
844
845 SVG_PLOTTER* plotter = new SVG_PLOTTER();
846 plotter->SetRenderSettings( aRenderSettings );
847 plotter->SetPageSettings( pageInfo );
848 plotter->SetColorMode( !aSvgJob->m_blackAndWhite );
849
850 VECTOR2I plot_offset = symbolBB.GetCenter();
851 const double scale = 1.0;
852
853 // Currently, plot units are in decimal
854 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
855
856 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
857
858 if( !plotter->OpenFile( fn.GetFullPath() ) )
859 {
861 wxString::Format( _( "Unable to open destination '%s'" ) + wxS( "\n" ),
862 fn.GetFullPath() ),
864
865 delete plotter;
867 }
868
869 LOCALE_IO toggle;
870 SCH_PLOT_OPTS plotOpts;
871
872 plotter->StartPlot( wxT( "1" ) );
873
874 bool background = true;
875 VECTOR2I offset( pageInfo.GetWidthIU( schIUScale.IU_PER_MILS ) / 2,
876 pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) / 2 );
877
878 // note, we want the fields from the original symbol pointer (in case of non-alias)
879 symbolToPlot->Plot( plotter, background, plotOpts, unit, bodyStyle, offset, false );
880 symbol->PlotFields( plotter, background, plotOpts, unit, bodyStyle, offset, false );
881
882 symbolToPlot->Plot( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
883 symbol->PlotFields( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
884
885 plotter->EndPlot();
886 delete plotter;
887 }
888 }
889
890 return CLI::EXIT_CODES::OK;
891}
892
893
895{
896 JOB_SYM_EXPORT_SVG* svgJob = dynamic_cast<JOB_SYM_EXPORT_SVG*>( aJob );
897
898 if( !svgJob )
900
901 wxFileName fn( svgJob->m_libraryPath );
902 fn.MakeAbsolute();
903
904 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
905
906 try
907 {
908 schLibrary.Load();
909 }
910 catch( ... )
911 {
912 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
914 }
915
916 LIB_SYMBOL* symbol = nullptr;
917
918 if( !svgJob->m_symbol.IsEmpty() )
919 {
920 // See if the selected symbol exists
921 symbol = schLibrary.GetSymbol( svgJob->m_symbol );
922
923 if( !symbol )
924 {
925 m_reporter->Report( _( "There is no symbol selected to save." ) + wxS( "\n" ),
928 }
929 }
930
931 if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) )
932 {
933 wxFileName::Mkdir( svgJob->m_outputDirectory );
934 }
935
936 SCH_RENDER_SETTINGS renderSettings;
938 renderSettings.LoadColors( cs );
940 renderSettings.m_ShowHiddenPins = svgJob->m_includeHiddenPins;
941 renderSettings.m_ShowHiddenFields = svgJob->m_includeHiddenFields;
942
943 int exitCode = CLI::EXIT_CODES::OK;
944
945 if( symbol )
946 {
947 exitCode = doSymExportSvg( svgJob, &renderSettings, symbol );
948 }
949 else
950 {
951 // Just plot all the symbols we can
952 const LIB_SYMBOL_MAP& libSymMap = schLibrary.GetSymbolMap();
953
954 for( const std::pair<const wxString, LIB_SYMBOL*>& entry : libSymMap )
955 {
956 exitCode = doSymExportSvg( svgJob, &renderSettings, entry.second );
957
958 if( exitCode != CLI::EXIT_CODES::OK )
959 break;
960 }
961 }
962
963 return exitCode;
964}
965
966
968{
969 JOB_SYM_UPGRADE* upgradeJob = dynamic_cast<JOB_SYM_UPGRADE*>( aJob );
970
971 if( !upgradeJob )
973
974 wxFileName fn( upgradeJob->m_libraryPath );
975 fn.MakeAbsolute();
976
977 SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
978
979 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
980 {
981 if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) )
982 {
983 m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
985
987 }
988 }
989 else if( fileType != SCH_IO_MGR::SCH_KICAD )
990 {
991 m_reporter->Report( _( "Output path must be specified to convert legacy and non-KiCad libraries\n" ),
993
995 }
996
997 if( fileType == SCH_IO_MGR::SCH_KICAD )
998 {
999 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
1000
1001 try
1002 {
1003 schLibrary.Load();
1004 }
1005 catch( ... )
1006 {
1007 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
1009 }
1010
1011 bool shouldSave =
1012 upgradeJob->m_force
1014
1015 if( shouldSave )
1016 {
1017 m_reporter->Report( _( "Saving symbol library in updated format\n" ),
1019
1020 try
1021 {
1022 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1023 {
1024 schLibrary.SetFileName( upgradeJob->m_outputLibraryPath );
1025 }
1026
1027 schLibrary.SetModified();
1028 schLibrary.Save();
1029 }
1030 catch( ... )
1031 {
1032 m_reporter->Report( ( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
1034 }
1035 }
1036 else
1037 {
1038 m_reporter->Report( _( "Symbol library was not updated\n" ), RPT_SEVERITY_INFO );
1039 }
1040 }
1041 else
1042 {
1043 if( !SCH_IO_MGR::ConvertLibrary( nullptr, fn.GetAbsolutePath(), upgradeJob->m_outputLibraryPath ) )
1044 {
1045 m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR );
1047 }
1048 }
1049
1050 return CLI::EXIT_CODES::OK;
1051}
1052
1053
1054
1056{
1057 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( aJob );
1058
1059 if( !ercJob )
1061
1062 SCHEMATIC* sch = getSchematic( ercJob->m_filename );
1063
1064 if( !sch )
1066
1067 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
1068
1069 if( ercJob->m_outputFile.IsEmpty() )
1070 {
1071 wxFileName fn = sch->GetFileName();
1072 fn.SetName( fn.GetName() );
1073
1075 fn.SetExt( FILEEXT::JsonFileExtension );
1076 else
1077 fn.SetExt( FILEEXT::ReportFileExtension );
1078
1079 ercJob->m_outputFile = fn.GetFullName();
1080 }
1081
1082 EDA_UNITS units;
1083
1084 switch( ercJob->m_units )
1085 {
1086 case JOB_SCH_ERC::UNITS::INCHES: units = EDA_UNITS::INCHES; break;
1087 case JOB_SCH_ERC::UNITS::MILS: units = EDA_UNITS::MILS; break;
1088 case JOB_SCH_ERC::UNITS::MILLIMETERS: units = EDA_UNITS::MILLIMETRES; break;
1089 default: units = EDA_UNITS::MILLIMETRES; break;
1090 }
1091
1092 std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
1093 std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
1094
1095 ERC_TESTER ercTester( sch );
1096
1097 m_reporter->Report( _( "Running ERC...\n" ), RPT_SEVERITY_INFO );
1098
1099 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet( getDrawingSheetProxyView( sch ) );
1100 ercTester.RunTests( drawingSheet.get(), nullptr, m_kiway->KiFACE( KIWAY::FACE_CVPCB ),
1101 &sch->Prj(), m_progressReporter );
1102
1103 markersProvider->SetSeverities( ercJob->m_severity );
1104
1105 m_reporter->Report( wxString::Format( _( "Found %d violations\n" ),
1106 markersProvider->GetCount() ),
1108
1109 ERC_REPORT reportWriter( sch, units );
1110
1111 bool wroteReport = false;
1112
1114 wroteReport = reportWriter.WriteJsonReport( ercJob->m_outputFile );
1115 else
1116 wroteReport = reportWriter.WriteTextReport( ercJob->m_outputFile );
1117
1118 if( !wroteReport )
1119 {
1120 m_reporter->Report( wxString::Format( _( "Unable to save ERC report to %s\n" ),
1121 ercJob->m_outputFile ),
1124 }
1125
1126 m_reporter->Report( wxString::Format( _( "Saved ERC Report to %s\n" ), ercJob->m_outputFile ),
1128
1129 if( ercJob->m_exitCodeViolations )
1130 {
1131 if( markersProvider->GetCount() > 0 )
1133 }
1134
1136}
1137
1138
1140{
1141 DS_PROXY_VIEW_ITEM* drawingSheet =
1143 &aSch->Prj(), &aSch->RootScreen()->GetTitleBlock(),
1144 aSch->GetProperties() );
1145
1146 drawingSheet->SetPageNumber( TO_UTF8( aSch->RootScreen()->GetPageNumber() ) );
1147 drawingSheet->SetSheetCount( aSch->RootScreen()->GetPageCount() );
1148 drawingSheet->SetFileName( TO_UTF8( aSch->RootScreen()->GetFileName() ) );
1151 drawingSheet->SetIsFirstPage( aSch->RootScreen()->GetVirtualPageNumber() == 1 );
1152
1153 drawingSheet->SetSheetName( "" );
1154 drawingSheet->SetSheetPath( "" );
1155
1156 return drawingSheet;
1157}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
int GetPageCount() const
Definition: base_screen.h:72
int GetVirtualPageNumber() const
Definition: base_screen.h:75
const wxString & GetPageNumber() const
Definition: base_screen.cpp:70
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr const Vec GetCenter() const
Definition: box2.h:230
constexpr size_type GetHeight() const
Definition: box2.h:215
Color settings are a bit different than most of the settings objects in that there can be more than o...
int ShowModal() override
bool LoadDrawingSheet(const wxString &aFullFileName, wxString *aMsg, bool aAppend=false)
Populates the list with a custom layout or the default layout if no custom layout is available.
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
void SetSheetPath(const std::string &aSheetPath)
Set the sheet path displayed in the title block.
void SetSheetCount(int aSheetCount)
Changes the sheet-count number displayed in the title block.
void SetPageNumber(const std::string &aPageNumber)
Changes the page number displayed in the title block.
void SetSheetName(const std::string &aSheetName)
Set the sheet name displayed in the title block.
void SetPageBorderColorLayer(int aLayerId)
Overrides the layer used to pick the color of the page border (normally LAYER_GRID)
void SetIsFirstPage(bool aIsFirstPage)
Change if this is first page.
void SetFileName(const std::string &aFileName)
Set the file name displayed in the title block.
void SetColorLayer(int aLayerId)
Can be used to override which layer ID is used for drawing sheet item colors.
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr)
void InitRenderSettings(SCH_RENDER_SETTINGS *aRenderSettings, const wxString &aTheme, SCHEMATIC *aSch, const wxString &aDrawingSheetOverride=wxEmptyString)
Configure the SCH_RENDER_SETTINGS object with the correct data to be used with plotting.
SCHEMATIC * getSchematic(const wxString &aPath)
DS_PROXY_VIEW_ITEM * getDrawingSheetProxyView(SCHEMATIC *aSch)
EESCHEMA_JOBS_HANDLER(KIWAY *aKiway)
int doSymExportSvg(JOB_SYM_EXPORT_SVG *aSvgJob, SCH_RENDER_SETTINGS *aRenderSettings, LIB_SYMBOL *symbol)
bool WriteJsonReport(const wxString &aFullFileName)
Writes a JSON formatted ERC Report to the given file path.
Definition: erc_report.cpp:109
bool WriteTextReport(const wxString &aFullFileName)
Writes the text report also available via GetTextReport directly to a given file path.
Definition: erc_report.cpp:95
Definition: erc.h:52
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition: erc.cpp:1751
void ApplyBomPreset(const BOM_PRESET &preset)
wxString Export(const BOM_FMT_PRESET &settings)
void AddColumn(const wxString &aFieldName, const wxString &aLabel, bool aAddedByUser)
const std::vector< BOM_FIELD > GetFieldsOrdered()
Provide an extensible class to resolve 3D model paths.
bool SetProject(PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, const EMBEDDED_FILES *aFiles)
Determines the full path of the given file name.
void Register(const std::string &aJobTypeName, std::function< int(JOB *job)> aHandler, std::function< bool(JOB *job, wxWindow *aParent)> aConfigHandler)
PROGRESS_REPORTER * m_progressReporter
REPORTER * m_reporter
std::vector< wxString > m_fieldsLabels
std::vector< wxString > m_fieldsOrdered
std::vector< wxString > m_fieldsGroupBy
JOB_PAGE_SIZE m_pageSizeSelect
SCH_PLOT_FORMAT m_plotFormat
JOB_HPGL_PLOT_ORIGIN_AND_UNITS m_HPGLPlotOrigin
std::vector< wxString > m_plotPages
JOB_HPGL_PAGE_SIZE m_HPGLPaperSizeSelect
wxString m_filename
Definition: job_sch_erc.h:36
int m_severity
Definition: job_sch_erc.h:48
OUTPUT_FORMAT m_format
Definition: job_sch_erc.h:56
UNITS m_units
Definition: job_sch_erc.h:46
bool m_exitCodeViolations
Definition: job_sch_erc.h:58
wxString m_outputFile
Definition: job_sch_erc.h:37
wxString m_outputLibraryPath
wxString m_libraryPath
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:79
void SetOutputPath(const wxString &aPath)
Definition: job.cpp:129
const std::map< wxString, wxString > & GetVarOverrides() const
Definition: job.h:87
wxString GetOutputPath() const
Definition: job.h:119
void SetDefaultPenWidth(int aWidth)
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:202
@ FACE_CVPCB
Definition: kiway.h:293
Define a library symbol object.
Definition: lib_symbol.h:78
bool IsAlias() const
Definition: lib_symbol.h:195
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.
Definition: lib_symbol.cpp:660
bool HasAlternateBodyStyle() const override
Test if symbol has more than one body conversion type (DeMorgan).
void PlotFields(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed)
Plot symbol fields.
Definition: lib_symbol.cpp:702
wxString GetName() const override
Definition: lib_symbol.h:137
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:304
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:236
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition: page_info.h:162
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:82
void SetHeightMils(double aHeightInMils)
Definition: page_info.cpp:259
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition: page_info.h:153
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:245
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:75
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:138
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:135
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:154
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:132
Container for project specific data.
Definition: project.h:64
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
Definition: project.cpp:90
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
wxString m_SchDrawingSheetFileName
std::vector< BOM_PRESET > m_BomPresets
std::vector< BOM_FMT_PRESET > m_BomFmtPresets
Holds all the data relating to one schematic.
Definition: schematic.h:77
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:306
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:312
SCH_SHEET_LIST Hierarchy() const override
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:214
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:858
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:208
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:95
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:92
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
A cache assistant for the KiCad s-expression symbol libraries.
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
virtual LIB_SYMBOL * GetSymbol(const wxString &aName)
void SetFileName(const wxString &aFileName)
const LIB_SYMBOL_MAP & GetSymbolMap() const
void SetModified(bool aModified=true)
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilepath)
Convert a schematic symbol library to the latest KiCad format.
Definition: sch_io_mgr.cpp:191
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Definition: sch_io_mgr.cpp:140
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
int CheckAnnotation(ANNOTATION_ERROR_HANDLER aErrorHandler)
Check for annotations errors.
A helper to define a symbol's reference designator in a schematic.
void LoadColors(const COLOR_SETTINGS *aSettings) override
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:130
const wxString & GetFileName() const
Definition: sch_screen.h:143
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:154
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Schematic symbol object.
Definition: sch_symbol.h:104
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:606
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:987
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
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 bool EndPlot() override
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.
bool IsTextVar(const wxString &aSource)
Returns true if the string is a text var, e.g starts with ${.
Definition: common.cpp:133
wxString GetTextVars(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition: common.cpp:121
The common library.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
ERCE_T
ERC error codes.
Definition: erc_settings.h:37
@ FRAME_SCH
Definition: frame_type.h:34
static const std::string CadstarNetlistFileExtension
static const std::string NetlistFileExtension
static const std::string ReportFileExtension
static const std::string JsonFileExtension
static const std::string XmlFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string OrCadPcb2NetlistFileExtension
static const std::string CsvFileExtension
static const std::string SpiceFileExtension
static const std::string SVGFileExtension
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:398
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:399
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:46
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30
static const int ERR_RC_VIOLATIONS
Definition: exit_codes.h:36
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
static const int SUCCESS
Definition: exit_codes.h:29
static const int ERR_INVALID_OUTPUT_CONFLICT
Rules check violation count was greater than 0.
Definition: exit_codes.h:34
static const int ERR_UNKNOWN
Definition: exit_codes.h:32
@ GNL_OPT_BOM
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:65
Plotting engines similar to ps (PostScript, Gerber, svg)
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
HPGL_PAGE_SIZE
Definition: sch_plotter.h:64
HPGL_PLOT_ORIGIN_AND_UNITS
Definition: sch_plotter.h:47
const int scale
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
wxString label
Definition: bom_settings.h:33
bool groupBy
Definition: bom_settings.h:35
wxString name
Definition: bom_settings.h:32
wxString fieldDelimiter
Definition: bom_settings.h:83
static std::vector< BOM_FMT_PRESET > BuiltInPresets()
wxString stringDelimiter
Definition: bom_settings.h:84
wxString refRangeDelimiter
Definition: bom_settings.h:86
wxString refDelimiter
Definition: bom_settings.h:85
wxString sortField
Definition: bom_settings.h:54
bool groupSymbols
Definition: bom_settings.h:57
std::vector< BOM_FIELD > fieldsOrdered
Definition: bom_settings.h:53
bool includeExcludedFromBOM
Definition: bom_settings.h:59
static std::vector< BOM_PRESET > BuiltInPresets()
bool excludeDNP
Definition: bom_settings.h:58
bool sortAsc
Definition: bom_settings.h:55
wxString filterString
Definition: bom_settings.h:56
constexpr int IUToMils(int iu) const
Definition: base_units.h:99
const double IU_PER_MILS
Definition: base_units.h:77
std::vector< wxString > m_plotPages
Definition: sch_plotter.h:84
wxString m_theme
Definition: sch_plotter.h:94
bool m_PDFPropertyPopups
Definition: sch_plotter.h:91
wxString m_outputDirectory
Definition: sch_plotter.h:96
HPGL_PLOT_ORIGIN_AND_UNITS m_HPGLPlotOrigin
Definition: sch_plotter.h:99
wxString m_outputFile
Definition: sch_plotter.h:97
int m_pageSizeSelect
Definition: sch_plotter.h:87
bool m_PDFMetadata
Definition: sch_plotter.h:93
bool m_blackAndWhite
Definition: sch_plotter.h:86
HPGL_PAGE_SIZE m_HPGLPaperSizeSelect
Definition: sch_plotter.h:90
double m_HPGLPenSize
Definition: sch_plotter.h:89
bool m_PDFHierarchicalLinks
Definition: sch_plotter.h:92
bool m_useBackgroundColor
Definition: sch_plotter.h:88
bool m_plotDrawingSheet
Definition: sch_plotter.h:83
Hold a name of a symbol's field, field value, and default visibility.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
VECTOR3I res
Definition of file extensions used in Kicad.