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 The 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>
32#include <jobs/job_sch_erc.h>
36#include <schematic.h>
37#include <schematic_settings.h>
38#include <wx/dir.h>
39#include <wx/file.h>
40#include <memory>
41#include <connection_graph.h>
42#include "eeschema_helpers.h"
43#include <filename_resolver.h>
44#include <kiway.h>
45#include <sch_painter.h>
46#include <locale_io.h>
47#include <erc/erc.h>
48#include <erc/erc_report.h>
52#include <paths.h>
53#include <reporter.h>
54#include <string_utils.h>
55
57
58#include <sch_file_versions.h>
59#include <sch_io/sch_io.h>
61
62#include <netlist.h>
72
73#include <fields_data_model.h>
74
79#include <confirm.h>
80
81
83 JOB_DISPATCHER( aKiway ),
84 m_cliSchematic( nullptr )
85{
86 Register( "bom",
87 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ),
88 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
89 {
90 JOB_EXPORT_SCH_BOM* bomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( job );
91
92 SCH_EDIT_FRAME* editFrame =
93 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
94
95 wxCHECK( bomJob && editFrame, false );
96
97 DIALOG_SYMBOL_FIELDS_TABLE dlg( editFrame, bomJob );
98 return dlg.ShowModal() == wxID_OK;
99 } );
100 Register( "pythonbom",
101 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, this, std::placeholders::_1 ),
102 []( JOB* job, wxWindow* aParent ) -> bool
103 {
104 return true;
105 } );
106 Register( "netlist",
107 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ),
108 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
109 {
110 JOB_EXPORT_SCH_NETLIST* netJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( job );
111
112 SCH_EDIT_FRAME* editFrame =
113 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
114
115 wxCHECK( netJob && editFrame, false );
116
117 DIALOG_EXPORT_NETLIST dlg( editFrame, aParent, netJob );
118 return dlg.ShowModal() == wxID_OK;
119 } );
120 Register( "plot",
121 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPlot, this, std::placeholders::_1 ),
122 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
123 {
124 JOB_EXPORT_SCH_PLOT* plotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( job );
125
126 SCH_EDIT_FRAME* editFrame =
127 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
128
129 wxCHECK( plotJob && editFrame, false );
130
131 if( plotJob->m_plotFormat == SCH_PLOT_FORMAT::HPGL )
132 {
133 DisplayErrorMessage( editFrame,
134 _( "Plotting to HPGL is no longer supported as of KiCad 10.0." ) );
135 return false;
136 }
137
138 DIALOG_PLOT_SCHEMATIC dlg( editFrame, aParent, plotJob );
139 return dlg.ShowModal() == wxID_OK;
140 } );
141 Register( "symupgrade",
142 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymUpgrade, this, std::placeholders::_1 ),
143 []( JOB* job, wxWindow* aParent ) -> bool
144 {
145 return true;
146 } );
147 Register( "symsvg",
148 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymExportSvg, this, std::placeholders::_1 ),
149 []( JOB* job, wxWindow* aParent ) -> bool
150 {
151 return true;
152 } );
153 Register( "erc", std::bind( &EESCHEMA_JOBS_HANDLER::JobSchErc, this, std::placeholders::_1 ),
154 []( JOB* job, wxWindow* aParent ) -> bool
155 {
156 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( job );
157
158 wxCHECK( ercJob, false );
159
160 DIALOG_ERC_JOB_CONFIG dlg( aParent, ercJob );
161 return dlg.ShowModal() == wxID_OK;
162 } );
163 Register( "upgrade", std::bind( &EESCHEMA_JOBS_HANDLER::JobUpgrade, this, std::placeholders::_1 ),
164 []( JOB* job, wxWindow* aParent ) -> bool
165 {
166 return true;
167 } );
168}
169
170
172{
173 SCHEMATIC* sch = nullptr;
174
175 if( !Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpenNotDummy() )
176 {
178 wxString schPath = aPath;
179
180 if( schPath.IsEmpty() )
181 {
182 wxFileName path = project.GetProjectFullName();
184 path.MakeAbsolute();
185 schPath = path.GetFullPath();
186 }
187
188 if( !m_cliSchematic )
189 m_cliSchematic = EESCHEMA_HELPERS::LoadSchematic( schPath, true, false, &project );
190
191 sch = m_cliSchematic;
192 }
193 else if( Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpen() )
194 {
195 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_kiway->Player( FRAME_SCH, false ) );
196
197 if( editFrame )
198 sch = &editFrame->Schematic();
199 }
200 else if( !aPath.IsEmpty() )
201 {
202 sch = EESCHEMA_HELPERS::LoadSchematic( aPath, true, false );
203 }
204
205 if( !sch )
206 m_reporter->Report( _( "Failed to load schematic\n" ), RPT_SEVERITY_ERROR );
207
208 return sch;
209}
210
212 const wxString& aTheme, SCHEMATIC* aSch,
213 const wxString& aDrawingSheetOverride )
214{
215 COLOR_SETTINGS* cs = ::GetColorSettings( aTheme );
216 aRenderSettings->LoadColors( cs );
217 aRenderSettings->m_ShowHiddenPins = false;
218 aRenderSettings->m_ShowHiddenFields = false;
219 aRenderSettings->m_ShowPinAltIcons = false;
220
221 aRenderSettings->SetDefaultPenWidth( aSch->Settings().m_DefaultLineWidth );
222 aRenderSettings->m_LabelSizeRatio = aSch->Settings().m_LabelSizeRatio;
223 aRenderSettings->m_TextOffsetRatio = aSch->Settings().m_TextOffsetRatio;
224 aRenderSettings->m_PinSymbolSize = aSch->Settings().m_PinSymbolSize;
225
226 aRenderSettings->SetDashLengthRatio( aSch->Settings().m_DashedLineDashRatio );
227 aRenderSettings->SetGapLengthRatio( aSch->Settings().m_DashedLineGapRatio );
228
229 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
230 // If empty, or not existing, the default drawing sheet is loaded.
231
232 auto loadSheet =
233 [&]( const wxString& path ) -> bool
234 {
235 wxString msg;
236 FILENAME_RESOLVER resolve;
237 resolve.SetProject( &aSch->Project() );
238 resolve.SetProgramBase( &Pgm() );
239
240 wxString absolutePath = resolve.ResolvePath( path, wxGetCwd(),
241 { aSch->GetEmbeddedFiles() } );
242
243 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath, &msg ) )
244 {
245 m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ), path )
246 + wxS( "\n" ) + msg + wxS( "\n" ),
248 return false;
249 }
250
251 return true;
252 };
253
254 // try to load the override first
255 if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
256 return;
257
258 // no override or failed override continues here
259 loadSheet( aSch->Settings().m_SchDrawingSheetFileName );
260}
261
262
264{
265 JOB_EXPORT_SCH_PLOT* aPlotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( aJob );
266
267 wxCHECK( aPlotJob, CLI::EXIT_CODES::ERR_UNKNOWN );
268
269 if( aPlotJob->m_plotFormat == SCH_PLOT_FORMAT::HPGL )
270 {
271 m_reporter->Report( _( "Plotting to HPGL is no longer supported as of KiCad 10.0.\n" ),
274 }
275
276 SCHEMATIC* sch = getSchematic( aPlotJob->m_filename );
277
278 if( !sch )
280
281 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
282 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
283
284 std::unique_ptr<SCH_RENDER_SETTINGS> renderSettings = std::make_unique<SCH_RENDER_SETTINGS>();
285 InitRenderSettings( renderSettings.get(), aPlotJob->m_theme, sch, aPlotJob->m_drawingSheet );
286
287 wxString font = aPlotJob->m_defaultFont;
288
289 if( font.IsEmpty() )
290 {
292 font = cfg ? cfg->m_Appearance.default_font : wxString( KICAD_FONT_NAME );
293 }
294
295 renderSettings->SetDefaultFont( font );
296 renderSettings->SetMinPenWidth( aPlotJob->m_minPenWidth );
297
298 std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
299
301
302 switch( aPlotJob->m_plotFormat )
303 {
304 case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF; break;
305 case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF; break;
306 case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG; break;
307 case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST; break;
308 case SCH_PLOT_FORMAT::HPGL: /* no longer supported */ break;
309 }
310
311 int pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
312
313 switch( aPlotJob->m_pageSizeSelect )
314 {
315 case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A; break;
316 case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4; break;
318 }
319
320 wxString outPath = aPlotJob->GetFullOutputPath( &sch->Project() );
321
322 if( !PATHS::EnsurePathExists( outPath, !aPlotJob->GetOutputPathIsDirectory() ) )
323 {
324 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
326 }
327
328 SCH_PLOT_OPTS plotOpts;
329 plotOpts.m_blackAndWhite = aPlotJob->m_blackAndWhite;
330 plotOpts.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups;
332 plotOpts.m_PDFMetadata = aPlotJob->m_PDFMetadata;
333
334 if( aPlotJob->GetOutputPathIsDirectory() )
335 {
336 plotOpts.m_outputDirectory = outPath;
337 plotOpts.m_outputFile = wxEmptyString;
338 }
339 else
340 {
341 plotOpts.m_outputDirectory = wxEmptyString;
342 plotOpts.m_outputFile = outPath;
343 }
344
345 plotOpts.m_pageSizeSelect = pageSizeSelect;
346 plotOpts.m_plotAll = aPlotJob->m_plotAll;
347 plotOpts.m_plotDrawingSheet = aPlotJob->m_plotDrawingSheet;
348 plotOpts.m_plotPages = aPlotJob->m_plotPages;
349 plotOpts.m_theme = aPlotJob->m_theme;
350 plotOpts.m_useBackgroundColor = aPlotJob->m_useBackgroundColor;
351 plotOpts.m_plotHopOver = aPlotJob->m_show_hop_over;
352
353 // Always export dxf in mm by kicad-cli (similar to Pcbnew)
355
356 schPlotter->Plot( format, plotOpts, renderSettings.get(), m_reporter );
357
358 if( m_reporter->HasMessageOfSeverity( RPT_SEVERITY_ERROR ) )
360
361 return CLI::EXIT_CODES::OK;
362}
363
364
366{
367 JOB_EXPORT_SCH_NETLIST* aNetJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( aJob );
368
369 wxCHECK( aNetJob, CLI::EXIT_CODES::ERR_UNKNOWN );
370
371 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
372
373 if( !sch )
375
376 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
377 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
378
379 // Annotation warning check
380 SCH_REFERENCE_LIST referenceList;
381 sch->Hierarchy().GetSymbols( referenceList );
382
383 if( referenceList.GetCount() > 0 )
384 {
385 if( referenceList.CheckAnnotation(
386 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
387 {
388 // We're only interested in the end result -- either errors or not
389 } )
390 > 0 )
391 {
392 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
393 "schematic editor to fix them\n" ),
395 }
396 }
397
398 // Test duplicate sheet names:
399 ERC_TESTER erc( sch );
400
401 if( erc.TestDuplicateSheetNames( false ) > 0 )
402 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
403
404 std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
405 unsigned netlistOption = 0;
406
407 wxString fileExt;
408
409 switch( aNetJob->format )
410 {
413 helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
414 break;
415
418 helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
419 break;
420
423 helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
424 break;
425
429 helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
430 break;
431
434 helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
435 break;
436
438 fileExt = wxS( "xml" );
439 helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
440 break;
441
443 fileExt = wxS( "asc" );
444 helper = std::make_unique<NETLIST_EXPORTER_PADS>( sch );
445 break;
446
448 fileExt = wxS( "txt" );
449 helper = std::make_unique<NETLIST_EXPORTER_ALLEGRO>( sch );
450 break;
451
452 default:
453 m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR );
455 }
456
457 if( aNetJob->GetConfiguredOutputPath().IsEmpty() )
458 {
459 wxFileName fn = sch->GetFileName();
460 fn.SetName( fn.GetName() );
461 fn.SetExt( fileExt );
462
463 aNetJob->SetConfiguredOutputPath( fn.GetFullName() );
464 }
465
466 wxString outPath = aNetJob->GetFullOutputPath( &sch->Project() );
467
468 if( !PATHS::EnsurePathExists( outPath, true ) )
469 {
470 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
472 }
473
474 bool res = helper->WriteNetlist( outPath, netlistOption, *m_reporter );
475
476 if( !res )
478
479 return CLI::EXIT_CODES::OK;
480}
481
482
484{
485 JOB_EXPORT_SCH_BOM* aBomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( aJob );
486
487 wxCHECK( aBomJob, CLI::EXIT_CODES::ERR_UNKNOWN );
488
489 SCHEMATIC* sch = getSchematic( aBomJob->m_filename );
490
491 if( !sch )
493
494 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
495 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
496
497 // Annotation warning check
498 SCH_REFERENCE_LIST referenceList;
499 sch->Hierarchy().GetSymbols( referenceList, false, false );
500
501 if( referenceList.GetCount() > 0 )
502 {
503 SCH_REFERENCE_LIST copy = referenceList;
504
505 // Check annotation splits references...
506 if( copy.CheckAnnotation(
507 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
508 {
509 // We're only interested in the end result -- either errors or not
510 } )
511 > 0 )
512 {
513 m_reporter->Report(
514 _( "Warning: schematic has annotation errors, please use the schematic "
515 "editor to fix them\n" ),
517 }
518 }
519
520 // Test duplicate sheet names:
521 ERC_TESTER erc( sch );
522
523 if( erc.TestDuplicateSheetNames( false ) > 0 )
524 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
525
526 // Build our data model
527 FIELDS_EDITOR_GRID_DATA_MODEL dataModel( referenceList, nullptr );
528
529 // Mandatory fields + quantity virtual field first
530 for( FIELD_T fieldId : MANDATORY_FIELDS )
531 {
532 dataModel.AddColumn( GetCanonicalFieldName( fieldId ),
533 GetDefaultFieldName( fieldId, DO_TRANSLATE ), false );
534 }
535
536 // User field names in symbols second
537 std::set<wxString> userFieldNames;
538
539 for( size_t i = 0; i < referenceList.GetCount(); ++i )
540 {
541 SCH_SYMBOL* symbol = referenceList[i].GetSymbol();
542
543 for( SCH_FIELD& field : symbol->GetFields() )
544 {
545 if( !field.IsMandatory() && !field.IsPrivate() )
546 userFieldNames.insert( field.GetName() );
547 }
548 }
549
550 for( const wxString& fieldName : userFieldNames )
551 dataModel.AddColumn( fieldName, GetGeneratedFieldDisplayName( fieldName ), true );
552
553 // Add any templateFieldNames which aren't already present in the userFieldNames
554 for( const TEMPLATE_FIELDNAME& templateFieldname :
556 {
557 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
558 {
559 dataModel.AddColumn( templateFieldname.m_Name, GetGeneratedFieldDisplayName( templateFieldname.m_Name ),
560 false );
561 }
562 }
563
564 BOM_PRESET preset;
565
566 // Load a preset if one is specified
567 if( !aBomJob->m_bomPresetName.IsEmpty() )
568 {
569 // Find the preset
570 const BOM_PRESET* schPreset = nullptr;
571
572 for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
573 {
574 if( p.name == aBomJob->m_bomPresetName )
575 {
576 schPreset = &p;
577 break;
578 }
579 }
580
581 for( const BOM_PRESET& p : sch->Settings().m_BomPresets )
582 {
583 if( p.name == aBomJob->m_bomPresetName )
584 {
585 schPreset = &p;
586 break;
587 }
588 }
589
590 if( !schPreset )
591 {
592 m_reporter->Report( wxString::Format( _( "BOM preset '%s' not found" ) + wxS( "\n" ),
593 aBomJob->m_bomPresetName ),
595
597 }
598
599 preset = *schPreset;
600 }
601 else
602 {
603 size_t i = 0;
604
605 for( const wxString& fieldName : aBomJob->m_fieldsOrdered )
606 {
607 // Handle wildcard. We allow the wildcard anywhere in the list, but it needs to respect
608 // fields that come before and after the wildcard.
609 if( fieldName == wxS( "*" ) )
610 {
611 for( const BOM_FIELD& modelField : dataModel.GetFieldsOrdered() )
612 {
613 struct BOM_FIELD field;
614
615 field.name = modelField.name;
616 field.show = true;
617 field.groupBy = false;
618 field.label = field.name;
619
620 bool fieldAlreadyPresent = false;
621
622 for( BOM_FIELD& presetField : preset.fieldsOrdered )
623 {
624 if( presetField.name == field.name )
625 {
626 fieldAlreadyPresent = true;
627 break;
628 }
629 }
630
631 bool fieldLaterInList = false;
632
633 for( const wxString& fieldInList : aBomJob->m_fieldsOrdered )
634 {
635 if( fieldInList == field.name )
636 {
637 fieldLaterInList = true;
638 break;
639 }
640 }
641
642 if( !fieldAlreadyPresent && !fieldLaterInList )
643 preset.fieldsOrdered.emplace_back( field );
644 }
645
646 continue;
647 }
648
649 struct BOM_FIELD field;
650
651 field.name = fieldName;
652 field.show = !fieldName.StartsWith( wxT( "__" ), &field.name );
653 field.groupBy = alg::contains( aBomJob->m_fieldsGroupBy, field.name );
654
655 if( ( aBomJob->m_fieldsLabels.size() > i ) && !aBomJob->m_fieldsLabels[i].IsEmpty() )
656 field.label = aBomJob->m_fieldsLabels[i];
657 else if( IsGeneratedField( field.name ) )
658 field.label = GetGeneratedFieldDisplayName( field.name );
659 else
660 field.label = field.name;
661
662 preset.fieldsOrdered.emplace_back( field );
663 i++;
664 }
665
666 preset.sortAsc = aBomJob->m_sortAsc;
667 preset.sortField = aBomJob->m_sortField;
668 preset.filterString = aBomJob->m_filterString;
669 preset.groupSymbols = ( aBomJob->m_fieldsGroupBy.size() > 0 );
670 preset.excludeDNP = aBomJob->m_excludeDNP;
671 }
672
673 dataModel.ApplyBomPreset( preset );
674
675 if( aBomJob->GetConfiguredOutputPath().IsEmpty() )
676 {
677 wxFileName fn = sch->GetFileName();
678 fn.SetName( fn.GetName() );
679 fn.SetExt( FILEEXT::CsvFileExtension );
680
681 aBomJob->SetConfiguredOutputPath( fn.GetFullName() );
682 }
683
684 wxString outPath = aBomJob->GetFullOutputPath( &sch->Project() );
685
686 if( !PATHS::EnsurePathExists( outPath, true ) )
687 {
688 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
690 }
691
692 wxFile f;
693
694 if( !f.Open( outPath, wxFile::write ) )
695 {
696 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ), outPath ),
698
700 }
701
702 BOM_FMT_PRESET fmt;
703
704 // Load a format preset if one is specified
705 if( !aBomJob->m_bomFmtPresetName.IsEmpty() )
706 {
707 // Find the preset
708 std::optional<BOM_FMT_PRESET> schFmtPreset;
709
711 {
712 if( p.name == aBomJob->m_bomFmtPresetName )
713 {
714 schFmtPreset = p;
715 break;
716 }
717 }
718
719 for( const BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
720 {
721 if( p.name == aBomJob->m_bomFmtPresetName )
722 {
723 schFmtPreset = p;
724 break;
725 }
726 }
727
728 if( !schFmtPreset )
729 {
730 m_reporter->Report( wxString::Format( _( "BOM format preset '%s' not found" ) + wxS( "\n" ),
731 aBomJob->m_bomFmtPresetName ),
733
735 }
736
737 fmt = *schFmtPreset;
738 }
739 else
740 {
741 fmt.fieldDelimiter = aBomJob->m_fieldDelimiter;
742 fmt.stringDelimiter = aBomJob->m_stringDelimiter;
743 fmt.refDelimiter = aBomJob->m_refDelimiter;
745 fmt.keepTabs = aBomJob->m_keepTabs;
746 fmt.keepLineBreaks = aBomJob->m_keepLineBreaks;
747 }
748
749 bool res = f.Write( dataModel.Export( fmt ) );
750
751 if( !res )
753
754 m_reporter->Report( wxString::Format( _( "Wrote bill of materials to '%s'." ), outPath ),
756
757 return CLI::EXIT_CODES::OK;
758}
759
760
762{
763 JOB_EXPORT_SCH_PYTHONBOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_PYTHONBOM*>( aJob );
764
765 wxCHECK( aNetJob, CLI::EXIT_CODES::ERR_UNKNOWN );
766
767 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
768
769 if( !sch )
771
772 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
773 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
774
775 // Annotation warning check
776 SCH_REFERENCE_LIST referenceList;
777 sch->Hierarchy().GetSymbols( referenceList );
778
779 if( referenceList.GetCount() > 0 )
780 {
781 if( referenceList.CheckAnnotation(
782 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
783 {
784 // We're only interested in the end result -- either errors or not
785 } )
786 > 0 )
787 {
788 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
789 "schematic editor to fix them\n" ),
791 }
792 }
793
794 // Test duplicate sheet names:
795 ERC_TESTER erc( sch );
796
797 if( erc.TestDuplicateSheetNames( false ) > 0 )
798 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
799
800 std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
801 std::make_unique<NETLIST_EXPORTER_XML>( sch );
802
803 if( aNetJob->GetConfiguredOutputPath().IsEmpty() )
804 {
805 wxFileName fn = sch->GetFileName();
806 fn.SetName( fn.GetName() + "-bom" );
807 fn.SetExt( FILEEXT::XmlFileExtension );
808
809 aNetJob->SetConfiguredOutputPath( fn.GetFullName() );
810 }
811
812 wxString outPath = aNetJob->GetFullOutputPath( &sch->Project() );
813
814 if( !PATHS::EnsurePathExists( outPath, true ) )
815 {
816 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
818 }
819
820 bool res = xmlNetlist->WriteNetlist( outPath, GNL_OPT_BOM, *m_reporter );
821
822 if( !res )
824
825 m_reporter->Report( wxString::Format( _( "Wrote bill of materials to '%s'." ), outPath ),
827
828 return CLI::EXIT_CODES::OK;
829}
830
831
833 LIB_SYMBOL* symbol )
834{
835 wxCHECK( symbol, CLI::EXIT_CODES::ERR_UNKNOWN );
836
837 LIB_SYMBOL_SPTR parent;
838 LIB_SYMBOL* symbolToPlot = symbol;
839
840 // if the symbol is an alias, then the draw items are stored in the root symbol
841 if( symbol->IsDerived() )
842 {
843 parent = symbol->GetRootSymbol();
844
845 wxCHECK( parent, CLI::EXIT_CODES::ERR_UNKNOWN );
846
847 symbolToPlot = parent.get();
848 }
849
850 // iterate from unit 1, unit 0 would be "all units" which we don't want
851 for( int unit = 1; unit < symbol->GetUnitCount() + 1; unit++ )
852 {
853 for( int bodyStyle = 1; bodyStyle <= symbol->GetBodyStyleCount(); ++bodyStyle )
854 {
855 wxString filename;
856 wxFileName fn;
857
858 fn.SetPath( aSvgJob->m_outputDirectory );
859 fn.SetExt( FILEEXT::SVGFileExtension );
860
861 filename = symbol->GetName();
862
863 for( wxChar c : wxFileName::GetForbiddenChars( wxPATH_DOS ) )
864 filename.Replace( c, ' ' );
865
866 // Even single units get a unit number in the filename. This simplifies the
867 // handling of the files as they have a uniform pattern.
868 // Also avoids aliasing 'sym', unit 2 and 'sym_unit2', unit 1 to the same file.
869 filename += wxString::Format( "_unit%d", unit );
870
871 if( symbol->HasDeMorganBodyStyles() )
872 {
873 if( bodyStyle == 2 )
874 filename += wxS( "_demorgan" );
875 }
876 else if( bodyStyle <= (int) symbol->GetBodyStyleNames().size() )
877 {
878 filename += wxS( "_" ) + symbol->GetBodyStyleNames()[bodyStyle-1].Lower();
879 }
880
881 fn.SetName( filename );
882 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ),
883 symbol->GetName(),
884 unit,
885 fn.GetFullPath() ),
887
888 // Get the symbol bounding box to fit the plot page to it
889 BOX2I symbolBB = symbol->Flatten()->GetUnitBoundingBox( unit, bodyStyle,
890 !aSvgJob->m_includeHiddenFields );
892 pageInfo.SetHeightMils( schIUScale.IUToMils( symbolBB.GetHeight() * 1.2 ) );
893 pageInfo.SetWidthMils( schIUScale.IUToMils( symbolBB.GetWidth() * 1.2 ) );
894
895 SVG_PLOTTER* plotter = new SVG_PLOTTER();
896 plotter->SetRenderSettings( aRenderSettings );
897 plotter->SetPageSettings( pageInfo );
898 plotter->SetColorMode( !aSvgJob->m_blackAndWhite );
899
900 VECTOR2I plot_offset = symbolBB.GetCenter();
901 const double scale = 1.0;
902
903 // Currently, plot units are in decimal
904 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
905
906 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
907
908 if( !plotter->OpenFile( fn.GetFullPath() ) )
909 {
910 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ) + wxS( "\n" ),
911 fn.GetFullPath() ),
913
914 delete plotter;
916 }
917
918 LOCALE_IO toggle;
919 SCH_PLOT_OPTS plotOpts;
920
921 plotter->StartPlot( wxT( "1" ) );
922
923 bool background = true;
924 VECTOR2I offset( pageInfo.GetWidthIU( schIUScale.IU_PER_MILS ) / 2,
925 pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) / 2 );
926
927 // note, we want the fields from the original symbol pointer (in case of non-alias)
928 symbolToPlot->Plot( plotter, background, plotOpts, unit, bodyStyle, offset, false );
929 symbol->PlotFields( plotter, background, plotOpts, unit, bodyStyle, offset, false );
930
931 symbolToPlot->Plot( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
932 symbol->PlotFields( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
933
934 plotter->EndPlot();
935 delete plotter;
936 }
937 }
938
939 if( m_reporter->HasMessageOfSeverity( RPT_SEVERITY_ERROR ) )
941
942 return CLI::EXIT_CODES::OK;
943}
944
945
947{
948 JOB_SYM_EXPORT_SVG* svgJob = dynamic_cast<JOB_SYM_EXPORT_SVG*>( aJob );
949
950 wxCHECK( svgJob, CLI::EXIT_CODES::ERR_UNKNOWN );
951
952 wxFileName fn( svgJob->m_libraryPath );
953 fn.MakeAbsolute();
954
955 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
956
957 try
958 {
959 schLibrary.Load();
960 }
961 catch( ... )
962 {
963 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
965 }
966
968 m_progressReporter->KeepRefreshing();
969
970 LIB_SYMBOL* symbol = nullptr;
971
972 if( !svgJob->m_symbol.IsEmpty() )
973 {
974 // See if the selected symbol exists
975 symbol = schLibrary.GetSymbol( svgJob->m_symbol );
976
977 if( !symbol )
978 {
979 m_reporter->Report( _( "There is no symbol selected to save." ) + wxS( "\n" ),
982 }
983 }
984
985 if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) )
986 {
987 if( !wxFileName::Mkdir( svgJob->m_outputDirectory ) )
988 {
989 m_reporter->Report( wxString::Format( _( "Unable to create output directory '%s'." ) + wxS( "\n" ),
990 svgJob->m_outputDirectory ),
993 }
994 }
995
996 SCH_RENDER_SETTINGS renderSettings;
998 renderSettings.LoadColors( cs );
999 renderSettings.SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS );
1000 renderSettings.m_ShowHiddenPins = svgJob->m_includeHiddenPins;
1001 renderSettings.m_ShowHiddenFields = svgJob->m_includeHiddenFields;
1002
1003 int exitCode = CLI::EXIT_CODES::OK;
1004
1005 if( symbol )
1006 {
1007 exitCode = doSymExportSvg( svgJob, &renderSettings, symbol );
1008 }
1009 else
1010 {
1011 // Just plot all the symbols we can
1012 const LIB_SYMBOL_MAP& libSymMap = schLibrary.GetSymbolMap();
1013
1014 for( const auto& [name, libSymbol] : libSymMap )
1015 {
1016 if( m_progressReporter )
1017 {
1018 m_progressReporter->AdvancePhase( wxString::Format( _( "Exporting %s" ), name ) );
1019 m_progressReporter->KeepRefreshing();
1020 }
1021
1022 exitCode = doSymExportSvg( svgJob, &renderSettings, libSymbol );
1023
1024 if( exitCode != CLI::EXIT_CODES::OK )
1025 break;
1026 }
1027 }
1028
1029 return exitCode;
1030}
1031
1032
1034{
1035 JOB_SYM_UPGRADE* upgradeJob = dynamic_cast<JOB_SYM_UPGRADE*>( aJob );
1036
1037 wxCHECK( upgradeJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1038
1039 wxFileName fn( upgradeJob->m_libraryPath );
1040 fn.MakeAbsolute();
1041
1042 SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
1043
1044 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1045 {
1046 if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) )
1047 {
1048 m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
1050
1052 }
1053 }
1054 else if( fileType != SCH_IO_MGR::SCH_KICAD )
1055 {
1056 m_reporter->Report( _( "Output path must be specified to convert legacy and non-KiCad libraries\n" ),
1058
1060 }
1061
1062 if( fileType == SCH_IO_MGR::SCH_KICAD )
1063 {
1064 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
1065
1066 try
1067 {
1068 schLibrary.Load();
1069 }
1070 catch( ... )
1071 {
1072 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
1074 }
1075
1076 if( m_progressReporter )
1077 m_progressReporter->KeepRefreshing();
1078
1079 bool shouldSave =
1081
1082 if( shouldSave )
1083 {
1084 m_reporter->Report( _( "Saving symbol library in updated format\n" ), RPT_SEVERITY_ACTION );
1085
1086 try
1087 {
1088 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1089 schLibrary.SetFileName( upgradeJob->m_outputLibraryPath );
1090
1091 schLibrary.SetModified();
1092 schLibrary.Save();
1093 }
1094 catch( ... )
1095 {
1096 m_reporter->Report( ( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
1098 }
1099 }
1100 else
1101 {
1102 m_reporter->Report( _( "Symbol library was not updated\n" ), RPT_SEVERITY_ERROR );
1103 }
1104 }
1105 else
1106 {
1107 if( !SCH_IO_MGR::ConvertLibrary( nullptr, fn.GetAbsolutePath(), upgradeJob->m_outputLibraryPath ) )
1108 {
1109 m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR );
1111 }
1112 }
1113
1114 return CLI::EXIT_CODES::OK;
1115}
1116
1117
1118
1120{
1121 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( aJob );
1122
1123 wxCHECK( ercJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1124
1125 SCHEMATIC* sch = getSchematic( ercJob->m_filename );
1126
1127 if( !sch )
1129
1130 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
1131 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
1132
1133 if( ercJob->GetConfiguredOutputPath().IsEmpty() )
1134 {
1135 wxFileName fn = sch->GetFileName();
1136 fn.SetName( fn.GetName() + wxS( "-erc" ) );
1137
1139 fn.SetExt( FILEEXT::JsonFileExtension );
1140 else
1141 fn.SetExt( FILEEXT::ReportFileExtension );
1142
1143 ercJob->SetConfiguredOutputPath( fn.GetFullName() );
1144 }
1145
1146 wxString outPath = ercJob->GetFullOutputPath( &sch->Project() );
1147
1148 if( !PATHS::EnsurePathExists( outPath, true ) )
1149 {
1150 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
1152 }
1153
1154 EDA_UNITS units;
1155
1156 switch( ercJob->m_units )
1157 {
1158 case JOB_SCH_ERC::UNITS::INCH: units = EDA_UNITS::INCH; break;
1159 case JOB_SCH_ERC::UNITS::MILS: units = EDA_UNITS::MILS; break;
1160 case JOB_SCH_ERC::UNITS::MM: units = EDA_UNITS::MM; break;
1161 default: units = EDA_UNITS::MM; break;
1162 }
1163
1164 std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
1165 std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
1166
1167 ERC_TESTER ercTester( sch );
1168
1169 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet( getDrawingSheetProxyView( sch ) );
1170 ercTester.RunTests( drawingSheet.get(), nullptr, m_kiway->KiFACE( KIWAY::FACE_CVPCB ),
1171 &sch->Project(), m_progressReporter );
1172
1173 markersProvider->SetSeverities( ercJob->m_severity );
1174
1175 m_reporter->Report( wxString::Format( _( "Found %d violations\n" ), markersProvider->GetCount() ),
1177
1178 ERC_REPORT reportWriter( sch, units );
1179
1180 bool wroteReport = false;
1181
1183 wroteReport = reportWriter.WriteJsonReport( outPath );
1184 else
1185 wroteReport = reportWriter.WriteTextReport( outPath );
1186
1187 if( !wroteReport )
1188 {
1189 m_reporter->Report( wxString::Format( _( "Unable to save ERC report to %s\n" ), outPath ),
1192 }
1193
1194 m_reporter->Report( wxString::Format( _( "Saved ERC Report to %s\n" ), outPath ),
1196
1197 if( ercJob->m_exitCodeViolations )
1198 {
1199 if( markersProvider->GetCount() > 0 )
1201 }
1202
1204}
1205
1206
1208{
1209 JOB_SCH_UPGRADE* aUpgradeJob = dynamic_cast<JOB_SCH_UPGRADE*>( aJob );
1210
1211 if( aUpgradeJob == nullptr )
1213
1214 SCHEMATIC* sch = getSchematic( aUpgradeJob->m_filename );
1215
1216 if( !sch )
1218
1219 bool shouldSave = aUpgradeJob->m_force;
1220
1222 shouldSave = true;
1223
1224 if( !shouldSave )
1225 {
1226 m_reporter->Report( _( "Schematic file was not updated\n" ), RPT_SEVERITY_ERROR );
1228 }
1229
1230 // needs an absolute path
1231 wxFileName schPath( aUpgradeJob->m_filename );
1232 schPath.MakeAbsolute();
1233 const wxString schFullPath = schPath.GetFullPath();
1234
1235 try
1236 {
1237 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
1238 SCH_SHEET* loadedSheet = pi->LoadSchematicFile( schFullPath, sch );
1239 pi->SaveSchematicFile( schFullPath, loadedSheet, sch );
1240 }
1241 catch( const IO_ERROR& ioe )
1242 {
1243 wxString msg =
1244 wxString::Format( _( "Error saving schematic file '%s'.\n%s" ), schFullPath, ioe.What().GetData() );
1245 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
1247 }
1248
1249 m_reporter->Report( _( "Successfully saved schematic file using the latest format\n" ), RPT_SEVERITY_INFO );
1250
1252}
1253
1254
1256{
1257 DS_PROXY_VIEW_ITEM* drawingSheet =
1259 &aSch->Project(), &aSch->RootScreen()->GetTitleBlock(),
1260 aSch->GetProperties() );
1261
1262 drawingSheet->SetPageNumber( TO_UTF8( aSch->RootScreen()->GetPageNumber() ) );
1263 drawingSheet->SetSheetCount( aSch->RootScreen()->GetPageCount() );
1264 drawingSheet->SetFileName( TO_UTF8( aSch->RootScreen()->GetFileName() ) );
1267 drawingSheet->SetIsFirstPage( aSch->RootScreen()->GetVirtualPageNumber() == 1 );
1268
1269 drawingSheet->SetSheetName( "" );
1270 drawingSheet->SetSheetPath( "" );
1271
1272 return drawingSheet;
1273}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
int GetPageCount() const
Definition base_screen.h:72
int GetVirtualPageNumber() const
Definition base_screen.h:75
const wxString & GetPageNumber() const
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
static DS_DATA_MODEL & GetTheInstance()
Return 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)
Change the sheet-count number displayed in the title block.
void SetPageNumber(const std::string &aPageNumber)
Change 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)
Override 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)
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 in the c-locale.
bool WriteTextReport(const wxString &aFullFileName)
Writes the text report also available via GetTextReport directly to a given file path.
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:1927
void ApplyBomPreset(const BOM_PRESET &preset)
wxString Export(const BOM_FMT_PRESET &settings)
void AddColumn(const wxString &aFieldName, const wxString &aLabel, bool aAddedByUser)
std::vector< BOM_FIELD > GetFieldsOrdered()
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
bool SetProject(const PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
void Register(const std::string &aJobTypeName, std::function< int(JOB *job)> aHandler, std::function< bool(JOB *job, wxWindow *aParent)> aConfigHandler)
JOB_DISPATCHER(KIWAY *aKiway)
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
std::vector< wxString > m_plotPages
bool m_exitCodeViolations
Definition job_rc.h:52
int m_severity
Definition job_rc.h:49
UNITS m_units
Definition job_rc.h:48
OUTPUT_FORMAT m_format
Definition job_rc.h:50
wxString m_filename
Definition job_rc.h:47
wxString m_outputLibraryPath
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:183
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition job.cpp:153
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
Definition job.cpp:100
bool GetOutputPathIsDirectory() const
Definition job.h:253
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition job.h:232
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition job.h:203
const std::map< wxString, wxString > & GetVarOverrides() const
Definition job.h:196
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:286
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:395
@ FACE_CVPCB
Definition kiway.h:295
Define a library symbol object.
Definition lib_symbol.h:85
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true, bool aIgnoreLabelsOnInvisiblePins=true) const
Get the bounding box for the symbol.
bool IsDerived() const
Definition lib_symbol.h:206
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
void PlotFields(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed)
Plot symbol fields.
wxString GetName() const override
Definition lib_symbol.h:148
const std::vector< wxString > & GetBodyStyleNames() const
Definition lib_symbol.h:607
bool HasDeMorganBodyStyles() const override
Definition lib_symbol.h:604
int GetBodyStyleCount() const override
Definition lib_symbol.h:596
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition page_info.h:168
void SetHeightMils(double aHeightInMils)
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition page_info.h:159
void SetWidthMils(double aWidthInMils)
static bool EnsurePathExists(const wxString &aPath, bool aPathToFile=false)
Attempts to create a given path if it does not exist.
Definition paths.cpp:477
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:125
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition plotter.cpp:76
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition plotter.h:154
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition plotter.h:151
virtual void SetCreator(const wxString &aCreator)
Definition plotter.h:173
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition plotter.h:148
Container for project specific data.
Definition project.h:65
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
Definition project.cpp:117
std::vector< BOM_PRESET > m_BomPresets
std::vector< BOM_FMT_PRESET > m_BomFmtPresets
Holds all the data relating to one schematic.
Definition schematic.h:88
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:103
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:106
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.
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.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
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:139
const wxString & GetFileName() const
Definition sch_screen.h:152
int GetFileFormatVersionAtLoad() const
Definition sch_screen.h:137
const TITLE_BLOCK & GetTitleBlock() const
Definition sch_screen.h:163
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.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
Schematic symbol object.
Definition sch_symbol.h:75
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
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 std::vector< TEMPLATE_FIELDNAME > & GetTemplateFieldNames()
Return a template field name list for read only access.
wxString GetGeneratedFieldDisplayName(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition common.cpp:123
bool IsGeneratedField(const wxString &aSource)
Returns true if the string is generated, e.g contains a single text var reference.
Definition common.cpp:136
The common library.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:194
This file is part of 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:48
ERCE_T
ERC error codes.
@ 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
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
#define KICAD_FONT_NAME
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:494
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition layer_ids.h:495
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition lib_symbol.h:52
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
Rules check violation count was greater than 0.
Definition exit_codes.h:37
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
Definition exit_codes.h:34
static const int ERR_UNKNOWN
Definition exit_codes.h:32
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
@ GNL_OPT_BOM
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:913
see class PGM_BASE
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:64
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...
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
@ PAGE_SIZE_AUTO
Definition sch_plotter.h:48
@ PAGE_SIZE_A
Definition sch_plotter.h:50
@ PAGE_SIZE_A4
Definition sch_plotter.h:49
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
T * GetAppSettings(const char *aFilename)
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.
wxString label
wxString name
wxString fieldDelimiter
static std::vector< BOM_FMT_PRESET > BuiltInPresets()
wxString stringDelimiter
wxString refRangeDelimiter
wxString refDelimiter
wxString sortField
bool groupSymbols
std::vector< BOM_FIELD > fieldsOrdered
static std::vector< BOM_PRESET > BuiltInPresets()
bool excludeDNP
wxString filterString
std::vector< wxString > m_plotPages
Definition sch_plotter.h:58
wxString m_theme
Definition sch_plotter.h:67
DXF_UNITS m_DXF_File_Unit
Definition sch_plotter.h:72
bool m_PDFPropertyPopups
Definition sch_plotter.h:64
wxString m_outputDirectory
Definition sch_plotter.h:69
wxString m_outputFile
Definition sch_plotter.h:70
bool m_blackAndWhite
Definition sch_plotter.h:61
bool m_PDFHierarchicalLinks
Definition sch_plotter.h:65
bool m_useBackgroundColor
Definition sch_plotter.h:63
bool m_plotDrawingSheet
Definition sch_plotter.h:57
Hold a name of a symbol's field, field value, and default visibility.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
wxString GetDefaultFieldName(FIELD_T aFieldId, bool aTranslateForHI)
Return a default symbol field name for a mandatory field type.
#define DO_TRANSLATE
#define MANDATORY_FIELDS
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
wxString GetCanonicalFieldName(FIELD_T aFieldType)
VECTOR3I res
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
Definition of file extensions used in Kicad.