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 <sch_screen.h>
39#include <wx/dir.h>
40#include <wx/file.h>
41#include <memory>
42#include <connection_graph.h>
43#include "eeschema_helpers.h"
44#include <filename_resolver.h>
45#include <kiway.h>
46#include <sch_painter.h>
47#include <locale_io.h>
48#include <erc/erc.h>
49#include <erc/erc_report.h>
53#include <paths.h>
54#include <reporter.h>
55#include <string_utils.h>
56
58
59#include <sch_file_versions.h>
60#include <sch_io/sch_io.h>
62
63#include <netlist.h>
73
74#include <fields_data_model.h>
75
80#include <confirm.h>
81#include <project_sch.h>
82
84
85
87 JOB_DISPATCHER( aKiway ),
88 m_cliSchematic( nullptr )
89{
90 Register( "bom",
91 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ),
92 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
93 {
94 JOB_EXPORT_SCH_BOM* bomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( job );
95
96 SCH_EDIT_FRAME* editFrame =
97 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
98
99 wxCHECK( bomJob && editFrame, false );
100
101 DIALOG_SYMBOL_FIELDS_TABLE dlg( editFrame, bomJob );
102 return dlg.ShowModal() == wxID_OK;
103 } );
104 Register( "pythonbom",
105 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, this, std::placeholders::_1 ),
106 []( JOB* job, wxWindow* aParent ) -> bool
107 {
108 return true;
109 } );
110 Register( "netlist",
111 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ),
112 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
113 {
114 JOB_EXPORT_SCH_NETLIST* netJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( job );
115
116 SCH_EDIT_FRAME* editFrame =
117 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
118
119 wxCHECK( netJob && editFrame, false );
120
121 DIALOG_EXPORT_NETLIST dlg( editFrame, aParent, netJob );
122 return dlg.ShowModal() == wxID_OK;
123 } );
124 Register( "plot",
125 std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPlot, this, std::placeholders::_1 ),
126 [aKiway]( JOB* job, wxWindow* aParent ) -> bool
127 {
128 JOB_EXPORT_SCH_PLOT* plotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( job );
129
130 SCH_EDIT_FRAME* editFrame =
131 static_cast<SCH_EDIT_FRAME*>( aKiway->Player( FRAME_SCH, false ) );
132
133 wxCHECK( plotJob && editFrame, false );
134
135 if( plotJob->m_plotFormat == SCH_PLOT_FORMAT::HPGL )
136 {
137 DisplayErrorMessage( editFrame,
138 _( "Plotting to HPGL is no longer supported as of KiCad 10.0." ) );
139 return false;
140 }
141
142 DIALOG_PLOT_SCHEMATIC dlg( editFrame, aParent, plotJob );
143 return dlg.ShowModal() == wxID_OK;
144 } );
145 Register( "symupgrade",
146 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymUpgrade, this, std::placeholders::_1 ),
147 []( JOB* job, wxWindow* aParent ) -> bool
148 {
149 return true;
150 } );
151 Register( "symsvg",
152 std::bind( &EESCHEMA_JOBS_HANDLER::JobSymExportSvg, this, std::placeholders::_1 ),
153 []( JOB* job, wxWindow* aParent ) -> bool
154 {
155 return true;
156 } );
157 Register( "erc", std::bind( &EESCHEMA_JOBS_HANDLER::JobSchErc, this, std::placeholders::_1 ),
158 []( JOB* job, wxWindow* aParent ) -> bool
159 {
160 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( job );
161
162 wxCHECK( ercJob, false );
163
164 DIALOG_ERC_JOB_CONFIG dlg( aParent, ercJob );
165 return dlg.ShowModal() == wxID_OK;
166 } );
167 Register( "upgrade", std::bind( &EESCHEMA_JOBS_HANDLER::JobUpgrade, this, std::placeholders::_1 ),
168 []( JOB* job, wxWindow* aParent ) -> bool
169 {
170 return true;
171 } );
172}
173
174
176{
177 SCHEMATIC* sch = nullptr;
178
179 if( !Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpenNotDummy() )
180 {
182 wxString schPath = aPath;
183
184 if( schPath.IsEmpty() )
185 {
186 wxFileName path = project.GetProjectFullName();
188 path.MakeAbsolute();
189 schPath = path.GetFullPath();
190 }
191
192 if( !m_cliSchematic )
193 m_cliSchematic = EESCHEMA_HELPERS::LoadSchematic( schPath, true, false, &project );
194
195 sch = m_cliSchematic;
196 }
197 else if( Pgm().IsGUI() && Pgm().GetSettingsManager().IsProjectOpen() )
198 {
199 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_kiway->Player( FRAME_SCH, false ) );
200
201 if( editFrame )
202 sch = &editFrame->Schematic();
203 }
204 else if( !aPath.IsEmpty() )
205 {
206 sch = EESCHEMA_HELPERS::LoadSchematic( aPath, true, false );
207 }
208
209 if( !sch )
210 m_reporter->Report( _( "Failed to load schematic\n" ), RPT_SEVERITY_ERROR );
211
212 return sch;
213}
214
216 const wxString& aTheme, SCHEMATIC* aSch,
217 const wxString& aDrawingSheetOverride )
218{
219 COLOR_SETTINGS* cs = ::GetColorSettings( aTheme );
220 aRenderSettings->LoadColors( cs );
221 aRenderSettings->m_ShowHiddenPins = false;
222 aRenderSettings->m_ShowHiddenFields = false;
223 aRenderSettings->m_ShowPinAltIcons = false;
224
225 aRenderSettings->SetDefaultPenWidth( aSch->Settings().m_DefaultLineWidth );
226 aRenderSettings->m_LabelSizeRatio = aSch->Settings().m_LabelSizeRatio;
227 aRenderSettings->m_TextOffsetRatio = aSch->Settings().m_TextOffsetRatio;
228 aRenderSettings->m_PinSymbolSize = aSch->Settings().m_PinSymbolSize;
229
230 aRenderSettings->SetDashLengthRatio( aSch->Settings().m_DashedLineDashRatio );
231 aRenderSettings->SetGapLengthRatio( aSch->Settings().m_DashedLineGapRatio );
232
233 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
234 // If empty, or not existing, the default drawing sheet is loaded.
235
236 auto loadSheet =
237 [&]( const wxString& path ) -> bool
238 {
239 wxString msg;
240 FILENAME_RESOLVER resolve;
241 resolve.SetProject( &aSch->Project() );
242 resolve.SetProgramBase( &Pgm() );
243
244 wxString absolutePath = resolve.ResolvePath( path, wxGetCwd(),
245 { aSch->GetEmbeddedFiles() } );
246
247 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath, &msg ) )
248 {
249 m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ), path )
250 + wxS( "\n" ) + msg + wxS( "\n" ),
252 return false;
253 }
254
255 return true;
256 };
257
258 // try to load the override first
259 if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
260 return;
261
262 // no override or failed override continues here
263 loadSheet( aSch->Settings().m_SchDrawingSheetFileName );
264}
265
266
268{
269 JOB_EXPORT_SCH_PLOT* aPlotJob = dynamic_cast<JOB_EXPORT_SCH_PLOT*>( aJob );
270
271 wxCHECK( aPlotJob, CLI::EXIT_CODES::ERR_UNKNOWN );
272
273 if( aPlotJob->m_plotFormat == SCH_PLOT_FORMAT::HPGL )
274 {
275 m_reporter->Report( _( "Plotting to HPGL is no longer supported as of KiCad 10.0.\n" ),
278 }
279
280 SCHEMATIC* sch = getSchematic( aPlotJob->m_filename );
281
282 if( !sch )
284
285 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
286 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
287
288 // Determine the variant to use. The CLI path populates m_variantNames directly, while
289 // the jobset path serializes into m_variant. Use whichever is available.
290 wxString variantName;
291
292 if( !aPlotJob->m_variantNames.empty() )
293 variantName = aPlotJob->m_variantNames.front();
294 else if( !aPlotJob->m_variant.IsEmpty() )
295 variantName = aPlotJob->m_variant;
296
297 if( !variantName.IsEmpty() && variantName != wxS( "all" ) )
298 sch->SetCurrentVariant( variantName );
299
300 std::unique_ptr<SCH_RENDER_SETTINGS> renderSettings = std::make_unique<SCH_RENDER_SETTINGS>();
301 InitRenderSettings( renderSettings.get(), aPlotJob->m_theme, sch, aPlotJob->m_drawingSheet );
302
303 wxString font = aPlotJob->m_defaultFont;
304
305 if( font.IsEmpty() )
306 {
308 font = cfg ? cfg->m_Appearance.default_font : wxString( KICAD_FONT_NAME );
309 }
310
311 renderSettings->SetDefaultFont( font );
312 renderSettings->SetMinPenWidth( aPlotJob->m_minPenWidth );
313
314 // Clear cached bounding boxes for all text items so they're recomputed with the correct
315 // default font. This is necessary because text bounding boxes may have been cached during
316 // schematic loading before the render settings (and thus default font) were configured.
317 SCH_SCREENS screens( sch->Root() );
318
319 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
320 {
321 for( SCH_ITEM* item : screen->Items() )
322 item->ClearCaches();
323
324 for( const auto& [libItemName, libSymbol] : screen->GetLibSymbols() )
325 libSymbol->ClearCaches();
326 }
327
328 std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
329
331
332 switch( aPlotJob->m_plotFormat )
333 {
334 case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF; break;
335 case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF; break;
336 case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG; break;
337 case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST; break;
338 case SCH_PLOT_FORMAT::HPGL: /* no longer supported */ break;
339 }
340
341 int pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
342
343 switch( aPlotJob->m_pageSizeSelect )
344 {
345 case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A; break;
346 case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4; break;
348 }
349
350 wxString outPath = aPlotJob->GetFullOutputPath( &sch->Project() );
351
352 if( !PATHS::EnsurePathExists( outPath, !aPlotJob->GetOutputPathIsDirectory() ) )
353 {
354 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
356 }
357
358 SCH_PLOT_OPTS plotOpts;
359 plotOpts.m_blackAndWhite = aPlotJob->m_blackAndWhite;
360 plotOpts.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups;
362 plotOpts.m_PDFMetadata = aPlotJob->m_PDFMetadata;
363
364 if( aPlotJob->GetOutputPathIsDirectory() )
365 {
366 plotOpts.m_outputDirectory = outPath;
367 plotOpts.m_outputFile = wxEmptyString;
368 }
369 else
370 {
371 plotOpts.m_outputDirectory = wxEmptyString;
372 plotOpts.m_outputFile = outPath;
373 }
374
375 plotOpts.m_pageSizeSelect = pageSizeSelect;
376 plotOpts.m_plotAll = aPlotJob->m_plotAll;
377 plotOpts.m_plotDrawingSheet = aPlotJob->m_plotDrawingSheet;
378 plotOpts.m_plotPages = aPlotJob->m_plotPages;
379 plotOpts.m_theme = aPlotJob->m_theme;
380 plotOpts.m_useBackgroundColor = aPlotJob->m_useBackgroundColor;
381 plotOpts.m_plotHopOver = aPlotJob->m_show_hop_over;
382
383 if( !variantName.IsEmpty() )
384 plotOpts.m_variant = variantName;
385
386 // Always export dxf in mm by kicad-cli (similar to Pcbnew)
388
389 schPlotter->Plot( format, plotOpts, renderSettings.get(), m_reporter );
390
391 if( m_reporter->HasMessageOfSeverity( RPT_SEVERITY_ERROR ) )
393
394 return CLI::EXIT_CODES::OK;
395}
396
397
399{
400 JOB_EXPORT_SCH_NETLIST* aNetJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( aJob );
401
402 wxCHECK( aNetJob, CLI::EXIT_CODES::ERR_UNKNOWN );
403
404 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
405
406 if( !sch )
408
409 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
410 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
411
412 // Apply variant if specified
413 if( !aNetJob->m_variantNames.empty() )
414 {
415 // For netlist export, we use the first variant name from the set
416 wxString variantName = *aNetJob->m_variantNames.begin();
417
418 if( variantName != wxS( "all" ) )
419 sch->SetCurrentVariant( variantName );
420 }
421
422 // Annotation warning check
423 SCH_REFERENCE_LIST referenceList;
424 sch->Hierarchy().GetSymbols( referenceList );
425
426 if( referenceList.GetCount() > 0 )
427 {
428 if( referenceList.CheckAnnotation(
429 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
430 {
431 // We're only interested in the end result -- either errors or not
432 } )
433 > 0 )
434 {
435 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
436 "schematic editor to fix them\n" ),
438 }
439 }
440
441 // Test duplicate sheet names:
442 ERC_TESTER erc( sch );
443
444 if( erc.TestDuplicateSheetNames( false ) > 0 )
445 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
446
447 std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
448 unsigned netlistOption = 0;
449
450 wxString fileExt;
451
452 switch( aNetJob->format )
453 {
456 helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
457 break;
458
461 helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
462 break;
463
466 helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
467 break;
468
472 helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
473 break;
474
477 helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
478 break;
479
481 fileExt = wxS( "xml" );
482 helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
483 break;
484
486 fileExt = wxS( "asc" );
487 helper = std::make_unique<NETLIST_EXPORTER_PADS>( sch );
488 break;
489
491 fileExt = wxS( "txt" );
492 helper = std::make_unique<NETLIST_EXPORTER_ALLEGRO>( sch );
493 break;
494
495 default:
496 m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR );
498 }
499
500 if( aNetJob->GetConfiguredOutputPath().IsEmpty() )
501 {
502 wxFileName fn = sch->GetFileName();
503 fn.SetName( fn.GetName() );
504 fn.SetExt( fileExt );
505
506 aNetJob->SetConfiguredOutputPath( fn.GetFullName() );
507 }
508
509 wxString outPath = aNetJob->GetFullOutputPath( &sch->Project() );
510
511 if( !PATHS::EnsurePathExists( outPath, true ) )
512 {
513 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
515 }
516
517 bool res = helper->WriteNetlist( outPath, netlistOption, *m_reporter );
518
519 if( !res )
521
522 return CLI::EXIT_CODES::OK;
523}
524
525
527{
528 JOB_EXPORT_SCH_BOM* aBomJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( aJob );
529
530 wxCHECK( aBomJob, CLI::EXIT_CODES::ERR_UNKNOWN );
531
532 SCHEMATIC* sch = getSchematic( aBomJob->m_filename );
533
534 if( !sch )
536
537 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
538 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
539
540 wxString currentVariant;
541
542 if( !aBomJob->m_variantNames.empty() )
543 {
544 currentVariant = aBomJob->m_variantNames.front();
545
546 if( currentVariant != wxS( "all" ) )
547 sch->SetCurrentVariant( currentVariant );
548 }
549
550 // Annotation warning check
551 SCH_REFERENCE_LIST referenceList;
552 sch->Hierarchy().GetSymbols( referenceList, false, false );
553
554 if( referenceList.GetCount() > 0 )
555 {
556 SCH_REFERENCE_LIST copy = referenceList;
557
558 // Check annotation splits references...
559 if( copy.CheckAnnotation(
560 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
561 {
562 // We're only interested in the end result -- either errors or not
563 } )
564 > 0 )
565 {
566 m_reporter->Report(
567 _( "Warning: schematic has annotation errors, please use the schematic "
568 "editor to fix them\n" ),
570 }
571 }
572
573 // Test duplicate sheet names:
574 ERC_TESTER erc( sch );
575
576 if( erc.TestDuplicateSheetNames( false ) > 0 )
577 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
578
579 // Build our data model
580 FIELDS_EDITOR_GRID_DATA_MODEL dataModel( referenceList, nullptr );
581
582 // Mandatory fields first
583 for( FIELD_T fieldId : MANDATORY_FIELDS )
584 {
585 dataModel.AddColumn( GetCanonicalFieldName( fieldId ),
586 GetDefaultFieldName( fieldId, DO_TRANSLATE ), false, currentVariant );
587 }
588
589 // Generated/virtual fields (e.g. ${QUANTITY}, ${ITEM_NUMBER}) present only in the fields table
592 false, currentVariant );
595 false, currentVariant );
596
597 // Attribute fields (boolean flags on symbols)
598 dataModel.AddColumn( wxS( "${DNP}" ), GetGeneratedFieldDisplayName( wxS( "${DNP}" ) ),
599 false, currentVariant );
600 dataModel.AddColumn( wxS( "${EXCLUDE_FROM_BOM}" ), GetGeneratedFieldDisplayName( wxS( "${EXCLUDE_FROM_BOM}" ) ),
601 false, currentVariant );
602 dataModel.AddColumn( wxS( "${EXCLUDE_FROM_BOARD}" ), GetGeneratedFieldDisplayName( wxS( "${EXCLUDE_FROM_BOARD}" ) ),
603 false, currentVariant );
604 dataModel.AddColumn( wxS( "${EXCLUDE_FROM_SIM}" ), GetGeneratedFieldDisplayName( wxS( "${EXCLUDE_FROM_SIM}" ) ),
605 false, currentVariant );
606
607 // User field names in symbols second
608 std::set<wxString> userFieldNames;
609
610 for( size_t i = 0; i < referenceList.GetCount(); ++i )
611 {
612 SCH_SYMBOL* symbol = referenceList[i].GetSymbol();
613
614 for( SCH_FIELD& field : symbol->GetFields() )
615 {
616 if( !field.IsMandatory() && !field.IsPrivate() )
617 userFieldNames.insert( field.GetName() );
618 }
619 }
620
621 for( const wxString& fieldName : userFieldNames )
622 dataModel.AddColumn( fieldName, GetGeneratedFieldDisplayName( fieldName ), true, currentVariant );
623
624 // Add any templateFieldNames which aren't already present in the userFieldNames
625 for( const TEMPLATE_FIELDNAME& templateFieldname :
627 {
628 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
629 {
630 dataModel.AddColumn( templateFieldname.m_Name, GetGeneratedFieldDisplayName( templateFieldname.m_Name ),
631 false, currentVariant );
632 }
633 }
634
635 BOM_PRESET preset;
636
637 // Load a preset if one is specified
638 if( !aBomJob->m_bomPresetName.IsEmpty() )
639 {
640 // Find the preset
641 const BOM_PRESET* schPreset = nullptr;
642
643 for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
644 {
645 if( p.name == aBomJob->m_bomPresetName )
646 {
647 schPreset = &p;
648 break;
649 }
650 }
651
652 for( const BOM_PRESET& p : sch->Settings().m_BomPresets )
653 {
654 if( p.name == aBomJob->m_bomPresetName )
655 {
656 schPreset = &p;
657 break;
658 }
659 }
660
661 if( !schPreset )
662 {
663 m_reporter->Report( wxString::Format( _( "BOM preset '%s' not found" ) + wxS( "\n" ),
664 aBomJob->m_bomPresetName ),
666
668 }
669
670 preset = *schPreset;
671 }
672 else
673 {
674 size_t i = 0;
675
676 for( const wxString& fieldName : aBomJob->m_fieldsOrdered )
677 {
678 // Handle wildcard. We allow the wildcard anywhere in the list, but it needs to respect
679 // fields that come before and after the wildcard.
680 if( fieldName == wxS( "*" ) )
681 {
682 for( const BOM_FIELD& modelField : dataModel.GetFieldsOrdered() )
683 {
684 struct BOM_FIELD field;
685
686 field.name = modelField.name;
687 field.show = true;
688 field.groupBy = false;
689 field.label = field.name;
690
691 bool fieldAlreadyPresent = false;
692
693 for( BOM_FIELD& presetField : preset.fieldsOrdered )
694 {
695 if( presetField.name == field.name )
696 {
697 fieldAlreadyPresent = true;
698 break;
699 }
700 }
701
702 bool fieldLaterInList = false;
703
704 for( const wxString& fieldInList : aBomJob->m_fieldsOrdered )
705 {
706 if( fieldInList == field.name )
707 {
708 fieldLaterInList = true;
709 break;
710 }
711 }
712
713 if( !fieldAlreadyPresent && !fieldLaterInList )
714 preset.fieldsOrdered.emplace_back( field );
715 }
716
717 continue;
718 }
719
720 struct BOM_FIELD field;
721
722 field.name = fieldName;
723 field.show = !fieldName.StartsWith( wxT( "__" ), &field.name );
724 field.groupBy = alg::contains( aBomJob->m_fieldsGroupBy, field.name );
725
726 if( ( aBomJob->m_fieldsLabels.size() > i ) && !aBomJob->m_fieldsLabels[i].IsEmpty() )
727 field.label = aBomJob->m_fieldsLabels[i];
728 else if( IsGeneratedField( field.name ) )
729 field.label = GetGeneratedFieldDisplayName( field.name );
730 else
731 field.label = field.name;
732
733 preset.fieldsOrdered.emplace_back( field );
734 i++;
735 }
736
737 preset.sortAsc = aBomJob->m_sortAsc;
738 preset.sortField = aBomJob->m_sortField;
739 preset.filterString = aBomJob->m_filterString;
740 preset.groupSymbols = aBomJob->m_groupSymbols;
741 preset.excludeDNP = aBomJob->m_excludeDNP;
742 }
743
744 BOM_FMT_PRESET fmt;
745
746 // Load a format preset if one is specified
747 if( !aBomJob->m_bomFmtPresetName.IsEmpty() )
748 {
749 std::optional<BOM_FMT_PRESET> schFmtPreset;
750
752 {
753 if( p.name == aBomJob->m_bomFmtPresetName )
754 {
755 schFmtPreset = p;
756 break;
757 }
758 }
759
760 for( const BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
761 {
762 if( p.name == aBomJob->m_bomFmtPresetName )
763 {
764 schFmtPreset = p;
765 break;
766 }
767 }
768
769 if( !schFmtPreset )
770 {
771 m_reporter->Report( wxString::Format( _( "BOM format preset '%s' not found" ) + wxS( "\n" ),
772 aBomJob->m_bomFmtPresetName ),
774
776 }
777
778 fmt = *schFmtPreset;
779 }
780 else
781 {
782 fmt.fieldDelimiter = aBomJob->m_fieldDelimiter;
783 fmt.stringDelimiter = aBomJob->m_stringDelimiter;
784 fmt.refDelimiter = aBomJob->m_refDelimiter;
786 fmt.keepTabs = aBomJob->m_keepTabs;
787 fmt.keepLineBreaks = aBomJob->m_keepLineBreaks;
788 }
789
790 if( aBomJob->GetConfiguredOutputPath().IsEmpty() )
791 {
792 wxFileName fn = sch->GetFileName();
793 fn.SetName( fn.GetName() );
794 fn.SetExt( FILEEXT::CsvFileExtension );
795
796 aBomJob->SetConfiguredOutputPath( fn.GetFullName() );
797 }
798
799 wxString configuredPath = aBomJob->GetConfiguredOutputPath();
800 bool hasVariantPlaceholder = configuredPath.Contains( wxS( "${VARIANT}" ) );
801
802 // Determine which variants to process
803 std::vector<wxString> variantsToProcess;
804
805 if( aBomJob->m_variantNames.size() > 1 && hasVariantPlaceholder )
806 {
807 variantsToProcess = aBomJob->m_variantNames;
808 }
809 else
810 {
811 variantsToProcess.push_back( currentVariant );
812 }
813
814 for( const wxString& variantName : variantsToProcess )
815 {
816 std::vector<wxString> singleVariant = { variantName };
817 dataModel.SetVariantNames( singleVariant );
818 dataModel.SetCurrentVariant( variantName );
819 dataModel.ApplyBomPreset( preset, variantName );
820
821 wxString outPath;
822
823 if( hasVariantPlaceholder )
824 {
825 wxString variantPath = configuredPath;
826 variantPath.Replace( wxS( "${VARIANT}" ), variantName );
827 aBomJob->SetConfiguredOutputPath( variantPath );
828 outPath = aBomJob->GetFullOutputPath( &sch->Project() );
829 aBomJob->SetConfiguredOutputPath( configuredPath );
830 }
831 else
832 {
833 outPath = aBomJob->GetFullOutputPath( &sch->Project() );
834 }
835
836 if( !PATHS::EnsurePathExists( outPath, true ) )
837 {
838 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
840 }
841
842 wxFile f;
843
844 if( !f.Open( outPath, wxFile::write ) )
845 {
846 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ), outPath ),
848
850 }
851
852 bool res = f.Write( dataModel.Export( fmt ) );
853
854 if( !res )
856
857 m_reporter->Report( wxString::Format( _( "Wrote bill of materials to '%s'." ), outPath ),
859 }
860
861 return CLI::EXIT_CODES::OK;
862}
863
864
866{
867 JOB_EXPORT_SCH_PYTHONBOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_PYTHONBOM*>( aJob );
868
869 wxCHECK( aNetJob, CLI::EXIT_CODES::ERR_UNKNOWN );
870
871 SCHEMATIC* sch = getSchematic( aNetJob->m_filename );
872
873 if( !sch )
875
876 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
877 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
878
879 // Annotation warning check
880 SCH_REFERENCE_LIST referenceList;
881 sch->Hierarchy().GetSymbols( referenceList );
882
883 if( referenceList.GetCount() > 0 )
884 {
885 if( referenceList.CheckAnnotation(
886 []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* )
887 {
888 // We're only interested in the end result -- either errors or not
889 } )
890 > 0 )
891 {
892 m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
893 "schematic editor to fix them\n" ),
895 }
896 }
897
898 // Test duplicate sheet names:
899 ERC_TESTER erc( sch );
900
901 if( erc.TestDuplicateSheetNames( false ) > 0 )
902 m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
903
904 std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
905 std::make_unique<NETLIST_EXPORTER_XML>( sch );
906
907 if( aNetJob->GetConfiguredOutputPath().IsEmpty() )
908 {
909 wxFileName fn = sch->GetFileName();
910 fn.SetName( fn.GetName() + "-bom" );
911 fn.SetExt( FILEEXT::XmlFileExtension );
912
913 aNetJob->SetConfiguredOutputPath( fn.GetFullName() );
914 }
915
916 wxString outPath = aNetJob->GetFullOutputPath( &sch->Project() );
917
918 if( !PATHS::EnsurePathExists( outPath, true ) )
919 {
920 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
922 }
923
924 bool res = xmlNetlist->WriteNetlist( outPath, GNL_OPT_BOM, *m_reporter );
925
926 if( !res )
928
929 m_reporter->Report( wxString::Format( _( "Wrote bill of materials to '%s'." ), outPath ),
931
932 return CLI::EXIT_CODES::OK;
933}
934
935
937 LIB_SYMBOL* symbol )
938{
939 wxCHECK( symbol, CLI::EXIT_CODES::ERR_UNKNOWN );
940
941 std::shared_ptr<LIB_SYMBOL> parent;
942 LIB_SYMBOL* symbolToPlot = symbol;
943
944 // if the symbol is an alias, then the draw items are stored in the root symbol
945 if( symbol->IsDerived() )
946 {
947 parent = symbol->GetRootSymbol();
948
949 wxCHECK( parent, CLI::EXIT_CODES::ERR_UNKNOWN );
950
951 symbolToPlot = parent.get();
952 }
953
954 // iterate from unit 1, unit 0 would be "all units" which we don't want
955 for( int unit = 1; unit < symbol->GetUnitCount() + 1; unit++ )
956 {
957 for( int bodyStyle = 1; bodyStyle <= symbol->GetBodyStyleCount(); ++bodyStyle )
958 {
959 wxString filename;
960 wxFileName fn;
961
962 fn.SetPath( aSvgJob->m_outputDirectory );
963 fn.SetExt( FILEEXT::SVGFileExtension );
964
965 filename = symbol->GetName();
966
967 for( wxChar c : wxFileName::GetForbiddenChars( wxPATH_DOS ) )
968 filename.Replace( c, ' ' );
969
970 // Even single units get a unit number in the filename. This simplifies the
971 // handling of the files as they have a uniform pattern.
972 // Also avoids aliasing 'sym', unit 2 and 'sym_unit2', unit 1 to the same file.
973 filename += wxString::Format( "_unit%d", unit );
974
975 if( symbol->HasDeMorganBodyStyles() )
976 {
977 if( bodyStyle == 2 )
978 filename += wxS( "_demorgan" );
979 }
980 else if( bodyStyle <= (int) symbol->GetBodyStyleNames().size() )
981 {
982 filename += wxS( "_" ) + symbol->GetBodyStyleNames()[bodyStyle-1].Lower();
983 }
984
985 fn.SetName( filename );
986 m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ),
987 symbol->GetName(),
988 unit,
989 fn.GetFullPath() ),
991
992 // Get the symbol bounding box to fit the plot page to it
993 BOX2I symbolBB = symbol->Flatten()->GetUnitBoundingBox( unit, bodyStyle,
994 !aSvgJob->m_includeHiddenFields );
996 pageInfo.SetHeightMils( schIUScale.IUToMils( symbolBB.GetHeight() * 1.2 ) );
997 pageInfo.SetWidthMils( schIUScale.IUToMils( symbolBB.GetWidth() * 1.2 ) );
998
999 SVG_PLOTTER* plotter = new SVG_PLOTTER();
1000 plotter->SetRenderSettings( aRenderSettings );
1001 plotter->SetPageSettings( pageInfo );
1002 plotter->SetColorMode( !aSvgJob->m_blackAndWhite );
1003
1004 VECTOR2I plot_offset = symbolBB.GetCenter();
1005 const double scale = 1.0;
1006
1007 // Currently, plot units are in decimal
1008 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, scale, false );
1009
1010 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
1011
1012 if( !plotter->OpenFile( fn.GetFullPath() ) )
1013 {
1014 m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ) + wxS( "\n" ),
1015 fn.GetFullPath() ),
1017
1018 delete plotter;
1020 }
1021
1022 LOCALE_IO toggle;
1023 SCH_PLOT_OPTS plotOpts;
1024
1025 plotter->StartPlot( wxT( "1" ) );
1026
1027 bool background = true;
1028 VECTOR2I offset( pageInfo.GetWidthIU( schIUScale.IU_PER_MILS ) / 2,
1029 pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) / 2 );
1030
1031 // note, we want the fields from the original symbol pointer (in case of non-alias)
1032 symbolToPlot->Plot( plotter, background, plotOpts, unit, bodyStyle, offset, false );
1033 symbol->PlotFields( plotter, background, plotOpts, unit, bodyStyle, offset, false );
1034
1035 symbolToPlot->Plot( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
1036 symbol->PlotFields( plotter, !background, plotOpts, unit, bodyStyle, offset, false );
1037
1038 plotter->EndPlot();
1039 delete plotter;
1040 }
1041 }
1042
1043 if( m_reporter->HasMessageOfSeverity( RPT_SEVERITY_ERROR ) )
1045
1046 return CLI::EXIT_CODES::OK;
1047}
1048
1049
1051{
1052 JOB_SYM_EXPORT_SVG* svgJob = dynamic_cast<JOB_SYM_EXPORT_SVG*>( aJob );
1053
1054 wxCHECK( svgJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1055
1056 wxFileName fn( svgJob->m_libraryPath );
1057 fn.MakeAbsolute();
1058
1059 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
1060
1061 try
1062 {
1063 schLibrary.Load();
1064 }
1065 catch( ... )
1066 {
1067 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
1069 }
1070
1071 if( m_progressReporter )
1072 m_progressReporter->KeepRefreshing();
1073
1074 LIB_SYMBOL* symbol = nullptr;
1075
1076 if( !svgJob->m_symbol.IsEmpty() )
1077 {
1078 // See if the selected symbol exists
1079 symbol = schLibrary.GetSymbol( svgJob->m_symbol );
1080
1081 if( !symbol )
1082 {
1083 m_reporter->Report( _( "There is no symbol selected to save." ) + wxS( "\n" ),
1086 }
1087 }
1088
1089 if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) )
1090 {
1091 if( !wxFileName::Mkdir( svgJob->m_outputDirectory ) )
1092 {
1093 m_reporter->Report( wxString::Format( _( "Unable to create output directory '%s'." ) + wxS( "\n" ),
1094 svgJob->m_outputDirectory ),
1097 }
1098 }
1099
1100 SCH_RENDER_SETTINGS renderSettings;
1102 renderSettings.LoadColors( cs );
1103 renderSettings.SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS );
1104 renderSettings.m_ShowHiddenPins = svgJob->m_includeHiddenPins;
1105 renderSettings.m_ShowHiddenFields = svgJob->m_includeHiddenFields;
1106
1107 int exitCode = CLI::EXIT_CODES::OK;
1108
1109 if( symbol )
1110 {
1111 exitCode = doSymExportSvg( svgJob, &renderSettings, symbol );
1112 }
1113 else
1114 {
1115 // Just plot all the symbols we can
1116 const LIB_SYMBOL_MAP& libSymMap = schLibrary.GetSymbolMap();
1117
1118 for( const auto& [name, libSymbol] : libSymMap )
1119 {
1120 if( m_progressReporter )
1121 {
1122 m_progressReporter->AdvancePhase( wxString::Format( _( "Exporting %s" ), name ) );
1123 m_progressReporter->KeepRefreshing();
1124 }
1125
1126 exitCode = doSymExportSvg( svgJob, &renderSettings, libSymbol );
1127
1128 if( exitCode != CLI::EXIT_CODES::OK )
1129 break;
1130 }
1131 }
1132
1133 return exitCode;
1134}
1135
1136
1138{
1139 JOB_SYM_UPGRADE* upgradeJob = dynamic_cast<JOB_SYM_UPGRADE*>( aJob );
1140
1141 wxCHECK( upgradeJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1142
1143 wxFileName fn( upgradeJob->m_libraryPath );
1144 fn.MakeAbsolute();
1145
1146 SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
1147
1148 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1149 {
1150 if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) )
1151 {
1152 m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
1154
1156 }
1157 }
1158 else if( fileType != SCH_IO_MGR::SCH_KICAD )
1159 {
1160 m_reporter->Report( _( "Output path must be specified to convert legacy and non-KiCad libraries\n" ),
1162
1164 }
1165
1166 if( fileType == SCH_IO_MGR::SCH_KICAD )
1167 {
1168 SCH_IO_KICAD_SEXPR_LIB_CACHE schLibrary( fn.GetFullPath() );
1169
1170 try
1171 {
1172 schLibrary.Load();
1173 }
1174 catch( ... )
1175 {
1176 m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
1178 }
1179
1180 if( m_progressReporter )
1181 m_progressReporter->KeepRefreshing();
1182
1183 bool shouldSave =
1185
1186 if( shouldSave )
1187 {
1188 m_reporter->Report( _( "Saving symbol library in updated format\n" ), RPT_SEVERITY_ACTION );
1189
1190 try
1191 {
1192 if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
1193 schLibrary.SetFileName( upgradeJob->m_outputLibraryPath );
1194
1195 schLibrary.SetModified();
1196 schLibrary.Save();
1197 }
1198 catch( ... )
1199 {
1200 m_reporter->Report( ( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
1202 }
1203 }
1204 else
1205 {
1206 m_reporter->Report( _( "Symbol library was not updated\n" ), RPT_SEVERITY_ERROR );
1207 }
1208 }
1209 else
1210 {
1211 if( !SCH_IO_MGR::ConvertLibrary( nullptr, fn.GetAbsolutePath(), upgradeJob->m_outputLibraryPath ) )
1212 {
1213 m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR );
1215 }
1216 }
1217
1218 return CLI::EXIT_CODES::OK;
1219}
1220
1221
1222
1224{
1225 JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( aJob );
1226
1227 wxCHECK( ercJob, CLI::EXIT_CODES::ERR_UNKNOWN );
1228
1229 SCHEMATIC* sch = getSchematic( ercJob->m_filename );
1230
1231 if( !sch )
1233
1234 aJob->SetTitleBlock( sch->RootScreen()->GetTitleBlock() );
1235 sch->Project().ApplyTextVars( aJob->GetVarOverrides() );
1236
1237 if( ercJob->GetConfiguredOutputPath().IsEmpty() )
1238 {
1239 wxFileName fn = sch->GetFileName();
1240 fn.SetName( fn.GetName() + wxS( "-erc" ) );
1241
1243 fn.SetExt( FILEEXT::JsonFileExtension );
1244 else
1245 fn.SetExt( FILEEXT::ReportFileExtension );
1246
1247 ercJob->SetConfiguredOutputPath( fn.GetFullName() );
1248 }
1249
1250 wxString outPath = ercJob->GetFullOutputPath( &sch->Project() );
1251
1252 if( !PATHS::EnsurePathExists( outPath, true ) )
1253 {
1254 m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
1256 }
1257
1258 EDA_UNITS units;
1259
1260 switch( ercJob->m_units )
1261 {
1262 case JOB_SCH_ERC::UNITS::INCH: units = EDA_UNITS::INCH; break;
1263 case JOB_SCH_ERC::UNITS::MILS: units = EDA_UNITS::MILS; break;
1264 case JOB_SCH_ERC::UNITS::MM: units = EDA_UNITS::MM; break;
1265 default: units = EDA_UNITS::MM; break;
1266 }
1267
1268 std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
1269 std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
1270
1271 // Running ERC requires libraries be loaded, so make sure they have been
1273 adapter->AsyncLoad();
1274 adapter->BlockUntilLoaded();
1275
1276 ERC_TESTER ercTester( sch );
1277
1278 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet( getDrawingSheetProxyView( sch ) );
1279 ercTester.RunTests( drawingSheet.get(), nullptr, m_kiway->KiFACE( KIWAY::FACE_CVPCB ),
1280 &sch->Project(), m_progressReporter );
1281
1282 markersProvider->SetSeverities( ercJob->m_severity );
1283
1284 m_reporter->Report( wxString::Format( _( "Found %d violations\n" ), markersProvider->GetCount() ),
1286
1287 ERC_REPORT reportWriter( sch, units, markersProvider );
1288
1289 bool wroteReport = false;
1290
1292 wroteReport = reportWriter.WriteJsonReport( outPath );
1293 else
1294 wroteReport = reportWriter.WriteTextReport( outPath );
1295
1296 if( !wroteReport )
1297 {
1298 m_reporter->Report( wxString::Format( _( "Unable to save ERC report to %s\n" ), outPath ),
1301 }
1302
1303 m_reporter->Report( wxString::Format( _( "Saved ERC Report to %s\n" ), outPath ),
1305
1306 if( ercJob->m_exitCodeViolations )
1307 {
1308 if( markersProvider->GetCount() > 0 )
1310 }
1311
1313}
1314
1315
1317{
1318 JOB_SCH_UPGRADE* aUpgradeJob = dynamic_cast<JOB_SCH_UPGRADE*>( aJob );
1319
1320 if( aUpgradeJob == nullptr )
1322
1323 SCHEMATIC* sch = getSchematic( aUpgradeJob->m_filename );
1324
1325 if( !sch )
1327
1328 bool shouldSave = aUpgradeJob->m_force;
1329
1331 shouldSave = true;
1332
1333 if( !shouldSave )
1334 {
1335 m_reporter->Report( _( "Schematic file was not updated\n" ), RPT_SEVERITY_ERROR );
1337 }
1338
1339 // needs an absolute path
1340 wxFileName schPath( aUpgradeJob->m_filename );
1341 schPath.MakeAbsolute();
1342 const wxString schFullPath = schPath.GetFullPath();
1343
1344 try
1345 {
1346 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
1347 SCH_SHEET* loadedSheet = pi->LoadSchematicFile( schFullPath, sch );
1348 pi->SaveSchematicFile( schFullPath, loadedSheet, sch );
1349 }
1350 catch( const IO_ERROR& ioe )
1351 {
1352 wxString msg =
1353 wxString::Format( _( "Error saving schematic file '%s'.\n%s" ), schFullPath, ioe.What().GetData() );
1354 m_reporter->Report( msg, RPT_SEVERITY_ERROR );
1356 }
1357
1358 m_reporter->Report( _( "Successfully saved schematic file using the latest format\n" ), RPT_SEVERITY_INFO );
1359
1361}
1362
1363
1365{
1366 DS_PROXY_VIEW_ITEM* drawingSheet =
1368 &aSch->Project(), &aSch->RootScreen()->GetTitleBlock(),
1369 aSch->GetProperties() );
1370
1371 drawingSheet->SetPageNumber( TO_UTF8( aSch->RootScreen()->GetPageNumber() ) );
1372 drawingSheet->SetSheetCount( aSch->RootScreen()->GetPageCount() );
1373 drawingSheet->SetFileName( TO_UTF8( aSch->RootScreen()->GetFileName() ) );
1376 drawingSheet->SetIsFirstPage( aSch->RootScreen()->GetVirtualPageNumber() == 1 );
1377
1378 drawingSheet->SetSheetName( "" );
1379 drawingSheet->SetSheetPath( "" );
1380
1381 return drawingSheet;
1382}
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, bool aCalculateConnectivity=true)
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:2054
void AddColumn(const wxString &aFieldName, const wxString &aLabel, bool aAddedByUser, const wxString &aVariantName)
wxString Export(const BOM_FMT_PRESET &settings)
void ApplyBomPreset(const BOM_PRESET &preset, const wxString &aVariantName)
static const wxString ITEM_NUMBER_VARIABLE
void SetVariantNames(const std::vector< wxString > &aVariantNames)
static const wxString QUANTITY_VARIABLE
std::vector< BOM_FIELD > GetFieldsOrdered()
void SetCurrentVariant(const wxString &aVariantName)
Set the current variant name for highlighting purposes.
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
std::vector< wxString > m_variantNames
std::vector< wxString > m_variantNames
JOB_PAGE_SIZE m_pageSizeSelect
SCH_PLOT_FORMAT m_plotFormat
std::vector< wxString > m_variantNames
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:184
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition job.cpp:157
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
Definition job.cpp:150
bool GetOutputPathIsDirectory() const
Definition job.h:256
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition job.h:233
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition job.h:204
const std::map< wxString, wxString > & GetVarOverrides() const
Definition job.h:197
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:295
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:407
@ FACE_CVPCB
Definition kiway.h:304
void AsyncLoad()
Loads all available libraries for this adapter type in the background.
Define a library symbol object.
Definition lib_symbol.h:83
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:203
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
void PlotFields(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed)
Plot symbol fields.
std::shared_ptr< LIB_SYMBOL > GetRootSymbol() const
Get the parent symbol that does not have another parent.
wxString GetName() const override
Definition lib_symbol.h:145
const std::vector< wxString > & GetBodyStyleNames() const
Definition lib_symbol.h:787
bool HasDeMorganBodyStyles() const override
Definition lib_symbol.h:784
int GetBodyStyleCount() const override
Definition lib_symbol.h:776
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h: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:508
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:131
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition plotter.cpp:77
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition plotter.h:169
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition plotter.h:166
virtual void SetCreator(const wxString &aCreator)
Definition plotter.h:188
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition plotter.h:163
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
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:126
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
void SetCurrentVariant(const wxString &aVariantName)
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
SCH_SHEET & Root() const
Definition schematic.h:132
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.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
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
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:749
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:141
const wxString & GetFileName() const
Definition sch_screen.h:154
int GetFileFormatVersionAtLoad() const
Definition sch_screen.h:139
const TITLE_BLOCK & GetTitleBlock() const
Definition sch_screen.h:165
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:48
Schematic symbol object.
Definition sch_symbol.h:76
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
An interface to the global shared library manager that is schematic-specific and linked to one projec...
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:323
bool IsGeneratedField(const wxString &aSource)
Returns true if the string is generated, e.g contains a single text var reference.
Definition common.cpp:335
The common library.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
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:496
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition layer_ids.h:497
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.
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:74
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
wxString m_variant
Definition sch_plotter.h:71
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)
std::string path
VECTOR3I res
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
Definition of file extensions used in Kicad.