73 std::placeholders::_1 ) );
89 const wxString& aDrawingSheetOverride )
105 auto loadSheet = [&](
const wxString&
path ) ->
bool
107 wxString resolvedSheetPath =
121 if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
148 std::unique_ptr<KIGFX::SCH_RENDER_SETTINGS> renderSettings =
149 std::make_unique<KIGFX::SCH_RENDER_SETTINGS>();
152 std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
157 case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF;
break;
158 case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF;
break;
159 case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG;
break;
160 case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST;
break;
161 case SCH_PLOT_FORMAT::HPGL: format = PLOT_FORMAT::HPGL;
break;
162 case SCH_PLOT_FORMAT::GERBER: format = PLOT_FORMAT::GERBER;
break;
168 case JOB_HPGL_PAGE_SIZE::DEFAULT: hpglPageSize = HPGL_PAGE_SIZE::DEFAULT;
break;
169 case JOB_HPGL_PAGE_SIZE::SIZE_A: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A;
break;
170 case JOB_HPGL_PAGE_SIZE::SIZE_A0: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A0;
break;
171 case JOB_HPGL_PAGE_SIZE::SIZE_A1: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A1;
break;
172 case JOB_HPGL_PAGE_SIZE::SIZE_A2: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A2;
break;
173 case JOB_HPGL_PAGE_SIZE::SIZE_A3: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A3;
break;
174 case JOB_HPGL_PAGE_SIZE::SIZE_A4: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A4;
break;
175 case JOB_HPGL_PAGE_SIZE::SIZE_A5: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A5;
break;
176 case JOB_HPGL_PAGE_SIZE::SIZE_B: hpglPageSize = HPGL_PAGE_SIZE::SIZE_B;
break;
177 case JOB_HPGL_PAGE_SIZE::SIZE_C: hpglPageSize = HPGL_PAGE_SIZE::SIZE_C;
break;
178 case JOB_HPGL_PAGE_SIZE::SIZE_D: hpglPageSize = HPGL_PAGE_SIZE::SIZE_D;
break;
179 case JOB_HPGL_PAGE_SIZE::SIZE_E: hpglPageSize = HPGL_PAGE_SIZE::SIZE_E;
break;
185 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT:
186 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT;
189 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER:
190 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER;
192 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT:
193 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT;
195 case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE:
196 hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE;
200 int pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
204 case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A;
break;
205 case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4;
break;
206 case JOB_PAGE_SIZE::PAGE_SIZE_AUTO: pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO;
break;
224 schPlotter->Plot( format, settings, renderSettings.get(),
m_reporter );
258 m_reporter->
Report(
_(
"Warning: schematic has annotation errors, please use the "
259 "schematic editor to fix them\n" ),
267 if(
erc.TestDuplicateSheetNames(
false ) > 0 )
273 std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
274 unsigned netlistOption = 0;
282 helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
287 helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
292 helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
298 helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
303 helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
307 fileExt = wxS(
"xml" );
308 helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
318 fn.SetName( fn.GetName() );
319 fn.SetExt( fileExt );
361 if(
copy.CheckAnnotation(
369 _(
"Warning: schematic has annotation errors, please use the schematic "
370 "editor to fix them\n" ),
378 if(
erc.TestDuplicateSheetNames(
false ) > 0 )
392 std::set<wxString> userFieldNames;
394 for(
size_t i = 0; i < referenceList.
GetCount(); ++i )
396 SCH_SYMBOL* symbol = referenceList[i].GetSymbol();
399 userFieldNames.insert( symbol->
GetFields()[j].GetName() );
402 for(
const wxString& fieldName : userFieldNames )
409 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
438 wxString::Format(
_(
"BOM preset '%s' not found" ), aBomJob->
m_bomPresetName ),
454 if( fieldName == wxS(
"*" ) )
460 field.
name = modelField.name;
465 bool fieldAlreadyPresent =
false;
468 if( presetField.
name == field.
name )
470 fieldAlreadyPresent =
true;
475 bool fieldLaterInList =
false;
478 if( fieldInList == field.
name )
480 fieldLaterInList =
true;
485 if( !fieldAlreadyPresent && !fieldLaterInList )
494 field.
name = fieldName;
522 fn.SetName( fn.GetName() );
533 wxString::Format(
_(
"Unable to open destination '%s'" ), aBomJob->
m_outputFile ),
582 bool res = f.Write( dataModel.
Export( fmt ) );
622 _(
"Warning: schematic has annotation errors, please use the schematic "
623 "editor to fix them\n" ),
631 if(
erc.TestDuplicateSheetNames(
false ) > 0 )
634 std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
635 std::make_unique<NETLIST_EXPORTER_XML>( sch );
640 fn.SetName( fn.GetName() +
"-bom" );
659 wxASSERT( symbol !=
nullptr );
661 if( symbol ==
nullptr )
671 symbolToPlot = parent.get();
688 pin.SetVisible(
true );
693 for(
int unit = 1; unit < symbol->
GetUnitCount() + 1; unit++ )
699 size_t forbidden_char;
704 filename = symbol->
GetName().Lower();
706 while( wxString::npos
707 != ( forbidden_char = filename.find_first_of(
708 wxFileName::GetForbiddenChars( wxPATH_DOS ) ) ) )
710 filename = filename.replace( forbidden_char, 1, wxS(
'_' ) );
716 filename += wxString::Format(
"_%d", unit );
719 filename += wxS(
"_demorgan" );
721 fn.SetName( filename );
722 m_reporter->
Report( wxString::Format(
_(
"Plotting symbol '%s' unit %d to '%s'\n" ),
723 symbol->
GetName(), unit, fn.GetFullPath() ),
729 filename += wxS(
"_demorgan" );
731 fn.SetName( filename );
733 symbol->
GetName(), fn.GetFullPath() ),
749 const double scale = 1.0;
756 if( !plotter->
OpenFile( fn.GetFullPath() ) )
770 bool background =
true;
778 symbolToPlot->
Plot( plotter, unit,
convert, background, plotPos, temp,
false );
782 symbolToPlot->
Plot( plotter, unit,
convert, !background, plotPos, temp,
false );
852 for(
const std::pair<const wxString, LIB_SYMBOL*>& entry : libSymMap )
854 exitCode =
doSymExportSvg( svgJob, &renderSettings, entry.second );
898 bool shouldSave = upgradeJob->
m_force
951 fn.SetName( fn.GetName() );
966 units = EDA_UNITS::INCHES;
969 units = EDA_UNITS::MILS;
973 units = EDA_UNITS::MILLIMETRES;
break;
976 std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
977 std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
986 markersProvider->SetSeverities( ercJob->
m_severity );
989 wxString::Format(
_(
"Found %d violations\n" ), markersProvider->GetCount() ),
994 bool wroteReport =
false;
1004 wxString::Format(
_(
"Unable to save ERC report to %s\n" ), ercJob->
m_outputFile ),
1014 if( markersProvider->GetCount() > 0 )
1041 return drawingSheet;
constexpr EDA_IU_SCALE schIUScale
int GetVirtualPageNumber() const
const wxString & GetPageNumber() const
coord_type GetHeight() const
coord_type GetWidth() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
void SetSheetPath(const std::string &aSheetPath)
Set the sheet path displayed in the title block.
void SetSheetCount(int aSheetCount)
Changes the sheet-count number displayed in the title block.
void SetPageNumber(const std::string &aPageNumber)
Changes the page number displayed in the title block.
void SetSheetName(const std::string &aSheetName)
Set the sheet name displayed in the title block.
void SetPageBorderColorLayer(int aLayerId)
Overrides the layer used to pick the color of the page border (normally LAYER_GRID)
void SetIsFirstPage(bool aIsFirstPage)
Change if this is first page.
void SetFileName(const std::string &aFileName)
Set the file name displayed in the title block.
void SetColorLayer(int aLayerId)
Can be used to override which layer ID is used for drawing sheet item colors.
static SCHEMATIC * LoadSchematic(wxString &aFileName)
int JobExportNetlist(JOB *aJob)
int JobSymUpgrade(JOB *aJob)
int JobExportBom(JOB *aJob)
void InitRenderSettings(KIGFX::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.
int JobSymExportSvg(JOB *aJob)
DS_PROXY_VIEW_ITEM * getDrawingSheetProxyView(SCHEMATIC *aSch)
int JobExportPythonBom(JOB *aJob)
int doSymExportSvg(JOB_SYM_EXPORT_SVG *aSvgJob, KIGFX::SCH_RENDER_SETTINGS *aRenderSettings, LIB_SYMBOL *symbol)
int JobExportPlot(JOB *aJob)
bool WriteJsonReport(const wxString &aFullFileName)
bool WriteTextReport(const wxString &aFullFileName)
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, PROGRESS_REPORTER *aProgressReporter)
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()
PROGRESS_REPORTER * m_progressReporter
void Register(const std::string &aJobTypeName, std::function< int(JOB *job)> aHandler)
std::vector< wxString > m_fieldsLabels
std::vector< wxString > m_fieldsOrdered
wxString m_refRangeDelimiter
std::vector< wxString > m_fieldsGroupBy
wxString m_stringDelimiter
wxString m_fieldDelimiter
wxString m_bomFmtPresetName
JOB_PAGE_SIZE m_pageSizeSelect
SCH_PLOT_FORMAT m_plotFormat
bool m_useBackgroundColor
wxString m_outputDirectory
JOB_HPGL_PLOT_ORIGIN_AND_UNITS m_HPGLPlotOrigin
std::vector< wxString > m_plotPages
JOB_HPGL_PAGE_SIZE m_HPGLPaperSizeSelect
bool m_exitCodeViolations
wxString m_outputDirectory
bool m_includeHiddenFields
wxString m_outputLibraryPath
An simple container class that lets us dispatch output jobs to kifaces.
const std::map< wxString, wxString > & GetVarOverrides() const
void SetDefaultPenWidth(int aWidth)
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
Store schematic specific render settings.
void LoadColors(const COLOR_SETTINGS *aSettings) override
The base class for drawable items used by schematic library symbols.
Define a library symbol object.
void Plot(PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const
Plot lib symbol to plotter.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
wxString GetName() const override
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed, bool aPlotHidden=true)
Plot Lib Fields only of the symbol to plotter.
int GetUnitCount() const override
For items with units, return the number of units.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Describe the page size and margins of a paper page on which to eventually print or plot.
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
static const wxChar Custom[]
"User" defined page type
void SetHeightMils(double aHeightInMils)
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
void SetWidthMils(double aWidthInMils)
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetRenderSettings(RENDER_SETTINGS *aSettings)
virtual void SetCreator(const wxString &aCreator)
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
wxString m_SchDrawingSheetFileName
TEMPLATES m_TemplateFieldNames
std::vector< BOM_PRESET > m_BomPresets
double m_DashedLineGapRatio
std::vector< BOM_FMT_PRESET > m_BomFmtPresets
double m_DashedLineDashRatio
Holds all the data relating to one schematic.
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
const std::map< wxString, wxString > * GetProperties()
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
virtual LIB_SYMBOL * GetSymbol(const wxString &aName)
const LIB_SYMBOL_MAP & GetSymbolMap() const
void SetFileName(const wxString &aFileName)
void SetModified(bool aModified=true)
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.
const PAGE_INFO & GetPageSettings() const
const wxString & GetFileName() const
const TITLE_BLOCK & GetTitleBlock() const
A cache assistant for the KiCad s-expression symbol libraries.
int GetFileFormatVersionAtLoad() const
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
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.
int GetFieldCount() const
Return the number of fields in this symbol.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
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 ${.
wxString GetTextVars(const wxString &aSource)
Returns any variables unexpanded, e.g.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
const std::string SpiceFileExtension
const std::string CadstarNetlistFileExtension
const std::string SVGFileExtension
const std::string CsvFileExtension
const std::string NetlistFileExtension
const std::string OrCadPcb2NetlistFileExtension
const std::string XmlFileExtension
const std::string JsonFileExtension
const std::string ReportFileExtension
@ LAYER_SCHEMATIC_DRAWINGSHEET
@ LAYER_SCHEMATIC_PAGE_LIMITS
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
static const int ERR_ARGS
static const int ERR_RC_VIOLATIONS
static const int ERR_INVALID_INPUT_FILE
static const int ERR_INVALID_OUTPUT_CONFLICT
Rules check violation count was greater than 0.
static const int ERR_UNKNOWN
PLOT_FORMAT
The set of supported output plot formats.
Plotting engines similar to ps (PostScript, Gerber, svg)
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
HPGL_PLOT_ORIGIN_AND_UNITS
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
static std::vector< BOM_FMT_PRESET > BuiltInPresets()
wxString refRangeDelimiter
std::vector< BOM_FIELD > fieldsOrdered
static std::vector< BOM_PRESET > BuiltInPresets()
constexpr int IUToMils(int iu) const
HPGL_PAGE_SIZE m_HPGLPaperSizeSelect
HPGL_PLOT_ORIGIN_AND_UNITS m_HPGLPlotOrigin
bool m_useBackgroundColor
std::vector< wxString > m_plotPages
wxString m_outputDirectory
Hold a name of a symbol's field, field value, and default visibility.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Definition of file extensions used in Kicad.