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( !aPath.IsEmpty() )
175 {
176 m_reporter->Report( _( "Loading schematic\n" ), RPT_SEVERITY_INFO );
177 sch = EESCHEMA_HELPERS::LoadSchematic( aPath, true, false );
178 }
179
180 if( !sch )
181 {
182 m_reporter->Report( _( "Failed to load schematic\n" ), RPT_SEVERITY_ERROR );
183 }
184
185 return sch;
186}
187
189 const wxString& aTheme, SCHEMATIC* aSch,
190 const wxString& aDrawingSheetOverride )
191{
193 aRenderSettings->LoadColors( cs );
194 aRenderSettings->m_ShowHiddenPins = false;
195 aRenderSettings->m_ShowHiddenFields = false;
196 aRenderSettings->m_ShowPinAltIcons = false;
197
198 aRenderSettings->SetDefaultPenWidth( aSch->Settings().m_DefaultLineWidth );
199 aRenderSettings->m_LabelSizeRatio = aSch->Settings().m_LabelSizeRatio;
200 aRenderSettings->m_TextOffsetRatio = aSch->Settings().m_TextOffsetRatio;
201 aRenderSettings->m_PinSymbolSize = aSch->Settings().m_PinSymbolSize;
202
203 aRenderSettings->SetDashLengthRatio( aSch->Settings().m_DashedLineDashRatio );
204 aRenderSettings->SetGapLengthRatio( aSch->Settings().m_DashedLineGapRatio );
205
206 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
207 // If empty, or not existing, the default drawing sheet is loaded.
208
209 auto loadSheet =
210 [&]( const wxString& path ) -> bool
211 {
212 wxString msg;
213 FILENAME_RESOLVER resolve;
214 resolve.SetProject( &aSch->Prj() );
215 resolve.SetProgramBase( &Pgm() );
216
217 wxString absolutePath = resolve.ResolvePath( path,
218 wxGetCwd(),
219 aSch->GetEmbeddedFiles() );
220
221 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath, &msg ) )
222 {
223 m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ),
224 path )
225 + wxS( "\n" ) + msg + wxS( "\n" ),
227 return false;
228 }
229
230 return true;
231 };
232
233 // try to load the override first
234 if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
235 return;
236
237 // no override or failed override continues here
238 loadSheet( aSch->Settings().m_SchDrawingSheetFileName );
239}
240
241
243{
244 JOB_EXPORT_SCH_PLOT* aPlotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( aJob );
245
246 if( !aPlotJob )
248
249 SCHEMATIC* sch = getSchematic( aPlotJob->m_filename );
250
251 if( !sch )
253
254 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
255
256 std::unique_ptr<SCH_RENDER_SETTINGS> renderSettings = std::make_unique<SCH_RENDER_SETTINGS>();
257 InitRenderSettings( renderSettings.get(), aPlotJob->m_theme, sch, aPlotJob->m_drawingSheet );
258
259 std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
260
261 PLOT_FORMAT format = PLOT_FORMAT::PDF;
262 switch( aPlotJob->m_plotFormat )
263 {
264 case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF; break;
265 case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF; break;
266 case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG; break;
267 case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST; break;
268 case SCH_PLOT_FORMAT::HPGL: format = PLOT_FORMAT::HPGL; break;
269 case SCH_PLOT_FORMAT::GERBER: format = PLOT_FORMAT::GERBER; break;
270 }
271
272 HPGL_PAGE_SIZE hpglPageSize = HPGL_PAGE_SIZE::DEFAULT;
273 switch( aPlotJob->m_HPGLPaperSizeSelect )
274 {
275 case JOB_HPGL_PAGE_SIZE::DEFAULT: hpglPageSize = HPGL_PAGE_SIZE::DEFAULT; break;
276 case JOB_HPGL_PAGE_SIZE::SIZE_A: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A; break;
277 case JOB_HPGL_PAGE_SIZE::SIZE_A0: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A0; break;
278 case JOB_HPGL_PAGE_SIZE::SIZE_A1: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A1; break;
279 case JOB_HPGL_PAGE_SIZE::SIZE_A2: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A2; break;
280 case JOB_HPGL_PAGE_SIZE::SIZE_A3: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A3; break;
281 case JOB_HPGL_PAGE_SIZE::SIZE_A4: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A4; break;
282 case JOB_HPGL_PAGE_SIZE::SIZE_A5: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A5; break;
283 case JOB_HPGL_PAGE_SIZE::SIZE_B: hpglPageSize = HPGL_PAGE_SIZE::SIZE_B; break;
284 case JOB_HPGL_PAGE_SIZE::SIZE_C: hpglPageSize = HPGL_PAGE_SIZE::SIZE_C; break;
285 case JOB_HPGL_PAGE_SIZE::SIZE_D: hpglPageSize = HPGL_PAGE_SIZE::SIZE_D; break;
286 case JOB_HPGL_PAGE_SIZE::SIZE_E: hpglPageSize = HPGL_PAGE_SIZE::SIZE_E; break;
287 }
288
289 HPGL_PLOT_ORIGIN_AND_UNITS hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE;
290 switch( aPlotJob->m_HPGLPlotOrigin )
291 {
292 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT:
293 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT;
294 break;
295 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER:
296 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER;
297 break;
298 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT:
299 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT;
300 break;
301 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE:
302 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE;
303 break;
304 }
305
306 int pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
307
308 switch( aPlotJob->m_pageSizeSelect )
309 {
310 case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A; break;
311 case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4; break;
312 case JOB_PAGE_SIZE::PAGE_SIZE_AUTO: pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO; break;
313 }
314
315 SCH_PLOT_OPTS plotOpts;
316 plotOpts.m_blackAndWhite = aPlotJob->m_blackAndWhite;
317 plotOpts.m_HPGLPaperSizeSelect = hpglPageSize;
318 plotOpts.m_HPGLPenSize = aPlotJob->m_HPGLPenSize;
319 plotOpts.m_HPGLPlotOrigin = hpglOrigin;
320 plotOpts.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups;
322 plotOpts.m_PDFMetadata = aPlotJob->m_PDFMetadata;
323 plotOpts.m_outputDirectory = aPlotJob->m_outputDirectory;
324 plotOpts.m_outputFile = aPlotJob->m_outputFile;
325 plotOpts.m_pageSizeSelect = pageSizeSelect;
326 plotOpts.m_plotAll = aPlotJob->m_plotAll;
327 plotOpts.m_plotDrawingSheet = aPlotJob->m_plotDrawingSheet;
328 plotOpts.m_plotPages = aPlotJob->m_plotPages;
329 plotOpts.m_theme = aPlotJob->m_theme;
330 plotOpts.m_useBackgroundColor = aPlotJob->m_useBackgroundColor;
331
332 schPlotter->Plot( format, plotOpts, renderSettings.get(), m_reporter );
333
334 return CLI::EXIT_CODES::OK;
335}
336
337
339{
340 JOB_EXPORT_SCH_NETLIST* aNetJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( aJob );
341
342 if( !aNetJob )
344
345 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
346
347 if( !sch )
349
350 // Annotation warning check
351 SCH_REFERENCE_LIST referenceList;
352 sch->Hierarchy().GetSymbols( referenceList );
353
354 if( referenceList.GetCount() > 0 )
355 {
356 if( referenceList.CheckAnnotation(
357 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
358 {
359 // We're only interested in the end result -- either errors or not
360 } )
361 > 0 )
362 {
363 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
364 "schematic editor to fix them\n" ),
366 }
367 }
368
369 // Test duplicate sheet names:
370 ERC_TESTER erc( sch );
371
372 if( erc.TestDuplicateSheetNames( false ) > 0 )
373 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
374
375 std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
376 unsigned netlistOption = 0;
377
378 wxString fileExt;
379
380 switch( aNetJob->format )
381 {
384 helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
385 break;
386
389 helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
390 break;
391
394 helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
395 break;
396
400 helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
401 break;
402
405 helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
406 break;
407
409 fileExt = wxS( "xml" );
410 helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
411 break;
412
414 fileExt = wxS( "asc" );
415 helper = std::make_unique<NETLIST_EXPORTER_PADS>( sch );
416 break;
417
419 fileExt = wxS( "txt" );
420 helper = std::make_unique<NETLIST_EXPORTER_ALLEGRO>( sch );
421 break;
422
423 default:
424 m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR );
426 }
427
428 if( aNetJob->GetOutputPath().IsEmpty() )
429 {
430 wxFileName fn = sch->GetFileName();
431 fn.SetName( fn.GetName() );
432 fn.SetExt( fileExt );
433
434 aNetJob->SetOutputPath( fn.GetFullName() );
435 }
436
437 bool res = helper->WriteNetlist( aNetJob->GetOutputPath(), netlistOption, *m_reporter );
438
439 if( !res )
441
442 return CLI::EXIT_CODES::OK;
443}
444
445
447{
448 JOB_EXPORT_SCH_BOM* aBomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( aJob );
449
450 if( !aBomJob )
452
453 SCHEMATIC* sch = getSchematic( aBomJob->m_filename );
454
455 if( !sch )
457
458 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
459
460 // Annotation warning check
461 SCH_REFERENCE_LIST referenceList;
462 sch->Hierarchy().GetSymbols( referenceList, false, false );
463
464 if( referenceList.GetCount() > 0 )
465 {
466 SCH_REFERENCE_LIST copy = referenceList;
467
468 // Check annotation splits references...
469 if( copy.CheckAnnotation(
470 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
471 {
472 // We're only interested in the end result -- either errors or not
473 } )
474 > 0 )
475 {
477 _( "Warning: schematic has annotation errors, please use the schematic "
478 "editor to fix them\n" ),
480 }
481 }
482
483 // Test duplicate sheet names:
484 ERC_TESTER erc( sch );
485
486 if( erc.TestDuplicateSheetNames( false ) > 0 )
487 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
488
489 // Build our data model
490 FIELDS_EDITOR_GRID_DATA_MODEL dataModel( referenceList );
491
492 // Mandatory fields + quantity virtual field first
493 for( int i = 0; i < MANDATORY_FIELDS; ++i )
495 TEMPLATE_FIELDNAME::GetDefaultFieldName( i, true ), false );
496
497 // User field names in symbols second
498 std::set<wxString> userFieldNames;
499
500 for( size_t i = 0; i < referenceList.GetCount(); ++i )
501 {
502 SCH_SYMBOL* symbol = referenceList[i].GetSymbol();
503
504 for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j )
505 userFieldNames.insert( symbol->GetFields()[j].GetName() );
506 }
507
508 for( const wxString& fieldName : userFieldNames )
509 dataModel.AddColumn( fieldName, GetTextVars( fieldName ), true );
510
511 // Add any templateFieldNames which aren't already present in the userFieldNames
512 for( const TEMPLATE_FIELDNAME& templateFieldname :
514 {
515 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
516 {
517 dataModel.AddColumn( templateFieldname.m_Name, GetTextVars( templateFieldname.m_Name ),
518 false );
519 }
520 }
521
522 BOM_PRESET preset;
523
524 // Load a preset if one is specified
525 if( !aBomJob->m_bomPresetName.IsEmpty() )
526 {
527 // Make sure the built-in presets are loaded
528 for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
529 sch->Settings().m_BomPresets.emplace_back( p );
530
531 // Find the preset
532 BOM_PRESET* schPreset = nullptr;
533
534 for( BOM_PRESET& p : sch->Settings().m_BomPresets )
535 {
536 if( p.name == aBomJob->m_bomPresetName )
537 {
538 schPreset = &p;
539 break;
540 }
541 }
542
543 if( !schPreset )
544 {
545 m_reporter->Report( wxString::Format( _( "BOM preset '%s' not found" ) + wxS( "\n" ),
546 aBomJob->m_bomPresetName ),
548
550 }
551
552 preset = *schPreset;
553 }
554 else
555 {
556 size_t i = 0;
557
558 for( wxString fieldName : aBomJob->m_fieldsOrdered )
559 {
560 // Handle wildcard. We allow the wildcard anywhere in the list, but it needs to respect
561 // fields that come before and after the wildcard.
562 if( fieldName == wxS( "*" ) )
563 {
564 for( const BOM_FIELD& modelField : dataModel.GetFieldsOrdered() )
565 {
566 struct BOM_FIELD field;
567
568 field.name = modelField.name;
569 field.show = true;
570 field.groupBy = false;
571 field.label = field.name;
572
573 bool fieldAlreadyPresent = false;
574 for( BOM_FIELD& presetField : preset.fieldsOrdered )
575 {
576 if( presetField.name == field.name )
577 {
578 fieldAlreadyPresent = true;
579 break;
580 }
581 }
582
583 bool fieldLaterInList = false;
584 for( const wxString& fieldInList : aBomJob->m_fieldsOrdered )
585 {
586 if( fieldInList == field.name )
587 {
588 fieldLaterInList = true;
589 break;
590 }
591 }
592
593 if( !fieldAlreadyPresent && !fieldLaterInList )
594 preset.fieldsOrdered.emplace_back( field );
595 }
596
597 continue;
598 }
599
600 struct BOM_FIELD field;
601
602 field.name = fieldName;
603 field.show = true;
604 field.groupBy = std::find( aBomJob->m_fieldsGroupBy.begin(),
605 aBomJob->m_fieldsGroupBy.end(), field.name )
606 != aBomJob->m_fieldsGroupBy.end();
607
608 if( ( aBomJob->m_fieldsLabels.size() > i ) && !aBomJob->m_fieldsLabels[i].IsEmpty() )
609 field.label = aBomJob->m_fieldsLabels[i];
610 else if( IsTextVar( field.name ) )
611 field.label = GetTextVars( field.name );
612 else
613 field.label = field.name;
614
615 preset.fieldsOrdered.emplace_back( field );
616 i++;
617 }
618
619 preset.sortAsc = aBomJob->m_sortAsc;
620 preset.sortField = aBomJob->m_sortField;
621 preset.filterString = aBomJob->m_filterString;
622 preset.groupSymbols = ( aBomJob->m_fieldsGroupBy.size() > 0 );
623 preset.excludeDNP = aBomJob->m_excludeDNP;
625 }
626
627 dataModel.ApplyBomPreset( preset );
628
629 if( aBomJob->GetOutputPath().IsEmpty() )
630 {
631 wxFileName fn = sch->GetFileName();
632 fn.SetName( fn.GetName() );
633 fn.SetExt( FILEEXT::CsvFileExtension );
634
635 aBomJob->SetOutputPath( fn.GetFullName() );
636 }
637
638 wxFile f;
639
640 if( !f.Open( aBomJob->GetOutputPath(), wxFile::write ) )
641 {
642 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ),
643 aBomJob->GetOutputPath() ),
645
647 }
648
649 BOM_FMT_PRESET fmt;
650
651 // Load a format preset if one is specified
652 if( !aBomJob->m_bomFmtPresetName.IsEmpty() )
653 {
654 // Make sure the built-in presets are loaded
656 sch->Settings().m_BomFmtPresets.emplace_back( p );
657
658 // Find the preset
659 BOM_FMT_PRESET* schFmtPreset = nullptr;
660
661 for( BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
662 {
663 if( p.name == aBomJob->m_bomFmtPresetName )
664 {
665 schFmtPreset = &p;
666 break;
667 }
668 }
669
670 if( !schFmtPreset )
671 {
673 wxString::Format( _( "BOM format preset '%s' not found" ) + wxS( "\n" ),
674 aBomJob->m_bomFmtPresetName ),
676
678 }
679
680 fmt = *schFmtPreset;
681 }
682 else
683 {
684 fmt.fieldDelimiter = aBomJob->m_fieldDelimiter;
685 fmt.stringDelimiter = aBomJob->m_stringDelimiter;
686 fmt.refDelimiter = aBomJob->m_refDelimiter;
688 fmt.keepTabs = aBomJob->m_keepTabs;
689 fmt.keepLineBreaks = aBomJob->m_keepLineBreaks;
690 }
691
692 bool res = f.Write( dataModel.Export( fmt ) );
693
694 if( !res )
696
697 return CLI::EXIT_CODES::OK;
698}
699
700
702{
703 JOB_EXPORT_SCH_PYTHONBOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_PYTHONBOM*>( aJob );
704
705 if( !aNetJob )
707
708 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
709
710 if( !sch )
712
713 // Annotation warning check
714 SCH_REFERENCE_LIST referenceList;
715 sch->Hierarchy().GetSymbols( referenceList );
716
717 if( referenceList.GetCount() > 0 )
718 {
719 if( referenceList.CheckAnnotation(
720 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
721 {
722 // We're only interested in the end result -- either errors or not
723 } )
724 > 0 )
725 {
727 _( "Warning: schematic has annotation errors, please use the schematic "
728 "editor to fix them\n" ),
730 }
731 }
732
733 // Test duplicate sheet names:
734 ERC_TESTER erc( sch );
735
736 if( erc.TestDuplicateSheetNames( false ) > 0 )
737 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
738
739 std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
740 std::make_unique<NETLIST_EXPORTER_XML>( sch );
741
742 if( aNetJob->GetOutputPath().IsEmpty() )
743 {
744 wxFileName fn = sch->GetFileName();
745 fn.SetName( fn.GetName() + "-bom" );
746 fn.SetExt( FILEEXT::XmlFileExtension );
747
748 aNetJob->SetOutputPath( fn.GetFullName() );
749 }
750
751 bool res = xmlNetlist->WriteNetlist( aNetJob->GetOutputPath(), GNL_OPT_BOM, *m_reporter );
752
753 if( !res )
755
756 return CLI::EXIT_CODES::OK;
757}
758
759
761 SCH_RENDER_SETTINGS* aRenderSettings,
762 LIB_SYMBOL* symbol )
763{
764 wxASSERT( symbol != nullptr );
765
766 if( symbol == nullptr )
768
769 LIB_SYMBOL* symbolToPlot = symbol;
770
771 // if the symbol is an alias, then the draw items are stored in the root symbol
772 if( symbol->IsAlias() )
773 {
774 if( LIB_SYMBOL_SPTR parent = symbol->GetRootSymbol() )
775 {
776 symbolToPlot = parent.get();
777 }
778 else
779 {
780 wxCHECK( false, CLI::EXIT_CODES::ERR_UNKNOWN );
781 }
782 }
783
784 // iterate from unit 1, unit 0 would be "all units" which we don't want
785 for( int unit = 1; unit < symbol->GetUnitCount() + 1; unit++ )
786 {
787 for( int bodyStyle = 1; bodyStyle < ( symbol->HasAlternateBodyStyle() ? 2 : 1 ) + 1; ++bodyStyle )
788 {
789 wxString filename;
790 wxFileName fn;
791 size_t forbidden_char;
792
793 fn.SetPath( aSvgJob->m_outputDirectory );
794 fn.SetExt( FILEEXT::SVGFileExtension );
795
796 filename = symbol->GetName().Lower();
797
798 while( wxString::npos
799 != ( forbidden_char = filename.find_first_of(
800 wxFileName::GetForbiddenChars( wxPATH_DOS ) ) ) )
801 {
802 filename = filename.replace( forbidden_char, 1, wxS( '_' ) );
803 }
804
805 //simplify the name if its single unit
806 if( symbol->GetUnitCount() > 1 )
807 {
808 filename += wxString::Format( "_%d", unit );
809
810 if( bodyStyle == 2 )
811 filename += wxS( "_demorgan" );
812
813 fn.SetName( filename );
814 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ),
815 symbol->GetName(), unit, fn.GetFullPath() ),
817 }
818 else
819 {
820 if( bodyStyle == 2 )
821 filename += wxS( "_demorgan" );
822
823 fn.SetName( filename );
824 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' to '%s'\n" ),
825 symbol->GetName(), fn.GetFullPath() ),
827 }
828
829 // Get the symbol bounding box to fit the plot page to it
830 BOX2I symbolBB = symbol->Flatten()->GetUnitBoundingBox( unit, bodyStyle, !aSvgJob->m_includeHiddenFields );
831 PAGE_INFO pageInfo( PAGE_INFO::Custom );
832 pageInfo.SetHeightMils( schIUScale.IUToMils( symbolBB.GetHeight() * 1.2 ) );
833 pageInfo.SetWidthMils( schIUScale.IUToMils( symbolBB.GetWidth() * 1.2 ) );
834
835 SVG_PLOTTER* plotter = new SVG_PLOTTER();
836 plotter->SetRenderSettings( aRenderSettings );
837 plotter->SetPageSettings( pageInfo );
838 plotter->SetColorMode( !aSvgJob->m_blackAndWhite );
839
840 VECTOR2I plot_offset = symbolBB.GetCenter();
841 const double scale = 1.0;
842
843 // Currently, plot units are in decimal
844 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
845
846 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
847
848 if( !plotter->OpenFile( fn.GetFullPath() ) )
849 {
851 wxString::Format( _( "Unable to open destination '%s'" ) + wxS( "\n" ),
852 fn.GetFullPath() ),
854
855 delete plotter;
857 }
858
859 LOCALE_IO toggle;
860 SCH_PLOT_OPTS plotOpts;
861
862 plotter->StartPlot( wxT( "1" ) );
863
864 bool background = true;
865 VECTOR2I offset( pageInfo.GetWidthIU( schIUScale.IU_PER_MILS ) / 2,
866 pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) / 2 );
867
868 // note, we want the fields from the original symbol pointer (in case of non-alias)
869 symbolToPlot->Plot( plotter, background, plotOpts, unit, bodyStyle, offset, false );
870 symbol->PlotFields( plotter, background, plotOpts, unit, bodyStyle, offset, false );
871
872 symbolToPlot->Plot( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
873 symbol->PlotFields( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
874
875 plotter->EndPlot();
876 delete plotter;
877 }
878 }
879
880 return CLI::EXIT_CODES::OK;
881}
882
883
885{
886 JOB_SYM_EXPORT_SVG* svgJob = dynamic_cast<JOB_SYM_EXPORT_SVG*>( aJob );
887
888 if( !svgJob )
890
891 wxFileName fn( svgJob->m_libraryPath );
892 fn.MakeAbsolute();
893
894 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
895
896 try
897 {
898 schLibrary.Load();
899 }
900 catch( ... )
901 {
902 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
904 }
905
906 LIB_SYMBOL* symbol = nullptr;
907
908 if( !svgJob->m_symbol.IsEmpty() )
909 {
910 // See if the selected symbol exists
911 symbol = schLibrary.GetSymbol( svgJob->m_symbol );
912
913 if( !symbol )
914 {
915 m_reporter->Report( _( "There is no symbol selected to save." ) + wxS( "\n" ),
918 }
919 }
920
921 if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) )
922 {
923 wxFileName::Mkdir( svgJob->m_outputDirectory );
924 }
925
926 SCH_RENDER_SETTINGS renderSettings;
928 renderSettings.LoadColors( cs );
930 renderSettings.m_ShowHiddenPins = svgJob->m_includeHiddenPins;
931 renderSettings.m_ShowHiddenFields = svgJob->m_includeHiddenFields;
932
933 int exitCode = CLI::EXIT_CODES::OK;
934
935 if( symbol )
936 {
937 exitCode = doSymExportSvg( svgJob, &renderSettings, symbol );
938 }
939 else
940 {
941 // Just plot all the symbols we can
942 const LIB_SYMBOL_MAP& libSymMap = schLibrary.GetSymbolMap();
943
944 for( const std::pair<const wxString, LIB_SYMBOL*>& entry : libSymMap )
945 {
946 exitCode = doSymExportSvg( svgJob, &renderSettings, entry.second );
947
948 if( exitCode != CLI::EXIT_CODES::OK )
949 break;
950 }
951 }
952
953 return exitCode;
954}
955
956
958{
959 JOB_SYM_UPGRADE* upgradeJob = dynamic_cast<JOB_SYM_UPGRADE*>( aJob );
960
961 if( !upgradeJob )
963
964 wxFileName fn( upgradeJob->m_libraryPath );
965 fn.MakeAbsolute();
966
967 SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
968
969 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
970 {
971 if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) )
972 {
973 m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
975
977 }
978 }
979 else if( fileType != SCH_IO_MGR::SCH_KICAD )
980 {
981 m_reporter->Report( _( "Output path must be specified to convert legacy and non-KiCad libraries\n" ),
983
985 }
986
987 if( fileType == SCH_IO_MGR::SCH_KICAD )
988 {
989 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
990
991 try
992 {
993 schLibrary.Load();
994 }
995 catch( ... )
996 {
997 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
999 }
1000
1001 bool shouldSave =
1002 upgradeJob->m_force
1004
1005 if( shouldSave )
1006 {
1007 m_reporter->Report( _( "Saving symbol library in updated format\n" ),
1009
1010 try
1011 {
1012 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1013 {
1014 schLibrary.SetFileName( upgradeJob->m_outputLibraryPath );
1015 }
1016
1017 schLibrary.SetModified();
1018 schLibrary.Save();
1019 }
1020 catch( ... )
1021 {
1022 m_reporter->Report( ( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
1024 }
1025 }
1026 else
1027 {
1028 m_reporter->Report( _( "Symbol library was not updated\n" ), RPT_SEVERITY_INFO );
1029 }
1030 }
1031 else
1032 {
1033 if( !SCH_IO_MGR::ConvertLibrary( nullptr, fn.GetAbsolutePath(), upgradeJob->m_outputLibraryPath ) )
1034 {
1035 m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR );
1037 }
1038 }
1039
1040 return CLI::EXIT_CODES::OK;
1041}
1042
1043
1044
1046{
1047 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( aJob );
1048
1049 if( !ercJob )
1051
1052 SCHEMATIC* sch = getSchematic( ercJob->m_filename );
1053
1054 if( !sch )
1056
1057 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
1058
1059 if( ercJob->m_outputFile.IsEmpty() )
1060 {
1061 wxFileName fn = sch->GetFileName();
1062 fn.SetName( fn.GetName() );
1063
1065 fn.SetExt( FILEEXT::JsonFileExtension );
1066 else
1067 fn.SetExt( FILEEXT::ReportFileExtension );
1068
1069 ercJob->m_outputFile = fn.GetFullName();
1070 }
1071
1072 EDA_UNITS units;
1073
1074 switch( ercJob->m_units )
1075 {
1076 case JOB_SCH_ERC::UNITS::INCHES: units = EDA_UNITS::INCHES; break;
1077 case JOB_SCH_ERC::UNITS::MILS: units = EDA_UNITS::MILS; break;
1078 case JOB_SCH_ERC::UNITS::MILLIMETERS: units = EDA_UNITS::MILLIMETRES; break;
1079 default: units = EDA_UNITS::MILLIMETRES; break;
1080 }
1081
1082 std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
1083 std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
1084
1085 ERC_TESTER ercTester( sch );
1086
1087 m_reporter->Report( _( "Running ERC...\n" ), RPT_SEVERITY_INFO );
1088
1089 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet( getDrawingSheetProxyView( sch ) );
1090 ercTester.RunTests( drawingSheet.get(), nullptr, m_kiway->KiFACE( KIWAY::FACE_CVPCB ),
1091 &sch->Prj(), m_progressReporter );
1092
1093 markersProvider->SetSeverities( ercJob->m_severity );
1094
1095 m_reporter->Report( wxString::Format( _( "Found %d violations\n" ),
1096 markersProvider->GetCount() ),
1098
1099 ERC_REPORT reportWriter( sch, units );
1100
1101 bool wroteReport = false;
1102
1104 wroteReport = reportWriter.WriteJsonReport( ercJob->m_outputFile );
1105 else
1106 wroteReport = reportWriter.WriteTextReport( ercJob->m_outputFile );
1107
1108 if( !wroteReport )
1109 {
1110 m_reporter->Report( wxString::Format( _( "Unable to save ERC report to %s\n" ),
1111 ercJob->m_outputFile ),
1114 }
1115
1116 m_reporter->Report( wxString::Format( _( "Saved ERC Report to %s\n" ), ercJob->m_outputFile ),
1118
1119 if( ercJob->m_exitCodeViolations )
1120 {
1121 if( markersProvider->GetCount() > 0 )
1123 }
1124
1126}
1127
1128
1130{
1131 DS_PROXY_VIEW_ITEM* drawingSheet =
1133 &aSch->Prj(), &aSch->RootScreen()->GetTitleBlock(),
1134 aSch->GetProperties() );
1135
1136 drawingSheet->SetPageNumber( TO_UTF8( aSch->RootScreen()->GetPageNumber() ) );
1137 drawingSheet->SetSheetCount( aSch->RootScreen()->GetPageCount() );
1138 drawingSheet->SetFileName( TO_UTF8( aSch->RootScreen()->GetFileName() ) );
1141 drawingSheet->SetIsFirstPage( aSch->RootScreen()->GetVirtualPageNumber() == 1 );
1142
1143 drawingSheet->SetSheetName( "" );
1144 drawingSheet->SetSheetPath( "" );
1145
1146 return drawingSheet;
1147}
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:1627
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:648
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:690
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:261
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition: page_info.h:153
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:247
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:308
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:314
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:860
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.
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.