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