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>
35#include <schematic.h>
36#include <schematic_settings.h>
37#include <wx/dir.h>
38#include <wx/file.h>
39#include <memory>
40#include <connection_graph.h>
41#include "eeschema_helpers.h"
42#include <filename_resolver.h>
43#include <kiway.h>
44#include <sch_painter.h>
45#include <locale_io.h>
46#include <erc/erc.h>
47#include <erc/erc_report.h>
51#include <paths.h>
52#include <reporter.h>
53#include <string_utils.h>
54
56
57#include <sch_file_versions.h>
59
60#include <netlist.h>
70
71#include <fields_data_model.h>
72
77#include <confirm.h>
78
79
81 JOB_DISPATCHER( aKiway ),
82 m_cliSchematic( nullptr )
83{
84 Register( "bom",
85 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ),
86 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
87 {
88 JOB_EXPORT_SCH_BOM* bomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( job );
89
90 SCH_EDIT_FRAME* editFrame =
91 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
92
93 wxCHECK( bomJob && editFrame, false );
94
95 DIALOG_SYMBOL_FIELDS_TABLE dlg( editFrame, bomJob );
96 return dlg.ShowModal() == wxID_OK;
97 } );
98 Register( "pythonbom",
99 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, this, std::placeholders::_1 ),
100 []( JOB* job, wxWindow* aParent ) -> bool
101 {
102 return true;
103 } );
104 Register( "netlist",
105 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ),
106 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
107 {
108 JOB_EXPORT_SCH_NETLIST* netJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( job );
109
110 SCH_EDIT_FRAME* editFrame =
111 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
112
113 wxCHECK( netJob && editFrame, false );
114
115 DIALOG_EXPORT_NETLIST dlg( editFrame, aParent, netJob );
116 return dlg.ShowModal() == wxID_OK;
117 } );
118 Register( "plot",
119 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPlot, this, std::placeholders::_1 ),
120 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
121 {
122 JOB_EXPORT_SCH_PLOT* plotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( job );
123
124 SCH_EDIT_FRAME* editFrame =
125 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
126
127 wxCHECK( plotJob && editFrame, false );
128
129 if( plotJob->m_plotFormat == SCH_PLOT_FORMAT::HPGL )
130 {
131 DisplayErrorMessage( editFrame,
132 _( "Plotting to HPGL is no longer supported as of KiCad 10.0." ) );
133 return false;
134 }
135
136 DIALOG_PLOT_SCHEMATIC dlg( editFrame, aParent, plotJob );
137 return dlg.ShowModal() == wxID_OK;
138 } );
139 Register( "symupgrade",
140 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymUpgrade, this, std::placeholders::_1 ),
141 []( JOB* job, wxWindow* aParent ) -> bool
142 {
143 return true;
144 } );
145 Register( "symsvg",
146 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymExportSvg, this, std::placeholders::_1 ),
147 []( JOB* job, wxWindow* aParent ) -> bool
148 {
149 return true;
150 } );
151 Register( "erc", std::bind( &EESCHEMA_JOBS_HANDLER::JobSchErc, this, std::placeholders::_1 ),
152 []( JOB* job, wxWindow* aParent ) -> bool
153 {
154 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( job );
155
156 wxCHECK( ercJob, false );
157
158 DIALOG_ERC_JOB_CONFIG dlg( aParent, ercJob );
159 return dlg.ShowModal() == wxID_OK;
160 } );
161}
162
163
165{
166 SCHEMATIC* sch = nullptr;
167
168 if( !Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpenNotDummy() )
169 {
171 wxString schPath = aPath;
172
173 if( schPath.IsEmpty() )
174 {
175 wxFileName path = project.GetProjectFullName();
177 path.MakeAbsolute();
178 schPath = path.GetFullPath();
179 }
180
181 if( !m_cliSchematic )
182 m_cliSchematic = EESCHEMA_HELPERS::LoadSchematic( schPath, true, false, &project );
183
184 sch = m_cliSchematic;
185 }
186 else if( Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpen() )
187 {
188 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_kiway->Player( FRAME_SCH, false ) );
189
190 if( editFrame )
191 sch = &editFrame->Schematic();
192 }
193 else if( !aPath.IsEmpty() )
194 {
195 sch = EESCHEMA_HELPERS::LoadSchematic( aPath, true, false );
196 }
197
198 if( !sch )
199 m_reporter->Report( _( "Failed to load schematic\n" ), RPT_SEVERITY_ERROR );
200
201 return sch;
202}
203
205 const wxString& aTheme, SCHEMATIC* aSch,
206 const wxString& aDrawingSheetOverride )
207{
208 COLOR_SETTINGS* cs = ::GetColorSettings( aTheme );
209 aRenderSettings->LoadColors( cs );
210 aRenderSettings->m_ShowHiddenPins = false;
211 aRenderSettings->m_ShowHiddenFields = false;
212 aRenderSettings->m_ShowPinAltIcons = false;
213
214 aRenderSettings->SetDefaultPenWidth( aSch->Settings().m_DefaultLineWidth );
215 aRenderSettings->m_LabelSizeRatio = aSch->Settings().m_LabelSizeRatio;
216 aRenderSettings->m_TextOffsetRatio = aSch->Settings().m_TextOffsetRatio;
217 aRenderSettings->m_PinSymbolSize = aSch->Settings().m_PinSymbolSize;
218
219 aRenderSettings->SetDashLengthRatio( aSch->Settings().m_DashedLineDashRatio );
220 aRenderSettings->SetGapLengthRatio( aSch->Settings().m_DashedLineGapRatio );
221
222 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
223 // If empty, or not existing, the default drawing sheet is loaded.
224
225 auto loadSheet =
226 [&]( const wxString& path ) -> bool
227 {
228 wxString msg;
229 FILENAME_RESOLVER resolve;
230 resolve.SetProject( &aSch->Prj() );
231 resolve.SetProgramBase( &Pgm() );
232
233 wxString absolutePath = resolve.ResolvePath( path, wxGetCwd(),
234 { aSch->GetEmbeddedFiles() } );
235
236 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath, &msg ) )
237 {
238 m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ), path )
239 + wxS( "\n" ) + msg + wxS( "\n" ),
241 return false;
242 }
243
244 return true;
245 };
246
247 // try to load the override first
248 if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
249 return;
250
251 // no override or failed override continues here
252 loadSheet( aSch->Settings().m_SchDrawingSheetFileName );
253}
254
255
257{
258 JOB_EXPORT_SCH_PLOT* aPlotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( aJob );
259
260 wxCHECK( aPlotJob, CLI::EXIT_CODES::ERR_UNKNOWN );
261
262 if( aPlotJob->m_plotFormat == SCH_PLOT_FORMAT::HPGL )
263 {
264 m_reporter->Report( _( "Plotting to HPGL is no longer supported as of KiCad 10.0.\n" ),
267 }
268
269 SCHEMATIC* sch = getSchematic( aPlotJob->m_filename );
270
271 if( !sch )
273
274 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
275 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
276
277 std::unique_ptr<SCH_RENDER_SETTINGS> renderSettings = std::make_unique<SCH_RENDER_SETTINGS>();
278 InitRenderSettings( renderSettings.get(), aPlotJob->m_theme, sch, aPlotJob->m_drawingSheet );
279
280 wxString font = aPlotJob->m_defaultFont;
281
282 if( font.IsEmpty() )
283 {
284 EESCHEMA_SETTINGS* cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
285 font = cfg ? cfg->m_Appearance.default_font : wxString( KICAD_FONT_NAME );
286 }
287
288 renderSettings->SetDefaultFont( font );
289 renderSettings->SetMinPenWidth( aPlotJob->m_minPenWidth );
290
291 std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
292
293 PLOT_FORMAT format = PLOT_FORMAT::PDF;
294
295 switch( aPlotJob->m_plotFormat )
296 {
297 case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF; break;
298 case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF; break;
299 case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG; break;
300 case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST; break;
301 case SCH_PLOT_FORMAT::HPGL: /* no longer supported */ break;
302 }
303
304 int pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
305
306 switch( aPlotJob->m_pageSizeSelect )
307 {
308 case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A; break;
309 case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4; break;
310 case JOB_PAGE_SIZE::PAGE_SIZE_AUTO: pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO; break;
311 }
312
313 wxString outPath = aPlotJob->GetFullOutputPath( &sch->Prj() );
314
315 if( !PATHS::EnsurePathExists( outPath, !aPlotJob->GetOutputPathIsDirectory() ) )
316 {
317 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
319 }
320
321 SCH_PLOT_OPTS plotOpts;
322 plotOpts.m_blackAndWhite = aPlotJob->m_blackAndWhite;
323 plotOpts.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups;
325 plotOpts.m_PDFMetadata = aPlotJob->m_PDFMetadata;
326
327 if( aPlotJob->GetOutputPathIsDirectory() )
328 {
329 plotOpts.m_outputDirectory = outPath;
330 plotOpts.m_outputFile = wxEmptyString;
331 }
332 else
333 {
334 plotOpts.m_outputDirectory = wxEmptyString;
335 plotOpts.m_outputFile = outPath;
336 }
337
338 plotOpts.m_pageSizeSelect = pageSizeSelect;
339 plotOpts.m_plotAll = aPlotJob->m_plotAll;
340 plotOpts.m_plotDrawingSheet = aPlotJob->m_plotDrawingSheet;
341 plotOpts.m_plotPages = aPlotJob->m_plotPages;
342 plotOpts.m_theme = aPlotJob->m_theme;
343 plotOpts.m_useBackgroundColor = aPlotJob->m_useBackgroundColor;
344 plotOpts.m_plotHopOver = aPlotJob->m_show_hop_over;
345
346 schPlotter->Plot( format, plotOpts, renderSettings.get(), m_reporter );
347
350
351 return CLI::EXIT_CODES::OK;
352}
353
354
356{
357 JOB_EXPORT_SCH_NETLIST* aNetJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( aJob );
358
359 wxCHECK( aNetJob, CLI::EXIT_CODES::ERR_UNKNOWN );
360
361 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
362
363 if( !sch )
365
366 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
367 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
368
369 // Annotation warning check
370 SCH_REFERENCE_LIST referenceList;
371 sch->Hierarchy().GetSymbols( referenceList );
372
373 if( referenceList.GetCount() > 0 )
374 {
375 if( referenceList.CheckAnnotation(
376 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
377 {
378 // We're only interested in the end result -- either errors or not
379 } )
380 > 0 )
381 {
382 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
383 "schematic editor to fix them\n" ),
385 }
386 }
387
388 // Test duplicate sheet names:
389 ERC_TESTER erc( sch );
390
391 if( erc.TestDuplicateSheetNames( false ) > 0 )
392 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
393
394 std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
395 unsigned netlistOption = 0;
396
397 wxString fileExt;
398
399 switch( aNetJob->format )
400 {
403 helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
404 break;
405
408 helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
409 break;
410
413 helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
414 break;
415
419 helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
420 break;
421
424 helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
425 break;
426
428 fileExt = wxS( "xml" );
429 helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
430 break;
431
433 fileExt = wxS( "asc" );
434 helper = std::make_unique<NETLIST_EXPORTER_PADS>( sch );
435 break;
436
438 fileExt = wxS( "txt" );
439 helper = std::make_unique<NETLIST_EXPORTER_ALLEGRO>( sch );
440 break;
441
442 default:
443 m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR );
445 }
446
447 if( aNetJob->GetConfiguredOutputPath().IsEmpty() )
448 {
449 wxFileName fn = sch->GetFileName();
450 fn.SetName( fn.GetName() );
451 fn.SetExt( fileExt );
452
453 aNetJob->SetConfiguredOutputPath( fn.GetFullName() );
454 }
455
456 wxString outPath = aNetJob->GetFullOutputPath( &sch->Prj() );
457
458 if( !PATHS::EnsurePathExists( outPath, true ) )
459 {
460 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
462 }
463
464 bool res = helper->WriteNetlist( outPath, netlistOption, *m_reporter );
465
466 if( !res )
468
469 return CLI::EXIT_CODES::OK;
470}
471
472
474{
475 JOB_EXPORT_SCH_BOM* aBomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( aJob );
476
477 wxCHECK( aBomJob, CLI::EXIT_CODES::ERR_UNKNOWN );
478
479 SCHEMATIC* sch = getSchematic( aBomJob->m_filename );
480
481 if( !sch )
483
484 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
485 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
486
487 // Annotation warning check
488 SCH_REFERENCE_LIST referenceList;
489 sch->Hierarchy().GetSymbols( referenceList, false, false );
490
491 if( referenceList.GetCount() > 0 )
492 {
493 SCH_REFERENCE_LIST copy = referenceList;
494
495 // Check annotation splits references...
496 if( copy.CheckAnnotation(
497 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
498 {
499 // We're only interested in the end result -- either errors or not
500 } )
501 > 0 )
502 {
504 _( "Warning: schematic has annotation errors, please use the schematic "
505 "editor to fix them\n" ),
507 }
508 }
509
510 // Test duplicate sheet names:
511 ERC_TESTER erc( sch );
512
513 if( erc.TestDuplicateSheetNames( false ) > 0 )
514 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
515
516 // Build our data model
517 FIELDS_EDITOR_GRID_DATA_MODEL dataModel( referenceList, nullptr );
518
519 // Mandatory fields + quantity virtual field first
520 for( FIELD_T fieldId : MANDATORY_FIELDS )
521 {
522 dataModel.AddColumn( GetCanonicalFieldName( fieldId ),
523 GetDefaultFieldName( fieldId, DO_TRANSLATE ), false );
524 }
525
526 // User field names in symbols second
527 std::set<wxString> userFieldNames;
528
529 for( size_t i = 0; i < referenceList.GetCount(); ++i )
530 {
531 SCH_SYMBOL* symbol = referenceList[i].GetSymbol();
532
533 for( SCH_FIELD& field : symbol->GetFields() )
534 {
535 if( !field.IsMandatory() && !field.IsPrivate() )
536 userFieldNames.insert( field.GetName() );
537 }
538 }
539
540 for( const wxString& fieldName : userFieldNames )
541 dataModel.AddColumn( fieldName, GetGeneratedFieldDisplayName( fieldName ), true );
542
543 // Add any templateFieldNames which aren't already present in the userFieldNames
544 for( const TEMPLATE_FIELDNAME& templateFieldname :
546 {
547 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
548 {
549 dataModel.AddColumn( templateFieldname.m_Name, GetGeneratedFieldDisplayName( templateFieldname.m_Name ),
550 false );
551 }
552 }
553
554 BOM_PRESET preset;
555
556 // Load a preset if one is specified
557 if( !aBomJob->m_bomPresetName.IsEmpty() )
558 {
559 // Find the preset
560 const BOM_PRESET* schPreset = nullptr;
561
562 for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
563 {
564 if( p.name == aBomJob->m_bomPresetName )
565 {
566 schPreset = &p;
567 break;
568 }
569 }
570
571 for( const BOM_PRESET& p : sch->Settings().m_BomPresets )
572 {
573 if( p.name == aBomJob->m_bomPresetName )
574 {
575 schPreset = &p;
576 break;
577 }
578 }
579
580 if( !schPreset )
581 {
582 m_reporter->Report( wxString::Format( _( "BOM preset '%s' not found" ) + wxS( "\n" ),
583 aBomJob->m_bomPresetName ),
585
587 }
588
589 preset = *schPreset;
590 }
591 else
592 {
593 size_t i = 0;
594
595 for( const wxString& fieldName : aBomJob->m_fieldsOrdered )
596 {
597 // Handle wildcard. We allow the wildcard anywhere in the list, but it needs to respect
598 // fields that come before and after the wildcard.
599 if( fieldName == wxS( "*" ) )
600 {
601 for( const BOM_FIELD& modelField : dataModel.GetFieldsOrdered() )
602 {
603 struct BOM_FIELD field;
604
605 field.name = modelField.name;
606 field.show = true;
607 field.groupBy = false;
608 field.label = field.name;
609
610 bool fieldAlreadyPresent = false;
611
612 for( BOM_FIELD& presetField : preset.fieldsOrdered )
613 {
614 if( presetField.name == field.name )
615 {
616 fieldAlreadyPresent = true;
617 break;
618 }
619 }
620
621 bool fieldLaterInList = false;
622
623 for( const wxString& fieldInList : aBomJob->m_fieldsOrdered )
624 {
625 if( fieldInList == field.name )
626 {
627 fieldLaterInList = true;
628 break;
629 }
630 }
631
632 if( !fieldAlreadyPresent && !fieldLaterInList )
633 preset.fieldsOrdered.emplace_back( field );
634 }
635
636 continue;
637 }
638
639 struct BOM_FIELD field;
640
641 field.name = fieldName;
642 field.show = !fieldName.StartsWith( wxT( "__" ), &field.name );
643 field.groupBy = alg::contains( aBomJob->m_fieldsGroupBy, field.name );
644
645 if( ( aBomJob->m_fieldsLabels.size() > i ) && !aBomJob->m_fieldsLabels[i].IsEmpty() )
646 field.label = aBomJob->m_fieldsLabels[i];
647 else if( IsGeneratedField( field.name ) )
648 field.label = GetGeneratedFieldDisplayName( field.name );
649 else
650 field.label = field.name;
651
652 preset.fieldsOrdered.emplace_back( field );
653 i++;
654 }
655
656 preset.sortAsc = aBomJob->m_sortAsc;
657 preset.sortField = aBomJob->m_sortField;
658 preset.filterString = aBomJob->m_filterString;
659 preset.groupSymbols = ( aBomJob->m_fieldsGroupBy.size() > 0 );
660 preset.excludeDNP = aBomJob->m_excludeDNP;
662 }
663
664 dataModel.ApplyBomPreset( preset );
665
666 if( aBomJob->GetConfiguredOutputPath().IsEmpty() )
667 {
668 wxFileName fn = sch->GetFileName();
669 fn.SetName( fn.GetName() );
670 fn.SetExt( FILEEXT::CsvFileExtension );
671
672 aBomJob->SetConfiguredOutputPath( fn.GetFullName() );
673 }
674
675 wxString outPath = aBomJob->GetFullOutputPath( &sch->Prj() );
676
677 if( !PATHS::EnsurePathExists( outPath, true ) )
678 {
679 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
681 }
682
683 wxFile f;
684
685 if( !f.Open( outPath, wxFile::write ) )
686 {
687 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ), outPath ),
689
691 }
692
693 BOM_FMT_PRESET fmt;
694
695 // Load a format preset if one is specified
696 if( !aBomJob->m_bomFmtPresetName.IsEmpty() )
697 {
698 // Find the preset
699 std::optional<BOM_FMT_PRESET> schFmtPreset;
700
702 {
703 if( p.name == aBomJob->m_bomFmtPresetName )
704 {
705 schFmtPreset = p;
706 break;
707 }
708 }
709
710 for( const BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
711 {
712 if( p.name == aBomJob->m_bomFmtPresetName )
713 {
714 schFmtPreset = p;
715 break;
716 }
717 }
718
719 if( !schFmtPreset )
720 {
721 m_reporter->Report( wxString::Format( _( "BOM format preset '%s' not found" ) + wxS( "\n" ),
722 aBomJob->m_bomFmtPresetName ),
724
726 }
727
728 fmt = *schFmtPreset;
729 }
730 else
731 {
732 fmt.fieldDelimiter = aBomJob->m_fieldDelimiter;
733 fmt.stringDelimiter = aBomJob->m_stringDelimiter;
734 fmt.refDelimiter = aBomJob->m_refDelimiter;
736 fmt.keepTabs = aBomJob->m_keepTabs;
737 fmt.keepLineBreaks = aBomJob->m_keepLineBreaks;
738 }
739
740 bool res = f.Write( dataModel.Export( fmt ) );
741
742 if( !res )
744
745 m_reporter->Report( wxString::Format( _( "Wrote bill of materials to '%s'." ), outPath ),
747
748 return CLI::EXIT_CODES::OK;
749}
750
751
753{
754 JOB_EXPORT_SCH_PYTHONBOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_PYTHONBOM*>( aJob );
755
756 wxCHECK( aNetJob, CLI::EXIT_CODES::ERR_UNKNOWN );
757
758 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
759
760 if( !sch )
762
763 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
764 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
765
766 // Annotation warning check
767 SCH_REFERENCE_LIST referenceList;
768 sch->Hierarchy().GetSymbols( referenceList );
769
770 if( referenceList.GetCount() > 0 )
771 {
772 if( referenceList.CheckAnnotation(
773 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
774 {
775 // We're only interested in the end result -- either errors or not
776 } )
777 > 0 )
778 {
779 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
780 "schematic editor to fix them\n" ),
782 }
783 }
784
785 // Test duplicate sheet names:
786 ERC_TESTER erc( sch );
787
788 if( erc.TestDuplicateSheetNames( false ) > 0 )
789 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
790
791 std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
792 std::make_unique<NETLIST_EXPORTER_XML>( sch );
793
794 if( aNetJob->GetConfiguredOutputPath().IsEmpty() )
795 {
796 wxFileName fn = sch->GetFileName();
797 fn.SetName( fn.GetName() + "-bom" );
798 fn.SetExt( FILEEXT::XmlFileExtension );
799
800 aNetJob->SetConfiguredOutputPath( fn.GetFullName() );
801 }
802
803 wxString outPath = aNetJob->GetFullOutputPath( &sch->Prj() );
804
805 if( !PATHS::EnsurePathExists( outPath, true ) )
806 {
807 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
809 }
810
811 bool res = xmlNetlist->WriteNetlist( outPath, GNL_OPT_BOM, *m_reporter );
812
813 if( !res )
815
816 m_reporter->Report( wxString::Format( _( "Wrote bill of materials to '%s'." ), outPath ),
818
819 return CLI::EXIT_CODES::OK;
820}
821
822
824 SCH_RENDER_SETTINGS* aRenderSettings,
825 LIB_SYMBOL* symbol )
826{
827 wxCHECK( symbol, CLI::EXIT_CODES::ERR_UNKNOWN );
828
829 LIB_SYMBOL_SPTR parent;
830 LIB_SYMBOL* symbolToPlot = symbol;
831
832 // if the symbol is an alias, then the draw items are stored in the root symbol
833 if( symbol->IsDerived() )
834 {
835 parent = symbol->GetRootSymbol();
836
837 wxCHECK( parent, CLI::EXIT_CODES::ERR_UNKNOWN );
838
839 symbolToPlot = parent.get();
840 }
841
842 // iterate from unit 1, unit 0 would be "all units" which we don't want
843 for( int unit = 1; unit < symbol->GetUnitCount() + 1; unit++ )
844 {
845 for( int bodyStyle = 1; bodyStyle < ( symbol->HasAlternateBodyStyle() ? 2 : 1 ) + 1;
846 ++bodyStyle )
847 {
848 wxString filename;
849 wxFileName fn;
850
851 fn.SetPath( aSvgJob->m_outputDirectory );
852 fn.SetExt( FILEEXT::SVGFileExtension );
853
854 filename = symbol->GetName();
855
856 for( wxChar c : wxFileName::GetForbiddenChars( wxPATH_DOS ) )
857 filename.Replace( c, ' ' );
858
859 // Even single units get a unit number in the filename. This simplifies the
860 // handling of the files as they have a uniform pattern.
861 // Also avoids aliasing 'sym', unit 2 and 'sym_unit2', unit 1 to the same file.
862 filename += wxString::Format( "_unit%d", unit );
863
864 if( bodyStyle == 2 )
865 filename += wxS( "_demorgan" );
866
867 fn.SetName( filename );
868 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ),
869 symbol->GetName(),
870 unit,
871 fn.GetFullPath() ),
873
874 // Get the symbol bounding box to fit the plot page to it
875 BOX2I symbolBB = symbol->Flatten()->GetUnitBoundingBox( unit, bodyStyle,
876 !aSvgJob->m_includeHiddenFields );
877 PAGE_INFO pageInfo( PAGE_INFO::Custom );
878 pageInfo.SetHeightMils( schIUScale.IUToMils( symbolBB.GetHeight() * 1.2 ) );
879 pageInfo.SetWidthMils( schIUScale.IUToMils( symbolBB.GetWidth() * 1.2 ) );
880
881 SVG_PLOTTER* plotter = new SVG_PLOTTER();
882 plotter->SetRenderSettings( aRenderSettings );
883 plotter->SetPageSettings( pageInfo );
884 plotter->SetColorMode( !aSvgJob->m_blackAndWhite );
885
886 VECTOR2I plot_offset = symbolBB.GetCenter();
887 const double scale = 1.0;
888
889 // Currently, plot units are in decimal
890 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
891
892 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
893
894 if( !plotter->OpenFile( fn.GetFullPath() ) )
895 {
896 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ) + wxS( "\n" ),
897 fn.GetFullPath() ),
899
900 delete plotter;
902 }
903
904 LOCALE_IO toggle;
905 SCH_PLOT_OPTS plotOpts;
906
907 plotter->StartPlot( wxT( "1" ) );
908
909 bool background = true;
910 VECTOR2I offset( pageInfo.GetWidthIU( schIUScale.IU_PER_MILS ) / 2,
911 pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) / 2 );
912
913 // note, we want the fields from the original symbol pointer (in case of non-alias)
914 symbolToPlot->Plot( plotter, background, plotOpts, unit, bodyStyle, offset, false );
915 symbol->PlotFields( plotter, background, plotOpts, unit, bodyStyle, offset, false );
916
917 symbolToPlot->Plot( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
918 symbol->PlotFields( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
919
920 plotter->EndPlot();
921 delete plotter;
922 }
923 }
924
927
928 return CLI::EXIT_CODES::OK;
929}
930
931
933{
934 JOB_SYM_EXPORT_SVG* svgJob = dynamic_cast<JOB_SYM_EXPORT_SVG*>( aJob );
935
936 wxCHECK( svgJob, CLI::EXIT_CODES::ERR_UNKNOWN );
937
938 wxFileName fn( svgJob->m_libraryPath );
939 fn.MakeAbsolute();
940
941 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
942
943 try
944 {
945 schLibrary.Load();
946 }
947 catch( ... )
948 {
949 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
951 }
952
955
956 LIB_SYMBOL* symbol = nullptr;
957
958 if( !svgJob->m_symbol.IsEmpty() )
959 {
960 // See if the selected symbol exists
961 symbol = schLibrary.GetSymbol( svgJob->m_symbol );
962
963 if( !symbol )
964 {
965 m_reporter->Report( _( "There is no symbol selected to save." ) + wxS( "\n" ),
968 }
969 }
970
971 if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) )
972 {
973 if( !wxFileName::Mkdir( svgJob->m_outputDirectory ) )
974 {
975 m_reporter->Report( wxString::Format( _( "Unable to create output directory '%s'." ) + wxS( "\n" ),
976 svgJob->m_outputDirectory ),
979 }
980 }
981
982 SCH_RENDER_SETTINGS renderSettings;
984 renderSettings.LoadColors( cs );
986 renderSettings.m_ShowHiddenPins = svgJob->m_includeHiddenPins;
987 renderSettings.m_ShowHiddenFields = svgJob->m_includeHiddenFields;
988
989 int exitCode = CLI::EXIT_CODES::OK;
990
991 if( symbol )
992 {
993 exitCode = doSymExportSvg( svgJob, &renderSettings, symbol );
994 }
995 else
996 {
997 // Just plot all the symbols we can
998 const LIB_SYMBOL_MAP& libSymMap = schLibrary.GetSymbolMap();
999
1000 for( const auto& [name, libSymbol] : libSymMap )
1001 {
1002 if( m_progressReporter )
1003 {
1004 m_progressReporter->AdvancePhase( wxString::Format( _( "Exporting %s" ), name ) );
1006 }
1007
1008 exitCode = doSymExportSvg( svgJob, &renderSettings, libSymbol );
1009
1010 if( exitCode != CLI::EXIT_CODES::OK )
1011 break;
1012 }
1013 }
1014
1015 return exitCode;
1016}
1017
1018
1020{
1021 JOB_SYM_UPGRADE* upgradeJob = dynamic_cast<JOB_SYM_UPGRADE*>( aJob );
1022
1023 wxCHECK( upgradeJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1024
1025 wxFileName fn( upgradeJob->m_libraryPath );
1026 fn.MakeAbsolute();
1027
1028 SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
1029
1030 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1031 {
1032 if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) )
1033 {
1034 m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
1036
1038 }
1039 }
1040 else if( fileType != SCH_IO_MGR::SCH_KICAD )
1041 {
1042 m_reporter->Report( _( "Output path must be specified to convert legacy and non-KiCad libraries\n" ),
1044
1046 }
1047
1048 if( fileType == SCH_IO_MGR::SCH_KICAD )
1049 {
1050 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
1051
1052 try
1053 {
1054 schLibrary.Load();
1055 }
1056 catch( ... )
1057 {
1058 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
1060 }
1061
1062 if( m_progressReporter )
1064
1065 bool shouldSave = upgradeJob->m_force
1067
1068 if( shouldSave )
1069 {
1070 m_reporter->Report( _( "Saving symbol library in updated format\n" ), RPT_SEVERITY_ACTION );
1071
1072 try
1073 {
1074 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1075 schLibrary.SetFileName( upgradeJob->m_outputLibraryPath );
1076
1077 schLibrary.SetModified();
1078 schLibrary.Save();
1079 }
1080 catch( ... )
1081 {
1082 m_reporter->Report( ( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
1084 }
1085 }
1086 else
1087 {
1088 m_reporter->Report( _( "Symbol library was not updated\n" ), RPT_SEVERITY_ERROR );
1089 }
1090 }
1091 else
1092 {
1093 if( !SCH_IO_MGR::ConvertLibrary( nullptr, fn.GetAbsolutePath(), upgradeJob->m_outputLibraryPath ) )
1094 {
1095 m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR );
1097 }
1098 }
1099
1100 return CLI::EXIT_CODES::OK;
1101}
1102
1103
1104
1106{
1107 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( aJob );
1108
1109 wxCHECK( ercJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1110
1111 SCHEMATIC* sch = getSchematic( ercJob->m_filename );
1112
1113 if( !sch )
1115
1116 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
1117 sch->Prj().ApplyTextVars( aJob->GetVarOverrides() );
1118
1119 if( ercJob->GetConfiguredOutputPath().IsEmpty() )
1120 {
1121 wxFileName fn = sch->GetFileName();
1122 fn.SetName( fn.GetName() + wxS( "-erc" ) );
1123
1125 fn.SetExt( FILEEXT::JsonFileExtension );
1126 else
1127 fn.SetExt( FILEEXT::ReportFileExtension );
1128
1129 ercJob->SetConfiguredOutputPath( fn.GetFullName() );
1130 }
1131
1132 wxString outPath = ercJob->GetFullOutputPath( &sch->Prj() );
1133
1134 if( !PATHS::EnsurePathExists( outPath, true ) )
1135 {
1136 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
1138 }
1139
1140 EDA_UNITS units;
1141
1142 switch( ercJob->m_units )
1143 {
1144 case JOB_SCH_ERC::UNITS::INCH: units = EDA_UNITS::INCH; break;
1145 case JOB_SCH_ERC::UNITS::MILS: units = EDA_UNITS::MILS; break;
1146 case JOB_SCH_ERC::UNITS::MM: units = EDA_UNITS::MM; break;
1147 default: units = EDA_UNITS::MM; break;
1148 }
1149
1150 std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
1151 std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
1152
1153 ERC_TESTER ercTester( sch );
1154
1155 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet( getDrawingSheetProxyView( sch ) );
1156 ercTester.RunTests( drawingSheet.get(), nullptr, m_kiway->KiFACE( KIWAY::FACE_CVPCB ),
1157 &sch->Prj(), m_progressReporter );
1158
1159 markersProvider->SetSeverities( ercJob->m_severity );
1160
1161 m_reporter->Report( wxString::Format( _( "Found %d violations\n" ), markersProvider->GetCount() ),
1163
1164 ERC_REPORT reportWriter( sch, units );
1165
1166 bool wroteReport = false;
1167
1169 wroteReport = reportWriter.WriteJsonReport( outPath );
1170 else
1171 wroteReport = reportWriter.WriteTextReport( outPath );
1172
1173 if( !wroteReport )
1174 {
1175 m_reporter->Report( wxString::Format( _( "Unable to save ERC report to %s\n" ), outPath ),
1178 }
1179
1180 m_reporter->Report( wxString::Format( _( "Saved ERC Report to %s\n" ), outPath ),
1182
1183 if( ercJob->m_exitCodeViolations )
1184 {
1185 if( markersProvider->GetCount() > 0 )
1187 }
1188
1190}
1191
1192
1194{
1195 DS_PROXY_VIEW_ITEM* drawingSheet =
1197 &aSch->Prj(), &aSch->RootScreen()->GetTitleBlock(),
1198 aSch->GetProperties() );
1199
1200 drawingSheet->SetPageNumber( TO_UTF8( aSch->RootScreen()->GetPageNumber() ) );
1201 drawingSheet->SetSheetCount( aSch->RootScreen()->GetPageCount() );
1202 drawingSheet->SetFileName( TO_UTF8( aSch->RootScreen()->GetFileName() ) );
1205 drawingSheet->SetIsFirstPage( aSch->RootScreen()->GetVirtualPageNumber() == 1 );
1206
1207 drawingSheet->SetSheetName( "" );
1208 drawingSheet->SetSheetPath( "" );
1209
1210 return drawingSheet;
1211}
const char * name
Definition: DXF_plotter.cpp:62
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
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)
Populate the list with a custom layout or the default layout if no custom layout is available.
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)
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:120
bool WriteTextReport(const wxString &aFullFileName)
Writes the text report also available via GetTextReport directly to a given file path.
Definition: erc_report.cpp:106
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:1817
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.
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
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
wxString m_libraryPath
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:248
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition: job.h:227
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: job.h:198
const std::map< wxString, wxString > & GetVarOverrides() const
Definition: job.h:191
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
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:198
@ FACE_CVPCB
Definition: kiway.h:295
Define a library symbol object.
Definition: lib_symbol.h:85
bool IsDerived() const
Definition: lib_symbol.h:207
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:638
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:680
wxString GetName() const override
Definition: lib_symbol.h:149
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:345
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:277
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: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
static bool EnsurePathExists(const wxString &aPath, bool aPathToFile=false)
Attempts to create a given path if it does not exist.
Definition: paths.cpp:484
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:75
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
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
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:103
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition: reporter.h:102
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition: reporter.h:140
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:87
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:102
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:311
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:317
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:219
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:888
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:213
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:105
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
A cache assistant for the KiCad s-expression symbol libraries.
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
virtual LIB_SYMBOL * GetSymbol(const wxString &aName)
void SetFileName(const wxString &aFileName)
const LIB_SYMBOL_MAP & GetSymbolMap() const
void SetModified(bool aModified=true)
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilepath)
Convert a schematic symbol library to the latest KiCad format.
Definition: sch_io_mgr.cpp:205
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:134
const wxString & GetFileName() const
Definition: sch_screen.h:147
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:158
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:75
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
Definition: sch_symbol.cpp:780
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:121
bool IsGeneratedField(const wxString &aSource)
Returns true if the string is generated, e.g contains a single text var reference.
Definition: common.cpp:134
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.
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
#define KICAD_FONT_NAME
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:485
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:486
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:893
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...
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
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:429
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:103
const double IU_PER_MILS
Definition: base_units.h:77
std::vector< wxString > m_plotPages
Definition: sch_plotter.h:58
wxString m_theme
Definition: sch_plotter.h:67
bool m_PDFPropertyPopups
Definition: sch_plotter.h:64
wxString m_outputDirectory
Definition: sch_plotter.h:69
wxString m_outputFile
Definition: sch_plotter.h:70
int m_pageSizeSelect
Definition: sch_plotter.h:62
bool m_PDFMetadata
Definition: sch_plotter.h:66
bool m_blackAndWhite
Definition: sch_plotter.h:61
bool m_PDFHierarchicalLinks
Definition: sch_plotter.h:65
bool m_plotHopOver
Definition: sch_plotter.h:60
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
Definition of file extensions used in Kicad.